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

Side by Side Diff: url/gurl.cc

Issue 2562813003: Merge logic for SameDomainOrHost for GURLs and Origins (Closed)
Patch Set: brettw review Created 4 years 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
« no previous file with comments | « net/base/registry_controlled_domains/registry_controlled_domain.cc ('k') | url/url_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "url/gurl.h" 5 #include "url/gurl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <ostream> 10 #include <ostream>
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 url::StdStringCanonOutput output(&spec_); 114 url::StdStringCanonOutput output(&spec_);
115 is_valid_ = url::Canonicalize( 115 is_valid_ = url::Canonicalize(
116 input_spec.data(), static_cast<int>(input_spec.length()), trim_path_end, 116 input_spec.data(), static_cast<int>(input_spec.length()), trim_path_end,
117 NULL, &output, &parsed_); 117 NULL, &output, &parsed_);
118 118
119 output.Complete(); // Must be done before using string. 119 output.Complete(); // Must be done before using string.
120 if (is_valid_ && SchemeIsFileSystem()) { 120 if (is_valid_ && SchemeIsFileSystem()) {
121 inner_url_.reset(new GURL(spec_.data(), parsed_.Length(), 121 inner_url_.reset(new GURL(spec_.data(), parsed_.Length(),
122 *parsed_.inner_parsed(), true)); 122 *parsed_.inner_parsed(), true));
123 } 123 }
124 // Valid URLs always have non-empty specs.
125 DCHECK(!is_valid_ || !spec_.empty());
124 } 126 }
125 127
126 void GURL::InitializeFromCanonicalSpec() { 128 void GURL::InitializeFromCanonicalSpec() {
127 if (is_valid_ && SchemeIsFileSystem()) { 129 if (is_valid_ && SchemeIsFileSystem()) {
128 inner_url_.reset( 130 inner_url_.reset(
129 new GURL(spec_.data(), parsed_.Length(), 131 new GURL(spec_.data(), parsed_.Length(),
130 *parsed_.inner_parsed(), true)); 132 *parsed_.inner_parsed(), true));
131 } 133 }
132 134
133 #ifndef NDEBUG 135 #ifndef NDEBUG
134 // For testing purposes, check that the parsed canonical URL is identical to 136 // For testing purposes, check that the parsed canonical URL is identical to
135 // what we would have produced. Skip checking for invalid URLs have no meaning 137 // what we would have produced. Skip checking for invalid URLs have no meaning
136 // and we can't always canonicalize then reproducibly. 138 // and we can't always canonicalize then reproducibly.
137 if (is_valid_) { 139 if (is_valid_) {
140 DCHECK(!spec_.empty());
138 url::Component scheme; 141 url::Component scheme;
139 // We can't do this check on the inner_url of a filesystem URL, as 142 // We can't do this check on the inner_url of a filesystem URL, as
140 // canonical_spec actually points to the start of the outer URL, so we'd 143 // canonical_spec actually points to the start of the outer URL, so we'd
141 // end up with infinite recursion in this constructor. 144 // end up with infinite recursion in this constructor.
142 if (!url::FindAndCompareScheme(spec_.data(), spec_.length(), 145 if (!url::FindAndCompareScheme(spec_.data(), spec_.length(),
143 url::kFileSystemScheme, &scheme) || 146 url::kFileSystemScheme, &scheme) ||
144 scheme.begin == parsed_.scheme.begin) { 147 scheme.begin == parsed_.scheme.begin) {
145 // We need to retain trailing whitespace on path URLs, as the |parsed_| 148 // We need to retain trailing whitespace on path URLs, as the |parsed_|
146 // spec we originally received may legitimately contain trailing white- 149 // spec we originally received may legitimately contain trailing white-
147 // space on the path or components e.g. if the #ref has been 150 // space on the path or components e.g. if the #ref has been
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 h.len -= 2; 436 h.len -= 2;
434 } 437 }
435 return ComponentString(h); 438 return ComponentString(h);
436 } 439 }
437 440
438 std::string GURL::GetContent() const { 441 std::string GURL::GetContent() const {
439 return is_valid_ ? ComponentString(parsed_.GetContent()) : std::string(); 442 return is_valid_ ? ComponentString(parsed_.GetContent()) : std::string();
440 } 443 }
441 444
442 bool GURL::HostIsIPAddress() const { 445 bool GURL::HostIsIPAddress() const {
443 if (!is_valid_ || spec_.empty()) 446 return is_valid_ && url::HostIsIPAddress(host_piece());
444 return false;
445
446 url::RawCanonOutputT<char, 128> ignored_output;
447 url::CanonHostInfo host_info;
448 url::CanonicalizeIPAddress(spec_.c_str(), parsed_.host, &ignored_output,
449 &host_info);
450 return host_info.IsIPAddress();
451 } 447 }
452 448
453 #ifdef WIN32 449 #ifdef WIN32
454 450
455 const GURL& GURL::EmptyGURL() { 451 const GURL& GURL::EmptyGURL() {
456 // Avoid static object construction/destruction on startup/shutdown. 452 // Avoid static object construction/destruction on startup/shutdown.
457 if (!empty_gurl) { 453 if (!empty_gurl) {
458 // Create the string. Be careful that we don't break in the case that this 454 // Create the string. Be careful that we don't break in the case that this
459 // is being called from multiple threads. 455 // is being called from multiple threads.
460 GURL* new_empty_gurl = new GURL; 456 GURL* new_empty_gurl = new GURL;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 508 }
513 509
514 bool operator==(const GURL& x, const base::StringPiece& spec) { 510 bool operator==(const GURL& x, const base::StringPiece& spec) {
515 DCHECK_EQ(GURL(spec).possibly_invalid_spec(), spec); 511 DCHECK_EQ(GURL(spec).possibly_invalid_spec(), spec);
516 return x.possibly_invalid_spec() == spec; 512 return x.possibly_invalid_spec() == spec;
517 } 513 }
518 514
519 bool operator!=(const GURL& x, const base::StringPiece& spec) { 515 bool operator!=(const GURL& x, const base::StringPiece& spec) {
520 return !(x == spec); 516 return !(x == spec);
521 } 517 }
OLDNEW
« no previous file with comments | « net/base/registry_controlled_domains/registry_controlled_domain.cc ('k') | url/url_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698