OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/plugin_updater.h" | 5 #include "chrome/browser/plugin_updater.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { | 59 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { |
60 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) | 60 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) |
61 enable = false; | 61 enable = false; |
62 NPAPI::PluginList::Singleton()->EnableGroup(enable, group_name); | 62 NPAPI::PluginList::Singleton()->EnableGroup(enable, group_name); |
63 NotifyPluginStatusChanged(); | 63 NotifyPluginStatusChanged(); |
64 } | 64 } |
65 | 65 |
66 void PluginUpdater::EnablePluginFile(bool enable, | 66 void PluginUpdater::EnablePluginFile(bool enable, |
67 const FilePath::StringType& path) { | 67 const FilePath::StringType& path) { |
68 FilePath file_path(path); | 68 FilePath file_path(path); |
69 if (enable && !PluginGroup::IsPluginPathDisabledByPolicy(file_path)) | 69 bool disabled_by_policy = |
70 PluginGroup::IsPluginPathDisabledByPolicy(file_path); | |
71 if (enable && !disabled_by_policy) | |
70 NPAPI::PluginList::Singleton()->EnablePlugin(file_path); | 72 NPAPI::PluginList::Singleton()->EnablePlugin(file_path); |
71 else | 73 else |
72 NPAPI::PluginList::Singleton()->DisablePlugin(file_path); | 74 NPAPI::PluginList::Singleton()->DisablePlugin(file_path, |
75 disabled_by_policy); | |
73 | 76 |
74 NotifyPluginStatusChanged(); | 77 NotifyPluginStatusChanged(); |
75 } | 78 } |
76 | 79 |
77 void PluginUpdater::Observe(NotificationType type, | 80 void PluginUpdater::Observe(NotificationType type, |
78 const NotificationSource& source, | 81 const NotificationSource& source, |
79 const NotificationDetails& details) { | 82 const NotificationDetails& details) { |
80 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); | 83 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); |
81 const std::string* pref_name = Details<std::string>(details).ptr(); | 84 const std::string* pref_name = Details<std::string>(details).ptr(); |
82 if (!pref_name) { | 85 if (!pref_name) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 if (!enabled) { | 186 if (!enabled) { |
184 if (force_enable_internal_pdf) { | 187 if (force_enable_internal_pdf) { |
185 enabled = true; | 188 enabled = true; |
186 plugin->SetBoolean("enabled", true); | 189 plugin->SetBoolean("enabled", true); |
187 } else if (force_internal_pdf_for_this_run) { | 190 } else if (force_internal_pdf_for_this_run) { |
188 enabled = true; | 191 enabled = true; |
189 } | 192 } |
190 } | 193 } |
191 } | 194 } |
192 if (!enabled) | 195 if (!enabled) |
193 NPAPI::PluginList::Singleton()->DisablePlugin(plugin_path); | 196 NPAPI::PluginList::Singleton()->DisablePlugin(plugin_path, false); |
194 } else if (!enabled && plugin->GetString("name", &group_name)) { | 197 } else if (!enabled && plugin->GetString("name", &group_name)) { |
195 // Don't disable this group if it's for the pdf plugin and we just | 198 // Don't disable this group if it's for the pdf plugin and we just |
196 // forced it on. | 199 // forced it on. |
197 if (force_enable_internal_pdf && pdf_group_name == group_name) | 200 if (force_enable_internal_pdf && pdf_group_name == group_name) |
198 continue; | 201 continue; |
199 | 202 |
200 // Otherwise this is a list of groups. | 203 // Otherwise this is a list of groups. |
201 EnablePluginGroup(false, group_name); | 204 EnablePluginGroup(false, group_name); |
202 } | 205 } |
203 } | 206 } |
204 } | 207 } |
205 | 208 |
206 // Build the set of policy-disabled plugin patterns once and cache it. | 209 // Build the set of policy-disabled plugin patterns once and cache it. |
207 // Don't do this in the constructor, there's no profile available there. | 210 // Don't do this in the constructor, there's no profile available there. |
208 const ListValue* plugin_blacklist = | 211 const ListValue* plugin_blacklist = |
209 profile->GetPrefs()->GetList(prefs::kPluginsPluginsBlacklist); | 212 profile->GetPrefs()->GetList(prefs::kPluginsPluginsBlacklist); |
210 DisablePluginsFromPolicy(plugin_blacklist); | 213 DisablePluginsFromPolicy(plugin_blacklist); |
211 | 214 |
212 if ((!enable_internal_pdf_ && !found_internal_pdf) && | 215 if ((!enable_internal_pdf_ && !found_internal_pdf) && |
213 !force_internal_pdf_for_this_run) { | 216 !force_internal_pdf_for_this_run) { |
214 // The internal PDF plugin is disabled by default, and the user hasn't | 217 // The internal PDF plugin is disabled by default, and the user hasn't |
215 // overridden the default. | 218 // overridden the default. |
216 NPAPI::PluginList::Singleton()->DisablePlugin(pdf_path); | 219 NPAPI::PluginList::Singleton()->DisablePlugin(pdf_path, false); |
217 EnablePluginGroup(false, pdf_group_name); | 220 EnablePluginGroup(false, pdf_group_name); |
218 } | 221 } |
219 | 222 |
220 if (force_enable_internal_pdf) { | 223 if (force_enable_internal_pdf) { |
221 // See http://crbug.com/50105 for background. | 224 // See http://crbug.com/50105 for background. |
222 EnablePluginGroup(false, ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); | 225 EnablePluginGroup(false, ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); |
223 | 226 |
224 // We want to save this, but doing so requires loading the list of plugins, | 227 // We want to save this, but doing so requires loading the list of plugins, |
225 // so do it after a minute as to not impact startup performance. Note that | 228 // so do it after a minute as to not impact startup performance. Note that |
226 // plugins are loaded after 30s by the metrics service. | 229 // plugins are loaded after 30s by the metrics service. |
227 UpdatePreferences(profile, kPluginUpdateDelayMs); | 230 UpdatePreferences(profile, kPluginUpdateDelayMs); |
228 } | 231 } |
229 } | 232 } |
230 | 233 |
231 void PluginUpdater::UpdatePreferences(Profile* profile, int delay_ms) { | 234 void PluginUpdater::UpdatePreferences(Profile* profile, int delay_ms) { |
232 BrowserThread::PostDelayedTask( | 235 BrowserThread::PostDelayedTask( |
233 BrowserThread::FILE, | 236 BrowserThread::FILE, |
234 FROM_HERE, | 237 FROM_HERE, |
235 NewRunnableFunction( | 238 NewRunnableFunction( |
236 &PluginUpdater::GetPreferencesDataOnFileThread, profile), delay_ms); | 239 &PluginUpdater::GetPreferencesDataOnFileThread, profile), delay_ms); |
237 } | 240 } |
238 | 241 |
239 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { | 242 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { |
240 std::vector<WebPluginInfo> plugins; | 243 std::vector<WebPluginInfo> plugins; |
241 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); | 244 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); |
245 NPAPI::PluginList::DisabledPluginsList disabled_plugins; | |
246 NPAPI::PluginList::Singleton()->GetDisabledPlugins(&disabled_plugins); | |
242 | 247 |
243 std::vector<PluginGroup> groups; | 248 std::vector<PluginGroup> groups; |
244 NPAPI::PluginList::Singleton()->GetPluginGroups(false, &groups); | 249 NPAPI::PluginList::Singleton()->GetPluginGroups(false, &groups); |
250 NPAPI::PluginList::DisabledGroupsList disabled_groups; | |
251 NPAPI::PluginList::Singleton()->GetDisabledGroups(&disabled_groups); | |
245 | 252 |
246 BrowserThread::PostTask( | 253 BrowserThread::PostTask( |
247 BrowserThread::UI, | 254 BrowserThread::UI, |
248 FROM_HERE, | 255 FROM_HERE, |
249 NewRunnableFunction( | 256 NewRunnableFunction( |
250 &PluginUpdater::OnUpdatePreferences, | 257 &PluginUpdater::OnUpdatePreferences, |
251 static_cast<Profile*>(profile), plugins, groups)); | 258 static_cast<Profile*>(profile), |
259 plugins, groups, | |
260 disabled_plugins, disabled_groups)); | |
252 } | 261 } |
253 | 262 |
254 void PluginUpdater::OnUpdatePreferences( | 263 void PluginUpdater::OnUpdatePreferences( |
255 Profile* profile, | 264 Profile* profile, |
256 const std::vector<WebPluginInfo>& plugins, | 265 const std::vector<WebPluginInfo>& plugins, |
257 const std::vector<PluginGroup>& groups) { | 266 const std::vector<PluginGroup>& groups, |
267 const NPAPI::PluginList::DisabledPluginsList& disabled_plugins, | |
268 const NPAPI::PluginList::DisabledGroupsList& disabled_groups) { | |
258 ListValue* plugins_list = profile->GetPrefs()->GetMutableList( | 269 ListValue* plugins_list = profile->GetPrefs()->GetMutableList( |
259 prefs::kPluginsPluginsList); | 270 prefs::kPluginsPluginsList); |
260 plugins_list->Clear(); | 271 plugins_list->Clear(); |
261 | 272 |
262 FilePath internal_dir; | 273 FilePath internal_dir; |
263 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) | 274 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) |
264 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory, | 275 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory, |
265 internal_dir); | 276 internal_dir); |
266 | 277 |
267 // Add the plugin files. | 278 // Add the plugin files. |
268 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); | 279 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); |
269 it != plugins.end(); | 280 it != plugins.end(); |
270 ++it) { | 281 ++it) { |
271 plugins_list->Append(CreatePluginFileSummary(*it)); | 282 DictionaryValue* summary = CreatePluginFileSummary(*it); |
283 NPAPI::PluginList::DisabledPluginsList::const_iterator entry = | |
284 disabled_plugins.find(it->path); | |
285 // If the plugin is disabled only by policy don't store this state in the | |
286 // user pref store. | |
287 if (entry != disabled_plugins.end() && | |
288 entry->second == NPAPI::PluginList::POLICY) | |
danno
2010/12/14 09:43:39
Add methods to check this so the code looks more l
pastarmovj
2010/12/15 14:44:51
This doesn't seem to me to bring any more strucure
| |
289 summary->SetBoolean("enabled", true); | |
290 plugins_list->Append(summary); | |
272 } | 291 } |
273 | 292 |
274 // Add the groups as well. | 293 // Add the groups as well. |
275 for (size_t i = 0; i < groups.size(); ++i) { | 294 for (std::vector<PluginGroup>::const_iterator it = groups.begin(); |
295 it != groups.end(); | |
296 ++it) { | |
276 // Don't save preferences for vulnerable pugins. | 297 // Don't save preferences for vulnerable pugins. |
277 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 298 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
278 switches::kDisableOutdatedPlugins) || | 299 switches::kDisableOutdatedPlugins) || |
279 !groups[i].IsVulnerable()) { | 300 !it->IsVulnerable()) { |
danno
2010/12/14 09:43:39
Might make code more readable to switch order of t
pastarmovj
2010/12/15 14:44:51
Done.
| |
280 plugins_list->Append(groups[i].GetSummary()); | 301 DictionaryValue* summary = it->GetSummary(); |
302 NPAPI::PluginList::DisabledGroupsList::const_iterator entry = | |
303 disabled_groups.find(it->GetGroupName()); | |
304 // If the plugin is disabled only by policy don't store this state in the | |
305 // user pref store. | |
306 if (entry != disabled_groups.end() && | |
307 entry->second == NPAPI::PluginList::POLICY) | |
308 summary->SetBoolean("enabled", true); | |
309 plugins_list->Append(summary); | |
281 } | 310 } |
282 } | 311 } |
283 } | 312 } |
284 | 313 |
285 void PluginUpdater::NotifyPluginStatusChanged() { | 314 void PluginUpdater::NotifyPluginStatusChanged() { |
286 if (notify_pending_) | 315 if (notify_pending_) |
287 return; | 316 return; |
288 notify_pending_ = true; | 317 notify_pending_ = true; |
289 MessageLoop::current()->PostTask( | 318 MessageLoop::current()->PostTask( |
290 FROM_HERE, | 319 FROM_HERE, |
291 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); | 320 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); |
292 } | 321 } |
293 | 322 |
294 void PluginUpdater::OnNotifyPluginStatusChanged() { | 323 void PluginUpdater::OnNotifyPluginStatusChanged() { |
295 GetInstance()->notify_pending_ = false; | 324 GetInstance()->notify_pending_ = false; |
296 NotificationService::current()->Notify( | 325 NotificationService::current()->Notify( |
297 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, | 326 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, |
298 Source<PluginUpdater>(GetInstance()), | 327 Source<PluginUpdater>(GetInstance()), |
299 NotificationService::NoDetails()); | 328 NotificationService::NoDetails()); |
300 } | 329 } |
301 | 330 |
302 /*static*/ | 331 /*static*/ |
303 PluginUpdater* PluginUpdater::GetInstance() { | 332 PluginUpdater* PluginUpdater::GetInstance() { |
304 return Singleton<PluginUpdater>::get(); | 333 return Singleton<PluginUpdater>::get(); |
305 } | 334 } |
OLD | NEW |