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/plugin_prefs.h" | 5 #include "chrome/browser/plugins/plugin_prefs.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
26 #include "chrome/browser/plugins/plugin_installer.h" | 26 #include "chrome/browser/plugins/plugin_installer.h" |
27 #include "chrome/browser/plugins/plugin_metadata.h" | 27 #include "chrome/browser/plugins/plugin_metadata.h" |
28 #include "chrome/browser/plugins/plugin_prefs_factory.h" | 28 #include "chrome/browser/plugins/plugin_prefs_factory.h" |
29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
31 #include "chrome/common/chrome_content_client.h" | |
31 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
34 #include "components/keyed_service/core/keyed_service.h" | 35 #include "components/keyed_service/core/keyed_service.h" |
35 #include "components/prefs/scoped_user_pref_update.h" | 36 #include "components/prefs/scoped_user_pref_update.h" |
36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
37 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
38 #include "content/public/browser/plugin_service.h" | 39 #include "content/public/browser/plugin_service.h" |
39 #include "content/public/common/webplugininfo.h" | 40 #include "content/public/common/webplugininfo.h" |
40 | 41 |
(...skipping 12 matching lines...) Expand all Loading... | |
53 if (PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, | 54 if (PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, |
54 &component_updated_pepper_flash_dir) && | 55 &component_updated_pepper_flash_dir) && |
55 component_updated_pepper_flash_dir.IsParent(plugin)) { | 56 component_updated_pepper_flash_dir.IsParent(plugin)) { |
56 return true; | 57 return true; |
57 } | 58 } |
58 } | 59 } |
59 | 60 |
60 return false; | 61 return false; |
61 } | 62 } |
62 | 63 |
64 bool IsPDFViewerPlugin(const base::string16& plugin_name) { | |
65 return plugin_name == base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName); | |
66 } | |
67 | |
63 } // namespace | 68 } // namespace |
64 | 69 |
65 PluginPrefs::PluginState::PluginState() { | 70 PluginPrefs::PluginState::PluginState() { |
66 } | 71 } |
67 | 72 |
68 PluginPrefs::PluginState::~PluginState() { | 73 PluginPrefs::PluginState::~PluginState() { |
69 } | 74 } |
70 | 75 |
71 bool PluginPrefs::PluginState::Get(const base::FilePath& plugin, | 76 bool PluginPrefs::PluginState::Get(const base::FilePath& plugin, |
72 bool* enabled) const { | 77 bool* enabled) const { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 223 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
219 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins)); | 224 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins)); |
220 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 225 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
221 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); | 226 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); |
222 callback.Run(true); | 227 callback.Run(true); |
223 } | 228 } |
224 | 229 |
225 PluginPrefs::PolicyStatus PluginPrefs::PolicyStatusForPlugin( | 230 PluginPrefs::PolicyStatus PluginPrefs::PolicyStatusForPlugin( |
226 const base::string16& name) const { | 231 const base::string16& name) const { |
227 base::AutoLock auto_lock(lock_); | 232 base::AutoLock auto_lock(lock_); |
228 if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_)) { | 233 |
234 // Special handling for PDF based on its specific policy. | |
235 if (IsPDFViewerPlugin(name) && always_open_pdf_externally_) | |
236 return POLICY_DISABLED; | |
asanka
2016/09/30 14:34:53
This should propagate up to PluginService::GetPlug
pastarmovj
2016/10/04 10:06:34
I am not sure I understand the question but the ge
asanka
2016/10/05 15:18:27
Once the PDF plugin is disabled, the downloads cod
pastarmovj
2016/10/05 15:32:25
Followed up as discussed on a new bug https://bugs
| |
237 | |
238 if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_)) | |
229 return POLICY_ENABLED; | 239 return POLICY_ENABLED; |
230 } else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) && | 240 |
231 !IsStringMatchedInSet( | 241 if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) && |
232 name, policy_disabled_plugin_exception_patterns_)) { | 242 !IsStringMatchedInSet( |
243 name, policy_disabled_plugin_exception_patterns_)) { | |
233 return POLICY_DISABLED; | 244 return POLICY_DISABLED; |
234 } else { | |
235 return NO_POLICY; | |
236 } | 245 } |
246 | |
247 return NO_POLICY; | |
237 } | 248 } |
238 | 249 |
239 bool PluginPrefs::IsPluginEnabled(const content::WebPluginInfo& plugin) const { | 250 bool PluginPrefs::IsPluginEnabled(const content::WebPluginInfo& plugin) const { |
240 std::unique_ptr<PluginMetadata> plugin_metadata( | 251 std::unique_ptr<PluginMetadata> plugin_metadata( |
241 PluginFinder::GetInstance()->GetPluginMetadata(plugin)); | 252 PluginFinder::GetInstance()->GetPluginMetadata(plugin)); |
242 base::string16 group_name = plugin_metadata->name(); | 253 base::string16 group_name = plugin_metadata->name(); |
243 | 254 |
244 // Check if the plugin or its group is enabled by policy. | 255 // Check if the plugin or its group is enabled by policy. |
245 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); | 256 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); |
246 PolicyStatus group_status = PolicyStatusForPlugin(group_name); | 257 PolicyStatus group_status = PolicyStatusForPlugin(group_name); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 } | 291 } |
281 | 292 |
282 void PluginPrefs::UpdatePatternsAndNotify(std::set<base::string16>* patterns, | 293 void PluginPrefs::UpdatePatternsAndNotify(std::set<base::string16>* patterns, |
283 const std::string& pref_name) { | 294 const std::string& pref_name) { |
284 base::AutoLock auto_lock(lock_); | 295 base::AutoLock auto_lock(lock_); |
285 ListValueToStringSet(prefs_->GetList(pref_name.c_str()), patterns); | 296 ListValueToStringSet(prefs_->GetList(pref_name.c_str()), patterns); |
286 | 297 |
287 NotifyPluginStatusChanged(); | 298 NotifyPluginStatusChanged(); |
288 } | 299 } |
289 | 300 |
301 void PluginPrefs::UpdatePdfPolicy(const std::string& pref_name) { | |
302 base::AutoLock auto_lock(lock_); | |
303 always_open_pdf_externally_ = | |
304 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); | |
305 | |
306 NotifyPluginStatusChanged(); | |
307 } | |
308 | |
290 /*static*/ | 309 /*static*/ |
291 bool PluginPrefs::IsStringMatchedInSet( | 310 bool PluginPrefs::IsStringMatchedInSet( |
292 const base::string16& name, | 311 const base::string16& name, |
293 const std::set<base::string16>& pattern_set) { | 312 const std::set<base::string16>& pattern_set) { |
294 std::set<base::string16>::const_iterator pattern(pattern_set.begin()); | 313 std::set<base::string16>::const_iterator pattern(pattern_set.begin()); |
295 while (pattern != pattern_set.end()) { | 314 while (pattern != pattern_set.end()) { |
296 if (base::MatchPattern(name, *pattern)) | 315 if (base::MatchPattern(name, *pattern)) |
297 return true; | 316 return true; |
298 ++pattern; | 317 ++pattern; |
299 } | 318 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 | 431 |
413 // Build the set of policy enabled/disabled plugin patterns once and cache it. | 432 // Build the set of policy enabled/disabled plugin patterns once and cache it. |
414 // Don't do this in the constructor, there's no profile available there. | 433 // Don't do this in the constructor, there's no profile available there. |
415 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), | 434 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins), |
416 &policy_disabled_plugin_patterns_); | 435 &policy_disabled_plugin_patterns_); |
417 ListValueToStringSet( | 436 ListValueToStringSet( |
418 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), | 437 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions), |
419 &policy_disabled_plugin_exception_patterns_); | 438 &policy_disabled_plugin_exception_patterns_); |
420 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), | 439 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins), |
421 &policy_enabled_plugin_patterns_); | 440 &policy_enabled_plugin_patterns_); |
441 always_open_pdf_externally_ = | |
442 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); | |
422 | 443 |
423 registrar_.Init(prefs_); | 444 registrar_.Init(prefs_); |
424 | 445 |
425 // Because pointers to our own members will remain unchanged for the | 446 // Because pointers to our own members will remain unchanged for the |
426 // lifetime of |registrar_| (which we also own), we can bind their | 447 // lifetime of |registrar_| (which we also own), we can bind their |
427 // pointer values directly in the callbacks to avoid string-based | 448 // pointer values directly in the callbacks to avoid string-based |
428 // lookups at notification time. | 449 // lookups at notification time. |
429 registrar_.Add(prefs::kPluginsDisabledPlugins, | 450 registrar_.Add(prefs::kPluginsDisabledPlugins, |
430 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, | 451 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, |
431 base::Unretained(this), | 452 base::Unretained(this), |
432 &policy_disabled_plugin_patterns_)); | 453 &policy_disabled_plugin_patterns_)); |
433 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, | 454 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, |
434 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, | 455 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, |
435 base::Unretained(this), | 456 base::Unretained(this), |
436 &policy_disabled_plugin_exception_patterns_)); | 457 &policy_disabled_plugin_exception_patterns_)); |
437 registrar_.Add(prefs::kPluginsEnabledPlugins, | 458 registrar_.Add(prefs::kPluginsEnabledPlugins, |
438 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, | 459 base::Bind(&PluginPrefs::UpdatePatternsAndNotify, |
439 base::Unretained(this), | 460 base::Unretained(this), |
440 &policy_enabled_plugin_patterns_)); | 461 &policy_enabled_plugin_patterns_)); |
462 registrar_.Add(prefs::kPluginsAlwaysOpenPdfExternally, | |
463 base::Bind(&PluginPrefs::UpdatePdfPolicy, | |
464 base::Unretained(this))); | |
441 | 465 |
442 NotifyPluginStatusChanged(); | 466 NotifyPluginStatusChanged(); |
443 } | 467 } |
444 | 468 |
445 void PluginPrefs::ShutdownOnUIThread() { | 469 void PluginPrefs::ShutdownOnUIThread() { |
446 prefs_ = NULL; | 470 prefs_ = NULL; |
447 registrar_.RemoveAll(); | 471 registrar_.RemoveAll(); |
448 } | 472 } |
449 | 473 |
450 PluginPrefs::PluginPrefs() : profile_(NULL), | 474 PluginPrefs::PluginPrefs() : always_open_pdf_externally_(false), |
475 profile_(NULL), | |
451 prefs_(NULL) { | 476 prefs_(NULL) { |
452 } | 477 } |
453 | 478 |
454 PluginPrefs::~PluginPrefs() { | 479 PluginPrefs::~PluginPrefs() { |
455 } | 480 } |
456 | 481 |
457 void PluginPrefs::SetPolicyEnforcedPluginPatterns( | 482 void PluginPrefs::SetPolicyEnforcedPluginPatternsForTests( |
458 const std::set<base::string16>& disabled_patterns, | 483 const std::set<base::string16>& disabled_patterns, |
459 const std::set<base::string16>& disabled_exception_patterns, | 484 const std::set<base::string16>& disabled_exception_patterns, |
460 const std::set<base::string16>& enabled_patterns) { | 485 const std::set<base::string16>& enabled_patterns) { |
461 policy_disabled_plugin_patterns_ = disabled_patterns; | 486 policy_disabled_plugin_patterns_ = disabled_patterns; |
462 policy_disabled_plugin_exception_patterns_ = disabled_exception_patterns; | 487 policy_disabled_plugin_exception_patterns_ = disabled_exception_patterns; |
463 policy_enabled_plugin_patterns_ = enabled_patterns; | 488 policy_enabled_plugin_patterns_ = enabled_patterns; |
464 } | 489 } |
465 | 490 |
491 void PluginPrefs::SetAlwaysOpenPdfExternallyForTests( | |
492 bool always_open_pdf_externally) { | |
493 always_open_pdf_externally_ = always_open_pdf_externally; | |
494 } | |
495 | |
496 | |
466 void PluginPrefs::OnUpdatePreferences( | 497 void PluginPrefs::OnUpdatePreferences( |
467 const std::vector<content::WebPluginInfo>& plugins) { | 498 const std::vector<content::WebPluginInfo>& plugins) { |
468 if (!prefs_) | 499 if (!prefs_) |
469 return; | 500 return; |
470 | 501 |
471 PluginFinder* finder = PluginFinder::GetInstance(); | 502 PluginFinder* finder = PluginFinder::GetInstance(); |
472 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 503 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
473 base::ListValue* plugins_list = update.Get(); | 504 base::ListValue* plugins_list = update.Get(); |
474 plugins_list->Clear(); | 505 plugins_list->Clear(); |
475 | 506 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 } | 543 } |
513 } | 544 } |
514 | 545 |
515 void PluginPrefs::NotifyPluginStatusChanged() { | 546 void PluginPrefs::NotifyPluginStatusChanged() { |
516 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 547 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
517 content::NotificationService::current()->Notify( | 548 content::NotificationService::current()->Notify( |
518 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 549 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
519 content::Source<Profile>(profile_), | 550 content::Source<Profile>(profile_), |
520 content::NotificationService::NoDetails()); | 551 content::NotificationService::NoDetails()); |
521 } | 552 } |
OLD | NEW |