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 "chrome/common/content_settings_pattern.h" | 5 #include "chrome/common/content_settings_pattern.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "chrome/common/content_settings_pattern_parser.h" | 12 #include "chrome/common/content_settings_pattern_parser.h" |
13 #include "chrome/common/render_messages.h" | |
14 #include "chrome/common/url_constants.h" | |
15 #include "extensions/common/constants.h" | |
16 #include "ipc/ipc_message_utils.h" | |
17 #include "net/base/dns_util.h" | 13 #include "net/base/dns_util.h" |
18 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
19 #include "url/gurl.h" | 15 #include "url/gurl.h" |
20 #include "url/url_canon.h" | |
21 | 16 |
22 namespace { | 17 namespace { |
23 | 18 |
| 19 // The component supports only one scheme for simplicity. |
| 20 const char* non_port_non_domain_wildcard_scheme = NULL; |
| 21 |
24 std::string GetDefaultPort(const std::string& scheme) { | 22 std::string GetDefaultPort(const std::string& scheme) { |
25 if (scheme == url::kHttpScheme) | 23 if (scheme == url::kHttpScheme) |
26 return "80"; | 24 return "80"; |
27 if (scheme == url::kHttpsScheme) | 25 if (scheme == url::kHttpsScheme) |
28 return "443"; | 26 return "443"; |
29 return std::string(); | 27 return std::string(); |
30 } | 28 } |
31 | 29 |
32 // Returns true if |sub_domain| is a sub domain or equls |domain|. E.g. | 30 // Returns true if |sub_domain| is a sub domain or equls |domain|. E.g. |
33 // "mail.google.com" is a sub domain of "google.com" but "evilhost.com" is not a | 31 // "mail.google.com" is a sub domain of "google.com" but "evilhost.com" is not a |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 return 0; | 76 return 0; |
79 } | 77 } |
80 | 78 |
81 typedef ContentSettingsPattern::BuilderInterface BuilderInterface; | 79 typedef ContentSettingsPattern::BuilderInterface BuilderInterface; |
82 | 80 |
83 } // namespace | 81 } // namespace |
84 | 82 |
85 // //////////////////////////////////////////////////////////////////////////// | 83 // //////////////////////////////////////////////////////////////////////////// |
86 // ContentSettingsPattern::Builder | 84 // ContentSettingsPattern::Builder |
87 // | 85 // |
| 86 class ContentSettingsPattern::Builder : |
| 87 public ContentSettingsPattern::BuilderInterface { |
| 88 public: |
| 89 explicit Builder(bool use_legacy_validate); |
| 90 virtual ~Builder(); |
| 91 |
| 92 // BuilderInterface: |
| 93 virtual BuilderInterface* WithPort(const std::string& port) OVERRIDE; |
| 94 virtual BuilderInterface* WithPortWildcard() OVERRIDE; |
| 95 virtual BuilderInterface* WithHost(const std::string& host) OVERRIDE; |
| 96 virtual BuilderInterface* WithDomainWildcard() OVERRIDE; |
| 97 virtual BuilderInterface* WithScheme(const std::string& scheme) OVERRIDE; |
| 98 virtual BuilderInterface* WithSchemeWildcard() OVERRIDE; |
| 99 virtual BuilderInterface* WithPath(const std::string& path) OVERRIDE; |
| 100 virtual BuilderInterface* WithPathWildcard() OVERRIDE; |
| 101 virtual BuilderInterface* Invalid() OVERRIDE; |
| 102 virtual ContentSettingsPattern Build() OVERRIDE; |
| 103 |
| 104 private: |
| 105 // Canonicalizes the pattern parts so that they are ASCII only, either |
| 106 // in original (if it was already ASCII) or punycode form. Returns true if |
| 107 // the canonicalization was successful. |
| 108 static bool Canonicalize(PatternParts* parts); |
| 109 |
| 110 // Returns true when the pattern |parts| represent a valid pattern. |
| 111 static bool Validate(const PatternParts& parts); |
| 112 |
| 113 static bool LegacyValidate(const PatternParts& parts); |
| 114 |
| 115 bool is_valid_; |
| 116 |
| 117 bool use_legacy_validate_; |
| 118 |
| 119 PatternParts parts_; |
| 120 |
| 121 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 122 }; |
| 123 |
88 ContentSettingsPattern::Builder::Builder(bool use_legacy_validate) | 124 ContentSettingsPattern::Builder::Builder(bool use_legacy_validate) |
89 : is_valid_(true), | 125 : is_valid_(true), |
90 use_legacy_validate_(use_legacy_validate) {} | 126 use_legacy_validate_(use_legacy_validate) {} |
91 | 127 |
92 ContentSettingsPattern::Builder::~Builder() {} | 128 ContentSettingsPattern::Builder::~Builder() {} |
93 | 129 |
94 BuilderInterface* ContentSettingsPattern::Builder::WithPort( | 130 BuilderInterface* ContentSettingsPattern::Builder::WithPort( |
95 const std::string& port) { | 131 const std::string& port) { |
96 parts_.port = port; | 132 parts_.port = port; |
97 parts_.is_port_wildcard = false; | 133 parts_.is_port_wildcard = false; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 if (parts.has_domain_wildcard || !parts.host.empty() || !parts.port.empty()) | 253 if (parts.has_domain_wildcard || !parts.host.empty() || !parts.port.empty()) |
218 return false; | 254 return false; |
219 if (parts.is_path_wildcard) | 255 if (parts.is_path_wildcard) |
220 return parts.path.empty(); | 256 return parts.path.empty(); |
221 return (!parts.path.empty() && | 257 return (!parts.path.empty() && |
222 parts.path != "/" && | 258 parts.path != "/" && |
223 parts.path.find("*") == std::string::npos); | 259 parts.path.find("*") == std::string::npos); |
224 } | 260 } |
225 | 261 |
226 // If the pattern is for an extension URL test if it is valid. | 262 // If the pattern is for an extension URL test if it is valid. |
227 if (parts.scheme == std::string(extensions::kExtensionScheme) && | 263 if (IsNonWildcardDomainNonPortScheme(parts.scheme) && |
228 parts.port.empty() && | 264 parts.port.empty() && |
229 !parts.is_port_wildcard) { | 265 !parts.is_port_wildcard) { |
230 return true; | 266 return true; |
231 } | 267 } |
232 | 268 |
233 // Non-file patterns are invalid if either the scheme, host or port part is | 269 // Non-file patterns are invalid if either the scheme, host or port part is |
234 // empty. | 270 // empty. |
235 if ((parts.scheme.empty() && !parts.is_scheme_wildcard) || | 271 if ((parts.scheme.empty() && !parts.is_scheme_wildcard) || |
236 (parts.host.empty() && !parts.has_domain_wildcard) || | 272 (parts.host.empty() && !parts.has_domain_wildcard) || |
237 (parts.port.empty() && !parts.is_port_wildcard)) { | 273 (parts.port.empty() && !parts.is_port_wildcard)) { |
(...skipping 16 matching lines...) Expand all Loading... |
254 bool ContentSettingsPattern::Builder::LegacyValidate( | 290 bool ContentSettingsPattern::Builder::LegacyValidate( |
255 const PatternParts& parts) { | 291 const PatternParts& parts) { |
256 // If the pattern is for a "file-pattern" test if it is valid. | 292 // If the pattern is for a "file-pattern" test if it is valid. |
257 if (parts.scheme == std::string(url::kFileScheme) && | 293 if (parts.scheme == std::string(url::kFileScheme) && |
258 !parts.is_scheme_wildcard && | 294 !parts.is_scheme_wildcard && |
259 parts.host.empty() && | 295 parts.host.empty() && |
260 parts.port.empty()) | 296 parts.port.empty()) |
261 return true; | 297 return true; |
262 | 298 |
263 // If the pattern is for an extension URL test if it is valid. | 299 // If the pattern is for an extension URL test if it is valid. |
264 if (parts.scheme == std::string(extensions::kExtensionScheme) && | 300 if (IsNonWildcardDomainNonPortScheme(parts.scheme) && |
265 !parts.is_scheme_wildcard && | 301 !parts.is_scheme_wildcard && |
266 !parts.host.empty() && | 302 !parts.host.empty() && |
267 !parts.has_domain_wildcard && | 303 !parts.has_domain_wildcard && |
268 parts.port.empty() && | 304 parts.port.empty() && |
269 !parts.is_port_wildcard) | 305 !parts.is_port_wildcard) |
270 return true; | 306 return true; |
271 | 307 |
272 // Non-file patterns are invalid if either the scheme, host or port part is | 308 // Non-file patterns are invalid if either the scheme, host or port part is |
273 // empty. | 309 // empty. |
274 if ((!parts.is_scheme_wildcard) || | 310 if ((!parts.is_scheme_wildcard) || |
(...skipping 29 matching lines...) Expand all Loading... |
304 // following patterns: | 340 // following patterns: |
305 // - [*.]domain.tld (matches domain.tld and all sub-domains) | 341 // - [*.]domain.tld (matches domain.tld and all sub-domains) |
306 // - host (matches an exact hostname) | 342 // - host (matches an exact hostname) |
307 // - a.b.c.d (matches an exact IPv4 ip) | 343 // - a.b.c.d (matches an exact IPv4 ip) |
308 // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip) | 344 // - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip) |
309 // - file:///tmp/test.html (a complete URL without a host) | 345 // - file:///tmp/test.html (a complete URL without a host) |
310 // Version 2 adds a resource identifier for plugins. | 346 // Version 2 adds a resource identifier for plugins. |
311 // TODO(jochen): update once this feature is no longer behind a flag. | 347 // TODO(jochen): update once this feature is no longer behind a flag. |
312 const int ContentSettingsPattern::kContentSettingsPatternVersion = 1; | 348 const int ContentSettingsPattern::kContentSettingsPatternVersion = 1; |
313 | 349 |
314 // TODO(markusheintz): These two constants were moved to the Pattern Parser. | |
315 // Remove once the dependency of the ContentSettingsBaseProvider is removed. | |
316 const char* ContentSettingsPattern::kDomainWildcard = "[*.]"; | |
317 const size_t ContentSettingsPattern::kDomainWildcardLength = 4; | |
318 | |
319 // static | 350 // static |
320 BuilderInterface* ContentSettingsPattern::CreateBuilder( | 351 BuilderInterface* ContentSettingsPattern::CreateBuilder( |
321 bool validate) { | 352 bool validate) { |
322 return new Builder(validate); | 353 return new Builder(validate); |
323 } | 354 } |
324 | 355 |
325 // static | 356 // static |
| 357 ContentSettingsPattern ContentSettingsPattern::Wildcard() { |
| 358 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
| 359 ContentSettingsPattern::CreateBuilder(true)); |
| 360 builder->WithSchemeWildcard()->WithDomainWildcard()->WithPortWildcard()-> |
| 361 WithPathWildcard(); |
| 362 return builder->Build(); |
| 363 } |
| 364 |
| 365 // static |
326 ContentSettingsPattern ContentSettingsPattern::FromURL( | 366 ContentSettingsPattern ContentSettingsPattern::FromURL( |
327 const GURL& url) { | 367 const GURL& url) { |
328 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | 368 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
329 ContentSettingsPattern::CreateBuilder(false)); | 369 ContentSettingsPattern::CreateBuilder(false)); |
330 | 370 |
331 const GURL* local_url = &url; | 371 const GURL* local_url = &url; |
332 if (url.SchemeIsFileSystem() && url.inner_url()) { | 372 if (url.SchemeIsFileSystem() && url.inner_url()) { |
333 local_url = url.inner_url(); | 373 local_url = url.inner_url(); |
334 } | 374 } |
335 if (local_url->SchemeIsFile()) { | 375 if (local_url->SchemeIsFile()) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 } | 421 } |
382 } | 422 } |
383 return builder->Build(); | 423 return builder->Build(); |
384 } | 424 } |
385 | 425 |
386 // static | 426 // static |
387 ContentSettingsPattern ContentSettingsPattern::FromString( | 427 ContentSettingsPattern ContentSettingsPattern::FromString( |
388 const std::string& pattern_spec) { | 428 const std::string& pattern_spec) { |
389 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | 429 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
390 ContentSettingsPattern::CreateBuilder(false)); | 430 ContentSettingsPattern::CreateBuilder(false)); |
391 content_settings::PatternParser::Parse(pattern_spec, builder.get()); | 431 content_settings::PatternParser::Parse(pattern_spec, |
| 432 builder.get()); |
392 return builder->Build(); | 433 return builder->Build(); |
393 } | 434 } |
394 | 435 |
395 // static | 436 // static |
396 ContentSettingsPattern ContentSettingsPattern::LegacyFromString( | 437 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( |
397 const std::string& pattern_spec) { | 438 const char* scheme) { |
398 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | 439 DCHECK(scheme); |
399 ContentSettingsPattern::CreateBuilder(true)); | 440 DCHECK(!non_port_non_domain_wildcard_scheme || |
400 content_settings::PatternParser::Parse(pattern_spec, builder.get()); | 441 non_port_non_domain_wildcard_scheme == scheme); |
401 return builder->Build(); | 442 non_port_non_domain_wildcard_scheme = scheme; |
402 } | 443 } |
403 | 444 |
404 // static | 445 // static |
405 ContentSettingsPattern ContentSettingsPattern::Wildcard() { | 446 bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme( |
406 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | 447 const std::string& scheme) { |
407 ContentSettingsPattern::CreateBuilder(true)); | 448 DCHECK(non_port_non_domain_wildcard_scheme); |
408 builder->WithSchemeWildcard()->WithDomainWildcard()->WithPortWildcard()-> | 449 return scheme == non_port_non_domain_wildcard_scheme; |
409 WithPathWildcard(); | |
410 return builder->Build(); | |
411 } | 450 } |
412 | 451 |
413 ContentSettingsPattern::ContentSettingsPattern() | 452 ContentSettingsPattern::ContentSettingsPattern() |
414 : is_valid_(false) { | 453 : is_valid_(false) { |
415 } | 454 } |
416 | 455 |
417 ContentSettingsPattern::ContentSettingsPattern( | 456 ContentSettingsPattern::ContentSettingsPattern( |
418 const PatternParts& parts, | 457 const PatternParts& parts, |
419 bool valid) | 458 bool valid) |
420 : parts_(parts), | 459 : parts_(parts), |
421 is_valid_(valid) { | 460 is_valid_(valid) { |
422 } | 461 } |
423 | 462 |
424 void ContentSettingsPattern::WriteToMessage(IPC::Message* m) const { | |
425 IPC::WriteParam(m, is_valid_); | |
426 IPC::WriteParam(m, parts_); | |
427 } | |
428 | |
429 bool ContentSettingsPattern::ReadFromMessage(const IPC::Message* m, | |
430 PickleIterator* iter) { | |
431 return IPC::ReadParam(m, iter, &is_valid_) && | |
432 IPC::ReadParam(m, iter, &parts_); | |
433 } | |
434 | |
435 bool ContentSettingsPattern::Matches( | 463 bool ContentSettingsPattern::Matches( |
436 const GURL& url) const { | 464 const GURL& url) const { |
437 // An invalid pattern matches nothing. | 465 // An invalid pattern matches nothing. |
438 if (!is_valid_) | 466 if (!is_valid_) |
439 return false; | 467 return false; |
440 | 468 |
441 const GURL* local_url = &url; | 469 const GURL* local_url = &url; |
442 if (url.SchemeIsFileSystem() && url.inner_url()) { | 470 if (url.SchemeIsFileSystem() && url.inner_url()) { |
443 local_url = url.inner_url(); | 471 local_url = url.inner_url(); |
444 } | 472 } |
(...skipping 19 matching lines...) Expand all Loading... |
464 // Match the host part. | 492 // Match the host part. |
465 const std::string host(net::TrimEndingDot(local_url->host())); | 493 const std::string host(net::TrimEndingDot(local_url->host())); |
466 if (!parts_.has_domain_wildcard) { | 494 if (!parts_.has_domain_wildcard) { |
467 if (parts_.host != host) | 495 if (parts_.host != host) |
468 return false; | 496 return false; |
469 } else { | 497 } else { |
470 if (!IsSubDomainOrEqual(host, parts_.host)) | 498 if (!IsSubDomainOrEqual(host, parts_.host)) |
471 return false; | 499 return false; |
472 } | 500 } |
473 | 501 |
474 // For chrome extensions URLs ignore the port. | 502 // Ignore the port if the scheme doesn't support it. |
475 if (parts_.scheme == std::string(extensions::kExtensionScheme)) | 503 if (IsNonWildcardDomainNonPortScheme(parts_.scheme)) |
476 return true; | 504 return true; |
477 | 505 |
478 // Match the port part. | 506 // Match the port part. |
479 std::string port(local_url->port()); | 507 std::string port(local_url->port()); |
480 | 508 |
481 // Use the default port if the port string is empty. GURL returns an empty | 509 // Use the default port if the port string is empty. GURL returns an empty |
482 // string if no port at all was specified or if the default port was | 510 // string if no port at all was specified or if the default port was |
483 // specified. | 511 // specified. |
484 if (port.empty()) { | 512 if (port.empty()) { |
485 port = GetDefaultPort(scheme); | 513 port = GetDefaultPort(scheme); |
486 } | 514 } |
487 | 515 |
488 if (!parts_.is_port_wildcard && | 516 if (!parts_.is_port_wildcard && |
489 parts_.port != port ) { | 517 parts_.port != port ) { |
490 return false; | 518 return false; |
491 } | 519 } |
492 | 520 |
493 return true; | 521 return true; |
494 } | 522 } |
495 | 523 |
496 bool ContentSettingsPattern::MatchesAllHosts() const { | 524 bool ContentSettingsPattern::MatchesAllHosts() const { |
497 return parts_.has_domain_wildcard && parts_.host.empty(); | 525 return parts_.has_domain_wildcard && parts_.host.empty(); |
498 } | 526 } |
499 | 527 |
500 const std::string ContentSettingsPattern::ToString() const { | 528 std::string ContentSettingsPattern::ToString() const { |
501 if (IsValid()) | 529 if (IsValid()) |
502 return content_settings::PatternParser::ToString(parts_); | 530 return content_settings::PatternParser::ToString(parts_); |
503 else | 531 else |
504 return std::string(); | 532 return std::string(); |
505 } | 533 } |
506 | 534 |
507 ContentSettingsPattern::Relation ContentSettingsPattern::Compare( | 535 ContentSettingsPattern::Relation ContentSettingsPattern::Compare( |
508 const ContentSettingsPattern& other) const { | 536 const ContentSettingsPattern& other) const { |
509 // Two invalid patterns are identical in the way they behave. They don't match | 537 // Two invalid patterns are identical in the way they behave. They don't match |
510 // anything and are represented as an empty string. So it's fair to treat them | 538 // anything and are represented as an empty string. So it's fair to treat them |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 const ContentSettingsPattern& other) const { | 583 const ContentSettingsPattern& other) const { |
556 return Compare(other) < 0; | 584 return Compare(other) < 0; |
557 } | 585 } |
558 | 586 |
559 bool ContentSettingsPattern::operator>( | 587 bool ContentSettingsPattern::operator>( |
560 const ContentSettingsPattern& other) const { | 588 const ContentSettingsPattern& other) const { |
561 return Compare(other) > 0; | 589 return Compare(other) > 0; |
562 } | 590 } |
563 | 591 |
564 // static | 592 // static |
| 593 ContentSettingsPattern::Relation ContentSettingsPattern::CompareScheme( |
| 594 const ContentSettingsPattern::PatternParts& parts, |
| 595 const ContentSettingsPattern::PatternParts& other_parts) { |
| 596 if (parts.is_scheme_wildcard && !other_parts.is_scheme_wildcard) |
| 597 return ContentSettingsPattern::SUCCESSOR; |
| 598 if (!parts.is_scheme_wildcard && other_parts.is_scheme_wildcard) |
| 599 return ContentSettingsPattern::PREDECESSOR; |
| 600 |
| 601 int result = parts.scheme.compare(other_parts.scheme); |
| 602 if (result == 0) |
| 603 return ContentSettingsPattern::IDENTITY; |
| 604 if (result > 0) |
| 605 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
| 606 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
| 607 } |
| 608 |
| 609 // static |
565 ContentSettingsPattern::Relation ContentSettingsPattern::CompareHost( | 610 ContentSettingsPattern::Relation ContentSettingsPattern::CompareHost( |
566 const ContentSettingsPattern::PatternParts& parts, | 611 const ContentSettingsPattern::PatternParts& parts, |
567 const ContentSettingsPattern::PatternParts& other_parts) { | 612 const ContentSettingsPattern::PatternParts& other_parts) { |
568 if (!parts.has_domain_wildcard && !other_parts.has_domain_wildcard) { | 613 if (!parts.has_domain_wildcard && !other_parts.has_domain_wildcard) { |
569 // Case 1: No host starts with a wild card | 614 // Case 1: No host starts with a wild card |
570 int result = CompareDomainNames(parts.host, other_parts.host); | 615 int result = CompareDomainNames(parts.host, other_parts.host); |
571 if (result == 0) | 616 if (result == 0) |
572 return ContentSettingsPattern::IDENTITY; | 617 return ContentSettingsPattern::IDENTITY; |
573 if (result < 0) | 618 if (result < 0) |
574 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 619 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 687 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
643 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 688 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
644 } | 689 } |
645 } | 690 } |
646 | 691 |
647 NOTREACHED(); | 692 NOTREACHED(); |
648 return ContentSettingsPattern::IDENTITY; | 693 return ContentSettingsPattern::IDENTITY; |
649 } | 694 } |
650 | 695 |
651 // static | 696 // static |
652 ContentSettingsPattern::Relation ContentSettingsPattern::CompareScheme( | |
653 const ContentSettingsPattern::PatternParts& parts, | |
654 const ContentSettingsPattern::PatternParts& other_parts) { | |
655 if (parts.is_scheme_wildcard && !other_parts.is_scheme_wildcard) | |
656 return ContentSettingsPattern::SUCCESSOR; | |
657 if (!parts.is_scheme_wildcard && other_parts.is_scheme_wildcard) | |
658 return ContentSettingsPattern::PREDECESSOR; | |
659 | |
660 int result = parts.scheme.compare(other_parts.scheme); | |
661 if (result == 0) | |
662 return ContentSettingsPattern::IDENTITY; | |
663 if (result > 0) | |
664 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | |
665 return ContentSettingsPattern::DISJOINT_ORDER_POST; | |
666 } | |
667 | |
668 // static | |
669 ContentSettingsPattern::Relation ContentSettingsPattern::ComparePort( | 697 ContentSettingsPattern::Relation ContentSettingsPattern::ComparePort( |
670 const ContentSettingsPattern::PatternParts& parts, | 698 const ContentSettingsPattern::PatternParts& parts, |
671 const ContentSettingsPattern::PatternParts& other_parts) { | 699 const ContentSettingsPattern::PatternParts& other_parts) { |
672 if (parts.is_port_wildcard && !other_parts.is_port_wildcard) | 700 if (parts.is_port_wildcard && !other_parts.is_port_wildcard) |
673 return ContentSettingsPattern::SUCCESSOR; | 701 return ContentSettingsPattern::SUCCESSOR; |
674 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) | 702 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) |
675 return ContentSettingsPattern::PREDECESSOR; | 703 return ContentSettingsPattern::PREDECESSOR; |
676 | 704 |
677 int result = parts.port.compare(other_parts.port); | 705 int result = parts.port.compare(other_parts.port); |
678 if (result == 0) | 706 if (result == 0) |
679 return ContentSettingsPattern::IDENTITY; | 707 return ContentSettingsPattern::IDENTITY; |
680 if (result > 0) | 708 if (result > 0) |
681 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 709 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
682 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 710 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
683 } | 711 } |
OLD | NEW |