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