Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first commit

  • Loading branch information...
commit b29aae3309008310e978329ce0f46dfcc5036159 0 parents
U-yong-THINK\yong authored
Showing with 22,814 additions and 0 deletions.
  1. +86 −0 cefclient/Resource.h
  2. +630 −0 cefclient/cefclient.cpp
  3. +54 −0 cefclient/cefclient.h
  4. +191 −0 cefclient/cefclient.rc
  5. +86 −0 cefclient/cefclient_switches.cpp
  6. +86 −0 cefclient/cefclient_switches.h
  7. +798 −0 cefclient/cefclient_win.cpp
  8. +377 −0 cefclient/client_handler.cpp
  9. +223 −0 cefclient/client_handler.h
  10. +188 −0 cefclient/client_handler_win.cpp
  11. +34 −0 cefclient/client_popup_handler.cpp
  12. +36 −0 cefclient/client_popup_handler.h
  13. +201 −0 cefclient/clientplugin.cpp
  14. +100 −0 cefclient/clientplugin.h
  15. +220 −0 cefclient/download_handler.cpp
  16. +25 −0 cefclient/download_handler.h
  17. +905 −0 cefclient/osrplugin.cpp
  18. +29 −0 cefclient/osrplugin.h
  19. BIN  cefclient/res/cefclient.ico
  20. +13 −0 cefclient/res/domaccess.html
  21. +131 −0 cefclient/res/extensionperf.html
  22. +24 −0 cefclient/res/localstorage.html
  23. BIN  cefclient/res/logo.png
  24. BIN  cefclient/res/logoball.png
  25. +78 −0 cefclient/res/modaldialog.html
  26. +58 −0 cefclient/res/modalmain.html
  27. +51 −0 cefclient/res/osrplugin.html
  28. BIN  cefclient/res/small.ico
  29. +36 −0 cefclient/res/transparency.html
  30. +57 −0 cefclient/res/uiplugin.html
  31. +19 −0 cefclient/res/xmlhttprequest.html
  32. +26 −0 cefclient/resource_util.h
  33. +43 −0 cefclient/resource_util_win.cpp
  34. +74 −0 cefclient/string_util.cpp
  35. +17 −0 cefclient/string_util.h
  36. +293 −0 cefclient/uiplugin.cpp
  37. +29 −0 cefclient/uiplugin.h
  38. +36 −0 cefclient/util.h
  39. BIN  dist/chrome.pak
  40. 0  dist/debug.log
  41. BIN  dist/icudt.dll
  42. BIN  dist/libcef.dll
  43. BIN  dist/locales/en-US.pak
  44. +38 −0 h54d.sln
  45. +337 −0 h54d.vcxproj
  46. +202 −0 h54d.vcxproj.filters
  47. +3,975 −0 include/cef.h
  48. +3,769 −0 include/cef_capi.h
  49. +129 −0 include/cef_nplugin.h
  50. +49 −0 include/cef_nplugin_capi.h
  51. +345 −0 include/cef_runnable.h
  52. +68 −0 include/cef_version.h
  53. +322 −0 include/cef_wrapper.h
  54. +112 −0 include/internal/cef_build.h
  55. +54 −0 include/internal/cef_export.h
  56. +91 −0 include/internal/cef_nplugin_types.h
  57. +196 −0 include/internal/cef_ptr.h
  58. +112 −0 include/internal/cef_string.h
  59. +87 −0 include/internal/cef_string_list.h
  60. +96 −0 include/internal/cef_string_map.h
  61. +104 −0 include/internal/cef_string_multimap.h
  62. +203 −0 include/internal/cef_string_types.h
  63. +694 −0 include/internal/cef_string_wrappers.h
  64. +76 −0 include/internal/cef_time.h
  65. +1,083 −0 include/internal/cef_tuple.h
  66. +1,100 −0 include/internal/cef_types.h
  67. +101 −0 include/internal/cef_types_win.h
  68. +662 −0 include/internal/cef_types_wrappers.h
  69. +177 −0 include/internal/cef_win.h
  70. +14 −0 include/internal/npapi/README-TRANSFER.txt
  71. +363 −0 include/internal/npapi/basictypes.h
  72. +148 −0 include/internal/npapi/build_config.h
  73. +922 −0 include/internal/npapi/npapi.h
  74. +1,079 −0 include/internal/npapi/npapi_extensions.h
  75. +239 −0 include/internal/npapi/npfunctions.h
  76. +39 −0 include/internal/npapi/nphostapi.h
  77. +397 −0 include/internal/npapi/npruntime.h
  78. +121 −0 include/internal/npapi/nptypes.h
  79. +56 −0 include/internal/npapi/port.h
  80. BIN  lib/Debug/libcef.lib
  81. BIN  lib/Release/libcef.lib
86 cefclient/Resource.h
@@ -0,0 +1,86 @@
+// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
+// reserved. Use of this source code is governed by a BSD-style license that
+// can be found in the LICENSE file.
+
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by cefclient.rc
+//
+#define BINARY 256
+#define IDC_MYICON 2
+#define IDD_CEFCLIENT_DIALOG 102
+#define IDS_APP_TITLE 103
+#define IDD_ABOUTBOX 103
+#define IDM_ABOUT 104
+#define IDM_EXIT 105
+#define IDI_CEFCLIENT 107
+#define IDI_SMALL 108
+#define IDC_CEFCLIENT 109
+#define IDR_MAINFRAME 128
+#define IDC_NAV_BACK 200
+#define IDC_NAV_FORWARD 201
+#define IDC_NAV_RELOAD 202
+#define IDC_NAV_STOP 203
+#define ID_WARN_CONSOLEMESSAGE 32000
+#define ID_WARN_DOWNLOADCOMPLETE 32001
+#define ID_WARN_DOWNLOADERROR 32002
+#define ID_FIND 32101
+#define ID_PRINT 32102
+#define ID_TESTS_GETSOURCE 32769
+#define ID_TESTS_GETTEXT 32770
+#define ID_TESTS_JAVASCRIPT_BINDING 32771
+#define ID_TESTS_JAVASCRIPT_EXTENSION 32772
+#define ID_TESTS_JAVASCRIPT_EXECUTE 32773
+#define ID_TESTS_PLUGIN 32774
+#define ID_TESTS_POPUP 32775
+#define ID_TESTS_REQUEST 32776
+#define ID_TESTS_SCHEME_HANDLER 32777
+#define ID_TESTS_UIAPP 32778
+#define ID_TESTS_LOCALSTORAGE 32779
+#define ID_TESTS_ACCELERATED2DCANVAS 32780
+#define ID_TESTS_ACCELERATEDLAYERS 32781
+#define ID_TESTS_WEBGL 32782
+#define ID_TESTS_HTML5VIDEO 32783
+#define ID_TESTS_XMLHTTPREQUEST 32784
+#define ID_TESTS_ZOOM_IN 32785
+#define ID_TESTS_ZOOM_OUT 32786
+#define ID_TESTS_ZOOM_RESET 32787
+#define ID_TESTS_DEVTOOLS_SHOW 32788
+#define ID_TESTS_DEVTOOLS_CLOSE 32789
+#define ID_TESTS_WEBURLREQUEST 32790
+#define ID_TESTS_DOMACCESS 32791
+#define ID_TESTS_DRAGDROP 32792
+#define ID_TESTS_OSRAPP 32793
+#define ID_TESTS_MODALDIALOG 32794
+#define ID_TESTS_JAVASCRIPT_PERFORMANCE 32795
+#define ID_TESTS_TRANSPARENT_POPUP 32796
+#define ID_TESTS_TRANSPARENT_OSRAPP 32797
+#define ID_TESTS_JAVASCRIPT_INVOKE 32798
+#define ID_TESTS_GETIMAGE 32799
+#define IDC_STATIC -1
+#define IDS_LOGO 1000
+#define IDS_UIPLUGIN 1001
+#define IDS_LOGOBALL 1002
+#define IDS_LOCALSTORAGE 1003
+#define IDS_XMLHTTPREQUEST 1004
+#define IDS_DOMACCESS 1005
+#define IDS_OSRPLUGIN 1006
+#define IDS_MODALMAIN 1007
+#define IDS_MODALDIALOG 1008
+#define IDS_EXTENSIONPERF 1009
+#define IDS_TRANSPARENCY 1010
+
+// Avoid files associated with MacOS
+#define _X86_
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NO_MFC 1
+#define _APS_NEXT_RESOURCE_VALUE 130
+#define _APS_NEXT_COMMAND_VALUE 32795
+#define _APS_NEXT_CONTROL_VALUE 1000
+#define _APS_NEXT_SYMED_VALUE 110
+#endif
+#endif
630 cefclient/cefclient.cpp
@@ -0,0 +1,630 @@
+// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
+// reserved. Use of this source code is governed by a BSD-style license that
+// can be found in the LICENSE file.
+
+#include "include/cef.h"
+#include "include/cef_runnable.h"
+#include "include/cef_wrapper.h"
+#include "cefclient.h"
+#include "cefclient_switches.h"
+#include "client_handler.h"
+#include "binding_test.h"
+#include "string_util.h"
+#include "util.h"
+#include <cstdlib>
+#include <sstream>
+#include <stdio.h>
+#include <string>
+
+namespace {
+
+void UIT_InvokeScript(CefRefPtr<CefBrowser> browser)
+{
+ REQUIRE_UI_THREAD();
+
+ CefRefPtr<CefFrame> frame = browser->GetMainFrame();
+ CefRefPtr<CefV8Context> v8Context = frame->GetV8Context();
+ CefString url = frame->GetURL();
+
+ if (!v8Context.get()) {
+ frame->ExecuteJavaScript("alert('Failed to get V8 context!');", url, 0);
+ } else if (v8Context->Enter()) {
+ CefRefPtr<CefV8Value> globalObj = v8Context->GetGlobal();
+ CefRefPtr<CefV8Value> evalFunc = globalObj->GetValue("eval");
+
+ CefRefPtr<CefV8Value> arg0 = CefV8Value::CreateString("1+2");
+
+ CefV8ValueList args;
+ args.push_back(arg0);
+
+ CefRefPtr<CefV8Value> retVal;
+ CefRefPtr<CefV8Exception> exception;
+ if (evalFunc->ExecuteFunctionWithContext(v8Context, globalObj, args, retVal,
+ exception, false)) {
+ if (retVal.get()) {
+ frame->ExecuteJavaScript(
+ std::string("alert('InvokeScript returns ") +
+ retVal->GetStringValue().ToString() + "!');",
+ url, 0);
+ } else {
+ frame->ExecuteJavaScript(
+ std::string("alert('InvokeScript returns exception: ") +
+ exception->GetMessage().ToString() + "!');",
+ url, 0);
+ }
+ } else {
+ frame->ExecuteJavaScript("alert('Failed to execute function!');", url, 0);
+ }
+
+ v8Context->Exit();
+ } else {
+ frame->ExecuteJavaScript("alert('Failed to enter into V8 context!');",
+ url, 0);
+ }
+}
+
+// Return the int representation of the specified string.
+int GetIntValue(const CefString& str)
+{
+ if (str.empty())
+ return 0;
+
+ std::string stdStr = str;
+ return atoi(stdStr.c_str());
+}
+
+
+// ClientApp implementation.
+class ClientApp : public CefApp,
+ public CefProxyHandler
+{
+public:
+ ClientApp(cef_proxy_type_t proxy_type, const CefString& proxy_config)
+ : proxy_type_(proxy_type),
+ proxy_config_(proxy_config)
+ {
+ }
+
+ // CefApp methods
+ virtual CefRefPtr<CefProxyHandler> GetProxyHandler() OVERRIDE { return this; }
+
+ // CefProxyHandler methods
+ virtual void GetProxyForUrl(const CefString& url,
+ CefProxyInfo& proxy_info) OVERRIDE
+ {
+ proxy_info.proxyType = proxy_type_;
+ if (!proxy_config_.empty())
+ CefString(&proxy_info.proxyList) = proxy_config_;
+ }
+
+protected:
+ cef_proxy_type_t proxy_type_;
+ CefString proxy_config_;
+
+ IMPLEMENT_REFCOUNTING(ClientApp);
+};
+
+} // namespace
+
+CefRefPtr<ClientHandler> g_handler;
+CefRefPtr<CefCommandLine> g_command_line;
+
+CefRefPtr<CefBrowser> AppGetBrowser()
+{
+ if(!g_handler.get())
+ return NULL;
+ return g_handler->GetBrowser();
+}
+
+CefWindowHandle AppGetMainHwnd()
+{
+ if(!g_handler.get())
+ return NULL;
+ return g_handler->GetMainHwnd();
+}
+
+void AppInitCommandLine(int argc, const char* const* argv)
+{
+ g_command_line = CefCommandLine::CreateCommandLine();
+#if defined(OS_WIN)
+ g_command_line->InitFromString(::GetCommandLineW());
+#else
+ g_command_line->InitFromArgv(argc, argv);
+#endif
+}
+
+// Returns the application command line object.
+CefRefPtr<CefCommandLine> AppGetCommandLine()
+{
+ return g_command_line;
+}
+
+// Returns the application settings based on command line arguments.
+void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app)
+{
+ ASSERT(g_command_line.get());
+ if (!g_command_line.get())
+ return;
+
+ CefString str;
+
+#if defined(OS_WIN)
+ settings.multi_threaded_message_loop =
+ g_command_line->HasSwitch(cefclient::kMultiThreadedMessageLoop);
+#endif
+
+ CefString(&settings.cache_path) =
+ g_command_line->GetSwitchValue(cefclient::kCachePath);
+ CefString(&settings.user_agent) =
+ g_command_line->GetSwitchValue(cefclient::kUserAgent);
+ CefString(&settings.product_version) =
+ g_command_line->GetSwitchValue(cefclient::kProductVersion);
+ CefString(&settings.locale) =
+ g_command_line->GetSwitchValue(cefclient::kLocale);
+ CefString(&settings.log_file) =
+ g_command_line->GetSwitchValue(cefclient::kLogFile);
+
+ {
+ std::string str = g_command_line->GetSwitchValue(cefclient::kLogSeverity);
+ bool invalid = false;
+ if (!str.empty()) {
+ if (str == cefclient::kLogSeverity_Verbose)
+ settings.log_severity = LOGSEVERITY_VERBOSE;
+ else if (str == cefclient::kLogSeverity_Info)
+ settings.log_severity = LOGSEVERITY_INFO;
+ else if (str == cefclient::kLogSeverity_Warning)
+ settings.log_severity = LOGSEVERITY_WARNING;
+ else if (str == cefclient::kLogSeverity_Error)
+ settings.log_severity = LOGSEVERITY_ERROR;
+ else if (str == cefclient::kLogSeverity_ErrorReport)
+ settings.log_severity = LOGSEVERITY_ERROR_REPORT;
+ else if (str == cefclient::kLogSeverity_Disable)
+ settings.log_severity = LOGSEVERITY_DISABLE;
+ else
+ invalid = true;
+ }
+ if (str.empty() || invalid) {
+#ifdef NDEBUG
+ // Only log error messages and higher in release build.
+ settings.log_severity = LOGSEVERITY_ERROR;
+#endif
+ }
+ }
+
+ {
+ std::string str = g_command_line->GetSwitchValue(cefclient::kGraphicsImpl);
+ if (!str.empty()) {
+#if defined(OS_WIN)
+ if (str == cefclient::kGraphicsImpl_Angle)
+ settings.graphics_implementation = ANGLE_IN_PROCESS;
+ else if (str == cefclient::kGraphicsImpl_AngleCmdBuffer)
+ settings.graphics_implementation = ANGLE_IN_PROCESS_COMMAND_BUFFER;
+ else
+#endif
+ if (str == cefclient::kGraphicsImpl_Desktop)
+ settings.graphics_implementation = DESKTOP_IN_PROCESS;
+ else if (str == cefclient::kGraphicsImpl_DesktopCmdBuffer)
+ settings.graphics_implementation = DESKTOP_IN_PROCESS_COMMAND_BUFFER;
+ }
+ }
+
+ settings.local_storage_quota = GetIntValue(
+ g_command_line->GetSwitchValue(cefclient::kLocalStorageQuota));
+ settings.session_storage_quota = GetIntValue(
+ g_command_line->GetSwitchValue(cefclient::kSessionStorageQuota));
+
+ CefString(&settings.javascript_flags) =
+ g_command_line->GetSwitchValue(cefclient::kJavascriptFlags);
+
+ // Retrieve command-line proxy configuration, if any.
+ bool has_proxy = false;
+ cef_proxy_type_t proxy_type;
+ CefString proxy_config;
+
+ if (g_command_line->HasSwitch(cefclient::kProxyType)) {
+ std::string str = g_command_line->GetSwitchValue(cefclient::kProxyType);
+ if (str == cefclient::kProxyType_Direct) {
+ has_proxy = true;
+ proxy_type = PROXY_TYPE_DIRECT;
+ } else if (str == cefclient::kProxyType_Named ||
+ str == cefclient::kProxyType_Pac) {
+ proxy_config = g_command_line->GetSwitchValue(cefclient::kProxyConfig);
+ if (!proxy_config.empty()) {
+ has_proxy = true;
+ proxy_type = (str == cefclient::kProxyType_Named?
+ PROXY_TYPE_NAMED:PROXY_TYPE_PAC_STRING);
+ }
+ }
+ }
+
+ if (has_proxy) {
+ // Provide a ClientApp instance to handle proxy resolution.
+ app = new ClientApp(proxy_type, proxy_config);
+ }
+}
+
+// Returns the application browser settings based on command line arguments.
+void AppGetBrowserSettings(CefBrowserSettings& settings)
+{
+ ASSERT(g_command_line.get());
+ if (!g_command_line.get())
+ return;
+
+ settings.drag_drop_disabled =
+ g_command_line->HasSwitch(cefclient::kDragDropDisabled);
+ settings.load_drops_disabled =
+ g_command_line->HasSwitch(cefclient::kLoadDropsDisabled);
+ settings.history_disabled =
+ g_command_line->HasSwitch(cefclient::kHistoryDisabled);
+ settings.remote_fonts_disabled =
+ g_command_line->HasSwitch(cefclient::kRemoteFontsDisabled);
+
+ CefString(&settings.default_encoding) =
+ g_command_line->GetSwitchValue(cefclient::kDefaultEncoding);
+
+ settings.encoding_detector_enabled =
+ g_command_line->HasSwitch(cefclient::kEncodingDetectorEnabled);
+ settings.javascript_disabled =
+ g_command_line->HasSwitch(cefclient::kJavascriptDisabled);
+ settings.javascript_open_windows_disallowed =
+ g_command_line->HasSwitch(cefclient::kJavascriptOpenWindowsDisallowed);
+ settings.javascript_close_windows_disallowed =
+ g_command_line->HasSwitch(cefclient::kJavascriptCloseWindowsDisallowed);
+ settings.javascript_access_clipboard_disallowed =
+ g_command_line->HasSwitch(
+ cefclient::kJavascriptAccessClipboardDisallowed);
+ settings.dom_paste_disabled =
+ g_command_line->HasSwitch(cefclient::kDomPasteDisabled);
+ settings.caret_browsing_enabled =
+ g_command_line->HasSwitch(cefclient::kCaretBrowsingDisabled);
+ settings.java_disabled =
+ g_command_line->HasSwitch(cefclient::kJavaDisabled);
+ settings.plugins_disabled =
+ g_command_line->HasSwitch(cefclient::kPluginsDisabled);
+ settings.universal_access_from_file_urls_allowed =
+ g_command_line->HasSwitch(cefclient::kUniversalAccessFromFileUrlsAllowed);
+ settings.file_access_from_file_urls_allowed =
+ g_command_line->HasSwitch(cefclient::kFileAccessFromFileUrlsAllowed);
+ settings.web_security_disabled =
+ g_command_line->HasSwitch(cefclient::kWebSecurityDisabled);
+ settings.xss_auditor_enabled =
+ g_command_line->HasSwitch(cefclient::kXssAuditorEnabled);
+ settings.image_load_disabled =
+ g_command_line->HasSwitch(cefclient::kImageLoadingDisabled);
+ settings.shrink_standalone_images_to_fit =
+ g_command_line->HasSwitch(cefclient::kShrinkStandaloneImagesToFit);
+ settings.site_specific_quirks_disabled =
+ g_command_line->HasSwitch(cefclient::kSiteSpecificQuirksDisabled);
+ settings.text_area_resize_disabled =
+ g_command_line->HasSwitch(cefclient::kTextAreaResizeDisabled);
+ settings.page_cache_disabled =
+ g_command_line->HasSwitch(cefclient::kPageCacheDisabled);
+ settings.tab_to_links_disabled =
+ g_command_line->HasSwitch(cefclient::kTabToLinksDisabled);
+ settings.hyperlink_auditing_disabled =
+ g_command_line->HasSwitch(cefclient::kHyperlinkAuditingDisabled);
+ settings.user_style_sheet_enabled =
+ g_command_line->HasSwitch(cefclient::kUserStyleSheetEnabled);
+
+ CefString(&settings.user_style_sheet_location) =
+ g_command_line->GetSwitchValue(cefclient::kUserStyleSheetLocation);
+
+ settings.author_and_user_styles_disabled =
+ g_command_line->HasSwitch(cefclient::kAuthorAndUserStylesDisabled);
+ settings.local_storage_disabled =
+ g_command_line->HasSwitch(cefclient::kLocalStorageDisabled);
+ settings.databases_disabled =
+ g_command_line->HasSwitch(cefclient::kDatabasesDisabled);
+ settings.application_cache_disabled =
+ g_command_line->HasSwitch(cefclient::kApplicationCacheDisabled);
+ settings.webgl_disabled =
+ g_command_line->HasSwitch(cefclient::kWebglDisabled);
+ settings.accelerated_compositing_enabled =
+ g_command_line->HasSwitch(cefclient::kAcceleratedCompositingEnabled);
+ settings.threaded_compositing_enabled =
+ g_command_line->HasSwitch(cefclient::kThreadedCompositingEnabled);
+ settings.accelerated_layers_disabled =
+ g_command_line->HasSwitch(cefclient::kAcceleratedLayersDisabled);
+ settings.accelerated_video_disabled =
+ g_command_line->HasSwitch(cefclient::kAcceleratedVideoDisabled);
+ settings.accelerated_2d_canvas_disabled =
+ g_command_line->HasSwitch(cefclient::kAcceledated2dCanvasDisabled);
+ settings.accelerated_drawing_disabled =
+ g_command_line->HasSwitch(cefclient::kAcceleratedDrawingDisabled);
+ settings.accelerated_plugins_disabled =
+ g_command_line->HasSwitch(cefclient::kAcceleratedPluginsDisabled);
+ settings.developer_tools_disabled =
+ g_command_line->HasSwitch(cefclient::kDeveloperToolsDisabled);
+}
+
+static void ExecuteGetSource(CefRefPtr<CefFrame> frame)
+{
+ // Retrieve the current page source and display.
+ std::string source = frame->GetSource();
+ source = StringReplace(source, "<", "&lt;");
+ source = StringReplace(source, ">", "&gt;");
+ std::stringstream ss;
+ ss << "<html><body>Source:" << "<pre>" << source
+ << "</pre></body></html>";
+ frame->LoadString(ss.str(), "http://tests/getsource");
+}
+
+void RunGetSourceTest(CefRefPtr<CefBrowser> browser)
+{
+ // Execute the GetSource() call on the UI thread.
+ CefPostTask(TID_UI,
+ NewCefRunnableFunction(&ExecuteGetSource, browser->GetMainFrame()));
+}
+
+static void ExecuteGetText(CefRefPtr<CefFrame> frame)
+{
+ std::string text = frame->GetText();
+ text = StringReplace(text, "<", "&lt;");
+ text = StringReplace(text, ">", "&gt;");
+ std::stringstream ss;
+ ss << "<html><body>Text:" << "<pre>" << text
+ << "</pre></body></html>";
+ frame->LoadString(ss.str(), "http://tests/gettext");
+}
+
+void RunGetTextTest(CefRefPtr<CefBrowser> browser)
+{
+ // Execute the GetText() call on the UI thread.
+ CefPostTask(TID_UI,
+ NewCefRunnableFunction(&ExecuteGetText, browser->GetMainFrame()));
+}
+
+void RunRequestTest(CefRefPtr<CefBrowser> browser)
+{
+ // Create a new request
+ CefRefPtr<CefRequest> request(CefRequest::CreateRequest());
+
+ // Set the request URL
+ request->SetURL("http://tests/request");
+
+ // Add post data to the request. The correct method and content-
+ // type headers will be set by CEF.
+ CefRefPtr<CefPostDataElement> postDataElement(
+ CefPostDataElement::CreatePostDataElement());
+ std::string data = "arg1=val1&arg2=val2";
+ postDataElement->SetToBytes(data.length(), data.c_str());
+ CefRefPtr<CefPostData> postData(CefPostData::CreatePostData());
+ postData->AddElement(postDataElement);
+ request->SetPostData(postData);
+
+ // Add a custom header
+ CefRequest::HeaderMap headerMap;
+ headerMap.insert(
+ std::make_pair("X-My-Header", "My Header Value"));
+ request->SetHeaderMap(headerMap);
+
+ // Load the request
+ browser->GetMainFrame()->LoadRequest(request);
+}
+
+void RunJavaScriptExecuteTest(CefRefPtr<CefBrowser> browser)
+{
+ browser->GetMainFrame()->ExecuteJavaScript(
+ "alert('JavaScript execute works!');", "about:blank", 0);
+}
+
+void RunJavaScriptInvokeTest(CefRefPtr<CefBrowser> browser)
+{
+ if (CefCurrentlyOn(TID_UI)) {
+ UIT_InvokeScript(browser);
+ } else {
+ // Execute on the UI thread.
+ CefPostTask(TID_UI, NewCefRunnableFunction(&UIT_InvokeScript, browser));
+ }
+}
+
+void RunPopupTest(CefRefPtr<CefBrowser> browser)
+{
+ browser->GetMainFrame()->ExecuteJavaScript(
+ "window.open('http://www.google.com');", "about:blank", 0);
+}
+
+void RunLocalStorageTest(CefRefPtr<CefBrowser> browser)
+{
+ browser->GetMainFrame()->LoadURL("http://tests/localstorage");
+}
+
+void RunAccelerated2DCanvasTest(CefRefPtr<CefBrowser> browser)
+{
+ browser->GetMainFrame()->LoadURL(
+ "http://mudcu.be/labs/JS1k/BreathingGalaxies.html");
+}
+
+void RunAcceleratedLayersTest(CefRefPtr<CefBrowser> browser)
+{
+ browser->GetMainFrame()->LoadURL(
+ "http://webkit.org/blog-files/3d-transforms/poster-circle.html");
+}
+
+void RunWebGLTest(CefRefPtr<CefBrowser> browser)
+{
+ browser->GetMainFrame()->LoadURL(
+ "http://webglsamples.googlecode.com/hg/field/field.html");
+}
+
+void RunHTML5VideoTest(CefRefPtr<CefBrowser> browser)
+{
+ browser->GetMainFrame()->LoadURL(
+ "http://www.youtube.com/watch?v=siOHh0uzcuY&html5=True");
+}
+
+void RunXMLHTTPRequestTest(CefRefPtr<CefBrowser> browser)
+{
+ browser->GetMainFrame()->LoadURL("http://tests/xmlhttprequest");
+}
+
+void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser)
+{
+ class RequestClient : public CefWebURLRequestClient
+ {
+ public:
+ RequestClient(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
+
+ virtual void OnStateChange(CefRefPtr<CefWebURLRequest> requester,
+ RequestState state)
+ {
+ REQUIRE_UI_THREAD();
+ if (state == WUR_STATE_DONE) {
+ buffer_ = StringReplace(buffer_, "<", "&lt;");
+ buffer_ = StringReplace(buffer_, ">", "&gt;");
+ std::stringstream ss;
+ ss << "<html><body>Source:<pre>" << buffer_ << "</pre></body></html>";
+
+ browser_->GetMainFrame()->LoadString(ss.str(),
+ "http://tests/weburlrequest");
+ }
+ }
+
+ virtual void OnRedirect(CefRefPtr<CefWebURLRequest> requester,
+ CefRefPtr<CefRequest> request,
+ CefRefPtr<CefResponse> response)
+ {
+ REQUIRE_UI_THREAD();
+ }
+
+ virtual void OnHeadersReceived(CefRefPtr<CefWebURLRequest> requester,
+ CefRefPtr<CefResponse> response)
+ {
+ REQUIRE_UI_THREAD();
+ }
+
+ virtual void OnProgress(CefRefPtr<CefWebURLRequest> requester,
+ uint64 bytesSent, uint64 totalBytesToBeSent)
+ {
+ REQUIRE_UI_THREAD();
+ }
+
+ virtual void OnData(CefRefPtr<CefWebURLRequest> requester,
+ const void* data, int dataLength)
+ {
+ REQUIRE_UI_THREAD();
+ buffer_.append(static_cast<const char*>(data), dataLength);
+ }
+
+ virtual void OnError(CefRefPtr<CefWebURLRequest> requester,
+ ErrorCode errorCode)
+ {
+ REQUIRE_UI_THREAD();
+ std::stringstream ss;
+ ss << "Load failed with error code " << errorCode;
+ browser_->GetMainFrame()->LoadString(ss.str(),
+ "http://tests/weburlrequest");
+ }
+
+ protected:
+ CefRefPtr<CefBrowser> browser_;
+ std::string buffer_;
+
+ IMPLEMENT_REFCOUNTING(CefWebURLRequestClient);
+ };
+
+ CefRefPtr<CefRequest> request(CefRequest::CreateRequest());
+ request->SetURL("http://www.google.com");
+
+ CefRefPtr<CefWebURLRequestClient> client(new RequestClient(browser));
+ CefRefPtr<CefWebURLRequest> requester(
+ CefWebURLRequest::CreateWebURLRequest(request, client));
+}
+
+void RunDOMAccessTest(CefRefPtr<CefBrowser> browser)
+{
+ class Listener : public CefDOMEventListener
+ {
+ public:
+ Listener() {}
+ virtual void HandleEvent(CefRefPtr<CefDOMEvent> event)
+ {
+ CefRefPtr<CefDOMDocument> document = event->GetDocument();
+ ASSERT(document.get());
+
+ std::stringstream ss;
+
+ CefRefPtr<CefDOMNode> button = event->GetTarget();
+ ASSERT(button.get());
+ std::string buttonValue = button->GetElementAttribute("value");
+ ss << "You clicked the " << buttonValue.c_str() << " button. ";
+
+ if (document->HasSelection()) {
+ std::string startName, endName;
+
+ // Determine the start name by first trying to locate the "id" attribute
+ // and then defaulting to the tag name.
+ {
+ CefRefPtr<CefDOMNode> node = document->GetSelectionStartNode();
+ if (!node->IsElement())
+ node = node->GetParent();
+ if (node->IsElement() && node->HasElementAttribute("id"))
+ startName = node->GetElementAttribute("id");
+ else
+ startName = node->GetName();
+ }
+
+ // Determine the end name by first trying to locate the "id" attribute
+ // and then defaulting to the tag name.
+ {
+ CefRefPtr<CefDOMNode> node = document->GetSelectionEndNode();
+ if (!node->IsElement())
+ node = node->GetParent();
+ if (node->IsElement() && node->HasElementAttribute("id"))
+ endName = node->GetElementAttribute("id");
+ else
+ endName = node->GetName();
+ }
+
+ ss << "The selection is from " <<
+ startName.c_str() << ":" << document->GetSelectionStartOffset() <<
+ " to " <<
+ endName.c_str() << ":" << document->GetSelectionEndOffset();
+ } else {
+ ss << "Nothing is selected.";
+ }
+
+ // Update the description.
+ CefRefPtr<CefDOMNode> desc = document->GetElementById("description");
+ ASSERT(desc.get());
+ CefRefPtr<CefDOMNode> text = desc->GetFirstChild();
+ ASSERT(text.get());
+ ASSERT(text->IsText());
+ text->SetValue(ss.str());
+ }
+
+ IMPLEMENT_REFCOUNTING(Listener);
+ };
+
+ class Visitor : public CefDOMVisitor
+ {
+ public:
+ Visitor() {}
+ virtual void Visit(CefRefPtr<CefDOMDocument> document)
+ {
+ // Register an click listener for the button.
+ CefRefPtr<CefDOMNode> button = document->GetElementById("button");
+ ASSERT(button.get());
+ button->AddEventListener("click", new Listener(), false);
+ }
+
+ IMPLEMENT_REFCOUNTING(Visitor);
+ };
+
+ // The DOM visitor will be called after the path is loaded.
+ CefRefPtr<CefClient> client = browser->GetClient();
+ static_cast<ClientHandler*>(client.get())->AddDOMVisitor(
+ "http://tests/domaccess", new Visitor());
+
+ browser->GetMainFrame()->LoadURL("http://tests/domaccess");
+}
+
+void RunDragDropTest(CefRefPtr<CefBrowser> browser)
+{
+ browser->GetMainFrame()->LoadURL("http://html5demos.com/drag");
+}
+
+void RunModalDialogTest(CefRefPtr<CefBrowser> browser)
+{
+ browser->GetMainFrame()->LoadURL("http://tests/modalmain");
+}
54 cefclient/cefclient.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
+// reserved. Use of this source code is governed by a BSD-style license that
+// can be found in the LICENSE file.
+
+#ifndef _CEFCLIENT_H
+#define _CEFCLIENT_H
+
+#include "include/cef.h"
+
+// Returns the main browser window instance.
+CefRefPtr<CefBrowser> AppGetBrowser();
+
+// Returns the main application window handle.
+CefWindowHandle AppGetMainHwnd();
+
+// Returns the application working directory.
+std::string AppGetWorkingDirectory();
+
+// Initialize the application command line.
+void AppInitCommandLine(int argc, const char* const* argv);
+
+// Returns the application command line object.
+CefRefPtr<CefCommandLine> AppGetCommandLine();
+
+// Returns the application settings based on command line arguments.
+void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app);
+
+// Returns the application browser settings based on command line arguments.
+void AppGetBrowserSettings(CefBrowserSettings& settings);
+
+// Implementations for various tests.
+void RunGetSourceTest(CefRefPtr<CefBrowser> browser);
+void RunGetTextTest(CefRefPtr<CefBrowser> browser);
+void RunRequestTest(CefRefPtr<CefBrowser> browser);
+void RunJavaScriptExecuteTest(CefRefPtr<CefBrowser> browser);
+void RunJavaScriptInvokeTest(CefRefPtr<CefBrowser> browser);
+void RunPopupTest(CefRefPtr<CefBrowser> browser);
+void RunLocalStorageTest(CefRefPtr<CefBrowser> browser);
+void RunAccelerated2DCanvasTest(CefRefPtr<CefBrowser> browser);
+void RunAcceleratedLayersTest(CefRefPtr<CefBrowser> browser);
+void RunWebGLTest(CefRefPtr<CefBrowser> browser);
+void RunHTML5VideoTest(CefRefPtr<CefBrowser> browser);
+void RunXMLHTTPRequestTest(CefRefPtr<CefBrowser> browser);
+void RunWebURLRequestTest(CefRefPtr<CefBrowser> browser);
+void RunDOMAccessTest(CefRefPtr<CefBrowser> browser);
+void RunDragDropTest(CefRefPtr<CefBrowser> browser);
+void RunModalDialogTest(CefRefPtr<CefBrowser> browser);
+
+#if defined(OS_WIN)
+void RunTransparentPopupTest(CefRefPtr<CefBrowser> browser);
+void RunGetImageTest(CefRefPtr<CefBrowser> browser);
+#endif
+
+#endif // _CEFCLIENT_H
191 cefclient/cefclient.rc
@@ -0,0 +1,191 @@
+// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#define APSTUDIO_HIDDEN_SYMBOLS
+#include "windows.h"
+#undef APSTUDIO_HIDDEN_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Binary
+//
+
+IDS_LOGO BINARY "res\\logo.png"
+IDS_UIPLUGIN BINARY "res\\uiplugin.html"
+IDS_OSRPLUGIN BINARY "res\\osrplugin.html"
+IDS_LOGOBALL BINARY "res\\logoball.png"
+IDS_LOCALSTORAGE BINARY "res\\localstorage.html"
+IDS_XMLHTTPREQUEST BINARY "res\\xmlhttprequest.html"
+IDS_DOMACCESS BINARY "res\\domaccess.html"
+IDS_MODALMAIN BINARY "res\\modalmain.html"
+IDS_MODALDIALOG BINARY "res\\modaldialog.html"
+IDS_EXTENSIONPERF BINARY "res\\extensionperf.html"
+IDS_TRANSPARENCY BINARY "res\\transparency.html"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+IDI_CEFCLIENT ICON "res\cefclient.ico"
+IDI_SMALL ICON "res\small.ico"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Menu
+//
+
+IDC_CEFCLIENT MENU
+BEGIN
+ POPUP "&File"
+ BEGIN
+ MENUITEM "&Find...", ID_FIND
+ MENUITEM SEPARATOR
+ MENUITEM "&Print...", ID_PRINT
+ MENUITEM SEPARATOR
+ MENUITEM "E&xit", IDM_EXIT
+ END
+ POPUP "&Help"
+ BEGIN
+ MENUITEM "&About ...", IDM_ABOUT
+ END
+ POPUP "Tests"
+ BEGIN
+ MENUITEM "Get Source", ID_TESTS_GETSOURCE
+ MENUITEM "Get Text", ID_TESTS_GETTEXT
+ MENUITEM "JavaScript Binding Handler", ID_TESTS_JAVASCRIPT_BINDING
+ MENUITEM "JavaScript Extension Handler",ID_TESTS_JAVASCRIPT_EXTENSION
+ MENUITEM "JavaScript Extension Performance",ID_TESTS_JAVASCRIPT_PERFORMANCE
+ MENUITEM "JavaScript Execute", ID_TESTS_JAVASCRIPT_EXECUTE
+ MENUITEM "JavaScript Invoke", ID_TESTS_JAVASCRIPT_INVOKE
+ MENUITEM "Plugin", ID_TESTS_PLUGIN
+ MENUITEM "Popup Window", ID_TESTS_POPUP
+ MENUITEM "Transparent Popup Window", ID_TESTS_TRANSPARENT_POPUP
+ MENUITEM "Request", ID_TESTS_REQUEST
+ MENUITEM "Scheme Handler", ID_TESTS_SCHEME_HANDLER
+ MENUITEM "UI App Example", ID_TESTS_UIAPP
+ MENUITEM "Off-Screen Rendering Example",ID_TESTS_OSRAPP
+ MENUITEM "Transparent Off-Screen Rendering Example",ID_TESTS_TRANSPARENT_OSRAPP
+ MENUITEM "Local Storage", ID_TESTS_LOCALSTORAGE
+ MENUITEM "XMLHttpRequest", ID_TESTS_XMLHTTPREQUEST
+ MENUITEM "WebURLRequest", ID_TESTS_WEBURLREQUEST
+ MENUITEM "DOM Access", ID_TESTS_DOMACCESS
+ MENUITEM "Accelerated 2D Canvas", ID_TESTS_ACCELERATED2DCANVAS
+ MENUITEM "Accelerated Layers", ID_TESTS_ACCELERATEDLAYERS
+ MENUITEM "WebGL", ID_TESTS_WEBGL
+ MENUITEM "HTML5 Video", ID_TESTS_HTML5VIDEO
+ MENUITEM "Drag && Drop", ID_TESTS_DRAGDROP
+ MENUITEM "Zoom In", ID_TESTS_ZOOM_IN
+ MENUITEM "Zoom Out", ID_TESTS_ZOOM_OUT
+ MENUITEM "Reset Zoom", ID_TESTS_ZOOM_RESET
+ MENUITEM "Show Developer Tools", ID_TESTS_DEVTOOLS_SHOW
+ MENUITEM "Close Developer Tools", ID_TESTS_DEVTOOLS_CLOSE
+ MENUITEM "Modal Dialog", ID_TESTS_MODALDIALOG
+ MENUITEM "Get Image", ID_TESTS_GETIMAGE
+ END
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Accelerator
+//
+
+IDC_CEFCLIENT ACCELERATORS
+BEGIN
+ "?", IDM_ABOUT, ASCII, ALT
+ "/", IDM_ABOUT, ASCII, ALT
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_ABOUTBOX DIALOG 22, 17, 230, 75
+STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
+CAPTION "About"
+FONT 8, "System"
+BEGIN
+ ICON IDI_CEFCLIENT,IDC_MYICON,14,9,16,16
+ LTEXT "cefclient Version 1.0",IDC_STATIC,49,10,119,8,SS_NOPREFIX
+ LTEXT "Copyright (C) 2008",IDC_STATIC,49,20,119,8
+ DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP
+END
+
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
+ "#include ""windows.h""\r\n"
+ "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+STRINGTABLE
+BEGIN
+ IDS_APP_TITLE "cefclient"
+ IDC_CEFCLIENT "CEFCLIENT"
+END
+
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
86 cefclient/cefclient_switches.cpp
@@ -0,0 +1,86 @@
+// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
+// reserved. Use of this source code is governed by a BSD-style license that
+// can be found in the LICENSE file.
+
+#include "cefclient_switches.h"
+
+namespace cefclient {
+
+// CefSettings attributes.
+const char kMultiThreadedMessageLoop[] = "multi-threaded-message-loop";
+const char kCachePath[] = "cache-path";
+const char kUserAgent[] = "user-agent";
+const char kProductVersion[] = "product-version";
+const char kLocale[] = "locale";
+const char kLogFile[] = "log-file";
+const char kLogSeverity[] = "log-severity";
+const char kLogSeverity_Verbose[] = "verbose";
+const char kLogSeverity_Info[] = "info";
+const char kLogSeverity_Warning[] = "warning";
+const char kLogSeverity_Error[] = "error";
+const char kLogSeverity_ErrorReport[] = "error-report";
+const char kLogSeverity_Disable[] = "disable";
+const char kGraphicsImpl[] = "graphics-implementation";
+const char kGraphicsImpl_Angle[] = "angle";
+const char kGraphicsImpl_AngleCmdBuffer[] = "angle-command-buffer";
+const char kGraphicsImpl_Desktop[] = "desktop";
+const char kGraphicsImpl_DesktopCmdBuffer[] = "desktop-command-buffer";
+const char kLocalStorageQuota[] = "local-storage-quota";
+const char kSessionStorageQuota[] = "session-storage-quota";
+const char kJavascriptFlags[] = "javascript-flags";
+
+// CefBrowserSettings attributes.
+const char kDragDropDisabled[] = "drag-drop-disabled";
+const char kLoadDropsDisabled[] = "load-drops-disabled";
+const char kHistoryDisabled[] = "history-disabled";
+const char kRemoteFontsDisabled[] = "remote-fonts-disabled";
+const char kDefaultEncoding[] = "default-encoding";
+const char kEncodingDetectorEnabled[] = "encoding-detector-enabled";
+const char kJavascriptDisabled[] = "javascript-disabled";
+const char kJavascriptOpenWindowsDisallowed[] =
+ "javascript-open-windows-disallowed";
+const char kJavascriptCloseWindowsDisallowed[] =
+ "javascript-close-windows-disallowed";
+const char kJavascriptAccessClipboardDisallowed[] =
+ "javascript-access-clipboard-disallowed";
+const char kDomPasteDisabled[] = "dom-paste-disabled";
+const char kCaretBrowsingDisabled[] = "caret-browsing-enabled";
+const char kJavaDisabled[] = "java-disabled";
+const char kPluginsDisabled[] = "plugins-disabled";
+const char kUniversalAccessFromFileUrlsAllowed[] =
+ "universal-access-from-file-urls-allowed";
+const char kFileAccessFromFileUrlsAllowed[] =
+ "file-access-from-file-urls-allowed";
+const char kWebSecurityDisabled[] = "web-security-disabled";
+const char kXssAuditorEnabled[] = "xss-auditor-enabled";
+const char kImageLoadingDisabled[] = "image-load-disabled";
+const char kShrinkStandaloneImagesToFit[] = "shrink-standalone-images-to-fit";
+const char kSiteSpecificQuirksDisabled[] = "site-specific-quirks-disabled";
+const char kTextAreaResizeDisabled[] = "text-area-resize-disabled";
+const char kPageCacheDisabled[] = "page-cache-disabled";
+const char kTabToLinksDisabled[] = "tab-to-links-disabled";
+const char kHyperlinkAuditingDisabled[] = "hyperlink-auditing-disabled";
+const char kUserStyleSheetEnabled[] = "user-style-sheet-enabled";
+const char kUserStyleSheetLocation[] = "user-style-sheet-location";
+const char kAuthorAndUserStylesDisabled[] = "author-and-user-styles-disabled";
+const char kLocalStorageDisabled[] = "local-storage-disabled";
+const char kDatabasesDisabled[] = "databases-disabled";
+const char kApplicationCacheDisabled[] = "application-cache-disabled";
+const char kWebglDisabled[] = "webgl-disabled";
+const char kAcceleratedCompositingEnabled[] = "accelerated-compositing-enabled";
+const char kThreadedCompositingEnabled[] = "threaded-compositing-enabled";
+const char kAcceleratedLayersDisabled[] = "accelerated-layers-disabled";
+const char kAcceleratedVideoDisabled[] = "accelerated-video-disabled";
+const char kAcceledated2dCanvasDisabled[] = "accelerated-2d-canvas-disabled";
+const char kAcceleratedDrawingDisabled[] = "accelerated-drawing-disabled";
+const char kAcceleratedPluginsDisabled[] = "accelerated-plugins-disabled";
+const char kDeveloperToolsDisabled[] = "developer-tools-disabled";
+
+// Other attributes.
+const char kProxyType[] = "proxy-type";
+const char kProxyType_Direct[] = "direct";
+const char kProxyType_Named[] = "named";
+const char kProxyType_Pac[] = "pac";
+const char kProxyConfig[] = "proxy-config";
+
+} // namespace cefclient
86 cefclient/cefclient_switches.h
@@ -0,0 +1,86 @@
+// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
+// reserved. Use of this source code is governed by a BSD-style license that
+// can be found in the LICENSE file.
+
+// Defines all of the command line switches used by cefclient.
+
+#ifndef _CEFCLIENT_SWITCHES_H
+#define _CEFCLIENT_SWITCHES_H
+
+namespace cefclient {
+
+// CefSettings attributes.
+extern const char kMultiThreadedMessageLoop[];
+extern const char kCachePath[];
+extern const char kUserAgent[];
+extern const char kProductVersion[];
+extern const char kLocale[];
+extern const char kLogFile[];
+extern const char kLogSeverity[];
+extern const char kLogSeverity_Verbose[];
+extern const char kLogSeverity_Info[];
+extern const char kLogSeverity_Warning[];
+extern const char kLogSeverity_Error[];
+extern const char kLogSeverity_ErrorReport[];
+extern const char kLogSeverity_Disable[];
+extern const char kGraphicsImpl[];
+extern const char kGraphicsImpl_Angle[];
+extern const char kGraphicsImpl_AngleCmdBuffer[];
+extern const char kGraphicsImpl_Desktop[];
+extern const char kGraphicsImpl_DesktopCmdBuffer[];
+extern const char kLocalStorageQuota[];
+extern const char kSessionStorageQuota[];
+extern const char kJavascriptFlags[];
+
+// CefBrowserSettings attributes.
+extern const char kDragDropDisabled[];
+extern const char kLoadDropsDisabled[];
+extern const char kHistoryDisabled[];
+extern const char kRemoteFontsDisabled[];
+extern const char kDefaultEncoding[];
+extern const char kEncodingDetectorEnabled[];
+extern const char kJavascriptDisabled[];
+extern const char kJavascriptOpenWindowsDisallowed[];
+extern const char kJavascriptCloseWindowsDisallowed[];
+extern const char kJavascriptAccessClipboardDisallowed[];
+extern const char kDomPasteDisabled[];
+extern const char kCaretBrowsingDisabled[];
+extern const char kJavaDisabled[];
+extern const char kPluginsDisabled[];
+extern const char kUniversalAccessFromFileUrlsAllowed[];
+extern const char kFileAccessFromFileUrlsAllowed[];
+extern const char kWebSecurityDisabled[];
+extern const char kXssAuditorEnabled[];
+extern const char kImageLoadingDisabled[];
+extern const char kShrinkStandaloneImagesToFit[];
+extern const char kSiteSpecificQuirksDisabled[];
+extern const char kTextAreaResizeDisabled[];
+extern const char kPageCacheDisabled[];
+extern const char kTabToLinksDisabled[];
+extern const char kHyperlinkAuditingDisabled[];
+extern const char kUserStyleSheetEnabled[];
+extern const char kUserStyleSheetLocation[];
+extern const char kAuthorAndUserStylesDisabled[];
+extern const char kLocalStorageDisabled[];
+extern const char kDatabasesDisabled[];
+extern const char kApplicationCacheDisabled[];
+extern const char kWebglDisabled[];
+extern const char kAcceleratedCompositingEnabled[];
+extern const char kThreadedCompositingEnabled[];
+extern const char kAcceleratedLayersDisabled[];
+extern const char kAcceleratedVideoDisabled[];
+extern const char kAcceledated2dCanvasDisabled[];
+extern const char kAcceleratedDrawingDisabled[];
+extern const char kAcceleratedPluginsDisabled[];
+extern const char kDeveloperToolsDisabled[];
+
+// Other attributes.
+extern const char kProxyType[];
+extern const char kProxyType_Direct[];
+extern const char kProxyType_Named[];
+extern const char kProxyType_Pac[];
+extern const char kProxyConfig[];
+
+} // namespace cefclient
+
+#endif // _CEFCLIENT_SWITCHES_H
798 cefclient/cefclient_win.cpp
@@ -0,0 +1,798 @@
+// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
+// reserved. Use of this source code is governed by a BSD-style license that
+// can be found in the LICENSE file.
+
+#include "include/cef.h"
+#include "include/cef_runnable.h"
+#include "cefclient.h"
+#include "binding_test.h"
+#include "client_handler.h"
+#include "extension_test.h"
+#include "osrplugin_test.h"
+#include "plugin_test.h"
+#include "resource.h"
+#include "scheme_test.h"
+#include "string_util.h"
+#include "uiplugin_test.h"
+#include <commdlg.h>
+#include <direct.h>
+#include <sstream>
+
+#include <shellapi.h>
+
+#define MAX_LOADSTRING 100
+#define MAX_URL_LENGTH 255
+#define BUTTON_WIDTH 72
+#define URLBAR_HEIGHT 24
+
+// Global Variables:
+HINSTANCE hInst; // current instance
+TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
+TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
+char szWorkingDir[MAX_PATH]; // The current working directory
+UINT uFindMsg; // Message identifier for find events.
+HWND hFindDlg = NULL; // Handle for the find dialog.
+
+// Forward declarations of functions included in this code module:
+ATOM MyRegisterClass(HINSTANCE hInstance);
+BOOL InitInstance(HINSTANCE, int);
+LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
+INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
+
+// The global ClientHandler reference.
+extern CefRefPtr<ClientHandler> g_handler;
+
+#if defined(OS_WIN)
+// Add Common Controls to the application manifest because it's required to
+// support the default tooltip implementation.
+#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
+#endif
+
+// Program entry point function.
+int APIENTRY wWinMain(HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPTSTR lpCmdLine,
+ int nCmdShow)
+{
+ UNREFERENCED_PARAMETER(hPrevInstance);
+ UNREFERENCED_PARAMETER(lpCmdLine);
+
+ // Retrieve the current working directory.
+ if(_getcwd(szWorkingDir, MAX_PATH) == NULL)
+ szWorkingDir[0] = 0;
+
+ // Parse command line arguments. The passed in values are ignored on Windows.
+ AppInitCommandLine(0, NULL);
+
+ CefSettings settings;
+ CefRefPtr<CefApp> app;
+
+ // Populate the settings based on command line arguments.
+ AppGetSettings(settings, app);
+
+ // Initialize CEF.
+ CefInitialize(settings, app);
+
+ // Register the internal client plugin.
+ InitPluginTest();
+
+ // Register the internal UI client plugin.
+ InitUIPluginTest();
+
+ // Register the internal OSR client plugin.
+ InitOSRPluginTest();
+
+ // Register the V8 extension handler.
+ InitExtensionTest();
+
+ // Register the scheme handler.
+ InitSchemeTest();
+
+ HACCEL hAccelTable;
+
+ // Initialize global strings
+ LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
+ LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING);
+ MyRegisterClass(hInstance);
+
+ // Perform application initialization
+ if (!InitInstance (hInstance, nCmdShow))
+ {
+ return FALSE;
+ }
+
+ hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT));
+
+ // Register the find event message.
+ uFindMsg = RegisterWindowMessage(FINDMSGSTRING);
+
+ int result = 0;
+
+ if (!settings.multi_threaded_message_loop) {
+ // Run the CEF message loop. This function will block until the application
+ // recieves a WM_QUIT message.
+ CefRunMessageLoop();
+ } else {
+ MSG msg;
+
+ // Run the application message loop.
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ // Allow processing of find dialog messages.
+ if (hFindDlg && IsDialogMessage(hFindDlg, &msg))
+ continue;
+
+ if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+
+ result = (int)msg.wParam;
+ }
+
+ // Shut down CEF.
+ CefShutdown();
+
+ return result;
+}
+
+//
+// FUNCTION: MyRegisterClass()
+//
+// PURPOSE: Registers the window class.
+//
+// COMMENTS:
+//
+// This function and its usage are only necessary if you want this code
+// to be compatible with Win32 systems prior to the 'RegisterClassEx'
+// function that was added to Windows 95. It is important to call this
+// function so that the application will get 'well formed' small icons
+// associated with it.
+//
+ATOM MyRegisterClass(HINSTANCE hInstance)
+{
+ WNDCLASSEX wcex;
+
+ wcex.cbSize = sizeof(WNDCLASSEX);
+
+ wcex.style = CS_HREDRAW | CS_VREDRAW;
+ wcex.lpfnWndProc = WndProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hInstance = hInstance;
+ wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CEFCLIENT));
+ wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
+ wcex.lpszMenuName = MAKEINTRESOURCE(IDC_CEFCLIENT);
+ wcex.lpszClassName = szWindowClass;
+ wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
+
+ return RegisterClassEx(&wcex);
+}
+
+//
+// FUNCTION: InitInstance(HINSTANCE, int)
+//
+// PURPOSE: Saves instance handle and creates main window
+//
+// COMMENTS:
+//
+// In this function, we save the instance handle in a global variable and
+// create and display the main program window.
+//
+BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
+{
+ HWND hWnd;
+
+ hInst = hInstance; // Store instance handle in our global variable
+
+ hWnd = CreateWindow(szWindowClass, szTitle,
+ WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, 0, CW_USEDEFAULT,
+ 0, NULL, NULL, hInstance, NULL);
+
+ if (!hWnd)
+ {
+ return FALSE;
+ }
+
+ ShowWindow(hWnd, nCmdShow);
+ UpdateWindow(hWnd);
+
+ return TRUE;
+}
+
+//
+// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
+//
+// PURPOSE: Processes messages for the main window.
+//
+LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
+ stopWnd = NULL, editWnd = NULL;
+ static WNDPROC editWndOldProc = NULL;
+
+ // Static members used for the find dialog.
+ static FINDREPLACE fr;
+ static WCHAR szFindWhat[80] = {0};
+ static WCHAR szLastFindWhat[80] = {0};
+ static bool findNext = false;
+ static bool lastMatchCase = false;
+
+ int wmId, wmEvent;
+ PAINTSTRUCT ps;
+ HDC hdc;
+
+ if(hWnd == editWnd)
+ {
+ // Callback for the edit window
+ switch (message)
+ {
+ case WM_CHAR:
+ if (wParam == VK_RETURN && g_handler.get())
+ {
+ // When the user hits the enter key load the URL
+ CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
+ wchar_t strPtr[MAX_URL_LENGTH] = {0};
+ *((LPWORD)strPtr) = MAX_URL_LENGTH;
+ LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
+ if (strLen > 0) {
+ strPtr[strLen] = 0;
+ browser->GetMainFrame()->LoadURL(strPtr);
+ }
+
+ return 0;
+ }
+ }
+
+ return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam, lParam);
+ }
+ else if (message == uFindMsg)
+ {
+ // Find event.
+ LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;
+
+ if (lpfr->Flags & FR_DIALOGTERM)
+ {
+ // The find dialog box has been dismissed so invalidate the handle and
+ // reset the search results.
+ hFindDlg = NULL;
+ if(g_handler.get())
+ {
+ g_handler->GetBrowser()->StopFinding(true);
+ szLastFindWhat[0] = 0;
+ findNext = false;
+ }
+ return 0;
+ }
+
+ if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get())
+ {
+ // Search for the requested string.
+ bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false);
+ if(matchCase != lastMatchCase ||
+ (matchCase && wcsncmp(szFindWhat, szLastFindWhat,
+ sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) ||
+ (!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat,
+ sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0))
+ {
+ // The search string has changed, so reset the search results.
+ if(szLastFindWhat[0] != 0) {
+ g_handler->GetBrowser()->StopFinding(true);
+ findNext = false;
+ }
+ lastMatchCase = matchCase;
+ wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR),
+ szFindWhat);
+ }
+
+ g_handler->GetBrowser()->Find(0, lpfr->lpstrFindWhat,
+ (lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext);
+ if(!findNext)
+ findNext = true;
+ }
+
+ return 0;
+ }
+ else
+ {
+ // Callback for the main window
+ switch (message)
+ {
+ case WM_CREATE:
+ {
+ // Create the single static handler class instance
+ g_handler = new ClientHandler();
+ g_handler->SetMainHwnd(hWnd);
+
+ // Create the child windows used for navigation
+ RECT rect;
+ int x = 0;
+
+ GetClientRect(hWnd, &rect);
+
+ backWnd = CreateWindow(L"BUTTON", L"Back",
+ WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
+ | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
+ hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
+ x += BUTTON_WIDTH;
+
+ forwardWnd = CreateWindow(L"BUTTON", L"Forward",
+ WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
+ | WS_DISABLED, x, 0, BUTTON_WIDTH,
+ URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
+ hInst, 0);
+ x += BUTTON_WIDTH;
+
+ reloadWnd = CreateWindow(L"BUTTON", L"Reload",
+ WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
+ | WS_DISABLED, x, 0, BUTTON_WIDTH,
+ URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
+ hInst, 0);
+ x += BUTTON_WIDTH;
+
+ stopWnd = CreateWindow(L"BUTTON", L"Stop",
+ WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
+ | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
+ hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
+ x += BUTTON_WIDTH;
+
+ editWnd = CreateWindow(L"EDIT", 0,
+ WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
+ ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
+ x, 0, rect.right - BUTTON_WIDTH * 4,
+ URLBAR_HEIGHT, hWnd, 0, hInst, 0);
+
+ // Assign the edit window's WNDPROC to this function so that we can
+ // capture the enter key
+ editWndOldProc =
+ reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
+ SetWindowLongPtr(editWnd, GWLP_WNDPROC,
+ reinterpret_cast<LONG_PTR>(WndProc));
+ g_handler->SetEditHwnd(editWnd);
+ g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);
+
+ rect.top += URLBAR_HEIGHT;
+
+ CefWindowInfo info;
+ CefBrowserSettings settings;
+
+ // Populate the settings based on command line arguments.
+ AppGetBrowserSettings(settings);
+
+ // Initialize window info to the defaults for a child window
+ info.SetAsChild(hWnd, rect);
+
+ // Creat the new child browser window
+ CefBrowser::CreateBrowser(info,
+ static_cast<CefRefPtr<CefClient> >(g_handler),
+ "http://www.google.com", settings);
+ }
+ return 0;
+
+ case WM_COMMAND:
+ {
+ CefRefPtr<CefBrowser> browser;
+ if(g_handler.get())
+ browser = g_handler->GetBrowser();
+
+ wmId = LOWORD(wParam);
+ wmEvent = HIWORD(wParam);
+ // Parse the menu selections:
+ switch (wmId)
+ {
+ case IDM_ABOUT:
+ DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
+ return 0;
+ case IDM_EXIT:
+ DestroyWindow(hWnd);
+ return 0;
+ case ID_WARN_CONSOLEMESSAGE:
+ if(g_handler.get()) {
+ std::wstringstream ss;
+ ss << L"Console messages will be written to "
+ << std::wstring(CefString(g_handler->GetLogFile()));
+ MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
+ MB_OK | MB_ICONINFORMATION);
+ }
+ return 0;
+ case ID_WARN_DOWNLOADCOMPLETE:
+ case ID_WARN_DOWNLOADERROR:
+ if(g_handler.get()) {
+ std::wstringstream ss;
+ ss << L"File \"" <<
+ std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
+ L"\" ";
+
+ if(wmId == ID_WARN_DOWNLOADCOMPLETE)
+ ss << L"downloaded successfully.";
+ else
+ ss << L"failed to download.";
+
+ MessageBox(hWnd, ss.str().c_str(), L"File Download",
+ MB_OK | MB_ICONINFORMATION);
+ }
+ return 0;
+ case ID_FIND:
+ if(!hFindDlg)
+ {
+ // Create the find dialog.
+ ZeroMemory(&fr, sizeof(fr));
+ fr.lStructSize = sizeof(fr);
+ fr.hwndOwner = hWnd;
+ fr.lpstrFindWhat = szFindWhat;
+ fr.wFindWhatLen = sizeof(szFindWhat);
+ fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN;
+
+ hFindDlg = FindText(&fr);
+ }
+ else
+ {
+ // Give focus to the existing find dialog.
+ ::SetFocus(hFindDlg);
+ }
+ return 0;
+ case ID_PRINT:
+ if(browser.get())
+ browser->GetMainFrame()->Print();
+ return 0;
+ case IDC_NAV_BACK: // Back button
+ if(browser.get())
+ browser->GoBack();
+ return 0;
+ case IDC_NAV_FORWARD: // Forward button
+ if(browser.get())
+ browser->GoForward();
+ return 0;
+ case IDC_NAV_RELOAD: // Reload button
+ if(browser.get())
+ browser->Reload();
+ return 0;
+ case IDC_NAV_STOP: // Stop button
+ if(browser.get())
+ browser->StopLoad();
+ return 0;
+ case ID_TESTS_GETSOURCE: // Test the GetSource function
+ if(browser.get())
+ RunGetSourceTest(browser);
+ return 0;
+ case ID_TESTS_GETTEXT: // Test the GetText function
+ if(browser.get())
+ RunGetTextTest(browser);
+ return 0;
+ case ID_TESTS_JAVASCRIPT_BINDING: // Test the V8 binding handler
+ if(browser.get())
+ RunBindingTest(browser);
+ return 0;
+ case ID_TESTS_JAVASCRIPT_EXTENSION: // Test the V8 extension handler
+ if(browser.get())
+ RunExtensionTest(browser);
+ return 0;
+ case ID_TESTS_JAVASCRIPT_PERFORMANCE: // Test the V8 performance
+ if(browser.get())
+ RunExtensionPerfTest(browser);
+ return 0;
+ case ID_TESTS_JAVASCRIPT_EXECUTE: // Test execution of javascript
+ if(browser.get())
+ RunJavaScriptExecuteTest(browser);
+ return 0;
+ case ID_TESTS_JAVASCRIPT_INVOKE:
+ if(browser.get())
+ RunJavaScriptInvokeTest(browser);
+ return 0;
+ case ID_TESTS_PLUGIN: // Test the custom plugin
+ if(browser.get())
+ RunPluginTest(browser);
+ return 0;
+ case ID_TESTS_POPUP: // Test a popup window
+ if(browser.get())
+ RunPopupTest(browser);
+ return 0;
+ case ID_TESTS_TRANSPARENT_POPUP: // Test a transparent popup window
+ if(browser.get())
+ RunTransparentPopupTest(browser);
+ return 0;
+ case ID_TESTS_REQUEST: // Test a request
+ if(browser.get())
+ RunRequestTest(browser);
+ return 0;
+ case ID_TESTS_SCHEME_HANDLER: // Test the scheme handler
+ if(browser.get())
+ RunSchemeTest(browser);
+ return 0;
+ case ID_TESTS_UIAPP: // Test the UI app
+ if(browser.get())
+ RunUIPluginTest(browser);
+ return 0;
+ case ID_TESTS_OSRAPP: // Test the OSR app
+ if(browser.get())
+ RunOSRPluginTest(browser, false);
+ return 0;
+ case ID_TESTS_TRANSPARENT_OSRAPP: // Test the OSR app with transparency
+ if(browser.get())
+ RunOSRPluginTest(browser, true);
+ return 0;
+ case ID_TESTS_DOMACCESS: // Test DOM access
+ if(browser.get())
+ RunDOMAccessTest(browser);
+ return 0;
+ case ID_TESTS_LOCALSTORAGE: // Test localStorage
+ if(browser.get())
+ RunLocalStorageTest(browser);
+ return 0;
+ case ID_TESTS_ACCELERATED2DCANVAS: // Test accelerated 2d canvas
+ if(browser.get())
+ RunAccelerated2DCanvasTest(browser);
+ return 0;
+ case ID_TESTS_ACCELERATEDLAYERS: // Test accelerated layers
+ if(browser.get())
+ RunAcceleratedLayersTest(browser);
+ return 0;
+ case ID_TESTS_WEBGL: // Test WebGL
+ if(browser.get())
+ RunWebGLTest(browser);
+ return 0;
+ case ID_TESTS_HTML5VIDEO: // Test HTML5 video
+ if(browser.get())
+ RunHTML5VideoTest(browser);
+ return 0;
+ case ID_TESTS_DRAGDROP: // Test drag & drop
+ if(browser.get())
+ RunDragDropTest(browser);
+ return 0;
+ case ID_TESTS_XMLHTTPREQUEST: // Test XMLHttpRequest
+ if(browser.get())
+ RunXMLHTTPRequestTest(browser);
+ return 0;
+ case ID_TESTS_WEBURLREQUEST:
+ if (browser.get())
+ RunWebURLRequestTest(browser);
+ return 0;
+ case ID_TESTS_ZOOM_IN:
+ if(browser.get())
+ browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
+ return 0;
+ case ID_TESTS_ZOOM_OUT:
+ if(browser.get())
+ browser->SetZoomLevel(browser->GetZoomLevel() - 0.5);
+ return 0;
+ case ID_TESTS_ZOOM_RESET:
+ if(browser.get())
+ browser->SetZoomLevel(0.0);
+ return 0;
+ case ID_TESTS_DEVTOOLS_SHOW:
+ if (browser.get())
+ browser->ShowDevTools();
+ return 0;
+ case ID_TESTS_DEVTOOLS_CLOSE:
+ if (browser.get())
+ browser->CloseDevTools();
+ return 0;
+ case ID_TESTS_MODALDIALOG:
+ if(browser.get())
+ RunModalDialogTest(browser);
+ return 0;
+ case ID_TESTS_GETIMAGE:
+ if(browser.get())
+ RunGetImageTest(browser);
+ return 0;
+ }
+ }
+ break;
+
+ case WM_PAINT:
+ hdc = BeginPaint(hWnd, &ps);
+ EndPaint(hWnd, &ps);
+ return 0;
+
+ case WM_SETFOCUS:
+ if(g_handler.get() && g_handler->GetBrowserHwnd())
+ {
+ // Pass focus to the browser window
+ PostMessage(g_handler->GetBrowserHwnd(), WM_SETFOCUS, wParam, NULL);
+ }
+ return 0;
+
+ case WM_SIZE:
+ if(g_handler.get() && g_handler->GetBrowserHwnd())
+ {
+ // Resize the browser window and address bar to match the new frame
+ // window size
+ RECT rect;
+ GetClientRect(hWnd, &rect);
+ rect.top += URLBAR_HEIGHT;
+
+ int urloffset = rect.left + BUTTON_WIDTH * 4;
+
+ HDWP hdwp = BeginDeferWindowPos(1);
+ hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
+ 0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
+ hdwp = DeferWindowPos(hdwp, g_handler->GetBrowserHwnd(), NULL,
+ rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
+ SWP_NOZORDER);
+ EndDeferWindowPos(hdwp);
+ }
+ break;
+
+ case WM_ERASEBKGND:
+ if(g_handler.get() && g_handler->GetBrowserHwnd())
+ {
+ // Dont erase the background if the browser window has been loaded
+ // (this avoids flashing)
+ return 0;
+ }
+ break;
+
+ case WM_CLOSE:
+ if (g_handler.get()) {
+ CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
+ if (browser.get()) {
+ // Let the browser window know we are about to destroy it.
+ browser->ParentWindowWillClose();
+ }
+ }
+ break;
+
+ case WM_DESTROY:
+ // The frame window has exited
+ PostQuitMessage(0);
+ return 0;
+ }
+
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+}
+
+// Message handler for about box.
+INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ UNREFERENCED_PARAMETER(lParam);
+ switch (message)
+ {
+ case WM_INITDIALOG:
+ return (INT_PTR)TRUE;
+
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
+ {
+ EndDialog(hDlg, LOWORD(wParam));
+ return (INT_PTR)TRUE;
+ }
+ break;
+ }
+ return (INT_PTR)FALSE;
+}
+
+
+// Global functions
+
+std::string AppGetWorkingDirectory()
+{
+ return szWorkingDir;
+}
+
+void RunTransparentPopupTest(CefRefPtr<CefBrowser> browser)
+{
+ CefWindowInfo info;
+ CefBrowserSettings settings;
+
+ // Initialize window info to the defaults for a popup window
+ info.SetAsPopup(NULL, "TransparentPopup");
+ info.SetTransparentPainting(TRUE);
+ info.m_nWidth = 500;
+ info.m_nHeight = 500;
+
+ // Creat the popup browser window
+ CefBrowser::CreateBrowser(info,
+ static_cast<CefRefPtr<CefClient> >(g_handler),
+ "http://tests/transparency", settings);
+}
+
+namespace {
+
+// Determine a temporary path for the bitmap file.
+bool GetBitmapTempPath(LPWSTR szTempName)
+{
+ DWORD dwRetVal;
+ DWORD dwBufSize = 512;
+ TCHAR lpPathBuffer[512];
+ UINT uRetVal;
+
+ dwRetVal = GetTempPath(dwBufSize, // length of the buffer
+ lpPathBuffer); // buffer for path
+ if (dwRetVal > dwBufSize || (dwRetVal == 0))
+ return false;
+
+ // Create a temporary file.
+ uRetVal = GetTempFileName(lpPathBuffer, // directory for tmp files
+ L"image", // temp file name prefix
+ 0, // create unique name
+ szTempName); // buffer for name
+ if (uRetVal == 0)
+ return false;
+
+ size_t len = wcslen(szTempName);
+ wcscpy(szTempName + len - 3, L"bmp");
+ return true;
+}
+
+void UIT_RunGetImageTest(CefRefPtr<CefBrowser> browser)
+{
+ REQUIRE_UI_THREAD();
+
+ int width, height;
+ bool success = false;
+
+ // Retrieve the image size.
+ if (browser->GetSize(PET_VIEW, width, height)) {
+ void* bits;
+
+ // Populate the bitmap info header.
+ BITMAPINFOHEADER info;
+ info.biSize = sizeof(BITMAPINFOHEADER);
+ info.biWidth = width;
+ info.biHeight = -height; // minus means top-down bitmap
+ info.biPlanes = 1;
+ info.biBitCount = 32;
+ info.biCompression = BI_RGB; // no compression
+ info.biSizeImage = 0;
+ info.biXPelsPerMeter = 1;
+ info.biYPelsPerMeter = 1;
+ info.biClrUsed = 0;
+ info.biClrImportant = 0;
+
+ // Create the bitmap and retrieve the bit buffer.
+ HDC screen_dc = GetDC(NULL);
+ HBITMAP bitmap =
+ CreateDIBSection(screen_dc, reinterpret_cast<BITMAPINFO*>(&info),
+ DIB_RGB_COLORS, &bits, NULL, 0);
+ ReleaseDC(NULL, screen_dc);
+
+ // Read the image into the bit buffer.
+ if (bitmap && browser->GetImage(PET_VIEW, width, height, bits)) {
+ // Populate the bitmap file header.
+ BITMAPFILEHEADER file;
+ file.bfType = 0x4d42;
+ file.bfSize = sizeof(BITMAPFILEHEADER);
+ file.bfReserved1 = 0;
+ file.bfReserved2 = 0;
+ file.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
+
+ TCHAR temp_path[512];
+ if (GetBitmapTempPath(temp_path)) {
+ // Write the bitmap to file.
+ HANDLE file_handle =
+ CreateFile(temp_path, GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL, 0);
+ if (file_handle != INVALID_HANDLE_VALUE) {
+ DWORD bytes_written = 0;
+ WriteFile(file_handle, &file, sizeof(file), &bytes_written, 0);
+ WriteFile(file_handle, &info, sizeof(info), &bytes_written, 0);
+ WriteFile(file_handle, bits, width * height * 4, &bytes_written, 0);
+
+ CloseHandle(file_handle);
+
+ // Open the bitmap in the default viewer.
+ ShellExecute(NULL, L"open", temp_path, NULL, NULL, SW_SHOWNORMAL);
+ success = true;
+ }
+ }
+ }
+
+ DeleteObject(bitmap);
+ }
+
+ if (!success) {
+ browser->GetMainFrame()->ExecuteJavaScript(
+ "alert('Failed to create image!');",
+ browser->GetMainFrame()->GetURL(), 0);
+ }
+}
+
+} // namespace
+
+void RunGetImageTest(CefRefPtr<CefBrowser> browser)
+{
+ // Execute the test function on the UI thread.
+ CefPostTask(TID_UI, NewCefRunnableFunction(UIT_RunGetImageTest, browser));
+}
377 cefclient/client_handler.cpp
@@ -0,0 +1,377 @@
+// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
+// reserved. Use of this source code is governed by a BSD-style license that
+// can be found in the LICENSE file.
+
+#include "include/cef.h"
+#include "client_handler.h"
+#include "binding_test.h"
+#include "cefclient.h"
+#include "download_handler.h"
+#include "string_util.h"
+#include <sstream>
+#include <stdio.h>
+#include <string>
+
+
+ClientHandler::ClientHandler()
+ : m_MainHwnd(NULL),
+ m_BrowserHwnd(NULL),
+ m_EditHwnd(NULL),
+ m_BackHwnd(NULL),
+ m_ForwardHwnd(NULL),
+ m_StopHwnd(NULL),
+ m_ReloadHwnd(NULL),
+ m_bFormElementHasFocus(false)
+{
+}
+
+ClientHandler::~ClientHandler()
+{
+}
+
+
+void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
+{
+ REQUIRE_UI_THREAD();
+
+ AutoLock lock_scope(this);
+ if(!m_Browser.get())
+ {
+ // We need to keep the main child window, but not popup windows
+ m_Browser = browser;
+ m_BrowserHwnd = browser->GetWindowHandle();
+ }
+}
+
+bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser)
+{
+ REQUIRE_UI_THREAD();
+
+ if (m_BrowserHwnd == browser->GetWindowHandle()) {
+ // Since the main window contains the browser window, we need to close
+ // the parent window instead of the browser window.
+ CloseMainWindow();
+
+ // Return true here so that we can skip closing the browser window
+ // in this pass. (It will be destroyed due to the call to close
+ // the parent above.)
+ return true;
+ }
+
+ // A popup browser window is not contained in another window, so we can let
+ // these windows close by themselves.
+ return false;
+}
+
+void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
+{
+ REQUIRE_UI_THREAD();
+
+ if(m_BrowserHwnd == browser->GetWindowHandle()) {
+ // Free the browser pointer so that the browser can be destroyed
+ m_Browser = NULL;
+ }
+}
+
+void ClientHandler::OnLoadStart(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefFrame> frame)
+{
+ REQUIRE_UI_THREAD();
+
+ if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
+ // We've just started loading a page
+ SetLoading(true);
+ }
+}
+
+void ClientHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefFrame> frame,
+ int httpStatusCode)
+{
+ REQUIRE_UI_THREAD();
+
+ if(m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
+ // We've just finished loading a page
+ SetLoading(false);
+
+ CefRefPtr<CefDOMVisitor> visitor = GetDOMVisitor(frame->GetURL());
+ if(visitor.get())
+ frame->VisitDOM(visitor);
+ }
+}
+
+bool ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefFrame> frame,
+ ErrorCode errorCode,
+ const CefString& failedUrl,
+ CefString& errorText)
+{
+ REQUIRE_UI_THREAD();
+
+ if(errorCode == ERR_CACHE_MISS) {
+ // Usually caused by navigating to a page with POST data via back or
+ // forward buttons.
+ errorText = "<html><head><title>Expired Form Data</title></head>"
+ "<body><h1>Expired Form Data</h1>"
+ "<h2>Your form request has expired. "
+ "Click reload to re-submit the form data.</h2></body>"
+ "</html>";
+ } else {
+ // All other messages.
+ std::stringstream ss;
+ ss << "<html><head><title>Load Failed</title></head>"
+ "<body><h1>Load Failed</h1>"
+ "<h2>Load of URL " << std::string(failedUrl) <<
+ " failed with error code " << static_cast<int>(errorCode) <<
+ ".</h2></body>"
+ "</html>";
+ errorText = ss.str();
+ }
+
+ return false;
+}
+
+bool ClientHandler::GetDownloadHandler(CefRefPtr<CefBrowser> browser,
+ const CefString& mimeType,
+ const CefString& fileName,
+ int64 contentLength,
+ CefRefPtr<CefDownloadHandler>& handler)
+{
+ REQUIRE_UI_THREAD();
+
+ // Create the handler for the file download.
+ handler = CreateDownloadHandler(this, fileName);
+
+ // Close the browser window if it is a popup with no other document contents.
+ if (browser->IsPopup() && !browser->HasDocument())
+ browser->CloseBrowser();
+
+ return true;
+}
+
+void ClientHandler::OnNavStateChange(CefRefPtr<CefBrowser> browser,
+ bool canGoBack,
+ bool canGoForward)
+{
+ REQUIRE_UI_THREAD();
+
+ SetNavState(canGoBack, canGoForward);
+}
+
+bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
+ const CefString& message,
+ const CefString& source,
+ int line)
+{
+ REQUIRE_UI_THREAD();
+
+ bool first_message;
+ std::string logFile;
+
+ {
+ AutoLock lock_scope(this);
+
+ first_message = m_LogFile.empty();
+ if(first_message) {
+ std::stringstream ss;
+ ss << AppGetWorkingDirectory();
+#if defined(OS_WIN)
+ ss << "\\";
+#else
+ ss << "/";
+#endif
+ ss << "console.log";
+ m_LogFile = ss.str();
+ }
+ logFile = m_LogFile;
+}
+
+ FILE* file = fopen(logFile.c_str(), "a");
+ if(file) {
+ std::stringstream ss;
+ ss << "Message: " << std::string(message) << "\r\nSource: " <<
+ std::string(source) << "\r\nLine: " << line <<
+ "\r\n-----------------------\r\n";
+ fputs(ss.str().c_str(), file);
+ fclose(file);
+
+ if(first_message)
+ SendNotification(NOTIFY_CONSOLE_MESSAGE);
+ }
+
+ return false;
+}
+
+void ClientHandler::OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefFrame> frame,
+ CefRefPtr<CefDOMNode> node)
+{
+ REQUIRE_UI_THREAD();
+
+ // Set to true if a form element has focus.
+ m_bFormElementHasFocus = (node.get() && node->IsFormControlElement());
+}
+
+bool ClientHandler::OnKeyEvent(CefRefPtr<CefBrowser> browser,
+ KeyEventType type,
+ int code,
+ int modifiers,
+ bool isSystemKey,
+ bool isAfterJavaScript)
+{
+ REQUIRE_UI_THREAD();
+
+ if (isAfterJavaScript && !m_bFormElementHasFocus && code == 0x20) {
+ // Special handling for the space character if a form element does not have
+ // focus.
+ if (type == KEYEVENT_RAWKEYDOWN) {
+ browser->GetMainFrame()->ExecuteJavaScript(
+ "alert('You pressed the space bar!');", "", 0);
+ }
+ return true;
+ }
+
+ return false;
+}
+
+bool ClientHandler::GetPrintHeaderFooter(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefFrame> frame,
+ const CefPrintInfo& printInfo,
+ const CefString& url,
+ const CefString& title,
+ int currentPage,
+ int maxPages,
+ CefString& topLeft,
+ CefString& topCenter,
+ CefString& topRight,
+ CefString& bottomLeft,
+ CefString& bottomCenter,
+ CefString& bottomRight)
+{
+ REQUIRE_UI_THREAD();
+
+ // Place the page title at top left
+ topLeft = title;
+ // Place the page URL at top right
+ topRight = url;
+
+ // Place "Page X of Y" at bottom center
+ std::stringstream strstream;
+ strstream << "Page " << currentPage << " of " << maxPages;
+ bottomCenter = strstream.str();
+
+ return false;
+}
+
+void ClientHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefFrame> frame,
+ CefRefPtr<CefV8Context> context)
+{
+ REQUIRE_UI_THREAD();
+
+ // Add the V8 bindings.
+ InitBindingTest(browser, frame, context->GetGlobal());
+}
+
+bool ClientHandler::OnDragStart(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefDragData> dragData,
+ DragOperationsMask mask)
+{
+ REQUIRE_UI_THREAD();
+
+ // Forbid dragging of image files.
+ if (dragData->IsFile()) {
+ std::string fileExt = dragData->GetFileExtension();
+ if (fileExt == ".png" || fileExt == ".jpg" || fileExt == ".gif")
+ return true;
+ }
+
+ return false;
+}
+
+bool ClientHandler::OnDragEnter(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefDragData> dragData,
+ DragOperationsMask mask)
+{
+ REQUIRE_UI_THREAD();
+
+ // Forbid dragging of link URLs.
+ if (dragData->IsLink())
+ return true;
+
+ return false;
+}
+
+void ClientHandler::NotifyDownloadComplete(const CefString& fileName)
+{
+ SetLastDownloadFile(fileName);
+ SendNotification(NOTIFY_DOWNLOAD_COMPLETE);
+}
+
+void ClientHandler::NotifyDownloadError(const CefString& fileName)
+{
+ SetLastDownloadFile(fileName);
+ SendNotification(NOTIFY_DOWNLOAD_ERROR);
+}
+
+void ClientHandler::SetMainHwnd(CefWindowHandle hwnd)
+{
+ AutoLock lock_scope(this);
+ m_MainHwnd = hwnd;
+}
+
+void ClientHandler::SetEditHwnd(CefWindowHandle hwnd)
+{
+ AutoLock lock_scope(this);
+ m_EditHwnd = hwnd;
+}
+
+void ClientHandler::SetButtonHwnds(CefWindowHandle backHwnd,
+ CefWindowHandle forwardHwnd,
+ CefWindowHandle reloadHwnd,
+ CefWindowHandle stopHwnd)
+{
+ AutoLock lock_scope(this);
+ m_BackHwnd = backHwnd;
+ m_ForwardHwnd = forwardHwnd;
+ m_ReloadHwnd = reloadHwnd;
+ m_StopHwnd = stopHwnd;
+}
+
+std::string ClientHandler::GetLogFile()
+{
+ AutoLock lock_scope(this);
+ return m_LogFile;
+}
+
+void ClientHandler::SetLastDownloadFile(const std::string& fileName)
+{
+ AutoLock lock_scope(this);
+ m_LastDownloadFile = fileName;
+}
+
+std::string ClientHandler::GetLastDownloadFile()
+{
+ AutoLock lock_scope(this);
+ return m_LastDownloadFile;
+}
+
+void ClientHandler::AddDOMVisitor(const std::string& path,
+ CefRefPtr<CefDOMVisitor> visitor)
+{
+ AutoLock lock_scope(this);
+ DOMVisitorMap::iterator it = m_DOMVisitors.find(path);
+ if (it == m_DOMVisitors.end())
+ m_DOMVisitors.insert(std::make_pair(path, visitor));
+ else
+ it->second = visitor;
+}
+
+CefRefPtr<CefDOMVisitor> ClientHandler::GetDOMVisitor(const std::string& path)
+{
+ AutoLock lock_scope(this);
+ DOMVisitorMap::iterator it = m_DOMVisitors.find(path);
+ if (it != m_DOMVisitors.end())
+ return it->second;
+ return NULL;
+}
223 cefclient/client_handler.h
@@ -0,0 +1,223 @@
+// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
+// reserved. Use of this source code is governed by a BSD-style license that
+// can be found in the LICENSE file.
+
+#ifndef _CLIENT_HANDLER_H
+#define _CLIENT_HANDLER_H
+
+#include "include/cef.h"
+#include "download_handler.h"
+#include "util.h"
+
+
+// Define this value to redirect all popup URLs to the main application browser
+// window.
+//#define TEST_REDIRECT_POPUP_URLS
+
+
+// ClientHandler implementation.
+class ClientHandler : public CefClient,
+ public CefLifeSpanHandler,
+ public CefLoadHandler,
+ public CefRequestHandler,
+ public CefDisplayHandler,
+ public CefFocusHandler,
+ public CefKeyboardHandler,
+ public CefPrintHandler,
+ public CefV8ContextHandler,
+ public CefDragHandler,
+ public DownloadListener
+{
+public:
+ ClientHandler();
+ virtual ~ClientHandler();
+
+ // CefClient methods
+ virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE
+ { return this; }
+ virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE
+ { return this; }
+ virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
+ { return this; }
+ virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE
+ { return this; }
+ virtual CefRefPtr<CefFocusHandler> GetFocusHandler() OVERRIDE
+ { return this; }
+ virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE
+ { return this; }
+ virtual CefRefPtr<CefPrintHandler> GetPrintHandler() OVERRIDE
+ { return this; }
+ virtual CefRefPtr<CefV8ContextHandler> GetV8ContextHandler() OVERRIDE
+ { return this; }
+ virtual CefRefPtr<CefDragHandler> GetDragHandler() OVERRIDE
+ { return this; }
+
+ // CefLifeSpanHandler methods
+ virtual bool OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
+ const CefPopupFeatures& popupFeatures,
+ CefWindowInfo& windowInfo,
+ const CefString& url,
+ CefRefPtr<CefClient>& client,
+ CefBrowserSettings& settings) OVERRIDE;
+ virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
+ virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
+ virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
+
+ // CefLoadHandler methods
+ virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefFrame> frame) OVERRIDE;