Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/plugins/plugin_prefs.cc

Issue 2369353002: Adds a pref and a policy to decide if PDFs should always be opened externally. (Closed)
Patch Set: Rebase and move the friend decl in the ifdef. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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_);
233
234 // Special handling for PDF based on its specific policy.
235 if (IsPDFViewerPlugin(name) && always_open_pdf_externally_) {
236 return POLICY_DISABLED;
Bernhard Bauer 2016/09/29 08:44:35 Nit: I think it's more common to leave out braces
pastarmovj 2016/09/29 12:14:41 Yup. Copy-paste relict.
237 }
238
228 if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_)) { 239 if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_)) {
229 return POLICY_ENABLED; 240 return POLICY_ENABLED;
230 } else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) && 241 } else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) &&
Bernhard Bauer 2016/09/29 08:44:35 Remove these else's?
pastarmovj 2016/09/29 12:14:41 Done.
231 !IsStringMatchedInSet( 242 !IsStringMatchedInSet(
232 name, policy_disabled_plugin_exception_patterns_)) { 243 name, policy_disabled_plugin_exception_patterns_)) {
233 return POLICY_DISABLED; 244 return POLICY_DISABLED;
234 } else { 245 } else {
235 return NO_POLICY; 246 return NO_POLICY;
236 } 247 }
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(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::kAlwaysOpenPdfExternally);
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
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::kAlwaysOpenPdfExternally);
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::kAlwaysOpenPdfExternally,
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::SetPolicyEnforcedPluginPatterns(
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::SetAlwaysOpenPdfExternally(bool always_open_pdf_externally) {
492 always_open_pdf_externally_ = always_open_pdf_externally;
493 }
494
495
466 void PluginPrefs::OnUpdatePreferences( 496 void PluginPrefs::OnUpdatePreferences(
467 const std::vector<content::WebPluginInfo>& plugins) { 497 const std::vector<content::WebPluginInfo>& plugins) {
468 if (!prefs_) 498 if (!prefs_)
469 return; 499 return;
470 500
471 PluginFinder* finder = PluginFinder::GetInstance(); 501 PluginFinder* finder = PluginFinder::GetInstance();
472 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); 502 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList);
473 base::ListValue* plugins_list = update.Get(); 503 base::ListValue* plugins_list = update.Get();
474 plugins_list->Clear(); 504 plugins_list->Clear();
475 505
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 542 }
513 } 543 }
514 544
515 void PluginPrefs::NotifyPluginStatusChanged() { 545 void PluginPrefs::NotifyPluginStatusChanged() {
516 DCHECK_CURRENTLY_ON(BrowserThread::UI); 546 DCHECK_CURRENTLY_ON(BrowserThread::UI);
517 content::NotificationService::current()->Notify( 547 content::NotificationService::current()->Notify(
518 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, 548 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
519 content::Source<Profile>(profile_), 549 content::Source<Profile>(profile_),
520 content::NotificationService::NoDetails()); 550 content::NotificationService::NoDetails());
521 } 551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698