Commit 936e595f authored by Marshall Greenblatt's avatar Marshall Greenblatt

- Support runtime configuration of renderer-related preferences (issue #1501).

- Persist modified user preferences including per-host zoom settings when a
  cache_path value is specified and persist_user_preferences is set to true
  via CefSettings or CefRequestContextSettings.
- Avoid the need to duplicate files from chrome/ by having CefBrowserContext
  extend Chrome's Profile class.
parent 487ea8a9
......@@ -612,10 +612,11 @@
'target_name': 'cef_locales',
'type': 'none',
'dependencies': [
'<(DEPTH)/ui/strings/ui_strings.gyp:ui_strings',
'<(DEPTH)/chrome/chrome_resources.gyp:platform_locale_settings',
'<(DEPTH)/components/components_strings.gyp:components_strings',
'<(DEPTH)/content/app/strings/content_strings.gyp:content_strings',
'<(DEPTH)/extensions/extensions_strings.gyp:extensions_strings',
'<(DEPTH)/ui/strings/ui_strings.gyp:ui_strings',
'cef_strings',
],
'actions': [
......@@ -811,6 +812,7 @@
'action_name': 'make_pack_strings_header',
'variables': {
'header_inputs': [
'<(SHARED_INTERMEDIATE_DIR)/chrome/grit/platform_locale_settings.h',
'<(SHARED_INTERMEDIATE_DIR)/components/strings/grit/components_strings.h',
'<(SHARED_INTERMEDIATE_DIR)/content/app/strings/grit/content_strings.h',
'<(SHARED_INTERMEDIATE_DIR)/extensions/strings/grit/extensions_strings.h',
......@@ -854,6 +856,7 @@
'<(DEPTH)/cef/libcef/resources/grit_stub',
'<(DEPTH)/cef/libcef/resources/grit_stub/chrome',
'<(grit_out_dir)',
'<(SHARED_INTERMEDIATE_DIR)/chrome',
'<(SHARED_INTERMEDIATE_DIR)/components',
'<(SHARED_INTERMEDIATE_DIR)/ui/resources',
'<(SHARED_INTERMEDIATE_DIR)/ui/strings',
......@@ -957,14 +960,12 @@
'libcef/browser/browser_message_filter.h',
'libcef/browser/browser_message_loop.cc',
'libcef/browser/browser_message_loop.h',
'libcef/browser/browser_pref_store.cc',
'libcef/browser/browser_pref_store.h',
'libcef/browser/browser_settings.cc',
'libcef/browser/browser_settings.h',
'libcef/browser/browser_urlrequest_impl.cc',
'libcef/browser/browser_urlrequest_impl.h',
'libcef/browser/chrome_browser_process_stub.cc',
'libcef/browser/chrome_browser_process_stub.h',
'libcef/browser/chrome_profile_stub.cc',
'libcef/browser/chrome_profile_stub.h',
'libcef/browser/chrome_scheme_handler.cc',
'libcef/browser/chrome_scheme_handler.h',
'libcef/browser/content_browser_client.cc',
......@@ -1051,6 +1052,10 @@
'libcef/browser/plugins/plugin_info_message_filter.h',
'libcef/browser/plugins/plugin_service_filter.cc',
'libcef/browser/plugins/plugin_service_filter.h',
'libcef/browser/prefs/browser_prefs.cc',
'libcef/browser/prefs/browser_prefs.h',
'libcef/browser/prefs/renderer_prefs.cc',
'libcef/browser/prefs/renderer_prefs.h',
'libcef/browser/print_settings_impl.cc',
'libcef/browser/print_settings_impl.h',
'libcef/browser/printing/printing_message_filter.cc',
......@@ -1223,16 +1228,10 @@
'<(DEPTH)/chrome/common/chrome_switches.cc',
'<(DEPTH)/chrome/common/chrome_switches.h',
# Include sources for proxy support.
'<(DEPTH)/base/prefs/testing_pref_store.cc',
'<(DEPTH)/base/prefs/testing_pref_store.h',
'<(DEPTH)/chrome/browser/net/proxy_service_factory.cc',
'<(DEPTH)/chrome/browser/net/proxy_service_factory.h',
'<(DEPTH)/chrome/browser/net/utility_process_mojo_proxy_resolver_factory.cc',
'<(DEPTH)/chrome/browser/net/utility_process_mojo_proxy_resolver_factory.h',
'<(DEPTH)/chrome/browser/prefs/command_line_pref_store.cc',
'<(DEPTH)/chrome/browser/prefs/command_line_pref_store.h',
'<(DEPTH)/chrome/common/pref_names.cc',
'<(DEPTH)/chrome/common/pref_names.h',
'<(DEPTH)/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.cc',
'<(DEPTH)/components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h',
'<(DEPTH)/components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.cc',
......@@ -1357,6 +1356,32 @@
'<(DEPTH)/chrome/browser/plugins/plugin_metadata.h',
'<(DEPTH)/components/nacl/common/nacl_constants.cc',
'<(DEPTH)/components/nacl/common/nacl_constants.h',
# Include sources for preferences support.
'<(DEPTH)/base/prefs/testing_pref_store.cc',
'<(DEPTH)/base/prefs/testing_pref_store.h',
'<(DEPTH)/chrome/browser/accessibility/animation_policy_prefs.cc',
'<(DEPTH)/chrome/browser/accessibility/animation_policy_prefs.h',
'<(DEPTH)/chrome/browser/character_encoding.cc',
'<(DEPTH)/chrome/browser/character_encoding.h',
'<(DEPTH)/chrome/browser/defaults.cc',
'<(DEPTH)/chrome/browser/defaults.h',
'<(DEPTH)/chrome/browser/extensions/extension_webkit_preferences.cc',
'<(DEPTH)/chrome/browser/extensions/extension_webkit_preferences.h',
'<(DEPTH)/chrome/browser/font_family_cache.cc',
'<(DEPTH)/chrome/browser/font_family_cache.h',
'<(DEPTH)/chrome/browser/prefs/command_line_pref_store.cc',
'<(DEPTH)/chrome/browser/prefs/command_line_pref_store.h',
'<(DEPTH)/chrome/browser/renderer_preferences_util.cc',
'<(DEPTH)/chrome/browser/renderer_preferences_util.h',
'<(DEPTH)/chrome/browser/ui/prefs/prefs_tab_helper.cc',
'<(DEPTH)/chrome/browser/ui/prefs/prefs_tab_helper.h',
'<(DEPTH)/chrome/browser/ui/zoom/chrome_zoom_level_prefs.cc',
'<(DEPTH)/chrome/browser/ui/zoom/chrome_zoom_level_prefs.h',
'<(DEPTH)/chrome/common/pref_font_webkit_names.h',
'<(DEPTH)/chrome/common/pref_names.cc',
'<(DEPTH)/chrome/common/pref_names.h',
'<(DEPTH)/chrome/common/pref_names_util.cc',
'<(DEPTH)/chrome/common/pref_names_util.h',
],
'conditions': [
['OS=="win"', {
......
......@@ -24,6 +24,11 @@
# Strip symbols and create dSYM files for the Release target.
'mac_strip_release': 1,
}],
['os_posix==1 and OS!="mac" and OS!="android"', {
# Disable theme support on Linux so we don't need to implement
# ThemeService[Factory] classes.
'enable_themes': 0,
}]
]
}, 'conditions': [
['os_posix==1 and OS!="mac" and OS!="android"', {
......
......@@ -218,15 +218,25 @@ typedef struct _cef_settings_t {
///
// To persist session cookies (cookies without an expiry date or validity
// interval) by default when using the global cookie manager set this value to
// true. Session cookies are generally intended to be transient and most Web
// browsers do not persist them. A |cache_path| value must also be specified
// to enable this feature. Also configurable using the
// true (1). Session cookies are generally intended to be transient and most
// Web browsers do not persist them. A |cache_path| value must also be
// specified to enable this feature. Also configurable using the
// "persist-session-cookies" command-line switch. Can be overridden for
// individual CefRequestContext instances via the
// CefRequestContextSettings.persist_session_cookies value.
///
int persist_session_cookies;
///
// To persist user preferences as a JSON file in the cache path directory set
// this value to true (1). A |cache_path| value must also be specified
// to enable this feature. Also configurable using the
// "persist-user-preferences" command-line switch. Can be overridden for
// individual CefRequestContext instances via the
// CefRequestContextSettings.persist_user_preferences value.
///
int persist_user_preferences;
///
// Value that will be returned as the User-Agent HTTP header. If empty the
// default User-Agent string will be used. Also configurable using the
......@@ -394,13 +404,21 @@ typedef struct _cef_request_context_settings_t {
///
// To persist session cookies (cookies without an expiry date or validity
// interval) by default when using the global cookie manager set this value to
// true. Session cookies are generally intended to be transient and most Web
// browsers do not persist them. Can be set globally using the
// true (1). Session cookies are generally intended to be transient and most
// Web browsers do not persist them. Can be set globally using the
// CefSettings.persist_session_cookies value. This value will be ignored if
// |cache_path| is empty or if it matches the CefSettings.cache_path value.
///
int persist_session_cookies;
///
// To persist user preferences as a JSON file in the cache path directory set
// this value to true (1). Can be set globally using the
// CefSettings.persist_user_preferences value. This value will be ignored if
// |cache_path| is empty or if it matches the CefSettings.cache_path value.
///
int persist_user_preferences;
///
// Set to true (1) to ignore errors related to invalid SSL certificates.
// Enabling this setting can lead to potential security vulnerabilities like
......
......@@ -489,6 +489,7 @@ struct CefSettingsTraits {
cef_string_set(src->user_data_path.str, src->user_data_path.length,
&target->user_data_path, copy);
target->persist_session_cookies = src->persist_session_cookies;
target->persist_user_preferences = src->persist_user_preferences;
cef_string_set(src->user_agent.str, src->user_agent.length,
&target->user_agent, copy);
......@@ -541,6 +542,7 @@ struct CefRequestContextSettingsTraits {
cef_string_set(src->cache_path.str, src->cache_path.length,
&target->cache_path, copy);
target->persist_session_cookies = src->persist_session_cookies;
target->persist_user_preferences = src->persist_user_preferences;
target->ignore_certificate_errors = src->ignore_certificate_errors;
cef_string_set(src->accept_language_list.str,
src->accept_language_list.length, &target->accept_language_list, copy);
......
......@@ -5,12 +5,15 @@
#include "libcef/browser/browser_context.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/extensions/extensions_util.h"
#include "base/logging.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#ifndef NDEBUG
base::AtomicRefCount CefBrowserContext::DebugObjCt = 0;
......@@ -24,16 +27,8 @@ CefBrowserContext::CefBrowserContext()
}
CefBrowserContext::~CefBrowserContext() {
if (resource_context_.get()) {
// Destruction of the ResourceContext will trigger destruction of all
// associated URLRequests.
content::BrowserThread::DeleteSoon(
content::BrowserThread::IO, FROM_HERE, resource_context_.release());
}
// Remove any BrowserContextKeyedServiceFactory associations.
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
this);
// Should be cleared in Shutdown().
DCHECK(!resource_context_.get());
#ifndef NDEBUG
base::AtomicRefCountDec(&DebugObjCt);
......@@ -68,6 +63,27 @@ void CefBrowserContext::Initialize() {
extension_system_->Init();
}
void CefBrowserContext::Shutdown() {
CEF_REQUIRE_UIT();
if (resource_context_.get()) {
// Destruction of the ResourceContext will trigger destruction of all
// associated URLRequests.
content::BrowserThread::DeleteSoon(
content::BrowserThread::IO, FROM_HERE, resource_context_.release());
}
// Remove any BrowserContextKeyedServiceFactory associations. This must be
// called before the ProxyService owned by CefBrowserContextImpl is destroyed.
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
this);
}
content::ResourceContext* CefBrowserContext::GetResourceContext() {
return resource_context_.get();
}
ChromeZoomLevelPrefs* CefBrowserContext::GetZoomLevelPrefs() {
return static_cast<ChromeZoomLevelPrefs*>(
GetStoragePartition(this, NULL)->GetZoomLevelDelegate());
}
......@@ -7,6 +7,7 @@
#pragma once
#include "include/cef_request_context_handler.h"
#include "libcef/browser/chrome_profile_stub.h"
#include "libcef/browser/resource_context.h"
#include "libcef/browser/url_request_context_getter_impl.h"
......@@ -115,7 +116,7 @@ class CefExtensionSystem;
// of this class is passed to WebContents::Create in CefBrowserHostImpl::
// CreateInternal. Only accessed on the UI thread unless otherwise indicated.
class CefBrowserContext
: public content::BrowserContext,
: public ChromeProfileStub,
public base::RefCountedThreadSafe<
CefBrowserContext, content::BrowserThread::DeleteOnUIThread> {
public:
......@@ -127,6 +128,9 @@ class CefBrowserContext
// BrowserContext methods.
content::ResourceContext* GetResourceContext() override;
// Profile methods.
ChromeZoomLevelPrefs* GetZoomLevelPrefs() override;
// Returns the settings associated with this object. Safe to call from any
// thread.
virtual const CefRequestContextSettings& GetSettings() const = 0;
......@@ -148,9 +152,6 @@ class CefBrowserContext
// Settings for plugins and extensions.
virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0;
// Preferences.
virtual PrefService* GetPrefs() = 0;
CefResourceContext* resource_context() const {
return resource_context_.get();
}
......@@ -166,6 +167,9 @@ class CefBrowserContext
protected:
~CefBrowserContext() override;
// Must be called before the child object destructor has completed.
void Shutdown();
private:
// Only allow deletion via scoped_refptr().
friend struct content::BrowserThread::DeleteOnThread<
......
......@@ -10,6 +10,7 @@
#include "libcef/browser/context.h"
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/permission_manager.h"
#include "libcef/browser/prefs/browser_prefs.h"
#include "libcef/browser/ssl_host_state_delegate.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h"
......@@ -22,9 +23,12 @@
#include "base/prefs/pref_service.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/font_family_cache.h"
#include "chrome/browser/net/proxy_service_factory.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "components/ui/zoom/zoom_event_manager.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
......@@ -131,6 +135,12 @@ CefBrowserContextImpl::CefBrowserContextImpl(
}
CefBrowserContextImpl::~CefBrowserContextImpl() {
Shutdown();
// The FontFamilyCache references the ProxyService so delete it before the
// ProxyService is deleted.
SetUserData(&kFontFamilyCacheKey, NULL);
pref_proxy_config_tracker_->DetachFromPrefService();
if (host_content_settings_map_.get())
......@@ -166,10 +176,11 @@ void CefBrowserContextImpl::Initialize() {
CefString(&CefContext::Get()->settings().accept_language_list);
}
// Initialize user preferences.
pref_store_ = new CefBrowserPrefStore();
pref_store_->SetInitializationCompleted();
pref_service_ = pref_store_->CreateService().Pass();
// Initialize preferences.
base::FilePath pref_path;
if (!cache_path_.empty() && settings_.persist_user_preferences)
pref_path = cache_path_.AppendASCII(browser_prefs::kUserPrefsFileName);
pref_service_ = browser_prefs::CreatePrefService(pref_path);
CefBrowserContext::Initialize();
......@@ -239,8 +250,14 @@ base::FilePath CefBrowserContextImpl::GetPath() const {
}
scoped_ptr<content::ZoomLevelDelegate>
CefBrowserContextImpl::CreateZoomLevelDelegate(const base::FilePath&) {
return scoped_ptr<content::ZoomLevelDelegate>();
CefBrowserContextImpl::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
if (cache_path_.empty())
return scoped_ptr<content::ZoomLevelDelegate>();
return make_scoped_ptr(new ChromeZoomLevelPrefs(
GetPrefs(), cache_path_, partition_path,
ui_zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
}
bool CefBrowserContextImpl::IsOffTheRecord() const {
......@@ -313,6 +330,14 @@ content::PermissionManager* CefBrowserContextImpl::GetPermissionManager() {
return permission_manager_.get();
}
PrefService* CefBrowserContextImpl::GetPrefs() {
return pref_service_.get();
}
const PrefService* CefBrowserContextImpl::GetPrefs() const {
return pref_service_.get();
}
const CefRequestContextSettings& CefBrowserContextImpl::GetSettings() const {
return settings_;
}
......@@ -380,7 +405,3 @@ HostContentSettingsMap* CefBrowserContextImpl::GetHostContentSettingsMap() {
}
return host_content_settings_map_.get();
}
PrefService* CefBrowserContextImpl::GetPrefs() {
return pref_service_.get();
}
......@@ -8,7 +8,6 @@
#include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_pref_store.h"
#include "libcef/browser/url_request_context_getter_impl.h"
#include "base/files/file_path.h"
......@@ -16,11 +15,6 @@
#include "base/memory/scoped_ptr.h"
#include "components/proxy_config/pref_proxy_config_tracker.h"
namespace content {
class DownloadManagerDelegate;
class SpeechRecognitionPreferences;
}
class CefBrowserContextProxy;
class CefDownloadManagerDelegate;
class CefSSLHostStateDelegate;
......@@ -75,6 +69,10 @@ class CefBrowserContextImpl : public CefBrowserContext {
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::PermissionManager* GetPermissionManager() override;
// Profile methods.
PrefService* GetPrefs() override;
const PrefService* GetPrefs() const override;
// CefBrowserContext methods.
const CefRequestContextSettings& GetSettings() const override;
CefRefPtr<CefRequestContextHandler> GetHandler() const override;
......@@ -89,7 +87,6 @@ class CefBrowserContextImpl : public CefBrowserContext {
content::URLRequestInterceptorScopedVector request_interceptors)
override;
HostContentSettingsMap* GetHostContentSettingsMap() override;
PrefService* GetPrefs() override;
// Guaranteed to exist once this object has been initialized.
scoped_refptr<CefURLRequestContextGetterImpl> request_context() const {
......@@ -112,7 +109,6 @@ class CefBrowserContextImpl : public CefBrowserContext {
typedef std::vector<const CefBrowserContextProxy*> ProxyList;
ProxyList proxy_list_;
scoped_refptr<CefBrowserPrefStore> pref_store_;
scoped_ptr<PrefService> pref_service_;
scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
......
......@@ -10,6 +10,7 @@
#include "libcef/browser/url_request_context_getter_proxy.h"
#include "base/logging.h"
#include "chrome/browser/font_family_cache.h"
#include "components/guest_view/common/guest_view_constants.h"
#include "content/browser/streams/stream_context.h"
#include "content/public/browser/storage_partition.h"
......@@ -27,6 +28,12 @@ bool ShouldProxyUserData(const void* key) {
if (key == guest_view::kGuestViewManagerKeyName)
return true;
// If this value is not proxied then there will be a use-after-free while
// destroying the FontFamilyCache because it will try to access the
// ProxyService owned by CefBrowserContextImpl (which has already been freed).
if (key == kFontFamilyCacheKey)
return true;
return false;
}
......@@ -43,6 +50,8 @@ CefBrowserContextProxy::CefBrowserContextProxy(
}
CefBrowserContextProxy::~CefBrowserContextProxy() {
Shutdown();
parent_->RemoveProxy(this);
}
......@@ -142,6 +151,14 @@ content::PermissionManager* CefBrowserContextProxy::GetPermissionManager() {
return parent_->GetPermissionManager();
}
PrefService* CefBrowserContextProxy::GetPrefs() {
return parent_->GetPrefs();
}
const PrefService* CefBrowserContextProxy::GetPrefs() const {
return parent_->GetPrefs();
}
const CefRequestContextSettings& CefBrowserContextProxy::GetSettings() const {
return parent_->GetSettings();
}
......@@ -173,7 +190,3 @@ net::URLRequestContextGetter*
HostContentSettingsMap* CefBrowserContextProxy::GetHostContentSettingsMap() {
return parent_->GetHostContentSettingsMap();
}
PrefService* CefBrowserContextProxy::GetPrefs() {
return parent_->GetPrefs();
}
......@@ -13,11 +13,6 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
namespace content {
class DownloadManagerDelegate;
class SpeechRecognitionPreferences;
}
class CefDownloadManagerDelegate;
class CefURLRequestContextGetterProxy;
......@@ -56,6 +51,10 @@ class CefBrowserContextProxy : public CefBrowserContext {
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::PermissionManager* GetPermissionManager() override;
// Profile methods.
PrefService* GetPrefs() override;
const PrefService* GetPrefs() const override;
// CefBrowserContext methods.
const CefRequestContextSettings& GetSettings() const override;
CefRefPtr<CefRequestContextHandler> GetHandler() const override;
......@@ -70,7 +69,6 @@ class CefBrowserContextProxy : public CefBrowserContext {
content::URLRequestInterceptorScopedVector request_interceptors)
override;
HostContentSettingsMap* GetHostContentSettingsMap() override;
PrefService* GetPrefs() override;
scoped_refptr<CefBrowserContextImpl> parent() const {
return parent_;
......
......@@ -10,7 +10,6 @@
#include "libcef/browser/browser_context_impl.h"
#include "libcef/browser/browser_info.h"
#include "libcef/browser/browser_pref_store.h"
#include "libcef/browser/chrome_scheme_handler.h"
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
......@@ -40,6 +39,7 @@
#include "base/command_line.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/view_messages.h"
......@@ -3039,6 +3039,7 @@ CefBrowserHostImpl::CefBrowserHostImpl(
CefString(), CefString(),
CefFrameHostImpl::kInvalidFrameId);
PrefsTabHelper::CreateForWebContents(web_contents_.get());
printing::PrintViewManager::CreateForWebContents(web_contents_.get());
// Make sure RenderViewCreated is called at least one time.
......
// 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 "libcef/browser/browser_settings.h"
#include <string>
#include "include/internal/cef_types_wrappers.h"
#include "libcef/common/cef_switches.h"
#include "base/command_line.h"
#include "content/public/common/web_preferences.h"
// Set default preferences based on CEF command-line flags. Chromium command-
// line flags should not exist for these preferences.
void SetDefaults(content::WebPreferences& web) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kDefaultEncoding)) {
web.default_encoding =
command_line->GetSwitchValueASCII(switches::kDefaultEncoding);
}
web.javascript_can_open_windows_automatically =
!command_line->HasSwitch(switches::kDisableJavascriptOpenWindows);
web.allow_scripts_to_close_windows =
!command_line->HasSwitch(switches::kDisableJavascriptCloseWindows);
web.javascript_can_access_clipboard =
!command_line->HasSwitch(switches::kDisableJavascriptAccessClipboard);
web.dom_paste_enabled =
!command_line->HasSwitch(switches::kDisableJavascriptDomPaste);
web.caret_browsing_enabled =
command_line->HasSwitch(switches::kEnableCaretBrowsing);
web.allow_universal_access_from_file_urls =
command_line->HasSwitch(switches::kAllowUniversalAccessFromFileUrls);
web.loads_images_automatically =
!command_line->HasSwitch(switches::kDisableImageLoading);
web.shrinks_standalone_images_to_fit =
command_line->HasSwitch(switches::kImageShrinkStandaloneToFit);
web.text_areas_are_resizable =
!command_line->HasSwitch(switches::kDisableTextAreaResize);
web.tabs_to_links =
!command_line->HasSwitch(switches::kDisableTabToLinks);
}
// Helper macro for setting a WebPreferences variable based on the value of a
// CefBrowserSettings variable.
#define SET_STATE(cef_var, web_var) \
if (cef_var == STATE_ENABLED) \
web_var = true; \
else if (cef_var == STATE_DISABLED) \
web_var = false;
// Use the preferences from WebContentsImpl::GetWebkitPrefs and the
// WebPreferences constructor by default. Only override features that are
// explicitly enabled or disabled.
void BrowserToWebSettings(const CefBrowserSettings& cef,
content::WebPreferences& web) {
SetDefaults(web);
if (cef.standard_font_family.length > 0) {
web.standard_font_family_map[content::kCommonScript] =
CefString(&cef.standard_font_family);
}
if (cef.fixed_font_family.length > 0) {
web.fixed_font_family_map[content::kCommonScript] =
CefString(&cef.fixed_font_family);
}
if (cef.serif_font_family.length > 0) {
web.serif_font_family_map[content::kCommonScript] =
CefString(&cef.serif_font_family);
}
if (cef.sans_serif_font_family.length > 0) {
web.sans_serif_font_family_map[content::kCommonScript] =
CefString(&cef.sans_serif_font_family);
}
if (cef.cursive_font_family.length > 0) {
web.cursive_font_family_map[content::kCommonScript] =
CefString(&cef.cursive_font_family);
}
if (cef.fantasy_font_family.length > 0) {
web.fantasy_font_family_map[content::kCommonScript] =
CefString(&cef.fantasy_font_family);
}
if (cef.default_font_size > 0)
web.default_font_size = cef.default_font_size;
if (cef.default_fixed_font_size > 0)
web.default_fixed_font_size = cef.default_fixed_font_size;
if (cef.minimum_font_size > 0)
web.minimum_font_size = cef.minimum_font_size;
if (cef.minimum_logical_font_size > 0)
web.minimum_logical_font_size = cef.minimum_logical_font_size;
if (cef.default_encoding.length > 0)
web.default_encoding = CefString(&cef.default_encoding);
SET_STATE(cef.remote_fonts, web.remote_fonts_enabled);
SET_STATE(cef.javascript, web.javascript_enabled);
SET_STATE(cef.javascript_open_windows,
web.javascript_can_open_windows_automatically);
SET_STATE(cef.javascript_close_windows, web.allow_scripts_to_close_windows);
SET_STATE(cef.javascript_access_clipboard,
web.javascript_can_access_clipboard);
SET_STATE(cef.javascript_dom_paste, web.dom_paste_enabled);
SET_STATE(cef.caret_browsing, web.caret_browsing_enabled);
SET_STATE(cef.plugins, web.plugins_enabled);
SET_STATE(cef.universal_access_from_file_urls,
web.allow_universal_access_from_file_urls);
SET_STATE(cef.file_access_from_file_urls,
web.allow_file_access_from_file_urls);
SET_STATE(cef.web_security, web.web_security_enabled);
SET_STATE(cef.image_loading, web.loads_images_automatically);
SET_STATE(cef.image_shrink_standalone_to_fit,
web.shrinks_standalone_images_to_fit);
SET_STATE(cef.text_area_resize, web.text_areas_are_resizable);
SET_STATE(cef.tab_to_links, web.tabs_to_links);
SET_STATE(cef.local_storage, web.local_storage_enabled);
SET_STATE(cef.databases, web.databases_enabled);
SET_STATE(cef.application_cache, web.application_cache_enabled);
// Never explicitly enable GPU-related functions in this method because the
// GPU blacklist is not being checked here.
if (cef.webgl == STATE_DISABLED)
web.experimental_webgl_enabled = false;
}
// 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_LIBCEF_BROWSER_BROWSER_SETTINGS_H_
#define CEF_LIBCEF_BROWSER_BROWSER_SETTINGS_H_
#pragma once
#include "include/internal/cef_types_wrappers.h"
namespace content {
struct WebPreferences;
}
void BrowserToWebSettings(const CefBrowserSettings& cef,
content::WebPreferences& web);
#endif // CEF_LIBCEF_BROWSER_BROWSER_SETTINGS_H_
......@@ -12,8 +12,8 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
// This file provides a stub implementation of chrome::BrowserProcess so that
// PrintJobWorker can determine the current locale.
// This file provides a stub implementation of Chrome's BrowserProcess object
// for use as an interop layer between CEF and files that live in chrome/.
class BackgroundModeManager {