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

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

Issue 18344010: Completing high dpi support for Instant Extended. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase Created 7 years, 5 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 | Annotate | Revision Log
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/favicon_types.h"
14 #include "chrome/common/favicon/favicon_url_parser.h"
13 #include "chrome/common/omnibox_focus_state.h" 15 #include "chrome/common/omnibox_focus_state.h"
14 #include "chrome/common/render_messages.h" 16 #include "chrome/common/render_messages.h"
15 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
16 #include "chrome/renderer/searchbox/searchbox_extension.h" 18 #include "chrome/renderer/searchbox/searchbox_extension.h"
17 #include "content/public/renderer/render_view.h" 19 #include "content/public/renderer/render_view.h"
18 #include "grit/renderer_resources.h" 20 #include "grit/renderer_resources.h"
19 #include "net/base/escape.h" 21 #include "net/base/escape.h"
20 #include "third_party/WebKit/public/web/WebDocument.h" 22 #include "third_party/WebKit/public/web/WebDocument.h"
21 #include "third_party/WebKit/public/web/WebFrame.h" 23 #include "third_party/WebKit/public/web/WebFrame.h"
22 #include "third_party/WebKit/public/web/WebView.h" 24 #include "third_party/WebKit/public/web/WebView.h"
(...skipping 19 matching lines...) Expand all
42 return false; 44 return false;
43 } 45 }
44 } 46 }
45 return true; 47 return true;
46 } 48 }
47 49
48 } // namespace 50 } // namespace
49 51
50 namespace internal { // for testing 52 namespace internal { // for testing
51 53
52 // Parses |url| and fills in |id| with the InstantRestrictedID obtained from the 54 bool GetInstantRestrictedIDFromPath(int render_view_id,
samarth 2013/07/24 00:11:05 Please add a comment with that this does.
pedro (no code reviews) 2013/07/24 01:10:55 Done.
53 // |url|. |render_view_id| is the ID of the associated RenderView. 55 const std::string& path,
54 // 56 InstantRestrictedID* id) {
55 // Valid |url| forms:
56 // chrome-search://favicon/<view_id>/<restricted_id>
57 // chrome-search://thumb/<view_id>/<restricted_id>
58 //
59 // If the |url| is valid, returns true and fills in |id| with restricted_id
60 // value. If the |url| is invalid, returns false and |id| is not set.
61 bool GetInstantRestrictedIDFromURL(int render_view_id,
62 const GURL& url,
63 InstantRestrictedID* id) {
64 // Strip leading path.
65 std::string path = url.path().substr(1);
66
67 // Check that the path is of Most visited item ID form. 57 // Check that the path is of Most visited item ID form.
68 std::vector<std::string> tokens; 58 std::vector<std::string> tokens;
69 if (Tokenize(path, "/", &tokens) != 2) 59 if (Tokenize(path, "/", &tokens) != 2)
70 return false; 60 return false;
71 61
72 int view_id = 0; 62 int view_id = 0;
73 if (!base::StringToInt(tokens[0], &view_id) || view_id != render_view_id) 63 if (!base::StringToInt(tokens[0], &view_id) || view_id != render_view_id)
74 return false; 64 return false;
75 return base::StringToInt(tokens[1], id); 65 return base::StringToInt(tokens[1], id);
76 } 66 }
77 67
68 bool GetRestrictedIDFromFaviconUrl(int render_view_id,
69 const GURL& url,
70 std::string* favicon_params,
71 InstantRestrictedID* rid) {
72 // Strip leading slash.
73 std::string raw_path = url.path();
74 DCHECK_GT(raw_path.length(), (size_t) 0);
75 DCHECK_EQ(raw_path[0], '/');
76 raw_path = raw_path.substr(1);
77
78 chrome::ParsedFaviconPath parsed;
79 if (!chrome::ParseFaviconPath(raw_path, chrome::FAVICON, &parsed))
80 return false;
81
82 // The part of the URL which details the favicon parameters should be returned
83 // so the favicon URL can be reconstructed, by replacing the restricted_id
84 // with the actual URL from which the favicon is being requested.
85 *favicon_params = raw_path.substr(0, parsed.path_index);
86
87 // The part of the favicon URL which is supposed to contain the URL from
88 // which the favicon is being requested (i.e., the page's URL) actually
89 // contains a pair in the format "<view_id>/<restricted_id>". If the page's
90 // URL is not in the expected format then the execution must be stopped,
91 // returning |true|, indicating that the favicon URL should be translated
92 // without the page's URL part, to prevent search providers from spoofing
93 // the user's browsing history. For example, the following favicon URL
94 // "chrome-search://favicon/http://www.secretsite.com" it is not in the
95 // expected format "chrome-search://favicon/<view_id>/<restricted_id>" so
96 // the pages's URL part ("http://www.secretsite.com") should be removed
97 // entirely from the translated URL otherwise the search engine would know
98 // if the user has visited that page (by verifying whether the favicon URL
99 // returns an image for a particular page's URL); the translated URL in this
100 // case would be "chrome-search://favicon/" which would simply return the
101 // default favicon.
102 std::string id_part = raw_path.substr(parsed.path_index);
103 InstantRestrictedID id;
104 if (!GetInstantRestrictedIDFromPath(render_view_id, id_part, &id))
105 return true;
106
107 *rid = id;
108 return true;
109 }
110
111 // Parses a thumbnail |url| and fills in |id| with the InstantRestrictedID
112 // obtained from the |url|. |render_view_id| is the ID of the associated
113 // RenderView.
114 //
115 // Valid |url| forms:
116 // chrome-search://thumb/<view_id>/<restricted_id>
117 //
118 // If the |url| is valid, returns true and fills in |id| with restricted_id
119 // value. If the |url| is invalid, returns false and |id| is not set.
120 bool GetRestrictedIDFromThumbnailUrl(int render_view_id,
121 const GURL& url,
122 InstantRestrictedID* id) {
123 // Strip leading slash.
124 std::string path = url.path();
125 DCHECK_GT(path.length(), (size_t) 0);
126 DCHECK_EQ(path[0], '/');
127 path = path.substr(1);
128
129 return internal::GetInstantRestrictedIDFromPath(render_view_id, path, id);
samarth 2013/07/24 00:11:05 You're already in namespace internal so the qualif
pedro (no code reviews) 2013/07/24 01:10:55 Done.
130 }
131
78 } // namespace internal 132 } // namespace internal
79 133
80 SearchBox::SearchBox(content::RenderView* render_view) 134 SearchBox::SearchBox(content::RenderView* render_view)
81 : content::RenderViewObserver(render_view), 135 : content::RenderViewObserver(render_view),
82 content::RenderViewObserverTracker<SearchBox>(render_view), 136 content::RenderViewObserverTracker<SearchBox>(render_view),
83 app_launcher_enabled_(false), 137 app_launcher_enabled_(false),
84 is_focused_(false), 138 is_focused_(false),
85 is_input_in_progress_(false), 139 is_input_in_progress_(false),
86 is_key_capture_enabled_(false), 140 is_key_capture_enabled_(false),
87 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize), 141 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize),
(...skipping 14 matching lines...) Expand all
102 156
103 void SearchBox::DeleteMostVisitedItem( 157 void SearchBox::DeleteMostVisitedItem(
104 InstantRestrictedID most_visited_item_id) { 158 InstantRestrictedID most_visited_item_id) {
105 render_view()->Send(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem( 159 render_view()->Send(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
106 render_view()->GetRoutingID(), render_view()->GetPageId(), 160 render_view()->GetRoutingID(), render_view()->GetPageId(),
107 GetURLForMostVisitedItem(most_visited_item_id))); 161 GetURLForMostVisitedItem(most_visited_item_id)));
108 } 162 }
109 163
110 bool SearchBox::GenerateFaviconURLFromTransientURL(const GURL& transient_url, 164 bool SearchBox::GenerateFaviconURLFromTransientURL(const GURL& transient_url,
111 GURL* url) const { 165 GURL* url) const {
112 InstantRestrictedID rid = 0; 166 std::string favicon_params;
113 if (!internal::GetInstantRestrictedIDFromURL(render_view()->GetRoutingID(), 167 InstantRestrictedID rid = -1;
114 transient_url, &rid)) { 168 bool success = internal::GetRestrictedIDFromFaviconUrl(
169 render_view()->GetRoutingID(), transient_url, &favicon_params, &rid);
170 if (!success)
115 return false; 171 return false;
116 }
117 172
118 GURL most_visited_item_url(GetURLForMostVisitedItem(rid)); 173 InstantMostVisitedItem item;
119 if (most_visited_item_url.is_empty()) 174 std::string item_url = "";
samarth 2013/07/24 00:11:05 = "" is unnecessary.
pedro (no code reviews) 2013/07/24 01:10:55 Done.
120 return false; 175 if (rid != -1 && GetMostVisitedItemWithID(rid, &item))
121 *url = GURL(base::StringPrintf("chrome-search://favicon/%s", 176 item_url = item.url.spec();
122 most_visited_item_url.spec().c_str())); 177
178 *url = GURL(base::StringPrintf("chrome-search://favicon/%s%s",
179 favicon_params.c_str(),
180 item_url.c_str()));
123 return true; 181 return true;
124 } 182 }
125 183
126 bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url, 184 bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url,
127 GURL* url) const { 185 GURL* url) const {
128 InstantRestrictedID rid = 0; 186 InstantRestrictedID rid = 0;
129 if (!internal::GetInstantRestrictedIDFromURL(render_view()->GetRoutingID(), 187 if (!internal::GetRestrictedIDFromThumbnailUrl(render_view()->GetRoutingID(),
130 transient_url, &rid)) { 188 transient_url, &rid)) {
131 return false; 189 return false;
132 } 190 }
133 191
134 GURL most_visited_item_url(GetURLForMostVisitedItem(rid)); 192 GURL most_visited_item_url(GetURLForMostVisitedItem(rid));
135 if (most_visited_item_url.is_empty()) 193 if (most_visited_item_url.is_empty())
136 return false; 194 return false;
137 *url = GURL(base::StringPrintf("chrome-search://thumb/%s", 195 *url = GURL(base::StringPrintf("chrome-search://thumb/%s",
138 most_visited_item_url.spec().c_str())); 196 most_visited_item_url.spec().c_str()));
139 return true; 197 return true;
140 } 198 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 407 }
350 408
351 void SearchBox::Reset() { 409 void SearchBox::Reset() {
352 query_.clear(); 410 query_.clear();
353 start_margin_ = 0; 411 start_margin_ = 0;
354 width_ = 0; 412 width_ = 0;
355 is_focused_ = false; 413 is_focused_ = false;
356 is_key_capture_enabled_ = false; 414 is_key_capture_enabled_ = false;
357 theme_info_ = ThemeBackgroundInfo(); 415 theme_info_ = ThemeBackgroundInfo();
358 } 416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698