OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_updater.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 : enable_internal_pdf_(true), | 33 : enable_internal_pdf_(true), |
34 notify_pending_(false) { | 34 notify_pending_(false) { |
35 } | 35 } |
36 | 36 |
37 DictionaryValue* PluginUpdater::CreatePluginFileSummary( | 37 DictionaryValue* PluginUpdater::CreatePluginFileSummary( |
38 const webkit::npapi::WebPluginInfo& plugin) { | 38 const webkit::npapi::WebPluginInfo& plugin) { |
39 DictionaryValue* data = new DictionaryValue(); | 39 DictionaryValue* data = new DictionaryValue(); |
40 data->SetString("path", plugin.path.value()); | 40 data->SetString("path", plugin.path.value()); |
41 data->SetString("name", plugin.name); | 41 data->SetString("name", plugin.name); |
42 data->SetString("version", plugin.version); | 42 data->SetString("version", plugin.version); |
43 data->SetBoolean("enabled", plugin.enabled); | 43 data->SetBoolean("enabled", webkit::npapi::IsPluginEnabled(plugin)); |
44 return data; | 44 return data; |
45 } | 45 } |
46 | 46 |
47 // static | 47 // static |
48 ListValue* PluginUpdater::GetPluginGroupsData() { | 48 ListValue* PluginUpdater::GetPluginGroupsData() { |
49 std::vector<webkit::npapi::PluginGroup> plugin_groups; | 49 std::vector<webkit::npapi::PluginGroup> plugin_groups; |
50 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, &plugin_groups); | 50 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, &plugin_groups); |
51 | 51 |
52 // Construct DictionaryValues to return to the UI | 52 // Construct DictionaryValues to return to the UI |
53 ListValue* plugin_groups_data = new ListValue(); | 53 ListValue* plugin_groups_data = new ListValue(); |
54 for (size_t i = 0; i < plugin_groups.size(); ++i) { | 54 for (size_t i = 0; i < plugin_groups.size(); ++i) { |
55 plugin_groups_data->Append(plugin_groups[i].GetDataForUI()); | 55 plugin_groups_data->Append(plugin_groups[i].GetDataForUI()); |
56 } | 56 } |
57 return plugin_groups_data; | 57 return plugin_groups_data; |
58 } | 58 } |
59 | 59 |
60 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { | 60 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { |
61 if (webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy(group_name)) | |
62 enable = false; | |
63 webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name); | 61 webkit::npapi::PluginList::Singleton()->EnableGroup(enable, group_name); |
64 NotifyPluginStatusChanged(); | 62 NotifyPluginStatusChanged(); |
65 } | 63 } |
66 | 64 |
67 void PluginUpdater::EnablePluginFile(bool enable, | 65 void PluginUpdater::EnablePlugin(bool enable, |
68 const FilePath::StringType& path) { | 66 const FilePath::StringType& path) { |
69 FilePath file_path(path); | 67 FilePath file_path(path); |
70 if (enable && | 68 if (enable) |
71 !webkit::npapi::PluginGroup::IsPluginPathDisabledByPolicy(file_path)) | |
72 webkit::npapi::PluginList::Singleton()->EnablePlugin(file_path); | 69 webkit::npapi::PluginList::Singleton()->EnablePlugin(file_path); |
73 else | 70 else |
74 webkit::npapi::PluginList::Singleton()->DisablePlugin(file_path); | 71 webkit::npapi::PluginList::Singleton()->DisablePlugin(file_path); |
75 | 72 |
76 NotifyPluginStatusChanged(); | 73 NotifyPluginStatusChanged(); |
77 } | 74 } |
78 | 75 |
79 void PluginUpdater::Observe(NotificationType type, | 76 void PluginUpdater::Observe(NotificationType type, |
80 const NotificationSource& source, | 77 const NotificationSource& source, |
81 const NotificationDetails& details) { | 78 const NotificationDetails& details) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { | 240 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { |
244 std::vector<webkit::npapi::WebPluginInfo> plugins; | 241 std::vector<webkit::npapi::WebPluginInfo> plugins; |
245 webkit::npapi::PluginList::Singleton()->GetPlugins(false, &plugins); | 242 webkit::npapi::PluginList::Singleton()->GetPlugins(false, &plugins); |
246 | 243 |
247 std::vector<webkit::npapi::PluginGroup> groups; | 244 std::vector<webkit::npapi::PluginGroup> groups; |
248 webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups); | 245 webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups); |
249 | 246 |
250 BrowserThread::PostTask( | 247 BrowserThread::PostTask( |
251 BrowserThread::UI, | 248 BrowserThread::UI, |
252 FROM_HERE, | 249 FROM_HERE, |
253 NewRunnableFunction( | 250 NewRunnableFunction(&PluginUpdater::OnUpdatePreferences, |
254 &PluginUpdater::OnUpdatePreferences, | 251 static_cast<Profile*>(profile), |
255 static_cast<Profile*>(profile), plugins, groups)); | 252 plugins, groups)); |
256 } | 253 } |
257 | 254 |
258 void PluginUpdater::OnUpdatePreferences( | 255 void PluginUpdater::OnUpdatePreferences( |
259 Profile* profile, | 256 Profile* profile, |
260 const std::vector<webkit::npapi::WebPluginInfo>& plugins, | 257 const std::vector<webkit::npapi::WebPluginInfo>& plugins, |
261 const std::vector<webkit::npapi::PluginGroup>& groups) { | 258 const std::vector<webkit::npapi::PluginGroup>& groups) { |
262 ListValue* plugins_list = profile->GetPrefs()->GetMutableList( | 259 ListValue* plugins_list = profile->GetPrefs()->GetMutableList( |
263 prefs::kPluginsPluginsList); | 260 prefs::kPluginsPluginsList); |
264 plugins_list->Clear(); | 261 plugins_list->Clear(); |
265 | 262 |
266 FilePath internal_dir; | 263 FilePath internal_dir; |
267 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) | 264 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) |
268 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory, | 265 profile->GetPrefs()->SetFilePath(prefs::kPluginsLastInternalDirectory, |
269 internal_dir); | 266 internal_dir); |
270 | 267 |
271 // Add the plugin files. | 268 // Add the plugin files. |
272 for (std::vector<webkit::npapi::WebPluginInfo>::const_iterator it = | 269 for (size_t i = 0; i < plugins.size(); ++i) { |
273 plugins.begin(); | 270 DictionaryValue* summary = CreatePluginFileSummary(plugins[i]); |
274 it != plugins.end(); | 271 // If the plugin is disabled only by policy don't store this state in the |
275 ++it) { | 272 // user pref store. |
276 plugins_list->Append(CreatePluginFileSummary(*it)); | 273 if (plugins[i].enabled == |
| 274 webkit::npapi::WebPluginInfo::USER_ENABLED_POLICY_DISABLED) { |
| 275 summary->SetBoolean("enabled", true); |
| 276 } |
| 277 bool enabled_val; |
| 278 summary->GetBoolean("enabled", &enabled_val); |
| 279 plugins_list->Append(summary); |
277 } | 280 } |
278 | 281 |
279 // Add the groups as well. | 282 // Add the groups as well. |
280 for (size_t i = 0; i < groups.size(); ++i) { | 283 for (size_t i = 0; i < groups.size(); ++i) { |
281 plugins_list->Append(groups[i].GetSummary()); | 284 DictionaryValue* summary = groups[i].GetSummary(); |
| 285 // If the plugin is disabled only by policy don't store this state in the |
| 286 // user pref store. |
| 287 if (!groups[i].Enabled() && |
| 288 webkit::npapi::PluginGroup::IsPluginNameDisabledByPolicy( |
| 289 groups[i].GetGroupName())) |
| 290 summary->SetBoolean("enabled", true); |
| 291 plugins_list->Append(summary); |
282 } | 292 } |
283 } | 293 } |
284 | 294 |
285 void PluginUpdater::NotifyPluginStatusChanged() { | 295 void PluginUpdater::NotifyPluginStatusChanged() { |
286 if (notify_pending_) | 296 if (notify_pending_) |
287 return; | 297 return; |
288 notify_pending_ = true; | 298 notify_pending_ = true; |
289 MessageLoop::current()->PostTask( | 299 MessageLoop::current()->PostTask( |
290 FROM_HERE, | 300 FROM_HERE, |
291 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); | 301 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); |
292 } | 302 } |
293 | 303 |
294 void PluginUpdater::OnNotifyPluginStatusChanged() { | 304 void PluginUpdater::OnNotifyPluginStatusChanged() { |
295 GetInstance()->notify_pending_ = false; | 305 GetInstance()->notify_pending_ = false; |
296 NotificationService::current()->Notify( | 306 NotificationService::current()->Notify( |
297 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, | 307 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, |
298 Source<PluginUpdater>(GetInstance()), | 308 Source<PluginUpdater>(GetInstance()), |
299 NotificationService::NoDetails()); | 309 NotificationService::NoDetails()); |
300 } | 310 } |
301 | 311 |
302 /*static*/ | 312 /*static*/ |
303 PluginUpdater* PluginUpdater::GetInstance() { | 313 PluginUpdater* PluginUpdater::GetInstance() { |
304 return Singleton<PluginUpdater>::get(); | 314 return Singleton<PluginUpdater>::get(); |
305 } | 315 } |
OLD | NEW |