OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/content_settings/core/browser/host_content_settings_map.h" | 5 #include "components/content_settings/core/browser/host_content_settings_map.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 | 49 |
50 const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = { | 50 const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = { |
51 {"platform_app", content_settings::SETTING_SOURCE_EXTENSION}, | 51 {"platform_app", content_settings::SETTING_SOURCE_EXTENSION}, |
52 {"policy", content_settings::SETTING_SOURCE_POLICY}, | 52 {"policy", content_settings::SETTING_SOURCE_POLICY}, |
53 {"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED}, | 53 {"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED}, |
54 {"extension", content_settings::SETTING_SOURCE_EXTENSION}, | 54 {"extension", content_settings::SETTING_SOURCE_EXTENSION}, |
55 {"preference", content_settings::SETTING_SOURCE_USER}, | 55 {"preference", content_settings::SETTING_SOURCE_USER}, |
56 {"default", content_settings::SETTING_SOURCE_USER}, | 56 {"default", content_settings::SETTING_SOURCE_USER}, |
57 }; | 57 }; |
58 | 58 |
59 const ContentSettingsType kMigrateContentSettingTypes[] = { | |
raymes
2016/03/02 04:32:49
nit: could you move this into MigrateOldSettings?
lshang
2016/03/03 02:55:14
Done.
| |
60 // Only content types of scoping type: REQUESTING_DOMAIN_ONLY_SCOPE, | |
61 // REQUESTING_ORIGIN_ONLY_SCOPE and TOP_LEVEL_DOMAIN_ONLY_SCOPE need to be | |
62 // migrated. | |
63 CONTENT_SETTINGS_TYPE_COOKIES, | |
64 CONTENT_SETTINGS_TYPE_IMAGES, | |
65 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | |
66 CONTENT_SETTINGS_TYPE_PLUGINS, | |
67 CONTENT_SETTINGS_TYPE_POPUPS, | |
68 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
69 CONTENT_SETTINGS_TYPE_MOUSELOCK, | |
70 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | |
71 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | |
72 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
73 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | |
74 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, | |
75 CONTENT_SETTINGS_TYPE_KEYGEN, | |
76 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, | |
77 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT}; | |
raymes
2016/03/02 04:38:11
Also, it could be good to add the content settings
lshang
2016/03/03 02:55:14
Done.
We recently encountered old formatted settin
| |
78 | |
59 static_assert( | 79 static_assert( |
60 arraysize(kProviderNamesSourceMap) == | 80 arraysize(kProviderNamesSourceMap) == |
61 HostContentSettingsMap::NUM_PROVIDER_TYPES, | 81 HostContentSettingsMap::NUM_PROVIDER_TYPES, |
62 "kProviderNamesSourceMap should have NUM_PROVIDER_TYPES elements"); | 82 "kProviderNamesSourceMap should have NUM_PROVIDER_TYPES elements"); |
63 | 83 |
64 // Returns true if the |content_type| supports a resource identifier. | 84 // Returns true if the |content_type| supports a resource identifier. |
65 // Resource identifiers are supported (but not required) for plugins. | 85 // Resource identifiers are supported (but not required) for plugins. |
66 bool SupportsResourceIdentifier(ContentSettingsType content_type) { | 86 bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
67 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 87 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
68 } | 88 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 // This ensures that content settings are cleared for the guest profile. This | 184 // This ensures that content settings are cleared for the guest profile. This |
165 // wouldn't be needed except that we used to allow settings to be stored for | 185 // wouldn't be needed except that we used to allow settings to be stored for |
166 // the guest profile and so we need to ensure those get cleared. | 186 // the guest profile and so we need to ensure those get cleared. |
167 if (is_guest_profile) | 187 if (is_guest_profile) |
168 pref_provider->ClearPrefs(); | 188 pref_provider->ClearPrefs(); |
169 | 189 |
170 content_settings::ObservableProvider* default_provider = | 190 content_settings::ObservableProvider* default_provider = |
171 new content_settings::DefaultProvider(prefs_, is_off_the_record_); | 191 new content_settings::DefaultProvider(prefs_, is_off_the_record_); |
172 default_provider->AddObserver(this); | 192 default_provider->AddObserver(this); |
173 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; | 193 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
194 | |
195 MigrateOldSettings(); | |
174 } | 196 } |
175 | 197 |
176 // static | 198 // static |
177 void HostContentSettingsMap::RegisterProfilePrefs( | 199 void HostContentSettingsMap::RegisterProfilePrefs( |
178 user_prefs::PrefRegistrySyncable* registry) { | 200 user_prefs::PrefRegistrySyncable* registry) { |
179 // Ensure the content settings are all registered. | 201 // Ensure the content settings are all registered. |
180 content_settings::ContentSettingsRegistry::GetInstance(); | 202 content_settings::ContentSettingsRegistry::GetInstance(); |
181 | 203 |
182 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); | 204 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); |
183 | 205 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 primary_url, secondary_url); | 487 primary_url, secondary_url); |
466 ContentSettingsPattern primary_pattern = patterns.primary_pattern; | 488 ContentSettingsPattern primary_pattern = patterns.primary_pattern; |
467 ContentSettingsPattern secondary_pattern = patterns.secondary_pattern; | 489 ContentSettingsPattern secondary_pattern = patterns.secondary_pattern; |
468 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) | 490 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) |
469 return; | 491 return; |
470 | 492 |
471 SetContentSetting(primary_pattern, secondary_pattern, content_type, | 493 SetContentSetting(primary_pattern, secondary_pattern, content_type, |
472 resource_identifier, setting); | 494 resource_identifier, setting); |
473 } | 495 } |
474 | 496 |
497 void HostContentSettingsMap::MigrateOldSettings() { | |
498 for (const ContentSettingsType& type : kMigrateContentSettingTypes) { | |
499 ContentSettingsForOneType settings; | |
500 GetSettingsForOneType(type, std::string(), &settings); | |
501 for (const ContentSettingPatternSource& setting_entry : settings) { | |
502 // Migrate old-format settings only. | |
503 if (setting_entry.secondary_pattern != | |
504 ContentSettingsPattern::Wildcard()) { | |
505 GURL url(setting_entry.primary_pattern.ToString()); | |
506 // Pull out the value of the old-format setting. Only do this if the | |
507 // patterns are as we expect them to be, otherwise the setting will just | |
508 // be removed for safety. | |
509 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; | |
510 if (setting_entry.primary_pattern == setting_entry.secondary_pattern && | |
511 url.is_valid()) { | |
512 content_setting = GetContentSetting(url, url, type, std::string()); | |
513 } | |
514 // Remove the old pattern. | |
515 SetContentSetting(setting_entry.primary_pattern, | |
516 setting_entry.secondary_pattern, type, std::string(), | |
517 CONTENT_SETTING_DEFAULT); | |
518 // Set the new pattern. | |
519 if (content_setting) { | |
520 SetContentSettingDefaultScope(url, GURL(), type, std::string(), | |
521 content_setting); | |
522 } | |
523 } | |
524 } | |
525 } | |
526 } | |
527 | |
475 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( | 528 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
476 const GURL& primary_url, | 529 const GURL& primary_url, |
477 const GURL& secondary_url, | 530 const GURL& secondary_url, |
478 ContentSettingsType content_type, | 531 ContentSettingsType content_type, |
479 const std::string& resource_identifier) { | 532 const std::string& resource_identifier) { |
480 DCHECK(thread_checker_.CalledOnValidThread()); | 533 DCHECK(thread_checker_.CalledOnValidThread()); |
481 | 534 |
482 ContentSetting setting = GetContentSetting( | 535 ContentSetting setting = GetContentSetting( |
483 primary_url, secondary_url, content_type, resource_identifier); | 536 primary_url, secondary_url, content_type, resource_identifier); |
484 if (setting == CONTENT_SETTING_ALLOW) { | 537 if (setting == CONTENT_SETTING_ALLOW) { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 rule.secondary_pattern.Matches(secondary_url)) { | 857 rule.secondary_pattern.Matches(secondary_url)) { |
805 if (primary_pattern) | 858 if (primary_pattern) |
806 *primary_pattern = rule.primary_pattern; | 859 *primary_pattern = rule.primary_pattern; |
807 if (secondary_pattern) | 860 if (secondary_pattern) |
808 *secondary_pattern = rule.secondary_pattern; | 861 *secondary_pattern = rule.secondary_pattern; |
809 return make_scoped_ptr(rule.value.get()->DeepCopy()); | 862 return make_scoped_ptr(rule.value.get()->DeepCopy()); |
810 } | 863 } |
811 } | 864 } |
812 return scoped_ptr<base::Value>(); | 865 return scoped_ptr<base::Value>(); |
813 } | 866 } |
OLD | NEW |