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