Chromium Code Reviews| Index: chrome/browser/ui/webui/web_ui_util.cc |
| diff --git a/chrome/browser/ui/webui/web_ui_util.cc b/chrome/browser/ui/webui/web_ui_util.cc |
| index b6f49b33c191f5be028829a0205fac852acbce27..ee056c0aff8a25f411dfe9e7a40954b8a824c766 100644 |
| --- a/chrome/browser/ui/webui/web_ui_util.cc |
| +++ b/chrome/browser/ui/webui/web_ui_util.cc |
| @@ -42,10 +42,38 @@ std::string GetImageDataUrlFromResource(int res) { |
| return str_url; |
| } |
| +bool IsChromeURL(const GURL& url) { |
| + return url.SchemeIs(chrome::kChromeUIScheme) || |
| + url.SchemeIs(chrome::kAboutScheme); |
| +} |
| + |
| +std::string GetChromeURLHost(const GURL& url) { |
| + if (url.has_host()) |
| + return url.host(); |
| + std::string path = url.path(); |
| + // "about://host" has path "//host"; skip "//" in this special case. |
| + size_t begin = StartsWithASCII(path, "//", true) ? 2 : 0; |
| + size_t end = path.find_first_of("/?#", begin); |
| + size_t length = (end == std::string::npos) ? end : end - begin; |
| + return path.length() > begin ? path.substr(begin, length) : std::string(); |
|
abarth-chromium
2011/05/27 17:19:25
These functions are way too low-level for chrome/b
msw
2011/05/31 13:34:29
I rewrote this as URLFixerUpper::FixupChromeURL.
|
| +} |
| + |
| +std::string GetChromeURLPath(const GURL& url) { |
| + if (url.has_host()) |
| + return url.path(); |
| + std::string path = url.path(); |
| + // "about://host" has path "//host"; skip "//" in this special case. |
| + size_t host_begin = StartsWithASCII(path, "//", true) ? 2 : 0; |
| + size_t path_begin = path.find_first_of("/?#", host_begin); |
| + return path.length() > path_begin ? path.substr(path_begin) : std::string(); |
| +} |
| + |
| +bool HostEquals(const GURL& url, const char* host) { |
| + return LowerCaseEqualsASCII(GetChromeURLHost(url), host); |
| +} |
| + |
| bool ChromeURLHostEquals(const GURL& url, const char* host) { |
| - return (url.SchemeIs(chrome::kChromeUIScheme) || |
| - url.SchemeIs(chrome::kAboutScheme)) && |
| - LowerCaseEqualsASCII(url.host(), host); |
| + return IsChromeURL(url) && HostEquals(url, host); |
| } |
| } // namespace web_ui_util |