Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/site_settings_helper.h" | 5 #include "chrome/browser/ui/webui/site_settings_helper.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/permissions/chooser_context_base.h" | 9 #include "chrome/browser/permissions/chooser_context_base.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/usb/usb_chooser_context_factory.h" | 11 #include "chrome/browser/usb/usb_chooser_context_factory.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "components/content_settings/core/browser/host_content_settings_map.h" | 13 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 14 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
| 15 | 15 |
| 16 namespace site_settings { | 16 namespace site_settings { |
| 17 | 17 |
| 18 const char kSetting[] = "setting"; | 18 const char kSetting[] = "setting"; |
| 19 const char kOrigin[] = "origin"; | 19 const char kOrigin[] = "origin"; |
| 20 const char kPolicyProviderId[] = "policy"; | 20 const char kPolicyProviderId[] = "policy"; |
| 21 const char kSource[] = "source"; | 21 const char kSource[] = "source"; |
| 22 const char kIncognito[] = "incognito"; | |
| 22 const char kEmbeddingOrigin[] = "embeddingOrigin"; | 23 const char kEmbeddingOrigin[] = "embeddingOrigin"; |
| 23 const char kPreferencesSource[] = "preference"; | 24 const char kPreferencesSource[] = "preference"; |
| 24 const char kObject[] = "object"; | 25 const char kObject[] = "object"; |
| 25 const char kObjectName[] = "objectName"; | 26 const char kObjectName[] = "objectName"; |
| 26 | 27 |
| 27 const char kGroupTypeUsb[] = "usb-devices"; | 28 const char kGroupTypeUsb[] = "usb-devices"; |
| 28 | 29 |
| 29 ChooserContextBase* GetUsbChooserContext(Profile* profile) { | 30 ChooserContextBase* GetUsbChooserContext(Profile* profile) { |
| 30 return reinterpret_cast<ChooserContextBase*>( | 31 return reinterpret_cast<ChooserContextBase*>( |
| 31 UsbChooserContextFactory::GetForProfile(profile)); | 32 UsbChooserContextFactory::GetForProfile(profile)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 NOTREACHED() << type << " is not a recognized content settings type."; | 74 NOTREACHED() << type << " is not a recognized content settings type."; |
| 74 return std::string(); | 75 return std::string(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 // Create a DictionaryValue* that will act as a data source for a single row | 78 // Create a DictionaryValue* that will act as a data source for a single row |
| 78 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). | 79 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). |
| 79 std::unique_ptr<base::DictionaryValue> GetExceptionForPage( | 80 std::unique_ptr<base::DictionaryValue> GetExceptionForPage( |
| 80 const ContentSettingsPattern& pattern, | 81 const ContentSettingsPattern& pattern, |
| 81 const ContentSettingsPattern& secondary_pattern, | 82 const ContentSettingsPattern& secondary_pattern, |
| 82 const ContentSetting& setting, | 83 const ContentSetting& setting, |
| 83 const std::string& provider_name) { | 84 const std::string& provider_name, |
| 85 bool incognito) { | |
| 84 base::DictionaryValue* exception = new base::DictionaryValue(); | 86 base::DictionaryValue* exception = new base::DictionaryValue(); |
| 85 exception->SetString(kOrigin, pattern.ToString()); | 87 exception->SetString(kOrigin, pattern.ToString()); |
| 86 exception->SetString(kEmbeddingOrigin, | 88 exception->SetString(kEmbeddingOrigin, |
| 87 secondary_pattern == ContentSettingsPattern::Wildcard() ? | 89 secondary_pattern == ContentSettingsPattern::Wildcard() ? |
| 88 std::string() : | 90 std::string() : |
| 89 secondary_pattern.ToString()); | 91 secondary_pattern.ToString()); |
| 90 | 92 |
| 91 std::string setting_string = | 93 std::string setting_string = |
| 92 content_settings::ContentSettingToString(setting); | 94 content_settings::ContentSettingToString(setting); |
| 93 DCHECK(!setting_string.empty()); | 95 DCHECK(!setting_string.empty()); |
| 94 | 96 |
| 95 exception->SetString(kSetting, setting_string); | 97 exception->SetString(kSetting, setting_string); |
| 96 exception->SetString(kSource, provider_name); | 98 exception->SetString(kSource, provider_name); |
| 99 exception->SetBoolean(kIncognito, incognito); | |
| 97 return base::WrapUnique(exception); | 100 return base::WrapUnique(exception); |
| 98 } | 101 } |
| 99 | 102 |
| 100 void GetExceptionsFromHostContentSettingsMap(const HostContentSettingsMap* map, | 103 void GetExceptionsFromHostContentSettingsMap(const HostContentSettingsMap* map, |
| 101 ContentSettingsType type, | 104 ContentSettingsType type, |
| 102 content::WebUI* web_ui, | 105 content::WebUI* web_ui, |
| 106 bool incognito, | |
| 103 base::ListValue* exceptions) { | 107 base::ListValue* exceptions) { |
| 104 ContentSettingsForOneType entries; | 108 ContentSettingsForOneType entries; |
| 105 map->GetSettingsForOneType(type, std::string(), &entries); | 109 map->GetSettingsForOneType(type, std::string(), &entries); |
| 106 // Group settings by primary_pattern. | 110 // Group settings by primary_pattern. |
| 107 AllPatternsSettings all_patterns_settings; | 111 AllPatternsSettings all_patterns_settings; |
| 108 for (ContentSettingsForOneType::iterator i = entries.begin(); | 112 for (ContentSettingsForOneType::iterator i = entries.begin(); |
| 109 i != entries.end(); ++i) { | 113 i != entries.end(); ++i) { |
| 110 // Don't add default settings. | 114 // Don't add default settings. |
| 111 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && | 115 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && |
| 112 i->secondary_pattern == ContentSettingsPattern::Wildcard() && | 116 i->secondary_pattern == ContentSettingsPattern::Wildcard() && |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 const std::string& source = i->first.second; | 154 const std::string& source = i->first.second; |
| 151 auto& this_provider_exceptions = all_provider_exceptions | 155 auto& this_provider_exceptions = all_provider_exceptions |
| 152 [HostContentSettingsMap::GetProviderTypeFromSource(source)]; | 156 [HostContentSettingsMap::GetProviderTypeFromSource(source)]; |
| 153 | 157 |
| 154 // Add the "parent" entry for the non-embedded setting. | 158 // Add the "parent" entry for the non-embedded setting. |
| 155 ContentSetting parent_setting = | 159 ContentSetting parent_setting = |
| 156 parent == one_settings.end() ? CONTENT_SETTING_DEFAULT : parent->second; | 160 parent == one_settings.end() ? CONTENT_SETTING_DEFAULT : parent->second; |
| 157 const ContentSettingsPattern& secondary_pattern = | 161 const ContentSettingsPattern& secondary_pattern = |
| 158 parent == one_settings.end() ? primary_pattern : parent->first; | 162 parent == one_settings.end() ? primary_pattern : parent->first; |
| 159 this_provider_exceptions.push_back(GetExceptionForPage( | 163 this_provider_exceptions.push_back(GetExceptionForPage( |
| 160 primary_pattern, secondary_pattern, parent_setting, source)); | 164 primary_pattern, secondary_pattern, parent_setting, source, incognito)); |
| 161 | 165 |
| 162 // Add the "children" for any embedded settings. | 166 // Add the "children" for any embedded settings. |
| 163 for (OnePatternSettings::const_iterator j = one_settings.begin(); | 167 for (OnePatternSettings::const_iterator j = one_settings.begin(); |
| 164 j != one_settings.end(); ++j) { | 168 j != one_settings.end(); ++j) { |
| 165 // Skip the non-embedded setting which we already added above. | 169 // Skip the non-embedded setting which we already added above. |
| 166 if (j == parent) | 170 if (j == parent) |
| 167 continue; | 171 continue; |
| 168 | 172 |
| 169 ContentSetting content_setting = j->second; | 173 ContentSetting content_setting = j->second; |
| 170 this_provider_exceptions.push_back(GetExceptionForPage( | 174 this_provider_exceptions.push_back(GetExceptionForPage( |
| 171 primary_pattern, j->first, content_setting, source)); | 175 primary_pattern, j->first, content_setting, source, incognito)); |
| 172 } | 176 } |
| 173 } | 177 } |
| 174 | 178 |
| 175 // For camera and microphone, we do not have policy exceptions, but we do have | 179 // For camera and microphone, we do not have policy exceptions, but we do have |
| 176 // the policy-set allowed URLs, which should be displayed in the same manner. | 180 // the policy-set allowed URLs, which should be displayed in the same manner. |
| 177 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 181 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 178 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 182 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 179 auto& policy_exceptions = all_provider_exceptions | 183 auto& policy_exceptions = all_provider_exceptions |
| 180 [HostContentSettingsMap::GetProviderTypeFromSource(kPolicyProviderId)]; | 184 [HostContentSettingsMap::GetProviderTypeFromSource(kPolicyProviderId)]; |
| 181 DCHECK(policy_exceptions.empty()); | 185 DCHECK(policy_exceptions.empty()); |
| 182 GetPolicyAllowedUrls(type, &policy_exceptions, web_ui); | 186 GetPolicyAllowedUrls(type, &policy_exceptions, web_ui, incognito); |
| 183 } | 187 } |
| 184 | 188 |
| 185 for (auto& one_provider_exceptions : all_provider_exceptions) { | 189 for (auto& one_provider_exceptions : all_provider_exceptions) { |
| 186 for (auto& exception : one_provider_exceptions) | 190 for (auto& exception : one_provider_exceptions) |
| 187 exceptions->Append(std::move(exception)); | 191 exceptions->Append(std::move(exception)); |
| 188 } | 192 } |
| 189 } | 193 } |
| 190 | 194 |
| 191 void GetPolicyAllowedUrls( | 195 void GetPolicyAllowedUrls( |
| 192 ContentSettingsType type, | 196 ContentSettingsType type, |
| 193 std::vector<std::unique_ptr<base::DictionaryValue>>* exceptions, | 197 std::vector<std::unique_ptr<base::DictionaryValue>>* exceptions, |
| 194 content::WebUI* web_ui) { | 198 content::WebUI* web_ui, |
| 199 bool incognito) { | |
| 195 DCHECK(type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 200 DCHECK(type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 196 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 201 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 197 | 202 |
| 198 PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); | 203 PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); |
| 199 const base::ListValue* policy_urls = prefs->GetList( | 204 const base::ListValue* policy_urls = prefs->GetList( |
| 200 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | 205 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC |
| 201 ? prefs::kAudioCaptureAllowedUrls | 206 ? prefs::kAudioCaptureAllowedUrls |
| 202 : prefs::kVideoCaptureAllowedUrls); | 207 : prefs::kVideoCaptureAllowedUrls); |
| 203 | 208 |
| 204 // Convert the URLs to |ContentSettingsPattern|s. Ignore any invalid ones. | 209 // Convert the URLs to |ContentSettingsPattern|s. Ignore any invalid ones. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 217 } | 222 } |
| 218 | 223 |
| 219 // The patterns are shown in the UI in a reverse order defined by | 224 // The patterns are shown in the UI in a reverse order defined by |
| 220 // |ContentSettingsPattern::operator<|. | 225 // |ContentSettingsPattern::operator<|. |
| 221 std::sort( | 226 std::sort( |
| 222 patterns.begin(), patterns.end(), std::greater<ContentSettingsPattern>()); | 227 patterns.begin(), patterns.end(), std::greater<ContentSettingsPattern>()); |
| 223 | 228 |
| 224 for (const ContentSettingsPattern& pattern : patterns) { | 229 for (const ContentSettingsPattern& pattern : patterns) { |
| 225 exceptions->push_back(GetExceptionForPage(pattern, ContentSettingsPattern(), | 230 exceptions->push_back(GetExceptionForPage(pattern, ContentSettingsPattern(), |
| 226 CONTENT_SETTING_ALLOW, | 231 CONTENT_SETTING_ALLOW, |
| 227 kPolicyProviderId)); | 232 kPolicyProviderId, incognito)); |
| 228 } | 233 } |
| 229 } | 234 } |
| 230 | 235 |
| 231 const ChooserTypeNameEntry* ChooserTypeFromGroupName(const std::string& name) { | 236 const ChooserTypeNameEntry* ChooserTypeFromGroupName(const std::string& name) { |
| 232 for (const auto& chooser_type : kChooserTypeGroupNames) { | 237 for (const auto& chooser_type : kChooserTypeGroupNames) { |
| 233 if (chooser_type.name == name) | 238 if (chooser_type.name == name) |
| 234 return &chooser_type; | 239 return &chooser_type; |
| 235 } | 240 } |
| 236 return nullptr; | 241 return nullptr; |
| 237 } | 242 } |
| 238 | 243 |
| 239 // Create a DictionaryValue* that will act as a data source for a single row | 244 // Create a DictionaryValue* that will act as a data source for a single row |
| 240 // in a chooser permission exceptions table. | 245 // in a chooser permission exceptions table. |
| 241 std::unique_ptr<base::DictionaryValue> GetChooserExceptionForPage( | 246 std::unique_ptr<base::DictionaryValue> GetChooserExceptionForPage( |
| 242 const GURL& requesting_origin, | 247 const GURL& requesting_origin, |
| 243 const GURL& embedding_origin, | 248 const GURL& embedding_origin, |
| 244 const std::string& provider_name, | 249 const std::string& provider_name, |
| 250 bool incognito, | |
| 245 const std::string& name, | 251 const std::string& name, |
| 246 const base::DictionaryValue* object) { | 252 const base::DictionaryValue* object) { |
| 247 std::unique_ptr<base::DictionaryValue> exception(new base::DictionaryValue()); | 253 std::unique_ptr<base::DictionaryValue> exception(new base::DictionaryValue()); |
| 248 | 254 |
| 249 std::string setting_string = | 255 std::string setting_string = |
| 250 content_settings::ContentSettingToString(CONTENT_SETTING_DEFAULT); | 256 content_settings::ContentSettingToString(CONTENT_SETTING_DEFAULT); |
| 251 DCHECK(!setting_string.empty()); | 257 DCHECK(!setting_string.empty()); |
| 252 | 258 |
| 253 exception->SetString(site_settings::kSetting, setting_string); | 259 exception->SetString(site_settings::kSetting, setting_string); |
| 254 exception->SetString(site_settings::kOrigin, requesting_origin.spec()); | 260 exception->SetString(site_settings::kOrigin, requesting_origin.spec()); |
| 255 exception->SetString( | 261 exception->SetString( |
| 256 site_settings::kEmbeddingOrigin, embedding_origin.spec()); | 262 site_settings::kEmbeddingOrigin, embedding_origin.spec()); |
| 257 exception->SetString(site_settings::kSource, provider_name); | 263 exception->SetString(site_settings::kSource, provider_name); |
| 264 exception->SetBoolean(kIncognito, incognito); | |
|
stevenjb
2016/09/01 15:47:55
It *looks* like the only thing we use |incognito|
Finnur
2016/09/01 16:48:17
Correct.
We send down (to .js) a single Array<Si
stevenjb
2016/09/01 17:07:54
I was suggesting (1). I don't think the inefficien
| |
| 258 if (object) { | 265 if (object) { |
| 259 exception->SetString(kObjectName, name); | 266 exception->SetString(kObjectName, name); |
| 260 exception->Set(kObject, object->CreateDeepCopy()); | 267 exception->Set(kObject, object->CreateDeepCopy()); |
| 261 } | 268 } |
| 262 return exception; | 269 return exception; |
| 263 } | 270 } |
| 264 | 271 |
| 265 void GetChooserExceptionsFromProfile( | 272 void GetChooserExceptionsFromProfile( |
| 266 Profile* profile, | 273 Profile* profile, |
| 267 bool incognito, | 274 bool incognito, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 const SortedObjects& sorted_objects = one_origin_objects_entry.second; | 316 const SortedObjects& sorted_objects = one_origin_objects_entry.second; |
| 310 | 317 |
| 311 // Skip the embedded settings which will be added below. | 318 // Skip the embedded settings which will be added below. |
| 312 if (requesting_origin != embedding_origin) { | 319 if (requesting_origin != embedding_origin) { |
| 313 has_embedded_entries = true; | 320 has_embedded_entries = true; |
| 314 continue; | 321 continue; |
| 315 } | 322 } |
| 316 | 323 |
| 317 for (const auto& sorted_objects_entry : sorted_objects) { | 324 for (const auto& sorted_objects_entry : sorted_objects) { |
| 318 this_provider_exceptions.push_back(GetChooserExceptionForPage( | 325 this_provider_exceptions.push_back(GetChooserExceptionForPage( |
| 319 requesting_origin, embedding_origin, source, | 326 requesting_origin, embedding_origin, source, incognito, |
| 320 sorted_objects_entry.first, sorted_objects_entry.second)); | 327 sorted_objects_entry.first, |
| 328 sorted_objects_entry.second)); | |
| 321 } | 329 } |
| 322 } | 330 } |
| 323 | 331 |
| 324 if (has_embedded_entries) { | 332 if (has_embedded_entries) { |
| 325 // Add a "parent" entry that simply acts as a heading for all entries | 333 // Add a "parent" entry that simply acts as a heading for all entries |
| 326 // where |requesting_origin| has been embedded. | 334 // where |requesting_origin| has been embedded. |
| 327 this_provider_exceptions.push_back( | 335 this_provider_exceptions.push_back( |
| 328 GetChooserExceptionForPage(requesting_origin, requesting_origin, | 336 GetChooserExceptionForPage(requesting_origin, requesting_origin, |
| 329 source, std::string(), nullptr)); | 337 source, incognito, std::string(), |
| 338 nullptr)); | |
| 330 | 339 |
| 331 // Add the "children" for any embedded settings. | 340 // Add the "children" for any embedded settings. |
| 332 for (const auto& one_origin_objects_entry : one_origin_objects) { | 341 for (const auto& one_origin_objects_entry : one_origin_objects) { |
| 333 const GURL& embedding_origin = one_origin_objects_entry.first; | 342 const GURL& embedding_origin = one_origin_objects_entry.first; |
| 334 const SortedObjects& sorted_objects = one_origin_objects_entry.second; | 343 const SortedObjects& sorted_objects = one_origin_objects_entry.second; |
| 335 | 344 |
| 336 // Skip the non-embedded setting which we already added above. | 345 // Skip the non-embedded setting which we already added above. |
| 337 if (requesting_origin == embedding_origin) | 346 if (requesting_origin == embedding_origin) |
| 338 continue; | 347 continue; |
| 339 | 348 |
| 340 for (const auto& sorted_objects_entry : sorted_objects) { | 349 for (const auto& sorted_objects_entry : sorted_objects) { |
| 341 this_provider_exceptions.push_back(GetChooserExceptionForPage( | 350 this_provider_exceptions.push_back(GetChooserExceptionForPage( |
| 342 requesting_origin, embedding_origin, source, | 351 requesting_origin, embedding_origin, source, incognito, |
| 343 sorted_objects_entry.first, sorted_objects_entry.second)); | 352 sorted_objects_entry.first, sorted_objects_entry.second)); |
| 344 } | 353 } |
| 345 } | 354 } |
| 346 } | 355 } |
| 347 } | 356 } |
| 348 | 357 |
| 349 for (auto& one_provider_exceptions : all_provider_exceptions) { | 358 for (auto& one_provider_exceptions : all_provider_exceptions) { |
| 350 for (auto& exception : one_provider_exceptions) | 359 for (auto& exception : one_provider_exceptions) |
| 351 exceptions->Append(std::move(exception)); | 360 exceptions->Append(std::move(exception)); |
| 352 } | 361 } |
| 353 } | 362 } |
| 354 | 363 |
| 355 } // namespace site_settings | 364 } // namespace site_settings |
| OLD | NEW |