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

Unified Diff: chrome/browser/ui/webui/web_ui_util.cc

Issue 7068007: Revise about: and chrome: url handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup and improve patch. Created 9 years, 7 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
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

Powered by Google App Engine
This is Rietveld 408576698