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

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: Use view_id/rid instead of view_id:rid in URL. 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 s->WriteUtf8(WriteInto(&result, len + 1)); 78 s->WriteUtf8(WriteInto(&result, len + 1));
79 } 79 }
80 return result; 80 return result;
81 } 81 }
82 82
83 void Dispatch(WebKit::WebFrame* frame, const WebKit::WebString& script) { 83 void Dispatch(WebKit::WebFrame* frame, const WebKit::WebString& script) {
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(
89 return UTF8ToV8String( 89 int render_view_id,
90 base::StringPrintf("chrome-search://thumb/%s", 90 InstantRestrictedID most_visited_item_id) {
91 base::Uint64ToString(most_visited_item_id).c_str())); 91 return UTF8ToV8String(base::StringPrintf("chrome-search://thumb/%d/%d",
92 render_view_id,
93 most_visited_item_id));
92 } 94 }
93 95
94 v8::Handle<v8::String> GenerateFaviconURL(uint64 most_visited_item_id) { 96 v8::Handle<v8::String> GenerateFaviconURL(
95 return UTF8ToV8String( 97 int render_view_id,
96 base::StringPrintf("chrome-search://favicon/%s", 98 InstantRestrictedID most_visited_item_id) {
97 base::Uint64ToString(most_visited_item_id).c_str())); 99 return UTF8ToV8String(base::StringPrintf("chrome-search://favicon/%d/%d",
100 render_view_id,
101 most_visited_item_id));
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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|.
170 // NOTE: Includes "url", "title" and "domain" which are private data, so should 174 // 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 175 // not be returned to the Instant page. These should be erased before returning
172 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js. 176 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js.
173 v8::Handle<v8::Object> GenerateMostVisitedItem( 177 v8::Handle<v8::Object> GenerateMostVisitedItem(
174 InstantRestrictedID restricted_id, 178 InstantRestrictedID restricted_id,
Jered 2013/06/04 23:19:20 Can we also order these as render_view_id, restric
kmadhusu 2013/06/05 00:48:30 Done.
179 int render_view_id,
175 const InstantMostVisitedItem &mv_item) { 180 const InstantMostVisitedItem &mv_item) {
176 // We set the "dir" attribute of the title, so that in RTL locales, a LTR 181 // 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 182 // 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 183 // 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 184 // "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 185 // 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 186 // directionality. So the title will be truncated as "soft developer
182 // network". Setting the "dir" attribute as "ltr" renders the truncated 187 // network". Setting the "dir" attribute as "ltr" renders the truncated
183 // title as "MSDN: Microsoft D...". As another example, the title of 188 // 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 189 // 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 190 // title will be rendered as "!Yahoo" if its "dir" attribute is not set to
186 // "ltr". 191 // "ltr".
187 std::string direction; 192 std::string direction;
188 if (base::i18n::StringContainsStrongRTLChars(mv_item.title)) 193 if (base::i18n::StringContainsStrongRTLChars(mv_item.title))
189 direction = kRTLHtmlTextDirection; 194 direction = kRTLHtmlTextDirection;
190 else 195 else
191 direction = kLTRHtmlTextDirection; 196 direction = kLTRHtmlTextDirection;
192 197
193 string16 title = mv_item.title; 198 string16 title = mv_item.title;
194 if (title.empty()) 199 if (title.empty())
195 title = UTF8ToUTF16(mv_item.url.spec()); 200 title = UTF8ToUTF16(mv_item.url.spec());
196 201
197 v8::Handle<v8::Object> obj = v8::Object::New(); 202 v8::Handle<v8::Object> obj = v8::Object::New();
198 obj->Set(v8::String::New("rid"), v8::Int32::New(restricted_id)); 203 obj->Set(v8::String::New("rid"), v8::Int32::New(restricted_id));
199 obj->Set(v8::String::New("thumbnailUrl"), 204 obj->Set(v8::String::New("thumbnailUrl"),
200 GenerateThumbnailURL(restricted_id)); 205 GenerateThumbnailURL(render_view_id, restricted_id));
201 obj->Set(v8::String::New("faviconUrl"), 206 obj->Set(v8::String::New("faviconUrl"),
202 GenerateFaviconURL(restricted_id)); 207 GenerateFaviconURL(render_view_id, restricted_id));
203 obj->Set(v8::String::New("title"), UTF16ToV8String(title)); 208 obj->Set(v8::String::New("title"), UTF16ToV8String(title));
204 obj->Set(v8::String::New("domain"), UTF8ToV8String(mv_item.url.host())); 209 obj->Set(v8::String::New("domain"), UTF8ToV8String(mv_item.url.host()));
205 obj->Set(v8::String::New("direction"), UTF8ToV8String(direction)); 210 obj->Set(v8::String::New("direction"), UTF8ToV8String(direction));
206 obj->Set(v8::String::New("url"), UTF8ToV8String(mv_item.url.spec())); 211 obj->Set(v8::String::New("url"), UTF8ToV8String(mv_item.url.spec()));
207 return obj; 212 return obj;
208 } 213 }
209 214
210 // Returns the render view for the current JS context if it matches |origin|, 215 // 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 216 // otherwise returns NULL. Used to restrict methods that access suggestions and
212 // most visited data to pages with origin chrome-search://most-visited and 217 // most visited data to pages with origin chrome-search://most-visited and
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 return v8::Undefined(); 1245 return v8::Undefined();
1241 DVLOG(1) << render_view << " GetMostVisitedItems"; 1246 DVLOG(1) << render_view << " GetMostVisitedItems";
1242 1247
1243 const SearchBox* search_box = SearchBox::Get(render_view); 1248 const SearchBox* search_box = SearchBox::Get(render_view);
1244 1249
1245 std::vector<InstantMostVisitedItemIDPair> instant_mv_items; 1250 std::vector<InstantMostVisitedItemIDPair> instant_mv_items;
1246 search_box->GetMostVisitedItems(&instant_mv_items); 1251 search_box->GetMostVisitedItems(&instant_mv_items);
1247 v8::Handle<v8::Array> v8_mv_items = v8::Array::New(instant_mv_items.size()); 1252 v8::Handle<v8::Array> v8_mv_items = v8::Array::New(instant_mv_items.size());
1248 for (size_t i = 0; i < instant_mv_items.size(); ++i) { 1253 for (size_t i = 0; i < instant_mv_items.size(); ++i) {
1249 v8_mv_items->Set(i, GenerateMostVisitedItem(instant_mv_items[i].first, 1254 v8_mv_items->Set(i, GenerateMostVisitedItem(instant_mv_items[i].first,
1255 render_view->GetRoutingID(),
1250 instant_mv_items[i].second)); 1256 instant_mv_items[i].second));
1251 } 1257 }
1252 return v8_mv_items; 1258 return v8_mv_items;
1253 } 1259 }
1254 1260
1255 // static 1261 // static
1256 v8::Handle<v8::Value> SearchBoxExtensionWrapper::DeleteMostVisitedItem( 1262 v8::Handle<v8::Value> SearchBoxExtensionWrapper::DeleteMostVisitedItem(
1257 const v8::Arguments& args) { 1263 const v8::Arguments& args) {
1258 content::RenderView* render_view = GetRenderView(); 1264 content::RenderView* render_view = GetRenderView();
1259 if (!render_view || !args.Length()) return v8::Undefined(); 1265 if (!render_view || !args.Length()) return v8::Undefined();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 if (args.Length() < 1 || !args[0]->IsNumber()) 1394 if (args.Length() < 1 || !args[0]->IsNumber())
1389 return v8::Undefined(); 1395 return v8::Undefined();
1390 1396
1391 DVLOG(1) << render_view << " GetMostVisitedItem"; 1397 DVLOG(1) << render_view << " GetMostVisitedItem";
1392 InstantRestrictedID restricted_id = args[0]->IntegerValue(); 1398 InstantRestrictedID restricted_id = args[0]->IntegerValue();
1393 InstantMostVisitedItem mv_item; 1399 InstantMostVisitedItem mv_item;
1394 if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID( 1400 if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID(
1395 restricted_id, &mv_item)) { 1401 restricted_id, &mv_item)) {
1396 return v8::Undefined(); 1402 return v8::Undefined();
1397 } 1403 }
1398 return GenerateMostVisitedItem(restricted_id, mv_item); 1404 return GenerateMostVisitedItem(restricted_id,
1405 render_view->GetRoutingID(),
1406 mv_item);
1399 } 1407 }
1400 1408
1401 // static 1409 // static
1402 v8::Handle<v8::Value> SearchBoxExtensionWrapper::IsFocused( 1410 v8::Handle<v8::Value> SearchBoxExtensionWrapper::IsFocused(
1403 const v8::Arguments& args) { 1411 const v8::Arguments& args) {
1404 content::RenderView* render_view = GetRenderView(); 1412 content::RenderView* render_view = GetRenderView();
1405 if (!render_view) return v8::Undefined(); 1413 if (!render_view) return v8::Undefined();
1406 1414
1407 bool is_focused = SearchBox::Get(render_view)->is_focused(); 1415 bool is_focused = SearchBox::Get(render_view)->is_focused();
1408 DVLOG(1) << render_view << " IsFocused: " << is_focused; 1416 DVLOG(1) << render_view << " IsFocused: " << is_focused;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 void SearchBoxExtension::DispatchBarsHidden(WebKit::WebFrame* frame) { 1481 void SearchBoxExtension::DispatchBarsHidden(WebKit::WebFrame* frame) {
1474 Dispatch(frame, kDispatchBarsHiddenEventScript); 1482 Dispatch(frame, kDispatchBarsHiddenEventScript);
1475 } 1483 }
1476 1484
1477 // static 1485 // static
1478 void SearchBoxExtension::DispatchFocusChange(WebKit::WebFrame* frame) { 1486 void SearchBoxExtension::DispatchFocusChange(WebKit::WebFrame* frame) {
1479 Dispatch(frame, kDispatchFocusChangedScript); 1487 Dispatch(frame, kDispatchFocusChangedScript);
1480 } 1488 }
1481 1489
1482 } // namespace extensions_v8 1490 } // namespace extensions_v8
OLDNEW
« chrome/renderer/chrome_content_renderer_client.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