OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/renderer/searchbox/searchbox.h" | 5 #include "chrome/renderer/searchbox/searchbox.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/favicon/fallback_icon_url_parser.h" | |
13 #include "chrome/common/favicon/favicon_url_parser.h" | 14 #include "chrome/common/favicon/favicon_url_parser.h" |
15 #include "chrome/common/favicon/large_icon_url_parser.h" | |
14 #include "chrome/common/omnibox_focus_state.h" | 16 #include "chrome/common/omnibox_focus_state.h" |
15 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
16 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
17 #include "chrome/renderer/searchbox/searchbox_extension.h" | 19 #include "chrome/renderer/searchbox/searchbox_extension.h" |
18 #include "components/favicon_base/favicon_types.h" | 20 #include "components/favicon_base/favicon_types.h" |
19 #include "content/public/renderer/render_view.h" | 21 #include "content/public/renderer/render_view.h" |
20 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
21 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
22 #include "third_party/WebKit/public/web/WebFrame.h" | 24 #include "third_party/WebKit/public/web/WebFrame.h" |
23 #include "third_party/WebKit/public/web/WebView.h" | 25 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 // default favicon. | 110 // default favicon. |
109 std::string id_part = raw_path.substr(parsed.path_index); | 111 std::string id_part = raw_path.substr(parsed.path_index); |
110 InstantRestrictedID id; | 112 InstantRestrictedID id; |
111 if (!GetInstantRestrictedIDFromPath(render_view_id, id_part, &id)) | 113 if (!GetInstantRestrictedIDFromPath(render_view_id, id_part, &id)) |
112 return true; | 114 return true; |
113 | 115 |
114 *rid = id; | 116 *rid = id; |
115 return true; | 117 return true; |
116 } | 118 } |
117 | 119 |
120 // Similar to GetRestrictedIDFromFaviconUrl(), but for large icons. | |
121 bool GetRestrictedIDFromLargeIconUrl(int render_view_id, | |
122 const GURL& url, | |
123 std::string* favicon_params, | |
124 InstantRestrictedID* rid) { | |
125 // Strip leading slash. | |
126 std::string raw_path = url.path(); | |
127 DCHECK_GT(raw_path.length(), (size_t) 0); | |
128 DCHECK_EQ(raw_path[0], '/'); | |
129 raw_path = raw_path.substr(1); | |
130 | |
131 LargeIconUrlParser parser; | |
132 if (!parser.Parse(raw_path)) | |
133 return false; | |
134 | |
135 *favicon_params = raw_path.substr(0, parser.path_index()); | |
136 | |
137 std::string id_part = raw_path.substr(parser.path_index()); | |
138 InstantRestrictedID id; | |
139 if (!GetInstantRestrictedIDFromPath(render_view_id, id_part, &id)) | |
140 return true; | |
141 | |
142 *rid = id; | |
143 return true; | |
144 } | |
145 | |
146 // Similar to GetRestrictedIDFromFaviconUrl(), but for fallback icons. | |
147 bool GetRestrictedIDFromFallbackIconUrl(int render_view_id, | |
148 const GURL& url, | |
149 std::string* favicon_params, | |
150 InstantRestrictedID* rid) { | |
151 // Strip leading slash. | |
152 std::string raw_path = url.path(); | |
153 DCHECK_GT(raw_path.length(), (size_t) 0); | |
154 DCHECK_EQ(raw_path[0], '/'); | |
155 raw_path = raw_path.substr(1); | |
156 | |
157 chrome::ParsedFallbackIconPath parser; | |
158 if (!parser.Parse(raw_path)) | |
159 return false; | |
160 | |
161 *favicon_params = raw_path.substr(0, parser.path_index()); | |
162 | |
163 std::string id_part = raw_path.substr(parser.path_index()); | |
164 InstantRestrictedID id; | |
165 if (!GetInstantRestrictedIDFromPath(render_view_id, id_part, &id)) | |
166 return true; | |
167 | |
168 *rid = id; | |
169 return true; | |
beaudoin
2015/03/19 02:17:35
This looks like three copies of the same code with
huangs
2015/03/19 02:23:30
I have grand plans to refactor these. Triplicatin
| |
170 } | |
171 | |
172 | |
118 // Parses a thumbnail |url| and fills in |id| with the InstantRestrictedID | 173 // Parses a thumbnail |url| and fills in |id| with the InstantRestrictedID |
119 // obtained from the |url|. |render_view_id| is the ID of the associated | 174 // obtained from the |url|. |render_view_id| is the ID of the associated |
120 // RenderView. | 175 // RenderView. |
121 // | 176 // |
122 // Valid |url| forms: | 177 // Valid |url| forms: |
123 // chrome-search://thumb/<view_id>/<restricted_id> | 178 // chrome-search://thumb/<view_id>/<restricted_id> |
124 // | 179 // |
125 // If the |url| is valid, returns true and fills in |id| with restricted_id | 180 // If the |url| is valid, returns true and fills in |id| with restricted_id |
126 // value. If the |url| is invalid, returns false and |id| is not set. | 181 // value. If the |url| is invalid, returns false and |id| is not set. |
127 bool GetRestrictedIDFromThumbnailUrl(int render_view_id, | 182 bool GetRestrictedIDFromThumbnailUrl(int render_view_id, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 std::string item_url; | 258 std::string item_url; |
204 if (rid != -1 && GetMostVisitedItemWithID(rid, &item)) | 259 if (rid != -1 && GetMostVisitedItemWithID(rid, &item)) |
205 item_url = item.url.spec(); | 260 item_url = item.url.spec(); |
206 | 261 |
207 *url = GURL(base::StringPrintf("chrome-search://favicon/%s%s", | 262 *url = GURL(base::StringPrintf("chrome-search://favicon/%s%s", |
208 favicon_params.c_str(), | 263 favicon_params.c_str(), |
209 item_url.c_str())); | 264 item_url.c_str())); |
210 return true; | 265 return true; |
211 } | 266 } |
212 | 267 |
268 bool SearchBox::GenerateLargeIconURLFromTransientURL(const GURL& transient_url, | |
269 GURL* url) const { | |
270 std::string favicon_params; | |
271 InstantRestrictedID rid = -1; | |
272 bool success = internal::GetRestrictedIDFromLargeIconUrl( | |
273 render_view()->GetRoutingID(), transient_url, &favicon_params, &rid); | |
274 if (!success) | |
275 return false; | |
276 | |
277 InstantMostVisitedItem item; | |
278 std::string item_url; | |
279 if (rid != -1 && GetMostVisitedItemWithID(rid, &item)) | |
280 item_url = item.url.spec(); | |
281 | |
282 *url = GURL(base::StringPrintf("chrome-search://large-icon/%s%s", | |
283 favicon_params.c_str(), | |
284 item_url.c_str())); | |
285 return true; | |
286 } | |
287 | |
288 bool SearchBox::GenerateFallbackIconURLFromTransientURL( | |
289 const GURL& transient_url, | |
290 GURL* url) const { | |
291 std::string favicon_params; | |
292 InstantRestrictedID rid = -1; | |
293 bool success = internal::GetRestrictedIDFromFallbackIconUrl( | |
294 render_view()->GetRoutingID(), transient_url, &favicon_params, &rid); | |
295 if (!success) | |
296 return false; | |
297 | |
298 InstantMostVisitedItem item; | |
299 std::string item_url; | |
300 if (rid != -1 && GetMostVisitedItemWithID(rid, &item)) | |
301 item_url = item.url.spec(); | |
302 | |
303 *url = GURL(base::StringPrintf("chrome-search://fallback-icon/%s%s", | |
304 favicon_params.c_str(), | |
305 item_url.c_str())); | |
306 return true; | |
beaudoin
2015/03/19 02:17:35
Same here, I'd be fine with an internal::GenerateU
huangs
2015/03/19 02:23:30
Same as above.
| |
307 } | |
308 | |
213 bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url, | 309 bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url, |
214 GURL* url) const { | 310 GURL* url) const { |
215 InstantRestrictedID rid = 0; | 311 InstantRestrictedID rid = 0; |
216 if (!internal::GetRestrictedIDFromThumbnailUrl(render_view()->GetRoutingID(), | 312 if (!internal::GetRestrictedIDFromThumbnailUrl(render_view()->GetRoutingID(), |
217 transient_url, &rid)) { | 313 transient_url, &rid)) { |
218 return false; | 314 return false; |
219 } | 315 } |
220 | 316 |
221 GURL most_visited_item_url(GetURLForMostVisitedItem(rid)); | 317 GURL most_visited_item_url(GetURLForMostVisitedItem(rid)); |
222 if (most_visited_item_url.is_empty()) | 318 if (most_visited_item_url.is_empty()) |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 | 579 |
484 void SearchBox::Reset() { | 580 void SearchBox::Reset() { |
485 query_.clear(); | 581 query_.clear(); |
486 embedded_search_request_params_ = EmbeddedSearchRequestParams(); | 582 embedded_search_request_params_ = EmbeddedSearchRequestParams(); |
487 suggestion_ = InstantSuggestion(); | 583 suggestion_ = InstantSuggestion(); |
488 start_margin_ = 0; | 584 start_margin_ = 0; |
489 is_focused_ = false; | 585 is_focused_ = false; |
490 is_key_capture_enabled_ = false; | 586 is_key_capture_enabled_ = false; |
491 theme_info_ = ThemeBackgroundInfo(); | 587 theme_info_ = ThemeBackgroundInfo(); |
492 } | 588 } |
OLD | NEW |