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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ 6 #define CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ 7 8 #include <string> 9 10 #include "base/macros.h" 11 #include "base/memory/scoped_refptr.h" 12 #include "base/strings/string16.h" 13 #include "components/keyed_service/core/refcounted_keyed_service.h" 14 #include "components/prefs/pref_change_registrar.h" 15 #include "components/prefs/pref_service.h" 16 17 class Profile; 18 19 namespace content { 20 struct WebPluginInfo; 21 } 22 23 // This class stores information about whether a plugin or a plugin group is 24 // enabled or disabled. 25 // Except where otherwise noted, it can be used on every thread. 26 class PluginPrefs : public RefcountedKeyedService { 27 public: 28 enum PolicyStatus { 29 NO_POLICY = 0, // Neither enabled or disabled by policy. 30 POLICY_ENABLED, 31 POLICY_DISABLED, 32 }; 33 34 // Returns the instance associated with |profile|, creating it if necessary. 35 static scoped_refptr<PluginPrefs> GetForProfile(Profile* profile); 36 37 // Usually the PluginPrefs associated with a TestingProfile is NULL. 38 // This method overrides that for a given TestingProfile, returning the newly 39 // created PluginPrefs object. 40 static scoped_refptr<PluginPrefs> GetForTestingProfile(Profile* profile); 41 42 // Creates a new instance. This method should only be used for testing. 43 PluginPrefs(); 44 45 // Associates this instance with |prefs|. This enables or disables 46 // plugin groups as defined by the user's preferences. 47 // This method should only be called on the UI thread. 48 void SetPrefs(PrefService* prefs); 49 50 // Returns whether there is a policy enabling or disabling plugins of the 51 // given name. 52 PolicyStatus PolicyStatusForPlugin(const base::string16& name) const; 53 54 // Returns whether the plugin is enabled or not. 55 bool IsPluginEnabled(const content::WebPluginInfo& plugin) const; 56 set_profile(Profile * profile)57 void set_profile(Profile* profile) { profile_ = profile; } 58 59 // RefCountedProfileKeyedBase method override. 60 void ShutdownOnUIThread() override; 61 62 private: 63 friend class base::RefCountedThreadSafe<PluginPrefs>; 64 friend class PDFIFrameNavigationThrottleTest; 65 friend class PluginPrefsTest; 66 friend class PrintPreviewDialogControllerBrowserTest; 67 68 ~PluginPrefs() override; 69 70 // Callback for changes to the AlwaysOpenPdfExternally policy. 71 void UpdatePdfPolicy(const std::string& pref_name); 72 73 // Allows unit tests to directly set the AlwaysOpenPdfExternally pref. 74 void SetAlwaysOpenPdfExternallyForTests(bool always_open_pdf_externally); 75 76 bool always_open_pdf_externally_ = false; 77 78 Profile* profile_ = nullptr; 79 80 // Weak pointer, owned by the profile. 81 PrefService* prefs_ = nullptr; 82 83 PrefChangeRegistrar registrar_; 84 85 DISALLOW_COPY_AND_ASSIGN(PluginPrefs); 86 }; 87 88 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ 89