Chromium Code Reviews| Index: content/common/origin_util.cc |
| diff --git a/content/common/origin_util.cc b/content/common/origin_util.cc |
| index 11873d63cfd9de6f8b7b2c4592d785abef089e42..f81fb18779909026227b0b11d5e8c3b207d71444 100644 |
| --- a/content/common/origin_util.cc |
| +++ b/content/common/origin_util.cc |
| @@ -90,4 +90,58 @@ void ResetSchemesAndOriginsWhitelistForTesting() { |
| g_trustworthy_whitelist.Get().Reset(); |
| } |
| +bool HasSuborigin(const GURL& url) { |
| + return url.scheme() == "http-so" || url.scheme() == "https-so"; |
|
nasko
2016/09/26 22:54:54
Shouldn't the GURL be valid before we start poking
jww
2016/09/28 23:35:14
Done.
|
| +} |
| + |
| +std::string SuboriginFromUrl(const GURL& url) { |
| + if (!HasSuborigin(url)) |
| + return ""; |
| + size_t suborigin_end = url.host().find("."); |
| + return url.host().substr(0, suborigin_end); |
| +} |
| + |
| +std::string HostFromUrlStripSuborigin(const GURL& url) { |
|
nasko
2016/09/26 22:54:54
Unused method?
jww
2016/09/28 23:35:14
Done.
|
| + std::string host = url.host(); |
| + size_t suborigin_end = host.find("."); |
| + if (suborigin_end == std::string::npos) |
| + return host; |
| + return url.host().substr(suborigin_end + 1, |
| + host.length() - suborigin_end - 1); |
| +} |
| + |
| +std::string SchemeFromUrlStripSuborigin(const GURL& url) { |
|
nasko
2016/09/26 22:54:55
Unused method?
jww
2016/09/28 23:35:15
Done.
|
| + if (!HasSuborigin(url)) |
| + return ""; |
| + |
| + if (url.scheme() == "http-so") |
| + return "http"; |
| + |
| + if (url.scheme() == "https-so") |
| + return "https"; |
| + |
| + NOTREACHED(); |
| + return ""; |
| +} |
| + |
| +GURL UrlStripSuborigin(const GURL& url) { |
| + if (!HasSuborigin(url)) |
| + return url; |
| + |
| + GURL::Replacements replacements; |
| + if (url.scheme() == "http-so") { |
| + replacements.SetSchemeStr("http"); |
|
nasko
2016/09/26 22:54:54
Use constants instead of hardcoded strings.
jww
2016/09/28 23:35:14
Done.
|
| + } else { |
| + DCHECK(url.scheme() == "https-so"); |
| + replacements.SetSchemeStr("https"); |
| + } |
| + |
| + size_t suborigin_end = url.host().find("."); |
| + std::string new_host(url.host().substr( |
| + suborigin_end + 1, url.host().length() - suborigin_end - 1)); |
| + replacements.SetHostStr(new_host); |
| + |
| + return url.ReplaceComponents(replacements); |
| +} |
| + |
| } // namespace content |