Add global and per-browser settings (issue #145).

This exposes the following new capabilities:
- Ability to disable drag & drop from other windows.
- Ability to specify additional plugin search paths.
- Ability to customize WebPreferences values, including enabling cross-site scripting.
- Ability to set User-Agent or product version.
- Ability to set default locale.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@144 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2010-11-18 21:05:25 +00:00
parent f1e4219271
commit 1e1c2ad8d7
32 changed files with 978 additions and 246 deletions

View File

@ -483,6 +483,8 @@
'libcef/browser_request_context.h', 'libcef/browser_request_context.h',
'libcef/browser_resource_loader_bridge.cc', 'libcef/browser_resource_loader_bridge.cc',
'libcef/browser_resource_loader_bridge.h', 'libcef/browser_resource_loader_bridge.h',
'libcef/browser_settings.cc',
'libcef/browser_settings.h',
'libcef/browser_socket_stream_bridge.cc', 'libcef/browser_socket_stream_bridge.cc',
'libcef/browser_socket_stream_bridge.h', 'libcef/browser_socket_stream_bridge.h',
'libcef/browser_web_worker.h', 'libcef/browser_web_worker.h',

View File

@ -45,37 +45,33 @@
#include "cef_types.h" #include "cef_types.h"
class CefBrowser; class CefBrowser;
class CefBrowserSettings;
class CefDownloadHandler; class CefDownloadHandler;
class CefFrame; class CefFrame;
class CefHandler; class CefHandler;
class CefPopupFeatures;
class CefPostData; class CefPostData;
class CefPostDataElement; class CefPostDataElement;
class CefRequest; class CefRequest;
class CefSchemeHandler; class CefSchemeHandler;
class CefSchemeHandlerFactory; class CefSchemeHandlerFactory;
class CefSettings;
class CefStreamReader; class CefStreamReader;
class CefStreamWriter; class CefStreamWriter;
class CefTask; class CefTask;
class CefV8Handler; class CefV8Handler;
class CefV8Value; class CefV8Value;
class CefPopupFeatures;
// This function should only be called once when the application is started. // This function should be called once when the application is started to
// Create the thread to host the UI message loop. A return value of true // initialize CEF. A return value of true indicates that it succeeded and
// indicates that it succeeded and false indicates that it failed. Set // false indicates that it failed.
// |multi_threaded_message_loop| to true to have the message loop run in
// a separate thread. If |multi_threaded_message_loop| is false than
// the CefDoMessageLoopWork() function must be called from your message loop.
// Set |cache_path| to the location where cache data will be stored on disk.
// If |cache_path| is empty an in-memory cache will be used for cache data.
/*--cef()--*/ /*--cef()--*/
bool CefInitialize(bool multi_threaded_message_loop, bool CefInitialize(const CefSettings& settings,
const std::wstring& cache_path); const CefBrowserSettings& browser_defaults);
// This function should only be called once before the application exits. // This function should be called once before the application exits to shut down
// Shut down the thread hosting the UI message loop and destroy any created // CEF.
// windows.
/*--cef()--*/ /*--cef()--*/
void CefShutdown(); void CefShutdown();
@ -559,9 +555,10 @@ public:
/*--cef()--*/ /*--cef()--*/
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser, virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& windowInfo, bool popup, CefWindowInfo& windowInfo, bool popup,
const CefPopupFeatures& popupFeatures,
CefRefPtr<CefHandler>& handler, CefRefPtr<CefHandler>& handler,
std::wstring& url, std::wstring& url,
const CefPopupFeatures& popupFeatures) =0; CefBrowserSettings& settings) =0;
// Event called after a new window is created. The return value is currently // Event called after a new window is created. The return value is currently
// ignored. // ignored.
@ -1495,10 +1492,9 @@ public:
{ {
Init(); Init();
} }
~CefPopupFeatures() virtual ~CefPopupFeatures()
{ {
if(additionalFeatures) Reset();
cef_string_list_free(additionalFeatures);
} }
CefPopupFeatures(const CefPopupFeatures& r) CefPopupFeatures(const CefPopupFeatures& r)
@ -1512,6 +1508,55 @@ public:
*this = r; *this = r;
} }
void Reset()
{
if(additionalFeatures)
cef_string_list_free(additionalFeatures);
}
void Attach(const cef_popup_features_t& r)
{
Reset();
*static_cast<cef_popup_features_t*>(this) = r;
}
void Detach()
{
Init();
}
CefPopupFeatures& operator=(const CefPopupFeatures& r)
{
return operator=(static_cast<const cef_popup_features_t&>(r));
}
CefPopupFeatures& operator=(const cef_popup_features_t& r)
{
if(additionalFeatures)
cef_string_list_free(additionalFeatures);
additionalFeatures = r.additionalFeatures ?
cef_string_list_copy(r.additionalFeatures) : NULL;
x = r.x;
xSet = r.xSet;
y = r.y;
ySet = r.ySet;
width = r.width;
widthSet = r.widthSet;
height = r.height;
heightSet = r.heightSet;
menuBarVisible = r.menuBarVisible;
statusBarVisible = r.statusBarVisible;
toolBarVisible = r.toolBarVisible;
locationBarVisible = r.locationBarVisible;
scrollbarsVisible = r.scrollbarsVisible;
resizable = r.resizable;
fullscreen = r.fullscreen;
dialog = r.dialog;
return *this;
}
protected:
void Init() void Init()
{ {
x = 0; x = 0;
@ -1534,47 +1579,255 @@ public:
dialog = false; dialog = false;
additionalFeatures = NULL; additionalFeatures = NULL;
} }
};
CefPopupFeatures& operator=(const CefPopupFeatures& r)
// Class representing initialization settings.
class CefSettings : public cef_settings_t
{ {
return operator=(static_cast<const cef_popup_features_t&>(r)); public:
} CefSettings()
CefPopupFeatures& operator=(const cef_popup_features_t& r)
{ {
if(additionalFeatures) Init();
cef_string_list_free(additionalFeatures);
if(r.additionalFeatures) {
additionalFeatures = cef_string_list_alloc();
unsigned int size = cef_string_list_size(r.additionalFeatures);
for(unsigned int i = 0; i < size; ++i) {
cef_string_t feature = cef_string_list_value(r.additionalFeatures, i);
cef_string_list_append(additionalFeatures, feature);
cef_string_free(feature);
} }
} virtual ~CefSettings()
else { {
additionalFeatures = NULL; Reset();
} }
x = r.x; CefSettings(const CefSettings& r)
xSet = r.xSet; {
y = r.y; Init();
ySet = r.ySet; *this = r;
width = r.width; }
widthSet = r.widthSet; CefSettings(const cef_settings_t& r)
height = r.height; {
heightSet = r.heightSet; Init();
menuBarVisible = r.menuBarVisible; *this = r;
statusBarVisible = r.statusBarVisible; }
toolBarVisible = r.toolBarVisible;
locationBarVisible = r.locationBarVisible; void Reset()
scrollbarsVisible = r.scrollbarsVisible; {
resizable = r.resizable; if(cache_path)
fullscreen = r.fullscreen; cef_string_free(cache_path);
dialog = r.dialog; if(user_agent)
cef_string_free(user_agent);
if(product_version)
cef_string_free(product_version);
if(locale)
cef_string_free(locale);
if(extra_plugin_paths)
cef_string_list_free(extra_plugin_paths);
Init();
}
void Attach(const cef_settings_t& r)
{
Reset();
*static_cast<cef_settings_t*>(this) = r;
}
void Detach()
{
Init();
}
CefSettings& operator=(const CefSettings& r)
{
return operator=(static_cast<const cef_settings_t&>(r));
}
CefSettings& operator=(const cef_settings_t& r)
{
multi_threaded_message_loop = r.multi_threaded_message_loop;
if(cache_path)
cef_string_free(cache_path);
cache_path = r.cache_path ? cef_string_alloc(r.cache_path) : NULL;
if(user_agent)
cef_string_free(user_agent);
user_agent = r.user_agent ? cef_string_alloc(r.user_agent) : NULL;
if(product_version)
cef_string_free(product_version);
product_version = r.product_version ?
cef_string_alloc(r.product_version) : NULL;
if(locale)
cef_string_free(locale);
locale = r.locale ? cef_string_alloc(r.locale) : NULL;
if(extra_plugin_paths)
cef_string_list_free(extra_plugin_paths);
extra_plugin_paths = r.extra_plugin_paths ?
cef_string_list_copy(r.extra_plugin_paths) : NULL;
return *this; return *this;
} }
protected:
void Init()
{
memset(static_cast<cef_settings_t*>(this), 0, sizeof(cef_settings_t));
size = sizeof(cef_settings_t);
}
};
// Class representing browser initialization settings.
class CefBrowserSettings : public cef_browser_settings_t
{
public:
CefBrowserSettings()
{
Init();
}
virtual ~CefBrowserSettings()
{
Reset();
}
CefBrowserSettings(const CefBrowserSettings& r)
{
Init();
*this = r;
}
CefBrowserSettings(const cef_browser_settings_t& r)
{
Init();
*this = r;
}
void Reset()
{
if(standard_font_family)
cef_string_free(standard_font_family);
if(fixed_font_family)
cef_string_free(fixed_font_family);
if(serif_font_family)
cef_string_free(serif_font_family);
if(sans_serif_font_family)
cef_string_free(sans_serif_font_family);
if(cursive_font_family)
cef_string_free(cursive_font_family);
if(fantasy_font_family)
cef_string_free(fantasy_font_family);
if(default_encoding)
cef_string_free(default_encoding);
if(user_style_sheet_location)
cef_string_free(user_style_sheet_location);
Init();
}
void Attach(const cef_browser_settings_t& r)
{
Reset();
*static_cast<cef_browser_settings_t*>(this) = r;
}
void Detach()
{
Init();
}
CefBrowserSettings& operator=(const CefBrowserSettings& r)
{
return operator=(static_cast<const cef_browser_settings_t&>(r));
}
CefBrowserSettings& operator=(const cef_browser_settings_t& r)
{
drag_drop_disabled = r.drag_drop_disabled;
if(standard_font_family)
cef_string_free(standard_font_family);
standard_font_family = r.standard_font_family ?
cef_string_alloc(r.standard_font_family) : NULL;
if(fixed_font_family)
cef_string_free(fixed_font_family);
fixed_font_family = r.fixed_font_family ?
cef_string_alloc(r.fixed_font_family) : NULL;
if(serif_font_family)
cef_string_free(serif_font_family);
serif_font_family = r.serif_font_family ?
cef_string_alloc(r.serif_font_family) : NULL;
if(sans_serif_font_family)
cef_string_free(sans_serif_font_family);
serif_font_family = r.sans_serif_font_family ?
cef_string_alloc(r.sans_serif_font_family) : NULL;
if(cursive_font_family)
cef_string_free(cursive_font_family);
cursive_font_family = r.cursive_font_family ?
cef_string_alloc(r.cursive_font_family) : NULL;
if(fantasy_font_family)
cef_string_free(fantasy_font_family);
fantasy_font_family = r.fantasy_font_family ?
cef_string_alloc(r.fantasy_font_family) : NULL;
default_font_size = r.default_font_size;
default_fixed_font_size = r.default_fixed_font_size;
minimum_font_size = r.minimum_font_size;
minimum_logical_font_size = r.minimum_logical_font_size;
remote_fonts_disabled = r.remote_fonts_disabled;
if(default_encoding)
cef_string_free(default_encoding);
default_encoding = r.default_encoding ?
cef_string_alloc(r.default_encoding) : NULL;
encoding_detector_enabled = r.encoding_detector_enabled;
javascript_disabled = r.javascript_disabled;
javascript_open_windows_disallowed = r.javascript_open_windows_disallowed;
javascript_close_windows_disallowed = r.javascript_close_windows_disallowed;
javascript_access_clipboard_disallowed =
r.javascript_access_clipboard_disallowed;
dom_paste_disabled = r.dom_paste_disabled;
caret_browsing_enabled = r.caret_browsing_enabled;
java_disabled = r.java_disabled;
plugins_disabled = r.plugins_disabled;
universal_access_from_file_urls_allowed =
r.universal_access_from_file_urls_allowed;
file_access_from_file_urls_allowed = r.file_access_from_file_urls_allowed;
web_security_disabled = r.web_security_disabled;
xss_auditor_enabled = r.xss_auditor_enabled;
image_load_disabled = r.image_load_disabled;
shrink_standalone_images_to_fit = r.shrink_standalone_images_to_fit;
site_specific_quirks_disabled = r.site_specific_quirks_disabled;
text_area_resize_disabled = r.text_area_resize_disabled;
page_cache_disabled = r.page_cache_disabled;
tab_to_links_disabled = r.tab_to_links_disabled;
hyperlink_auditing_disabled = r.hyperlink_auditing_disabled;
user_style_sheet_enabled = r.user_style_sheet_enabled;
if(user_style_sheet_location)
cef_string_free(user_style_sheet_location);
user_style_sheet_location = r.user_style_sheet_location ?
cef_string_alloc(r.user_style_sheet_location) : NULL;
author_and_user_styles_disabled = r.author_and_user_styles_disabled;
local_storage_disabled = r.local_storage_disabled;
databases_disabled = r.databases_disabled;
application_cache_disabled = r.application_cache_disabled;
experimental_webgl_enabled = r.experimental_webgl_enabled;
accelerated_compositing_disabled = r.accelerated_compositing_disabled;
accelerated_2d_canvas_disabled = r.accelerated_2d_canvas_disabled;
return *this;
}
protected:
void Init()
{
memset(static_cast<cef_browser_settings_t*>(this), 0,
sizeof(cef_browser_settings_t));
size = sizeof(cef_browser_settings_t);
}
}; };
#endif // _CEF_H #endif // _CEF_H

View File

@ -48,19 +48,14 @@ extern "C" {
#include "cef_types.h" #include "cef_types.h"
// This function should only be called once when the application is started. // This function should be called once when the application is started to
// Create the thread to host the UI message loop. A return value of true (1) // initialize CEF. A return value of true (1) indicates that it succeeded and
// indicates that it succeeded and false (0) indicates that it failed. Set // false (0) indicates that it failed.
// |multi_threaded_message_loop| to true (1) to have the message loop run in a CEF_EXPORT int cef_initialize(const struct _cef_settings_t* settings,
// separate thread. If |multi_threaded_message_loop| is false (0) than the const struct _cef_browser_settings_t* browser_defaults);
// cef_do_message_loop_work() function must be called from your message loop.
// Set |cache_path| to the location where cache data will be stored on disk. If
// |cache_path| is NULL an in-memory cache will be used for cache data.
CEF_EXPORT int cef_initialize(int multi_threaded_message_loop,
const wchar_t* cache_path);
// This function should only be called once before the application exits. Shut // This function should be called once before the application exits to shut down
// down the thread hosting the UI message loop and destroy any created windows. // CEF.
CEF_EXPORT void cef_shutdown(); CEF_EXPORT void cef_shutdown();
// Perform message loop processing. Has no affect if the browser UI loop is // Perform message loop processing. Has no affect if the browser UI loop is
@ -382,8 +377,9 @@ typedef struct _cef_handler_t
enum cef_retval_t (CEF_CALLBACK *handle_before_created)( enum cef_retval_t (CEF_CALLBACK *handle_before_created)(
struct _cef_handler_t* self, struct _cef_browser_t* parentBrowser, struct _cef_handler_t* self, struct _cef_browser_t* parentBrowser,
struct _cef_window_info_t* windowInfo, int popup, struct _cef_window_info_t* windowInfo, int popup,
const struct _cef_popup_features_t* popupFeatures,
struct _cef_handler_t** handler, cef_string_t* url, struct _cef_handler_t** handler, cef_string_t* url,
const struct _cef_popup_features_t* popupFeatures); struct _cef_browser_settings_t* settings);
// Event called after a new window is created. The return value is currently // Event called after a new window is created. The return value is currently
// ignored. // ignored.

View File

@ -55,7 +55,7 @@ public:
pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE); pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&lock_, &attr_); pthread_mutex_init(&lock_, &attr_);
} }
~CefCriticalSection() virtual ~CefCriticalSection()
{ {
pthread_mutex_destroy(&lock_); pthread_mutex_destroy(&lock_);
pthread_mutexattr_destroy(&attr_); pthread_mutexattr_destroy(&attr_);
@ -81,10 +81,9 @@ public:
{ {
Init(); Init();
} }
~CefWindowInfo() virtual ~CefWindowInfo()
{ {
if(m_windowName) Reset();
cef_string_free(m_windowName);
} }
CefWindowInfo(const CefWindowInfo& r) CefWindowInfo(const CefWindowInfo& r)
@ -98,13 +97,22 @@ public:
*this = r; *this = r;
} }
void Init() void Reset()
{ {
m_windowName = NULL; if(m_windowName)
m_x = 0; cef_string_free(m_windowName);
m_y = 0; Init();
m_nWidth = 0; }
m_nHeight = 0;
void Attach(const cef_window_info_t& r)
{
Reset();
*static_cast<cef_window_info_t*>(this) = r;
}
void Detach()
{
Init();
} }
CefWindowInfo& operator=(const CefWindowInfo& r) CefWindowInfo& operator=(const CefWindowInfo& r)
@ -125,6 +133,16 @@ public:
m_nHeight = r.m_nHeight; m_nHeight = r.m_nHeight;
return *this; return *this;
} }
protected:
void Init()
{
m_windowName = NULL;
m_x = 0;
m_y = 0;
m_nWidth = 0;
m_nHeight = 0;
}
}; };
// Class representing print context information. // Class representing print context information.
@ -135,7 +153,7 @@ public:
{ {
Init(); Init();
} }
~CefPrintInfo() virtual ~CefPrintInfo()
{ {
} }

View File

@ -58,7 +58,7 @@ public:
pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE); pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&lock_, &attr_); pthread_mutex_init(&lock_, &attr_);
} }
~CefCriticalSection() virtual ~CefCriticalSection()
{ {
pthread_mutex_destroy(&lock_); pthread_mutex_destroy(&lock_);
pthread_mutexattr_destroy(&attr_); pthread_mutexattr_destroy(&attr_);
@ -84,10 +84,9 @@ public:
{ {
Init(); Init();
} }
~CefWindowInfo() virtual ~CefWindowInfo()
{ {
if(m_windowName) Reset();
cef_string_free(m_windowName);
} }
CefWindowInfo(const CefWindowInfo& r) CefWindowInfo(const CefWindowInfo& r)
@ -101,15 +100,22 @@ public:
*this = r; *this = r;
} }
void Init() void Reset()
{ {
m_View = NULL; if(m_windowName)
m_ParentView = NULL; cef_string_free(m_windowName);
m_windowName = NULL; Init();
m_x = 0; }
m_y = 0;
m_nWidth = 0; void Attach(const cef_window_info_t& r)
m_nHeight = 0; {
Reset();
*static_cast<cef_window_info_t*>(this) = r;
}
void Detach()
{
Init();
} }
void SetAsChild(CefWindowHandle ParentView, int x, int y, int width, void SetAsChild(CefWindowHandle ParentView, int x, int y, int width,
@ -142,6 +148,18 @@ public:
m_nHeight = r.m_nHeight; m_nHeight = r.m_nHeight;
return *this; return *this;
} }
protected:
void Init()
{
m_View = NULL;
m_ParentView = NULL;
m_windowName = NULL;
m_x = 0;
m_y = 0;
m_nWidth = 0;
m_nHeight = 0;
}
}; };
// Class representing print context information. // Class representing print context information.
@ -152,7 +170,7 @@ public:
{ {
Init(); Init();
} }
~CefPrintInfo() virtual ~CefPrintInfo()
{ {
} }

View File

@ -59,6 +59,8 @@ CEF_EXPORT void cef_string_list_clear(cef_string_list_t list);
// Free the string list. // Free the string list.
CEF_EXPORT void cef_string_list_free(cef_string_list_t list); CEF_EXPORT void cef_string_list_free(cef_string_list_t list);
// Creates a copy of an existing string list.
CEF_EXPORT cef_string_list_t cef_string_list_copy(cef_string_list_t list);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -54,6 +54,162 @@ typedef long int64;
typedef long long int64; typedef long long int64;
#endif #endif
// Initialization settings. Specify NULL or 0 to get the recommended default
// values.
typedef struct _cef_settings_t
{
// Size of this structure.
size_t size;
// Set to true (1) to have the message loop run in a separate thread. If
// false (0) than the CefDoMessageLoopWork() function must be called from
// your application message loop.
bool multi_threaded_message_loop;
// The location where cache data will be stored on disk. If empty an
// in-memory cache will be used. HTML5 databases such as localStorage will
// only persist across sessions if a cache path is specified.
cef_string_t cache_path;
// Value that will be returned as the User-Agent HTTP header. If empty the
// default User-Agent string will be used.
cef_string_t user_agent;
// Value that will be inserted as the product portion of the default
// User-Agent string. If empty the Chromium product version will be used. If
// |userAgent| is specified this value will be ignored.
cef_string_t product_version;
// The locale string that will be passed to WebKit. If empty the default
// locale of "en-US" will be used.
cef_string_t locale;
// List of file system paths that will be searched by the browser to locate
// plugins. This is in addition to the default search paths.
cef_string_list_t extra_plugin_paths;
} cef_settings_t;
// Browser initialization settings. Specify NULL or 0 to get the recommended
// default values. The consequences of using custom values may not be well
// tested.
typedef struct _cef_browser_settings_t
{
// Size of this structure.
size_t size;
// Disable drag & drop of URLs from other windows.
bool drag_drop_disabled;
// The below values map to WebPreferences settings.
// Font settings.
cef_string_t standard_font_family;
cef_string_t fixed_font_family;
cef_string_t serif_font_family;
cef_string_t sans_serif_font_family;
cef_string_t cursive_font_family;
cef_string_t fantasy_font_family;
int default_font_size;
int default_fixed_font_size;
int minimum_font_size;
int minimum_logical_font_size;
// Set to true (1) to disable loading of fonts from remote sources.
bool remote_fonts_disabled;
// Default encoding for Web content. If empty "ISO-8859-1" will be used.
cef_string_t default_encoding;
// Set to true (1) to attempt automatic detection of content encoding.
bool encoding_detector_enabled;
// Set to true (1) to disable JavaScript.
bool javascript_disabled;
// Set to true (1) to disallow JavaScript from opening windows.
bool javascript_open_windows_disallowed;
// Set to true (1) to disallow JavaScript from closing windows.
bool javascript_close_windows_disallowed;
// Set to true (1) to disallow JavaScript from accessing the clipboard.
bool javascript_access_clipboard_disallowed;
// Set to true (1) to disable DOM pasting in the editor. DOM pasting also
// depends on |javascript_cannot_access_clipboard| being false (0).
bool dom_paste_disabled;
// Set to true (1) to enable drawing of the caret position.
bool caret_browsing_enabled;
// Set to true (1) to disable Java.
bool java_disabled;
// Set to true (1) to disable plugins.
bool plugins_disabled;
// Set to true (1) to allow access to all URLs from file URLs.
bool universal_access_from_file_urls_allowed;
// Set to true (1) to allow access to file URLs from other file URLs.
bool file_access_from_file_urls_allowed;
// Set to true (1) to allow risky security behavior such as cross-site
// scripting (XSS). Use with extreme care.
bool web_security_disabled;
// Set to true (1) to enable console warnings about XSS attempts.
bool xss_auditor_enabled;
// Set to true (1) to suppress the network load of image URLs. A cached
// image will still be rendered if requested.
bool image_load_disabled;
// Set to true (1) to shrink standalone images to fit the page.
bool shrink_standalone_images_to_fit;
// Set to true (1) to disable browser backwards compatibility features.
bool site_specific_quirks_disabled;
// Set to true (1) to disable resize of text areas.
bool text_area_resize_disabled;
// Set to true (1) to disable use of the page cache.
bool page_cache_disabled;
// Set to true (1) to not have the tab key advance focus to links.
bool tab_to_links_disabled;
// Set to true (1) to disable hyperlink pings (<a ping> and window.sendPing).
bool hyperlink_auditing_disabled;
// Set to true (1) to enable the user style sheet for all pages.
// |user_style_sheet_location| must be set to the style sheet URL.
bool user_style_sheet_enabled;
cef_string_t user_style_sheet_location;
// Set to true (1) to disable style sheets.
bool author_and_user_styles_disabled;
// Set to true (1) to disable local storage.
bool local_storage_disabled;
// Set to true (1) to disable databases.
bool databases_disabled;
// Set to true (1) to disable application cache.
bool application_cache_disabled;
// Set to true (1) to enable experimental WebGL features.
bool experimental_webgl_enabled;
// Set to true (1) to disable accelerated compositing.
bool accelerated_compositing_disabled;
// Set to true (1) to disable accelerated 2d canvas.
bool accelerated_2d_canvas_disabled;
} cef_browser_settings_t;
// Define handler return value types. Returning RV_HANDLED indicates // Define handler return value types. Returning RV_HANDLED indicates
// that the implementation completely handled the method and that no further // that the implementation completely handled the method and that no further
// processing is required. Returning RV_CONTINUE indicates that the // processing is required. Returning RV_CONTINUE indicates that the

View File

@ -48,7 +48,7 @@ public:
memset(&m_sec, 0, sizeof(CRITICAL_SECTION)); memset(&m_sec, 0, sizeof(CRITICAL_SECTION));
InitializeCriticalSection(&m_sec); InitializeCriticalSection(&m_sec);
} }
~CefCriticalSection() virtual ~CefCriticalSection()
{ {
DeleteCriticalSection(&m_sec); DeleteCriticalSection(&m_sec);
} }
@ -72,10 +72,9 @@ public:
{ {
Init(); Init();
} }
~CefWindowInfo() virtual ~CefWindowInfo()
{ {
if(m_windowName) Reset();
cef_string_free(m_windowName);
} }
CefWindowInfo(const CefWindowInfo& r) CefWindowInfo(const CefWindowInfo& r)
@ -89,18 +88,22 @@ public:
*this = r; *this = r;
} }
void Init() void Reset()
{ {
m_dwExStyle = 0; if(m_windowName)
m_windowName = NULL; cef_string_free(m_windowName);
m_dwStyle = 0; Init();
m_x = 0; }
m_y = 0;
m_nWidth = 0; void Attach(const cef_window_info_t& r)
m_nHeight = 0; {
m_hWndParent = NULL; Reset();
m_hMenu = 0; *static_cast<cef_window_info_t*>(this) = r;
m_hWnd = NULL; }
void Detach()
{
Init();
} }
CefWindowInfo& operator=(const CefWindowInfo& r) CefWindowInfo& operator=(const CefWindowInfo& r)
@ -154,6 +157,21 @@ public:
else else
m_windowName = NULL; m_windowName = NULL;
} }
protected:
void Init()
{
m_dwExStyle = 0;
m_windowName = NULL;
m_dwStyle = 0;
m_x = 0;
m_y = 0;
m_nWidth = 0;
m_nHeight = 0;
m_hWndParent = NULL;
m_hMenu = 0;
m_hWnd = NULL;
}
}; };
// Class representing print context information. // Class representing print context information.
@ -164,7 +182,7 @@ public:
{ {
Init(); Init();
} }
~CefPrintInfo() virtual ~CefPrintInfo()
{ {
} }

View File

@ -46,10 +46,11 @@ using webkit_glue::WebStringToStdString;
using webkit_glue::WebStringToStdWString; using webkit_glue::WebStringToStdWString;
CefBrowserImpl::CefBrowserImpl(CefWindowInfo& windowInfo, bool popup, CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
const CefBrowserSettings& settings, bool popup,
CefRefPtr<CefHandler> handler) CefRefPtr<CefHandler> handler)
: window_info_(windowInfo), is_popup_(popup), is_modal_(false), : window_info_(windowInfo), settings_(settings), is_popup_(popup),
handler_(handler), webviewhost_(NULL), popuphost_(NULL), is_modal_(false), handler_(handler), webviewhost_(NULL), popuphost_(NULL),
frame_main_(NULL), unique_id_(0) frame_main_(NULL), unique_id_(0)
{ {
delegate_.reset(new BrowserWebViewDelegate(this)); delegate_.reset(new BrowserWebViewDelegate(this));
@ -486,6 +487,7 @@ std::wstring CefBrowserImpl::GetURL(CefRefPtr<CefFrame> frame)
return std::wstring(); return std::wstring();
} }
// static
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup, bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler> handler, CefRefPtr<CefHandler> handler,
const std::wstring& url) const std::wstring& url)
@ -494,24 +496,26 @@ bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
return false; return false;
std::wstring newUrl = url; std::wstring newUrl = url;
CefBrowserSettings settings(_Context->browser_defaults());
if(handler.get()) if(handler.get())
{ {
// Give the handler an opportunity to modify window attributes, handler, // Give the handler an opportunity to modify window attributes, handler,
// or cancel the window creation. // or cancel the window creation.
CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo, CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo,
popup, handler, newUrl, CefPopupFeatures()); popup, CefPopupFeatures(), handler, newUrl, settings);
if(rv == RV_HANDLED) if(rv == RV_HANDLED)
return false; return false;
} }
CefRefPtr<CefBrowserImpl> browser( CefRefPtr<CefBrowserImpl> browser(
new CefBrowserImpl(windowInfo, popup, handler)); new CefBrowserImpl(windowInfo, settings, popup, handler));
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(browser.get(), CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(browser.get(),
&CefBrowserImpl::UIT_CreateBrowser, newUrl)); &CefBrowserImpl::UIT_CreateBrowser, newUrl));
return true; return true;
} }
// static
CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo, CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
bool popup, CefRefPtr<CefHandler> handler, const std::wstring& url) bool popup, CefRefPtr<CefHandler> handler, const std::wstring& url)
{ {
@ -520,18 +524,20 @@ CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
std::wstring newUrl = url; std::wstring newUrl = url;
CefRefPtr<CefBrowser> alternateBrowser; CefRefPtr<CefBrowser> alternateBrowser;
CefBrowserSettings settings(_Context->browser_defaults());
if(handler.get()) if(handler.get())
{ {
// Give the handler an opportunity to modify window attributes, handler, // Give the handler an opportunity to modify window attributes, handler,
// or cancel the window creation. // or cancel the window creation.
CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo, CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo,
popup, handler, newUrl, CefPopupFeatures()); popup, CefPopupFeatures(), handler, newUrl, settings);
if(rv == RV_HANDLED) if(rv == RV_HANDLED)
return false; return false;
} }
CefRefPtr<CefBrowser> browser(new CefBrowserImpl(windowInfo, popup, handler)); CefRefPtr<CefBrowser> browser(
new CefBrowserImpl(windowInfo, settings, popup, handler));
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser(newUrl); static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser(newUrl);
return browser; return browser;
@ -802,17 +808,21 @@ CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(
CefRefPtr<CefHandler> handler = handler_; CefRefPtr<CefHandler> handler = handler_;
std::wstring newUrl = url; std::wstring newUrl = url;
// Start with the current browser window's settings.
CefBrowserSettings settings(settings_);
if(handler_.get()) if(handler_.get())
{ {
// Give the handler an opportunity to modify window attributes, handler, // Give the handler an opportunity to modify window attributes, handler,
// or cancel the window creation. // or cancel the window creation.
CefHandler::RetVal rv = handler_->HandleBeforeCreated(this, info, true, CefHandler::RetVal rv = handler_->HandleBeforeCreated(this, info, true,
handler, newUrl, features); features, handler, newUrl, settings);
if(rv == RV_HANDLED) if(rv == RV_HANDLED)
return NULL; return NULL;
} }
CefRefPtr<CefBrowserImpl> browser(new CefBrowserImpl(info, true, handler)); CefRefPtr<CefBrowserImpl> browser(
new CefBrowserImpl(info, settings, true, handler));
browser->UIT_CreateBrowser(newUrl); browser->UIT_CreateBrowser(newUrl);
return browser; return browser;

View File

@ -33,7 +33,8 @@ class WebView;
class CefBrowserImpl : public CefThreadSafeBase<CefBrowser> class CefBrowserImpl : public CefThreadSafeBase<CefBrowser>
{ {
public: public:
CefBrowserImpl(CefWindowInfo& windowInfo, bool popup, CefBrowserImpl(const CefWindowInfo& windowInfo,
const CefBrowserSettings& settings, bool popup,
CefRefPtr<CefHandler> handler); CefRefPtr<CefHandler> handler);
virtual ~CefBrowserImpl() {} virtual ~CefBrowserImpl() {}
@ -231,10 +232,12 @@ public:
static bool ImplementsThreadSafeReferenceCounting() { return true; } static bool ImplementsThreadSafeReferenceCounting() { return true; }
const CefBrowserSettings& settings() const { return settings_; }
const FilePath& file_system_root() const { return file_system_root_.path(); } const FilePath& file_system_root() const { return file_system_root_.path(); }
protected: protected:
CefWindowInfo window_info_; CefWindowInfo window_info_;
CefBrowserSettings settings_;
bool is_popup_; bool is_popup_;
bool is_modal_; bool is_modal_;
CefRefPtr<CefHandler> handler_; CefRefPtr<CefHandler> handler_;

View File

@ -5,6 +5,7 @@
#include "cef_context.h" #include "cef_context.h"
#include "browser_impl.h" #include "browser_impl.h"
#include "browser_settings.h"
#include "browser_webview_mac.h" #include "browser_webview_mac.h"
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@ -14,6 +15,7 @@
#include "third_party/WebKit/WebKit/chromium/public/WebRect.h" #include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSize.h" #include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h" #include "third_party/WebKit/WebKit/chromium/public/WebView.h"
#include "webkit/glue/webpreferences.h"
using WebKit::WebRect; using WebKit::WebRect;
using WebKit::WebSize; using WebKit::WebSize;
@ -44,10 +46,13 @@ void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
gfx::Rect contentRect(window_info_.m_x, window_info_.m_y, gfx::Rect contentRect(window_info_.m_x, window_info_.m_y,
window_info_.m_nWidth, window_info_.m_nHeight); window_info_.m_nWidth, window_info_.m_nHeight);
WebPreferences prefs;
BrowserToWebSettings(settings_, prefs);
// Create the webview host object // Create the webview host object
webviewhost_.reset( webviewhost_.reset(
WebViewHost::Create(parentView, contentRect, delegate_.get(), WebViewHost::Create(parentView, contentRect, delegate_.get(),
NULL, *_Context->web_preferences())); NULL, prefs));
delegate_->RegisterDragDrop(); delegate_->RegisterDragDrop();
BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle(); BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle();

View File

@ -5,6 +5,7 @@
#include "cef_context.h" #include "cef_context.h"
#include "browser_impl.h" #include "browser_impl.h"
#include "browser_settings.h"
#include "printing/units.h" #include "printing/units.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
@ -14,6 +15,7 @@
#include "third_party/WebKit/WebKit/chromium/public/WebRect.h" #include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSize.h" #include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h" #include "third_party/WebKit/WebKit/chromium/public/WebView.h"
#include "webkit/glue/webpreferences.h"
#include <shellapi.h> #include <shellapi.h>
#include <shlwapi.h> #include <shlwapi.h>
@ -116,10 +118,15 @@ void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
// Add the new browser to the list maintained by the context // Add the new browser to the list maintained by the context
_Context->AddBrowser(this); _Context->AddBrowser(this);
WebPreferences prefs;
BrowserToWebSettings(settings_, prefs);
// Create the webview host object // Create the webview host object
webviewhost_.reset( webviewhost_.reset(
WebViewHost::Create(window_info_.m_hWnd, gfx::Rect(), delegate_.get(), WebViewHost::Create(window_info_.m_hWnd, gfx::Rect(), delegate_.get(),
NULL, *_Context->web_preferences())); NULL, prefs));
if (!settings_.drag_drop_disabled)
delegate_->RegisterDragDrop(); delegate_->RegisterDragDrop();
// Size the web view window to the browser window // Size the web view window to the browser window

214
libcef/browser_settings.cc Normal file
View File

@ -0,0 +1,214 @@
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
#include "../include/cef.h"
#include "base/utf_string_conversions.h"
#include "webkit/glue/webpreferences.h"
void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web)
{
if (cef.standard_font_family)
web.standard_font_family = cef.standard_font_family;
else
web.standard_font_family = L"Times";
if (cef.fixed_font_family)
web.fixed_font_family = cef.fixed_font_family;
else
web.fixed_font_family = L"Courier";
if (cef.serif_font_family)
web.serif_font_family = cef.serif_font_family;
else
web.serif_font_family = L"Times";
if (cef.sans_serif_font_family)
web.sans_serif_font_family = cef.sans_serif_font_family;
else
web.sans_serif_font_family = L"Helvetica";
// These two fonts below are picked from the intersection of
// Win XP font list and Vista font list :
// http://www.microsoft.com/typography/fonts/winxp.htm
// http://blogs.msdn.com/michkap/archive/2006/04/04/567881.aspx
// Some of them are installed only with CJK and complex script
// support enabled on Windows XP and are out of consideration here.
// (although we enabled both on our buildbots.)
// They (especially Impact for fantasy) are not typical cursive
// and fantasy fonts, but it should not matter for layout tests
// as long as they're available.
if (cef.cursive_font_family) {
web.cursive_font_family = cef.cursive_font_family;
} else {
#if defined(OS_MACOSX)
web.cursive_font_family = L"Apple Chancery";
#else
web.cursive_font_family = L"Comic Sans MS";
#endif
}
if (cef.fantasy_font_family) {
web.fantasy_font_family = cef.fantasy_font_family;
} else {
#if defined(OS_MACOSX)
web.fantasy_font_family = L"Papyrus";
#else
web.fantasy_font_family = L"Impact";
#endif
}
if (cef.default_font_size > 0)
web.default_font_size = cef.default_font_size;
else
web.default_font_size = 16;
if (cef.default_fixed_font_size > 0)
web.default_fixed_font_size = cef.default_fixed_font_size;
else
web.default_fixed_font_size = 13;
if (cef.minimum_font_size > 0)
web.minimum_font_size = cef.minimum_font_size;
else
web.minimum_font_size = 1;
if (cef.minimum_logical_font_size > 0)
web.minimum_logical_font_size = cef.minimum_logical_font_size;
else
web.minimum_logical_font_size = 9;
if (cef.default_encoding)
web.default_encoding = WideToUTF8(cef.default_encoding);
else
web.default_encoding = "ISO-8859-1";
web.javascript_enabled = !cef.javascript_disabled;
web.web_security_enabled = !cef.web_security_disabled;
web.javascript_can_open_windows_automatically =
!cef.javascript_open_windows_disallowed;
web.loads_images_automatically = !cef.image_load_disabled;
web.plugins_enabled = !cef.plugins_disabled;
web.dom_paste_enabled = !cef.dom_paste_disabled;
web.developer_extras_enabled = false;
web.inspector_settings.clear();
web.site_specific_quirks_enabled = !cef.site_specific_quirks_disabled;
web.shrinks_standalone_images_to_fit = cef.shrink_standalone_images_to_fit;
web.uses_universal_detector = cef.encoding_detector_enabled;
web.text_areas_are_resizable = !cef.text_area_resize_disabled;
web.java_enabled = !cef.java_disabled;
web.allow_scripts_to_close_windows = !cef.javascript_close_windows_disallowed;
web.uses_page_cache = !cef.page_cache_disabled;
web.remote_fonts_enabled = !cef.remote_fonts_disabled;
web.javascript_can_access_clipboard =
!cef.javascript_access_clipboard_disallowed;
web.xss_auditor_enabled = cef.xss_auditor_enabled;
web.local_storage_enabled = !cef.local_storage_disabled;
web.databases_enabled = !cef.databases_disabled;
web.application_cache_enabled = !cef.application_cache_disabled;
web.tabs_to_links = !cef.tab_to_links_disabled;
web.caret_browsing_enabled = cef.caret_browsing_enabled;
web.hyperlink_auditing_enabled = !cef.hyperlink_auditing_disabled;
web.user_style_sheet_enabled = cef.user_style_sheet_enabled;
if (cef.user_style_sheet_location) {
web.user_style_sheet_location =
GURL(WideToUTF8(cef.user_style_sheet_location));
}
web.author_and_user_styles_enabled = !cef.author_and_user_styles_disabled;
web.allow_universal_access_from_file_urls =
cef.universal_access_from_file_urls_allowed;
web.allow_file_access_from_file_urls = cef.file_access_from_file_urls_allowed;
web.experimental_webgl_enabled = cef.experimental_webgl_enabled;
web.show_composited_layer_borders = false;
web.accelerated_compositing_enabled = !cef.accelerated_compositing_disabled;
web.accelerated_2d_canvas_enabled = !cef.accelerated_2d_canvas_disabled;
web.memory_info_enabled = false;
}
void WebToBrowserSettings(const WebPreferences& web, CefBrowserSettings& cef)
{
cef.Reset();
if (!web.standard_font_family.empty()) {
cef.standard_font_family =
cef_string_alloc(web.standard_font_family.c_str());
}
if (!web.fixed_font_family.empty()) {
cef.fixed_font_family =
cef_string_alloc(web.fixed_font_family.c_str());
}
if (!web.serif_font_family.empty()) {
cef.serif_font_family =
cef_string_alloc(web.serif_font_family.c_str());
}
if (!web.cursive_font_family.empty()) {
cef.cursive_font_family =
cef_string_alloc(web.cursive_font_family.c_str());
}
if (!web.fantasy_font_family.empty()) {
cef.fantasy_font_family =
cef_string_alloc(web.fantasy_font_family.c_str());
}
cef.default_font_size = web.default_font_size;
cef.default_fixed_font_size = web.default_fixed_font_size;
cef.minimum_font_size = web.minimum_font_size;
cef.minimum_logical_font_size = web.minimum_logical_font_size;
cef.remote_fonts_disabled = !web.remote_fonts_enabled;
if (!web.default_encoding.empty()) {
std::wstring wstr;
UTF8ToWide(web.default_encoding.c_str(), web.default_encoding.length(),
&wstr);
cef.default_encoding = cef_string_alloc(wstr.c_str());
}
cef.encoding_detector_enabled = web.uses_universal_detector;
cef.javascript_disabled = !web.java_enabled;
cef.javascript_open_windows_disallowed =
!web.javascript_can_open_windows_automatically;
cef.javascript_close_windows_disallowed =
!web.allow_scripts_to_close_windows;
cef.javascript_access_clipboard_disallowed =
!web.javascript_can_access_clipboard;
cef.dom_paste_disabled = !web.dom_paste_enabled;
cef.caret_browsing_enabled = web.caret_browsing_enabled;
cef.java_disabled = !web.java_enabled;
cef.plugins_disabled = !web.plugins_enabled;
cef.universal_access_from_file_urls_allowed =
web.allow_universal_access_from_file_urls;
cef.file_access_from_file_urls_allowed = web.allow_file_access_from_file_urls;
cef.web_security_disabled = !web.web_security_enabled;
cef.xss_auditor_enabled = web.xss_auditor_enabled;
cef.image_load_disabled = !web.loads_images_automatically;
cef.shrink_standalone_images_to_fit = web.shrinks_standalone_images_to_fit;
cef.site_specific_quirks_disabled = !web.site_specific_quirks_enabled;
cef.text_area_resize_disabled = !web.text_areas_are_resizable;
cef.page_cache_disabled = !web.uses_page_cache;
cef.tab_to_links_disabled = !web.tabs_to_links;
cef.hyperlink_auditing_disabled = !web.hyperlink_auditing_enabled;
cef.user_style_sheet_enabled = web.user_style_sheet_enabled;
if (!web.user_style_sheet_location.is_empty()) {
std::string str = web.user_style_sheet_location.spec();
std::wstring wstr;
UTF8ToWide(str.c_str(), str.length(), &wstr);
cef.user_style_sheet_location = cef_string_alloc(wstr.c_str());
}
cef.author_and_user_styles_disabled = !web.author_and_user_styles_enabled;
cef.local_storage_disabled = !web.local_storage_enabled;
cef.databases_disabled = !web.databases_enabled;
cef.application_cache_disabled = !web.application_cache_enabled;
cef.experimental_webgl_enabled = web.experimental_webgl_enabled;
cef.accelerated_compositing_disabled = !web.accelerated_compositing_enabled;
cef.accelerated_2d_canvas_disabled = !web.accelerated_2d_canvas_enabled;
}

14
libcef/browser_settings.h Normal file
View File

@ -0,0 +1,14 @@
// 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_BROWSER_SETTINGS_H
#define _CEF_BROWSER_SETTINGS_H
class CefBrowserSettings;
struct WebPreferences;
void BrowserToWebSettings(const CefBrowserSettings& cef, WebPreferences& web);
void WebToBrowserSettings(const WebPreferences& web, CefBrowserSettings& cef);
#endif // _CEF_BROWSER_SETTINGS_H

View File

@ -16,6 +16,8 @@ MSVC_POP_WARNING();
#include "browser_webkit_glue.h" #include "browser_webkit_glue.h"
#undef LOG #undef LOG
#include "cef_context.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/scoped_ptr.h" #include "base/scoped_ptr.h"
@ -70,6 +72,9 @@ bool IsProtocolSupportedForMedia(const GURL& url) {
} }
std::string GetWebKitLocale() { std::string GetWebKitLocale() {
const CefSettings& settings = _Context->settings();
if (settings.locale)
return WideToUTF8(settings.locale);
return "en-US"; return "en-US";
} }
@ -119,7 +124,10 @@ std::wstring WebStringToStdWString(const WebKit::WebString& str) {
} }
std::string GetProductVersion() { std::string GetProductVersion() {
return std::string("Chrome/7.0.517.0"); const CefSettings& settings = _Context->settings();
if (settings.product_version)
return WideToUTF8(settings.product_version);
return "Chrome/7.0.517.0";
} }
bool IsSingleProcess() { bool IsSingleProcess() {

View File

@ -161,23 +161,6 @@ void TranslatePopupFeatures(const WebWindowFeatures& webKitFeatures,
} // namespace } // namespace
// WebViewDelegate -----------------------------------------------------------
void BrowserWebViewDelegate::SetUserStyleSheetEnabled(bool is_enabled) {
WebPreferences* prefs = _Context->web_preferences();
prefs->user_style_sheet_enabled = is_enabled;
if (browser_->GetWebView())
prefs->Apply(browser_->GetWebView());
}
void BrowserWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) {
WebPreferences* prefs = _Context->web_preferences();
prefs->user_style_sheet_enabled = true;
prefs->user_style_sheet_location = location;
if (browser_->GetWebView())
prefs->Apply(browser_->GetWebView());
}
// WebViewClient ------------------------------------------------------------- // WebViewClient -------------------------------------------------------------
WebView* BrowserWebViewDelegate::createView(WebFrame* creator, WebView* BrowserWebViewDelegate::createView(WebFrame* creator,
@ -912,6 +895,7 @@ void BrowserWebViewDelegate::RegisterDragDrop() {
void BrowserWebViewDelegate::RevokeDragDrop() { void BrowserWebViewDelegate::RevokeDragDrop() {
#if defined(OS_WIN) #if defined(OS_WIN)
if (drop_delegate_.get())
::RevokeDragDrop(browser_->GetWebViewWndHandle()); ::RevokeDragDrop(browser_->GetWebViewWndHandle());
#endif #endif
} }

View File

@ -39,7 +39,6 @@
#include "browser_navigation_controller.h" #include "browser_navigation_controller.h"
class CefBrowserImpl; class CefBrowserImpl;
struct WebPreferences;
class GURL; class GURL;
class WebWidgetHost; class WebWidgetHost;
class FilePath; class FilePath;
@ -218,10 +217,6 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient,
pending_extra_data_.reset(extra_data); pending_extra_data_.reset(extra_data);
} }
// Methods for modifying WebPreferences
void SetUserStyleSheetEnabled(bool is_enabled);
void SetUserStyleSheetLocation(const GURL& location);
// Sets the webview as a drop target. // Sets the webview as a drop target.
void RegisterDragDrop(); void RegisterDragDrop();
void RevokeDragDrop(); void RevokeDragDrop();

View File

@ -15,28 +15,28 @@
#endif #endif
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "webkit/glue/plugins/plugin_list.h" #include "webkit/glue/plugins/plugin_list.h"
#include "webkit/glue/webpreferences.h"
// Global CefContext pointer // Global CefContext pointer
CefRefPtr<CefContext> _Context; CefRefPtr<CefContext> _Context;
bool CefInitialize(bool multi_threaded_message_loop, bool CefInitialize(const CefSettings& settings,
const std::wstring& cache_path) const CefBrowserSettings& browser_defaults)
{ {
// Return true if the context is already initialized // Return true if the context is already initialized
if(_Context.get()) if(_Context.get())
return true; return true;
if(settings.size != sizeof(cef_settings_t) ||
browser_defaults.size != sizeof(cef_browser_settings_t)) {
NOTREACHED();
return false;
}
// Create the new global context object // Create the new global context object
_Context = new CefContext(); _Context = new CefContext();
// Initialize the global context // Initialize the global context
#if defined(OS_WIN) return _Context->Initialize(settings, browser_defaults);
FilePath cachePath(cache_path);
#else
FilePath cachePath(WideToUTF8(_Context->cache_path()));
#endif
return _Context->Initialize(multi_threaded_message_loop, cachePath);
} }
void CefShutdown() void CefShutdown()
@ -176,7 +176,7 @@ bool CefPostDelayedTask(CefThreadId threadId, CefRefPtr<CefTask> task,
// CefContext // CefContext
CefContext::CefContext() : process_(NULL), webprefs_(NULL) CefContext::CefContext() : process_(NULL)
{ {
} }
@ -187,64 +187,27 @@ CefContext::~CefContext()
Shutdown(); Shutdown();
} }
bool CefContext::Initialize(bool multi_threaded_message_loop, bool CefContext::Initialize(const CefSettings& settings,
const FilePath& cache_path) const CefBrowserSettings& browser_defaults)
{ {
cache_path_ = cache_path; settings_ = settings;
browser_defaults_ = browser_defaults;
// Initialize web preferences std::wstring cachePathStr;
webprefs_ = new WebPreferences; if(settings.cache_path)
*webprefs_ = WebPreferences(); cachePathStr = settings.cache_path;
webprefs_->standard_font_family = L"Times"; #if defined(OS_WIN)
webprefs_->fixed_font_family = L"Courier"; cache_path_ = FilePath(cachePathStr);
webprefs_->serif_font_family = L"Times";
webprefs_->sans_serif_font_family = L"Helvetica";
// These two fonts are picked from the intersection of
// Win XP font list and Vista font list :
// http://www.microsoft.com/typography/fonts/winxp.htm
// http://blogs.msdn.com/michkap/archive/2006/04/04/567881.aspx
// Some of them are installed only with CJK and complex script
// support enabled on Windows XP and are out of consideration here.
// (although we enabled both on our buildbots.)
// They (especially Impact for fantasy) are not typical cursive
// and fantasy fonts, but it should not matter for layout tests
// as long as they're available.
#if defined(OS_MACOSX)
webprefs_->cursive_font_family = L"Apple Chancery";
webprefs_->fantasy_font_family = L"Papyrus";
#else #else
webprefs_->cursive_font_family = L"Comic Sans MS"; cache_path_ = FilePath(WideToUTF8(cachePathStr));
webprefs_->fantasy_font_family = L"Impact";
#endif #endif
webprefs_->default_encoding = "ISO-8859-1";
webprefs_->default_font_size = 16;
webprefs_->default_fixed_font_size = 13;
webprefs_->minimum_font_size = 1;
webprefs_->minimum_logical_font_size = 9;
webprefs_->javascript_can_open_windows_automatically = true;
webprefs_->dom_paste_enabled = true;
webprefs_->developer_extras_enabled = true;
webprefs_->site_specific_quirks_enabled = true;
webprefs_->shrinks_standalone_images_to_fit = false;
webprefs_->uses_universal_detector = false;
webprefs_->text_areas_are_resizable = true;
webprefs_->java_enabled = true;
webprefs_->allow_scripts_to_close_windows = false;
webprefs_->xss_auditor_enabled = false;
webprefs_->remote_fonts_enabled = true;
webprefs_->local_storage_enabled = true;
webprefs_->application_cache_enabled = true;
webprefs_->databases_enabled = true;
webprefs_->allow_file_access_from_file_urls = true;
webprefs_->accelerated_2d_canvas_enabled = true;
webprefs_->accelerated_compositing_enabled = true;
#if defined(OS_MACOSX) || defined(OS_WIN) #if defined(OS_MACOSX) || defined(OS_WIN)
// We want to be sure to init NSPR on the main thread. // We want to be sure to init NSPR on the main thread.
base::EnsureNSPRInit(); base::EnsureNSPRInit();
#endif #endif
process_ = new CefProcess(multi_threaded_message_loop); process_ = new CefProcess(settings_.multi_threaded_message_loop);
process_->CreateChildThreads(); process_->CreateChildThreads();
return true; return true;

View File

@ -19,7 +19,6 @@
class BrowserRequestContext; class BrowserRequestContext;
class CefBrowserImpl; class CefBrowserImpl;
struct WebPreferences;
class CefContext : public CefThreadSafeBase<CefBase> class CefContext : public CefThreadSafeBase<CefBase>
{ {
@ -30,8 +29,8 @@ public:
~CefContext(); ~CefContext();
// These methods will be called on the main application thread. // These methods will be called on the main application thread.
bool Initialize(bool multi_threaded_message_loop, bool Initialize(const CefSettings& settings,
const FilePath& cache_path); const CefBrowserSettings& browser_defaults);
void Shutdown(); void Shutdown();
scoped_refptr<CefProcess> process() { return process_; } scoped_refptr<CefProcess> process() { return process_; }
@ -43,13 +42,11 @@ public:
// Retrieve the path at which cache data will be stored on disk. If empty, // Retrieve the path at which cache data will be stored on disk. If empty,
// cache data will be stored in-memory. // cache data will be stored in-memory.
const FilePath& cache_path() { return cache_path_; } const FilePath& cache_path() const { return cache_path_; }
WebPreferences* web_preferences() const CefSettings& settings() const { return settings_; }
{ const CefBrowserSettings& browser_defaults() const
REQUIRE_UIT(); { return browser_defaults_; }
return webprefs_;
}
// The BrowserRequestContext object is managed by CefProcessIOThread. // The BrowserRequestContext object is managed by CefProcessIOThread.
void set_request_context(BrowserRequestContext* request_context) void set_request_context(BrowserRequestContext* request_context)
@ -70,8 +67,9 @@ private:
// asserts and possible memory leaks. // asserts and possible memory leaks.
base::AtExitManager at_exit_manager_; base::AtExitManager at_exit_manager_;
CefSettings settings_;
CefBrowserSettings browser_defaults_;
FilePath cache_path_; FilePath cache_path_;
WebPreferences* webprefs_;
scoped_refptr<BrowserRequestContext> request_context_; scoped_refptr<BrowserRequestContext> request_context_;
scoped_ptr<DOMStorageContext> storage_context_; scoped_ptr<DOMStorageContext> storage_context_;

View File

@ -21,6 +21,7 @@
#endif #endif
#include "webkit/blob/blob_storage_controller.h" #include "webkit/blob/blob_storage_controller.h"
#include "webkit/blob/blob_url_request_job.h" #include "webkit/blob/blob_url_request_job.h"
#include "webkit/glue/plugins/plugin_list.h"
#include "webkit/extensions/v8/gc_extension.h" #include "webkit/extensions/v8/gc_extension.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
@ -121,6 +122,26 @@ void CefProcessUIThread::Init() {
// Create the storage context object. // Create the storage context object.
_Context->set_storage_context(new DOMStorageContext()); _Context->set_storage_context(new DOMStorageContext());
} }
const CefSettings& settings = _Context->settings();
if (settings.user_agent)
webkit_glue::SetUserAgent(WideToUTF8(settings.user_agent));
if (settings.extra_plugin_paths) {
cef_string_t str;
FilePath path;
int size = cef_string_list_size(settings.extra_plugin_paths);
for(int i = 0; i < size; ++i) {
str = cef_string_list_value(settings.extra_plugin_paths, i);
#if defined(OS_WIN)
path = FilePath(str);
#else
path = FilePath(WideToUTF8(str));
#endif
NPAPI::PluginList::Singleton()->AddExtraPluginPath(path);
}
}
} }
void CefProcessUIThread::CleanUp() { void CefProcessUIThread::CleanUp() {

View File

@ -53,3 +53,10 @@ CEF_EXPORT void cef_string_list_free(cef_string_list_t list)
DCHECK(list); DCHECK(list);
delete (StringList*)list; delete (StringList*)list;
} }
CEF_EXPORT cef_string_list_t cef_string_list_copy(cef_string_list_t list)
{
DCHECK(list);
StringList* impl = (StringList*)list;
return new StringList(*impl);
}

View File

@ -24,8 +24,10 @@
enum cef_retval_t CEF_CALLBACK handler_handle_before_created( enum cef_retval_t CEF_CALLBACK handler_handle_before_created(
struct _cef_handler_t* self, cef_browser_t* parentBrowser, struct _cef_handler_t* self, cef_browser_t* parentBrowser,
cef_window_info_t* windowInfo, int popup, struct _cef_handler_t** handler, cef_window_info_t* windowInfo, int popup,
cef_string_t* url, const struct _cef_popup_features_t* popupFeatures) const struct _cef_popup_features_t* popupFeatures,
struct _cef_handler_t** handler, cef_string_t* url,
struct _cef_browser_settings_t* settings)
{ {
DCHECK(self); DCHECK(self);
DCHECK(windowInfo); DCHECK(windowInfo);
@ -34,8 +36,14 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_created(
if(!self || !windowInfo || !handler || !*handler || !url) if(!self || !windowInfo || !handler || !*handler || !url)
return RV_CONTINUE; return RV_CONTINUE;
CefWindowInfo wndInfo(*windowInfo); CefWindowInfo wndInfo;
CefPopupFeatures features(*popupFeatures); CefBrowserSettings browserSettings;
CefPopupFeatures features;
// Take ownership of the pointers instead of copying.
wndInfo.Attach(*windowInfo);
browserSettings.Attach(*settings);
features.Attach(*popupFeatures);
// |newHandler| will start off pointing to the current handler. // |newHandler| will start off pointing to the current handler.
CefRefPtr<CefHandler> handlerPtr = CefHandlerCppToC::Unwrap(*handler); CefRefPtr<CefHandler> handlerPtr = CefHandlerCppToC::Unwrap(*handler);
@ -51,7 +59,8 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_created(
urlStr = *url; urlStr = *url;
enum cef_retval_t rv = CefHandlerCppToC::Get(self)->HandleBeforeCreated( enum cef_retval_t rv = CefHandlerCppToC::Get(self)->HandleBeforeCreated(
browserPtr, wndInfo, popup?true:false, handlerPtr, urlStr, features); browserPtr, wndInfo, popup?true:false, features, handlerPtr, urlStr,
browserSettings);
transfer_string_contents(urlStr, url); transfer_string_contents(urlStr, url);
@ -60,13 +69,16 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_created(
*handler = CefHandlerCppToC::Wrap(handlerPtr); *handler = CefHandlerCppToC::Wrap(handlerPtr);
} }
// WindowInfo may or may not have changed. // Window info may or may not have changed.
*windowInfo = wndInfo; *windowInfo = wndInfo;
#ifdef WIN32
// The m_windowName must be duplicated since it's a cef_string_t // Browser settings may or may not have changed.
if(windowInfo->m_windowName) *settings = browserSettings;
windowInfo->m_windowName = cef_string_alloc(windowInfo->m_windowName);
#endif // Don't free the pointers.
features.Detach();
wndInfo.Detach();
browserSettings.Detach();
return rv; return rv;
} }

View File

@ -24,8 +24,8 @@
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeCreated( CefHandler::RetVal CefHandlerCToCpp::HandleBeforeCreated(
CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& windowInfo, bool popup, CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& windowInfo, bool popup,
CefRefPtr<CefHandler>& handler, std::wstring& url, const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler,
const CefPopupFeatures& popupFeatures) std::wstring& url, CefBrowserSettings& settings)
{ {
if(CEF_MEMBER_MISSING(struct_, handle_before_created)) if(CEF_MEMBER_MISSING(struct_, handle_before_created))
return RV_CONTINUE; return RV_CONTINUE;
@ -44,7 +44,8 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeCreated(
urlRet = cef_string_alloc(url.c_str()); urlRet = cef_string_alloc(url.c_str());
cef_retval_t rv = struct_->handle_before_created(struct_, cef_retval_t rv = struct_->handle_before_created(struct_,
browserStruct, &windowInfo, popup, &handlerStruct, &urlRet, &popupFeatures); browserStruct, &windowInfo, popup, &popupFeatures, &handlerStruct,
&urlRet, &settings);
if(handlerStruct && handlerStruct != origHandlerStruct) { if(handlerStruct && handlerStruct != origHandlerStruct) {
// The handler was changed. // The handler was changed.

View File

@ -32,8 +32,9 @@ public:
// CefHandler methods // CefHandler methods
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser, virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& windowInfo, bool popup, CefRefPtr<CefHandler>& handler, CefWindowInfo& windowInfo, bool popup,
std::wstring& url, const CefPopupFeatures& popupFeatures); const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler,
std::wstring& url, CefBrowserSettings& settings);
virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser); virtual RetVal HandleAfterCreated(CefRefPtr<CefBrowser> browser);
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser, virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame, const std::wstring& url); CefRefPtr<CefFrame> frame, const std::wstring& url);

View File

@ -27,13 +27,25 @@
#include "base/string_split.h" #include "base/string_split.h"
CEF_EXPORT int cef_initialize(int multi_threaded_message_loop, CEF_EXPORT int cef_initialize(const struct _cef_settings_t* settings,
const wchar_t* cache_path) const struct _cef_browser_settings_t* browser_defaults)
{ {
std::wstring cachePath; CefSettings settingsObj;
if(cache_path) CefBrowserSettings browserDefaultsObj;
cachePath = cache_path;
return CefInitialize(multi_threaded_message_loop?true:false, cachePath); // Take ownership of the pointers instead of copying.
if (settings)
settingsObj.Attach(*settings);
if (browser_defaults)
browserDefaultsObj.Attach(*browser_defaults);
int ret = CefInitialize(settingsObj, browserDefaultsObj);
// Don't free the pointers.
settingsObj.Detach();
browserDefaultsObj.Detach();
return ret;
} }
CEF_EXPORT void cef_shutdown() CEF_EXPORT void cef_shutdown()

View File

@ -25,11 +25,10 @@
#include "libcef_dll/ctocpp/zip_reader_ctocpp.h" #include "libcef_dll/ctocpp/zip_reader_ctocpp.h"
bool CefInitialize(bool multi_threaded_message_loop, bool CefInitialize(const CefSettings& settings,
const std::wstring& cache_path) const CefBrowserSettings& browser_defaults)
{ {
return cef_initialize(multi_threaded_message_loop, cache_path.c_str()) return cef_initialize(&settings, &browser_defaults)?true:false;
?true:false;
} }
void CefShutdown() void CefShutdown()

View File

@ -42,9 +42,10 @@ public:
// window modify the object that |handler| points to. // window modify the object that |handler| points to.
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser, virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& createInfo, bool popup, CefWindowInfo& createInfo, bool popup,
const CefPopupFeatures& popupFeatures,
CefRefPtr<CefHandler>& handler, CefRefPtr<CefHandler>& handler,
std::wstring& url, std::wstring& url,
const CefPopupFeatures& popupFeatures) CefBrowserSettings& settings)
{ {
return RV_CONTINUE; return RV_CONTINUE;
} }

View File

@ -348,7 +348,9 @@ int main(int argc, char* argv[])
getcwd(szWorkingDir, sizeof(szWorkingDir)); getcwd(szWorkingDir, sizeof(szWorkingDir));
// Initialize CEF. This will also create the NSApplication instance. // Initialize CEF. This will also create the NSApplication instance.
CefInitialize(false, std::wstring()); CefSettings settings;
CefBrowserSettings browserDefaults;
CefInitialize(settings, browserDefaults);
// Initialize tests. // Initialize tests.
InitExtensionTest(); InitExtensionTest();

View File

@ -62,15 +62,20 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
if(_wgetcwd(szWorkingDir, MAX_PATH) == NULL) if(_wgetcwd(szWorkingDir, MAX_PATH) == NULL)
szWorkingDir[0] = 0; szWorkingDir[0] = 0;
CefSettings settings;
CefBrowserSettings browserDefaults;
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP #ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
// Initialize the CEF with messages processed using the current application's // Initialize the CEF with messages processed using the current application's
// message loop. // message loop.
CefInitialize(false, std::wstring()); settings.multi_threaded_message_loop = false;
#else #else
// Initialize the CEF with messages processed using a separate UI thread. // Initialize the CEF with messages processed using a separate UI thread.
CefInitialize(true, std::wstring()); settings.multi_threaded_message_loop = true;
#endif #endif
CefInitialize(settings, browserDefaults);
// Register the internal client plugin. // Register the internal client plugin.
InitPluginTest(); InitPluginTest();

View File

@ -26,9 +26,10 @@ public:
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser, virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& createInfo, bool popup, CefWindowInfo& createInfo, bool popup,
const CefPopupFeatures& popupFeatures,
CefRefPtr<CefHandler>& handler, CefRefPtr<CefHandler>& handler,
std::wstring& url, std::wstring& url,
const CefPopupFeatures& popupFeatures) CefBrowserSettings& settings)
{ {
return RV_CONTINUE; return RV_CONTINUE;
} }

View File

@ -19,7 +19,11 @@ class CefTestSuite : public TestSuite {
virtual void Initialize() { virtual void Initialize() {
TestSuite::Initialize(); TestSuite::Initialize();
CefInitialize(true, std::wstring());
CefSettings settings;
CefBrowserSettings browserDefaults;
settings.multi_threaded_message_loop = true;
CefInitialize(settings, browserDefaults);
} }
virtual void Shutdown() { virtual void Shutdown() {

View File

@ -1057,7 +1057,9 @@ class obj_analysis:
structuretypes = { structuretypes = {
'CefPrintInfo' : 'cef_print_info_t', 'CefPrintInfo' : 'cef_print_info_t',
'CefWindowInfo' : 'cef_window_info_t', 'CefWindowInfo' : 'cef_window_info_t',
'CefPopupFeatures' : 'cef_popup_features_t' 'CefPopupFeatures' : 'cef_popup_features_t',
'CefSettings' : 'cef_settings_t',
'CefBrowserSettings' : 'cef_browser_settings_t',
} }
if value in structuretypes.keys(): if value in structuretypes.keys():
return { return {