| 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/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 #include <vector> | 10 #include <vector> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 typedef std::map<std::string, std::string> StringMap; | 35 typedef std::map<std::string, std::string> StringMap; |
| 36 | 36 |
| 37 // The preference keys where resource identifiers are stored for | 37 // The preference keys where resource identifiers are stored for |
| 38 // ContentSettingsType values that support resource identifiers. | 38 // ContentSettingsType values that support resource identifiers. |
| 39 const char* kResourceTypeNames[] = { | 39 const char* kResourceTypeNames[] = { |
| 40 NULL, | 40 NULL, |
| 41 NULL, | 41 NULL, |
| 42 NULL, | 42 NULL, |
| 43 "per_plugin", | 43 "per_plugin", |
| 44 NULL, | 44 NULL, |
| 45 NULL, // Not used for Geolocation | 45 NULL, |
| 46 NULL, // Not used for Notifications | 46 NULL, // Not used for Notifications |
| 47 }; | 47 }; |
| 48 COMPILE_ASSERT(arraysize(kResourceTypeNames) == CONTENT_SETTINGS_NUM_TYPES, | 48 COMPILE_ASSERT(arraysize(kResourceTypeNames) == CONTENT_SETTINGS_NUM_TYPES, |
| 49 resource_type_names_incorrect_size); | 49 resource_type_names_incorrect_size); |
| 50 | 50 |
| 51 // The default setting for each content type. | 51 // The default setting for each content type. |
| 52 const ContentSetting kDefaultSettings[] = { | 52 const ContentSetting kDefaultSettings[] = { |
| 53 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES | 53 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES |
| 54 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES | 54 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES |
| 55 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT | 55 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT |
| 56 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS | 56 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS |
| 57 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS | 57 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS |
| 58 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_GEOLOCATION | 58 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_GEOLOCATION |
| 59 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_NOTIFICATIONS | 59 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_NOTIFICATIONS |
| 60 }; | 60 }; |
| 61 COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, | 61 COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, |
| 62 default_settings_incorrect_size); | 62 default_settings_incorrect_size); |
| 63 | 63 |
| 64 // The names of the ContentSettingsType values, for use with dictionary prefs. | 64 // The names of the ContentSettingsType values, for use with dictionary prefs. |
| 65 const char* kTypeNames[] = { | 65 const char* kTypeNames[] = { |
| 66 "cookies", | 66 "cookies", |
| 67 "images", | 67 "images", |
| 68 "javascript", | 68 "javascript", |
| 69 "plugins", | 69 "plugins", |
| 70 "popups", | 70 "popups", |
| 71 "geolocation", |
| 71 // TODO(markusheintz): Refactoring in progress. Content settings exceptions | 72 // TODO(markusheintz): Refactoring in progress. Content settings exceptions |
| 72 // for notifications and geolocation will be added next. | 73 // for notifications added next. |
| 73 "geolocation", // Only used for default Geolocation settings | |
| 74 "notifications", // Only used for default Notifications settings. | 74 "notifications", // Only used for default Notifications settings. |
| 75 }; | 75 }; |
| 76 COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, | 76 COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, |
| 77 type_names_incorrect_size); | 77 type_names_incorrect_size); |
| 78 | 78 |
| 79 void SetDefaultContentSettings(DictionaryValue* default_settings) { | 79 void SetDefaultContentSettings(DictionaryValue* default_settings) { |
| 80 default_settings->Clear(); | 80 default_settings->Clear(); |
| 81 | 81 |
| 82 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 82 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 83 if (kTypeNames[i] != NULL) { | 83 if (kTypeNames[i] != NULL) { |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // static | 354 // static |
| 355 void PrefProvider::RegisterUserPrefs(PrefService* prefs) { | 355 void PrefProvider::RegisterUserPrefs(PrefService* prefs) { |
| 356 prefs->RegisterIntegerPref( | 356 prefs->RegisterIntegerPref( |
| 357 prefs::kContentSettingsVersion, | 357 prefs::kContentSettingsVersion, |
| 358 ContentSettingsPattern::kContentSettingsPatternVersion, | 358 ContentSettingsPattern::kContentSettingsPatternVersion, |
| 359 PrefService::UNSYNCABLE_PREF); | 359 PrefService::UNSYNCABLE_PREF); |
| 360 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatternPairs, | 360 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatternPairs, |
| 361 PrefService::SYNCABLE_PREF); | 361 PrefService::SYNCABLE_PREF); |
| 362 | 362 |
| 363 // Obsolete prefs, for migration: | 363 // Obsolete prefs, for migration: |
| 364 prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings, |
| 365 PrefService::SYNCABLE_PREF); |
| 364 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns, | 366 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns, |
| 365 PrefService::SYNCABLE_PREF); | 367 PrefService::SYNCABLE_PREF); |
| 366 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts, | 368 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts, |
| 367 PrefService::UNSYNCABLE_PREF); | 369 PrefService::UNSYNCABLE_PREF); |
| 368 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings, | 370 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings, |
| 369 PrefService::UNSYNCABLE_PREF); | 371 PrefService::UNSYNCABLE_PREF); |
| 370 } | 372 } |
| 371 | 373 |
| 372 PrefProvider::PrefProvider(PrefService* prefs, | 374 PrefProvider::PrefProvider(PrefService* prefs, |
| 373 bool incognito) | 375 bool incognito) |
| 374 : prefs_(prefs), | 376 : prefs_(prefs), |
| 375 is_incognito_(incognito), | 377 is_incognito_(incognito), |
| 376 updating_preferences_(false) { | 378 updating_preferences_(false) { |
| 377 DCHECK(prefs_); | 379 DCHECK(prefs_); |
| 378 if (!is_incognito_) { | 380 if (!is_incognito_) { |
| 379 // Migrate obsolete preferences. | 381 // Migrate obsolete preferences. |
| 380 MigrateObsoletePerhostPref(); | 382 MigrateObsoletePerhostPref(); |
| 381 MigrateObsoletePopupsPref(); | 383 MigrateObsoletePopupsPref(); |
| 382 MigrateObsoleteContentSettingsPatternPref(); | 384 MigrateObsoleteContentSettingsPatternPref(); |
| 385 MigrateObsoleteGeolocationPref(); |
| 383 } | 386 } |
| 384 | 387 |
| 385 // Verify preferences version. | 388 // Verify preferences version. |
| 386 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) { | 389 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) { |
| 387 prefs_->SetInteger(prefs::kContentSettingsVersion, | 390 prefs_->SetInteger(prefs::kContentSettingsVersion, |
| 388 ContentSettingsPattern::kContentSettingsPatternVersion); | 391 ContentSettingsPattern::kContentSettingsPatternVersion); |
| 389 } | 392 } |
| 390 if (prefs_->GetInteger(prefs::kContentSettingsVersion) > | 393 if (prefs_->GetInteger(prefs::kContentSettingsVersion) > |
| 391 ContentSettingsPattern::kContentSettingsPatternVersion) { | 394 ContentSettingsPattern::kContentSettingsPatternVersion) { |
| 392 return; | 395 return; |
| 393 } | 396 } |
| 394 | 397 |
| 395 // Read content settings exceptions. | 398 // Read content settings exceptions. |
| 396 ReadContentSettingsFromPref(false); | 399 ReadContentSettingsFromPref(false); |
| 397 | 400 |
| 398 if (!is_incognito_) { | 401 if (!is_incognito_) { |
| 399 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", | 402 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", |
| 400 value_map_.size()); | 403 value_map_.size()); |
| 401 } | 404 } |
| 402 | 405 |
| 403 pref_change_registrar_.Init(prefs_); | 406 pref_change_registrar_.Init(prefs_); |
| 404 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); | 407 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); |
| 405 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); | 408 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); |
| 409 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); |
| 406 } | 410 } |
| 407 | 411 |
| 408 ContentSetting PrefProvider::GetContentSetting( | 412 ContentSetting PrefProvider::GetContentSetting( |
| 409 const GURL& primary_url, | 413 const GURL& primary_url, |
| 410 const GURL& secondary_url, | 414 const GURL& secondary_url, |
| 411 ContentSettingsType content_type, | 415 ContentSettingsType content_type, |
| 412 const ResourceIdentifier& resource_identifier) const { | 416 const ResourceIdentifier& resource_identifier) const { |
| 413 // For a |PrefProvider| used in a |HostContentSettingsMap| of a non incognito | 417 // For a |PrefProvider| used in a |HostContentSettingsMap| of a non incognito |
| 414 // profile, this will always return NULL. | 418 // profile, this will always return NULL. |
| 415 // TODO(markusheintz): I don't like this. I'd like to have an | 419 // TODO(markusheintz): I don't like this. I'd like to have an |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 466 } |
| 463 | 467 |
| 464 void PrefProvider::SetContentSetting( | 468 void PrefProvider::SetContentSetting( |
| 465 const ContentSettingsPattern& primary_pattern, | 469 const ContentSettingsPattern& primary_pattern, |
| 466 const ContentSettingsPattern& secondary_pattern, | 470 const ContentSettingsPattern& secondary_pattern, |
| 467 ContentSettingsType content_type, | 471 ContentSettingsType content_type, |
| 468 const ResourceIdentifier& resource_identifier, | 472 const ResourceIdentifier& resource_identifier, |
| 469 ContentSetting setting) { | 473 ContentSetting setting) { |
| 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 471 DCHECK(prefs_); | 475 DCHECK(prefs_); |
| 472 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 476 DCHECK(kTypeNames[content_type] != NULL); |
| 473 | 477 |
| 474 // Update in memory value map. | 478 // Update in memory value map. |
| 475 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; | 479 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; |
| 476 if (!is_incognito_) | 480 if (!is_incognito_) |
| 477 map_to_modify = &value_map_; | 481 map_to_modify = &value_map_; |
| 478 | 482 |
| 479 { | 483 { |
| 480 base::AutoLock auto_lock(lock_); | 484 base::AutoLock auto_lock(lock_); |
| 481 if (setting == CONTENT_SETTING_DEFAULT) { | 485 if (setting == CONTENT_SETTING_DEFAULT) { |
| 482 map_to_modify->DeleteValue( | 486 map_to_modify->DeleteValue( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 int type, | 550 int type, |
| 547 const NotificationSource& source, | 551 const NotificationSource& source, |
| 548 const NotificationDetails& details) { | 552 const NotificationDetails& details) { |
| 549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 553 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 550 | 554 |
| 551 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 555 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 552 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); | 556 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
| 553 if (updating_preferences_) | 557 if (updating_preferences_) |
| 554 return; | 558 return; |
| 555 | 559 |
| 560 AutoReset<bool> auto_reset(&updating_preferences_, true); |
| 556 std::string* name = Details<std::string>(details).ptr(); | 561 std::string* name = Details<std::string>(details).ptr(); |
| 557 if (*name == prefs::kContentSettingsPatternPairs) { | 562 if (*name == prefs::kContentSettingsPatternPairs) { |
| 558 SyncObsoletePref(); | 563 SyncObsoletePatternPref(); |
| 559 ReadContentSettingsFromPref(true); | 564 SyncObsoleteGeolocationPref(); |
| 560 } else if (*name == prefs::kContentSettingsPatterns) { | 565 } else if (*name == prefs::kContentSettingsPatterns) { |
| 561 AutoReset<bool> auto_reset(&updating_preferences_, true); | |
| 562 MigrateObsoleteContentSettingsPatternPref(); | 566 MigrateObsoleteContentSettingsPatternPref(); |
| 563 ReadContentSettingsFromPref(true); | 567 } else if (*name == prefs::kGeolocationContentSettings) { |
| 568 MigrateObsoleteGeolocationPref(); |
| 564 } else { | 569 } else { |
| 565 NOTREACHED() << "Unexpected preference observed"; | 570 NOTREACHED() << "Unexpected preference observed"; |
| 566 return; | 571 return; |
| 567 } | 572 } |
| 573 ReadContentSettingsFromPref(true); |
| 568 | 574 |
| 569 NotifyObservers(ContentSettingsPattern(), | 575 NotifyObservers(ContentSettingsPattern(), |
| 570 ContentSettingsPattern(), | 576 ContentSettingsPattern(), |
| 571 CONTENT_SETTINGS_TYPE_DEFAULT, | 577 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 572 std::string()); | 578 std::string()); |
| 573 } else { | 579 } else { |
| 574 NOTREACHED() << "Unexpected notification"; | 580 NOTREACHED() << "Unexpected notification"; |
| 575 } | 581 } |
| 576 } | 582 } |
| 577 | 583 |
| 578 PrefProvider::~PrefProvider() { | 584 PrefProvider::~PrefProvider() { |
| 579 DCHECK(!prefs_); | 585 DCHECK(!prefs_); |
| 580 } | 586 } |
| 581 | 587 |
| 582 // //////////////////////////////////////////////////////////////////////////// | 588 // //////////////////////////////////////////////////////////////////////////// |
| 583 // Private | 589 // Private |
| 584 | 590 |
| 585 void PrefProvider::UpdatePref( | 591 void PrefProvider::UpdatePref( |
| 586 const ContentSettingsPattern& primary_pattern, | 592 const ContentSettingsPattern& primary_pattern, |
| 587 const ContentSettingsPattern& secondary_pattern, | 593 const ContentSettingsPattern& secondary_pattern, |
| 588 ContentSettingsType content_type, | 594 ContentSettingsType content_type, |
| 589 const ResourceIdentifier& resource_identifier, | 595 const ResourceIdentifier& resource_identifier, |
| 590 ContentSetting setting) { | 596 ContentSetting setting) { |
| 591 AutoReset<bool> auto_reset(&updating_preferences_, true); | 597 AutoReset<bool> auto_reset(&updating_preferences_, true); |
| 592 UpdatePatternPairsPref(primary_pattern, | 598 UpdatePatternPairsPref(primary_pattern, |
| 593 secondary_pattern, | 599 secondary_pattern, |
| 594 content_type, | 600 content_type, |
| 595 resource_identifier, | 601 resource_identifier, |
| 596 setting); | 602 setting); |
| 597 UpdatePatternsPref(primary_pattern, | 603 if (content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION && |
| 598 secondary_pattern, | 604 content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
| 599 content_type, | 605 UpdateObsoletePatternsPref(primary_pattern, |
| 600 resource_identifier, | 606 secondary_pattern, |
| 601 setting); | 607 content_type, |
| 608 resource_identifier, |
| 609 setting); |
| 610 } |
| 611 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 612 UpdateObsoleteGeolocationPref(primary_pattern, secondary_pattern, setting); |
| 613 } |
| 602 } | 614 } |
| 603 | 615 |
| 604 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { | 616 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { |
| 605 base::AutoLock auto_lock(lock_); | 617 base::AutoLock auto_lock(lock_); |
| 606 | 618 |
| 607 const DictionaryValue* all_settings_dictionary = | 619 const DictionaryValue* all_settings_dictionary = |
| 608 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); | 620 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 609 | 621 |
| 610 if (overwrite) | 622 if (overwrite) |
| 611 value_map_.clear(); | 623 value_map_.clear(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 content_type, | 698 content_type, |
| 687 ResourceIdentifier(""), | 699 ResourceIdentifier(""), |
| 688 Value::CreateIntegerValue(setting)); | 700 Value::CreateIntegerValue(setting)); |
| 689 } | 701 } |
| 690 } | 702 } |
| 691 } | 703 } |
| 692 } | 704 } |
| 693 } | 705 } |
| 694 } | 706 } |
| 695 | 707 |
| 696 void PrefProvider::UpdatePatternsPref( | 708 void PrefProvider::UpdateObsoletePatternsPref( |
| 697 const ContentSettingsPattern& primary_pattern, | 709 const ContentSettingsPattern& primary_pattern, |
| 698 const ContentSettingsPattern& secondary_pattern, | 710 const ContentSettingsPattern& secondary_pattern, |
| 699 ContentSettingsType content_type, | 711 ContentSettingsType content_type, |
| 700 const ResourceIdentifier& resource_identifier, | 712 const ResourceIdentifier& resource_identifier, |
| 701 ContentSetting setting) { | 713 ContentSetting setting) { |
| 702 DictionaryPrefUpdate update(prefs_, | 714 DictionaryPrefUpdate update(prefs_, |
| 703 prefs::kContentSettingsPatterns); | 715 prefs::kContentSettingsPatterns); |
| 704 DictionaryValue* all_settings_dictionary = update.Get(); | 716 DictionaryValue* all_settings_dictionary = update.Get(); |
| 705 | 717 |
| 706 // Get settings dictionary for |primary_pattern|. | 718 // Get settings dictionary for |primary_pattern|. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 } | 831 } |
| 820 } | 832 } |
| 821 // Remove the settings dictionary if it is empty. | 833 // Remove the settings dictionary if it is empty. |
| 822 if (settings_dictionary->empty()) { | 834 if (settings_dictionary->empty()) { |
| 823 all_settings_dictionary->RemoveWithoutPathExpansion( | 835 all_settings_dictionary->RemoveWithoutPathExpansion( |
| 824 pattern_str, NULL); | 836 pattern_str, NULL); |
| 825 } | 837 } |
| 826 } | 838 } |
| 827 } | 839 } |
| 828 | 840 |
| 841 void PrefProvider::UpdateObsoleteGeolocationPref( |
| 842 const ContentSettingsPattern& primary_pattern, |
| 843 const ContentSettingsPattern& secondary_pattern, |
| 844 ContentSetting setting) { |
| 845 if (!prefs_) |
| 846 return; |
| 847 |
| 848 const GURL requesting_origin(primary_pattern.ToString()); |
| 849 const GURL embedding_origin(secondary_pattern.ToString()); |
| 850 DCHECK(requesting_origin.is_valid() && embedding_origin.is_valid()); |
| 851 |
| 852 DictionaryPrefUpdate update(prefs_, prefs::kGeolocationContentSettings); |
| 853 DictionaryValue* obsolete_geolocation_settings = update.Get(); |
| 854 DictionaryValue* requesting_origin_settings_dictionary = NULL; |
| 855 obsolete_geolocation_settings->GetDictionaryWithoutPathExpansion( |
| 856 requesting_origin.spec(), &requesting_origin_settings_dictionary); |
| 857 if (setting == CONTENT_SETTING_DEFAULT) { |
| 858 if (requesting_origin_settings_dictionary) { |
| 859 requesting_origin_settings_dictionary->RemoveWithoutPathExpansion( |
| 860 embedding_origin.spec(), NULL); |
| 861 if (requesting_origin_settings_dictionary->empty()) { |
| 862 obsolete_geolocation_settings->RemoveWithoutPathExpansion( |
| 863 requesting_origin.spec(), NULL); |
| 864 } |
| 865 } |
| 866 } else { |
| 867 if (!requesting_origin_settings_dictionary) { |
| 868 requesting_origin_settings_dictionary = new DictionaryValue; |
| 869 obsolete_geolocation_settings->SetWithoutPathExpansion( |
| 870 requesting_origin.spec(), requesting_origin_settings_dictionary); |
| 871 } |
| 872 DCHECK(requesting_origin_settings_dictionary); |
| 873 requesting_origin_settings_dictionary->SetWithoutPathExpansion( |
| 874 embedding_origin.spec(), Value::CreateIntegerValue(setting)); |
| 875 } |
| 876 } |
| 877 |
| 829 // static | 878 // static |
| 830 void PrefProvider::CanonicalizeContentSettingsExceptions( | 879 void PrefProvider::CanonicalizeContentSettingsExceptions( |
| 831 DictionaryValue* all_settings_dictionary) { | 880 DictionaryValue* all_settings_dictionary) { |
| 832 DCHECK(all_settings_dictionary); | 881 DCHECK(all_settings_dictionary); |
| 833 | 882 |
| 834 std::vector<std::string> remove_items; | 883 std::vector<std::string> remove_items; |
| 835 std::vector<std::pair<std::string, std::string> > move_items; | 884 std::vector<std::pair<std::string, std::string> > move_items; |
| 836 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); | 885 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); |
| 837 i != all_settings_dictionary->end_keys(); ++i) { | 886 i != all_settings_dictionary->end_keys(); ++i) { |
| 838 const std::string& pattern_str(*i); | 887 const std::string& pattern_str(*i); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 "", | 1011 "", |
| 963 CONTENT_SETTING_ALLOW); | 1012 CONTENT_SETTING_ALLOW); |
| 964 } | 1013 } |
| 965 prefs_->ClearPref(prefs::kPopupWhitelistedHosts); | 1014 prefs_->ClearPref(prefs::kPopupWhitelistedHosts); |
| 966 } | 1015 } |
| 967 } | 1016 } |
| 968 | 1017 |
| 969 void PrefProvider::MigrateObsoleteContentSettingsPatternPref() { | 1018 void PrefProvider::MigrateObsoleteContentSettingsPatternPref() { |
| 970 if (prefs_->HasPrefPath(prefs::kContentSettingsPatterns) && !is_incognito_) { | 1019 if (prefs_->HasPrefPath(prefs::kContentSettingsPatterns) && !is_incognito_) { |
| 971 const DictionaryValue* patterns_dictionary = | 1020 const DictionaryValue* patterns_dictionary = |
| 972 prefs_->GetDictionary(prefs::kContentSettingsPatterns); | 1021 prefs_->GetDictionary(prefs::kContentSettingsPatterns); |
| 973 | 1022 |
| 974 // A map with an old key, new key mapping. If the new key is empty then the | 1023 // A map with an old key, new key mapping. If the new key is empty then the |
| 975 // value for the old key will be removed. | 1024 // value for the old key will be removed. |
| 976 StringMap keys_to_change; | 1025 StringMap keys_to_change; |
| 977 | |
| 978 { | 1026 { |
| 979 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs); | 1027 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs); |
| 980 DictionaryValue* pattern_pairs_dictionary = update.Get(); | 1028 DictionaryValue* pattern_pairs_dictionary = update.Get(); |
| 981 for (DictionaryValue::key_iterator i( | 1029 for (DictionaryValue::key_iterator i( |
| 982 patterns_dictionary->begin_keys()); | 1030 patterns_dictionary->begin_keys()); |
| 983 i != patterns_dictionary->end_keys(); | 1031 i != patterns_dictionary->end_keys(); |
| 984 ++i) { | 1032 ++i) { |
| 985 const std::string& key(*i); | 1033 const std::string& key(*i); |
| 986 // Remove broken pattern keys and fix keys with pattern pairs. | 1034 // Remove broken pattern keys and fix keys with pattern pairs. |
| 987 size_t sep_pos = key.find(","); | 1035 size_t sep_pos = key.find(","); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 DCHECK(found); | 1087 DCHECK(found); |
| 1040 if (!pattern_str_pair.second.empty()) { | 1088 if (!pattern_str_pair.second.empty()) { |
| 1041 mutable_patterns_dictionary->SetWithoutPathExpansion( | 1089 mutable_patterns_dictionary->SetWithoutPathExpansion( |
| 1042 pattern_str_pair.second, dict.release()); | 1090 pattern_str_pair.second, dict.release()); |
| 1043 } | 1091 } |
| 1044 } | 1092 } |
| 1045 } | 1093 } |
| 1046 } | 1094 } |
| 1047 } | 1095 } |
| 1048 | 1096 |
| 1049 void PrefProvider::SyncObsoletePref() { | 1097 void PrefProvider::SyncObsoletePatternPref() { |
| 1050 AutoReset<bool> auto_reset(&updating_preferences_, true); | |
| 1051 if (prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs) && | 1098 if (prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs) && |
| 1052 !is_incognito_) { | 1099 !is_incognito_) { |
| 1053 const DictionaryValue* pattern_pairs_dictionary = | 1100 const DictionaryValue* pattern_pairs_dictionary = |
| 1054 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); | 1101 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 1055 | 1102 |
| 1056 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatterns); | 1103 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatterns); |
| 1057 DictionaryValue* obsolete_settings_dictionary = update.Get(); | 1104 DictionaryValue* obsolete_settings_dictionary = update.Get(); |
| 1058 | 1105 |
| 1059 for (DictionaryValue::key_iterator i = | 1106 for (DictionaryValue::key_iterator i = |
| 1060 pattern_pairs_dictionary->begin_keys(); | 1107 pattern_pairs_dictionary->begin_keys(); |
| 1061 i != pattern_pairs_dictionary->end_keys(); | 1108 i != pattern_pairs_dictionary->end_keys(); |
| 1062 ++i) { | 1109 ++i) { |
| 1063 const std::string& key(*i); | 1110 const std::string& key(*i); |
| 1064 // Validate pattern string and skip it if it is invalid. | 1111 // Validate pattern string and skip it if it is invalid. |
| 1065 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = | 1112 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = |
| 1066 ParsePatternString(key); | 1113 ParsePatternString(key); |
| 1067 if (!pattern_pair.first.IsValid() || !pattern_pair.second.IsValid()) { | 1114 if (!pattern_pair.first.IsValid() || !pattern_pair.second.IsValid()) { |
| 1068 LOG(DFATAL) << "Invalid pattern strings: " << key; | 1115 LOG(DFATAL) << "Invalid pattern strings: " << key; |
| 1069 continue; | 1116 continue; |
| 1070 } | 1117 } |
| 1071 | 1118 |
| 1072 // Copy dictionary | 1119 DictionaryValue* settings_dictionary = NULL; |
| 1073 DictionaryValue* dictionary = NULL; | |
| 1074 bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion( | 1120 bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion( |
| 1075 key, &dictionary); | 1121 key, &settings_dictionary); |
| 1076 DCHECK(found); | 1122 DCHECK(found); |
| 1077 std::string new_key = pattern_pair.first.ToString(); | 1123 scoped_ptr<DictionaryValue> settings_dictionary_copy( |
| 1078 // Existing values are overwritten. | 1124 new DictionaryValue()); |
| 1079 obsolete_settings_dictionary->SetWithoutPathExpansion( | 1125 for (size_t i = CONTENT_SETTINGS_TYPE_COOKIES; |
| 1080 new_key, dictionary->DeepCopy()); | 1126 i <= CONTENT_SETTINGS_TYPE_POPUPS; |
| 1127 ++i) { |
| 1128 DCHECK(kTypeNames[i]); |
| 1129 std::string type_name(kTypeNames[i]); |
| 1130 if (settings_dictionary->HasKey(type_name)) { |
| 1131 Value* value = NULL; |
| 1132 bool found = settings_dictionary->GetWithoutPathExpansion( |
| 1133 type_name, &value); |
| 1134 DCHECK(found); |
| 1135 settings_dictionary_copy->SetWithoutPathExpansion( |
| 1136 type_name, value->DeepCopy()); |
| 1137 } |
| 1138 } |
| 1139 |
| 1140 // Ignore empty dictionaryies. |
| 1141 if (!settings_dictionary_copy->empty()) { |
| 1142 std::string new_key = pattern_pair.first.ToString(); |
| 1143 // Existing values are overwritten. |
| 1144 obsolete_settings_dictionary->SetWithoutPathExpansion( |
| 1145 new_key, settings_dictionary_copy.release()); |
| 1146 } |
| 1081 } | 1147 } |
| 1082 } | 1148 } |
| 1083 } | 1149 } |
| 1150 |
| 1151 void PrefProvider::MigrateObsoleteGeolocationPref() { |
| 1152 if (!prefs_->HasPrefPath(prefs::kGeolocationContentSettings)) |
| 1153 return; |
| 1154 |
| 1155 const DictionaryValue* geolocation_settings = |
| 1156 prefs_->GetDictionary(prefs::kGeolocationContentSettings); |
| 1157 for (DictionaryValue::key_iterator i = |
| 1158 geolocation_settings->begin_keys(); |
| 1159 i != geolocation_settings->end_keys(); |
| 1160 ++i) { |
| 1161 const std::string& primary_key(*i); |
| 1162 GURL primary_url(primary_key); |
| 1163 DCHECK(primary_url.is_valid()); |
| 1164 |
| 1165 DictionaryValue* requesting_origin_settings = NULL; |
| 1166 bool found = geolocation_settings->GetDictionaryWithoutPathExpansion( |
| 1167 primary_key, &requesting_origin_settings); |
| 1168 DCHECK(found); |
| 1169 |
| 1170 for (DictionaryValue::key_iterator j = |
| 1171 requesting_origin_settings->begin_keys(); |
| 1172 j != requesting_origin_settings->end_keys(); |
| 1173 ++j) { |
| 1174 const std::string& secondary_key(*j); |
| 1175 GURL secondary_url(secondary_key); |
| 1176 DCHECK(secondary_url.is_valid()); |
| 1177 |
| 1178 int setting_value; |
| 1179 found = requesting_origin_settings->GetIntegerWithoutPathExpansion( |
| 1180 secondary_key, &setting_value); |
| 1181 DCHECK(found); |
| 1182 |
| 1183 ContentSettingsPattern primary_pattern = |
| 1184 ContentSettingsPattern::FromURLNoWildcard(primary_url); |
| 1185 ContentSettingsPattern secondary_pattern = |
| 1186 ContentSettingsPattern::FromURLNoWildcard(secondary_url); |
| 1187 DCHECK(primary_pattern.IsValid() && secondary_pattern.IsValid()); |
| 1188 |
| 1189 SetContentSetting(primary_pattern, |
| 1190 secondary_pattern, |
| 1191 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 1192 std::string(), |
| 1193 IntToContentSetting(setting_value)); |
| 1194 } |
| 1195 } |
| 1196 } |
| 1197 |
| 1198 void PrefProvider::SyncObsoleteGeolocationPref() { |
| 1199 DCHECK(prefs_); |
| 1200 DCHECK(prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs)); |
| 1201 |
| 1202 // Clear the obsolete preference for geolocation settings. Then copy all |
| 1203 // geolocation settings from the new preference to the obsolete one. |
| 1204 prefs_->ClearPref(prefs::kGeolocationContentSettings); |
| 1205 const DictionaryValue* pattern_pairs_dictionary = |
| 1206 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 1207 for (DictionaryValue::key_iterator i = |
| 1208 pattern_pairs_dictionary->begin_keys(); |
| 1209 i != pattern_pairs_dictionary->end_keys(); |
| 1210 ++i) { |
| 1211 const std::string& key(*i); |
| 1212 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = |
| 1213 ParsePatternString(key); |
| 1214 DCHECK(pattern_pair.first.IsValid() && pattern_pair.second.IsValid()); |
| 1215 |
| 1216 DictionaryValue* settings_dictionary = NULL; |
| 1217 bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion( |
| 1218 key, &settings_dictionary); |
| 1219 DCHECK(found); |
| 1220 |
| 1221 if (settings_dictionary->HasKey( |
| 1222 kTypeNames[CONTENT_SETTINGS_TYPE_GEOLOCATION])) { |
| 1223 int setting_value; |
| 1224 settings_dictionary->GetInteger( |
| 1225 kTypeNames[CONTENT_SETTINGS_TYPE_GEOLOCATION], &setting_value); |
| 1226 |
| 1227 UpdateObsoleteGeolocationPref(pattern_pair.first, |
| 1228 pattern_pair.second, |
| 1229 ContentSetting(setting_value)); |
| 1230 } |
| 1231 } |
| 1232 } |
| 1084 | 1233 |
| 1085 } // namespace content_settings | 1234 } // namespace content_settings |
| OLD | NEW |