Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/public/common/origin_util.h" | 5 #include "content/public/common/origin_util.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "content/public/common/content_client.h" | 10 #include "content/public/common/content_client.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 | 85 |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void ResetSchemesAndOriginsWhitelistForTesting() { | 89 void ResetSchemesAndOriginsWhitelistForTesting() { |
| 90 g_trustworthy_whitelist.Get().Reset(); | 90 g_trustworthy_whitelist.Get().Reset(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool HasSuborigin(const GURL& url) { | |
| 94 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.
| |
| 95 } | |
| 96 | |
| 97 std::string SuboriginFromUrl(const GURL& url) { | |
| 98 if (!HasSuborigin(url)) | |
| 99 return ""; | |
| 100 size_t suborigin_end = url.host().find("."); | |
| 101 return url.host().substr(0, suborigin_end); | |
| 102 } | |
| 103 | |
| 104 std::string HostFromUrlStripSuborigin(const GURL& url) { | |
|
nasko
2016/09/26 22:54:54
Unused method?
jww
2016/09/28 23:35:14
Done.
| |
| 105 std::string host = url.host(); | |
| 106 size_t suborigin_end = host.find("."); | |
| 107 if (suborigin_end == std::string::npos) | |
| 108 return host; | |
| 109 return url.host().substr(suborigin_end + 1, | |
| 110 host.length() - suborigin_end - 1); | |
| 111 } | |
| 112 | |
| 113 std::string SchemeFromUrlStripSuborigin(const GURL& url) { | |
|
nasko
2016/09/26 22:54:55
Unused method?
jww
2016/09/28 23:35:15
Done.
| |
| 114 if (!HasSuborigin(url)) | |
| 115 return ""; | |
| 116 | |
| 117 if (url.scheme() == "http-so") | |
| 118 return "http"; | |
| 119 | |
| 120 if (url.scheme() == "https-so") | |
| 121 return "https"; | |
| 122 | |
| 123 NOTREACHED(); | |
| 124 return ""; | |
| 125 } | |
| 126 | |
| 127 GURL UrlStripSuborigin(const GURL& url) { | |
| 128 if (!HasSuborigin(url)) | |
| 129 return url; | |
| 130 | |
| 131 GURL::Replacements replacements; | |
| 132 if (url.scheme() == "http-so") { | |
| 133 replacements.SetSchemeStr("http"); | |
|
nasko
2016/09/26 22:54:54
Use constants instead of hardcoded strings.
jww
2016/09/28 23:35:14
Done.
| |
| 134 } else { | |
| 135 DCHECK(url.scheme() == "https-so"); | |
| 136 replacements.SetSchemeStr("https"); | |
| 137 } | |
| 138 | |
| 139 size_t suborigin_end = url.host().find("."); | |
| 140 std::string new_host(url.host().substr( | |
| 141 suborigin_end + 1, url.host().length() - suborigin_end - 1)); | |
| 142 replacements.SetHostStr(new_host); | |
| 143 | |
| 144 return url.ReplaceComponents(replacements); | |
| 145 } | |
| 146 | |
| 93 } // namespace content | 147 } // namespace content |
| OLD | NEW |