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

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

Issue 15907006: Rip out browser-side RID caching for most visited items. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 7 years, 6 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_extension.h" 5 #include "chrome/renderer/searchbox/searchbox_extension.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 if (!frame) return; 84 if (!frame) return;
85 frame->executeScript(WebKit::WebScriptSource(script)); 85 frame->executeScript(WebKit::WebScriptSource(script));
86 } 86 }
87 87
88 v8::Handle<v8::String> GenerateThumbnailURL(uint64 most_visited_item_id) { 88 v8::Handle<v8::String> GenerateThumbnailURL(uint64 most_visited_item_id) {
89 return UTF8ToV8String( 89 return UTF8ToV8String(
90 base::StringPrintf("chrome-search://thumb/%s", 90 base::StringPrintf("chrome-search://thumb/%s",
91 base::Uint64ToString(most_visited_item_id).c_str())); 91 base::Uint64ToString(most_visited_item_id).c_str()));
92 } 92 }
93 93
94 v8::Handle<v8::String> GenerateFaviconURL(uint64 most_visited_item_id) { 94 v8::Handle<v8::String> GenerateThumbnailURL(const GURL& url) {
Jered 2013/05/31 17:34:33 Instead of overloading based on types, give these
kmadhusu 2013/06/04 02:36:01 Done. As per the next comment, I moved GenerateThu
95 return UTF8ToV8String( 95 return UTF8ToV8String(
96 base::StringPrintf("chrome-search://favicon/%s", 96 base::StringPrintf("chrome-search://thumb/%s", url.spec().c_str()));
97 base::Uint64ToString(most_visited_item_id).c_str())); 97 }
98
99 v8::Handle<v8::String> GenerateFaviconURL(const GURL& url) {
100 return UTF8ToV8String(
101 base::StringPrintf("chrome-search://favicon/%s", url.spec().c_str()));
98 } 102 }
99 103
100 // If |url| starts with |prefix|, removes |prefix|. 104 // If |url| starts with |prefix|, removes |prefix|.
101 void StripPrefix(string16* url, const string16& prefix) { 105 void StripPrefix(string16* url, const string16& prefix) {
102 if (StartsWith(*url, prefix, true)) 106 if (StartsWith(*url, prefix, true))
103 url->erase(0, prefix.length()); 107 url->erase(0, prefix.length());
104 } 108 }
105 109
106 // Removes leading "http://" or "http://www." from |url| unless |user_input| 110 // Removes leading "http://" or "http://www." from |url| unless |user_input|
107 // starts with those prefixes. 111 // starts with those prefixes.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 obj->Set(v8::String::New("rid"), v8::Uint32::New(restricted_id)); 164 obj->Set(v8::String::New("rid"), v8::Uint32::New(restricted_id));
161 165
162 v8::Handle<v8::Object> ranking_data = v8::Object::New(); 166 v8::Handle<v8::Object> ranking_data = v8::Object::New();
163 ranking_data->Set(v8::String::New("relevance"), 167 ranking_data->Set(v8::String::New("relevance"),
164 v8::Int32::New(result.relevance)); 168 v8::Int32::New(result.relevance));
165 obj->Set(v8::String::New("rankingData"), ranking_data); 169 obj->Set(v8::String::New("rankingData"), ranking_data);
166 return obj; 170 return obj;
167 } 171 }
168 172
169 // Populates a Javascript MostVisitedItem object from |mv_item|. 173 // Populates a Javascript MostVisitedItem object from |mv_item|.
174 //
175 // Set |privileged_mode| to true to set the most visited item url in thumbnail
Jered 2013/05/31 17:34:33 Instead of doing this, how about always specifying
kmadhusu 2013/06/04 02:36:01 Done.
176 // URL.
177 //
170 // NOTE: Includes "url", "title" and "domain" which are private data, so should 178 // NOTE: Includes "url", "title" and "domain" which are private data, so should
171 // not be returned to the Instant page. These should be erased before returning 179 // not be returned to the Instant page. These should be erased before returning
172 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js. 180 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js.
173 v8::Handle<v8::Object> GenerateMostVisitedItem( 181 v8::Handle<v8::Object> GenerateMostVisitedItem(
174 InstantRestrictedID restricted_id, 182 InstantRestrictedID restricted_id,
175 const InstantMostVisitedItem &mv_item) { 183 const InstantMostVisitedItem &mv_item,
184 bool privileged_mode) {
176 // We set the "dir" attribute of the title, so that in RTL locales, a LTR 185 // We set the "dir" attribute of the title, so that in RTL locales, a LTR
177 // title is rendered left-to-right and truncated from the right. For 186 // title is rendered left-to-right and truncated from the right. For
178 // example, the title of http://msdn.microsoft.com/en-us/default.aspx is 187 // example, the title of http://msdn.microsoft.com/en-us/default.aspx is
179 // "MSDN: Microsoft developer network". In RTL locales, in the New Tab 188 // "MSDN: Microsoft developer network". In RTL locales, in the New Tab
180 // page, if the "dir" of this title is not specified, it takes Chrome UI's 189 // page, if the "dir" of this title is not specified, it takes Chrome UI's
181 // directionality. So the title will be truncated as "soft developer 190 // directionality. So the title will be truncated as "soft developer
182 // network". Setting the "dir" attribute as "ltr" renders the truncated 191 // network". Setting the "dir" attribute as "ltr" renders the truncated
183 // title as "MSDN: Microsoft D...". As another example, the title of 192 // title as "MSDN: Microsoft D...". As another example, the title of
184 // http://yahoo.com is "Yahoo!". In RTL locales, in the New Tab page, the 193 // http://yahoo.com is "Yahoo!". In RTL locales, in the New Tab page, the
185 // title will be rendered as "!Yahoo" if its "dir" attribute is not set to 194 // title will be rendered as "!Yahoo" if its "dir" attribute is not set to
186 // "ltr". 195 // "ltr".
187 std::string direction; 196 std::string direction;
188 if (base::i18n::StringContainsStrongRTLChars(mv_item.title)) 197 if (base::i18n::StringContainsStrongRTLChars(mv_item.title))
189 direction = kRTLHtmlTextDirection; 198 direction = kRTLHtmlTextDirection;
190 else 199 else
191 direction = kLTRHtmlTextDirection; 200 direction = kLTRHtmlTextDirection;
192 201
193 string16 title = mv_item.title; 202 string16 title = mv_item.title;
194 if (title.empty()) 203 if (title.empty())
195 title = UTF8ToUTF16(mv_item.url.spec()); 204 title = UTF8ToUTF16(mv_item.url.spec());
196 205
197 v8::Handle<v8::Object> obj = v8::Object::New(); 206 v8::Handle<v8::Object> obj = v8::Object::New();
198 obj->Set(v8::String::New("rid"), v8::Int32::New(restricted_id)); 207 obj->Set(v8::String::New("rid"), v8::Int32::New(restricted_id));
199 obj->Set(v8::String::New("thumbnailUrl"), 208 obj->Set(v8::String::New("thumbnailUrl"),
200 GenerateThumbnailURL(restricted_id)); 209 privileged_mode ? GenerateThumbnailURL(mv_item.url) :
201 obj->Set(v8::String::New("faviconUrl"), 210 GenerateThumbnailURL(restricted_id));
202 GenerateFaviconURL(restricted_id)); 211 obj->Set(v8::String::New("faviconUrl"), GenerateFaviconURL(mv_item.url));
Jered 2013/05/31 17:34:33 This is priveleged.
kmadhusu 2013/06/04 02:36:01 Fixed.
203 obj->Set(v8::String::New("title"), UTF16ToV8String(title)); 212 obj->Set(v8::String::New("title"), UTF16ToV8String(title));
204 obj->Set(v8::String::New("domain"), UTF8ToV8String(mv_item.url.host())); 213 obj->Set(v8::String::New("domain"), UTF8ToV8String(mv_item.url.host()));
205 obj->Set(v8::String::New("direction"), UTF8ToV8String(direction)); 214 obj->Set(v8::String::New("direction"), UTF8ToV8String(direction));
206 obj->Set(v8::String::New("url"), UTF8ToV8String(mv_item.url.spec())); 215 obj->Set(v8::String::New("url"), UTF8ToV8String(mv_item.url.spec()));
207 return obj; 216 return obj;
208 } 217 }
209 218
210 // Returns the render view for the current JS context if it matches |origin|, 219 // Returns the render view for the current JS context if it matches |origin|,
211 // otherwise returns NULL. Used to restrict methods that access suggestions and 220 // otherwise returns NULL. Used to restrict methods that access suggestions and
212 // most visited data to pages with origin chrome-search://most-visited and 221 // most visited data to pages with origin chrome-search://most-visited and
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 return v8::Undefined(); 1257 return v8::Undefined();
1249 DVLOG(1) << render_view << " GetMostVisitedItems"; 1258 DVLOG(1) << render_view << " GetMostVisitedItems";
1250 1259
1251 const SearchBox* search_box = SearchBox::Get(render_view); 1260 const SearchBox* search_box = SearchBox::Get(render_view);
1252 1261
1253 std::vector<InstantMostVisitedItemIDPair> instant_mv_items; 1262 std::vector<InstantMostVisitedItemIDPair> instant_mv_items;
1254 search_box->GetMostVisitedItems(&instant_mv_items); 1263 search_box->GetMostVisitedItems(&instant_mv_items);
1255 v8::Handle<v8::Array> v8_mv_items = v8::Array::New(instant_mv_items.size()); 1264 v8::Handle<v8::Array> v8_mv_items = v8::Array::New(instant_mv_items.size());
1256 for (size_t i = 0; i < instant_mv_items.size(); ++i) { 1265 for (size_t i = 0; i < instant_mv_items.size(); ++i) {
1257 v8_mv_items->Set(i, GenerateMostVisitedItem(instant_mv_items[i].first, 1266 v8_mv_items->Set(i, GenerateMostVisitedItem(instant_mv_items[i].first,
1258 instant_mv_items[i].second)); 1267 instant_mv_items[i].second,
1268 false));
1259 } 1269 }
1260 return v8_mv_items; 1270 return v8_mv_items;
1261 } 1271 }
1262 1272
1263 // static 1273 // static
1264 v8::Handle<v8::Value> SearchBoxExtensionWrapper::DeleteMostVisitedItem( 1274 v8::Handle<v8::Value> SearchBoxExtensionWrapper::DeleteMostVisitedItem(
1265 const v8::Arguments& args) { 1275 const v8::Arguments& args) {
1266 content::RenderView* render_view = GetRenderView(); 1276 content::RenderView* render_view = GetRenderView();
1267 if (!render_view || !args.Length()) return v8::Undefined(); 1277 if (!render_view || !args.Length()) return v8::Undefined();
1268 1278
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 if (args.Length() < 1 || !args[0]->IsNumber()) 1406 if (args.Length() < 1 || !args[0]->IsNumber())
1397 return v8::Undefined(); 1407 return v8::Undefined();
1398 1408
1399 DVLOG(1) << render_view << " GetMostVisitedItem"; 1409 DVLOG(1) << render_view << " GetMostVisitedItem";
1400 InstantRestrictedID restricted_id = args[0]->IntegerValue(); 1410 InstantRestrictedID restricted_id = args[0]->IntegerValue();
1401 InstantMostVisitedItem mv_item; 1411 InstantMostVisitedItem mv_item;
1402 if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID( 1412 if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID(
1403 restricted_id, &mv_item)) { 1413 restricted_id, &mv_item)) {
1404 return v8::Undefined(); 1414 return v8::Undefined();
1405 } 1415 }
1406 return GenerateMostVisitedItem(restricted_id, mv_item); 1416 return GenerateMostVisitedItem(restricted_id, mv_item, true);
1407 } 1417 }
1408 1418
1409 // static 1419 // static
1410 v8::Handle<v8::Value> SearchBoxExtensionWrapper::IsFocused( 1420 v8::Handle<v8::Value> SearchBoxExtensionWrapper::IsFocused(
1411 const v8::Arguments& args) { 1421 const v8::Arguments& args) {
1412 content::RenderView* render_view = GetRenderView(); 1422 content::RenderView* render_view = GetRenderView();
1413 if (!render_view) return v8::Undefined(); 1423 if (!render_view) return v8::Undefined();
1414 1424
1415 bool is_focused = SearchBox::Get(render_view)->is_focused(); 1425 bool is_focused = SearchBox::Get(render_view)->is_focused();
1416 DVLOG(1) << render_view << " IsFocused: " << is_focused; 1426 DVLOG(1) << render_view << " IsFocused: " << is_focused;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 void SearchBoxExtension::DispatchBarsHidden(WebKit::WebFrame* frame) { 1496 void SearchBoxExtension::DispatchBarsHidden(WebKit::WebFrame* frame) {
1487 Dispatch(frame, kDispatchBarsHiddenEventScript); 1497 Dispatch(frame, kDispatchBarsHiddenEventScript);
1488 } 1498 }
1489 1499
1490 // static 1500 // static
1491 void SearchBoxExtension::DispatchFocusChange(WebKit::WebFrame* frame) { 1501 void SearchBoxExtension::DispatchFocusChange(WebKit::WebFrame* frame) {
1492 Dispatch(frame, kDispatchFocusChangedScript); 1502 Dispatch(frame, kDispatchFocusChangedScript);
1493 } 1503 }
1494 1504
1495 } // namespace extensions_v8 1505 } // namespace extensions_v8
OLDNEW
« chrome/browser/ui/webui/ntp/thumbnail_source.cc ('K') | « chrome/renderer/searchbox/searchbox.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698