| 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 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #endif | 59 #endif |
| 60 | 60 |
| 61 using content::PluginService; | 61 using content::PluginService; |
| 62 using content::WebContents; | 62 using content::WebContents; |
| 63 using content::WebUIMessageHandler; | 63 using content::WebUIMessageHandler; |
| 64 using webkit::npapi::PluginGroup; | 64 using webkit::npapi::PluginGroup; |
| 65 using webkit::WebPluginInfo; | 65 using webkit::WebPluginInfo; |
| 66 | 66 |
| 67 namespace { | 67 namespace { |
| 68 | 68 |
| 69 // Helper callback method to process result of CanEnablePlugin method. |
| 70 void CheckCanEnablePluginCallback(bool can_enable) { |
| 71 DCHECK(can_enable); |
| 72 } |
| 73 |
| 69 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() { | 74 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() { |
| 70 ChromeWebUIDataSource* source = | 75 ChromeWebUIDataSource* source = |
| 71 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost); | 76 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost); |
| 72 source->set_use_json_js_format_v2(); | 77 source->set_use_json_js_format_v2(); |
| 73 | 78 |
| 74 source->AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE); | 79 source->AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE); |
| 75 source->AddLocalizedString("pluginsDetailsModeLink", | 80 source->AddLocalizedString("pluginsDetailsModeLink", |
| 76 IDS_PLUGINS_DETAILS_MODE_LINK); | 81 IDS_PLUGINS_DETAILS_MODE_LINK); |
| 77 source->AddLocalizedString("pluginsNoneInstalled", | 82 source->AddLocalizedString("pluginsNoneInstalled", |
| 78 IDS_PLUGINS_NONE_INSTALLED); | 83 IDS_PLUGINS_NONE_INSTALLED); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 172 |
| 168 private: | 173 private: |
| 169 // Call this to start getting the plugins on the UI thread. | 174 // Call this to start getting the plugins on the UI thread. |
| 170 void GetPluginFinder(); | 175 void GetPluginFinder(); |
| 171 | 176 |
| 172 // Called when we have a PluginFinder and need to load the list of plug-ins. | 177 // Called when we have a PluginFinder and need to load the list of plug-ins. |
| 173 void LoadPlugins(PluginFinder* plugin_finder); | 178 void LoadPlugins(PluginFinder* plugin_finder); |
| 174 | 179 |
| 175 // Called on the UI thread when the plugin information is ready. | 180 // Called on the UI thread when the plugin information is ready. |
| 176 void PluginsLoaded(PluginFinder* plugin_finder, | 181 void PluginsLoaded(PluginFinder* plugin_finder, |
| 177 const std::vector<PluginGroup>& groups); | 182 const std::vector<webkit::WebPluginInfo>& plugins); |
| 178 | 183 |
| 179 content::NotificationRegistrar registrar_; | 184 content::NotificationRegistrar registrar_; |
| 180 | 185 |
| 181 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_; | 186 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_; |
| 182 | 187 |
| 188 typedef base::hash_map<std::string, std::vector<const WebPluginInfo*> > |
| 189 PluginGroups; |
| 190 |
| 183 // This pref guards the value whether about:plugins is in the details mode or | 191 // This pref guards the value whether about:plugins is in the details mode or |
| 184 // not. | 192 // not. |
| 185 BooleanPrefMember show_details_; | 193 BooleanPrefMember show_details_; |
| 186 | 194 |
| 187 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); | 195 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); |
| 188 }; | 196 }; |
| 189 | 197 |
| 190 PluginsDOMHandler::PluginsDOMHandler() | 198 PluginsDOMHandler::PluginsDOMHandler() |
| 191 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 199 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 192 } | 200 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 241 } |
| 234 | 242 |
| 235 std::string enable_str; | 243 std::string enable_str; |
| 236 std::string is_group_str; | 244 std::string is_group_str; |
| 237 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) { | 245 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) { |
| 238 NOTREACHED(); | 246 NOTREACHED(); |
| 239 return; | 247 return; |
| 240 } | 248 } |
| 241 bool enable = enable_str == "true"; | 249 bool enable = enable_str == "true"; |
| 242 | 250 |
| 243 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); | 251 scoped_refptr<PluginPrefs> plugin_prefs(PluginPrefs::GetForProfile(profile)); |
| 244 if (is_group_str == "true") { | 252 if (is_group_str == "true") { |
| 245 string16 group_name; | 253 string16 group_name; |
| 246 if (!args->GetString(0, &group_name)) { | 254 if (!args->GetString(0, &group_name)) { |
| 247 NOTREACHED(); | 255 NOTREACHED(); |
| 248 return; | 256 return; |
| 249 } | 257 } |
| 250 | 258 |
| 251 plugin_prefs->EnablePluginGroup(enable, group_name); | 259 plugin_prefs->EnablePluginGroup(enable, group_name); |
| 252 if (enable) { | 260 if (enable) { |
| 253 // See http://crbug.com/50105 for background. | 261 // See http://crbug.com/50105 for background. |
| 254 string16 adobereader = ASCIIToUTF16( | 262 string16 adobereader = ASCIIToUTF16( |
| 255 PluginGroup::kAdobeReaderGroupName); | 263 PluginGroup::kAdobeReaderGroupName); |
| 256 string16 internalpdf = | 264 string16 internalpdf = |
| 257 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); | 265 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); |
| 258 if (group_name == adobereader) | 266 if (group_name == adobereader) |
| 259 plugin_prefs->EnablePluginGroup(false, internalpdf); | 267 plugin_prefs->EnablePluginGroup(false, internalpdf); |
| 260 else if (group_name == internalpdf) | 268 else if (group_name == internalpdf) |
| 261 plugin_prefs->EnablePluginGroup(false, adobereader); | 269 plugin_prefs->EnablePluginGroup(false, adobereader); |
| 262 } | 270 } |
| 263 } else { | 271 } else { |
| 264 FilePath::StringType file_path; | 272 FilePath::StringType file_path; |
| 265 if (!args->GetString(0, &file_path)) { | 273 if (!args->GetString(0, &file_path)) { |
| 266 NOTREACHED(); | 274 NOTREACHED(); |
| 267 return; | 275 return; |
| 268 } | 276 } |
| 269 DCHECK(plugin_prefs->CanEnablePlugin(enable, FilePath(file_path))); | 277 |
| 270 plugin_prefs->EnablePlugin(enable, FilePath(file_path), | 278 plugin_prefs->EnablePlugin(enable, FilePath(file_path), |
| 271 base::Bind(&base::DoNothing)); | 279 base::Bind(&base::DoNothing), |
| 280 base::Bind(&CheckCanEnablePluginCallback)); |
| 272 } | 281 } |
| 273 } | 282 } |
| 274 | 283 |
| 275 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { | 284 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { |
| 276 std::string details_mode; | 285 std::string details_mode; |
| 277 if (!args->GetString(0, &details_mode)) { | 286 if (!args->GetString(0, &details_mode)) { |
| 278 NOTREACHED(); | 287 NOTREACHED(); |
| 279 return; | 288 return; |
| 280 } | 289 } |
| 281 show_details_.SetValue(details_mode == "true"); | 290 show_details_.SetValue(details_mode == "true"); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 336 |
| 328 #if defined(ENABLE_PLUGIN_INSTALLATION) | 337 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 329 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins, | 338 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins, |
| 330 weak_ptr_factory_.GetWeakPtr())); | 339 weak_ptr_factory_.GetWeakPtr())); |
| 331 #else | 340 #else |
| 332 LoadPlugins(NULL); | 341 LoadPlugins(NULL); |
| 333 #endif | 342 #endif |
| 334 } | 343 } |
| 335 | 344 |
| 336 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) { | 345 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) { |
| 337 PluginService::GetInstance()->GetPluginGroups( | 346 PluginService::GetInstance()->GetPlugins( |
| 338 base::Bind(&PluginsDOMHandler::PluginsLoaded, | 347 base::Bind(&PluginsDOMHandler::PluginsLoaded, |
| 339 weak_ptr_factory_.GetWeakPtr(), plugin_finder)); | 348 weak_ptr_factory_.GetWeakPtr(), plugin_finder)); |
| 340 } | 349 } |
| 341 | 350 |
| 342 void PluginsDOMHandler::PluginsLoaded(PluginFinder* plugin_finder, | 351 void PluginsDOMHandler::PluginsLoaded( |
| 343 const std::vector<PluginGroup>& groups) { | 352 PluginFinder* plugin_finder, |
| 353 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 344 Profile* profile = Profile::FromWebUI(web_ui()); | 354 Profile* profile = Profile::FromWebUI(web_ui()); |
| 345 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); | 355 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
| 346 | 356 |
| 347 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | 357 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
| 348 | 358 |
| 349 // Construct DictionaryValues to return to the UI | 359 // Group plug-ins by identifier. This is done to be able to display |
| 360 // the plug-ins in UI in a grouped fashion. |
| 361 PluginGroups groups; |
| 362 for (size_t i = 0; i < plugins.size(); ++i) { |
| 363 PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]); |
| 364 groups[installer->identifier()].push_back(&plugins[i]); |
| 365 } |
| 366 |
| 367 // Construct DictionaryValues to return to UI. |
| 350 ListValue* plugin_groups_data = new ListValue(); | 368 ListValue* plugin_groups_data = new ListValue(); |
| 351 for (size_t i = 0; i < groups.size(); ++i) { | 369 for (PluginGroups::const_iterator it = groups.begin(); |
| 352 const PluginGroup& group = groups[i]; | 370 it != groups.end(); ++it) { |
| 353 if (group.IsEmpty()) | 371 const std::vector<const WebPluginInfo*>& group_plugins = it->second; |
| 354 continue; | |
| 355 ListValue* plugin_files = new ListValue(); | 372 ListValue* plugin_files = new ListValue(); |
| 356 string16 group_name = group.GetGroupName(); | 373 PluginInstaller* plugin_installer = |
| 374 plugin_finder->GetPluginInstaller(*group_plugins[0]); |
| 375 string16 group_name = plugin_installer->name(); |
| 376 std::string group_identifier = plugin_installer->identifier(); |
| 357 bool group_enabled = false; | 377 bool group_enabled = false; |
| 358 bool all_plugins_enabled_by_policy = true; | 378 bool all_plugins_enabled_by_policy = true; |
| 359 bool all_plugins_disabled_by_policy = true; | 379 bool all_plugins_disabled_by_policy = true; |
| 360 const WebPluginInfo* active_plugin = NULL; | 380 const WebPluginInfo* active_plugin = NULL; |
| 361 for (size_t j = 0; j < group.web_plugin_infos().size(); ++j) { | 381 for (size_t j = 0; j < group_plugins.size(); ++j) { |
| 362 const WebPluginInfo& group_plugin = group.web_plugin_infos()[j]; | 382 const WebPluginInfo& group_plugin = *group_plugins[j]; |
| 363 | 383 |
| 364 DictionaryValue* plugin_file = new DictionaryValue(); | 384 DictionaryValue* plugin_file = new DictionaryValue(); |
| 365 plugin_file->SetString("name", group_plugin.name); | 385 plugin_file->SetString("name", group_plugin.name); |
| 366 plugin_file->SetString("description", group_plugin.desc); | 386 plugin_file->SetString("description", group_plugin.desc); |
| 367 plugin_file->SetString("path", group_plugin.path.value()); | 387 plugin_file->SetString("path", group_plugin.path.value()); |
| 368 plugin_file->SetString("version", group_plugin.version); | 388 plugin_file->SetString("version", group_plugin.version); |
| 369 plugin_file->SetString("type", PluginTypeToString(group_plugin.type)); | 389 plugin_file->SetString("type", PluginTypeToString(group_plugin.type)); |
| 370 | 390 |
| 371 ListValue* mime_types = new ListValue(); | 391 ListValue* mime_types = new ListValue(); |
| 372 const std::vector<webkit::WebPluginMimeType>& plugin_mime_types = | 392 const std::vector<webkit::WebPluginMimeType>& plugin_mime_types = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 397 PluginPrefs::PolicyStatus plugin_status = | 417 PluginPrefs::PolicyStatus plugin_status = |
| 398 plugin_prefs->PolicyStatusForPlugin(group_plugin.name); | 418 plugin_prefs->PolicyStatusForPlugin(group_plugin.name); |
| 399 PluginPrefs::PolicyStatus group_status = | 419 PluginPrefs::PolicyStatus group_status = |
| 400 plugin_prefs->PolicyStatusForPlugin(group_name); | 420 plugin_prefs->PolicyStatusForPlugin(group_name); |
| 401 if (plugin_status == PluginPrefs::POLICY_ENABLED || | 421 if (plugin_status == PluginPrefs::POLICY_ENABLED || |
| 402 group_status == PluginPrefs::POLICY_ENABLED) { | 422 group_status == PluginPrefs::POLICY_ENABLED) { |
| 403 enabled_mode = "enabledByPolicy"; | 423 enabled_mode = "enabledByPolicy"; |
| 404 } else { | 424 } else { |
| 405 all_plugins_enabled_by_policy = false; | 425 all_plugins_enabled_by_policy = false; |
| 406 if (plugin_status == PluginPrefs::POLICY_DISABLED || | 426 if (plugin_status == PluginPrefs::POLICY_DISABLED || |
| 407 group_status == PluginPrefs::POLICY_DISABLED) { | 427 group_status == PluginPrefs::POLICY_DISABLED) { |
| 408 enabled_mode = "disabledByPolicy"; | 428 enabled_mode = "disabledByPolicy"; |
| 409 } else { | 429 } else { |
| 410 all_plugins_disabled_by_policy = false; | 430 all_plugins_disabled_by_policy = false; |
| 411 if (plugin_enabled) { | 431 if (plugin_enabled) { |
| 412 enabled_mode = "enabledByUser"; | 432 enabled_mode = "enabledByUser"; |
| 413 } else { | 433 } else { |
| 414 enabled_mode = "disabledByUser"; | 434 enabled_mode = "disabledByUser"; |
| 415 } | 435 } |
| 416 } | 436 } |
| 417 } | 437 } |
| 418 plugin_file->SetString("enabledMode", enabled_mode); | 438 plugin_file->SetString("enabledMode", enabled_mode); |
| 419 | 439 |
| 420 plugin_files->Append(plugin_file); | 440 plugin_files->Append(plugin_file); |
| 421 } | 441 } |
| 422 DictionaryValue* group_data = new DictionaryValue(); | 442 DictionaryValue* group_data = new DictionaryValue(); |
| 423 | 443 |
| 424 group_data->Set("plugin_files", plugin_files); | 444 group_data->Set("plugin_files", plugin_files); |
| 425 group_data->SetString("name", group_name); | 445 group_data->SetString("name", group_name); |
| 426 group_data->SetString("id", group.identifier()); | 446 group_data->SetString("id", group_identifier); |
| 427 group_data->SetString("description", active_plugin->desc); | 447 group_data->SetString("description", active_plugin->desc); |
| 428 group_data->SetString("version", active_plugin->version); | 448 group_data->SetString("version", active_plugin->version); |
| 429 | 449 |
| 430 #if defined(ENABLE_PLUGIN_INSTALLATION) | 450 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 431 PluginInstaller* installer = | 451 PluginInstaller* installer = |
| 432 plugin_finder->FindPluginWithIdentifier(group.identifier()); | 452 plugin_finder->FindPluginWithIdentifier(group_identifier); |
| 433 if (installer) { | 453 if (installer) { |
| 434 bool out_of_date = installer->GetSecurityStatus(*active_plugin) == | 454 bool out_of_date = installer->GetSecurityStatus(*active_plugin) == |
| 435 PluginInstaller::SECURITY_STATUS_OUT_OF_DATE; | 455 PluginInstaller::SECURITY_STATUS_OUT_OF_DATE; |
| 436 group_data->SetBoolean("critical", out_of_date); | 456 group_data->SetBoolean("critical", out_of_date); |
| 437 group_data->SetString("update_url", installer->plugin_url().spec()); | 457 group_data->SetString("update_url", installer->plugin_url().spec()); |
| 438 } | 458 } |
| 439 #endif | 459 #endif |
| 440 | 460 |
| 441 std::string enabled_mode; | 461 std::string enabled_mode; |
| 442 if (all_plugins_enabled_by_policy) { | 462 if (all_plugins_enabled_by_policy) { |
| 443 enabled_mode = "enabledByPolicy"; | 463 enabled_mode = "enabledByPolicy"; |
| 444 } else if (all_plugins_disabled_by_policy) { | 464 } else if (all_plugins_disabled_by_policy) { |
| 445 enabled_mode = "disabledByPolicy"; | 465 enabled_mode = "disabledByPolicy"; |
| 446 } else if (group_enabled) { | 466 } else if (group_enabled) { |
| 447 enabled_mode = "enabledByUser"; | 467 enabled_mode = "enabledByUser"; |
| 448 } else { | 468 } else { |
| 449 enabled_mode = "disabledByUser"; | 469 enabled_mode = "disabledByUser"; |
| 450 } | 470 } |
| 451 group_data->SetString("enabledMode", enabled_mode); | 471 group_data->SetString("enabledMode", enabled_mode); |
| 452 | 472 |
| 453 bool always_allowed = false; | 473 bool always_allowed = false; |
| 454 if (group_enabled) { | 474 if (group_enabled) { |
| 455 const DictionaryValue* whitelist = profile->GetPrefs()->GetDictionary( | 475 const DictionaryValue* whitelist = profile->GetPrefs()->GetDictionary( |
| 456 prefs::kContentSettingsPluginWhitelist); | 476 prefs::kContentSettingsPluginWhitelist); |
| 457 whitelist->GetBoolean(group.identifier(), &always_allowed); | 477 whitelist->GetBoolean(group_identifier, &always_allowed); |
| 458 } | 478 } |
| 459 group_data->SetBoolean("alwaysAllowed", always_allowed); | 479 group_data->SetBoolean("alwaysAllowed", always_allowed); |
| 460 | 480 |
| 461 plugin_groups_data->Append(group_data); | 481 plugin_groups_data->Append(group_data); |
| 462 } | 482 } |
| 483 |
| 463 DictionaryValue results; | 484 DictionaryValue results; |
| 464 results.Set("plugins", plugin_groups_data); | 485 results.Set("plugins", plugin_groups_data); |
| 465 web_ui()->CallJavascriptFunction("returnPluginsData", results); | 486 web_ui()->CallJavascriptFunction("returnPluginsData", results); |
| 466 } | 487 } |
| 467 | 488 |
| 468 } // namespace | 489 } // namespace |
| 469 | 490 |
| 470 /////////////////////////////////////////////////////////////////////////////// | 491 /////////////////////////////////////////////////////////////////////////////// |
| 471 // | 492 // |
| 472 // PluginsUI | 493 // PluginsUI |
| (...skipping 18 matching lines...) Expand all Loading... |
| 491 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { | 512 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { |
| 492 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, | 513 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, |
| 493 false, | 514 false, |
| 494 PrefService::UNSYNCABLE_PREF); | 515 PrefService::UNSYNCABLE_PREF); |
| 495 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, | 516 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, |
| 496 true, | 517 true, |
| 497 PrefService::UNSYNCABLE_PREF); | 518 PrefService::UNSYNCABLE_PREF); |
| 498 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, | 519 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, |
| 499 PrefService::SYNCABLE_PREF); | 520 PrefService::SYNCABLE_PREF); |
| 500 } | 521 } |
| OLD | NEW |