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

Side by Side Diff: chrome/browser/content_settings/content_settings_utils.cc

Issue 8334020: Check for default content setting pattern when requiring user authorization for plug-ins. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 9 years, 2 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/content_settings/content_settings_utils.h" 5 #include "chrome/browser/content_settings/content_settings_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 *setting = CONTENT_SETTING_DEFAULT; 113 *setting = CONTENT_SETTING_DEFAULT;
114 return true; 114 return true;
115 } 115 }
116 int int_value = -1; 116 int int_value = -1;
117 if (!value->GetAsInteger(&int_value)) 117 if (!value->GetAsInteger(&int_value))
118 return false; 118 return false;
119 *setting = IntToContentSetting(int_value); 119 *setting = IntToContentSetting(int_value);
120 return *setting != CONTENT_SETTING_DEFAULT; 120 return *setting != CONTENT_SETTING_DEFAULT;
121 } 121 }
122 122
123 base::Value* GetContentSettingValueAndPatterns(
124 const ProviderInterface* provider,
125 const GURL& primary_url,
126 const GURL& secondary_url,
127 ContentSettingsType content_type,
128 const std::string& resource_identifier,
129 bool include_incognito,
130 ContentSettingsPattern* primary_pattern,
131 ContentSettingsPattern* secondary_pattern) {
132 if (include_incognito) {
133 // Check incognito-only specific settings. It's essential that the
134 // |RuleIterator| gets out of scope before we get a rule iterator for the
135 // normal mode.
136 scoped_ptr<RuleIterator> incognito_rule_iterator(
137 provider->GetRuleIterator(content_type, resource_identifier, true));
138 base::Value* value = GetContentSettingValueAndPatterns(
139 incognito_rule_iterator.get(), primary_url, secondary_url,
140 primary_pattern, secondary_pattern);
141 if (value)
142 return value;
143 }
144 // No settings from the incognito; use the normal mode.
145 scoped_ptr<RuleIterator> rule_iterator(
146 provider->GetRuleIterator(content_type, resource_identifier, false));
147 return GetContentSettingValueAndPatterns(
148 rule_iterator.get(), primary_url, secondary_url,
149 primary_pattern, secondary_pattern);
150 }
151
152 base::Value* GetContentSettingValueAndPatterns(
153 RuleIterator* rule_iterator,
154 const GURL& primary_url,
155 const GURL& secondary_url,
156 ContentSettingsPattern* primary_pattern,
157 ContentSettingsPattern* secondary_pattern) {
158 while (rule_iterator->HasNext()) {
159 const Rule& rule = rule_iterator->Next();
160 if (rule.primary_pattern.Matches(primary_url) &&
161 rule.secondary_pattern.Matches(secondary_url)) {
162 if (primary_pattern)
163 *primary_pattern = rule.primary_pattern;
164 if (secondary_pattern)
165 *secondary_pattern = rule.secondary_pattern;
166 return rule.value.get()->DeepCopy();
167 }
168 }
169 return NULL;
170 }
171
123 base::Value* GetContentSettingValue(const ProviderInterface* provider, 172 base::Value* GetContentSettingValue(const ProviderInterface* provider,
124 const GURL& primary_url, 173 const GURL& primary_url,
125 const GURL& secondary_url, 174 const GURL& secondary_url,
126 ContentSettingsType content_type, 175 ContentSettingsType content_type,
127 const std::string& resource_identifier, 176 const std::string& resource_identifier,
128 bool include_incognito) { 177 bool include_incognito) {
129 if (include_incognito) { 178 return GetContentSettingValueAndPatterns(provider, primary_url, secondary_url,
130 // Check incognito-only specific settings. It's essential that the 179 content_type, resource_identifier,
131 // |RuleIterator| gets out of scope before we get a rule iterator for the 180 include_incognito, NULL, NULL);
132 // normal mode.
133 scoped_ptr<RuleIterator> incognito_rule_iterator(
134 provider->GetRuleIterator(content_type, resource_identifier, true));
135 base::Value* value = GetContentSettingValue(
136 incognito_rule_iterator.get(), primary_url, secondary_url);
137 if (value)
138 return value;
139 }
140 // No settings from the incognito; use the normal mode.
141 scoped_ptr<RuleIterator> rule_iterator(
142 provider->GetRuleIterator(content_type, resource_identifier, false));
143 return GetContentSettingValue(
144 rule_iterator.get(), primary_url, secondary_url);
145 } 181 }
146 182
147 ContentSetting GetContentSetting(const ProviderInterface* provider, 183 ContentSetting GetContentSetting(const ProviderInterface* provider,
148 const GURL& primary_url, 184 const GURL& primary_url,
149 const GURL& secondary_url, 185 const GURL& secondary_url,
150 ContentSettingsType content_type, 186 ContentSettingsType content_type,
151 const std::string& resource_identifier, 187 const std::string& resource_identifier,
152 bool include_incognito) { 188 bool include_incognito) {
153 if (include_incognito) { 189 scoped_ptr<base::Value> value(
154 // Check incognito-only specific settings. It's essential that the 190 GetContentSettingValue(provider, primary_url, secondary_url,
155 // |RuleIterator| gets out of scope before we get a rule iterator for the 191 content_type, resource_identifier,
156 // normal mode. 192 include_incognito));
157 scoped_ptr<RuleIterator> incognito_rule_iterator( 193 return ValueToContentSetting(value.get());
158 provider->GetRuleIterator(content_type, resource_identifier, true));
159 ContentSetting setting = GetContentSetting(
160 incognito_rule_iterator.get(), primary_url, secondary_url);
161 if (setting != CONTENT_SETTING_DEFAULT)
162 return setting;
163 }
164 // No settings from the incognito; use the normal mode.
165 scoped_ptr<RuleIterator> rule_iterator(
166 provider->GetRuleIterator(content_type, resource_identifier, false));
167 return GetContentSetting(rule_iterator.get(), primary_url, secondary_url);
168 }
169
170 base::Value* GetContentSettingValue(RuleIterator* rule_iterator,
171 const GURL& primary_url,
172 const GURL& secondary_url) {
173 while (rule_iterator->HasNext()) {
174 const Rule& rule = rule_iterator->Next();
175 if (rule.primary_pattern.Matches(primary_url) &&
176 rule.secondary_pattern.Matches(secondary_url)) {
177 return rule.value.get()->DeepCopy();
178 }
179 }
180 return NULL;
181 }
182
183 ContentSetting GetContentSetting(RuleIterator* rule_iterator,
184 const GURL& primary_url,
185 const GURL& secondary_url) {
186 while (rule_iterator->HasNext()) {
187 const Rule& rule = rule_iterator->Next();
188 if (rule.primary_pattern.Matches(primary_url) &&
189 rule.secondary_pattern.Matches(secondary_url)) {
190 return ValueToContentSetting(rule.value.get());
191 }
192 }
193 return CONTENT_SETTING_DEFAULT;
194 } 194 }
195 195
196 } // namespace content_settings 196 } // namespace content_settings
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/content_settings_utils.h ('k') | chrome/browser/content_settings/host_content_settings_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698