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/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/prefs/pref_change_registrar.h" | 14 #include "base/prefs/pref_change_registrar.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "chrome/browser/plugins/plugin_finder.h" | 17 #include "chrome/browser/plugins/plugin_finder.h" |
18 #include "components/browser_context_keyed_service/refcounted_browser_context_ke
yed_service.h" | 18 #include "components/browser_context_keyed_service/refcounted_browser_context_ke
yed_service.h" |
19 | 19 |
20 class Profile; | 20 class Profile; |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class ListValue; | 23 class ListValue; |
24 } | 24 } |
25 | 25 |
26 namespace webkit { | 26 namespace webkit { |
27 struct WebPluginInfo; | 27 struct WebPluginInfo; |
28 namespace npapi { | |
29 class PluginList; | |
30 } | |
31 } | 28 } |
32 | 29 |
33 // This class stores information about whether a plug-in or a plug-in group is | 30 // This class stores information about whether a plug-in or a plug-in group is |
34 // enabled or disabled. | 31 // enabled or disabled. |
35 // Except where otherwise noted, it can be used on every thread. | 32 // Except where otherwise noted, it can be used on every thread. |
36 class PluginPrefs : public RefcountedBrowserContextKeyedService { | 33 class PluginPrefs : public RefcountedBrowserContextKeyedService { |
37 public: | 34 public: |
38 enum PolicyStatus { | 35 enum PolicyStatus { |
39 NO_POLICY = 0, // Neither enabled or disabled by policy. | 36 NO_POLICY = 0, // Neither enabled or disabled by policy. |
40 POLICY_ENABLED, | 37 POLICY_ENABLED, |
41 POLICY_DISABLED, | 38 POLICY_DISABLED, |
42 }; | 39 }; |
43 | 40 |
44 // Returns the instance associated with |profile|, creating it if necessary. | 41 // Returns the instance associated with |profile|, creating it if necessary. |
45 static scoped_refptr<PluginPrefs> GetForProfile(Profile* profile); | 42 static scoped_refptr<PluginPrefs> GetForProfile(Profile* profile); |
46 | 43 |
47 // Usually the PluginPrefs associated with a TestingProfile is NULL. | 44 // Usually the PluginPrefs associated with a TestingProfile is NULL. |
48 // This method overrides that for a given TestingProfile, returning the newly | 45 // This method overrides that for a given TestingProfile, returning the newly |
49 // created PluginPrefs object. | 46 // created PluginPrefs object. |
50 static scoped_refptr<PluginPrefs> GetForTestingProfile(Profile* profile); | 47 static scoped_refptr<PluginPrefs> GetForTestingProfile(Profile* profile); |
51 | 48 |
52 // Sets the plug-in list for tests. | |
53 void SetPluginListForTesting(webkit::npapi::PluginList* plugin_list); | |
54 | |
55 // Creates a new instance. This method should only be used for testing. | 49 // Creates a new instance. This method should only be used for testing. |
56 PluginPrefs(); | 50 PluginPrefs(); |
57 | 51 |
58 // Associates this instance with |prefs|. This enables or disables | 52 // Associates this instance with |prefs|. This enables or disables |
59 // plugin groups as defined by the user's preferences. | 53 // plugin groups as defined by the user's preferences. |
60 // This method should only be called on the UI thread. | 54 // This method should only be called on the UI thread. |
61 void SetPrefs(PrefService* prefs); | 55 void SetPrefs(PrefService* prefs); |
62 | 56 |
63 // Enable or disable a plugin group. | 57 // Enable or disable a plugin group. |
64 void EnablePluginGroup(bool enable, const string16& group_name); | 58 void EnablePluginGroup(bool enable, const string16& group_name); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // preference changes. | 106 // preference changes. |
113 void UpdatePatternsAndNotify(std::set<string16>* patterns, | 107 void UpdatePatternsAndNotify(std::set<string16>* patterns, |
114 const std::string& pref_name); | 108 const std::string& pref_name); |
115 | 109 |
116 // Allows unit tests to directly set enforced plug-in patterns. | 110 // Allows unit tests to directly set enforced plug-in patterns. |
117 void SetPolicyEnforcedPluginPatterns( | 111 void SetPolicyEnforcedPluginPatterns( |
118 const std::set<string16>& disabled_patterns, | 112 const std::set<string16>& disabled_patterns, |
119 const std::set<string16>& disabled_exception_patterns, | 113 const std::set<string16>& disabled_exception_patterns, |
120 const std::set<string16>& enabled_patterns); | 114 const std::set<string16>& enabled_patterns); |
121 | 115 |
122 // Returns the plugin list to use, either the singleton or the override. | |
123 webkit::npapi::PluginList* GetPluginList() const; | |
124 | |
125 // Callback for after the plugin groups have been loaded. | 116 // Callback for after the plugin groups have been loaded. |
126 void EnablePluginGroupInternal( | 117 void EnablePluginGroupInternal( |
127 bool enabled, | 118 bool enabled, |
128 const string16& group_name, | 119 const string16& group_name, |
129 const std::vector<webkit::WebPluginInfo>& plugins); | 120 const std::vector<webkit::WebPluginInfo>& plugins); |
130 void EnablePluginInternal( | 121 void EnablePluginInternal( |
131 bool enabled, | 122 bool enabled, |
132 const base::FilePath& path, | 123 const base::FilePath& path, |
133 PluginFinder* plugin_finder, | 124 PluginFinder* plugin_finder, |
134 const base::Callback<void(bool)>& callback, | 125 const base::Callback<void(bool)>& callback, |
135 const std::vector<webkit::WebPluginInfo>& plugins); | 126 const std::vector<webkit::WebPluginInfo>& plugins); |
136 | 127 |
137 // Called on the file thread to get the data necessary to update the saved | |
138 // preferences. | |
139 void GetPreferencesDataOnFileThread(); | |
140 | |
141 // Called on the UI thread with the plugin data to save the preferences. | 128 // Called on the UI thread with the plugin data to save the preferences. |
142 void OnUpdatePreferences(const std::vector<webkit::WebPluginInfo>& plugins); | 129 void OnUpdatePreferences(const std::vector<webkit::WebPluginInfo>& plugins); |
143 | 130 |
144 // Sends the notification that plugin data has changed. | 131 // Sends the notification that plugin data has changed. |
145 void NotifyPluginStatusChanged(); | 132 void NotifyPluginStatusChanged(); |
146 | 133 |
147 static void ListValueToStringSet(const base::ListValue* src, | 134 static void ListValueToStringSet(const base::ListValue* src, |
148 std::set<string16>* dest); | 135 std::set<string16>* dest); |
149 | 136 |
150 // Checks if |name| matches any of the patterns in |pattern_set|. | 137 // Checks if |name| matches any of the patterns in |pattern_set|. |
151 static bool IsStringMatchedInSet(const string16& name, | 138 static bool IsStringMatchedInSet(const string16& name, |
152 const std::set<string16>& pattern_set); | 139 const std::set<string16>& pattern_set); |
153 | 140 |
154 // Guards access to the following data structures. | 141 // Guards access to the following data structures. |
155 mutable base::Lock lock_; | 142 mutable base::Lock lock_; |
156 | 143 |
157 PluginState plugin_state_; | 144 PluginState plugin_state_; |
158 std::map<string16, bool> plugin_group_state_; | 145 std::map<string16, bool> plugin_group_state_; |
159 | 146 |
160 std::set<string16> policy_disabled_plugin_patterns_; | 147 std::set<string16> policy_disabled_plugin_patterns_; |
161 std::set<string16> policy_disabled_plugin_exception_patterns_; | 148 std::set<string16> policy_disabled_plugin_exception_patterns_; |
162 std::set<string16> policy_enabled_plugin_patterns_; | 149 std::set<string16> policy_enabled_plugin_patterns_; |
163 | 150 |
164 // Weak pointer, owns us. Only used as a notification source. | 151 // Weak pointer, owns us. Only used as a notification source. |
165 Profile* profile_; | 152 Profile* profile_; |
166 | 153 |
167 // Weak pointer, owned by the profile. | 154 // Weak pointer, owned by the profile. |
168 PrefService* prefs_; | 155 PrefService* prefs_; |
169 | 156 |
170 // PluginList to use for testing. If this is NULL, defaults to the global | |
171 // singleton. | |
172 webkit::npapi::PluginList* plugin_list_; | |
173 | |
174 PrefChangeRegistrar registrar_; | 157 PrefChangeRegistrar registrar_; |
175 | 158 |
176 DISALLOW_COPY_AND_ASSIGN(PluginPrefs); | 159 DISALLOW_COPY_AND_ASSIGN(PluginPrefs); |
177 }; | 160 }; |
178 | 161 |
179 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ | 162 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_PREFS_H_ |
OLD | NEW |