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

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

View File

@@ -33,7 +33,8 @@ class WebView;
class CefBrowserImpl : public CefThreadSafeBase<CefBrowser>
{
public:
CefBrowserImpl(CefWindowInfo& windowInfo, bool popup,
CefBrowserImpl(const CefWindowInfo& windowInfo,
const CefBrowserSettings& settings, bool popup,
CefRefPtr<CefHandler> handler);
virtual ~CefBrowserImpl() {}
@@ -102,7 +103,7 @@ public:
const std::wstring& scriptUrl,
int startLine);
std::wstring GetURL(CefRefPtr<CefFrame> frame);
WebKit::WebView* GetWebView() const {
return webviewhost_.get() ? webviewhost_->webview() : NULL;
}
@@ -231,10 +232,12 @@ public:
static bool ImplementsThreadSafeReferenceCounting() { return true; }
const CefBrowserSettings& settings() const { return settings_; }
const FilePath& file_system_root() const { return file_system_root_.path(); }
protected:
CefWindowInfo window_info_;
CefBrowserSettings settings_;
bool is_popup_;
bool is_modal_;
CefRefPtr<CefHandler> handler_;

View File

@@ -5,6 +5,7 @@
#include "cef_context.h"
#include "browser_impl.h"
#include "browser_settings.h"
#include "browser_webview_mac.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/WebSize.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
#include "webkit/glue/webpreferences.h"
using WebKit::WebRect;
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,
window_info_.m_nWidth, window_info_.m_nHeight);
WebPreferences prefs;
BrowserToWebSettings(settings_, prefs);
// Create the webview host object
webviewhost_.reset(
WebViewHost::Create(parentView, contentRect, delegate_.get(),
NULL, *_Context->web_preferences()));
NULL, prefs));
delegate_->RegisterDragDrop();
BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle();

View File

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

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

View File

@@ -161,23 +161,6 @@ void TranslatePopupFeatures(const WebWindowFeatures& webKitFeatures,
} // 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 -------------------------------------------------------------
WebView* BrowserWebViewDelegate::createView(WebFrame* creator,
@@ -912,7 +895,8 @@ void BrowserWebViewDelegate::RegisterDragDrop() {
void BrowserWebViewDelegate::RevokeDragDrop() {
#if defined(OS_WIN)
::RevokeDragDrop(browser_->GetWebViewWndHandle());
if (drop_delegate_.get())
::RevokeDragDrop(browser_->GetWebViewWndHandle());
#endif
}

View File

@@ -39,7 +39,6 @@
#include "browser_navigation_controller.h"
class CefBrowserImpl;
struct WebPreferences;
class GURL;
class WebWidgetHost;
class FilePath;
@@ -218,10 +217,6 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient,
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.
void RegisterDragDrop();
void RevokeDragDrop();

View File

@@ -15,28 +15,28 @@
#endif
#include "base/utf_string_conversions.h"
#include "webkit/glue/plugins/plugin_list.h"
#include "webkit/glue/webpreferences.h"
// Global CefContext pointer
CefRefPtr<CefContext> _Context;
bool CefInitialize(bool multi_threaded_message_loop,
const std::wstring& cache_path)
bool CefInitialize(const CefSettings& settings,
const CefBrowserSettings& browser_defaults)
{
// Return true if the context is already initialized
if(_Context.get())
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
_Context = new CefContext();
// Initialize the global context
#if defined(OS_WIN)
FilePath cachePath(cache_path);
#else
FilePath cachePath(WideToUTF8(_Context->cache_path()));
#endif
return _Context->Initialize(multi_threaded_message_loop, cachePath);
return _Context->Initialize(settings, browser_defaults);
}
void CefShutdown()
@@ -176,7 +176,7 @@ bool CefPostDelayedTask(CefThreadId threadId, CefRefPtr<CefTask> task,
// CefContext
CefContext::CefContext() : process_(NULL), webprefs_(NULL)
CefContext::CefContext() : process_(NULL)
{
}
@@ -187,64 +187,27 @@ CefContext::~CefContext()
Shutdown();
}
bool CefContext::Initialize(bool multi_threaded_message_loop,
const FilePath& cache_path)
bool CefContext::Initialize(const CefSettings& settings,
const CefBrowserSettings& browser_defaults)
{
cache_path_ = cache_path;
settings_ = settings;
browser_defaults_ = browser_defaults;
// Initialize web preferences
webprefs_ = new WebPreferences;
*webprefs_ = WebPreferences();
webprefs_->standard_font_family = L"Times";
webprefs_->fixed_font_family = L"Courier";
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";
std::wstring cachePathStr;
if(settings.cache_path)
cachePathStr = settings.cache_path;
#if defined(OS_WIN)
cache_path_ = FilePath(cachePathStr);
#else
webprefs_->cursive_font_family = L"Comic Sans MS";
webprefs_->fantasy_font_family = L"Impact";
cache_path_ = FilePath(WideToUTF8(cachePathStr));
#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)
// We want to be sure to init NSPR on the main thread.
base::EnsureNSPRInit();
#endif
process_ = new CefProcess(multi_threaded_message_loop);
process_ = new CefProcess(settings_.multi_threaded_message_loop);
process_->CreateChildThreads();
return true;

View File

@@ -19,7 +19,6 @@
class BrowserRequestContext;
class CefBrowserImpl;
struct WebPreferences;
class CefContext : public CefThreadSafeBase<CefBase>
{
@@ -30,8 +29,8 @@ public:
~CefContext();
// These methods will be called on the main application thread.
bool Initialize(bool multi_threaded_message_loop,
const FilePath& cache_path);
bool Initialize(const CefSettings& settings,
const CefBrowserSettings& browser_defaults);
void Shutdown();
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,
// 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()
{
REQUIRE_UIT();
return webprefs_;
}
const CefSettings& settings() const { return settings_; }
const CefBrowserSettings& browser_defaults() const
{ return browser_defaults_; }
// The BrowserRequestContext object is managed by CefProcessIOThread.
void set_request_context(BrowserRequestContext* request_context)
@@ -70,8 +67,9 @@ private:
// asserts and possible memory leaks.
base::AtExitManager at_exit_manager_;
CefSettings settings_;
CefBrowserSettings browser_defaults_;
FilePath cache_path_;
WebPreferences* webprefs_;
scoped_refptr<BrowserRequestContext> request_context_;
scoped_ptr<DOMStorageContext> storage_context_;

View File

@@ -21,6 +21,7 @@
#endif
#include "webkit/blob/blob_storage_controller.h"
#include "webkit/blob/blob_url_request_job.h"
#include "webkit/glue/plugins/plugin_list.h"
#include "webkit/extensions/v8/gc_extension.h"
#include "net/url_request/url_request.h"
@@ -117,10 +118,30 @@ void CefProcessUIThread::Init() {
URLRequest::RegisterProtocolFactory("blob", &BlobURLRequestJobFactory);
if(!_Context->cache_path().empty()) {
if (!_Context->cache_path().empty()) {
// Create the storage context object.
_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() {

View File

@@ -53,3 +53,10 @@ CEF_EXPORT void cef_string_list_free(cef_string_list_t list)
DCHECK(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);
}