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

Side by Side Diff: chrome/renderer/searchbox/searchbox.cc

Issue 1010783002: [Icons NTP] Working prototype to fetch, store, and display big icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 unified diff | Download patch
OLDNEW
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/big_icon_url_parser.h"
14 #include "chrome/common/favicon/fallback_icon_url_parser.h"
13 #include "chrome/common/favicon/favicon_url_parser.h" 15 #include "chrome/common/favicon/favicon_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"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool GetRestrictedIDFromBigIconUrl(int render_view_id,
121 const GURL& url,
122 std::string* favicon_params,
123 InstantRestrictedID* rid) {
124 // Strip leading slash.
125 std::string raw_path = url.path();
126 DCHECK_GT(raw_path.length(), (size_t) 0);
127 DCHECK_EQ(raw_path[0], '/');
128 raw_path = raw_path.substr(1);
129
130 chrome::BigIconUrlParser parser;
131 if (!parser.Parse(raw_path))
132 return false;
133
134 *favicon_params = raw_path.substr(0, parser.path_index());
135
136 std::string id_part = raw_path.substr(parser.path_index());
137 InstantRestrictedID id;
138 if (!GetInstantRestrictedIDFromPath(render_view_id, id_part, &id))
139 return true;
140
141 *rid = id;
142 return true;
143 }
144
145 bool GetRestrictedIDFromFallbackIconUrl(int render_view_id,
146 const GURL& url,
147 std::string* favicon_params,
148 InstantRestrictedID* rid) {
149 // Strip leading slash.
150 std::string raw_path = url.path();
151 DCHECK_GT(raw_path.length(), (size_t) 0);
152 DCHECK_EQ(raw_path[0], '/');
153 raw_path = raw_path.substr(1);
154
155 chrome::ParsedFallbackIconPath parser;
156 if (!parser.Parse(raw_path))
157 return false;
158
159 *favicon_params = raw_path.substr(0, parser.path_index());
160
161 std::string id_part = raw_path.substr(parser.path_index());
162 InstantRestrictedID id;
163 if (!GetInstantRestrictedIDFromPath(render_view_id, id_part, &id))
164 return true;
165
166 *rid = id;
167 return true;
168 }
169
170
118 // Parses a thumbnail |url| and fills in |id| with the InstantRestrictedID 171 // 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 172 // obtained from the |url|. |render_view_id| is the ID of the associated
120 // RenderView. 173 // RenderView.
121 // 174 //
122 // Valid |url| forms: 175 // Valid |url| forms:
123 // chrome-search://thumb/<view_id>/<restricted_id> 176 // chrome-search://thumb/<view_id>/<restricted_id>
124 // 177 //
125 // If the |url| is valid, returns true and fills in |id| with restricted_id 178 // 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. 179 // value. If the |url| is invalid, returns false and |id| is not set.
127 bool GetRestrictedIDFromThumbnailUrl(int render_view_id, 180 bool GetRestrictedIDFromThumbnailUrl(int render_view_id,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 std::string item_url; 256 std::string item_url;
204 if (rid != -1 && GetMostVisitedItemWithID(rid, &item)) 257 if (rid != -1 && GetMostVisitedItemWithID(rid, &item))
205 item_url = item.url.spec(); 258 item_url = item.url.spec();
206 259
207 *url = GURL(base::StringPrintf("chrome-search://favicon/%s%s", 260 *url = GURL(base::StringPrintf("chrome-search://favicon/%s%s",
208 favicon_params.c_str(), 261 favicon_params.c_str(),
209 item_url.c_str())); 262 item_url.c_str()));
210 return true; 263 return true;
211 } 264 }
212 265
266 bool SearchBox::GenerateBigIconURLFromTransientURL(const GURL& transient_url,
267 GURL* url) const {
268 std::string favicon_params;
269 InstantRestrictedID rid = -1;
270 bool success = internal::GetRestrictedIDFromBigIconUrl(
271 render_view()->GetRoutingID(), transient_url, &favicon_params, &rid);
272 if (!success)
273 return false;
274
275 InstantMostVisitedItem item;
276 std::string item_url;
277 if (rid != -1 && GetMostVisitedItemWithID(rid, &item))
278 item_url = item.url.spec();
279
280 *url = GURL(base::StringPrintf("chrome-search://big-icon/%s%s",
281 favicon_params.c_str(),
282 item_url.c_str()));
283 return true;
284 }
285
286 bool SearchBox::GenerateFallbackIconURLFromTransientURL(
287 const GURL& transient_url,
288 GURL* url) const {
289 std::string favicon_params;
290 InstantRestrictedID rid = -1;
291 bool success = internal::GetRestrictedIDFromFallbackIconUrl(
292 render_view()->GetRoutingID(), transient_url, &favicon_params, &rid);
293 if (!success)
294 return false;
295
296 InstantMostVisitedItem item;
297 std::string item_url;
298 if (rid != -1 && GetMostVisitedItemWithID(rid, &item))
299 item_url = item.url.spec();
300
301 *url = GURL(base::StringPrintf("chrome-search://fallback-icon/%s%s",
302 favicon_params.c_str(),
303 item_url.c_str()));
304 return true;
305 }
306
213 bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url, 307 bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url,
214 GURL* url) const { 308 GURL* url) const {
215 InstantRestrictedID rid = 0; 309 InstantRestrictedID rid = 0;
216 if (!internal::GetRestrictedIDFromThumbnailUrl(render_view()->GetRoutingID(), 310 if (!internal::GetRestrictedIDFromThumbnailUrl(render_view()->GetRoutingID(),
217 transient_url, &rid)) { 311 transient_url, &rid)) {
218 return false; 312 return false;
219 } 313 }
220 314
221 GURL most_visited_item_url(GetURLForMostVisitedItem(rid)); 315 GURL most_visited_item_url(GetURLForMostVisitedItem(rid));
222 if (most_visited_item_url.is_empty()) 316 if (most_visited_item_url.is_empty())
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 577
484 void SearchBox::Reset() { 578 void SearchBox::Reset() {
485 query_.clear(); 579 query_.clear();
486 embedded_search_request_params_ = EmbeddedSearchRequestParams(); 580 embedded_search_request_params_ = EmbeddedSearchRequestParams();
487 suggestion_ = InstantSuggestion(); 581 suggestion_ = InstantSuggestion();
488 start_margin_ = 0; 582 start_margin_ = 0;
489 is_focused_ = false; 583 is_focused_ = false;
490 is_key_capture_enabled_ = false; 584 is_key_capture_enabled_ = false;
491 theme_info_ = ThemeBackgroundInfo(); 585 theme_info_ = ThemeBackgroundInfo();
492 } 586 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698