Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
| 9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 145 |
| 146 base::string16 title = mv_item.title; | 146 base::string16 title = mv_item.title; |
| 147 if (title.empty()) | 147 if (title.empty()) |
| 148 title = base::UTF8ToUTF16(mv_item.url.spec()); | 148 title = base::UTF8ToUTF16(mv_item.url.spec()); |
| 149 | 149 |
| 150 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 150 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 151 obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"), | 151 obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"), |
| 152 v8::Int32::New(isolate, render_view_id)); | 152 v8::Int32::New(isolate, render_view_id)); |
| 153 obj->Set(v8::String::NewFromUtf8(isolate, "rid"), | 153 obj->Set(v8::String::NewFromUtf8(isolate, "rid"), |
| 154 v8::Int32::New(isolate, restricted_id)); | 154 v8::Int32::New(isolate, restricted_id)); |
| 155 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrl"), | 155 |
| 156 GenerateThumbnailURL(isolate, render_view_id, restricted_id)); | 156 // If the suggestion already has a suggested thumbnail, we create an thumbnail |
| 157 // array with both the local thumbnail and the proposed one. | |
| 158 // Otherwise, we just create an array with the generated one. | |
| 159 if (!mv_item.thumbnail.spec().empty()) { | |
| 160 v8::Local<v8::Array> thumbs = v8::Array::New(isolate, 2); | |
| 161 thumbs->Set(0, UTF8ToV8String(isolate, base::StringPrintf( | |
|
kmadhusu
2015/07/31 21:05:45
nit: Create a helper function to generate this thu
fserb
2015/08/05 14:56:26
Done.
| |
| 162 "chrome-search://thumb2/%s", | |
| 163 mv_item.url.spec().c_str()))); | |
| 164 thumbs->Set(1, UTF8ToV8String(isolate, mv_item.thumbnail.spec())); | |
| 165 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrls"), thumbs); | |
| 166 } else { | |
| 167 v8::Local<v8::Array> thumbs = v8::Array::New(isolate, 1); | |
| 168 thumbs->Set(0, | |
| 169 GenerateThumbnailURL(isolate, render_view_id, restricted_id)); | |
| 170 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrls"), thumbs); | |
| 171 } | |
| 172 | |
| 173 // If the suggestion already has a favicon, we populate the element with it. | |
| 174 if (!mv_item.favicon.spec().empty()) { | |
| 175 obj->Set(v8::String::NewFromUtf8(isolate, "faviconUrl"), | |
| 176 UTF8ToV8String(isolate, mv_item.favicon.spec())); | |
| 177 } | |
| 178 | |
| 157 if (IsIconNTPEnabled()) { | 179 if (IsIconNTPEnabled()) { |
| 158 // Update website http://www.chromium.org/embeddedsearch when we make this | 180 // Update website http://www.chromium.org/embeddedsearch when we make this |
| 159 // permanent. | 181 // permanent. |
| 160 // Large icon size is 48px * window.devicePixelRatio. This is easier to set | 182 // Large icon size is 48px * window.devicePixelRatio. This is easier to set |
| 161 // from JS, where IsIconNTPEnabled() is not available. So we add stubs | 183 // from JS, where IsIconNTPEnabled() is not available. So we add stubs |
| 162 // here, and let JS fill in details. | 184 // here, and let JS fill in details. |
| 163 obj->Set(v8::String::NewFromUtf8(isolate, "largeIconUrl"), | 185 obj->Set(v8::String::NewFromUtf8(isolate, "largeIconUrl"), |
| 164 v8::String::NewFromUtf8(isolate, "chrome-search://large-icon/")); | 186 v8::String::NewFromUtf8(isolate, "chrome-search://large-icon/")); |
| 165 obj->Set(v8::String::NewFromUtf8(isolate, "fallbackIconUrl"), | 187 obj->Set(v8::String::NewFromUtf8(isolate, "fallbackIconUrl"), |
| 166 v8::String::NewFromUtf8(isolate, "chrome-search://fallback-icon/")); | 188 v8::String::NewFromUtf8(isolate, "chrome-search://fallback-icon/")); |
| (...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1273 if (!render_view) return; | 1295 if (!render_view) return; |
| 1274 | 1296 |
| 1275 bool display_instant_results = | 1297 bool display_instant_results = |
| 1276 SearchBox::Get(render_view)->display_instant_results(); | 1298 SearchBox::Get(render_view)->display_instant_results(); |
| 1277 DVLOG(1) << render_view << " GetDisplayInstantResults" << | 1299 DVLOG(1) << render_view << " GetDisplayInstantResults" << |
| 1278 display_instant_results; | 1300 display_instant_results; |
| 1279 args.GetReturnValue().Set(display_instant_results); | 1301 args.GetReturnValue().Set(display_instant_results); |
| 1280 } | 1302 } |
| 1281 | 1303 |
| 1282 } // namespace extensions_v8 | 1304 } // namespace extensions_v8 |
| OLD | NEW |