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

Side by Side Diff: url/scheme_host_port.cc

Issue 2378323003: Add url::Origin::GetURL() to convert Origins to URLs without reparsing (Closed)
Patch Set: remove fuzzer Created 4 years, 2 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
« url/origin.cc ('K') | « url/scheme_host_port.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/scheme_host_port.h" 5 #include "url/scheme_host_port.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <tuple> 10 #include <tuple>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/numerics/safe_conversions.h" 13 #include "base/numerics/safe_conversions.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 #include "url/third_party/mozilla/url_parse.h"
16 #include "url/url_canon.h" 17 #include "url/url_canon.h"
17 #include "url/url_canon_stdstring.h" 18 #include "url/url_canon_stdstring.h"
18 #include "url/url_constants.h" 19 #include "url/url_constants.h"
19 #include "url/url_util.h" 20 #include "url/url_util.h"
20 21
21 namespace url { 22 namespace url {
22 23
23 namespace { 24 namespace {
24 25
25 bool IsCanonicalHost(const base::StringPiece& host) { 26 bool IsCanonicalHost(const base::StringPiece& host) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (default_port == PORT_UNSPECIFIED) 161 if (default_port == PORT_UNSPECIFIED)
161 return result; 162 return result;
162 if (port_ != default_port) { 163 if (port_ != default_port) {
163 result.push_back(':'); 164 result.push_back(':');
164 result.append(base::UintToString(port_)); 165 result.append(base::UintToString(port_));
165 } 166 }
166 167
167 return result; 168 return result;
168 } 169 }
169 170
171 GURL SchemeHostPort::GetURL() const {
172 std::string serialized = Serialize();
173 if (serialized.empty())
174 return GURL();
175
176 static const int schemeSeparatorLength = strlen(kStandardSchemeSeparator);
177
178 Parsed parsed;
179 parsed.scheme = Component(0, scheme().length());
180
181 int host_begin = scheme().length() + schemeSeparatorLength;
182 parsed.host = Component(host_begin, host().length());
183
184 if (serialized.length() > host_begin + host().length()) {
185 int port_begin = host_begin + host().length() + 1;
186 parsed.port = Component(port_begin, serialized.length() - port_begin);
187 }
188
189 // Append a / on the end of the URL.
190 parsed.path = Component(serialized.length(), 1);
191 serialized.append("/");
192
193 return GURL(serialized.data(), serialized.length(), parsed, true);
194 }
195
170 bool SchemeHostPort::Equals(const SchemeHostPort& other) const { 196 bool SchemeHostPort::Equals(const SchemeHostPort& other) const {
171 return port_ == other.port() && scheme_ == other.scheme() && 197 return port_ == other.port() && scheme_ == other.scheme() &&
172 host_ == other.host(); 198 host_ == other.host();
173 } 199 }
174 200
175 bool SchemeHostPort::operator<(const SchemeHostPort& other) const { 201 bool SchemeHostPort::operator<(const SchemeHostPort& other) const {
176 return std::tie(port_, scheme_, host_) < 202 return std::tie(port_, scheme_, host_) <
177 std::tie(other.port_, other.scheme_, other.host_); 203 std::tie(other.port_, other.scheme_, other.host_);
178 } 204 }
179 205
180 } // namespace url 206 } // namespace url
OLDNEW
« url/origin.cc ('K') | « url/scheme_host_port.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698