├── Bin ├── 7z.dll ├── 7z.exe ├── Binary.cmd ├── Package.cmd └── wget.exe ├── Browser.sln ├── Browser ├── Browser.ico ├── Browser.rc ├── Browser.vcxproj ├── Browser.vcxproj.filters ├── BrowserDlg.cpp ├── BrowserDlg.h ├── BrowserDlgManager.cpp ├── BrowserDlgManager.h ├── BrowserUI.cpp ├── BrowserUI.h ├── BrowserWindow.cpp ├── BrowserWindow.h ├── ClientApp.h ├── ClientAppBrowser.cpp ├── ClientAppBrowser.h ├── ClientAppRenderer.cpp ├── ClientAppRenderer.h ├── ClientHandler.cpp ├── ClientHandler.h ├── ClientRenderDelegate.cpp ├── ClientRenderDelegate.h ├── ClientRunner.cpp ├── ClientRunner.h ├── ClientSwitches.cpp ├── ClientSwitches.h ├── Logo.png ├── MainContext.cpp ├── MainContext.h ├── MainDlg.cpp ├── MessageLoop.h ├── PerfTest.cpp ├── PerfTest.h ├── ResourceUtil.cpp ├── ResourceUtil.h ├── Skin │ ├── BrowserDlg.xml │ ├── btnBackward.png │ ├── btnClose.png │ ├── btnDownload.png │ ├── btnFavList.png │ ├── btnFavorites.png │ ├── btnForward.png │ ├── btnGoto.png │ ├── btnHome.png │ ├── btnMax.png │ ├── btnMin.png │ ├── btnPushed.png │ ├── btnRefresh.png │ ├── btnRestore.png │ ├── btnSearch.png │ ├── btnSettings.png │ ├── btnTabClose.png │ └── btnTabNew.png ├── TempWindow.cpp ├── TempWindow.h ├── binding.html ├── resource.h ├── stdafx.cpp └── stdafx.h ├── Build.cmd ├── FlashTools ├── DllMain.cpp ├── FlashTools.vcxproj ├── FlashTools.vcxproj.filters ├── MinHook │ ├── MinHook.h │ ├── buffer.c │ ├── buffer.h │ ├── hde │ │ ├── hde32.c │ │ ├── hde32.h │ │ ├── hde64.c │ │ ├── hde64.h │ │ ├── pstdint.h │ │ ├── table32.h │ │ └── table64.h │ ├── hook.c │ ├── trampoline.c │ └── trampoline.h ├── Module.def └── stdafx.h ├── LICENSE ├── README.md └── docs ├── css └── style.css └── index.html /Bin/7z.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanwer/Browser/619c40dc6cab859703352f0e1a5b40b12f826ae3/Bin/7z.dll -------------------------------------------------------------------------------- /Bin/7z.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanwer/Browser/619c40dc6cab859703352f0e1a5b40b12f826ae3/Bin/7z.exe -------------------------------------------------------------------------------- /Bin/Binary.cmd: -------------------------------------------------------------------------------- 1 | @Echo Off 2 | SET Version=%1 3 | if "%Version%" =="" (SET Version=3.2623.1401.gb90a3be) 4 | for /f "tokens=1-4 delims=." %%a in ("%Version%") do ((set V1=%%a)&(set V2=%%b)&(set V3=%%c)&(set V4=%%d)) 5 | IF EXIST .\Bin ( PUSHD .\Bin ) else ( PUSHD %CD% ) 6 | IF NOT EXIST libcef.dll ( 7 | Echo Download %V1%.%V2%.%V3%.%V4% binary files 8 | IF NOT EXIST "cef_binary_%Version%_windows32.7z" ( 9 | wget.exe https://github.com/sanwer/libcef/releases/download/%V1%.%V2%.%V3%/cef_binary_%Version%_windows32.7z 10 | IF %ERRORLEVEL%==1 GOTO ErrorBinary 11 | ) 12 | 7z.exe x cef_binary_%Version%_windows32.7z 13 | IF %ERRORLEVEL%==1 GOTO ErrorBinary 14 | IF NOT EXIST libcef.dll GOTO ErrorBinary 15 | ) 16 | GOTO EndBinary 17 | 18 | :ErrorBinary 19 | Echo [ERROR]: There was an error in downloading binary files. 20 | PAUSE 21 | 22 | :EndBinary 23 | POPD 24 | -------------------------------------------------------------------------------- /Bin/Package.cmd: -------------------------------------------------------------------------------- 1 | @Echo Off 2 | Echo Packaging binary 3 | IF EXIST .\Bin ( PUSHD .\Bin ) else ( PUSHD %CD% ) 4 | IF EXIST Browser.7z DEL /F /Q /S Browser.7z 5 | SET FILES=locales\en-US.pak locales\zh-CN.pak 6 | IF EXIST swiftshader ( SET FILES=%FILES% swiftshader ) 7 | SET FILES=%FILES% cef.pak cef_100_percent.pak cef_200_percent.pak cef_extensions.pak 8 | IF EXIST devtools_resources.pak ( SET FILES=%FILES% devtools_resources.pak ) 9 | SET FILES=%FILES% d3dcompiler_43.dll d3dcompiler_47.dll libcef.dll libEGL.dll libGLESv2.dll 10 | IF EXIST chrome_elf.dll ( SET FILES=%FILES% chrome_elf.dll ) 11 | SET FILES=%FILES% icudtl.dat natives_blob.bin snapshot_blob.bin 12 | IF EXIST v8_context_snapshot.bin ( SET FILES=%FILES% v8_context_snapshot.bin ) 13 | IF EXIST FlashTools.dll ( SET FILES=%FILES% FlashTools.dll ) 14 | 7z.exe a -mx9 -t7z Browser.7z Browser.exe %FILES% 15 | Rem IF EXIST BrowserInst.exe DEL /F /Q /S BrowserInst.exe 16 | Rem COPY /b 7zsfx.sfx + config.txt + Browser.7z BrowserInst.exe 17 | IF "%ERRORLEVEL%"=="1" GOTO ErrorPackage 18 | GOTO EndPackage 19 | 20 | :ErrorPackage 21 | Echo [ERROR]: There is an error in packing binaries. 22 | PAUSE 23 | 24 | :EndPackage 25 | POPD 26 | -------------------------------------------------------------------------------- /Bin/wget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanwer/Browser/619c40dc6cab859703352f0e1a5b40b12f826ae3/Bin/wget.exe -------------------------------------------------------------------------------- /Browser.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Browser", "Browser\Browser.vcxproj", "{E59198AF-B45C-412D-9077-5EF79A13241D}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {95EC0A3D-22B5-4635-948F-194EAE364F42} = {95EC0A3D-22B5-4635-948F-194EAE364F42} 7 | {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9} = {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9} 8 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E} = {E106ACD7-4E53-4AEE-942B-D0DD426DB34E} 9 | EndProjectSection 10 | EndProject 11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DuiLib", "..\DuiLib\DuiLib.vcxproj", "{E106ACD7-4E53-4AEE-942B-D0DD426DB34E}" 12 | EndProject 13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcef_dll_wrapper", "..\libcef\libcef_dll_wrapper.vcxproj", "{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}" 14 | EndProject 15 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FlashTools", "FlashTools\FlashTools.vcxproj", "{95EC0A3D-22B5-4635-948F-194EAE364F42}" 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Win32 = Debug|Win32 20 | Debug|x64 = Debug|x64 21 | Release|Win32 = Release|Win32 22 | Release|x64 = Release|x64 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {E59198AF-B45C-412D-9077-5EF79A13241D}.Debug|Win32.ActiveCfg = Debug|Win32 26 | {E59198AF-B45C-412D-9077-5EF79A13241D}.Debug|Win32.Build.0 = Debug|Win32 27 | {E59198AF-B45C-412D-9077-5EF79A13241D}.Debug|x64.ActiveCfg = Debug|x64 28 | {E59198AF-B45C-412D-9077-5EF79A13241D}.Debug|x64.Build.0 = Debug|x64 29 | {E59198AF-B45C-412D-9077-5EF79A13241D}.Release|Win32.ActiveCfg = Release|Win32 30 | {E59198AF-B45C-412D-9077-5EF79A13241D}.Release|Win32.Build.0 = Release|Win32 31 | {E59198AF-B45C-412D-9077-5EF79A13241D}.Release|x64.ActiveCfg = Release|x64 32 | {E59198AF-B45C-412D-9077-5EF79A13241D}.Release|x64.Build.0 = Release|x64 33 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Debug|Win32.ActiveCfg = Debug|Win32 34 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Debug|Win32.Build.0 = Debug|Win32 35 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Debug|x64.ActiveCfg = Debug|x64 36 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Debug|x64.Build.0 = Debug|x64 37 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Release|Win32.ActiveCfg = Release|Win32 38 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Release|Win32.Build.0 = Release|Win32 39 | {E106ACD7-4E53-4AEE-942B-D0DD426DB34E}.Release|x64.ActiveCfg = Release|x64 40 | {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|Win32.ActiveCfg = Debug|Win32 41 | {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|Win32.Build.0 = Debug|Win32 42 | {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Debug|x64.ActiveCfg = Debug|Win32 43 | {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|Win32.ActiveCfg = Release|Win32 44 | {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|Win32.Build.0 = Release|Win32 45 | {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9}.Release|x64.ActiveCfg = Release|x64 46 | {95EC0A3D-22B5-4635-948F-194EAE364F42}.Debug|Win32.ActiveCfg = Debug|Win32 47 | {95EC0A3D-22B5-4635-948F-194EAE364F42}.Debug|Win32.Build.0 = Debug|Win32 48 | {95EC0A3D-22B5-4635-948F-194EAE364F42}.Debug|x64.ActiveCfg = Debug|Win32 49 | {95EC0A3D-22B5-4635-948F-194EAE364F42}.Release|Win32.ActiveCfg = Release|Win32 50 | {95EC0A3D-22B5-4635-948F-194EAE364F42}.Release|Win32.Build.0 = Release|Win32 51 | {95EC0A3D-22B5-4635-948F-194EAE364F42}.Release|x64.ActiveCfg = Release|Win32 52 | EndGlobalSection 53 | GlobalSection(SolutionProperties) = preSolution 54 | HideSolutionNode = FALSE 55 | EndGlobalSection 56 | EndGlobal 57 | -------------------------------------------------------------------------------- /Browser/Browser.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanwer/Browser/619c40dc6cab859703352f0e1a5b40b12f826ae3/Browser/Browser.ico -------------------------------------------------------------------------------- /Browser/Browser.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #define APSTUDIO_HIDDEN_SYMBOLS 11 | #include "windows.h" 12 | #include "include/cef_version.h" 13 | #undef APSTUDIO_HIDDEN_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | #undef APSTUDIO_READONLY_SYMBOLS 17 | 18 | ///////////////////////////////////////////////////////////////////////////// 19 | // resources 20 | 21 | #if !defined(AFX_RESOURCE_DLL) 22 | #ifdef _WIN32 23 | LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL 24 | #endif //_WIN32 25 | 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | // Binary 29 | // 30 | 31 | IDS_LOGO_PNG BINARY "Logo.png" 32 | IDS_BINDING_HTML BINARY "binding.html" 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // Icon 37 | // 38 | 39 | // Icon with lowest ID value placed first to ensure application icon 40 | // remains consistent on all systems. 41 | IDR_MAINFRAME ICON "Browser.ico" 42 | 43 | #ifdef APSTUDIO_INVOKED 44 | ///////////////////////////////////////////////////////////////////////////// 45 | // 46 | // TEXTINCLUDE 47 | // 48 | 49 | 1 TEXTINCLUDE 50 | BEGIN 51 | "resource.h\0" 52 | END 53 | 54 | 2 TEXTINCLUDE 55 | BEGIN 56 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 57 | "#include ""windows.h""\r\n" 58 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 59 | "\0" 60 | END 61 | 62 | 3 TEXTINCLUDE 63 | BEGIN 64 | "\r\n" 65 | "\0" 66 | END 67 | 68 | #endif // APSTUDIO_INVOKED 69 | 70 | 71 | ///////////////////////////////////////////////////////////////////////////// 72 | // 73 | // Version 74 | // 75 | 76 | VS_VERSION_INFO VERSIONINFO 77 | FILEVERSION 1,0,0,1 78 | PRODUCTVERSION 1,0,0,1 79 | FILEFLAGSMASK 0x17L 80 | #ifdef _DEBUG 81 | FILEFLAGS 0x1L 82 | #else 83 | FILEFLAGS 0x0L 84 | #endif 85 | FILEOS 0x4L 86 | FILETYPE 0x1L 87 | FILESUBTYPE 0x0L 88 | BEGIN 89 | BLOCK "StringFileInfo" 90 | BEGIN 91 | BLOCK "080404b0" 92 | BEGIN 93 | VALUE "FileDescription", "https://github.com/sanwer/Browser" 94 | VALUE "FileVersion", "1,0,0,1" 95 | VALUE "InternalName", "Browser" 96 | VALUE "LegalCopyright", "Copyright (C) 2016-2017" 97 | VALUE "OriginalFilename", "Browser.exe" 98 | VALUE "ProductName", "Browser" 99 | VALUE "ProductVersion", "1,0,0,1" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x804, 1200 105 | END 106 | END 107 | 108 | ///////////////////////////////////////////////////////////////////////////// 109 | // 110 | // ZIPRES 111 | // 112 | 113 | IDR_ZIPRES ZIPRES "Skin.zip" 114 | 115 | #endif // resources 116 | ///////////////////////////////////////////////////////////////////////////// 117 | 118 | 119 | 120 | #ifndef APSTUDIO_INVOKED 121 | ///////////////////////////////////////////////////////////////////////////// 122 | // 123 | // Generated from the TEXTINCLUDE 3 resource. 124 | // 125 | 126 | 127 | ///////////////////////////////////////////////////////////////////////////// 128 | #endif // not APSTUDIO_INVOKED 129 | 130 | -------------------------------------------------------------------------------- /Browser/Browser.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {E59198AF-B45C-412D-9077-5EF79A13241D} 23 | Browser 24 | Browser 25 | 26 | 27 | 28 | Application 29 | Unicode 30 | v100 31 | true 32 | true 33 | false 34 | false 35 | true 36 | true 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | $(SolutionDir)Bin\$(Configuration)\$(ProjectName)\ 47 | $(SolutionDir)Bin\$(Configuration)\$(ProjectName)\ 48 | $(SolutionDir)Bin\$(Platform)\$(Configuration)\$(ProjectName)\ 49 | $(SolutionDir)Bin\$(Platform)\$(Configuration)\$(ProjectName)\ 50 | $(SolutionDir)Bin\ 51 | $(SolutionDir)Bin\ 52 | $(SolutionDir)Bin\$(Platform)\ 53 | $(SolutionDir)Bin\$(Platform)\ 54 | $(ProjectName)_d 55 | $(ProjectName)_d 56 | true 57 | true 58 | false 59 | false 60 | 61 | 62 | 63 | NotUsing 64 | Level3 65 | Disabled 66 | WIN32;_DEBUG;_WINDOWS;UILIB_STATIC;%(PreprocessorDefinitions) 67 | .;..\..\libcef;..\..\DuiLib 68 | MultiThreadedDebug 69 | 70 | 71 | Windows 72 | true 73 | $(SolutionDir)Lib\;..\..\libcef\Lib\;%(AdditionalLibraryDirectories) 74 | DuiLib_d.lib;libcef_dll_wrapper_d.lib;%(AdditionalDependencies) 75 | 76 | 77 | IF NOT EXIST Skin.zip ..\Bin\7z.exe a Skin.zip .\Skin\* 78 | 79 | 80 | .;..\..\libcef 81 | 82 | 83 | 84 | 85 | NotUsing 86 | Level3 87 | Disabled 88 | WIN32;_DEBUG;_WINDOWS;UILIB_STATIC;%(PreprocessorDefinitions) 89 | .;..\..\libcef;..\..\DuiLib 90 | MultiThreadedDebug 91 | 92 | 93 | Windows 94 | true 95 | $(SolutionDir)Lib\$(Platform)\;..\..\libcef\Lib\$(Platform)\;%(AdditionalLibraryDirectories) 96 | DuiLib_d.lib;libcef_dll_wrapper_d.lib;%(AdditionalDependencies) 97 | 98 | 99 | IF NOT EXIST Skin.zip ..\Bin\7z.exe a Skin.zip .\Skin\* 100 | 101 | 102 | .;..\..\libcef 103 | 104 | 105 | 106 | 107 | Level3 108 | NotUsing 109 | MaxSpeed 110 | true 111 | true 112 | WIN32;NDEBUG;_WINDOWS;UILIB_STATIC;%(PreprocessorDefinitions) 113 | .;..\..\libcef;..\..\DuiLib 114 | MultiThreaded 115 | 116 | 117 | Windows 118 | true 119 | true 120 | true 121 | $(SolutionDir)Lib\;..\..\libcef\Lib\;%(AdditionalLibraryDirectories) 122 | DuiLib.lib;libcef_dll_wrapper.lib;%(AdditionalDependencies) 123 | 124 | 125 | IF NOT EXIST Skin.zip ..\Bin\7z.exe a Skin.zip .\Skin\* 126 | 127 | 128 | .;..\..\libcef 129 | 130 | 131 | 132 | 133 | Level3 134 | NotUsing 135 | MaxSpeed 136 | true 137 | true 138 | WIN32;NDEBUG;_WINDOWS;UILIB_STATIC;%(PreprocessorDefinitions) 139 | .;..\..\libcef;..\..\DuiLib 140 | MultiThreaded 141 | 142 | 143 | 144 | IF NOT EXIST Skin.zip ..\Bin\7z.exe a Skin.zip .\Skin\* 145 | 146 | Windows 147 | true 148 | true 149 | true 150 | $(SolutionDir)Lib\$(Platform)\;..\..\libcef\Lib\$(Platform)\;%(AdditionalLibraryDirectories) 151 | DuiLib.lib;libcef_dll_wrapper.lib;%(AdditionalDependencies) 152 | 153 | 154 | .;..\..\libcef 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | Create 174 | Create 175 | Create 176 | Create 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /Browser/Browser.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | 源文件 32 | 33 | 34 | 源文件 35 | 36 | 37 | 源文件 38 | 39 | 40 | 源文件 41 | 42 | 43 | 源文件 44 | 45 | 46 | 源文件 47 | 48 | 49 | 源文件 50 | 51 | 52 | 源文件 53 | 54 | 55 | 源文件 56 | 57 | 58 | 源文件 59 | 60 | 61 | 源文件 62 | 63 | 64 | 源文件 65 | 66 | 67 | 68 | 69 | 头文件 70 | 71 | 72 | 头文件 73 | 74 | 75 | 头文件 76 | 77 | 78 | 头文件 79 | 80 | 81 | 头文件 82 | 83 | 84 | 头文件 85 | 86 | 87 | 头文件 88 | 89 | 90 | 头文件 91 | 92 | 93 | 头文件 94 | 95 | 96 | 头文件 97 | 98 | 99 | 头文件 100 | 101 | 102 | 头文件 103 | 104 | 105 | 头文件 106 | 107 | 108 | 头文件 109 | 110 | 111 | 头文件 112 | 113 | 114 | 头文件 115 | 116 | 117 | 头文件 118 | 119 | 120 | 头文件 121 | 122 | 123 | 124 | 125 | 资源文件 126 | 127 | 128 | 资源文件 129 | 130 | 131 | 资源文件 132 | 133 | 134 | 资源文件 135 | 136 | 137 | 138 | 139 | 资源文件 140 | 141 | 142 | -------------------------------------------------------------------------------- /Browser/BrowserDlg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanwer/Browser/619c40dc6cab859703352f0e1a5b40b12f826ae3/Browser/BrowserDlg.cpp -------------------------------------------------------------------------------- /Browser/BrowserDlg.h: -------------------------------------------------------------------------------- 1 | #ifndef __BROWSER_WND_H__ 2 | #define __BROWSER_WND_H__ 3 | #pragma once 4 | #include "MessageLoop.h" 5 | #include "BrowserWindow.h" 6 | #include "ClientApp.h" 7 | #include "BrowserUI.h" 8 | 9 | namespace Browser 10 | { 11 | class BrowserDlg : public DuiLib::WindowImplBase, public Browser::BrowserWindow::Delegate, public base::RefCountedThreadSafe 12 | { 13 | public: 14 | class Delegate { 15 | public: 16 | virtual CefRefPtr GetRequestContext() = 0; 17 | virtual void OnBrowserDlgDestroyed(BrowserDlg* pDlg) = 0; 18 | protected: 19 | virtual ~Delegate() {} 20 | }; 21 | BrowserDlg(); 22 | ~BrowserDlg(); 23 | 24 | public: 25 | LPCTSTR GetWindowClassName() const; 26 | virtual void InitWindow(); 27 | virtual void OnFinalMessage(HWND hWnd); 28 | virtual DuiLib::CDuiString GetSkinFile(); 29 | virtual LRESULT ResponseDefaultKeyEvent(WPARAM wParam); 30 | virtual DuiLib::CControlUI* CreateControl(LPCTSTR pstrClass); 31 | LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam); 32 | 33 | protected: 34 | void Notify(DuiLib::TNotifyUI& msg); 35 | 36 | private: 37 | // BrowserWindow::Delegate methods. 38 | void OnBrowserCreated(CefRefPtr browser) OVERRIDE; 39 | void OnBrowserClosed(CefRefPtr browser) OVERRIDE; 40 | void OnBrowserAllClosed() OVERRIDE; 41 | void OnSetAddress(CefRefPtr browser, const CefString& url) OVERRIDE; 42 | void OnSetTitle(CefRefPtr browser, const CefString& title) OVERRIDE; 43 | void OnSetFullscreen(CefRefPtr browser, bool fullscreen) OVERRIDE; 44 | void OnSetLoadingState(CefRefPtr browser, bool isLoading,bool canGoBack,bool canGoForward) OVERRIDE; 45 | void OnSetDraggableRegions(CefRefPtr browser, const std::vector& regions) OVERRIDE; 46 | void OnNewTab(CefRefPtr browser, const CefString& url) OVERRIDE; 47 | void NotifyDestroyedIfDone(); 48 | 49 | private: 50 | DuiLib::CHorizontalLayoutUI* uiTabs; 51 | DuiLib::CLabelUI* pTitle; 52 | DuiLib::CButtonUI* tabNew; 53 | DuiLib::CControlUI* uiToolbar; 54 | DuiLib::CButtonUI* btnBackward; 55 | DuiLib::CButtonUI* btnForward; 56 | DuiLib::CEditUI* editUrl; 57 | DuiLib::CEditUI* editKeyword; 58 | DuiLib::CDuiString m_sPopup; 59 | 60 | public: 61 | // BrowserDlg methods. 62 | void Init( 63 | BrowserDlg::Delegate* delegate, 64 | HWND hParent, 65 | bool with_controls, 66 | const CefRect& bounds, 67 | const CefBrowserSettings& settings, 68 | const CefString& url); 69 | 70 | void InitAsPopup( 71 | BrowserDlg::Delegate* delegate, 72 | bool with_controls, 73 | const CefPopupFeatures& popupFeatures, 74 | CefWindowInfo& windowInfo, 75 | CefRefPtr& client, 76 | CefBrowserSettings& settings); 77 | 78 | void NewTab(const CefString& url); 79 | 80 | CefRefPtr GetBrowser(); 81 | CefWindowHandle GetWindowHandle(); 82 | void LoadURL(const CefString& url); 83 | 84 | private: 85 | void CreateBrowserWindow(const CefString& startup_url); 86 | void CreateBrowserDlg(const CefBrowserSettings& settings); 87 | 88 | HWND m_hParent; 89 | bool m_bWithControls; 90 | bool m_bIsPopup; 91 | RECT m_rcStart; 92 | bool m_bInitialized; 93 | bool m_bWindowDestroyed; 94 | bool m_bBrowserDestroyed; 95 | int m_nCurBrowserId; 96 | BrowserDlg::Delegate* m_Delegate; 97 | Browser::BrowserUI* m_pBrowserUI; 98 | scoped_ptr m_BrowserCtrl; 99 | }; 100 | } 101 | #endif -------------------------------------------------------------------------------- /Browser/BrowserDlgManager.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "BrowserDlgManager.h" 3 | #include 4 | #include "include/base/cef_bind.h" 5 | #include "include/base/cef_logging.h" 6 | #include "include/wrapper/cef_closure_task.h" 7 | #include "include/wrapper/cef_helpers.h" 8 | #include "MainContext.h" 9 | #include "ClientSwitches.h" 10 | 11 | namespace Browser 12 | { 13 | namespace 14 | { 15 | class ClientRequestContextHandler : public CefRequestContextHandler 16 | { 17 | public: 18 | ClientRequestContextHandler() {} 19 | bool OnBeforePluginLoad( 20 | const CefString& mime_type, 21 | const CefString& plugin_url, 22 | bool is_main_frame, 23 | const CefString& top_origin_url, 24 | CefRefPtr plugin_info, 25 | PluginPolicy* plugin_policy) /*OVERRIDE*/ 26 | { 27 | // Always allow the PDF plugin to load. 28 | if (*plugin_policy != PLUGIN_POLICY_ALLOW && mime_type == "application/pdf") { 29 | *plugin_policy = PLUGIN_POLICY_ALLOW; 30 | return true; 31 | } 32 | return false; 33 | } 34 | private: 35 | IMPLEMENT_REFCOUNTING(ClientRequestContextHandler); 36 | }; 37 | } 38 | 39 | BrowserDlgManager::BrowserDlgManager(bool terminate_when_all_windows_closed) 40 | : m_bTerminateWhenAllWindowsClosed(terminate_when_all_windows_closed) 41 | { 42 | CefRefPtr command_line = CefCommandLine::GetGlobalCommandLine(); 43 | DCHECK(command_line.get()); 44 | m_bRequestContextPerBrowser = command_line->HasSwitch(Switches::kRequestContextPerBrowser); 45 | m_bRequestContextSharedBrowser = command_line->HasSwitch(Switches::kRequestContextSharedCache); 46 | } 47 | 48 | BrowserDlgManager::~BrowserDlgManager() 49 | { 50 | // All root windows should already have been destroyed. 51 | DCHECK(m_BrowserDlgSet.empty()); 52 | } 53 | 54 | scoped_refptr BrowserDlgManager::CreateBrowserDlg( 55 | HWND hParent, 56 | bool with_controls, 57 | const CefRect& bounds, 58 | const CefString& url) 59 | { 60 | CefBrowserSettings settings; 61 | MainContext::Get()->PopulateBrowserSettings(&settings); 62 | scoped_refptr pDlg = new BrowserDlg(); 63 | if(pDlg){ 64 | pDlg->Init(this, hParent, with_controls, bounds, settings, url.empty() ? MainContext::Get()->GetMainURL() : url); 65 | 66 | // Store a reference to the root window on the main thread. 67 | OnBrowserDlgCreated(pDlg); 68 | } 69 | 70 | return pDlg; 71 | } 72 | 73 | scoped_refptr BrowserDlgManager::CreateBrowserDlgAsPopup( 74 | bool with_controls, 75 | const CefPopupFeatures& popupFeatures, 76 | CefWindowInfo& windowInfo, 77 | CefRefPtr& client, 78 | CefBrowserSettings& settings) 79 | { 80 | MainContext::Get()->PopulateBrowserSettings(&settings); 81 | scoped_refptr pDlg = new Browser::BrowserDlg(); 82 | if(pDlg){ 83 | pDlg->InitAsPopup(this, with_controls, popupFeatures, windowInfo, client, settings); 84 | 85 | // Store a reference to the root window on the main thread. 86 | OnBrowserDlgCreated(pDlg); 87 | } 88 | 89 | return pDlg; 90 | } 91 | 92 | scoped_refptr BrowserDlgManager::GetWindowForBrowser(int browser_id) 93 | { 94 | DCHECK(CefCurrentlyOn(TID_UI)); 95 | 96 | BrowserDlgSet::const_iterator it = m_BrowserDlgSet.begin(); 97 | for (; it != m_BrowserDlgSet.end(); ++it) { 98 | CefRefPtr browser = (*it)->GetBrowser(); 99 | if (browser.get() && browser->GetIdentifier() == browser_id) 100 | return *it; 101 | } 102 | return NULL; 103 | } 104 | 105 | void BrowserDlgManager::CloseAllWindows(bool force) 106 | { 107 | if (!CefCurrentlyOn(TID_UI)) { 108 | // Execute this method on the main thread. 109 | CefPostTask(TID_UI, CefCreateClosureTask(base::Bind(&BrowserDlgManager::CloseAllWindows, base::Unretained(this), force))); 110 | return; 111 | } 112 | 113 | if (m_BrowserDlgSet.empty()) 114 | return; 115 | 116 | BrowserDlgSet::const_iterator it = m_BrowserDlgSet.begin(); 117 | for (; it != m_BrowserDlgSet.end(); ++it) 118 | (*it)->Close(force); 119 | } 120 | 121 | void BrowserDlgManager::OnBrowserDlgCreated(scoped_refptr pDlg) 122 | { 123 | if (!CefCurrentlyOn(TID_UI)) { 124 | // Execute this method on the main thread. 125 | CefPostTask(TID_UI, CefCreateClosureTask(base::Bind(&BrowserDlgManager::OnBrowserDlgCreated, base::Unretained(this), pDlg))); 126 | return; 127 | } 128 | 129 | m_BrowserDlgSet.insert(pDlg); 130 | } 131 | 132 | CefRefPtr BrowserDlgManager::GetRequestContext() 133 | { 134 | DCHECK(CefCurrentlyOn(TID_UI)); 135 | 136 | if (m_bRequestContextPerBrowser) { 137 | // Create a new request context for each browser. 138 | CefRequestContextSettings settings; 139 | 140 | CefRefPtr command_line = 141 | CefCommandLine::GetGlobalCommandLine(); 142 | if (command_line->HasSwitch(Switches::kCachePath)) { 143 | if (m_bRequestContextSharedBrowser) { 144 | // Give each browser the same cache path. The resulting context objects 145 | // will share the same storage internally. 146 | CefString(&settings.cache_path) = 147 | command_line->GetSwitchValue(Switches::kCachePath); 148 | } else { 149 | // Give each browser a unique cache path. This will create completely 150 | // isolated context objects. 151 | std::stringstream ss; 152 | ss << command_line->GetSwitchValue(Switches::kCachePath).ToString() << 153 | time(NULL); 154 | CefString(&settings.cache_path) = ss.str(); 155 | } 156 | } 157 | 158 | return CefRequestContext::CreateContext(settings, new ClientRequestContextHandler); 159 | } 160 | 161 | // All browsers will share the global request context. 162 | if (!m_SharedRequestContext.get()) { 163 | m_SharedRequestContext = CefRequestContext::CreateContext(CefRequestContext::GetGlobalContext(), new ClientRequestContextHandler); 164 | } 165 | return m_SharedRequestContext; 166 | } 167 | 168 | void BrowserDlgManager::OnBrowserDlgDestroyed(BrowserDlg* pDlg) 169 | { 170 | DCHECK(CefCurrentlyOn(TID_UI)); 171 | 172 | BrowserDlgSet::iterator it = m_BrowserDlgSet.find(pDlg); 173 | if (it != m_BrowserDlgSet.end()) 174 | m_BrowserDlgSet.erase(it); 175 | 176 | if (m_bTerminateWhenAllWindowsClosed && m_BrowserDlgSet.empty()) { 177 | // Quit the main message loop after all windows have closed. 178 | CefQuitMessageLoop(); 179 | //PostQuitMessage(0); 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /Browser/BrowserDlgManager.h: -------------------------------------------------------------------------------- 1 | #ifndef __BROWSER_MANAGER_H__ 2 | #define __BROWSER_MANAGER_H__ 3 | #pragma once 4 | #include 5 | #include "include/base/cef_scoped_ptr.h" 6 | #include "include/cef_command_line.h" 7 | #include "BrowserDlg.h" 8 | #include "TempWindow.h" 9 | 10 | namespace Browser 11 | { 12 | class BrowserDlgManager : public BrowserDlg::Delegate { 13 | public: 14 | // If |terminate_when_all_windows_closed| is true quit the main message loop 15 | // after all windows have closed. 16 | explicit BrowserDlgManager(bool terminate_when_all_windows_closed); 17 | 18 | scoped_refptr CreateBrowserDlg( 19 | HWND hParent, 20 | bool with_controls, 21 | const CefRect& bounds, 22 | const CefString& url); 23 | 24 | scoped_refptr CreateBrowserDlgAsPopup( 25 | bool with_controls, 26 | const CefPopupFeatures& popupFeatures, 27 | CefWindowInfo& windowInfo, 28 | CefRefPtr& client, 29 | CefBrowserSettings& settings); 30 | 31 | // Returns the BrowserDlg associated with the specified browser ID. Must be 32 | // called on the main thread. 33 | scoped_refptr GetWindowForBrowser(int browser_id); 34 | 35 | // Close all existing windows. If |force| is true onunload handlers will not 36 | // be executed. 37 | void CloseAllWindows(bool force); 38 | 39 | private: 40 | // Allow deletion via scoped_ptr only. 41 | friend struct base::DefaultDeleter; 42 | 43 | ~BrowserDlgManager(); 44 | 45 | void OnBrowserDlgCreated(scoped_refptr pDlg); 46 | 47 | // BrowserDlg::Delegate methods. 48 | CefRefPtr GetRequestContext() OVERRIDE; 49 | void OnBrowserDlgDestroyed(BrowserDlg* pDlg) OVERRIDE; 50 | 51 | const bool m_bTerminateWhenAllWindowsClosed; 52 | bool m_bRequestContextPerBrowser; 53 | bool m_bRequestContextSharedBrowser; 54 | 55 | // Existing root windows. Only accessed on the main thread. 56 | typedef std::set > BrowserDlgSet; 57 | BrowserDlgSet m_BrowserDlgSet; 58 | 59 | // Singleton window used as the temporary parent for popup browsers. 60 | TempWindow m_TempWindow; 61 | 62 | CefRefPtr m_SharedRequestContext; 63 | 64 | DISALLOW_COPY_AND_ASSIGN(BrowserDlgManager); 65 | }; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Browser/BrowserUI.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include 4 | #include "BrowserUI.h" 5 | #include "BrowserDlg.h" 6 | #include "MessageLoop.h" 7 | #include "BrowserDlgManager.h" 8 | #include "MainContext.h" 9 | 10 | namespace Browser 11 | { 12 | BrowserUI::BrowserUI(BrowserDlg* pParent, HWND hParentWnd) 13 | : m_pParent(pParent), 14 | m_hParentWnd(hParentWnd), 15 | m_pCtrl(NULL), 16 | m_nCurBrowserId(0) 17 | { 18 | SetBkColor(0xFFFFFFFF); 19 | } 20 | 21 | LPCTSTR BrowserUI::GetClass() const 22 | { 23 | return _T("BrowserUI"); 24 | } 25 | 26 | LPVOID BrowserUI::GetInterface(LPCTSTR pstrName) 27 | { 28 | if( _tcsicmp(pstrName, _T("BrowserUI")) == 0 ) return static_cast(this); 29 | return CControlUI::GetInterface(pstrName); 30 | } 31 | 32 | void BrowserUI::SetPos(RECT rc, bool bNeedInvalidate) 33 | { 34 | DuiLib::CDuiRect rcPos = rc; 35 | if (m_pCtrl && !rcPos.IsNull()) { 36 | m_pCtrl->ShowBrowser(m_nCurBrowserId, rc.left, rc.top, rc.right - rc.left,rc.bottom - rc.top); 37 | } 38 | CControlUI::SetPos(rc, bNeedInvalidate); 39 | } 40 | 41 | void BrowserUI::SetCtrl(BrowserWindow* pCtrl) 42 | { 43 | m_pCtrl = pCtrl; 44 | } 45 | 46 | void BrowserUI::CreateBrowser(const CefString& url, CefRefPtr request_context) 47 | { 48 | if(m_pCtrl){ 49 | CefBrowserSettings settings; 50 | RECT rcPos = GetPos(); 51 | CefRect cef_rect(rcPos.left, rcPos.top, rcPos.right - rcPos.left, rcPos.bottom - rcPos.top); 52 | m_pCtrl->CreateBrowser(m_hParentWnd, url, cef_rect, settings, request_context); 53 | } 54 | } 55 | 56 | void BrowserUI::ShowBrowser(int nBrowserId) 57 | { 58 | m_nCurBrowserId = nBrowserId; 59 | if(m_pCtrl){ 60 | RECT rcPos = GetPos(); 61 | m_pCtrl->ShowBrowser(nBrowserId, rcPos.left, rcPos.top, rcPos.right - rcPos.left, rcPos.bottom - rcPos.top); 62 | } 63 | } 64 | 65 | void BrowserUI::CloseBrowser(int nBrowserId) 66 | { 67 | if(m_pCtrl){ 68 | CefRefPtr pBrowser = m_pCtrl->GetBrowser(nBrowserId); 69 | if(pBrowser.get()){ 70 | pBrowser->GetHost()->CloseBrowser(false); 71 | } 72 | } 73 | } 74 | 75 | IMPLEMENT_DUICONTROL(TitleUI) 76 | TitleUI::TitleUI() : m_bSelected(false), m_uButtonState(0), m_dwSelectedBkColor(0), 77 | m_uTextStyle(DT_VCENTER | DT_SINGLELINE), m_iFont(-1), m_dwTextColor(0), m_dwDisabledTextColor(0) 78 | { 79 | ::ZeroMemory(&m_rcTextPadding, sizeof(m_rcTextPadding)); 80 | } 81 | 82 | TitleUI::~TitleUI() 83 | { 84 | if( !m_sGroupName.IsEmpty() && m_pManager ) m_pManager->RemoveOptionGroup(m_sGroupName, this); 85 | } 86 | 87 | LPCTSTR TitleUI::GetClass() const 88 | { 89 | return _T("TitleUI"); 90 | } 91 | 92 | UINT TitleUI::GetControlFlags() const 93 | { 94 | if( IsEnabled()) return UIFLAG_SETCURSOR; 95 | else return 0; 96 | } 97 | 98 | LPVOID TitleUI::GetInterface(LPCTSTR pstrName) 99 | { 100 | if( _tcsicmp(pstrName, _T("Title")) == 0 ) return static_cast(this); 101 | return CHorizontalLayoutUI::GetInterface(pstrName); 102 | } 103 | 104 | LPCTSTR TitleUI::GetGroup() const 105 | { 106 | return m_sGroupName; 107 | } 108 | 109 | void TitleUI::SetGroup(LPCTSTR pStrGroupName) 110 | { 111 | if( pStrGroupName == NULL ) { 112 | if( m_sGroupName.IsEmpty() ) return; 113 | m_sGroupName.Empty(); 114 | } 115 | else { 116 | if( m_sGroupName == pStrGroupName ) return; 117 | if (!m_sGroupName.IsEmpty() && m_pManager) m_pManager->RemoveOptionGroup(m_sGroupName, this); 118 | m_sGroupName = pStrGroupName; 119 | } 120 | 121 | if( !m_sGroupName.IsEmpty() ) { 122 | if (m_pManager) m_pManager->AddOptionGroup(m_sGroupName, this); 123 | } 124 | else { 125 | if (m_pManager) m_pManager->RemoveOptionGroup(m_sGroupName, this); 126 | } 127 | 128 | Selected(m_bSelected); 129 | } 130 | 131 | bool TitleUI::IsSelected() const 132 | { 133 | return m_bSelected; 134 | } 135 | 136 | void TitleUI::Selected(bool bSelected) 137 | { 138 | if(!(m_bSelected^bSelected)) return; 139 | 140 | m_bSelected = bSelected; 141 | if( m_bSelected ) m_uButtonState |= UISTATE_SELECTED; 142 | else m_uButtonState &= ~UISTATE_SELECTED; 143 | 144 | if( m_pManager != NULL ) { 145 | if( !m_sGroupName.IsEmpty() ) { 146 | if( m_bSelected ) { 147 | CStdPtrArray* aOptionGroup = m_pManager->GetOptionGroup(m_sGroupName); 148 | if(aOptionGroup){ 149 | for( int i = 0; i < aOptionGroup->GetSize(); i++ ) { 150 | TitleUI* pControl = static_cast(aOptionGroup->GetAt(i)); 151 | if( pControl != this ) { 152 | pControl->Selected(false); 153 | } 154 | } 155 | } 156 | m_pManager->SendNotify(this, DUI_MSGTYPE_SELECTCHANGED); 157 | } 158 | } 159 | else { 160 | m_pManager->SendNotify(this, DUI_MSGTYPE_SELECTCHANGED); 161 | } 162 | } 163 | 164 | Invalidate(); 165 | } 166 | 167 | bool TitleUI::Activate() 168 | { 169 | if( !CHorizontalLayoutUI::Activate() ) return false; 170 | if( !m_sGroupName.IsEmpty() ) Selected(true); 171 | else Selected(!m_bSelected); 172 | 173 | return true; 174 | } 175 | 176 | void TitleUI::DoEvent(TEventUI& event) 177 | { 178 | if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) { 179 | if( m_pParent != NULL ) m_pParent->DoEvent(event); 180 | else CHorizontalLayoutUI::DoEvent(event); 181 | return; 182 | } 183 | 184 | if( event.Type == UIEVENT_SETFOCUS ) 185 | { 186 | m_bFocused = true; 187 | return; 188 | } 189 | if( event.Type == UIEVENT_KILLFOCUS ) 190 | { 191 | m_bFocused = false; 192 | return; 193 | } 194 | if( event.Type == UIEVENT_BUTTONDOWN || event.Type == UIEVENT_DBLCLICK) 195 | { 196 | if( ::PtInRect(&m_rcItem, event.ptMouse) && IsEnabled() ) { 197 | m_uButtonState |= UISTATE_PUSHED | UISTATE_CAPTURED; 198 | Invalidate(); 199 | } 200 | return; 201 | } 202 | if( event.Type == UIEVENT_MOUSEMOVE ) 203 | { 204 | if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) { 205 | if( ::PtInRect(&m_rcItem, event.ptMouse) ) m_uButtonState |= UISTATE_PUSHED; 206 | else m_uButtonState &= ~UISTATE_PUSHED; 207 | Invalidate(); 208 | } 209 | return; 210 | } 211 | if( event.Type == UIEVENT_BUTTONUP ) 212 | { 213 | if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) { 214 | m_uButtonState &= ~(UISTATE_PUSHED | UISTATE_CAPTURED); 215 | Invalidate(); 216 | if( ::PtInRect(&m_rcItem, event.ptMouse) ) Activate(); 217 | } 218 | return; 219 | } 220 | if( event.Type == UIEVENT_CONTEXTMENU ) 221 | { 222 | if( IsContextMenuUsed() ) { 223 | m_pManager->SendNotify(this, DUI_MSGTYPE_MENU, event.wParam, event.lParam); 224 | } 225 | return; 226 | } 227 | if( event.Type == UIEVENT_MOUSEENTER ) 228 | { 229 | if( IsEnabled() ) { 230 | m_uButtonState |= UISTATE_HOT; 231 | Invalidate(); 232 | } 233 | } 234 | if( event.Type == UIEVENT_MOUSELEAVE ) 235 | { 236 | if( IsEnabled() ) { 237 | m_uButtonState &= ~UISTATE_HOT; 238 | Invalidate(); 239 | } 240 | } 241 | 242 | CHorizontalLayoutUI::DoEvent(event); 243 | } 244 | 245 | void TitleUI::SetVisible(bool bVisible) 246 | { 247 | CHorizontalLayoutUI::SetVisible(bVisible); 248 | if( !IsVisible() && m_bSelected && !m_sGroupName.IsEmpty() ) 249 | { 250 | Selected(false); 251 | } 252 | } 253 | 254 | void TitleUI::SetEnabled(bool bEnable) 255 | { 256 | CControlUI::SetEnabled(bEnable); 257 | if( !IsEnabled() ) { 258 | if( m_bSelected ) m_uButtonState = UISTATE_SELECTED; 259 | else m_uButtonState = 0; 260 | } 261 | } 262 | 263 | void TitleUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) 264 | { 265 | if( _tcsicmp(pstrName, _T("font")) == 0 ) SetFont(_ttoi(pstrValue)); 266 | else if( _tcsicmp(pstrName, _T("textcolor")) == 0 ) { 267 | if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue); 268 | LPTSTR pstr = NULL; 269 | DWORD clrColor = _tcstoul(pstrValue, &pstr, 16); 270 | SetTextColor(clrColor); 271 | } 272 | else if( _tcsicmp(pstrName, _T("textpadding")) == 0 ) { 273 | RECT rcTextPadding = { 0 }; 274 | LPTSTR pstr = NULL; 275 | rcTextPadding.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr); 276 | rcTextPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr); 277 | rcTextPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr); 278 | rcTextPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr); 279 | SetTextPadding(rcTextPadding); 280 | } 281 | else if( _tcsicmp(pstrName, _T("group")) == 0 ){ 282 | SetGroup(pstrValue); 283 | } 284 | else if( _tcsicmp(pstrName, _T("selected")) == 0 ){ 285 | Selected(_tcsicmp(pstrValue, _T("true")) == 0); 286 | } 287 | else if( _tcsicmp(pstrName, _T("selectedbkcolor")) == 0 ) { 288 | if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue); 289 | LPTSTR pstr = NULL; 290 | DWORD clrColor = _tcstoul(pstrValue, &pstr, 16); 291 | SetSelectedBkColor(clrColor); 292 | } 293 | else CHorizontalLayoutUI::SetAttribute(pstrName, pstrValue); 294 | } 295 | 296 | void TitleUI::SetSelectedBkColor( DWORD dwBkColor ) 297 | { 298 | m_dwSelectedBkColor = dwBkColor; 299 | } 300 | 301 | DWORD TitleUI::GetSelectBkColor() 302 | { 303 | return m_dwSelectedBkColor; 304 | } 305 | 306 | void TitleUI::PaintBkColor(HDC hDC) 307 | { 308 | if(IsSelected()) { 309 | if(m_dwSelectedBkColor != 0) { 310 | CRenderEngine::DrawColor(hDC, m_rcPaint, GetAdjustColor(m_dwSelectedBkColor)); 311 | } 312 | } 313 | else { 314 | return CHorizontalLayoutUI::PaintBkColor(hDC); 315 | } 316 | } 317 | 318 | UINT TitleUI::GetTextStyle() const 319 | { 320 | return m_uTextStyle; 321 | } 322 | 323 | void TitleUI::SetTextColor(DWORD dwTextColor) 324 | { 325 | m_dwTextColor = dwTextColor; 326 | Invalidate(); 327 | } 328 | 329 | DWORD TitleUI::GetTextColor() const 330 | { 331 | return m_dwTextColor; 332 | } 333 | 334 | void TitleUI::SetDisabledTextColor(DWORD dwTextColor) 335 | { 336 | m_dwDisabledTextColor = dwTextColor; 337 | Invalidate(); 338 | } 339 | 340 | DWORD TitleUI::GetDisabledTextColor() const 341 | { 342 | return m_dwDisabledTextColor; 343 | } 344 | 345 | void TitleUI::SetFont(int index) 346 | { 347 | m_iFont = index; 348 | Invalidate(); 349 | } 350 | 351 | int TitleUI::GetFont() const 352 | { 353 | return m_iFont; 354 | } 355 | 356 | RECT TitleUI::GetTextPadding() const 357 | { 358 | return m_rcTextPadding; 359 | } 360 | 361 | void TitleUI::SetTextPadding(RECT rc) 362 | { 363 | m_rcTextPadding = rc; 364 | Invalidate(); 365 | } 366 | 367 | void TitleUI::PaintText(HDC hDC) 368 | { 369 | if( m_dwTextColor == 0 ) m_dwTextColor = m_pManager->GetDefaultFontColor(); 370 | if( m_dwDisabledTextColor == 0 ) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor(); 371 | 372 | RECT rc = m_rcItem; 373 | GetManager()->GetDPIObj()->Scale(&m_rcTextPadding); 374 | rc.left += m_rcTextPadding.left; 375 | rc.right -= m_rcTextPadding.right; 376 | rc.top += m_rcTextPadding.top; 377 | rc.bottom -= m_rcTextPadding.bottom; 378 | 379 | CDuiString sText = GetText(); 380 | if( sText.IsEmpty() ) return; 381 | int nLinks = 0; 382 | if( IsEnabled() ) { 383 | CRenderEngine::DrawText(hDC, m_pManager, rc, sText, m_dwTextColor, m_iFont, m_uTextStyle); 384 | } 385 | else { 386 | CRenderEngine::DrawText(hDC, m_pManager, rc, sText, m_dwDisabledTextColor, m_iFont, m_uTextStyle); 387 | } 388 | } 389 | } 390 | -------------------------------------------------------------------------------- /Browser/BrowserUI.h: -------------------------------------------------------------------------------- 1 | #ifndef __BROWSERUI_H__ 2 | #define __BROWSERUI_H__ 3 | #pragma once 4 | #include "ClientHandler.h" 5 | #include 6 | using namespace DuiLib; 7 | 8 | namespace Browser 9 | { 10 | class BrowserDlg; 11 | class BrowserWindow; 12 | 13 | class BrowserUI : public DuiLib::CControlUI 14 | { 15 | DECLARE_DUICONTROL(BrowserUI) 16 | public: 17 | BrowserUI(BrowserDlg* pParent, HWND hParentWnd); 18 | 19 | LPCTSTR GetClass() const; 20 | LPVOID GetInterface(LPCTSTR pstrName); 21 | void SetPos(RECT rc, bool bNeedInvalidate = true); 22 | void SetCtrl(BrowserWindow* pCtrl); 23 | void CreateBrowser(const CefString& url, CefRefPtr request_context); 24 | void ShowBrowser(int nBrowserId=0); 25 | void CloseBrowser(int nBrowserId=0); 26 | 27 | protected: 28 | HWND m_hParentWnd; 29 | BrowserDlg* m_pParent; 30 | BrowserWindow* m_pCtrl; 31 | int m_nCurBrowserId; 32 | 33 | DISALLOW_COPY_AND_ASSIGN(BrowserUI); 34 | }; 35 | 36 | class TitleUI : public CHorizontalLayoutUI 37 | { 38 | DECLARE_DUICONTROL(TitleUI) 39 | public: 40 | TitleUI(); 41 | ~TitleUI(); 42 | 43 | LPCTSTR GetClass() const; 44 | UINT GetControlFlags() const; 45 | LPVOID GetInterface(LPCTSTR pstrName); 46 | 47 | LPCTSTR GetGroup() const; 48 | void SetGroup(LPCTSTR pStrGroupName = NULL); 49 | 50 | bool IsSelected() const; 51 | virtual void Selected(bool bSelected = true); 52 | 53 | bool Activate(); 54 | void DoEvent(TEventUI& event); 55 | void SetVisible(bool bVisible = true); 56 | void SetEnabled(bool bEnable = true); 57 | 58 | void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue); 59 | 60 | void SetSelectedBkColor(DWORD dwBkColor); 61 | DWORD GetSelectBkColor(); 62 | void PaintBkColor(HDC hDC); 63 | 64 | void SetTextStyle(UINT uStyle); 65 | UINT GetTextStyle() const; 66 | void SetTextColor(DWORD dwTextColor); 67 | DWORD GetTextColor() const; 68 | void SetDisabledTextColor(DWORD dwTextColor); 69 | DWORD GetDisabledTextColor() const; 70 | void SetFont(int index); 71 | int GetFont() const; 72 | RECT GetTextPadding() const; 73 | void SetTextPadding(RECT rc); 74 | void PaintText(HDC hDC); 75 | 76 | protected: 77 | bool m_bSelected; 78 | UINT m_uButtonState; 79 | DWORD m_dwSelectedBkColor; 80 | CDuiString m_sGroupName; 81 | 82 | int m_iFont; 83 | UINT m_uTextStyle; 84 | RECT m_rcTextPadding; 85 | DWORD m_dwTextColor; 86 | DWORD m_dwDisabledTextColor; 87 | }; 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /Browser/BrowserWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "MainContext.h" 3 | #include "BrowserWindow.h" 4 | #include "include/base/cef_bind.h" 5 | 6 | namespace Browser 7 | { 8 | BrowserWindow::BrowserWindow(Delegate* delegate, const CefString& startup_url) 9 | : m_Delegate(delegate) 10 | { 11 | DCHECK(m_Delegate); 12 | m_ClientHandler = new ClientHandler(this, startup_url); 13 | } 14 | 15 | void BrowserWindow::CreateBrowser( 16 | CefWindowHandle parent_handle, 17 | const CefString& url, 18 | const CefRect& rect, 19 | const CefBrowserSettings& settings, 20 | CefRefPtr request_context) 21 | { 22 | DCHECK(CefCurrentlyOn(TID_UI)); 23 | 24 | CefWindowInfo window_info; 25 | RECT wnd_rect = {rect.x, rect.y, rect.x + rect.width, rect.y + rect.height}; 26 | window_info.SetAsChild(parent_handle, wnd_rect); 27 | 28 | CefBrowserHost::CreateBrowser(window_info, m_ClientHandler, 29 | url.empty() ? m_ClientHandler->StartupUrl() : url, settings, request_context); 30 | } 31 | 32 | void BrowserWindow::GetPopupConfig(CefWindowHandle temp_handle, 33 | CefWindowInfo& windowInfo, 34 | CefRefPtr& client, 35 | CefBrowserSettings& settings) 36 | { 37 | // Note: This method may be called on any thread. 38 | // The window will be properly sized after the browser is created. 39 | windowInfo.SetAsChild(temp_handle, RECT()); 40 | client = m_ClientHandler; 41 | } 42 | 43 | void BrowserWindow::ShowPopup(int nBrowserId, CefWindowHandle hParentWnd, int x, int y, size_t width, size_t height) 44 | { 45 | DCHECK(CefCurrentlyOn(TID_UI)); 46 | 47 | CefRefPtr pBrowser = m_ClientHandler->GetBrowser(nBrowserId); 48 | if (pBrowser){ 49 | HWND hWnd = pBrowser->GetHost()->GetWindowHandle(); 50 | if (hWnd){ 51 | SetParent(hWnd, hParentWnd); 52 | SetWindowPos(hWnd, NULL, x, y, static_cast(width), static_cast(height), SWP_NOZORDER); 53 | ::ShowWindow(hWnd, SW_SHOW); 54 | pBrowser->GetHost()->SetFocus(true); 55 | } 56 | } 57 | } 58 | 59 | void BrowserWindow::ShowBrowser(int nBrowserId, int x, int y, size_t width, size_t height) 60 | { 61 | DCHECK(CefCurrentlyOn(TID_UI)); 62 | 63 | CefRefPtr pBrowser = m_ClientHandler->GetBrowser(nBrowserId); 64 | std::vector>::iterator item = m_ClientHandler->m_BrowserList.begin(); 65 | for (; item != m_ClientHandler->m_BrowserList.end(); item++) 66 | { 67 | if (*item){ 68 | HWND hWnd = (*item)->GetHost()->GetWindowHandle(); 69 | if ((*item)->IsSame(pBrowser)){ 70 | if (hWnd){ 71 | SetWindowPos(hWnd, NULL, x, y,static_cast(width), static_cast(height),SWP_NOZORDER); 72 | ::ShowWindow(hWnd, SW_SHOW); 73 | (*item)->GetHost()->SetFocus(true); 74 | } 75 | }else{ 76 | if (hWnd){ 77 | ::ShowWindow(hWnd, SW_HIDE); 78 | } 79 | } 80 | } 81 | } 82 | } 83 | 84 | CefWindowHandle BrowserWindow::GetWindowHandle(int nBrowserId) const 85 | { 86 | DCHECK(CefCurrentlyOn(TID_UI)); 87 | 88 | CefRefPtr pBrowser = m_ClientHandler->GetBrowser(nBrowserId); 89 | if (pBrowser) 90 | return pBrowser->GetHost()->GetWindowHandle(); 91 | return NULL; 92 | } 93 | 94 | CefRefPtr BrowserWindow::GetBrowser(int nBrowserId) const 95 | { 96 | DCHECK(CefCurrentlyOn(TID_UI)); 97 | return m_ClientHandler->GetBrowser(nBrowserId);; 98 | } 99 | 100 | void BrowserWindow::OnBrowserCreated(CefRefPtr browser) 101 | { 102 | DCHECK(CefCurrentlyOn(TID_UI)); 103 | 104 | m_Delegate->OnBrowserCreated(browser); 105 | } 106 | 107 | void BrowserWindow::OnBrowserClosing(CefRefPtr browser) 108 | { 109 | DCHECK(CefCurrentlyOn(TID_UI)); 110 | } 111 | 112 | void BrowserWindow::OnBrowserClosed(CefRefPtr browser) 113 | { 114 | DCHECK(CefCurrentlyOn(TID_UI)); 115 | } 116 | 117 | void BrowserWindow::OnBrowserAllClosed() 118 | { 119 | DCHECK(CefCurrentlyOn(TID_UI)); 120 | 121 | m_ClientHandler->DetachDelegate(); 122 | m_ClientHandler = NULL; 123 | 124 | // |this| may be deleted. 125 | m_Delegate->OnBrowserAllClosed(); 126 | } 127 | 128 | void BrowserWindow::OnSetAddress(CefRefPtr browser, const CefString& url) 129 | { 130 | DCHECK(CefCurrentlyOn(TID_UI)); 131 | m_Delegate->OnSetAddress(browser, url); 132 | } 133 | 134 | void BrowserWindow::OnSetTitle(CefRefPtr browser, const CefString& title) 135 | { 136 | DCHECK(CefCurrentlyOn(TID_UI)); 137 | m_Delegate->OnSetTitle(browser, title); 138 | } 139 | 140 | void BrowserWindow::OnSetFullscreen(CefRefPtr browser, bool fullscreen) 141 | { 142 | DCHECK(CefCurrentlyOn(TID_UI)); 143 | m_Delegate->OnSetFullscreen(browser, fullscreen); 144 | } 145 | 146 | void BrowserWindow::OnSetLoadingState(CefRefPtr browser, bool isLoading,bool canGoBack,bool canGoForward) 147 | { 148 | DCHECK(CefCurrentlyOn(TID_UI)); 149 | m_Delegate->OnSetLoadingState(browser, isLoading, canGoBack, canGoForward); 150 | } 151 | 152 | void BrowserWindow::OnSetDraggableRegions(CefRefPtr browser, const std::vector& regions) 153 | { 154 | DCHECK(CefCurrentlyOn(TID_UI)); 155 | m_Delegate->OnSetDraggableRegions(browser, regions); 156 | } 157 | 158 | void BrowserWindow::OnNewTab(CefRefPtr browser, const CefString& url) 159 | { 160 | m_Delegate->OnNewTab(browser, url); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /Browser/BrowserWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef __BROWSER_WINDOW_H__ 2 | #define __BROWSER_WINDOW_H__ 3 | #pragma once 4 | #include "include/base/cef_scoped_ptr.h" 5 | #include "include/cef_browser.h" 6 | #include "ClientHandler.h" 7 | #include "MessageLoop.h" 8 | 9 | namespace Browser 10 | { 11 | class BrowserWindow : public ClientHandler::Delegate 12 | { 13 | public: 14 | class Delegate { 15 | public: 16 | virtual void OnBrowserCreated(CefRefPtr browser) = 0; 17 | virtual void OnBrowserClosed(CefRefPtr browser) = 0; 18 | virtual void OnBrowserAllClosed() = 0; 19 | virtual void OnSetAddress(CefRefPtr browser, const CefString& url) = 0; 20 | virtual void OnSetTitle(CefRefPtr browser, const CefString& title) = 0; 21 | virtual void OnSetFullscreen(CefRefPtr browser, bool fullscreen) = 0; 22 | virtual void OnSetLoadingState(CefRefPtr browser, bool isLoading,bool canGoBack,bool canGoForward) = 0; 23 | virtual void OnSetDraggableRegions(CefRefPtr browser, const std::vector& regions) = 0; 24 | virtual void OnNewTab(CefRefPtr browser, const CefString& url) = 0; 25 | 26 | protected: 27 | virtual ~Delegate() {} 28 | }; 29 | 30 | // Constructor may be called on any thread. 31 | // |delegate| must outlive this object. 32 | explicit BrowserWindow(Delegate* delegate, const CefString& startup_url); 33 | 34 | 35 | // Create a new browser and native window. 36 | virtual void CreateBrowser( 37 | CefWindowHandle parent_handle, 38 | const CefString& url, 39 | const CefRect& rect, 40 | const CefBrowserSettings& settings, 41 | CefRefPtr request_context); 42 | 43 | // Retrieve the configuration that will be used when creating a popup window. 44 | // The popup browser will initially be parented to |temp_handle| which should 45 | // be a pre-existing hidden window. The native window will be created later 46 | // after the browser has been created. This method may be called on any 47 | // thread. 48 | virtual void GetPopupConfig( 49 | CefWindowHandle temp_handle, 50 | CefWindowInfo& windowInfo, 51 | CefRefPtr& client, 52 | CefBrowserSettings& settings); 53 | 54 | // Show the popup window with correct parent and bounds in parent coordinates. 55 | virtual void ShowPopup(int nBrowserId, CefWindowHandle hParentWnd, int x, int y, size_t width, size_t height); 56 | 57 | // Show the window. 58 | virtual void ShowBrowser(int nBrowserId, int x, int y, size_t width, size_t height); 59 | 60 | // Returns the window handle. 61 | virtual CefWindowHandle GetWindowHandle(int nBrowserId) const; 62 | 63 | // Returns the browser owned by the window. 64 | CefRefPtr GetBrowser(int nBrowserId) const; 65 | 66 | protected: 67 | // Allow deletion via scoped_ptr only. 68 | friend struct base::DefaultDeleter; 69 | 70 | // ClientHandler::Delegate methods. 71 | void OnBrowserCreated(CefRefPtr browser) OVERRIDE; 72 | void OnBrowserClosing(CefRefPtr browser) OVERRIDE; 73 | void OnBrowserClosed(CefRefPtr browser) OVERRIDE; 74 | void OnBrowserAllClosed() OVERRIDE; 75 | void OnSetAddress(CefRefPtr browser, const CefString& url) OVERRIDE; 76 | void OnSetTitle(CefRefPtr browser, const CefString& title) OVERRIDE; 77 | void OnSetFullscreen(CefRefPtr browser, bool fullscreen) OVERRIDE; 78 | void OnSetLoadingState(CefRefPtr browser, bool isLoading,bool canGoBack,bool canGoForward) OVERRIDE; 79 | void OnSetDraggableRegions(CefRefPtr browser, const std::vector& regions) OVERRIDE; 80 | void OnNewTab(CefRefPtr browser, const CefString& url) OVERRIDE; 81 | 82 | Delegate* m_Delegate; 83 | CefRefPtr m_ClientHandler; 84 | 85 | private: 86 | DISALLOW_COPY_AND_ASSIGN(BrowserWindow); 87 | }; 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /Browser/ClientApp.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLIENT_APP_H__ 2 | #define __CLIENT_APP_H__ 3 | #pragma once 4 | #include 5 | #include "include/cef_version.h" 6 | #include "include/cef_app.h" 7 | 8 | namespace Browser 9 | { 10 | class ClientApp : public CefApp 11 | { 12 | public: 13 | ClientApp(){}; 14 | 15 | #if CHROME_VERSION_BUILD >= 2924 16 | class Delegate : public virtual CefBaseRefCounted 17 | #else 18 | class Delegate : public virtual CefBase 19 | #endif 20 | {}; 21 | 22 | static bool IsBrowser(CefRefPtr command_line){ 23 | return !command_line->HasSwitch("type"); 24 | } 25 | 26 | static bool IsRenderer(CefRefPtr command_line) { 27 | const std::string& process_type = command_line->GetSwitchValue("type"); 28 | return process_type == "renderer"; 29 | } 30 | 31 | protected: 32 | std::vector cookie_schemes; 33 | 34 | private: 35 | DISALLOW_COPY_AND_ASSIGN(ClientApp); 36 | }; 37 | 38 | class ClientAppOther : public ClientApp { 39 | public: 40 | ClientAppOther(){} 41 | 42 | private: 43 | IMPLEMENT_REFCOUNTING(ClientAppOther); 44 | DISALLOW_COPY_AND_ASSIGN(ClientAppOther); 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Browser/ClientAppBrowser.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanwer/Browser/619c40dc6cab859703352f0e1a5b40b12f826ae3/Browser/ClientAppBrowser.cpp -------------------------------------------------------------------------------- /Browser/ClientAppBrowser.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLIENT_APP_BROWSER_H__ 2 | #define __CLIENT_APP_BROWSER_H__ 3 | #pragma once 4 | #include 5 | #include "ClientApp.h" 6 | 7 | namespace Browser 8 | { 9 | class ClientAppBrowser : public ClientApp , public CefBrowserProcessHandler 10 | { 11 | public: 12 | class Delegate : public ClientApp::Delegate 13 | { 14 | public: 15 | virtual void OnBeforeCommandLineProcessing( 16 | CefRefPtr app, 17 | CefRefPtr command_line) {} 18 | 19 | virtual void OnContextInitialized(CefRefPtr app) {} 20 | 21 | virtual void OnBeforeChildProcessLaunch( 22 | CefRefPtr app, 23 | CefRefPtr command_line) {} 24 | 25 | virtual void OnRenderProcessThreadCreated( 26 | CefRefPtr app, 27 | CefRefPtr extra_info) {} 28 | }; 29 | typedef std::set > DelegateSet; 30 | 31 | ClientAppBrowser(); 32 | 33 | private: 34 | // Creates all of the Delegate objects. 35 | static void CreateDelegates(DelegateSet& delegates); 36 | // CefApp methods. 37 | void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr command_line) OVERRIDE; 38 | void OnRegisterCustomSchemes( 39 | #if CHROME_VERSION_BUILD >= 2924 40 | CefRawPtr registrar 41 | #else 42 | CefRefPtr registrar 43 | #endif 44 | ) OVERRIDE; 45 | CefRefPtr GetBrowserProcessHandler() OVERRIDE{return this;} 46 | 47 | // CefBrowserProcessHandler methods. 48 | void OnContextInitialized() OVERRIDE; 49 | void OnBeforeChildProcessLaunch(CefRefPtr command_line) OVERRIDE; 50 | void OnRenderProcessThreadCreated(CefRefPtr extra_info) OVERRIDE; 51 | 52 | private: 53 | DelegateSet m_delegates; 54 | 55 | IMPLEMENT_REFCOUNTING(ClientAppBrowser); 56 | DISALLOW_COPY_AND_ASSIGN(ClientAppBrowser); 57 | }; 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /Browser/ClientAppRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ClientAppRenderer.h" 3 | #include "include/base/cef_logging.h" 4 | #include "PerfTest.h" 5 | 6 | namespace Browser 7 | { 8 | ClientAppRenderer::ClientAppRenderer() { 9 | CreateDelegates(m_delegates); 10 | } 11 | 12 | ////////////////////////////////////////////////////////////////////////////////////////// 13 | // CefRenderProcessHandler methods. 14 | void ClientAppRenderer::OnRenderThreadCreated(CefRefPtr extra_info) 15 | { 16 | DelegateSet::iterator it = m_delegates.begin(); 17 | for (; it != m_delegates.end(); ++it) 18 | (*it)->OnRenderThreadCreated(this, extra_info); 19 | } 20 | 21 | void ClientAppRenderer::OnWebKitInitialized() 22 | { 23 | DelegateSet::iterator it = m_delegates.begin(); 24 | for (; it != m_delegates.end(); ++it) 25 | (*it)->OnWebKitInitialized(this); 26 | } 27 | 28 | void ClientAppRenderer::OnBrowserCreated(CefRefPtr browser) 29 | { 30 | DelegateSet::iterator it = m_delegates.begin(); 31 | for (; it != m_delegates.end(); ++it) 32 | (*it)->OnBrowserCreated(this, browser); 33 | } 34 | 35 | void ClientAppRenderer::OnBrowserDestroyed(CefRefPtr browser) 36 | { 37 | DelegateSet::iterator it = m_delegates.begin(); 38 | for (; it != m_delegates.end(); ++it) 39 | (*it)->OnBrowserDestroyed(this, browser); 40 | } 41 | 42 | CefRefPtr ClientAppRenderer::GetLoadHandler() 43 | { 44 | CefRefPtr load_handler; 45 | DelegateSet::iterator it = m_delegates.begin(); 46 | for (; it != m_delegates.end() && !load_handler.get(); ++it) 47 | load_handler = (*it)->GetLoadHandler(this); 48 | 49 | return load_handler; 50 | } 51 | 52 | void ClientAppRenderer::OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) 53 | { 54 | DelegateSet::iterator it = m_delegates.begin(); 55 | for (; it != m_delegates.end(); ++it) 56 | (*it)->OnContextCreated(this, browser, frame, context); 57 | } 58 | 59 | void ClientAppRenderer::OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) 60 | { 61 | DelegateSet::iterator it = m_delegates.begin(); 62 | for (; it != m_delegates.end(); ++it) 63 | (*it)->OnContextReleased(this, browser, frame, context); 64 | } 65 | 66 | void ClientAppRenderer::OnUncaughtException 67 | (CefRefPtr browser, 68 | CefRefPtr frame, 69 | CefRefPtr context, 70 | CefRefPtr exception, 71 | CefRefPtr stackTrace) 72 | { 73 | DelegateSet::iterator it = m_delegates.begin(); 74 | for (; it != m_delegates.end(); ++it) { 75 | (*it)->OnUncaughtException(this, browser, frame, context, exception,stackTrace); 76 | } 77 | } 78 | 79 | void ClientAppRenderer::OnFocusedNodeChanged( 80 | CefRefPtr browser, 81 | CefRefPtr frame, 82 | CefRefPtr node) 83 | { 84 | DelegateSet::iterator it = m_delegates.begin(); 85 | for (; it != m_delegates.end(); ++it) 86 | (*it)->OnFocusedNodeChanged(this, browser, frame, node); 87 | } 88 | 89 | bool ClientAppRenderer::OnProcessMessageReceived( 90 | CefRefPtr browser, 91 | CefProcessId source_process, 92 | CefRefPtr message) 93 | { 94 | DCHECK_EQ(source_process, PID_BROWSER); 95 | 96 | bool handled = false; 97 | 98 | DelegateSet::iterator it = m_delegates.begin(); 99 | for (; it != m_delegates.end() && !handled; ++it) { 100 | handled = (*it)->OnProcessMessageReceived(this, browser, source_process,message); 101 | } 102 | 103 | return handled; 104 | } 105 | 106 | // static 107 | void ClientAppRenderer::CreateDelegates(DelegateSet& delegates) { 108 | Renderer::CreateDelegates(delegates); 109 | PerfTest::CreateDelegates(delegates); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /Browser/ClientAppRenderer.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLIENT_APP_RENDERER_H__ 2 | #define __CLIENT_APP_RENDERER_H__ 3 | #pragma once 4 | #include 5 | #include "ClientApp.h" 6 | 7 | namespace Browser 8 | { 9 | class ClientAppRenderer : public ClientApp , public CefRenderProcessHandler 10 | { 11 | public: 12 | class Delegate : public ClientApp::Delegate 13 | { 14 | public: 15 | virtual void OnRenderThreadCreated(CefRefPtr app, 16 | CefRefPtr extra_info) {} 17 | 18 | virtual void OnWebKitInitialized(CefRefPtr app) {} 19 | 20 | virtual void OnBrowserCreated(CefRefPtr app, 21 | CefRefPtr browser) {} 22 | 23 | virtual void OnBrowserDestroyed(CefRefPtr app, 24 | CefRefPtr browser) {} 25 | 26 | virtual CefRefPtr GetLoadHandler( 27 | CefRefPtr app) { 28 | return NULL; 29 | } 30 | 31 | virtual void OnContextCreated(CefRefPtr app, 32 | CefRefPtr browser, 33 | CefRefPtr frame, 34 | CefRefPtr context) {} 35 | 36 | virtual void OnContextReleased(CefRefPtr app, 37 | CefRefPtr browser, 38 | CefRefPtr frame, 39 | CefRefPtr context) {} 40 | 41 | virtual void OnUncaughtException(CefRefPtr app, 42 | CefRefPtr browser, 43 | CefRefPtr frame, 44 | CefRefPtr context, 45 | CefRefPtr exception, 46 | CefRefPtr stackTrace) {} 47 | 48 | virtual void OnFocusedNodeChanged(CefRefPtr app, 49 | CefRefPtr browser, 50 | CefRefPtr frame, 51 | CefRefPtr node) {} 52 | 53 | virtual bool OnProcessMessageReceived( 54 | CefRefPtr app, 55 | CefRefPtr browser, 56 | CefProcessId source_process, 57 | CefRefPtr message) { 58 | return false; 59 | } 60 | }; 61 | typedef std::set > DelegateSet; 62 | 63 | ClientAppRenderer(); 64 | 65 | private: 66 | // Creates all of the Delegate objects. 67 | static void CreateDelegates(DelegateSet& delegates); 68 | 69 | // CefApp methods. 70 | CefRefPtr GetRenderProcessHandler() OVERRIDE{return this;} 71 | 72 | // CefRenderProcessHandler methods. 73 | void OnRenderThreadCreated(CefRefPtr extra_info) OVERRIDE; 74 | void OnWebKitInitialized() OVERRIDE; 75 | void OnBrowserCreated(CefRefPtr browser) OVERRIDE; 76 | void OnBrowserDestroyed(CefRefPtr browser) OVERRIDE; 77 | CefRefPtr GetLoadHandler() OVERRIDE; 78 | void OnContextCreated(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; 79 | void OnContextReleased(CefRefPtr browser, CefRefPtr frame, CefRefPtr context) OVERRIDE; 80 | void OnUncaughtException( 81 | CefRefPtr browser, 82 | CefRefPtr frame, 83 | CefRefPtr context, 84 | CefRefPtr exception, 85 | CefRefPtr stackTrace) OVERRIDE; 86 | void OnFocusedNodeChanged( 87 | CefRefPtr browser, 88 | CefRefPtr frame, 89 | CefRefPtr node) OVERRIDE; 90 | bool OnProcessMessageReceived( 91 | CefRefPtr browser, 92 | CefProcessId source_process, 93 | CefRefPtr message) OVERRIDE; 94 | 95 | private: 96 | DelegateSet m_delegates; 97 | 98 | IMPLEMENT_REFCOUNTING(ClientAppRenderer); 99 | DISALLOW_COPY_AND_ASSIGN(ClientAppRenderer); 100 | }; 101 | 102 | namespace Renderer 103 | { 104 | void CreateDelegates(ClientAppRenderer::DelegateSet& delegates); 105 | } 106 | } 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /Browser/ClientHandler.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanwer/Browser/619c40dc6cab859703352f0e1a5b40b12f826ae3/Browser/ClientHandler.cpp -------------------------------------------------------------------------------- /Browser/ClientHandler.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanwer/Browser/619c40dc6cab859703352f0e1a5b40b12f826ae3/Browser/ClientHandler.h -------------------------------------------------------------------------------- /Browser/ClientRenderDelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ClientRenderDelegate.h" 3 | #include 4 | #include 5 | #include "include/cef_dom.h" 6 | #include "include/wrapper/cef_helpers.h" 7 | #include "include/wrapper/cef_message_router.h" 8 | 9 | namespace Browser 10 | { 11 | namespace Renderer 12 | { 13 | class ClientRenderDelegate : public ClientAppRenderer::Delegate { 14 | public: 15 | ClientRenderDelegate() { 16 | } 17 | 18 | virtual void OnWebKitInitialized(CefRefPtr app) OVERRIDE { 19 | // Create the renderer-side router for query handling. 20 | CefMessageRouterConfig config; 21 | m_MessageRouter = CefMessageRouterRendererSide::Create(config); 22 | } 23 | 24 | virtual void OnContextCreated(CefRefPtr app, 25 | CefRefPtr browser, 26 | CefRefPtr frame, 27 | CefRefPtr context) OVERRIDE { 28 | m_MessageRouter->OnContextCreated(browser, frame, context); 29 | } 30 | 31 | virtual void OnContextReleased(CefRefPtr app, 32 | CefRefPtr browser, 33 | CefRefPtr frame, 34 | CefRefPtr context) OVERRIDE { 35 | m_MessageRouter->OnContextReleased(browser, frame, context); 36 | } 37 | 38 | virtual void OnFocusedNodeChanged(CefRefPtr app, 39 | CefRefPtr browser, 40 | CefRefPtr frame, 41 | CefRefPtr node) OVERRIDE { 42 | } 43 | 44 | virtual bool OnProcessMessageReceived( 45 | CefRefPtr app, 46 | CefRefPtr browser, 47 | CefProcessId source_process, 48 | CefRefPtr message) OVERRIDE { 49 | return m_MessageRouter->OnProcessMessageReceived( 50 | browser, source_process, message); 51 | } 52 | 53 | private: 54 | // Handles the renderer side of query routing. 55 | CefRefPtr m_MessageRouter; 56 | 57 | IMPLEMENT_REFCOUNTING(ClientRenderDelegate); 58 | }; 59 | 60 | void CreateDelegates(ClientAppRenderer::DelegateSet& delegates) { 61 | delegates.insert(new ClientRenderDelegate); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Browser/ClientRenderDelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLIENT_RENDER_DELEGATE_H__ 2 | #define __CLIENT_RENDER_DELEGATE_H__ 3 | #pragma once 4 | #include "include/cef_base.h" 5 | #include "ClientAppRenderer.h" 6 | 7 | namespace Browser 8 | { 9 | namespace Renderer 10 | { 11 | void CreateDelegates(ClientAppRenderer::DelegateSet& delegates); 12 | } 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /Browser/ClientRunner.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "include/base/cef_bind.h" 5 | #include "include/cef_parser.h" 6 | #include "include/cef_task.h" 7 | #include "include/cef_trace.h" 8 | #include "include/cef_web_plugin.h" 9 | #include "include/wrapper/cef_stream_resource_handler.h" 10 | #include "ClientApp.h" 11 | #include "ResourceUtil.h" 12 | #include "ClientRunner.h" 13 | 14 | namespace Browser 15 | { 16 | namespace ClientRunner 17 | { 18 | const char kTestOrigin[] = "http://tests/"; 19 | 20 | // Replace all instances of |from| with |to| in |str|. 21 | std::string StringReplace(const std::string& str, const std::string& from, const std::string& to) 22 | { 23 | std::string result = str; 24 | std::string::size_type pos = 0; 25 | std::string::size_type from_len = from.length(); 26 | std::string::size_type to_len = to.length(); 27 | do { 28 | pos = result.find(from, pos); 29 | if (pos != std::string::npos) { 30 | result.replace(pos, from_len, to); 31 | pos += to_len; 32 | } 33 | } while (pos != std::string::npos); 34 | return result; 35 | } 36 | 37 | // Add a file extension to |url| if none is currently specified. 38 | std::string RequestUrlFilter(const std::string& url) { 39 | if (url.find(kTestOrigin) != 0U) { 40 | // Don't filter anything outside of the test origin. 41 | return url; 42 | } 43 | 44 | // Identify where the query or fragment component, if any, begins. 45 | size_t suffix_pos = url.find('?'); 46 | if (suffix_pos == std::string::npos) 47 | suffix_pos = url.find('#'); 48 | 49 | std::string url_base, url_suffix; 50 | if (suffix_pos == std::string::npos) { 51 | url_base = url; 52 | } else { 53 | url_base = url.substr(0, suffix_pos); 54 | url_suffix = url.substr(suffix_pos); 55 | } 56 | 57 | // Identify the last path component. 58 | size_t path_pos = url_base.rfind('/'); 59 | if (path_pos == std::string::npos) 60 | return url; 61 | 62 | const std::string& path_component = url_base.substr(path_pos); 63 | 64 | // Identify if a file extension is currently specified. 65 | size_t ext_pos = path_component.rfind("."); 66 | if (ext_pos != std::string::npos) 67 | return url; 68 | 69 | // Rebuild the URL with a file extension. 70 | return url_base + ".html" + url_suffix; 71 | } 72 | 73 | std::string GetDataURI(const std::string& data, const std::string& mime_type) 74 | { 75 | return "data:" + mime_type + ";base64," + 76 | CefURIEncode(CefBase64Encode(data.data(), data.size()), false).ToString(); 77 | } 78 | 79 | std::string GetErrorString(cef_errorcode_t code) 80 | { 81 | // Case condition that returns |code| as a string. 82 | #define CASE(code) case code: return #code 83 | 84 | switch (code) { 85 | CASE(ERR_NONE); 86 | CASE(ERR_FAILED); 87 | CASE(ERR_ABORTED); 88 | CASE(ERR_INVALID_ARGUMENT); 89 | CASE(ERR_INVALID_HANDLE); 90 | CASE(ERR_FILE_NOT_FOUND); 91 | CASE(ERR_TIMED_OUT); 92 | CASE(ERR_FILE_TOO_BIG); 93 | CASE(ERR_UNEXPECTED); 94 | CASE(ERR_ACCESS_DENIED); 95 | CASE(ERR_NOT_IMPLEMENTED); 96 | CASE(ERR_CONNECTION_CLOSED); 97 | CASE(ERR_CONNECTION_RESET); 98 | CASE(ERR_CONNECTION_REFUSED); 99 | CASE(ERR_CONNECTION_ABORTED); 100 | CASE(ERR_CONNECTION_FAILED); 101 | CASE(ERR_NAME_NOT_RESOLVED); 102 | CASE(ERR_INTERNET_DISCONNECTED); 103 | CASE(ERR_SSL_PROTOCOL_ERROR); 104 | CASE(ERR_ADDRESS_INVALID); 105 | CASE(ERR_ADDRESS_UNREACHABLE); 106 | CASE(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); 107 | CASE(ERR_TUNNEL_CONNECTION_FAILED); 108 | CASE(ERR_NO_SSL_VERSIONS_ENABLED); 109 | CASE(ERR_SSL_VERSION_OR_CIPHER_MISMATCH); 110 | CASE(ERR_SSL_RENEGOTIATION_REQUESTED); 111 | CASE(ERR_CERT_COMMON_NAME_INVALID); 112 | CASE(ERR_CERT_DATE_INVALID); 113 | CASE(ERR_CERT_AUTHORITY_INVALID); 114 | CASE(ERR_CERT_CONTAINS_ERRORS); 115 | CASE(ERR_CERT_NO_REVOCATION_MECHANISM); 116 | CASE(ERR_CERT_UNABLE_TO_CHECK_REVOCATION); 117 | CASE(ERR_CERT_REVOKED); 118 | CASE(ERR_CERT_INVALID); 119 | CASE(ERR_CERT_END); 120 | CASE(ERR_INVALID_URL); 121 | CASE(ERR_DISALLOWED_URL_SCHEME); 122 | CASE(ERR_UNKNOWN_URL_SCHEME); 123 | CASE(ERR_TOO_MANY_REDIRECTS); 124 | CASE(ERR_UNSAFE_REDIRECT); 125 | CASE(ERR_UNSAFE_PORT); 126 | CASE(ERR_INVALID_RESPONSE); 127 | CASE(ERR_INVALID_CHUNKED_ENCODING); 128 | CASE(ERR_METHOD_NOT_SUPPORTED); 129 | CASE(ERR_UNEXPECTED_PROXY_AUTH); 130 | CASE(ERR_EMPTY_RESPONSE); 131 | CASE(ERR_RESPONSE_HEADERS_TOO_BIG); 132 | CASE(ERR_CACHE_MISS); 133 | CASE(ERR_INSECURE_RESPONSE); 134 | default: 135 | return "UNKNOWN"; 136 | } 137 | } 138 | 139 | void SetupResourceManager(CefRefPtr resource_manager) { 140 | if (!CefCurrentlyOn(TID_IO)) { 141 | // Execute on the browser IO thread. 142 | CefPostTask(TID_IO, base::Bind(SetupResourceManager, resource_manager)); 143 | return; 144 | } 145 | 146 | const std::string& test_origin = kTestOrigin; 147 | 148 | // Add the URL filter. 149 | resource_manager->SetUrlFilter(base::Bind(RequestUrlFilter)); 150 | 151 | // Add provider for bundled resource files. 152 | // Read resources from the binary. 153 | resource_manager->AddProvider(CreateBinaryResourceProvider(test_origin), 100, std::string()); 154 | } 155 | 156 | void Alert(CefRefPtr browser, const std::string& message) 157 | { 158 | // Escape special characters in the message. 159 | std::string msg = StringReplace(message, "\\", "\\\\"); 160 | msg = StringReplace(msg, "'", "\\'"); 161 | 162 | // Execute a JavaScript alert(). 163 | CefRefPtr frame = browser->GetMainFrame(); 164 | frame->ExecuteJavaScript("alert('" + msg + "');", frame->GetURL(), 0); 165 | } 166 | 167 | namespace Binding 168 | { 169 | const char kTestUrl[] = "http://tests/binding"; 170 | const char kTestMessageName[] = "BindingTest"; 171 | 172 | // Handle messages in the browser process. 173 | class BindingHandler : public CefMessageRouterBrowserSide::Handler { 174 | public: 175 | BindingHandler() {} 176 | 177 | // Called due to cefQuery execution in binding.html. 178 | virtual bool OnQuery(CefRefPtr browser, 179 | CefRefPtr frame, 180 | int64 query_id, 181 | const CefString& request, 182 | bool persistent, 183 | CefRefPtr callback) OVERRIDE 184 | { 185 | // Only handle messages from the test URL. 186 | const std::string& url = frame->GetURL(); 187 | if (url.find(kTestUrl) != 0) 188 | return false; 189 | 190 | const std::string& message_name = request; 191 | if (message_name.find(kTestMessageName) == 0) { 192 | // Reverse the string and return. 193 | std::string result = message_name.substr(sizeof(kTestMessageName)); 194 | std::reverse(result.begin(), result.end()); 195 | callback->Success(result); 196 | return true; 197 | } 198 | 199 | return false; 200 | } 201 | }; 202 | 203 | void CreateMessageHandlers(MessageHandlerSet& handlers) 204 | { 205 | handlers.insert(new BindingHandler()); 206 | } 207 | } 208 | 209 | void CreateMessageHandlers(MessageHandlerSet& handlers) 210 | { 211 | // Create the binding test handlers. 212 | Binding::CreateMessageHandlers(handlers); 213 | } 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /Browser/ClientRunner.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLIENTRUNNER_H__ 2 | #define __CLIENTRUNNER_H__ 3 | #pragma once 4 | #include 5 | #include 6 | #include "include/cef_browser.h" 7 | #include "include/cef_request.h" 8 | #include "include/wrapper/cef_message_router.h" 9 | #include "include/wrapper/cef_resource_manager.h" 10 | 11 | namespace Browser 12 | { 13 | namespace ClientRunner 14 | { 15 | // Returns a data: URI with the specified contents. 16 | std::string GetDataURI(const std::string& data, 17 | const std::string& mime_type); 18 | 19 | // Returns the string representation of the specified error code. 20 | std::string GetErrorString(cef_errorcode_t code); 21 | 22 | // Set up the resource manager for tests. 23 | void SetupResourceManager(CefRefPtr resource_manager); 24 | 25 | // Show a JS alert message. 26 | void Alert(CefRefPtr browser, const std::string& message); 27 | 28 | // Create all CefMessageRouterBrowserSide::Handler objects. They will be 29 | // deleted when the ClientHandler is destroyed. 30 | typedef std::set MessageHandlerSet; 31 | void CreateMessageHandlers(MessageHandlerSet& handlers); 32 | } 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Browser/ClientSwitches.cpp: -------------------------------------------------------------------------------- 1 | #include "ClientSwitches.h" 2 | 3 | namespace Browser { 4 | namespace Switches { 5 | // CEF and Chromium support a wide range of command-line switches. This file 6 | // only contains command-line switches specific to the cefclient application. 7 | // View CEF/Chromium documentation or search for *_switches.cc files in the 8 | // Chromium source code to identify other existing command-line switches. 9 | // Below is a partial listing of relevant *_switches.cc files: 10 | // base/base_switches.cc 11 | // cef/libcef/common/cef_switches.cc 12 | // chrome/common/chrome_switches.cc (not all apply) 13 | // content/public/common/content_switches.cc 14 | 15 | const char kMultiThreadedMessageLoop[] = "multi-threaded-message-loop"; 16 | const char kCachePath[] = "cache-path"; 17 | const char kUrl[] = "url"; 18 | const char kOffScreenRenderingEnabled[] = "off-screen-rendering-enabled"; 19 | const char kOffScreenFrameRate[] = "off-screen-frame-rate"; 20 | const char kTransparentPaintingEnabled[] = "transparent-painting-enabled"; 21 | const char kShowUpdateRect[] = "show-update-rect"; 22 | const char kMouseCursorChangeDisabled[] = "mouse-cursor-change-disabled"; 23 | const char kRequestContextPerBrowser[] = "request-context-per-browser"; 24 | const char kRequestContextSharedCache[] = "request-context-shared-cache"; 25 | const char kBackgroundColor[] = "background-color"; 26 | const char kEnableGPU[] = "enable-gpu"; 27 | const char kFilterURL[] = "filter-url"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Browser/ClientSwitches.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLIENT_SWITCHES_H__ 2 | #define __CLIENT_SWITCHES_H__ 3 | #pragma once 4 | 5 | namespace Browser { 6 | namespace Switches { 7 | extern const char kMultiThreadedMessageLoop[]; 8 | extern const char kCachePath[]; 9 | extern const char kUrl[]; 10 | extern const char kOffScreenRenderingEnabled[]; 11 | extern const char kOffScreenFrameRate[]; 12 | extern const char kTransparentPaintingEnabled[]; 13 | extern const char kShowUpdateRect[]; 14 | extern const char kMouseCursorChangeDisabled[]; 15 | extern const char kRequestContextPerBrowser[]; 16 | extern const char kRequestContextSharedCache[]; 17 | extern const char kBackgroundColor[]; 18 | extern const char kEnableGPU[]; 19 | extern const char kFilterURL[]; 20 | } 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /Browser/Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sanwer/Browser/619c40dc6cab859703352f0e1a5b40b12f826ae3/Browser/Logo.png -------------------------------------------------------------------------------- /Browser/MainContext.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "MainContext.h" 3 | #include "include/base/cef_logging.h" 4 | #include "include/cef_parser.h" 5 | #include "ClientSwitches.h" 6 | #include 7 | #include 8 | 9 | namespace Browser 10 | { 11 | namespace { 12 | MainContext* g_main_context = NULL; 13 | 14 | // Returns the ARGB value for |color|. 15 | cef_color_t ParseColor(const std::string& color) { 16 | std::string colorToLower; 17 | colorToLower.resize(color.size()); 18 | std::transform(color.begin(), color.end(), colorToLower.begin(), ::tolower); 19 | 20 | if (colorToLower == "black") 21 | return CefColorSetARGB(255, 0, 0, 0); 22 | else if (colorToLower == "blue") 23 | return CefColorSetARGB(255, 0, 0, 255); 24 | else if (colorToLower == "green") 25 | return CefColorSetARGB(255, 0, 255, 0); 26 | else if (colorToLower == "red") 27 | return CefColorSetARGB(255, 255, 0, 0); 28 | else if (colorToLower == "white") 29 | return CefColorSetARGB(255, 255, 255, 255); 30 | 31 | // Use the default color. 32 | return 0; 33 | } 34 | } 35 | 36 | // static 37 | MainContext* MainContext::Get() { 38 | DCHECK(g_main_context); 39 | return g_main_context; 40 | } 41 | MainContext::MainContext(CefRefPtr command_line, bool terminate_when_all_windows_closed) 42 | : m_CommandLine(command_line), 43 | m_bTerminateWhenAllWindowsClosed(terminate_when_all_windows_closed), 44 | m_bInitialized(false), 45 | m_bShutdown(false), 46 | m_BackgroundColor(CefColorSetARGB(255, 255, 255, 255)) 47 | { 48 | DCHECK(!g_main_context); 49 | g_main_context = this; 50 | DCHECK(m_CommandLine.get()); 51 | 52 | if (m_CommandLine->HasSwitch(Switches::kBackgroundColor)) { 53 | // Parse the background color value. 54 | m_BackgroundColor = ParseColor(m_CommandLine->GetSwitchValue(Switches::kBackgroundColor)); 55 | } 56 | } 57 | 58 | MainContext::~MainContext() { 59 | g_main_context = NULL; 60 | // The context must either not have been initialized, or it must have also 61 | // been shut down. 62 | DCHECK(!m_bInitialized || m_bShutdown); 63 | } 64 | 65 | std::string MainContext::GetConsoleLogPath() { 66 | return GetAppWorkingDirectory() + "console.log"; 67 | } 68 | 69 | std::string MainContext::GetDownloadPath(const std::string& file_name) { 70 | TCHAR szFolderPath[MAX_PATH]; 71 | std::string path; 72 | 73 | // Save the file in the user's "My Documents" folder. 74 | if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, 75 | NULL, 0, szFolderPath))) { 76 | path = CefString(szFolderPath); 77 | path += "\\" + file_name; 78 | } 79 | 80 | return path; 81 | } 82 | 83 | std::string MainContext::GetAppWorkingDirectory() { 84 | char szWorkingDir[MAX_PATH + 1]; 85 | if (_getcwd(szWorkingDir, MAX_PATH) == NULL) { 86 | szWorkingDir[0] = 0; 87 | } else { 88 | // Add trailing path separator. 89 | size_t len = strlen(szWorkingDir); 90 | szWorkingDir[len] = '\\'; 91 | szWorkingDir[len + 1] = 0; 92 | } 93 | return szWorkingDir; 94 | } 95 | 96 | std::wstring MainContext::GetMainURL() { 97 | return m_sMainUrl; 98 | } 99 | 100 | cef_color_t MainContext::GetBackgroundColor() { 101 | return m_BackgroundColor; 102 | } 103 | 104 | void MainContext::PopulateSettings(CefSettings* settings) { 105 | settings->multi_threaded_message_loop = 106 | m_CommandLine->HasSwitch(Switches::kMultiThreadedMessageLoop); 107 | 108 | CefString(&settings->cache_path) = 109 | m_CommandLine->GetSwitchValue(Switches::kCachePath); 110 | 111 | if (m_CommandLine->HasSwitch(Switches::kOffScreenRenderingEnabled)) 112 | settings->windowless_rendering_enabled = true; 113 | 114 | settings->background_color = m_BackgroundColor; 115 | } 116 | 117 | void MainContext::PopulateBrowserSettings(CefBrowserSettings* settings) { 118 | if (m_CommandLine->HasSwitch(Switches::kOffScreenFrameRate)) { 119 | settings->windowless_frame_rate = atoi(m_CommandLine-> 120 | GetSwitchValue(Switches::kOffScreenFrameRate).ToString().c_str()); 121 | } 122 | } 123 | 124 | BrowserDlgManager* MainContext::GetBrowserDlgManager() { 125 | DCHECK(InValidState()); 126 | return m_BrowserDlgManager.get(); 127 | } 128 | 129 | bool MainContext::Initialize(const CefMainArgs& args, 130 | const CefSettings& settings, 131 | CefRefPtr application, 132 | void* windows_sandbox_info) { 133 | DCHECK(m_ThreadChecker.CalledOnValidThread()); 134 | DCHECK(!m_bInitialized); 135 | DCHECK(!m_bShutdown); 136 | 137 | if (!CefInitialize(args, settings, application, windows_sandbox_info)) 138 | return false; 139 | 140 | m_BrowserDlgManager.reset(new BrowserDlgManager(m_bTerminateWhenAllWindowsClosed)); 141 | 142 | // Set the main URL. 143 | if (m_CommandLine->HasSwitch(Switches::kUrl)) 144 | m_sMainUrl = m_CommandLine->GetSwitchValue(Switches::kUrl); 145 | 146 | m_bInitialized = true; 147 | 148 | return true; 149 | } 150 | 151 | void MainContext::Shutdown() { 152 | DCHECK(m_ThreadChecker.CalledOnValidThread()); 153 | DCHECK(m_bInitialized); 154 | DCHECK(!m_bShutdown); 155 | 156 | m_BrowserDlgManager.reset(); 157 | 158 | CefShutdown(); 159 | 160 | m_bShutdown = true; 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /Browser/MainContext.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAIN_CONTEXT_H__ 2 | #define __MAIN_CONTEXT_H__ 3 | #pragma once 4 | #include 5 | #include "include/base/cef_ref_counted.h" 6 | #include "include/base/cef_scoped_ptr.h" 7 | #include "include/base/cef_thread_checker.h" 8 | #include "include/internal/cef_types_wrappers.h" 9 | #include "include/cef_command_line.h" 10 | #include "BrowserDlgManager.h" 11 | 12 | namespace Browser 13 | { 14 | class BrowserDlgManager; 15 | 16 | // Used to store global context in the browser process. The methods of this 17 | // class are thread-safe unless otherwise indicated. 18 | class MainContext 19 | { 20 | public: 21 | // Returns the singleton instance of this object. 22 | static MainContext* Get(); 23 | MainContext(CefRefPtr command_line, bool terminate_when_all_windows_closed); 24 | 25 | public: 26 | // Returns the full path to the console log file. 27 | std::string GetConsoleLogPath(); 28 | 29 | // Returns the full path to |file_name|. 30 | std::string GetDownloadPath(const std::string& file_name); 31 | 32 | // Returns the app working directory including trailing path separator. 33 | std::string GetAppWorkingDirectory(); 34 | 35 | // Returns the main application URL. 36 | std::wstring GetMainURL(); 37 | 38 | // Returns the background color. 39 | virtual cef_color_t GetBackgroundColor(); 40 | 41 | // Populate |settings| based on command-line arguments. 42 | virtual void PopulateSettings(CefSettings* settings); 43 | virtual void PopulateBrowserSettings(CefBrowserSettings* settings); 44 | 45 | // Returns the object used to create/manage RootWindow instances. 46 | virtual BrowserDlgManager* GetBrowserDlgManager(); 47 | 48 | // Initialize CEF and associated main context state. This method must be 49 | // called on the same thread that created this object. 50 | bool Initialize(const CefMainArgs& args, 51 | const CefSettings& settings, 52 | CefRefPtr application, 53 | void* windows_sandbox_info); 54 | 55 | // Shut down CEF and associated context state. This method must be called on 56 | // the same thread that created this object. 57 | void Shutdown(); 58 | 59 | private: 60 | // Allow deletion via scoped_ptr only. 61 | friend struct base::DefaultDeleter; 62 | virtual ~MainContext(); 63 | 64 | // Returns true if the context is in a valid state (initialized and not yet 65 | // shut down). 66 | bool InValidState() const { 67 | return m_bInitialized && !m_bShutdown; 68 | } 69 | 70 | CefRefPtr m_CommandLine; 71 | const bool m_bTerminateWhenAllWindowsClosed; 72 | 73 | // Track context state. Accessing these variables from multiple threads is 74 | // safe because only a single thread will exist at the time that they're set 75 | // (during context initialization and shutdown). 76 | bool m_bInitialized; 77 | bool m_bShutdown; 78 | 79 | std::wstring m_sMainUrl; 80 | cef_color_t m_BackgroundColor; 81 | 82 | scoped_ptr m_BrowserDlgManager; 83 | 84 | // Used to verify that methods are called on the correct thread. 85 | base::ThreadChecker m_ThreadChecker; 86 | 87 | DISALLOW_COPY_AND_ASSIGN(MainContext); 88 | }; 89 | } 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /Browser/MainDlg.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "include/base/cef_scoped_ptr.h" 3 | #include "include/cef_command_line.h" 4 | #include "include/cef_sandbox_win.h" 5 | #include "ClientAppBrowser.h" 6 | #include "ClientAppRenderer.h" 7 | #include "MessageLoop.h" 8 | #include "MainContext.h" 9 | #include "BrowserDlgManager.h" 10 | #include "ClientRunner.h" 11 | #include "ClientSwitches.h" 12 | #include 13 | #include 14 | using namespace Browser; 15 | 16 | int APIENTRY _tWinMain(HINSTANCE hInstance, 17 | HINSTANCE hPrevInstance, 18 | LPTSTR lpCmdLine, 19 | int nCmdShow) 20 | { 21 | int result = 0; 22 | HRESULT Hr = ::CoInitialize(NULL); 23 | if(FAILED(Hr)) return 0; 24 | 25 | DuiLib::CPaintManagerUI::SetInstance(hInstance); 26 | DuiLib::CPaintManagerUI::SetResourceType(DuiLib::UILIB_ZIPRESOURCE); 27 | DuiLib::CPaintManagerUI::SetResourcePath(DuiLib::CPaintManagerUI::GetInstancePath()); 28 | DuiLib::CPaintManagerUI::SetResourceZip(MAKEINTRESOURCE(IDR_ZIPRES), _T("ZIPRES")); 29 | 30 | HMODULE hFlashTools = NULL; 31 | #ifdef _DEBUG 32 | hFlashTools = LoadLibrary(_T("FlashTools_d.dll")); 33 | #else 34 | hFlashTools = LoadLibrary(_T("FlashTools.dll")); 35 | #endif 36 | 37 | CefMainArgs main_args(hInstance); 38 | CefSettings settings; 39 | void* sandbox_info = NULL; 40 | #ifdef CEF_USE_SANDBOX 41 | CefScopedSandboxInfo scoped_sandbox; 42 | sandbox_info = scoped_sandbox.sandbox_info(); 43 | #else 44 | settings.no_sandbox = true; 45 | #endif 46 | // Parse command-line arguments. 47 | CefRefPtr command_line = CefCommandLine::CreateCommandLine(); 48 | command_line->InitFromString(::GetCommandLineW()); 49 | 50 | CefRefPtr app; 51 | if (ClientApp::IsBrowser(command_line)) 52 | app = new ClientAppBrowser(); 53 | else if (ClientApp::IsRenderer(command_line)) 54 | app = new ClientAppRenderer(); 55 | else 56 | app = new ClientAppOther(); 57 | 58 | // Execute the secondary process, if any. 59 | int exit_code = CefExecuteProcess(main_args, app, sandbox_info); 60 | if (exit_code >= 0) 61 | return exit_code; 62 | 63 | // Create the main context object. 64 | scoped_ptr context(new MainContext(command_line, true)); 65 | 66 | // Populate the settings based on command line arguments. 67 | context->PopulateSettings(&settings); 68 | 69 | WCHAR szBuffer[MAX_PATH]; 70 | ::ZeroMemory(&szBuffer, sizeof(szBuffer)); 71 | GetTempPathW(MAX_PATH,szBuffer); 72 | std::wstring sBuffer = szBuffer; 73 | sBuffer += L"Browser"; 74 | CefString(&settings.cache_path).FromWString(sBuffer); 75 | 76 | settings.ignore_certificate_errors = true; 77 | 78 | //settings.command_line_args_disabled = true; 79 | 80 | CefString(&settings.locale).FromASCII("zh-CN"); 81 | 82 | #ifndef _DEBUG 83 | settings.log_severity = LOGSEVERITY_DISABLE; 84 | #endif 85 | //settings.multi_threaded_message_loop = true; 86 | //settings.single_process = true; 87 | 88 | CefRect rect = CefRect(); 89 | std::string url,width,height; 90 | url = command_line->GetSwitchValue(Switches::kUrl); 91 | width = command_line->GetSwitchValue("width"); 92 | height = command_line->GetSwitchValue("height"); 93 | if (url.empty()){ 94 | url = "http://www.baidu.com"; 95 | // Set the main URL. 96 | command_line->AppendSwitchWithValue(Switches::kUrl, url); 97 | } 98 | if (width.empty()){ 99 | rect.width = 1024; 100 | }else{ 101 | rect.width = atoi(width.c_str()); 102 | } 103 | if (height.empty()){ 104 | rect.height = 700; 105 | }else{ 106 | rect.height = atoi(height.c_str()); 107 | } 108 | 109 | // Initialize CEF. 110 | context->Initialize(main_args, settings, app, sandbox_info); 111 | 112 | // Register scheme handlers. 113 | //ClientRunner::RegisterSchemeHandlers(); 114 | 115 | // Create the first window. 116 | BrowserDlg* pDlg = context->GetBrowserDlgManager()->CreateBrowserDlg( 117 | NULL, 118 | true, // Show controls. 119 | rect, // Use default system size. 120 | url); // Use default URL. 121 | 122 | if(pDlg) { 123 | pDlg->CenterWindow(); 124 | } 125 | 126 | //DuiLib::CPaintManagerUI::MessageLoop(); 127 | CefRunMessageLoop(); 128 | 129 | DuiLib::CPaintManagerUI::Term(); 130 | 131 | // Shut down CEF. 132 | context->Shutdown(); 133 | 134 | if(hFlashTools){ 135 | CloseHandle(hFlashTools); 136 | hFlashTools= NULL; 137 | } 138 | ::CoUninitialize(); 139 | return result; 140 | } 141 | -------------------------------------------------------------------------------- /Browser/MessageLoop.h: -------------------------------------------------------------------------------- 1 | #ifndef __MESSAGE_LOOP_H__ 2 | #define __MESSAGE_LOOP_H__ 3 | #pragma once 4 | #include "include/base/cef_bind.h" 5 | #include "include/base/cef_scoped_ptr.h" 6 | #include "include/cef_task.h" 7 | #include 8 | 9 | namespace Browser { 10 | struct DeleteOnMainThread { 11 | template 12 | static void Destruct(const T* x) { 13 | if (CefCurrentlyOn(TID_UI)) { 14 | delete x; 15 | } else { 16 | CefPostTask(TID_UI, CefCreateClosureTask(base::Bind(&DeleteOnMainThread::Destruct, x))); 17 | } 18 | } 19 | }; 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Browser/PerfTest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ClientAppRenderer.h" 3 | #include "PerfTest.h" 4 | #include 5 | #include 6 | #include "include/wrapper/cef_stream_resource_handler.h" 7 | 8 | namespace Browser 9 | { 10 | namespace PerfTest 11 | { 12 | const char kGetPerfTests[] = "GetPerfTests"; 13 | 14 | class V8Handler : public CefV8Handler 15 | { 16 | public: 17 | V8Handler() {} 18 | 19 | virtual bool Execute(const CefString& name, 20 | CefRefPtr object, 21 | const CefV8ValueList& arguments, 22 | CefRefPtr& retval, 23 | CefString& exception) OVERRIDE 24 | { 25 | if (name == kGetPerfTests) { 26 | retval = CefV8Value::CreateString("Performance Test"); 27 | } 28 | return true; 29 | } 30 | private: 31 | IMPLEMENT_REFCOUNTING(V8Handler); 32 | }; 33 | 34 | // Handle bindings in the render process. 35 | class RenderDelegate : public ClientAppRenderer::Delegate 36 | { 37 | public: 38 | RenderDelegate() {} 39 | 40 | virtual void OnContextCreated(CefRefPtr app, 41 | CefRefPtr browser, 42 | CefRefPtr frame, 43 | CefRefPtr context) OVERRIDE { 44 | CefRefPtr object = context->GetGlobal(); 45 | 46 | CefRefPtr handler = new V8Handler(); 47 | 48 | // Bind functions. 49 | object->SetValue(kGetPerfTests, 50 | CefV8Value::CreateFunction(kGetPerfTests, handler), 51 | V8_PROPERTY_ATTRIBUTE_READONLY); 52 | } 53 | 54 | private: 55 | IMPLEMENT_REFCOUNTING(RenderDelegate); 56 | }; 57 | 58 | void CreateDelegates(ClientAppRenderer::DelegateSet& delegates) { 59 | delegates.insert(new RenderDelegate); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Browser/PerfTest.h: -------------------------------------------------------------------------------- 1 | #ifndef __PERFTEST_H__ 2 | #define __PERFTEST_H__ 3 | #pragma once 4 | #include "ClientAppRenderer.h" 5 | 6 | namespace Browser 7 | { 8 | namespace PerfTest 9 | { 10 | void CreateDelegates(ClientAppRenderer::DelegateSet& delegates); 11 | } 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /Browser/ResourceUtil.cpp: -------------------------------------------------------------------------------- 1 | #include "include/base/cef_logging.h" 2 | #include "include/cef_stream.h" 3 | #include "include/wrapper/cef_byte_read_handler.h" 4 | #include "include/wrapper/cef_stream_resource_handler.h" 5 | #include "resource.h" 6 | #include "ResourceUtil.h" 7 | 8 | namespace Browser 9 | { 10 | namespace 11 | { 12 | bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes) 13 | { 14 | HINSTANCE hInst = GetModuleHandle(NULL); 15 | HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(binaryId), MAKEINTRESOURCE(BINARY)); 16 | if (hRes) { 17 | HGLOBAL hGlob = LoadResource(hInst, hRes); 18 | if (hGlob) { 19 | dwSize = SizeofResource(hInst, hRes); 20 | pBytes = (LPBYTE)LockResource(hGlob); 21 | if (dwSize > 0 && pBytes) 22 | return true; 23 | } 24 | } 25 | 26 | return false; 27 | } 28 | 29 | int GetResourceId(const char* resource_name) { 30 | // Map of resource labels to BINARY id values. 31 | static struct _resource_map { 32 | char* name; 33 | int id; 34 | } resource_map[] = { 35 | {"Logo.png", IDS_LOGO_PNG}, 36 | {"binding.html", IDS_BINDING_HTML}, 37 | }; 38 | 39 | for (int i = 0; i < sizeof(resource_map)/sizeof(_resource_map); ++i) { 40 | if (!stricmp(resource_map[i].name, resource_name)) 41 | return resource_map[i].id; 42 | } 43 | 44 | return 0; 45 | } 46 | 47 | // Provider of binary resources. 48 | class BinaryResourceProvider : public CefResourceManager::Provider { 49 | public: 50 | explicit BinaryResourceProvider(const std::string& url_path) 51 | : url_path_(url_path) { 52 | DCHECK(!url_path.empty()); 53 | } 54 | 55 | bool OnRequest(scoped_refptr request) OVERRIDE { 56 | CEF_REQUIRE_IO_THREAD(); 57 | 58 | const std::string& url = request->url(); 59 | if (url.find(url_path_) != 0L) { 60 | // Not handled by this provider. 61 | return false; 62 | } 63 | 64 | CefRefPtr handler; 65 | 66 | const std::string& relative_path = url.substr(url_path_.length()); 67 | if (!relative_path.empty()) { 68 | CefRefPtr stream = 69 | GetBinaryResourceReader(relative_path.data()); 70 | if (stream.get()) { 71 | handler = new CefStreamResourceHandler( 72 | request->mime_type_resolver().Run(url), 73 | stream); 74 | } 75 | } 76 | 77 | request->Continue(handler); 78 | return true; 79 | } 80 | 81 | private: 82 | std::string url_path_; 83 | 84 | DISALLOW_COPY_AND_ASSIGN(BinaryResourceProvider); 85 | }; 86 | 87 | } // namespace 88 | 89 | bool LoadBinaryResource(const char* resource_name, std::string& resource_data) { 90 | int resource_id = GetResourceId(resource_name); 91 | if (resource_id == 0) 92 | return false; 93 | 94 | DWORD dwSize; 95 | LPBYTE pBytes; 96 | 97 | if (LoadBinaryResource(resource_id, dwSize, pBytes)) { 98 | resource_data = std::string(reinterpret_cast(pBytes), dwSize); 99 | return true; 100 | } 101 | 102 | NOTREACHED(); // The resource should be found. 103 | return false; 104 | } 105 | 106 | CefRefPtr GetBinaryResourceReader(const char* resource_name) { 107 | int resource_id = GetResourceId(resource_name); 108 | if (resource_id == 0) 109 | return NULL; 110 | 111 | DWORD dwSize; 112 | LPBYTE pBytes; 113 | 114 | if (LoadBinaryResource(resource_id, dwSize, pBytes)) { 115 | return CefStreamReader::CreateForHandler( 116 | new CefByteReadHandler(pBytes, dwSize, NULL)); 117 | } 118 | 119 | NOTREACHED(); // The resource should be found. 120 | return NULL; 121 | } 122 | 123 | CefResourceManager::Provider* CreateBinaryResourceProvider(const std::string& url_path) 124 | { 125 | return new BinaryResourceProvider(url_path); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Browser/ResourceUtil.h: -------------------------------------------------------------------------------- 1 | #ifndef __RESOURCE_UTIL_H__ 2 | #define __RESOURCE_UTIL_H__ 3 | #pragma once 4 | #include 5 | #include "include/cef_stream.h" 6 | #include "include/wrapper/cef_resource_manager.h" 7 | 8 | namespace Browser 9 | { 10 | // Retrieve a resource as a string. 11 | bool LoadBinaryResource(const char* resource_name, std::string& resource_data); 12 | 13 | // Retrieve a resource as a steam reader. 14 | CefRefPtr GetBinaryResourceReader(const char* resource_name); 15 | 16 | #ifdef OS_WIN 17 | // Create a new provider for loading binary resources. 18 | CefResourceManager::Provider* CreateBinaryResourceProvider(const std::string& url_path); 19 | #endif 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Browser/Skin/BrowserDlg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |