Chromium Code Reviews| Index: chrome/renderer/searchbox/searchbox.cc |
| diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc |
| index 4aa93c34843229e4c3e01c57c83285162c96ddc3..439508cf451d0a55d2cda522630a7e51d0260310 100644 |
| --- a/chrome/renderer/searchbox/searchbox.cc |
| +++ b/chrome/renderer/searchbox/searchbox.cc |
| @@ -24,6 +24,32 @@ namespace { |
| // Size of the results cache. |
| const size_t kMaxInstantAutocompleteResultItemCacheSize = 100; |
| +// Parses |url| and fills in |id| with the InstantRestrictedID obtained from the |
| +// |url|. |render_view_id| is the ID of the associated RenderView. |
| +// |
| +// Valid |url| forms: |
| +// chrome-search://favicon/<view_id>/<restriced_id> or |
| +// chrome-search://thumb/<view_id>/<restricted_id> |
| +// |
| +// If the |url| is valid, returns true and fills in |id| with restricted_id |
| +// value. If the |url| is invalid, returns false and |id| is not set. |
| +bool GetInstantRestrictedIDFromURL(int render_view_id, |
| + const GURL& url, |
| + InstantRestrictedID* id) { |
| + // Strip leading slash. |
| + std::string path = url.path().substr(1); |
| + |
| + // Check that the path is of Most visited item ID form. |
| + std::vector<std::string> tokens; |
| + if (Tokenize(path, "/", &tokens) != 2) |
| + return false; |
| + |
| + int view_id = 0; |
| + if (!base::StringToInt(tokens[0], &view_id) || view_id != render_view_id) |
| + return false; |
| + return base::StringToInt(tokens[1], id); |
| +} |
| + |
| } // namespace |
| SearchBox::SearchBox(content::RenderView* render_view) |
| @@ -155,6 +181,36 @@ const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() { |
| return theme_info_; |
| } |
| +bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url, |
| + GURL* url) const { |
| + InstantRestrictedID rid = 0; |
| + if (!GetInstantRestrictedIDFromURL(render_view()->GetRoutingID(), |
| + transient_url, &rid)) |
|
palmer
2013/06/05 17:50:54
Nit: curly braces, here and on line 202
kmadhusu
2013/06/05 18:40:39
Done.
|
| + return false; |
| + |
| + GURL most_visited_item_url(GetURLForMostVisitedItem(rid)); |
| + if (most_visited_item_url.is_empty()) |
| + return false; |
| + *url = GURL(base::StringPrintf("chrome-search://thumb/%s", |
| + most_visited_item_url.spec().c_str())); |
| + return true; |
| +} |
| + |
| +bool SearchBox::GenerateFaviconURLFromTransientURL(const GURL& transient_url, |
| + GURL* url) const { |
| + InstantRestrictedID rid = 0; |
| + if (!GetInstantRestrictedIDFromURL(render_view()->GetRoutingID(), |
| + transient_url, &rid)) |
| + return false; |
| + |
| + GURL most_visited_item_url(GetURLForMostVisitedItem(rid)); |
| + if (most_visited_item_url.is_empty()) |
| + return false; |
| + *url = GURL(base::StringPrintf("chrome-search://favicon/%s", |
| + most_visited_item_url.spec().c_str())); |
| + return true; |
| +} |
| + |
| bool SearchBox::OnMessageReceived(const IPC::Message& message) { |
| bool handled = true; |
| IPC_BEGIN_MESSAGE_MAP(SearchBox, message) |
| @@ -405,9 +461,8 @@ void SearchBox::SetQuery(const string16& query, bool verbatim) { |
| } |
| void SearchBox::OnMostVisitedChanged( |
| - const std::vector<InstantMostVisitedItemIDPair>& items) { |
| - most_visited_items_cache_.AddItemsWithRestrictedID(items); |
| - |
| + const std::vector<InstantMostVisitedItem>& items) { |
| + most_visited_items_cache_.AddItems(items); |
| if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( |
| render_view()->GetWebView()->mainFrame()); |