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

@@ -45,37 +45,33 @@
#include "cef_types.h"
class CefBrowser;
class CefBrowserSettings;
class CefDownloadHandler;
class CefFrame;
class CefHandler;
class CefPopupFeatures;
class CefPostData;
class CefPostDataElement;
class CefRequest;
class CefSchemeHandler;
class CefSchemeHandlerFactory;
class CefSettings;
class CefStreamReader;
class CefStreamWriter;
class CefTask;
class CefV8Handler;
class CefV8Value;
class CefPopupFeatures;
// This function should only be called once when the application is started.
// Create the thread to host the UI message loop. A return value of true
// indicates that it succeeded and false indicates that it failed. Set
// |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.
// This function should be called once when the application is started to
// initialize CEF. A return value of true indicates that it succeeded and
// false indicates that it failed.
/*--cef()--*/
bool CefInitialize(bool multi_threaded_message_loop,
const std::wstring& cache_path);
bool CefInitialize(const CefSettings& settings,
const CefBrowserSettings& browser_defaults);
// This function should only be called once before the application exits.
// Shut down the thread hosting the UI message loop and destroy any created
// windows.
// This function should be called once before the application exits to shut down
// CEF.
/*--cef()--*/
void CefShutdown();
@@ -559,9 +555,10 @@ public:
/*--cef()--*/
virtual RetVal HandleBeforeCreated(CefRefPtr<CefBrowser> parentBrowser,
CefWindowInfo& windowInfo, bool popup,
const CefPopupFeatures& popupFeatures,
CefRefPtr<CefHandler>& handler,
std::wstring& url,
const CefPopupFeatures& popupFeatures) =0;
CefBrowserSettings& settings) =0;
// Event called after a new window is created. The return value is currently
// ignored.
@@ -1495,10 +1492,9 @@ public:
{
Init();
}
~CefPopupFeatures()
virtual ~CefPopupFeatures()
{
if(additionalFeatures)
cef_string_list_free(additionalFeatures);
Reset();
}
CefPopupFeatures(const CefPopupFeatures& r)
@@ -1512,6 +1508,55 @@ public:
*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()
{
x = 0;
@@ -1534,47 +1579,255 @@ public:
dialog = false;
additionalFeatures = NULL;
}
};
CefPopupFeatures& operator=(const CefPopupFeatures& r)
// Class representing initialization settings.
class CefSettings : public cef_settings_t
{
public:
CefSettings()
{
return operator=(static_cast<const cef_popup_features_t&>(r));
Init();
}
virtual ~CefSettings()
{
Reset();
}
CefPopupFeatures& operator=(const cef_popup_features_t& r)
CefSettings(const CefSettings& r)
{
if(additionalFeatures)
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);
}
}
else {
additionalFeatures = NULL;
}
Init();
*this = r;
}
CefSettings(const cef_settings_t& r)
{
Init();
*this = r;
}
void Reset()
{
if(cache_path)
cef_string_free(cache_path);
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;
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()
{
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

View File

@@ -48,19 +48,14 @@ extern "C" {
#include "cef_types.h"
// This function should only be called once when the application is started.
// Create the thread to host the UI message loop. A return value of true (1)
// indicates that it succeeded and false (0) indicates that it failed. Set
// |multi_threaded_message_loop| to true (1) to have the message loop run in a
// separate thread. If |multi_threaded_message_loop| is false (0) than the
// 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 be called once when the application is started to
// initialize CEF. A return value of true (1) indicates that it succeeded and
// false (0) indicates that it failed.
CEF_EXPORT int cef_initialize(const struct _cef_settings_t* settings,
const struct _cef_browser_settings_t* browser_defaults);
// This function should only be called once before the application exits. Shut
// down the thread hosting the UI message loop and destroy any created windows.
// This function should be called once before the application exits to shut down
// CEF.
CEF_EXPORT void cef_shutdown();
// 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)(
struct _cef_handler_t* self, struct _cef_browser_t* parentBrowser,
struct _cef_window_info_t* windowInfo, int popup,
const struct _cef_popup_features_t* popupFeatures,
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
// ignored.

View File

@@ -55,7 +55,7 @@ public:
pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&lock_, &attr_);
}
~CefCriticalSection()
virtual ~CefCriticalSection()
{
pthread_mutex_destroy(&lock_);
pthread_mutexattr_destroy(&attr_);
@@ -81,10 +81,9 @@ public:
{
Init();
}
~CefWindowInfo()
virtual ~CefWindowInfo()
{
if(m_windowName)
cef_string_free(m_windowName);
Reset();
}
CefWindowInfo(const CefWindowInfo& r)
@@ -98,13 +97,22 @@ public:
*this = r;
}
void Init()
void Reset()
{
m_windowName = NULL;
m_x = 0;
m_y = 0;
m_nWidth = 0;
m_nHeight = 0;
if(m_windowName)
cef_string_free(m_windowName);
Init();
}
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)
@@ -125,6 +133,16 @@ public:
m_nHeight = r.m_nHeight;
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.
@@ -135,7 +153,7 @@ public:
{
Init();
}
~CefPrintInfo()
virtual ~CefPrintInfo()
{
}

View File

@@ -58,7 +58,7 @@ public:
pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&lock_, &attr_);
}
~CefCriticalSection()
virtual ~CefCriticalSection()
{
pthread_mutex_destroy(&lock_);
pthread_mutexattr_destroy(&attr_);
@@ -84,10 +84,9 @@ public:
{
Init();
}
~CefWindowInfo()
virtual ~CefWindowInfo()
{
if(m_windowName)
cef_string_free(m_windowName);
Reset();
}
CefWindowInfo(const CefWindowInfo& r)
@@ -101,17 +100,24 @@ public:
*this = r;
}
void Init()
void Reset()
{
m_View = NULL;
m_ParentView = NULL;
m_windowName = NULL;
m_x = 0;
m_y = 0;
m_nWidth = 0;
m_nHeight = 0;
if(m_windowName)
cef_string_free(m_windowName);
Init();
}
void Attach(const cef_window_info_t& r)
{
Reset();
*static_cast<cef_window_info_t*>(this) = r;
}
void Detach()
{
Init();
}
void SetAsChild(CefWindowHandle ParentView, int x, int y, int width,
int height)
{
@@ -142,6 +148,18 @@ public:
m_nHeight = r.m_nHeight;
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.
@@ -152,7 +170,7 @@ public:
{
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.
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
}

View File

@@ -54,6 +54,162 @@ typedef long int64;
typedef long long int64;
#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
// that the implementation completely handled the method and that no further
// processing is required. Returning RV_CONTINUE indicates that the

View File

@@ -48,7 +48,7 @@ public:
memset(&m_sec, 0, sizeof(CRITICAL_SECTION));
InitializeCriticalSection(&m_sec);
}
~CefCriticalSection()
virtual ~CefCriticalSection()
{
DeleteCriticalSection(&m_sec);
}
@@ -72,10 +72,9 @@ public:
{
Init();
}
~CefWindowInfo()
virtual ~CefWindowInfo()
{
if(m_windowName)
cef_string_free(m_windowName);
Reset();
}
CefWindowInfo(const CefWindowInfo& r)
@@ -89,18 +88,22 @@ public:
*this = r;
}
void Init()
void Reset()
{
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;
if(m_windowName)
cef_string_free(m_windowName);
Init();
}
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)
@@ -154,6 +157,21 @@ public:
else
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.
@@ -164,7 +182,7 @@ public:
{
Init();
}
~CefPrintInfo()
virtual ~CefPrintInfo()
{
}