Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/web_ui_util.h" | 5 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 scoped_refptr<RefCountedMemory> raw_icon(icon_data); | 35 scoped_refptr<RefCountedMemory> raw_icon(icon_data); |
| 36 std::string str_url; | 36 std::string str_url; |
| 37 str_url.insert(str_url.end(), | 37 str_url.insert(str_url.end(), |
| 38 raw_icon->front(), | 38 raw_icon->front(), |
| 39 raw_icon->front() + raw_icon->size()); | 39 raw_icon->front() + raw_icon->size()); |
| 40 base::Base64Encode(str_url, &str_url); | 40 base::Base64Encode(str_url, &str_url); |
| 41 str_url.insert(0, "data:image/png;base64,"); | 41 str_url.insert(0, "data:image/png;base64,"); |
| 42 return str_url; | 42 return str_url; |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool IsChromeURL(const GURL& url) { | |
| 46 return url.SchemeIs(chrome::kChromeUIScheme) || | |
| 47 url.SchemeIs(chrome::kAboutScheme); | |
| 48 } | |
| 49 | |
| 50 std::string GetChromeURLHost(const GURL& url) { | |
| 51 if (url.has_host()) | |
| 52 return url.host(); | |
| 53 std::string path = url.path(); | |
| 54 // "about://host" has path "//host"; skip "//" in this special case. | |
| 55 size_t begin = StartsWithASCII(path, "//", true) ? 2 : 0; | |
| 56 size_t end = path.find_first_of("/?#", begin); | |
| 57 size_t length = (end == std::string::npos) ? end : end - begin; | |
| 58 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.
| |
| 59 } | |
| 60 | |
| 61 std::string GetChromeURLPath(const GURL& url) { | |
| 62 if (url.has_host()) | |
| 63 return url.path(); | |
| 64 std::string path = url.path(); | |
| 65 // "about://host" has path "//host"; skip "//" in this special case. | |
| 66 size_t host_begin = StartsWithASCII(path, "//", true) ? 2 : 0; | |
| 67 size_t path_begin = path.find_first_of("/?#", host_begin); | |
| 68 return path.length() > path_begin ? path.substr(path_begin) : std::string(); | |
| 69 } | |
| 70 | |
| 71 bool HostEquals(const GURL& url, const char* host) { | |
| 72 return LowerCaseEqualsASCII(GetChromeURLHost(url), host); | |
| 73 } | |
| 74 | |
| 45 bool ChromeURLHostEquals(const GURL& url, const char* host) { | 75 bool ChromeURLHostEquals(const GURL& url, const char* host) { |
| 46 return (url.SchemeIs(chrome::kChromeUIScheme) || | 76 return IsChromeURL(url) && HostEquals(url, host); |
| 47 url.SchemeIs(chrome::kAboutScheme)) && | |
| 48 LowerCaseEqualsASCII(url.host(), host); | |
| 49 } | 77 } |
| 50 | 78 |
| 51 } // namespace web_ui_util | 79 } // namespace web_ui_util |
| OLD | NEW |