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/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 26 matching lines...) Expand all Loading... | |
| 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, | 45 NULL, |
| 46 NULL, // Not used for Notifications | 46 NULL, // Not used for Notifications |
| 47 NULL, // Not used for Intents. | 47 NULL, |
| 48 NULL, | 48 NULL, |
| 49 }; | 49 }; |
| 50 COMPILE_ASSERT(arraysize(kResourceTypeNames) == CONTENT_SETTINGS_NUM_TYPES, | 50 COMPILE_ASSERT(arraysize(kResourceTypeNames) == CONTENT_SETTINGS_NUM_TYPES, |
| 51 resource_type_names_incorrect_size); | 51 resource_type_names_incorrect_size); |
| 52 | 52 |
| 53 // The default setting for each content type. | 53 // The default setting for each content type. |
| 54 const ContentSetting kDefaultSettings[] = { | 54 const ContentSetting kDefaultSettings[] = { |
| 55 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES | 55 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES |
| 56 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES | 56 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES |
| 57 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT | 57 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT |
| 58 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS | 58 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS |
| 59 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS | 59 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS |
| 60 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_GEOLOCATION | 60 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_GEOLOCATION |
| 61 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_NOTIFICATIONS | 61 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_NOTIFICATIONS |
| 62 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_INTENTS | 62 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_INTENTS |
| 63 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE | 63 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE |
| 64 }; | 64 }; |
| 65 COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, | 65 COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, |
| 66 default_settings_incorrect_size); | 66 default_settings_incorrect_size); |
| 67 | 67 |
| 68 // The names of the ContentSettingsType values, for use with dictionary prefs. | 68 // The names of the ContentSettingsType values, for use with dictionary prefs. |
| 69 const char* kTypeNames[] = { | 69 const char* kTypeNames[] = { |
| 70 "cookies", | 70 "cookies", |
| 71 "images", | 71 "images", |
| 72 "javascript", | 72 "javascript", |
| 73 "plugins", | 73 "plugins", |
| 74 "popups", | 74 "popups", |
| 75 "geolocation", | 75 "geolocation", |
| 76 // TODO(markusheintz): Refactoring in progress. Content settings exceptions | 76 "notifications", |
| 77 // for notifications added next. | |
| 78 "notifications", // Only used for default Notifications settings. | |
| 79 "intents", | 77 "intents", |
| 80 "auto-select-certificate" | 78 "auto-select-certificate" |
| 81 }; | 79 }; |
| 82 COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, | 80 COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, |
| 83 type_names_incorrect_size); | 81 type_names_incorrect_size); |
| 84 | 82 |
| 85 void SetDefaultContentSettings(DictionaryValue* default_settings) { | 83 void SetDefaultContentSettings(DictionaryValue* default_settings) { |
| 86 default_settings->Clear(); | 84 default_settings->Clear(); |
| 87 | 85 |
| 88 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 86 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 116 | 114 |
| 117 ContentSetting FixObsoleteCookiePromptMode(ContentSettingsType content_type, | 115 ContentSetting FixObsoleteCookiePromptMode(ContentSettingsType content_type, |
| 118 ContentSetting setting) { | 116 ContentSetting setting) { |
| 119 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES && | 117 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES && |
| 120 setting == CONTENT_SETTING_ASK) { | 118 setting == CONTENT_SETTING_ASK) { |
| 121 return CONTENT_SETTING_BLOCK; | 119 return CONTENT_SETTING_BLOCK; |
| 122 } | 120 } |
| 123 return setting; | 121 return setting; |
| 124 } | 122 } |
| 125 | 123 |
| 124 // Clears all settings for the given |type| in the given |pattern_pairs| | |
| 125 // dictionary. | |
| 126 void ClearSettings(ContentSettingsType type, | |
| 127 DictionaryValue* pattern_pairs) { | |
| 128 std::string type_name(kTypeNames[type]); | |
| 129 for (DictionaryValue::key_iterator i = pattern_pairs->begin_keys(); | |
| 130 i != pattern_pairs->end_keys(); | |
| 131 ++i) { | |
| 132 const std::string& pattern_pair(*i); | |
| 133 | |
| 134 DictionaryValue* settings = NULL; | |
| 135 pattern_pairs->GetDictionaryWithoutPathExpansion( | |
| 136 pattern_pair, &settings); | |
| 137 | |
| 138 settings->RemoveWithoutPathExpansion(type_name, NULL); | |
| 139 } | |
| 140 } | |
| 141 | |
| 126 } // namespace | 142 } // namespace |
| 127 | 143 |
| 128 namespace content_settings { | 144 namespace content_settings { |
| 129 | 145 |
| 130 PrefDefaultProvider::PrefDefaultProvider(PrefService* prefs, | 146 PrefDefaultProvider::PrefDefaultProvider(PrefService* prefs, |
| 131 bool incognito) | 147 bool incognito) |
| 132 : prefs_(prefs), | 148 : prefs_(prefs), |
| 133 is_incognito_(incognito), | 149 is_incognito_(incognito), |
| 134 updating_preferences_(false) { | 150 updating_preferences_(false) { |
| 135 DCHECK(prefs_); | 151 DCHECK(prefs_); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 ContentSettingsPattern::kContentSettingsPatternVersion, | 380 ContentSettingsPattern::kContentSettingsPatternVersion, |
| 365 PrefService::UNSYNCABLE_PREF); | 381 PrefService::UNSYNCABLE_PREF); |
| 366 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatternPairs, | 382 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatternPairs, |
| 367 PrefService::SYNCABLE_PREF); | 383 PrefService::SYNCABLE_PREF); |
| 368 | 384 |
| 369 // Obsolete prefs, for migration: | 385 // Obsolete prefs, for migration: |
| 370 prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings, | 386 prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings, |
| 371 PrefService::SYNCABLE_PREF); | 387 PrefService::SYNCABLE_PREF); |
| 372 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns, | 388 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns, |
| 373 PrefService::SYNCABLE_PREF); | 389 PrefService::SYNCABLE_PREF); |
| 390 prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins, | |
| 391 PrefService::SYNCABLE_PREF); | |
| 392 prefs->RegisterListPref(prefs::kDesktopNotificationDeniedOrigins, | |
| 393 PrefService::SYNCABLE_PREF); | |
| 374 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts, | 394 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts, |
| 375 PrefService::UNSYNCABLE_PREF); | 395 PrefService::UNSYNCABLE_PREF); |
| 376 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings, | 396 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings, |
| 377 PrefService::UNSYNCABLE_PREF); | 397 PrefService::UNSYNCABLE_PREF); |
| 378 } | 398 } |
| 379 | 399 |
| 380 PrefProvider::PrefProvider(PrefService* prefs, | 400 PrefProvider::PrefProvider(PrefService* prefs, |
| 381 bool incognito) | 401 bool incognito) |
| 382 : prefs_(prefs), | 402 : prefs_(prefs), |
| 383 is_incognito_(incognito), | 403 is_incognito_(incognito), |
| 384 updating_preferences_(false) { | 404 updating_preferences_(false) { |
| 385 DCHECK(prefs_); | 405 DCHECK(prefs_); |
| 386 if (!is_incognito_) { | 406 if (!is_incognito_) { |
| 387 // Migrate obsolete preferences. | 407 // Migrate obsolete preferences. |
| 388 MigrateObsoletePerhostPref(); | 408 MigrateObsoletePerhostPref(); |
| 389 MigrateObsoletePopupsPref(); | 409 MigrateObsoletePopupsPref(); |
| 390 MigrateObsoleteContentSettingsPatternPref(); | 410 MigrateObsoleteContentSettingsPatternPref(); |
| 391 MigrateObsoleteGeolocationPref(); | 411 MigrateObsoleteGeolocationPref(); |
| 412 MigrateObsoleteNotificationsPrefs(); | |
| 392 } | 413 } |
| 393 | 414 |
| 394 // Verify preferences version. | 415 // Verify preferences version. |
| 395 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) { | 416 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) { |
| 396 prefs_->SetInteger(prefs::kContentSettingsVersion, | 417 prefs_->SetInteger(prefs::kContentSettingsVersion, |
| 397 ContentSettingsPattern::kContentSettingsPatternVersion); | 418 ContentSettingsPattern::kContentSettingsPatternVersion); |
| 398 } | 419 } |
| 399 if (prefs_->GetInteger(prefs::kContentSettingsVersion) > | 420 if (prefs_->GetInteger(prefs::kContentSettingsVersion) > |
| 400 ContentSettingsPattern::kContentSettingsPatternVersion) { | 421 ContentSettingsPattern::kContentSettingsPatternVersion) { |
| 401 return; | 422 return; |
| 402 } | 423 } |
| 403 | 424 |
| 404 // Read content settings exceptions. | 425 // Read content settings exceptions. |
| 405 ReadContentSettingsFromPref(false); | 426 ReadContentSettingsFromPref(false); |
| 406 | 427 |
| 407 if (!is_incognito_) { | 428 if (!is_incognito_) { |
| 408 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", | 429 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", |
| 409 value_map_.size()); | 430 value_map_.size()); |
| 410 } | 431 } |
| 411 | 432 |
| 412 pref_change_registrar_.Init(prefs_); | 433 pref_change_registrar_.Init(prefs_); |
| 413 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); | 434 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); |
| 414 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); | 435 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); |
| 415 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); | 436 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); |
| 437 pref_change_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this); | |
| 438 pref_change_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this); | |
| 416 } | 439 } |
| 417 | 440 |
| 418 ContentSetting PrefProvider::GetContentSetting( | 441 ContentSetting PrefProvider::GetContentSetting( |
| 419 const GURL& primary_url, | 442 const GURL& primary_url, |
| 420 const GURL& secondary_url, | 443 const GURL& secondary_url, |
| 421 ContentSettingsType content_type, | 444 ContentSettingsType content_type, |
| 422 const ResourceIdentifier& resource_identifier) const { | 445 const ResourceIdentifier& resource_identifier) const { |
| 423 // For a |PrefProvider| used in a |HostContentSettingsMap| of a non incognito | 446 // For a |PrefProvider| used in a |HostContentSettingsMap| of a non incognito |
| 424 // profile, this will always return NULL. | 447 // profile, this will always return NULL. |
| 425 // TODO(markusheintz): I don't like this. I'd like to have an | 448 // TODO(markusheintz): I don't like this. I'd like to have an |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 } | 527 } |
| 505 } | 528 } |
| 506 | 529 |
| 507 // Update the content settings preference. | 530 // Update the content settings preference. |
| 508 if (!is_incognito_) { | 531 if (!is_incognito_) { |
| 509 UpdatePref(primary_pattern, | 532 UpdatePref(primary_pattern, |
| 510 secondary_pattern, | 533 secondary_pattern, |
| 511 content_type, | 534 content_type, |
| 512 resource_identifier, | 535 resource_identifier, |
| 513 setting); | 536 setting); |
| 537 prefs_->ScheduleSavePersistentPrefs(); | |
| 514 } | 538 } |
| 515 | 539 |
| 516 NotifyObservers( | 540 NotifyObservers( |
| 517 primary_pattern, secondary_pattern, content_type, resource_identifier); | 541 primary_pattern, secondary_pattern, content_type, resource_identifier); |
| 518 } | 542 } |
| 519 | 543 |
| 520 void PrefProvider::ClearAllContentSettingsRules( | 544 void PrefProvider::ClearAllContentSettingsRules( |
| 521 ContentSettingsType content_type) { | 545 ContentSettingsType content_type) { |
| 522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 523 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 547 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 538 entry->content_type, | 562 entry->content_type, |
| 539 entry->identifier, | 563 entry->identifier, |
| 540 CONTENT_SETTING_DEFAULT); | 564 CONTENT_SETTING_DEFAULT); |
| 541 // Delete current |entry| and set |entry| to the next value map entry. | 565 // Delete current |entry| and set |entry| to the next value map entry. |
| 542 entry = map_to_modify->erase(entry); | 566 entry = map_to_modify->erase(entry); |
| 543 } else { | 567 } else { |
| 544 ++entry; | 568 ++entry; |
| 545 } | 569 } |
| 546 } | 570 } |
| 547 } | 571 } |
| 548 | 572 prefs_->ScheduleSavePersistentPrefs(); |
| 549 NotifyObservers(ContentSettingsPattern(), | 573 NotifyObservers(ContentSettingsPattern(), |
| 550 ContentSettingsPattern(), | 574 ContentSettingsPattern(), |
| 551 content_type, | 575 content_type, |
| 552 std::string()); | 576 std::string()); |
| 553 } | 577 } |
| 554 | 578 |
| 555 void PrefProvider::Observe( | 579 void PrefProvider::Observe( |
| 556 int type, | 580 int type, |
| 557 const NotificationSource& source, | 581 const NotificationSource& source, |
| 558 const NotificationDetails& details) { | 582 const NotificationDetails& details) { |
| 559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 560 | 584 |
| 561 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 585 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 562 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); | 586 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
| 563 if (updating_preferences_) | 587 if (updating_preferences_) |
| 564 return; | 588 return; |
| 565 | 589 |
| 566 if (!is_incognito_) { | 590 if (!is_incognito_) { |
| 567 AutoReset<bool> auto_reset(&updating_preferences_, true); | 591 AutoReset<bool> auto_reset(&updating_preferences_, true); |
| 568 std::string* name = Details<std::string>(details).ptr(); | 592 std::string* name = Details<std::string>(details).ptr(); |
| 569 if (*name == prefs::kContentSettingsPatternPairs) { | 593 if (*name == prefs::kContentSettingsPatternPairs) { |
| 570 SyncObsoletePatternPref(); | 594 SyncObsoletePatternPref(); |
| 571 SyncObsoleteGeolocationPref(); | 595 SyncObsoletePrefs(); |
| 572 } else if (*name == prefs::kContentSettingsPatterns) { | 596 } else if (*name == prefs::kContentSettingsPatterns) { |
| 573 MigrateObsoleteContentSettingsPatternPref(); | 597 MigrateObsoleteContentSettingsPatternPref(); |
| 574 } else if (*name == prefs::kGeolocationContentSettings) { | 598 } else if (*name == prefs::kGeolocationContentSettings) { |
| 575 MigrateObsoleteGeolocationPref(); | 599 MigrateObsoleteGeolocationPref(); |
| 600 } else if (*name == prefs::kDesktopNotificationAllowedOrigins || | |
| 601 *name == prefs::kDesktopNotificationDeniedOrigins) { | |
| 602 MigrateObsoleteNotificationsPrefs(); | |
| 576 } else { | 603 } else { |
| 577 NOTREACHED() << "Unexpected preference observed"; | 604 NOTREACHED() << "Unexpected preference observed"; |
| 578 return; | 605 return; |
| 579 } | 606 } |
| 580 } | 607 } |
| 608 prefs_->ScheduleSavePersistentPrefs(); | |
| 581 ReadContentSettingsFromPref(true); | 609 ReadContentSettingsFromPref(true); |
| 582 | 610 |
| 583 NotifyObservers(ContentSettingsPattern(), | 611 NotifyObservers(ContentSettingsPattern(), |
| 584 ContentSettingsPattern(), | 612 ContentSettingsPattern(), |
| 585 CONTENT_SETTINGS_TYPE_DEFAULT, | 613 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 586 std::string()); | 614 std::string()); |
| 587 } else { | 615 } else { |
| 588 NOTREACHED() << "Unexpected notification"; | 616 NOTREACHED() << "Unexpected notification"; |
| 589 } | 617 } |
| 590 } | 618 } |
| 591 | 619 |
| 592 PrefProvider::~PrefProvider() { | 620 PrefProvider::~PrefProvider() { |
| 593 DCHECK(!prefs_); | 621 DCHECK(!prefs_); |
| 594 } | 622 } |
| 595 | 623 |
| 596 // //////////////////////////////////////////////////////////////////////////// | 624 // //////////////////////////////////////////////////////////////////////////// |
| 597 // Private | 625 // Private |
| 598 | 626 |
| 599 void PrefProvider::UpdatePref( | 627 void PrefProvider::UpdatePref( |
| 600 const ContentSettingsPattern& primary_pattern, | 628 const ContentSettingsPattern& primary_pattern, |
| 601 const ContentSettingsPattern& secondary_pattern, | 629 const ContentSettingsPattern& secondary_pattern, |
| 602 ContentSettingsType content_type, | 630 ContentSettingsType content_type, |
| 603 const ResourceIdentifier& resource_identifier, | 631 const ResourceIdentifier& resource_identifier, |
| 604 ContentSetting setting) { | 632 ContentSetting setting) { |
| 605 AutoReset<bool> auto_reset(&updating_preferences_, true); | 633 AutoReset<bool> auto_reset(&updating_preferences_, true); |
| 606 UpdatePatternPairsPref(primary_pattern, | 634 { |
| 607 secondary_pattern, | 635 DictionaryPrefUpdate update(prefs_, |
| 608 content_type, | 636 prefs::kContentSettingsPatternPairs); |
| 609 resource_identifier, | 637 DictionaryValue* pattern_pairs_settings = update.Get(); |
| 610 setting); | 638 UpdatePatternPairsSettings(primary_pattern, |
| 639 secondary_pattern, | |
| 640 content_type, | |
| 641 resource_identifier, | |
| 642 setting, | |
| 643 pattern_pairs_settings); | |
| 644 } | |
| 611 if (content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION && | 645 if (content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION && |
| 612 content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 646 content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
| 613 UpdateObsoletePatternsPref(primary_pattern, | 647 UpdateObsoletePatternsPref(primary_pattern, |
| 614 secondary_pattern, | 648 secondary_pattern, |
| 615 content_type, | 649 content_type, |
| 616 resource_identifier, | 650 resource_identifier, |
| 617 setting); | 651 setting); |
| 618 } | 652 } else if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 619 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | |
| 620 UpdateObsoleteGeolocationPref(primary_pattern, secondary_pattern, setting); | 653 UpdateObsoleteGeolocationPref(primary_pattern, secondary_pattern, setting); |
| 654 } else if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | |
| 655 ListPrefUpdate update_allowed_sites( | |
| 656 prefs_, prefs::kDesktopNotificationAllowedOrigins); | |
| 657 ListPrefUpdate update_denied_sites( | |
| 658 prefs_, prefs::kDesktopNotificationDeniedOrigins); | |
| 659 UpdateObsoleteNotificationsSettings(primary_pattern, | |
| 660 secondary_pattern, | |
| 661 setting, | |
| 662 update_allowed_sites.Get(), | |
| 663 update_denied_sites.Get()); | |
| 621 } | 664 } |
| 622 } | 665 } |
| 623 | 666 |
| 624 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { | 667 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { |
| 625 base::AutoLock auto_lock(lock_); | 668 base::AutoLock auto_lock(lock_); |
| 626 | 669 |
| 627 const DictionaryValue* all_settings_dictionary = | 670 const DictionaryValue* all_settings_dictionary = |
| 628 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); | 671 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 629 | 672 |
| 630 if (overwrite) | 673 if (overwrite) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 } | 815 } |
| 773 } | 816 } |
| 774 // Remove the settings dictionary if it is empty. | 817 // Remove the settings dictionary if it is empty. |
| 775 if (settings_dictionary->empty()) { | 818 if (settings_dictionary->empty()) { |
| 776 all_settings_dictionary->RemoveWithoutPathExpansion( | 819 all_settings_dictionary->RemoveWithoutPathExpansion( |
| 777 pattern_str, NULL); | 820 pattern_str, NULL); |
| 778 } | 821 } |
| 779 } | 822 } |
| 780 } | 823 } |
| 781 | 824 |
| 782 void PrefProvider::UpdatePatternPairsPref( | 825 void PrefProvider::UpdatePatternPairsSettings( |
| 783 const ContentSettingsPattern& primary_pattern, | 826 const ContentSettingsPattern& primary_pattern, |
| 784 const ContentSettingsPattern& secondary_pattern, | 827 const ContentSettingsPattern& secondary_pattern, |
| 785 ContentSettingsType content_type, | 828 ContentSettingsType content_type, |
| 786 const ResourceIdentifier& resource_identifier, | 829 const ResourceIdentifier& resource_identifier, |
| 787 ContentSetting setting) { | 830 ContentSetting setting, |
| 788 DictionaryPrefUpdate update(prefs_, | 831 DictionaryValue* pattern_pairs_settings) { |
| 789 prefs::kContentSettingsPatternPairs); | |
| 790 DictionaryValue* all_settings_dictionary = update.Get(); | |
| 791 | |
| 792 // Get settings dictionary for the given patterns. | 832 // Get settings dictionary for the given patterns. |
| 793 std::string pattern_str(CreatePatternString(primary_pattern, | 833 std::string pattern_str(CreatePatternString(primary_pattern, |
| 794 secondary_pattern)); | 834 secondary_pattern)); |
| 795 DictionaryValue* settings_dictionary = NULL; | 835 DictionaryValue* settings_dictionary = NULL; |
| 796 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 836 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion( |
| 797 pattern_str, &settings_dictionary); | 837 pattern_str, &settings_dictionary); |
| 798 | 838 |
| 799 if (!found && (setting != CONTENT_SETTING_DEFAULT)) { | 839 if (!found && (setting != CONTENT_SETTING_DEFAULT)) { |
| 800 settings_dictionary = new DictionaryValue; | 840 settings_dictionary = new DictionaryValue; |
| 801 all_settings_dictionary->SetWithoutPathExpansion( | 841 pattern_pairs_settings->SetWithoutPathExpansion( |
| 802 pattern_str, settings_dictionary); | 842 pattern_str, settings_dictionary); |
| 803 } | 843 } |
| 804 | 844 |
| 805 if (settings_dictionary) { | 845 if (settings_dictionary) { |
| 806 if (RequiresResourceIdentifier(content_type)) { | 846 if (RequiresResourceIdentifier(content_type)) { |
| 807 // Get resource dictionary. | 847 // Get resource dictionary. |
| 808 std::string res_dictionary_path(kResourceTypeNames[content_type]); | 848 std::string res_dictionary_path(kResourceTypeNames[content_type]); |
| 809 DictionaryValue* resource_dictionary = NULL; | 849 DictionaryValue* resource_dictionary = NULL; |
| 810 found = settings_dictionary->GetDictionary( | 850 found = settings_dictionary->GetDictionary( |
| 811 res_dictionary_path, &resource_dictionary); | 851 res_dictionary_path, &resource_dictionary); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 833 if (setting == CONTENT_SETTING_DEFAULT) { | 873 if (setting == CONTENT_SETTING_DEFAULT) { |
| 834 settings_dictionary->RemoveWithoutPathExpansion(setting_path, | 874 settings_dictionary->RemoveWithoutPathExpansion(setting_path, |
| 835 NULL); | 875 NULL); |
| 836 } else { | 876 } else { |
| 837 settings_dictionary->SetWithoutPathExpansion( | 877 settings_dictionary->SetWithoutPathExpansion( |
| 838 setting_path, Value::CreateIntegerValue(setting)); | 878 setting_path, Value::CreateIntegerValue(setting)); |
| 839 } | 879 } |
| 840 } | 880 } |
| 841 // Remove the settings dictionary if it is empty. | 881 // Remove the settings dictionary if it is empty. |
| 842 if (settings_dictionary->empty()) { | 882 if (settings_dictionary->empty()) { |
| 843 all_settings_dictionary->RemoveWithoutPathExpansion( | 883 pattern_pairs_settings->RemoveWithoutPathExpansion( |
| 844 pattern_str, NULL); | 884 pattern_str, NULL); |
| 845 } | 885 } |
| 846 } | 886 } |
| 847 } | 887 } |
| 848 | 888 |
| 849 void PrefProvider::UpdateObsoleteGeolocationPref( | 889 void PrefProvider::UpdateObsoleteGeolocationPref( |
| 850 const ContentSettingsPattern& primary_pattern, | 890 const ContentSettingsPattern& primary_pattern, |
| 851 const ContentSettingsPattern& secondary_pattern, | 891 const ContentSettingsPattern& secondary_pattern, |
| 852 ContentSetting setting) { | 892 ContentSetting setting) { |
| 853 if (!prefs_) | 893 if (!prefs_) |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 876 requesting_origin_settings_dictionary = new DictionaryValue; | 916 requesting_origin_settings_dictionary = new DictionaryValue; |
| 877 obsolete_geolocation_settings->SetWithoutPathExpansion( | 917 obsolete_geolocation_settings->SetWithoutPathExpansion( |
| 878 requesting_origin.spec(), requesting_origin_settings_dictionary); | 918 requesting_origin.spec(), requesting_origin_settings_dictionary); |
| 879 } | 919 } |
| 880 DCHECK(requesting_origin_settings_dictionary); | 920 DCHECK(requesting_origin_settings_dictionary); |
| 881 requesting_origin_settings_dictionary->SetWithoutPathExpansion( | 921 requesting_origin_settings_dictionary->SetWithoutPathExpansion( |
| 882 embedding_origin.spec(), Value::CreateIntegerValue(setting)); | 922 embedding_origin.spec(), Value::CreateIntegerValue(setting)); |
| 883 } | 923 } |
| 884 } | 924 } |
| 885 | 925 |
| 926 void PrefProvider::UpdateObsoleteNotificationsSettings( | |
| 927 const ContentSettingsPattern& primary_pattern, | |
| 928 const ContentSettingsPattern& secondary_pattern, | |
| 929 ContentSetting setting, | |
| 930 ListValue* allowed_sites, | |
| 931 ListValue* denied_sites) { | |
| 932 DCHECK_EQ(secondary_pattern, ContentSettingsPattern::Wildcard()); | |
| 933 GURL origin(primary_pattern.ToString()); | |
| 934 DCHECK(origin.is_valid()); | |
| 935 scoped_ptr<StringValue> value(new StringValue(origin.spec())); | |
| 936 if (setting == CONTENT_SETTING_ALLOW) { | |
| 937 denied_sites->Remove(*value, NULL); | |
| 938 allowed_sites->AppendIfNotPresent(value.release()); | |
| 939 } else if (setting == CONTENT_SETTING_BLOCK) { | |
| 940 allowed_sites->Remove(*value, NULL); | |
| 941 denied_sites->AppendIfNotPresent(value.release()); | |
| 942 } else if (setting == CONTENT_SETTING_DEFAULT) { | |
| 943 denied_sites->Remove(*value, NULL); | |
| 944 allowed_sites->Remove(*value, NULL); | |
| 945 } else { | |
| 946 NOTREACHED() << "Setting value: " << setting | |
| 947 << " is not supported for notifications"; | |
| 948 } | |
| 949 } | |
| 950 | |
| 886 // static | 951 // static |
| 887 void PrefProvider::CanonicalizeContentSettingsExceptions( | 952 void PrefProvider::CanonicalizeContentSettingsExceptions( |
| 888 DictionaryValue* all_settings_dictionary) { | 953 DictionaryValue* all_settings_dictionary) { |
| 889 DCHECK(all_settings_dictionary); | 954 DCHECK(all_settings_dictionary); |
| 890 | 955 |
| 891 std::vector<std::string> remove_items; | 956 std::vector<std::string> remove_items; |
| 892 std::vector<std::pair<std::string, std::string> > move_items; | 957 std::vector<std::pair<std::string, std::string> > move_items; |
| 893 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); | 958 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); |
| 894 i != all_settings_dictionary->end_keys(); ++i) { | 959 i != all_settings_dictionary->end_keys(); ++i) { |
| 895 const std::string& pattern_str(*i); | 960 const std::string& pattern_str(*i); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 new_key, settings_dictionary_copy.release()); | 1218 new_key, settings_dictionary_copy.release()); |
| 1154 } | 1219 } |
| 1155 } | 1220 } |
| 1156 } | 1221 } |
| 1157 } | 1222 } |
| 1158 | 1223 |
| 1159 void PrefProvider::MigrateObsoleteGeolocationPref() { | 1224 void PrefProvider::MigrateObsoleteGeolocationPref() { |
| 1160 if (!prefs_->HasPrefPath(prefs::kGeolocationContentSettings)) | 1225 if (!prefs_->HasPrefPath(prefs::kGeolocationContentSettings)) |
| 1161 return; | 1226 return; |
| 1162 | 1227 |
| 1228 DictionaryPrefUpdate update(prefs_, | |
| 1229 prefs::kContentSettingsPatternPairs); | |
| 1230 DictionaryValue* pattern_pairs_settings = update.Get(); | |
| 1231 | |
| 1163 const DictionaryValue* geolocation_settings = | 1232 const DictionaryValue* geolocation_settings = |
| 1164 prefs_->GetDictionary(prefs::kGeolocationContentSettings); | 1233 prefs_->GetDictionary(prefs::kGeolocationContentSettings); |
| 1165 for (DictionaryValue::key_iterator i = | 1234 for (DictionaryValue::key_iterator i = |
| 1166 geolocation_settings->begin_keys(); | 1235 geolocation_settings->begin_keys(); |
| 1167 i != geolocation_settings->end_keys(); | 1236 i != geolocation_settings->end_keys(); |
| 1168 ++i) { | 1237 ++i) { |
| 1169 const std::string& primary_key(*i); | 1238 const std::string& primary_key(*i); |
| 1170 GURL primary_url(primary_key); | 1239 GURL primary_url(primary_key); |
| 1171 DCHECK(primary_url.is_valid()); | 1240 DCHECK(primary_url.is_valid()); |
| 1172 | 1241 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1187 found = requesting_origin_settings->GetIntegerWithoutPathExpansion( | 1256 found = requesting_origin_settings->GetIntegerWithoutPathExpansion( |
| 1188 secondary_key, &setting_value); | 1257 secondary_key, &setting_value); |
| 1189 DCHECK(found); | 1258 DCHECK(found); |
| 1190 | 1259 |
| 1191 ContentSettingsPattern primary_pattern = | 1260 ContentSettingsPattern primary_pattern = |
| 1192 ContentSettingsPattern::FromURLNoWildcard(primary_url); | 1261 ContentSettingsPattern::FromURLNoWildcard(primary_url); |
| 1193 ContentSettingsPattern secondary_pattern = | 1262 ContentSettingsPattern secondary_pattern = |
| 1194 ContentSettingsPattern::FromURLNoWildcard(secondary_url); | 1263 ContentSettingsPattern::FromURLNoWildcard(secondary_url); |
| 1195 DCHECK(primary_pattern.IsValid() && secondary_pattern.IsValid()); | 1264 DCHECK(primary_pattern.IsValid() && secondary_pattern.IsValid()); |
| 1196 | 1265 |
| 1197 UpdatePatternPairsPref(primary_pattern, | 1266 UpdatePatternPairsSettings(primary_pattern, |
| 1198 secondary_pattern, | 1267 secondary_pattern, |
| 1199 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 1268 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 1200 std::string(), | 1269 std::string(), |
| 1201 IntToContentSetting(setting_value)); | 1270 IntToContentSetting(setting_value), |
| 1271 pattern_pairs_settings); | |
| 1202 } | 1272 } |
| 1203 } | 1273 } |
| 1204 } | 1274 } |
| 1205 | 1275 |
| 1206 void PrefProvider::SyncObsoleteGeolocationPref() { | 1276 void PrefProvider::MigrateObsoleteNotificationsPrefs() { |
| 1277 // The notifications settings in the preferences | |
| 1278 // prefs::kContentSettingsPatternPairs do not contain the latest | |
| 1279 // notifications settings. So all notification settings are cleared and | |
| 1280 // migrated from the obsolete preferences for notifications settings that | |
| 1281 // contain the latest settings. | |
| 1282 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs); | |
| 1283 DictionaryValue* pattern_pairs_settings = update.Get(); | |
| 1284 ClearSettings(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, pattern_pairs_settings); | |
| 1285 | |
| 1286 const ListValue* allow_sites = | |
|
battre
2011/08/29 17:44:04
nit: rename to allowed_origins (+ed, sites-->origi
markusheintz_
2011/08/30 15:14:02
Done.
| |
| 1287 prefs_->GetList(prefs::kDesktopNotificationAllowedOrigins); | |
| 1288 for (size_t i = 0; i < allow_sites->GetSize(); ++i) { | |
| 1289 std::string url_string; | |
| 1290 bool status = allow_sites->GetString(i, &url_string); | |
| 1291 DCHECK(status); | |
| 1292 ContentSettingsPattern primary_pattern = | |
| 1293 ContentSettingsPattern::FromURLNoWildcard(GURL(url_string)); | |
| 1294 DCHECK(primary_pattern.IsValid()); | |
| 1295 UpdatePatternPairsSettings(primary_pattern, | |
| 1296 ContentSettingsPattern::Wildcard(), | |
| 1297 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 1298 std::string(), | |
| 1299 CONTENT_SETTING_ALLOW, | |
| 1300 pattern_pairs_settings); | |
| 1301 } | |
| 1302 | |
| 1303 const ListValue* denied_sites = | |
|
battre
2011/08/29 17:44:04
dito
markusheintz_
2011/08/30 15:14:02
Done.
| |
| 1304 prefs_->GetList(prefs::kDesktopNotificationDeniedOrigins); | |
| 1305 for (size_t i = 0; i < denied_sites->GetSize(); ++i) { | |
| 1306 std::string url_string; | |
| 1307 bool status = denied_sites->GetString(i, &url_string); | |
| 1308 DCHECK(status); | |
| 1309 ContentSettingsPattern primary_pattern = | |
| 1310 ContentSettingsPattern::FromURLNoWildcard(GURL(url_string)); | |
| 1311 DCHECK(primary_pattern.IsValid()); | |
| 1312 UpdatePatternPairsSettings(primary_pattern, | |
| 1313 ContentSettingsPattern::Wildcard(), | |
| 1314 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 1315 std::string(), | |
| 1316 CONTENT_SETTING_BLOCK, | |
| 1317 pattern_pairs_settings); | |
| 1318 } | |
| 1319 } | |
| 1320 | |
| 1321 void PrefProvider::SyncObsoletePrefs() { | |
| 1207 DCHECK(prefs_); | 1322 DCHECK(prefs_); |
| 1208 DCHECK(prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs)); | 1323 DCHECK(prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs)); |
| 1209 | 1324 |
| 1210 // Clear the obsolete preference for geolocation settings. Then copy all | 1325 // Clear obsolete preferences first. Then copy the settings from the new |
| 1211 // geolocation settings from the new preference to the obsolete one. | 1326 // preference to the obsolete ones. |
| 1212 prefs_->ClearPref(prefs::kGeolocationContentSettings); | 1327 prefs_->ClearPref(prefs::kGeolocationContentSettings); |
| 1328 prefs_->ClearPref(prefs::kDesktopNotificationAllowedOrigins); | |
| 1329 prefs_->ClearPref(prefs::kDesktopNotificationDeniedOrigins); | |
| 1330 | |
| 1331 ListPrefUpdate update_allowed_sites( | |
|
battre
2011/08/29 17:44:04
dito
markusheintz_
2011/08/30 15:14:02
Done.
| |
| 1332 prefs_, prefs::kDesktopNotificationAllowedOrigins); | |
| 1333 ListPrefUpdate update_denied_sites( | |
| 1334 prefs_, prefs::kDesktopNotificationDeniedOrigins); | |
| 1335 ListValue* allowed_sites = update_allowed_sites.Get(); | |
| 1336 ListValue* denied_sites = update_denied_sites.Get(); | |
| 1337 | |
| 1213 const DictionaryValue* pattern_pairs_dictionary = | 1338 const DictionaryValue* pattern_pairs_dictionary = |
| 1214 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); | 1339 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 1215 for (DictionaryValue::key_iterator i = | 1340 for (DictionaryValue::key_iterator i = |
| 1216 pattern_pairs_dictionary->begin_keys(); | 1341 pattern_pairs_dictionary->begin_keys(); |
| 1217 i != pattern_pairs_dictionary->end_keys(); | 1342 i != pattern_pairs_dictionary->end_keys(); |
| 1218 ++i) { | 1343 ++i) { |
| 1219 const std::string& key(*i); | 1344 const std::string& key(*i); |
| 1220 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = | 1345 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = |
| 1221 ParsePatternString(key); | 1346 ParsePatternString(key); |
| 1222 DCHECK(pattern_pair.first.IsValid() && pattern_pair.second.IsValid()); | 1347 DCHECK(pattern_pair.first.IsValid() && pattern_pair.second.IsValid()); |
| 1223 | 1348 |
| 1224 DictionaryValue* settings_dictionary = NULL; | 1349 DictionaryValue* settings_dictionary = NULL; |
| 1225 bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion( | 1350 pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion( |
| 1226 key, &settings_dictionary); | 1351 key, &settings_dictionary); |
| 1227 DCHECK(found); | |
| 1228 | 1352 |
| 1229 if (settings_dictionary->HasKey( | 1353 int setting_value = 0; |
| 1230 kTypeNames[CONTENT_SETTINGS_TYPE_GEOLOCATION])) { | 1354 if (settings_dictionary->GetInteger( |
| 1231 int setting_value; | 1355 kTypeNames[CONTENT_SETTINGS_TYPE_NOTIFICATIONS], &setting_value)) { |
| 1232 settings_dictionary->GetInteger( | 1356 UpdateObsoleteNotificationsSettings(pattern_pair.first, |
| 1233 kTypeNames[CONTENT_SETTINGS_TYPE_GEOLOCATION], &setting_value); | 1357 pattern_pair.second, |
| 1358 ContentSetting(setting_value), | |
| 1359 allowed_sites, | |
| 1360 denied_sites); | |
| 1361 } | |
| 1234 | 1362 |
| 1363 setting_value = 0; | |
| 1364 if (settings_dictionary->GetInteger( | |
| 1365 kTypeNames[CONTENT_SETTINGS_TYPE_GEOLOCATION], &setting_value)) { | |
| 1235 UpdateObsoleteGeolocationPref(pattern_pair.first, | 1366 UpdateObsoleteGeolocationPref(pattern_pair.first, |
| 1236 pattern_pair.second, | 1367 pattern_pair.second, |
| 1237 ContentSetting(setting_value)); | 1368 ContentSetting(setting_value)); |
| 1238 } | 1369 } |
| 1239 } | 1370 } |
| 1240 } | 1371 } |
| 1241 | 1372 |
| 1242 } // namespace content_settings | 1373 } // namespace content_settings |
| OLD | NEW |