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

Side by Side Diff: chrome/browser/plugin_prefs.h

Issue 7848025: Store plug-in enabled/disabled state in PluginPrefs instead of WebPluginInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: indent Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_PLUGIN_PREFS_H_ 5 #ifndef CHROME_BROWSER_PLUGIN_PREFS_H_
6 #define CHROME_BROWSER_PLUGIN_PREFS_H_ 6 #define CHROME_BROWSER_PLUGIN_PREFS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map>
9 #include <set> 10 #include <set>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/basictypes.h" 13 #include "base/basictypes.h"
13 #include "base/file_path.h" 14 #include "base/file_path.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/synchronization/lock.h"
15 #include "chrome/browser/prefs/pref_change_registrar.h" 17 #include "chrome/browser/prefs/pref_change_registrar.h"
16 #include "content/common/notification_observer.h" 18 #include "content/common/notification_observer.h"
17 19
18 class NotificationDetails; 20 class NotificationDetails;
19 class NotificationSource; 21 class NotificationSource;
20 class Profile; 22 class Profile;
21 23
22 namespace content { 24 namespace content {
23 class ResourceContext; 25 class ResourceContext;
24 } 26 }
25 27
26 namespace base { 28 namespace base {
27 class DictionaryValue; 29 class DictionaryValue;
28 class ListValue; 30 class ListValue;
29 } 31 }
30 32
31 namespace webkit { 33 namespace webkit {
32 struct WebPluginInfo; 34 struct WebPluginInfo;
33 namespace npapi { 35 namespace npapi {
34 class PluginGroup; 36 class PluginGroup;
35 } 37 }
36 } 38 }
37 39
38 // This class stores information about whether a plug-in or a plug-in group is 40 // This class stores information about whether a plug-in or a plug-in group is
39 // enabled or disabled. 41 // enabled or disabled.
40 // Except for the |IsPluginEnabled| method, it should only be used on the UI 42 // Except for the |IsPluginEnabled| method, it should only be used on the UI
41 // thread. 43 // thread.
Joao da Silva 2011/09/13 09:30:48 Please update this comment.
Bernhard Bauer 2011/09/13 12:13:01 Done.
42 class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, 44 class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>,
43 public NotificationObserver { 45 public NotificationObserver {
44 public: 46 public:
47 enum PolicyStatus {
48 NO_POLICY = 0, // Neither enabled or disabled by policy.
49 POLICY_ENABLED,
50 POLICY_DISABLED,
51 };
52
45 // Initializes the factory for this class for dependency tracking. 53 // Initializes the factory for this class for dependency tracking.
46 // This should be called before the first profile is created. 54 // This should be called before the first profile is created.
47 static void Initialize(); 55 static void Initialize();
48 56
49 // Returns the instance associated with |profile|, creating it if necessary. 57 // Returns the instance associated with |profile|, creating it if necessary.
50 static PluginPrefs* GetForProfile(Profile* profile); 58 static PluginPrefs* GetForProfile(Profile* profile);
51 59
52 // Creates a new instance. This method should only be used for testing. 60 // Creates a new instance. This method should only be used for testing.
53 PluginPrefs(); 61 PluginPrefs();
54 62
55 // Associates this instance with |prefs|. This enables or disables 63 // Associates this instance with |prefs|. This enables or disables
56 // plugin groups as defined by the user's preferences. 64 // plugin groups as defined by the user's preferences.
57 void SetPrefs(PrefService* prefs); 65 void SetPrefs(PrefService* prefs);
58 66
59 // Enable or disable a plugin group. 67 // Enable or disable a plugin group.
68 // This method should only be called on the FILE thread.
60 void EnablePluginGroup(bool enable, const string16& group_name); 69 void EnablePluginGroup(bool enable, const string16& group_name);
61 70
62 // Enable or disable a specific plugin file. 71 // Enable or disable a specific plugin file.
72 // This method should only be called on the FILE thread.
63 void EnablePlugin(bool enable, const FilePath& file_path); 73 void EnablePlugin(bool enable, const FilePath& file_path);
64 74
75 // All plug-ins default to being enabled until they're disabled by the user.
76 // This allows us to let a plug-in start out disabled, even for profiles that
77 // don't exist yet.
78 static void EnablePluginDefault(bool enable, const FilePath& file_path);
79
80 // Returns whether there is a policy enabling or disabling plug-ins of the
81 // given name.
82 PolicyStatus PolicyStatusForPlugin(const string16& name);
83
65 // Returns whether the plugin is enabled or not. 84 // Returns whether the plugin is enabled or not.
66 bool IsPluginEnabled(const webkit::WebPluginInfo& plugin); 85 bool IsPluginEnabled(const webkit::WebPluginInfo& plugin);
67 86
68 // Write the enable/disable status to the user's preference file.
69 void UpdatePreferences(int delay_ms);
70
71 // NotificationObserver method overrides 87 // NotificationObserver method overrides
72 virtual void Observe(int type, 88 virtual void Observe(int type,
73 const NotificationSource& source, 89 const NotificationSource& source,
74 const NotificationDetails& details); 90 const NotificationDetails& details);
Joao da Silva 2011/09/13 09:30:48 OVERRIDE
Bernhard Bauer 2011/09/13 12:13:01 Done.
75 91
76 static void RegisterPrefs(PrefService* prefs); 92 static void RegisterPrefs(PrefService* prefs);
77 93
78 void ShutdownOnUIThread(); 94 void ShutdownOnUIThread();
79 95
80 private: 96 private:
81 friend class base::RefCountedThreadSafe<PluginPrefs>; 97 friend class base::RefCountedThreadSafe<PluginPrefs>;
98 friend class PluginPrefsTest;
82 99
83 class Factory; 100 class Factory;
84 101
85 virtual ~PluginPrefs(); 102 virtual ~PluginPrefs();
86 103
104 void SetPolicyEnforcedPluginPatterns(
105 const std::set<string16>& disabled_patterns,
106 const std::set<string16>& disabled_exception_patterns,
107 const std::set<string16>& enabled_patterns);
108
87 // Called on the file thread to get the data necessary to update the saved 109 // Called on the file thread to get the data necessary to update the saved
88 // preferences. 110 // preferences.
89 void GetPreferencesDataOnFileThread(); 111 void GetPreferencesDataOnFileThread();
90 112
91 // Called on the UI thread with the plugin data to save the preferences. 113 // Called on the UI thread with the plugin data to save the preferences.
92 void OnUpdatePreferences(std::vector<webkit::WebPluginInfo> plugins, 114 void OnUpdatePreferences(std::vector<webkit::npapi::PluginGroup> groups);
93 std::vector<webkit::npapi::PluginGroup> groups);
94 115
95 // Queues sending the notification that plugin data has changed. This is done 116 // Sends the notification that plugin data has changed.
96 // so that if a bunch of changes happen, we only send one notification.
97 void NotifyPluginStatusChanged(); 117 void NotifyPluginStatusChanged();
98 118
99 // Used for the post task to notify that plugin enabled status changed. 119 // Used for the post task to notify that plugin enabled status changed.
100 void OnNotifyPluginStatusChanged(); 120 void OnNotifyPluginStatusChanged();
101 121
102 base::DictionaryValue* CreatePluginFileSummary( 122 static void ListValueToStringSet(const base::ListValue* src,
103 const webkit::WebPluginInfo& plugin); 123 std::set<string16>* dest);
104 124
105 // Force plugins to be enabled or disabled due to policy. 125 // Checks if |name| matches any of the patterns in |pattern_set|.
106 // |disabled_list| contains the list of StringValues of the names of the 126 static bool IsStringMatchedInSet(const string16& name,
107 // policy-disabled plugins, |exceptions_list| the policy-allowed plugins, 127 const std::set<string16>& pattern_set);
108 // and |enabled_list| the policy-enabled plugins.
109 void UpdatePluginsStateFromPolicy(const base::ListValue* disabled_list,
110 const base::ListValue* exceptions_list,
111 const base::ListValue* enabled_list);
112 128
113 void ListValueToStringSet(const base::ListValue* src, 129 mutable base::Lock lock_;
114 std::set<string16>* dest); 130
131 std::map<FilePath, bool> plugin_state_;
132 std::map<string16, bool> plugin_group_state_;
133
134 std::set<string16> policy_disabled_plugin_patterns_;
135 std::set<string16> policy_disabled_plugin_exception_patterns_;
136 std::set<string16> policy_enabled_plugin_patterns_;
115 137
116 // Weak pointer, owned by the profile. 138 // Weak pointer, owned by the profile.
117 PrefService* prefs_; 139 PrefService* prefs_;
118 140
119 PrefChangeRegistrar registrar_; 141 PrefChangeRegistrar registrar_;
120 142
121 bool notify_pending_;
122
123 DISALLOW_COPY_AND_ASSIGN(PluginPrefs); 143 DISALLOW_COPY_AND_ASSIGN(PluginPrefs);
124 }; 144 };
125 145
126 #endif // CHROME_BROWSER_PLUGIN_PREFS_H_ 146 #endif // CHROME_BROWSER_PLUGIN_PREFS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698