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