OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/common/favicon/favicon_url_parser.h" | 5 #include "chrome/common/favicon/favicon_url_parser.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "components/favicon_base/favicon_types.h" | 8 #include "components/favicon_base/favicon_types.h" |
9 #include "net/url_request/url_request.h" | 9 #include "net/url_request/url_request.h" |
10 #include "ui/base/webui/web_ui_util.h" | 10 #include "ui/base/webui/web_ui_util.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 return path.compare(start_index, search.length(), search) == 0; | 28 return path.compare(start_index, search.length(), search) == 0; |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 namespace chrome { | 33 namespace chrome { |
34 | 34 |
35 bool ParseFaviconPath(const std::string& path, | 35 bool ParseFaviconPath(const std::string& path, |
36 int icon_types, | 36 int icon_types, |
37 ParsedFaviconPath* parsed) { | 37 ParsedFaviconPath* parsed) { |
38 DCHECK(parsed); | |
pkotwicz
2015/01/26 22:27:18
I think the DCHECK() is not useful. If |parsed| is
huangs
2015/01/26 23:00:43
It's a controlled-crash vs. uncontrolled-crash iss
| |
38 parsed->is_icon_url = false; | 39 parsed->is_icon_url = false; |
39 parsed->url = ""; | 40 parsed->url = ""; |
40 parsed->size_in_dip = gfx::kFaviconSize; | 41 parsed->size_in_dip = gfx::kFaviconSize; |
41 parsed->device_scale_factor = 1.0f; | 42 parsed->device_scale_factor = 1.0f; |
42 parsed->path_index = std::string::npos; | 43 parsed->path_index = std::string::npos; |
43 | 44 |
44 if (path.empty()) | 45 if (path.empty()) |
45 return false; | 46 return false; |
46 | 47 |
47 size_t parsed_index = 0; | 48 size_t parsed_index = 0; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 icon_types == favicon_base::FAVICON) | 90 icon_types == favicon_base::FAVICON) |
90 return false; | 91 return false; |
91 | 92 |
92 parsed_index = slash + 1; | 93 parsed_index = slash + 1; |
93 } | 94 } |
94 | 95 |
95 if (HasSubstringAt(path, parsed_index, kIconURLParameter)) { | 96 if (HasSubstringAt(path, parsed_index, kIconURLParameter)) { |
96 parsed_index += strlen(kIconURLParameter); | 97 parsed_index += strlen(kIconURLParameter); |
97 parsed->is_icon_url = true; | 98 parsed->is_icon_url = true; |
98 parsed->url = path.substr(parsed_index); | 99 parsed->url = path.substr(parsed_index); |
99 } else { | 100 } else if (HasSubstringAt(path, parsed_index, kOriginParameter)) { |
100 // URL requests prefixed with "origin/" are converted to a form with an | 101 // URL requests prefixed with "origin/" are converted to a form with an |
101 // empty path and a valid scheme. (e.g., example.com --> | 102 // empty path and a valid scheme. (e.g., example.com --> |
102 // http://example.com/ or http://example.com/a --> http://example.com/) | 103 // http://example.com/ or http://example.com/a --> http://example.com/) |
103 if (HasSubstringAt(path, parsed_index, kOriginParameter)) { | 104 parsed_index += strlen(kOriginParameter); |
104 parsed_index += strlen(kOriginParameter); | 105 std::string possibly_invalid_url = path.substr(parsed_index); |
105 std::string possibly_invalid_url = path.substr(parsed_index); | |
106 | 106 |
107 // If the URL does not specify a scheme (e.g., example.com instead of | 107 // If the URL does not specify a scheme (e.g., example.com instead of |
108 // http://example.com), add "http://" as a default. | 108 // http://example.com), add "http://" as a default. |
109 if (!GURL(possibly_invalid_url).has_scheme()) | 109 if (!GURL(possibly_invalid_url).has_scheme()) |
110 possibly_invalid_url = "http://" + possibly_invalid_url; | 110 possibly_invalid_url = "http://" + possibly_invalid_url; |
111 | 111 |
112 // Strip the path beyond the top-level domain. | 112 // Strip the path beyond the top-level domain. |
113 parsed->url = GURL(possibly_invalid_url).GetOrigin().spec(); | 113 parsed->url = GURL(possibly_invalid_url).GetOrigin().spec(); |
114 } else { | 114 } else { |
115 parsed->url = path.substr(parsed_index); | 115 parsed->url = path.substr(parsed_index); |
116 } | |
117 } | 116 } |
118 | 117 |
119 // The parsed index needs to be returned in order to allow Instant Extended | 118 // The parsed index needs to be returned in order to allow Instant Extended |
120 // to translate favicon URLs using advanced parameters. | 119 // to translate favicon URLs using advanced parameters. |
121 // Example: | 120 // Example: |
122 // "chrome-search://favicon/size/16@2x/<renderer-id>/<most-visited-id>" | 121 // "chrome-search://favicon/size/16@2x/<renderer-id>/<most-visited-id>" |
123 // would be translated to: | 122 // would be translated to: |
124 // "chrome-search://favicon/size/16@2x/<most-visited-item-with-given-id>". | 123 // "chrome-search://favicon/size/16@2x/<most-visited-item-with-given-id>". |
125 parsed->path_index = parsed_index; | 124 parsed->path_index = parsed_index; |
126 return true; | 125 return true; |
127 } | 126 } |
128 | 127 |
129 } // namespace chrome | 128 } // namespace chrome |
OLD | NEW |