Remove HostContentSettingsMap usage due to UI thread blockage when creating multiple request contexts (issue #1734)

This commit is contained in:
Marshall Greenblatt
2015-10-14 11:14:05 -04:00
parent 3e9c8df55f
commit 4737056482
8 changed files with 19 additions and 101 deletions

View File

@@ -104,7 +104,6 @@
// CefURLRequestContextGetter* destruction. // CefURLRequestContextGetter* destruction.
*/ */
class HostContentSettingsMap;
class PrefService; class PrefService;
namespace extensions { namespace extensions {
@@ -145,9 +144,6 @@ class CefBrowserContext
content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) = 0; content::URLRequestInterceptorScopedVector request_interceptors) = 0;
// Settings for plugins and extensions.
virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0;
// Preferences. // Preferences.
virtual PrefService* GetPrefs() = 0; virtual PrefService* GetPrefs() = 0;

View File

@@ -13,17 +13,13 @@
#include "libcef/browser/permission_manager.h" #include "libcef/browser/permission_manager.h"
#include "libcef/browser/ssl_host_state_delegate.h" #include "libcef/browser/ssl_host_state_delegate.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h" #include "libcef/common/extensions/extensions_util.h"
#include "base/command_line.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "chrome/browser/net/proxy_service_factory.h" #include "chrome/browser/net/proxy_service_factory.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/guest_view/browser/guest_view_manager.h" #include "components/guest_view/browser/guest_view_manager.h"
#include "content/public/browser/download_manager.h" #include "content/public/browser/download_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
@@ -133,9 +129,6 @@ CefBrowserContextImpl::CefBrowserContextImpl(
CefBrowserContextImpl::~CefBrowserContextImpl() { CefBrowserContextImpl::~CefBrowserContextImpl() {
pref_proxy_config_tracker_->DetachFromPrefService(); pref_proxy_config_tracker_->DetachFromPrefService();
if (host_content_settings_map_.get())
host_content_settings_map_->ShutdownOnUIThread();
// Delete the download manager delegate here because otherwise we'll crash // Delete the download manager delegate here because otherwise we'll crash
// when it's accessed from the content::BrowserContext destructor. // when it's accessed from the content::BrowserContext destructor.
if (download_manager_delegate_.get()) if (download_manager_delegate_.get())
@@ -348,35 +341,6 @@ net::URLRequestContextGetter*
return NULL; return NULL;
} }
HostContentSettingsMap* CefBrowserContextImpl::GetHostContentSettingsMap() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!host_content_settings_map_.get()) {
// The |incognito| argument is intentionally set to false as it otherwise
// limits the types of values that can be stored in the settings map (for
// example, default values set via DefaultProvider::SetWebsiteSetting).
host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
// Change the default plugin policy.
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
const std::string& plugin_policy_str =
command_line->GetSwitchValueASCII(switches::kPluginPolicy);
if (!plugin_policy_str.empty()) {
ContentSetting plugin_policy = CONTENT_SETTING_ALLOW;
if (base::LowerCaseEqualsASCII(plugin_policy_str,
switches::kPluginPolicy_Detect)) {
plugin_policy = CONTENT_SETTING_DETECT_IMPORTANT_CONTENT;
} else if (base::LowerCaseEqualsASCII(plugin_policy_str,
switches::kPluginPolicy_Block)) {
plugin_policy = CONTENT_SETTING_BLOCK;
}
host_content_settings_map_->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_PLUGINS, plugin_policy);
}
}
return host_content_settings_map_.get();
}
PrefService* CefBrowserContextImpl::GetPrefs() { PrefService* CefBrowserContextImpl::GetPrefs() {
// TODO(cef): Perhaps use per-context settings. // TODO(cef): Perhaps use per-context settings.
return CefContentBrowserClient::Get()->pref_service(); return CefContentBrowserClient::Get()->pref_service();

View File

@@ -87,7 +87,6 @@ class CefBrowserContextImpl : public CefBrowserContext {
content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) content::URLRequestInterceptorScopedVector request_interceptors)
override; override;
HostContentSettingsMap* GetHostContentSettingsMap() override;
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
// Guaranteed to exist once this object has been initialized. // Guaranteed to exist once this object has been initialized.
@@ -117,7 +116,6 @@ class CefBrowserContextImpl : public CefBrowserContext {
scoped_refptr<CefURLRequestContextGetterImpl> url_request_getter_; scoped_refptr<CefURLRequestContextGetterImpl> url_request_getter_;
scoped_ptr<content::PermissionManager> permission_manager_; scoped_ptr<content::PermissionManager> permission_manager_;
scoped_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_; scoped_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_;
scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
DISALLOW_COPY_AND_ASSIGN(CefBrowserContextImpl); DISALLOW_COPY_AND_ASSIGN(CefBrowserContextImpl);
}; };

View File

@@ -170,10 +170,6 @@ net::URLRequestContextGetter*
return NULL; return NULL;
} }
HostContentSettingsMap* CefBrowserContextProxy::GetHostContentSettingsMap() {
return parent_->GetHostContentSettingsMap();
}
PrefService* CefBrowserContextProxy::GetPrefs() { PrefService* CefBrowserContextProxy::GetPrefs() {
return parent_->GetPrefs(); return parent_->GetPrefs();
} }

View File

@@ -69,7 +69,6 @@ class CefBrowserContextProxy : public CefBrowserContext {
content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) content::URLRequestInterceptorScopedVector request_interceptors)
override; override;
HostContentSettingsMap* GetHostContentSettingsMap() override;
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
scoped_refptr<CefBrowserContextImpl> parent() const { scoped_refptr<CefBrowserContextImpl> parent() const {

View File

@@ -17,7 +17,6 @@
#include "chrome/browser/prefs/command_line_pref_store.h" #include "chrome/browser/prefs/command_line_pref_store.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/proxy_config/proxy_config_dictionary.h" #include "components/proxy_config/proxy_config_dictionary.h"
#include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_prefs.h"
@@ -92,7 +91,6 @@ scoped_ptr<PrefService> CefBrowserPrefStore::CreateService() {
CefMediaCaptureDevicesDispatcher::RegisterPrefs(registry.get()); CefMediaCaptureDevicesDispatcher::RegisterPrefs(registry.get());
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get()); PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get()); extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get());
HostContentSettingsMap::RegisterProfilePrefs(registry.get());
// Print settings. // Print settings.
registry->RegisterBooleanPref(prefs::kPrintingEnabled, true); registry->RegisterBooleanPref(prefs::kPrintingEnabled, true);

View File

@@ -9,11 +9,14 @@
#include "libcef/browser/plugins/plugin_service_filter.h" #include "libcef/browser/plugins/plugin_service_filter.h"
#include "libcef/browser/web_plugin_impl.h" #include "libcef/browser/web_plugin_impl.h"
#include "libcef/common/cef_messages.h" #include "libcef/common/cef_messages.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h" #include "libcef/common/extensions/extensions_util.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/thread_task_runner_handle.h" #include "base/thread_task_runner_handle.h"
#include "chrome/browser/plugins/plugin_finder.h" #include "chrome/browser/plugins/plugin_finder.h"
@@ -159,8 +162,7 @@ CefPluginInfoMessageFilter::Context::Context(
int render_process_id, int render_process_id,
CefBrowserContext* profile) CefBrowserContext* profile)
: render_process_id_(render_process_id), : render_process_id_(render_process_id),
resource_context_(profile->GetResourceContext()), resource_context_(profile->GetResourceContext()) {
host_content_settings_map_(profile->GetHostContentSettingsMap()) {
#if defined(ENABLE_EXTENSIONS) #if defined(ENABLE_EXTENSIONS)
if (extensions::ExtensionsEnabled()) if (extensions::ExtensionsEnabled())
extension_registry_ = extensions::ExtensionRegistry::Get(profile); extension_registry_ = extensions::ExtensionRegistry::Get(profile);
@@ -500,57 +502,24 @@ void CefPluginInfoMessageFilter::Context::GetPluginContentSetting(
ContentSetting* setting, ContentSetting* setting,
bool* uses_default_content_setting, bool* uses_default_content_setting,
bool* is_managed) const { bool* is_managed) const {
scoped_ptr<base::Value> value; *setting = CONTENT_SETTING_ALLOW;
content_settings::SettingInfo info; *uses_default_content_setting = true;
bool uses_plugin_specific_setting = false; *is_managed = false;
if (ShouldUseJavaScriptSettingForPlugin(plugin)) {
value = host_content_settings_map_->GetWebsiteSetting(
policy_url,
policy_url,
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string(),
&info);
} else {
content_settings::SettingInfo specific_info;
scoped_ptr<base::Value> specific_setting =
host_content_settings_map_->GetWebsiteSetting(
policy_url,
plugin_url,
CONTENT_SETTINGS_TYPE_PLUGINS,
resource,
&specific_info);
content_settings::SettingInfo general_info;
scoped_ptr<base::Value> general_setting =
host_content_settings_map_->GetWebsiteSetting(
policy_url,
plugin_url,
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string(),
&general_info);
// If there is a plugin-specific setting, we use it, unless the general // Change the default plugin policy.
// setting was set by policy, in which case it takes precedence. const base::CommandLine* command_line =
// TODO(tommycli): Remove once we deprecate the plugin ASK policy. base::CommandLine::ForCurrentProcess();
bool legacy_ask_user = content_settings::ValueToContentSetting( const std::string& plugin_policy_str =
general_setting.get()) == CONTENT_SETTING_ASK; command_line->GetSwitchValueASCII(switches::kPluginPolicy);
bool use_policy = if (!plugin_policy_str.empty()) {
general_info.source == content_settings::SETTING_SOURCE_POLICY && if (base::LowerCaseEqualsASCII(plugin_policy_str,
!legacy_ask_user; switches::kPluginPolicy_Detect)) {
uses_plugin_specific_setting = specific_setting && !use_policy; *setting = CONTENT_SETTING_DETECT_IMPORTANT_CONTENT;
if (uses_plugin_specific_setting) { } else if (base::LowerCaseEqualsASCII(plugin_policy_str,
value = specific_setting.Pass(); switches::kPluginPolicy_Block)) {
info = specific_info; *setting = CONTENT_SETTING_BLOCK;
} else {
value = general_setting.Pass();
info = general_info;
} }
} }
*setting = content_settings::ValueToContentSetting(value.get());
*uses_default_content_setting =
!uses_plugin_specific_setting &&
info.primary_pattern == ContentSettingsPattern::Wildcard() &&
info.secondary_pattern == ContentSettingsPattern::Wildcard();
*is_managed = info.source == content_settings::SETTING_SOURCE_POLICY;
} }
bool CefPluginInfoMessageFilter::Context::IsPluginEnabled( bool CefPluginInfoMessageFilter::Context::IsPluginEnabled(

View File

@@ -15,7 +15,6 @@
#include "base/prefs/pref_member.h" #include "base/prefs/pref_member.h"
#include "base/sequenced_task_runner_helpers.h" #include "base/sequenced_task_runner_helpers.h"
#include "chrome/browser/plugins/plugin_metadata.h" #include "chrome/browser/plugins/plugin_metadata.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "content/public/browser/browser_message_filter.h" #include "content/public/browser/browser_message_filter.h"
@@ -74,7 +73,6 @@ class CefPluginInfoMessageFilter : public content::BrowserMessageFilter {
#if defined(ENABLE_EXTENSIONS) #if defined(ENABLE_EXTENSIONS)
extensions::ExtensionRegistry* extension_registry_; extensions::ExtensionRegistry* extension_registry_;
#endif #endif
const HostContentSettingsMap* host_content_settings_map_;
BooleanPrefMember allow_outdated_plugins_; BooleanPrefMember allow_outdated_plugins_;
BooleanPrefMember always_authorize_plugins_; BooleanPrefMember always_authorize_plugins_;