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

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

Issue 2518493002: Remove obsolete plugin state handling code. (Closed)
Patch Set: Removed unusued function. Created 4 years, 1 month 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
« no previous file with comments | « chrome/browser/plugins/plugin_prefs.h ('k') | chrome/browser/plugins/plugin_prefs_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/plugins/plugin_prefs.h" 5 #include "chrome/browser/plugins/plugin_prefs.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h"
15 #include "base/location.h" 14 #include "base/location.h"
16 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
17 #include "base/path_service.h" 16 #include "base/path_service.h"
18 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
19 #include "base/strings/pattern.h" 18 #include "base/strings/pattern.h"
20 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
22 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/values.h" 22 #include "base/values.h"
24 #include "build/build_config.h" 23 #include "build/build_config.h"
25 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 26 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
28 #include "chrome/browser/plugins/plugin_installer.h" 27 #include "chrome/browser/plugins/plugin_installer.h"
29 #include "chrome/browser/plugins/plugin_metadata.h" 28 #include "chrome/browser/plugins/plugin_metadata.h"
30 #include "chrome/browser/plugins/plugin_prefs_factory.h" 29 #include "chrome/browser/plugins/plugin_prefs_factory.h"
31 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/common/chrome_constants.h" 31 #include "chrome/common/chrome_constants.h"
33 #include "chrome/common/chrome_content_client.h" 32 #include "chrome/common/chrome_content_client.h"
34 #include "chrome/common/chrome_paths.h" 33 #include "chrome/common/chrome_paths.h"
35 #include "chrome/common/chrome_switches.h"
36 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
37 #include "components/content_settings/core/browser/host_content_settings_map.h" 35 #include "components/content_settings/core/browser/host_content_settings_map.h"
38 #include "components/content_settings/core/common/content_settings.h" 36 #include "components/content_settings/core/common/content_settings.h"
39 #include "components/content_settings/core/common/pref_names.h" 37 #include "components/content_settings/core/common/pref_names.h"
40 #include "components/keyed_service/core/keyed_service.h" 38 #include "components/keyed_service/core/keyed_service.h"
41 #include "components/prefs/scoped_user_pref_update.h" 39 #include "components/prefs/scoped_user_pref_update.h"
42 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/notification_service.h" 41 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/plugin_service.h" 42 #include "content/public/browser/plugin_service.h"
45 #include "content/public/common/content_constants.h" 43 #include "content/public/common/content_constants.h"
46 #include "content/public/common/webplugininfo.h" 44 #include "content/public/common/webplugininfo.h"
47 45
48 #if !defined(DISABLE_NACL)
49 #include "components/nacl/common/nacl_constants.h"
50 #endif
51
52 using content::BrowserThread; 46 using content::BrowserThread;
53 using content::PluginService; 47 using content::PluginService;
54 48
55 namespace { 49 namespace {
56 50
57 bool IsComponentUpdatedPepperFlash(const base::FilePath& plugin) {
58 if (plugin.BaseName().value() == chrome::kPepperFlashPluginFilename) {
59 base::FilePath component_updated_pepper_flash_dir;
60 if (PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN,
61 &component_updated_pepper_flash_dir) &&
62 component_updated_pepper_flash_dir.IsParent(plugin)) {
63 return true;
64 }
65 }
66
67 return false;
68 }
69
70 bool IsPDFViewerPlugin(const base::string16& plugin_name) { 51 bool IsPDFViewerPlugin(const base::string16& plugin_name) {
71 return plugin_name == base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName); 52 return plugin_name == base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName);
72 } 53 }
73 54
74 bool IsAdobeFlashPlayerPlugin(const base::string16& plugin_name) { 55 bool IsAdobeFlashPlayerPlugin(const base::string16& plugin_name) {
75 return (plugin_name == base::ASCIIToUTF16(content::kFlashPluginName) || 56 return (plugin_name == base::ASCIIToUTF16(content::kFlashPluginName) ||
76 plugin_name == base::ASCIIToUTF16( 57 plugin_name == base::ASCIIToUTF16(
77 PluginMetadata::kAdobeFlashPlayerGroupName)); 58 PluginMetadata::kAdobeFlashPlayerGroupName));
78 } 59 }
79 60
80 } // namespace 61 } // namespace
81 62
82 PluginPrefs::PluginState::PluginState() {
83 }
84
85 PluginPrefs::PluginState::~PluginState() {
86 }
87
88 bool PluginPrefs::PluginState::Get(const base::FilePath& plugin,
89 bool* enabled) const {
90 base::FilePath key = ConvertMapKey(plugin);
91 std::map<base::FilePath, bool>::const_iterator iter = state_.find(key);
92 if (iter != state_.end()) {
93 *enabled = iter->second;
94 return true;
95 }
96 return false;
97 }
98
99 void PluginPrefs::PluginState::Set(const base::FilePath& plugin, bool enabled) {
100 state_[ConvertMapKey(plugin)] = enabled;
101 }
102
103 base::FilePath PluginPrefs::PluginState::ConvertMapKey(
104 const base::FilePath& plugin) const {
105 // Keep the state of component-updated and bundled Pepper Flash in sync.
106 if (IsComponentUpdatedPepperFlash(plugin)) {
107 base::FilePath bundled_pepper_flash;
108 if (PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN,
109 &bundled_pepper_flash)) {
110 return bundled_pepper_flash;
111 }
112 }
113
114 return plugin;
115 }
116
117 // static 63 // static
118 scoped_refptr<PluginPrefs> PluginPrefs::GetForProfile(Profile* profile) { 64 scoped_refptr<PluginPrefs> PluginPrefs::GetForProfile(Profile* profile) {
119 return PluginPrefsFactory::GetPrefsForProfile(profile); 65 return PluginPrefsFactory::GetPrefsForProfile(profile);
120 } 66 }
121 67
122 // static 68 // static
123 scoped_refptr<PluginPrefs> PluginPrefs::GetForTestingProfile( 69 scoped_refptr<PluginPrefs> PluginPrefs::GetForTestingProfile(
124 Profile* profile) { 70 Profile* profile) {
125 return static_cast<PluginPrefs*>( 71 return static_cast<PluginPrefs*>(
126 PluginPrefsFactory::GetInstance()->SetTestingFactoryAndUse( 72 PluginPrefsFactory::GetInstance()->SetTestingFactoryAndUse(
127 profile, &PluginPrefsFactory::CreateForTestingProfile).get()); 73 profile, &PluginPrefsFactory::CreateForTestingProfile).get());
128 } 74 }
129 75
130 void PluginPrefs::EnablePluginGroup(bool enabled,
131 const base::string16& group_name) {
132 PluginService::GetInstance()->GetPlugins(
133 base::Bind(&PluginPrefs::EnablePluginGroupInternal,
134 this, enabled, group_name));
135 }
136
137 void PluginPrefs::EnablePluginGroupInternal(
138 bool enabled,
139 const base::string16& group_name,
140 const std::vector<content::WebPluginInfo>& plugins) {
141 base::AutoLock auto_lock(lock_);
142 PluginFinder* finder = PluginFinder::GetInstance();
143
144 // Set the desired state for the group.
145 plugin_group_state_[group_name] = enabled;
146
147 // Update the state for all plugins in the group.
148 for (size_t i = 0; i < plugins.size(); ++i) {
149 std::unique_ptr<PluginMetadata> plugin(
150 finder->GetPluginMetadata(plugins[i]));
151 if (group_name != plugin->name())
152 continue;
153 plugin_state_.Set(plugins[i].path, enabled);
154 }
155
156 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
157 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins));
158 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
159 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this));
160 }
161
162 void PluginPrefs::EnablePlugin(
163 bool enabled, const base::FilePath& path,
164 const base::Callback<void(bool)>& callback) {
165 PluginFinder* finder = PluginFinder::GetInstance();
166 content::WebPluginInfo plugin;
167 bool can_enable = true;
168 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) {
169 std::unique_ptr<PluginMetadata> plugin_metadata(
170 finder->GetPluginMetadata(plugin));
171 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name);
172 PolicyStatus group_status = PolicyStatusForPlugin(plugin_metadata->name());
173 if (enabled) {
174 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED)
175 can_enable = false;
176 } else {
177 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED)
178 can_enable = false;
179 }
180 } else {
181 NOTREACHED();
182 }
183
184 if (!can_enable) {
185 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
186 base::Bind(callback, false));
187 return;
188 }
189
190 PluginService::GetInstance()->GetPlugins(
191 base::Bind(&PluginPrefs::EnablePluginInternal, this,
192 enabled, path, finder, callback));
193 }
194
195 void PluginPrefs::EnablePluginInternal(
196 bool enabled,
197 const base::FilePath& path,
198 PluginFinder* plugin_finder,
199 const base::Callback<void(bool)>& callback,
200 const std::vector<content::WebPluginInfo>& plugins) {
201 {
202 // Set the desired state for the plugin.
203 base::AutoLock auto_lock(lock_);
204 plugin_state_.Set(path, enabled);
205 }
206
207 base::string16 group_name;
208 for (size_t i = 0; i < plugins.size(); ++i) {
209 if (plugins[i].path == path) {
210 std::unique_ptr<PluginMetadata> plugin_metadata(
211 plugin_finder->GetPluginMetadata(plugins[i]));
212 // set the group name for this plugin.
213 group_name = plugin_metadata->name();
214 DCHECK_EQ(enabled, IsPluginEnabled(plugins[i]));
215 break;
216 }
217 }
218
219 bool all_disabled = true;
220 for (size_t i = 0; i < plugins.size(); ++i) {
221 std::unique_ptr<PluginMetadata> plugin_metadata(
222 plugin_finder->GetPluginMetadata(plugins[i]));
223 DCHECK(!plugin_metadata->name().empty());
224 if (group_name == plugin_metadata->name()) {
225 all_disabled = all_disabled && !IsPluginEnabled(plugins[i]);
226 }
227 }
228
229 if (!group_name.empty()) {
230 // Update the state for the corresponding plugin group.
231 base::AutoLock auto_lock(lock_);
232 plugin_group_state_[group_name] = !all_disabled;
233 }
234
235 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
236 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins));
237 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
238 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this));
239 callback.Run(true);
240 }
241
242 PluginPrefs::PolicyStatus PluginPrefs::PolicyStatusForPlugin( 76 PluginPrefs::PolicyStatus PluginPrefs::PolicyStatusForPlugin(
243 const base::string16& name) const { 77 const base::string16& name) const {
244 base::AutoLock auto_lock(lock_); 78 base::AutoLock auto_lock(lock_);
245 79
246 // Special handling for PDF based on its specific policy. 80 // Special handling for PDF based on its specific policy.
247 if (IsPDFViewerPlugin(name) && always_open_pdf_externally_) 81 if (IsPDFViewerPlugin(name) && always_open_pdf_externally_)
248 return POLICY_DISABLED; 82 return POLICY_DISABLED;
249 83
250 if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_))
251 return POLICY_ENABLED;
252
253 if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) &&
254 !IsStringMatchedInSet(
255 name, policy_disabled_plugin_exception_patterns_)) {
256 return POLICY_DISABLED;
257 }
258
259 return NO_POLICY; 84 return NO_POLICY;
260 } 85 }
261 86
262 bool PluginPrefs::IsPluginEnabled(const content::WebPluginInfo& plugin) const { 87 bool PluginPrefs::IsPluginEnabled(const content::WebPluginInfo& plugin) const {
263 std::unique_ptr<PluginMetadata> plugin_metadata( 88 std::unique_ptr<PluginMetadata> plugin_metadata(
264 PluginFinder::GetInstance()->GetPluginMetadata(plugin)); 89 PluginFinder::GetInstance()->GetPluginMetadata(plugin));
265 base::string16 group_name = plugin_metadata->name(); 90 base::string16 group_name = plugin_metadata->name();
266 91
267 // Check if the plugin or its group is enabled by policy. 92 // Check if the plugin or its group is enabled by policy.
268 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); 93 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name);
269 PolicyStatus group_status = PolicyStatusForPlugin(group_name); 94 PolicyStatus group_status = PolicyStatusForPlugin(group_name);
270 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) 95 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED)
271 return true; 96 return true;
272 97
273 // Check if the plugin or its group is disabled by policy. 98 // Check if the plugin or its group is disabled by policy.
274 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) 99 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED)
275 return false; 100 return false;
276 101
277 #if !defined(DISABLE_NACL)
278 // If enabling NaCl, make sure the plugin is also enabled. See bug
279 // http://code.google.com/p/chromium/issues/detail?id=81010 for more
280 // information.
281 // TODO(dspringer): When NaCl is on by default, remove this code.
282 if ((plugin.name == base::ASCIIToUTF16(nacl::kNaClPluginName)) &&
283 base::CommandLine::ForCurrentProcess()->HasSwitch(
284 switches::kEnableNaCl)) {
285 return true;
286 }
287 #endif
288
289 base::AutoLock auto_lock(lock_);
290 // Check user preferences for the plugin.
291 bool plugin_enabled = false;
292 if (plugin_state_.Get(plugin.path, &plugin_enabled))
293 return plugin_enabled;
294
295 // Check user preferences for the plugin group.
296 std::map<base::string16, bool>::const_iterator group_it(
297 plugin_group_state_.find(group_name));
298 if (group_it != plugin_group_state_.end())
299 return group_it->second;
300
301 // Default to enabled. 102 // Default to enabled.
302 return true; 103 return true;
303 } 104 }
304 105
305 void PluginPrefs::UpdatePatternsAndNotify(std::set<base::string16>* patterns,
306 const std::string& pref_name) {
307 base::AutoLock auto_lock(lock_);
308 ListValueToStringSet(prefs_->GetList(pref_name.c_str()), patterns);
309
310 NotifyPluginStatusChanged();
311 }
312
313 void PluginPrefs::UpdatePdfPolicy(const std::string& pref_name) { 106 void PluginPrefs::UpdatePdfPolicy(const std::string& pref_name) {
314 base::AutoLock auto_lock(lock_); 107 base::AutoLock auto_lock(lock_);
315 always_open_pdf_externally_ = 108 always_open_pdf_externally_ =
316 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); 109 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally);
317 110
318 NotifyPluginStatusChanged(); 111 NotifyPluginStatusChanged();
319 } 112 }
320 113
321 /*static*/
322 bool PluginPrefs::IsStringMatchedInSet(
323 const base::string16& name,
324 const std::set<base::string16>& pattern_set) {
325 std::set<base::string16>::const_iterator pattern(pattern_set.begin());
326 while (pattern != pattern_set.end()) {
327 if (base::MatchPattern(name, *pattern))
328 return true;
329 ++pattern;
330 }
331
332 return false;
333 }
334
335 /* static */
336 void PluginPrefs::ListValueToStringSet(const base::ListValue* src,
337 std::set<base::string16>* dest) {
338 DCHECK(src);
339 DCHECK(dest);
340 dest->clear();
341 base::ListValue::const_iterator end(src->end());
342 for (base::ListValue::const_iterator current(src->begin());
343 current != end; ++current) {
344 base::string16 plugin_name;
345 if ((*current)->GetAsString(&plugin_name)) {
346 dest->insert(plugin_name);
347 }
348 }
349 }
350
351 void PluginPrefs::SetPrefs(PrefService* prefs) { 114 void PluginPrefs::SetPrefs(PrefService* prefs) {
352 prefs_ = prefs; 115 prefs_ = prefs;
353 bool update_internal_dir = false; 116 bool update_internal_dir = false;
354 bool plugins_migrated = false; 117 bool plugins_migrated = false;
355 base::FilePath last_internal_dir = 118 base::FilePath last_internal_dir =
356 prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory); 119 prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory);
357 base::FilePath cur_internal_dir; 120 base::FilePath cur_internal_dir;
358 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && 121 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) &&
359 cur_internal_dir != last_internal_dir) { 122 cur_internal_dir != last_internal_dir) {
360 update_internal_dir = true; 123 update_internal_dir = true;
(...skipping 21 matching lines...) Expand all
382 if (!enabled) { 145 if (!enabled) {
383 base::string16 name; 146 base::string16 name;
384 plugin->GetString("name", &name); 147 plugin->GetString("name", &name);
385 if (IsPDFViewerPlugin(name)) 148 if (IsPDFViewerPlugin(name))
386 prefs->SetBoolean(prefs::kPluginsAlwaysOpenPdfExternally, true); 149 prefs->SetBoolean(prefs::kPluginsAlwaysOpenPdfExternally, true);
387 if (IsAdobeFlashPlayerPlugin(name)) { 150 if (IsAdobeFlashPlayerPlugin(name)) {
388 HostContentSettingsMapFactory::GetForProfile(profile_) 151 HostContentSettingsMapFactory::GetForProfile(profile_)
389 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 152 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
390 CONTENT_SETTING_BLOCK); 153 CONTENT_SETTING_BLOCK);
391 } 154 }
392 // TODO(http://crbug.com/662002): Remove the enabled flag completely.
393 enabled = true;
394 plugin->SetBoolean("enabled", true);
395 plugins_migrated = true; 155 plugins_migrated = true;
396 } 156 }
397 157
398 base::FilePath::StringType path; 158 base::FilePath::StringType path;
399 // The plugin list constains all the plugin files in addition to the 159 // The plugin list constains all the plugin files in addition to the
400 // plugin groups. 160 // plugin groups.
401 if (plugin->GetString("path", &path)) { 161 if (plugin->GetString("path", &path)) {
402 // Files have a path attribute, groups don't. 162 // Files have a path attribute, groups don't.
403 base::FilePath plugin_path(path); 163 base::FilePath plugin_path(path);
404 164
(...skipping 28 matching lines...) Expand all
433 } 193 }
434 194
435 // If |relative_path| is empty, |plugin_path| is not within 195 // If |relative_path| is empty, |plugin_path| is not within
436 // |last_internal_dir|. We don't need to update it. 196 // |last_internal_dir|. We don't need to update it.
437 if (!relative_path.empty()) { 197 if (!relative_path.empty()) {
438 plugin_path = cur_internal_dir.Append(relative_path); 198 plugin_path = cur_internal_dir.Append(relative_path);
439 path = plugin_path.value(); 199 path = plugin_path.value();
440 plugin->SetString("path", path); 200 plugin->SetString("path", path);
441 } 201 }
442 } 202 }
443
444 plugin_state_.Set(plugin_path, enabled);
445 } 203 }
446 } 204 }
447 } else {
448 // If the saved plugin list is empty, then the call to UpdatePreferences()
449 // below failed in an earlier run, possibly because the user closed the
450 // browser too quickly.
451
452 // Only want one PDF plugin enabled at a time. See http://crbug.com/50105
453 // for background.
454 plugin_group_state_[base::ASCIIToUTF16(
455 PluginMetadata::kAdobeReaderGroupName)] = false;
456 } 205 }
457 } // Scoped update of prefs::kPluginsPluginsList. 206 } // Scoped update of prefs::kPluginsPluginsList.
458 207
459 UMA_HISTOGRAM_BOOLEAN("Plugin.EnabledStatusMigrationDone", plugins_migrated); 208 UMA_HISTOGRAM_BOOLEAN("Plugin.EnabledStatusMigrationDone", plugins_migrated);
460 209
461 // Build the set of policy enabled/disabled plugin patterns once and cache it.
462 // Don't do this in the constructor, there's no profile available there.
463 // TODO(http://crbug.com/662002): : Remove the prefs completely.
464 ListValueToStringSet(prefs_->GetList(prefs::kPluginsDisabledPlugins),
465 &policy_disabled_plugin_patterns_);
466 ListValueToStringSet(
467 prefs_->GetList(prefs::kPluginsDisabledPluginsExceptions),
468 &policy_disabled_plugin_exception_patterns_);
469 ListValueToStringSet(prefs_->GetList(prefs::kPluginsEnabledPlugins),
470 &policy_enabled_plugin_patterns_);
471 always_open_pdf_externally_ = 210 always_open_pdf_externally_ =
472 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally); 211 prefs_->GetBoolean(prefs::kPluginsAlwaysOpenPdfExternally);
473 212
474 registrar_.Init(prefs_); 213 registrar_.Init(prefs_);
475 214
476 // Because pointers to our own members will remain unchanged for the 215 // Because pointers to our own members will remain unchanged for the
477 // lifetime of |registrar_| (which we also own), we can bind their 216 // lifetime of |registrar_| (which we also own), we can bind their
478 // pointer values directly in the callbacks to avoid string-based 217 // pointer values directly in the callbacks to avoid string-based
479 // lookups at notification time. 218 // lookups at notification time.
480 registrar_.Add(prefs::kPluginsDisabledPlugins,
481 base::Bind(&PluginPrefs::UpdatePatternsAndNotify,
482 base::Unretained(this),
483 &policy_disabled_plugin_patterns_));
484 registrar_.Add(prefs::kPluginsDisabledPluginsExceptions,
485 base::Bind(&PluginPrefs::UpdatePatternsAndNotify,
486 base::Unretained(this),
487 &policy_disabled_plugin_exception_patterns_));
488 registrar_.Add(prefs::kPluginsEnabledPlugins,
489 base::Bind(&PluginPrefs::UpdatePatternsAndNotify,
490 base::Unretained(this),
491 &policy_enabled_plugin_patterns_));
492 registrar_.Add(prefs::kPluginsAlwaysOpenPdfExternally, 219 registrar_.Add(prefs::kPluginsAlwaysOpenPdfExternally,
493 base::Bind(&PluginPrefs::UpdatePdfPolicy, 220 base::Bind(&PluginPrefs::UpdatePdfPolicy,
494 base::Unretained(this))); 221 base::Unretained(this)));
495 222
496 NotifyPluginStatusChanged(); 223 NotifyPluginStatusChanged();
497 } 224 }
498 225
499 void PluginPrefs::ShutdownOnUIThread() { 226 void PluginPrefs::ShutdownOnUIThread() {
500 prefs_ = NULL; 227 prefs_ = NULL;
501 registrar_.RemoveAll(); 228 registrar_.RemoveAll();
502 } 229 }
503 230
504 PluginPrefs::PluginPrefs() : always_open_pdf_externally_(false), 231 PluginPrefs::PluginPrefs() : always_open_pdf_externally_(false),
505 profile_(NULL), 232 profile_(NULL),
506 prefs_(NULL) { 233 prefs_(NULL) {
507 } 234 }
508 235
509 PluginPrefs::~PluginPrefs() { 236 PluginPrefs::~PluginPrefs() {
510 } 237 }
511 238
512 void PluginPrefs::SetPolicyEnforcedPluginPatternsForTests(
513 const std::set<base::string16>& disabled_patterns,
514 const std::set<base::string16>& disabled_exception_patterns,
515 const std::set<base::string16>& enabled_patterns) {
516 policy_disabled_plugin_patterns_ = disabled_patterns;
517 policy_disabled_plugin_exception_patterns_ = disabled_exception_patterns;
518 policy_enabled_plugin_patterns_ = enabled_patterns;
519 }
520
521 void PluginPrefs::SetAlwaysOpenPdfExternallyForTests( 239 void PluginPrefs::SetAlwaysOpenPdfExternallyForTests(
522 bool always_open_pdf_externally) { 240 bool always_open_pdf_externally) {
523 always_open_pdf_externally_ = always_open_pdf_externally; 241 always_open_pdf_externally_ = always_open_pdf_externally;
524 } 242 }
525 243
526 244
527 void PluginPrefs::OnUpdatePreferences( 245 void PluginPrefs::OnUpdatePreferences(
528 const std::vector<content::WebPluginInfo>& plugins) { 246 const std::vector<content::WebPluginInfo>& plugins) {
529 if (!prefs_) 247 if (!prefs_)
530 return; 248 return;
531 249
532 PluginFinder* finder = PluginFinder::GetInstance(); 250 PluginFinder* finder = PluginFinder::GetInstance();
533 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); 251 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList);
534 base::ListValue* plugins_list = update.Get(); 252 base::ListValue* plugins_list = update.Get();
535 plugins_list->Clear(); 253 plugins_list->Clear();
536 254
537 base::FilePath internal_dir; 255 base::FilePath internal_dir;
538 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) 256 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir))
539 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); 257 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir);
540 258
541 base::AutoLock auto_lock(lock_); 259 base::AutoLock auto_lock(lock_);
542 260
543 // Add the plugin files. 261 // Add the plugin files.
544 std::set<base::string16> group_names; 262 std::set<base::string16> group_names;
545 for (size_t i = 0; i < plugins.size(); ++i) { 263 for (size_t i = 0; i < plugins.size(); ++i) {
546 std::unique_ptr<base::DictionaryValue> summary(new base::DictionaryValue()); 264 std::unique_ptr<base::DictionaryValue> summary(new base::DictionaryValue());
547 summary->SetString("path", plugins[i].path.value()); 265 summary->SetString("path", plugins[i].path.value());
548 summary->SetString("name", plugins[i].name); 266 summary->SetString("name", plugins[i].name);
549 summary->SetString("version", plugins[i].version); 267 summary->SetString("version", plugins[i].version);
550 bool enabled = true;
551 plugin_state_.Get(plugins[i].path, &enabled);
552 summary->SetBoolean("enabled", enabled);
553 plugins_list->Append(std::move(summary)); 268 plugins_list->Append(std::move(summary));
554 269
555 std::unique_ptr<PluginMetadata> plugin_metadata( 270 std::unique_ptr<PluginMetadata> plugin_metadata(
556 finder->GetPluginMetadata(plugins[i])); 271 finder->GetPluginMetadata(plugins[i]));
557 // Insert into a set of all group names. 272 // Insert into a set of all group names.
558 group_names.insert(plugin_metadata->name()); 273 group_names.insert(plugin_metadata->name());
559 } 274 }
560 275
561 // Add the plugin groups. 276 // Add the plugin groups.
562 for (std::set<base::string16>::const_iterator it = group_names.begin(); 277 for (std::set<base::string16>::const_iterator it = group_names.begin();
563 it != group_names.end(); ++it) { 278 it != group_names.end(); ++it) {
564 std::unique_ptr<base::DictionaryValue> summary(new base::DictionaryValue()); 279 std::unique_ptr<base::DictionaryValue> summary(new base::DictionaryValue());
565 summary->SetString("name", *it); 280 summary->SetString("name", *it);
566 bool enabled = true;
567 std::map<base::string16, bool>::iterator gstate_it =
568 plugin_group_state_.find(*it);
569 if (gstate_it != plugin_group_state_.end())
570 enabled = gstate_it->second;
571 summary->SetBoolean("enabled", enabled);
572 plugins_list->Append(std::move(summary)); 281 plugins_list->Append(std::move(summary));
573 } 282 }
574 } 283 }
575 284
576 void PluginPrefs::NotifyPluginStatusChanged() { 285 void PluginPrefs::NotifyPluginStatusChanged() {
577 DCHECK_CURRENTLY_ON(BrowserThread::UI); 286 DCHECK_CURRENTLY_ON(BrowserThread::UI);
578 content::NotificationService::current()->Notify( 287 content::NotificationService::current()->Notify(
579 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, 288 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
580 content::Source<Profile>(profile_), 289 content::Source<Profile>(profile_),
581 content::NotificationService::NoDetails()); 290 content::NotificationService::NoDetails());
582 } 291 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_prefs.h ('k') | chrome/browser/plugins/plugin_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698