Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 | 153 |
| 154 // Register the prefs for the content settings providers. | 154 // Register the prefs for the content settings providers. |
| 155 content_settings::PrefDefaultProvider::RegisterUserPrefs(prefs); | 155 content_settings::PrefDefaultProvider::RegisterUserPrefs(prefs); |
| 156 content_settings::PolicyDefaultProvider::RegisterUserPrefs(prefs); | 156 content_settings::PolicyDefaultProvider::RegisterUserPrefs(prefs); |
| 157 content_settings::PrefProvider::RegisterUserPrefs(prefs); | 157 content_settings::PrefProvider::RegisterUserPrefs(prefs); |
| 158 content_settings::PolicyProvider::RegisterUserPrefs(prefs); | 158 content_settings::PolicyProvider::RegisterUserPrefs(prefs); |
| 159 } | 159 } |
| 160 | 160 |
| 161 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( | 161 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( |
| 162 ContentSettingsType content_type) const { | 162 ContentSettingsType content_type) const { |
| 163 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | |
| 163 ContentSetting setting = CONTENT_SETTING_DEFAULT; | 164 ContentSetting setting = CONTENT_SETTING_DEFAULT; |
| 164 for (ConstDefaultProviderIterator provider = | 165 for (ConstDefaultProviderIterator provider = |
| 165 default_content_settings_providers_.begin(); | 166 default_content_settings_providers_.begin(); |
| 166 provider != default_content_settings_providers_.end(); ++provider) { | 167 provider != default_content_settings_providers_.end(); ++provider) { |
| 167 ContentSetting provided_setting = | 168 ContentSetting provided_setting = |
| 168 (*provider)->ProvideDefaultSetting(content_type); | 169 (*provider)->ProvideDefaultSetting(content_type); |
| 169 if (provided_setting != CONTENT_SETTING_DEFAULT) | 170 if (provided_setting != CONTENT_SETTING_DEFAULT) |
| 170 setting = provided_setting; | 171 setting = provided_setting; |
| 171 } | 172 } |
| 172 // The method GetDefaultContentSetting always has to return an explicit | 173 // The method GetDefaultContentSetting always has to return an explicit |
| 173 // value that is to be used as default. We here rely on the | 174 // value that is to be used as default. We here rely on the |
| 174 // PrefContentSettingProvider to always provide a value. | 175 // PrefContentSettingProvider to always provide a value. |
| 175 CHECK_NE(CONTENT_SETTING_DEFAULT, setting); | 176 CHECK_NE(CONTENT_SETTING_DEFAULT, setting); |
| 176 return setting; | 177 return setting; |
| 177 } | 178 } |
| 178 | 179 |
| 179 ContentSettings HostContentSettingsMap::GetDefaultContentSettings() const { | 180 ContentSettings HostContentSettingsMap::GetDefaultContentSettings() const { |
| 180 ContentSettings output(CONTENT_SETTING_DEFAULT); | 181 ContentSettings output(CONTENT_SETTING_DEFAULT); |
| 181 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) | 182 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 183 if (i == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE) | |
| 184 continue; | |
|
wtc
2011/09/02 18:53:22
It may be a good idea to explain why we skip
CONTE
markusheintz_
2011/09/02 19:39:12
Done.
| |
| 182 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i)); | 185 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i)); |
| 186 } | |
| 183 return output; | 187 return output; |
| 184 } | 188 } |
| 185 | 189 |
| 186 ContentSetting HostContentSettingsMap::GetCookieContentSetting( | 190 ContentSetting HostContentSettingsMap::GetCookieContentSetting( |
| 187 const GURL& url, | 191 const GURL& url, |
| 188 const GURL& first_party_url, | 192 const GURL& first_party_url, |
| 189 bool setting_cookie) const { | 193 bool setting_cookie) const { |
| 190 if (ShouldAllowAllContent(first_party_url, CONTENT_SETTINGS_TYPE_COOKIES)) | 194 if (ShouldAllowAllContent(first_party_url, CONTENT_SETTINGS_TYPE_COOKIES)) |
| 191 return CONTENT_SETTING_ALLOW; | 195 return CONTENT_SETTING_ALLOW; |
| 192 | 196 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 const GURL& secondary_url, | 228 const GURL& secondary_url, |
| 225 ContentSettingsType content_type, | 229 ContentSettingsType content_type, |
| 226 const std::string& resource_identifier) const { | 230 const std::string& resource_identifier) const { |
| 227 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); | 231 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); |
| 228 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), | 232 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), |
| 229 resource_identifier.empty()); | 233 resource_identifier.empty()); |
| 230 return GetContentSettingInternal( | 234 return GetContentSettingInternal( |
| 231 primary_url, secondary_url, content_type, resource_identifier); | 235 primary_url, secondary_url, content_type, resource_identifier); |
| 232 } | 236 } |
| 233 | 237 |
| 238 Value* HostContentSettingsMap::GetContentSettingValue( | |
| 239 const GURL& primary_url, | |
| 240 const GURL& secondary_url, | |
| 241 ContentSettingsType content_type, | |
| 242 const std::string& resource_identifier) const { | |
| 243 // Check if the scheme of the requesting url is whitelisted. | |
| 244 if (ShouldAllowAllContent(secondary_url, content_type)) | |
| 245 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); | |
| 246 | |
| 247 // First check if there are specific settings for the |primary_url| and | |
| 248 // |secondary_url|. The list of |content_settings_providers_| is ordered | |
| 249 // according to their priority. So iterate through the list of providers and | |
| 250 // break when the first non |NULL| value is returned. | |
|
wtc
2011/09/02 18:53:22
Nit: thanks for the comments! You can omit the la
markusheintz_
2011/09/02 19:39:12
Done.
| |
| 251 for (ConstProviderIterator provider = content_settings_providers_.begin(); | |
| 252 provider != content_settings_providers_.end(); | |
| 253 ++provider) { | |
| 254 Value* value = (*provider)->GetContentSettingValue( | |
| 255 primary_url, secondary_url, content_type, resource_identifier); | |
| 256 if (value) | |
| 257 return value; | |
| 258 } | |
| 259 | |
| 260 // If no specific settings were found for the |primary_url|, |secondary_url| | |
| 261 // pair, then the default value for the given |content_type| should be | |
| 262 // returned. For CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE the default is | |
| 263 // 'no filter available'. That's why we return |NULL| for this content type. | |
| 264 if (content_type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE) | |
| 265 return NULL; | |
| 266 return Value::CreateIntegerValue(GetDefaultContentSetting(content_type)); | |
| 267 } | |
| 268 | |
| 234 ContentSetting HostContentSettingsMap::GetContentSettingInternal( | 269 ContentSetting HostContentSettingsMap::GetContentSettingInternal( |
| 235 const GURL& primary_url, | 270 const GURL& primary_url, |
| 236 const GURL& secondary_url, | 271 const GURL& secondary_url, |
| 237 ContentSettingsType content_type, | 272 ContentSettingsType content_type, |
| 238 const std::string& resource_identifier) const { | 273 const std::string& resource_identifier) const { |
| 239 ContentSetting setting = GetNonDefaultContentSetting( | 274 ContentSetting setting = GetNonDefaultContentSetting( |
| 240 primary_url, secondary_url, content_type, resource_identifier); | 275 primary_url, secondary_url, content_type, resource_identifier); |
| 241 if (setting == CONTENT_SETTING_DEFAULT) | 276 if (setting == CONTENT_SETTING_DEFAULT) |
| 242 return GetDefaultContentSetting(content_type); | 277 return GetDefaultContentSetting(content_type); |
| 243 return setting; | 278 return setting; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 270 const GURL& secondary_url) const { | 305 const GURL& secondary_url) const { |
| 271 ContentSettings output = GetNonDefaultContentSettings( | 306 ContentSettings output = GetNonDefaultContentSettings( |
| 272 primary_url, secondary_url); | 307 primary_url, secondary_url); |
| 273 | 308 |
| 274 // If we require a resource identifier, set the content settings to default, | 309 // If we require a resource identifier, set the content settings to default, |
| 275 // otherwise make the defaults explicit. | 310 // otherwise make the defaults explicit. |
| 276 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { | 311 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
| 277 // A managed default content setting has the highest priority and hence | 312 // A managed default content setting has the highest priority and hence |
| 278 // will overwrite any previously set value. | 313 // will overwrite any previously set value. |
| 279 if (output.settings[j] == CONTENT_SETTING_DEFAULT && | 314 if (output.settings[j] == CONTENT_SETTING_DEFAULT && |
| 280 j != CONTENT_SETTINGS_TYPE_PLUGINS) { | 315 j != CONTENT_SETTINGS_TYPE_PLUGINS && |
| 316 j != CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE) { | |
| 281 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); | 317 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); |
| 282 } | 318 } |
| 283 } | 319 } |
| 284 return output; | 320 return output; |
| 285 } | 321 } |
| 286 | 322 |
| 287 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( | 323 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( |
| 288 const GURL& primary_url, | 324 const GURL& primary_url, |
| 289 const GURL& secondary_url) const { | 325 const GURL& secondary_url) const { |
| 290 ContentSettings output(CONTENT_SETTING_DEFAULT); | 326 ContentSettings output(CONTENT_SETTING_DEFAULT); |
| 291 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { | 327 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
| 328 if (j == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE) | |
| 329 continue; | |
| 292 output.settings[j] = GetNonDefaultContentSetting( | 330 output.settings[j] = GetNonDefaultContentSetting( |
| 293 primary_url, | 331 primary_url, |
| 294 secondary_url, | 332 secondary_url, |
| 295 ContentSettingsType(j), | 333 ContentSettingsType(j), |
| 296 ""); | 334 ""); |
| 297 } | 335 } |
| 298 return output; | 336 return output; |
| 299 } | 337 } |
| 300 | 338 |
| 301 void HostContentSettingsMap::GetSettingsForOneType( | 339 void HostContentSettingsMap::GetSettingsForOneType( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 i != settings_map.end(); | 372 i != settings_map.end(); |
| 335 ++i) { | 373 ++i) { |
| 336 settings->push_back(i->second); | 374 settings->push_back(i->second); |
| 337 } | 375 } |
| 338 } | 376 } |
| 339 } | 377 } |
| 340 | 378 |
| 341 void HostContentSettingsMap::SetDefaultContentSetting( | 379 void HostContentSettingsMap::SetDefaultContentSetting( |
| 342 ContentSettingsType content_type, | 380 ContentSettingsType content_type, |
| 343 ContentSetting setting) { | 381 ContentSetting setting) { |
| 382 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | |
| 344 DCHECK(IsSettingAllowedForType(setting, content_type)); | 383 DCHECK(IsSettingAllowedForType(setting, content_type)); |
| 345 for (DefaultProviderIterator provider = | 384 for (DefaultProviderIterator provider = |
| 346 default_content_settings_providers_.begin(); | 385 default_content_settings_providers_.begin(); |
| 347 provider != default_content_settings_providers_.end(); ++provider) { | 386 provider != default_content_settings_providers_.end(); ++provider) { |
| 348 (*provider)->UpdateDefaultSetting(content_type, setting); | 387 (*provider)->UpdateDefaultSetting(content_type, setting); |
| 349 } | 388 } |
| 350 } | 389 } |
| 351 | 390 |
| 352 void HostContentSettingsMap::SetContentSetting( | 391 void HostContentSettingsMap::SetContentSetting( |
| 353 const ContentSettingsPattern& primary_pattern, | 392 const ContentSettingsPattern& primary_pattern, |
| 354 const ContentSettingsPattern& secondary_pattern, | 393 const ContentSettingsPattern& secondary_pattern, |
| 355 ContentSettingsType content_type, | 394 ContentSettingsType content_type, |
| 356 const std::string& resource_identifier, | 395 const std::string& resource_identifier, |
| 357 ContentSetting setting) { | 396 ContentSetting setting) { |
| 397 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | |
| 358 DCHECK(IsSettingAllowedForType(setting, content_type)); | 398 DCHECK(IsSettingAllowedForType(setting, content_type)); |
| 359 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), | 399 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), |
| 360 resource_identifier.empty()); | 400 resource_identifier.empty()); |
| 361 for (ProviderIterator provider = content_settings_providers_.begin(); | 401 for (ProviderIterator provider = content_settings_providers_.begin(); |
| 362 provider != content_settings_providers_.end(); | 402 provider != content_settings_providers_.end(); |
| 363 ++provider) { | 403 ++provider) { |
| 364 (*provider)->SetContentSetting( | 404 (*provider)->SetContentSetting( |
| 365 primary_pattern, | 405 primary_pattern, |
| 366 secondary_pattern, | 406 secondary_pattern, |
| 367 content_type, | 407 content_type, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | 583 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
| 544 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? | 584 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? |
| 545 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); | 585 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); |
| 546 } | 586 } |
| 547 if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) { | 587 if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) { |
| 548 SetBlockThirdPartyCookies(cookie_behavior == | 588 SetBlockThirdPartyCookies(cookie_behavior == |
| 549 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | 589 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
| 550 } | 590 } |
| 551 } | 591 } |
| 552 } | 592 } |
| OLD | NEW |