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

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

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 #include "chrome/browser/plugin_prefs.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/command_line.h"
10 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
12 #include "base/message_loop.h" 13 #include "base/message_loop.h"
13 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 17 #include "base/values.h"
16 #include "base/version.h" 18 #include "base/version.h"
17 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/prefs/scoped_user_pref_update.h" 20 #include "chrome/browser/prefs/scoped_user_pref_update.h"
19 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_dependency_manager.h" 22 #include "chrome/browser/profiles/profile_dependency_manager.h"
21 #include "chrome/browser/profiles/profile_keyed_service.h" 23 #include "chrome/browser/profiles/profile_keyed_service.h"
22 #include "chrome/browser/profiles/profile_keyed_service_factory.h" 24 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
23 #include "chrome/common/chrome_content_client.h" 25 #include "chrome/common/chrome_content_client.h"
24 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
26 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
28 #include "content/browser/browser_thread.h" 30 #include "content/browser/browser_thread.h"
29 #include "content/common/notification_service.h" 31 #include "content/common/notification_service.h"
32 #include "webkit/plugins/npapi/plugin_group.h"
30 #include "webkit/plugins/npapi/plugin_list.h" 33 #include "webkit/plugins/npapi/plugin_list.h"
31 #include "webkit/plugins/webplugininfo.h" 34 #include "webkit/plugins/webplugininfo.h"
32 35
33 namespace { 36 namespace {
34 37
35 class PluginPrefsWrapper : public ProfileKeyedService { 38 class PluginPrefsWrapper : public ProfileKeyedService {
36 public: 39 public:
37 explicit PluginPrefsWrapper(scoped_refptr<PluginPrefs> plugin_prefs) 40 explicit PluginPrefsWrapper(scoped_refptr<PluginPrefs> plugin_prefs)
38 : plugin_prefs_(plugin_prefs) {} 41 : plugin_prefs_(plugin_prefs) {}
39 virtual ~PluginPrefsWrapper() {} 42 virtual ~PluginPrefsWrapper() {}
40 43
41 PluginPrefs* plugin_prefs() { return plugin_prefs_.get(); } 44 PluginPrefs* plugin_prefs() { return plugin_prefs_.get(); }
42 45
43 private: 46 private:
44 // ProfileKeyedService methods: 47 // ProfileKeyedService methods:
45 virtual void Shutdown() OVERRIDE { 48 virtual void Shutdown() OVERRIDE {
46 plugin_prefs_->ShutdownOnUIThread(); 49 plugin_prefs_->ShutdownOnUIThread();
47 } 50 }
48 51
49 scoped_refptr<PluginPrefs> plugin_prefs_; 52 scoped_refptr<PluginPrefs> plugin_prefs_;
50 }; 53 };
51 54
55 // Default state for a plug-in (not state of the default plug-in!).
56 base::LazyInstance<base::Lock> g_default_state_lock(base::LINKER_INITIALIZED);
57 base::LazyInstance<std::map<FilePath, bool> > g_default_plugin_state(
58 base::LINKER_INITIALIZED);
59
52 } 60 }
53 61
54 // How long to wait to save the plugin enabled information, which might need to 62 // How long to wait to save the plugin enabled information, which might need to
55 // go to disk. 63 // go to disk.
56 #define kPluginUpdateDelayMs (60 * 1000) 64 #define kPluginUpdateDelayMs (60 * 1000)
57 65
58 class PluginPrefs::Factory : public ProfileKeyedServiceFactory { 66 class PluginPrefs::Factory : public ProfileKeyedServiceFactory {
59 public: 67 public:
60 static Factory* GetInstance(); 68 static Factory* GetInstance();
61 69
(...skipping 19 matching lines...) Expand all
81 } 89 }
82 90
83 // static 91 // static
84 PluginPrefs* PluginPrefs::GetForProfile(Profile* profile) { 92 PluginPrefs* PluginPrefs::GetForProfile(Profile* profile) {
85 PluginPrefs* plugin_prefs = 93 PluginPrefs* plugin_prefs =
86 Factory::GetInstance()->GetWrapperForProfile(profile)->plugin_prefs(); 94 Factory::GetInstance()->GetWrapperForProfile(profile)->plugin_prefs();
87 DCHECK(plugin_prefs); 95 DCHECK(plugin_prefs);
88 return plugin_prefs; 96 return plugin_prefs;
89 } 97 }
90 98
91 DictionaryValue* PluginPrefs::CreatePluginFileSummary( 99 void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) {
92 const webkit::WebPluginInfo& plugin) { 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
93 DictionaryValue* data = new DictionaryValue(); 101 webkit::npapi::PluginList* plugin_list =
94 data->SetString("path", plugin.path.value()); 102 webkit::npapi::PluginList::Singleton();
95 data->SetString("name", plugin.name); 103 std::vector<webkit::npapi::PluginGroup> groups;
96 data->SetString("version", plugin.version); 104 plugin_list->GetPluginGroups(true, &groups);
97 data->SetBoolean("enabled", IsPluginEnabled(plugin)); 105
98 return data; 106 base::AutoLock auto_lock(lock_);
107
108 // Set the desired state for the group.
109 plugin_group_state_[group_name] = enabled;
110
111 // Update the state for all plug-ins in the group.
112 for (size_t i = 0; i < groups.size(); ++i) {
113 if (groups[i].GetGroupName() != group_name)
114 continue;
115 const std::vector<webkit::WebPluginInfo>& plugins =
116 groups[i].web_plugin_infos();
117 for (size_t j = 0; j < plugins.size(); ++j)
118 plugin_state_[plugins[j].path] = enabled;
119 break;
120 }
121
122 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
123 NewRunnableMethod(this, &PluginPrefs::OnUpdatePreferences, groups));
124 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
125 NewRunnableMethod(this, &PluginPrefs::NotifyPluginStatusChanged));
99 } 126 }
100 127
101 void PluginPrefs::EnablePluginGroup(bool enable, const string16& group_name) { 128 void PluginPrefs::EnablePlugin(bool enabled, const FilePath& path) {
102 webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name); 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
103 NotifyPluginStatusChanged(); 130
131 {
132 // Set the desired state for the plug-in.
133 base::AutoLock auto_lock(lock_);
134 plugin_state_[path] = enabled;
135 }
136
137 webkit::npapi::PluginList* plugin_list =
138 webkit::npapi::PluginList::Singleton();
139 std::vector<webkit::npapi::PluginGroup> groups;
140 plugin_list->GetPluginGroups(true, &groups);
141
142 bool found_group = false;
143 for (size_t i = 0; i < groups.size(); ++i) {
144 bool all_disabled = true;
145 const std::vector<webkit::WebPluginInfo>& plugins =
146 groups[i].web_plugin_infos();
147 for (size_t j = 0; j < plugins.size(); ++j) {
148 all_disabled = all_disabled && !IsPluginEnabled(plugins[j]);
149 if (plugins[j].path == path) {
150 found_group = true;
151 DCHECK_EQ(enabled, IsPluginEnabled(plugins[j]));
152 }
153 }
154 if (found_group) {
155 // Update the state for the corresponding plug-in group.
156 base::AutoLock auto_lock(lock_);
157 plugin_group_state_[groups[i].GetGroupName()] = !all_disabled;
158 break;
159 }
160 }
161
162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
163 NewRunnableMethod(this, &PluginPrefs::OnUpdatePreferences, groups));
164 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
165 NewRunnableMethod(this, &PluginPrefs::NotifyPluginStatusChanged));
104 } 166 }
105 167
106 void PluginPrefs::EnablePlugin(bool enable, const FilePath& path) { 168 // static
107 if (enable) 169 void PluginPrefs::EnablePluginDefault(bool enable, const FilePath& file_path) {
108 webkit::npapi::PluginList::Singleton()->EnablePlugin(path); 170 base::AutoLock lock(g_default_state_lock.Get());
109 else 171 g_default_plugin_state.Get()[file_path] = enable;
110 webkit::npapi::PluginList::Singleton()->DisablePlugin(path); 172 }
111 173
112 NotifyPluginStatusChanged(); 174 PluginPrefs::PolicyStatus PluginPrefs::PolicyStatusForPlugin(
175 const string16& name) {
176 base::AutoLock auto_lock(lock_);
Joao da Silva 2011/09/13 09:30:48 The lock is acquired when reading here, but isn't
Bernhard Bauer 2011/09/13 12:13:01 Added a lock in |Observe|.
177 if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_)) {
178 return POLICY_ENABLED;
179 } else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) &&
180 !IsStringMatchedInSet(
181 name, policy_disabled_plugin_exception_patterns_)) {
182 return POLICY_DISABLED;
183 } else {
184 return NO_POLICY;
185 }
113 } 186 }
114 187
115 bool PluginPrefs::IsPluginEnabled(const webkit::WebPluginInfo& plugin) { 188 bool PluginPrefs::IsPluginEnabled(const webkit::WebPluginInfo& plugin) {
189 scoped_ptr<webkit::npapi::PluginGroup> group(
190 webkit::npapi::PluginList::Singleton()->GetPluginGroup(plugin));
191 string16 group_name = group->GetGroupName();
192
193 // Check if the plug-in or its group is enabled by policy.
194 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name);
195 PolicyStatus group_status = PolicyStatusForPlugin(group_name);
196 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED)
197 return true;
198
199 // Check if the plug-in or its group is disabled by policy.
200 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED)
201 return false;
202
116 // If enabling NaCl, make sure the plugin is also enabled. See bug 203 // If enabling NaCl, make sure the plugin is also enabled. See bug
117 // http://code.google.com/p/chromium/issues/detail?id=81010 for more 204 // http://code.google.com/p/chromium/issues/detail?id=81010 for more
118 // information. 205 // information.
119 // TODO(dspringer): When NaCl is on by default, remove this code. 206 // TODO(dspringer): When NaCl is on by default, remove this code.
120 if ((plugin.name == 207 if ((plugin.name ==
121 ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName)) && 208 ASCIIToUTF16(chrome::ChromeContentClient::kNaClPluginName)) &&
122 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl)) { 209 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaCl)) {
123 return true; 210 return true;
124 } 211 }
125 return webkit::IsPluginEnabled(plugin); 212
213 base::AutoLock auto_lock(lock_);
214 // Check user preferences for the plug-in.
215 std::map<FilePath, bool>::iterator plugin_it =
216 plugin_state_.find(plugin.path);
217 if (plugin_it != plugin_state_.end())
218 return plugin_it->second;
219
220 // Check user preferences for the plug-in group.
221 std::map<string16, bool>::iterator group_it(
222 plugin_group_state_.find(plugin.name));
223 if (group_it != plugin_group_state_.end())
224 return group_it->second;
225
226 base::AutoLock default_lock(g_default_state_lock.Get());
227 std::map<FilePath, bool>::iterator defaults_it =
228 g_default_plugin_state.Get().find(plugin.path);
229 if (defaults_it != g_default_plugin_state.Get().end())
230 return defaults_it->second;
231
232 // Default to enabled.
233 return true;
126 } 234 }
127 235
128 void PluginPrefs::Observe(int type, 236 void PluginPrefs::Observe(int type,
129 const NotificationSource& source, 237 const NotificationSource& source,
130 const NotificationDetails& details) { 238 const NotificationDetails& details) {
131 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type); 239 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type);
132 const std::string* pref_name = Details<std::string>(details).ptr(); 240 const std::string* pref_name = Details<std::string>(details).ptr();
133 if (!pref_name) { 241 if (!pref_name) {
134 NOTREACHED(); 242 NOTREACHED();
135 return; 243 return;
136 } 244 }
137 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); 245 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr());
138 if (*pref_name == prefs::kPluginsDisabledPlugins || 246 if (*pref_name == prefs::kPluginsDisabledPlugins) {
139 *pref_name == prefs::kPluginsDisabledPluginsExceptions || 247 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins),
140 *pref_name == prefs::kPluginsEnabledPlugins) { 248 &policy_disabled_plugin_patterns_);
141 const ListValue* disabled_list = 249 } else if (*pref_name == prefs::kPluginsDisabledPluginsExceptions) {
142 prefs_->GetList(prefs::kPluginsDisabledPlugins); 250 ListValueToStringSet(
143 const ListValue* exceptions_list = 251 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions),
144 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions); 252 &policy_disabled_plugin_exception_patterns_);
145 const ListValue* enabled_list = 253 } else if (*pref_name == prefs::kPluginsEnabledPlugins) {
146 prefs_->GetList(prefs::kPluginsEnabledPlugins); 254 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins),
147 UpdatePluginsStateFromPolicy(disabled_list, exceptions_list, enabled_list); 255 &policy_enabled_plugin_patterns_);
256 } else {
257 NOTREACHED();
148 } 258 }
149 }
150
151 void PluginPrefs::UpdatePluginsStateFromPolicy(
152 const ListValue* disabled_list,
153 const ListValue* exceptions_list,
154 const ListValue* enabled_list) {
155 std::set<string16> disabled_plugin_patterns;
156 std::set<string16> disabled_plugin_exception_patterns;
157 std::set<string16> enabled_plugin_patterns;
158
159 ListValueToStringSet(disabled_list, &disabled_plugin_patterns);
160 ListValueToStringSet(exceptions_list, &disabled_plugin_exception_patterns);
161 ListValueToStringSet(enabled_list, &enabled_plugin_patterns);
162
163 webkit::npapi::PluginGroup::SetPolicyEnforcedPluginPatterns(
164 disabled_plugin_patterns,
165 disabled_plugin_exception_patterns,
166 enabled_plugin_patterns);
167
168 NotifyPluginStatusChanged(); 259 NotifyPluginStatusChanged();
169 } 260 }
170 261
262 /*static*/
263 bool PluginPrefs::IsStringMatchedInSet(const string16& name,
264 const std::set<string16>& pattern_set) {
265 std::set<string16>::const_iterator pattern(pattern_set.begin());
266 while (pattern != pattern_set.end()) {
267 if (MatchPattern(name, *pattern))
268 return true;
269 ++pattern;
270 }
271
272 return false;
273 }
274
275 /* static */
171 void PluginPrefs::ListValueToStringSet(const ListValue* src, 276 void PluginPrefs::ListValueToStringSet(const ListValue* src,
172 std::set<string16>* dest) { 277 std::set<string16>* dest) {
173 DCHECK(src); 278 DCHECK(src);
174 DCHECK(dest); 279 DCHECK(dest);
175 ListValue::const_iterator end(src->end()); 280 ListValue::const_iterator end(src->end());
176 for (ListValue::const_iterator current(src->begin()); 281 for (ListValue::const_iterator current(src->begin());
177 current != end; ++current) { 282 current != end; ++current) {
178 string16 plugin_name; 283 string16 plugin_name;
179 if ((*current)->GetAsString(&plugin_name)) { 284 if ((*current)->GetAsString(&plugin_name)) {
180 dest->insert(plugin_name); 285 dest->insert(plugin_name);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 374 }
270 375
271 internal_pdf_enabled = enabled; 376 internal_pdf_enabled = enabled;
272 } else if (FilePath::CompareIgnoreCase(path, nacl_path_str) == 0) { 377 } else if (FilePath::CompareIgnoreCase(path, nacl_path_str) == 0) {
273 if (!enabled && force_enable_nacl) { 378 if (!enabled && force_enable_nacl) {
274 enabled = true; 379 enabled = true;
275 plugin->SetBoolean("enabled", true); 380 plugin->SetBoolean("enabled", true);
276 } 381 }
277 } 382 }
278 383
279 if (!enabled) 384 plugin_state_[plugin_path] = enabled;
280 webkit::npapi::PluginList::Singleton()->DisablePlugin(plugin_path);
281 } else if (!enabled && plugin->GetString("name", &group_name)) { 385 } else if (!enabled && plugin->GetString("name", &group_name)) {
282 // Don't disable this group if it's for the pdf or nacl plugins and 386 // Don't disable this group if it's for the pdf or nacl plugins and
283 // we just forced it on. 387 // we just forced it on.
284 if (force_enable_internal_pdf && pdf_group_name == group_name) 388 if (force_enable_internal_pdf && pdf_group_name == group_name)
285 continue; 389 continue;
286 if (force_enable_nacl && (nacl_group_name == group_name || 390 if (force_enable_nacl && (nacl_group_name == group_name ||
287 old_nacl_group_name == group_name)) 391 old_nacl_group_name == group_name))
288 continue; 392 continue;
289 393
290 // Otherwise this is a list of groups. 394 // Otherwise this is a list of groups.
291 EnablePluginGroup(false, group_name); 395 plugin_group_state_[group_name] = false;
292 } 396 }
293 } 397 }
294 } else { 398 } else {
295 // If the saved plugin list is empty, then the call to UpdatePreferences() 399 // If the saved plugin list is empty, then the call to UpdatePreferences()
296 // below failed in an earlier run, possibly because the user closed the 400 // below failed in an earlier run, possibly because the user closed the
297 // browser too quickly. Try to force enable the internal PDF and nacl 401 // browser too quickly. Try to force enable the internal PDF and nacl
298 // plugins again. 402 // plugins again.
299 force_enable_internal_pdf = true; 403 force_enable_internal_pdf = true;
300 force_enable_nacl = true; 404 force_enable_nacl = true;
301 } 405 }
302 } // Scoped update of prefs::kPluginsPluginsList. 406 } // Scoped update of prefs::kPluginsPluginsList.
303 407
304 // Build the set of policy enabled/disabled plugin patterns once and cache it. 408 // Build the set of policy enabled/disabled plugin patterns once and cache it.
305 // Don't do this in the constructor, there's no profile available there. 409 // Don't do this in the constructor, there's no profile available there.
306 const ListValue* disabled_plugins = 410 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins),
307 prefs_->GetList(prefs::kPluginsDisabledPlugins); 411 &policy_disabled_plugin_patterns_);
308 const ListValue* disabled_exception_plugins = 412 ListValueToStringSet(
309 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions); 413 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions),
310 const ListValue* enabled_plugins = 414 &policy_disabled_plugin_exception_patterns_);
311 prefs_->GetList(prefs::kPluginsEnabledPlugins); 415 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins),
312 UpdatePluginsStateFromPolicy(disabled_plugins, 416 &policy_enabled_plugin_patterns_);
313 disabled_exception_plugins,
314 enabled_plugins);
315 417
316 registrar_.RemoveAll();
317 registrar_.Init(prefs_); 418 registrar_.Init(prefs_);
318 registrar_.Add(prefs::kPluginsDisabledPlugins, this); 419 registrar_.Add(prefs::kPluginsDisabledPlugins, this);
319 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this); 420 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions, this);
320 registrar_.Add(prefs::kPluginsEnabledPlugins, this); 421 registrar_.Add(prefs::kPluginsEnabledPlugins, this);
321 422
322 if (force_enable_internal_pdf || internal_pdf_enabled) { 423 if (force_enable_internal_pdf || internal_pdf_enabled) {
323 // See http://crbug.com/50105 for background. 424 // See http://crbug.com/50105 for background.
324 EnablePluginGroup(false, ASCIIToUTF16( 425 plugin_group_state_[ASCIIToUTF16(
325 webkit::npapi::PluginGroup::kAdobeReaderGroupName)); 426 webkit::npapi::PluginGroup::kAdobeReaderGroupName)] = false;
326 } 427 }
327 428
328 if (force_enable_internal_pdf || force_enable_nacl) { 429 if (force_enable_internal_pdf || force_enable_nacl) {
329 // We want to save this, but doing so requires loading the list of plugins, 430 // We want to save this, but doing so requires loading the list of plugins,
330 // so do it after a minute as to not impact startup performance. Note that 431 // so do it after a minute as to not impact startup performance. Note that
331 // plugins are loaded after 30s by the metrics service. 432 // plugins are loaded after 30s by the metrics service.
332 UpdatePreferences(kPluginUpdateDelayMs); 433 BrowserThread::PostDelayedTask(
434 BrowserThread::FILE,
435 FROM_HERE,
436 NewRunnableMethod(this, &PluginPrefs::GetPreferencesDataOnFileThread),
437 kPluginUpdateDelayMs);
333 } 438 }
439
440 NotifyPluginStatusChanged();
334 } 441 }
335 442
336 void PluginPrefs::ShutdownOnUIThread() { 443 void PluginPrefs::ShutdownOnUIThread() {
337 prefs_ = NULL; 444 prefs_ = NULL;
338 registrar_.RemoveAll(); 445 registrar_.RemoveAll();
339 } 446 }
340 447
341 // static 448 // static
342 PluginPrefs::Factory* PluginPrefs::Factory::GetInstance() { 449 PluginPrefs::Factory* PluginPrefs::Factory::GetInstance() {
343 return Singleton<PluginPrefs::Factory>::get(); 450 return Singleton<PluginPrefs::Factory>::get();
344 } 451 }
345 452
346 PluginPrefsWrapper* PluginPrefs::Factory::GetWrapperForProfile( 453 PluginPrefsWrapper* PluginPrefs::Factory::GetWrapperForProfile(
347 Profile* profile) { 454 Profile* profile) {
348 return static_cast<PluginPrefsWrapper*>(GetServiceForProfile(profile, true)); 455 return static_cast<PluginPrefsWrapper*>(GetServiceForProfile(profile, true));
349 } 456 }
350 457
351 PluginPrefs::Factory::Factory() 458 PluginPrefs::Factory::Factory()
352 : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) { 459 : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) {
353 } 460 }
354 461
355 ProfileKeyedService* PluginPrefs::Factory::BuildServiceInstanceFor( 462 ProfileKeyedService* PluginPrefs::Factory::BuildServiceInstanceFor(
356 Profile* profile) const { 463 Profile* profile) const {
357 scoped_refptr<PluginPrefs> plugin_prefs(new PluginPrefs()); 464 scoped_refptr<PluginPrefs> plugin_prefs(new PluginPrefs());
358 plugin_prefs->SetPrefs(profile->GetPrefs()); 465 plugin_prefs->SetPrefs(profile->GetPrefs());
359 return new PluginPrefsWrapper(plugin_prefs); 466 return new PluginPrefsWrapper(plugin_prefs);
360 } 467 }
361 468
362 PluginPrefs::PluginPrefs() : notify_pending_(false) { 469 PluginPrefs::PluginPrefs() {
363 } 470 }
364 471
365 PluginPrefs::~PluginPrefs() { 472 PluginPrefs::~PluginPrefs() {
366 } 473 }
367 474
368 void PluginPrefs::UpdatePreferences(int delay_ms) { 475 void PluginPrefs::SetPolicyEnforcedPluginPatterns(
369 BrowserThread::PostDelayedTask( 476 const std::set<string16>& disabled_patterns,
370 BrowserThread::FILE, 477 const std::set<string16>& disabled_exception_patterns,
371 FROM_HERE, 478 const std::set<string16>& enabled_patterns) {
372 NewRunnableMethod(this, &PluginPrefs::GetPreferencesDataOnFileThread), 479 policy_disabled_plugin_patterns_ = disabled_patterns;
373 delay_ms); 480 policy_disabled_plugin_exception_patterns_ = disabled_exception_patterns;
481 policy_enabled_plugin_patterns_ = enabled_patterns;
374 } 482 }
375 483
376 void PluginPrefs::GetPreferencesDataOnFileThread() { 484 void PluginPrefs::GetPreferencesDataOnFileThread() {
377 std::vector<webkit::WebPluginInfo> plugins;
378 std::vector<webkit::npapi::PluginGroup> groups; 485 std::vector<webkit::npapi::PluginGroup> groups;
379 486
380 webkit::npapi::PluginList* plugin_list = 487 webkit::npapi::PluginList* plugin_list =
381 webkit::npapi::PluginList::Singleton(); 488 webkit::npapi::PluginList::Singleton();
382 plugin_list->GetPlugins(&plugins);
383 plugin_list->GetPluginGroups(false, &groups); 489 plugin_list->GetPluginGroups(false, &groups);
384 490
385 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 491 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
386 NewRunnableMethod(this, &PluginPrefs::OnUpdatePreferences, 492 NewRunnableMethod(this, &PluginPrefs::OnUpdatePreferences, groups));
387 plugins, groups));
388 } 493 }
389 494
390 void PluginPrefs::OnUpdatePreferences( 495 void PluginPrefs::OnUpdatePreferences(
391 std::vector<webkit::WebPluginInfo> plugins,
392 std::vector<webkit::npapi::PluginGroup> groups) { 496 std::vector<webkit::npapi::PluginGroup> groups) {
393 if (!prefs_) 497 if (!prefs_)
394 return; 498 return;
395 499
396 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); 500 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList);
397 ListValue* plugins_list = update.Get(); 501 ListValue* plugins_list = update.Get();
398 plugins_list->Clear(); 502 plugins_list->Clear();
399 503
400 FilePath internal_dir; 504 FilePath internal_dir;
401 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) 505 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir))
402 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); 506 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir);
403 507
404 // Add the plugin files. 508 base::AutoLock auto_lock(lock_);
405 for (size_t i = 0; i < plugins.size(); ++i) { 509
406 DictionaryValue* summary = CreatePluginFileSummary(plugins[i]); 510 // Add the plug-in groups.
407 // If the plugin is managed by policy, store the user preferred state 511 for (size_t i = 0; i < groups.size(); ++i) {
408 // instead. 512 // Add the plugin files to the same list.
409 if (plugins[i].enabled & webkit::WebPluginInfo::MANAGED_MASK) { 513 const std::vector<webkit::WebPluginInfo>& plugins =
410 bool user_enabled = 514 groups[i].web_plugin_infos();
411 (plugins[i].enabled & webkit::WebPluginInfo::USER_MASK) == 515 for (size_t j = 0; j < plugins.size(); ++j) {
412 webkit::WebPluginInfo::USER_ENABLED; 516 DictionaryValue* summary = new DictionaryValue();
413 summary->SetBoolean("enabled", user_enabled); 517 summary->SetString("path", plugins[j].path.value());
518 summary->SetString("name", plugins[j].name);
519 summary->SetString("version", plugins[j].version);
520 bool enabled = true;
521 std::map<FilePath, bool>::iterator it =
522 plugin_state_.find(plugins[j].path);
523 if (it != plugin_state_.end())
524 enabled = it->second;
525 summary->SetBoolean("enabled", enabled);
526 plugins_list->Append(summary);
414 } 527 }
528
529 DictionaryValue* summary = new DictionaryValue();
530 string16 name = groups[i].GetGroupName();
531 summary->SetString("name", name);
532 bool enabled = true;
533 std::map<string16, bool>::iterator it =
534 plugin_group_state_.find(name);
535 if (it != plugin_group_state_.end())
536 enabled = it->second;
537 summary->SetBoolean("enabled", enabled);
415 plugins_list->Append(summary); 538 plugins_list->Append(summary);
416 } 539 }
417
418 // Add the groups as well.
419 for (size_t i = 0; i < groups.size(); ++i) {
420 DictionaryValue* summary = groups[i].GetSummary();
421 // If the plugin is disabled only by policy don't store this state in the
422 // user pref store.
423 if (!groups[i].Enabled() &&
424 webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy(
425 groups[i].GetGroupName()))
426 summary->SetBoolean("enabled", true);
427 plugins_list->Append(summary);
428 }
429 } 540 }
430 541
431 void PluginPrefs::NotifyPluginStatusChanged() { 542 void PluginPrefs::NotifyPluginStatusChanged() {
432 if (notify_pending_) 543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
433 return;
434 notify_pending_ = true;
435 MessageLoop::current()->PostTask(
436 FROM_HERE,
437 NewRunnableMethod(this, &PluginPrefs::OnNotifyPluginStatusChanged));
438 }
439
440 void PluginPrefs::OnNotifyPluginStatusChanged() {
441 notify_pending_ = false;
442 NotificationService::current()->Notify( 544 NotificationService::current()->Notify(
443 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, 545 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
444 Source<PluginPrefs>(this), 546 Source<PluginPrefs>(this),
445 NotificationService::NoDetails()); 547 NotificationService::NoDetails());
446 } 548 }
447 549
448 /*static*/ 550 /*static*/
449 void PluginPrefs::RegisterPrefs(PrefService* prefs) { 551 void PluginPrefs::RegisterPrefs(PrefService* prefs) {
450 FilePath internal_dir; 552 FilePath internal_dir;
451 PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir); 553 PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir);
452 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, 554 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory,
453 internal_dir, 555 internal_dir,
454 PrefService::UNSYNCABLE_PREF); 556 PrefService::UNSYNCABLE_PREF);
455 prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, 557 prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF,
456 false, 558 false,
457 PrefService::UNSYNCABLE_PREF); 559 PrefService::UNSYNCABLE_PREF);
458 prefs->RegisterBooleanPref(prefs::kPluginsEnabledNaCl, 560 prefs->RegisterBooleanPref(prefs::kPluginsEnabledNaCl,
459 false, 561 false,
460 PrefService::UNSYNCABLE_PREF); 562 PrefService::UNSYNCABLE_PREF);
461 prefs->RegisterListPref(prefs::kPluginsPluginsList, 563 prefs->RegisterListPref(prefs::kPluginsPluginsList,
462 PrefService::UNSYNCABLE_PREF); 564 PrefService::UNSYNCABLE_PREF);
463 prefs->RegisterListPref(prefs::kPluginsDisabledPlugins, 565 prefs->RegisterListPref(prefs::kPluginsDisabledPlugins,
464 PrefService::UNSYNCABLE_PREF); 566 PrefService::UNSYNCABLE_PREF);
465 prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions, 567 prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions,
466 PrefService::UNSYNCABLE_PREF); 568 PrefService::UNSYNCABLE_PREF);
467 prefs->RegisterListPref(prefs::kPluginsEnabledPlugins, 569 prefs->RegisterListPref(prefs::kPluginsEnabledPlugins,
468 PrefService::UNSYNCABLE_PREF); 570 PrefService::UNSYNCABLE_PREF);
469 } 571 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698