Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: components/content_settings/core/browser/host_content_settings_map.cc

Issue 1991623005: Only Register() platform specific content settings types on different platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // wouldn't be needed except that we used to allow settings to be stored for 164 // wouldn't be needed except that we used to allow settings to be stored for
165 // the guest profile and so we need to ensure those get cleared. 165 // the guest profile and so we need to ensure those get cleared.
166 if (is_guest_profile) 166 if (is_guest_profile)
167 pref_provider_->ClearPrefs(); 167 pref_provider_->ClearPrefs();
168 168
169 content_settings::ObservableProvider* default_provider = 169 content_settings::ObservableProvider* default_provider =
170 new content_settings::DefaultProvider(prefs_, is_off_the_record_); 170 new content_settings::DefaultProvider(prefs_, is_off_the_record_);
171 default_provider->AddObserver(this); 171 default_provider->AddObserver(this);
172 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; 172 content_settings_providers_[DEFAULT_PROVIDER] = default_provider;
173 173
174 // ios doean't have KEYGEN to be migrated.
175 #if !defined(OS_IOS)
174 MigrateOldSettings(); 176 MigrateOldSettings();
raymes 2016/05/20 19:10:16 Maybe we can just rename this to MigrateKeygenSett
lshang 2016/05/24 11:55:45 Good suggestion! I made a separate CL(https://code
175 177 #endif
176 RecordNumberOfExceptions(); 178 RecordNumberOfExceptions();
177 } 179 }
178 180
179 // static 181 // static
180 void HostContentSettingsMap::RegisterProfilePrefs( 182 void HostContentSettingsMap::RegisterProfilePrefs(
181 user_prefs::PrefRegistrySyncable* registry) { 183 user_prefs::PrefRegistrySyncable* registry) {
182 // Ensure the content settings are all registered. 184 // Ensure the content settings are all registered.
183 content_settings::ContentSettingsRegistry::GetInstance(); 185 content_settings::ContentSettingsRegistry::GetInstance();
184 186
185 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); 187 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 resource_identifier, setting); 469 resource_identifier, setting);
468 } 470 }
469 471
470 void HostContentSettingsMap::MigrateOldSettings() { 472 void HostContentSettingsMap::MigrateOldSettings() {
471 const ContentSettingsType kMigrateContentSettingTypes[] = { 473 const ContentSettingsType kMigrateContentSettingTypes[] = {
472 // Only content types of scoping type: REQUESTING_DOMAIN_ONLY_SCOPE, 474 // Only content types of scoping type: REQUESTING_DOMAIN_ONLY_SCOPE,
473 // REQUESTING_ORIGIN_ONLY_SCOPE and TOP_LEVEL_DOMAIN_ONLY_SCOPE need to be 475 // REQUESTING_ORIGIN_ONLY_SCOPE and TOP_LEVEL_DOMAIN_ONLY_SCOPE need to be
474 // migrated. 476 // migrated.
475 CONTENT_SETTINGS_TYPE_KEYGEN}; 477 CONTENT_SETTINGS_TYPE_KEYGEN};
476 for (const ContentSettingsType& type : kMigrateContentSettingTypes) { 478 for (const ContentSettingsType& type : kMigrateContentSettingTypes) {
477 WebsiteSettingsInfo::ScopingType scoping_type = 479 const content_settings::ContentSettingsInfo* info =
478 content_settings::ContentSettingsRegistry::GetInstance() 480 content_settings::ContentSettingsRegistry::GetInstance()->Get(type);
479 ->Get(type) 481 if (info) {
480 ->website_settings_info() 482 WebsiteSettingsInfo::ScopingType scoping_type =
481 ->scoping_type(); 483 info->website_settings_info()->scoping_type();
482 DCHECK_NE( 484 DCHECK_NE(
483 scoping_type, 485 scoping_type,
484 WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE); 486 WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE);
485 487
486 ContentSettingsForOneType settings; 488 ContentSettingsForOneType settings;
487 GetSettingsForOneType(type, std::string(), &settings); 489 GetSettingsForOneType(type, std::string(), &settings);
488 for (const ContentSettingPatternSource& setting_entry : settings) { 490 for (const ContentSettingPatternSource& setting_entry : settings) {
489 // Migrate user preference settings only. 491 // Migrate user preference settings only.
490 if (setting_entry.source != "preference") 492 if (setting_entry.source != "preference")
491 continue; 493 continue;
492 // Migrate old-format settings only. 494 // Migrate old-format settings only.
493 if (setting_entry.secondary_pattern != 495 if (setting_entry.secondary_pattern !=
494 ContentSettingsPattern::Wildcard()) { 496 ContentSettingsPattern::Wildcard()) {
495 GURL url(setting_entry.primary_pattern.ToString()); 497 GURL url(setting_entry.primary_pattern.ToString());
496 // Pull out the value of the old-format setting. Only do this if the 498 // Pull out the value of the old-format setting. Only do this if the
497 // patterns are as we expect them to be, otherwise the setting will just 499 // patterns are as we expect them to be, otherwise the setting will
498 // be removed for safety. 500 // just be removed for safety.
499 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; 501 ContentSetting content_setting = CONTENT_SETTING_DEFAULT;
500 if (setting_entry.primary_pattern == setting_entry.secondary_pattern && 502 if (setting_entry.primary_pattern ==
501 url.is_valid()) { 503 setting_entry.secondary_pattern &&
502 content_setting = GetContentSetting(url, url, type, std::string()); 504 url.is_valid()) {
505 content_setting = GetContentSetting(url, url, type, std::string());
506 }
507 // Remove the old pattern.
508 SetContentSettingCustomScope(setting_entry.primary_pattern,
509 setting_entry.secondary_pattern, type,
510 std::string(), CONTENT_SETTING_DEFAULT);
511 // Set the new pattern.
512 SetContentSettingDefaultScope(url, GURL(), type, std::string(),
513 content_setting);
503 } 514 }
504 // Remove the old pattern.
505 SetContentSettingCustomScope(setting_entry.primary_pattern,
506 setting_entry.secondary_pattern, type, std::string(),
507 CONTENT_SETTING_DEFAULT);
508 // Set the new pattern.
509 SetContentSettingDefaultScope(url, GURL(), type, std::string(),
510 content_setting);
511 } 515 }
512 } 516 }
513 } 517 }
514 } 518 }
515 519
516 void HostContentSettingsMap::RecordNumberOfExceptions() { 520 void HostContentSettingsMap::RecordNumberOfExceptions() {
517 for (const content_settings::WebsiteSettingsInfo* info : 521 for (const content_settings::WebsiteSettingsInfo* info :
518 *content_settings::WebsiteSettingsRegistry::GetInstance()) { 522 *content_settings::WebsiteSettingsRegistry::GetInstance()) {
519 ContentSettingsType content_type = info->type(); 523 ContentSettingsType content_type = info->type();
520 const std::string type_name = info->name(); 524 const std::string type_name = info->name();
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 rule.secondary_pattern.Matches(secondary_url)) { 866 rule.secondary_pattern.Matches(secondary_url)) {
863 if (primary_pattern) 867 if (primary_pattern)
864 *primary_pattern = rule.primary_pattern; 868 *primary_pattern = rule.primary_pattern;
865 if (secondary_pattern) 869 if (secondary_pattern)
866 *secondary_pattern = rule.secondary_pattern; 870 *secondary_pattern = rule.secondary_pattern;
867 return base::WrapUnique(rule.value.get()->DeepCopy()); 871 return base::WrapUnique(rule.value.get()->DeepCopy());
868 } 872 }
869 } 873 }
870 return std::unique_ptr<base::Value>(); 874 return std::unique_ptr<base::Value>();
871 } 875 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698