mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Expose command line parsing support with a new CefCommandLine class (issue #422).
- cefclient: Add the ability to specify CefSettings and CefBrowserSettings values on the command line. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@378 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "include/cef_runnable.h"
|
||||
#include "include/cef_wrapper.h"
|
||||
#include "cefclient.h"
|
||||
#include "cefclient_switches.h"
|
||||
#include "client_handler.h"
|
||||
#include "binding_test.h"
|
||||
#include "string_util.h"
|
||||
@@ -61,9 +62,20 @@ void UIT_InvokeScript(CefRefPtr<CefBrowser> browser)
|
||||
}
|
||||
}
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CefRefPtr<ClientHandler> g_handler;
|
||||
CefRefPtr<CefCommandLine> g_command_line;
|
||||
|
||||
CefRefPtr<CefBrowser> AppGetBrowser()
|
||||
{
|
||||
@@ -79,6 +91,192 @@ CefWindowHandle AppGetMainHwnd()
|
||||
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)
|
||||
{
|
||||
ASSERT(g_command_line.get());
|
||||
if (!g_command_line.get())
|
||||
return;
|
||||
|
||||
CefString str;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
settings.multi_threaded_message_loop =
|
||||
g_command_line->HasSwitch(cefclient::kMultiThreadedMessageLoop);
|
||||
#endif
|
||||
|
||||
CefString(&settings.cache_path) =
|
||||
g_command_line->GetSwitchValue(cefclient::kCachePath);
|
||||
CefString(&settings.user_agent) =
|
||||
g_command_line->GetSwitchValue(cefclient::kUserAgent);
|
||||
CefString(&settings.product_version) =
|
||||
g_command_line->GetSwitchValue(cefclient::kProductVersion);
|
||||
CefString(&settings.locale) =
|
||||
g_command_line->GetSwitchValue(cefclient::kLocale);
|
||||
CefString(&settings.log_file) =
|
||||
g_command_line->GetSwitchValue(cefclient::kLogFile);
|
||||
|
||||
{
|
||||
std::string str = g_command_line->GetSwitchValue(cefclient::kLogSeverity);
|
||||
bool invalid = false;
|
||||
if (!str.empty()) {
|
||||
if (str == cefclient::kLogSeverity_Verbose)
|
||||
settings.log_severity = LOGSEVERITY_VERBOSE;
|
||||
else if (str == cefclient::kLogSeverity_Info)
|
||||
settings.log_severity = LOGSEVERITY_INFO;
|
||||
else if (str == cefclient::kLogSeverity_Warning)
|
||||
settings.log_severity = LOGSEVERITY_WARNING;
|
||||
else if (str == cefclient::kLogSeverity_Error)
|
||||
settings.log_severity = LOGSEVERITY_ERROR;
|
||||
else if (str == cefclient::kLogSeverity_ErrorReport)
|
||||
settings.log_severity = LOGSEVERITY_ERROR_REPORT;
|
||||
else if (str == cefclient::kLogSeverity_Disable)
|
||||
settings.log_severity = LOGSEVERITY_DISABLE;
|
||||
else
|
||||
invalid = true;
|
||||
}
|
||||
if (str.empty() || invalid) {
|
||||
#ifdef NDEBUG
|
||||
// Only log error messages and higher in release build.
|
||||
settings.log_severity = LOGSEVERITY_ERROR;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::string str = g_command_line->GetSwitchValue(cefclient::kGraphicsImpl);
|
||||
if (!str.empty()) {
|
||||
#if defined(OS_WIN)
|
||||
if (str == cefclient::kGraphicsImpl_Angle)
|
||||
settings.graphics_implementation = ANGLE_IN_PROCESS;
|
||||
else if (str == cefclient::kGraphicsImpl_AngleCmdBuffer)
|
||||
settings.graphics_implementation = ANGLE_IN_PROCESS_COMMAND_BUFFER;
|
||||
else
|
||||
#endif
|
||||
if (str == cefclient::kGraphicsImpl_Desktop)
|
||||
settings.graphics_implementation = DESKTOP_IN_PROCESS;
|
||||
else if (str == cefclient::kGraphicsImpl_DesktopCmdBuffer)
|
||||
settings.graphics_implementation = DESKTOP_IN_PROCESS_COMMAND_BUFFER;
|
||||
}
|
||||
}
|
||||
|
||||
settings.local_storage_quota = GetIntValue(
|
||||
g_command_line->GetSwitchValue(cefclient::kLocalStorageQuota));
|
||||
settings.session_storage_quota = GetIntValue(
|
||||
g_command_line->GetSwitchValue(cefclient::kSessionStorageQuota));
|
||||
|
||||
CefString(&settings.javascript_flags) =
|
||||
g_command_line->GetSwitchValue(cefclient::kJavascriptFlags);
|
||||
}
|
||||
|
||||
// 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.remote_fonts_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kRemoteFontsDisabled);
|
||||
|
||||
CefString(&settings.default_encoding) =
|
||||
g_command_line->GetSwitchValue(cefclient::kDefaultEncoding);
|
||||
|
||||
settings.encoding_detector_enabled =
|
||||
g_command_line->HasSwitch(cefclient::kEncodingDetectorEnabled);
|
||||
settings.javascript_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kJavascriptDisabled);
|
||||
settings.javascript_open_windows_disallowed =
|
||||
g_command_line->HasSwitch(cefclient::kJavascriptOpenWindowsDisallowed);
|
||||
settings.javascript_close_windows_disallowed =
|
||||
g_command_line->HasSwitch(cefclient::kJavascriptCloseWindowsDisallowed);
|
||||
settings.javascript_access_clipboard_disallowed =
|
||||
g_command_line->HasSwitch(
|
||||
cefclient::kJavascriptAccessClipboardDisallowed);
|
||||
settings.dom_paste_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kDomPasteDisabled);
|
||||
settings.caret_browsing_enabled =
|
||||
g_command_line->HasSwitch(cefclient::kCaretBrowsingDisabled);
|
||||
settings.java_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kJavaDisabled);
|
||||
settings.plugins_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kPluginsDisabled);
|
||||
settings.universal_access_from_file_urls_allowed =
|
||||
g_command_line->HasSwitch(cefclient::kUniversalAccessFromFileUrlsAllowed);
|
||||
settings.file_access_from_file_urls_allowed =
|
||||
g_command_line->HasSwitch(cefclient::kFileAccessFromFileUrlsAllowed);
|
||||
settings.web_security_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kWebSecurityDisabled);
|
||||
settings.xss_auditor_enabled =
|
||||
g_command_line->HasSwitch(cefclient::kXssAuditorEnabled);
|
||||
settings.image_load_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kImageLoadingDisabled);
|
||||
settings.shrink_standalone_images_to_fit =
|
||||
g_command_line->HasSwitch(cefclient::kShrinkStandaloneImagesToFit);
|
||||
settings.site_specific_quirks_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kSiteSpecificQuirksDisabled);
|
||||
settings.text_area_resize_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kTextAreaResizeDisabled);
|
||||
settings.page_cache_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kPageCacheDisabled);
|
||||
settings.tab_to_links_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kTabToLinksDisabled);
|
||||
settings.hyperlink_auditing_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kHyperlinkAuditingDisabled);
|
||||
settings.user_style_sheet_enabled =
|
||||
g_command_line->HasSwitch(cefclient::kUserStyleSheetEnabled);
|
||||
|
||||
CefString(&settings.user_style_sheet_location) =
|
||||
g_command_line->GetSwitchValue(cefclient::kUserStyleSheetLocation);
|
||||
|
||||
settings.author_and_user_styles_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kAuthorAndUserStylesDisabled);
|
||||
settings.local_storage_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kLocalStorageDisabled);
|
||||
settings.databases_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kDatabasesDisabled);
|
||||
settings.application_cache_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kApplicationCacheDisabled);
|
||||
settings.webgl_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kWebglDisabled);
|
||||
settings.accelerated_compositing_enabled =
|
||||
g_command_line->HasSwitch(cefclient::kAcceleratedCompositingEnabled);
|
||||
settings.threaded_compositing_enabled =
|
||||
g_command_line->HasSwitch(cefclient::kThreadedCompositingEnabled);
|
||||
settings.accelerated_layers_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kAcceleratedLayersDisabled);
|
||||
settings.accelerated_video_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kAcceleratedVideoDisabled);
|
||||
settings.accelerated_2d_canvas_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kAcceledated2dCanvasDisabled);
|
||||
settings.accelerated_drawing_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kAcceleratedDrawingDisabled);
|
||||
settings.accelerated_plugins_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kAcceleratedPluginsDisabled);
|
||||
settings.developer_tools_disabled =
|
||||
g_command_line->HasSwitch(cefclient::kDeveloperToolsDisabled);
|
||||
}
|
||||
|
||||
static void ExecuteGetSource(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
// Retrieve the current page source and display.
|
||||
|
@@ -16,6 +16,18 @@ 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);
|
||||
|
||||
// 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);
|
||||
|
@@ -323,7 +323,14 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
// Parse command line arguments.
|
||||
AppInitCommandLine(argc, argv);
|
||||
|
||||
CefSettings settings;
|
||||
|
||||
// Populate the settings based on command line arguments.
|
||||
AppGetSettings(settings);
|
||||
|
||||
CefInitialize(settings);
|
||||
|
||||
// Register the V8 extension handler.
|
||||
@@ -393,7 +400,10 @@ int main(int argc, char *argv[]) {
|
||||
// Create the browser view.
|
||||
CefWindowInfo window_info;
|
||||
CefBrowserSettings browserSettings;
|
||||
|
||||
|
||||
// Populate the settings based on command line arguments.
|
||||
AppGetBrowserSettings(browserSettings);
|
||||
|
||||
window_info.SetAsChild(vbox);
|
||||
|
||||
CefBrowser::CreateBrowserSync(window_info,
|
||||
|
@@ -371,6 +371,10 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
// 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);
|
||||
CefBrowser::CreateBrowser(window_info, g_handler.get(),
|
||||
"http://www.google.com", settings);
|
||||
@@ -541,12 +545,15 @@ int main(int argc, char* argv[])
|
||||
|
||||
// Initialize the ClientApplication instance.
|
||||
[ClientApplication sharedApplication];
|
||||
|
||||
// Parse command line arguments.
|
||||
AppInitCommandLine(argc, argv);
|
||||
|
||||
// Initialize CEF.
|
||||
CefSettings settings;
|
||||
|
||||
// Use the Chinese language locale.
|
||||
// CefString(&settings.locale).FromASCII("zh-cn");
|
||||
// Populate the settings based on command line arguments.
|
||||
AppGetSettings(settings);
|
||||
|
||||
CefInitialize(settings);
|
||||
|
||||
|
78
tests/cefclient/cefclient_switches.cpp
Normal file
78
tests/cefclient/cefclient_switches.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "cefclient_switches.h"
|
||||
|
||||
namespace cefclient {
|
||||
|
||||
// CefSettings attributes.
|
||||
const char kMultiThreadedMessageLoop[] = "multi-threaded-message-loop";
|
||||
const char kCachePath[] = "cache-path";
|
||||
const char kUserAgent[] = "user-agent";
|
||||
const char kProductVersion[] = "product-version";
|
||||
const char kLocale[] = "locale";
|
||||
const char kLogFile[] = "log-file";
|
||||
const char kLogSeverity[] = "log-severity";
|
||||
const char kLogSeverity_Verbose[] = "verbose";
|
||||
const char kLogSeverity_Info[] = "info";
|
||||
const char kLogSeverity_Warning[] = "warning";
|
||||
const char kLogSeverity_Error[] = "error";
|
||||
const char kLogSeverity_ErrorReport[] = "error-report";
|
||||
const char kLogSeverity_Disable[] = "disable";
|
||||
const char kGraphicsImpl[] = "graphics-implementation";
|
||||
const char kGraphicsImpl_Angle[] = "angle";
|
||||
const char kGraphicsImpl_AngleCmdBuffer[] = "angle-command-buffer";
|
||||
const char kGraphicsImpl_Desktop[] = "desktop";
|
||||
const char kGraphicsImpl_DesktopCmdBuffer[] = "desktop-command-buffer";
|
||||
const char kLocalStorageQuota[] = "local-storage-quota";
|
||||
const char kSessionStorageQuota[] = "session-storage-quota";
|
||||
const char kJavascriptFlags[] = "javascript-flags";
|
||||
|
||||
// CefBrowserSettings attributes.
|
||||
const char kDragDropDisabled[] = "drag-drop-disabled";
|
||||
const char kLoadDropsDisabled[] = "load-drops-disabled";
|
||||
const char kRemoteFontsDisabled[] = "remote-fonts-disabled";
|
||||
const char kDefaultEncoding[] = "default-encoding";
|
||||
const char kEncodingDetectorEnabled[] = "encoding-detector-enabled";
|
||||
const char kJavascriptDisabled[] = "javascript-disabled";
|
||||
const char kJavascriptOpenWindowsDisallowed[] =
|
||||
"javascript-open-windows-disallowed";
|
||||
const char kJavascriptCloseWindowsDisallowed[] =
|
||||
"javascript-close-windows-disallowed";
|
||||
const char kJavascriptAccessClipboardDisallowed[] =
|
||||
"javascript-access-clipboard-disallowed";
|
||||
const char kDomPasteDisabled[] = "dom-paste-disabled";
|
||||
const char kCaretBrowsingDisabled[] = "caret-browsing-enabled";
|
||||
const char kJavaDisabled[] = "java-disabled";
|
||||
const char kPluginsDisabled[] = "plugins-disabled";
|
||||
const char kUniversalAccessFromFileUrlsAllowed[] =
|
||||
"universal-access-from-file-urls-allowed";
|
||||
const char kFileAccessFromFileUrlsAllowed[] =
|
||||
"file-access-from-file-urls-allowed";
|
||||
const char kWebSecurityDisabled[] = "web-security-disabled";
|
||||
const char kXssAuditorEnabled[] = "xss-auditor-enabled";
|
||||
const char kImageLoadingDisabled[] = "image-load-disabled";
|
||||
const char kShrinkStandaloneImagesToFit[] = "shrink-standalone-images-to-fit";
|
||||
const char kSiteSpecificQuirksDisabled[] = "site-specific-quirks-disabled";
|
||||
const char kTextAreaResizeDisabled[] = "text-area-resize-disabled";
|
||||
const char kPageCacheDisabled[] = "page-cache-disabled";
|
||||
const char kTabToLinksDisabled[] = "tab-to-links-disabled";
|
||||
const char kHyperlinkAuditingDisabled[] = "hyperlink-auditing-disabled";
|
||||
const char kUserStyleSheetEnabled[] = "user-style-sheet-enabled";
|
||||
const char kUserStyleSheetLocation[] = "user-style-sheet-location";
|
||||
const char kAuthorAndUserStylesDisabled[] = "author-and-user-styles-disabled";
|
||||
const char kLocalStorageDisabled[] = "local-storage-disabled";
|
||||
const char kDatabasesDisabled[] = "databases-disabled";
|
||||
const char kApplicationCacheDisabled[] = "application-cache-disabled";
|
||||
const char kWebglDisabled[] = "webgl-disabled";
|
||||
const char kAcceleratedCompositingEnabled[] = "accelerated-compositing-enabled";
|
||||
const char kThreadedCompositingEnabled[] = "threaded-compositing-enabled";
|
||||
const char kAcceleratedLayersDisabled[] = "accelerated-layers-disabled";
|
||||
const char kAcceleratedVideoDisabled[] = "accelerated-video-disabled";
|
||||
const char kAcceledated2dCanvasDisabled[] = "accelerated-2d-canvas-disabled";
|
||||
const char kAcceleratedDrawingDisabled[] = "accelerated-drawing-disabled";
|
||||
const char kAcceleratedPluginsDisabled[] = "accelerated-plugins-disabled";
|
||||
const char kDeveloperToolsDisabled[] = "developer-tools-disabled";
|
||||
|
||||
} // namespace cefclient
|
78
tests/cefclient/cefclient_switches.h
Normal file
78
tests/cefclient/cefclient_switches.h
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
// Defines all of the command line switches used by cefclient.
|
||||
|
||||
#ifndef _CEFCLIENT_SWITCHES_H
|
||||
#define _CEFCLIENT_SWITCHES_H
|
||||
|
||||
namespace cefclient {
|
||||
|
||||
// CefSettings attributes.
|
||||
extern const char kMultiThreadedMessageLoop[];
|
||||
extern const char kCachePath[];
|
||||
extern const char kUserAgent[];
|
||||
extern const char kProductVersion[];
|
||||
extern const char kLocale[];
|
||||
extern const char kLogFile[];
|
||||
extern const char kLogSeverity[];
|
||||
extern const char kLogSeverity_Verbose[];
|
||||
extern const char kLogSeverity_Info[];
|
||||
extern const char kLogSeverity_Warning[];
|
||||
extern const char kLogSeverity_Error[];
|
||||
extern const char kLogSeverity_ErrorReport[];
|
||||
extern const char kLogSeverity_Disable[];
|
||||
extern const char kGraphicsImpl[];
|
||||
extern const char kGraphicsImpl_Angle[];
|
||||
extern const char kGraphicsImpl_AngleCmdBuffer[];
|
||||
extern const char kGraphicsImpl_Desktop[];
|
||||
extern const char kGraphicsImpl_DesktopCmdBuffer[];
|
||||
extern const char kLocalStorageQuota[];
|
||||
extern const char kSessionStorageQuota[];
|
||||
extern const char kJavascriptFlags[];
|
||||
|
||||
// CefBrowserSettings attributes.
|
||||
extern const char kDragDropDisabled[];
|
||||
extern const char kLoadDropsDisabled[];
|
||||
extern const char kRemoteFontsDisabled[];
|
||||
extern const char kDefaultEncoding[];
|
||||
extern const char kEncodingDetectorEnabled[];
|
||||
extern const char kJavascriptDisabled[];
|
||||
extern const char kJavascriptOpenWindowsDisallowed[];
|
||||
extern const char kJavascriptCloseWindowsDisallowed[];
|
||||
extern const char kJavascriptAccessClipboardDisallowed[];
|
||||
extern const char kDomPasteDisabled[];
|
||||
extern const char kCaretBrowsingDisabled[];
|
||||
extern const char kJavaDisabled[];
|
||||
extern const char kPluginsDisabled[];
|
||||
extern const char kUniversalAccessFromFileUrlsAllowed[];
|
||||
extern const char kFileAccessFromFileUrlsAllowed[];
|
||||
extern const char kWebSecurityDisabled[];
|
||||
extern const char kXssAuditorEnabled[];
|
||||
extern const char kImageLoadingDisabled[];
|
||||
extern const char kShrinkStandaloneImagesToFit[];
|
||||
extern const char kSiteSpecificQuirksDisabled[];
|
||||
extern const char kTextAreaResizeDisabled[];
|
||||
extern const char kPageCacheDisabled[];
|
||||
extern const char kTabToLinksDisabled[];
|
||||
extern const char kHyperlinkAuditingDisabled[];
|
||||
extern const char kUserStyleSheetEnabled[];
|
||||
extern const char kUserStyleSheetLocation[];
|
||||
extern const char kAuthorAndUserStylesDisabled[];
|
||||
extern const char kLocalStorageDisabled[];
|
||||
extern const char kDatabasesDisabled[];
|
||||
extern const char kApplicationCacheDisabled[];
|
||||
extern const char kWebglDisabled[];
|
||||
extern const char kAcceleratedCompositingEnabled[];
|
||||
extern const char kThreadedCompositingEnabled[];
|
||||
extern const char kAcceleratedLayersDisabled[];
|
||||
extern const char kAcceleratedVideoDisabled[];
|
||||
extern const char kAcceledated2dCanvasDisabled[];
|
||||
extern const char kAcceleratedDrawingDisabled[];
|
||||
extern const char kAcceleratedPluginsDisabled[];
|
||||
extern const char kDeveloperToolsDisabled[];
|
||||
|
||||
} // namespace cefclient
|
||||
|
||||
#endif // _CEFCLIENT_SWITCHES_H
|
@@ -25,10 +25,6 @@
|
||||
#define BUTTON_WIDTH 72
|
||||
#define URLBAR_HEIGHT 24
|
||||
|
||||
// Define this value to run CEF with messages processed using the current
|
||||
// application's message loop.
|
||||
#define TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||
|
||||
// Global Variables:
|
||||
HINSTANCE hInst; // current instance
|
||||
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
|
||||
@@ -65,28 +61,15 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
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;
|
||||
|
||||
// Specify a cache path value.
|
||||
//CefString(&settings.cache_path).FromASCII("c:\\temp\\cache");
|
||||
|
||||
// Use the Chinese language locale.
|
||||
// CefString(&settings.locale).FromASCII("zh-cn");
|
||||
|
||||
#ifdef NDEBUG
|
||||
// Only log error messages and higher in release build.
|
||||
settings.log_severity = LOGSEVERITY_ERROR;
|
||||
#endif
|
||||
|
||||
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||
// Initialize the CEF with messages processed using the current application's
|
||||
// message loop.
|
||||
settings.multi_threaded_message_loop = false;
|
||||
#else
|
||||
// Initialize the CEF with messages processed using a separate UI thread.
|
||||
settings.multi_threaded_message_loop = true;
|
||||
#endif
|
||||
// Populate the settings based on command line arguments.
|
||||
AppGetSettings(settings);
|
||||
|
||||
// Initialize CEF.
|
||||
CefInitialize(settings);
|
||||
|
||||
// Register the internal client plugin.
|
||||
@@ -124,27 +107,27 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||
|
||||
int result = 0;
|
||||
|
||||
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
|
||||
// Run the CEF message loop. This function will block until the application
|
||||
// recieves a WM_QUIT message.
|
||||
CefRunMessageLoop();
|
||||
#else
|
||||
MSG msg;
|
||||
if (!settings.multi_threaded_message_loop) {
|
||||
// Run the CEF message loop. This function will block until the application
|
||||
// recieves a WM_QUIT message.
|
||||
CefRunMessageLoop();
|
||||
} else {
|
||||
MSG msg;
|
||||
|
||||
// Run the application message loop.
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
// Allow processing of find dialog messages.
|
||||
if (hFindDlg && IsDialogMessage(hFindDlg, &msg))
|
||||
continue;
|
||||
// Run the application message loop.
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
// Allow processing of find dialog messages.
|
||||
if (hFindDlg && IsDialogMessage(hFindDlg, &msg))
|
||||
continue;
|
||||
|
||||
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = (int)msg.wParam;
|
||||
#endif
|
||||
result = (int)msg.wParam;
|
||||
}
|
||||
|
||||
// Shut down CEF.
|
||||
CefShutdown();
|
||||
@@ -373,6 +356,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
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);
|
||||
|
||||
|
115
tests/unittests/command_line_unittest.cc
Normal file
115
tests/unittests/command_line_unittest.cc
Normal 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 "include/cef.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void VerifyCommandLine(CefRefPtr<CefCommandLine> command_line)
|
||||
{
|
||||
std::string program = command_line->GetProgram();
|
||||
EXPECT_EQ("test.exe", program);
|
||||
|
||||
EXPECT_TRUE(command_line->HasSwitches());
|
||||
|
||||
EXPECT_TRUE(command_line->HasSwitch("switch1"));
|
||||
std::string switch1 = command_line->GetSwitchValue("switch1");
|
||||
EXPECT_EQ("", switch1);
|
||||
EXPECT_TRUE(command_line->HasSwitch("switch2"));
|
||||
std::string switch2 = command_line->GetSwitchValue("switch2");
|
||||
EXPECT_EQ("val2", switch2);
|
||||
EXPECT_TRUE(command_line->HasSwitch("switch3"));
|
||||
std::string switch3 = command_line->GetSwitchValue("switch3");
|
||||
EXPECT_EQ("val3", switch3);
|
||||
EXPECT_TRUE(command_line->HasSwitch("switch4"));
|
||||
std::string switch4 = command_line->GetSwitchValue("switch4");
|
||||
EXPECT_EQ("val 4", switch4);
|
||||
EXPECT_FALSE(command_line->HasSwitch("switchnoexist"));
|
||||
|
||||
CefCommandLine::SwitchMap switches;
|
||||
command_line->GetSwitches(switches);
|
||||
EXPECT_EQ((size_t)4, switches.size());
|
||||
|
||||
bool has1 = false, has2 = false, has3 = false, has4 = false;
|
||||
|
||||
CefCommandLine::SwitchMap::const_iterator it = switches.begin();
|
||||
for (; it != switches.end(); ++it) {
|
||||
std::string name = it->first;
|
||||
std::string val = it->second;
|
||||
|
||||
if (name == "switch1") {
|
||||
has1 = true;
|
||||
EXPECT_EQ("", val);
|
||||
} else if (name == "switch2") {
|
||||
has2 = true;
|
||||
EXPECT_EQ("val2", val);
|
||||
} else if (name == "switch3") {
|
||||
has3 = true;
|
||||
EXPECT_EQ("val3", val);
|
||||
} else if (name == "switch4") {
|
||||
has4 = true;
|
||||
EXPECT_EQ("val 4", val);
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(has1);
|
||||
EXPECT_TRUE(has2);
|
||||
EXPECT_TRUE(has3);
|
||||
EXPECT_TRUE(has4);
|
||||
|
||||
EXPECT_TRUE(command_line->HasArguments());
|
||||
|
||||
CefCommandLine::ArgumentList args;
|
||||
command_line->GetArguments(args);
|
||||
EXPECT_EQ((size_t)2, args.size());
|
||||
std::string arg0 = args[0];
|
||||
EXPECT_EQ("arg1", arg0);
|
||||
std::string arg1 = args[1];
|
||||
EXPECT_EQ("arg 2", arg1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test creating a command line from argc/argv or string.
|
||||
TEST(CommandLineTest, Init)
|
||||
{
|
||||
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
||||
EXPECT_TRUE(command_line.get() != NULL);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
command_line->InitFromString("test.exe --switch1 -switch2=val2 /switch3=val3 "
|
||||
"-switch4=\"val 4\" arg1 \"arg 2\"");
|
||||
#else
|
||||
const char* args[] = {
|
||||
"test.exe",
|
||||
"--switch1",
|
||||
"-switch2=val2",
|
||||
"-switch3=val3",
|
||||
"-switch4=\"val 4\"",
|
||||
"arg1",
|
||||
"\"arg 2\""
|
||||
};
|
||||
command_line->InitFromArgv(sizeof(args) / sizeof(char*), args);
|
||||
#endif
|
||||
|
||||
VerifyCommandLine(command_line);
|
||||
}
|
||||
|
||||
// Test creating a command line using set and append methods.
|
||||
TEST(CommandLineTest, Manual)
|
||||
{
|
||||
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
||||
EXPECT_TRUE(command_line.get() != NULL);
|
||||
|
||||
command_line->SetProgram("test.exe");
|
||||
command_line->AppendSwitch("switch1");
|
||||
command_line->AppendSwitchWithValue("switch2", "val2");
|
||||
command_line->AppendSwitchWithValue("switch3", "val3");
|
||||
command_line->AppendSwitchWithValue("switch4", "val 4");
|
||||
command_line->AppendArgument("arg1");
|
||||
command_line->AppendArgument("arg 2");
|
||||
|
||||
VerifyCommandLine(command_line);
|
||||
}
|
Reference in New Issue
Block a user