Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: components/content_settings/core/browser/content_settings_utils.cc

Issue 1442083002: Stop inheriting push notification permissions from regular to incognito (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review nits Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/content_settings/core/browser/content_settings_utils.h" 5 #include "components/content_settings/core/browser/content_settings_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
12 #include "base/prefs/pref_registry.h"
13 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
14 #include "base/values.h" 12 #include "base/values.h"
15 #include "components/content_settings/core/browser/content_settings_provider.h"
16 #include "components/content_settings/core/browser/content_settings_rule.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h" 13 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "components/content_settings/core/browser/website_settings_info.h"
19 #include "components/content_settings/core/browser/website_settings_registry.h"
20 #include "components/content_settings/core/common/content_settings_pattern.h"
21 #include "components/pref_registry/pref_registry_syncable.h"
22 #include "url/gurl.h"
23 14
24 namespace { 15 namespace {
25 16
26 const char kPatternSeparator[] = ","; 17 const char kPatternSeparator[] = ",";
27 18
28 struct ContentSettingsStringMapping { 19 struct ContentSettingsStringMapping {
29 ContentSetting content_setting; 20 ContentSetting content_setting;
30 const char* content_setting_str; 21 const char* content_setting_str;
31 }; 22 };
32 const ContentSettingsStringMapping kContentSettingsStringMapping[] = { 23 const ContentSettingsStringMapping kContentSettingsStringMapping[] = {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 120 }
130 121
131 scoped_ptr<base::Value> ContentSettingToValue(ContentSetting setting) { 122 scoped_ptr<base::Value> ContentSettingToValue(ContentSetting setting) {
132 if (setting <= CONTENT_SETTING_DEFAULT || 123 if (setting <= CONTENT_SETTING_DEFAULT ||
133 setting >= CONTENT_SETTING_NUM_SETTINGS) { 124 setting >= CONTENT_SETTING_NUM_SETTINGS) {
134 return nullptr; 125 return nullptr;
135 } 126 }
136 return make_scoped_ptr(new base::FundamentalValue(setting)); 127 return make_scoped_ptr(new base::FundamentalValue(setting));
137 } 128 }
138 129
139 base::Value* GetContentSettingValueAndPatterns(
140 const ProviderInterface* provider,
141 const GURL& primary_url,
142 const GURL& secondary_url,
143 ContentSettingsType content_type,
144 const std::string& resource_identifier,
145 bool include_incognito,
146 ContentSettingsPattern* primary_pattern,
147 ContentSettingsPattern* secondary_pattern) {
148 if (include_incognito) {
149 // Check incognito-only specific settings. It's essential that the
150 // |RuleIterator| gets out of scope before we get a rule iterator for the
151 // normal mode.
152 scoped_ptr<RuleIterator> incognito_rule_iterator(
153 provider->GetRuleIterator(content_type, resource_identifier, true));
154 base::Value* value = GetContentSettingValueAndPatterns(
155 incognito_rule_iterator.get(), primary_url, secondary_url,
156 primary_pattern, secondary_pattern);
157 if (value)
158 return value;
159 }
160 // No settings from the incognito; use the normal mode.
161 scoped_ptr<RuleIterator> rule_iterator(
162 provider->GetRuleIterator(content_type, resource_identifier, false));
163 return GetContentSettingValueAndPatterns(
164 rule_iterator.get(), primary_url, secondary_url,
165 primary_pattern, secondary_pattern);
166 }
167
168 base::Value* GetContentSettingValueAndPatterns(
169 RuleIterator* rule_iterator,
170 const GURL& primary_url,
171 const GURL& secondary_url,
172 ContentSettingsPattern* primary_pattern,
173 ContentSettingsPattern* secondary_pattern) {
174 while (rule_iterator->HasNext()) {
175 const Rule& rule = rule_iterator->Next();
176 if (rule.primary_pattern.Matches(primary_url) &&
177 rule.secondary_pattern.Matches(secondary_url)) {
178 if (primary_pattern)
179 *primary_pattern = rule.primary_pattern;
180 if (secondary_pattern)
181 *secondary_pattern = rule.secondary_pattern;
182 return rule.value.get()->DeepCopy();
183 }
184 }
185 return NULL;
186 }
187
188 void GetRendererContentSettingRules(const HostContentSettingsMap* map, 130 void GetRendererContentSettingRules(const HostContentSettingsMap* map,
189 RendererContentSettingRules* rules) { 131 RendererContentSettingRules* rules) {
190 map->GetSettingsForOneType( 132 map->GetSettingsForOneType(
191 CONTENT_SETTINGS_TYPE_IMAGES, 133 CONTENT_SETTINGS_TYPE_IMAGES,
192 ResourceIdentifier(), 134 ResourceIdentifier(),
193 &(rules->image_rules)); 135 &(rules->image_rules));
194 map->GetSettingsForOneType( 136 map->GetSettingsForOneType(
195 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 137 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
196 ResourceIdentifier(), 138 ResourceIdentifier(),
197 &(rules->script_rules)); 139 &(rules->script_rules));
198 } 140 }
199 141
200 } // namespace content_settings 142 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698