├── LICENSE ├── README.md ├── build └── Release │ ├── cef.pak │ ├── d3dcompiler_43.dll │ ├── d3dcompiler_46.dll │ ├── debug.log │ ├── devtools_resources.pak │ ├── doomtool.exe │ ├── doomtool.pdb │ ├── ffmpegsumo.dll │ ├── icudt.dll │ ├── libEGL.dll │ ├── libGLESv2.dll │ ├── libcef.dll │ └── locales │ ├── am.pak │ ├── ar.pak │ ├── bg.pak │ ├── bn.pak │ ├── ca.pak │ ├── cs.pak │ ├── da.pak │ ├── de.pak │ ├── el.pak │ ├── en-GB.pak │ ├── en-US.pak │ ├── es-419.pak │ ├── es.pak │ ├── et.pak │ ├── fa.pak │ ├── fi.pak │ ├── fil.pak │ ├── fr.pak │ ├── gu.pak │ ├── he.pak │ ├── hi.pak │ ├── hr.pak │ ├── hu.pak │ ├── id.pak │ ├── it.pak │ ├── ja.pak │ ├── kn.pak │ ├── ko.pak │ ├── lt.pak │ ├── lv.pak │ ├── ml.pak │ ├── mr.pak │ ├── ms.pak │ ├── nb.pak │ ├── nl.pak │ ├── pl.pak │ ├── pt-BR.pak │ ├── pt-PT.pak │ ├── ro.pak │ ├── ru.pak │ ├── sk.pak │ ├── sl.pak │ ├── sr.pak │ ├── sv.pak │ ├── sw.pak │ ├── ta.pak │ ├── te.pak │ ├── th.pak │ ├── tr.pak │ ├── uk.pak │ ├── vi.pak │ ├── zh-CN.pak │ └── zh-TW.pak ├── cef-based-ui.gif ├── doomtool.sln ├── doomtool.vcxproj ├── doomtool ├── README-TRANSFER.txt ├── cefclient.aps ├── cefclient.rc ├── cefclient_module.h ├── cefclient_osr_widget_win.cpp ├── cefclient_osr_widget_win.h ├── cefclient_win.cpp ├── client_app.cpp ├── client_app.h ├── client_app_delegates.cpp ├── client_handler.cpp ├── client_handler.h ├── client_handler_win.cpp ├── client_renderer.cpp ├── client_renderer.h ├── client_switches.cpp ├── client_switches.h ├── compatibility.manifest ├── doomtool.exe.manifest ├── extensions │ ├── cefclient_extensions_require.cpp │ ├── cefclient_extensions_require.h │ ├── cefclient_extensions_require_win.cpp │ ├── cefclient_extensions_window.cpp │ ├── cefclient_extensions_window.h │ └── cefclient_extensions_window_win.cpp ├── osrenderer.cpp ├── osrenderer.h ├── res │ ├── doomtool.ico │ ├── window.html │ └── window.js ├── resource.h ├── resource_util.h ├── resource_util_win.cpp ├── scheme_test.cpp ├── scheme_test.h ├── string_util.cpp ├── string_util.h ├── util.h ├── window_test.cpp ├── window_test.h └── window_test_win.cpp └── index.html /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cef3-window-sample 2 | 3 | [Chromium Embedded Framework 3](http://bitbucket.org/chromiumembedded/cef) offscreen rendering example on windows. 4 | GUI and animation build with html/css3. 5 | 6 | ![screenshot](https://github.com/teaegg/cef3-windows-sample/blob/master/cef-based-ui.gif) 7 | 8 | ## Install 9 | 10 | ```sh 11 | $ git clone https://github.com/teaegg/cef3-windows-sample.git 12 | ``` 13 | 14 | Or [download as ZIP](https://github.com/teaegg/cef3-windows-sample/archive/master.zip). 15 | 16 | 1. open doomtool.vcxproj with vs2010+. 17 | 2. build 18 | 19 | Or run the doomtool.exe in /cef3-windows-sample/build/Release/ 20 | 21 | ## Contributing 22 | 23 | 1. Fork it! 24 | 2. Create your feature branch: `git checkout -b my-new-feature` 25 | 3. Commit your changes: `git commit -m 'Add some feature'` 26 | 4. Push to the branch: `git push origin my-new-feature` 27 | 5. Submit a pull request :D 28 | 29 | ## License 30 | 31 | [MIT License](https://github.com/teaegg/cef3-windows-sample/blob/master/README.md) 32 | -------------------------------------------------------------------------------- /build/Release/cef.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/cef.pak -------------------------------------------------------------------------------- /build/Release/d3dcompiler_43.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/d3dcompiler_43.dll -------------------------------------------------------------------------------- /build/Release/d3dcompiler_46.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/d3dcompiler_46.dll -------------------------------------------------------------------------------- /build/Release/debug.log: -------------------------------------------------------------------------------- 1 | [0129/163508:ERROR:child_process_launcher.cc(327)] Failed to launch child process 2 | [0129/163508:ERROR:child_process_launcher.cc(327)] Failed to launch child process 3 | [0129/170621:INFO:CONSOLE(0)] "Uncaught TypeError: Object 2 has no method 'addEventListener'", source: http://localhost/ (0) 4 | [0129/170642:INFO:CONSOLE(0)] "Uncaught TypeError: Object 2 has no method 'addEventListener'", source: http://localhost/ (0) 5 | [0129/170711:INFO:CONSOLE(0)] "Uncaught TypeError: Object 0 has no method 'addEventListener'", source: https://www.google.ca/?gfe_rd=cr&ei=PNnKVJC7BsermAK8i4DQCQ&gws_rd=ssl (0) 6 | [0129/170716:INFO:CONSOLE(0)] "Uncaught TypeError: Object 2 has no method 'addEventListener'", source: http://localhost/ (0) 7 | -------------------------------------------------------------------------------- /build/Release/devtools_resources.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/devtools_resources.pak -------------------------------------------------------------------------------- /build/Release/doomtool.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/doomtool.exe -------------------------------------------------------------------------------- /build/Release/doomtool.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/doomtool.pdb -------------------------------------------------------------------------------- /build/Release/ffmpegsumo.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/ffmpegsumo.dll -------------------------------------------------------------------------------- /build/Release/icudt.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/icudt.dll -------------------------------------------------------------------------------- /build/Release/libEGL.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/libEGL.dll -------------------------------------------------------------------------------- /build/Release/libGLESv2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/libGLESv2.dll -------------------------------------------------------------------------------- /build/Release/libcef.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/libcef.dll -------------------------------------------------------------------------------- /build/Release/locales/am.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/am.pak -------------------------------------------------------------------------------- /build/Release/locales/ar.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/ar.pak -------------------------------------------------------------------------------- /build/Release/locales/bg.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/bg.pak -------------------------------------------------------------------------------- /build/Release/locales/bn.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/bn.pak -------------------------------------------------------------------------------- /build/Release/locales/ca.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/ca.pak -------------------------------------------------------------------------------- /build/Release/locales/cs.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/cs.pak -------------------------------------------------------------------------------- /build/Release/locales/da.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/da.pak -------------------------------------------------------------------------------- /build/Release/locales/de.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/de.pak -------------------------------------------------------------------------------- /build/Release/locales/el.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/el.pak -------------------------------------------------------------------------------- /build/Release/locales/en-GB.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/en-GB.pak -------------------------------------------------------------------------------- /build/Release/locales/en-US.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/en-US.pak -------------------------------------------------------------------------------- /build/Release/locales/es-419.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/es-419.pak -------------------------------------------------------------------------------- /build/Release/locales/es.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/es.pak -------------------------------------------------------------------------------- /build/Release/locales/et.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/et.pak -------------------------------------------------------------------------------- /build/Release/locales/fa.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/fa.pak -------------------------------------------------------------------------------- /build/Release/locales/fi.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/fi.pak -------------------------------------------------------------------------------- /build/Release/locales/fil.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/fil.pak -------------------------------------------------------------------------------- /build/Release/locales/fr.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/fr.pak -------------------------------------------------------------------------------- /build/Release/locales/gu.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/gu.pak -------------------------------------------------------------------------------- /build/Release/locales/he.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/he.pak -------------------------------------------------------------------------------- /build/Release/locales/hi.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/hi.pak -------------------------------------------------------------------------------- /build/Release/locales/hr.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/hr.pak -------------------------------------------------------------------------------- /build/Release/locales/hu.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/hu.pak -------------------------------------------------------------------------------- /build/Release/locales/id.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/id.pak -------------------------------------------------------------------------------- /build/Release/locales/it.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/it.pak -------------------------------------------------------------------------------- /build/Release/locales/ja.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/ja.pak -------------------------------------------------------------------------------- /build/Release/locales/kn.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/kn.pak -------------------------------------------------------------------------------- /build/Release/locales/ko.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/ko.pak -------------------------------------------------------------------------------- /build/Release/locales/lt.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/lt.pak -------------------------------------------------------------------------------- /build/Release/locales/lv.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/lv.pak -------------------------------------------------------------------------------- /build/Release/locales/ml.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/ml.pak -------------------------------------------------------------------------------- /build/Release/locales/mr.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/mr.pak -------------------------------------------------------------------------------- /build/Release/locales/ms.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/ms.pak -------------------------------------------------------------------------------- /build/Release/locales/nb.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/nb.pak -------------------------------------------------------------------------------- /build/Release/locales/nl.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/nl.pak -------------------------------------------------------------------------------- /build/Release/locales/pl.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/pl.pak -------------------------------------------------------------------------------- /build/Release/locales/pt-BR.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/pt-BR.pak -------------------------------------------------------------------------------- /build/Release/locales/pt-PT.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/pt-PT.pak -------------------------------------------------------------------------------- /build/Release/locales/ro.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/ro.pak -------------------------------------------------------------------------------- /build/Release/locales/ru.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/ru.pak -------------------------------------------------------------------------------- /build/Release/locales/sk.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/sk.pak -------------------------------------------------------------------------------- /build/Release/locales/sl.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/sl.pak -------------------------------------------------------------------------------- /build/Release/locales/sr.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/sr.pak -------------------------------------------------------------------------------- /build/Release/locales/sv.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/sv.pak -------------------------------------------------------------------------------- /build/Release/locales/sw.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/sw.pak -------------------------------------------------------------------------------- /build/Release/locales/ta.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/ta.pak -------------------------------------------------------------------------------- /build/Release/locales/te.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/te.pak -------------------------------------------------------------------------------- /build/Release/locales/th.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/th.pak -------------------------------------------------------------------------------- /build/Release/locales/tr.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/tr.pak -------------------------------------------------------------------------------- /build/Release/locales/uk.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/uk.pak -------------------------------------------------------------------------------- /build/Release/locales/vi.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/vi.pak -------------------------------------------------------------------------------- /build/Release/locales/zh-CN.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/zh-CN.pak -------------------------------------------------------------------------------- /build/Release/locales/zh-TW.pak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/build/Release/locales/zh-TW.pak -------------------------------------------------------------------------------- /cef-based-ui.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/cef-based-ui.gif -------------------------------------------------------------------------------- /doomtool.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doomtool", "doomtool.vcxproj", "{3A113CDF-838F-4E6F-97EA-BCD6975656D9}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {3A113CDF-838F-4E6F-97EA-BCD6975656D9}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {3A113CDF-838F-4E6F-97EA-BCD6975656D9}.Debug|Win32.Build.0 = Debug|Win32 14 | {3A113CDF-838F-4E6F-97EA-BCD6975656D9}.Release|Win32.ActiveCfg = Release|Win32 15 | {3A113CDF-838F-4E6F-97EA-BCD6975656D9}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /doomtool.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 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 | {3A113CDF-838F-4E6F-97EA-BCD6975656D9} 63 | Win32Proj 64 | doomtool 65 | 66 | 67 | 68 | Application 69 | true 70 | Unicode 71 | v100 72 | 73 | 74 | Application 75 | false 76 | true 77 | Unicode 78 | v100 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | true 92 | build\$(Configuration)\ 93 | $(OutDir)obj\$(ProjectName)\ 94 | 95 | 96 | false 97 | build\$(Configuration)\ 98 | $(OutDir)obj\$(ProjectName)\ 99 | $(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include; 100 | $(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib 101 | 102 | 103 | 104 | NotUsing 105 | Level4 106 | Disabled 107 | _DEBUG;ANGLE_DX11;_WIN32_WINNT=0x0602;WINVER=0x0602;WIN32;_WINDOWS;NOMINMAX;PSAPI_VERSION=1;_CRT_RAND_S;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;WIN32_LEAN_AND_MEAN;_ATL_NO_OPENGL;_HAS_EXCEPTIONS=0;_SECURE_ATL;CHROMIUM_BUILD;TOOLKIT_VIEWS=1;USE_LIBJPEG_TURBO=1;ENABLE_ONE_CLICK_SIGNIN;ENABLE_REMOTING=1;ENABLE_WEBRTC=1;ENABLE_PEPPER_CDMS;ENABLE_CONFIGURATION_POLICY;ENABLE_INPUT_SPEECH;ENABLE_NOTIFICATIONS;ENABLE_GPU=1;ENABLE_EGLIMAGE=1;__STD_C;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE;NTDDI_VERSION=0x06020000;ENABLE_TASK_MANAGER=1;ENABLE_EXTENSIONS=1;ENABLE_PLUGIN_INSTALLATION=1;ENABLE_PLUGINS=1;ENABLE_SESSION_SERVICE=1;ENABLE_THEMES=1;ENABLE_AUTOFILL_DIALOG=1;ENABLE_BACKGROUND=1;ENABLE_AUTOMATION=1;ENABLE_GOOGLE_NOW=1;CLD_VERSION=1;ENABLE_FULL_PRINTING=1;ENABLE_PRINTING=1;ENABLE_SPELLCHECK=1;ENABLE_CAPTIVE_PORTAL_DETECTION=1;ENABLE_APP_LIST=1;ENABLE_SETTINGS_APP=1;ENABLE_MANAGED_USERS=1;ENABLE_MDNS=1;USING_CEF_SHARED;__STDC_CONSTANT_MACROS;__STDC_FORMAT_MACROS;DYNAMIC_ANNOTATIONS_ENABLED=1;WTF_USE_DYNAMIC_ANNOTATIONS=1;%(PreprocessorDefinitions) 108 | MultiThreadedDebug 109 | /MP /we4389 %(AdditionalOptions) 110 | 4351;4355;4396;4503;4819;4100;4121;4125;4127;4130;4131;4189;4201;4238;4244;4245;4310;4428;4481;4505;4510;4512;4530;4610;4611;4701;4702;4706;4099;%(DisableSpecificWarnings) 111 | true 112 | ProgramDatabase 113 | doomtool\;cef\;%(AdditionalIncludeDirectories) 114 | 115 | 116 | Windows 117 | true 118 | wininet.lib;dnsapi.lib;version.lib;msimg32.lib;ws2_32.lib;usp10.lib;psapi.lib;dbghelp.lib;winmm.lib;shlwapi.lib;kernel32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;user32.lib;uuid.lib;odbc32.lib;odbccp32.lib;delayimp.lib;comctl32.lib;rpcrt4.lib;opengl32.lib;glu32.lib;cef\$(Configuration)\libcef_dll_wrapper.lib;cef\$(Configuration)\libcef.lib;%(AdditionalDependencies) 119 | %(DelayLoadDLLs) 120 | /safeseh /dynamicbase /ignore:4199 /ignore:4221 /nxcompat /largeaddressaware %(AdditionalOptions) 121 | 122 | 123 | call xcopy /defy cef\$(Configuration)\*.dll $(OutDir) 124 | call xcopy /defy cef\Resources\* $(OutDir) 125 | 126 | 127 | 128 | doomtool/doomtool.exe.manifest;doomtool/compatibility.manifest %(AdditionalManifestFiles) 129 | 130 | 131 | 132 | 133 | Level4 134 | NotUsing 135 | MaxSpeed 136 | true 137 | true 138 | ANGLE_DX11;_WIN32_WINNT=0x0602;WINVER=0x0602;WIN32;_WINDOWS;NOMINMAX;PSAPI_VERSION=1;_CRT_RAND_S;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;WIN32_LEAN_AND_MEAN;_ATL_NO_OPENGL;_HAS_EXCEPTIONS=0;_SECURE_ATL;CHROMIUM_BUILD;TOOLKIT_VIEWS=1;USE_LIBJPEG_TURBO=1;ENABLE_ONE_CLICK_SIGNIN;ENABLE_REMOTING=1;ENABLE_WEBRTC=1;ENABLE_PEPPER_CDMS;ENABLE_CONFIGURATION_POLICY;ENABLE_INPUT_SPEECH;ENABLE_NOTIFICATIONS;ENABLE_GPU=1;ENABLE_EGLIMAGE=1;__STD_C;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE;NTDDI_VERSION=0x06020000;ENABLE_TASK_MANAGER=1;ENABLE_EXTENSIONS=1;ENABLE_PLUGIN_INSTALLATION=1;ENABLE_PLUGINS=1;ENABLE_SESSION_SERVICE=1;ENABLE_THEMES=1;ENABLE_AUTOFILL_DIALOG=1;ENABLE_BACKGROUND=1;ENABLE_AUTOMATION=1;ENABLE_GOOGLE_NOW=1;CLD_VERSION=1;ENABLE_FULL_PRINTING=1;ENABLE_PRINTING=1;ENABLE_SPELLCHECK=1;ENABLE_CAPTIVE_PORTAL_DETECTION=1;ENABLE_APP_LIST=1;ENABLE_SETTINGS_APP=1;ENABLE_MANAGED_USERS=1;ENABLE_MDNS=1;USING_CEF_SHARED;__STDC_CONSTANT_MACROS;__STDC_FORMAT_MACROS;NDEBUG;NVALGRIND;DYNAMIC_ANNOTATIONS_ENABLED=0;%(PreprocessorDefinitions) 139 | MultiThreaded 140 | /MP /we4389 /Oy- %(AdditionalOptions) 141 | 4351;4355;4396;4503;4819;4100;4121;4125;4127;4130;4131;4189;4201;4238;4244;4245;4310;4428;4481;4505;4510;4512;4530;4610;4611;4701;4702;4706;4099;%(DisableSpecificWarnings) 142 | true 143 | ProgramDatabase 144 | doomtool\;cef\;%(AdditionalIncludeDirectories) 145 | 146 | 147 | Windows 148 | true 149 | true 150 | true 151 | wininet.lib;dnsapi.lib;version.lib;msimg32.lib;ws2_32.lib;usp10.lib;psapi.lib;dbghelp.lib;winmm.lib;shlwapi.lib;kernel32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;user32.lib;uuid.lib;odbc32.lib;odbccp32.lib;delayimp.lib;comctl32.lib;rpcrt4.lib;opengl32.lib;glu32.lib;cef\$(Configuration)\libcef_dll_wrapper.lib;cef\$(Configuration)\libcef.lib;%(AdditionalDependencies) 152 | %(DelayLoadDLLs) 153 | /safeseh /dynamicbase /ignore:4199 /ignore:4221 /nxcompat /largeaddressaware %(AdditionalOptions) 154 | 155 | 156 | call xcopy /defy cef\$(Configuration)\*.dll $(OutDir) 157 | call xcopy /defy cef\Resources\* $(OutDir) 158 | 159 | 160 | 161 | doomtool/doomtool.exe.manifest;doomtool/compatibility.manifest %(AdditionalManifestFiles) 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /doomtool/README-TRANSFER.txt: -------------------------------------------------------------------------------- 1 | Files in this directory have been copied from other locations in the Chromium 2 | source tree. They have been modified only to the extent necessary to work in 3 | the CEF Binary Distribution directory structure. Below is a listing of the 4 | original file locations. 5 | 6 | ../build/win/compatibility.manifest 7 | -------------------------------------------------------------------------------- /doomtool/cefclient.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/doomtool/cefclient.aps -------------------------------------------------------------------------------- /doomtool/cefclient.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 | #undef APSTUDIO_HIDDEN_SYMBOLS 13 | 14 | ///////////////////////////////////////////////////////////////////////////// 15 | #undef APSTUDIO_READONLY_SYMBOLS 16 | 17 | ///////////////////////////////////////////////////////////////////////////// 18 | // English (United States) resources 19 | 20 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 21 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 22 | #pragma code_page(1252) 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Icon 27 | // 28 | 29 | // Icon with lowest ID value placed first to ensure application icon 30 | // remains consistent on all systems. 31 | IDI_DOOMTOOL ICON "res\\doomtool.ico" 32 | 33 | #ifdef APSTUDIO_INVOKED 34 | ///////////////////////////////////////////////////////////////////////////// 35 | // 36 | // TEXTINCLUDE 37 | // 38 | 39 | 1 TEXTINCLUDE 40 | BEGIN 41 | "resource.h\0" 42 | END 43 | 44 | 2 TEXTINCLUDE 45 | BEGIN 46 | "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" 47 | "#include ""windows.h""\r\n" 48 | "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" 49 | "\0" 50 | END 51 | 52 | 3 TEXTINCLUDE 53 | BEGIN 54 | "\r\n" 55 | "\0" 56 | END 57 | 58 | #endif // APSTUDIO_INVOKED 59 | 60 | 61 | ///////////////////////////////////////////////////////////////////////////// 62 | // 63 | // 256 64 | // 65 | 66 | IDS_WINDOW 256 "res\\window.html" 67 | IDS_WINDOW_JS 256 "res\\window.js" 68 | #endif // English (United States) resources 69 | ///////////////////////////////////////////////////////////////////////////// 70 | 71 | 72 | 73 | #ifndef APSTUDIO_INVOKED 74 | ///////////////////////////////////////////////////////////////////////////// 75 | // 76 | // Generated from the TEXTINCLUDE 3 resource. 77 | // 78 | 79 | 80 | ///////////////////////////////////////////////////////////////////////////// 81 | #endif // not APSTUDIO_INVOKED 82 | 83 | -------------------------------------------------------------------------------- /doomtool/cefclient_module.h: -------------------------------------------------------------------------------- 1 | #ifndef CEF_TESTS_CEFCLIENT_MODULE_H_ 2 | #define CEF_TESTS_CEFCLIENT_MODULE_H_ 3 | 4 | #include "include/cef_base.h" 5 | 6 | class CefV8Module : public virtual CefBase { 7 | public: 8 | /// 9 | // Called to retrieve the module name. 10 | // Return true if the directory was provided. 11 | /// 12 | virtual bool GetModuleName(CefString& name) { return false; } 13 | 14 | /// 15 | // Called to retrieve the module version. 16 | // Return true if the directory was provided. 17 | /// 18 | virtual bool GetModuleVersion(CefString& version) { return false; } 19 | 20 | /// 21 | // Called to retrieve the module Dependents. 22 | // Return true if the directory was provided. 23 | /// 24 | //virtual bool GetModuleDependents(std::vector& deps) { return false; } 25 | 26 | /// 27 | // Called when the module manager wants to load the module. 28 | // Return true if the directory was provided. 29 | /// 30 | virtual bool OnExecute(/*const CefV8ValueList& deps, */CefRefPtr& obj) { return false; } 31 | }; 32 | 33 | #endif // CEF_TESTS_CEFCLIENT_MODULE_H_ -------------------------------------------------------------------------------- /doomtool/cefclient_osr_widget_win.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "cefclient_osr_widget_win.h" 6 | 7 | #include 8 | 9 | #include "include/cef_runnable.h" 10 | #include "resource.h" 11 | #include "util.h" 12 | 13 | // static 14 | CefRefPtr OSRWindow::Create(HINSTANCE hInst, 15 | OSRBrowserProvider* browser_provider, 16 | bool transparent) { 17 | ASSERT(browser_provider); 18 | if (!browser_provider) 19 | return NULL; 20 | 21 | return new OSRWindow(hInst, browser_provider, transparent); 22 | } 23 | 24 | // static 25 | CefRefPtr OSRWindow::From( 26 | CefRefPtr renderHandler) { 27 | return static_cast(renderHandler.get()); 28 | } 29 | 30 | HWND OSRWindow::CreateWidget(HWND hWndParent, const RECT& rect, LPCTSTR windowName, LPCTSTR className) { 31 | //ASSERT(hInst_ == NULL); 32 | 33 | RegisterOSRClass(hInst_, className); 34 | HWND hWnd = ::CreateWindowEx(WS_EX_LAYERED, className, windowName, 35 | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_VISIBLE, 36 | rect.left, rect.top, rect.right, rect.bottom, 37 | hWndParent, 0, hInst_, 0); 38 | 39 | if (!hWnd) 40 | return 0; 41 | 42 | SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast(this)); 43 | // Reference released in OnDestroyed(). 44 | AddRef(); 45 | 46 | return hWnd; 47 | } 48 | 49 | void OSRWindow::DestroyWidget() { 50 | //if (IsWindow(hWnd_)) 51 | //DestroyWindow(hWnd_); 52 | } 53 | 54 | void OSRWindow::OnBeforeClose(CefRefPtr browser) { 55 | PostMessage(browser->GetHost()->GetWindowHandle(), WM_CLOSE, 0, 0); 56 | } 57 | 58 | bool OSRWindow::GetRootScreenRect(CefRefPtr browser, 59 | CefRect& rect) { 60 | RECT window_rect = {0}; 61 | HWND root_window = GetAncestor(browser->GetHost()->GetWindowHandle(), GA_ROOT); 62 | if (::GetWindowRect(root_window, &window_rect)) { 63 | rect = CefRect(window_rect.left, 64 | window_rect.top, 65 | window_rect.right - window_rect.left, 66 | window_rect.bottom - window_rect.top); 67 | return true; 68 | } 69 | return false; 70 | } 71 | 72 | bool OSRWindow::GetViewRect(CefRefPtr browser, 73 | CefRect& rect) { 74 | RECT clientRect; 75 | if (!::GetClientRect(browser->GetHost()->GetWindowHandle(), &clientRect)) 76 | return false; 77 | rect.x = rect.y = 0; 78 | rect.width = clientRect.right; 79 | rect.height = clientRect.bottom; 80 | return true; 81 | } 82 | 83 | bool OSRWindow::GetScreenPoint(CefRefPtr browser, 84 | int viewX, 85 | int viewY, 86 | int& screenX, 87 | int& screenY) { 88 | if (!::IsWindow(browser->GetHost()->GetWindowHandle())) 89 | return false; 90 | 91 | // Convert the point from view coordinates to actual screen coordinates. 92 | POINT screen_pt = {viewX, viewY}; 93 | ClientToScreen(browser->GetHost()->GetWindowHandle(), &screen_pt); 94 | screenX = screen_pt.x; 95 | screenY = screen_pt.y; 96 | return true; 97 | } 98 | 99 | void OSRWindow::OnPopupShow(CefRefPtr browser, 100 | bool show) { 101 | if (!show) { 102 | CefRect dirty_rect = renderer_.popup_rect(); 103 | renderer_.ClearPopupRects(); 104 | browser->GetHost()->Invalidate(dirty_rect, PET_VIEW); 105 | } 106 | renderer_.OnPopupShow(browser, show); 107 | } 108 | 109 | void OSRWindow::OnPopupSize(CefRefPtr browser, 110 | const CefRect& rect) { 111 | renderer_.OnPopupSize(browser, rect); 112 | } 113 | 114 | void OSRWindow::OnPaint(CefRefPtr browser, 115 | PaintElementType type, 116 | const RectList& dirtyRects, 117 | const void* buffer, 118 | int width, int height) { 119 | /*if (painting_popup_) { 120 | renderer_.OnPaint(browser, type, dirtyRects, buffer, width, height); 121 | return; 122 | } 123 | if (!hDC_) 124 | EnableGL(); 125 | 126 | wglMakeCurrent(hDC_, hRC_); 127 | renderer_.OnPaint(browser, type, dirtyRects, buffer, width, height); 128 | if (type == PET_VIEW && !renderer_.popup_rect().IsEmpty()) { 129 | painting_popup_ = true; 130 | CefRect client_popup_rect(0, 0, 131 | renderer_.popup_rect().width, 132 | renderer_.popup_rect().height); 133 | browser->GetHost()->Invalidate(client_popup_rect, PET_POPUP); 134 | painting_popup_ = false; 135 | } 136 | renderer_.Render(); 137 | SwapBuffers(hDC_);*/ 138 | //::OutputDebugStringA("ON PAINT"); 139 | SIZE sz = {width, height}; 140 | HWND hWnd = browser->GetHost()->GetWindowHandle(); 141 | HDC hdc = GetDC(hWnd); 142 | HDC hMemDc = CreateCompatibleDC(hdc); 143 | HBITMAP hBitmap = CreateBitmap(width, height, 1, 32, buffer); 144 | HGDIOBJ hOldBitmap = SelectObject(hMemDc, hBitmap); 145 | 146 | BLENDFUNCTION _Blend; 147 | _Blend.BlendOp=AC_SRC_OVER; 148 | _Blend.BlendFlags=0; 149 | _Blend.AlphaFormat= AC_SRC_ALPHA; 150 | _Blend.SourceConstantAlpha=255; 151 | 152 | POINT pt = {0, 0}; 153 | 154 | ::UpdateLayeredWindow(hWnd, NULL, NULL, &sz, hMemDc, &pt, 0, &_Blend, ULW_ALPHA); 155 | 156 | SelectObject(hMemDc, hOldBitmap); 157 | DeleteObject(hBitmap); 158 | DeleteDC(hMemDc); 159 | } 160 | 161 | void OSRWindow::OnCursorChange(CefRefPtr browser, 162 | CefCursorHandle cursor) { 163 | HWND hWnd = browser->GetHost()->GetWindowHandle(); 164 | if (!::IsWindow(hWnd)) 165 | return; 166 | 167 | // Change the plugin window's cursor. 168 | SetClassLongPtr(hWnd, GCLP_HCURSOR, 169 | static_cast(reinterpret_cast(cursor))); 170 | SetCursor(cursor); 171 | } 172 | 173 | void OSRWindow::Invalidate() { 174 | if (!CefCurrentlyOn(TID_UI)) { 175 | CefPostTask(TID_UI, NewCefRunnableMethod(this, &OSRWindow::Invalidate)); 176 | return; 177 | } 178 | 179 | // Don't post another task if the previous task is still pending. 180 | if (render_task_pending_) 181 | return; 182 | 183 | render_task_pending_ = true; 184 | 185 | // Render at 30fps. 186 | static const int kRenderDelay = 1000 / 30; 187 | CefPostDelayedTask(TID_UI, NewCefRunnableMethod(this, &OSRWindow::Render), 188 | kRenderDelay); 189 | } 190 | 191 | OSRWindow::OSRWindow(HINSTANCE hInst, OSRBrowserProvider* browser_provider, bool transparent) 192 | : renderer_(transparent), 193 | browser_provider_(browser_provider), 194 | //hWnd_(NULL), 195 | hDC_(NULL), 196 | hRC_(NULL), 197 | hInst_(hInst), 198 | painting_popup_(false), 199 | render_task_pending_(false) { 200 | } 201 | 202 | OSRWindow::~OSRWindow() { 203 | DestroyWidget(); 204 | } 205 | 206 | void OSRWindow::Render() { 207 | ASSERT(CefCurrentlyOn(TID_UI)); 208 | if (render_task_pending_) 209 | render_task_pending_ = false; 210 | 211 | if (!hDC_) 212 | EnableGL(); 213 | 214 | wglMakeCurrent(hDC_, hRC_); 215 | renderer_.Render(); 216 | SwapBuffers(hDC_); 217 | } 218 | 219 | void OSRWindow::EnableGL() { 220 | /*ASSERT(CefCurrentlyOn(TID_UI)); 221 | 222 | PIXELFORMATDESCRIPTOR pfd; 223 | int format; 224 | 225 | // Get the device context. 226 | hDC_ = GetDC(hWnd_); 227 | 228 | // Set the pixel format for the DC. 229 | ZeroMemory(&pfd, sizeof(pfd)); 230 | pfd.nSize = sizeof(pfd); 231 | pfd.nVersion = 1; 232 | pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; 233 | pfd.iPixelType = PFD_TYPE_RGBA; 234 | pfd.cColorBits = 24; 235 | pfd.cDepthBits = 16; 236 | pfd.iLayerType = PFD_MAIN_PLANE; 237 | format = ChoosePixelFormat(hDC_, &pfd); 238 | SetPixelFormat(hDC_, format, &pfd); 239 | 240 | // Create and enable the render context. 241 | hRC_ = wglCreateContext(hDC_); 242 | wglMakeCurrent(hDC_, hRC_); 243 | 244 | renderer_.Initialize();*/ 245 | } 246 | 247 | void OSRWindow::DisableGL() { 248 | /*ASSERT(CefCurrentlyOn(TID_UI)); 249 | 250 | if (!hDC_) 251 | return; 252 | 253 | renderer_.Cleanup(); 254 | 255 | if (IsWindow(hWnd_)) { 256 | wglMakeCurrent(NULL, NULL); 257 | wglDeleteContext(hRC_); 258 | ReleaseDC(hWnd_, hDC_); 259 | } 260 | 261 | hDC_ = NULL; 262 | hRC_ = NULL;*/ 263 | } 264 | 265 | void OSRWindow::OnDestroyed(HWND hWnd) { 266 | SetWindowLongPtr(hWnd, GWLP_USERDATA, 0L); 267 | CefRefPtr browser = browser_provider_->GetBrowser(hWnd); 268 | if (browser.get()) { 269 | // Notify the browser window that we would like to close it. This 270 | // will result in a call to ClientHandler::DoClose() if the 271 | // JavaScript 'onbeforeunload' event handler allows it. 272 | browser->GetHost()->CloseBrowser(false); 273 | } 274 | Release(); 275 | } 276 | 277 | ATOM OSRWindow::RegisterOSRClass(HINSTANCE hInstance, LPCTSTR className) { 278 | WNDCLASSEX wcex; 279 | 280 | wcex.cbSize = sizeof(WNDCLASSEX); 281 | wcex.style = CS_OWNDC; 282 | wcex.lpfnWndProc = &OSRWindow::WndProc; 283 | wcex.cbClsExtra = 0; 284 | wcex.cbWndExtra = 0; 285 | wcex.hInstance = hInstance; 286 | wcex.hIcon = NULL; 287 | wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 288 | wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 289 | wcex.lpszMenuName = NULL; 290 | wcex.lpszClassName = className; 291 | wcex.hIconSm = NULL; 292 | return RegisterClassEx(&wcex); 293 | } 294 | 295 | bool OSRWindow::isKeyDown(WPARAM wparam) { 296 | return (GetKeyState(wparam) & 0x8000) != 0; 297 | } 298 | 299 | int OSRWindow::GetCefMouseModifiers(WPARAM wparam) { 300 | int modifiers = 0; 301 | if (wparam & MK_CONTROL) 302 | modifiers |= EVENTFLAG_CONTROL_DOWN; 303 | if (wparam & MK_SHIFT) 304 | modifiers |= EVENTFLAG_SHIFT_DOWN; 305 | if (isKeyDown(VK_MENU)) 306 | modifiers |= EVENTFLAG_ALT_DOWN; 307 | if (wparam & MK_LBUTTON) 308 | modifiers |= EVENTFLAG_LEFT_MOUSE_BUTTON; 309 | if (wparam & MK_MBUTTON) 310 | modifiers |= EVENTFLAG_MIDDLE_MOUSE_BUTTON; 311 | if (wparam & MK_RBUTTON) 312 | modifiers |= EVENTFLAG_RIGHT_MOUSE_BUTTON; 313 | 314 | // Low bit set from GetKeyState indicates "toggled". 315 | if (::GetKeyState(VK_NUMLOCK) & 1) 316 | modifiers |= EVENTFLAG_NUM_LOCK_ON; 317 | if (::GetKeyState(VK_CAPITAL) & 1) 318 | modifiers |= EVENTFLAG_CAPS_LOCK_ON; 319 | return modifiers; 320 | } 321 | 322 | int OSRWindow::GetCefKeyboardModifiers(WPARAM wparam, LPARAM lparam) { 323 | int modifiers = 0; 324 | if (isKeyDown(VK_SHIFT)) 325 | modifiers |= EVENTFLAG_SHIFT_DOWN; 326 | if (isKeyDown(VK_CONTROL)) 327 | modifiers |= EVENTFLAG_CONTROL_DOWN; 328 | if (isKeyDown(VK_MENU)) 329 | modifiers |= EVENTFLAG_ALT_DOWN; 330 | 331 | // Low bit set from GetKeyState indicates "toggled". 332 | if (::GetKeyState(VK_NUMLOCK) & 1) 333 | modifiers |= EVENTFLAG_NUM_LOCK_ON; 334 | if (::GetKeyState(VK_CAPITAL) & 1) 335 | modifiers |= EVENTFLAG_CAPS_LOCK_ON; 336 | 337 | switch (wparam) { 338 | case VK_RETURN: 339 | if ((lparam >> 16) & KF_EXTENDED) 340 | modifiers |= EVENTFLAG_IS_KEY_PAD; 341 | break; 342 | case VK_INSERT: 343 | case VK_DELETE: 344 | case VK_HOME: 345 | case VK_END: 346 | case VK_PRIOR: 347 | case VK_NEXT: 348 | case VK_UP: 349 | case VK_DOWN: 350 | case VK_LEFT: 351 | case VK_RIGHT: 352 | if (!((lparam >> 16) & KF_EXTENDED)) 353 | modifiers |= EVENTFLAG_IS_KEY_PAD; 354 | break; 355 | case VK_NUMLOCK: 356 | case VK_NUMPAD0: 357 | case VK_NUMPAD1: 358 | case VK_NUMPAD2: 359 | case VK_NUMPAD3: 360 | case VK_NUMPAD4: 361 | case VK_NUMPAD5: 362 | case VK_NUMPAD6: 363 | case VK_NUMPAD7: 364 | case VK_NUMPAD8: 365 | case VK_NUMPAD9: 366 | case VK_DIVIDE: 367 | case VK_MULTIPLY: 368 | case VK_SUBTRACT: 369 | case VK_ADD: 370 | case VK_DECIMAL: 371 | case VK_CLEAR: 372 | modifiers |= EVENTFLAG_IS_KEY_PAD; 373 | break; 374 | case VK_SHIFT: 375 | if (isKeyDown(VK_LSHIFT)) 376 | modifiers |= EVENTFLAG_IS_LEFT; 377 | else if (isKeyDown(VK_RSHIFT)) 378 | modifiers |= EVENTFLAG_IS_RIGHT; 379 | break; 380 | case VK_CONTROL: 381 | if (isKeyDown(VK_LCONTROL)) 382 | modifiers |= EVENTFLAG_IS_LEFT; 383 | else if (isKeyDown(VK_RCONTROL)) 384 | modifiers |= EVENTFLAG_IS_RIGHT; 385 | break; 386 | case VK_MENU: 387 | if (isKeyDown(VK_LMENU)) 388 | modifiers |= EVENTFLAG_IS_LEFT; 389 | else if (isKeyDown(VK_RMENU)) 390 | modifiers |= EVENTFLAG_IS_RIGHT; 391 | break; 392 | case VK_LWIN: 393 | modifiers |= EVENTFLAG_IS_LEFT; 394 | break; 395 | case VK_RWIN: 396 | modifiers |= EVENTFLAG_IS_RIGHT; 397 | break; 398 | } 399 | return modifiers; 400 | } 401 | 402 | bool OSRWindow::IsOverPopupWidget(int x, int y) const { 403 | const CefRect& rc = renderer_.popup_rect(); 404 | int popup_right = rc.x + rc.width; 405 | int popup_bottom = rc.y + rc.height; 406 | return (x >= rc.x) && (x < popup_right) && 407 | (y >= rc.y) && (y < popup_bottom); 408 | } 409 | 410 | int OSRWindow::GetPopupXOffset() const { 411 | return renderer_.original_popup_rect().x - renderer_.popup_rect().x; 412 | } 413 | 414 | int OSRWindow::GetPopupYOffset() const { 415 | return renderer_.original_popup_rect().y - renderer_.popup_rect().y; 416 | } 417 | 418 | void OSRWindow::ApplyPopupOffset(int& x, int& y) const { 419 | if (IsOverPopupWidget(x, y)) { 420 | x += GetPopupXOffset(); 421 | y += GetPopupYOffset(); 422 | } 423 | } 424 | 425 | // Plugin window procedure. 426 | // static 427 | LRESULT CALLBACK OSRWindow::WndProc(HWND hWnd, UINT message, 428 | WPARAM wParam, LPARAM lParam) { 429 | static POINT lastMousePos, curMousePos; 430 | static bool mouseRotation = false; 431 | static bool mouseTracking = false; 432 | 433 | static int lastClickX = 0; 434 | static int lastClickY = 0; 435 | static CefBrowserHost::MouseButtonType lastClickButton = MBT_LEFT; 436 | static int gLastClickCount = 0; 437 | static double gLastClickTime = 0; 438 | 439 | static bool gLastMouseDownOnView = false; 440 | 441 | OSRWindow* window = 442 | reinterpret_cast(GetWindowLongPtr(hWnd, GWLP_USERDATA)); 443 | 444 | CefRefPtr browser; 445 | if (window && window->browser_provider_->GetBrowser(hWnd).get()) 446 | browser = window->browser_provider_->GetBrowser(hWnd)->GetHost(); 447 | 448 | LONG currentTime = 0; 449 | bool cancelPreviousClick = false; 450 | 451 | if (message == WM_LBUTTONDOWN || message == WM_RBUTTONDOWN || 452 | message == WM_MBUTTONDOWN || message == WM_MOUSEMOVE || 453 | message == WM_MOUSELEAVE) { 454 | currentTime = GetMessageTime(); 455 | int x = GET_X_LPARAM(lParam); 456 | int y = GET_Y_LPARAM(lParam); 457 | cancelPreviousClick = 458 | (abs(lastClickX - x) > (GetSystemMetrics(SM_CXDOUBLECLK) / 2)) 459 | || (abs(lastClickY - y) > (GetSystemMetrics(SM_CYDOUBLECLK) / 2)) 460 | || ((currentTime - gLastClickTime) > GetDoubleClickTime()); 461 | if (cancelPreviousClick && 462 | (message == WM_MOUSEMOVE || message == WM_MOUSELEAVE)) { 463 | gLastClickCount = 0; 464 | lastClickX = 0; 465 | lastClickY = 0; 466 | gLastClickTime = 0; 467 | } 468 | } 469 | 470 | switch (message) { 471 | case WM_SYSCOMMAND: { 472 | switch(wParam) { 473 | case SC_MINIMIZE: { 474 | ::MessageBox(NULL, L"minimize", NULL, 0); 475 | return 0; 476 | } 477 | case SC_MAXIMIZE: { 478 | ::MessageBox(NULL, L"maximize", NULL, 0); 479 | } 480 | } 481 | } 482 | break; 483 | case WM_GETMINMAXINFO: 484 | { 485 | MINMAXINFO *lpMMI = (MINMAXINFO*)lParam; 486 | lpMMI->ptMaxSize.x = GetSystemMetrics(SM_CXFULLSCREEN); 487 | lpMMI->ptMaxSize.y = GetSystemMetrics(SM_CYFULLSCREEN) + GetSystemMetrics(SM_CYCAPTION); 488 | } 489 | break; 490 | case WM_DESTROY: 491 | if (window) 492 | window->OnDestroyed(hWnd); 493 | return 0; 494 | 495 | case WM_LBUTTONDOWN: 496 | case WM_RBUTTONDOWN: 497 | case WM_MBUTTONDOWN: { 498 | SetCapture(hWnd); 499 | SetFocus(hWnd); 500 | int x = GET_X_LPARAM(lParam); 501 | int y = GET_Y_LPARAM(lParam); 502 | if (wParam & MK_SHIFT) { 503 | // Start rotation effect. 504 | lastMousePos.x = curMousePos.x = x; 505 | lastMousePos.y = curMousePos.y = y; 506 | mouseRotation = true; 507 | } else { 508 | CefBrowserHost::MouseButtonType btnType = 509 | (message == WM_LBUTTONDOWN ? MBT_LEFT : ( 510 | message == WM_RBUTTONDOWN ? MBT_RIGHT : MBT_MIDDLE)); 511 | if (!cancelPreviousClick && (btnType == lastClickButton)) { 512 | ++gLastClickCount; 513 | } else { 514 | gLastClickCount = 1; 515 | lastClickX = x; 516 | lastClickY = y; 517 | } 518 | gLastClickTime = currentTime; 519 | lastClickButton = btnType; 520 | 521 | if (browser.get()) { 522 | CefMouseEvent mouse_event; 523 | mouse_event.x = x; 524 | mouse_event.y = y; 525 | gLastMouseDownOnView = !window->IsOverPopupWidget(x, y); 526 | window->ApplyPopupOffset(mouse_event.x, mouse_event.y); 527 | mouse_event.modifiers = GetCefMouseModifiers(wParam); 528 | browser->SendMouseClickEvent(mouse_event, btnType, false, 529 | gLastClickCount); 530 | } 531 | } 532 | break; 533 | } 534 | 535 | case WM_LBUTTONUP: 536 | case WM_RBUTTONUP: 537 | case WM_MBUTTONUP: 538 | if (GetCapture() == hWnd) 539 | ReleaseCapture(); 540 | if (mouseRotation) { 541 | // End rotation effect. 542 | mouseRotation = false; 543 | window->renderer_.SetSpin(0, 0); 544 | window->Invalidate(); 545 | } else { 546 | int x = GET_X_LPARAM(lParam); 547 | int y = GET_Y_LPARAM(lParam); 548 | CefBrowserHost::MouseButtonType btnType = 549 | (message == WM_LBUTTONUP ? MBT_LEFT : ( 550 | message == WM_RBUTTONUP ? MBT_RIGHT : MBT_MIDDLE)); 551 | if (browser.get()) { 552 | CefMouseEvent mouse_event; 553 | mouse_event.x = x; 554 | mouse_event.y = y; 555 | if (gLastMouseDownOnView && 556 | window->IsOverPopupWidget(x, y) && 557 | (window->GetPopupXOffset() || window->GetPopupYOffset())) { 558 | break; 559 | } 560 | window->ApplyPopupOffset(mouse_event.x, mouse_event.y); 561 | mouse_event.modifiers = GetCefMouseModifiers(wParam); 562 | browser->SendMouseClickEvent(mouse_event, btnType, true, 563 | gLastClickCount); 564 | } 565 | } 566 | break; 567 | 568 | case WM_MOUSEMOVE: { 569 | int x = GET_X_LPARAM(lParam); 570 | int y = GET_Y_LPARAM(lParam); 571 | if (mouseRotation) { 572 | // Apply rotation effect. 573 | curMousePos.x = x; 574 | curMousePos.y = y; 575 | window->renderer_.IncrementSpin((curMousePos.x - lastMousePos.x), 576 | (curMousePos.y - lastMousePos.y)); 577 | lastMousePos.x = curMousePos.x; 578 | lastMousePos.y = curMousePos.y; 579 | window->Invalidate(); 580 | } else { 581 | if (!mouseTracking) { 582 | // Start tracking mouse leave. Required for the WM_MOUSELEAVE event to 583 | // be generated. 584 | TRACKMOUSEEVENT tme; 585 | tme.cbSize = sizeof(TRACKMOUSEEVENT); 586 | tme.dwFlags = TME_LEAVE; 587 | tme.hwndTrack = hWnd; 588 | TrackMouseEvent(&tme); 589 | mouseTracking = true; 590 | } 591 | if (browser.get()) { 592 | CefMouseEvent mouse_event; 593 | mouse_event.x = x; 594 | mouse_event.y = y; 595 | window->ApplyPopupOffset(mouse_event.x, mouse_event.y); 596 | mouse_event.modifiers = GetCefMouseModifiers(wParam); 597 | browser->SendMouseMoveEvent(mouse_event, false); 598 | } 599 | } 600 | break; 601 | } 602 | 603 | case WM_MOUSELEAVE: 604 | if (mouseTracking) { 605 | // Stop tracking mouse leave. 606 | TRACKMOUSEEVENT tme; 607 | tme.cbSize = sizeof(TRACKMOUSEEVENT); 608 | tme.dwFlags = TME_LEAVE & TME_CANCEL; 609 | tme.hwndTrack = hWnd; 610 | TrackMouseEvent(&tme); 611 | mouseTracking = false; 612 | } 613 | if (browser.get()) { 614 | CefMouseEvent mouse_event; 615 | mouse_event.x = 0; 616 | mouse_event.y = 0; 617 | mouse_event.modifiers = GetCefMouseModifiers(wParam); 618 | browser->SendMouseMoveEvent(mouse_event, true); 619 | } 620 | break; 621 | 622 | case WM_MOUSEWHEEL: 623 | if (browser.get()) { 624 | POINT screen_point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; 625 | HWND scrolled_wnd = ::WindowFromPoint(screen_point); 626 | if (scrolled_wnd != hWnd) { 627 | break; 628 | } 629 | ScreenToClient(hWnd, &screen_point); 630 | int delta = GET_WHEEL_DELTA_WPARAM(wParam); 631 | 632 | CefMouseEvent mouse_event; 633 | mouse_event.x = screen_point.x; 634 | mouse_event.y = screen_point.y; 635 | window->ApplyPopupOffset(mouse_event.x, mouse_event.y); 636 | mouse_event.modifiers = GetCefMouseModifiers(wParam); 637 | 638 | browser->SendMouseWheelEvent(mouse_event, 639 | isKeyDown(VK_SHIFT) ? delta : 0, 640 | !isKeyDown(VK_SHIFT) ? delta : 0); 641 | } 642 | break; 643 | 644 | case WM_SIZE: 645 | if (browser.get()) 646 | browser->WasResized(); 647 | break; 648 | 649 | case WM_SETFOCUS: 650 | case WM_KILLFOCUS: 651 | if (browser.get()) 652 | browser->SendFocusEvent(message == WM_SETFOCUS); 653 | break; 654 | 655 | case WM_CAPTURECHANGED: 656 | case WM_CANCELMODE: 657 | if (!mouseRotation) { 658 | if (browser.get()) 659 | browser->SendCaptureLostEvent(); 660 | } 661 | break; 662 | case WM_SYSCHAR: 663 | case WM_SYSKEYDOWN: 664 | case WM_SYSKEYUP: 665 | case WM_KEYDOWN: 666 | case WM_KEYUP: 667 | case WM_CHAR: { 668 | CefKeyEvent event; 669 | event.windows_key_code = wParam; 670 | event.native_key_code = lParam; 671 | event.is_system_key = message == WM_SYSCHAR || 672 | message == WM_SYSKEYDOWN || 673 | message == WM_SYSKEYUP; 674 | 675 | if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN) 676 | event.type = KEYEVENT_RAWKEYDOWN; 677 | else if (message == WM_KEYUP || message == WM_SYSKEYUP) 678 | event.type = KEYEVENT_KEYUP; 679 | else 680 | event.type = KEYEVENT_CHAR; 681 | event.modifiers = GetCefKeyboardModifiers(wParam, lParam); 682 | if (browser.get()) 683 | browser->SendKeyEvent(event); 684 | break; 685 | } 686 | 687 | case WM_PAINT: { 688 | PAINTSTRUCT ps; 689 | RECT rc; 690 | BeginPaint(hWnd, &ps); 691 | rc = ps.rcPaint; 692 | EndPaint(hWnd, &ps); 693 | if (browser.get()) { 694 | browser->Invalidate(CefRect(rc.left, 695 | rc.top, 696 | rc.right - rc.left, 697 | rc.bottom - rc.top), PET_VIEW); 698 | } 699 | return 0; 700 | } 701 | 702 | case WM_ERASEBKGND: 703 | return 0; 704 | 705 | case ID_OPENMAINWINDOW: { 706 | RECT rect; 707 | rect.right = GetSystemMetrics(SM_CXFULLSCREEN); 708 | rect.bottom = GetSystemMetrics(SM_CYFULLSCREEN) + GetSystemMetrics(SM_CYCAPTION); 709 | rect.left = 0; 710 | rect.top = 0; 711 | 712 | HWND hWnd = window->CreateWidget(NULL, rect, L"DoomTool", L"DoomToolWnd"); 713 | CefWindowInfo info; 714 | CefBrowserSettings browser_settings; 715 | info.SetAsOffScreen(hWnd); 716 | info.SetTransparentPainting(TRUE); 717 | CefBrowserHost::CreateBrowser(info, browser->GetClient().get(), 718 | L"http://localhost/", browser_settings, NULL); 719 | return 0; 720 | } 721 | 722 | } 723 | 724 | return DefWindowProc(hWnd, message, wParam, lParam); 725 | } 726 | -------------------------------------------------------------------------------- /doomtool/cefclient_osr_widget_win.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_WIN_H_ 6 | #define CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_WIN_H_ 7 | #pragma once 8 | 9 | #include "include/cef_render_handler.h" 10 | #include "client_handler.h" 11 | #include "osrenderer.h" 12 | 13 | class OSRBrowserProvider { 14 | public: 15 | virtual CefRefPtr GetBrowser(HWND hWnd) =0; 16 | 17 | protected: 18 | virtual ~OSRBrowserProvider() {} 19 | }; 20 | 21 | class OSRWindow : public ClientHandler::RenderHandler { 22 | public: 23 | // Create a new OSRWindow instance. |browser_provider| must outlive this 24 | // object. 25 | static CefRefPtr Create(HINSTANCE hInst, 26 | OSRBrowserProvider* browser_provider, 27 | bool transparent); 28 | 29 | static CefRefPtr From( 30 | CefRefPtr renderHandler); 31 | 32 | // Create the underlying window. 33 | HWND CreateWidget(HWND hWndParent, const RECT& rect, LPCTSTR windowName, LPCTSTR className); 34 | 35 | // Destroy the underlying window. 36 | void DestroyWidget(); 37 | 38 | /*HWND hwnd() const { 39 | return hWnd_; 40 | }*/ 41 | 42 | // ClientHandler::RenderHandler methods 43 | virtual void OnBeforeClose(CefRefPtr browser) OVERRIDE; 44 | 45 | // CefRenderHandler methods 46 | virtual bool GetRootScreenRect(CefRefPtr browser, 47 | CefRect& rect) OVERRIDE; 48 | virtual bool GetViewRect(CefRefPtr browser, 49 | CefRect& rect) OVERRIDE; 50 | virtual bool GetScreenPoint(CefRefPtr browser, 51 | int viewX, 52 | int viewY, 53 | int& screenX, 54 | int& screenY) OVERRIDE; 55 | virtual void OnPopupShow(CefRefPtr browser, 56 | bool show) OVERRIDE; 57 | virtual void OnPopupSize(CefRefPtr browser, 58 | const CefRect& rect) OVERRIDE; 59 | virtual void OnPaint(CefRefPtr browser, 60 | PaintElementType type, 61 | const RectList& dirtyRects, 62 | const void* buffer, 63 | int width, 64 | int height) OVERRIDE; 65 | virtual void OnCursorChange(CefRefPtr browser, 66 | CefCursorHandle cursor) OVERRIDE; 67 | 68 | void Invalidate(); 69 | 70 | private: 71 | OSRWindow(HINSTANCE hInst, OSRBrowserProvider* browser_provider, bool transparent); 72 | virtual ~OSRWindow(); 73 | 74 | void Render(); 75 | void EnableGL(); 76 | void DisableGL(); 77 | void OnDestroyed(HWND hWnd); 78 | static ATOM RegisterOSRClass(HINSTANCE hInstance, LPCTSTR className); 79 | static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, 80 | LPARAM lParam); 81 | static int GetCefKeyboardModifiers(WPARAM wparam, LPARAM lparam); 82 | static int GetCefMouseModifiers(WPARAM wparam); 83 | static bool isKeyDown(WPARAM wparam); 84 | bool IsOverPopupWidget(int x, int y) const; 85 | int GetPopupXOffset() const; 86 | int GetPopupYOffset() const; 87 | void ApplyPopupOffset(int& x, int& y) const; 88 | 89 | ClientOSRenderer renderer_; 90 | OSRBrowserProvider* browser_provider_; 91 | //HWND hWnd_; 92 | HDC hDC_; 93 | HGLRC hRC_; 94 | HINSTANCE hInst_; 95 | 96 | bool painting_popup_; 97 | bool render_task_pending_; 98 | 99 | IMPLEMENT_REFCOUNTING(OSRWindow); 100 | }; 101 | 102 | #endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_WIN_H_ 103 | -------------------------------------------------------------------------------- /doomtool/cefclient_win.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include 6 | 7 | #include "client_app.h" 8 | #include "cefclient_osr_widget_win.h" 9 | #include "resource.h" 10 | 11 | CefRefPtr g_handler; 12 | 13 | class MainBrowserProvider : public OSRBrowserProvider { 14 | virtual CefRefPtr GetBrowser(HWND hWnd) { 15 | if (g_handler.get()) 16 | return g_handler->GetBrowser(hWnd); 17 | 18 | return NULL; 19 | } 20 | } g_main_browser_provider; 21 | 22 | // Entry point function for all processes. 23 | int APIENTRY wWinMain(HINSTANCE hInstance, 24 | HINSTANCE hPrevInstance, 25 | LPTSTR lpCmdLine, 26 | int nCmdShow) { 27 | UNREFERENCED_PARAMETER(hPrevInstance); 28 | UNREFERENCED_PARAMETER(lpCmdLine); 29 | //MessageBoxA(NULL, "main", NULL, 0); 30 | // Provide CEF with command-line arguments. 31 | CefMainArgs main_args(hInstance); 32 | 33 | // SimpleApp implements application-level callbacks. It will create the first 34 | // browser instance in OnContextInitialized() after CEF has initialized. 35 | CefRefPtr app(new ClientApp); 36 | 37 | // CEF applications have multiple sub-processes (render, plugin, GPU, etc) 38 | // that share the same executable. This function checks the command-line and, 39 | // if this is a sub-process, executes the appropriate logic. 40 | int exit_code = CefExecuteProcess(main_args, app.get()); 41 | if (exit_code >= 0) { 42 | // The sub-process has completed so return here. 43 | return exit_code; 44 | } 45 | 46 | // Try to open the mutex. 47 | HANDLE hMutex = ::OpenMutex(MUTEX_ALL_ACCESS, 0, L"DoomToolInstance"); 48 | 49 | // If hMutex is 0 then the mutex doesn't exist. 50 | if (!hMutex) { 51 | hMutex = ::CreateMutex(0, 0, L"DoomToolInstance"); 52 | } else { 53 | // This is a second instance. Bring the 54 | // original instance to the top. 55 | HWND hWnd; 56 | hWnd = ::FindWindow(L"DoomToolWnd", NULL); 57 | if(hWnd) { 58 | ::SetForegroundWindow(hWnd); 59 | ::ShowWindow(hWnd, SW_RESTORE); 60 | } else { 61 | hWnd = ::FindWindow(L"DoomToolPopUpWnd", NULL); 62 | if(hWnd) 63 | ::PostMessage(hWnd ,ID_OPENMAINWINDOW, 0, 0); 64 | } 65 | return 0; 66 | } 67 | 68 | // Specify CEF global settings here. 69 | CefSettings settings; 70 | CefString(&settings.browser_subprocess_path).FromASCII("G:/project/doomtool/build/Release/doomtool.exe"); 71 | // Initialize CEF. 72 | CefInitialize(main_args, settings, app.get()); 73 | 74 | // Create the single static handler class instance 75 | g_handler = new ClientHandler(); 76 | 77 | CefWindowInfo info; 78 | CefBrowserSettings browser_settings; 79 | 80 | 81 | CefRefPtr osr_window = OSRWindow::Create(hInstance, &g_main_browser_provider, TRUE); 82 | 83 | g_handler->SetOSRHandler(osr_window.get()); 84 | 85 | RECT rect; 86 | rect.right = GetSystemMetrics(SM_CXFULLSCREEN); 87 | rect.bottom = GetSystemMetrics(SM_CYFULLSCREEN) + GetSystemMetrics(SM_CYCAPTION); 88 | rect.left = 0; 89 | rect.top = 0; 90 | 91 | HWND hWnd = osr_window->CreateWidget(NULL, rect, L"DoomTool", L"DoomToolWnd"); 92 | CefWindowInfo info2; 93 | info2.SetAsOffScreen(hWnd); 94 | info2.SetTransparentPainting(TRUE); 95 | CefBrowserHost::CreateBrowser(info2, g_handler.get(), 96 | g_handler->GetStartupURL(), browser_settings, NULL); 97 | 98 | // Run the CEF message loop. This will block until CefQuitMessageLoop() is 99 | // called. 100 | CefRunMessageLoop(); 101 | 102 | // Shut down CEF. 103 | CefShutdown(); 104 | 105 | ReleaseMutex(hMutex); 106 | 107 | return 0; 108 | } 109 | -------------------------------------------------------------------------------- /doomtool/client_app.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | // This file is shared by cefclient and cef_unittests so don't include using 6 | // a qualified path. 7 | #include "client_app.h" // NOLINT(build/include) 8 | #include "client_handler.h" 9 | 10 | #include 11 | 12 | #include "include/cef_cookie.h" 13 | #include "include/cef_process_message.h" 14 | #include "include/cef_task.h" 15 | #include "include/cef_v8.h" 16 | #include "util.h" // NOLINT(build/include) 17 | 18 | ClientApp::ClientApp() { 19 | } 20 | 21 | void ClientApp::OnRegisterCustomSchemes( 22 | CefRefPtr registrar) { 23 | // Default schemes that support cookies. 24 | cookieable_schemes_.push_back("http"); 25 | cookieable_schemes_.push_back("https"); 26 | 27 | RegisterCustomSchemes(registrar, cookieable_schemes_); 28 | } 29 | 30 | void ClientApp::OnContextInitialized() { 31 | //REQUIRE_UI_THREAD(); 32 | 33 | CreateBrowserDelegates(browser_delegates_); 34 | 35 | // Register cookieable schemes with the global cookie manager. 36 | CefRefPtr manager = CefCookieManager::GetGlobalManager(); 37 | ASSERT(manager.get()); 38 | manager->SetSupportedSchemes(cookieable_schemes_); 39 | 40 | BrowserDelegateSet::iterator it = browser_delegates_.begin(); 41 | for (; it != browser_delegates_.end(); ++it) 42 | (*it)->OnContextInitialized(this); 43 | } 44 | 45 | void ClientApp::OnBeforeChildProcessLaunch( 46 | CefRefPtr command_line) { 47 | BrowserDelegateSet::iterator it = browser_delegates_.begin(); 48 | for (; it != browser_delegates_.end(); ++it) 49 | (*it)->OnBeforeChildProcessLaunch(this, command_line); 50 | } 51 | 52 | void ClientApp::OnRenderProcessThreadCreated( 53 | CefRefPtr extra_info) { 54 | BrowserDelegateSet::iterator it = browser_delegates_.begin(); 55 | for (; it != browser_delegates_.end(); ++it) 56 | (*it)->OnRenderProcessThreadCreated(this, extra_info); 57 | } 58 | 59 | void ClientApp::OnRenderThreadCreated(CefRefPtr extra_info) { 60 | CreateRenderDelegates(render_delegates_); 61 | 62 | RenderDelegateSet::iterator it = render_delegates_.begin(); 63 | for (; it != render_delegates_.end(); ++it) 64 | (*it)->OnRenderThreadCreated(this, extra_info); 65 | } 66 | 67 | void ClientApp::OnWebKitInitialized() { 68 | RenderDelegateSet::iterator it = render_delegates_.begin(); 69 | for (; it != render_delegates_.end(); ++it) 70 | (*it)->OnWebKitInitialized(this); 71 | } 72 | 73 | void ClientApp::OnBrowserCreated(CefRefPtr browser) { 74 | RenderDelegateSet::iterator it = render_delegates_.begin(); 75 | for (; it != render_delegates_.end(); ++it) 76 | (*it)->OnBrowserCreated(this, browser); 77 | } 78 | 79 | void ClientApp::OnBrowserDestroyed(CefRefPtr browser) { 80 | RenderDelegateSet::iterator it = render_delegates_.begin(); 81 | for (; it != render_delegates_.end(); ++it) 82 | (*it)->OnBrowserDestroyed(this, browser); 83 | } 84 | 85 | CefRefPtr ClientApp::GetLoadHandler() { 86 | CefRefPtr load_handler; 87 | RenderDelegateSet::iterator it = render_delegates_.begin(); 88 | for (; it != render_delegates_.end() && !load_handler.get(); ++it) 89 | load_handler = (*it)->GetLoadHandler(this); 90 | 91 | return load_handler; 92 | } 93 | 94 | bool ClientApp::OnBeforeNavigation(CefRefPtr browser, 95 | CefRefPtr frame, 96 | CefRefPtr request, 97 | NavigationType navigation_type, 98 | bool is_redirect) { 99 | RenderDelegateSet::iterator it = render_delegates_.begin(); 100 | for (; it != render_delegates_.end(); ++it) { 101 | if ((*it)->OnBeforeNavigation(this, browser, frame, request, 102 | navigation_type, is_redirect)) { 103 | return true; 104 | } 105 | } 106 | 107 | return false; 108 | } 109 | 110 | void ClientApp::OnContextCreated(CefRefPtr browser, 111 | CefRefPtr frame, 112 | CefRefPtr context) { 113 | RenderDelegateSet::iterator it = render_delegates_.begin(); 114 | for (; it != render_delegates_.end(); ++it) 115 | (*it)->OnContextCreated(this, browser, frame, context); 116 | } 117 | 118 | void ClientApp::OnContextReleased(CefRefPtr browser, 119 | CefRefPtr frame, 120 | CefRefPtr context) { 121 | RenderDelegateSet::iterator it = render_delegates_.begin(); 122 | for (; it != render_delegates_.end(); ++it) 123 | (*it)->OnContextReleased(this, browser, frame, context); 124 | } 125 | 126 | void ClientApp::OnUncaughtException(CefRefPtr browser, 127 | CefRefPtr frame, 128 | CefRefPtr context, 129 | CefRefPtr exception, 130 | CefRefPtr stackTrace) { 131 | RenderDelegateSet::iterator it = render_delegates_.begin(); 132 | for (; it != render_delegates_.end(); ++it) { 133 | (*it)->OnUncaughtException(this, browser, frame, context, exception, 134 | stackTrace); 135 | } 136 | } 137 | 138 | void ClientApp::OnFocusedNodeChanged(CefRefPtr browser, 139 | CefRefPtr frame, 140 | CefRefPtr node) { 141 | RenderDelegateSet::iterator it = render_delegates_.begin(); 142 | for (; it != render_delegates_.end(); ++it) 143 | (*it)->OnFocusedNodeChanged(this, browser, frame, node); 144 | } 145 | 146 | bool ClientApp::OnProcessMessageReceived( 147 | CefRefPtr browser, 148 | CefProcessId source_process, 149 | CefRefPtr message) { 150 | ASSERT(source_process == PID_BROWSER); 151 | 152 | bool handled = false; 153 | 154 | RenderDelegateSet::iterator it = render_delegates_.begin(); 155 | for (; it != render_delegates_.end() && !handled; ++it) { 156 | handled = (*it)->OnProcessMessageReceived(this, browser, source_process, 157 | message); 158 | } 159 | 160 | return handled; 161 | } 162 | -------------------------------------------------------------------------------- /doomtool/client_app.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #ifndef CEF_TESTS_CEFCLIENT_CLIENT_APP_H_ 6 | #define CEF_TESTS_CEFCLIENT_CLIENT_APP_H_ 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "include/cef_app.h" 15 | 16 | class ClientApp : public CefApp, 17 | public CefBrowserProcessHandler, 18 | public CefRenderProcessHandler { 19 | public: 20 | // Interface for browser delegates. All BrowserDelegates must be returned via 21 | // CreateBrowserDelegates. Do not perform work in the BrowserDelegate 22 | // constructor. See CefBrowserProcessHandler for documentation. 23 | class BrowserDelegate : public virtual CefBase { 24 | public: 25 | virtual void OnContextInitialized(CefRefPtr app) {} 26 | 27 | virtual void OnBeforeChildProcessLaunch( 28 | CefRefPtr app, 29 | CefRefPtr command_line) {} 30 | 31 | virtual void OnRenderProcessThreadCreated( 32 | CefRefPtr app, 33 | CefRefPtr extra_info) {} 34 | }; 35 | 36 | typedef std::set > BrowserDelegateSet; 37 | 38 | // Interface for renderer delegates. All RenderDelegates must be returned via 39 | // CreateRenderDelegates. Do not perform work in the RenderDelegate 40 | // constructor. See CefRenderProcessHandler for documentation. 41 | class RenderDelegate : public virtual CefBase { 42 | public: 43 | virtual void OnRenderThreadCreated(CefRefPtr app, 44 | CefRefPtr extra_info) {} 45 | 46 | virtual void OnWebKitInitialized(CefRefPtr app) {} 47 | 48 | virtual void OnBrowserCreated(CefRefPtr app, 49 | CefRefPtr browser) {} 50 | 51 | virtual void OnBrowserDestroyed(CefRefPtr app, 52 | CefRefPtr browser) {} 53 | 54 | virtual CefRefPtr GetLoadHandler(CefRefPtr app) { 55 | return NULL; 56 | } 57 | 58 | virtual bool OnBeforeNavigation(CefRefPtr app, 59 | CefRefPtr browser, 60 | CefRefPtr frame, 61 | CefRefPtr request, 62 | cef_navigation_type_t navigation_type, 63 | bool is_redirect) { 64 | return false; 65 | } 66 | 67 | virtual void OnContextCreated(CefRefPtr app, 68 | CefRefPtr browser, 69 | CefRefPtr frame, 70 | CefRefPtr context) {} 71 | 72 | virtual void OnContextReleased(CefRefPtr app, 73 | CefRefPtr browser, 74 | CefRefPtr frame, 75 | CefRefPtr context) {} 76 | 77 | virtual void OnUncaughtException(CefRefPtr app, 78 | CefRefPtr browser, 79 | CefRefPtr frame, 80 | CefRefPtr context, 81 | CefRefPtr exception, 82 | CefRefPtr stackTrace) {} 83 | 84 | virtual void OnFocusedNodeChanged(CefRefPtr app, 85 | CefRefPtr browser, 86 | CefRefPtr frame, 87 | CefRefPtr node) {} 88 | 89 | // Called when a process message is received. Return true if the message was 90 | // handled and should not be passed on to other handlers. RenderDelegates 91 | // should check for unique message names to avoid interfering with each 92 | // other. 93 | virtual bool OnProcessMessageReceived( 94 | CefRefPtr app, 95 | CefRefPtr browser, 96 | CefProcessId source_process, 97 | CefRefPtr message) { 98 | return false; 99 | } 100 | }; 101 | 102 | typedef std::set > RenderDelegateSet; 103 | 104 | ClientApp(); 105 | 106 | private: 107 | // Creates all of the BrowserDelegate objects. Implemented in 108 | // client_app_delegates. 109 | static void CreateBrowserDelegates(BrowserDelegateSet& delegates); 110 | 111 | // Creates all of the RenderDelegate objects. Implemented in 112 | // client_app_delegates. 113 | static void CreateRenderDelegates(RenderDelegateSet& delegates); 114 | 115 | // Registers custom schemes. Implemented in client_app_delegates. 116 | static void RegisterCustomSchemes(CefRefPtr registrar, 117 | std::vector& cookiable_schemes); 118 | 119 | // CefApp methods. 120 | virtual void OnRegisterCustomSchemes( 121 | CefRefPtr registrar) OVERRIDE; 122 | virtual CefRefPtr GetBrowserProcessHandler() 123 | OVERRIDE { return this; } 124 | virtual CefRefPtr GetRenderProcessHandler() 125 | OVERRIDE { return this; } 126 | 127 | // CefBrowserProcessHandler methods. 128 | virtual void OnContextInitialized() OVERRIDE; 129 | virtual void OnBeforeChildProcessLaunch( 130 | CefRefPtr command_line) OVERRIDE; 131 | virtual void OnRenderProcessThreadCreated(CefRefPtr extra_info) 132 | OVERRIDE; 133 | 134 | // CefRenderProcessHandler methods. 135 | virtual void OnRenderThreadCreated(CefRefPtr extra_info) 136 | OVERRIDE; 137 | virtual void OnWebKitInitialized() OVERRIDE; 138 | virtual void OnBrowserCreated(CefRefPtr browser) OVERRIDE; 139 | virtual void OnBrowserDestroyed(CefRefPtr browser) OVERRIDE; 140 | virtual CefRefPtr GetLoadHandler() OVERRIDE; 141 | virtual bool OnBeforeNavigation(CefRefPtr browser, 142 | CefRefPtr frame, 143 | CefRefPtr request, 144 | NavigationType navigation_type, 145 | bool is_redirect) OVERRIDE; 146 | virtual void OnContextCreated(CefRefPtr browser, 147 | CefRefPtr frame, 148 | CefRefPtr context) OVERRIDE; 149 | virtual void OnContextReleased(CefRefPtr browser, 150 | CefRefPtr frame, 151 | CefRefPtr context) OVERRIDE; 152 | virtual void OnUncaughtException(CefRefPtr browser, 153 | CefRefPtr frame, 154 | CefRefPtr context, 155 | CefRefPtr exception, 156 | CefRefPtr stackTrace) 157 | OVERRIDE; 158 | virtual void OnFocusedNodeChanged(CefRefPtr browser, 159 | CefRefPtr frame, 160 | CefRefPtr node) OVERRIDE; 161 | virtual bool OnProcessMessageReceived( 162 | CefRefPtr browser, 163 | CefProcessId source_process, 164 | CefRefPtr message) OVERRIDE; 165 | 166 | // Set of supported BrowserDelegates. Only used in the browser process. 167 | BrowserDelegateSet browser_delegates_; 168 | 169 | // Set of supported RenderDelegates. Only used in the renderer process. 170 | RenderDelegateSet render_delegates_; 171 | 172 | // Schemes that will be registered with the global cookie manager. Used in 173 | // both the browser and renderer process. 174 | std::vector cookieable_schemes_; 175 | 176 | IMPLEMENT_REFCOUNTING(ClientApp); 177 | }; 178 | 179 | #endif // CEF_TESTS_CEFCLIENT_CLIENT_APP_H_ 180 | -------------------------------------------------------------------------------- /doomtool/client_app_delegates.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "client_app.h" 6 | #include "client_renderer.h" 7 | #include "scheme_test.h" 8 | #include "extensions\cefclient_extensions_window.h" 9 | #include "extensions\cefclient_extensions_require.h" 10 | 11 | // static 12 | void ClientApp::CreateBrowserDelegates(BrowserDelegateSet& delegates) { 13 | } 14 | 15 | // static 16 | void ClientApp::CreateRenderDelegates(RenderDelegateSet& delegates) { 17 | client_renderer::CreateRenderDelegates(delegates); 18 | extensions_window::CreateRenderDelegates(delegates); 19 | extensions_require::CreateRenderDelegates(delegates); 20 | } 21 | 22 | // static 23 | void ClientApp::RegisterCustomSchemes( 24 | CefRefPtr registrar, 25 | std::vector& cookiable_schemes) { 26 | scheme_test::RegisterCustomSchemes(registrar, cookiable_schemes); 27 | } 28 | -------------------------------------------------------------------------------- /doomtool/client_handler.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "client_handler.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "include/cef_browser.h" 14 | #include "include/cef_frame.h" 15 | #include "include/cef_path_util.h" 16 | #include "include/cef_process_util.h" 17 | #include "include/cef_runnable.h" 18 | #include "include/cef_trace.h" 19 | #include "include/cef_url.h" 20 | #include "include/wrapper/cef_stream_resource_handler.h" 21 | #include "client_renderer.h" 22 | #include "cefclient_osr_widget_win.h" 23 | #include "client_switches.h" 24 | #include "resource_util.h" 25 | #include "string_util.h" 26 | #include "extensions/cefclient_extensions_window.h" 27 | #include "extensions/cefclient_extensions_require.h" 28 | 29 | namespace { 30 | 31 | const char kTestOrigin[] = "http://tests/"; 32 | 33 | // Retrieve the file name and mime type based on the specified url. 34 | bool ParseTestUrl(const std::string& url, 35 | std::string* file_name, 36 | std::string* mime_type) { 37 | // Retrieve the path component. 38 | CefURLParts parts; 39 | CefParseURL(url, parts); 40 | std::string file = CefString(&parts.path); 41 | if (file.size() < 2) 42 | return false; 43 | 44 | // Remove the leading slash. 45 | file = file.substr(1); 46 | 47 | // Verify that the file name is valid. 48 | for(size_t i = 0; i < file.size(); ++i) { 49 | const char c = file[i]; 50 | if (!isalpha(c) && !isdigit(c) && c != '_' && c != '.') 51 | return false; 52 | } 53 | 54 | // Determine the mime type based on the file extension, if any. 55 | size_t pos = file.rfind("."); 56 | if (pos != std::string::npos) { 57 | std::string ext = file.substr(pos + 1); 58 | if (ext == "html") 59 | *mime_type = "text/html"; 60 | else if (ext == "png") 61 | *mime_type = "image/png"; 62 | else 63 | return false; 64 | } else { 65 | // Default to an html extension if none is specified. 66 | *mime_type = "text/html"; 67 | file += ".html"; 68 | } 69 | 70 | *file_name = file; 71 | return true; 72 | } 73 | 74 | } // namespace 75 | 76 | int ClientHandler::m_BrowserCount = 0; 77 | 78 | ClientHandler::ClientHandler() 79 | : m_StartupURL("http://localhost/") { 80 | // Create the browser-side router for query handling. 81 | CreateProcessMessageDelegates(process_message_delegates_); 82 | } 83 | 84 | ClientHandler::~ClientHandler() { 85 | } 86 | 87 | bool ClientHandler::OnProcessMessageReceived( 88 | CefRefPtr browser, 89 | CefProcessId source_process, 90 | CefRefPtr message) { 91 | // Check for messages from the client renderer. 92 | std::string message_name = message->GetName(); 93 | 94 | bool handled = false; 95 | 96 | // Execute delegate callbacks. 97 | ProcessMessageDelegateSet::iterator it = process_message_delegates_.begin(); 98 | for (; it != process_message_delegates_.end() && !handled; ++it) { 99 | handled = (*it)->OnProcessMessageReceived(this, browser, source_process, 100 | message); 101 | } 102 | 103 | return handled; 104 | } 105 | 106 | void ClientHandler::OnBeforeContextMenu( 107 | CefRefPtr browser, 108 | CefRefPtr frame, 109 | CefRefPtr params, 110 | CefRefPtr model) { 111 | // disable the context menu 112 | model->Clear(); 113 | } 114 | 115 | bool ClientHandler::OnContextMenuCommand( 116 | CefRefPtr browser, 117 | CefRefPtr frame, 118 | CefRefPtr params, 119 | int command_id, 120 | EventFlags event_flags) { 121 | return false; 122 | } 123 | 124 | bool ClientHandler::OnConsoleMessage(CefRefPtr browser, 125 | const CefString& message, 126 | const CefString& source, 127 | int line) { 128 | return false; 129 | } 130 | 131 | void ClientHandler::OnBeforeDownload( 132 | CefRefPtr browser, 133 | CefRefPtr download_item, 134 | const CefString& suggested_name, 135 | CefRefPtr callback) { 136 | } 137 | 138 | void ClientHandler::OnDownloadUpdated( 139 | CefRefPtr browser, 140 | CefRefPtr download_item, 141 | CefRefPtr callback) { 142 | } 143 | 144 | bool ClientHandler::OnDragEnter(CefRefPtr browser, 145 | CefRefPtr dragData, 146 | DragOperationsMask mask) { 147 | REQUIRE_UI_THREAD(); 148 | 149 | // Forbid dragging of link URLs. 150 | if (mask & DRAG_OPERATION_LINK) 151 | return true; 152 | 153 | return false; 154 | } 155 | 156 | void ClientHandler::OnRequestGeolocationPermission( 157 | CefRefPtr browser, 158 | const CefString& requesting_url, 159 | int request_id, 160 | CefRefPtr callback) { 161 | // Allow geolocation access from all websites. 162 | callback->Continue(true); 163 | } 164 | 165 | bool ClientHandler::OnPreKeyEvent(CefRefPtr browser, 166 | const CefKeyEvent& event, 167 | CefEventHandle os_event, 168 | bool* is_keyboard_shortcut) { 169 | return false; 170 | } 171 | 172 | bool ClientHandler::OnBeforePopup(CefRefPtr browser, 173 | CefRefPtr frame, 174 | const CefString& target_url, 175 | const CefString& target_frame_name, 176 | const CefPopupFeatures& popupFeatures, 177 | CefWindowInfo& windowInfo, 178 | CefRefPtr& client, 179 | CefBrowserSettings& settings, 180 | bool* no_javascript_access) { 181 | return false; 182 | } 183 | 184 | void ClientHandler::OnAfterCreated(CefRefPtr browser) { 185 | REQUIRE_UI_THREAD(); 186 | 187 | AutoLock lock_scope(this); 188 | // Add to the list of browsers. 189 | m_Browsers.push_back(browser); 190 | 191 | m_BrowserCount++; 192 | } 193 | 194 | bool ClientHandler::DoClose(CefRefPtr browser) { 195 | // Allow the close. For windowed browsers this will result in the OS close 196 | // event being sent. 197 | return false; 198 | } 199 | 200 | void ClientHandler::OnBeforeClose(CefRefPtr browser) { 201 | REQUIRE_UI_THREAD(); 202 | // Remove from the browser list. 203 | BrowserList::iterator bit = m_Browsers.begin(); 204 | for (; bit != m_Browsers.end(); ++bit) { 205 | if ((*bit)->IsSame(browser)) { 206 | m_Browsers.erase(bit); 207 | if (m_OSRHandler.get()) { 208 | m_OSRHandler->OnBeforeClose(browser); 209 | } 210 | break; 211 | } 212 | } 213 | 214 | if (--m_BrowserCount == 0) { 215 | m_OSRHandler = NULL; 216 | // Quit the application message loop. 217 | CefQuitMessageLoop(); 218 | } 219 | } 220 | 221 | void ClientHandler::OnLoadingStateChange(CefRefPtr browser, 222 | bool isLoading, 223 | bool canGoBack, 224 | bool canGoForward) { 225 | } 226 | 227 | void ClientHandler::OnLoadError(CefRefPtr browser, 228 | CefRefPtr frame, 229 | ErrorCode errorCode, 230 | const CefString& errorText, 231 | const CefString& failedUrl) { 232 | REQUIRE_UI_THREAD(); 233 | 234 | // Don't display an error for downloaded files. 235 | if (errorCode == ERR_ABORTED) 236 | return; 237 | 238 | // Don't display an error for external protocols that we allow the OS to 239 | // handle. See OnProtocolExecution(). 240 | if (errorCode == ERR_UNKNOWN_URL_SCHEME) { 241 | std::string urlStr = frame->GetURL(); 242 | if (urlStr.find("spotify:") == 0) 243 | return; 244 | } 245 | 246 | // Display a load error message. 247 | std::stringstream ss; 248 | ss << "" 249 | "

Failed to load URL " << std::string(failedUrl) << 250 | " with error " << std::string(errorText) << " (" << errorCode << 251 | ").

"; 252 | frame->LoadString(ss.str(), failedUrl); 253 | } 254 | 255 | bool ClientHandler::OnBeforeBrowse(CefRefPtr browser, 256 | CefRefPtr frame, 257 | CefRefPtr request, 258 | bool is_redirect) { 259 | return false; 260 | } 261 | 262 | CefRefPtr ClientHandler::GetResourceHandler( 263 | CefRefPtr browser, 264 | CefRefPtr frame, 265 | CefRefPtr request) { 266 | return NULL; 267 | } 268 | 269 | bool ClientHandler::OnQuotaRequest(CefRefPtr browser, 270 | const CefString& origin_url, 271 | int64 new_size, 272 | CefRefPtr callback) { 273 | static const int64 max_size = 1024 * 1024 * 20; // 20mb. 274 | 275 | // Grant the quota request if the size is reasonable. 276 | callback->Continue(new_size <= max_size); 277 | return true; 278 | } 279 | 280 | void ClientHandler::OnProtocolExecution(CefRefPtr browser, 281 | const CefString& url, 282 | bool& allow_os_execution) { 283 | } 284 | 285 | void ClientHandler::OnRenderProcessTerminated(CefRefPtr browser, 286 | TerminationStatus status) { 287 | // Load the startup URL if that's not the website that we terminated on. 288 | CefRefPtr frame = browser->GetMainFrame(); 289 | std::string url = frame->GetURL(); 290 | std::transform(url.begin(), url.end(), url.begin(), tolower); 291 | 292 | std::string startupURL = GetStartupURL(); 293 | if (startupURL != "chrome://crash" && !url.empty() && 294 | url.find(startupURL) != 0) { 295 | frame->LoadURL(startupURL); 296 | } 297 | } 298 | 299 | bool ClientHandler::GetRootScreenRect(CefRefPtr browser, 300 | CefRect& rect) { 301 | if (!m_OSRHandler.get()) 302 | return false; 303 | return m_OSRHandler->GetRootScreenRect(browser, rect); 304 | } 305 | 306 | bool ClientHandler::GetViewRect(CefRefPtr browser, CefRect& rect) { 307 | if (!m_OSRHandler.get()) 308 | return false; 309 | return m_OSRHandler->GetViewRect(browser, rect); 310 | } 311 | 312 | bool ClientHandler::GetScreenPoint(CefRefPtr browser, 313 | int viewX, 314 | int viewY, 315 | int& screenX, 316 | int& screenY) { 317 | if (!m_OSRHandler.get()) 318 | return false; 319 | return m_OSRHandler->GetScreenPoint(browser, viewX, viewY, screenX, screenY); 320 | } 321 | 322 | bool ClientHandler::GetScreenInfo(CefRefPtr browser, 323 | CefScreenInfo& screen_info) { 324 | if (!m_OSRHandler.get()) 325 | return false; 326 | return m_OSRHandler->GetScreenInfo(browser, screen_info); 327 | } 328 | 329 | void ClientHandler::OnPopupShow(CefRefPtr browser, 330 | bool show) { 331 | if (!m_OSRHandler.get()) 332 | return; 333 | return m_OSRHandler->OnPopupShow(browser, show); 334 | } 335 | 336 | void ClientHandler::OnPopupSize(CefRefPtr browser, 337 | const CefRect& rect) { 338 | if (!m_OSRHandler.get()) 339 | return; 340 | return m_OSRHandler->OnPopupSize(browser, rect); 341 | } 342 | 343 | void ClientHandler::OnPaint(CefRefPtr browser, 344 | PaintElementType type, 345 | const RectList& dirtyRects, 346 | const void* buffer, 347 | int width, 348 | int height) { 349 | if (!m_OSRHandler.get()) 350 | return; 351 | m_OSRHandler->OnPaint(browser, type, dirtyRects, buffer, width, height); 352 | } 353 | 354 | void ClientHandler::OnCursorChange(CefRefPtr browser, 355 | CefCursorHandle cursor) { 356 | if (!m_OSRHandler.get()) 357 | return; 358 | m_OSRHandler->OnCursorChange(browser, cursor); 359 | } 360 | 361 | void ClientHandler::CloseAllBrowsers(bool force_close) { 362 | if (!CefCurrentlyOn(TID_UI)) { 363 | // Execute on the UI thread. 364 | CefPostTask(TID_UI, 365 | NewCefRunnableMethod(this, &ClientHandler::CloseAllBrowsers, 366 | force_close)); 367 | return; 368 | } 369 | 370 | if (!m_Browsers.empty()) { 371 | // Request that any popup browsers close. 372 | BrowserList::const_iterator it = m_Browsers.begin(); 373 | for (; it != m_Browsers.end(); ++it) 374 | (*it)->GetHost()->CloseBrowser(force_close); 375 | } 376 | } 377 | 378 | std::string ClientHandler::GetLogFile() { 379 | AutoLock lock_scope(this); 380 | return m_LogFile; 381 | } 382 | 383 | void ClientHandler::SetLastDownloadFile(const std::string& fileName) { 384 | AutoLock lock_scope(this); 385 | m_LastDownloadFile = fileName; 386 | } 387 | 388 | std::string ClientHandler::GetLastDownloadFile() { 389 | AutoLock lock_scope(this); 390 | return m_LastDownloadFile; 391 | } 392 | 393 | // static 394 | void ClientHandler::CreateProcessMessageDelegates( 395 | ProcessMessageDelegateSet& delegates) { 396 | extensions_window::CreateProcessMessageDelegates(delegates); 397 | extensions_require::CreateProcessMessageDelegates(delegates); 398 | } 399 | 400 | -------------------------------------------------------------------------------- /doomtool/client_handler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #ifndef CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_ 6 | #define CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_ 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "include/cef_client.h" 14 | #include "util.h" 15 | 16 | 17 | // Define this value to redirect all popup URLs to the main application browser 18 | // window. 19 | // #define TEST_REDIRECT_POPUP_URLS 20 | 21 | 22 | // ClientHandler implementation. 23 | class ClientHandler : public CefClient, 24 | public CefContextMenuHandler, 25 | public CefDisplayHandler, 26 | public CefDownloadHandler, 27 | public CefDragHandler, 28 | public CefGeolocationHandler, 29 | public CefKeyboardHandler, 30 | public CefLifeSpanHandler, 31 | public CefLoadHandler, 32 | public CefRenderHandler, 33 | public CefRequestHandler { 34 | public: 35 | // Interface for process message delegates. Do not perform work in the 36 | // RenderDelegate constructor. 37 | class ProcessMessageDelegate : public virtual CefBase { 38 | public: 39 | // Called when a process message is received. Return true if the message was 40 | // handled and should not be passed on to other handlers. 41 | // ProcessMessageDelegates should check for unique message names to avoid 42 | // interfering with each other. 43 | virtual bool OnProcessMessageReceived( 44 | CefRefPtr handler, 45 | CefRefPtr browser, 46 | CefProcessId source_process, 47 | CefRefPtr message) { 48 | return false; 49 | } 50 | }; 51 | 52 | typedef std::set > 53 | ProcessMessageDelegateSet; 54 | 55 | // Interface implemented to handle off-screen rendering. 56 | class RenderHandler : public CefRenderHandler { 57 | public: 58 | virtual void OnBeforeClose(CefRefPtr browser) =0; 59 | }; 60 | 61 | ClientHandler(); 62 | virtual ~ClientHandler(); 63 | 64 | // CefClient methods 65 | virtual CefRefPtr GetContextMenuHandler() OVERRIDE { 66 | return this; 67 | } 68 | virtual CefRefPtr GetDisplayHandler() OVERRIDE { 69 | return this; 70 | } 71 | virtual CefRefPtr GetDownloadHandler() OVERRIDE { 72 | return this; 73 | } 74 | virtual CefRefPtr GetDragHandler() OVERRIDE { 75 | return this; 76 | } 77 | virtual CefRefPtr GetGeolocationHandler() OVERRIDE { 78 | return this; 79 | } 80 | virtual CefRefPtr GetKeyboardHandler() OVERRIDE { 81 | return this; 82 | } 83 | virtual CefRefPtr GetLifeSpanHandler() OVERRIDE { 84 | return this; 85 | } 86 | virtual CefRefPtr GetLoadHandler() OVERRIDE { 87 | return this; 88 | } 89 | virtual CefRefPtr GetRenderHandler() OVERRIDE { 90 | return this; 91 | } 92 | virtual CefRefPtr GetRequestHandler() OVERRIDE { 93 | return this; 94 | } 95 | virtual bool OnProcessMessageReceived(CefRefPtr browser, 96 | CefProcessId source_process, 97 | CefRefPtr message) 98 | OVERRIDE; 99 | 100 | // CefContextMenuHandler methods 101 | virtual void OnBeforeContextMenu(CefRefPtr browser, 102 | CefRefPtr frame, 103 | CefRefPtr params, 104 | CefRefPtr model) OVERRIDE; 105 | virtual bool OnContextMenuCommand(CefRefPtr browser, 106 | CefRefPtr frame, 107 | CefRefPtr params, 108 | int command_id, 109 | EventFlags event_flags) OVERRIDE; 110 | 111 | // CefDisplayHandler methods 112 | virtual void OnAddressChange(CefRefPtr browser, 113 | CefRefPtr frame, 114 | const CefString& url) OVERRIDE; 115 | virtual void OnTitleChange(CefRefPtr browser, 116 | const CefString& title) OVERRIDE; 117 | virtual bool OnConsoleMessage(CefRefPtr browser, 118 | const CefString& message, 119 | const CefString& source, 120 | int line) OVERRIDE; 121 | 122 | // CefDownloadHandler methods 123 | virtual void OnBeforeDownload( 124 | CefRefPtr browser, 125 | CefRefPtr download_item, 126 | const CefString& suggested_name, 127 | CefRefPtr callback) OVERRIDE; 128 | virtual void OnDownloadUpdated( 129 | CefRefPtr browser, 130 | CefRefPtr download_item, 131 | CefRefPtr callback) OVERRIDE; 132 | 133 | // CefDragHandler methods 134 | virtual bool OnDragEnter(CefRefPtr browser, 135 | CefRefPtr dragData, 136 | DragOperationsMask mask) OVERRIDE; 137 | 138 | // CefGeolocationHandler methods 139 | virtual void OnRequestGeolocationPermission( 140 | CefRefPtr browser, 141 | const CefString& requesting_url, 142 | int request_id, 143 | CefRefPtr callback) OVERRIDE; 144 | 145 | // CefKeyboardHandler methods 146 | virtual bool OnPreKeyEvent(CefRefPtr browser, 147 | const CefKeyEvent& event, 148 | CefEventHandle os_event, 149 | bool* is_keyboard_shortcut) OVERRIDE; 150 | 151 | // CefLifeSpanHandler methods 152 | virtual bool OnBeforePopup(CefRefPtr browser, 153 | CefRefPtr frame, 154 | const CefString& target_url, 155 | const CefString& target_frame_name, 156 | const CefPopupFeatures& popupFeatures, 157 | CefWindowInfo& windowInfo, 158 | CefRefPtr& client, 159 | CefBrowserSettings& settings, 160 | bool* no_javascript_access) OVERRIDE; 161 | virtual void OnAfterCreated(CefRefPtr browser) OVERRIDE; 162 | virtual bool DoClose(CefRefPtr browser) OVERRIDE; 163 | virtual void OnBeforeClose(CefRefPtr browser) OVERRIDE; 164 | 165 | // CefLoadHandler methods 166 | virtual void OnLoadingStateChange(CefRefPtr browser, 167 | bool isLoading, 168 | bool canGoBack, 169 | bool canGoForward) OVERRIDE; 170 | virtual void OnLoadError(CefRefPtr browser, 171 | CefRefPtr frame, 172 | ErrorCode errorCode, 173 | const CefString& errorText, 174 | const CefString& failedUrl) OVERRIDE; 175 | 176 | // CefRequestHandler methods 177 | virtual bool OnBeforeBrowse(CefRefPtr browser, 178 | CefRefPtr frame, 179 | CefRefPtr request, 180 | bool is_redirect) OVERRIDE; 181 | virtual CefRefPtr GetResourceHandler( 182 | CefRefPtr browser, 183 | CefRefPtr frame, 184 | CefRefPtr request) OVERRIDE; 185 | virtual bool OnQuotaRequest(CefRefPtr browser, 186 | const CefString& origin_url, 187 | int64 new_size, 188 | CefRefPtr callback) OVERRIDE; 189 | virtual void OnProtocolExecution(CefRefPtr browser, 190 | const CefString& url, 191 | bool& allow_os_execution) OVERRIDE; 192 | virtual void OnRenderProcessTerminated(CefRefPtr browser, 193 | TerminationStatus status) OVERRIDE; 194 | 195 | // CefRenderHandler methods 196 | virtual bool GetRootScreenRect(CefRefPtr browser, 197 | CefRect& rect) OVERRIDE; 198 | virtual bool GetViewRect(CefRefPtr browser, 199 | CefRect& rect) OVERRIDE; 200 | virtual bool GetScreenPoint(CefRefPtr browser, 201 | int viewX, 202 | int viewY, 203 | int& screenX, 204 | int& screenY) OVERRIDE; 205 | virtual bool GetScreenInfo(CefRefPtr browser, 206 | CefScreenInfo& screen_info) OVERRIDE; 207 | virtual void OnPopupShow(CefRefPtr browser, bool show) OVERRIDE; 208 | virtual void OnPopupSize(CefRefPtr browser, 209 | const CefRect& rect) OVERRIDE; 210 | virtual void OnPaint(CefRefPtr browser, 211 | PaintElementType type, 212 | const RectList& dirtyRects, 213 | const void* buffer, 214 | int width, 215 | int height) OVERRIDE; 216 | virtual void OnCursorChange(CefRefPtr browser, 217 | CefCursorHandle cursor) OVERRIDE; 218 | 219 | void SetOSRHandler(CefRefPtr handler) { m_OSRHandler = handler; } 220 | CefRefPtr GetOSRHandler() { return m_OSRHandler; } 221 | 222 | CefRefPtr GetBrowser(HWND hWnd = 0) { 223 | if (!m_Browsers.empty()) { 224 | BrowserList::const_iterator it = m_Browsers.begin(); 225 | for (; it != m_Browsers.end(); ++it) 226 | if((*it)->GetHost()->GetWindowHandle() == hWnd){ 227 | return *it; 228 | } 229 | } 230 | return NULL; 231 | } 232 | 233 | // Request that all existing browser windows close. 234 | void CloseAllBrowsers(bool force_close); 235 | 236 | std::string GetLogFile(); 237 | 238 | void SetLastDownloadFile(const std::string& fileName); 239 | std::string GetLastDownloadFile(); 240 | 241 | // Returns the startup URL. 242 | std::string GetStartupURL() { return m_StartupURL; } 243 | 244 | protected: 245 | // Create all of ProcessMessageDelegate objects. 246 | static void CreateProcessMessageDelegates( 247 | ProcessMessageDelegateSet& delegates); 248 | 249 | // Returns the full download path for the specified file, or an empty path to 250 | // use the default temp directory. 251 | std::string GetDownloadPath(const std::string& file_name); 252 | 253 | // List of any popup browser windows. Only accessed on the CEF UI thread. 254 | typedef std::list > BrowserList; 255 | BrowserList m_Browsers; 256 | 257 | // True if the main browser window is currently closing. 258 | bool m_bIsClosing; 259 | 260 | CefRefPtr m_OSRHandler; 261 | 262 | // Support for logging. 263 | std::string m_LogFile; 264 | 265 | // Support for downloading files. 266 | std::string m_LastDownloadFile; 267 | 268 | // Registered delegates. 269 | ProcessMessageDelegateSet process_message_delegates_; 270 | 271 | // The startup URL. 272 | std::string m_StartupURL; 273 | 274 | // Number of currently existing browser windows. The application will exit 275 | // when the number of windows reaches 0. 276 | static int m_BrowserCount; 277 | 278 | // Include the default reference counting implementation. 279 | IMPLEMENT_REFCOUNTING(ClientHandler); 280 | // Include the default locking implementation. 281 | IMPLEMENT_LOCKING(ClientHandler); 282 | }; 283 | 284 | #endif // CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_ 285 | -------------------------------------------------------------------------------- /doomtool/client_handler_win.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "client_handler.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "include/cef_browser.h" 12 | #include "include/cef_frame.h" 13 | #include "resource.h" 14 | 15 | void ClientHandler::OnAddressChange(CefRefPtr browser, 16 | CefRefPtr frame, 17 | const CefString& url) { 18 | } 19 | 20 | void ClientHandler::OnTitleChange(CefRefPtr browser, 21 | const CefString& title) { 22 | REQUIRE_UI_THREAD(); 23 | 24 | // Set the frame window title bar 25 | CefWindowHandle hwnd = browser->GetHost()->GetWindowHandle(); 26 | SetWindowText(hwnd, std::wstring(title).c_str()); 27 | } 28 | 29 | std::string ClientHandler::GetDownloadPath(const std::string& file_name) { 30 | TCHAR szFolderPath[MAX_PATH]; 31 | std::string path; 32 | 33 | // Save the file in the user's "My Documents" folder. 34 | if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, 35 | NULL, 0, szFolderPath))) { 36 | path = CefString(szFolderPath); 37 | path += "\\" + file_name; 38 | } 39 | 40 | return path; 41 | } 42 | -------------------------------------------------------------------------------- /doomtool/client_renderer.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "client_renderer.h" 6 | 7 | #include 8 | #include 9 | 10 | #include "include/cef_dom.h" 11 | #include "util.h" 12 | 13 | namespace client_renderer { 14 | 15 | const char kFocusedNodeChangedMessage[] = "ClientRenderer.FocusedNodeChanged"; 16 | 17 | namespace { 18 | 19 | class ClientRenderDelegate : public ClientApp::RenderDelegate { 20 | public: 21 | ClientRenderDelegate() 22 | : last_node_is_editable_(false) { 23 | } 24 | 25 | virtual void OnFocusedNodeChanged(CefRefPtr app, 26 | CefRefPtr browser, 27 | CefRefPtr frame, 28 | CefRefPtr node) OVERRIDE { 29 | bool is_editable = (node.get() && node->IsEditable()); 30 | if (is_editable != last_node_is_editable_) { 31 | // Notify the browser of the change in focused element type. 32 | last_node_is_editable_ = is_editable; 33 | CefRefPtr message = 34 | CefProcessMessage::Create(kFocusedNodeChangedMessage); 35 | message->GetArgumentList()->SetBool(0, is_editable); 36 | browser->SendProcessMessage(PID_BROWSER, message); 37 | } 38 | } 39 | 40 | private: 41 | bool last_node_is_editable_; 42 | 43 | IMPLEMENT_REFCOUNTING(ClientRenderDelegate); 44 | }; 45 | 46 | } // namespace 47 | 48 | void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates) { 49 | delegates.insert(new ClientRenderDelegate); 50 | } 51 | 52 | } // namespace client_renderer 53 | -------------------------------------------------------------------------------- /doomtool/client_renderer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #ifndef CEF_TESTS_CEFCLIENT_CLIENT_RENDERER_H_ 6 | #define CEF_TESTS_CEFCLIENT_CLIENT_RENDERER_H_ 7 | #pragma once 8 | 9 | #include "include/cef_base.h" 10 | #include "client_app.h" 11 | 12 | namespace client_renderer { 13 | 14 | // Message sent when the focused node changes. 15 | extern const char kFocusedNodeChangedMessage[]; 16 | 17 | // Create the render delegate. 18 | void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates); 19 | 20 | } // namespace client_renderer 21 | 22 | #endif // CEF_TESTS_CEFCLIENT_CLIENT_RENDERER_H_ 23 | -------------------------------------------------------------------------------- /doomtool/client_switches.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | // This file is shared by cefclient and cef_unittests so don't include using 6 | // a qualified path. 7 | #include "client_switches.h" // NOLINT(build/include) 8 | 9 | namespace cefclient { 10 | 11 | // CEF and Chromium support a wide range of command-line switches. This file 12 | // only contains command-line switches specific to the cefclient application. 13 | // View CEF/Chromium documentation or search for *_switches.cc files in the 14 | // Chromium source code to identify other existing command-line switches. 15 | // Below is a partial listing of relevant *_switches.cc files: 16 | // base/base_switches.cc 17 | // cef/libcef/common/cef_switches.cc 18 | // chrome/common/chrome_switches.cc (not all apply) 19 | // content/public/common/content_switches.cc 20 | 21 | const char kMultiThreadedMessageLoop[] = "multi-threaded-message-loop"; 22 | const char kCachePath[] = "cache-path"; 23 | const char kUrl[] = "url"; 24 | const char kOffScreenRenderingEnabled[] = "off-screen-rendering-enabled"; 25 | const char kTransparentPaintingEnabled[] = "transparent-painting-enabled"; 26 | const char kMouseCursorChangeDisabled[] = "mouse-cursor-change-disabled"; 27 | 28 | } // namespace cefclient 29 | -------------------------------------------------------------------------------- /doomtool/client_switches.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | // Defines all of the command line switches used by cefclient. 6 | 7 | #ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_ 8 | #define CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_ 9 | #pragma once 10 | 11 | namespace cefclient { 12 | 13 | extern const char kMultiThreadedMessageLoop[]; 14 | extern const char kCachePath[]; 15 | extern const char kUrl[]; 16 | extern const char kOffScreenRenderingEnabled[]; 17 | extern const char kTransparentPaintingEnabled[]; 18 | extern const char kMouseCursorChangeDisabled[]; 19 | 20 | } // namespace cefclient 21 | 22 | #endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_ 23 | -------------------------------------------------------------------------------- /doomtool/compatibility.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /doomtool/doomtool.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /doomtool/extensions/cefclient_extensions_require.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/doomtool/extensions/cefclient_extensions_require.cpp -------------------------------------------------------------------------------- /doomtool/extensions/cefclient_extensions_require.h: -------------------------------------------------------------------------------- 1 | #ifndef CEFCLIENT_EXTENSIONS_REQUIRE_H_ 2 | #define CEFCLIENT_EXTENSIONS_REQUIRE_H_ 3 | 4 | #include "client_handler.h" 5 | #include "client_app.h" 6 | 7 | namespace extensions_require { 8 | 9 | // Delegate creation. Called from ClientHandler. 10 | void CreateProcessMessageDelegates( 11 | ClientHandler::ProcessMessageDelegateSet& delegates); 12 | // Create the render delegate. 13 | void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates); 14 | 15 | // Platform implementations. 16 | 17 | } // namespace extensions_require 18 | 19 | #endif // CEFCLIENT_EXTENSIONS_REQUIRE_H_ 20 | -------------------------------------------------------------------------------- /doomtool/extensions/cefclient_extensions_require_win.cpp: -------------------------------------------------------------------------------- 1 | #include "cefclient_extensions_require.h" 2 | 3 | namespace extensions_require { 4 | 5 | namespace { 6 | 7 | } // namespace 8 | 9 | 10 | } // namespace extensions_require 11 | -------------------------------------------------------------------------------- /doomtool/extensions/cefclient_extensions_window.cpp: -------------------------------------------------------------------------------- 1 | #include "cefclient_extensions_window.h" 2 | #include "cefclient_osr_widget_win.h" 3 | 4 | namespace extensions_window { 5 | 6 | namespace { 7 | 8 | // Handle messages in the browser process. 9 | class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate { 10 | public: 11 | ProcessMessageDelegate() { 12 | } 13 | 14 | // From ClientHandler::ProcessMessageDelegate. 15 | virtual bool OnProcessMessageReceived( 16 | CefRefPtr handler, 17 | CefRefPtr browser, 18 | CefProcessId source_process, 19 | CefRefPtr message) OVERRIDE { 20 | std::string name = message->GetName(); 21 | HWND hwnd = browser->GetHost()->GetWindowHandle(); 22 | if(name == "startDrag") { 23 | StartDrag(hwnd); 24 | return true; 25 | } else if (name == "setZoomLevel") { 26 | browser->GetHost()->SetZoomLevel(message->GetArgumentList()->GetInt(0)); 27 | return true; 28 | } else if (name == "setTopMost") { 29 | SetTopMost(hwnd, message->GetArgumentList()->GetBool(0)); 30 | return true; 31 | } else if (name == "moveTo") { 32 | MoveTo(hwnd, message->GetArgumentList()->GetInt(0), message->GetArgumentList()->GetInt(1)); 33 | return true; 34 | } else if (name == "moveBy") { 35 | MoveBy(hwnd, message->GetArgumentList()->GetInt(0), message->GetArgumentList()->GetInt(1)); 36 | return true; 37 | } else if (name == "resizeTo") { 38 | ResizeTo(hwnd, message->GetArgumentList()->GetInt(0), message->GetArgumentList()->GetInt(1)); 39 | return true; 40 | } else if (name == "resizeBy") { 41 | ResizeBy(hwnd, message->GetArgumentList()->GetInt(0), message->GetArgumentList()->GetInt(1)); 42 | return true; 43 | } else if (name == "focus") { 44 | Focus(hwnd); 45 | return true; 46 | } else if (name == "blur") { 47 | Blur(hwnd); 48 | return true; 49 | } else if (name == "show") { 50 | Show(hwnd); 51 | return true; 52 | } else if (name == "hide") { 53 | Hide(hwnd); 54 | return true; 55 | } else if (name == "reload") { 56 | browser->Reload(); 57 | return true; 58 | } else if (name == "reloadIgnoringCache") { 59 | browser->ReloadIgnoreCache(); 60 | return true; 61 | } else if (name == "maximize") { 62 | Maximize(hwnd); 63 | return true; 64 | } else if (name == "minimize") { 65 | Minimize(hwnd); 66 | return true; 67 | } else if (name == "restore") { 68 | Restore(hwnd); 69 | return true; 70 | } else if (name == "popUp") { 71 | RECT rect; 72 | rect.right = GetSystemMetrics(SM_CXFULLSCREEN); 73 | rect.bottom = GetSystemMetrics(SM_CYFULLSCREEN) + GetSystemMetrics(SM_CYCAPTION); 74 | rect.left = 0; 75 | rect.top = 0; 76 | CefRefPtr osr_window = OSRWindow::From(handler->GetOSRHandler()); 77 | HWND hWnd = osr_window->CreateWidget(NULL, rect, NULL,L"DoomToolPopUpWnd"); 78 | 79 | if(!hWnd) 80 | ::MessageBoxA(NULL, "CreateWidget failed!", NULL, 0); 81 | CefWindowInfo info; 82 | CefBrowserSettings settings; 83 | info.SetAsOffScreen(hWnd); 84 | info.SetTransparentPainting(TRUE); 85 | 86 | if(!CefBrowserHost::CreateBrowser(info, browser->GetHost()->GetClient(), "http://localhost", settings, NULL)) 87 | ::MessageBoxA(NULL, "CreateBrowser failed!", NULL, 0); 88 | } else { 89 | ASSERT(false); // Not reached. 90 | } 91 | return false; 92 | } 93 | 94 | IMPLEMENT_REFCOUNTING(ProcessMessageDelegate); 95 | }; 96 | 97 | // Handles the native implementation for the client_app extension. 98 | class V8Handler : public CefV8Handler { 99 | public: 100 | V8Handler(){ 101 | } 102 | 103 | virtual bool Execute(const CefString& name, 104 | CefRefPtr object, 105 | const CefV8ValueList& arguments, 106 | CefRefPtr& retval, 107 | CefString& exception) { 108 | bool handled = false; 109 | CefRefPtr browser = CefV8Context::GetCurrentContext()->GetBrowser(); 110 | 111 | ASSERT(browser.get()); 112 | CefRefPtr message = CefProcessMessage::Create(name); 113 | if (name == "setZoomLevel") { 114 | // Send a message to the browser process. 115 | if (arguments.size() == 1 && 116 | arguments[0]->IsInt()) { 117 | message->GetArgumentList()->SetInt(0, arguments[0]->GetIntValue()); 118 | browser->SendProcessMessage(PID_BROWSER, message); 119 | handled = true; 120 | } 121 | } else if (name == "setTopMost") { 122 | if (arguments.size() == 1 && arguments[0]->IsBool()) { 123 | message->GetArgumentList()->SetBool(0, arguments[0]->GetBoolValue()); 124 | browser->SendProcessMessage(PID_BROWSER, message); 125 | handled = true; 126 | } 127 | } else if ( name == "moveTo" || 128 | name == "moveBy" || 129 | name == "resizeTo" || 130 | name == "resizeBy") { 131 | if(arguments.size() == 2 && arguments[0]->IsInt() && arguments[1]->IsInt()) { 132 | message->GetArgumentList()->SetInt(0, arguments[0]->GetIntValue()); 133 | message->GetArgumentList()->SetInt(1, arguments[1]->GetIntValue()); 134 | browser->SendProcessMessage(PID_BROWSER, message); 135 | handled = true; 136 | } 137 | } else if ( name == "startDrag" || 138 | name == "focus" || 139 | name == "blur" || 140 | name == "show" || 141 | name == "hide" || 142 | name == "reload" || 143 | name == "reloadIgnoringCache" || 144 | name == "maximize" || 145 | name == "minimize" || 146 | name == "restore" || 147 | name == "popUp"){ 148 | if(arguments.size() == 0) { 149 | browser->SendProcessMessage(PID_BROWSER, message); 150 | handled = true; 151 | } 152 | } else { 153 | ASSERT(false); // function name missed. 154 | } 155 | if (!handled) 156 | exception = "Invalid method arguments"; 157 | 158 | return true; 159 | } 160 | 161 | IMPLEMENT_REFCOUNTING(V8Handler); 162 | }; 163 | 164 | class RenderDelegate : public ClientApp::RenderDelegate { 165 | public: 166 | RenderDelegate() { 167 | } 168 | 169 | virtual void OnContextCreated(CefRefPtr app, 170 | CefRefPtr browser, 171 | CefRefPtr frame, 172 | CefRefPtr context) OVERRIDE { 173 | if(!frame->IsMain()) 174 | return; 175 | CefRefPtr object = context->GetGlobal(); 176 | 177 | CefRefPtr handler = new V8Handler(); 178 | 179 | // Bind window functions. 180 | object->SetValue("startDrag", 181 | CefV8Value::CreateFunction("startDrag", handler), 182 | V8_PROPERTY_ATTRIBUTE_READONLY); 183 | object->SetValue("setZoomLevel", 184 | CefV8Value::CreateFunction("setZoomLevel", handler), 185 | V8_PROPERTY_ATTRIBUTE_READONLY); 186 | object->SetValue("moveTo", 187 | CefV8Value::CreateFunction("moveTo", handler), 188 | V8_PROPERTY_ATTRIBUTE_READONLY); 189 | object->SetValue("moveBy", 190 | CefV8Value::CreateFunction("moveBy", handler), 191 | V8_PROPERTY_ATTRIBUTE_READONLY); 192 | object->SetValue("resizeTo", 193 | CefV8Value::CreateFunction("resizeTo", handler), 194 | V8_PROPERTY_ATTRIBUTE_READONLY); 195 | object->SetValue("resizeBy", 196 | CefV8Value::CreateFunction("resizeBy", handler), 197 | V8_PROPERTY_ATTRIBUTE_READONLY); 198 | object->SetValue("focus", 199 | CefV8Value::CreateFunction("focus", handler), 200 | V8_PROPERTY_ATTRIBUTE_READONLY); 201 | object->SetValue("blur", 202 | CefV8Value::CreateFunction("blur", handler), 203 | V8_PROPERTY_ATTRIBUTE_READONLY); 204 | object->SetValue("show", 205 | CefV8Value::CreateFunction("show", handler), 206 | V8_PROPERTY_ATTRIBUTE_READONLY); 207 | object->SetValue("hide", 208 | CefV8Value::CreateFunction("hide", handler), 209 | V8_PROPERTY_ATTRIBUTE_READONLY); 210 | object->SetValue("reload", 211 | CefV8Value::CreateFunction("reload", handler), 212 | V8_PROPERTY_ATTRIBUTE_READONLY); 213 | object->SetValue("reloadIgnoringCache", 214 | CefV8Value::CreateFunction("reloadIgnoringCache", handler), 215 | V8_PROPERTY_ATTRIBUTE_READONLY); 216 | object->SetValue("maximize", 217 | CefV8Value::CreateFunction("maximize", handler), 218 | V8_PROPERTY_ATTRIBUTE_READONLY); 219 | object->SetValue("minimize", 220 | CefV8Value::CreateFunction("minimize", handler), 221 | V8_PROPERTY_ATTRIBUTE_READONLY); 222 | object->SetValue("restore", 223 | CefV8Value::CreateFunction("restore", handler), 224 | V8_PROPERTY_ATTRIBUTE_READONLY); 225 | object->SetValue("setTopMost", 226 | CefV8Value::CreateFunction("setTopMost", handler), 227 | V8_PROPERTY_ATTRIBUTE_READONLY); 228 | object->SetValue("popUp", 229 | CefV8Value::CreateFunction("popUp", handler), 230 | V8_PROPERTY_ATTRIBUTE_READONLY); 231 | 232 | std::string window_code = 233 | "(function() {" 234 | " var zoomLevel_ = 0;" 235 | " window.__defineGetter__('zoomLevel', function() {" 236 | " return zoomLevel_;" 237 | " });" 238 | " window.__defineSetter__('zoomLevel', function(b) {" 239 | " window.setZoomLevel(b);" 240 | " zoomLevel_ = b;" 241 | " });" 242 | " window.addEventListener('load', function(){" 243 | " var regions = document.querySelectorAll('*[dragable-region]');" 244 | " for(i in regions) {" 245 | " regions[i].addEventListener('mousedown', function(event) {" 246 | " if (event.target != event.currentTarget)" 247 | " return;" 248 | " window.startDrag();" 249 | " }, false);" 250 | " }" 251 | " }, false);" 252 | "})();"; 253 | frame->ExecuteJavaScript(window_code, frame->GetURL(), 0); 254 | } 255 | 256 | IMPLEMENT_REFCOUNTING(RenderDelegate); 257 | }; 258 | 259 | } // namespace 260 | 261 | void CreateProcessMessageDelegates( 262 | ClientHandler::ProcessMessageDelegateSet& delegates) { 263 | delegates.insert(new ProcessMessageDelegate); 264 | } 265 | 266 | void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates) { 267 | delegates.insert(new RenderDelegate); 268 | } 269 | 270 | } // namespace extensions_window 271 | -------------------------------------------------------------------------------- /doomtool/extensions/cefclient_extensions_window.h: -------------------------------------------------------------------------------- 1 | #ifndef CEFCLIENT_EXTENSIONS_WINDOW_H_ 2 | #define CEFCLIENT_EXTENSIONS_WINDOW_H_ 3 | 4 | #include "client_handler.h" 5 | #include "client_app.h" 6 | 7 | namespace extensions_window { 8 | 9 | // Delegate creation. Called from ClientHandler. 10 | void CreateProcessMessageDelegates( 11 | ClientHandler::ProcessMessageDelegateSet& delegates); 12 | // Create the render delegate. 13 | void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates); 14 | 15 | // Platform implementations. 16 | void StartDrag(HWND hwnd); 17 | void SetTopMost(HWND hwnd, bool on); 18 | void MoveTo(HWND hwnd, int x, int y); 19 | void MoveBy(HWND hwnd, int x, int y); 20 | void ResizeTo(HWND hwnd, int width, int height); 21 | void ResizeBy(HWND hwnd, int width, int height); 22 | void Focus(HWND hwnd); 23 | void Blur(HWND hwnd); 24 | void Show(HWND hwnd); 25 | void Hide(HWND hwnd); 26 | void Maximize(HWND hwnd); 27 | void Minimize(HWND hwnd); 28 | void Restore(HWND hwnd); 29 | } // namespace extensions_window 30 | 31 | #endif // CEFCLIENT_EXTENSIONS_WINDOW_H_ 32 | -------------------------------------------------------------------------------- /doomtool/extensions/cefclient_extensions_window_win.cpp: -------------------------------------------------------------------------------- 1 | #include "cefclient_extensions_window.h" 2 | 3 | namespace extensions_window { 4 | 5 | namespace { 6 | 7 | // Toggles the current display state. 8 | void Toggle(HWND hwnd, UINT nCmdShow) { 9 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 10 | WINDOWPLACEMENT placement; 11 | ::GetWindowPlacement(root_wnd, &placement); 12 | 13 | if (placement.showCmd == nCmdShow) 14 | ::ShowWindow(root_wnd, SW_RESTORE); 15 | else 16 | ::ShowWindow(root_wnd, nCmdShow); 17 | } 18 | 19 | } // namespace 20 | 21 | void StartDrag(HWND hwnd) { 22 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 23 | WINDOWPLACEMENT placement; 24 | ::GetWindowPlacement(root_wnd, &placement); 25 | if(placement.showCmd == SW_MAXIMIZE) 26 | return; 27 | 28 | ::ReleaseCapture(); 29 | ::SendMessage(root_wnd, WM_NCLBUTTONDOWN, HTCAPTION, NULL); 30 | ::SendMessage(root_wnd, WM_LBUTTONUP, NULL, NULL); 31 | } 32 | 33 | void SetTopMost(HWND hwnd, bool on) { 34 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 35 | ::SetWindowPos(root_wnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); 36 | } 37 | 38 | void MoveTo(HWND hwnd, int x, int y) { 39 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 40 | // Retrieve current window placement information. 41 | WINDOWPLACEMENT placement; 42 | ::GetWindowPlacement(root_wnd, &placement); 43 | if(placement.showCmd == SW_MAXIMIZE) 44 | return; 45 | else if (placement.showCmd == SW_MINIMIZE) 46 | ::ShowWindow(root_wnd, SW_RESTORE); 47 | ::SetWindowPos(root_wnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); 48 | 49 | } 50 | void MoveBy(HWND hwnd, int x, int y) { 51 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 52 | RECT rect = {0}; 53 | if (::GetWindowRect(root_wnd, &rect)) { 54 | MoveTo(hwnd, rect.left+x, rect.top+y); 55 | } 56 | } 57 | 58 | void ResizeTo(HWND hwnd, int width, int height) { 59 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 60 | 61 | // Retrieve current window placement information. 62 | WINDOWPLACEMENT placement; 63 | ::GetWindowPlacement(root_wnd, &placement); 64 | 65 | if(placement.showCmd == SW_MAXIMIZE) 66 | return; 67 | 68 | HMONITOR monitor = MonitorFromRect(&placement.rcNormalPosition, 69 | MONITOR_DEFAULTTONEAREST); 70 | MONITORINFO info; 71 | info.cbSize = sizeof(info); 72 | GetMonitorInfo(monitor, &info); 73 | 74 | if (width < 100) 75 | width = 100; 76 | else if (width > info.rcWork.right - info.rcWork.left) 77 | width = info.rcWork.right - info.rcWork.left; 78 | if (height < 100) 79 | height = 100; 80 | else if (height > info.rcWork.bottom - info.rcWork.top) 81 | height = info.rcWork.bottom - info.rcWork.top; 82 | 83 | ::SetWindowPos(root_wnd, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER); 84 | if (placement.showCmd == SW_MINIMIZE) 85 | ::ShowWindow(root_wnd, SW_RESTORE); 86 | } 87 | 88 | void ResizeBy(HWND hwnd, int width, int height) { 89 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 90 | RECT rect = {0}; 91 | if (::GetWindowRect(root_wnd, &rect)) { 92 | ResizeTo(root_wnd, rect.right-rect.left+width, rect.bottom-rect.top+height); 93 | } 94 | } 95 | 96 | void Focus(HWND hwnd) { 97 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 98 | ::SetFocus(root_wnd); 99 | } 100 | 101 | void Blur(HWND hwnd) { 102 | ::SetFocus(NULL); 103 | } 104 | 105 | void Show(HWND hwnd) { 106 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 107 | ::ShowWindow(root_wnd, SW_SHOW); 108 | } 109 | 110 | void Hide(HWND hwnd) { 111 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 112 | ::ShowWindow(root_wnd, SW_HIDE); 113 | } 114 | 115 | void Maximize(HWND hwnd) { 116 | Toggle(hwnd, SW_MAXIMIZE); 117 | } 118 | 119 | void Minimize(HWND hwnd) { 120 | Toggle(hwnd, SW_MINIMIZE); 121 | } 122 | 123 | void Restore(HWND hwnd) { 124 | HWND root_wnd = ::GetAncestor(hwnd, GA_ROOT); 125 | ::ShowWindow(root_wnd, SW_RESTORE); 126 | } 127 | 128 | } // namespace extensions_window 129 | -------------------------------------------------------------------------------- /doomtool/osrenderer.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include "osrenderer.h" 6 | 7 | #if defined(OS_WIN) 8 | #include 9 | #include 10 | #elif defined(OS_MACOSX) 11 | #include 12 | #elif defined(OS_LINUX) 13 | #include 14 | #include 15 | #else 16 | #error Platform is not supported. 17 | #endif 18 | 19 | #include "util.h" 20 | 21 | #ifndef GL_BGR 22 | #define GL_BGR 0x80E0 23 | #endif 24 | #ifndef GL_BGRA 25 | #define GL_BGRA 0x80E1 26 | #endif 27 | #ifndef GL_UNSIGNED_INT_8_8_8_8_REV 28 | #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 29 | #endif 30 | 31 | 32 | ClientOSRenderer::ClientOSRenderer(bool transparent) 33 | : transparent_(transparent), 34 | initialized_(false), 35 | texture_id_(0), 36 | view_width_(0), 37 | view_height_(0), 38 | spin_x_(0), 39 | spin_y_(0) { 40 | } 41 | 42 | ClientOSRenderer::~ClientOSRenderer() { 43 | Cleanup(); 44 | } 45 | 46 | void ClientOSRenderer::Initialize() { 47 | if (initialized_) 48 | return; 49 | 50 | glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); 51 | 52 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 53 | 54 | // Necessary for non-power-of-2 textures to render correctly. 55 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 56 | 57 | // Create the texture. 58 | glGenTextures(1, &texture_id_); 59 | ASSERT(texture_id_ != 0); 60 | 61 | glBindTexture(GL_TEXTURE_2D, texture_id_); 62 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 63 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 64 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 65 | 66 | initialized_ = true; 67 | } 68 | 69 | void ClientOSRenderer::Cleanup() { 70 | if (texture_id_ != 0) 71 | glDeleteTextures(1, &texture_id_); 72 | } 73 | 74 | void ClientOSRenderer::Render() { 75 | if (view_width_ == 0 || view_height_ == 0) 76 | return; 77 | 78 | ASSERT(initialized_); 79 | 80 | struct { 81 | float tu, tv; 82 | float x, y, z; 83 | } static vertices[] = { 84 | {0.0f, 1.0f, -1.0f, -1.0f, 0.0f}, 85 | {1.0f, 1.0f, 1.0f, -1.0f, 0.0f}, 86 | {1.0f, 0.0f, 1.0f, 1.0f, 0.0f}, 87 | {0.0f, 0.0f, -1.0f, 1.0f, 0.0f} 88 | }; 89 | 90 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 91 | 92 | glMatrixMode(GL_MODELVIEW); 93 | glLoadIdentity(); 94 | 95 | // Match GL units to screen coordinates. 96 | glViewport(0, 0, view_width_, view_height_); 97 | glMatrixMode(GL_PROJECTION); 98 | glLoadIdentity(); 99 | glOrtho(0, 0, view_width_, view_height_, 0.1, 100.0); 100 | 101 | // Draw the background gradient. 102 | /*glPushAttrib(GL_ALL_ATTRIB_BITS); 103 | glBegin(GL_QUADS); 104 | glColor4f(1.0, 0.0, 0.0, 1.0); // red 105 | glVertex2f(-1.0, -1.0); 106 | glVertex2f(1.0, -1.0); 107 | glColor4f(1.0, 0.0, 0.0, 1.0); // blue 108 | glVertex2f(1.0, 1.0); 109 | glVertex2f(-1.0, 1.0); 110 | glEnd(); 111 | glPopAttrib();*/ 112 | 113 | // Rotate the view based on the mouse spin. 114 | if (spin_x_ != 0) 115 | glRotatef(-spin_x_, 1.0f, 0.0f, 0.0f); 116 | if (spin_y_ != 0) 117 | glRotatef(-spin_y_, 0.0f, 1.0f, 0.0f); 118 | 119 | if (transparent_) { 120 | // Alpha blending style. Texture values have premultiplied alpha. 121 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 122 | 123 | // Enable alpha blending. 124 | glEnable(GL_BLEND); 125 | } 126 | 127 | // Enable 2D textures. 128 | glEnable(GL_TEXTURE_2D); 129 | 130 | // Draw the facets with the texture. 131 | ASSERT(texture_id_ != 0); 132 | glBindTexture(GL_TEXTURE_2D, texture_id_); 133 | glInterleavedArrays(GL_T2F_V3F, 0, vertices); 134 | glDrawArrays(GL_QUADS, 0, 4); 135 | 136 | // Disable 2D textures. 137 | glDisable(GL_TEXTURE_2D); 138 | 139 | if (transparent_) { 140 | // Disable alpha blending. 141 | glDisable(GL_BLEND); 142 | } 143 | } 144 | 145 | void ClientOSRenderer::OnPopupShow(CefRefPtr browser, 146 | bool show) { 147 | if (!show) { 148 | // Clear the popup rectangle. 149 | ClearPopupRects(); 150 | } 151 | } 152 | 153 | void ClientOSRenderer::OnPopupSize(CefRefPtr browser, 154 | const CefRect& rect) { 155 | if (rect.width <= 0 || rect.height <= 0) 156 | return; 157 | original_popup_rect_ = rect; 158 | popup_rect_ = GetPopupRectInWebView(original_popup_rect_); 159 | } 160 | 161 | CefRect ClientOSRenderer::GetPopupRectInWebView(const CefRect& original_rect) { 162 | CefRect rc(original_rect); 163 | // if x or y are negative, move them to 0. 164 | if (rc.x < 0) 165 | rc.x = 0; 166 | if (rc.y < 0) 167 | rc.y = 0; 168 | // if popup goes outside the view, try to reposition origin 169 | if (rc.x + rc.width > view_width_) 170 | rc.x = view_width_ - rc.width; 171 | if (rc.y + rc.height > view_height_) 172 | rc.y = view_height_ - rc.height; 173 | // if x or y became negative, move them to 0 again. 174 | if (rc.x < 0) 175 | rc.x = 0; 176 | if (rc.y < 0) 177 | rc.y = 0; 178 | return rc; 179 | } 180 | 181 | void ClientOSRenderer::ClearPopupRects() { 182 | popup_rect_.Set(0, 0, 0, 0); 183 | original_popup_rect_.Set(0, 0, 0, 0); 184 | } 185 | 186 | void ClientOSRenderer::OnPaint(CefRefPtr browser, 187 | CefRenderHandler::PaintElementType type, 188 | const CefRenderHandler::RectList& dirtyRects, 189 | const void* buffer, int width, int height) { 190 | if (!initialized_) 191 | Initialize(); 192 | 193 | if (transparent_) { 194 | // Enable alpha blending. 195 | glEnable(GL_BLEND); 196 | } 197 | 198 | // Enable 2D textures. 199 | glEnable(GL_TEXTURE_2D); 200 | 201 | ASSERT(texture_id_ != 0); 202 | glBindTexture(GL_TEXTURE_2D, texture_id_); 203 | 204 | if (type == PET_VIEW) { 205 | int old_width = view_width_; 206 | int old_height = view_height_; 207 | 208 | view_width_ = width; 209 | view_height_ = height; 210 | 211 | glPixelStorei(GL_UNPACK_ROW_LENGTH, view_width_); 212 | 213 | if (old_width != view_width_ || old_height != view_height_) { 214 | // Update/resize the whole texture. 215 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); 216 | glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); 217 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, view_width_, view_height_, 0, 218 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buffer); 219 | } else { 220 | // Update just the dirty rectangles. 221 | CefRenderHandler::RectList::const_iterator i = dirtyRects.begin(); 222 | for (; i != dirtyRects.end(); ++i) { 223 | const CefRect& rect = *i; 224 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, rect.x); 225 | glPixelStorei(GL_UNPACK_SKIP_ROWS, rect.y); 226 | glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x, rect.y, rect.width, 227 | rect.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 228 | buffer); 229 | } 230 | } 231 | } else if (type == PET_POPUP && popup_rect_.width > 0 && 232 | popup_rect_.height > 0) { 233 | int skip_pixels = 0, x = popup_rect_.x; 234 | int skip_rows = 0, y = popup_rect_.y; 235 | int w = width; 236 | int h = height; 237 | 238 | // Adjust the popup to fit inside the view. 239 | if (x < 0) { 240 | skip_pixels = -x; 241 | x = 0; 242 | } 243 | if (y < 0) { 244 | skip_rows = -y; 245 | y = 0; 246 | } 247 | if (x + w > view_width_) 248 | w -= x + w - view_width_; 249 | if (y + h > view_height_) 250 | h -= y + h - view_height_; 251 | 252 | // Update the popup rectangle. 253 | glPixelStorei(GL_UNPACK_ROW_LENGTH, width); 254 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels); 255 | glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows); 256 | glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_BGRA, 257 | GL_UNSIGNED_INT_8_8_8_8_REV, buffer); 258 | } 259 | 260 | // Disable 2D textures. 261 | glDisable(GL_TEXTURE_2D); 262 | 263 | if (transparent_) { 264 | // Disable alpha blending. 265 | glDisable(GL_BLEND); 266 | } 267 | } 268 | 269 | void ClientOSRenderer::SetSpin(float spinX, float spinY) { 270 | spin_x_ = spinX; 271 | spin_y_ = spinY; 272 | } 273 | 274 | void ClientOSRenderer::IncrementSpin(float spinDX, float spinDY) { 275 | spin_x_ -= spinDX; 276 | spin_y_ -= spinDY; 277 | } 278 | -------------------------------------------------------------------------------- /doomtool/osrenderer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #ifndef CEF_TESTS_CEFCLIENT_OSRENDERER_H_ 6 | #define CEF_TESTS_CEFCLIENT_OSRENDERER_H_ 7 | #pragma once 8 | 9 | #include "include/cef_browser.h" 10 | #include "include/cef_render_handler.h" 11 | 12 | class ClientOSRenderer { 13 | public: 14 | // The context must outlive this object. 15 | explicit ClientOSRenderer(bool transparent); 16 | virtual ~ClientOSRenderer(); 17 | 18 | // Initialize the OpenGL environment. 19 | void Initialize(); 20 | 21 | // Clean up the OpenGL environment. 22 | void Cleanup(); 23 | 24 | // Render to the screen. 25 | void Render(); 26 | 27 | // Forwarded from CefRenderHandler callbacks. 28 | void OnPopupShow(CefRefPtr browser, 29 | bool show); 30 | void OnPopupSize(CefRefPtr browser, 31 | const CefRect& rect); 32 | void OnPaint(CefRefPtr browser, 33 | CefRenderHandler::PaintElementType type, 34 | const CefRenderHandler::RectList& dirtyRects, 35 | const void* buffer, int width, int height); 36 | 37 | // Apply spin. 38 | void SetSpin(float spinX, float spinY); 39 | void IncrementSpin(float spinDX, float spinDY); 40 | 41 | bool IsTransparent() { return transparent_; } 42 | 43 | int GetViewWidth() { return view_width_; } 44 | int GetViewHeight() { return view_height_; } 45 | 46 | const CefRect& popup_rect() const { return popup_rect_; } 47 | const CefRect& original_popup_rect() const { return original_popup_rect_; } 48 | 49 | CefRect GetPopupRectInWebView(const CefRect& original_rect); 50 | void ClearPopupRects(); 51 | 52 | private: 53 | bool transparent_; 54 | bool initialized_; 55 | unsigned int texture_id_; 56 | int view_width_; 57 | int view_height_; 58 | CefRect popup_rect_; 59 | CefRect original_popup_rect_; 60 | float spin_x_; 61 | float spin_y_; 62 | }; 63 | 64 | #endif // CEF_TESTS_CEFCLIENT_OSRENDERER_H_ 65 | 66 | -------------------------------------------------------------------------------- /doomtool/res/doomtool.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/doomtool/res/doomtool.ico -------------------------------------------------------------------------------- /doomtool/res/window.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teaegg/cef3-windows-sample/253e3f00cb3c82ca3ce4bcc5cb6cc56f026c40c0/doomtool/res/window.html -------------------------------------------------------------------------------- /doomtool/res/window.js: -------------------------------------------------------------------------------- 1 | var app; 2 | if (!app) 3 | app = {}; 4 | if(!app.window) 5 | app.window = {}; 6 | (function () { 7 | native function sendMessage(); 8 | app.sendMessage = function(name, arguments) { 9 | return sendMessage(name, arguments); 10 | }; 11 | 12 | native function WindowShow(); 13 | app.window.show = function() { 14 | WindowShow(); 15 | } 16 | 17 | native function WindowHide(); 18 | app.window.hide = function() { 19 | WindowHide(); 20 | } 21 | 22 | native function WindowMinimize(); 23 | app.window.minimize = function() { 24 | WindowMinimize(); 25 | } 26 | 27 | native function WindowMaximize(); 28 | app.window.maximize = function() { 29 | WindowMaximize(); 30 | } 31 | 32 | native function WindowClose(); 33 | app.window.close = function() { 34 | WindowClose(); 35 | } 36 | })(); -------------------------------------------------------------------------------- /doomtool/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by cefclient.rc 4 | // 5 | #define IDI_CEFCLIENT 107 6 | #define IDS_WINDOW 1010 7 | #define IDS_WINDOW_JS 1011 8 | #define ID_OPENMAINWINDOW 32500 9 | #define ID_QUIT 32501 10 | 11 | // Next default values for new objects 12 | // 13 | #ifdef APSTUDIO_INVOKED 14 | #ifndef APSTUDIO_READONLY_SYMBOLS 15 | #define _APS_NO_MFC 1 16 | #define _APS_NEXT_RESOURCE_VALUE 151 17 | #define _APS_NEXT_COMMAND_VALUE 32774 18 | #define _APS_NEXT_CONTROL_VALUE 1000 19 | #define _APS_NEXT_SYMED_VALUE 111 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /doomtool/resource_util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #ifndef CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_ 6 | #define CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_ 7 | #pragma once 8 | 9 | #include 10 | #include "include/cef_stream.h" 11 | 12 | #if defined(OS_POSIX) 13 | // Returns the directory containing resource files. 14 | bool GetResourceDir(std::string& dir); 15 | #endif 16 | 17 | // Retrieve a resource as a string. 18 | bool LoadBinaryResource(const char* resource_name, std::string& resource_data); 19 | 20 | // Retrieve a resource as a steam reader. 21 | CefRefPtr GetBinaryResourceReader(const char* resource_name); 22 | 23 | #endif // CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_ 24 | -------------------------------------------------------------------------------- /doomtool/resource_util_win.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "resource_util.h" 6 | #include "include/cef_stream.h" 7 | #include "include/wrapper/cef_byte_read_handler.h" 8 | #include "resource.h" 9 | #include "util.h" 10 | 11 | namespace { 12 | 13 | bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes) { 14 | HINSTANCE hInst = GetModuleHandle(NULL); 15 | HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(binaryId), 16 | MAKEINTRESOURCE(256)); 17 | if (hRes) { 18 | HGLOBAL hGlob = LoadResource(hInst, hRes); 19 | if (hGlob) { 20 | dwSize = SizeofResource(hInst, hRes); 21 | pBytes = (LPBYTE)LockResource(hGlob); 22 | if (dwSize > 0 && pBytes) 23 | return true; 24 | } 25 | } 26 | 27 | return false; 28 | } 29 | 30 | int GetResourceId(const char* resource_name) { 31 | // Map of resource labels to BINARY id values. 32 | static struct _resource_map { 33 | char* name; 34 | int id; 35 | } resource_map[] = { 36 | {"window.html", IDS_WINDOW}, 37 | {"window.js", IDS_WINDOW_JS} 38 | }; 39 | 40 | for (int i = 0; i < sizeof(resource_map)/sizeof(_resource_map); ++i) { 41 | if (!strcmp(resource_map[i].name, resource_name)) 42 | return resource_map[i].id; 43 | } 44 | 45 | return 0; 46 | } 47 | 48 | } // namespace 49 | 50 | bool LoadBinaryResource(const char* resource_name, std::string& resource_data) { 51 | int resource_id = GetResourceId(resource_name); 52 | if (resource_id == 0) 53 | return false; 54 | 55 | DWORD dwSize; 56 | LPBYTE pBytes; 57 | 58 | if (LoadBinaryResource(resource_id, dwSize, pBytes)) { 59 | resource_data = std::string(reinterpret_cast(pBytes), dwSize); 60 | return true; 61 | } 62 | 63 | ASSERT(FALSE); // The resource should be found. 64 | return false; 65 | } 66 | 67 | CefRefPtr GetBinaryResourceReader(const char* resource_name) { 68 | int resource_id = GetResourceId(resource_name); 69 | if (resource_id == 0) 70 | return NULL; 71 | 72 | DWORD dwSize; 73 | LPBYTE pBytes; 74 | 75 | if (LoadBinaryResource(resource_id, dwSize, pBytes)) { 76 | return CefStreamReader::CreateForHandler( 77 | new CefByteReadHandler(pBytes, dwSize, NULL)); 78 | } 79 | 80 | ASSERT(FALSE); // The resource should be found. 81 | return NULL; 82 | } 83 | -------------------------------------------------------------------------------- /doomtool/scheme_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "scheme_test.h" 6 | #include 7 | #include 8 | #include "include/cef_browser.h" 9 | #include "include/cef_callback.h" 10 | #include "include/cef_frame.h" 11 | #include "include/cef_resource_handler.h" 12 | #include "include/cef_response.h" 13 | #include "include/cef_request.h" 14 | #include "include/cef_scheme.h" 15 | #include "resource_util.h" 16 | #include "string_util.h" 17 | #include "util.h" 18 | 19 | #if defined(OS_WIN) 20 | #include "resource.h" 21 | #endif 22 | 23 | namespace scheme_test { 24 | 25 | namespace { 26 | 27 | // Implementation of the schema handler for client:// requests. 28 | class ClientSchemeHandler : public CefResourceHandler { 29 | public: 30 | ClientSchemeHandler() : offset_(0) {} 31 | 32 | virtual bool ProcessRequest(CefRefPtr request, 33 | CefRefPtr callback) 34 | OVERRIDE { 35 | REQUIRE_IO_THREAD(); 36 | 37 | bool handled = false; 38 | 39 | AutoLock lock_scope(this); 40 | 41 | std::string url = request->GetURL(); 42 | if (strstr(url.c_str(), "handler.html") != NULL) { 43 | // Build the response html 44 | data_ = "Client Scheme Handler" 45 | "" 46 | "This contents of this page page are served by the " 47 | "ClientSchemeHandler class handling the client:// protocol." 48 | "
You should see an image:" 49 | "
";
 50 | 
 51 |       // Output a string representation of the request
 52 |       std::string dump;
 53 |       DumpRequestContents(request, dump);
 54 |       data_.append(dump);
 55 | 
 56 |       data_.append("

Try the test form:" 57 | "
" 58 | "" 59 | "" 60 | "" 61 | "
"); 62 | 63 | handled = true; 64 | 65 | // Set the resulting mime type 66 | mime_type_ = "text/html"; 67 | } else if (strstr(url.c_str(), "logo.png") != NULL) { 68 | // Load the response image 69 | if (LoadBinaryResource("logo.png", data_)) { 70 | handled = true; 71 | // Set the resulting mime type 72 | mime_type_ = "image/png"; 73 | } 74 | } 75 | 76 | if (handled) { 77 | // Indicate the headers are available. 78 | callback->Continue(); 79 | return true; 80 | } 81 | 82 | return false; 83 | } 84 | 85 | virtual void GetResponseHeaders(CefRefPtr response, 86 | int64& response_length, 87 | CefString& redirectUrl) OVERRIDE { 88 | REQUIRE_IO_THREAD(); 89 | 90 | ASSERT(!data_.empty()); 91 | 92 | response->SetMimeType(mime_type_); 93 | response->SetStatus(200); 94 | 95 | // Set the resulting response length 96 | response_length = data_.length(); 97 | } 98 | 99 | virtual void Cancel() OVERRIDE { 100 | REQUIRE_IO_THREAD(); 101 | } 102 | 103 | virtual bool ReadResponse(void* data_out, 104 | int bytes_to_read, 105 | int& bytes_read, 106 | CefRefPtr callback) 107 | OVERRIDE { 108 | REQUIRE_IO_THREAD(); 109 | 110 | bool has_data = false; 111 | bytes_read = 0; 112 | 113 | AutoLock lock_scope(this); 114 | 115 | if (offset_ < data_.length()) { 116 | // Copy the next block of data into the buffer. 117 | int transfer_size = 118 | std::min(bytes_to_read, static_cast(data_.length() - offset_)); 119 | memcpy(data_out, data_.c_str() + offset_, transfer_size); 120 | offset_ += transfer_size; 121 | 122 | bytes_read = transfer_size; 123 | has_data = true; 124 | } 125 | 126 | return has_data; 127 | } 128 | 129 | private: 130 | std::string data_; 131 | std::string mime_type_; 132 | size_t offset_; 133 | 134 | IMPLEMENT_REFCOUNTING(ClientSchemeHandler); 135 | IMPLEMENT_LOCKING(ClientSchemeHandler); 136 | }; 137 | 138 | // Implementation of the factory for for creating schema handlers. 139 | class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory { 140 | public: 141 | // Return a new scheme handler instance to handle the request. 142 | virtual CefRefPtr Create(CefRefPtr browser, 143 | CefRefPtr frame, 144 | const CefString& scheme_name, 145 | CefRefPtr request) 146 | OVERRIDE { 147 | REQUIRE_IO_THREAD(); 148 | return new ClientSchemeHandler(); 149 | } 150 | 151 | IMPLEMENT_REFCOUNTING(ClientSchemeHandlerFactory); 152 | }; 153 | 154 | } // namespace 155 | 156 | void RegisterCustomSchemes(CefRefPtr registrar, 157 | std::vector& cookiable_schemes) { 158 | registrar->AddCustomScheme("client", true, false, false); 159 | } 160 | 161 | void InitTest() { 162 | CefRegisterSchemeHandlerFactory("client", "tests", 163 | new ClientSchemeHandlerFactory()); 164 | } 165 | 166 | } // namespace scheme_test 167 | -------------------------------------------------------------------------------- /doomtool/scheme_test.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #ifndef CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_ 6 | #define CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_ 7 | #pragma once 8 | 9 | #include 10 | #include "include/cef_base.h" 11 | 12 | class CefBrowser; 13 | class CefSchemeRegistrar; 14 | 15 | namespace scheme_test { 16 | 17 | // Register the scheme. 18 | void RegisterCustomSchemes(CefRefPtr registrar, 19 | std::vector& cookiable_schemes); 20 | 21 | // Create the scheme handler. 22 | void InitTest(); 23 | 24 | } // namespace scheme_test 25 | 26 | #endif // CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_ 27 | -------------------------------------------------------------------------------- /doomtool/string_util.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "string_util.h" 6 | #include 7 | #include 8 | #include "include/cef_request.h" 9 | 10 | void DumpRequestContents(CefRefPtr request, std::string& str) { 11 | std::stringstream ss; 12 | 13 | ss << "URL: " << std::string(request->GetURL()); 14 | ss << "\nMethod: " << std::string(request->GetMethod()); 15 | 16 | CefRequest::HeaderMap headerMap; 17 | request->GetHeaderMap(headerMap); 18 | if (headerMap.size() > 0) { 19 | ss << "\nHeaders:"; 20 | CefRequest::HeaderMap::const_iterator it = headerMap.begin(); 21 | for (; it != headerMap.end(); ++it) { 22 | ss << "\n\t" << std::string((*it).first) << ": " << 23 | std::string((*it).second); 24 | } 25 | } 26 | 27 | CefRefPtr postData = request->GetPostData(); 28 | if (postData.get()) { 29 | CefPostData::ElementVector elements; 30 | postData->GetElements(elements); 31 | if (elements.size() > 0) { 32 | ss << "\nPost Data:"; 33 | CefRefPtr element; 34 | CefPostData::ElementVector::const_iterator it = elements.begin(); 35 | for (; it != elements.end(); ++it) { 36 | element = (*it); 37 | if (element->GetType() == PDE_TYPE_BYTES) { 38 | // the element is composed of bytes 39 | ss << "\n\tBytes: "; 40 | if (element->GetBytesCount() == 0) { 41 | ss << "(empty)"; 42 | } else { 43 | // retrieve the data. 44 | size_t size = element->GetBytesCount(); 45 | char* bytes = new char[size]; 46 | element->GetBytes(size, bytes); 47 | ss << std::string(bytes, size); 48 | delete [] bytes; 49 | } 50 | } else if (element->GetType() == PDE_TYPE_FILE) { 51 | ss << "\n\tFile: " << std::string(element->GetFile()); 52 | } 53 | } 54 | } 55 | } 56 | 57 | str = ss.str(); 58 | } 59 | 60 | std::string StringReplace(const std::string& str, const std::string& from, 61 | const std::string& to) { 62 | std::string result = str; 63 | std::string::size_type pos = 0; 64 | std::string::size_type from_len = from.length(); 65 | std::string::size_type to_len = to.length(); 66 | do { 67 | pos = result.find(from, pos); 68 | if (pos != std::string::npos) { 69 | result.replace(pos, from_len, to); 70 | pos += to_len; 71 | } 72 | } while (pos != std::string::npos); 73 | return result; 74 | } 75 | -------------------------------------------------------------------------------- /doomtool/string_util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #ifndef CEF_TESTS_CEFCLIENT_STRING_UTIL_H_ 6 | #define CEF_TESTS_CEFCLIENT_STRING_UTIL_H_ 7 | #pragma once 8 | 9 | #include 10 | #include "include/cef_base.h" 11 | 12 | class CefRequest; 13 | 14 | // Dump the contents of the request into a string. 15 | void DumpRequestContents(CefRefPtr request, std::string& str); 16 | 17 | // Replace all instances of |from| with |to| in |str|. 18 | std::string StringReplace(const std::string& str, const std::string& from, 19 | const std::string& to); 20 | 21 | #endif // CEF_TESTS_CEFCLIENT_STRING_UTIL_H_ 22 | -------------------------------------------------------------------------------- /doomtool/util.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #ifndef CEF_TESTS_CEFCLIENT_UTIL_H_ 6 | #define CEF_TESTS_CEFCLIENT_UTIL_H_ 7 | #pragma once 8 | 9 | #include "include/cef_task.h" 10 | 11 | #if defined(OS_WIN) 12 | 13 | #include // NOLINT(build/include_order) 14 | 15 | #ifndef NDEBUG 16 | #define ASSERT(condition) if (!(condition)) { DebugBreak(); } 17 | #else 18 | #define ASSERT(condition) ((void)0) 19 | #endif 20 | 21 | #else // !OS_WIN 22 | 23 | #include // NOLINT(build/include_order) 24 | 25 | #ifndef NDEBUG 26 | #define ASSERT(condition) if (!(condition)) { assert(false); } 27 | #else 28 | #define ASSERT(condition) ((void)0) 29 | #endif 30 | 31 | #endif // !OS_WIN 32 | 33 | #define REQUIRE_UI_THREAD() ASSERT(CefCurrentlyOn(TID_UI)); 34 | #define REQUIRE_IO_THREAD() ASSERT(CefCurrentlyOn(TID_IO)); 35 | #define REQUIRE_FILE_THREAD() ASSERT(CefCurrentlyOn(TID_FILE)); 36 | 37 | #endif // CEF_TESTS_CEFCLIENT_UTIL_H_ 38 | -------------------------------------------------------------------------------- /doomtool/window_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "window_test.h" 6 | #include "resource_util.h" 7 | 8 | namespace window_test { 9 | 10 | namespace { 11 | 12 | const char* kMessagePositionName = "WindowTest.Position"; 13 | const char* kMessageMinimizeName = "WindowTest.Minimize"; 14 | const char* kMessageMaximizeName = "WindowMaximize"; 15 | const char* kMessageRestoreName = "WindowTest.Restore"; 16 | 17 | // Handle messages in the browser process. 18 | class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate { 19 | public: 20 | ProcessMessageDelegate() { 21 | } 22 | 23 | // From ClientHandler::ProcessMessageDelegate. 24 | virtual bool OnProcessMessageReceived( 25 | CefRefPtr handler, 26 | CefRefPtr browser, 27 | CefProcessId source_process, 28 | CefRefPtr message) OVERRIDE { 29 | std::string message_name = message->GetName(); 30 | if (message_name == kMessagePositionName) { 31 | CefRefPtr args = message->GetArgumentList(); 32 | if (args->GetSize() >= 4) { 33 | int x = args->GetInt(0); 34 | int y = args->GetInt(1); 35 | int width = args->GetInt(2); 36 | int height = args->GetInt(3); 37 | SetPos(browser->GetHost()->GetWindowHandle(), x, y, width, height); 38 | } 39 | return true; 40 | } else if (message_name == kMessageMinimizeName) { 41 | Minimize(browser->GetHost()->GetWindowHandle()); 42 | return true; 43 | } else if (message_name == kMessageMaximizeName) { 44 | Maximize(browser->GetHost()->GetWindowHandle()); 45 | return true; 46 | } else if (message_name == kMessageRestoreName) { 47 | Restore(browser->GetHost()->GetWindowHandle()); 48 | return true; 49 | } 50 | 51 | return false; 52 | } 53 | 54 | IMPLEMENT_REFCOUNTING(ProcessMessageDelegate); 55 | }; 56 | 57 | // Handles the native implementation for the client_app extension. 58 | class WindowExtensionHandler : public CefV8Handler { 59 | public: 60 | WindowExtensionHandler(){ 61 | } 62 | 63 | virtual bool Execute(const CefString& name, 64 | CefRefPtr object, 65 | const CefV8ValueList& arguments, 66 | CefRefPtr& retval, 67 | CefString& exception) { 68 | bool handled = false; 69 | 70 | if (name == "sendMessage") { 71 | // Send a message to the browser process. 72 | if ((arguments.size() == 1 || arguments.size() == 2) && 73 | arguments[0]->IsString()) { 74 | CefRefPtr browser = 75 | CefV8Context::GetCurrentContext()->GetBrowser(); 76 | ASSERT(browser.get()); 77 | 78 | CefString name = arguments[0]->GetStringValue(); 79 | if (!name.empty()) { 80 | CefRefPtr message = 81 | CefProcessMessage::Create(name); 82 | // Translate the arguments, if any. 83 | if (arguments.size() == 2 && arguments[1]->IsArray()) 84 | SetList(arguments[1], message->GetArgumentList()); 85 | 86 | browser->SendProcessMessage(PID_BROWSER, message); 87 | handled = true; 88 | } 89 | } 90 | } else if (name == "WindowMaximize") { 91 | if (arguments.size() == 0) { 92 | CefRefPtr browser = 93 | CefV8Context::GetCurrentContext()->GetBrowser(); 94 | CefRefPtr message = CefProcessMessage::Create(name); 95 | browser->SendProcessMessage(PID_BROWSER, message); 96 | handled = true; 97 | } 98 | } 99 | if (!handled) 100 | exception = "Invalid method arguments"; 101 | 102 | return true; 103 | } 104 | 105 | private: 106 | IMPLEMENT_REFCOUNTING(ClientAppExtensionHandler); 107 | }; 108 | 109 | class WindowRenderDelegate : public ClientApp::RenderDelegate { 110 | public: 111 | WindowRenderDelegate() { 112 | } 113 | 114 | virtual void OnWebKitInitialized(CefRefPtr app) { 115 | // Register the client_app extension. 116 | std::string window_code; 117 | if(!LoadBinaryResource("window.js", window_code)) 118 | ::MessageBox(NULL,L"LOAD ARROR!", 0,0); 119 | CefRegisterExtension("v8/app", window_code, 120 | new WindowExtensionHandler()); 121 | } 122 | 123 | virtual bool OnProcessMessageReceived( 124 | CefRefPtr app, 125 | CefRefPtr browser, 126 | CefProcessId source_process, 127 | CefRefPtr message) OVERRIDE { 128 | return false; 129 | } 130 | 131 | private: 132 | IMPLEMENT_REFCOUNTING(DOMRenderDelegate); 133 | }; 134 | 135 | } // namespace 136 | 137 | void CreateProcessMessageDelegates( 138 | ClientHandler::ProcessMessageDelegateSet& delegates) { 139 | delegates.insert(new ProcessMessageDelegate); 140 | } 141 | void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates) { 142 | delegates.insert(new WindowRenderDelegate); 143 | } 144 | void ModifyBounds(const CefRect& display, CefRect& window) { 145 | window.x += display.x; 146 | window.y += display.y; 147 | 148 | if (window.x < display.x) 149 | window.x = display.x; 150 | if (window.y < display.y) 151 | window.y = display.y; 152 | if (window.width < 100) 153 | window.width = 100; 154 | else if (window.width >= display.width) 155 | window.width = display.width; 156 | if (window.height < 100) 157 | window.height = 100; 158 | else if (window.height >= display.height) 159 | window.height = display.height; 160 | if (window.x + window.width >= display.x + display.width) 161 | window.x = display.x + display.width - window.width; 162 | if (window.y + window.height >= display.y + display.height) 163 | window.y = display.y + display.height - window.height; 164 | } 165 | 166 | // Transfer a V8 value to a List index. 167 | void SetListValue(CefRefPtr list, int index, 168 | CefRefPtr value) { 169 | if (value->IsArray()) { 170 | CefRefPtr new_list = CefListValue::Create(); 171 | SetList(value, new_list); 172 | list->SetList(index, new_list); 173 | } else if (value->IsString()) { 174 | list->SetString(index, value->GetStringValue()); 175 | } else if (value->IsBool()) { 176 | list->SetBool(index, value->GetBoolValue()); 177 | } else if (value->IsInt()) { 178 | list->SetInt(index, value->GetIntValue()); 179 | } else if (value->IsDouble()) { 180 | list->SetDouble(index, value->GetDoubleValue()); 181 | } 182 | } 183 | 184 | // Transfer a V8 array to a List. 185 | void SetList(CefRefPtr source, CefRefPtr target) { 186 | ASSERT(source->IsArray()); 187 | 188 | int arg_length = source->GetArrayLength(); 189 | if (arg_length == 0) 190 | return; 191 | 192 | // Start with null types in all spaces. 193 | target->SetSize(arg_length); 194 | 195 | for (int i = 0; i < arg_length; ++i) 196 | SetListValue(target, i, source->GetValue(i)); 197 | } 198 | 199 | // Transfer a List value to a V8 array index. 200 | void SetListValue(CefRefPtr list, int index, 201 | CefRefPtr value) { 202 | CefRefPtr new_value; 203 | 204 | CefValueType type = value->GetType(index); 205 | switch (type) { 206 | case VTYPE_LIST: { 207 | CefRefPtr list = value->GetList(index); 208 | new_value = CefV8Value::CreateArray(static_cast(list->GetSize())); 209 | SetList(list, new_value); 210 | } break; 211 | case VTYPE_BOOL: 212 | new_value = CefV8Value::CreateBool(value->GetBool(index)); 213 | break; 214 | case VTYPE_DOUBLE: 215 | new_value = CefV8Value::CreateDouble(value->GetDouble(index)); 216 | break; 217 | case VTYPE_INT: 218 | new_value = CefV8Value::CreateInt(value->GetInt(index)); 219 | break; 220 | case VTYPE_STRING: 221 | new_value = CefV8Value::CreateString(value->GetString(index)); 222 | break; 223 | default: 224 | break; 225 | } 226 | 227 | if (new_value.get()) { 228 | list->SetValue(index, new_value); 229 | } else { 230 | list->SetValue(index, CefV8Value::CreateNull()); 231 | } 232 | } 233 | 234 | // Transfer a List to a V8 array. 235 | void SetList(CefRefPtr source, CefRefPtr target) { 236 | ASSERT(target->IsArray()); 237 | 238 | int arg_length = static_cast(source->GetSize()); 239 | if (arg_length == 0) 240 | return; 241 | 242 | for (int i = 0; i < arg_length; ++i) 243 | SetListValue(target, i, source); 244 | } 245 | 246 | } // namespace window_test 247 | -------------------------------------------------------------------------------- /doomtool/window_test.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #ifndef CEF_TESTS_CEFCLIENT_WINDOW_TEST_H_ 6 | #define CEF_TESTS_CEFCLIENT_WINDOW_TEST_H_ 7 | #pragma once 8 | 9 | #include "client_handler.h" 10 | #include "client_app.h" 11 | 12 | namespace window_test { 13 | 14 | // Delegate creation. Called from ClientHandler. 15 | void CreateProcessMessageDelegates( 16 | ClientHandler::ProcessMessageDelegateSet& delegates); 17 | // Create the render delegate. 18 | void CreateRenderDelegates(ClientApp::RenderDelegateSet& delegates); 19 | 20 | // Fit |window| inside |display|. Coordinates are relative to the upper-left 21 | // corner of the display. 22 | void ModifyBounds(const CefRect& display, CefRect& window); 23 | 24 | // Forward declarations. 25 | void SetList(CefRefPtr source, CefRefPtr target); 26 | void SetList(CefRefPtr source, CefRefPtr target); 27 | 28 | // Platform implementations. 29 | void SetPos(CefWindowHandle handle, int x, int y, int width, int height); 30 | void Minimize(CefWindowHandle handle); 31 | void Maximize(CefWindowHandle handle); 32 | void Restore(CefWindowHandle handle); 33 | 34 | } // namespace window_test 35 | 36 | #endif // CEF_TESTS_CEFCLIENT_WINDOW_TEST_H_ 37 | -------------------------------------------------------------------------------- /doomtool/window_test_win.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 2 | // reserved. Use of this source code is governed by a BSD-style license that 3 | // can be found in the LICENSE file. 4 | 5 | #include "window_test.h" 6 | 7 | namespace window_test { 8 | 9 | namespace { 10 | 11 | // Toggles the current display state. 12 | void Toggle(CefWindowHandle handle, UINT nCmdShow) { 13 | HWND root_wnd = ::GetAncestor(handle, GA_ROOT); 14 | 15 | // Retrieve current window placement information. 16 | WINDOWPLACEMENT placement; 17 | ::GetWindowPlacement(root_wnd, &placement); 18 | 19 | if (placement.showCmd == nCmdShow) 20 | ::ShowWindow(root_wnd, SW_RESTORE); 21 | else 22 | ::ShowWindow(root_wnd, nCmdShow); 23 | } 24 | 25 | } // namespace 26 | 27 | void SetPos(CefWindowHandle handle, int x, int y, int width, int height) { 28 | HWND root_wnd = ::GetAncestor(handle, GA_ROOT); 29 | 30 | // Retrieve current window placement information. 31 | WINDOWPLACEMENT placement; 32 | ::GetWindowPlacement(root_wnd, &placement); 33 | 34 | // Retrieve information about the display that contains the window. 35 | HMONITOR monitor = MonitorFromRect(&placement.rcNormalPosition, 36 | MONITOR_DEFAULTTONEAREST); 37 | MONITORINFO info; 38 | info.cbSize = sizeof(info); 39 | GetMonitorInfo(monitor, &info); 40 | 41 | // Make sure the window is inside the display. 42 | CefRect display_rect( 43 | info.rcWork.left, 44 | info.rcWork.top, 45 | info.rcWork.right - info.rcWork.left, 46 | info.rcWork.bottom - info.rcWork.top); 47 | CefRect window_rect(x, y, width, height); 48 | ModifyBounds(display_rect, window_rect); 49 | 50 | if (placement.showCmd == SW_MINIMIZE || placement.showCmd == SW_MAXIMIZE) { 51 | // The window is currently minimized or maximized. Restore it to the desired 52 | // position. 53 | placement.rcNormalPosition.left = window_rect.x; 54 | placement.rcNormalPosition.right = window_rect.x + window_rect.width; 55 | placement.rcNormalPosition.top = window_rect.y; 56 | placement.rcNormalPosition.bottom = window_rect.y + window_rect.height; 57 | ::SetWindowPlacement(root_wnd, &placement); 58 | ::ShowWindow(root_wnd, SW_RESTORE); 59 | } else { 60 | // Set the window position. 61 | ::SetWindowPos(root_wnd, NULL, window_rect.x, window_rect.y, 62 | window_rect.width, window_rect.height, SWP_NOZORDER); 63 | } 64 | } 65 | 66 | void Minimize(CefWindowHandle handle) { 67 | Toggle(handle, SW_MINIMIZE); 68 | } 69 | 70 | void Maximize(CefWindowHandle handle) { 71 | Toggle(handle, SW_MAXIMIZE); 72 | } 73 | 74 | void Restore(CefWindowHandle handle) { 75 | ::ShowWindow(::GetAncestor(handle, GA_ROOT), SW_RESTORE); 76 | } 77 | 78 | } // namespace window_test 79 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | DoomTool 4 | 63 | 115 | 116 | 117 |
118 |
titlebar
121 |
122 | Click a button to perform the associated window action. 123 | 124 | 125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 | 146 | 147 | --------------------------------------------------------------------------------