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); | |
49 OverriddenPlugin overridden_plugin; | 47 OverriddenPlugin overridden_plugin; |
| 48 overridden_plugin.render_process_id = render_process_id; |
50 overridden_plugin.render_view_id = render_view_id; | 49 overridden_plugin.render_view_id = render_view_id; |
51 overridden_plugin.url = url; | 50 overridden_plugin.url = url; |
52 overridden_plugin.plugin = plugin; | 51 overridden_plugin.plugin = plugin; |
53 details->overridden_plugins.push_back(overridden_plugin); | 52 base::AutoLock auto_lock(lock_); |
| 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::IsPluginEnabled( | 72 bool ChromePluginServiceFilter::ShouldUsePlugin( |
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); | 80 // Check whether the plugin is overridden. |
| 81 for (size_t i = 0; i < overridden_plugins_.size(); ++i) { |
| 82 if (overridden_plugins_[i].render_process_id == render_process_id && |
| 83 overridden_plugins_[i].render_view_id == render_view_id && |
| 84 (overridden_plugins_[i].url == url || |
| 85 overridden_plugins_[i].url.is_empty())) { |
81 | 86 |
82 // Check whether the plugin is overridden. | 87 bool use = overridden_plugins_[i].plugin.path == plugin->path; |
83 if (details) { | 88 if (use) |
84 for (size_t i = 0; i < details->overridden_plugins.size(); ++i) { | 89 *plugin = overridden_plugins_[i].plugin; |
85 if (details->overridden_plugins[i].render_view_id == render_view_id && | 90 return use; |
86 (details->overridden_plugins[i].url == url || | |
87 details->overridden_plugins[i].url.is_empty())) { | |
88 | |
89 bool use = details->overridden_plugins[i].plugin.path == plugin->path; | |
90 if (!use) | |
91 return false; | |
92 *plugin = details->overridden_plugins[i].plugin; | |
93 break; | |
94 } | |
95 } | 91 } |
96 } | 92 } |
97 | 93 |
98 // Check whether the plugin is disabled. | 94 // Check whether the plugin is disabled. |
99 ResourceContextMap::iterator prefs_it = | 95 ResourceContextMap::iterator prefs_it = |
100 resource_context_map_.find(context); | 96 resource_context_map_.find(context); |
101 if (prefs_it == resource_context_map_.end()) | 97 if (prefs_it == resource_context_map_.end()) |
102 return false; | 98 return false; |
103 | 99 |
104 PluginPrefs* plugin_prefs = prefs_it->second.get(); | 100 PluginPrefs* plugin_prefs = prefs_it->second.get(); |
(...skipping 11 matching lines...) Expand all Loading... |
116 (policy_url.scheme() != origin.scheme() || | 112 (policy_url.scheme() != origin.scheme() || |
117 policy_url.host() != origin.host() || | 113 policy_url.host() != origin.host() || |
118 policy_url.port() != origin.port())) { | 114 policy_url.port() != origin.port())) { |
119 return false; | 115 return false; |
120 } | 116 } |
121 } | 117 } |
122 | 118 |
123 return true; | 119 return true; |
124 } | 120 } |
125 | 121 |
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. | |
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 | |
159 ChromePluginServiceFilter::ChromePluginServiceFilter() { | 122 ChromePluginServiceFilter::ChromePluginServiceFilter() { |
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
161 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 124 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
162 content::NotificationService::AllSources()); | 125 content::NotificationService::AllSources()); |
163 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 126 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
164 content::NotificationService::AllSources()); | 127 content::NotificationService::AllSources()); |
165 } | 128 } |
166 | 129 |
167 ChromePluginServiceFilter::~ChromePluginServiceFilter() { | 130 ChromePluginServiceFilter::~ChromePluginServiceFilter() { |
168 } | 131 } |
169 | 132 |
170 void ChromePluginServiceFilter::Observe( | 133 void ChromePluginServiceFilter::Observe( |
171 int type, | 134 int type, |
172 const content::NotificationSource& source, | 135 const content::NotificationSource& source, |
173 const content::NotificationDetails& details) { | 136 const content::NotificationDetails& details) { |
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
175 switch (type) { | 138 switch (type) { |
176 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 139 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
177 int render_process_id = | 140 int render_process_id = |
178 content::Source<content::RenderProcessHost>(source).ptr()->GetID(); | 141 content::Source<content::RenderProcessHost>(source).ptr()->GetID(); |
179 | 142 |
180 base::AutoLock auto_lock(lock_); | 143 base::AutoLock auto_lock(lock_); |
181 plugin_details_.erase(render_process_id); | 144 for (size_t i = 0; i < overridden_plugins_.size(); ++i) { |
| 145 if (overridden_plugins_[i].render_process_id == render_process_id) { |
| 146 overridden_plugins_.erase(overridden_plugins_.begin() + i); |
| 147 break; |
| 148 } |
| 149 } |
182 break; | 150 break; |
183 } | 151 } |
184 case chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED: { | 152 case chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED: { |
185 Profile* profile = content::Source<Profile>(source).ptr(); | 153 Profile* profile = content::Source<Profile>(source).ptr(); |
186 PluginService::GetInstance()->PurgePluginListCache(profile, false); | 154 PluginService::GetInstance()->PurgePluginListCache(profile, false); |
187 if (profile && profile->HasOffTheRecordProfile()) { | 155 if (profile && profile->HasOffTheRecordProfile()) { |
188 PluginService::GetInstance()->PurgePluginListCache( | 156 PluginService::GetInstance()->PurgePluginListCache( |
189 profile->GetOffTheRecordProfile(), false); | 157 profile->GetOffTheRecordProfile(), false); |
190 } | 158 } |
191 break; | 159 break; |
192 } | 160 } |
193 default: { | 161 default: { |
194 NOTREACHED(); | 162 NOTREACHED(); |
195 } | 163 } |
196 } | 164 } |
197 } | 165 } |
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(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 |