| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 v8::Local<v8::String> GenerateThumbnailURL( | 110 v8::Local<v8::String> GenerateThumbnailURL( |
| 111 v8::Isolate* isolate, | 111 v8::Isolate* isolate, |
| 112 int render_view_id, | 112 int render_view_id, |
| 113 InstantRestrictedID most_visited_item_id) { | 113 InstantRestrictedID most_visited_item_id) { |
| 114 return UTF8ToV8String( | 114 return UTF8ToV8String( |
| 115 isolate, | 115 isolate, |
| 116 base::StringPrintf( | 116 base::StringPrintf( |
| 117 "chrome-search://thumb/%d/%d", render_view_id, most_visited_item_id)); | 117 "chrome-search://thumb/%d/%d", render_view_id, most_visited_item_id)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 v8::Local<v8::String> GenerateThumb2URL(v8::Isolate* isolate, std::string url) { |
| 121 return UTF8ToV8String( |
| 122 isolate, base::StringPrintf("chrome-search://thumb2/%s", url.c_str())); |
| 123 } |
| 124 |
| 120 // Populates a Javascript MostVisitedItem object from |mv_item|. | 125 // Populates a Javascript MostVisitedItem object from |mv_item|. |
| 121 // NOTE: Includes "url", "title" and "domain" which are private data, so should | 126 // NOTE: Includes "url", "title" and "domain" which are private data, so should |
| 122 // not be returned to the Instant page. These should be erased before returning | 127 // not be returned to the Instant page. These should be erased before returning |
| 123 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js. | 128 // the object. See GetMostVisitedItemsWrapper() in searchbox_api.js. |
| 124 v8::Local<v8::Object> GenerateMostVisitedItem( | 129 v8::Local<v8::Object> GenerateMostVisitedItem( |
| 125 v8::Isolate* isolate, | 130 v8::Isolate* isolate, |
| 126 int render_view_id, | 131 int render_view_id, |
| 127 InstantRestrictedID restricted_id, | 132 InstantRestrictedID restricted_id, |
| 128 const InstantMostVisitedItem& mv_item) { | 133 const InstantMostVisitedItem& mv_item) { |
| 129 // We set the "dir" attribute of the title, so that in RTL locales, a LTR | 134 // We set the "dir" attribute of the title, so that in RTL locales, a LTR |
| (...skipping 15 matching lines...) Expand all Loading... |
| 145 | 150 |
| 146 base::string16 title = mv_item.title; | 151 base::string16 title = mv_item.title; |
| 147 if (title.empty()) | 152 if (title.empty()) |
| 148 title = base::UTF8ToUTF16(mv_item.url.spec()); | 153 title = base::UTF8ToUTF16(mv_item.url.spec()); |
| 149 | 154 |
| 150 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 155 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 151 obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"), | 156 obj->Set(v8::String::NewFromUtf8(isolate, "renderViewId"), |
| 152 v8::Int32::New(isolate, render_view_id)); | 157 v8::Int32::New(isolate, render_view_id)); |
| 153 obj->Set(v8::String::NewFromUtf8(isolate, "rid"), | 158 obj->Set(v8::String::NewFromUtf8(isolate, "rid"), |
| 154 v8::Int32::New(isolate, restricted_id)); | 159 v8::Int32::New(isolate, restricted_id)); |
| 155 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrl"), | 160 |
| 156 GenerateThumbnailURL(isolate, render_view_id, restricted_id)); | 161 // If the suggestion already has a suggested thumbnail, we create an thumbnail |
| 162 // array with both the local thumbnail and the proposed one. |
| 163 // Otherwise, we just create an array with the generated one. |
| 164 if (!mv_item.thumbnail.spec().empty()) { |
| 165 v8::Local<v8::Array> thumbs = v8::Array::New(isolate, 2); |
| 166 thumbs->Set(0, GenerateThumb2URL(isolate, mv_item.url.spec())); |
| 167 thumbs->Set(1, UTF8ToV8String(isolate, mv_item.thumbnail.spec())); |
| 168 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrls"), thumbs); |
| 169 } else { |
| 170 v8::Local<v8::Array> thumbs = v8::Array::New(isolate, 1); |
| 171 thumbs->Set(0, |
| 172 GenerateThumbnailURL(isolate, render_view_id, restricted_id)); |
| 173 obj->Set(v8::String::NewFromUtf8(isolate, "thumbnailUrls"), thumbs); |
| 174 } |
| 175 |
| 176 // If the suggestion already has a favicon, we populate the element with it. |
| 177 if (!mv_item.favicon.spec().empty()) { |
| 178 obj->Set(v8::String::NewFromUtf8(isolate, "faviconUrl"), |
| 179 UTF8ToV8String(isolate, mv_item.favicon.spec())); |
| 180 } |
| 181 |
| 157 if (IsIconNTPEnabled()) { | 182 if (IsIconNTPEnabled()) { |
| 158 // Update website http://www.chromium.org/embeddedsearch when we make this | 183 // Update website http://www.chromium.org/embeddedsearch when we make this |
| 159 // permanent. | 184 // permanent. |
| 160 // Large icon size is 48px * window.devicePixelRatio. This is easier to set | 185 // Large icon size is 48px * window.devicePixelRatio. This is easier to set |
| 161 // from JS, where IsIconNTPEnabled() is not available. So we add stubs | 186 // from JS, where IsIconNTPEnabled() is not available. So we add stubs |
| 162 // here, and let JS fill in details. | 187 // here, and let JS fill in details. |
| 163 obj->Set(v8::String::NewFromUtf8(isolate, "largeIconUrl"), | 188 obj->Set(v8::String::NewFromUtf8(isolate, "largeIconUrl"), |
| 164 v8::String::NewFromUtf8(isolate, "chrome-search://large-icon/")); | 189 v8::String::NewFromUtf8(isolate, "chrome-search://large-icon/")); |
| 165 obj->Set(v8::String::NewFromUtf8(isolate, "fallbackIconUrl"), | 190 obj->Set(v8::String::NewFromUtf8(isolate, "fallbackIconUrl"), |
| 166 v8::String::NewFromUtf8(isolate, "chrome-search://fallback-icon/")); | 191 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; | 1298 if (!render_view) return; |
| 1274 | 1299 |
| 1275 bool display_instant_results = | 1300 bool display_instant_results = |
| 1276 SearchBox::Get(render_view)->display_instant_results(); | 1301 SearchBox::Get(render_view)->display_instant_results(); |
| 1277 DVLOG(1) << render_view << " GetDisplayInstantResults" << | 1302 DVLOG(1) << render_view << " GetDisplayInstantResults" << |
| 1278 display_instant_results; | 1303 display_instant_results; |
| 1279 args.GetReturnValue().Set(display_instant_results); | 1304 args.GetReturnValue().Set(display_instant_results); |
| 1280 } | 1305 } |
| 1281 | 1306 |
| 1282 } // namespace extensions_v8 | 1307 } // namespace extensions_v8 |
| OLD | NEW |