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.cc

Issue 7564006: Rename PluginUpdater to PluginPrefs and make it per-profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 9 years, 4 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 #include "chrome/browser/plugin_updater.h" 5 #include "chrome/browser/plugin_prefs.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/singleton.h"
10 #include "base/message_loop.h" 12 #include "base/message_loop.h"
11 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/synchronization/lock.h"
Elliot Glaysher 2011/08/04 17:51:00 I don't see you using a lock in this file. Left ov
Bernhard Bauer 2011/08/05 13:42:20 Yup. Gone.
12 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 16 #include "base/values.h"
14 #include "base/version.h" 17 #include "base/version.h"
15 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/prefs/scoped_user_pref_update.h" 19 #include "chrome/browser/prefs/scoped_user_pref_update.h"
17 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_dependency_manager.h"
22 #include "chrome/browser/profiles/profile_keyed_service.h"
23 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
18 #include "chrome/common/chrome_content_client.h" 24 #include "chrome/common/chrome_content_client.h"
19 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
22 #include "content/browser/browser_thread.h" 29 #include "content/browser/browser_thread.h"
23 #include "content/common/notification_service.h" 30 #include "content/common/notification_service.h"
24 #include "webkit/plugins/npapi/plugin_list.h" 31 #include "webkit/plugins/npapi/plugin_list.h"
25 #include "webkit/plugins/npapi/webplugininfo.h" 32 #include "webkit/plugins/npapi/webplugininfo.h"
26 33
27 // How long to wait to save the plugin enabled information, which might need to 34 // How long to wait to save the plugin enabled information, which might need to
28 // go to disk. 35 // go to disk.
29 #define kPluginUpdateDelayMs (60 * 1000) 36 #define kPluginUpdateDelayMs (60 * 1000)
30 37
31 PluginUpdater::PluginUpdater() 38 class PluginPrefs::Factory : public ProfileKeyedServiceFactory {
32 : notify_pending_(false) { 39 public:
40 static Factory* GetInstance();
41
42 PluginPrefs* GetPluginPrefsForProfile(Profile* profile);
43
44 private:
45 friend struct DefaultSingletonTraits<Factory>;
46
47 Factory();
48 virtual ~Factory() {}
49
50 // ProfileKeyedServiceFactory methods:
51 virtual ProfileKeyedService* BuildServiceInstanceFor(
52 Profile* profile) const OVERRIDE;
53 virtual bool ServiceRedirectedInIncognito() OVERRIDE { return true; }
54 virtual bool ServiceIsCreatedWithProfile() OVERRIDE { return true; }
55
56 };
57
58 struct PluginPrefs::PluginInfo {
59 std::vector<webkit::npapi::WebPluginInfo> plugins;
60 std::vector<webkit::npapi::PluginGroup> groups;
61 };
62
63 // static
64 void PluginPrefs::Initialize() {
65 Factory::GetInstance();
33 } 66 }
34 67
35 DictionaryValue* PluginUpdater::CreatePluginFileSummary( 68 // static
69 PluginPrefs* PluginPrefs::GetForProfile(Profile* profile) {
70 return Factory::GetInstance()->GetPluginPrefsForProfile(profile);
71 }
72
73 DictionaryValue* PluginPrefs::CreatePluginFileSummary(
36 const webkit::npapi::WebPluginInfo& plugin) { 74 const webkit::npapi::WebPluginInfo& plugin) {
37 DictionaryValue* data = new DictionaryValue(); 75 DictionaryValue* data = new DictionaryValue();
38 data->SetString("path", plugin.path.value()); 76 data->SetString("path", plugin.path.value());
39 data->SetString("name", plugin.name); 77 data->SetString("name", plugin.name);
40 data->SetString("version", plugin.version); 78 data->SetString("version", plugin.version);
41 data->SetBoolean("enabled", webkit::npapi::IsPluginEnabled(plugin)); 79 data->SetBoolean("enabled", IsPluginEnabled(plugin));
42 return data; 80 return data;
43 } 81 }
44 82
45 // static 83 void PluginPrefs::EnablePluginGroup(bool enable, const string16& group_name) {
46 ListValue* PluginUpdater::GetPluginGroupsData() {
47 std::vector<webkit::npapi::PluginGroup> plugin_groups;
48 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, &plugin_groups);
49
50 // Construct DictionaryValues to return to the UI
51 ListValue* plugin_groups_data = new ListValue();
52 for (size_t i = 0; i < plugin_groups.size(); ++i) {
53 plugin_groups_data->Append(plugin_groups[i].GetDataForUI());
54 }
55 return plugin_groups_data;
56 }
57
58 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) {
59 webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name); 84 webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name);
60 NotifyPluginStatusChanged(); 85 NotifyPluginStatusChanged();
61 } 86 }
62 87
63 void PluginUpdater::EnablePlugin(bool enable, 88 void PluginPrefs::EnablePlugin(bool enable, const FilePath& path) {
64 const FilePath::StringType& path) {
65 FilePath file_path(path);
66 if (enable) 89 if (enable)
67 webkit::npapi::PluginList::Singleton()->EnablePlugin(file_path); 90 webkit::npapi::PluginList::Singleton()->EnablePlugin(path);
68 else 91 else
69 webkit::npapi::PluginList::Singleton()->DisablePlugin(file_path); 92 webkit::npapi::PluginList::Singleton()->DisablePlugin(path);
70 93
71 NotifyPluginStatusChanged(); 94 NotifyPluginStatusChanged();
72 } 95 }
73 96
74 void PluginUpdater::Observe(int type, 97 bool PluginPrefs::IsPluginEnabled(const webkit::npapi::WebPluginInfo& plugin) {
98 // If enabling NaCl, make sure the plugin is also enabled. See bug
99 // http://code.google.com/p/chromium/issues/detail?id=81010 for more
100 // information.
101 // TODO(dspringer): When NaCl is on by default, remove this code.
102 if ((plugin.name ==
103 ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName)) &&
104 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl)) {
105 return true;
106 }
107 return webkit::npapi::IsPluginEnabled(plugin);
108 }
109
110 void PluginPrefs::Observe(int type,
75 const NotificationSource& source, 111 const NotificationSource& source,
76 const NotificationDetails& details) { 112 const NotificationDetails& details) {
77 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); 113 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type);
78 const std::string* pref_name = Details<std::string>(details).ptr(); 114 const std::string* pref_name = Details<std::string>(details).ptr();
79 if (!pref_name) { 115 if (!pref_name) {
80 NOTREACHED(); 116 NOTREACHED();
81 return; 117 return;
82 } 118 }
119 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr());
83 if (*pref_name == prefs::kPluginsDisabledPlugins || 120 if (*pref_name == prefs::kPluginsDisabledPlugins ||
84 *pref_name == prefs::kPluginsDisabledPluginsExceptions || 121 *pref_name == prefs::kPluginsDisabledPluginsExceptions ||
85 *pref_name == prefs::kPluginsEnabledPlugins) { 122 *pref_name == prefs::kPluginsEnabledPlugins) {
86 PrefService* pref_service = Source<PrefService>(source).ptr();
87 const ListValue* disabled_list = 123 const ListValue* disabled_list =
88 pref_service->GetList(prefs::kPluginsDisabledPlugins); 124 prefs_->GetList(prefs::kPluginsDisabledPlugins);
89 const ListValue* exceptions_list = 125 const ListValue* exceptions_list =
90 pref_service->GetList(prefs::kPluginsDisabledPluginsExceptions); 126 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions);
91 const ListValue* enabled_list = 127 const ListValue* enabled_list =
92 pref_service->GetList(prefs::kPluginsEnabledPlugins); 128 prefs_->GetList(prefs::kPluginsEnabledPlugins);
93 UpdatePluginsStateFromPolicy(disabled_list, exceptions_list, enabled_list); 129 UpdatePluginsStateFromPolicy(disabled_list, exceptions_list, enabled_list);
94 } 130 }
95 } 131 }
96 132
97 void PluginUpdater::UpdatePluginsStateFromPolicy( 133 void PluginPrefs::UpdatePluginsStateFromPolicy(
98 const ListValue* disabled_list, 134 const ListValue* disabled_list,
99 const ListValue* exceptions_list, 135 const ListValue* exceptions_list,
100 const ListValue* enabled_list) { 136 const ListValue* enabled_list) {
101 std::set<string16> disabled_plugin_patterns; 137 std::set<string16> disabled_plugin_patterns;
102 std::set<string16> disabled_plugin_exception_patterns; 138 std::set<string16> disabled_plugin_exception_patterns;
103 std::set<string16> enabled_plugin_patterns; 139 std::set<string16> enabled_plugin_patterns;
104 140
105 ListValueToStringSet(disabled_list, &disabled_plugin_patterns); 141 ListValueToStringSet(disabled_list, &disabled_plugin_patterns);
106 ListValueToStringSet(exceptions_list, &disabled_plugin_exception_patterns); 142 ListValueToStringSet(exceptions_list, &disabled_plugin_exception_patterns);
107 ListValueToStringSet(enabled_list, &enabled_plugin_patterns); 143 ListValueToStringSet(enabled_list, &enabled_plugin_patterns);
108 144
109 webkit::npapi::PluginGroup::SetPolicyEnforcedPluginPatterns( 145 webkit::npapi::PluginGroup::SetPolicyEnforcedPluginPatterns(
110 disabled_plugin_patterns, 146 disabled_plugin_patterns,
111 disabled_plugin_exception_patterns, 147 disabled_plugin_exception_patterns,
112 enabled_plugin_patterns); 148 enabled_plugin_patterns);
113 149
114 NotifyPluginStatusChanged(); 150 NotifyPluginStatusChanged();
115 } 151 }
116 152
117 void PluginUpdater::ListValueToStringSet(const ListValue* src, 153 void PluginPrefs::ListValueToStringSet(const ListValue* src,
118 std::set<string16>* dest) { 154 std::set<string16>* dest) {
119 DCHECK(src); 155 DCHECK(src);
120 DCHECK(dest); 156 DCHECK(dest);
121 ListValue::const_iterator end(src->end()); 157 ListValue::const_iterator end(src->end());
122 for (ListValue::const_iterator current(src->begin()); 158 for (ListValue::const_iterator current(src->begin());
123 current != end; ++current) { 159 current != end; ++current) {
124 string16 plugin_name; 160 string16 plugin_name;
125 if ((*current)->GetAsString(&plugin_name)) { 161 if ((*current)->GetAsString(&plugin_name)) {
126 dest->insert(plugin_name); 162 dest->insert(plugin_name);
127 } 163 }
128 } 164 }
129 } 165 }
130 166
131 void PluginUpdater::SetProfile(Profile* profile) { 167 void PluginPrefs::SetProfile(Profile* profile) {
168 prefs_ = profile->GetPrefs();
132 bool update_internal_dir = false; 169 bool update_internal_dir = false;
133 FilePath last_internal_dir = 170 FilePath last_internal_dir =
134 profile->GetPrefs()->GetFilePath(prefs::kPluginsLastInternalDirectory); 171 prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory);
135 FilePath cur_internal_dir; 172 FilePath cur_internal_dir;
136 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && 173 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) &&
137 cur_internal_dir != last_internal_dir) { 174 cur_internal_dir != last_internal_dir) {
138 update_internal_dir = true; 175 update_internal_dir = true;
139 profile->GetPrefs()->SetFilePath( 176 prefs_->SetFilePath(
140 prefs::kPluginsLastInternalDirectory, cur_internal_dir); 177 prefs::kPluginsLastInternalDirectory, cur_internal_dir);
141 } 178 }
142 179
143 bool force_enable_internal_pdf = false; 180 bool force_enable_internal_pdf = false;
144 bool internal_pdf_enabled = false; 181 bool internal_pdf_enabled = false;
145 string16 pdf_group_name = 182 string16 pdf_group_name =
146 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); 183 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName);
147 FilePath pdf_path; 184 FilePath pdf_path;
148 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); 185 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
149 FilePath::StringType pdf_path_str = pdf_path.value(); 186 FilePath::StringType pdf_path_str = pdf_path.value();
150 if (!profile->GetPrefs()->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { 187 if (!prefs_->GetBoolean(prefs::kPluginsEnabledInternalPDF)) {
151 // We switched to the internal pdf plugin being on by default, and so we 188 // We switched to the internal pdf plugin being on by default, and so we
152 // need to force it to be enabled. We only want to do it this once though, 189 // need to force it to be enabled. We only want to do it this once though,
153 // i.e. we don't want to enable it again if the user disables it afterwards. 190 // i.e. we don't want to enable it again if the user disables it afterwards.
154 profile->GetPrefs()->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); 191 prefs_->SetBoolean(prefs::kPluginsEnabledInternalPDF, true);
155 force_enable_internal_pdf = true; 192 force_enable_internal_pdf = true;
156 } 193 }
157 194
158 { // Scoped update of prefs::kPluginsPluginsList. 195 { // Scoped update of prefs::kPluginsPluginsList.
159 ListPrefUpdate update(profile->GetPrefs(), prefs::kPluginsPluginsList); 196 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList);
160 ListValue* saved_plugins_list = update.Get(); 197 ListValue* saved_plugins_list = update.Get();
161 if (saved_plugins_list && !saved_plugins_list->empty()) { 198 if (saved_plugins_list && !saved_plugins_list->empty()) {
162 for (ListValue::const_iterator it = saved_plugins_list->begin(); 199 for (ListValue::const_iterator it = saved_plugins_list->begin();
163 it != saved_plugins_list->end(); 200 it != saved_plugins_list->end();
164 ++it) { 201 ++it) {
165 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { 202 if (!(*it)->IsType(Value::TYPE_DICTIONARY)) {
166 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; 203 LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList;
167 continue; // Oops, don't know what to do with this item. 204 continue; // Oops, don't know what to do with this item.
168 } 205 }
169 206
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // If the saved plugin list is empty, then the call to UpdatePreferences() 251 // If the saved plugin list is empty, then the call to UpdatePreferences()
215 // below failed in an earlier run, possibly because the user closed the 252 // below failed in an earlier run, possibly because the user closed the
216 // browser too quickly. Try to force enable the internal PDF plugin again. 253 // browser too quickly. Try to force enable the internal PDF plugin again.
217 force_enable_internal_pdf = true; 254 force_enable_internal_pdf = true;
218 } 255 }
219 } // Scoped update of prefs::kPluginsPluginsList. 256 } // Scoped update of prefs::kPluginsPluginsList.
220 257
221 // Build the set of policy enabled/disabled plugin patterns once and cache it. 258 // Build the set of policy enabled/disabled plugin patterns once and cache it.
222 // Don't do this in the constructor, there's no profile available there. 259 // Don't do this in the constructor, there's no profile available there.
223 const ListValue* disabled_plugins = 260 const ListValue* disabled_plugins =
224 profile->GetPrefs()->GetList(prefs::kPluginsDisabledPlugins); 261 prefs_->GetList(prefs::kPluginsDisabledPlugins);
225 const ListValue* disabled_exception_plugins = 262 const ListValue* disabled_exception_plugins =
226 profile->GetPrefs()->GetList(prefs::kPluginsDisabledPluginsExceptions); 263 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions);
227 const ListValue* enabled_plugins = 264 const ListValue* enabled_plugins =
228 profile->GetPrefs()->GetList(prefs::kPluginsEnabledPlugins); 265 prefs_->GetList(prefs::kPluginsEnabledPlugins);
229 UpdatePluginsStateFromPolicy(disabled_plugins, 266 UpdatePluginsStateFromPolicy(disabled_plugins,
230 disabled_exception_plugins, 267 disabled_exception_plugins,
231 enabled_plugins); 268 enabled_plugins);
232 269
233 registrar_.RemoveAll(); 270 registrar_.RemoveAll();
234 registrar_.Init(profile->GetPrefs()); 271 registrar_.Init(prefs_);
235 registrar_.Add(prefs::kPluginsDisabledPlugins, this); 272 registrar_.Add(prefs::kPluginsDisabledPlugins, this);
236 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this); 273 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this);
237 registrar_.Add(prefs::kPluginsEnabledPlugins, this); 274 registrar_.Add(prefs::kPluginsEnabledPlugins, this);
238 275
239 if (force_enable_internal_pdf || internal_pdf_enabled) { 276 if (force_enable_internal_pdf || internal_pdf_enabled) {
240 // See http://crbug.com/50105 for background. 277 // See http://crbug.com/50105 for background.
241 EnablePluginGroup(false, ASCIIToUTF16( 278 EnablePluginGroup(false, ASCIIToUTF16(
242 webkit::npapi::PluginGroup::kAdobeReaderGroupName)); 279 webkit::npapi::PluginGroup::kAdobeReaderGroupName));
243 } 280 }
244 281
245 if (force_enable_internal_pdf) { 282 if (force_enable_internal_pdf) {
246 // We want to save this, but doing so requires loading the list of plugins, 283 // We want to save this, but doing so requires loading the list of plugins,
247 // so do it after a minute as to not impact startup performance. Note that 284 // so do it after a minute as to not impact startup performance. Note that
248 // plugins are loaded after 30s by the metrics service. 285 // plugins are loaded after 30s by the metrics service.
249 UpdatePreferences(profile, kPluginUpdateDelayMs); 286 UpdatePreferences(kPluginUpdateDelayMs);
250 } 287 }
251 } 288 }
252 289
253 void PluginUpdater::Shutdown() { 290 void PluginPrefs::Shutdown() {
254 registrar_.RemoveAll(); 291 registrar_.RemoveAll();
292 prefs_ = NULL;
255 } 293 }
256 294
257 void PluginUpdater::UpdatePreferences(Profile* profile, int delay_ms) { 295 // static
258 BrowserThread::PostDelayedTask( 296 PluginPrefs::Factory* PluginPrefs::Factory::GetInstance() {
259 BrowserThread::FILE, 297 return Singleton<PluginPrefs::Factory>::get();
260 FROM_HERE,
261 NewRunnableFunction(
262 &PluginUpdater::GetPreferencesDataOnFileThread, profile), delay_ms);
263 } 298 }
264 299
265 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { 300 PluginPrefs* PluginPrefs::Factory::GetPluginPrefsForProfile(Profile* profile) {
266 std::vector<webkit::npapi::WebPluginInfo> plugins; 301 PluginPrefs* plugin_prefs =
267 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); 302 static_cast<PluginPrefs*>(GetServiceForProfile(profile, false));
268 303 DCHECK(plugin_prefs);
269 std::vector<webkit::npapi::PluginGroup> groups; 304 return plugin_prefs;
270 webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups);
271
272 BrowserThread::PostTask(
273 BrowserThread::UI,
274 FROM_HERE,
275 NewRunnableFunction(&PluginUpdater::OnUpdatePreferences,
276 static_cast<Profile*>(profile),
277 plugins, groups));
278 } 305 }
279 306
280 void PluginUpdater::OnUpdatePreferences( 307 PluginPrefs::Factory::Factory()
281 Profile* profile, 308 : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) {
Elliot Glaysher 2011/08/04 17:51:00 I can't see any examples, but just in case: if you
Bernhard Bauer 2011/08/05 13:42:20 Thanks for the heads-up! This one doesn't, though.
282 const std::vector<webkit::npapi::WebPluginInfo>& plugins, 309 }
283 const std::vector<webkit::npapi::PluginGroup>& groups) { 310
284 ListPrefUpdate update(profile->GetPrefs(), prefs::kPluginsPluginsList); 311 ProfileKeyedService* PluginPrefs::Factory::BuildServiceInstanceFor(
312 Profile* profile) const {
313 PluginPrefs* plugin_prefs = new PluginPrefs();
314 plugin_prefs->SetProfile(profile);
315 return plugin_prefs;
316 }
317
318 PluginPrefs::PluginPrefs() : factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
319 notify_pending_(false) {
320 }
321
322 void PluginPrefs::UpdatePreferences(int delay_ms) {
323 PluginInfo* plugin_info = new PluginInfo;
324 Task* callback = factory_.NewRunnableMethod(
325 &PluginPrefs::OnUpdatePreferences, plugin_info);
326 BrowserThread::PostDelayedTask(
327 BrowserThread::FILE,
328 FROM_HERE,
329 NewRunnableFunction(&PluginPrefs::GetPreferencesDataOnFileThread,
330 plugin_info, callback),
331 delay_ms);
332 }
333
334 // static
335 void PluginPrefs::GetPreferencesDataOnFileThread(PluginInfo* plugin_info,
336 Task* callback) {
337 webkit::npapi::PluginList* plugin_list =
338 webkit::npapi::PluginList::Singleton();
339 plugin_list->GetPlugins(&plugin_info->plugins);
340 plugin_list->GetPluginGroups(false, &plugin_info->groups);
341
342 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
343 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
344 NewRunnableFunction(&PluginPrefs::DeletePluginInfo, plugin_info));
345 }
346
347 void PluginPrefs::OnUpdatePreferences(const PluginInfo* plugin_info) {
348 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList);
285 ListValue* plugins_list = update.Get(); 349 ListValue* plugins_list = update.Get();
286 plugins_list->Clear(); 350 plugins_list->Clear();
287 351
288 FilePath internal_dir; 352 FilePath internal_dir;
289 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) 353 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir))
290 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory, 354 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir);
291 internal_dir);
292 355
293 // Add the plugin files. 356 // Add the plugin files.
294 for (size_t i = 0; i < plugins.size(); ++i) { 357 for (size_t i = 0; i < plugin_info->plugins.size(); ++i) {
295 DictionaryValue* summary = CreatePluginFileSummary(plugins[i]); 358 DictionaryValue* summary = CreatePluginFileSummary(plugin_info->plugins[i]);
296 // If the plugin is managed by policy, store the user preferred state 359 // If the plugin is managed by policy, store the user preferred state
297 // instead. 360 // instead.
298 if (plugins[i].enabled & webkit::npapi::WebPluginInfo::MANAGED_MASK) { 361 if (plugin_info->plugins[i].enabled &
362 webkit::npapi::WebPluginInfo::MANAGED_MASK) {
299 bool user_enabled = 363 bool user_enabled =
300 (plugins[i].enabled & webkit::npapi::WebPluginInfo::USER_MASK) == 364 (plugin_info->plugins[i].enabled &
301 webkit::npapi::WebPluginInfo::USER_ENABLED; 365 webkit::npapi::WebPluginInfo::USER_MASK) ==
366 webkit::npapi::WebPluginInfo::USER_ENABLED;
302 summary->SetBoolean("enabled", user_enabled); 367 summary->SetBoolean("enabled", user_enabled);
303 } 368 }
304 plugins_list->Append(summary); 369 plugins_list->Append(summary);
305 } 370 }
306 371
307 // Add the groups as well. 372 // Add the groups as well.
308 for (size_t i = 0; i < groups.size(); ++i) { 373 for (size_t i = 0; i < plugin_info->groups.size(); ++i) {
309 DictionaryValue* summary = groups[i].GetSummary(); 374 DictionaryValue* summary = plugin_info->groups[i].GetSummary();
310 // If the plugin is disabled only by policy don't store this state in the 375 // If the plugin is disabled only by policy don't store this state in the
311 // user pref store. 376 // user pref store.
312 if (!groups[i].Enabled() && 377 if (!plugin_info->groups[i].Enabled() &&
313 webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy( 378 webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy(
314 groups[i].GetGroupName())) 379 plugin_info->groups[i].GetGroupName()))
315 summary->SetBoolean("enabled", true); 380 summary->SetBoolean("enabled", true);
316 plugins_list->Append(summary); 381 plugins_list->Append(summary);
317 } 382 }
318 } 383 }
319 384
320 void PluginUpdater::NotifyPluginStatusChanged() { 385 // static
386 void PluginPrefs::DeletePluginInfo(PluginInfo* plugin_info) {
387 delete plugin_info;
388 }
389
390 void PluginPrefs::NotifyPluginStatusChanged() {
321 if (notify_pending_) 391 if (notify_pending_)
322 return; 392 return;
323 notify_pending_ = true; 393 notify_pending_ = true;
324 MessageLoop::current()->PostTask( 394 MessageLoop::current()->PostTask(
325 FROM_HERE, 395 FROM_HERE,
326 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); 396 factory_.NewRunnableMethod(&PluginPrefs::OnNotifyPluginStatusChanged));
327 } 397 }
328 398
329 void PluginUpdater::OnNotifyPluginStatusChanged() { 399 void PluginPrefs::OnNotifyPluginStatusChanged() {
330 GetInstance()->notify_pending_ = false; 400 notify_pending_ = false;
331 NotificationService::current()->Notify( 401 NotificationService::current()->Notify(
332 content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, 402 content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
333 Source<PluginUpdater>(GetInstance()), 403 Source<PluginPrefs>(this),
334 NotificationService::NoDetails()); 404 NotificationService::NoDetails());
335 } 405 }
336 406
337 /*static*/ 407 /*static*/
338 PluginUpdater* PluginUpdater::GetInstance() { 408 void PluginPrefs::RegisterPrefs(PrefService* prefs) {
339 return Singleton<PluginUpdater>::get();
340 }
341
342 /*static*/
343 void PluginUpdater::RegisterPrefs(PrefService* prefs) {
344 FilePath internal_dir; 409 FilePath internal_dir;
345 PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir); 410 PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir);
346 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, 411 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory,
347 internal_dir, 412 internal_dir,
348 PrefService::UNSYNCABLE_PREF); 413 PrefService::UNSYNCABLE_PREF);
349 prefs->RegisterListPref(prefs::kPluginsDisabledPlugins, 414 prefs->RegisterListPref(prefs::kPluginsDisabledPlugins,
350 PrefService::UNSYNCABLE_PREF); 415 PrefService::UNSYNCABLE_PREF);
351 prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions, 416 prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions,
352 PrefService::UNSYNCABLE_PREF); 417 PrefService::UNSYNCABLE_PREF);
353 prefs->RegisterListPref(prefs::kPluginsEnabledPlugins, 418 prefs->RegisterListPref(prefs::kPluginsEnabledPlugins,
354 PrefService::UNSYNCABLE_PREF); 419 PrefService::UNSYNCABLE_PREF);
355 } 420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698