| 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/ui/webui/plugins_ui.h" | 5 #include "chrome/browser/ui/webui/plugins_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/api/prefs/pref_member.h" | 20 #include "chrome/browser/api/prefs/pref_member.h" |
| 21 #include "chrome/browser/content_settings/host_content_settings_map.h" | 21 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 22 #include "chrome/browser/plugins/plugin_finder.h" | 22 #include "chrome/browser/plugins/plugin_finder.h" |
| 23 #include "chrome/browser/plugins/plugin_installer.h" | 23 #include "chrome/browser/plugins/plugin_metadata.h" |
| 24 #include "chrome/browser/plugins/plugin_prefs.h" | 24 #include "chrome/browser/plugins/plugin_prefs.h" |
| 25 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
| 26 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 26 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_window.h" | 29 #include "chrome/browser/ui/browser_window.h" |
| 30 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 30 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 31 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 31 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 32 #include "chrome/common/chrome_content_client.h" | 32 #include "chrome/common/chrome_content_client.h" |
| 33 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 // Callback for the "setPluginAlwaysAllowed" message. | 157 // Callback for the "setPluginAlwaysAllowed" message. |
| 158 void HandleSetPluginAlwaysAllowed(const ListValue* args); | 158 void HandleSetPluginAlwaysAllowed(const ListValue* args); |
| 159 | 159 |
| 160 // content::NotificationObserver method overrides | 160 // content::NotificationObserver method overrides |
| 161 virtual void Observe(int type, | 161 virtual void Observe(int type, |
| 162 const content::NotificationSource& source, | 162 const content::NotificationSource& source, |
| 163 const content::NotificationDetails& details) OVERRIDE; | 163 const content::NotificationDetails& details) OVERRIDE; |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 // Call this to start getting the plugins on the UI thread. | 166 void LoadPlugins(); |
| 167 void GetPluginFinder(); | |
| 168 | |
| 169 // Called when we have a PluginFinder and need to load the list of plug-ins. | |
| 170 void LoadPlugins(PluginFinder* plugin_finder); | |
| 171 | 167 |
| 172 // Called on the UI thread when the plugin information is ready. | 168 // Called on the UI thread when the plugin information is ready. |
| 173 void PluginsLoaded(PluginFinder* plugin_finder, | 169 void PluginsLoaded(const std::vector<webkit::WebPluginInfo>& plugins); |
| 174 const std::vector<webkit::WebPluginInfo>& plugins); | |
| 175 | 170 |
| 176 content::NotificationRegistrar registrar_; | 171 content::NotificationRegistrar registrar_; |
| 177 | 172 |
| 178 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_; | 173 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_; |
| 179 | 174 |
| 180 // Holds grouped plug-ins. The key is the group identifier and | 175 // Holds grouped plug-ins. The key is the group identifier and |
| 181 // the value is the list of plug-ins belonging to the group. | 176 // the value is the list of plug-ins belonging to the group. |
| 182 typedef base::hash_map<std::string, std::vector<const WebPluginInfo*> > | 177 typedef base::hash_map<std::string, std::vector<const WebPluginInfo*> > |
| 183 PluginGroups; | 178 PluginGroups; |
| 184 | 179 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 214 base::Unretained(this))); | 209 base::Unretained(this))); |
| 215 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs", | 210 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs", |
| 216 base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs, | 211 base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs, |
| 217 base::Unretained(this))); | 212 base::Unretained(this))); |
| 218 web_ui()->RegisterMessageCallback("getShowDetails", | 213 web_ui()->RegisterMessageCallback("getShowDetails", |
| 219 base::Bind(&PluginsDOMHandler::HandleGetShowDetails, | 214 base::Bind(&PluginsDOMHandler::HandleGetShowDetails, |
| 220 base::Unretained(this))); | 215 base::Unretained(this))); |
| 221 } | 216 } |
| 222 | 217 |
| 223 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { | 218 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { |
| 224 GetPluginFinder(); | 219 LoadPlugins(); |
| 225 } | 220 } |
| 226 | 221 |
| 227 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { | 222 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { |
| 228 Profile* profile = Profile::FromWebUI(web_ui()); | 223 Profile* profile = Profile::FromWebUI(web_ui()); |
| 229 | 224 |
| 230 // Be robust in accepting badness since plug-ins display HTML (hence | 225 // Be robust in accepting badness since plug-ins display HTML (hence |
| 231 // JavaScript). | 226 // JavaScript). |
| 232 if (args->GetSize() != 3) { | 227 if (args->GetSize() != 3) { |
| 233 NOTREACHED(); | 228 NOTREACHED(); |
| 234 return; | 229 return; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 // whitelisted by the user from automatically whitelisted ones. | 308 // whitelisted by the user from automatically whitelisted ones. |
| 314 DictionaryPrefUpdate update(profile->GetPrefs(), | 309 DictionaryPrefUpdate update(profile->GetPrefs(), |
| 315 prefs::kContentSettingsPluginWhitelist); | 310 prefs::kContentSettingsPluginWhitelist); |
| 316 update->SetBoolean(plugin, allowed); | 311 update->SetBoolean(plugin, allowed); |
| 317 } | 312 } |
| 318 | 313 |
| 319 void PluginsDOMHandler::Observe(int type, | 314 void PluginsDOMHandler::Observe(int type, |
| 320 const content::NotificationSource& source, | 315 const content::NotificationSource& source, |
| 321 const content::NotificationDetails& details) { | 316 const content::NotificationDetails& details) { |
| 322 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); | 317 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); |
| 323 GetPluginFinder(); | 318 LoadPlugins(); |
| 324 } | 319 } |
| 325 | 320 |
| 326 void PluginsDOMHandler::GetPluginFinder() { | 321 void PluginsDOMHandler::LoadPlugins() { |
| 327 if (weak_ptr_factory_.HasWeakPtrs()) | 322 if (weak_ptr_factory_.HasWeakPtrs()) |
| 328 return; | 323 return; |
| 329 | 324 |
| 330 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins, | |
| 331 weak_ptr_factory_.GetWeakPtr())); | |
| 332 } | |
| 333 | |
| 334 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) { | |
| 335 PluginService::GetInstance()->GetPlugins( | 325 PluginService::GetInstance()->GetPlugins( |
| 336 base::Bind(&PluginsDOMHandler::PluginsLoaded, | 326 base::Bind(&PluginsDOMHandler::PluginsLoaded, |
| 337 weak_ptr_factory_.GetWeakPtr(), plugin_finder)); | 327 weak_ptr_factory_.GetWeakPtr())); |
| 338 } | 328 } |
| 339 | 329 |
| 340 void PluginsDOMHandler::PluginsLoaded( | 330 void PluginsDOMHandler::PluginsLoaded( |
| 341 PluginFinder* plugin_finder, | |
| 342 const std::vector<webkit::WebPluginInfo>& plugins) { | 331 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 343 Profile* profile = Profile::FromWebUI(web_ui()); | 332 Profile* profile = Profile::FromWebUI(web_ui()); |
| 344 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); | 333 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
| 345 | 334 |
| 346 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | 335 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
| 347 | 336 |
| 337 PluginFinder* plugin_finder = PluginFinder::GetInstance(); |
| 348 // Group plug-ins by identifier. This is done to be able to display | 338 // Group plug-ins by identifier. This is done to be able to display |
| 349 // the plug-ins in UI in a grouped fashion. | 339 // the plug-ins in UI in a grouped fashion. |
| 350 PluginGroups groups; | 340 PluginGroups groups; |
| 351 for (size_t i = 0; i < plugins.size(); ++i) { | 341 for (size_t i = 0; i < plugins.size(); ++i) { |
| 352 PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]); | 342 PluginMetadata* plugin = plugin_finder->GetPluginMetadata(plugins[i]); |
| 353 groups[installer->identifier()].push_back(&plugins[i]); | 343 groups[plugin->identifier()].push_back(&plugins[i]); |
| 354 } | 344 } |
| 355 | 345 |
| 356 // Construct DictionaryValues to return to UI. | 346 // Construct DictionaryValues to return to UI. |
| 357 ListValue* plugin_groups_data = new ListValue(); | 347 ListValue* plugin_groups_data = new ListValue(); |
| 358 for (PluginGroups::const_iterator it = groups.begin(); | 348 for (PluginGroups::const_iterator it = groups.begin(); |
| 359 it != groups.end(); ++it) { | 349 it != groups.end(); ++it) { |
| 360 const std::vector<const WebPluginInfo*>& group_plugins = it->second; | 350 const std::vector<const WebPluginInfo*>& group_plugins = it->second; |
| 361 ListValue* plugin_files = new ListValue(); | 351 ListValue* plugin_files = new ListValue(); |
| 362 PluginInstaller* plugin_installer = | 352 PluginMetadata* plugin_metadata = |
| 363 plugin_finder->GetPluginInstaller(*group_plugins[0]); | 353 plugin_finder->GetPluginMetadata(*group_plugins[0]); |
| 364 string16 group_name = plugin_installer->name(); | 354 string16 group_name = plugin_metadata->name(); |
| 365 std::string group_identifier = plugin_installer->identifier(); | 355 std::string group_identifier = plugin_metadata->identifier(); |
| 366 bool group_enabled = false; | 356 bool group_enabled = false; |
| 367 bool all_plugins_enabled_by_policy = true; | 357 bool all_plugins_enabled_by_policy = true; |
| 368 bool all_plugins_disabled_by_policy = true; | 358 bool all_plugins_disabled_by_policy = true; |
| 369 const WebPluginInfo* active_plugin = NULL; | 359 const WebPluginInfo* active_plugin = NULL; |
| 370 for (size_t j = 0; j < group_plugins.size(); ++j) { | 360 for (size_t j = 0; j < group_plugins.size(); ++j) { |
| 371 const WebPluginInfo& group_plugin = *group_plugins[j]; | 361 const WebPluginInfo& group_plugin = *group_plugins[j]; |
| 372 | 362 |
| 373 DictionaryValue* plugin_file = new DictionaryValue(); | 363 DictionaryValue* plugin_file = new DictionaryValue(); |
| 374 plugin_file->SetString("name", group_plugin.name); | 364 plugin_file->SetString("name", group_plugin.name); |
| 375 plugin_file->SetString("description", group_plugin.desc); | 365 plugin_file->SetString("description", group_plugin.desc); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 420 } |
| 431 DictionaryValue* group_data = new DictionaryValue(); | 421 DictionaryValue* group_data = new DictionaryValue(); |
| 432 | 422 |
| 433 group_data->Set("plugin_files", plugin_files); | 423 group_data->Set("plugin_files", plugin_files); |
| 434 group_data->SetString("name", group_name); | 424 group_data->SetString("name", group_name); |
| 435 group_data->SetString("id", group_identifier); | 425 group_data->SetString("id", group_identifier); |
| 436 group_data->SetString("description", active_plugin->desc); | 426 group_data->SetString("description", active_plugin->desc); |
| 437 group_data->SetString("version", active_plugin->version); | 427 group_data->SetString("version", active_plugin->version); |
| 438 | 428 |
| 439 #if defined(ENABLE_PLUGIN_INSTALLATION) | 429 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 440 PluginInstaller* installer = | 430 bool out_of_date = plugin_metadata->GetSecurityStatus(*active_plugin) == |
| 441 plugin_finder->FindPluginWithIdentifier(group_identifier); | 431 PluginMetadata::SECURITY_STATUS_OUT_OF_DATE; |
| 442 if (installer) { | 432 group_data->SetBoolean("critical", out_of_date); |
| 443 bool out_of_date = installer->GetSecurityStatus(*active_plugin) == | 433 group_data->SetString("update_url", plugin_metadata->plugin_url().spec()); |
| 444 PluginInstaller::SECURITY_STATUS_OUT_OF_DATE; | |
| 445 group_data->SetBoolean("critical", out_of_date); | |
| 446 group_data->SetString("update_url", installer->plugin_url().spec()); | |
| 447 } | |
| 448 #endif | 434 #endif |
| 449 | 435 |
| 450 std::string enabled_mode; | 436 std::string enabled_mode; |
| 451 if (all_plugins_enabled_by_policy) { | 437 if (all_plugins_enabled_by_policy) { |
| 452 enabled_mode = "enabledByPolicy"; | 438 enabled_mode = "enabledByPolicy"; |
| 453 } else if (all_plugins_disabled_by_policy) { | 439 } else if (all_plugins_disabled_by_policy) { |
| 454 enabled_mode = "disabledByPolicy"; | 440 enabled_mode = "disabledByPolicy"; |
| 455 } else if (group_enabled) { | 441 } else if (group_enabled) { |
| 456 enabled_mode = "enabledByUser"; | 442 enabled_mode = "enabledByUser"; |
| 457 } else { | 443 } else { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { | 487 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { |
| 502 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, | 488 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, |
| 503 false, | 489 false, |
| 504 PrefService::UNSYNCABLE_PREF); | 490 PrefService::UNSYNCABLE_PREF); |
| 505 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, | 491 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, |
| 506 true, | 492 true, |
| 507 PrefService::UNSYNCABLE_PREF); | 493 PrefService::UNSYNCABLE_PREF); |
| 508 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, | 494 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, |
| 509 PrefService::SYNCABLE_PREF); | 495 PrefService::SYNCABLE_PREF); |
| 510 } | 496 } |
| OLD | NEW |