Merge logic for SameDomainOrHost for GURLs and Origins
Previously, we used to just call:
SameDomainOrHost(origin1.GetURL(), origin2.GetURL())
This isn't necessary, as we have all the information in the Origin itself.
Additionally, GetURL() isn't free. We do a bunch of string copies,
allocations, and some non-cheap policy decisions.
This patch moves GURL::HostIsIPAddress logic to url_util, and reuses
that code for both GURLs and Origins.
BUG=664174,348655
Review-Url: https://codereview.chromium.org/2562813003
Cr-Commit-Position: refs/heads/master@{#439287}
diff --git a/url/url_util.cc b/url/url_util.cc
index 0b3044dc..b3e3604 100644
--- a/url/url_util.cc
+++ b/url/url_util.cc
@@ -538,6 +538,14 @@
return true;
}
+bool HostIsIPAddress(base::StringPiece host) {
+ url::RawCanonOutputT<char, 128> ignored_output;
+ url::CanonHostInfo host_info;
+ url::CanonicalizeIPAddress(host.data(), Component(0, host.length()),
+ &ignored_output, &host_info);
+ return host_info.IsIPAddress();
+}
+
bool Canonicalize(const char* spec,
int spec_len,
bool trim_path_end,