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 <functional> |
| 8 #include <string> |
| 9 |
7 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
8 #include "base/values.h" | 11 #include "base/values.h" |
9 #include "chrome/browser/permissions/chooser_context_base.h" | 12 #include "chrome/browser/permissions/chooser_context_base.h" |
10 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/usb/usb_chooser_context_factory.h" | 14 #include "chrome/browser/usb/usb_chooser_context_factory.h" |
12 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
13 #include "components/content_settings/core/browser/host_content_settings_map.h" | 16 #include "components/content_settings/core/browser/host_content_settings_map.h" |
14 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
15 | 18 |
16 namespace site_settings { | 19 namespace site_settings { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 exception->SetString(kSetting, setting_string); | 100 exception->SetString(kSetting, setting_string); |
98 exception->SetString(kSource, provider_name); | 101 exception->SetString(kSource, provider_name); |
99 exception->SetBoolean(kIncognito, incognito); | 102 exception->SetBoolean(kIncognito, incognito); |
100 return base::WrapUnique(exception); | 103 return base::WrapUnique(exception); |
101 } | 104 } |
102 | 105 |
103 void GetExceptionsFromHostContentSettingsMap(const HostContentSettingsMap* map, | 106 void GetExceptionsFromHostContentSettingsMap(const HostContentSettingsMap* map, |
104 ContentSettingsType type, | 107 ContentSettingsType type, |
105 content::WebUI* web_ui, | 108 content::WebUI* web_ui, |
106 bool incognito, | 109 bool incognito, |
| 110 const std::string* filter, |
107 base::ListValue* exceptions) { | 111 base::ListValue* exceptions) { |
108 ContentSettingsForOneType entries; | 112 ContentSettingsForOneType entries; |
109 map->GetSettingsForOneType(type, std::string(), &entries); | 113 map->GetSettingsForOneType(type, std::string(), &entries); |
110 // Group settings by primary_pattern. | 114 // Group settings by primary_pattern. |
111 AllPatternsSettings all_patterns_settings; | 115 AllPatternsSettings all_patterns_settings; |
112 for (ContentSettingsForOneType::iterator i = entries.begin(); | 116 for (ContentSettingsForOneType::iterator i = entries.begin(); |
113 i != entries.end(); ++i) { | 117 i != entries.end(); ++i) { |
114 // Don't add default settings. | 118 // Don't add default settings. |
115 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && | 119 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && |
116 i->secondary_pattern == ContentSettingsPattern::Wildcard() && | 120 i->secondary_pattern == ContentSettingsPattern::Wildcard() && |
117 i->source != kPreferencesSource) { | 121 i->source != kPreferencesSource) { |
118 continue; | 122 continue; |
119 } | 123 } |
120 | 124 |
121 // Off-the-record HostContentSettingsMap contains incognito content settings | 125 // Off-the-record HostContentSettingsMap contains incognito content settings |
122 // as well as normal content settings. Here, we use the incongnito settings | 126 // as well as normal content settings. Here, we use the incongnito settings |
123 // only. | 127 // only. |
124 if (map->is_off_the_record() && !i->incognito) | 128 if (map->is_off_the_record() && !i->incognito) |
125 continue; | 129 continue; |
126 | 130 |
| 131 if (filter && i->primary_pattern.ToString() != *filter) |
| 132 continue; |
| 133 |
127 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] | 134 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] |
128 [i->secondary_pattern] = i->setting; | 135 [i->secondary_pattern] = i->setting; |
129 } | 136 } |
130 | 137 |
131 // Keep the exceptions sorted by provider so they will be displayed in | 138 // Keep the exceptions sorted by provider so they will be displayed in |
132 // precedence order. | 139 // precedence order. |
133 std::vector<std::unique_ptr<base::DictionaryValue>> | 140 std::vector<std::unique_ptr<base::DictionaryValue>> |
134 all_provider_exceptions[HostContentSettingsMap::NUM_PROVIDER_TYPES]; | 141 all_provider_exceptions[HostContentSettingsMap::NUM_PROVIDER_TYPES]; |
135 | 142 |
136 // |all_patterns_settings| is sorted from the lowest precedence pattern to | 143 // |all_patterns_settings| is sorted from the lowest precedence pattern to |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 } | 362 } |
356 } | 363 } |
357 | 364 |
358 for (auto& one_provider_exceptions : all_provider_exceptions) { | 365 for (auto& one_provider_exceptions : all_provider_exceptions) { |
359 for (auto& exception : one_provider_exceptions) | 366 for (auto& exception : one_provider_exceptions) |
360 exceptions->Append(std::move(exception)); | 367 exceptions->Append(std::move(exception)); |
361 } | 368 } |
362 } | 369 } |
363 | 370 |
364 } // namespace site_settings | 371 } // namespace site_settings |
OLD | NEW |