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

Side by Side Diff: chrome/browser/host_content_settings_map.cc

Issue 2878075: Introduce a resource identifier for content settings. (Closed)
Patch Set: updates Created 10 years, 4 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/host_content_settings_map.h" 5 #include "chrome/browser/host_content_settings_map.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/chrome_thread.h" 10 #include "chrome/browser/chrome_thread.h"
(...skipping 14 matching lines...) Expand all
25 #include "net/base/static_cookie_policy.h" 25 #include "net/base/static_cookie_policy.h"
26 26
27 namespace { 27 namespace {
28 // The version of the pattern format implemented. Version 1 includes the 28 // The version of the pattern format implemented. Version 1 includes the
29 // following patterns: 29 // following patterns:
30 // - [*.]domain.tld (matches domain.tld and all sub-domains) 30 // - [*.]domain.tld (matches domain.tld and all sub-domains)
31 // - host (matches an exact hostname) 31 // - host (matches an exact hostname)
32 // - a.b.c.d (matches an exact IPv4 ip) 32 // - a.b.c.d (matches an exact IPv4 ip)
33 // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip) 33 // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip)
34 // - file:///tmp/test.html (a complete URL without a host) 34 // - file:///tmp/test.html (a complete URL without a host)
35 // Version 2 adds a resource identifier for plugins.
36 // TODO(jochen): update once this feature is no longer behind a flag.
35 const int kContentSettingsPatternVersion = 1; 37 const int kContentSettingsPatternVersion = 1;
36 38
37 // The format of a domain wildcard. 39 // The format of a domain wildcard.
38 const char kDomainWildcard[] = "[*.]"; 40 const char kDomainWildcard[] = "[*.]";
39 41
40 // The length of kDomainWildcard (without the trailing '\0') 42 // The length of kDomainWildcard (without the trailing '\0')
41 const size_t kDomainWildcardLength = arraysize(kDomainWildcard) - 1; 43 const size_t kDomainWildcardLength = arraysize(kDomainWildcard) - 1;
42 44
45 // The preference keys where resource identifiers are stored for
46 // ContentSettingsType values that support resource identifiers.
47 const char* kResourceTypeNames[CONTENT_SETTINGS_NUM_TYPES] = {
48 NULL,
49 NULL,
50 NULL,
51 "per_plugin",
52 NULL,
53 NULL, // Not used for Geolocation
54 NULL, // Not used for Notifications
55 };
56
57 // The names of the ContentSettingsType values, for use with dictionary prefs.
58 const char* kTypeNames[CONTENT_SETTINGS_NUM_TYPES] = {
59 "cookies",
60 "images",
61 "javascript",
62 "plugins",
63 "popups",
64 NULL, // Not used for Geolocation
65 NULL, // Not used for Notifications
66 };
67
68 // The default setting for each content type.
69 const ContentSetting kDefaultSettings[CONTENT_SETTINGS_NUM_TYPES] = {
70 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES
71 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES
72 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT
73 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS
74 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS
75 CONTENT_SETTING_ASK, // Not used for Geolocation
76 CONTENT_SETTING_ASK, // Not used for Notifications
77 };
78
79 // True if a given content settings type requires additional resource
80 // identifiers.
81 const bool kRequiresResourceIdentifier[CONTENT_SETTINGS_NUM_TYPES] = {
82 false, // CONTENT_SETTINGS_TYPE_COOKIES
83 false, // CONTENT_SETTINGS_TYPE_IMAGES
84 false, // CONTENT_SETTINGS_TYPE_JAVASCRIPT
85 true, // CONTENT_SETTINGS_TYPE_PLUGINS
86 false, // CONTENT_SETTINGS_TYPE_POPUPS
87 false, // Not used for Geolocation
88 false, // Not used for Notifications
89 };
90
91 // Returns true if we should allow all content types for this URL. This is
92 // true for various internal objects like chrome:// URLs, so UI and other
93 // things users think of as "not webpages" don't break.
94 static bool ShouldAllowAllContent(const GURL& url) {
95 return url.SchemeIs(chrome::kChromeInternalScheme) ||
96 url.SchemeIs(chrome::kChromeUIScheme) ||
97 url.SchemeIs(chrome::kExtensionScheme) ||
98 url.SchemeIs(chrome::kGearsScheme) ||
99 url.SchemeIs(chrome::kUserScriptScheme);
100 }
43 } // namespace 101 } // namespace
44 102
45 // static 103 // static
46 HostContentSettingsMap::Pattern HostContentSettingsMap::Pattern::FromURL( 104 HostContentSettingsMap::Pattern HostContentSettingsMap::Pattern::FromURL(
47 const GURL& url) { 105 const GURL& url) {
48 return Pattern(!url.has_host() || url.HostIsIPAddress() ? 106 return Pattern(!url.has_host() || url.HostIsIPAddress() ?
49 net::GetHostOrSpecFromURL(url) : 107 net::GetHostOrSpecFromURL(url) :
50 std::string(kDomainWildcard) + url.host()); 108 std::string(kDomainWildcard) + url.host());
51 } 109 }
52 110
(...skipping 26 matching lines...) Expand all
79 return pattern_ == host; 137 return pattern_ == host;
80 138
81 const size_t match = 139 const size_t match =
82 host.rfind(pattern_.substr(kDomainWildcardLength)); 140 host.rfind(pattern_.substr(kDomainWildcardLength));
83 141
84 return (match != std::string::npos) && 142 return (match != std::string::npos) &&
85 (match == 0 || host[match - 1] == '.') && 143 (match == 0 || host[match - 1] == '.') &&
86 (match + pattern_.length() - kDomainWildcardLength == host.length()); 144 (match + pattern_.length() - kDomainWildcardLength == host.length());
87 } 145 }
88 146
89 // static
90 const wchar_t*
91 HostContentSettingsMap::kTypeNames[CONTENT_SETTINGS_NUM_TYPES] = {
92 L"cookies",
93 L"images",
94 L"javascript",
95 L"plugins",
96 L"popups",
97 NULL, // Not used for Geolocation
98 NULL, // Not used for Notifications
99 };
100
101 // static
102 const ContentSetting
103 HostContentSettingsMap::kDefaultSettings[CONTENT_SETTINGS_NUM_TYPES] = {
104 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES
105 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES
106 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT
107 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS
108 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS
109 CONTENT_SETTING_ASK, // Not used for Geolocation
110 CONTENT_SETTING_ASK, // Not used for Notifications
111 };
112
113 HostContentSettingsMap::HostContentSettingsMap(Profile* profile) 147 HostContentSettingsMap::HostContentSettingsMap(Profile* profile)
114 : profile_(profile), 148 : profile_(profile),
115 block_third_party_cookies_(false), 149 block_third_party_cookies_(false),
116 is_off_the_record_(profile_->IsOffTheRecord()), 150 is_off_the_record_(profile_->IsOffTheRecord()),
117 updating_preferences_(false) { 151 updating_preferences_(false) {
118 PrefService* prefs = profile_->GetPrefs(); 152 PrefService* prefs = profile_->GetPrefs();
119 153
120 // Migrate obsolete cookie pref. 154 // Migrate obsolete cookie pref.
121 if (prefs->HasPrefPath(prefs::kCookieBehavior)) { 155 if (prefs->HasPrefPath(prefs::kCookieBehavior)) {
122 int cookie_behavior = prefs->GetInteger(prefs::kCookieBehavior); 156 int cookie_behavior = prefs->GetInteger(prefs::kCookieBehavior);
(...skipping 10 matching lines...) Expand all
133 } 167 }
134 168
135 // Migrate obsolete popups pref. 169 // Migrate obsolete popups pref.
136 if (prefs->HasPrefPath(prefs::kPopupWhitelistedHosts)) { 170 if (prefs->HasPrefPath(prefs::kPopupWhitelistedHosts)) {
137 const ListValue* whitelist_pref = 171 const ListValue* whitelist_pref =
138 prefs->GetList(prefs::kPopupWhitelistedHosts); 172 prefs->GetList(prefs::kPopupWhitelistedHosts);
139 for (ListValue::const_iterator i(whitelist_pref->begin()); 173 for (ListValue::const_iterator i(whitelist_pref->begin());
140 i != whitelist_pref->end(); ++i) { 174 i != whitelist_pref->end(); ++i) {
141 std::string host; 175 std::string host;
142 (*i)->GetAsString(&host); 176 (*i)->GetAsString(&host);
143 SetContentSetting(Pattern(host), CONTENT_SETTINGS_TYPE_POPUPS, 177 SetContentSetting(Pattern(host), CONTENT_SETTINGS_TYPE_POPUPS, "",
144 CONTENT_SETTING_ALLOW); 178 CONTENT_SETTING_ALLOW);
145 } 179 }
146 prefs->ClearPref(prefs::kPopupWhitelistedHosts); 180 prefs->ClearPref(prefs::kPopupWhitelistedHosts);
147 } 181 }
148 182
149 // Migrate obsolete per-host pref. 183 // Migrate obsolete per-host pref.
150 if (prefs->HasPrefPath(prefs::kPerHostContentSettings)) { 184 if (prefs->HasPrefPath(prefs::kPerHostContentSettings)) {
151 const DictionaryValue* all_settings_dictionary = 185 const DictionaryValue* all_settings_dictionary =
152 prefs->GetDictionary(prefs::kPerHostContentSettings); 186 prefs->GetDictionary(prefs::kPerHostContentSettings);
153 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); 187 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys());
154 i != all_settings_dictionary->end_keys(); ++i) { 188 i != all_settings_dictionary->end_keys(); ++i) {
155 const std::string& host(*i); 189 const std::string& host(*i);
156 Pattern pattern(std::string(kDomainWildcard) + host); 190 Pattern pattern(std::string(kDomainWildcard) + host);
157 DictionaryValue* host_settings_dictionary = NULL; 191 DictionaryValue* host_settings_dictionary = NULL;
158 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( 192 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion(
159 host, &host_settings_dictionary); 193 host, &host_settings_dictionary);
160 DCHECK(found); 194 DCHECK(found);
161 ContentSettings settings; 195 ContentSettings settings;
162 GetSettingsFromDictionary(host_settings_dictionary, &settings); 196 GetSettingsFromDictionary(host_settings_dictionary, &settings);
163 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { 197 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) {
164 if (settings.settings[j] != CONTENT_SETTING_DEFAULT) 198 if (settings.settings[j] != CONTENT_SETTING_DEFAULT &&
199 !RequiresResourceIdentifier(ContentSettingsType(j)))
165 SetContentSetting( 200 SetContentSetting(
166 pattern, ContentSettingsType(j), settings.settings[j]); 201 pattern, ContentSettingsType(j), "", settings.settings[j]);
167 } 202 }
168 } 203 }
169 prefs->ClearPref(prefs::kPerHostContentSettings); 204 prefs->ClearPref(prefs::kPerHostContentSettings);
170 } 205 }
171 206
172 // Read global defaults. 207 // Read global defaults.
173 DCHECK_EQ(arraysize(kTypeNames), 208 DCHECK_EQ(arraysize(kTypeNames),
174 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); 209 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES));
175 ReadDefaultSettings(false); 210 ReadDefaultSettings(false);
176 211
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } 251 }
217 252
218 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( 253 ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
219 ContentSettingsType content_type) const { 254 ContentSettingsType content_type) const {
220 AutoLock auto_lock(lock_); 255 AutoLock auto_lock(lock_);
221 return default_content_settings_.settings[content_type]; 256 return default_content_settings_.settings[content_type];
222 } 257 }
223 258
224 ContentSetting HostContentSettingsMap::GetContentSetting( 259 ContentSetting HostContentSettingsMap::GetContentSetting(
225 const GURL& url, 260 const GURL& url,
226 ContentSettingsType content_type) const { 261 ContentSettingsType content_type,
227 return GetContentSettings(url).settings[content_type]; 262 const std::string& resource_identifier) const {
263 ContentSetting setting = GetNonDefaultContentSetting(url,
264 content_type,
265 resource_identifier);
266 if (setting == CONTENT_SETTING_DEFAULT)
267 return GetDefaultContentSetting(content_type);
268 return setting;
269 }
270
271 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting(
272 const GURL& url,
273 ContentSettingsType content_type,
274 const std::string& resource_identifier) const {
275 if (ShouldAllowAllContent(url))
276 return CONTENT_SETTING_ALLOW;
277
278 if (!RequiresResourceIdentifier(content_type))
279 return GetNonDefaultContentSettings(url).settings[content_type];
280
281 if (CommandLine::ForCurrentProcess()->HasSwitch(
282 switches::kEnableClickToPlay)) {
283 DCHECK(!resource_identifier.empty());
284 }
285
286 AutoLock auto_lock(lock_);
287
288 const std::string host(net::GetHostOrSpecFromURL(url));
289 ContentSettingsTypeResourceIdentifierPair
290 requested_setting(content_type, resource_identifier);
291
292 // Check for exact matches first.
293 HostContentSettings::const_iterator i(host_content_settings_.find(host));
294 if (i != host_content_settings_.end() &&
295 i->second.content_settings_for_resources.find(requested_setting) !=
296 i->second.content_settings_for_resources.end()) {
297 return i->second.content_settings_for_resources.find(
298 requested_setting)->second;
299 }
300
301 // If this map is not for an off-the-record profile, these searches will never
302 // match. The additional off-the-record exceptions always overwrite the
303 // regular ones.
304 i = off_the_record_settings_.find(host);
305 if (i != off_the_record_settings_.end() &&
306 i->second.content_settings_for_resources.find(requested_setting) !=
307 i->second.content_settings_for_resources.end()) {
308 return i->second.content_settings_for_resources.find(
309 requested_setting)->second;
310 }
311
312 // Match patterns starting with the most concrete pattern match.
313 for (std::string key = std::string(kDomainWildcard) + host; ; ) {
314 HostContentSettings::const_iterator i(off_the_record_settings_.find(key));
315 if (i != off_the_record_settings_.end() &&
316 i->second.content_settings_for_resources.find(requested_setting) !=
317 i->second.content_settings_for_resources.end()) {
318 return i->second.content_settings_for_resources.find(
319 requested_setting)->second;
320 }
321
322 i = host_content_settings_.find(key);
323 if (i != host_content_settings_.end() &&
324 i->second.content_settings_for_resources.find(requested_setting) !=
325 i->second.content_settings_for_resources.end()) {
326 return i->second.content_settings_for_resources.find(
327 requested_setting)->second;
328 }
329
330 const size_t next_dot = key.find('.', kDomainWildcardLength);
331 if (next_dot == std::string::npos)
332 break;
333 key.erase(kDomainWildcardLength, next_dot - kDomainWildcardLength + 1);
334 }
335
336 return CONTENT_SETTING_DEFAULT;
228 } 337 }
229 338
230 ContentSettings HostContentSettingsMap::GetContentSettings( 339 ContentSettings HostContentSettingsMap::GetContentSettings(
231 const GURL& url) const { 340 const GURL& url) const {
341 ContentSettings output = GetNonDefaultContentSettings(url);
342
343 // Make the remaining defaults explicit.
344 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j)
345 if (output.settings[j] == CONTENT_SETTING_DEFAULT ||
346 RequiresResourceIdentifier(ContentSettingsType(j)))
347 output.settings[j] = default_content_settings_.settings[j];
348
349 return output;
350 }
351
352 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings(
353 const GURL& url) const {
232 if (ShouldAllowAllContent(url)) 354 if (ShouldAllowAllContent(url))
233 return ContentSettings(CONTENT_SETTING_ALLOW); 355 return ContentSettings(CONTENT_SETTING_ALLOW);
234 356
235 AutoLock auto_lock(lock_); 357 AutoLock auto_lock(lock_);
236 358
237 const std::string host(net::GetHostOrSpecFromURL(url)); 359 const std::string host(net::GetHostOrSpecFromURL(url));
238 ContentSettings output; 360 ContentSettings output;
239 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) 361 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j)
240 output.settings[j] = CONTENT_SETTING_DEFAULT; 362 output.settings[j] = CONTENT_SETTING_DEFAULT;
241 363
242 // Check for exact matches first. 364 // Check for exact matches first.
243 HostContentSettings::const_iterator i(host_content_settings_.find(host)); 365 HostContentSettings::const_iterator i(host_content_settings_.find(host));
244 if (i != host_content_settings_.end()) 366 if (i != host_content_settings_.end())
245 output = i->second; 367 output = i->second.content_settings;
246 368
247 // If this map is not for an off-the-record profile, these searches will never 369 // If this map is not for an off-the-record profile, these searches will never
248 // match. The additional off-the-record exceptions always overwrite the 370 // match. The additional off-the-record exceptions always overwrite the
249 // regular ones. 371 // regular ones.
250 i = off_the_record_settings_.find(host); 372 i = off_the_record_settings_.find(host);
251 if (i != off_the_record_settings_.end()) { 373 if (i != off_the_record_settings_.end()) {
252 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) 374 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j)
253 if (i->second.settings[j] != CONTENT_SETTING_DEFAULT) 375 if (i->second.content_settings.settings[j] != CONTENT_SETTING_DEFAULT)
254 output.settings[j] = i->second.settings[j]; 376 output.settings[j] = i->second.content_settings.settings[j];
255 } 377 }
256 378
257 // Match patterns starting with the most concrete pattern match. 379 // Match patterns starting with the most concrete pattern match.
258 for (std::string key = std::string(kDomainWildcard) + host; ; ) { 380 for (std::string key = std::string(kDomainWildcard) + host; ; ) {
259 HostContentSettings::const_iterator i(off_the_record_settings_.find(key)); 381 HostContentSettings::const_iterator i(off_the_record_settings_.find(key));
260 if (i != off_the_record_settings_.end()) { 382 if (i != off_the_record_settings_.end()) {
261 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { 383 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) {
262 if (output.settings[j] == CONTENT_SETTING_DEFAULT) 384 if (output.settings[j] == CONTENT_SETTING_DEFAULT)
263 output.settings[j] = i->second.settings[j]; 385 output.settings[j] = i->second.content_settings.settings[j];
264 } 386 }
265 } 387 }
266 i = host_content_settings_.find(key); 388 i = host_content_settings_.find(key);
267 if (i != host_content_settings_.end()) { 389 if (i != host_content_settings_.end()) {
268 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { 390 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) {
269 if (output.settings[j] == CONTENT_SETTING_DEFAULT) 391 if (output.settings[j] == CONTENT_SETTING_DEFAULT)
270 output.settings[j] = i->second.settings[j]; 392 output.settings[j] = i->second.content_settings.settings[j];
271 } 393 }
272 } 394 }
273 const size_t next_dot = key.find('.', kDomainWildcardLength); 395 const size_t next_dot = key.find('.', kDomainWildcardLength);
274 if (next_dot == std::string::npos) 396 if (next_dot == std::string::npos)
275 break; 397 break;
276 key.erase(kDomainWildcardLength, next_dot - kDomainWildcardLength + 1); 398 key.erase(kDomainWildcardLength, next_dot - kDomainWildcardLength + 1);
277 } 399 }
278 400
279 // Make the remaining defaults explicit.
280 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j)
281 if (output.settings[j] == CONTENT_SETTING_DEFAULT)
282 output.settings[j] = default_content_settings_.settings[j];
283
284 return output; 401 return output;
285 } 402 }
286 403
287 void HostContentSettingsMap::GetSettingsForOneType( 404 void HostContentSettingsMap::GetSettingsForOneType(
288 ContentSettingsType content_type, 405 ContentSettingsType content_type,
406 const std::string& resource_identifier,
289 SettingsForOneType* settings) const { 407 SettingsForOneType* settings) const {
408 if (CommandLine::ForCurrentProcess()->HasSwitch(
409 switches::kEnableClickToPlay)) {
410 DCHECK(!RequiresResourceIdentifier(content_type) ||
411 !resource_identifier.empty());
412 }
290 DCHECK(settings); 413 DCHECK(settings);
291 settings->clear(); 414 settings->clear();
292 415
293 const HostContentSettings* map_to_return = 416 const HostContentSettings* map_to_return =
294 is_off_the_record_ ? &off_the_record_settings_ : &host_content_settings_; 417 is_off_the_record_ ? &off_the_record_settings_ : &host_content_settings_;
418 ContentSettingsTypeResourceIdentifierPair
419 requested_setting(content_type, resource_identifier);
295 420
296 AutoLock auto_lock(lock_); 421 AutoLock auto_lock(lock_);
297 for (HostContentSettings::const_iterator i(map_to_return->begin()); 422 for (HostContentSettings::const_iterator i(map_to_return->begin());
298 i != map_to_return->end(); ++i) { 423 i != map_to_return->end(); ++i) {
299 ContentSetting setting = i->second.settings[content_type]; 424 ContentSetting setting;
425 if (RequiresResourceIdentifier(content_type)) {
426 if (i->second.content_settings_for_resources.find(requested_setting) !=
427 i->second.content_settings_for_resources.end())
428 setting = i->second.content_settings_for_resources.find(
429 requested_setting)->second;
430 else
431 setting = CONTENT_SETTING_DEFAULT;
432 } else {
433 setting = i->second.content_settings.settings[content_type];
434 }
300 if (setting != CONTENT_SETTING_DEFAULT) { 435 if (setting != CONTENT_SETTING_DEFAULT) {
301 // Use of push_back() relies on the map iterator traversing in order of 436 // Use of push_back() relies on the map iterator traversing in order of
302 // ascending keys. 437 // ascending keys.
303 settings->push_back(std::make_pair(Pattern(i->first), setting)); 438 settings->push_back(std::make_pair(Pattern(i->first), setting));
304 } 439 }
305 } 440 }
306 } 441 }
307 442
308 void HostContentSettingsMap::SetDefaultContentSetting( 443 void HostContentSettingsMap::SetDefaultContentSetting(
309 ContentSettingsType content_type, 444 ContentSettingsType content_type,
310 ContentSetting setting) { 445 ContentSetting setting) {
311 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. 446 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation.
312 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 447 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
313 PrefService* prefs = profile_->GetPrefs(); 448 PrefService* prefs = profile_->GetPrefs();
314 449
315 // The default settings may not be directly modified for OTR sessions. 450 // The default settings may not be directly modified for OTR sessions.
316 // Instead, they are synced to the main profile's setting. 451 // Instead, they are synced to the main profile's setting.
317 if (is_off_the_record_) { 452 if (is_off_the_record_) {
318 NOTREACHED(); 453 NOTREACHED();
319 return; 454 return;
320 } 455 }
321 456
322 DictionaryValue* default_settings_dictionary = 457 DictionaryValue* default_settings_dictionary =
323 prefs->GetMutableDictionary(prefs::kDefaultContentSettings); 458 prefs->GetMutableDictionary(prefs::kDefaultContentSettings);
324 std::wstring dictionary_path(kTypeNames[content_type]); 459 std::string dictionary_path(kTypeNames[content_type]);
325 updating_preferences_ = true; 460 updating_preferences_ = true;
326 { 461 {
327 AutoLock auto_lock(lock_); 462 AutoLock auto_lock(lock_);
328 ScopedPrefUpdate update(prefs, prefs::kDefaultContentSettings); 463 ScopedPrefUpdate update(prefs, prefs::kDefaultContentSettings);
329 if ((setting == CONTENT_SETTING_DEFAULT) || 464 if ((setting == CONTENT_SETTING_DEFAULT) ||
330 (setting == kDefaultSettings[content_type])) { 465 (setting == kDefaultSettings[content_type])) {
331 default_content_settings_.settings[content_type] = 466 default_content_settings_.settings[content_type] =
332 kDefaultSettings[content_type]; 467 kDefaultSettings[content_type];
333 default_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, 468 default_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path,
334 NULL); 469 NULL);
335 } else { 470 } else {
336 default_content_settings_.settings[content_type] = setting; 471 default_content_settings_.settings[content_type] = setting;
337 default_settings_dictionary->SetWithoutPathExpansion( 472 default_settings_dictionary->SetWithoutPathExpansion(
338 dictionary_path, Value::CreateIntegerValue(setting)); 473 dictionary_path, Value::CreateIntegerValue(setting));
339 } 474 }
340 } 475 }
341 updating_preferences_ = false; 476 updating_preferences_ = false;
342 477
343 NotifyObservers(ContentSettingsDetails(content_type)); 478 NotifyObservers(ContentSettingsDetails(Pattern(), content_type, ""));
344 } 479 }
345 480
346 void HostContentSettingsMap::SetContentSetting(const Pattern& pattern, 481 void HostContentSettingsMap::SetContentSetting(
347 ContentSettingsType content_type, 482 const Pattern& pattern,
348 ContentSetting setting) { 483 ContentSettingsType content_type,
484 const std::string& resource_identifier,
485 ContentSetting setting) {
349 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. 486 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation.
350 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 487 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
488 if (CommandLine::ForCurrentProcess()->HasSwitch(
489 switches::kEnableClickToPlay)) {
490 DCHECK(!RequiresResourceIdentifier(content_type) ||
491 !resource_identifier.empty());
492 }
351 493
352 bool early_exit = false; 494 bool early_exit = false;
353 std::wstring wide_pattern(UTF8ToWide(pattern.AsString())); 495 std::string pattern_str(pattern.AsString());
354 PrefService* prefs = NULL; 496 PrefService* prefs = NULL;
355 DictionaryValue* all_settings_dictionary = NULL; 497 DictionaryValue* all_settings_dictionary = NULL;
356 HostContentSettings* map_to_modify = &off_the_record_settings_; 498 HostContentSettings* map_to_modify = &off_the_record_settings_;
357 if (!is_off_the_record_) { 499 if (!is_off_the_record_) {
358 prefs = profile_->GetPrefs(); 500 prefs = profile_->GetPrefs();
359 all_settings_dictionary = 501 all_settings_dictionary =
360 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); 502 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns);
361 map_to_modify = &host_content_settings_; 503 map_to_modify = &host_content_settings_;
362 } 504 }
363 505
364 { 506 {
365 AutoLock auto_lock(lock_); 507 AutoLock auto_lock(lock_);
366 if (!map_to_modify->count(pattern.AsString())) 508 if (!map_to_modify->count(pattern.AsString()))
367 (*map_to_modify)[pattern.AsString()] = ContentSettings(); 509 (*map_to_modify)[pattern.AsString()].content_settings = ContentSettings();
368 HostContentSettings::iterator 510 HostContentSettings::iterator
369 i(map_to_modify->find(pattern.AsString())); 511 i(map_to_modify->find(pattern.AsString()));
370 ContentSettings& settings = i->second; 512 ContentSettings& settings = i->second.content_settings;
371 settings.settings[content_type] = setting; 513 if (RequiresResourceIdentifier(content_type)) {
372 if (AllDefault(settings)) { 514 settings.settings[content_type] = CONTENT_SETTING_DEFAULT;
515 if (setting != CONTENT_SETTING_DEFAULT) {
516 i->second.content_settings_for_resources[
517 ContentSettingsTypeResourceIdentifierPair(content_type,
518 resource_identifier)] = setting;
519 } else {
520 i->second.content_settings_for_resources.erase(
521 ContentSettingsTypeResourceIdentifierPair(content_type,
522 resource_identifier));
523 }
524 } else {
525 settings.settings[content_type] = setting;
526 }
527 if (AllDefault(i->second)) {
373 map_to_modify->erase(i); 528 map_to_modify->erase(i);
374 if (all_settings_dictionary) 529 if (all_settings_dictionary)
375 all_settings_dictionary->RemoveWithoutPathExpansion(wide_pattern, NULL); 530 all_settings_dictionary->RemoveWithoutPathExpansion(pattern_str, NULL);
376 531
377 // We can't just return because |NotifyObservers()| needs to be called, 532 // We can't just return because |NotifyObservers()| needs to be called,
378 // without |lock_| being held. 533 // without |lock_| being held.
379 early_exit = true; 534 early_exit = true;
380 } 535 }
381 } 536 }
382 537
383 if (!early_exit && all_settings_dictionary) { 538 if (!early_exit && all_settings_dictionary) {
384 DictionaryValue* host_settings_dictionary; 539 DictionaryValue* host_settings_dictionary = NULL;
385 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( 540 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion(
386 wide_pattern, &host_settings_dictionary); 541 pattern_str, &host_settings_dictionary);
387 if (!found) { 542 if (!found) {
388 host_settings_dictionary = new DictionaryValue; 543 host_settings_dictionary = new DictionaryValue;
389 all_settings_dictionary->SetWithoutPathExpansion( 544 all_settings_dictionary->SetWithoutPathExpansion(
390 wide_pattern, host_settings_dictionary); 545 pattern_str, host_settings_dictionary);
391 DCHECK_NE(setting, CONTENT_SETTING_DEFAULT); 546 DCHECK_NE(setting, CONTENT_SETTING_DEFAULT);
392 } 547 }
393 std::wstring dictionary_path(kTypeNames[content_type]); 548 if (RequiresResourceIdentifier(content_type)) {
394 if (setting == CONTENT_SETTING_DEFAULT) { 549 std::string dictionary_path(kResourceTypeNames[content_type]);
395 host_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path, 550 DictionaryValue* resource_dictionary = NULL;
396 NULL); 551 found = host_settings_dictionary->GetDictionary(
552 dictionary_path, &resource_dictionary);
553 if (!found) {
554 resource_dictionary = new DictionaryValue;
555 host_settings_dictionary->Set(dictionary_path, resource_dictionary);
556 }
557 if (setting == CONTENT_SETTING_DEFAULT) {
558 resource_dictionary->RemoveWithoutPathExpansion(resource_identifier,
559 NULL);
560 } else {
561 resource_dictionary->SetWithoutPathExpansion(
562 resource_identifier, Value::CreateIntegerValue(setting));
563 }
397 } else { 564 } else {
398 host_settings_dictionary->SetWithoutPathExpansion( 565 std::string dictionary_path(kTypeNames[content_type]);
399 dictionary_path, Value::CreateIntegerValue(setting)); 566 if (setting == CONTENT_SETTING_DEFAULT) {
567 host_settings_dictionary->RemoveWithoutPathExpansion(dictionary_path,
568 NULL);
569 } else {
570 host_settings_dictionary->SetWithoutPathExpansion(
571 dictionary_path, Value::CreateIntegerValue(setting));
572 }
400 } 573 }
401 } 574 }
402 575
403 updating_preferences_ = true; 576 updating_preferences_ = true;
404 if (!is_off_the_record_) 577 if (!is_off_the_record_)
405 ScopedPrefUpdate update(prefs, prefs::kContentSettingsPatterns); 578 ScopedPrefUpdate update(prefs, prefs::kContentSettingsPatterns);
406 updating_preferences_ = false; 579 updating_preferences_ = false;
407 580
408 NotifyObservers(ContentSettingsDetails(pattern, content_type)); 581 NotifyObservers(ContentSettingsDetails(pattern, content_type, ""));
409 } 582 }
410 583
411 void HostContentSettingsMap::AddExceptionForURL( 584 void HostContentSettingsMap::AddExceptionForURL(
412 const GURL& url, 585 const GURL& url,
413 ContentSettingsType content_type, 586 ContentSettingsType content_type,
587 const std::string& resource_identifier,
414 ContentSetting setting) { 588 ContentSetting setting) {
415 // Make sure there is no entry that would override the pattern we are about 589 // Make sure there is no entry that would override the pattern we are about
416 // to insert for exactly this URL. 590 // to insert for exactly this URL.
417 SetContentSetting(Pattern::FromURLNoWildcard(url), 591 SetContentSetting(Pattern::FromURLNoWildcard(url),
418 content_type, 592 content_type,
593 resource_identifier,
419 CONTENT_SETTING_DEFAULT); 594 CONTENT_SETTING_DEFAULT);
420 SetContentSetting(Pattern::FromURL(url), content_type, setting); 595 SetContentSetting(Pattern::FromURL(url),
596 content_type,
597 resource_identifier,
598 setting);
421 } 599 }
422 600
423 void HostContentSettingsMap::ClearSettingsForOneType( 601 void HostContentSettingsMap::ClearSettingsForOneType(
424 ContentSettingsType content_type) { 602 ContentSettingsType content_type) {
425 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. 603 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation.
426 604
427 PrefService* prefs = NULL; 605 PrefService* prefs = NULL;
428 DictionaryValue* all_settings_dictionary = NULL; 606 DictionaryValue* all_settings_dictionary = NULL;
429 HostContentSettings* map_to_modify = &off_the_record_settings_; 607 HostContentSettings* map_to_modify = &off_the_record_settings_;
430 608
431 if (!is_off_the_record_) { 609 if (!is_off_the_record_) {
432 prefs = profile_->GetPrefs(); 610 prefs = profile_->GetPrefs();
433 all_settings_dictionary = 611 all_settings_dictionary =
434 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); 612 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns);
435 map_to_modify = &host_content_settings_; 613 map_to_modify = &host_content_settings_;
436 } 614 }
437 615
438 { 616 {
439 AutoLock auto_lock(lock_); 617 AutoLock auto_lock(lock_);
440 for (HostContentSettings::iterator i(map_to_modify->begin()); 618 for (HostContentSettings::iterator i(map_to_modify->begin());
441 i != map_to_modify->end(); ) { 619 i != map_to_modify->end(); ) {
442 if (i->second.settings[content_type] != CONTENT_SETTING_DEFAULT) { 620 if (RequiresResourceIdentifier(content_type) ||
443 i->second.settings[content_type] = CONTENT_SETTING_DEFAULT; 621 i->second.content_settings.settings[content_type] !=
444 std::wstring wide_host(UTF8ToWide(i->first)); 622 CONTENT_SETTING_DEFAULT) {
623 if (RequiresResourceIdentifier(content_type))
624 i->second.content_settings_for_resources.clear();
625 i->second.content_settings.settings[content_type] =
626 CONTENT_SETTING_DEFAULT;
627 std::string host(i->first);
445 if (AllDefault(i->second)) { 628 if (AllDefault(i->second)) {
446 if (all_settings_dictionary) 629 if (all_settings_dictionary)
447 all_settings_dictionary-> 630 all_settings_dictionary->
448 RemoveWithoutPathExpansion(wide_host, NULL); 631 RemoveWithoutPathExpansion(host, NULL);
449 map_to_modify->erase(i++); 632 map_to_modify->erase(i++);
450 } else if (all_settings_dictionary) { 633 } else if (all_settings_dictionary) {
451 DictionaryValue* host_settings_dictionary; 634 DictionaryValue* host_settings_dictionary;
452 bool found = 635 bool found =
453 all_settings_dictionary->GetDictionaryWithoutPathExpansion( 636 all_settings_dictionary->GetDictionaryWithoutPathExpansion(
454 wide_host, &host_settings_dictionary); 637 host, &host_settings_dictionary);
455 DCHECK(found); 638 DCHECK(found);
456 host_settings_dictionary->RemoveWithoutPathExpansion( 639 host_settings_dictionary->RemoveWithoutPathExpansion(
457 kTypeNames[content_type], NULL); 640 kTypeNames[content_type], NULL);
458 ++i; 641 ++i;
459 } 642 }
460 } else { 643 } else {
461 ++i; 644 ++i;
462 } 645 }
463 } 646 }
464 } 647 }
465 648
466 updating_preferences_ = true; 649 updating_preferences_ = true;
467 if (!is_off_the_record_) 650 if (!is_off_the_record_)
468 ScopedPrefUpdate update(prefs, prefs::kContentSettingsPatterns); 651 ScopedPrefUpdate update(prefs, prefs::kContentSettingsPatterns);
469 updating_preferences_ = false; 652 updating_preferences_ = false;
470 653
471 NotifyObservers(ContentSettingsDetails(content_type)); 654 NotifyObservers(ContentSettingsDetails(Pattern(), content_type, ""));
655 }
656
657 bool HostContentSettingsMap::RequiresResourceIdentifier(
658 ContentSettingsType content_type) const {
659 // TODO(bauerb): Enable once all call sites are adopted.
660 #if 0
661 if (CommandLine::ForCurrentProcess()->HasSwitch(
662 switches::kEnableClickToPlay))
663 return kRequiresResourceIdentifier[content_type];
664 else
665 #endif
666 return false;
472 } 667 }
473 668
474 void HostContentSettingsMap::SetBlockThirdPartyCookies(bool block) { 669 void HostContentSettingsMap::SetBlockThirdPartyCookies(bool block) {
475 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 670 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
476 671
477 // This setting may not be directly modified for OTR sessions. Instead, it 672 // This setting may not be directly modified for OTR sessions. Instead, it
478 // is synced to the main profile's setting. 673 // is synced to the main profile's setting.
479 if (is_off_the_record_) { 674 if (is_off_the_record_) {
480 NOTREACHED(); 675 NOTREACHED();
481 return; 676 return;
(...skipping 23 matching lines...) Expand all
505 block_third_party_cookies_ = false; 700 block_third_party_cookies_ = false;
506 } 701 }
507 702
508 if (!is_off_the_record_) { 703 if (!is_off_the_record_) {
509 PrefService* prefs = profile_->GetPrefs(); 704 PrefService* prefs = profile_->GetPrefs();
510 updating_preferences_ = true; 705 updating_preferences_ = true;
511 prefs->ClearPref(prefs::kDefaultContentSettings); 706 prefs->ClearPref(prefs::kDefaultContentSettings);
512 prefs->ClearPref(prefs::kContentSettingsPatterns); 707 prefs->ClearPref(prefs::kContentSettingsPatterns);
513 prefs->ClearPref(prefs::kBlockThirdPartyCookies); 708 prefs->ClearPref(prefs::kBlockThirdPartyCookies);
514 updating_preferences_ = false; 709 updating_preferences_ = false;
515 NotifyObservers(ContentSettingsDetails()); 710 NotifyObservers(
711 ContentSettingsDetails(Pattern(), CONTENT_SETTINGS_TYPE_DEFAULT, ""));
516 } 712 }
517 } 713 }
518 714
519 bool HostContentSettingsMap::IsOffTheRecord() { 715 bool HostContentSettingsMap::IsOffTheRecord() {
520 return profile_->IsOffTheRecord(); 716 return profile_->IsOffTheRecord();
521 } 717 }
522 718
523 void HostContentSettingsMap::Observe(NotificationType type, 719 void HostContentSettingsMap::Observe(NotificationType type,
524 const NotificationSource& source, 720 const NotificationSource& source,
525 const NotificationDetails& details) { 721 const NotificationDetails& details) {
(...skipping 10 matching lines...) Expand all
536 ReadExceptions(true); 732 ReadExceptions(true);
537 } else if (prefs::kBlockThirdPartyCookies == *name) { 733 } else if (prefs::kBlockThirdPartyCookies == *name) {
538 AutoLock auto_lock(lock_); 734 AutoLock auto_lock(lock_);
539 block_third_party_cookies_ = profile_->GetPrefs()->GetBoolean( 735 block_third_party_cookies_ = profile_->GetPrefs()->GetBoolean(
540 prefs::kBlockThirdPartyCookies); 736 prefs::kBlockThirdPartyCookies);
541 } else { 737 } else {
542 NOTREACHED() << "Unexpected preference observed"; 738 NOTREACHED() << "Unexpected preference observed";
543 return; 739 return;
544 } 740 }
545 741
546 if (!is_off_the_record_) 742 if (!is_off_the_record_) {
547 NotifyObservers(ContentSettingsDetails()); 743 NotifyObservers(
744 ContentSettingsDetails(Pattern(), CONTENT_SETTINGS_TYPE_DEFAULT, ""));
745 }
548 } else if (NotificationType::PROFILE_DESTROYED == type) { 746 } else if (NotificationType::PROFILE_DESTROYED == type) {
549 UnregisterObservers(); 747 UnregisterObservers();
550 } else { 748 } else {
551 NOTREACHED() << "Unexpected notification"; 749 NOTREACHED() << "Unexpected notification";
552 } 750 }
553 } 751 }
554 752
555 HostContentSettingsMap::~HostContentSettingsMap() { 753 HostContentSettingsMap::~HostContentSettingsMap() {
556 UnregisterObservers(); 754 UnregisterObservers();
557 } 755 }
558 756
559 // static
560 bool HostContentSettingsMap::ShouldAllowAllContent(const GURL& url) {
561 return url.SchemeIs(chrome::kChromeInternalScheme) ||
562 url.SchemeIs(chrome::kChromeUIScheme) ||
563 url.SchemeIs(chrome::kExtensionScheme) ||
564 url.SchemeIs(chrome::kGearsScheme) ||
565 url.SchemeIs(chrome::kUserScriptScheme);
566 }
567
568 void HostContentSettingsMap::GetSettingsFromDictionary( 757 void HostContentSettingsMap::GetSettingsFromDictionary(
569 const DictionaryValue* dictionary, 758 const DictionaryValue* dictionary,
570 ContentSettings* settings) { 759 ContentSettings* settings) {
571 for (DictionaryValue::key_iterator i(dictionary->begin_keys()); 760 for (DictionaryValue::key_iterator i(dictionary->begin_keys());
572 i != dictionary->end_keys(); ++i) { 761 i != dictionary->end_keys(); ++i) {
573 const std::string& content_type(*i); 762 const std::string& content_type(*i);
574 int setting = CONTENT_SETTING_DEFAULT;
575 bool found = dictionary->GetIntegerWithoutPathExpansion(content_type,
576 &setting);
577 DCHECK(found);
578 for (size_t type = 0; type < arraysize(kTypeNames); ++type) { 763 for (size_t type = 0; type < arraysize(kTypeNames); ++type) {
579 if ((kTypeNames[type] != NULL) && 764 if ((kTypeNames[type] != NULL) && (kTypeNames[type] == content_type)) {
580 (WideToUTF8(kTypeNames[type]) == content_type)) { 765 int setting = CONTENT_SETTING_DEFAULT;
766 bool found = dictionary->GetIntegerWithoutPathExpansion(content_type,
767 &setting);
768 DCHECK(found);
581 settings->settings[type] = IntToContentSetting(setting); 769 settings->settings[type] = IntToContentSetting(setting);
582 break; 770 break;
583 } 771 }
584 } 772 }
585 } 773 }
586 if (!CommandLine::ForCurrentProcess()->HasSwitch( 774 if (!CommandLine::ForCurrentProcess()->HasSwitch(
587 switches::kEnableCookiePrompt)) { 775 switches::kEnableCookiePrompt)) {
588 // Migrate obsolete cookie prompt mode. 776 // Migrate obsolete cookie prompt mode.
589 if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == 777 if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] ==
590 CONTENT_SETTING_ASK) 778 CONTENT_SETTING_ASK)
591 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; 779 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK;
592 } 780 }
593 } 781 }
594 782
783 void HostContentSettingsMap::GetResourceSettingsFromDictionary(
784 const DictionaryValue* dictionary,
785 ResourceContentSettings* settings) {
786 for (DictionaryValue::key_iterator i(dictionary->begin_keys());
787 i != dictionary->end_keys(); ++i) {
788 const std::string& content_type(*i);
789 for (size_t type = 0; type < arraysize(kResourceTypeNames); ++type) {
790 if ((kResourceTypeNames[type] != NULL) &&
791 (kResourceTypeNames[type] == content_type)) {
792 DictionaryValue* resource_dictionary = NULL;
793 bool found = dictionary->GetDictionary(content_type,
794 &resource_dictionary);
795 DCHECK(found);
796 for (DictionaryValue::key_iterator j(resource_dictionary->begin_keys());
797 j != resource_dictionary->end_keys(); ++j) {
798 const std::string& resource_identifier(*j);
799 int setting = CONTENT_SETTING_DEFAULT;
800 bool found = resource_dictionary->GetIntegerWithoutPathExpansion(
801 resource_identifier, &setting);
802 DCHECK(found);
803 (*settings)[ContentSettingsTypeResourceIdentifierPair(
804 ContentSettingsType(type), resource_identifier)] =
805 ContentSetting(setting);
806 }
807
808 break;
809 }
810 }
811 }
812 }
813
595 void HostContentSettingsMap::ForceDefaultsToBeExplicit() { 814 void HostContentSettingsMap::ForceDefaultsToBeExplicit() {
596 DCHECK_EQ(arraysize(kDefaultSettings), 815 DCHECK_EQ(arraysize(kDefaultSettings),
597 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES)); 816 static_cast<size_t>(CONTENT_SETTINGS_NUM_TYPES));
598 817
599 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 818 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
600 if (default_content_settings_.settings[i] == CONTENT_SETTING_DEFAULT) 819 if (default_content_settings_.settings[i] == CONTENT_SETTING_DEFAULT)
601 default_content_settings_.settings[i] = kDefaultSettings[i]; 820 default_content_settings_.settings[i] = kDefaultSettings[i];
602 } 821 }
603 } 822 }
604 823
605 bool HostContentSettingsMap::AllDefault(const ContentSettings& settings) const { 824 bool HostContentSettingsMap::AllDefault(
606 for (size_t i = 0; i < arraysize(settings.settings); ++i) { 825 const ExtendedContentSettings& settings) const {
607 if (settings.settings[i] != CONTENT_SETTING_DEFAULT) 826 for (size_t i = 0; i < arraysize(settings.content_settings.settings); ++i) {
827 if (settings.content_settings.settings[i] != CONTENT_SETTING_DEFAULT)
608 return false; 828 return false;
609 } 829 }
610 return true; 830 return settings.content_settings_for_resources.empty();
611 } 831 }
612 832
613 void HostContentSettingsMap::ReadDefaultSettings(bool overwrite) { 833 void HostContentSettingsMap::ReadDefaultSettings(bool overwrite) {
614 PrefService* prefs = profile_->GetPrefs(); 834 PrefService* prefs = profile_->GetPrefs();
615 const DictionaryValue* default_settings_dictionary = 835 const DictionaryValue* default_settings_dictionary =
616 prefs->GetDictionary(prefs::kDefaultContentSettings); 836 prefs->GetDictionary(prefs::kDefaultContentSettings);
617 if (overwrite) 837 if (overwrite)
618 default_content_settings_ = ContentSettings(); 838 default_content_settings_ = ContentSettings();
619 // Careful: The returned value could be NULL if the pref has never been set. 839 // Careful: The returned value could be NULL if the pref has never been set.
620 if (default_settings_dictionary != NULL) { 840 if (default_settings_dictionary != NULL) {
(...skipping 15 matching lines...) Expand all
636 i != all_settings_dictionary->end_keys(); ++i) { 856 i != all_settings_dictionary->end_keys(); ++i) {
637 const std::string& pattern(*i); 857 const std::string& pattern(*i);
638 if (!Pattern(pattern).IsValid()) 858 if (!Pattern(pattern).IsValid())
639 LOG(WARNING) << "Invalid pattern stored in content settings"; 859 LOG(WARNING) << "Invalid pattern stored in content settings";
640 DictionaryValue* pattern_settings_dictionary = NULL; 860 DictionaryValue* pattern_settings_dictionary = NULL;
641 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( 861 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion(
642 pattern, &pattern_settings_dictionary); 862 pattern, &pattern_settings_dictionary);
643 DCHECK(found); 863 DCHECK(found);
644 ContentSettings settings; 864 ContentSettings settings;
645 GetSettingsFromDictionary(pattern_settings_dictionary, &settings); 865 GetSettingsFromDictionary(pattern_settings_dictionary, &settings);
646 host_content_settings_[pattern] = settings; 866 host_content_settings_[pattern].content_settings = settings;
867 GetResourceSettingsFromDictionary(
868 pattern_settings_dictionary,
869 &host_content_settings_[pattern].content_settings_for_resources);
647 } 870 }
648 } 871 }
649 } 872 }
650 873
651 void HostContentSettingsMap::NotifyObservers( 874 void HostContentSettingsMap::NotifyObservers(
652 const ContentSettingsDetails& details) { 875 const ContentSettingsDetails& details) {
653 NotificationService::current()->Notify( 876 NotificationService::current()->Notify(
654 NotificationType::CONTENT_SETTINGS_CHANGED, 877 NotificationType::CONTENT_SETTINGS_CHANGED,
655 Source<HostContentSettingsMap>(this), 878 Source<HostContentSettingsMap>(this),
656 Details<const ContentSettingsDetails>(&details)); 879 Details<const ContentSettingsDetails>(&details));
657 } 880 }
658 881
659 void HostContentSettingsMap::UnregisterObservers() { 882 void HostContentSettingsMap::UnregisterObservers() {
660 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 883 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
661 if (!profile_) 884 if (!profile_)
662 return; 885 return;
663 PrefService* prefs = profile_->GetPrefs(); 886 PrefService* prefs = profile_->GetPrefs();
664 prefs->RemovePrefObserver(prefs::kDefaultContentSettings, this); 887 prefs->RemovePrefObserver(prefs::kDefaultContentSettings, this);
665 prefs->RemovePrefObserver(prefs::kContentSettingsPatterns, this); 888 prefs->RemovePrefObserver(prefs::kContentSettingsPatterns, this);
666 prefs->RemovePrefObserver(prefs::kBlockThirdPartyCookies, this); 889 prefs->RemovePrefObserver(prefs::kBlockThirdPartyCookies, this);
667 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, 890 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED,
668 Source<Profile>(profile_)); 891 Source<Profile>(profile_));
669 profile_ = NULL; 892 profile_ = NULL;
670 } 893 }
OLDNEW
« no previous file with comments | « chrome/browser/host_content_settings_map.h ('k') | chrome/browser/host_content_settings_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698