From 936e595fe5e9aa5e7641abf72e1f872f9d0ceb73 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 16 Oct 2015 20:44:00 -0400 Subject: [PATCH] - 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. --- cef.gyp | 47 ++- cef.gypi | 5 + include/internal/cef_types.h | 28 +- include/internal/cef_types_wrappers.h | 2 + libcef/browser/browser_context.cc | 36 +- libcef/browser/browser_context.h | 12 +- libcef/browser/browser_context_impl.cc | 41 +- libcef/browser/browser_context_impl.h | 12 +- libcef/browser/browser_context_proxy.cc | 21 +- libcef/browser/browser_context_proxy.h | 10 +- libcef/browser/browser_host_impl.cc | 3 +- libcef/browser/browser_pref_store.h | 25 -- libcef/browser/browser_settings.cc | 128 ------ libcef/browser/browser_settings.h | 18 - libcef/browser/chrome_browser_process_stub.h | 4 +- libcef/browser/chrome_profile_stub.cc | 222 ++++++++++ libcef/browser/chrome_profile_stub.h | 57 +++ libcef/browser/content_browser_client.cc | 42 +- libcef/browser/content_browser_client.h | 2 - libcef/browser/context.cc | 3 + ...browser_context_keyed_service_factories.cc | 2 + .../extensions/extensions_api_client.cc | 2 + .../browser_prefs.cc} | 65 ++- libcef/browser/prefs/browser_prefs.h | 26 ++ libcef/browser/prefs/renderer_prefs.cc | 393 ++++++++++++++++++ libcef/browser/prefs/renderer_prefs.h | 39 ++ libcef/common/cef_switches.cc | 3 + libcef/common/cef_switches.h | 1 + libcef/common/main_delegate.cc | 4 + libcef/resources/cef_strings.grd | 78 ++++ patch/patch.cfg | 13 + patch/patches/font_family_cache_1501.patch | 13 + .../renderer_preferences_util_545103.patch | 24 ++ tests/cefclient/browser/preferences_test.cc | 5 + tests/cefclient/resources/preferences.html | 29 ++ tests/unittests/os_rendering_unittest.cc | 8 +- tools/repack_locales.py | 5 + 37 files changed, 1135 insertions(+), 293 deletions(-) delete mode 100644 libcef/browser/browser_pref_store.h delete mode 100644 libcef/browser/browser_settings.cc delete mode 100644 libcef/browser/browser_settings.h create mode 100644 libcef/browser/chrome_profile_stub.cc create mode 100644 libcef/browser/chrome_profile_stub.h rename libcef/browser/{browser_pref_store.cc => prefs/browser_prefs.cc} (69%) create mode 100644 libcef/browser/prefs/browser_prefs.h create mode 100644 libcef/browser/prefs/renderer_prefs.cc create mode 100644 libcef/browser/prefs/renderer_prefs.h create mode 100644 patch/patches/font_family_cache_1501.patch create mode 100644 patch/patches/renderer_preferences_util_545103.patch diff --git a/cef.gyp b/cef.gyp index c0138928d..9e7871cdf 100644 --- a/cef.gyp +++ b/cef.gyp @@ -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"', { diff --git a/cef.gypi b/cef.gypi index 24115cc1c..4b8263590 100644 --- a/cef.gypi +++ b/cef.gypi @@ -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"', { diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 950f36d47..19aaf4c41 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -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 diff --git a/include/internal/cef_types_wrappers.h b/include/internal/cef_types_wrappers.h index c5e83d7c6..83dae76ef 100644 --- a/include/internal/cef_types_wrappers.h +++ b/include/internal/cef_types_wrappers.h @@ -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); diff --git a/libcef/browser/browser_context.cc b/libcef/browser/browser_context.cc index a3d0eab23..fe5418177 100644 --- a/libcef/browser/browser_context.cc +++ b/libcef/browser/browser_context.cc @@ -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( + GetStoragePartition(this, NULL)->GetZoomLevelDelegate()); +} diff --git a/libcef/browser/browser_context.h b/libcef/browser/browser_context.h index 577000472..57e546a84 100644 --- a/libcef/browser/browser_context.h +++ b/libcef/browser/browser_context.h @@ -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< diff --git a/libcef/browser/browser_context_impl.cc b/libcef/browser/browser_context_impl.cc index b1b6a7fb1..f9ba48a74 100644 --- a/libcef/browser/browser_context_impl.cc +++ b/libcef/browser/browser_context_impl.cc @@ -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 - CefBrowserContextImpl::CreateZoomLevelDelegate(const base::FilePath&) { - return scoped_ptr(); + CefBrowserContextImpl::CreateZoomLevelDelegate( + const base::FilePath& partition_path) { + if (cache_path_.empty()) + return scoped_ptr(); + + 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(); -} diff --git a/libcef/browser/browser_context_impl.h b/libcef/browser/browser_context_impl.h index 5fabb796b..fac31ddb0 100644 --- a/libcef/browser/browser_context_impl.h +++ b/libcef/browser/browser_context_impl.h @@ -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 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 request_context() const { @@ -112,7 +109,6 @@ class CefBrowserContextImpl : public CefBrowserContext { typedef std::vector ProxyList; ProxyList proxy_list_; - scoped_refptr pref_store_; scoped_ptr pref_service_; scoped_ptr pref_proxy_config_tracker_; diff --git a/libcef/browser/browser_context_proxy.cc b/libcef/browser/browser_context_proxy.cc index 09e89f66e..f84615f91 100644 --- a/libcef/browser/browser_context_proxy.cc +++ b/libcef/browser/browser_context_proxy.cc @@ -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(); -} diff --git a/libcef/browser/browser_context_proxy.h b/libcef/browser/browser_context_proxy.h index af1d219d4..1b820f738 100644 --- a/libcef/browser/browser_context_proxy.h +++ b/libcef/browser/browser_context_proxy.h @@ -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 GetHandler() const override; @@ -70,7 +69,6 @@ class CefBrowserContextProxy : public CefBrowserContext { content::URLRequestInterceptorScopedVector request_interceptors) override; HostContentSettingsMap* GetHostContentSettingsMap() override; - PrefService* GetPrefs() override; scoped_refptr parent() const { return parent_; diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 3e1b42373..0d865c3b7 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -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. diff --git a/libcef/browser/browser_pref_store.h b/libcef/browser/browser_pref_store.h deleted file mode 100644 index 70c6c02dc..000000000 --- a/libcef/browser/browser_pref_store.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2013 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_PREF_STORE_H_ -#define CEF_LIBCEF_BROWSER_BROWSER_PREF_STORE_H_ - -#include "base/memory/scoped_ptr.h" -#include "base/prefs/testing_pref_store.h" - -class PrefService; - -class CefBrowserPrefStore : public TestingPrefStore { - public: - CefBrowserPrefStore(); - - scoped_ptr CreateService(); - - protected: - ~CefBrowserPrefStore() override; - - DISALLOW_COPY_AND_ASSIGN(CefBrowserPrefStore); -}; - -#endif // CEF_LIBCEF_BROWSER_BROWSER_PREF_STORE_H_ diff --git a/libcef/browser/browser_settings.cc b/libcef/browser/browser_settings.cc deleted file mode 100644 index 08b510d1b..000000000 --- a/libcef/browser/browser_settings.cc +++ /dev/null @@ -1,128 +0,0 @@ -// 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 - -#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; -} diff --git a/libcef/browser/browser_settings.h b/libcef/browser/browser_settings.h deleted file mode 100644 index 13972bb8c..000000000 --- a/libcef/browser/browser_settings.h +++ /dev/null @@ -1,18 +0,0 @@ -// 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_ diff --git a/libcef/browser/chrome_browser_process_stub.h b/libcef/browser/chrome_browser_process_stub.h index 287ba6867..8252a1d1e 100644 --- a/libcef/browser/chrome_browser_process_stub.h +++ b/libcef/browser/chrome_browser_process_stub.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 { public: diff --git a/libcef/browser/chrome_profile_stub.cc b/libcef/browser/chrome_profile_stub.cc new file mode 100644 index 000000000..9b2a3e507 --- /dev/null +++ b/libcef/browser/chrome_profile_stub.cc @@ -0,0 +1,222 @@ +// Copyright (c) 2015 The Chromium Embedded Framework Authors. +// Portions copyright (c) 2012 The Chromium 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/chrome_profile_stub.h" + +// Profile implementation. +// Based on chrome/browser/profiles/profile.cc. + +Profile::Profile() { +} + +Profile::~Profile() { +} + +// static +Profile* Profile::FromBrowserContext(content::BrowserContext* browser_context) { + // This is safe; this is the only implementation of the browser context. + return static_cast(browser_context); +} + +// static +Profile* Profile::FromWebUI(content::WebUI* web_ui) { + NOTIMPLEMENTED(); + return NULL; +} + +TestingProfile* Profile::AsTestingProfile() { + return NULL; +} + +ChromeZoomLevelPrefs* Profile::GetZoomLevelPrefs() { + return NULL; +} + +// static +void Profile::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { + NOTIMPLEMENTED(); +} + +std::string Profile::GetDebugName() { + NOTIMPLEMENTED(); + return std::string(); +} + +bool Profile::IsGuestSession() const { + NOTIMPLEMENTED(); + return false; +} + +bool Profile::IsSystemProfile() const { + NOTIMPLEMENTED(); + return false; +} + +bool Profile::IsNewProfile() { + NOTIMPLEMENTED(); + return false; +} + +bool Profile::IsSyncAllowed() { + NOTIMPLEMENTED(); + return false; +} + +void Profile::MaybeSendDestroyedNotification() { + NOTIMPLEMENTED(); +} + +bool ProfileCompare::operator()(Profile* a, Profile* b) const { + DCHECK(a && b); + if (a->IsSameProfile(b)) + return false; + return a->GetOriginalProfile() < b->GetOriginalProfile(); +} + +double Profile::GetDefaultZoomLevelForProfile() { + NOTIMPLEMENTED(); + return 0.0; +} + + +// ChromeProfileStub implementation. + +ChromeProfileStub::ChromeProfileStub(){ +} + +ChromeProfileStub::~ChromeProfileStub() { +} + +scoped_refptr ChromeProfileStub::GetIOTaskRunner() { + NOTIMPLEMENTED(); + return scoped_refptr(); +} + +std::string ChromeProfileStub::GetProfileUserName() const { + NOTIMPLEMENTED(); + return std::string(); +} + +Profile::ProfileType ChromeProfileStub::GetProfileType() const { + NOTIMPLEMENTED(); + return REGULAR_PROFILE; +} + +Profile* ChromeProfileStub::GetOffTheRecordProfile() { + NOTIMPLEMENTED(); + return NULL; +} + +void ChromeProfileStub::DestroyOffTheRecordProfile() { + NOTIMPLEMENTED(); +} + +bool ChromeProfileStub::HasOffTheRecordProfile() { + NOTIMPLEMENTED(); + return false; +} + +Profile* ChromeProfileStub::GetOriginalProfile() { + return this; +} + +bool ChromeProfileStub::IsSupervised() const { + NOTIMPLEMENTED(); + return false; +} + +bool ChromeProfileStub::IsChild() const { + NOTIMPLEMENTED(); + return false; +} + +bool ChromeProfileStub::IsLegacySupervised() const { + NOTIMPLEMENTED(); + return false; +} + +ExtensionSpecialStoragePolicy* + ChromeProfileStub::GetExtensionSpecialStoragePolicy() { + NOTIMPLEMENTED(); + return NULL; +} + +PrefService* ChromeProfileStub::GetOffTheRecordPrefs() { + NOTIMPLEMENTED(); + return NULL; +} + +net::URLRequestContextGetter* + ChromeProfileStub::GetRequestContextForExtensions() { + NOTIMPLEMENTED(); + return NULL; +} + +net::SSLConfigService* ChromeProfileStub::GetSSLConfigService() { + NOTIMPLEMENTED(); + return NULL; +} + +bool ChromeProfileStub::IsSameProfile(Profile* profile) { + NOTIMPLEMENTED(); + return false; +} + +base::Time ChromeProfileStub::GetStartTime() const { + NOTIMPLEMENTED(); + return base::Time(); +} + +base::FilePath ChromeProfileStub::last_selected_directory() { + NOTIMPLEMENTED(); + return base::FilePath(); +} + +void ChromeProfileStub::set_last_selected_directory( + const base::FilePath& path) { + NOTIMPLEMENTED(); +} + +PrefProxyConfigTracker* ChromeProfileStub::GetProxyConfigTracker() { + NOTIMPLEMENTED(); + return NULL; +} + +chrome_browser_net::Predictor* ChromeProfileStub::GetNetworkPredictor() { + NOTIMPLEMENTED(); + return NULL; +} + +DevToolsNetworkControllerHandle* + ChromeProfileStub::GetDevToolsNetworkControllerHandle() { + NOTIMPLEMENTED(); + return NULL; +} + +void ChromeProfileStub::ClearNetworkingHistorySince( + base::Time time, + const base::Closure& completion) { + NOTIMPLEMENTED(); +} + +GURL ChromeProfileStub::GetHomePage() { + NOTIMPLEMENTED(); + return GURL(); +} + +bool ChromeProfileStub::WasCreatedByVersionOrLater( + const std::string& version) { + NOTIMPLEMENTED(); + return false; +} + +void ChromeProfileStub::SetExitType(ExitType exit_type) { + NOTIMPLEMENTED(); +} + +Profile::ExitType ChromeProfileStub::GetLastSessionExitType() { + NOTIMPLEMENTED(); + return EXIT_NORMAL; +} diff --git a/libcef/browser/chrome_profile_stub.h b/libcef/browser/chrome_profile_stub.h new file mode 100644 index 000000000..723f9c986 --- /dev/null +++ b/libcef/browser/chrome_profile_stub.h @@ -0,0 +1,57 @@ +// Copyright (c) 2015 The Chromium Embedded Framework Authors. +// Portions copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This class gathers state related to a single user profile. + +#ifndef CEF_LIBCEF_BROWSER_CHROME_PROFILE_STUB_H_ +#define CEF_LIBCEF_BROWSER_CHROME_PROFILE_STUB_H_ + +#include "chrome/browser/profiles/profile.h" + +// This file provides a stub implementation of Chrome's Profile object for use +// as an interop layer between CEF and files that live in chrome/. + +class ChromeProfileStub : public Profile { + public: + ChromeProfileStub(); + ~ChromeProfileStub() override; + + protected: + // Profile methods. + scoped_refptr GetIOTaskRunner() override; + std::string GetProfileUserName() const override; + ProfileType GetProfileType() const override; + Profile* GetOffTheRecordProfile() override; + void DestroyOffTheRecordProfile() override; + bool HasOffTheRecordProfile() override; + Profile* GetOriginalProfile() override; + bool IsSupervised() const override; + bool IsChild() const override; + bool IsLegacySupervised() const override; + ExtensionSpecialStoragePolicy* + GetExtensionSpecialStoragePolicy() override; + PrefService* GetOffTheRecordPrefs() override; + net::URLRequestContextGetter* GetRequestContextForExtensions() override; + net::SSLConfigService* GetSSLConfigService() override; + bool IsSameProfile(Profile* profile) override; + base::Time GetStartTime() const override; + base::FilePath last_selected_directory() override; + void set_last_selected_directory(const base::FilePath& path) override; + PrefProxyConfigTracker* GetProxyConfigTracker() override; + chrome_browser_net::Predictor* GetNetworkPredictor() override; + DevToolsNetworkControllerHandle* + GetDevToolsNetworkControllerHandle() override; + void ClearNetworkingHistorySince(base::Time time, + const base::Closure& completion) override; + GURL GetHomePage() override; + bool WasCreatedByVersionOrLater(const std::string& version) override; + void SetExitType(ExitType exit_type) override; + ExitType GetLastSessionExitType() override; + + private: + DISALLOW_COPY_AND_ASSIGN(ChromeProfileStub); +}; + +#endif // CEF_LIBCEF_BROWSER_CHROME_PROFILE_STUB_H_ diff --git a/libcef/browser/content_browser_client.cc b/libcef/browser/content_browser_client.cc index 3863a4b45..162642ed8 100644 --- a/libcef/browser/content_browser_client.cc +++ b/libcef/browser/content_browser_client.cc @@ -10,7 +10,6 @@ #include "libcef/browser/browser_host_impl.h" #include "libcef/browser/browser_main.h" #include "libcef/browser/browser_message_filter.h" -#include "libcef/browser/browser_settings.h" #include "libcef/browser/chrome_scheme_handler.h" #include "libcef/browser/context.h" #include "libcef/browser/devtools_delegate.h" @@ -20,6 +19,7 @@ #include "libcef/browser/pepper/browser_pepper_host_factory.h" #include "libcef/browser/plugins/plugin_info_message_filter.h" #include "libcef/browser/plugins/plugin_service_filter.h" +#include "libcef/browser/prefs/renderer_prefs.h" #include "libcef/browser/printing/printing_message_filter.h" #include "libcef/browser/resource_dispatcher_host_delegate.h" #include "libcef/browser/speech_recognition_manager_delegate.h" @@ -1004,24 +1004,10 @@ void CefContentBrowserClient::ResourceDispatcherHostCreated() { void CefContentBrowserClient::OverrideWebkitPrefs( content::RenderViewHost* rvh, content::WebPreferences* prefs) { - const base::CommandLine* command_line = - base::CommandLine::ForCurrentProcess(); + renderer_prefs::PopulateWebPreferences(rvh, *prefs); - CefRefPtr browser = - extensions::GetOwnerBrowserForHost(rvh); - if (browser.get()) { - // Populate WebPreferences based on CefBrowserSettings. - BrowserToWebSettings(browser->settings(), *prefs); - } - - prefs->base_background_color = GetBaseBackgroundColor(browser); if (rvh->GetView()) rvh->GetView()->SetBackgroundColor(prefs->base_background_color); - - prefs->asynchronous_spell_checking_enabled = true; - // Auto-correct does not work in combination with the unified text checker. - prefs->unified_textchecker_enabled = - !command_line->HasSwitch(switches::kEnableSpellingAutoCorrect); } void CefContentBrowserClient::BrowserURLHandlerCreated( @@ -1161,27 +1147,3 @@ CefContentBrowserClient::browser_context() const { CefDevToolsDelegate* CefContentBrowserClient::devtools_delegate() const { return browser_main_parts_->devtools_delegate(); } - -// static -SkColor CefContentBrowserClient::GetBaseBackgroundColor( - CefRefPtr browser) { - if (browser.get()) { - const CefBrowserSettings& browser_settings = browser->settings(); - if (CefColorGetA(browser_settings.background_color) > 0) { - return SkColorSetRGB( - CefColorGetR(browser_settings.background_color), - CefColorGetG(browser_settings.background_color), - CefColorGetB(browser_settings.background_color)); - } - } - - const CefSettings& settings = CefContext::Get()->settings(); - if (CefColorGetA(settings.background_color) > 0) { - return SkColorSetRGB( - CefColorGetR(settings.background_color), - CefColorGetG(settings.background_color), - CefColorGetB(settings.background_color)); - } - - return SK_ColorWHITE; -} diff --git a/libcef/browser/content_browser_client.h b/libcef/browser/content_browser_client.h index ec0a55162..2720ca1c4 100644 --- a/libcef/browser/content_browser_client.h +++ b/libcef/browser/content_browser_client.h @@ -170,8 +170,6 @@ class CefContentBrowserClient : public content::ContentBrowserClient { CefDevToolsDelegate* devtools_delegate() const; private: - static SkColor GetBaseBackgroundColor(CefRefPtr browser); - CefBrowserMainParts* browser_main_parts_; scoped_ptr plugin_service_filter_; diff --git a/libcef/browser/context.cc b/libcef/browser/context.cc index 263a9d1c9..8bd0a104c 100644 --- a/libcef/browser/context.cc +++ b/libcef/browser/context.cc @@ -360,6 +360,9 @@ void CefContext::PopulateRequestContextSettings( settings->persist_session_cookies = settings_.persist_session_cookies || command_line->HasSwitch(switches::kPersistSessionCookies); + settings->persist_user_preferences = + settings_.persist_user_preferences || + command_line->HasSwitch(switches::kPersistUserPreferences); settings->ignore_certificate_errors = settings_.ignore_certificate_errors || command_line->HasSwitch(switches::kIgnoreCertificateErrors); diff --git a/libcef/browser/extensions/browser_context_keyed_service_factories.cc b/libcef/browser/extensions/browser_context_keyed_service_factories.cc index 698521ea3..84f53ed19 100644 --- a/libcef/browser/extensions/browser_context_keyed_service_factories.cc +++ b/libcef/browser/extensions/browser_context_keyed_service_factories.cc @@ -6,12 +6,14 @@ #include "libcef/browser/extensions/api/streams_private/streams_private_api.h" +#include "chrome/browser/ui/prefs/prefs_tab_helper.h" #include "extensions/browser/renderer_startup_helper.h" namespace extensions { namespace cef { void EnsureBrowserContextKeyedServiceFactoriesBuilt() { + PrefsTabHelper::GetServiceInstance(); RendererStartupHelperFactory::GetInstance(); StreamsPrivateAPI::GetFactoryInstance(); } diff --git a/libcef/browser/extensions/extensions_api_client.cc b/libcef/browser/extensions/extensions_api_client.cc index 8bbf818f7..5a5e439a0 100644 --- a/libcef/browser/extensions/extensions_api_client.cc +++ b/libcef/browser/extensions/extensions_api_client.cc @@ -11,6 +11,7 @@ #include "libcef/browser/extensions/pdf_web_contents_helper_client.h" #include "libcef/browser/printing/print_view_manager.h" +#include "chrome/browser/ui/prefs/prefs_tab_helper.h" #include "components/pdf/browser/pdf_web_contents_helper.h" namespace extensions { @@ -33,6 +34,7 @@ CefExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate( void CefExtensionsAPIClient::AttachWebContentsHelpers( content::WebContents* web_contents) const { + PrefsTabHelper::CreateForWebContents(web_contents); printing::PrintViewManager::CreateForWebContents(web_contents); pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( web_contents, diff --git a/libcef/browser/browser_pref_store.cc b/libcef/browser/prefs/browser_prefs.cc similarity index 69% rename from libcef/browser/browser_pref_store.cc rename to libcef/browser/prefs/browser_prefs.cc index 1d9e0abb3..8cfbf4553 100644 --- a/libcef/browser/browser_pref_store.cc +++ b/libcef/browser/prefs/browser_prefs.cc @@ -2,15 +2,20 @@ // 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_pref_store.h" +#include "libcef/browser/prefs/browser_prefs.h" #include "libcef/browser/media_capture_devices_dispatcher.h" +#include "libcef/browser/prefs/renderer_prefs.h" #include "libcef/common/cef_switches.h" #include "base/command_line.h" +#include "base/files/file_path.h" +#include "base/prefs/json_pref_store.h" +#include "base/prefs/pref_filter.h" +#include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/prefs/pref_service_factory.h" -#include "base/prefs/pref_registry_simple.h" +#include "base/prefs/testing_pref_store.h" #include "base/strings/string_number_conversions.h" #include "base/values.h" #include "chrome/browser/prefs/command_line_pref_store.h" @@ -20,10 +25,13 @@ #include "components/pref_registry/pref_registry_syncable.h" #include "components/proxy_config/pref_proxy_config_tracker_impl.h" #include "components/proxy_config/proxy_config_dictionary.h" +#include "content/public/browser/browser_thread.h" #include "extensions/browser/extension_prefs.h" #include "grit/cef_strings.h" #include "ui/base/l10n/l10n_util.h" +namespace browser_prefs { + namespace { // A helper function for registering localized values. @@ -73,31 +81,56 @@ void RegisterLocalizedValue(PrefRegistrySimple* registry, } // namespace -CefBrowserPrefStore::CefBrowserPrefStore() { -} +const char kUserPrefsFileName[] = "UserPrefs.json"; -scoped_ptr CefBrowserPrefStore::CreateService() { +scoped_ptr CreatePrefService(const base::FilePath& pref_path) { const base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::PrefServiceFactory factory; - factory.set_command_line_prefs( - new CommandLinePrefStore(command_line)); - factory.set_user_prefs(this); + // Used to store command-line preferences, most of which will be evaluated in + // the CommandLinePrefStore constructor. Preferences set in this manner cannot + // be overridden by the user. + scoped_refptr command_line_pref_store( + new CommandLinePrefStore(command_line)); + renderer_prefs::SetCommandLinePrefDefaults(command_line_pref_store.get()); + factory.set_command_line_prefs(command_line_pref_store); + + // Used to store user preferences. + scoped_refptr user_pref_store; + if (!pref_path.empty()) { + // Store preferences on disk. + scoped_refptr task_runner = + JsonPrefStore::GetTaskRunnerForFile( + pref_path, + content::BrowserThread::GetBlockingPool()); + scoped_refptr json_pref_store = + new JsonPrefStore(pref_path, task_runner, scoped_ptr()); + factory.set_user_prefs(json_pref_store.get()); + } else { + // Store preferences in memory. + scoped_refptr testing_pref_store = new TestingPrefStore(); + testing_pref_store->SetInitializationCompleted(); + factory.set_user_prefs(testing_pref_store.get()); + } + + // Registry that will be populated with all known preferences. Preferences + // are registered with default values that may be changed via a *PrefStore. scoped_refptr registry( new user_prefs::PrefRegistrySyncable()); - // Default settings. + // Default preferences. CefMediaCaptureDevicesDispatcher::RegisterPrefs(registry.get()); PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get()); extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get()); HostContentSettingsMap::RegisterProfilePrefs(registry.get()); + renderer_prefs::RegisterProfilePrefs(registry.get()); - // Print settings. + // Print preferences. registry->RegisterBooleanPref(prefs::kPrintingEnabled, true); - // Spell checking settings. + // Spell checking preferences. // Based on SpellcheckServiceFactory::RegisterProfilePrefs. registry->RegisterListPref(prefs::kSpellCheckDictionaries, new base::ListValue); @@ -119,18 +152,18 @@ scoped_ptr CefBrowserPrefStore::CreateService() { registry->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, command_line->HasSwitch(switches::kEnableSpellingAutoCorrect)); - // Pepper flash settings. + // Pepper flash preferences. // Based on DeviceIDFetcher::RegisterProfilePrefs. registry->RegisterBooleanPref(prefs::kEnableDRM, false); registry->RegisterStringPref(prefs::kDRMSalt, ""); - // Plugin settings. + // Plugin preferences. // Based on chrome::RegisterBrowserUserPrefs. registry->RegisterBooleanPref(prefs::kPluginsAllowOutdated, false); registry->RegisterBooleanPref(prefs::kPluginsAlwaysAuthorize, false); if (command_line->HasSwitch(switches::kEnablePreferenceTesting)) { - // Register preferences used with unit tests. + // Preferences used with unit tests. registry->RegisterBooleanPref("test.bool", true); registry->RegisterIntegerPref("test.int", 2); registry->RegisterDoublePref("test.double", 5.0); @@ -139,8 +172,8 @@ scoped_ptr CefBrowserPrefStore::CreateService() { registry->RegisterDictionaryPref("test.dict"); } + // Build the PrefService that manages the PrefRegistry and PrefStores. return factory.Create(registry.get()); } -CefBrowserPrefStore::~CefBrowserPrefStore() { -} +} // namespace browser_prefs diff --git a/libcef/browser/prefs/browser_prefs.h b/libcef/browser/prefs/browser_prefs.h new file mode 100644 index 000000000..77fbe592e --- /dev/null +++ b/libcef/browser/prefs/browser_prefs.h @@ -0,0 +1,26 @@ +// Copyright (c) 2013 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_PREFS_BROWSER_PREFS_H_ +#define CEF_LIBCEF_BROWSER_PREFS_BROWSER_PREFS_H_ + +#include "base/memory/scoped_ptr.h" + +class PrefService; + +namespace base { +class FilePath; +} + +namespace browser_prefs { + +// Name for the user prefs JSON file. +extern const char kUserPrefsFileName[]; + +// Create the PrefService used to manage pref registration and storage. +scoped_ptr CreatePrefService(const base::FilePath& pref_path); + +} // namespace browser_prefs + +#endif // CEF_LIBCEF_BROWSER_PREFS_BROWSER_PREFS_H_ diff --git a/libcef/browser/prefs/renderer_prefs.cc b/libcef/browser/prefs/renderer_prefs.cc new file mode 100644 index 000000000..9a10a8e0c --- /dev/null +++ b/libcef/browser/prefs/renderer_prefs.cc @@ -0,0 +1,393 @@ +// 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/prefs/renderer_prefs.h" + +#include + +#include "libcef/browser/browser_context.h" +#include "libcef/browser/context.h" +#include "libcef/browser/extensions/browser_extensions_util.h" +#include "libcef/common/cef_switches.h" +#include "libcef/common/extensions/extensions_util.h" + +#include "base/command_line.h" +#include "base/prefs/pref_service.h" +#include "base/prefs/pref_store.h" +#include "base/values.h" +#include "chrome/browser/accessibility/animation_policy_prefs.h" +#include "chrome/browser/character_encoding.h" +#include "chrome/browser/defaults.h" +#include "chrome/browser/extensions/extension_webkit_preferences.h" +#include "chrome/browser/font_family_cache.h" +#include "chrome/browser/prefs/command_line_pref_store.h" +#include "chrome/browser/ui/prefs/prefs_tab_helper.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" +#include "components/pref_registry/pref_registry_syncable.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/site_instance.h" +#include "content/public/browser/web_contents.h" +#include "content/public/common/web_preferences.h" +#include "extensions/browser/extension_registry.h" +#include "extensions/browser/view_type_utils.h" +#include "extensions/common/constants.h" + +namespace renderer_prefs { + +namespace { + +// Set default values based on CEF command-line flags for preferences that are +// not available via the PrefService. Chromium command-line flags should not +// exist for these preferences. +void SetDefaultPrefs(content::WebPreferences& web) { + const base::CommandLine* command_line = + base::CommandLine::ForCurrentProcess(); + + web.allow_scripts_to_close_windows = + !command_line->HasSwitch(switches::kDisableJavascriptCloseWindows); + web.javascript_can_access_clipboard = + !command_line->HasSwitch(switches::kDisableJavascriptAccessClipboard); + web.caret_browsing_enabled = + command_line->HasSwitch(switches::kEnableCaretBrowsing); + web.allow_universal_access_from_file_urls = + command_line->HasSwitch(switches::kAllowUniversalAccessFromFileUrls); + web.shrinks_standalone_images_to_fit = + command_line->HasSwitch(switches::kImageShrinkStandaloneToFit); + web.text_areas_are_resizable = + !command_line->HasSwitch(switches::kDisableTextAreaResize); + + web.asynchronous_spell_checking_enabled = true; + // Auto-correct does not work in combination with the unified text checker. + web.unified_textchecker_enabled = + !command_line->HasSwitch(switches::kEnableSpellingAutoCorrect); +} + +// Chrome preferences. +// Should match ChromeContentBrowserClient::OverrideWebkitPrefs. +void SetChromePrefs(CefBrowserContext* profile, + content::WebPreferences& web) { + PrefService* prefs = profile->GetPrefs(); + + // Fill per-script font preferences. + FontFamilyCache::FillFontFamilyMap(profile, + prefs::kWebKitStandardFontFamilyMap, + &web.standard_font_family_map); + FontFamilyCache::FillFontFamilyMap(profile, + prefs::kWebKitFixedFontFamilyMap, + &web.fixed_font_family_map); + FontFamilyCache::FillFontFamilyMap(profile, + prefs::kWebKitSerifFontFamilyMap, + &web.serif_font_family_map); + FontFamilyCache::FillFontFamilyMap(profile, + prefs::kWebKitSansSerifFontFamilyMap, + &web.sans_serif_font_family_map); + FontFamilyCache::FillFontFamilyMap(profile, + prefs::kWebKitCursiveFontFamilyMap, + &web.cursive_font_family_map); + FontFamilyCache::FillFontFamilyMap(profile, + prefs::kWebKitFantasyFontFamilyMap, + &web.fantasy_font_family_map); + FontFamilyCache::FillFontFamilyMap(profile, + prefs::kWebKitPictographFontFamilyMap, + &web.pictograph_font_family_map); + + web.default_font_size = + prefs->GetInteger(prefs::kWebKitDefaultFontSize); + web.default_fixed_font_size = + prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); + web.minimum_font_size = + prefs->GetInteger(prefs::kWebKitMinimumFontSize); + web.minimum_logical_font_size = + prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); + + web.default_encoding = prefs->GetString(prefs::kDefaultCharset); + + web.javascript_can_open_windows_automatically = + prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically); + web.dom_paste_enabled = + prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); + web.tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); + + if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) + web.javascript_enabled = false; + if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) + web.web_security_enabled = false; + if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) + web.plugins_enabled = false; + web.loads_images_automatically = + prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); + + if (prefs->GetBoolean(prefs::kDisable3DAPIs)) + web.experimental_webgl_enabled = false; + + web.allow_displaying_insecure_content = + prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent); + web.allow_running_insecure_content = + prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); + + web.password_echo_enabled = browser_defaults::kPasswordEchoEnabled; + + web.uses_universal_detector = + prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector); + web.text_areas_are_resizable = + prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); + web.hyperlink_auditing_enabled = + prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); + + if (extensions::ExtensionsEnabled()) { + std::string image_animation_policy = + prefs->GetString(prefs::kAnimationPolicy); + if (image_animation_policy == kAnimationPolicyOnce) + web.animation_policy = + content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE; + else if (image_animation_policy == kAnimationPolicyNone) + web.animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION; + else + web.animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED; + } + + // Make sure we will set the default_encoding with canonical encoding name. + web.default_encoding = + CharacterEncoding::GetCanonicalEncodingNameByAliasName( + web.default_encoding); + if (web.default_encoding.empty()) { + prefs->ClearPref(prefs::kDefaultCharset); + web.default_encoding = prefs->GetString(prefs::kDefaultCharset); + } + DCHECK(!web.default_encoding.empty()); + + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnablePotentiallyAnnoyingSecurityFeatures)) { + web.disable_reading_from_canvas = true; + web.strict_mixed_content_checking = true; + web.strict_powerful_feature_restrictions = true; + } +} + +// Extension preferences. +// Should match ChromeContentBrowserClientExtensionsPart::OverrideWebkitPrefs. +void SetExtensionPrefs(content::RenderViewHost* rvh, + content::WebPreferences& web) { + if (!extensions::ExtensionsEnabled()) + return; + + const extensions::ExtensionRegistry* registry = + extensions::ExtensionRegistry::Get( + rvh->GetProcess()->GetBrowserContext()); + if (!registry) + return; + + // Note: it's not possible for kExtensionsScheme to change during the lifetime + // of the process. + // + // Ensure that we are only granting extension preferences to URLs with the + // correct scheme. Without this check, chrome-guest:// schemes used by webview + // tags as well as hosts that happen to match the id of an installed extension + // would get the wrong preferences. + const GURL& site_url = rvh->GetSiteInstance()->GetSiteURL(); + if (!site_url.SchemeIs(extensions::kExtensionScheme)) + return; + + content::WebContents* web_contents = + content::WebContents::FromRenderViewHost(rvh); + extensions::ViewType view_type = extensions::GetViewType(web_contents); + const extensions::Extension* extension = + registry->enabled_extensions().GetByID(site_url.host()); + extension_webkit_preferences::SetPreferences(extension, view_type, &web); +} + +// 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; + +// Set preferences based on CefBrowserSettings. +void SetCefPrefs(const CefBrowserSettings& cef, + content::WebPreferences& 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; +} + +void SetString(CommandLinePrefStore* prefs, + const std::string& key, + const std::string& value) { + prefs->SetValue( + key, + make_scoped_ptr(new base::StringValue(value)), + WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); +} + +void SetBool(CommandLinePrefStore* prefs, + const std::string& key, + bool value) { + prefs->SetValue(key, + make_scoped_ptr(new base::FundamentalValue(value)), + WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); +} + +SkColor GetBaseBackgroundColor(CefRefPtr browser) { + if (browser.get()) { + const CefBrowserSettings& browser_settings = browser->settings(); + if (CefColorGetA(browser_settings.background_color) > 0) { + return SkColorSetRGB( + CefColorGetR(browser_settings.background_color), + CefColorGetG(browser_settings.background_color), + CefColorGetB(browser_settings.background_color)); + } + } + + const CefSettings& settings = CefContext::Get()->settings(); + if (CefColorGetA(settings.background_color) > 0) { + return SkColorSetRGB( + CefColorGetR(settings.background_color), + CefColorGetG(settings.background_color), + CefColorGetB(settings.background_color)); + } + + return SK_ColorWHITE; +} + +} // namespace + +void SetCommandLinePrefDefaults(CommandLinePrefStore* prefs) { + const base::CommandLine* command_line = + base::CommandLine::ForCurrentProcess(); + + if (command_line->HasSwitch(switches::kDefaultEncoding)) { + SetString(prefs, prefs::kDefaultCharset, + command_line->GetSwitchValueASCII(switches::kDefaultEncoding)); + } + + if (command_line->HasSwitch(switches::kDisableJavascriptOpenWindows)) + SetBool(prefs, prefs::kWebKitJavascriptCanOpenWindowsAutomatically, false); + if (command_line->HasSwitch(switches::kDisableJavascriptDomPaste)) + SetBool(prefs, prefs::kWebKitDomPasteEnabled, false); + if (command_line->HasSwitch(switches::kDisableImageLoading)) + SetBool(prefs, prefs::kWebKitLoadsImagesAutomatically, false); + if (command_line->HasSwitch(switches::kDisableTabToLinks)) + SetBool(prefs, prefs::kWebkitTabsToLinks, false); +} + +void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { + PrefsTabHelper::RegisterProfilePrefs(registry); + RegisterAnimationPolicyPrefs(registry); + + // From chrome::RegisterBrowserUserPrefs. + registry->RegisterBooleanPref( + prefs::kEnableDoNotTrack, + false, + user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); +#if defined(ENABLE_WEBRTC) + registry->RegisterBooleanPref(prefs::kWebRTCMultipleRoutesEnabled, true); + registry->RegisterBooleanPref(prefs::kWebRTCNonProxiedUdpEnabled, true); +#endif +#if !defined(OS_MACOSX) + registry->RegisterBooleanPref(prefs::kFullscreenAllowed, true); +#endif + + // From ChromeContentBrowserClient::RegisterProfilePrefs. + registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false); + registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true); + + // From Profile::RegisterProfilePrefs. + registry->RegisterDictionaryPref(prefs::kPartitionDefaultZoomLevel); + registry->RegisterDictionaryPref(prefs::kPartitionPerHostZoomLevels); +} + +void PopulateWebPreferences(content::RenderViewHost* rvh, + content::WebPreferences& web) { + CefRefPtr browser = + extensions::GetOwnerBrowserForHost(rvh); + + // Set defaults for preferences that are not handled by PrefService. + SetDefaultPrefs(web); + + // Set preferences based on the context's PrefService. + if (browser.get()) { + CefBrowserContext* profile = + static_cast( + browser->web_contents()->GetBrowserContext()); + SetChromePrefs(profile, web); + } + + // Set preferences based on the extension. + SetExtensionPrefs(rvh, web); + + // Set preferences based on CefBrowserSettings. + if (browser.get()) + SetCefPrefs(browser->settings(), web); + + // Set the background color for the WebView. + web.base_background_color = GetBaseBackgroundColor(browser); +} + +} // namespace renderer_prefs diff --git a/libcef/browser/prefs/renderer_prefs.h b/libcef/browser/prefs/renderer_prefs.h new file mode 100644 index 000000000..67c6eb0f8 --- /dev/null +++ b/libcef/browser/prefs/renderer_prefs.h @@ -0,0 +1,39 @@ +// 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_PREFS_RENDERER_PREFS_H_ +#define CEF_LIBCEF_BROWSER_PREFS_RENDERER_PREFS_H_ +#pragma once + +#include "include/internal/cef_types_wrappers.h" + +class CommandLinePrefStore; + +namespace content { +class RenderViewHost; +struct WebPreferences; +} + +namespace user_prefs { +class PrefRegistrySyncable; +} + +namespace renderer_prefs { + +// Register additional renderer-related preferences. +void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); + +// Set default values based on CEF command-line flags for preferences that are +// available via the PrefService. Chromium command-line flags should not exist +// for these preferences. +void SetCommandLinePrefDefaults(CommandLinePrefStore* prefs); + +// Populate WebPreferences based on a combination of command-line values, +// PrefService and CefBrowserSettings. +void PopulateWebPreferences(content::RenderViewHost* rvh, + content::WebPreferences& web); + +} // namespace renderer_prefs + +#endif // CEF_LIBCEF_BROWSER_PREFS_RENDERER_PREFS_H_ diff --git a/libcef/common/cef_switches.cc b/libcef/common/cef_switches.cc index 65d61b8d2..febef8828 100644 --- a/libcef/common/cef_switches.cc +++ b/libcef/common/cef_switches.cc @@ -73,6 +73,9 @@ const char kDisableTabToLinks[] = "disable-tab-to-links"; // Persist session cookies. const char kPersistSessionCookies[] = "persist-session-cookies"; +// Persist user preferences. +const char kPersistUserPreferences[] = "persist-user-preferences"; + // Enable media (WebRTC audio/video) streaming. const char kEnableMediaStream[] = "enable-media-stream"; diff --git a/libcef/common/cef_switches.h b/libcef/common/cef_switches.h index 589c4621e..3cf1d69df 100644 --- a/libcef/common/cef_switches.h +++ b/libcef/common/cef_switches.h @@ -34,6 +34,7 @@ extern const char kImageShrinkStandaloneToFit[]; extern const char kDisableTextAreaResize[]; extern const char kDisableTabToLinks[]; extern const char kPersistSessionCookies[]; +extern const char kPersistUserPreferences[]; extern const char kEnableMediaStream[]; extern const char kEnableSpeechInput[]; extern const char kEnableProfanityFilter[]; diff --git a/libcef/common/main_delegate.cc b/libcef/common/main_delegate.cc index 45c5cb593..e3fe5fe8e 100644 --- a/libcef/common/main_delegate.cc +++ b/libcef/common/main_delegate.cc @@ -22,6 +22,7 @@ #include "base/strings/string_util.h" #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" +#include "chrome/browser/browser_process.h" #include "chrome/child/pdf_child_init.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" @@ -682,6 +683,9 @@ void CefMainDelegate::InitializeResourceBundle() { locale, &content_client_, ui::ResourceBundle::LOAD_COMMON_RESOURCES); + if (!loaded_locale.empty() && g_browser_process) + g_browser_process->SetApplicationLocale(loaded_locale); + ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); if (!content_client_.pack_loading_disabled()) { diff --git a/libcef/resources/cef_strings.grd b/libcef/resources/cef_strings.grd index bbb8e8520..ad5fd6f4a 100644 --- a/libcef/resources/cef_strings.grd +++ b/libcef/resources/cef_strings.grd @@ -402,6 +402,84 @@ need to be translated for each locale.--> Hide This Plugin + + + + + en-US,en + + + + windows-1252 + + + + false + + + + windows-1252 + + + $1Japanese ($2Shift_JIS) + + + Unicode + + + Western + + + Chinese Simplified + + + Chinese Traditional + + + Korean + + + Japanese + + + Thai + + + Central European + + + Cyrillic + + + Greek + + + Baltic + + + South European + + + Nordic + + + Celtic + + + Romanian + + + Turkish + + + Arabic + + + Hebrew + + + Vietnamese + diff --git a/patch/patch.cfg b/patch/patch.cfg index a03a369fe..41fda76d5 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -218,4 +218,17 @@ patches = [ 'name': 'extension_process_policy_543230', 'path': '../chrome/common/extensions/', }, + { + # Fix missing check for defined(ENABLE_THEMES) in + # renderer_preferences_util.cc on Linux. + # https://code.google.com/p/chromium/issues/detail?id=545103 + 'name': 'renderer_preferences_util_545103', + 'path': '../chrome/browser/', + }, + { + # Expose the FontFamilyCache UserData key. + # https://bitbucket.org/chromiumembedded/cef/issues/1501 + 'name': 'font_family_cache_1501', + 'path': '../chrome/browser/', + }, ] diff --git a/patch/patches/font_family_cache_1501.patch b/patch/patches/font_family_cache_1501.patch new file mode 100644 index 000000000..dbf0daefe --- /dev/null +++ b/patch/patches/font_family_cache_1501.patch @@ -0,0 +1,13 @@ +diff --git font_family_cache.h font_family_cache.h +index d5ff699..71fa27b 100644 +--- font_family_cache.h ++++ font_family_cache.h +@@ -19,6 +19,8 @@ class Profile; + + FORWARD_DECLARE_TEST(FontFamilyCacheTest, Caching); + ++extern const char kFontFamilyCacheKey[]; ++ + // Caches font family preferences associated with a PrefService. This class + // relies on the assumption that each concatenation of map_name + '.' + script + // is a unique string. It also relies on the assumption that the (const char*) diff --git a/patch/patches/renderer_preferences_util_545103.patch b/patch/patches/renderer_preferences_util_545103.patch new file mode 100644 index 000000000..383047f51 --- /dev/null +++ b/patch/patches/renderer_preferences_util_545103.patch @@ -0,0 +1,24 @@ +diff --git renderer_preferences_util.cc renderer_preferences_util.cc +index f7628fe..e2f1451 100644 +--- renderer_preferences_util.cc ++++ renderer_preferences_util.cc +@@ -25,7 +25,8 @@ + #include "ui/views/controls/textfield/textfield.h" + #endif + +-#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) ++#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) && \ ++ defined(ENABLE_THEMES) + #include "chrome/browser/themes/theme_service.h" + #include "chrome/browser/themes/theme_service_factory.h" + #include "ui/views/linux_ui/linux_ui.h" +@@ -81,7 +82,8 @@ void UpdateFromSystemSettings(content::RendererPreferences* prefs, + prefs->caret_blink_interval = views::Textfield::GetCaretBlinkMs() / 1000.0; + #endif + +-#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) ++#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS) && \ ++ defined(ENABLE_THEMES) + views::LinuxUI* linux_ui = views::LinuxUI::instance(); + if (linux_ui) { + if (ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme()) { diff --git a/tests/cefclient/browser/preferences_test.cc b/tests/cefclient/browser/preferences_test.cc index eec12beda..7cf9c928a 100644 --- a/tests/cefclient/browser/preferences_test.cc +++ b/tests/cefclient/browser/preferences_test.cc @@ -196,6 +196,11 @@ class Handler : public CefMessageRouterBrowserSide::Handler { command_line->HasSwitch("proxy-pac-url") || command_line->HasSwitch("proxy-server")); + // If allow running insecure content is enabled via the command-line then it + // cannot be enabled via preferences. + dict->SetBool("allow_running_insecure_content", + command_line->HasSwitch("allow-running-insecure-content")); + // Serialize the state to JSON and return to the JavaScript caller. callback->Success(GetJSON(dict)); } diff --git a/tests/cefclient/resources/preferences.html b/tests/cefclient/resources/preferences.html index 2cc7f04e2..168d9a654 100644 --- a/tests/cefclient/resources/preferences.html +++ b/tests/cefclient/resources/preferences.html @@ -32,6 +32,12 @@ Enable spell checking + + +
+ Allow running insecure content + +
@@ -214,6 +220,19 @@ response.browser.enable_spellchecking; } + // Web content settings. + if (preferences_state.allow_running_insecure_content) { + // Cannot disable running insecure content when enabled via the + // command-line. + document.getElementById("allow_running_insecure_content").checked = + true; + document.getElementById("allow_running_insecure_content").disabled = + true; + } else { + document.getElementById("allow_running_insecure_content").checked = + response.webkit.webprefs.allow_running_insecure_content; + } + // Proxy settings. document.getElementById("proxy_type").value = response.proxy.mode; @@ -252,6 +271,16 @@ document.getElementById("enable_spellchecking").checked; } + // Web content settings. + if (!preferences_state.allow_running_insecure_content) { + has_preferences = true; + + preferences.webkit = {}; + preferences.webkit.webprefs = {}; + preferences.webkit.webprefs.allow_running_insecure_content = + document.getElementById("allow_running_insecure_content").checked; + } + // Proxy settings. if (!preferences_state.proxy_configured) { has_preferences = true; diff --git a/tests/unittests/os_rendering_unittest.cc b/tests/unittests/os_rendering_unittest.cc index 3261e415c..a558bf561 100644 --- a/tests/unittests/os_rendering_unittest.cc +++ b/tests/unittests/os_rendering_unittest.cc @@ -692,11 +692,13 @@ class OSRTestHandler : public RoutingTestHandler, // first pixel of border #if defined(OS_MACOSX) EXPECT_EQ(0xff5d99d6, *(reinterpret_cast(buffer))); -#else +#elif defined(OS_LINUX) || defined(OS_WIN) if (scale_factor_ == 1.0f) - EXPECT_EQ(0xffd69c2b, *(reinterpret_cast(buffer))); + EXPECT_EQ(0xff6497ea, *(reinterpret_cast(buffer))); else if (scale_factor_ == 2.0f) - EXPECT_EQ(0xffe59700, *(reinterpret_cast(buffer))); + EXPECT_EQ(0xff4d90fe, *(reinterpret_cast(buffer))); +#else +#error "Unsupported platform" #endif EXPECT_EQ(expanded_select_rect.width, width); EXPECT_EQ(expanded_select_rect.height, height); diff --git a/tools/repack_locales.py b/tools/repack_locales.py index 12723ffe6..d83a57819 100644 --- a/tools/repack_locales.py +++ b/tools/repack_locales.py @@ -54,6 +54,11 @@ def calc_inputs(locale): """Determine the files that need processing for the given locale.""" inputs = [] + #e.g. + # '<(SHARED_INTERMEDIATE_DIR)/chrome/platform_locale_settings_da.pak' + inputs.append(os.path.join(SHARE_INT_DIR, 'chrome', + 'platform_locale_settings_%s.pak' % locale)) + #e.g. # '<(SHARED_INTERMEDIATE_DIR)/components/strings/components_strings_da.pak' inputs.append(os.path.join(SHARE_INT_DIR, 'components', 'strings',