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

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

Issue 2481923002: [WIP] make GURL::path() return a StringPiece (Closed)
Patch Set: thanks asan Created 4 years, 1 month 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // static 226 // static
227 bool ContentSettingsPattern::Builder::Canonicalize(PatternParts* parts) { 227 bool ContentSettingsPattern::Builder::Canonicalize(PatternParts* parts) {
228 // Canonicalize the scheme part. 228 // Canonicalize the scheme part.
229 const std::string scheme(base::ToLowerASCII(parts->scheme)); 229 const std::string scheme(base::ToLowerASCII(parts->scheme));
230 parts->scheme = scheme; 230 parts->scheme = scheme;
231 231
232 if (parts->scheme == std::string(url::kFileScheme) && 232 if (parts->scheme == std::string(url::kFileScheme) &&
233 !parts->is_path_wildcard) { 233 !parts->is_path_wildcard) {
234 GURL url(std::string(url::kFileScheme) + 234 GURL url(std::string(url::kFileScheme) +
235 std::string(url::kStandardSchemeSeparator) + parts->path); 235 std::string(url::kStandardSchemeSeparator) + parts->path);
236 parts->path = url.path(); 236 parts->path = url.path().as_string();
237 } 237 }
238 238
239 // Canonicalize the host part. 239 // Canonicalize the host part.
240 const std::string host(parts->host); 240 const std::string host(parts->host);
241 url::CanonHostInfo host_info; 241 url::CanonHostInfo host_info;
242 std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); 242 std::string canonicalized_host(net::CanonicalizeHost(host, &host_info));
243 if (host_info.IsIPAddress() && parts->has_domain_wildcard) 243 if (host_info.IsIPAddress() && parts->has_domain_wildcard)
244 return false; 244 return false;
245 canonicalized_host = net::TrimEndingDot(canonicalized_host); 245 canonicalized_host = net::TrimEndingDot(canonicalized_host);
246 246
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // static 384 // static
385 ContentSettingsPattern ContentSettingsPattern::FromURL( 385 ContentSettingsPattern ContentSettingsPattern::FromURL(
386 const GURL& url) { 386 const GURL& url) {
387 std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder( 387 std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder(
388 ContentSettingsPattern::CreateBuilder(false)); 388 ContentSettingsPattern::CreateBuilder(false));
389 const GURL* local_url = &url; 389 const GURL* local_url = &url;
390 if (url.SchemeIsFileSystem() && url.inner_url()) { 390 if (url.SchemeIsFileSystem() && url.inner_url()) {
391 local_url = url.inner_url(); 391 local_url = url.inner_url();
392 } 392 }
393 if (local_url->SchemeIsFile()) { 393 if (local_url->SchemeIsFile()) {
394 builder->WithScheme(local_url->scheme())->WithPath(local_url->path()); 394 builder->WithScheme(local_url->scheme())
395 ->WithPath(local_url->path().as_string());
395 } else { 396 } else {
396 // Please keep the order of the ifs below as URLs with an IP as host can 397 // Please keep the order of the ifs below as URLs with an IP as host can
397 // also have a "http" scheme. 398 // also have a "http" scheme.
398 if (local_url->HostIsIPAddress()) { 399 if (local_url->HostIsIPAddress()) {
399 builder->WithScheme(local_url->scheme())->WithHost(local_url->host()); 400 builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
400 } else if (local_url->SchemeIs(url::kHttpScheme)) { 401 } else if (local_url->SchemeIs(url::kHttpScheme)) {
401 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost( 402 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(
402 local_url->host()); 403 local_url->host());
403 } else if (local_url->SchemeIs(url::kHttpsScheme)) { 404 } else if (local_url->SchemeIs(url::kHttpsScheme)) {
404 builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost( 405 builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost(
(...skipping 17 matching lines...) Expand all
422 ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard( 423 ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard(
423 const GURL& url) { 424 const GURL& url) {
424 std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder( 425 std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder(
425 ContentSettingsPattern::CreateBuilder(false)); 426 ContentSettingsPattern::CreateBuilder(false));
426 427
427 const GURL* local_url = &url; 428 const GURL* local_url = &url;
428 if (url.SchemeIsFileSystem() && url.inner_url()) { 429 if (url.SchemeIsFileSystem() && url.inner_url()) {
429 local_url = url.inner_url(); 430 local_url = url.inner_url();
430 } 431 }
431 if (local_url->SchemeIsFile()) { 432 if (local_url->SchemeIsFile()) {
432 builder->WithScheme(local_url->scheme())->WithPath(local_url->path()); 433 builder->WithScheme(local_url->scheme())
434 ->WithPath(local_url->path().as_string());
433 } else { 435 } else {
434 builder->WithScheme(local_url->scheme())->WithHost(local_url->host()); 436 builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
435 if (local_url->port().empty()) { 437 if (local_url->port().empty()) {
436 builder->WithPort(GetDefaultPort(local_url->scheme())); 438 builder->WithPort(GetDefaultPort(local_url->scheme()));
437 } else { 439 } else {
438 builder->WithPort(local_url->port()); 440 builder->WithPort(local_url->port());
439 } 441 }
440 } 442 }
441 return builder->Build(); 443 return builder->Build();
442 } 444 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 553 }
552 554
553 // File URLs have no host. Matches if the pattern has the path wildcard set, 555 // File URLs have no host. Matches if the pattern has the path wildcard set,
554 // or if the path in the URL is identical to the one in the pattern. 556 // or if the path in the URL is identical to the one in the pattern.
555 // For filesystem:file URLs, the path used is the filesystem type, so all 557 // For filesystem:file URLs, the path used is the filesystem type, so all
556 // filesystem:file:///temporary/... are equivalent. 558 // filesystem:file:///temporary/... are equivalent.
557 // TODO(msramek): The file scheme should not behave differently when nested 559 // TODO(msramek): The file scheme should not behave differently when nested
558 // inside the filesystem scheme. Investigate and fix. 560 // inside the filesystem scheme. Investigate and fix.
559 if (!parts_.is_scheme_wildcard && scheme == url::kFileScheme) 561 if (!parts_.is_scheme_wildcard && scheme == url::kFileScheme)
560 return parts_.is_path_wildcard || 562 return parts_.is_path_wildcard ||
561 parts_.path == std::string(local_url->path()); 563 parts_.path == std::string(local_url->path().as_string());
562 564
563 // Match the host part. 565 // Match the host part.
564 const std::string host(net::TrimEndingDot(local_url->host())); 566 const std::string host(net::TrimEndingDot(local_url->host()));
565 if (!parts_.has_domain_wildcard) { 567 if (!parts_.has_domain_wildcard) {
566 if (parts_.host != host) 568 if (parts_.host != host)
567 return false; 569 return false;
568 } else { 570 } else {
569 if (!IsSubDomainOrEqual(host, parts_.host)) 571 if (!IsSubDomainOrEqual(host, parts_.host))
570 return false; 572 return false;
571 } 573 }
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) 822 if (!parts.is_path_wildcard && other_parts.is_path_wildcard)
821 return ContentSettingsPattern::PREDECESSOR; 823 return ContentSettingsPattern::PREDECESSOR;
822 824
823 int result = parts.path.compare(other_parts.path); 825 int result = parts.path.compare(other_parts.path);
824 if (result == 0) 826 if (result == 0)
825 return ContentSettingsPattern::IDENTITY; 827 return ContentSettingsPattern::IDENTITY;
826 if (result > 0) 828 if (result > 0)
827 return ContentSettingsPattern::DISJOINT_ORDER_PRE; 829 return ContentSettingsPattern::DISJOINT_ORDER_PRE;
828 return ContentSettingsPattern::DISJOINT_ORDER_POST; 830 return ContentSettingsPattern::DISJOINT_ORDER_POST;
829 } 831 }
OLDNEW
« no previous file with comments | « components/cloud_devices/common/cloud_devices_urls.cc ('k') | components/dom_distiller/core/page_features.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698