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

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: enhance tests Created 4 years, 5 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(
443 const ContentSettingsPattern& domain_pattern,
444 ContentSettingsPattern* origin_pattern) {
445 DCHECK(origin_pattern);
446
447 // Generated patterns must either have a scheme wildcard or be https.
448 if (domain_pattern.parts_.scheme != url::kHttpsScheme &&
449 !domain_pattern.parts_.is_scheme_wildcard) {
450 return false;
451 }
452
453 // Generated patterns will either have a port wildcard or be https (but not
msramek 2016/06/30 16:16:22 Not sure if this is just me, but this sentence rea
lshang 2016/07/04 02:46:01 Done.
454 // both).
455 if (domain_pattern.parts_.is_port_wildcard &&
456 domain_pattern.parts_.scheme == url::kHttpsScheme) {
457 return false;
458 }
459
460 // Generated patterns will always have a domain wildcard.
msramek 2016/06/30 16:16:22 nit: Patterns generated with ::FromUrl (which we w
lshang 2016/07/04 02:46:01 Done.
461 if (!domain_pattern.parts_.has_domain_wildcard)
462 return false;
463
464 // Generated patterns will always have a host.
465 if (domain_pattern.parts_.host.empty())
466 return false;
467
468 *origin_pattern = domain_pattern;
msramek 2016/06/30 16:16:22 Would it make sense to use Builder here instead of
lshang 2016/07/04 02:46:01 Done.
469
470 if (domain_pattern.parts_.is_scheme_wildcard) {
471 (*origin_pattern).parts_.scheme = url::kHttpScheme;
msramek 2016/06/30 16:16:22 The scheme wildcard exception was valid for both h
lshang 2016/07/04 02:46:01 That's a good point! Patterns generated from perm
msramek 2016/07/07 12:19:24 Yup, makes sense :)
472 (*origin_pattern).parts_.is_scheme_wildcard = false;
473 }
474
475 (*origin_pattern).parts_.has_domain_wildcard = false;
476
477 if (domain_pattern.parts_.is_port_wildcard) {
478 (*origin_pattern).parts_.port =
479 GetDefaultPort((*origin_pattern).parts_.scheme);
480 (*origin_pattern).parts_.is_port_wildcard = false;
481 }
482 return true;
483 }
484
485 // static
442 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( 486 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme(
443 const char* scheme) { 487 const char* scheme) {
444 DCHECK(scheme); 488 DCHECK(scheme);
445 DCHECK(!non_port_non_domain_wildcard_scheme || 489 DCHECK(!non_port_non_domain_wildcard_scheme ||
446 non_port_non_domain_wildcard_scheme == scheme); 490 non_port_non_domain_wildcard_scheme == scheme);
447 non_port_non_domain_wildcard_scheme = scheme; 491 non_port_non_domain_wildcard_scheme = scheme;
448 } 492 }
449 493
450 // static 494 // static
451 bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme( 495 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) 781 if (!parts.is_path_wildcard && other_parts.is_path_wildcard)
738 return ContentSettingsPattern::PREDECESSOR; 782 return ContentSettingsPattern::PREDECESSOR;
739 783
740 int result = parts.path.compare(other_parts.path); 784 int result = parts.path.compare(other_parts.path);
741 if (result == 0) 785 if (result == 0)
742 return ContentSettingsPattern::IDENTITY; 786 return ContentSettingsPattern::IDENTITY;
743 if (result > 0) 787 if (result > 0)
744 return ContentSettingsPattern::DISJOINT_ORDER_PRE; 788 return ContentSettingsPattern::DISJOINT_ORDER_PRE;
745 return ContentSettingsPattern::DISJOINT_ORDER_POST; 789 return ContentSettingsPattern::DISJOINT_ORDER_POST;
746 } 790 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698