| 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/values.h" | 8 #include "base/values.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 10 #include "components/content_settings/core/browser/host_content_settings_map.h" | 11 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 11 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
| 12 | 13 |
| 13 namespace site_settings { | 14 namespace site_settings { |
| 14 | 15 |
| 15 const char kSetting[] = "setting"; | 16 const char kSetting[] = "setting"; |
| 16 const char kOrigin[] = "origin"; | 17 const char kOrigin[] = "origin"; |
| 17 const char kPolicyProviderId[] = "policy"; | 18 const char kPolicyProviderId[] = "policy"; |
| 18 const char kSource[] = "source"; | 19 const char kSource[] = "source"; |
| 19 const char kEmbeddingOrigin[] = "embeddingOrigin"; | 20 const char kEmbeddingOrigin[] = "embeddingOrigin"; |
| 20 const char kPreferencesSource[] = "preference"; | 21 const char kPreferencesSource[] = "preference"; |
| 21 | 22 |
| 22 // Create a DictionaryValue* that will act as a data source for a single row | 23 // Create a DictionaryValue* that will act as a data source for a single row |
| 23 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). | 24 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). |
| 24 scoped_ptr<base::DictionaryValue> GetExceptionForPage( | 25 std::unique_ptr<base::DictionaryValue> GetExceptionForPage( |
| 25 const ContentSettingsPattern& pattern, | 26 const ContentSettingsPattern& pattern, |
| 26 const ContentSettingsPattern& secondary_pattern, | 27 const ContentSettingsPattern& secondary_pattern, |
| 27 const ContentSetting& setting, | 28 const ContentSetting& setting, |
| 28 const std::string& provider_name) { | 29 const std::string& provider_name) { |
| 29 base::DictionaryValue* exception = new base::DictionaryValue(); | 30 base::DictionaryValue* exception = new base::DictionaryValue(); |
| 30 exception->SetString(kOrigin, pattern.ToString()); | 31 exception->SetString(kOrigin, pattern.ToString()); |
| 31 exception->SetString(kEmbeddingOrigin, | 32 exception->SetString(kEmbeddingOrigin, |
| 32 secondary_pattern == ContentSettingsPattern::Wildcard() ? | 33 secondary_pattern == ContentSettingsPattern::Wildcard() ? |
| 33 std::string() : | 34 std::string() : |
| 34 secondary_pattern.ToString()); | 35 secondary_pattern.ToString()); |
| 35 | 36 |
| 36 std::string setting_string = | 37 std::string setting_string = |
| 37 content_settings::ContentSettingToString(setting); | 38 content_settings::ContentSettingToString(setting); |
| 38 DCHECK(!setting_string.empty()); | 39 DCHECK(!setting_string.empty()); |
| 39 | 40 |
| 40 exception->SetString(kSetting, setting_string); | 41 exception->SetString(kSetting, setting_string); |
| 41 exception->SetString(kSource, provider_name); | 42 exception->SetString(kSource, provider_name); |
| 42 return make_scoped_ptr(exception); | 43 return base::WrapUnique(exception); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void GetExceptionsFromHostContentSettingsMap(const HostContentSettingsMap* map, | 46 void GetExceptionsFromHostContentSettingsMap(const HostContentSettingsMap* map, |
| 46 ContentSettingsType type, | 47 ContentSettingsType type, |
| 47 content::WebUI* web_ui, | 48 content::WebUI* web_ui, |
| 48 base::ListValue* exceptions) { | 49 base::ListValue* exceptions) { |
| 49 ContentSettingsForOneType entries; | 50 ContentSettingsForOneType entries; |
| 50 map->GetSettingsForOneType(type, std::string(), &entries); | 51 map->GetSettingsForOneType(type, std::string(), &entries); |
| 51 // Group settings by primary_pattern. | 52 // Group settings by primary_pattern. |
| 52 AllPatternsSettings all_patterns_settings; | 53 AllPatternsSettings all_patterns_settings; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 // only. | 65 // only. |
| 65 if (map->is_off_the_record() && !i->incognito) | 66 if (map->is_off_the_record() && !i->incognito) |
| 66 continue; | 67 continue; |
| 67 | 68 |
| 68 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] | 69 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] |
| 69 [i->secondary_pattern] = i->setting; | 70 [i->secondary_pattern] = i->setting; |
| 70 } | 71 } |
| 71 | 72 |
| 72 // Keep the exceptions sorted by provider so they will be displayed in | 73 // Keep the exceptions sorted by provider so they will be displayed in |
| 73 // precedence order. | 74 // precedence order. |
| 74 std::vector<scoped_ptr<base::DictionaryValue>> | 75 std::vector<std::unique_ptr<base::DictionaryValue>> |
| 75 all_provider_exceptions[HostContentSettingsMap::NUM_PROVIDER_TYPES]; | 76 all_provider_exceptions[HostContentSettingsMap::NUM_PROVIDER_TYPES]; |
| 76 | 77 |
| 77 // |all_patterns_settings| is sorted from the lowest precedence pattern to | 78 // |all_patterns_settings| is sorted from the lowest precedence pattern to |
| 78 // the highest (see operator< in ContentSettingsPattern), so traverse it in | 79 // the highest (see operator< in ContentSettingsPattern), so traverse it in |
| 79 // reverse to show the patterns with the highest precedence (the more specific | 80 // reverse to show the patterns with the highest precedence (the more specific |
| 80 // ones) on the top. | 81 // ones) on the top. |
| 81 for (AllPatternsSettings::reverse_iterator i = all_patterns_settings.rbegin(); | 82 for (AllPatternsSettings::reverse_iterator i = all_patterns_settings.rbegin(); |
| 82 i != all_patterns_settings.rend(); | 83 i != all_patterns_settings.rend(); |
| 83 ++i) { | 84 ++i) { |
| 84 const ContentSettingsPattern& primary_pattern = i->first.first; | 85 const ContentSettingsPattern& primary_pattern = i->first.first; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 129 } |
| 129 | 130 |
| 130 for (auto& one_provider_exceptions : all_provider_exceptions) { | 131 for (auto& one_provider_exceptions : all_provider_exceptions) { |
| 131 for (auto& exception : one_provider_exceptions) | 132 for (auto& exception : one_provider_exceptions) |
| 132 exceptions->Append(std::move(exception)); | 133 exceptions->Append(std::move(exception)); |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 | 136 |
| 136 void GetPolicyAllowedUrls( | 137 void GetPolicyAllowedUrls( |
| 137 ContentSettingsType type, | 138 ContentSettingsType type, |
| 138 std::vector<scoped_ptr<base::DictionaryValue>>* exceptions, | 139 std::vector<std::unique_ptr<base::DictionaryValue>>* exceptions, |
| 139 content::WebUI* web_ui) { | 140 content::WebUI* web_ui) { |
| 140 DCHECK(type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 141 DCHECK(type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 141 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 142 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 142 | 143 |
| 143 PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); | 144 PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); |
| 144 const base::ListValue* policy_urls = prefs->GetList( | 145 const base::ListValue* policy_urls = prefs->GetList( |
| 145 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | 146 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC |
| 146 ? prefs::kAudioCaptureAllowedUrls | 147 ? prefs::kAudioCaptureAllowedUrls |
| 147 : prefs::kVideoCaptureAllowedUrls); | 148 : prefs::kVideoCaptureAllowedUrls); |
| 148 | 149 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 167 patterns.begin(), patterns.end(), std::greater<ContentSettingsPattern>()); | 168 patterns.begin(), patterns.end(), std::greater<ContentSettingsPattern>()); |
| 168 | 169 |
| 169 for (const ContentSettingsPattern& pattern : patterns) { | 170 for (const ContentSettingsPattern& pattern : patterns) { |
| 170 exceptions->push_back(GetExceptionForPage(pattern, ContentSettingsPattern(), | 171 exceptions->push_back(GetExceptionForPage(pattern, ContentSettingsPattern(), |
| 171 CONTENT_SETTING_ALLOW, | 172 CONTENT_SETTING_ALLOW, |
| 172 kPolicyProviderId)); | 173 kPolicyProviderId)); |
| 173 } | 174 } |
| 174 } | 175 } |
| 175 | 176 |
| 176 } // namespace site_settings | 177 } // namespace site_settings |
| OLD | NEW |