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 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ | 5 #ifndef CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ |
6 #define CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ | 6 #define CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "chrome/browser/plugins/plugin_finder.h" | 15 #include "chrome/browser/plugins/plugin_finder.h" |
16 #include "chrome/common/chrome_content_client.h" | 16 #include "chrome/common/chrome_content_client.h" |
17 #include "components/keyed_service/core/refcounted_keyed_service.h" | 17 #include "components/keyed_service/core/refcounted_keyed_service.h" |
18 #include "components/prefs/pref_change_registrar.h" | 18 #include "components/prefs/pref_change_registrar.h" |
19 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
20 | 20 |
21 class Profile; | 21 class Profile; |
22 | 22 |
23 namespace base { | |
24 class ListValue; | |
25 } | |
26 | |
27 namespace content { | 23 namespace content { |
28 struct WebPluginInfo; | 24 struct WebPluginInfo; |
29 } | 25 } |
30 | 26 |
31 // This class stores information about whether a plugin or a plugin group is | 27 // This class stores information about whether a plugin or a plugin group is |
32 // enabled or disabled. | 28 // enabled or disabled. |
33 // Except where otherwise noted, it can be used on every thread. | 29 // Except where otherwise noted, it can be used on every thread. |
34 class PluginPrefs : public RefcountedKeyedService { | 30 class PluginPrefs : public RefcountedKeyedService { |
35 public: | 31 public: |
36 enum PolicyStatus { | 32 enum PolicyStatus { |
(...skipping 11 matching lines...) Expand all Loading... |
48 static scoped_refptr<PluginPrefs> GetForTestingProfile(Profile* profile); | 44 static scoped_refptr<PluginPrefs> GetForTestingProfile(Profile* profile); |
49 | 45 |
50 // Creates a new instance. This method should only be used for testing. | 46 // Creates a new instance. This method should only be used for testing. |
51 PluginPrefs(); | 47 PluginPrefs(); |
52 | 48 |
53 // Associates this instance with |prefs|. This enables or disables | 49 // Associates this instance with |prefs|. This enables or disables |
54 // plugin groups as defined by the user's preferences. | 50 // plugin groups as defined by the user's preferences. |
55 // This method should only be called on the UI thread. | 51 // This method should only be called on the UI thread. |
56 void SetPrefs(PrefService* prefs); | 52 void SetPrefs(PrefService* prefs); |
57 | 53 |
58 // Enable or disable a plugin group. | |
59 void EnablePluginGroup(bool enable, const base::string16& group_name); | |
60 | |
61 // Enables or disables a specific plugin file, if possible. | |
62 // If the plugin state can't be changed (because of a policy for example) | |
63 // then enabling/disabling the plugin is ignored and |callback| is run | |
64 // with 'false' passed to it. Otherwise the plugin state is changed | |
65 // and |callback| is run with 'true' passed to it. | |
66 void EnablePlugin(bool enable, const base::FilePath& file_path, | |
67 const base::Callback<void(bool)>& callback); | |
68 | |
69 // Returns whether there is a policy enabling or disabling plugins of the | 54 // Returns whether there is a policy enabling or disabling plugins of the |
70 // given name. | 55 // given name. |
71 PolicyStatus PolicyStatusForPlugin(const base::string16& name) const; | 56 PolicyStatus PolicyStatusForPlugin(const base::string16& name) const; |
72 | 57 |
73 // Returns whether the plugin is enabled or not. | 58 // Returns whether the plugin is enabled or not. |
74 bool IsPluginEnabled(const content::WebPluginInfo& plugin) const; | 59 bool IsPluginEnabled(const content::WebPluginInfo& plugin) const; |
75 | 60 |
76 void set_profile(Profile* profile) { profile_ = profile; } | 61 void set_profile(Profile* profile) { profile_ = profile; } |
77 | 62 |
78 // RefCountedProfileKeyedBase method override. | 63 // RefCountedProfileKeyedBase method override. |
79 void ShutdownOnUIThread() override; | 64 void ShutdownOnUIThread() override; |
80 | 65 |
81 private: | 66 private: |
82 friend class base::RefCountedThreadSafe<PluginPrefs>; | 67 friend class base::RefCountedThreadSafe<PluginPrefs>; |
83 friend class PluginPrefsTest; | 68 friend class PluginPrefsTest; |
84 | 69 friend class PrintPreviewDialogControllerBrowserTest; |
85 // PluginState stores a mapping from plugin path to enable/disable state. We | |
86 // don't simply use a std::map, because we would like to keep the state of | |
87 // some plugins in sync with each other. | |
88 class PluginState { | |
89 public: | |
90 PluginState(); | |
91 ~PluginState(); | |
92 | |
93 // Returns whether |plugin| is found. If |plugin| cannot be found, | |
94 // |*enabled| won't be touched. | |
95 bool Get(const base::FilePath& plugin, bool* enabled) const; | |
96 void Set(const base::FilePath& plugin, bool enabled); | |
97 | |
98 private: | |
99 base::FilePath ConvertMapKey(const base::FilePath& plugin) const; | |
100 | |
101 std::map<base::FilePath, bool> state_; | |
102 }; | |
103 | 70 |
104 ~PluginPrefs() override; | 71 ~PluginPrefs() override; |
105 | 72 |
106 // Called to update one of the policy_xyz patterns below when a | |
107 // preference changes. | |
108 void UpdatePatternsAndNotify(std::set<base::string16>* patterns, | |
109 const std::string& pref_name); | |
110 | |
111 // Callback for changes to the AlwaysOpenPdfExternally policy. | 73 // Callback for changes to the AlwaysOpenPdfExternally policy. |
112 void UpdatePdfPolicy(const std::string& pref_name); | 74 void UpdatePdfPolicy(const std::string& pref_name); |
113 | 75 |
114 // Allows unit tests to directly set enforced plugin patterns. | |
115 void SetPolicyEnforcedPluginPatternsForTests( | |
116 const std::set<base::string16>& disabled_patterns, | |
117 const std::set<base::string16>& disabled_exception_patterns, | |
118 const std::set<base::string16>& enabled_patterns); | |
119 | |
120 // Allows unit tests to directly set the AlwaysOpenPdfExternally pref. | 76 // Allows unit tests to directly set the AlwaysOpenPdfExternally pref. |
121 void SetAlwaysOpenPdfExternallyForTests(bool always_open_pdf_externally); | 77 void SetAlwaysOpenPdfExternallyForTests(bool always_open_pdf_externally); |
122 | 78 |
123 // Callback for after the plugin groups have been loaded. | |
124 void EnablePluginGroupInternal( | |
125 bool enabled, | |
126 const base::string16& group_name, | |
127 const std::vector<content::WebPluginInfo>& plugins); | |
128 void EnablePluginInternal( | |
129 bool enabled, | |
130 const base::FilePath& path, | |
131 PluginFinder* plugin_finder, | |
132 const base::Callback<void(bool)>& callback, | |
133 const std::vector<content::WebPluginInfo>& plugins); | |
134 | |
135 // Called on the UI thread with the plugin data to save the preferences. | 79 // Called on the UI thread with the plugin data to save the preferences. |
136 void OnUpdatePreferences(const std::vector<content::WebPluginInfo>& plugins); | 80 void OnUpdatePreferences(const std::vector<content::WebPluginInfo>& plugins); |
137 | 81 |
138 // Sends the notification that plugin data has changed. | 82 // Sends the notification that plugin data has changed. |
139 void NotifyPluginStatusChanged(); | 83 void NotifyPluginStatusChanged(); |
140 | 84 |
141 static void ListValueToStringSet(const base::ListValue* src, | |
142 std::set<base::string16>* dest); | |
143 | |
144 // Checks if |name| matches any of the patterns in |pattern_set|. | |
145 static bool IsStringMatchedInSet(const base::string16& name, | |
146 const std::set<base::string16>& pattern_set); | |
147 | |
148 // Guards access to the following data structures. | 85 // Guards access to the following data structures. |
149 mutable base::Lock lock_; | 86 mutable base::Lock lock_; |
150 | 87 |
151 PluginState plugin_state_; | |
152 std::map<base::string16, bool> plugin_group_state_; | |
153 | |
154 std::set<base::string16> policy_disabled_plugin_patterns_; | |
155 std::set<base::string16> policy_disabled_plugin_exception_patterns_; | |
156 std::set<base::string16> policy_enabled_plugin_patterns_; | |
157 bool always_open_pdf_externally_; | 88 bool always_open_pdf_externally_; |
158 | 89 |
159 // Weak pointer, owns us. Only used as a notification source. | 90 // Weak pointer, owns us. Only used as a notification source. |
160 Profile* profile_; | 91 Profile* profile_; |
161 | 92 |
162 // Weak pointer, owned by the profile. | 93 // Weak pointer, owned by the profile. |
163 PrefService* prefs_; | 94 PrefService* prefs_; |
164 | 95 |
165 PrefChangeRegistrar registrar_; | 96 PrefChangeRegistrar registrar_; |
166 | 97 |
167 DISALLOW_COPY_AND_ASSIGN(PluginPrefs); | 98 DISALLOW_COPY_AND_ASSIGN(PluginPrefs); |
168 }; | 99 }; |
169 | 100 |
170 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ | 101 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ |
OLD | NEW |