Index: chrome/browser/plugins/chrome_plugin_service_filter.cc |
diff --git a/chrome/browser/plugins/chrome_plugin_service_filter.cc b/chrome/browser/plugins/chrome_plugin_service_filter.cc |
index 777d7b527554c5866d3d844a254717be9dee67c4..cbd6e9744dc6963c2858b436d01d053737a0e33b 100644 |
--- a/chrome/browser/plugins/chrome_plugin_service_filter.cc |
+++ b/chrome/browser/plugins/chrome_plugin_service_filter.cc |
@@ -53,6 +53,68 @@ void AuthorizeRenderer(content::RenderFrameHost* render_frame_host) { |
} // namespace |
+class ChromePluginServiceFilter::ProfileContentSettingObserver |
+ : public content_settings::Observer { |
+ public: |
+ explicit ProfileContentSettingObserver(Profile* profile); |
+ ~ProfileContentSettingObserver() override; |
+ void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
+ const ContentSettingsPattern& secondary_pattern, |
+ ContentSettingsType content_type, |
+ std::string resource_identifier) override; |
+ |
+ private: |
+ Profile* profile_; |
+}; |
+ |
+ChromePluginServiceFilter::ProfileContentSettingObserver:: |
+ ProfileContentSettingObserver(Profile* profile) |
+ : profile_(profile) {} |
+ |
+ChromePluginServiceFilter::ProfileContentSettingObserver:: |
+ ~ProfileContentSettingObserver() {} |
+ |
+void ChromePluginServiceFilter::ProfileContentSettingObserver:: |
+ OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
+ const ContentSettingsPattern& secondary_pattern, |
+ ContentSettingsType content_type, |
+ std::string resource_identifier) { |
+ DCHECK(base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)); |
+ if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) |
+ PluginService::GetInstance()->PurgePluginListCache(profile_, false); |
+} |
+ |
+struct ChromePluginServiceFilter::ContextInfo { |
+ ContextInfo( |
+ const scoped_refptr<PluginPrefs>& plugin_prefs, |
+ const scoped_refptr<HostContentSettingsMap>& host_content_settings_map, |
+ Profile* profile); |
+ ~ContextInfo(); |
+ |
+ scoped_refptr<PluginPrefs> plugin_prefs; |
+ scoped_refptr<HostContentSettingsMap> host_content_settings_map; |
+ ProfileContentSettingObserver observer; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ContextInfo); |
+}; |
+ |
+ChromePluginServiceFilter::ContextInfo::ContextInfo( |
+ const scoped_refptr<PluginPrefs>& plugin_prefs, |
+ const scoped_refptr<HostContentSettingsMap>& host_content_settings_map, |
+ Profile* profile) |
+ : plugin_prefs(plugin_prefs), |
+ host_content_settings_map(host_content_settings_map), |
+ observer(ProfileContentSettingObserver(profile)) { |
+ if (base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) |
+ host_content_settings_map->AddObserver(&observer); |
+} |
+ |
+ChromePluginServiceFilter::ContextInfo::~ContextInfo() { |
+ if (base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) |
+ host_content_settings_map->RemoveObserver(&observer); |
+} |
+ |
// static |
ChromePluginServiceFilter* ChromePluginServiceFilter::GetInstance() { |
return base::Singleton<ChromePluginServiceFilter>::get(); |
@@ -61,18 +123,18 @@ ChromePluginServiceFilter* ChromePluginServiceFilter::GetInstance() { |
void ChromePluginServiceFilter::RegisterResourceContext( |
scoped_refptr<PluginPrefs> plugin_prefs, |
scoped_refptr<HostContentSettingsMap> host_content_settings_map, |
+ Profile* profile, |
const void* context) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
base::AutoLock lock(lock_); |
- plugin_prefs_[context] = std::move(plugin_prefs); |
- host_content_settings_maps_[context] = std::move(host_content_settings_map); |
+ resource_context_map_[context] = base::MakeUnique<ContextInfo>( |
+ plugin_prefs, host_content_settings_map, profile); |
} |
void ChromePluginServiceFilter::UnregisterResourceContext( |
const void* context) { |
base::AutoLock lock(lock_); |
- plugin_prefs_.erase(context); |
- host_content_settings_maps_.erase(context); |
+ resource_context_map_.erase(context); |
} |
void ChromePluginServiceFilter::OverridePluginForFrame( |
@@ -113,30 +175,26 @@ bool ChromePluginServiceFilter::IsPluginAvailable( |
} |
// Check whether the plugin is disabled. |
- ResourceContextMap::iterator prefs_it = plugin_prefs_.find(context); |
+ auto context_info_it = resource_context_map_.find(context); |
// The context might not be found because RenderFrameMessageFilter might |
// outlive the Profile (the context is unregistered during the Profile |
// destructor). |
- if (prefs_it == plugin_prefs_.end()) |
+ if (context_info_it == resource_context_map_.end()) |
return false; |
- if (!prefs_it->second.get()->IsPluginEnabled(*plugin)) |
+ if (!context_info_it->second->plugin_prefs.get()->IsPluginEnabled(*plugin)) |
return false; |
// Check whether PreferHtmlOverPlugins feature is enabled. |
if (plugin->name == base::ASCIIToUTF16(content::kFlashPluginName) && |
base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) { |
- auto host_content_settings_map_it = |
- host_content_settings_maps_.find(context); |
- DCHECK(host_content_settings_map_it != host_content_settings_maps_.end()); |
- |
ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT; |
std::unique_ptr<PluginMetadata> plugin_metadata = |
PluginFinder::GetInstance()->GetPluginMetadata(*plugin); |
- GetPluginContentSetting(host_content_settings_map_it->second.get(), *plugin, |
- policy_url, policy_url, |
- plugin_metadata->identifier(), &plugin_setting, |
- nullptr, nullptr); |
+ GetPluginContentSetting( |
+ context_info_it->second->host_content_settings_map.get(), *plugin, |
+ policy_url, policy_url, plugin_metadata->identifier(), &plugin_setting, |
+ nullptr, nullptr); |
plugin_setting = |
content_settings::PluginsFieldTrial::EffectiveContentSetting( |
CONTENT_SETTINGS_TYPE_PLUGINS, plugin_setting); |