| 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/options/content_settings_handler.h" | 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 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/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/content_settings/content_settings_details.h" | 20 #include "chrome/browser/content_settings/content_settings_details.h" |
| 21 #include "chrome/browser/content_settings/content_settings_provider.h" | 21 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 22 #include "chrome/browser/content_settings/content_settings_utils.h" | 22 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 23 #include "chrome/browser/content_settings/host_content_settings_map.h" | 23 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 24 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 24 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 25 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 25 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 26 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 26 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 27 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 27 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
| 30 #include "chrome/common/chrome_content_settings_client.h" |
| 30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/content_settings.h" | 32 #include "chrome/common/content_settings.h" |
| 32 #include "chrome/common/content_settings_pattern.h" | 33 #include "chrome/common/content_settings_pattern.h" |
| 33 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 34 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
| 36 #include "components/google/core/browser/google_util.h" | 37 #include "components/google/core/browser/google_util.h" |
| 37 #include "components/user_prefs/user_prefs.h" | 38 #include "components/user_prefs/user_prefs.h" |
| 38 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
| 39 #include "content/public/browser/notification_source.h" | 40 #include "content/public/browser/notification_source.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 171 |
| 171 // Create a DictionaryValue* that will act as a data source for a single row | 172 // Create a DictionaryValue* that will act as a data source for a single row |
| 172 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). | 173 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). |
| 173 // Ownership of the pointer is passed to the caller. | 174 // Ownership of the pointer is passed to the caller. |
| 174 base::DictionaryValue* GetExceptionForPage( | 175 base::DictionaryValue* GetExceptionForPage( |
| 175 const ContentSettingsPattern& pattern, | 176 const ContentSettingsPattern& pattern, |
| 176 const ContentSettingsPattern& secondary_pattern, | 177 const ContentSettingsPattern& secondary_pattern, |
| 177 const ContentSetting& setting, | 178 const ContentSetting& setting, |
| 178 const std::string& provider_name) { | 179 const std::string& provider_name) { |
| 179 base::DictionaryValue* exception = new base::DictionaryValue(); | 180 base::DictionaryValue* exception = new base::DictionaryValue(); |
| 180 exception->SetString(kOrigin, pattern.ToString()); | 181 content_settings::ChromeContentSettingsClient client; |
| 182 exception->SetString(kOrigin, pattern.ToString(&client)); |
| 181 exception->SetString(kEmbeddingOrigin, | 183 exception->SetString(kEmbeddingOrigin, |
| 182 secondary_pattern == ContentSettingsPattern::Wildcard() ? | 184 secondary_pattern == ContentSettingsPattern::Wildcard() ? |
| 183 std::string() : | 185 std::string() : |
| 184 secondary_pattern.ToString()); | 186 secondary_pattern.ToString(&client)); |
| 185 exception->SetString(kSetting, ContentSettingToString(setting)); | 187 exception->SetString(kSetting, ContentSettingToString(setting)); |
| 186 exception->SetString(kSource, provider_name); | 188 exception->SetString(kSource, provider_name); |
| 187 return exception; | 189 return exception; |
| 188 } | 190 } |
| 189 | 191 |
| 190 // Create a DictionaryValue* that will act as a data source for a single row | 192 // Create a DictionaryValue* that will act as a data source for a single row |
| 191 // in the Geolocation exceptions table. Ownership of the pointer is passed to | 193 // in the Geolocation exceptions table. Ownership of the pointer is passed to |
| 192 // the caller. | 194 // the caller. |
| 193 base::DictionaryValue* GetGeolocationExceptionForPage( | 195 base::DictionaryValue* GetGeolocationExceptionForPage( |
| 194 const ContentSettingsPattern& origin, | 196 const ContentSettingsPattern& origin, |
| 195 const ContentSettingsPattern& embedding_origin, | 197 const ContentSettingsPattern& embedding_origin, |
| 196 ContentSetting setting) { | 198 ContentSetting setting) { |
| 197 base::DictionaryValue* exception = new base::DictionaryValue(); | 199 base::DictionaryValue* exception = new base::DictionaryValue(); |
| 200 content_settings::ChromeContentSettingsClient client; |
| 198 exception->SetString(kSetting, ContentSettingToString(setting)); | 201 exception->SetString(kSetting, ContentSettingToString(setting)); |
| 199 exception->SetString(kOrigin, origin.ToString()); | 202 exception->SetString(kOrigin, origin.ToString(&client)); |
| 200 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString()); | 203 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString(&client)); |
| 201 return exception; | 204 return exception; |
| 202 } | 205 } |
| 203 | 206 |
| 204 // Create a DictionaryValue* that will act as a data source for a single row | 207 // Create a DictionaryValue* that will act as a data source for a single row |
| 205 // in the desktop notifications exceptions table. Ownership of the pointer is | 208 // in the desktop notifications exceptions table. Ownership of the pointer is |
| 206 // passed to the caller. | 209 // passed to the caller. |
| 207 base::DictionaryValue* GetNotificationExceptionForPage( | 210 base::DictionaryValue* GetNotificationExceptionForPage( |
| 208 const ContentSettingsPattern& pattern, | 211 const ContentSettingsPattern& pattern, |
| 209 ContentSetting setting, | 212 ContentSetting setting, |
| 210 const std::string& provider_name) { | 213 const std::string& provider_name) { |
| 211 base::DictionaryValue* exception = new base::DictionaryValue(); | 214 base::DictionaryValue* exception = new base::DictionaryValue(); |
| 215 content_settings::ChromeContentSettingsClient client; |
| 212 exception->SetString(kSetting, ContentSettingToString(setting)); | 216 exception->SetString(kSetting, ContentSettingToString(setting)); |
| 213 exception->SetString(kOrigin, pattern.ToString()); | 217 exception->SetString(kOrigin, pattern.ToString(&client)); |
| 214 exception->SetString(kSource, provider_name); | 218 exception->SetString(kSource, provider_name); |
| 215 return exception; | 219 return exception; |
| 216 } | 220 } |
| 217 | 221 |
| 218 // Returns true whenever the |extension| is hosted and has |permission|. | 222 // Returns true whenever the |extension| is hosted and has |permission|. |
| 219 // Must have the AppFilter signature. | 223 // Must have the AppFilter signature. |
| 220 template <APIPermission::ID permission> | 224 template <APIPermission::ID permission> |
| 221 bool HostedAppHasPermission(const extensions::Extension& extension, | 225 bool HostedAppHasPermission(const extensions::Extension& extension, |
| 222 content::BrowserContext* /* context */) { | 226 content::BrowserContext* /* context */) { |
| 223 return extension.is_hosted_app() && | 227 return extension.is_hosted_app() && |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 base::DictionaryValue* media_dict = NULL; | 962 base::DictionaryValue* media_dict = NULL; |
| 959 bool result = (*media_entry)->GetAsDictionary(&media_dict); | 963 bool result = (*media_entry)->GetAsDictionary(&media_dict); |
| 960 DCHECK(result); | 964 DCHECK(result); |
| 961 | 965 |
| 962 std::string origin; | 966 std::string origin; |
| 963 std::string audio_setting; | 967 std::string audio_setting; |
| 964 std::string video_setting; | 968 std::string video_setting; |
| 965 media_dict->GetString(kOrigin, &origin); | 969 media_dict->GetString(kOrigin, &origin); |
| 966 media_dict->GetString(kSetting, &audio_setting); | 970 media_dict->GetString(kSetting, &audio_setting); |
| 967 media_dict->GetString(kVideoSetting, &video_setting); | 971 media_dict->GetString(kVideoSetting, &video_setting); |
| 972 content_settings::ChromeContentSettingsClient client; |
| 968 media_settings_.exceptions.push_back(MediaException( | 973 media_settings_.exceptions.push_back(MediaException( |
| 969 ContentSettingsPattern::FromString(origin), | 974 ContentSettingsPattern::FromString(&client, origin), |
| 970 ContentSettingFromString(audio_setting), | 975 ContentSettingFromString(audio_setting), |
| 971 ContentSettingFromString(video_setting))); | 976 ContentSettingFromString(video_setting))); |
| 972 } | 977 } |
| 973 PepperFlashContentSettingsUtils::SortMediaExceptions( | 978 PepperFlashContentSettingsUtils::SortMediaExceptions( |
| 974 &media_settings_.exceptions); | 979 &media_settings_.exceptions); |
| 975 media_settings_.exceptions_initialized = true; | 980 media_settings_.exceptions_initialized = true; |
| 976 UpdateFlashMediaLinksVisibility(); | 981 UpdateFlashMediaLinksVisibility(); |
| 977 | 982 |
| 978 base::StringValue type_string( | 983 base::StringValue type_string( |
| 979 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_MEDIASTREAM)); | 984 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_MEDIASTREAM)); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 std::string origin; | 1176 std::string origin; |
| 1172 std::string setting; | 1177 std::string setting; |
| 1173 bool rv = args->GetString(1, &origin); | 1178 bool rv = args->GetString(1, &origin); |
| 1174 DCHECK(rv); | 1179 DCHECK(rv); |
| 1175 rv = args->GetString(2, &setting); | 1180 rv = args->GetString(2, &setting); |
| 1176 DCHECK(rv); | 1181 DCHECK(rv); |
| 1177 ContentSetting content_setting = ContentSettingFromString(setting); | 1182 ContentSetting content_setting = ContentSettingFromString(setting); |
| 1178 | 1183 |
| 1179 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 1184 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
| 1180 content_setting == CONTENT_SETTING_BLOCK); | 1185 content_setting == CONTENT_SETTING_BLOCK); |
| 1186 content_settings::ChromeContentSettingsClient client; |
| 1181 DesktopNotificationProfileUtil::ClearSetting(profile, | 1187 DesktopNotificationProfileUtil::ClearSetting(profile, |
| 1182 ContentSettingsPattern::FromString(origin)); | 1188 ContentSettingsPattern::FromString(&client, origin)); |
| 1183 } | 1189 } |
| 1184 | 1190 |
| 1185 void ContentSettingsHandler::RemoveMediaException(const base::ListValue* args) { | 1191 void ContentSettingsHandler::RemoveMediaException(const base::ListValue* args) { |
| 1186 std::string mode; | 1192 std::string mode; |
| 1187 bool rv = args->GetString(1, &mode); | 1193 bool rv = args->GetString(1, &mode); |
| 1188 DCHECK(rv); | 1194 DCHECK(rv); |
| 1189 | 1195 |
| 1190 std::string pattern; | 1196 std::string pattern; |
| 1191 rv = args->GetString(2, &pattern); | 1197 rv = args->GetString(2, &pattern); |
| 1192 DCHECK(rv); | 1198 DCHECK(rv); |
| 1193 | 1199 |
| 1194 HostContentSettingsMap* settings_map = | 1200 HostContentSettingsMap* settings_map = |
| 1195 mode == "normal" ? GetContentSettingsMap() : | 1201 mode == "normal" ? GetContentSettingsMap() : |
| 1196 GetOTRContentSettingsMap(); | 1202 GetOTRContentSettingsMap(); |
| 1197 if (settings_map) { | 1203 if (settings_map) { |
| 1198 settings_map->SetWebsiteSetting(ContentSettingsPattern::FromString(pattern), | 1204 content_settings::ChromeContentSettingsClient client; |
| 1205 settings_map->SetWebsiteSetting(ContentSettingsPattern::FromString(&client, |
| 1206 pattern), |
| 1199 ContentSettingsPattern::Wildcard(), | 1207 ContentSettingsPattern::Wildcard(), |
| 1200 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 1208 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 1201 std::string(), | 1209 std::string(), |
| 1202 NULL); | 1210 NULL); |
| 1203 settings_map->SetWebsiteSetting(ContentSettingsPattern::FromString(pattern), | 1211 settings_map->SetWebsiteSetting(ContentSettingsPattern::FromString(&client, |
| 1212 pattern), |
| 1204 ContentSettingsPattern::Wildcard(), | 1213 ContentSettingsPattern::Wildcard(), |
| 1205 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 1214 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 1206 std::string(), | 1215 std::string(), |
| 1207 NULL); | 1216 NULL); |
| 1208 } | 1217 } |
| 1209 } | 1218 } |
| 1210 | 1219 |
| 1211 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( | 1220 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( |
| 1212 const base::ListValue* args, | 1221 const base::ListValue* args, |
| 1213 ContentSettingsType type) { | 1222 ContentSettingsType type) { |
| 1214 std::string mode; | 1223 std::string mode; |
| 1215 bool rv = args->GetString(1, &mode); | 1224 bool rv = args->GetString(1, &mode); |
| 1216 DCHECK(rv); | 1225 DCHECK(rv); |
| 1217 | 1226 |
| 1218 std::string pattern; | 1227 std::string pattern; |
| 1219 rv = args->GetString(2, &pattern); | 1228 rv = args->GetString(2, &pattern); |
| 1220 DCHECK(rv); | 1229 DCHECK(rv); |
| 1221 | 1230 |
| 1222 // The fourth argument to this handler is optional. | 1231 // The fourth argument to this handler is optional. |
| 1223 std::string secondary_pattern; | 1232 std::string secondary_pattern; |
| 1224 if (args->GetSize() >= 4U) { | 1233 if (args->GetSize() >= 4U) { |
| 1225 rv = args->GetString(3, &secondary_pattern); | 1234 rv = args->GetString(3, &secondary_pattern); |
| 1226 DCHECK(rv); | 1235 DCHECK(rv); |
| 1227 } | 1236 } |
| 1228 | 1237 |
| 1229 HostContentSettingsMap* settings_map = | 1238 HostContentSettingsMap* settings_map = |
| 1230 mode == "normal" ? GetContentSettingsMap() : | 1239 mode == "normal" ? GetContentSettingsMap() : |
| 1231 GetOTRContentSettingsMap(); | 1240 GetOTRContentSettingsMap(); |
| 1232 if (settings_map) { | 1241 if (settings_map) { |
| 1242 content_settings::ChromeContentSettingsClient client; |
| 1233 settings_map->SetWebsiteSetting( | 1243 settings_map->SetWebsiteSetting( |
| 1234 ContentSettingsPattern::FromString(pattern), | 1244 ContentSettingsPattern::FromString(&client, pattern), |
| 1235 secondary_pattern.empty() ? | 1245 secondary_pattern.empty() ? |
| 1236 ContentSettingsPattern::Wildcard() : | 1246 ContentSettingsPattern::Wildcard() : |
| 1237 ContentSettingsPattern::FromString(secondary_pattern), | 1247 ContentSettingsPattern::FromString(&client, secondary_pattern), |
| 1238 type, | 1248 type, |
| 1239 std::string(), | 1249 std::string(), |
| 1240 NULL); | 1250 NULL); |
| 1241 } | 1251 } |
| 1242 } | 1252 } |
| 1243 | 1253 |
| 1244 void ContentSettingsHandler::RemoveZoomLevelException( | 1254 void ContentSettingsHandler::RemoveZoomLevelException( |
| 1245 const base::ListValue* args) { | 1255 const base::ListValue* args) { |
| 1246 std::string mode; | 1256 std::string mode; |
| 1247 bool rv = args->GetString(1, &mode); | 1257 bool rv = args->GetString(1, &mode); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 NOTREACHED(); | 1434 NOTREACHED(); |
| 1425 } else { | 1435 } else { |
| 1426 HostContentSettingsMap* settings_map = | 1436 HostContentSettingsMap* settings_map = |
| 1427 mode == "normal" ? GetContentSettingsMap() : | 1437 mode == "normal" ? GetContentSettingsMap() : |
| 1428 GetOTRContentSettingsMap(); | 1438 GetOTRContentSettingsMap(); |
| 1429 | 1439 |
| 1430 // The settings map could be null if the mode was OTR but the OTR profile | 1440 // The settings map could be null if the mode was OTR but the OTR profile |
| 1431 // got destroyed before we received this message. | 1441 // got destroyed before we received this message. |
| 1432 if (!settings_map) | 1442 if (!settings_map) |
| 1433 return; | 1443 return; |
| 1434 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), | 1444 content_settings::ChromeContentSettingsClient client; |
| 1445 settings_map->SetContentSetting(ContentSettingsPattern::FromString(&client, |
| 1446 pattern), |
| 1435 ContentSettingsPattern::Wildcard(), | 1447 ContentSettingsPattern::Wildcard(), |
| 1436 type, | 1448 type, |
| 1437 std::string(), | 1449 std::string(), |
| 1438 ContentSettingFromString(setting)); | 1450 ContentSettingFromString(setting)); |
| 1439 } | 1451 } |
| 1440 } | 1452 } |
| 1441 | 1453 |
| 1442 void ContentSettingsHandler::CheckExceptionPatternValidity( | 1454 void ContentSettingsHandler::CheckExceptionPatternValidity( |
| 1443 const base::ListValue* args) { | 1455 const base::ListValue* args) { |
| 1444 std::string type_string; | 1456 std::string type_string; |
| 1445 CHECK(args->GetString(0, &type_string)); | 1457 CHECK(args->GetString(0, &type_string)); |
| 1446 std::string mode_string; | 1458 std::string mode_string; |
| 1447 CHECK(args->GetString(1, &mode_string)); | 1459 CHECK(args->GetString(1, &mode_string)); |
| 1448 std::string pattern_string; | 1460 std::string pattern_string; |
| 1449 CHECK(args->GetString(2, &pattern_string)); | 1461 CHECK(args->GetString(2, &pattern_string)); |
| 1450 | 1462 |
| 1463 content_settings::ChromeContentSettingsClient client; |
| 1451 ContentSettingsPattern pattern = | 1464 ContentSettingsPattern pattern = |
| 1452 ContentSettingsPattern::FromString(pattern_string); | 1465 ContentSettingsPattern::FromString(&client, pattern_string); |
| 1453 | 1466 |
| 1454 web_ui()->CallJavascriptFunction( | 1467 web_ui()->CallJavascriptFunction( |
| 1455 "ContentSettings.patternValidityCheckComplete", | 1468 "ContentSettings.patternValidityCheckComplete", |
| 1456 base::StringValue(type_string), | 1469 base::StringValue(type_string), |
| 1457 base::StringValue(mode_string), | 1470 base::StringValue(mode_string), |
| 1458 base::StringValue(pattern_string), | 1471 base::StringValue(pattern_string), |
| 1459 base::FundamentalValue(pattern.IsValid())); | 1472 base::FundamentalValue(pattern.IsValid())); |
| 1460 } | 1473 } |
| 1461 | 1474 |
| 1462 // static | 1475 // static |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { | 1587 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { |
| 1575 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); | 1588 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); |
| 1576 // Exceptions apply only when the feature is enabled. | 1589 // Exceptions apply only when the feature is enabled. |
| 1577 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); | 1590 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); |
| 1578 web_ui()->CallJavascriptFunction( | 1591 web_ui()->CallJavascriptFunction( |
| 1579 "ContentSettings.enableProtectedContentExceptions", | 1592 "ContentSettings.enableProtectedContentExceptions", |
| 1580 base::FundamentalValue(enable_exceptions)); | 1593 base::FundamentalValue(enable_exceptions)); |
| 1581 } | 1594 } |
| 1582 | 1595 |
| 1583 } // namespace options | 1596 } // namespace options |
| OLD | NEW |