Branch CEF3 files from /branches/cef3 to /trunk/cef3 (issue #564).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@571 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2012-04-03 01:34:16 +00:00
parent b568f160d9
commit 34adee805c
516 changed files with 83249 additions and 0 deletions

View File

@@ -0,0 +1,385 @@
// 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 "cefclient/cefclient.h"
#include <stdio.h>
#include <cstdlib>
#include <sstream>
#include <string>
#include "include/cef_app.h"
#include "include/cef_browser.h"
#include "include/cef_command_line.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "cefclient/cefclient_switches.h"
#include "cefclient/client_handler.h"
#include "cefclient/string_util.h"
#include "cefclient/util.h"
namespace {
// 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.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 = PROXY_TYPE_DIRECT;
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_disabled =
g_command_line->HasSwitch(cefclient::kAcceleratedCompositingDisabled);
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_painting_enabled =
g_command_line->HasSwitch(cefclient::kAcceleratedPaintingEnabled);
settings.accelerated_filters_enabled =
g_command_line->HasSwitch(cefclient::kAcceleratedFiltersEnabled);
settings.accelerated_plugins_disabled =
g_command_line->HasSwitch(cefclient::kAcceleratedPluginsDisabled);
settings.developer_tools_disabled =
g_command_line->HasSwitch(cefclient::kDeveloperToolsDisabled);
settings.fullscreen_enabled =
g_command_line->HasSwitch(cefclient::kFullscreenEnabled);
}
void RunGetSourceTest(CefRefPtr<CefBrowser> browser) {
class Visitor : public CefStringVisitor {
public:
Visitor(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
virtual void Visit(const CefString& string) OVERRIDE {
std::string source = StringReplace(string, "<", "&lt;");
source = StringReplace(source, ">", "&gt;");
std::stringstream ss;
ss << "<html><body>Source:<pre>" << source << "</pre></body></html>";
browser_->GetMainFrame()->LoadString(ss.str(), "http://tests/getsource");
}
private:
CefRefPtr<CefBrowser> browser_;
IMPLEMENT_REFCOUNTING(Visitor);
};
browser->GetMainFrame()->GetSource(new Visitor(browser));
}
void RunGetTextTest(CefRefPtr<CefBrowser> browser) {
class Visitor : public CefStringVisitor {
public:
Visitor(CefRefPtr<CefBrowser> browser) : browser_(browser) {}
virtual void Visit(const CefString& string) OVERRIDE {
std::string text = StringReplace(string, "<", "&lt;");
text = StringReplace(text, ">", "&gt;");
std::stringstream ss;
ss << "<html><body>Text:<pre>" << text << "</pre></body></html>";
browser_->GetMainFrame()->LoadString(ss.str(), "http://tests/gettext");
}
private:
CefRefPtr<CefBrowser> browser_;
IMPLEMENT_REFCOUNTING(Visitor);
};
browser->GetMainFrame()->GetText(new Visitor(browser));
}
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 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 RunDragDropTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL("http://html5demos.com/drag");
}
void RunGeolocationTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL("http://html5demos.com/geo");
}

View File

@@ -0,0 +1,55 @@
// 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 CEF_TESTS_CEFCLIENT_CEFCLIENT_H_
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_H_
#pragma once
#include <string>
#include "include/cef_base.h"
class CefApp;
class CefBrowser;
class CefCommandLine;
// 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 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 RunDragDropTest(CefRefPtr<CefBrowser> browser);
void RunGeolocationTest(CefRefPtr<CefBrowser> browser);
#if defined(OS_WIN)
void RunTransparentPopupTest(CefRefPtr<CefBrowser> browser);
#endif
#endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_H_

View File

@@ -0,0 +1,162 @@
// 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_LOGOBALL BINARY "res\\logoball.png"
IDS_LOCALSTORAGE BINARY "res\\localstorage.html"
IDS_XMLHTTPREQUEST BINARY "res\\xmlhttprequest.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 "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 "Popup Window", ID_TESTS_POPUP
MENUITEM "Request", ID_TESTS_REQUEST
MENUITEM "Scheme Handler", ID_TESTS_SCHEME_HANDLER
MENUITEM "Local Storage", ID_TESTS_LOCALSTORAGE
MENUITEM "XMLHttpRequest", ID_TESTS_XMLHTTPREQUEST
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 "Geolocation", ID_TESTS_GEOLOCATION
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

View File

@@ -0,0 +1,340 @@
// 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 <gtk/gtk.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include "cefclient/cefclient.h"
#include "include/cef_app.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "cefclient/client_handler.h"
#include "cefclient/scheme_test.h"
#include "cefclient/string_util.h"
char szWorkingDir[512]; // The current working directory
// The global ClientHandler reference.
extern CefRefPtr<ClientHandler> g_handler;
void destroy(void) {
CefQuitMessageLoop();
}
void TerminationSignalHandler(int signatl) {
destroy();
}
// Callback for Debug > Get Source... menu item.
gboolean GetSourceActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunGetSourceTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > Get Source... menu item.
gboolean GetTextActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunGetTextTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > Request... menu item.
gboolean RequestActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunRequestTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > Local Storage... menu item.
gboolean LocalStorageActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunLocalStorageTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > XMLHttpRequest... menu item.
gboolean XMLHttpRequestActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunXMLHTTPRequestTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > Scheme Handler... menu item.
gboolean SchemeHandlerActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunSchemeTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > Popup Window... menu item.
gboolean PopupWindowActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunPopupTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > Accelerated 2D Canvas... menu item.
gboolean Accelerated2DCanvasActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunAccelerated2DCanvasTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > Accelerated Layers... menu item.
gboolean AcceleratedLayersActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunAcceleratedLayersTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > WebGL... menu item.
gboolean WebGLActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunWebGLTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > HTML5 Video... menu item.
gboolean HTML5VideoActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunHTML5VideoTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for Debug > HTML5 Drag & Drop... menu item.
gboolean HTML5DragDropActivated(GtkWidget* widget) {
if (g_handler.get() && g_handler->GetBrowserId())
RunDragDropTest(g_handler->GetBrowser());
return FALSE; // Don't stop this message.
}
// Callback for when you click the back button.
void BackButtonClicked(GtkButton* button) {
if (g_handler.get() && g_handler->GetBrowserId())
g_handler->GetBrowser()->GoBack();
}
// Callback for when you click the forward button.
void ForwardButtonClicked(GtkButton* button) {
if (g_handler.get() && g_handler->GetBrowserId())
g_handler->GetBrowser()->GoForward();
}
// Callback for when you click the stop button.
void StopButtonClicked(GtkButton* button) {
if (g_handler.get() && g_handler->GetBrowserId())
g_handler->GetBrowser()->StopLoad();
}
// Callback for when you click the reload button.
void ReloadButtonClicked(GtkButton* button) {
if (g_handler.get() && g_handler->GetBrowserId())
g_handler->GetBrowser()->Reload();
}
// Callback for when you press enter in the URL box.
void URLEntryActivate(GtkEntry* entry) {
if (!g_handler.get() || !g_handler->GetBrowserId())
return;
const gchar* url = gtk_entry_get_text(entry);
g_handler->GetBrowser()->GetMainFrame()->LoadURL(std::string(url).c_str());
}
// GTK utility functions ----------------------------------------------
GtkWidget* AddMenuEntry(GtkWidget* menu_widget, const char* text,
GCallback callback) {
GtkWidget* entry = gtk_menu_item_new_with_label(text);
g_signal_connect(entry, "activate", callback, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu_widget), entry);
return entry;
}
GtkWidget* CreateMenu(GtkWidget* menu_bar, const char* text) {
GtkWidget* menu_widget = gtk_menu_new();
GtkWidget* menu_header = gtk_menu_item_new_with_label(text);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_header), menu_widget);
gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), menu_header);
return menu_widget;
}
GtkWidget* CreateMenuBar() {
GtkWidget* menu_bar = gtk_menu_bar_new();
GtkWidget* debug_menu = CreateMenu(menu_bar, "Tests");
AddMenuEntry(debug_menu, "Get Source",
G_CALLBACK(GetSourceActivated));
AddMenuEntry(debug_menu, "Get Text",
G_CALLBACK(GetTextActivated));
AddMenuEntry(debug_menu, "Request",
G_CALLBACK(RequestActivated));
AddMenuEntry(debug_menu, "Local Storage",
G_CALLBACK(LocalStorageActivated));
AddMenuEntry(debug_menu, "XMLHttpRequest",
G_CALLBACK(XMLHttpRequestActivated));
AddMenuEntry(debug_menu, "Scheme Handler",
G_CALLBACK(SchemeHandlerActivated));
AddMenuEntry(debug_menu, "Popup Window",
G_CALLBACK(PopupWindowActivated));
AddMenuEntry(debug_menu, "Accelerated 2D Canvas",
G_CALLBACK(Accelerated2DCanvasActivated));
AddMenuEntry(debug_menu, "Accelerated Layers",
G_CALLBACK(AcceleratedLayersActivated));
AddMenuEntry(debug_menu, "WebGL",
G_CALLBACK(WebGLActivated));
AddMenuEntry(debug_menu, "HTML5 Video",
G_CALLBACK(HTML5VideoActivated));
AddMenuEntry(debug_menu, "HTML5 Drag & Drop",
G_CALLBACK(HTML5DragDropActivated));
return menu_bar;
}
// WebViewDelegate::TakeFocus in the test webview delegate.
static gboolean HandleFocus(GtkWidget* widget,
GdkEventFocus* focus) {
if (g_handler.get() && g_handler->GetBrowserId()) {
// Give focus to the browser window.
g_handler->GetBrowser()->GetHost()->SetFocus(true);
}
return TRUE;
}
int main(int argc, char* argv[]) {
CefMainArgs main_args(argc, argv);
// Execute the secondary process, if any.
int exit_code = CefExecuteProcess(main_args, NULL);
if (exit_code >= 0)
return exit_code;
if (!getcwd(szWorkingDir, sizeof (szWorkingDir)))
return -1;
GtkWidget* window;
gtk_init(&argc, &argv);
// Parse command line arguments.
AppInitCommandLine(argc, argv);
CefSettings settings;
CefRefPtr<CefApp> app;
// Populate the settings based on command line arguments.
AppGetSettings(settings, app);
// Initialize CEF.
CefInitialize(main_args, settings, app);
// Register the scheme handler.
InitSchemeTest();
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
g_signal_connect(window, "focus", G_CALLBACK(&HandleFocus), NULL);
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
GtkWidget* menu_bar = CreateMenuBar();
gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, FALSE, 0);
GtkWidget* toolbar = gtk_toolbar_new();
// Turn off the labels on the toolbar buttons.
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
GtkToolItem* back = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK);
g_signal_connect(back, "clicked",
G_CALLBACK(BackButtonClicked), NULL);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), back, -1 /* append */);
GtkToolItem* forward = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD);
g_signal_connect(forward, "clicked",
G_CALLBACK(ForwardButtonClicked), NULL);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), forward, -1 /* append */);
GtkToolItem* reload = gtk_tool_button_new_from_stock(GTK_STOCK_REFRESH);
g_signal_connect(reload, "clicked",
G_CALLBACK(ReloadButtonClicked), NULL);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), reload, -1 /* append */);
GtkToolItem* stop = gtk_tool_button_new_from_stock(GTK_STOCK_STOP);
g_signal_connect(stop, "clicked",
G_CALLBACK(StopButtonClicked), NULL);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), stop, -1 /* append */);
GtkWidget* m_editWnd = gtk_entry_new();
g_signal_connect(G_OBJECT(m_editWnd), "activate",
G_CALLBACK(URLEntryActivate), NULL);
GtkToolItem* tool_item = gtk_tool_item_new();
gtk_container_add(GTK_CONTAINER(tool_item), m_editWnd);
gtk_tool_item_set_expand(tool_item, TRUE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1); // append
gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_widget_destroyed), &window);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(destroy), NULL);
// Create the handler.
g_handler = new ClientHandler();
g_handler->SetMainHwnd(vbox);
g_handler->SetEditHwnd(m_editWnd);
g_handler->SetButtonHwnds(GTK_WIDGET(back), GTK_WIDGET(forward),
GTK_WIDGET(reload), GTK_WIDGET(stop));
// Create the browser view.
CefWindowInfo window_info;
CefBrowserSettings browserSettings;
// Populate the settings based on command line arguments.
AppGetBrowserSettings(browserSettings);
window_info.SetAsChild(vbox);
CefBrowserHost::CreateBrowserSync(
window_info,
static_cast<CefRefPtr<CefClient> >(g_handler),
"http://www.google.com", browserSettings);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show_all(GTK_WIDGET(window));
// Install an signal handler so we clean up after ourselves.
signal(SIGINT, TerminationSignalHandler);
signal(SIGTERM, TerminationSignalHandler);
CefRunMessageLoop();
CefShutdown();
return 0;
}
// Global functions
std::string AppGetWorkingDirectory() {
return szWorkingDir;
}

View File

@@ -0,0 +1,12 @@
// Copyright (c) 2012 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_app.h"
int main(int argc, char* argv[]) {
CefMainArgs main_args(argc, argv);
// Execute the secondary process.
return CefExecuteProcess(main_args, NULL);
}

View File

@@ -0,0 +1,507 @@
// Copyright (c) 2010 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
#include <sstream>
#include "cefclient/cefclient.h"
#include "include/cef_app.h"
#import "include/cef_application_mac.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "cefclient/client_handler.h"
#include "cefclient/resource_util.h"
#include "cefclient/scheme_test.h"
#include "cefclient/string_util.h"
// The global ClientHandler reference.
extern CefRefPtr<ClientHandler> g_handler;
char szWorkingDir[512]; // The current working directory
// Sizes for URL bar layout
#define BUTTON_HEIGHT 22
#define BUTTON_WIDTH 72
#define BUTTON_MARGIN 8
#define URLBAR_HEIGHT 32
// Content area size for newly created windows.
const int kWindowWidth = 800;
const int kWindowHeight = 600;
// Memory AutoRelease pool.
static NSAutoreleasePool* g_autopool = nil;
// Provide the CefAppProtocol implementation required by CEF.
@interface ClientApplication : NSApplication<CefAppProtocol> {
@private
BOOL handlingSendEvent_;
}
@end
@implementation ClientApplication
- (BOOL)isHandlingSendEvent {
return handlingSendEvent_;
}
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
handlingSendEvent_ = handlingSendEvent;
}
- (void)sendEvent:(NSEvent*)event {
CefScopedSendingEvent sendingEventScoper;
[super sendEvent:event];
}
@end
// Common base class for CEF browser windows. Contains methods relating to hole
// punching required in order to display OpenGL underlay windows.
@interface ClientWindow : NSWindow {
@private
int underlaySurfaceCount_;
}
// Informs the window that an underlay surface has been added/removed. The
// window is non-opaque while underlay surfaces are present.
- (void)underlaySurfaceAdded;
- (void)underlaySurfaceRemoved;
@end
@implementation ClientWindow
- (void)underlaySurfaceAdded {
ASSERT(underlaySurfaceCount_ >= 0);
++underlaySurfaceCount_;
// We're having the OpenGL surface render under the window, so the window
// needs to be not opaque.
if (underlaySurfaceCount_ == 1)
[self setOpaque:NO];
}
- (void)underlaySurfaceRemoved {
--underlaySurfaceCount_;
ASSERT(underlaySurfaceCount_ >= 0);
if (underlaySurfaceCount_ == 0)
[self setOpaque:YES];
}
@end
// Receives notifications from controls and the browser window. Will delete
// itself when done.
@interface ClientWindowDelegate : NSObject <NSWindowDelegate>
- (IBAction)goBack:(id)sender;
- (IBAction)goForward:(id)sender;
- (IBAction)reload:(id)sender;
- (IBAction)stopLoading:(id)sender;
- (IBAction)takeURLStringValueFrom:(NSTextField *)sender;
- (void)alert:(NSString*)title withMessage:(NSString*)message;
- (void)notifyConsoleMessage:(id)object;
- (void)notifyDownloadComplete:(id)object;
- (void)notifyDownloadError:(id)object;
@end
@implementation ClientWindowDelegate
- (IBAction)goBack:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
g_handler->GetBrowser()->GoBack();
}
- (IBAction)goForward:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
g_handler->GetBrowser()->GoForward();
}
- (IBAction)reload:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
g_handler->GetBrowser()->Reload();
}
- (IBAction)stopLoading:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
g_handler->GetBrowser()->StopLoad();
}
- (IBAction)takeURLStringValueFrom:(NSTextField *)sender {
if (!g_handler.get() || !g_handler->GetBrowserId())
return;
NSString *url = [sender stringValue];
// if it doesn't already have a prefix, add http. If we can't parse it,
// just don't bother rather than making things worse.
NSURL* tempUrl = [NSURL URLWithString:url];
if (tempUrl && ![tempUrl scheme])
url = [@"http://" stringByAppendingString:url];
std::string urlStr = [url UTF8String];
g_handler->GetBrowser()->GetMainFrame()->LoadURL(urlStr);
}
- (void)alert:(NSString*)title withMessage:(NSString*)message {
NSAlert *alert = [NSAlert alertWithMessageText:title
defaultButton:@"OK"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:message];
[alert runModal];
}
- (void)notifyConsoleMessage:(id)object {
std::stringstream ss;
ss << "Console messages will be written to " << g_handler->GetLogFile();
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
[self alert:@"Console Messages" withMessage:str];
}
- (void)notifyDownloadComplete:(id)object {
std::stringstream ss;
ss << "File \"" << g_handler->GetLastDownloadFile() <<
"\" downloaded successfully.";
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
[self alert:@"File Download" withMessage:str];
}
- (void)notifyDownloadError:(id)object {
std::stringstream ss;
ss << "File \"" << g_handler->GetLastDownloadFile() <<
"\" failed to download.";
NSString* str = [NSString stringWithUTF8String:(ss.str().c_str())];
[self alert:@"File Download" withMessage:str];
}
- (void)windowDidBecomeKey:(NSNotification*)notification {
if (g_handler.get() && g_handler->GetBrowserId()) {
// Give focus to the browser window.
g_handler->GetBrowser()->GetHost()->SetFocus(true);
}
}
// Called when the window is about to close. Perform the self-destruction
// sequence by getting rid of the window. By returning YES, we allow the window
// to be removed from the screen.
- (BOOL)windowShouldClose:(id)window {
// Try to make the window go away.
[window autorelease];
// Clean ourselves up after clearing the stack of anything that might have the
// window on it.
[self performSelectorOnMainThread:@selector(cleanup:)
withObject:window
waitUntilDone:NO];
return YES;
}
// Deletes itself.
- (void)cleanup:(id)window {
[self release];
}
@end
NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
NSButton* button = [[[NSButton alloc] initWithFrame:*rect] autorelease];
[button setTitle:title];
[button setBezelStyle:NSSmallSquareBezelStyle];
[button setAutoresizingMask:(NSViewMaxXMargin | NSViewMinYMargin)];
[parent addSubview:button];
rect->origin.x += BUTTON_WIDTH;
return button;
}
// Receives notifications from the application. Will delete itself when done.
@interface ClientAppDelegate : NSObject
- (void)createApp:(id)object;
- (IBAction)testGetSource:(id)sender;
- (IBAction)testGetText:(id)sender;
- (IBAction)testRequest:(id)sender;
- (IBAction)testLocalStorage:(id)sender;
- (IBAction)testXMLHttpRequest:(id)sender;
- (IBAction)testSchemeHandler:(id)sender;
- (IBAction)testPopupWindow:(id)sender;
- (IBAction)testAccelerated2DCanvas:(id)sender;
- (IBAction)testAcceleratedLayers:(id)sender;
- (IBAction)testWebGL:(id)sender;
- (IBAction)testHTML5Video:(id)sender;
- (IBAction)testDragDrop:(id)sender;
@end
@implementation ClientAppDelegate
// Create the application on the UI thread.
- (void)createApp:(id)object {
[NSApplication sharedApplication];
[NSBundle loadNibNamed:@"MainMenu" owner:NSApp];
// Set the delegate for application events.
[NSApp setDelegate:self];
// Add the Tests menu.
NSMenu* menubar = [NSApp mainMenu];
NSMenuItem *testItem = [[[NSMenuItem alloc] initWithTitle:@"Tests"
action:nil
keyEquivalent:@""] autorelease];
NSMenu *testMenu = [[[NSMenu alloc] initWithTitle:@"Tests"] autorelease];
[testMenu addItemWithTitle:@"Get Source"
action:@selector(testGetSource:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"Get Text"
action:@selector(testGetText:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"Popup Window"
action:@selector(testPopupWindow:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"Request"
action:@selector(testRequest:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"Scheme Handler"
action:@selector(testSchemeHandler:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"Local Storage"
action:@selector(testLocalStorage:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"XMLHttpRequest"
action:@selector(testXMLHttpRequest:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"Accelerated 2D Canvas"
action:@selector(testAccelerated2DCanvas:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"Accelerated Layers"
action:@selector(testAcceleratedLayers:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"WebGL"
action:@selector(testWebGL:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"HTML5 Video"
action:@selector(testHTML5Video:)
keyEquivalent:@""];
[testMenu addItemWithTitle:@"Drag & Drop"
action:@selector(testDragDrop:)
keyEquivalent:@""];
[testItem setSubmenu:testMenu];
[menubar addItem:testItem];
// Create the delegate for control and browser window events.
ClientWindowDelegate* delegate = [[ClientWindowDelegate alloc] init];
// Create the main application window.
NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
NSRect window_rect = { {0, screen_rect.size.height - kWindowHeight},
{kWindowWidth, kWindowHeight} };
NSWindow* mainWnd = [[ClientWindow alloc]
initWithContentRect:window_rect
styleMask:(NSTitledWindowMask |
NSClosableWindowMask |
NSMiniaturizableWindowMask |
NSResizableWindowMask )
backing:NSBackingStoreBuffered
defer:NO];
[mainWnd setTitle:@"cefclient"];
[mainWnd setDelegate:delegate];
// Rely on the window delegate to clean us up rather than immediately
// releasing when the window gets closed. We use the delegate to do
// everything from the autorelease pool so the window isn't on the stack
// during cleanup (ie, a window close from javascript).
[mainWnd setReleasedWhenClosed:NO];
NSView* contentView = [mainWnd contentView];
// Create the buttons.
NSRect button_rect = [contentView bounds];
button_rect.origin.y = window_rect.size.height - URLBAR_HEIGHT +
(URLBAR_HEIGHT - BUTTON_HEIGHT) / 2;
button_rect.size.height = BUTTON_HEIGHT;
button_rect.origin.x += BUTTON_MARGIN;
button_rect.size.width = BUTTON_WIDTH;
NSButton* button = MakeButton(&button_rect, @"Back", contentView);
[button setTarget:delegate];
[button setAction:@selector(goBack:)];
button = MakeButton(&button_rect, @"Forward", contentView);
[button setTarget:delegate];
[button setAction:@selector(goForward:)];
button = MakeButton(&button_rect, @"Reload", contentView);
[button setTarget:delegate];
[button setAction:@selector(reload:)];
button = MakeButton(&button_rect, @"Stop", contentView);
[button setTarget:delegate];
[button setAction:@selector(stopLoading:)];
// Create the URL text field.
button_rect.origin.x += BUTTON_MARGIN;
button_rect.size.width = [contentView bounds].size.width -
button_rect.origin.x - BUTTON_MARGIN;
NSTextField* editWnd = [[NSTextField alloc] initWithFrame:button_rect];
[contentView addSubview:editWnd];
[editWnd setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)];
[editWnd setTarget:delegate];
[editWnd setAction:@selector(takeURLStringValueFrom:)];
[[editWnd cell] setWraps:NO];
[[editWnd cell] setScrollable:YES];
// Create the handler.
g_handler = new ClientHandler();
g_handler->SetMainHwnd(contentView);
g_handler->SetEditHwnd(editWnd);
// Create the browser view.
CefWindowInfo window_info;
CefBrowserSettings settings;
// Populate the settings based on command line arguments.
AppGetBrowserSettings(settings);
window_info.SetAsChild(contentView, 0, 0, kWindowWidth, kWindowHeight);
CefBrowserHost::CreateBrowser(window_info, g_handler.get(),
"http://www.google.com", settings);
// Show the window.
[mainWnd makeKeyAndOrderFront: nil];
// Size the window.
NSRect r = [mainWnd contentRectForFrameRect:[mainWnd frame]];
r.size.width = kWindowWidth;
r.size.height = kWindowHeight + URLBAR_HEIGHT;
[mainWnd setFrame:[mainWnd frameRectForContentRect:r] display:YES];
}
- (IBAction)testGetSource:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunGetSourceTest(g_handler->GetBrowser());
}
- (IBAction)testGetText:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunGetTextTest(g_handler->GetBrowser());
}
- (IBAction)testRequest:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunRequestTest(g_handler->GetBrowser());
}
- (IBAction)testLocalStorage:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunLocalStorageTest(g_handler->GetBrowser());
}
- (IBAction)testXMLHttpRequest:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunXMLHTTPRequestTest(g_handler->GetBrowser());
}
- (IBAction)testSchemeHandler:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunSchemeTest(g_handler->GetBrowser());
}
- (IBAction)testPopupWindow:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunPopupTest(g_handler->GetBrowser());
}
- (IBAction)testAccelerated2DCanvas:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunAccelerated2DCanvasTest(g_handler->GetBrowser());
}
- (IBAction)testAcceleratedLayers:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunAcceleratedLayersTest(g_handler->GetBrowser());
}
- (IBAction)testWebGL:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunWebGLTest(g_handler->GetBrowser());
}
- (IBAction)testHTML5Video:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunHTML5VideoTest(g_handler->GetBrowser());
}
- (IBAction)testDragDrop:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId())
RunDragDropTest(g_handler->GetBrowser());
}
// Sent by the default notification center immediately before the application
// terminates.
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Shut down CEF.
g_handler = NULL;
CefShutdown();
[self release];
// Release the AutoRelease pool.
[g_autopool release];
}
@end
int main(int argc, char* argv[]) {
CefMainArgs main_args(argc, argv);
// Execute the secondary process, if any.
int exit_code = CefExecuteProcess(main_args, NULL);
if (exit_code >= 0)
return exit_code;
// Retrieve the current working directory.
getcwd(szWorkingDir, sizeof(szWorkingDir));
// Initialize the AutoRelease pool.
g_autopool = [[NSAutoreleasePool alloc] init];
// Initialize the ClientApplication instance.
[ClientApplication sharedApplication];
// Parse command line arguments.
AppInitCommandLine(argc, argv);
CefSettings settings;
CefRefPtr<CefApp> app;
// Populate the settings based on command line arguments.
AppGetSettings(settings, app);
// Initialize CEF.
CefInitialize(main_args, settings, app);
// Initialize tests.
InitSchemeTest();
// Create the application delegate and window.
NSObject* delegate = [[ClientAppDelegate alloc] init];
[delegate performSelectorOnMainThread:@selector(createApp:) withObject:nil
waitUntilDone:NO];
// Run the application message loop.
CefRunMessageLoop();
// Don't put anything below this line because it won't be executed.
return 0;
}
// Global functions
std::string AppGetWorkingDirectory() {
return szWorkingDir;
}

View File

@@ -0,0 +1,87 @@
// 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.
// This file is shared by cefclient and cef_unittests so don't include using
// a qualified path.
#include "cefclient_switches.h" // NOLINT(build/include)
namespace cefclient {
// CefSettings attributes.
const char kMultiThreadedMessageLoop[] = "multi-threaded-message-loop";
const char kCachePath[] = "cache-path";
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 kAcceleratedCompositingDisabled[] =
"accelerated-compositing-disabled";
const char kAcceleratedLayersDisabled[] = "accelerated-layers-disabled";
const char kAcceleratedVideoDisabled[] = "accelerated-video-disabled";
const char kAcceledated2dCanvasDisabled[] = "accelerated-2d-canvas-disabled";
const char kAcceleratedPaintingEnabled[] = "accelerated-painting-enabled";
const char kAcceleratedFiltersEnabled[] = "accelerated-filters-enabled";
const char kAcceleratedPluginsDisabled[] = "accelerated-plugins-disabled";
const char kDeveloperToolsDisabled[] = "developer-tools-disabled";
const char kFullscreenEnabled[] = "fullscreen-enabled";
// 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

View File

@@ -0,0 +1,85 @@
// 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 CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_
#pragma once
namespace cefclient {
// CefSettings attributes.
extern const char kMultiThreadedMessageLoop[];
extern const char kCachePath[];
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 kAcceleratedCompositingDisabled[];
extern const char kAcceleratedLayersDisabled[];
extern const char kAcceleratedVideoDisabled[];
extern const char kAcceledated2dCanvasDisabled[];
extern const char kAcceleratedPaintingEnabled[];
extern const char kAcceleratedFiltersEnabled[];
extern const char kAcceleratedPluginsDisabled[];
extern const char kDeveloperToolsDisabled[];
extern const char kFullscreenEnabled[];
// 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 // CEF_TESTS_CEFCLIENT_CEFCLIENT_SWITCHES_H_

View File

@@ -0,0 +1,504 @@
// 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 "cefclient/cefclient.h"
#include <windows.h>
#include <commdlg.h>
#include <shellapi.h>
#include <direct.h>
#include <sstream>
#include <string>
#include "include/cef_app.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "cefclient/client_handler.h"
#include "cefclient/resource.h"
#include "cefclient/scheme_test.h"
#include "cefclient/string_util.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
// 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='*'\"") // NOLINT(whitespace/line_length)
#endif
// Program entry point function.
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow) {
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
CefMainArgs main_args(hInstance);
// Execute the secondary process, if any.
int exit_code = CefExecuteProcess(main_args, NULL);
if (exit_code >= 0)
return exit_code;
// 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(main_args, settings, app);
// 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));
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)) {
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
result = static_cast<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+1] = {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 {
// 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
CefBrowserHost::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 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_POPUP: // Test a popup window
if (browser.get())
RunPopupTest(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_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_XMLHTTPREQUEST: // Test XMLHttpRequest
if (browser.get())
RunXMLHTTPRequestTest(browser);
return 0;
case ID_TESTS_DRAGDROP: // Test drag & drop
if (browser.get())
RunDragDropTest(browser);
return 0;
case ID_TESTS_GEOLOCATION: // Test geolocation
if (browser.get())
RunGeolocationTest(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->GetBrowser()) {
// Pass focus to the browser window
CefWindowHandle hwnd =
g_handler->GetBrowser()->GetHost()->GetWindowHandle();
if (hwnd)
PostMessage(hwnd, WM_SETFOCUS, wParam, NULL);
}
return 0;
case WM_SIZE:
if (g_handler.get() && g_handler->GetBrowser()) {
CefWindowHandle hwnd =
g_handler->GetBrowser()->GetHost()->GetWindowHandle();
if (hwnd) {
// 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, hwnd, 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->GetBrowser()) {
CefWindowHandle hwnd =
g_handler->GetBrowser()->GetHost()->GetWindowHandle();
if (hwnd) {
// 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->GetHost()->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;
}

View File

@@ -0,0 +1,199 @@
// 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/client_handler.h"
#include <stdio.h>
#include <sstream>
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "cefclient/cefclient.h"
#include "cefclient/string_util.h"
ClientHandler::ClientHandler()
: m_MainHwnd(NULL),
m_BrowserId(0),
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_BrowserId = browser->GetIdentifier();
}
}
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
REQUIRE_UI_THREAD();
if (m_BrowserId == browser->GetIdentifier()) {
// 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_BrowserId == browser->GetIdentifier()) {
// 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_BrowserId == browser->GetIdentifier() && 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_BrowserId == browser->GetIdentifier() && frame->IsMain()) {
// We've just finished loading a page
SetLoading(false);
}
}
void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const CefString& errorText,
const CefString& failedUrl) {
REQUIRE_UI_THREAD();
}
void ClientHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
bool isLoading,
bool canGoBack,
bool canGoForward) {
REQUIRE_UI_THREAD();
SetLoading(isLoading);
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::OnRequestGeolocationPermission(
CefRefPtr<CefBrowser> browser,
const CefString& requesting_url,
int request_id,
CefRefPtr<CefGeolocationCallback> callback) {
// Allow geolocation access from all websites.
callback->Continue(true);
}
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::ShowDevTools() {
}
void ClientHandler::CloseDevTools() {
}

View File

@@ -0,0 +1,165 @@
// 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 CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
#define CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
#pragma once
#include <map>
#include <string>
#include "include/cef_client.h"
#include "cefclient/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 CefGeolocationHandler {
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<CefGeolocationHandler> GetGeolocationHandler() 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;
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE;
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const CefString& errorText,
const CefString& failedUrl) OVERRIDE;
// CefRequestHandler methods
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) OVERRIDE;
// CefDisplayHandler methods
virtual void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
bool isLoading,
bool canGoBack,
bool canGoForward) OVERRIDE;
virtual void OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) OVERRIDE;
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) OVERRIDE;
virtual bool OnConsoleMessage(CefRefPtr<CefBrowser> browser,
const CefString& message,
const CefString& source,
int line) OVERRIDE;
// CefGeolocationHandler methods
virtual void OnRequestGeolocationPermission(
CefRefPtr<CefBrowser> browser,
const CefString& requesting_url,
int request_id,
CefRefPtr<CefGeolocationCallback> callback) OVERRIDE;
void SetMainHwnd(CefWindowHandle hwnd);
CefWindowHandle GetMainHwnd() { return m_MainHwnd; }
void SetEditHwnd(CefWindowHandle hwnd);
void SetButtonHwnds(CefWindowHandle backHwnd,
CefWindowHandle forwardHwnd,
CefWindowHandle reloadHwnd,
CefWindowHandle stopHwnd);
CefRefPtr<CefBrowser> GetBrowser() { return m_Browser; }
int GetBrowserId() { return m_BrowserId; }
std::string GetLogFile();
void SetLastDownloadFile(const std::string& fileName);
std::string GetLastDownloadFile();
// Send a notification to the application. Notifications should not block the
// caller.
enum NotificationType {
NOTIFY_CONSOLE_MESSAGE,
NOTIFY_DOWNLOAD_COMPLETE,
NOTIFY_DOWNLOAD_ERROR,
};
void SendNotification(NotificationType type);
void CloseMainWindow();
void ShowDevTools();
void CloseDevTools();
protected:
void SetLoading(bool isLoading);
void SetNavState(bool canGoBack, bool canGoForward);
// The child browser window
CefRefPtr<CefBrowser> m_Browser;
// The main frame window handle
CefWindowHandle m_MainHwnd;
// The child browser id
int m_BrowserId;
// The edit window handle
CefWindowHandle m_EditHwnd;
// The button window handles
CefWindowHandle m_BackHwnd;
CefWindowHandle m_ForwardHwnd;
CefWindowHandle m_StopHwnd;
CefWindowHandle m_ReloadHwnd;
// Support for logging.
std::string m_LogFile;
// Support for downloading files.
std::string m_LastDownloadFile;
// True if a form element currently has focus
bool m_bFormElementHasFocus;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(ClientHandler);
// Include the default locking implementation.
IMPLEMENT_LOCKING(ClientHandler);
};
#endif // CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_

View File

@@ -0,0 +1,107 @@
// 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 <gtk/gtk.h>
#include <string>
#include "cefclient/client_handler.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_stream_resource_handler.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
// ClientHandler::ClientLifeSpanHandler implementation
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
const CefString& url,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings) {
REQUIRE_UI_THREAD();
return false;
}
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
std::string url = request->GetURL();
if (url == "http://tests/request") {
// Show the request contents
std::string dump;
DumpRequestContents(request, dump);
CefRefPtr<CefStreamReader> stream =
CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(dump.c_str())),
dump.size());
ASSERT(stream.get());
return new CefStreamResourceHandler("text/plain", stream);
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("localstorage.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
} else if (url == "http://tests/xmlhttprequest") {
// Show the xmlhttprequest contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("xmlhttprequest.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
}
return NULL;
}
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) {
REQUIRE_UI_THREAD();
if (m_BrowserId == browser->GetIdentifier() && frame->IsMain()) {
// Set the edit window text
std::string urlStr(url);
gtk_entry_set_text(GTK_ENTRY(m_EditHwnd), urlStr.c_str());
}
}
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) {
REQUIRE_UI_THREAD();
GtkWidget* window = gtk_widget_get_ancestor(
GTK_WIDGET(browser->GetHost()->GetWindowHandle()),
GTK_TYPE_WINDOW);
std::string titleStr(title);
gtk_window_set_title(GTK_WINDOW(window), titleStr.c_str());
}
void ClientHandler::SendNotification(NotificationType type) {
// TODO(port): Implement this method.
}
void ClientHandler::SetLoading(bool isLoading) {
if (isLoading)
gtk_widget_set_sensitive(GTK_WIDGET(m_StopHwnd), true);
else
gtk_widget_set_sensitive(GTK_WIDGET(m_StopHwnd), false);
}
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
if (canGoBack)
gtk_widget_set_sensitive(GTK_WIDGET(m_BackHwnd), true);
else
gtk_widget_set_sensitive(GTK_WIDGET(m_BackHwnd), false);
if (canGoForward)
gtk_widget_set_sensitive(GTK_WIDGET(m_ForwardHwnd), true);
else
gtk_widget_set_sensitive(GTK_WIDGET(m_ForwardHwnd), false);
}
void ClientHandler::CloseMainWindow() {
// TODO(port): Close main window.
}

View File

@@ -0,0 +1,119 @@
// 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.
#import <Cocoa/Cocoa.h>
#include "cefclient/client_handler.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_stream_resource_handler.h"
#include "cefclient/cefclient.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
// ClientHandler::ClientLifeSpanHandler implementation
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
const CefString& url,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings) {
REQUIRE_UI_THREAD();
return false;
}
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
std::string url = request->GetURL();
if (url == "http://tests/request") {
// Show the request contents
std::string dump;
DumpRequestContents(request, dump);
CefRefPtr<CefStreamReader> stream =
CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(dump.c_str())),
dump.size());
ASSERT(stream.get());
return new CefStreamResourceHandler("text/plain", stream);
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("localstorage.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
} else if (url == "http://tests/xmlhttprequest") {
// Show the xmlhttprequest contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader("xmlhttprequest.html");
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
}
return NULL;
}
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) {
REQUIRE_UI_THREAD();
if (m_BrowserId == browser->GetIdentifier() && frame->IsMain()) {
// Set the edit window text
NSTextField* textField = (NSTextField*)m_EditHwnd;
std::string urlStr(url);
NSString* str = [NSString stringWithUTF8String:urlStr.c_str()];
[textField setStringValue:str];
}
}
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) {
REQUIRE_UI_THREAD();
// Set the frame window title bar
NSView* view = (NSView*)browser->GetHost()->GetWindowHandle();
NSWindow* window = [view window];
std::string titleStr(title);
NSString* str = [NSString stringWithUTF8String:titleStr.c_str()];
[window setTitle:str];
}
void ClientHandler::SendNotification(NotificationType type) {
SEL sel = nil;
switch(type) {
case NOTIFY_CONSOLE_MESSAGE:
sel = @selector(notifyConsoleMessage:);
break;
case NOTIFY_DOWNLOAD_COMPLETE:
sel = @selector(notifyDownloadComplete:);
break;
case NOTIFY_DOWNLOAD_ERROR:
sel = @selector(notifyDownloadError:);
break;
}
if (sel == nil)
return;
NSWindow* window = [AppGetMainHwnd() window];
NSObject* delegate = [window delegate];
[delegate performSelectorOnMainThread:sel withObject:nil waitUntilDone:NO];
}
void ClientHandler::SetLoading(bool isLoading) {
// TODO(port): Change button status.
}
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
// TODO(port): Change button status.
}
void ClientHandler::CloseMainWindow() {
// TODO(port): Close window
}

View File

@@ -0,0 +1,115 @@
// 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/client_handler.h"
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_stream_resource_handler.h"
#include "cefclient/resource.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
const CefString& url,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings) {
REQUIRE_UI_THREAD();
return false;
}
CefRefPtr<CefResourceHandler> ClientHandler::GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
std::string url = request->GetURL();
if (url == "http://tests/request") {
// Show the request contents
std::string dump;
DumpRequestContents(request, dump);
CefRefPtr<CefStreamReader> stream =
CefStreamReader::CreateForData(
static_cast<void*>(const_cast<char*>(dump.c_str())),
dump.size());
ASSERT(stream.get());
return new CefStreamResourceHandler("text/plain", stream);
} else if (url == "http://tests/localstorage") {
// Show the localstorage contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader(IDS_LOCALSTORAGE);
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
} else if (url == "http://tests/xmlhttprequest") {
// Show the xmlhttprequest contents
CefRefPtr<CefStreamReader> stream =
GetBinaryResourceReader(IDS_XMLHTTPREQUEST);
ASSERT(stream.get());
return new CefStreamResourceHandler("text/html", stream);
}
return NULL;
}
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) {
REQUIRE_UI_THREAD();
if (m_BrowserId == browser->GetIdentifier() && frame->IsMain()) {
// Set the edit window text
SetWindowText(m_EditHwnd, std::wstring(url).c_str());
}
}
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) {
REQUIRE_UI_THREAD();
// Set the frame window title bar
CefWindowHandle hwnd = browser->GetHost()->GetWindowHandle();
if (m_BrowserId == browser->GetIdentifier()) {
// The frame window will be the parent of the browser window
hwnd = GetParent(hwnd);
}
SetWindowText(hwnd, std::wstring(title).c_str());
}
void ClientHandler::SendNotification(NotificationType type) {
UINT id;
switch (type) {
case NOTIFY_CONSOLE_MESSAGE:
id = ID_WARN_CONSOLEMESSAGE;
break;
case NOTIFY_DOWNLOAD_COMPLETE:
id = ID_WARN_DOWNLOADCOMPLETE;
break;
case NOTIFY_DOWNLOAD_ERROR:
id = ID_WARN_DOWNLOADERROR;
break;
default:
return;
}
PostMessage(m_MainHwnd, WM_COMMAND, id, 0);
}
void ClientHandler::SetLoading(bool isLoading) {
ASSERT(m_EditHwnd != NULL && m_ReloadHwnd != NULL && m_StopHwnd != NULL);
EnableWindow(m_EditHwnd, TRUE);
EnableWindow(m_ReloadHwnd, !isLoading);
EnableWindow(m_StopHwnd, isLoading);
}
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
ASSERT(m_BackHwnd != NULL && m_ForwardHwnd != NULL);
EnableWindow(m_BackHwnd, canGoBack);
EnableWindow(m_ForwardHwnd, canGoForward);
}
void ClientHandler::CloseMainWindow() {
::PostMessage(m_MainHwnd, WM_CLOSE, 0, 0);
}

View File

@@ -0,0 +1,3 @@
/* Localized versions of Info.plist keys */
NSHumanReadableCopyright = "© Chromium Embedded Framework Authors, 2010";

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>cefclient.icns</string>
<key>CFBundleIdentifier</key>
<string>org.cef.cefclient</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

Binary file not shown.

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>org.cef.cefclient.helper</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>LSFileQuarantineEnabled</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.5.0</string>
<key>LSUIElement</key>
<string>1</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
</dict>
</plist>

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,24 @@
<html>
<body>
<script language="JavaScript">
var val = window.localStorage.getItem('val');
function addLine() {
if(val == null)
val = '<br/>One Line.';
else
val += '<br/>Another Line.';
window.localStorage.setItem('val', val);
document.getElementById('out').innerHTML = val;
}
</script>
Click the "Add Line" button to add a line or the "Clear" button to clear.<br/>
This data will persist across sessions if a cache path was specified.<br/>
<input type="button" value="Add Line" onClick="addLine();"/>
<input type="button" value="Clear" onClick="window.localStorage.removeItem('val'); window.location.reload();"/>
<div id="out"></div>
<script language="JavaScript">
if(val != null)
document.getElementById('out').innerHTML = val;
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,19 @@
<html>
<body>
<script language="JavaScript">
function execXMLHttpRequest()
{
xhr = new XMLHttpRequest();
xhr.open("GET",document.getElementById("url").value,false);
xhr.setRequestHeader('My-Custom-Header', 'Some Value');
xhr.send();
document.getElementById('ta').value = "Status Code: "+xhr.status+"\n\n"+xhr.responseText;
}
</script>
<form>
URL: <input type="text" id="url" value="http://tests/request">
<br/><input type="button" onclick="execXMLHttpRequest();" value="Execute XMLHttpRequest">
<br/><textarea rows="10" cols="40" id="ta"></textarea>
</form>
</body>
</html>

View File

@@ -0,0 +1,59 @@
// 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_TESTS_GETSOURCE 32760
#define ID_TESTS_GETTEXT 32761
#define ID_TESTS_POPUP 32762
#define ID_TESTS_REQUEST 32763
#define ID_TESTS_SCHEME_HANDLER 32764
#define ID_TESTS_LOCALSTORAGE 32765
#define ID_TESTS_ACCELERATED2DCANVAS 32766
#define ID_TESTS_ACCELERATEDLAYERS 32767
#define ID_TESTS_WEBGL 32768
#define ID_TESTS_HTML5VIDEO 32769
#define ID_TESTS_XMLHTTPREQUEST 32770
#define ID_TESTS_DRAGDROP 32771
#define ID_TESTS_GEOLOCATION 32772
#define IDC_STATIC -1
#define IDS_LOGO 1000
#define IDS_LOGOBALL 1001
#define IDS_LOCALSTORAGE 1002
#define IDS_XMLHTTPREQUEST 1003
// 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 32774
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif

View File

@@ -0,0 +1,31 @@
// Copyright (c) 2009 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 CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_
#define CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_
#pragma once
#include "include/cef_base.h"
class CefStreamReader;
#if defined(OS_WIN)
#include "cefclient/resource.h"
// Load a resource of type BINARY
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes);
CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId);
#elif defined(OS_MACOSX) || defined(OS_POSIX)
#include <string> // NOLINT(build/include_order)
// Load the resource with the specified name.
bool LoadBinaryResource(const char* resource_name, std::string& resource_data);
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name);
#endif
#endif // CEF_TESTS_CEFCLIENT_RESOURCE_UTIL_H_

View File

@@ -0,0 +1,67 @@
// Copyright (c) 2011 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 The Chromium 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/resource_util.h"
#include <stdio.h>
#include <string>
#include "include/cef_stream.h"
#include "cefclient/util.h"
bool GetResourceDir(std::string& dir) {
char buff[1024];
// Retrieve the executable path.
ssize_t len = readlink("/proc/self/exe", buff, sizeof(buff)-1);
if (len == -1)
return false;
buff[len] = 0;
// Remove the executable name from the path.
char* pos = strrchr(buff, '/');
if (!pos)
return false;
// Add "files" to the path.
strcpy(pos+1, "files"); // NOLINT(runtime/printf)
dir = std::string(buff);
return true;
}
bool LoadBinaryResource(const char* resource_name, std::string& resource_data) {
std::string path;
if (!GetResourceDir(path))
return false;
path.append("/");
path.append(resource_name);
FILE* f = fopen(path.c_str(), "rb");
if (!f)
return false;
size_t bytes_read;
char buff[1024*8];
do {
bytes_read = fread(buff, 1, sizeof(buff)-1, f);
if (bytes_read > 0)
resource_data.append(buff, bytes_read);
} while (bytes_read > 0);
fclose(f);
return true;
}
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name) {
std::string path;
if (!GetResourceDir(path))
return NULL;
path.append("/");
path.append(resource_name);
return CefStreamReader::CreateForFile(path);
}

View File

@@ -0,0 +1,97 @@
// Copyright (c) 2011 The Chromium Embedded Framework Authors.
// Portions copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Foundation/Foundation.h>
#include <mach-o/dyld.h>
#include <stdio.h>
#include "cefclient/resource_util.h"
#include "include/cef_stream.h"
#include "cefclient/util.h"
namespace {
bool AmIBundled() {
// Implementation adapted from Chromium's base/mac/foundation_util.mm
ProcessSerialNumber psn = {0, kCurrentProcess};
FSRef fsref;
OSStatus pbErr;
if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) {
ASSERT(false);
return false;
}
FSCatalogInfo info;
OSErr fsErr;
if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info,
NULL, NULL, NULL)) != noErr) {
ASSERT(false);
return false;
}
return (info.nodeFlags & kFSNodeIsDirectoryMask);
}
bool GetResourceDir(std::string& dir) {
// Implementation adapted from Chromium's base/base_path_mac.mm
if (AmIBundled()) {
// Retrieve the executable directory.
uint32_t pathSize = 0;
_NSGetExecutablePath(NULL, &pathSize);
if (pathSize > 0) {
dir.resize(pathSize);
_NSGetExecutablePath(const_cast<char*>(dir.c_str()), &pathSize);
}
// Trim executable name up to the last separator
std::string::size_type last_separator = dir.find_last_of("/");
dir.resize(last_separator);
dir.append("/../Resources");
return true;
} else {
// TODO: Provide unbundled path
ASSERT(false);
return false;
}
}
bool ReadFileToString(const char* path, std::string& data) {
// Implementation adapted from base/file_util.cc
FILE* file = fopen(path, "rb");
if (!file)
return false;
char buf[1 << 16];
size_t len;
while ((len = fread(buf, 1, sizeof(buf), file)) > 0)
data.append(buf, len);
fclose(file);
return true;
}
} // namespace
bool LoadBinaryResource(const char* resource_name, std::string& resource_data) {
std::string path;
if (!GetResourceDir(path))
return false;
path.append("/");
path.append(resource_name);
return ReadFileToString(path.c_str(), resource_data);
}
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name) {
std::string path;
if (!GetResourceDir(path))
return NULL;
path.append("/");
path.append(resource_name);
return CefStreamReader::CreateForFile(path);
}

View File

@@ -0,0 +1,40 @@
// Copyright (c) 2008-2009 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/resource_util.h"
#include "include/cef_stream.h"
#include "include/wrapper/cef_byte_read_handler.h"
#if defined(OS_WIN)
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes) {
extern HINSTANCE hInst;
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(binaryId),
MAKEINTRESOURCE(256));
if (hRes) {
HGLOBAL hGlob = LoadResource(hInst, hRes);
if (hGlob) {
dwSize = SizeofResource(hInst, hRes);
pBytes = (LPBYTE)LockResource(hGlob);
if (dwSize > 0 && pBytes)
return true;
}
}
return false;
}
CefRefPtr<CefStreamReader> GetBinaryResourceReader(int binaryId) {
DWORD dwSize;
LPBYTE pBytes;
if (LoadBinaryResource(binaryId, dwSize, pBytes)) {
return CefStreamReader::CreateForHandler(
new CefByteReadHandler(pBytes, dwSize, NULL));
}
return NULL;
}
#endif // OS_WIN

View File

@@ -0,0 +1,171 @@
// Copyright (c) 2012 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/scheme_test.h"
#include <algorithm>
#include <string>
#include "include/cef_browser.h"
#include "include/cef_callback.h"
#include "include/cef_frame.h"
#include "include/cef_resource_handler.h"
#include "include/cef_response.h"
#include "include/cef_request.h"
#include "include/cef_scheme.h"
#include "cefclient/resource_util.h"
#include "cefclient/string_util.h"
#include "cefclient/util.h"
#if defined(OS_WIN)
#include "cefclient/resource.h"
#endif
// Implementation of the schema handler for client:// requests.
class ClientSchemeHandler : public CefResourceHandler {
public:
ClientSchemeHandler() : offset_(0) {}
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback)
OVERRIDE {
REQUIRE_IO_THREAD();
bool handled = false;
AutoLock lock_scope(this);
std::string url = request->GetURL();
if (strstr(url.c_str(), "handler.html") != NULL) {
// Build the response html
data_ = "<html><head><title>Client Scheme Handler</title></head><body>"
"This contents of this page page are served by the "
"ClientSchemeHandler class handling the client:// protocol."
"<br/>You should see an image:"
"<br/><img src=\"client://tests/client.png\"><pre>";
// Output a string representation of the request
std::string dump;
DumpRequestContents(request, dump);
data_.append(dump);
data_.append("</pre><br/>Try the test form:"
"<form method=\"POST\" action=\"handler.html\">"
"<input type=\"text\" name=\"field1\">"
"<input type=\"text\" name=\"field2\">"
"<input type=\"submit\">"
"</form></body></html>");
handled = true;
// Set the resulting mime type
mime_type_ = "text/html";
} else if (strstr(url.c_str(), "client.png") != NULL) {
// Load the response image
#if defined(OS_WIN)
DWORD dwSize;
LPBYTE pBytes;
if (LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) {
data_ = std::string(reinterpret_cast<const char*>(pBytes), dwSize);
handled = true;
// Set the resulting mime type
mime_type_ = "image/jpg";
}
#elif defined(OS_MACOSX) || defined(OS_LINUX)
if (LoadBinaryResource("logo.png", data_)) {
handled = true;
// Set the resulting mime type
mime_type_ = "image/png";
}
#else
#error "Unsupported platform"
#endif
}
if (handled) {
// Indicate the headers are available.
callback->Continue();
return true;
}
return false;
}
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& response_length,
CefString& redirectUrl) OVERRIDE {
REQUIRE_IO_THREAD();
ASSERT(!data_.empty());
response->SetMimeType(mime_type_);
response->SetStatus(200);
// Set the resulting response length
response_length = data_.length();
}
virtual void Cancel() OVERRIDE {
REQUIRE_IO_THREAD();
}
virtual bool ReadResponse(void* data_out,
int bytes_to_read,
int& bytes_read,
CefRefPtr<CefCallback> callback)
OVERRIDE {
REQUIRE_IO_THREAD();
bool has_data = false;
bytes_read = 0;
AutoLock lock_scope(this);
if (offset_ < data_.length()) {
// Copy the next block of data into the buffer.
int transfer_size =
std::min(bytes_to_read, static_cast<int>(data_.length() - offset_));
memcpy(data_out, data_.c_str() + offset_, transfer_size);
offset_ += transfer_size;
bytes_read = transfer_size;
has_data = true;
}
return has_data;
}
private:
std::string data_;
std::string mime_type_;
size_t offset_;
IMPLEMENT_REFCOUNTING(ClientSchemeHandler);
IMPLEMENT_LOCKING(ClientSchemeHandler);
};
// Implementation of the factory for for creating schema handlers.
class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
// Return a new scheme handler instance to handle the request.
virtual CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& scheme_name,
CefRefPtr<CefRequest> request)
OVERRIDE {
REQUIRE_IO_THREAD();
return new ClientSchemeHandler();
}
IMPLEMENT_REFCOUNTING(ClientSchemeHandlerFactory);
};
void InitSchemeTest() {
CefRegisterCustomScheme("client", true, false, false);
CefRegisterSchemeHandlerFactory("client", "tests",
new ClientSchemeHandlerFactory());
}
void RunSchemeTest(CefRefPtr<CefBrowser> browser) {
browser->GetMainFrame()->LoadURL("client://tests/handler.html");
}

View File

@@ -0,0 +1,19 @@
// Copyright (c) 2009 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 CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_
#define CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_
#pragma once
#include "include/cef_base.h"
class CefBrowser;
// Register the scheme handler.
void InitSchemeTest();
// Run the test.
void RunSchemeTest(CefRefPtr<CefBrowser> browser);
#endif // CEF_TESTS_CEFCLIENT_SCHEME_TEST_H_

View File

@@ -0,0 +1,74 @@
// 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 "cefclient/string_util.h"
#include <sstream>
#include <string>
#include "include/cef_request.h"
void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str) {
std::stringstream ss;
ss << "URL: " << std::string(request->GetURL());
ss << "\nMethod: " << std::string(request->GetMethod());
CefRequest::HeaderMap headerMap;
request->GetHeaderMap(headerMap);
if (headerMap.size() > 0) {
ss << "\nHeaders:";
CefRequest::HeaderMap::const_iterator it = headerMap.begin();
for (; it != headerMap.end(); ++it) {
ss << "\n\t" << std::string((*it).first) << ": " <<
std::string((*it).second);
}
}
CefRefPtr<CefPostData> postData = request->GetPostData();
if (postData.get()) {
CefPostData::ElementVector elements;
postData->GetElements(elements);
if (elements.size() > 0) {
ss << "\nPost Data:";
CefRefPtr<CefPostDataElement> element;
CefPostData::ElementVector::const_iterator it = elements.begin();
for (; it != elements.end(); ++it) {
element = (*it);
if (element->GetType() == PDE_TYPE_BYTES) {
// the element is composed of bytes
ss << "\n\tBytes: ";
if (element->GetBytesCount() == 0) {
ss << "(empty)";
} else {
// retrieve the data.
size_t size = element->GetBytesCount();
char* bytes = new char[size];
element->GetBytes(size, bytes);
ss << std::string(bytes, size);
delete [] bytes;
}
} else if (element->GetType() == PDE_TYPE_FILE) {
ss << "\n\tFile: " << std::string(element->GetFile());
}
}
}
}
str = ss.str();
}
std::string StringReplace(const std::string& str, const std::string& from,
const std::string& to) {
std::string result = str;
std::string::size_type pos = 0;
std::string::size_type from_len = from.length();
std::string::size_type to_len = to.length();
do {
pos = result.find(from, pos);
if (pos != std::string::npos) {
result.replace(pos, from_len, to);
pos += to_len;
}
} while (pos != std::string::npos);
return result;
}

View File

@@ -0,0 +1,21 @@
// 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.
#ifndef CEF_TESTS_CEFCLIENT_STRING_UTIL_H_
#define CEF_TESTS_CEFCLIENT_STRING_UTIL_H_
#pragma once
#include <string>
#include "include/cef_base.h"
class CefRequest;
// Dump the contents of the request into a string.
void DumpRequestContents(CefRefPtr<CefRequest> request, std::string& str);
// Replace all instances of |from| with |to| in |str|.
std::string StringReplace(const std::string& str, const std::string& from,
const std::string& to);
#endif // CEF_TESTS_CEFCLIENT_STRING_UTIL_H_

37
tests/cefclient/util.h Normal file
View File

@@ -0,0 +1,37 @@
// 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 CEF_TESTS_CEFCLIENT_UTIL_H_
#define CEF_TESTS_CEFCLIENT_UTIL_H_
#pragma once
#include "include/cef_task.h"
#if defined(OS_WIN)
#include <windows.h> // NOLINT(build/include_order)
#ifndef NDEBUG
#define ASSERT(condition) if (!(condition)) { DebugBreak(); }
#else
#define ASSERT(condition) ((void)0)
#endif
#else // !OS_WIN
#include <assert.h> // NOLINT(build/include_order)
#ifndef NDEBUG
#define ASSERT(condition) if (!(condition)) { assert(false); }
#else
#define ASSERT(condition) ((void)0)
#endif
#endif // !OS_WIN
#define REQUIRE_UI_THREAD() ASSERT(CefCurrentlyOn(TID_UI));
#define REQUIRE_IO_THREAD() ASSERT(CefCurrentlyOn(TID_IO));
#define REQUIRE_FILE_THREAD() ASSERT(CefCurrentlyOn(TID_FILE));
#endif // CEF_TESTS_CEFCLIENT_UTIL_H_