OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/plugins/plugin_prefs.h" | 5 #include "chrome/browser/plugins/plugin_prefs.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
26 #include "chrome/common/chrome_content_client.h" | 26 #include "chrome/common/chrome_content_client.h" |
27 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
30 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 30 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/plugin_service.h" | 33 #include "content/public/browser/plugin_service.h" |
34 #include "webkit/plugins/webplugininfo.h" | 34 #include "content/public/common/webplugininfo.h" |
35 | 35 |
36 using content::BrowserThread; | 36 using content::BrowserThread; |
37 using content::PluginService; | 37 using content::PluginService; |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 bool IsComponentUpdatedPepperFlash(const base::FilePath& plugin) { | 41 bool IsComponentUpdatedPepperFlash(const base::FilePath& plugin) { |
42 if (plugin.BaseName().value() == chrome::kPepperFlashPluginFilename) { | 42 if (plugin.BaseName().value() == chrome::kPepperFlashPluginFilename) { |
43 base::FilePath component_updated_pepper_flash_dir; | 43 base::FilePath component_updated_pepper_flash_dir; |
44 if (PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, | 44 if (PathService::Get(chrome::DIR_COMPONENT_UPDATED_PEPPER_FLASH_PLUGIN, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) { | 104 void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) { |
105 PluginService::GetInstance()->GetPlugins( | 105 PluginService::GetInstance()->GetPlugins( |
106 base::Bind(&PluginPrefs::EnablePluginGroupInternal, | 106 base::Bind(&PluginPrefs::EnablePluginGroupInternal, |
107 this, enabled, group_name)); | 107 this, enabled, group_name)); |
108 } | 108 } |
109 | 109 |
110 void PluginPrefs::EnablePluginGroupInternal( | 110 void PluginPrefs::EnablePluginGroupInternal( |
111 bool enabled, | 111 bool enabled, |
112 const string16& group_name, | 112 const string16& group_name, |
113 const std::vector<webkit::WebPluginInfo>& plugins) { | 113 const std::vector<content::WebPluginInfo>& plugins) { |
114 base::AutoLock auto_lock(lock_); | 114 base::AutoLock auto_lock(lock_); |
115 PluginFinder* finder = PluginFinder::GetInstance(); | 115 PluginFinder* finder = PluginFinder::GetInstance(); |
116 | 116 |
117 // Set the desired state for the group. | 117 // Set the desired state for the group. |
118 plugin_group_state_[group_name] = enabled; | 118 plugin_group_state_[group_name] = enabled; |
119 | 119 |
120 // Update the state for all plug-ins in the group. | 120 // Update the state for all plug-ins in the group. |
121 for (size_t i = 0; i < plugins.size(); ++i) { | 121 for (size_t i = 0; i < plugins.size(); ++i) { |
122 scoped_ptr<PluginMetadata> plugin(finder->GetPluginMetadata(plugins[i])); | 122 scoped_ptr<PluginMetadata> plugin(finder->GetPluginMetadata(plugins[i])); |
123 if (group_name != plugin->name()) | 123 if (group_name != plugin->name()) |
124 continue; | 124 continue; |
125 plugin_state_.Set(plugins[i].path, enabled); | 125 plugin_state_.Set(plugins[i].path, enabled); |
126 } | 126 } |
127 | 127 |
128 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 128 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
129 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins)); | 129 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins)); |
130 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 130 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
131 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); | 131 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); |
132 } | 132 } |
133 | 133 |
134 void PluginPrefs::EnablePlugin( | 134 void PluginPrefs::EnablePlugin( |
135 bool enabled, const base::FilePath& path, | 135 bool enabled, const base::FilePath& path, |
136 const base::Callback<void(bool)>& callback) { | 136 const base::Callback<void(bool)>& callback) { |
137 PluginFinder* finder = PluginFinder::GetInstance(); | 137 PluginFinder* finder = PluginFinder::GetInstance(); |
138 webkit::WebPluginInfo plugin; | 138 content::WebPluginInfo plugin; |
139 bool can_enable = true; | 139 bool can_enable = true; |
140 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) { | 140 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) { |
141 scoped_ptr<PluginMetadata> plugin_metadata( | 141 scoped_ptr<PluginMetadata> plugin_metadata( |
142 finder->GetPluginMetadata(plugin)); | 142 finder->GetPluginMetadata(plugin)); |
143 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); | 143 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); |
144 PolicyStatus group_status = PolicyStatusForPlugin(plugin_metadata->name()); | 144 PolicyStatus group_status = PolicyStatusForPlugin(plugin_metadata->name()); |
145 if (enabled) { | 145 if (enabled) { |
146 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) | 146 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) |
147 can_enable = false; | 147 can_enable = false; |
148 } else { | 148 } else { |
(...skipping 13 matching lines...) Expand all Loading... |
162 PluginService::GetInstance()->GetPlugins( | 162 PluginService::GetInstance()->GetPlugins( |
163 base::Bind(&PluginPrefs::EnablePluginInternal, this, | 163 base::Bind(&PluginPrefs::EnablePluginInternal, this, |
164 enabled, path, finder, callback)); | 164 enabled, path, finder, callback)); |
165 } | 165 } |
166 | 166 |
167 void PluginPrefs::EnablePluginInternal( | 167 void PluginPrefs::EnablePluginInternal( |
168 bool enabled, | 168 bool enabled, |
169 const base::FilePath& path, | 169 const base::FilePath& path, |
170 PluginFinder* plugin_finder, | 170 PluginFinder* plugin_finder, |
171 const base::Callback<void(bool)>& callback, | 171 const base::Callback<void(bool)>& callback, |
172 const std::vector<webkit::WebPluginInfo>& plugins) { | 172 const std::vector<content::WebPluginInfo>& plugins) { |
173 { | 173 { |
174 // Set the desired state for the plug-in. | 174 // Set the desired state for the plug-in. |
175 base::AutoLock auto_lock(lock_); | 175 base::AutoLock auto_lock(lock_); |
176 plugin_state_.Set(path, enabled); | 176 plugin_state_.Set(path, enabled); |
177 } | 177 } |
178 | 178 |
179 string16 group_name; | 179 string16 group_name; |
180 for (size_t i = 0; i < plugins.size(); ++i) { | 180 for (size_t i = 0; i < plugins.size(); ++i) { |
181 if (plugins[i].path == path) { | 181 if (plugins[i].path == path) { |
182 scoped_ptr<PluginMetadata> plugin_metadata( | 182 scoped_ptr<PluginMetadata> plugin_metadata( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 return POLICY_ENABLED; | 218 return POLICY_ENABLED; |
219 } else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) && | 219 } else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) && |
220 !IsStringMatchedInSet( | 220 !IsStringMatchedInSet( |
221 name, policy_disabled_plugin_exception_patterns_)) { | 221 name, policy_disabled_plugin_exception_patterns_)) { |
222 return POLICY_DISABLED; | 222 return POLICY_DISABLED; |
223 } else { | 223 } else { |
224 return NO_POLICY; | 224 return NO_POLICY; |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 bool PluginPrefs::IsPluginEnabled(const webkit::WebPluginInfo& plugin) const { | 228 bool PluginPrefs::IsPluginEnabled(const content::WebPluginInfo& plugin) const { |
229 scoped_ptr<PluginMetadata> plugin_metadata( | 229 scoped_ptr<PluginMetadata> plugin_metadata( |
230 PluginFinder::GetInstance()->GetPluginMetadata(plugin)); | 230 PluginFinder::GetInstance()->GetPluginMetadata(plugin)); |
231 string16 group_name = plugin_metadata->name(); | 231 string16 group_name = plugin_metadata->name(); |
232 | 232 |
233 // Check if the plug-in or its group is enabled by policy. | 233 // Check if the plug-in or its group is enabled by policy. |
234 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); | 234 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); |
235 PolicyStatus group_status = PolicyStatusForPlugin(group_name); | 235 PolicyStatus group_status = PolicyStatusForPlugin(group_name); |
236 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) | 236 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) |
237 return true; | 237 return true; |
238 | 238 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 void PluginPrefs::SetPolicyEnforcedPluginPatterns( | 515 void PluginPrefs::SetPolicyEnforcedPluginPatterns( |
516 const std::set<string16>& disabled_patterns, | 516 const std::set<string16>& disabled_patterns, |
517 const std::set<string16>& disabled_exception_patterns, | 517 const std::set<string16>& disabled_exception_patterns, |
518 const std::set<string16>& enabled_patterns) { | 518 const std::set<string16>& enabled_patterns) { |
519 policy_disabled_plugin_patterns_ = disabled_patterns; | 519 policy_disabled_plugin_patterns_ = disabled_patterns; |
520 policy_disabled_plugin_exception_patterns_ = disabled_exception_patterns; | 520 policy_disabled_plugin_exception_patterns_ = disabled_exception_patterns; |
521 policy_enabled_plugin_patterns_ = enabled_patterns; | 521 policy_enabled_plugin_patterns_ = enabled_patterns; |
522 } | 522 } |
523 | 523 |
524 void PluginPrefs::OnUpdatePreferences( | 524 void PluginPrefs::OnUpdatePreferences( |
525 const std::vector<webkit::WebPluginInfo>& plugins) { | 525 const std::vector<content::WebPluginInfo>& plugins) { |
526 if (!prefs_) | 526 if (!prefs_) |
527 return; | 527 return; |
528 | 528 |
529 PluginFinder* finder = PluginFinder::GetInstance(); | 529 PluginFinder* finder = PluginFinder::GetInstance(); |
530 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); | 530 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); |
531 ListValue* plugins_list = update.Get(); | 531 ListValue* plugins_list = update.Get(); |
532 plugins_list->Clear(); | 532 plugins_list->Clear(); |
533 | 533 |
534 base::FilePath internal_dir; | 534 base::FilePath internal_dir; |
535 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) | 535 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 } | 570 } |
571 } | 571 } |
572 | 572 |
573 void PluginPrefs::NotifyPluginStatusChanged() { | 573 void PluginPrefs::NotifyPluginStatusChanged() { |
574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
575 content::NotificationService::current()->Notify( | 575 content::NotificationService::current()->Notify( |
576 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 576 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
577 content::Source<Profile>(profile_), | 577 content::Source<Profile>(profile_), |
578 content::NotificationService::NoDetails()); | 578 content::NotificationService::NoDetails()); |
579 } | 579 } |
OLD | NEW |