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 |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "components/user_prefs/user_prefs.h" | 37 #include "components/user_prefs/user_prefs.h" |
38 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
39 #include "content/public/browser/notification_source.h" | 39 #include "content/public/browser/notification_source.h" |
40 #include "content/public/browser/notification_types.h" | 40 #include "content/public/browser/notification_types.h" |
41 #include "content/public/browser/user_metrics.h" | 41 #include "content/public/browser/user_metrics.h" |
42 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
43 #include "content/public/browser/web_ui.h" | 43 #include "content/public/browser/web_ui.h" |
44 #include "content/public/common/content_switches.h" | 44 #include "content/public/common/content_switches.h" |
45 #include "content/public/common/page_zoom.h" | 45 #include "content/public/common/page_zoom.h" |
46 #include "extensions/browser/extension_registry.h" | 46 #include "extensions/browser/extension_registry.h" |
| 47 #include "extensions/common/constants.h" |
47 #include "extensions/common/extension_set.h" | 48 #include "extensions/common/extension_set.h" |
48 #include "extensions/common/permissions/api_permission.h" | 49 #include "extensions/common/permissions/api_permission.h" |
49 #include "extensions/common/permissions/permissions_data.h" | 50 #include "extensions/common/permissions/permissions_data.h" |
50 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
51 #include "grit/locale_settings.h" | 52 #include "grit/locale_settings.h" |
52 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" |
53 | 54 |
54 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
55 #include "chrome/browser/chromeos/login/users/user_manager.h" | 56 #include "chrome/browser/chromeos/login/users/user_manager.h" |
56 #endif | 57 #endif |
(...skipping 113 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 exception->SetString(kOrigin, pattern.ToString(extensions::kExtensionScheme)); |
181 exception->SetString(kEmbeddingOrigin, | 182 exception->SetString(kEmbeddingOrigin, |
182 secondary_pattern == ContentSettingsPattern::Wildcard() ? | 183 secondary_pattern == ContentSettingsPattern::Wildcard() ? |
183 std::string() : | 184 std::string() : |
184 secondary_pattern.ToString()); | 185 secondary_pattern.ToString( |
| 186 extensions::kExtensionScheme)); |
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(); |
198 exception->SetString(kSetting, ContentSettingToString(setting)); | 200 exception->SetString(kSetting, ContentSettingToString(setting)); |
199 exception->SetString(kOrigin, origin.ToString()); | 201 exception->SetString(kOrigin, origin.ToString(extensions::kExtensionScheme)); |
200 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString()); | 202 exception->SetString(kEmbeddingOrigin, |
| 203 embedding_origin.ToString(extensions::kExtensionScheme)); |
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(); |
212 exception->SetString(kSetting, ContentSettingToString(setting)); | 215 exception->SetString(kSetting, ContentSettingToString(setting)); |
213 exception->SetString(kOrigin, pattern.ToString()); | 216 exception->SetString(kOrigin, pattern.ToString(extensions::kExtensionScheme)); |
214 exception->SetString(kSource, provider_name); | 217 exception->SetString(kSource, provider_name); |
215 return exception; | 218 return exception; |
216 } | 219 } |
217 | 220 |
218 // Returns true whenever the |extension| is hosted and has |permission|. | 221 // Returns true whenever the |extension| is hosted and has |permission|. |
219 // Must have the AppFilter signature. | 222 // Must have the AppFilter signature. |
220 template <APIPermission::ID permission> | 223 template <APIPermission::ID permission> |
221 bool HostedAppHasPermission(const extensions::Extension& extension, | 224 bool HostedAppHasPermission(const extensions::Extension& extension, |
222 content::BrowserContext* /* context */) { | 225 content::BrowserContext* /* context */) { |
223 return extension.is_hosted_app() && | 226 return extension.is_hosted_app() && |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 bool result = (*media_entry)->GetAsDictionary(&media_dict); | 962 bool result = (*media_entry)->GetAsDictionary(&media_dict); |
960 DCHECK(result); | 963 DCHECK(result); |
961 | 964 |
962 std::string origin; | 965 std::string origin; |
963 std::string audio_setting; | 966 std::string audio_setting; |
964 std::string video_setting; | 967 std::string video_setting; |
965 media_dict->GetString(kOrigin, &origin); | 968 media_dict->GetString(kOrigin, &origin); |
966 media_dict->GetString(kSetting, &audio_setting); | 969 media_dict->GetString(kSetting, &audio_setting); |
967 media_dict->GetString(kVideoSetting, &video_setting); | 970 media_dict->GetString(kVideoSetting, &video_setting); |
968 media_settings_.exceptions.push_back(MediaException( | 971 media_settings_.exceptions.push_back(MediaException( |
969 ContentSettingsPattern::FromString(origin), | 972 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 973 origin), |
970 ContentSettingFromString(audio_setting), | 974 ContentSettingFromString(audio_setting), |
971 ContentSettingFromString(video_setting))); | 975 ContentSettingFromString(video_setting))); |
972 } | 976 } |
973 PepperFlashContentSettingsUtils::SortMediaExceptions( | 977 PepperFlashContentSettingsUtils::SortMediaExceptions( |
974 &media_settings_.exceptions); | 978 &media_settings_.exceptions); |
975 media_settings_.exceptions_initialized = true; | 979 media_settings_.exceptions_initialized = true; |
976 UpdateFlashMediaLinksVisibility(); | 980 UpdateFlashMediaLinksVisibility(); |
977 | 981 |
978 base::StringValue type_string( | 982 base::StringValue type_string( |
979 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_MEDIASTREAM)); | 983 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_MEDIASTREAM)); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 std::string setting; | 1176 std::string setting; |
1173 bool rv = args->GetString(1, &origin); | 1177 bool rv = args->GetString(1, &origin); |
1174 DCHECK(rv); | 1178 DCHECK(rv); |
1175 rv = args->GetString(2, &setting); | 1179 rv = args->GetString(2, &setting); |
1176 DCHECK(rv); | 1180 DCHECK(rv); |
1177 ContentSetting content_setting = ContentSettingFromString(setting); | 1181 ContentSetting content_setting = ContentSettingFromString(setting); |
1178 | 1182 |
1179 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 1183 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
1180 content_setting == CONTENT_SETTING_BLOCK); | 1184 content_setting == CONTENT_SETTING_BLOCK); |
1181 DesktopNotificationProfileUtil::ClearSetting(profile, | 1185 DesktopNotificationProfileUtil::ClearSetting(profile, |
1182 ContentSettingsPattern::FromString(origin)); | 1186 ContentSettingsPattern::FromString(extensions::kExtensionScheme, origin)); |
1183 } | 1187 } |
1184 | 1188 |
1185 void ContentSettingsHandler::RemoveMediaException(const base::ListValue* args) { | 1189 void ContentSettingsHandler::RemoveMediaException(const base::ListValue* args) { |
1186 std::string mode; | 1190 std::string mode; |
1187 bool rv = args->GetString(1, &mode); | 1191 bool rv = args->GetString(1, &mode); |
1188 DCHECK(rv); | 1192 DCHECK(rv); |
1189 | 1193 |
1190 std::string pattern; | 1194 std::string pattern; |
1191 rv = args->GetString(2, &pattern); | 1195 rv = args->GetString(2, &pattern); |
1192 DCHECK(rv); | 1196 DCHECK(rv); |
1193 | 1197 |
1194 HostContentSettingsMap* settings_map = | 1198 HostContentSettingsMap* settings_map = |
1195 mode == "normal" ? GetContentSettingsMap() : | 1199 mode == "normal" ? GetContentSettingsMap() : |
1196 GetOTRContentSettingsMap(); | 1200 GetOTRContentSettingsMap(); |
1197 if (settings_map) { | 1201 if (settings_map) { |
1198 settings_map->SetWebsiteSetting(ContentSettingsPattern::FromString(pattern), | 1202 settings_map->SetWebsiteSetting( |
1199 ContentSettingsPattern::Wildcard(), | 1203 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
1200 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 1204 pattern), |
1201 std::string(), | 1205 ContentSettingsPattern::Wildcard(), |
1202 NULL); | 1206 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
1203 settings_map->SetWebsiteSetting(ContentSettingsPattern::FromString(pattern), | 1207 std::string(), |
1204 ContentSettingsPattern::Wildcard(), | 1208 NULL); |
1205 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 1209 settings_map->SetWebsiteSetting( |
1206 std::string(), | 1210 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
1207 NULL); | 1211 pattern), |
| 1212 ContentSettingsPattern::Wildcard(), |
| 1213 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 1214 std::string(), |
| 1215 NULL); |
1208 } | 1216 } |
1209 } | 1217 } |
1210 | 1218 |
1211 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( | 1219 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( |
1212 const base::ListValue* args, | 1220 const base::ListValue* args, |
1213 ContentSettingsType type) { | 1221 ContentSettingsType type) { |
1214 std::string mode; | 1222 std::string mode; |
1215 bool rv = args->GetString(1, &mode); | 1223 bool rv = args->GetString(1, &mode); |
1216 DCHECK(rv); | 1224 DCHECK(rv); |
1217 | 1225 |
1218 std::string pattern; | 1226 std::string pattern; |
1219 rv = args->GetString(2, &pattern); | 1227 rv = args->GetString(2, &pattern); |
1220 DCHECK(rv); | 1228 DCHECK(rv); |
1221 | 1229 |
1222 // The fourth argument to this handler is optional. | 1230 // The fourth argument to this handler is optional. |
1223 std::string secondary_pattern; | 1231 std::string secondary_pattern; |
1224 if (args->GetSize() >= 4U) { | 1232 if (args->GetSize() >= 4U) { |
1225 rv = args->GetString(3, &secondary_pattern); | 1233 rv = args->GetString(3, &secondary_pattern); |
1226 DCHECK(rv); | 1234 DCHECK(rv); |
1227 } | 1235 } |
1228 | 1236 |
1229 HostContentSettingsMap* settings_map = | 1237 HostContentSettingsMap* settings_map = |
1230 mode == "normal" ? GetContentSettingsMap() : | 1238 mode == "normal" ? GetContentSettingsMap() : |
1231 GetOTRContentSettingsMap(); | 1239 GetOTRContentSettingsMap(); |
1232 if (settings_map) { | 1240 if (settings_map) { |
1233 settings_map->SetWebsiteSetting( | 1241 settings_map->SetWebsiteSetting( |
1234 ContentSettingsPattern::FromString(pattern), | 1242 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 1243 pattern), |
1235 secondary_pattern.empty() ? | 1244 secondary_pattern.empty() ? |
1236 ContentSettingsPattern::Wildcard() : | 1245 ContentSettingsPattern::Wildcard() : |
1237 ContentSettingsPattern::FromString(secondary_pattern), | 1246 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 1247 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 settings_map->SetContentSetting( |
1435 ContentSettingsPattern::Wildcard(), | 1445 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
1436 type, | 1446 pattern), |
1437 std::string(), | 1447 ContentSettingsPattern::Wildcard(), |
1438 ContentSettingFromString(setting)); | 1448 type, |
| 1449 std::string(), |
| 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 |
1451 ContentSettingsPattern pattern = | 1463 ContentSettingsPattern pattern = |
1452 ContentSettingsPattern::FromString(pattern_string); | 1464 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 1465 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 |