| OLD | NEW |
| 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 "chrome/browser/content_settings/content_settings_pref_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 settings->RemoveWithoutPathExpansion(type_name, NULL); | 63 settings->RemoveWithoutPathExpansion(type_name, NULL); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 // If the given content type supports resource identifiers in user preferences, | 67 // If the given content type supports resource identifiers in user preferences, |
| 68 // returns true and sets |pref_key| to the key in the content settings | 68 // returns true and sets |pref_key| to the key in the content settings |
| 69 // dictionary under which per-resource content settings are stored. | 69 // dictionary under which per-resource content settings are stored. |
| 70 // Otherwise, returns false. | 70 // Otherwise, returns false. |
| 71 bool GetResourceTypeName(ContentSettingsType content_type, | 71 bool GetResourceTypeName(ContentSettingsType content_type, |
| 72 std::string* pref_key) { | 72 std::string* pref_key) { |
| 73 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS && | 73 if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 74 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 75 switches::kEnableResourceContentSettings)) { | |
| 76 *pref_key = kPerPluginPrefName; | 74 *pref_key = kPerPluginPrefName; |
| 77 return true; | 75 return true; |
| 78 } | 76 } |
| 79 return false; | 77 return false; |
| 80 } | 78 } |
| 81 | 79 |
| 82 } // namespace | 80 } // namespace |
| 83 | 81 |
| 84 namespace content_settings { | 82 namespace content_settings { |
| 85 | 83 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 const ResourceIdentifier& resource_identifier, | 157 const ResourceIdentifier& resource_identifier, |
| 160 Value* in_value) { | 158 Value* in_value) { |
| 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 162 DCHECK(prefs_); | 160 DCHECK(prefs_); |
| 163 // Default settings are set using a wildcard pattern for both | 161 // Default settings are set using a wildcard pattern for both |
| 164 // |primary_pattern| and |secondary_pattern|. Don't store default settings in | 162 // |primary_pattern| and |secondary_pattern|. Don't store default settings in |
| 165 // the |PrefProvider|. The |PrefProvider| handles settings for specific | 163 // the |PrefProvider|. The |PrefProvider| handles settings for specific |
| 166 // sites/origins defined by the |primary_pattern| and the |secondary_pattern|. | 164 // sites/origins defined by the |primary_pattern| and the |secondary_pattern|. |
| 167 // Default settings are handled by the |DefaultProvider|. | 165 // Default settings are handled by the |DefaultProvider|. |
| 168 if (primary_pattern == ContentSettingsPattern::Wildcard() && | 166 if (primary_pattern == ContentSettingsPattern::Wildcard() && |
| 169 secondary_pattern == ContentSettingsPattern::Wildcard()) { | 167 secondary_pattern == ContentSettingsPattern::Wildcard() && |
| 168 resource_identifier.empty()) { |
| 170 return false; | 169 return false; |
| 171 } | 170 } |
| 172 | 171 |
| 173 // At this point take the ownership of the |in_value|. | 172 // At this point take the ownership of the |in_value|. |
| 174 scoped_ptr<base::Value> value(in_value); | 173 scoped_ptr<base::Value> value(in_value); |
| 175 // Update in memory value map. | 174 // Update in memory value map. |
| 176 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; | 175 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; |
| 177 if (!is_incognito_) | 176 if (!is_incognito_) |
| 178 map_to_modify = &value_map_; | 177 map_to_modify = &value_map_; |
| 179 | 178 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 found = resource_dictionary->GetIntegerWithoutPathExpansion( | 417 found = resource_dictionary->GetIntegerWithoutPathExpansion( |
| 419 resource_identifier, &setting); | 418 resource_identifier, &setting); |
| 420 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting); | 419 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting); |
| 421 value_map_.SetValue(pattern_pair.first, | 420 value_map_.SetValue(pattern_pair.first, |
| 422 pattern_pair.second, | 421 pattern_pair.second, |
| 423 content_type, | 422 content_type, |
| 424 resource_identifier, | 423 resource_identifier, |
| 425 Value::CreateIntegerValue(setting)); | 424 Value::CreateIntegerValue(setting)); |
| 426 } | 425 } |
| 427 } | 426 } |
| 428 } else { | 427 } |
| 429 int setting = CONTENT_SETTING_DEFAULT; | 428 int setting = CONTENT_SETTING_DEFAULT; |
| 430 if (settings_dictionary->GetIntegerWithoutPathExpansion( | 429 if (settings_dictionary->GetIntegerWithoutPathExpansion( |
| 431 GetTypeName(ContentSettingsType(i)), &setting)) { | 430 GetTypeName(ContentSettingsType(i)), &setting)) { |
| 432 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting); | 431 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting); |
| 433 setting = FixObsoleteCookiePromptMode(content_type, | 432 setting = FixObsoleteCookiePromptMode(content_type, |
| 434 ContentSetting(setting)); | 433 ContentSetting(setting)); |
| 435 value_map_.SetValue(pattern_pair.first, | 434 value_map_.SetValue(pattern_pair.first, |
| 436 pattern_pair.second, | 435 pattern_pair.second, |
| 437 content_type, | 436 content_type, |
| 438 ResourceIdentifier(""), | 437 ResourceIdentifier(""), |
| 439 Value::CreateIntegerValue(setting)); | 438 Value::CreateIntegerValue(setting)); |
| 440 } | |
| 441 } | 439 } |
| 442 } | 440 } |
| 443 } | 441 } |
| 444 } | 442 } |
| 445 | 443 |
| 446 void PrefProvider::UpdateObsoletePatternsPref( | 444 void PrefProvider::UpdateObsoletePatternsPref( |
| 447 const ContentSettingsPattern& primary_pattern, | 445 const ContentSettingsPattern& primary_pattern, |
| 448 const ContentSettingsPattern& secondary_pattern, | 446 const ContentSettingsPattern& secondary_pattern, |
| 449 ContentSettingsType content_type, | 447 ContentSettingsType content_type, |
| 450 const ResourceIdentifier& resource_identifier, | 448 const ResourceIdentifier& resource_identifier, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 464 pattern_str, &settings_dictionary); | 462 pattern_str, &settings_dictionary); |
| 465 | 463 |
| 466 if (!found && (setting != CONTENT_SETTING_DEFAULT)) { | 464 if (!found && (setting != CONTENT_SETTING_DEFAULT)) { |
| 467 settings_dictionary = new DictionaryValue; | 465 settings_dictionary = new DictionaryValue; |
| 468 all_settings_dictionary->SetWithoutPathExpansion( | 466 all_settings_dictionary->SetWithoutPathExpansion( |
| 469 pattern_str, settings_dictionary); | 467 pattern_str, settings_dictionary); |
| 470 } | 468 } |
| 471 | 469 |
| 472 if (settings_dictionary) { | 470 if (settings_dictionary) { |
| 473 std::string res_dictionary_path; | 471 std::string res_dictionary_path; |
| 474 if (GetResourceTypeName(content_type, &res_dictionary_path)) { | 472 if (GetResourceTypeName(content_type, &res_dictionary_path) && |
| 473 !resource_identifier.empty()) { |
| 475 DictionaryValue* resource_dictionary = NULL; | 474 DictionaryValue* resource_dictionary = NULL; |
| 476 found = settings_dictionary->GetDictionary( | 475 found = settings_dictionary->GetDictionary( |
| 477 res_dictionary_path, &resource_dictionary); | 476 res_dictionary_path, &resource_dictionary); |
| 478 if (!found) { | 477 if (!found) { |
| 479 if (setting == CONTENT_SETTING_DEFAULT) | 478 if (setting == CONTENT_SETTING_DEFAULT) |
| 480 return; // Nothing to remove. Exit early. | 479 return; // Nothing to remove. Exit early. |
| 481 resource_dictionary = new DictionaryValue; | 480 resource_dictionary = new DictionaryValue; |
| 482 settings_dictionary->Set(res_dictionary_path, resource_dictionary); | 481 settings_dictionary->Set(res_dictionary_path, resource_dictionary); |
| 483 } | 482 } |
| 484 // Update resource dictionary. | 483 // Update resource dictionary. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 496 } else { | 495 } else { |
| 497 // Update settings dictionary. | 496 // Update settings dictionary. |
| 498 std::string setting_path = GetTypeName(content_type); | 497 std::string setting_path = GetTypeName(content_type); |
| 499 if (setting == CONTENT_SETTING_DEFAULT) { | 498 if (setting == CONTENT_SETTING_DEFAULT) { |
| 500 settings_dictionary->RemoveWithoutPathExpansion(setting_path, | 499 settings_dictionary->RemoveWithoutPathExpansion(setting_path, |
| 501 NULL); | 500 NULL); |
| 502 } else { | 501 } else { |
| 503 settings_dictionary->SetWithoutPathExpansion( | 502 settings_dictionary->SetWithoutPathExpansion( |
| 504 setting_path, Value::CreateIntegerValue(setting)); | 503 setting_path, Value::CreateIntegerValue(setting)); |
| 505 } | 504 } |
| 506 // Remove the settings dictionary if it is empty. | 505 } |
| 507 if (settings_dictionary->empty()) { | 506 // Remove the settings dictionary if it is empty. |
| 508 all_settings_dictionary->RemoveWithoutPathExpansion( | 507 if (settings_dictionary->empty()) { |
| 509 pattern_str, NULL); | 508 all_settings_dictionary->RemoveWithoutPathExpansion( |
| 510 } | 509 pattern_str, NULL); |
| 511 } | 510 } |
| 512 } | 511 } |
| 513 } | 512 } |
| 514 | 513 |
| 515 void PrefProvider::UpdatePatternPairsSettings( | 514 void PrefProvider::UpdatePatternPairsSettings( |
| 516 const ContentSettingsPattern& primary_pattern, | 515 const ContentSettingsPattern& primary_pattern, |
| 517 const ContentSettingsPattern& secondary_pattern, | 516 const ContentSettingsPattern& secondary_pattern, |
| 518 ContentSettingsType content_type, | 517 ContentSettingsType content_type, |
| 519 const ResourceIdentifier& resource_identifier, | 518 const ResourceIdentifier& resource_identifier, |
| 520 const base::Value* value, | 519 const base::Value* value, |
| 521 DictionaryValue* pattern_pairs_settings) { | 520 DictionaryValue* pattern_pairs_settings) { |
| 522 // Get settings dictionary for the given patterns. | 521 // Get settings dictionary for the given patterns. |
| 523 std::string pattern_str(CreatePatternString(primary_pattern, | 522 std::string pattern_str(CreatePatternString(primary_pattern, |
| 524 secondary_pattern)); | 523 secondary_pattern)); |
| 525 DictionaryValue* settings_dictionary = NULL; | 524 DictionaryValue* settings_dictionary = NULL; |
| 526 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion( | 525 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion( |
| 527 pattern_str, &settings_dictionary); | 526 pattern_str, &settings_dictionary); |
| 528 | 527 |
| 529 if (!found && value) { | 528 if (!found && value) { |
| 530 settings_dictionary = new DictionaryValue; | 529 settings_dictionary = new DictionaryValue; |
| 531 pattern_pairs_settings->SetWithoutPathExpansion( | 530 pattern_pairs_settings->SetWithoutPathExpansion( |
| 532 pattern_str, settings_dictionary); | 531 pattern_str, settings_dictionary); |
| 533 } | 532 } |
| 534 | 533 |
| 535 if (settings_dictionary) { | 534 if (settings_dictionary) { |
| 536 std::string res_dictionary_path; | 535 std::string res_dictionary_path; |
| 537 if (GetResourceTypeName(content_type, &res_dictionary_path)) { | 536 if (GetResourceTypeName(content_type, &res_dictionary_path) && |
| 537 !resource_identifier.empty()) { |
| 538 DictionaryValue* resource_dictionary = NULL; | 538 DictionaryValue* resource_dictionary = NULL; |
| 539 found = settings_dictionary->GetDictionary( | 539 found = settings_dictionary->GetDictionary( |
| 540 res_dictionary_path, &resource_dictionary); | 540 res_dictionary_path, &resource_dictionary); |
| 541 if (!found) { | 541 if (!found) { |
| 542 if (value == NULL) | 542 if (value == NULL) |
| 543 return; // Nothing to remove. Exit early. | 543 return; // Nothing to remove. Exit early. |
| 544 resource_dictionary = new DictionaryValue; | 544 resource_dictionary = new DictionaryValue; |
| 545 settings_dictionary->Set(res_dictionary_path, resource_dictionary); | 545 settings_dictionary->Set(res_dictionary_path, resource_dictionary); |
| 546 } | 546 } |
| 547 // Update resource dictionary. | 547 // Update resource dictionary. |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 | 1104 |
| 1105 void PrefProvider::AssertLockNotHeld() const { | 1105 void PrefProvider::AssertLockNotHeld() const { |
| 1106 #if !defined(NDEBUG) | 1106 #if !defined(NDEBUG) |
| 1107 // |Lock::Acquire()| will assert if the lock is held by this thread. | 1107 // |Lock::Acquire()| will assert if the lock is held by this thread. |
| 1108 lock_.Acquire(); | 1108 lock_.Acquire(); |
| 1109 lock_.Release(); | 1109 lock_.Release(); |
| 1110 #endif | 1110 #endif |
| 1111 } | 1111 } |
| 1112 | 1112 |
| 1113 } // namespace content_settings | 1113 } // namespace content_settings |
| OLD | NEW |