Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ |
6 | #define CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ | ||||
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 7 | |
Mark Rowe | 9204545e | 2023-12-29 14:32:16 | [diff] [blame] | 8 | #include <memory> |
Maksim Ivanov | ab376d5 | 2019-04-01 23:58:11 | [diff] [blame] | 9 | #include <string> |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 10 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 11 | #include "base/memory/raw_ptr.h" |
Maksim Ivanov | ab376d5 | 2019-04-01 23:58:11 | [diff] [blame] | 12 | #include "base/memory/scoped_refptr.h" |
sdefresne | 2eb633d | 2014-10-08 12:31:56 | [diff] [blame] | 13 | #include "components/keyed_service/core/refcounted_keyed_service.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 14 | #include "components/prefs/pref_change_registrar.h" |
15 | #include "components/prefs/pref_service.h" | ||||
Lei Zhang | 9bec86a | 2021-06-23 19:58:54 | [diff] [blame] | 16 | #include "ppapi/buildflags/buildflags.h" |
17 | |||||
18 | #if !BUILDFLAG(ENABLE_PLUGINS) | ||||
19 | #error "Plugins should be enabled" | ||||
20 | #endif | ||||
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 21 | |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 22 | class Profile; |
23 | |||||
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 24 | namespace content { |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 25 | struct WebPluginInfo; |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 26 | } |
27 | |||||
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 28 | // This class stores information about whether a plugin or a plugin group is |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 29 | // enabled or disabled. |
[email protected] | f7be2cba | 2011-09-15 15:33:45 | [diff] [blame] | 30 | // Except where otherwise noted, it can be used on every thread. |
sdefresne | 2eb633d | 2014-10-08 12:31:56 | [diff] [blame] | 31 | class PluginPrefs : public RefcountedKeyedService { |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 32 | public: |
[email protected] | e0379d5 | 2011-09-02 20:08:47 | [diff] [blame] | 33 | // Returns the instance associated with |profile|, creating it if necessary. |
[email protected] | abc7724 | 2012-03-16 04:32:31 | [diff] [blame] | 34 | static scoped_refptr<PluginPrefs> GetForProfile(Profile* profile); |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 35 | |
[email protected] | f7be2cba | 2011-09-15 15:33:45 | [diff] [blame] | 36 | // Usually the PluginPrefs associated with a TestingProfile is NULL. |
37 | // This method overrides that for a given TestingProfile, returning the newly | ||||
38 | // created PluginPrefs object. | ||||
[email protected] | abc7724 | 2012-03-16 04:32:31 | [diff] [blame] | 39 | static scoped_refptr<PluginPrefs> GetForTestingProfile(Profile* profile); |
[email protected] | f7be2cba | 2011-09-15 15:33:45 | [diff] [blame] | 40 | |
Peter Boström | fadb175 | 2021-09-30 19:17:01 | [diff] [blame] | 41 | PluginPrefs(const PluginPrefs&) = delete; |
42 | PluginPrefs& operator=(const PluginPrefs&) = delete; | ||||
43 | |||||
[email protected] | e0379d5 | 2011-09-02 20:08:47 | [diff] [blame] | 44 | // Creates a new instance. This method should only be used for testing. |
45 | PluginPrefs(); | ||||
46 | |||||
47 | // Associates this instance with |prefs|. This enables or disables | ||||
48 | // plugin groups as defined by the user's preferences. | ||||
[email protected] | f7be2cba | 2011-09-15 15:33:45 | [diff] [blame] | 49 | // This method should only be called on the UI thread. |
[email protected] | e0379d5 | 2011-09-02 20:08:47 | [diff] [blame] | 50 | void SetPrefs(PrefService* prefs); |
51 | |||||
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 52 | // Returns whether the plugin is enabled or not. |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 53 | bool IsPluginEnabled(const content::WebPluginInfo& plugin) const; |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 54 | |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 55 | void set_profile(Profile* profile) { profile_ = profile; } |
56 | |||||
[email protected] | 498e0a6e | 2012-02-15 14:52:10 | [diff] [blame] | 57 | // RefCountedProfileKeyedBase method override. |
dcheng | 99b1bc2 | 2014-10-22 18:47:42 | [diff] [blame] | 58 | void ShutdownOnUIThread() override; |
[email protected] | 498e0a6e | 2012-02-15 14:52:10 | [diff] [blame] | 59 | |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 60 | private: |
61 | friend class base::RefCountedThreadSafe<PluginPrefs>; | ||||
Amber Won | 6b5edc75 | 2017-08-17 19:23:54 | [diff] [blame] | 62 | friend class PDFIFrameNavigationThrottleTest; |
K. Moon | 370bcbc | 2022-08-29 22:07:38 | [diff] [blame] | 63 | friend class PluginInfoHostImplTest; |
[email protected] | f7be2cba | 2011-09-15 15:33:45 | [diff] [blame] | 64 | friend class PluginPrefsTest; |
pastarmovj | 8b32e59 | 2016-11-21 15:30:44 | [diff] [blame] | 65 | friend class PrintPreviewDialogControllerBrowserTest; |
[email protected] | 65a0c61 | 2012-09-11 03:35:24 | [diff] [blame] | 66 | |
dcheng | 99b1bc2 | 2014-10-22 18:47:42 | [diff] [blame] | 67 | ~PluginPrefs() override; |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 68 | |
pastarmovj | d5e6f66 | 2016-10-05 16:52:17 | [diff] [blame] | 69 | // Callback for changes to the AlwaysOpenPdfExternally policy. |
70 | void UpdatePdfPolicy(const std::string& pref_name); | ||||
71 | |||||
pastarmovj | d5e6f66 | 2016-10-05 16:52:17 | [diff] [blame] | 72 | // Allows unit tests to directly set the AlwaysOpenPdfExternally pref. |
73 | void SetAlwaysOpenPdfExternallyForTests(bool always_open_pdf_externally); | ||||
74 | |||||
Evan Stade | 53b5a52 | 2019-06-25 01:46:53 | [diff] [blame] | 75 | bool always_open_pdf_externally_ = false; |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 76 | |
Christian Xu | 4f5f7b6 | 2023-09-11 03:22:18 | [diff] [blame] | 77 | raw_ptr<Profile> profile_ = nullptr; |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 78 | |
79 | // Weak pointer, owned by the profile. | ||||
Christian Xu | 4f5f7b6 | 2023-09-11 03:22:18 | [diff] [blame] | 80 | raw_ptr<PrefService> prefs_ = nullptr; |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 81 | |
Mark Rowe | 9204545e | 2023-12-29 14:32:16 | [diff] [blame] | 82 | std::unique_ptr<PrefChangeRegistrar> registrar_; |
[email protected] | 8a271368 | 2011-08-19 10:36:59 | [diff] [blame] | 83 | }; |
84 | |||||
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 85 | #endif // CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ |