Chromium Code Reviews| Index: chrome/renderer/searchbox/searchbox.cc |
| diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc |
| index 9adce8536714bf97658937ee385048a46db5c780..2013380b8aabb447b1629f44aecbdc33b4818f0d 100644 |
| --- a/chrome/renderer/searchbox/searchbox.cc |
| +++ b/chrome/renderer/searchbox/searchbox.cc |
| @@ -10,7 +10,9 @@ |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "chrome/common/favicon/fallback_icon_url_parser.h" |
| #include "chrome/common/favicon/favicon_url_parser.h" |
| +#include "chrome/common/favicon/large_icon_url_parser.h" |
| #include "chrome/common/omnibox_focus_state.h" |
| #include "chrome/common/render_messages.h" |
| #include "chrome/common/url_constants.h" |
| @@ -115,6 +117,57 @@ bool GetRestrictedIDFromFaviconUrl(int render_view_id, |
| return true; |
| } |
| +bool GetRestrictedIDFromLargeIconUrl(int render_view_id, |
|
James Hawkins
2015/03/17 21:46:41
nit: Document methods and params.
huangs
2015/03/18 21:43:10
Done.
|
| + const GURL& url, |
| + std::string* favicon_params, |
| + InstantRestrictedID* rid) { |
| + // Strip leading slash. |
| + std::string raw_path = url.path(); |
| + DCHECK_GT(raw_path.length(), (size_t) 0); |
| + DCHECK_EQ(raw_path[0], '/'); |
| + raw_path = raw_path.substr(1); |
| + |
| + chrome::LargeIconUrlParser parser; |
| + if (!parser.Parse(raw_path)) |
| + return false; |
| + |
| + *favicon_params = raw_path.substr(0, parser.path_index()); |
| + |
| + std::string id_part = raw_path.substr(parser.path_index()); |
| + InstantRestrictedID id; |
| + if (!GetInstantRestrictedIDFromPath(render_view_id, id_part, &id)) |
| + return true; |
| + |
| + *rid = id; |
| + return true; |
| +} |
| + |
| +bool GetRestrictedIDFromFallbackIconUrl(int render_view_id, |
| + const GURL& url, |
| + std::string* favicon_params, |
| + InstantRestrictedID* rid) { |
| + // Strip leading slash. |
| + std::string raw_path = url.path(); |
| + DCHECK_GT(raw_path.length(), (size_t) 0); |
| + DCHECK_EQ(raw_path[0], '/'); |
| + raw_path = raw_path.substr(1); |
| + |
| + chrome::ParsedFallbackIconPath parser; |
| + if (!parser.Parse(raw_path)) |
| + return false; |
| + |
| + *favicon_params = raw_path.substr(0, parser.path_index()); |
| + |
| + std::string id_part = raw_path.substr(parser.path_index()); |
| + InstantRestrictedID id; |
| + if (!GetInstantRestrictedIDFromPath(render_view_id, id_part, &id)) |
| + return true; |
| + |
| + *rid = id; |
| + return true; |
| +} |
| + |
| + |
| // Parses a thumbnail |url| and fills in |id| with the InstantRestrictedID |
| // obtained from the |url|. |render_view_id| is the ID of the associated |
| // RenderView. |
| @@ -210,6 +263,47 @@ bool SearchBox::GenerateFaviconURLFromTransientURL(const GURL& transient_url, |
| return true; |
| } |
| +bool SearchBox::GenerateLargeIconURLFromTransientURL(const GURL& transient_url, |
| + GURL* url) const { |
| + std::string favicon_params; |
| + InstantRestrictedID rid = -1; |
| + bool success = internal::GetRestrictedIDFromLargeIconUrl( |
| + render_view()->GetRoutingID(), transient_url, &favicon_params, &rid); |
| + if (!success) |
| + return false; |
| + |
| + InstantMostVisitedItem item; |
| + std::string item_url; |
| + if (rid != -1 && GetMostVisitedItemWithID(rid, &item)) |
| + item_url = item.url.spec(); |
| + |
| + *url = GURL(base::StringPrintf("chrome-search://large-icon/%s%s", |
| + favicon_params.c_str(), |
| + item_url.c_str())); |
| + return true; |
| +} |
| + |
| +bool SearchBox::GenerateFallbackIconURLFromTransientURL( |
| + const GURL& transient_url, |
| + GURL* url) const { |
| + std::string favicon_params; |
| + InstantRestrictedID rid = -1; |
| + bool success = internal::GetRestrictedIDFromFallbackIconUrl( |
| + render_view()->GetRoutingID(), transient_url, &favicon_params, &rid); |
| + if (!success) |
| + return false; |
| + |
| + InstantMostVisitedItem item; |
| + std::string item_url; |
| + if (rid != -1 && GetMostVisitedItemWithID(rid, &item)) |
| + item_url = item.url.spec(); |
| + |
| + *url = GURL(base::StringPrintf("chrome-search://fallback-icon/%s%s", |
| + favicon_params.c_str(), |
| + item_url.c_str())); |
| + return true; |
| +} |
| + |
| bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url, |
| GURL* url) const { |
| InstantRestrictedID rid = 0; |