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