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

Side by Side Diff: components/content_settings/core/common/content_settings_pattern.cc

Issue 1895993003: Add migration code to change existing domain scoped content settings to be origin scoped (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rewrite ContentSettingsPatterns::MigrateFromDomaintoOrigin Created 4 years, 6 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/common/content_settings_pattern.h" 5 #include "components/content_settings/core/common/content_settings_pattern.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 ContentSettingsPattern ContentSettingsPattern::FromString( 432 ContentSettingsPattern ContentSettingsPattern::FromString(
433 const std::string& pattern_spec) { 433 const std::string& pattern_spec) {
434 std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder( 434 std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder(
435 ContentSettingsPattern::CreateBuilder(false)); 435 ContentSettingsPattern::CreateBuilder(false));
436 content_settings::PatternParser::Parse(pattern_spec, 436 content_settings::PatternParser::Parse(pattern_spec,
437 builder.get()); 437 builder.get());
438 return builder->Build(); 438 return builder->Build();
439 } 439 }
440 440
441 // static 441 // static
442 bool ContentSettingsPattern::MigrateFromDomaintoOrigin(
raymes 2016/06/27 07:23:29 MigrateFromDomainToOrigin (capital T)
lshang 2016/06/28 07:14:41 Done.
443 const ContentSettingsPattern& domain_pattern,
444 ContentSettingsPattern* origin_pattern) {
445 DCHECK(origin_pattern);
446
447 // First test if the domain pattern is generated using FromURL().
raymes 2016/06/27 07:23:29 nit: remove this line, I think it should be clear
lshang 2016/06/28 07:14:41 Done.
448 // Generated patterns must either have a scheme wildcard or be https.
449 if (domain_pattern.parts_.scheme != url::kHttpsScheme &&
450 !domain_pattern.parts_.is_scheme_wildcard)
raymes 2016/06/27 07:23:29 nit: add {}
lshang 2016/06/28 07:14:41 Done.
451 return false;
452
453 // Generated patterns will either have a port wildcard or be https (but not
454 // both).
455 if (domain_pattern.parts_.is_port_wildcard &&
456 domain_pattern.parts_.scheme == url::kHttpsScheme)
raymes 2016/06/27 07:23:29 nit: add {}
lshang 2016/06/28 07:14:41 Done.
457 return false;
458
459 // Generated patterns will always have a domain wildcard.
460 if (!domain_pattern.parts_.has_domain_wildcard)
461 return false;
462
463 // Generated patterns will always have a host.
464 if (domain_pattern.parts_.host.empty())
465 return false;
466
467 // Then migrate it to be origin scoped.
468 *origin_pattern = domain_pattern;
469
470 if (domain_pattern.parts_.is_scheme_wildcard) {
471 (*origin_pattern).parts_.scheme = url::kHttpScheme;
472 (*origin_pattern).parts_.is_scheme_wildcard = false;
473 }
474 if (domain_pattern.parts_.has_domain_wildcard)
raymes 2016/06/27 07:23:29 I think we know this will be true, so we can remov
lshang 2016/06/28 07:14:41 Done.
475 (*origin_pattern).parts_.has_domain_wildcard = false;
476 if (domain_pattern.parts_.is_port_wildcard) {
477 (*origin_pattern).parts_.port =
478 GetDefaultPort((*origin_pattern).parts_.scheme);
479 (*origin_pattern).parts_.is_port_wildcard = false;
480 }
481 return true;
482 }
483
484 // static
442 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( 485 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme(
443 const char* scheme) { 486 const char* scheme) {
444 DCHECK(scheme); 487 DCHECK(scheme);
445 DCHECK(!non_port_non_domain_wildcard_scheme || 488 DCHECK(!non_port_non_domain_wildcard_scheme ||
446 non_port_non_domain_wildcard_scheme == scheme); 489 non_port_non_domain_wildcard_scheme == scheme);
447 non_port_non_domain_wildcard_scheme = scheme; 490 non_port_non_domain_wildcard_scheme = scheme;
448 } 491 }
449 492
450 // static 493 // static
451 bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme( 494 bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme(
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) 780 if (!parts.is_path_wildcard && other_parts.is_path_wildcard)
738 return ContentSettingsPattern::PREDECESSOR; 781 return ContentSettingsPattern::PREDECESSOR;
739 782
740 int result = parts.path.compare(other_parts.path); 783 int result = parts.path.compare(other_parts.path);
741 if (result == 0) 784 if (result == 0)
742 return ContentSettingsPattern::IDENTITY; 785 return ContentSettingsPattern::IDENTITY;
743 if (result > 0) 786 if (result > 0)
744 return ContentSettingsPattern::DISJOINT_ORDER_PRE; 787 return ContentSettingsPattern::DISJOINT_ORDER_PRE;
745 return ContentSettingsPattern::DISJOINT_ORDER_POST; 788 return ContentSettingsPattern::DISJOINT_ORDER_POST;
746 } 789 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698