Index: chrome/browser/ui/webui/plugins_ui.cc |
diff --git a/chrome/browser/ui/webui/plugins_ui.cc b/chrome/browser/ui/webui/plugins_ui.cc |
index f2e8126290ed617dee816ffabba69f12fac98021..c6c7245b11d0857e8315ce181280bc6835706c9a 100644 |
--- a/chrome/browser/ui/webui/plugins_ui.cc |
+++ b/chrome/browser/ui/webui/plugins_ui.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -16,7 +16,9 @@ |
#include "base/path_service.h" |
#include "base/utf_string_conversions.h" |
#include "base/values.h" |
+#include "chrome/browser/content_settings/host_content_settings_map.h" |
#include "chrome/browser/plugin_prefs.h" |
+#include "chrome/browser/prefs/scoped_user_pref_update.h" |
#include "chrome/browser/prefs/pref_member.h" |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -79,6 +81,7 @@ ChromeWebUIDataSource* CreatePluginsUIHTMLSource() { |
IDS_PLUGINS_MIME_TYPES_FILE_EXTENSIONS); |
source->AddLocalizedString("disable", IDS_PLUGINS_DISABLE); |
source->AddLocalizedString("enable", IDS_PLUGINS_ENABLE); |
+ source->AddLocalizedString("alwaysAllowed", IDS_EXCEPTIONS_ALLOW_BUTTON); |
source->AddLocalizedString("noPlugins", IDS_PLUGINS_NO_PLUGINS); |
source->set_json_path("strings.js"); |
@@ -136,6 +139,9 @@ class PluginsDOMHandler : public WebUIMessageHandler, |
// Calback for the "getShowDetails" message. |
void HandleGetShowDetails(const ListValue* args); |
+ // Callback for the "setPluginAlwaysAllowed" message. |
+ void HandleSetPluginAlwaysAllowed(const ListValue* args); |
+ |
// content::NotificationObserver method overrides |
virtual void Observe(int type, |
const content::NotificationSource& source, |
@@ -179,6 +185,9 @@ void PluginsDOMHandler::RegisterMessages() { |
web_ui()->RegisterMessageCallback("enablePlugin", |
base::Bind(&PluginsDOMHandler::HandleEnablePluginMessage, |
base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback("setPluginAlwaysAllowed", |
+ base::Bind(&PluginsDOMHandler::HandleSetPluginAlwaysAllowed, |
+ base::Unretained(this))); |
web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs", |
base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs, |
base::Unretained(this))); |
@@ -196,20 +205,26 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { |
// Be robust in accepting badness since plug-ins display HTML (hence |
// JavaScript). |
- if (args->GetSize() != 3) |
+ if (args->GetSize() != 3) { |
+ NOTREACHED(); |
return; |
+ } |
std::string enable_str; |
std::string is_group_str; |
- if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) |
+ if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) { |
+ NOTREACHED(); |
return; |
+ } |
bool enable = enable_str == "true"; |
PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
if (is_group_str == "true") { |
string16 group_name; |
- if (!args->GetString(0, &group_name)) |
+ if (!args->GetString(0, &group_name)) { |
+ NOTREACHED(); |
return; |
+ } |
plugin_prefs->EnablePluginGroup(enable, group_name); |
if (enable) { |
@@ -225,8 +240,10 @@ void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { |
} |
} else { |
FilePath::StringType file_path; |
- if (!args->GetString(0, &file_path)) |
+ if (!args->GetString(0, &file_path)) { |
+ NOTREACHED(); |
return; |
+ } |
bool result = plugin_prefs->EnablePlugin(enable, FilePath(file_path)); |
DCHECK(result); |
} |
@@ -246,6 +263,34 @@ void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) { |
web_ui()->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); |
} |
+void PluginsDOMHandler::HandleSetPluginAlwaysAllowed(const ListValue* args) { |
+ // Be robust in the input parameters, but crash in a Debug build. |
+ if (args->GetSize() != 2) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ std::string plugin; |
+ bool allowed = false; |
+ if (!args->GetString(0, &plugin) || !args->GetBoolean(1, &allowed)) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
+ profile->GetHostContentSettingsMap()->SetContentSetting( |
+ ContentSettingsPattern::Wildcard(), |
+ ContentSettingsPattern::Wildcard(), |
+ CONTENT_SETTINGS_TYPE_PLUGINS, |
+ plugin, |
+ allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_DEFAULT); |
+ |
+ // Keep track of the whitelist separately, so that we can distinguish plug-ins |
+ // whitelisted by the user from automatically whitelisted ones. |
+ DictionaryPrefUpdate update(profile->GetPrefs(), |
+ prefs::kContentSettingsPluginWhitelist); |
+ update->SetBoolean(plugin, allowed); |
+} |
+ |
void PluginsDOMHandler::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
@@ -263,8 +308,12 @@ void PluginsDOMHandler::LoadPlugins() { |
} |
void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>& groups) { |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
PluginPrefs* plugin_prefs = |
- PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())); |
+ PluginPrefs::GetForProfile(profile); |
+ |
+ HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
+ ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
// Construct DictionaryValues to return to the UI |
ListValue* plugin_groups_data = new ListValue(); |
@@ -343,6 +392,7 @@ void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>& groups) { |
group_data->Set("plugin_files", plugin_files); |
group_data->SetString("name", group_name); |
+ group_data->SetString("id", group.identifier()); |
group_data->SetString("description", active_plugin->desc); |
group_data->SetString("version", active_plugin->version); |
group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin)); |
@@ -360,6 +410,22 @@ void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>& groups) { |
} |
group_data->SetString("enabledMode", enabled_mode); |
+ // TODO(bauerb): We should have a method on HostContentSettinsMap for this. |
+ bool always_allowed = false; |
+ ContentSettingsForOneType settings; |
+ map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, |
+ group.identifier(), &settings); |
+ for (ContentSettingsForOneType::const_iterator it = settings.begin(); |
+ it != settings.end(); ++it) { |
+ if (it->primary_pattern == wildcard && |
+ it->secondary_pattern == wildcard && |
+ it->setting == CONTENT_SETTING_ALLOW) { |
+ always_allowed = true; |
+ break; |
+ } |
+ } |
+ group_data->SetBoolean("alwaysAllowed", always_allowed); |
+ |
plugin_groups_data->Append(group_data); |
} |
DictionaryValue results; |
@@ -384,7 +450,6 @@ PluginsUI::PluginsUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
CreatePluginsUIHTMLSource()); |
} |
- |
// static |
RefCountedMemory* PluginsUI::GetFaviconResourceBytes() { |
return ResourceBundle::GetSharedInstance(). |
@@ -399,4 +464,6 @@ void PluginsUI::RegisterUserPrefs(PrefService* prefs) { |
prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, |
true, |
PrefService::UNSYNCABLE_PREF); |
+ prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, |
+ PrefService::SYNCABLE_PREF); |
} |