| 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 <string> | 8 #include <string> |
| 8 #include <vector> | |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "base/version.h" | 16 #include "base/version.h" |
| 17 #include "chrome/browser/browser_thread.h" | 17 #include "chrome/browser/browser_thread.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 38 DictionaryValue* data = new DictionaryValue(); | 38 DictionaryValue* data = new DictionaryValue(); |
| 39 data->SetString("path", plugin.path.value()); | 39 data->SetString("path", plugin.path.value()); |
| 40 data->SetString("name", plugin.name); | 40 data->SetString("name", plugin.name); |
| 41 data->SetString("version", plugin.version); | 41 data->SetString("version", plugin.version); |
| 42 data->SetBoolean("enabled", plugin.enabled); | 42 data->SetBoolean("enabled", plugin.enabled); |
| 43 return data; | 43 return data; |
| 44 } | 44 } |
| 45 | 45 |
| 46 // static | 46 // static |
| 47 ListValue* PluginUpdater::GetPluginGroupsData() { | 47 ListValue* PluginUpdater::GetPluginGroupsData() { |
| 48 NPAPI::PluginList::PluginMap plugin_groups; | 48 std::vector<PluginGroup> plugin_groups( |
| 49 NPAPI::PluginList::Singleton()->GetPluginGroups(true, &plugin_groups); | 49 NPAPI::PluginList::Singleton()->GetPluginGroups(true)); |
| 50 | 50 |
| 51 // Construct DictionaryValues to return to the UI | 51 // Construct DictionaryValues to return to the UI |
| 52 ListValue* plugin_groups_data = new ListValue(); | 52 ListValue* plugin_groups_data = new ListValue(); |
| 53 for (NPAPI::PluginList::PluginMap::const_iterator it = | 53 for (size_t i = 0; i < plugin_groups.size(); ++i) { |
| 54 plugin_groups.begin(); | 54 plugin_groups_data->Append(plugin_groups[i].GetDataForUI()); |
| 55 it != plugin_groups.end(); | |
| 56 ++it) { | |
| 57 plugin_groups_data->Append(it->second->GetDataForUI()); | |
| 58 } | 55 } |
| 59 return plugin_groups_data; | 56 return plugin_groups_data; |
| 60 } | 57 } |
| 61 | 58 |
| 62 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { | 59 void PluginUpdater::EnablePluginGroup(bool enable, const string16& group_name) { |
| 63 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) | 60 if (PluginGroup::IsPluginNameDisabledByPolicy(group_name)) |
| 64 enable = false; | 61 enable = false; |
| 65 NPAPI::PluginList::Singleton()->EnableGroup(enable, group_name); | 62 NPAPI::PluginList::Singleton()->EnableGroup(enable, group_name); |
| 66 NotifyPluginStatusChanged(); | 63 NotifyPluginStatusChanged(); |
| 67 } | 64 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 BrowserThread::FILE, | 234 BrowserThread::FILE, |
| 238 FROM_HERE, | 235 FROM_HERE, |
| 239 NewRunnableFunction( | 236 NewRunnableFunction( |
| 240 &PluginUpdater::GetPreferencesDataOnFileThread, profile), delay_ms); | 237 &PluginUpdater::GetPreferencesDataOnFileThread, profile), delay_ms); |
| 241 } | 238 } |
| 242 | 239 |
| 243 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { | 240 void PluginUpdater::GetPreferencesDataOnFileThread(void* profile) { |
| 244 std::vector<WebPluginInfo> plugins; | 241 std::vector<WebPluginInfo> plugins; |
| 245 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); | 242 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); |
| 246 | 243 |
| 247 NPAPI::PluginList::PluginMap groups; | 244 std::vector<PluginGroup> groups( |
| 248 NPAPI::PluginList::Singleton()->GetPluginGroups(false, &groups); | 245 NPAPI::PluginList::Singleton()->GetPluginGroups(false)); |
| 249 | 246 |
| 250 BrowserThread::PostTask( | 247 BrowserThread::PostTask( |
| 251 BrowserThread::UI, | 248 BrowserThread::UI, |
| 252 FROM_HERE, | 249 FROM_HERE, |
| 253 NewRunnableFunction( | 250 NewRunnableFunction( |
| 254 &PluginUpdater::OnUpdatePreferences, | 251 &PluginUpdater::OnUpdatePreferences, |
| 255 static_cast<Profile*>(profile), plugins, groups)); | 252 static_cast<Profile*>(profile), plugins, groups)); |
| 256 } | 253 } |
| 257 | 254 |
| 258 void PluginUpdater::OnUpdatePreferences( | 255 void PluginUpdater::OnUpdatePreferences( |
| 259 Profile* profile, | 256 Profile* profile, |
| 260 const std::vector<WebPluginInfo>& plugins, | 257 const std::vector<WebPluginInfo>& plugins, |
| 261 const NPAPI::PluginList::PluginMap& groups) { | 258 const std::vector<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<WebPluginInfo>::const_iterator it = plugins.begin(); | 269 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); |
| 273 it != plugins.end(); | 270 it != plugins.end(); |
| 274 ++it) { | 271 ++it) { |
| 275 plugins_list->Append(CreatePluginFileSummary(*it)); | 272 plugins_list->Append(CreatePluginFileSummary(*it)); |
| 276 } | 273 } |
| 277 | 274 |
| 278 // Add the groups as well. | 275 // Add the groups as well. |
| 279 for (NPAPI::PluginList::PluginMap::const_iterator it = groups.begin(); | 276 for (size_t i = 0; i < groups.size(); ++i) { |
| 280 it != groups.end(); ++it) { | |
| 281 // Don't save preferences for vulnerable pugins. | 277 // Don't save preferences for vulnerable pugins. |
| 282 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 278 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 283 switches::kDisableOutdatedPlugins) || | 279 switches::kDisableOutdatedPlugins) || |
| 284 !it->second->IsVulnerable()) { | 280 !groups[i].IsVulnerable()) { |
| 285 plugins_list->Append(it->second->GetSummary()); | 281 plugins_list->Append(groups[i].GetSummary()); |
| 286 } | 282 } |
| 287 } | 283 } |
| 288 } | 284 } |
| 289 | 285 |
| 290 void PluginUpdater::NotifyPluginStatusChanged() { | 286 void PluginUpdater::NotifyPluginStatusChanged() { |
| 291 if (notify_pending_) | 287 if (notify_pending_) |
| 292 return; | 288 return; |
| 293 notify_pending_ = true; | 289 notify_pending_ = true; |
| 294 MessageLoop::current()->PostTask( | 290 MessageLoop::current()->PostTask( |
| 295 FROM_HERE, | 291 FROM_HERE, |
| 296 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); | 292 NewRunnableFunction(&PluginUpdater::OnNotifyPluginStatusChanged)); |
| 297 } | 293 } |
| 298 | 294 |
| 299 void PluginUpdater::OnNotifyPluginStatusChanged() { | 295 void PluginUpdater::OnNotifyPluginStatusChanged() { |
| 300 GetPluginUpdater()->notify_pending_ = false; | 296 GetPluginUpdater()->notify_pending_ = false; |
| 301 NotificationService::current()->Notify( | 297 NotificationService::current()->Notify( |
| 302 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, | 298 NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, |
| 303 Source<PluginUpdater>(GetPluginUpdater()), | 299 Source<PluginUpdater>(GetPluginUpdater()), |
| 304 NotificationService::NoDetails()); | 300 NotificationService::NoDetails()); |
| 305 } | 301 } |
| 306 | 302 |
| 307 /*static*/ | 303 /*static*/ |
| 308 PluginUpdater* PluginUpdater::GetPluginUpdater() { | 304 PluginUpdater* PluginUpdater::GetPluginUpdater() { |
| 309 return Singleton<PluginUpdater>::get(); | 305 return Singleton<PluginUpdater>::get(); |
| 310 } | 306 } |
| OLD | NEW |