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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« url/origin.cc ('K') | « url/scheme_host_port.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/scheme_host_port.cc
diff --git a/url/scheme_host_port.cc b/url/scheme_host_port.cc
index 4d0f0007595561d99bb54ffb61c57cee033b21e5..bd1fce8ed3883227aa40a059561ab886e6019360 100644
--- a/url/scheme_host_port.cc
+++ b/url/scheme_host_port.cc
@@ -13,6 +13,7 @@
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "url/gurl.h"
+#include "url/third_party/mozilla/url_parse.h"
#include "url/url_canon.h"
#include "url/url_canon_stdstring.h"
#include "url/url_constants.h"
@@ -167,6 +168,31 @@ std::string SchemeHostPort::Serialize() const {
return result;
}
+GURL SchemeHostPort::GetURL() const {
+ std::string serialized = Serialize();
+ if (serialized.empty())
+ return GURL();
+
+ static const int schemeSeparatorLength = strlen(kStandardSchemeSeparator);
+
+ Parsed parsed;
+ parsed.scheme = Component(0, scheme().length());
+
+ int host_begin = scheme().length() + schemeSeparatorLength;
+ parsed.host = Component(host_begin, host().length());
+
+ if (serialized.length() > host_begin + host().length()) {
+ int port_begin = host_begin + host().length() + 1;
+ parsed.port = Component(port_begin, serialized.length() - port_begin);
+ }
+
+ // Append a / on the end of the URL.
+ parsed.path = Component(serialized.length(), 1);
+ serialized.append("/");
+
+ return GURL(serialized.data(), serialized.length(), parsed, true);
+}
+
bool SchemeHostPort::Equals(const SchemeHostPort& other) const {
return port_ == other.port() && scheme_ == other.scheme() &&
host_ == other.host();
« 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