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 <list> | 7 #include <list> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 20 matching lines...) Expand all Loading... | |
31 namespace { | 31 namespace { |
32 | 32 |
33 // The preference keys where resource identifiers are stored for | 33 // The preference keys where resource identifiers are stored for |
34 // ContentSettingsType values that support resource identifiers. | 34 // ContentSettingsType values that support resource identifiers. |
35 const char* kResourceTypeNames[] = { | 35 const char* kResourceTypeNames[] = { |
36 NULL, | 36 NULL, |
37 NULL, | 37 NULL, |
38 NULL, | 38 NULL, |
39 "per_plugin", | 39 "per_plugin", |
40 NULL, | 40 NULL, |
41 NULL, // Not used for Geolocation | 41 NULL, |
42 NULL, // Not used for Notifications | 42 NULL, // Not used for Notifications |
43 }; | 43 }; |
44 COMPILE_ASSERT(arraysize(kResourceTypeNames) == CONTENT_SETTINGS_NUM_TYPES, | 44 COMPILE_ASSERT(arraysize(kResourceTypeNames) == CONTENT_SETTINGS_NUM_TYPES, |
45 resource_type_names_incorrect_size); | 45 resource_type_names_incorrect_size); |
46 | 46 |
47 // The default setting for each content type. | 47 // The default setting for each content type. |
48 const ContentSetting kDefaultSettings[] = { | 48 const ContentSetting kDefaultSettings[] = { |
49 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES | 49 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES |
50 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES | 50 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_IMAGES |
51 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT | 51 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_JAVASCRIPT |
52 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS | 52 CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_PLUGINS |
53 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS | 53 CONTENT_SETTING_BLOCK, // CONTENT_SETTINGS_TYPE_POPUPS |
54 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_GEOLOCATION | 54 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_GEOLOCATION |
55 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_NOTIFICATIONS | 55 CONTENT_SETTING_ASK, // CONTENT_SETTINGS_TYPE_NOTIFICATIONS |
56 }; | 56 }; |
57 COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, | 57 COMPILE_ASSERT(arraysize(kDefaultSettings) == CONTENT_SETTINGS_NUM_TYPES, |
58 default_settings_incorrect_size); | 58 default_settings_incorrect_size); |
59 | 59 |
60 // The names of the ContentSettingsType values, for use with dictionary prefs. | 60 // The names of the ContentSettingsType values, for use with dictionary prefs. |
61 const char* kTypeNames[] = { | 61 const char* kTypeNames[] = { |
62 "cookies", | 62 "cookies", |
63 "images", | 63 "images", |
64 "javascript", | 64 "javascript", |
65 "plugins", | 65 "plugins", |
66 "popups", | 66 "popups", |
67 "geolocation", | |
67 // TODO(markusheintz): Refactoring in progress. Content settings exceptions | 68 // TODO(markusheintz): Refactoring in progress. Content settings exceptions |
68 // for notifications and geolocation will be added next. | 69 // for notifications added next. |
69 "geolocation", // Only used for default Geolocation settings | |
70 "notifications", // Only used for default Notifications settings. | 70 "notifications", // Only used for default Notifications settings. |
71 }; | 71 }; |
72 COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, | 72 COMPILE_ASSERT(arraysize(kTypeNames) == CONTENT_SETTINGS_NUM_TYPES, |
73 type_names_incorrect_size); | 73 type_names_incorrect_size); |
74 | 74 |
75 void SetDefaultContentSettings(DictionaryValue* default_settings) { | 75 void SetDefaultContentSettings(DictionaryValue* default_settings) { |
76 default_settings->Clear(); | 76 default_settings->Clear(); |
77 | 77 |
78 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 78 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
79 if (kTypeNames[i] != NULL) { | 79 if (kTypeNames[i] != NULL) { |
80 default_settings->SetInteger(kTypeNames[i], | 80 default_settings->SetInteger(kTypeNames[i], |
81 kDefaultSettings[i]); | 81 kDefaultSettings[i]); |
82 } | 82 } |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 void CopyKeys(DictionaryValue* source, | |
Bernhard Bauer
2011/08/09 14:09:45
Didn't you already delete this?
markusheintz_
2011/08/09 14:40:49
*Grrrr* to myself. Sorry that sneaked back in with
| |
87 DictionaryValue* target, | |
88 const char** keys_to_copy, | |
89 size_t size) { | |
90 for (DictionaryValue::key_iterator i(source->begin_keys()); | |
91 i != source->end_keys(); ++i) { | |
92 const std::string& key(*i); | |
93 for (size_t i = 0; i < size; ++i) { | |
94 if ((keys_to_copy[i] != NULL) && (keys_to_copy[i] == key)) { | |
95 Value* value; | |
96 bool found = source->GetWithoutPathExpansion( | |
97 key, &value); | |
98 DCHECK(found); | |
99 target->SetWithoutPathExpansion(key, value->DeepCopy()); | |
100 break; | |
101 } | |
102 } | |
103 } | |
104 } | |
105 | |
86 ContentSetting ValueToContentSetting(Value* value) { | 106 ContentSetting ValueToContentSetting(Value* value) { |
87 int int_value; | 107 int int_value; |
88 value->GetAsInteger(&int_value); | 108 value->GetAsInteger(&int_value); |
89 return IntToContentSetting(int_value); | 109 return IntToContentSetting(int_value); |
90 } | 110 } |
91 | 111 |
92 ContentSettingsType StringToContentSettingsType( | 112 ContentSettingsType StringToContentSettingsType( |
93 const std::string& content_type_str) { | 113 const std::string& content_type_str) { |
94 for (size_t type = 0; type < arraysize(kTypeNames); ++type) { | 114 for (size_t type = 0; type < arraysize(kTypeNames); ++type) { |
95 if ((kTypeNames[type] != NULL) && (kTypeNames[type] == content_type_str)) | 115 if ((kTypeNames[type] != NULL) && (kTypeNames[type] == content_type_str)) |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 // static | 370 // static |
351 void PrefProvider::RegisterUserPrefs(PrefService* prefs) { | 371 void PrefProvider::RegisterUserPrefs(PrefService* prefs) { |
352 prefs->RegisterIntegerPref( | 372 prefs->RegisterIntegerPref( |
353 prefs::kContentSettingsVersion, | 373 prefs::kContentSettingsVersion, |
354 ContentSettingsPattern::kContentSettingsPatternVersion, | 374 ContentSettingsPattern::kContentSettingsPatternVersion, |
355 PrefService::UNSYNCABLE_PREF); | 375 PrefService::UNSYNCABLE_PREF); |
356 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatternPairs, | 376 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatternPairs, |
357 PrefService::SYNCABLE_PREF); | 377 PrefService::SYNCABLE_PREF); |
358 | 378 |
359 // Obsolete prefs, for migration: | 379 // Obsolete prefs, for migration: |
380 prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings, | |
381 PrefService::SYNCABLE_PREF); | |
360 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns, | 382 prefs->RegisterDictionaryPref(prefs::kContentSettingsPatterns, |
361 PrefService::SYNCABLE_PREF); | 383 PrefService::SYNCABLE_PREF); |
362 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts, | 384 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts, |
363 PrefService::UNSYNCABLE_PREF); | 385 PrefService::UNSYNCABLE_PREF); |
364 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings, | 386 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings, |
365 PrefService::UNSYNCABLE_PREF); | 387 PrefService::UNSYNCABLE_PREF); |
366 } | 388 } |
367 | 389 |
368 PrefProvider::PrefProvider(PrefService* prefs, | 390 PrefProvider::PrefProvider(PrefService* prefs, |
369 bool incognito) | 391 bool incognito) |
370 : prefs_(prefs), | 392 : prefs_(prefs), |
371 is_incognito_(incognito), | 393 is_incognito_(incognito), |
372 updating_preferences_(false) { | 394 updating_preferences_(false) { |
373 DCHECK(prefs_); | 395 DCHECK(prefs_); |
374 if (!is_incognito_) { | 396 if (!is_incognito_) { |
375 // Migrate obsolete preferences. | 397 // Migrate obsolete preferences. |
376 MigrateObsoletePerhostPref(); | 398 MigrateObsoletePerhostPref(); |
377 MigrateObsoletePopupsPref(); | 399 MigrateObsoletePopupsPref(); |
378 MigrateObsoleteContentSettingsPatternPref(); | 400 MigrateObsoleteContentSettingsPatternPref(); |
401 MigrateObsoleteGeolocationPref(); | |
379 } | 402 } |
380 | 403 |
381 // Verify preferences version. | 404 // Verify preferences version. |
382 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) { | 405 if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) { |
383 prefs_->SetInteger(prefs::kContentSettingsVersion, | 406 prefs_->SetInteger(prefs::kContentSettingsVersion, |
384 ContentSettingsPattern::kContentSettingsPatternVersion); | 407 ContentSettingsPattern::kContentSettingsPatternVersion); |
385 } | 408 } |
386 if (prefs_->GetInteger(prefs::kContentSettingsVersion) > | 409 if (prefs_->GetInteger(prefs::kContentSettingsVersion) > |
387 ContentSettingsPattern::kContentSettingsPatternVersion) { | 410 ContentSettingsPattern::kContentSettingsPatternVersion) { |
388 return; | 411 return; |
389 } | 412 } |
390 | 413 |
391 // Read content settings exceptions. | 414 // Read content settings exceptions. |
392 ReadContentSettingsFromPref(false); | 415 ReadContentSettingsFromPref(false); |
393 | 416 |
394 if (!is_incognito_) { | 417 if (!is_incognito_) { |
395 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", | 418 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", |
396 value_map_.size()); | 419 value_map_.size()); |
397 } | 420 } |
398 | 421 |
399 pref_change_registrar_.Init(prefs_); | 422 pref_change_registrar_.Init(prefs_); |
400 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); | 423 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); |
401 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); | 424 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); |
425 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); | |
402 } | 426 } |
403 | 427 |
404 ContentSetting PrefProvider::GetContentSetting( | 428 ContentSetting PrefProvider::GetContentSetting( |
405 const GURL& primary_url, | 429 const GURL& primary_url, |
406 const GURL& secondary_url, | 430 const GURL& secondary_url, |
407 ContentSettingsType content_type, | 431 ContentSettingsType content_type, |
408 const ResourceIdentifier& resource_identifier) const { | 432 const ResourceIdentifier& resource_identifier) const { |
409 // For a |PrefProvider| used in a |HostContentSettingsMap| of a non incognito | 433 // For a |PrefProvider| used in a |HostContentSettingsMap| of a non incognito |
410 // profile, this will always return NULL. | 434 // profile, this will always return NULL. |
411 // TODO(markusheintz): I don't like this. I'd like to have an | 435 // TODO(markusheintz): I don't like this. I'd like to have an |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 } | 482 } |
459 | 483 |
460 void PrefProvider::SetContentSetting( | 484 void PrefProvider::SetContentSetting( |
461 const ContentSettingsPattern& primary_pattern, | 485 const ContentSettingsPattern& primary_pattern, |
462 const ContentSettingsPattern& secondary_pattern, | 486 const ContentSettingsPattern& secondary_pattern, |
463 ContentSettingsType content_type, | 487 ContentSettingsType content_type, |
464 const ResourceIdentifier& resource_identifier, | 488 const ResourceIdentifier& resource_identifier, |
465 ContentSetting setting) { | 489 ContentSetting setting) { |
466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
467 DCHECK(prefs_); | 491 DCHECK(prefs_); |
468 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 492 DCHECK(kTypeNames[content_type] != NULL); |
469 | 493 |
470 // Update in memory value map. | 494 // Update in memory value map. |
471 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; | 495 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; |
472 if (!is_incognito_) | 496 if (!is_incognito_) |
473 map_to_modify = &value_map_; | 497 map_to_modify = &value_map_; |
474 | 498 |
475 { | 499 { |
476 base::AutoLock auto_lock(lock_); | 500 base::AutoLock auto_lock(lock_); |
477 if (setting == CONTENT_SETTING_DEFAULT) { | 501 if (setting == CONTENT_SETTING_DEFAULT) { |
478 map_to_modify->DeleteValue( | 502 map_to_modify->DeleteValue( |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 const NotificationDetails& details) { | 568 const NotificationDetails& details) { |
545 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
546 | 570 |
547 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 571 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
548 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); | 572 DCHECK_EQ(prefs_, Source<PrefService>(source).ptr()); |
549 if (updating_preferences_) | 573 if (updating_preferences_) |
550 return; | 574 return; |
551 | 575 |
552 std::string* name = Details<std::string>(details).ptr(); | 576 std::string* name = Details<std::string>(details).ptr(); |
553 if (*name == prefs::kContentSettingsPatternPairs) { | 577 if (*name == prefs::kContentSettingsPatternPairs) { |
554 SyncObsoletePref(); | 578 SyncObsoletePatternPref(); |
579 SyncObsoleteGeolocationPref(); | |
555 ReadContentSettingsFromPref(true); | 580 ReadContentSettingsFromPref(true); |
556 } else if (*name == prefs::kContentSettingsPatterns) { | 581 } else if (*name == prefs::kContentSettingsPatterns) { |
557 AutoReset<bool> auto_reset(&updating_preferences_, true); | 582 AutoReset<bool> auto_reset(&updating_preferences_, true); |
558 MigrateObsoleteContentSettingsPatternPref(); | 583 MigrateObsoleteContentSettingsPatternPref(); |
559 ReadContentSettingsFromPref(true); | 584 ReadContentSettingsFromPref(true); |
585 } else if (*name == prefs::kGeolocationContentSettings) { | |
586 AutoReset<bool> auto_reset(&updating_preferences_, true); | |
587 MigrateObsoleteGeolocationPref(); | |
588 ReadContentSettingsFromPref(true); | |
560 } else { | 589 } else { |
561 NOTREACHED() << "Unexpected preference observed"; | 590 NOTREACHED() << "Unexpected preference observed"; |
562 return; | 591 return; |
563 } | 592 } |
564 | 593 |
565 NotifyObservers(ContentSettingsPattern(), | 594 NotifyObservers(ContentSettingsPattern(), |
566 ContentSettingsPattern(), | 595 ContentSettingsPattern(), |
567 CONTENT_SETTINGS_TYPE_DEFAULT, | 596 CONTENT_SETTINGS_TYPE_DEFAULT, |
568 std::string()); | 597 std::string()); |
569 } else { | 598 } else { |
(...skipping 13 matching lines...) Expand all Loading... | |
583 const ContentSettingsPattern& secondary_pattern, | 612 const ContentSettingsPattern& secondary_pattern, |
584 ContentSettingsType content_type, | 613 ContentSettingsType content_type, |
585 const ResourceIdentifier& resource_identifier, | 614 const ResourceIdentifier& resource_identifier, |
586 ContentSetting setting) { | 615 ContentSetting setting) { |
587 AutoReset<bool> auto_reset(&updating_preferences_, true); | 616 AutoReset<bool> auto_reset(&updating_preferences_, true); |
588 UpdatePatternPairsPref(primary_pattern, | 617 UpdatePatternPairsPref(primary_pattern, |
589 secondary_pattern, | 618 secondary_pattern, |
590 content_type, | 619 content_type, |
591 resource_identifier, | 620 resource_identifier, |
592 setting); | 621 setting); |
593 UpdatePatternsPref(primary_pattern, | 622 if (content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION && |
594 secondary_pattern, | 623 content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
595 content_type, | 624 UpdateObsoletePatternsPref(primary_pattern, |
596 resource_identifier, | 625 secondary_pattern, |
597 setting); | 626 content_type, |
627 resource_identifier, | |
628 setting); | |
629 } | |
630 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | |
631 UpdateObsoleteGeolocationPref(primary_pattern, secondary_pattern, setting); | |
632 } | |
598 } | 633 } |
599 | 634 |
600 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { | 635 void PrefProvider::ReadContentSettingsFromPref(bool overwrite) { |
601 base::AutoLock auto_lock(lock_); | 636 base::AutoLock auto_lock(lock_); |
602 | 637 |
603 const DictionaryValue* all_settings_dictionary = | 638 const DictionaryValue* all_settings_dictionary = |
604 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); | 639 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); |
605 | 640 |
606 if (overwrite) | 641 if (overwrite) |
607 value_map_.clear(); | 642 value_map_.clear(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 content_type, | 717 content_type, |
683 ResourceIdentifier(""), | 718 ResourceIdentifier(""), |
684 Value::CreateIntegerValue(setting)); | 719 Value::CreateIntegerValue(setting)); |
685 } | 720 } |
686 } | 721 } |
687 } | 722 } |
688 } | 723 } |
689 } | 724 } |
690 } | 725 } |
691 | 726 |
692 void PrefProvider::UpdatePatternsPref( | 727 void PrefProvider::UpdateObsoletePatternsPref( |
693 const ContentSettingsPattern& primary_pattern, | 728 const ContentSettingsPattern& primary_pattern, |
694 const ContentSettingsPattern& secondary_pattern, | 729 const ContentSettingsPattern& secondary_pattern, |
695 ContentSettingsType content_type, | 730 ContentSettingsType content_type, |
696 const ResourceIdentifier& resource_identifier, | 731 const ResourceIdentifier& resource_identifier, |
697 ContentSetting setting) { | 732 ContentSetting setting) { |
698 DictionaryPrefUpdate update(prefs_, | 733 DictionaryPrefUpdate update(prefs_, |
699 prefs::kContentSettingsPatterns); | 734 prefs::kContentSettingsPatterns); |
700 DictionaryValue* all_settings_dictionary = update.Get(); | 735 DictionaryValue* all_settings_dictionary = update.Get(); |
701 | 736 |
702 // Get settings dictionary for |primary_pattern|. | 737 // Get settings dictionary for |primary_pattern|. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 } | 850 } |
816 } | 851 } |
817 // Remove the settings dictionary if it is empty. | 852 // Remove the settings dictionary if it is empty. |
818 if (settings_dictionary->empty()) { | 853 if (settings_dictionary->empty()) { |
819 all_settings_dictionary->RemoveWithoutPathExpansion( | 854 all_settings_dictionary->RemoveWithoutPathExpansion( |
820 pattern_str, NULL); | 855 pattern_str, NULL); |
821 } | 856 } |
822 } | 857 } |
823 } | 858 } |
824 | 859 |
860 void PrefProvider::UpdateObsoleteGeolocationPref( | |
861 const ContentSettingsPattern& primary_pattern, | |
862 const ContentSettingsPattern& secondary_pattern, | |
863 ContentSetting setting) { | |
864 if (!prefs_) | |
865 return; | |
866 | |
867 const GURL requesting_origin(primary_pattern.ToString()); | |
868 const GURL embedding_origin(secondary_pattern.ToString()); | |
869 DCHECK(requesting_origin.is_valid() && embedding_origin.is_valid()); | |
870 | |
871 DictionaryPrefUpdate update(prefs_, prefs::kGeolocationContentSettings); | |
872 DictionaryValue* all_settings_dictionary = update.Get(); | |
873 DictionaryValue* requesting_origin_settings_dictionary = NULL; | |
874 all_settings_dictionary->GetDictionaryWithoutPathExpansion( | |
875 requesting_origin.spec(), &requesting_origin_settings_dictionary); | |
876 if (setting == CONTENT_SETTING_DEFAULT) { | |
877 if (requesting_origin_settings_dictionary) { | |
878 requesting_origin_settings_dictionary->RemoveWithoutPathExpansion( | |
879 embedding_origin.spec(), NULL); | |
880 if (requesting_origin_settings_dictionary->empty()) | |
Bernhard Bauer
2011/08/09 14:09:45
Nit: curlies please.
markusheintz_
2011/08/09 14:40:49
Done.
| |
881 all_settings_dictionary->RemoveWithoutPathExpansion( | |
882 requesting_origin.spec(), NULL); | |
883 } | |
884 } else { | |
885 if (!requesting_origin_settings_dictionary) { | |
886 requesting_origin_settings_dictionary = new DictionaryValue; | |
887 all_settings_dictionary->SetWithoutPathExpansion( | |
888 requesting_origin.spec(), requesting_origin_settings_dictionary); | |
889 } | |
890 DCHECK(requesting_origin_settings_dictionary); | |
891 requesting_origin_settings_dictionary->SetWithoutPathExpansion( | |
892 embedding_origin.spec(), Value::CreateIntegerValue(setting)); | |
893 } | |
894 } | |
895 | |
825 // static | 896 // static |
826 void PrefProvider::CanonicalizeContentSettingsExceptions( | 897 void PrefProvider::CanonicalizeContentSettingsExceptions( |
827 DictionaryValue* all_settings_dictionary) { | 898 DictionaryValue* all_settings_dictionary) { |
828 DCHECK(all_settings_dictionary); | 899 DCHECK(all_settings_dictionary); |
829 | 900 |
830 std::vector<std::string> remove_items; | 901 std::vector<std::string> remove_items; |
831 std::vector<std::pair<std::string, std::string> > move_items; | 902 std::vector<std::pair<std::string, std::string> > move_items; |
832 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); | 903 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); |
833 i != all_settings_dictionary->end_keys(); ++i) { | 904 i != all_settings_dictionary->end_keys(); ++i) { |
834 const std::string& pattern_str(*i); | 905 const std::string& pattern_str(*i); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
957 CONTENT_SETTINGS_TYPE_POPUPS, | 1028 CONTENT_SETTINGS_TYPE_POPUPS, |
958 "", | 1029 "", |
959 CONTENT_SETTING_ALLOW); | 1030 CONTENT_SETTING_ALLOW); |
960 } | 1031 } |
961 prefs_->ClearPref(prefs::kPopupWhitelistedHosts); | 1032 prefs_->ClearPref(prefs::kPopupWhitelistedHosts); |
962 } | 1033 } |
963 } | 1034 } |
964 | 1035 |
965 void PrefProvider::MigrateObsoleteContentSettingsPatternPref() { | 1036 void PrefProvider::MigrateObsoleteContentSettingsPatternPref() { |
966 if (prefs_->HasPrefPath(prefs::kContentSettingsPatterns) && !is_incognito_) { | 1037 if (prefs_->HasPrefPath(prefs::kContentSettingsPatterns) && !is_incognito_) { |
967 const DictionaryValue* all_settings_dictionary = | 1038 const DictionaryValue* patterns_dictionary = |
968 prefs_->GetDictionary(prefs::kContentSettingsPatterns); | 1039 prefs_->GetDictionary(prefs::kContentSettingsPatterns); |
969 | 1040 |
970 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs); | 1041 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs); |
971 DictionaryValue* exceptions_dictionary; | 1042 DictionaryValue* exceptions_dictionary; |
972 exceptions_dictionary = update.Get(); | 1043 exceptions_dictionary = update.Get(); |
973 for (DictionaryValue::key_iterator i(all_settings_dictionary->begin_keys()); | 1044 for (DictionaryValue::key_iterator i(patterns_dictionary->begin_keys()); |
974 i != all_settings_dictionary->end_keys(); | 1045 i != patterns_dictionary->end_keys(); |
975 ++i) { | 1046 ++i) { |
976 const std::string& key(*i); | 1047 const std::string& key(*i); |
977 if (key.empty()) | 1048 if (key.empty()) |
978 continue; | 1049 continue; |
979 | 1050 |
980 // Validate pattern string and skip it if it is invalid. | 1051 // Validate pattern string and skip it if it is invalid. |
981 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = | 1052 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = |
982 ParsePatternString(key); | 1053 ParsePatternString(key); |
983 const ContentSettingsPattern& primary_pattern = pattern_pair.first; | 1054 const ContentSettingsPattern& primary_pattern = pattern_pair.first; |
984 if (!primary_pattern.IsValid()) { | 1055 if (!primary_pattern.IsValid()) { |
985 LOG(DFATAL) << "Invalid pattern strings: " << key; | 1056 LOG(DFATAL) << "Invalid pattern strings: " << key; |
986 continue; | 1057 continue; |
987 } | 1058 } |
988 | 1059 |
989 // Copy dictionary value. | 1060 // Copy dictionary value. |
990 // Get old settings. | 1061 // Get old settings. |
991 DictionaryValue* dictionary = NULL; | 1062 DictionaryValue* dictionary = NULL; |
992 bool found = all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 1063 bool found = patterns_dictionary->GetDictionaryWithoutPathExpansion( |
993 key, &dictionary); | 1064 key, &dictionary); |
994 DCHECK(found); | 1065 DCHECK(found); |
995 | 1066 |
996 // Create new dictionary key. | 1067 // Create new dictionary key. |
997 std::string new_pattern_str = CreatePatternString( | 1068 std::string new_pattern_str = CreatePatternString( |
998 primary_pattern, ContentSettingsPattern::Wildcard()); | 1069 primary_pattern, ContentSettingsPattern::Wildcard()); |
999 | 1070 |
1000 // Existing values are overwritten. | 1071 // Existing values are overwritten. |
1001 exceptions_dictionary->SetWithoutPathExpansion( | 1072 exceptions_dictionary->SetWithoutPathExpansion( |
1002 new_pattern_str, dictionary->DeepCopy()); | 1073 new_pattern_str, dictionary->DeepCopy()); |
1003 } | 1074 } |
1004 } | 1075 } |
1005 } | 1076 } |
1006 | 1077 |
1007 void PrefProvider::SyncObsoletePref() { | 1078 void PrefProvider::SyncObsoletePatternPref() { |
1008 AutoReset<bool> auto_reset(&updating_preferences_, true); | 1079 AutoReset<bool> auto_reset(&updating_preferences_, true); |
1009 if (prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs) && | 1080 if (prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs) && |
1010 !is_incognito_) { | 1081 !is_incognito_) { |
1011 const DictionaryValue* pattern_pairs_dictionary = | 1082 const DictionaryValue* pattern_pairs_dictionary = |
1012 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); | 1083 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); |
1013 | 1084 |
1014 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatterns); | 1085 DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatterns); |
1015 DictionaryValue* obsolete_settings_dictionary = update.Get(); | 1086 DictionaryValue* obsolete_settings_dictionary = update.Get(); |
1016 | 1087 |
1017 for (DictionaryValue::key_iterator i = | 1088 for (DictionaryValue::key_iterator i = |
1018 pattern_pairs_dictionary->begin_keys(); | 1089 pattern_pairs_dictionary->begin_keys(); |
1019 i != pattern_pairs_dictionary->end_keys(); | 1090 i != pattern_pairs_dictionary->end_keys(); |
1020 ++i) { | 1091 ++i) { |
1021 const std::string& key(*i); | 1092 const std::string& key(*i); |
1022 // Validate pattern string and skip it if it is invalid. | 1093 // Validate pattern string and skip it if it is invalid. |
1023 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = | 1094 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = |
1024 ParsePatternString(key); | 1095 ParsePatternString(key); |
1025 if (!pattern_pair.first.IsValid() || !pattern_pair.second.IsValid()) { | 1096 if (!pattern_pair.first.IsValid() || !pattern_pair.second.IsValid()) { |
1026 LOG(DFATAL) << "Invalid pattern strings: " << key; | 1097 LOG(DFATAL) << "Invalid pattern strings: " << key; |
1027 continue; | 1098 continue; |
1028 } | 1099 } |
1029 | 1100 |
1030 // Copy dictionary | 1101 DictionaryValue* settings_dictionary = NULL; |
1031 DictionaryValue* dictionary = NULL; | |
1032 bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion( | 1102 bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion( |
1033 key, &dictionary); | 1103 key, &settings_dictionary); |
1034 DCHECK(found); | 1104 DCHECK(found); |
1035 std::string new_key = pattern_pair.first.ToString(); | 1105 scoped_ptr<DictionaryValue> settings_dictionary_copy( |
1036 // Existing values are overwritten. | 1106 new DictionaryValue()); |
1037 obsolete_settings_dictionary->SetWithoutPathExpansion( | 1107 for (size_t i = CONTENT_SETTINGS_TYPE_COOKIES; |
1038 new_key, dictionary->DeepCopy()); | 1108 i <= CONTENT_SETTINGS_TYPE_POPUPS; |
1109 ++i) { | |
1110 DCHECK(kTypeNames[i]); | |
1111 std::string type_name(kTypeNames[i]); | |
1112 if (settings_dictionary->HasKey(type_name)) { | |
1113 Value* value = NULL; | |
1114 bool found = settings_dictionary->GetWithoutPathExpansion( | |
1115 type_name, &value); | |
1116 DCHECK(found); | |
1117 settings_dictionary_copy->SetWithoutPathExpansion( | |
1118 type_name, value->DeepCopy()); | |
1119 } | |
1120 } | |
1121 | |
1122 // Ignore empty dictionaryies. | |
1123 if (!settings_dictionary_copy->empty()) { | |
1124 std::string new_key = pattern_pair.first.ToString(); | |
1125 // Existing values are overwritten. | |
1126 obsolete_settings_dictionary->SetWithoutPathExpansion( | |
1127 new_key, settings_dictionary_copy.release()); | |
1128 } | |
1039 } | 1129 } |
1040 } | 1130 } |
1041 } | 1131 } |
1132 | |
1133 void PrefProvider::MigrateObsoleteGeolocationPref() { | |
1134 if (!prefs_->HasPrefPath(prefs::kGeolocationContentSettings)) | |
1135 return; | |
1136 | |
1137 const DictionaryValue* geolocation_settings = | |
1138 prefs_->GetDictionary(prefs::kGeolocationContentSettings); | |
1139 for (DictionaryValue::key_iterator i = | |
1140 geolocation_settings->begin_keys(); | |
1141 i != geolocation_settings->end_keys(); | |
1142 ++i) { | |
1143 const std::string& primary_key(*i); | |
1144 GURL primary_url(primary_key); | |
1145 DCHECK(primary_url.is_valid()); | |
1146 | |
1147 DictionaryValue* requesting_origin_settings = NULL; | |
1148 bool found = geolocation_settings->GetDictionaryWithoutPathExpansion( | |
1149 primary_key, &requesting_origin_settings); | |
1150 DCHECK(found); | |
1151 | |
1152 for (DictionaryValue::key_iterator j = | |
1153 requesting_origin_settings->begin_keys(); | |
1154 j != requesting_origin_settings->end_keys(); | |
1155 ++j) { | |
1156 const std::string& secondary_key(*j); | |
1157 GURL secondary_url(secondary_key); | |
1158 DCHECK(secondary_url.is_valid()); | |
1159 | |
1160 int setting_value; | |
1161 found = requesting_origin_settings->GetIntegerWithoutPathExpansion( | |
1162 secondary_key, &setting_value); | |
1163 DCHECK(found); | |
1164 | |
1165 ContentSettingsPattern primary_pattern = | |
1166 ContentSettingsPattern::FromURLNoWildcard(primary_url); | |
1167 ContentSettingsPattern secondary_pattern = | |
1168 ContentSettingsPattern::FromURLNoWildcard(secondary_url); | |
1169 DCHECK(primary_pattern.IsValid() && secondary_pattern.IsValid()); | |
1170 | |
1171 SetContentSetting(primary_pattern, | |
1172 secondary_pattern, | |
1173 CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
1174 std::string(), | |
1175 IntToContentSetting(setting_value)); | |
1176 } | |
1177 } | |
1178 } | |
1179 | |
1180 void PrefProvider::SyncObsoleteGeolocationPref() { | |
1181 DCHECK(prefs_); | |
1182 DCHECK(prefs_->HasPrefPath(prefs::kContentSettingsPatternPairs)); | |
1183 | |
1184 { | |
Bernhard Bauer
2011/08/09 14:09:45
Nit: No need for the additional scope.
markusheintz_
2011/08/09 14:40:49
Done.
Bernhard Bauer
2011/08/09 14:57:33
Um, no. Scope, not empty line :-)
markusheintz_
2011/08/10 09:33:05
Uups ... I guess I just read "nit" and stopped rea
Bernhard Bauer
2011/08/10 10:40:03
:-D
| |
1185 DictionaryPrefUpdate update(prefs_, prefs::kGeolocationContentSettings); | |
1186 DictionaryValue* obsolete_geolocation_settings = update.Get(); | |
1187 obsolete_geolocation_settings->Clear(); | |
1188 | |
1189 const DictionaryValue* pattern_pairs_dictionary = | |
1190 prefs_->GetDictionary(prefs::kContentSettingsPatternPairs); | |
1191 for (DictionaryValue::key_iterator i = | |
1192 pattern_pairs_dictionary->begin_keys(); | |
1193 i != pattern_pairs_dictionary->end_keys(); | |
1194 ++i) { | |
1195 const std::string& key(*i); | |
1196 std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair = | |
1197 ParsePatternString(key); | |
1198 DCHECK(pattern_pair.first.IsValid() && pattern_pair.second.IsValid()); | |
1199 | |
1200 DictionaryValue* settings_dictionary = NULL; | |
1201 bool found = pattern_pairs_dictionary->GetDictionaryWithoutPathExpansion( | |
1202 key, &settings_dictionary); | |
1203 DCHECK(found); | |
1204 | |
1205 if (settings_dictionary->HasKey( | |
1206 kTypeNames[CONTENT_SETTINGS_TYPE_GEOLOCATION])) { | |
1207 const GURL primary_url(pattern_pair.first.ToString()); | |
1208 const GURL secondary_url(pattern_pair.second.ToString()); | |
1209 DCHECK(primary_url.is_valid() && secondary_url.is_valid()); | |
1210 | |
1211 int setting_value; | |
1212 settings_dictionary->GetInteger( | |
1213 kTypeNames[CONTENT_SETTINGS_TYPE_GEOLOCATION], &setting_value); | |
1214 | |
1215 // Add to obsolete pref. | |
1216 DictionaryValue* one_origin_settings = NULL; | |
1217 bool found = | |
1218 obsolete_geolocation_settings->GetDictionaryWithoutPathExpansion( | |
1219 primary_url.spec(), &one_origin_settings); | |
1220 if (!found) { | |
1221 one_origin_settings = new DictionaryValue(); | |
1222 obsolete_geolocation_settings->SetWithoutPathExpansion( | |
1223 primary_url.spec(), one_origin_settings); | |
1224 } | |
1225 | |
1226 one_origin_settings->SetWithoutPathExpansion( | |
1227 secondary_url.spec(), Value::CreateIntegerValue(setting_value)); | |
1228 } | |
1229 } | |
1230 } | |
1231 } | |
1042 | 1232 |
1043 } // namespace content_settings | 1233 } // namespace content_settings |
OLD | NEW |