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

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

Issue 1010783002: [Icons NTP] Working prototype to fetch, store, and display big icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
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/json/string_escape.h" 8 #include "base/json/string_escape.h"
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"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 v8::Handle<v8::String> GenerateThumbnailURL( 85 v8::Handle<v8::String> GenerateThumbnailURL(
86 v8::Isolate* isolate, 86 v8::Isolate* isolate,
87 int render_view_id, 87 int render_view_id,
88 InstantRestrictedID most_visited_item_id) { 88 InstantRestrictedID most_visited_item_id) {
89 return UTF8ToV8String( 89 return UTF8ToV8String(
90 isolate, 90 isolate,
91 base::StringPrintf( 91 base::StringPrintf(
92 "chrome-search://thumb/%d/%d", render_view_id, most_visited_item_id)); 92 "chrome-search://thumb/%d/%d", render_view_id, most_visited_item_id));
93 } 93 }
94 94
95 v8::Handle<v8::String> GenerateBigIconURL(
96 v8::Isolate* isolate,
97 int render_view_id,
98 InstantRestrictedID most_visited_item_id) {
99 int size = 48;
100 return UTF8ToV8String(
101 isolate,
102 base::StringPrintf("chrome-search://big-icon/%d/%d/%d",
103 size, render_view_id, most_visited_item_id));
104 }
105
106 v8::Handle<v8::String> GenerateFallbackIconURL(
107 v8::Isolate* isolate,
108 int render_view_id,
109 InstantRestrictedID most_visited_item_id) {
110 return UTF8ToV8String(
111 isolate,
112 base::StringPrintf("chrome-search://fallback-icon/,,,,1/%d/%d",
113 render_view_id, most_visited_item_id));
114 }
115
95 // Populates a Javascript MostVisitedItem object from |mv_item|. 116 // Populates a Javascript MostVisitedItem object from |mv_item|.
96 // NOTE: Includes "url", "title" and "domain" which are private data, so should 117 // NOTE: Includes "url", "title" and "domain" which are private data, so should
97 // not be returned to the Instant page. These should be erased before returning 118 // not be returned to the Instant page. These should be erased before returning
98 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js. 119 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js.
99 v8::Handle<v8::Object> GenerateMostVisitedItem( 120 v8::Handle<v8::Object> GenerateMostVisitedItem(
100 v8::Isolate* isolate, 121 v8::Isolate* isolate,
101 int render_view_id, 122 int render_view_id,
102 InstantRestrictedID restricted_id, 123 InstantRestrictedID restricted_id,
103 const InstantMostVisitedItem& mv_item) { 124 const InstantMostVisitedItem& mv_item) {
104 // We set the "dir" attribute of the title, so that in RTL locales, a LTR 125 // We set the "dir" attribute of the title, so that in RTL locales, a LTR
(...skipping 10 matching lines...) Expand all
115 std::string direction; 136 std::string direction;
116 if (base::i18n::StringContainsStrongRTLChars(mv_item.title)) 137 if (base::i18n::StringContainsStrongRTLChars(mv_item.title))
117 direction = kRTLHtmlTextDirection; 138 direction = kRTLHtmlTextDirection;
118 else 139 else
119 direction = kLTRHtmlTextDirection; 140 direction = kLTRHtmlTextDirection;
120 141
121 base::string16 title = mv_item.title; 142 base::string16 title = mv_item.title;
122 if (title.empty()) 143 if (title.empty())
123 title = base::UTF8ToUTF16(mv_item.url.spec()); 144 title = base::UTF8ToUTF16(mv_item.url.spec());
124 145
146 bool use_big_icon = true;
147
125 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 148 v8::Handle<v8::Object> obj = v8::Object::New(isolate);
126 obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"), 149 obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"),
127 v8::Int32::New(isolate, render_view_id)); 150 v8::Int32::New(isolate, render_view_id));
128 obj->Set(v8::String::NewFromUtf8(isolate, "rid"), 151 obj->Set(v8::String::NewFromUtf8(isolate, "rid"),
129 v8::Int32::New(isolate, restricted_id)); 152 v8::Int32::New(isolate, restricted_id));
130 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrl"), 153 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrl"),
131 GenerateThumbnailURL(isolate, render_view_id, restricted_id)); 154 GenerateThumbnailURL(isolate, render_view_id, restricted_id));
155 if (use_big_icon) {
156 obj->Set(v8::String::NewFromUtf8(isolate, "bigIconUrl"),
157 GenerateBigIconURL(isolate, render_view_id, restricted_id));
158 obj->Set(v8::String::NewFromUtf8(isolate, "fallbackIconUrl"),
159 GenerateFallbackIconURL(isolate, render_view_id, restricted_id));
160 }
132 obj->Set(v8::String::NewFromUtf8(isolate, "title"), 161 obj->Set(v8::String::NewFromUtf8(isolate, "title"),
133 UTF16ToV8String(isolate, title)); 162 UTF16ToV8String(isolate, title));
134 obj->Set(v8::String::NewFromUtf8(isolate, "domain"), 163 obj->Set(v8::String::NewFromUtf8(isolate, "domain"),
135 UTF8ToV8String(isolate, mv_item.url.host())); 164 UTF8ToV8String(isolate, mv_item.url.host()));
136 obj->Set(v8::String::NewFromUtf8(isolate, "direction"), 165 obj->Set(v8::String::NewFromUtf8(isolate, "direction"),
137 UTF8ToV8String(isolate, direction)); 166 UTF8ToV8String(isolate, direction));
138 obj->Set(v8::String::NewFromUtf8(isolate, "url"), 167 obj->Set(v8::String::NewFromUtf8(isolate, "url"),
139 UTF8ToV8String(isolate, mv_item.url.spec())); 168 UTF8ToV8String(isolate, mv_item.url.spec()));
140 return obj; 169 return obj;
141 } 170 }
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 if (!render_view) return; 1223 if (!render_view) return;
1195 1224
1196 bool display_instant_results = 1225 bool display_instant_results =
1197 SearchBox::Get(render_view)->display_instant_results(); 1226 SearchBox::Get(render_view)->display_instant_results();
1198 DVLOG(1) << render_view << " GetDisplayInstantResults" << 1227 DVLOG(1) << render_view << " GetDisplayInstantResults" <<
1199 display_instant_results; 1228 display_instant_results;
1200 args.GetReturnValue().Set(display_instant_results); 1229 args.GetReturnValue().Set(display_instant_results);
1201 } 1230 }
1202 1231
1203 } // namespace extensions_v8 1232 } // namespace extensions_v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698