Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 5 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/plugins/plugin_metadata.h" | 9 #include "chrome/browser/plugins/plugin_metadata.h" |
| 10 #include "chrome/browser/plugins/plugin_prefs.h" | 10 #include "chrome/browser/plugins/plugin_prefs.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 const void* context) { | 37 const void* context) { |
| 38 base::AutoLock lock(lock_); | 38 base::AutoLock lock(lock_); |
| 39 resource_context_map_.erase(context); | 39 resource_context_map_.erase(context); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void ChromePluginServiceFilter::OverridePluginForTab( | 42 void ChromePluginServiceFilter::OverridePluginForTab( |
| 43 int render_process_id, | 43 int render_process_id, |
| 44 int render_view_id, | 44 int render_view_id, |
| 45 const GURL& url, | 45 const GURL& url, |
| 46 const webkit::WebPluginInfo& plugin) { | 46 const webkit::WebPluginInfo& plugin) { |
| 47 base::AutoLock auto_lock(lock_); | |
| 48 ProcessDetails* details = GetOrRegisterProcess(render_process_id); | |
| 47 OverriddenPlugin overridden_plugin; | 49 OverriddenPlugin overridden_plugin; |
| 48 overridden_plugin.render_process_id = render_process_id; | |
| 49 overridden_plugin.render_view_id = render_view_id; | 50 overridden_plugin.render_view_id = render_view_id; |
| 50 overridden_plugin.url = url; | 51 overridden_plugin.url = url; |
| 51 overridden_plugin.plugin = plugin; | 52 overridden_plugin.plugin = plugin; |
| 52 base::AutoLock auto_lock(lock_); | 53 details->overridden_plugins.push_back(overridden_plugin); |
| 53 overridden_plugins_.push_back(overridden_plugin); | |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ChromePluginServiceFilter::RestrictPluginToProfileAndOrigin( | 56 void ChromePluginServiceFilter::RestrictPluginToProfileAndOrigin( |
| 57 const FilePath& plugin_path, | 57 const FilePath& plugin_path, |
| 58 Profile* profile, | 58 Profile* profile, |
| 59 const GURL& origin) { | 59 const GURL& origin) { |
| 60 base::AutoLock auto_lock(lock_); | 60 base::AutoLock auto_lock(lock_); |
| 61 restricted_plugins_[plugin_path] = | 61 restricted_plugins_[plugin_path] = |
| 62 std::make_pair(PluginPrefs::GetForProfile(profile), | 62 std::make_pair(PluginPrefs::GetForProfile(profile), |
| 63 origin); | 63 origin); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void ChromePluginServiceFilter::UnrestrictPlugin( | 66 void ChromePluginServiceFilter::UnrestrictPlugin( |
| 67 const FilePath& plugin_path) { | 67 const FilePath& plugin_path) { |
| 68 base::AutoLock auto_lock(lock_); | 68 base::AutoLock auto_lock(lock_); |
| 69 restricted_plugins_.erase(plugin_path); | 69 restricted_plugins_.erase(plugin_path); |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool ChromePluginServiceFilter::ShouldUsePlugin( | 72 bool ChromePluginServiceFilter::IsPluginEnabled( |
| 73 int render_process_id, | 73 int render_process_id, |
| 74 int render_view_id, | 74 int render_view_id, |
| 75 const void* context, | 75 const void* context, |
| 76 const GURL& url, | 76 const GURL& url, |
| 77 const GURL& policy_url, | 77 const GURL& policy_url, |
| 78 webkit::WebPluginInfo* plugin) { | 78 webkit::WebPluginInfo* plugin) { |
| 79 base::AutoLock auto_lock(lock_); | 79 base::AutoLock auto_lock(lock_); |
| 80 const ProcessDetails* details = GetProcess(render_process_id); | |
| 81 | |
| 80 // Check whether the plugin is overridden. | 82 // Check whether the plugin is overridden. |
| 81 for (size_t i = 0; i < overridden_plugins_.size(); ++i) { | 83 if (details) { |
| 82 if (overridden_plugins_[i].render_process_id == render_process_id && | 84 for (size_t i = 0; i < details->overridden_plugins.size(); ++i) { |
| 83 overridden_plugins_[i].render_view_id == render_view_id && | 85 if (details->overridden_plugins[i].render_view_id == render_view_id && |
| 84 (overridden_plugins_[i].url == url || | 86 (details->overridden_plugins[i].url == url || |
| 85 overridden_plugins_[i].url.is_empty())) { | 87 details->overridden_plugins[i].url.is_empty())) { |
| 86 | 88 |
| 87 bool use = overridden_plugins_[i].plugin.path == plugin->path; | 89 bool use = details->overridden_plugins[i].plugin.path == plugin->path; |
| 88 if (use) | 90 if (!use) |
| 89 *plugin = overridden_plugins_[i].plugin; | 91 return false; |
| 90 return use; | 92 *plugin = details->overridden_plugins[i].plugin; |
| 93 break; | |
| 94 } | |
| 91 } | 95 } |
| 92 } | 96 } |
| 93 | 97 |
| 94 // Check whether the plugin is disabled. | 98 // Check whether the plugin is disabled. |
| 95 ResourceContextMap::iterator prefs_it = | 99 ResourceContextMap::iterator prefs_it = |
| 96 resource_context_map_.find(context); | 100 resource_context_map_.find(context); |
| 97 if (prefs_it == resource_context_map_.end()) | 101 if (prefs_it == resource_context_map_.end()) |
| 98 return false; | 102 return false; |
| 99 | 103 |
| 100 PluginPrefs* plugin_prefs = prefs_it->second.get(); | 104 PluginPrefs* plugin_prefs = prefs_it->second.get(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 112 (policy_url.scheme() != origin.scheme() || | 116 (policy_url.scheme() != origin.scheme() || |
| 113 policy_url.host() != origin.host() || | 117 policy_url.host() != origin.host() || |
| 114 policy_url.port() != origin.port())) { | 118 policy_url.port() != origin.port())) { |
| 115 return false; | 119 return false; |
| 116 } | 120 } |
| 117 } | 121 } |
| 118 | 122 |
| 119 return true; | 123 return true; |
| 120 } | 124 } |
| 121 | 125 |
| 126 bool ChromePluginServiceFilter::CanLoadPlugin(int render_process_id, | |
| 127 const FilePath& path) { | |
| 128 // The browser itself sometimes loads plug-ins to e.g. clear plug-in data. | |
| 129 // We always grant the browser permission. | |
|
jam
2013/01/31 18:11:25
nit: it would be helpful to have this comment in t
| |
| 130 if (!render_process_id) | |
| 131 return true; | |
| 132 | |
| 133 base::AutoLock auto_lock(lock_); | |
| 134 const ProcessDetails* details = GetProcess(render_process_id); | |
| 135 if (!details) | |
| 136 return false; | |
| 137 | |
| 138 if (details->authorized_plugins.find(path) == | |
| 139 details->authorized_plugins.end() && | |
| 140 details->authorized_plugins.find(FilePath()) == | |
| 141 details->authorized_plugins.end()) { | |
| 142 return false; | |
| 143 } | |
| 144 | |
| 145 return true; | |
| 146 } | |
| 147 | |
| 148 void ChromePluginServiceFilter::AuthorizePlugin(int render_process_id, | |
| 149 const FilePath& plugin_path) { | |
| 150 base::AutoLock auto_lock(lock_); | |
| 151 ProcessDetails* details = GetOrRegisterProcess(render_process_id); | |
| 152 details->authorized_plugins.insert(plugin_path); | |
| 153 } | |
| 154 | |
| 155 void ChromePluginServiceFilter::AuthorizeAllPlugins(int render_process_id) { | |
| 156 AuthorizePlugin(render_process_id, FilePath()); | |
| 157 } | |
| 158 | |
| 122 ChromePluginServiceFilter::ChromePluginServiceFilter() { | 159 ChromePluginServiceFilter::ChromePluginServiceFilter() { |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 161 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 125 content::NotificationService::AllSources()); | 162 content::NotificationService::AllSources()); |
| 126 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 163 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 127 content::NotificationService::AllSources()); | 164 content::NotificationService::AllSources()); |
| 128 } | 165 } |
| 129 | 166 |
| 130 ChromePluginServiceFilter::~ChromePluginServiceFilter() { | 167 ChromePluginServiceFilter::~ChromePluginServiceFilter() { |
| 131 } | 168 } |
| 132 | 169 |
| 133 void ChromePluginServiceFilter::Observe( | 170 void ChromePluginServiceFilter::Observe( |
| 134 int type, | 171 int type, |
| 135 const content::NotificationSource& source, | 172 const content::NotificationSource& source, |
| 136 const content::NotificationDetails& details) { | 173 const content::NotificationDetails& details) { |
| 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 138 switch (type) { | 175 switch (type) { |
| 139 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 176 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
| 140 int render_process_id = | 177 int render_process_id = |
| 141 content::Source<content::RenderProcessHost>(source).ptr()->GetID(); | 178 content::Source<content::RenderProcessHost>(source).ptr()->GetID(); |
| 142 | 179 |
| 143 base::AutoLock auto_lock(lock_); | 180 base::AutoLock auto_lock(lock_); |
| 144 for (size_t i = 0; i < overridden_plugins_.size(); ++i) { | 181 plugin_details_.erase(render_process_id); |
| 145 if (overridden_plugins_[i].render_process_id == render_process_id) { | |
| 146 overridden_plugins_.erase(overridden_plugins_.begin() + i); | |
| 147 break; | |
| 148 } | |
| 149 } | |
| 150 break; | 182 break; |
| 151 } | 183 } |
| 152 case chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED: { | 184 case chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED: { |
| 153 Profile* profile = content::Source<Profile>(source).ptr(); | 185 Profile* profile = content::Source<Profile>(source).ptr(); |
| 154 PluginService::GetInstance()->PurgePluginListCache(profile, false); | 186 PluginService::GetInstance()->PurgePluginListCache(profile, false); |
| 155 if (profile && profile->HasOffTheRecordProfile()) { | 187 if (profile && profile->HasOffTheRecordProfile()) { |
| 156 PluginService::GetInstance()->PurgePluginListCache( | 188 PluginService::GetInstance()->PurgePluginListCache( |
| 157 profile->GetOffTheRecordProfile(), false); | 189 profile->GetOffTheRecordProfile(), false); |
| 158 } | 190 } |
| 159 break; | 191 break; |
| 160 } | 192 } |
| 161 default: { | 193 default: { |
| 162 NOTREACHED(); | 194 NOTREACHED(); |
| 163 } | 195 } |
| 164 } | 196 } |
| 165 } | 197 } |
| 198 | |
| 199 ChromePluginServiceFilter::ProcessDetails* | |
| 200 ChromePluginServiceFilter::GetOrRegisterProcess( | |
| 201 int render_process_id) { | |
| 202 return &plugin_details_[render_process_id]; | |
| 203 } | |
| 204 | |
| 205 const ChromePluginServiceFilter::ProcessDetails* | |
| 206 ChromePluginServiceFilter::GetProcess( | |
| 207 int render_process_id) const { | |
| 208 std::map<int, ProcessDetails>::const_iterator it = | |
| 209 plugin_details_.find(render_process_id); | |
| 210 if (it == plugin_details_.end()) | |
| 211 return NULL; | |
| 212 return &it->second; | |
| 213 } | |
| 214 | |
| 215 ChromePluginServiceFilter::OverriddenPlugin::OverriddenPlugin() | |
| 216 : render_view_id(-1) { | |
|
jam
2013/01/31 18:11:25
nit: use MSG_ROUTING_NONE
| |
| 217 } | |
| 218 | |
| 219 ChromePluginServiceFilter::OverriddenPlugin::~OverriddenPlugin() { | |
| 220 } | |
| 221 | |
| 222 ChromePluginServiceFilter::ProcessDetails::ProcessDetails() { | |
| 223 } | |
| 224 | |
| 225 ChromePluginServiceFilter::ProcessDetails::~ProcessDetails() { | |
| 226 } | |
| 227 | |
| OLD | NEW |