| 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 26 matching lines...) Expand all Loading... |
| 37 #include "content/public/browser/web_ui.h" | 37 #include "content/public/browser/web_ui.h" |
| 38 #include "content/public/browser/web_ui_message_handler.h" | 38 #include "content/public/browser/web_ui_message_handler.h" |
| 39 #include "grit/browser_resources.h" | 39 #include "grit/browser_resources.h" |
| 40 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
| 41 #include "grit/theme_resources.h" | 41 #include "grit/theme_resources.h" |
| 42 #include "grit/theme_resources_standard.h" | 42 #include "grit/theme_resources_standard.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
| 45 #include "webkit/plugins/npapi/plugin_group.h" | 45 #include "webkit/plugins/npapi/plugin_group.h" |
| 46 | 46 |
| 47 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 48 #include "chrome/browser/plugin_finder.h" |
| 49 #include "chrome/browser/plugin_installer.h" |
| 50 #else |
| 51 // Forward-declare PluginFinder. It's never actually used, but we pass a NULL |
| 52 // pointer instead. |
| 53 class PluginFinder; |
| 54 #endif |
| 55 |
| 47 using content::PluginService; | 56 using content::PluginService; |
| 48 using content::WebContents; | 57 using content::WebContents; |
| 49 using content::WebUIMessageHandler; | 58 using content::WebUIMessageHandler; |
| 50 using webkit::npapi::PluginGroup; | 59 using webkit::npapi::PluginGroup; |
| 51 using webkit::WebPluginInfo; | 60 using webkit::WebPluginInfo; |
| 52 | 61 |
| 53 namespace { | 62 namespace { |
| 54 | 63 |
| 55 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() { | 64 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() { |
| 56 ChromeWebUIDataSource* source = | 65 ChromeWebUIDataSource* source = |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // Callback for the "setPluginAlwaysAllowed" message. | 151 // Callback for the "setPluginAlwaysAllowed" message. |
| 143 void HandleSetPluginAlwaysAllowed(const ListValue* args); | 152 void HandleSetPluginAlwaysAllowed(const ListValue* args); |
| 144 | 153 |
| 145 // content::NotificationObserver method overrides | 154 // content::NotificationObserver method overrides |
| 146 virtual void Observe(int type, | 155 virtual void Observe(int type, |
| 147 const content::NotificationSource& source, | 156 const content::NotificationSource& source, |
| 148 const content::NotificationDetails& details) OVERRIDE; | 157 const content::NotificationDetails& details) OVERRIDE; |
| 149 | 158 |
| 150 private: | 159 private: |
| 151 // Call this to start getting the plugins on the UI thread. | 160 // Call this to start getting the plugins on the UI thread. |
| 152 void LoadPlugins(); | 161 void GetPluginFinder(); |
| 162 |
| 163 // Called when we have a PluginFinder and need to load the list of plug-ins. |
| 164 void LoadPlugins(PluginFinder* plugin_finder); |
| 153 | 165 |
| 154 // Called on the UI thread when the plugin information is ready. | 166 // Called on the UI thread when the plugin information is ready. |
| 155 void PluginsLoaded(const std::vector<PluginGroup>& groups); | 167 void PluginsLoaded(PluginFinder* plugin_finder, |
| 168 const std::vector<PluginGroup>& groups); |
| 156 | 169 |
| 157 content::NotificationRegistrar registrar_; | 170 content::NotificationRegistrar registrar_; |
| 158 | 171 |
| 159 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_; | 172 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_; |
| 160 | 173 |
| 161 // This pref guards the value whether about:plugins is in the details mode or | 174 // This pref guards the value whether about:plugins is in the details mode or |
| 162 // not. | 175 // not. |
| 163 BooleanPrefMember show_details_; | 176 BooleanPrefMember show_details_; |
| 164 | 177 |
| 165 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); | 178 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 190 base::Unretained(this))); | 203 base::Unretained(this))); |
| 191 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs", | 204 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs", |
| 192 base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs, | 205 base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs, |
| 193 base::Unretained(this))); | 206 base::Unretained(this))); |
| 194 web_ui()->RegisterMessageCallback("getShowDetails", | 207 web_ui()->RegisterMessageCallback("getShowDetails", |
| 195 base::Bind(&PluginsDOMHandler::HandleGetShowDetails, | 208 base::Bind(&PluginsDOMHandler::HandleGetShowDetails, |
| 196 base::Unretained(this))); | 209 base::Unretained(this))); |
| 197 } | 210 } |
| 198 | 211 |
| 199 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { | 212 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { |
| 200 LoadPlugins(); | 213 GetPluginFinder(); |
| 201 } | 214 } |
| 202 | 215 |
| 203 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { | 216 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { |
| 204 Profile* profile = Profile::FromWebUI(web_ui()); | 217 Profile* profile = Profile::FromWebUI(web_ui()); |
| 205 | 218 |
| 206 // Be robust in accepting badness since plug-ins display HTML (hence | 219 // Be robust in accepting badness since plug-ins display HTML (hence |
| 207 // JavaScript). | 220 // JavaScript). |
| 208 if (args->GetSize() != 3) { | 221 if (args->GetSize() != 3) { |
| 209 NOTREACHED(); | 222 NOTREACHED(); |
| 210 return; | 223 return; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 // whitelisted by the user from automatically whitelisted ones. | 301 // whitelisted by the user from automatically whitelisted ones. |
| 289 DictionaryPrefUpdate update(profile->GetPrefs(), | 302 DictionaryPrefUpdate update(profile->GetPrefs(), |
| 290 prefs::kContentSettingsPluginWhitelist); | 303 prefs::kContentSettingsPluginWhitelist); |
| 291 update->SetBoolean(plugin, allowed); | 304 update->SetBoolean(plugin, allowed); |
| 292 } | 305 } |
| 293 | 306 |
| 294 void PluginsDOMHandler::Observe(int type, | 307 void PluginsDOMHandler::Observe(int type, |
| 295 const content::NotificationSource& source, | 308 const content::NotificationSource& source, |
| 296 const content::NotificationDetails& details) { | 309 const content::NotificationDetails& details) { |
| 297 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); | 310 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); |
| 298 LoadPlugins(); | 311 GetPluginFinder(); |
| 299 } | 312 } |
| 300 | 313 |
| 301 void PluginsDOMHandler::LoadPlugins() { | 314 void PluginsDOMHandler::GetPluginFinder() { |
| 302 if (weak_ptr_factory_.HasWeakPtrs()) | 315 if (weak_ptr_factory_.HasWeakPtrs()) |
| 303 return; | 316 return; |
| 304 | 317 |
| 318 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 319 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins, |
| 320 weak_ptr_factory_.GetWeakPtr())); |
| 321 #else |
| 322 LoadPlugins(NULL); |
| 323 #endif |
| 324 } |
| 325 |
| 326 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) { |
| 305 PluginService::GetInstance()->GetPluginGroups( | 327 PluginService::GetInstance()->GetPluginGroups( |
| 306 base::Bind(&PluginsDOMHandler::PluginsLoaded, | 328 base::Bind(&PluginsDOMHandler::PluginsLoaded, |
| 307 weak_ptr_factory_.GetWeakPtr())); | 329 weak_ptr_factory_.GetWeakPtr(), plugin_finder)); |
| 308 } | 330 } |
| 309 | 331 |
| 310 void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>& groups) { | 332 void PluginsDOMHandler::PluginsLoaded(PluginFinder* plugin_finder, |
| 333 const std::vector<PluginGroup>& groups) { |
| 311 Profile* profile = Profile::FromWebUI(web_ui()); | 334 Profile* profile = Profile::FromWebUI(web_ui()); |
| 312 PluginPrefs* plugin_prefs = | 335 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
| 313 PluginPrefs::GetForProfile(profile); | |
| 314 | 336 |
| 315 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 337 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
| 316 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | 338 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
| 317 | 339 |
| 318 // Construct DictionaryValues to return to the UI | 340 // Construct DictionaryValues to return to the UI |
| 319 ListValue* plugin_groups_data = new ListValue(); | 341 ListValue* plugin_groups_data = new ListValue(); |
| 320 for (size_t i = 0; i < groups.size(); ++i) { | 342 for (size_t i = 0; i < groups.size(); ++i) { |
| 321 const PluginGroup& group = groups[i]; | 343 const PluginGroup& group = groups[i]; |
| 322 if (group.IsEmpty()) | 344 if (group.IsEmpty()) |
| 323 continue; | 345 continue; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 plugin_files->Append(plugin_file); | 411 plugin_files->Append(plugin_file); |
| 390 } | 412 } |
| 391 DictionaryValue* group_data = new DictionaryValue(); | 413 DictionaryValue* group_data = new DictionaryValue(); |
| 392 | 414 |
| 393 group_data->Set("plugin_files", plugin_files); | 415 group_data->Set("plugin_files", plugin_files); |
| 394 group_data->SetString("name", group_name); | 416 group_data->SetString("name", group_name); |
| 395 group_data->SetString("id", group.identifier()); | 417 group_data->SetString("id", group.identifier()); |
| 396 group_data->SetString("description", active_plugin->desc); | 418 group_data->SetString("description", active_plugin->desc); |
| 397 group_data->SetString("version", active_plugin->version); | 419 group_data->SetString("version", active_plugin->version); |
| 398 group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin)); | 420 group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin)); |
| 399 group_data->SetString("update_url", group.GetUpdateURL()); | 421 |
| 422 std::string update_url; |
| 423 #if defined(ENABLE_PLUGIN_INSTALLATION) |
| 424 PluginInstaller* installer = |
| 425 plugin_finder->FindPluginWithIdentifier(group.identifier()); |
| 426 if (installer) |
| 427 update_url = installer->plugin_url().spec(); |
| 428 #endif |
| 429 group_data->SetString("update_url", update_url); |
| 400 | 430 |
| 401 std::string enabled_mode; | 431 std::string enabled_mode; |
| 402 if (all_plugins_enabled_by_policy) { | 432 if (all_plugins_enabled_by_policy) { |
| 403 enabled_mode = "enabledByPolicy"; | 433 enabled_mode = "enabledByPolicy"; |
| 404 } else if (all_plugins_disabled_by_policy) { | 434 } else if (all_plugins_disabled_by_policy) { |
| 405 enabled_mode = "disabledByPolicy"; | 435 enabled_mode = "disabledByPolicy"; |
| 406 } else if (group_enabled) { | 436 } else if (group_enabled) { |
| 407 enabled_mode = "enabledByUser"; | 437 enabled_mode = "enabledByUser"; |
| 408 } else { | 438 } else { |
| 409 enabled_mode = "disabledByUser"; | 439 enabled_mode = "disabledByUser"; |
| 410 } | 440 } |
| 411 group_data->SetString("enabledMode", enabled_mode); | 441 group_data->SetString("enabledMode", enabled_mode); |
| 412 | 442 |
| 413 // TODO(bauerb): We should have a method on HostContentSettinsMap for this. | 443 // TODO(bauerb): We should have a method on HostContentSettingsMap for this. |
| 414 bool always_allowed = false; | 444 bool always_allowed = false; |
| 415 ContentSettingsForOneType settings; | 445 ContentSettingsForOneType settings; |
| 416 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, | 446 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 417 group.identifier(), &settings); | 447 group.identifier(), &settings); |
| 418 for (ContentSettingsForOneType::const_iterator it = settings.begin(); | 448 for (ContentSettingsForOneType::const_iterator it = settings.begin(); |
| 419 it != settings.end(); ++it) { | 449 it != settings.end(); ++it) { |
| 420 if (it->primary_pattern == wildcard && | 450 if (it->primary_pattern == wildcard && |
| 421 it->secondary_pattern == wildcard && | 451 it->secondary_pattern == wildcard && |
| 422 it->setting == CONTENT_SETTING_ALLOW) { | 452 it->setting == CONTENT_SETTING_ALLOW) { |
| 423 always_allowed = true; | 453 always_allowed = true; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { | 490 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { |
| 461 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, | 491 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, |
| 462 false, | 492 false, |
| 463 PrefService::UNSYNCABLE_PREF); | 493 PrefService::UNSYNCABLE_PREF); |
| 464 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, | 494 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, |
| 465 true, | 495 true, |
| 466 PrefService::UNSYNCABLE_PREF); | 496 PrefService::UNSYNCABLE_PREF); |
| 467 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, | 497 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, |
| 468 PrefService::SYNCABLE_PREF); | 498 PrefService::SYNCABLE_PREF); |
| 469 } | 499 } |
| OLD | NEW |