Chromium Code Reviews| 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/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" | 21 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" |
| 21 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 22 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 22 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 23 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 23 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 24 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 24 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 25 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
| 28 #include "chrome/common/chrome_switches.h" | |
| 27 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 29 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 28 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 30 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
| 31 #include "chrome/grit/locale_settings.h" | 33 #include "chrome/grit/locale_settings.h" |
| 32 #include "components/content_settings/core/browser/content_settings_details.h" | 34 #include "components/content_settings/core/browser/content_settings_details.h" |
| 33 #include "components/content_settings/core/browser/content_settings_utils.h" | 35 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 34 #include "components/content_settings/core/browser/host_content_settings_map.h" | 36 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 35 #include "components/content_settings/core/browser/plugins_field_trial.h" | 37 #include "components/content_settings/core/browser/plugins_field_trial.h" |
| 36 #include "components/content_settings/core/common/content_settings.h" | 38 #include "components/content_settings/core/common/content_settings.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 if (name == kContentSettingsTypeGroupNames[i].name) | 136 if (name == kContentSettingsTypeGroupNames[i].name) |
| 135 return kContentSettingsTypeGroupNames[i].type; | 137 return kContentSettingsTypeGroupNames[i].type; |
| 136 } | 138 } |
| 137 | 139 |
| 138 NOTREACHED() << name << " is not a recognized content settings type."; | 140 NOTREACHED() << name << " is not a recognized content settings type."; |
| 139 return CONTENT_SETTINGS_TYPE_DEFAULT; | 141 return CONTENT_SETTINGS_TYPE_DEFAULT; |
| 140 } | 142 } |
| 141 | 143 |
| 142 // Create a DictionaryValue* that will act as a data source for a single row | 144 // Create a DictionaryValue* that will act as a data source for a single row |
| 143 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). | 145 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). |
| 144 // Ownership of the pointer is passed to the caller. | 146 scoped_ptr<base::DictionaryValue> GetExceptionForPage( |
| 145 base::DictionaryValue* GetExceptionForPage( | |
| 146 const ContentSettingsPattern& pattern, | 147 const ContentSettingsPattern& pattern, |
| 147 const ContentSettingsPattern& secondary_pattern, | 148 const ContentSettingsPattern& secondary_pattern, |
| 148 const ContentSetting& setting, | 149 const ContentSetting& setting, |
| 149 const std::string& provider_name) { | 150 const std::string& provider_name) { |
| 150 base::DictionaryValue* exception = new base::DictionaryValue(); | 151 base::DictionaryValue* exception = new base::DictionaryValue(); |
| 151 exception->SetString(kOrigin, pattern.ToString()); | 152 exception->SetString(kOrigin, pattern.ToString()); |
| 152 exception->SetString(kEmbeddingOrigin, | 153 exception->SetString(kEmbeddingOrigin, |
| 153 secondary_pattern == ContentSettingsPattern::Wildcard() ? | 154 secondary_pattern == ContentSettingsPattern::Wildcard() ? |
| 154 std::string() : | 155 std::string() : |
| 155 secondary_pattern.ToString()); | 156 secondary_pattern.ToString()); |
| 156 exception->SetString(kSetting, ContentSettingToString(setting)); | 157 exception->SetString(kSetting, ContentSettingToString(setting)); |
| 157 exception->SetString(kSource, provider_name); | 158 exception->SetString(kSource, provider_name); |
| 158 return exception; | 159 return make_scoped_ptr(exception); |
| 159 } | 160 } |
| 160 | 161 |
| 161 // Create a DictionaryValue* that will act as a data source for a single row | 162 // Create a DictionaryValue* that will act as a data source for a single row |
| 162 // in the Geolocation exceptions table. Ownership of the pointer is passed to | 163 // in the Geolocation exceptions table. |
| 163 // the caller. | 164 scoped_ptr<base::DictionaryValue> GetGeolocationExceptionForPage( |
| 164 base::DictionaryValue* GetGeolocationExceptionForPage( | |
| 165 const ContentSettingsPattern& origin, | 165 const ContentSettingsPattern& origin, |
| 166 const ContentSettingsPattern& embedding_origin, | 166 const ContentSettingsPattern& embedding_origin, |
| 167 ContentSetting setting) { | 167 ContentSetting setting) { |
| 168 base::DictionaryValue* exception = new base::DictionaryValue(); | 168 base::DictionaryValue* exception = new base::DictionaryValue(); |
| 169 exception->SetString(kSetting, ContentSettingToString(setting)); | 169 exception->SetString(kSetting, ContentSettingToString(setting)); |
| 170 exception->SetString(kOrigin, origin.ToString()); | 170 exception->SetString(kOrigin, origin.ToString()); |
| 171 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString()); | 171 exception->SetString(kEmbeddingOrigin, embedding_origin.ToString()); |
| 172 return exception; | 172 return make_scoped_ptr(exception); |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Create a DictionaryValue* that will act as a data source for a single row | 175 // Create a DictionaryValue* that will act as a data source for a single row |
| 176 // in the desktop notifications exceptions table. Ownership of the pointer is | 176 // in the desktop notifications exceptions table. |
| 177 // passed to the caller. | 177 scoped_ptr<base::DictionaryValue> GetNotificationExceptionForPage( |
| 178 base::DictionaryValue* GetNotificationExceptionForPage( | |
| 179 const ContentSettingsPattern& primary_pattern, | 178 const ContentSettingsPattern& primary_pattern, |
| 180 const ContentSettingsPattern& secondary_pattern, | 179 const ContentSettingsPattern& secondary_pattern, |
| 181 ContentSetting setting, | 180 ContentSetting setting, |
| 182 const std::string& provider_name) { | 181 const std::string& provider_name) { |
| 183 std::string embedding_origin; | 182 std::string embedding_origin; |
| 184 if (secondary_pattern != ContentSettingsPattern::Wildcard()) | 183 if (secondary_pattern != ContentSettingsPattern::Wildcard()) |
| 185 embedding_origin = secondary_pattern.ToString(); | 184 embedding_origin = secondary_pattern.ToString(); |
| 186 | 185 |
| 187 base::DictionaryValue* exception = new base::DictionaryValue(); | 186 base::DictionaryValue* exception = new base::DictionaryValue(); |
| 188 exception->SetString(kSetting, ContentSettingToString(setting)); | 187 exception->SetString(kSetting, ContentSettingToString(setting)); |
| 189 exception->SetString(kOrigin, primary_pattern.ToString()); | 188 exception->SetString(kOrigin, primary_pattern.ToString()); |
| 190 exception->SetString(kEmbeddingOrigin, embedding_origin); | 189 exception->SetString(kEmbeddingOrigin, embedding_origin); |
| 191 exception->SetString(kSource, provider_name); | 190 exception->SetString(kSource, provider_name); |
| 192 return exception; | 191 return make_scoped_ptr(exception); |
| 193 } | 192 } |
| 194 | 193 |
| 195 // Returns true whenever the |extension| is hosted and has |permission|. | 194 // Returns true whenever the |extension| is hosted and has |permission|. |
| 196 // Must have the AppFilter signature. | 195 // Must have the AppFilter signature. |
| 197 template <APIPermission::ID permission> | 196 template <APIPermission::ID permission> |
| 198 bool HostedAppHasPermission(const extensions::Extension& extension, | 197 bool HostedAppHasPermission(const extensions::Extension& extension, |
| 199 content::BrowserContext* /* context */) { | 198 content::BrowserContext* /* context */) { |
| 200 return extension.is_hosted_app() && | 199 return extension.is_hosted_app() && |
| 201 extension.permissions_data()->HasAPIPermission(permission); | 200 extension.permissions_data()->HasAPIPermission(permission); |
| 202 } | 201 } |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 pref_change_registrar_.Add( | 510 pref_change_registrar_.Add( |
| 512 prefs::kPepperFlashSettingsEnabled, | 511 prefs::kPepperFlashSettingsEnabled, |
| 513 base::Bind(&ContentSettingsHandler::OnPepperFlashPrefChanged, | 512 base::Bind(&ContentSettingsHandler::OnPepperFlashPrefChanged, |
| 514 base::Unretained(this))); | 513 base::Unretained(this))); |
| 515 pref_change_registrar_.Add( | 514 pref_change_registrar_.Add( |
| 516 prefs::kAudioCaptureAllowed, | 515 prefs::kAudioCaptureAllowed, |
| 517 base::Bind(&ContentSettingsHandler::UpdateSettingDefaultFromModel, | 516 base::Bind(&ContentSettingsHandler::UpdateSettingDefaultFromModel, |
| 518 base::Unretained(this), | 517 base::Unretained(this), |
| 519 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 518 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 520 pref_change_registrar_.Add( | 519 pref_change_registrar_.Add( |
| 520 prefs::kAudioCaptureAllowedUrls, | |
| 521 base::Bind(&ContentSettingsHandler::UpdateExceptionsViewFromModel, | |
| 522 base::Unretained(this), | |
| 523 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | |
| 524 pref_change_registrar_.Add( | |
| 521 prefs::kVideoCaptureAllowed, | 525 prefs::kVideoCaptureAllowed, |
| 522 base::Bind(&ContentSettingsHandler::UpdateSettingDefaultFromModel, | 526 base::Bind(&ContentSettingsHandler::UpdateSettingDefaultFromModel, |
| 523 base::Unretained(this), | 527 base::Unretained(this), |
| 524 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 528 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 525 pref_change_registrar_.Add( | 529 pref_change_registrar_.Add( |
| 530 prefs::kVideoCaptureAllowedUrls, | |
| 531 base::Bind(&ContentSettingsHandler::UpdateExceptionsViewFromModel, | |
| 532 base::Unretained(this), | |
| 533 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | |
| 534 pref_change_registrar_.Add( | |
| 526 prefs::kEnableDRM, | 535 prefs::kEnableDRM, |
| 527 base::Bind( | 536 base::Bind( |
| 528 &ContentSettingsHandler::UpdateProtectedContentExceptionsButton, | 537 &ContentSettingsHandler::UpdateProtectedContentExceptionsButton, |
| 529 base::Unretained(this))); | 538 base::Unretained(this))); |
| 530 | 539 |
| 531 // Here we only subscribe to the HostZoomMap for the default storage partition | 540 // Here we only subscribe to the HostZoomMap for the default storage partition |
| 532 // since we don't allow the user to manage the zoom levels for apps. | 541 // since we don't allow the user to manage the zoom levels for apps. |
| 533 // We're only interested in zoom-levels that are persisted, since the user | 542 // We're only interested in zoom-levels that are persisted, since the user |
| 534 // is given the opportunity to view/delete these in the content-settings page. | 543 // is given the opportunity to view/delete these in the content-settings page. |
| 535 host_zoom_map_subscription_ = | 544 host_zoom_map_subscription_ = |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1092 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); | 1101 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); |
| 1093 if (!otr_settings_map) | 1102 if (!otr_settings_map) |
| 1094 return; | 1103 return; |
| 1095 base::ListValue exceptions; | 1104 base::ListValue exceptions; |
| 1096 GetExceptionsFromHostContentSettingsMap(otr_settings_map, type, &exceptions); | 1105 GetExceptionsFromHostContentSettingsMap(otr_settings_map, type, &exceptions); |
| 1097 base::StringValue type_string(ContentSettingsTypeToGroupName(type)); | 1106 base::StringValue type_string(ContentSettingsTypeToGroupName(type)); |
| 1098 web_ui()->CallJavascriptFunction("ContentSettings.setOTRExceptions", | 1107 web_ui()->CallJavascriptFunction("ContentSettings.setOTRExceptions", |
| 1099 type_string, exceptions); | 1108 type_string, exceptions); |
| 1100 } | 1109 } |
| 1101 | 1110 |
| 1111 scoped_ptr<base::ListValue> ContentSettingsHandler::GetPolicyAllowedUrls( | |
| 1112 ContentSettingsType type) { | |
| 1113 DCHECK(type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | |
| 1114 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
| 1115 | |
| 1116 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | |
| 1117 const base::ListValue* policy_urls = prefs->GetList( | |
| 1118 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | |
| 1119 ? prefs::kAudioCaptureAllowedUrls | |
| 1120 : prefs::kVideoCaptureAllowedUrls); | |
| 1121 | |
| 1122 // Convert the URLs to |ContentSettingsPattern|s. Ignore any invalid ones. | |
| 1123 std::vector<ContentSettingsPattern> patterns; | |
| 1124 for (const base::Value* entry : *policy_urls) { | |
| 1125 std::string url; | |
| 1126 bool valid_string = entry->GetAsString(&url); | |
| 1127 if (!valid_string) | |
| 1128 continue; | |
| 1129 | |
| 1130 ContentSettingsPattern pattern = ContentSettingsPattern::FromString(url); | |
| 1131 if (!pattern.IsValid()) | |
| 1132 continue; | |
| 1133 | |
| 1134 patterns.push_back(pattern); | |
| 1135 } | |
| 1136 | |
| 1137 // The patterns are shown in the UI in a reverse order defined by | |
| 1138 // |ContentSettingsPattern::operator<|. | |
| 1139 std::sort( | |
| 1140 patterns.begin(), patterns.end(), std::greater<ContentSettingsPattern>()); | |
| 1141 | |
| 1142 scoped_ptr<base::ListValue> exceptions(new base::ListValue()); | |
| 1143 for (const ContentSettingsPattern& pattern : patterns) { | |
| 1144 exceptions->Append(GetExceptionForPage( | |
| 1145 pattern, | |
| 1146 ContentSettingsPattern(), | |
| 1147 CONTENT_SETTING_ALLOW, | |
| 1148 kPolicyProviderId)); | |
| 1149 } | |
| 1150 | |
| 1151 return exceptions.Pass(); | |
| 1152 } | |
| 1153 | |
| 1102 void ContentSettingsHandler::GetExceptionsFromHostContentSettingsMap( | 1154 void ContentSettingsHandler::GetExceptionsFromHostContentSettingsMap( |
| 1103 const HostContentSettingsMap* map, | 1155 const HostContentSettingsMap* map, |
| 1104 ContentSettingsType type, | 1156 ContentSettingsType type, |
| 1105 base::ListValue* exceptions) { | 1157 base::ListValue* exceptions) { |
| 1106 ContentSettingsForOneType entries; | 1158 ContentSettingsForOneType entries; |
| 1107 map->GetSettingsForOneType(type, std::string(), &entries); | 1159 map->GetSettingsForOneType(type, std::string(), &entries); |
| 1108 // Group settings by primary_pattern. | 1160 // Group settings by primary_pattern. |
| 1109 AllPatternsSettings all_patterns_settings; | 1161 AllPatternsSettings all_patterns_settings; |
| 1110 for (ContentSettingsForOneType::iterator i = entries.begin(); | 1162 for (ContentSettingsForOneType::iterator i = entries.begin(); |
| 1111 i != entries.end(); ++i) { | 1163 i != entries.end(); ++i) { |
| 1112 // Don't add default settings. | 1164 // Don't add default settings. |
| 1113 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && | 1165 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && |
| 1114 i->secondary_pattern == ContentSettingsPattern::Wildcard() && | 1166 i->secondary_pattern == ContentSettingsPattern::Wildcard() && |
| 1115 i->source != kPreferencesSource) { | 1167 i->source != kPreferencesSource) { |
| 1116 continue; | 1168 continue; |
| 1117 } | 1169 } |
| 1118 | 1170 |
| 1119 // Off-the-record HostContentSettingsMap contains incognito content settings | 1171 // Off-the-record HostContentSettingsMap contains incognito content settings |
| 1120 // as well as normal content settings. Here, we use the incongnito settings | 1172 // as well as normal content settings. Here, we use the incongnito settings |
| 1121 // only. | 1173 // only. |
| 1122 if (map->is_off_the_record() && !i->incognito) | 1174 if (map->is_off_the_record() && !i->incognito) |
| 1123 continue; | 1175 continue; |
| 1124 | 1176 |
| 1125 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] | 1177 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] |
| 1126 [i->secondary_pattern] = i->setting; | 1178 [i->secondary_pattern] = i->setting; |
| 1127 } | 1179 } |
| 1128 | 1180 |
| 1129 // Keep the exceptions sorted by provider so they will be displayed in | 1181 // Keep the exceptions sorted by provider so they will be displayed in |
| 1130 // precedence order. | 1182 // precedence order. |
| 1131 std::vector<std::vector<base::Value*> > all_provider_exceptions; | 1183 ScopedVector<base::ListValue> all_provider_exceptions; |
| 1132 all_provider_exceptions.resize(HostContentSettingsMap::NUM_PROVIDER_TYPES); | 1184 all_provider_exceptions.resize(HostContentSettingsMap::NUM_PROVIDER_TYPES); |
| 1185 for (auto& one_provider_exceptions : all_provider_exceptions) | |
| 1186 one_provider_exceptions = new base::ListValue(); | |
| 1133 | 1187 |
| 1134 // The all_patterns_settings is sorted from the lowest precedence pattern to | 1188 // The all_patterns_settings is sorted from the lowest precedence pattern to |
| 1135 // the highest (see operator< in ContentSettingsPattern), so traverse it in | 1189 // the highest (see operator< in ContentSettingsPattern), so traverse it in |
| 1136 // reverse to show the patterns with the highest precedence (the more specific | 1190 // reverse to show the patterns with the highest precedence (the more specific |
| 1137 // ones) on the top. | 1191 // ones) on the top. |
| 1138 for (AllPatternsSettings::reverse_iterator i = all_patterns_settings.rbegin(); | 1192 for (AllPatternsSettings::reverse_iterator i = all_patterns_settings.rbegin(); |
| 1139 i != all_patterns_settings.rend(); | 1193 i != all_patterns_settings.rend(); |
| 1140 ++i) { | 1194 ++i) { |
| 1141 const ContentSettingsPattern& primary_pattern = i->first.first; | 1195 const ContentSettingsPattern& primary_pattern = i->first.first; |
| 1142 const OnePatternSettings& one_settings = i->second; | 1196 const OnePatternSettings& one_settings = i->second; |
| 1143 | 1197 |
| 1144 // The "parent" entry either has an identical primary and secondary pattern, | 1198 // The "parent" entry either has an identical primary and secondary pattern, |
| 1145 // or has a wildcard secondary. The two cases are indistinguishable in the | 1199 // or has a wildcard secondary. The two cases are indistinguishable in the |
| 1146 // UI. | 1200 // UI. |
| 1147 OnePatternSettings::const_iterator parent = | 1201 OnePatternSettings::const_iterator parent = |
| 1148 one_settings.find(primary_pattern); | 1202 one_settings.find(primary_pattern); |
| 1149 if (parent == one_settings.end()) | 1203 if (parent == one_settings.end()) |
| 1150 parent = one_settings.find(ContentSettingsPattern::Wildcard()); | 1204 parent = one_settings.find(ContentSettingsPattern::Wildcard()); |
| 1151 | 1205 |
| 1152 const std::string& source = i->first.second; | 1206 const std::string& source = i->first.second; |
| 1153 std::vector<base::Value*>* this_provider_exceptions = | 1207 base::ListValue* this_provider_exceptions = |
| 1154 &all_provider_exceptions.at( | 1208 all_provider_exceptions.get().at( |
|
Bernhard Bauer
2015/07/28 15:35:31
Could you just use the [] operator? The bounds che
msramek
2015/07/29 13:07:09
Done. Since GetProviderTypeFromSource returns Prov
| |
| 1155 HostContentSettingsMap::GetProviderTypeFromSource(source)); | 1209 HostContentSettingsMap::GetProviderTypeFromSource(source)); |
| 1156 | 1210 |
| 1157 // Add the "parent" entry for the non-embedded setting. | 1211 // Add the "parent" entry for the non-embedded setting. |
| 1158 ContentSetting parent_setting = | 1212 ContentSetting parent_setting = |
| 1159 parent == one_settings.end() ? CONTENT_SETTING_DEFAULT : parent->second; | 1213 parent == one_settings.end() ? CONTENT_SETTING_DEFAULT : parent->second; |
| 1160 const ContentSettingsPattern& secondary_pattern = | 1214 const ContentSettingsPattern& secondary_pattern = |
| 1161 parent == one_settings.end() ? primary_pattern : parent->first; | 1215 parent == one_settings.end() ? primary_pattern : parent->first; |
| 1162 this_provider_exceptions->push_back(GetExceptionForPage(primary_pattern, | 1216 this_provider_exceptions->Append(GetExceptionForPage(primary_pattern, |
| 1163 secondary_pattern, | 1217 secondary_pattern, |
| 1164 parent_setting, | 1218 parent_setting, |
| 1165 source)); | 1219 source)); |
| 1166 | 1220 |
| 1167 // Add the "children" for any embedded settings. | 1221 // Add the "children" for any embedded settings. |
| 1168 for (OnePatternSettings::const_iterator j = one_settings.begin(); | 1222 for (OnePatternSettings::const_iterator j = one_settings.begin(); |
| 1169 j != one_settings.end(); ++j) { | 1223 j != one_settings.end(); ++j) { |
| 1170 // Skip the non-embedded setting which we already added above. | 1224 // Skip the non-embedded setting which we already added above. |
| 1171 if (j == parent) | 1225 if (j == parent) |
| 1172 continue; | 1226 continue; |
| 1173 | 1227 |
| 1174 ContentSetting content_setting = j->second; | 1228 ContentSetting content_setting = j->second; |
| 1175 this_provider_exceptions->push_back(GetExceptionForPage( | 1229 this_provider_exceptions->Append(GetExceptionForPage( |
| 1176 primary_pattern, | 1230 primary_pattern, |
| 1177 j->first, | 1231 j->first, |
| 1178 content_setting, | 1232 content_setting, |
| 1179 source)); | 1233 source)); |
| 1180 } | 1234 } |
| 1181 } | 1235 } |
| 1182 | 1236 |
| 1183 for (size_t i = 0; i < all_provider_exceptions.size(); ++i) { | 1237 // For camera and microphone, we do not have policy exceptions, but we do have |
| 1184 for (size_t j = 0; j < all_provider_exceptions[i].size(); ++j) { | 1238 // the policy-set allowed URLs, which should be displayed in the same manner. |
| 1185 exceptions->Append(all_provider_exceptions[i][j]); | 1239 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 1240 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | |
| 1241 base::ListValue* policy_exceptions = all_provider_exceptions.get().at( | |
| 1242 HostContentSettingsMap::GetProviderTypeFromSource(kPolicyProviderId)); | |
| 1243 DCHECK(policy_exceptions->empty()); | |
| 1244 policy_exceptions->Swap(GetPolicyAllowedUrls(type).release()); | |
|
Bernhard Bauer
2015/07/28 15:35:31
Doesn't this leak the ListValue object that is ret
msramek
2015/07/29 13:07:09
Good catch!
| |
| 1245 } | |
| 1246 | |
| 1247 for (auto& one_provider_exceptions : all_provider_exceptions) { | |
|
Bernhard Bauer
2015/07/28 15:35:31
Can you use const auto& here?
msramek
2015/07/29 13:07:09
Done.
| |
| 1248 for (auto& exception : *one_provider_exceptions) { | |
| 1249 exceptions->Append(exception->DeepCopy()); | |
|
Bernhard Bauer
2015/07/28 15:35:31
Hm... it's a pity that ListValue doesn't support r
msramek
2015/07/29 13:07:09
But ListValue uses std::vector (not std::list) und
Bernhard Bauer
2015/07/29 13:19:24
Heh. I like that ☺
| |
| 1186 } | 1250 } |
| 1187 } | 1251 } |
| 1188 } | 1252 } |
| 1189 | 1253 |
| 1190 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( | 1254 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( |
| 1191 const base::ListValue* args, | 1255 const base::ListValue* args, |
| 1192 ContentSettingsType type) { | 1256 ContentSettingsType type) { |
| 1193 std::string mode; | 1257 std::string mode; |
| 1194 bool rv = args->GetString(1, &mode); | 1258 bool rv = args->GetString(1, &mode); |
| 1195 DCHECK(rv); | 1259 DCHECK(rv); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1566 | 1630 |
| 1567 // Exceptions apply only when the feature is enabled. | 1631 // Exceptions apply only when the feature is enabled. |
| 1568 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); | 1632 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); |
| 1569 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); | 1633 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); |
| 1570 web_ui()->CallJavascriptFunction( | 1634 web_ui()->CallJavascriptFunction( |
| 1571 "ContentSettings.enableProtectedContentExceptions", | 1635 "ContentSettings.enableProtectedContentExceptions", |
| 1572 base::FundamentalValue(enable_exceptions)); | 1636 base::FundamentalValue(enable_exceptions)); |
| 1573 } | 1637 } |
| 1574 | 1638 |
| 1575 } // namespace options | 1639 } // namespace options |
| OLD | NEW |