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

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

Issue 10836031: Remove Instant v1 API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update history, title, favicon Created 8 years, 4 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
« no previous file with comments | « chrome/renderer/searchbox_extension.h ('k') | chrome/test/data/instant.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_extension.h" 5 #include "chrome/renderer/searchbox_extension.h"
6 6
7 #include <string>
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/command_line.h"
12 #include "base/string_split.h"
13 #include "base/stringprintf.h"
14 #include "chrome/renderer/searchbox.h" 7 #include "chrome/renderer/searchbox.h"
15 #include "content/public/renderer/render_view.h" 8 #include "content/public/renderer/render_view.h"
16 #include "grit/renderer_resources.h" 9 #include "grit/renderer_resources.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
20 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
21 #include "v8/include/v8.h" 13 #include "v8/include/v8.h"
22 14
23 using WebKit::WebFrame;
24 using WebKit::WebScriptSource;
25 using WebKit::WebString;
26 using WebKit::WebView;
27
28 namespace extensions_v8 { 15 namespace extensions_v8 {
29 16
30 static const char kSearchBoxExtensionName[] = "v8/SearchBox"; 17 static const char kSearchBoxExtensionName[] = "v8/SearchBox";
31 18
32 static const char kDispatchChangeEventScript[] = 19 static const char kDispatchChangeEventScript[] =
33 "if (window.chrome &&" 20 "if (window.chrome &&"
34 " window.chrome.searchBox &&" 21 " window.chrome.searchBox &&"
35 " window.chrome.searchBox.onchange &&" 22 " window.chrome.searchBox.onchange &&"
36 " typeof window.chrome.searchBox.onchange == 'function') {" 23 " typeof window.chrome.searchBox.onchange == 'function') {"
37 " window.chrome.searchBox.onchange();" 24 " window.chrome.searchBox.onchange();"
(...skipping 20 matching lines...) Expand all
58 45
59 static const char kDispatchResizeEventScript[] = 46 static const char kDispatchResizeEventScript[] =
60 "if (window.chrome &&" 47 "if (window.chrome &&"
61 " window.chrome.searchBox &&" 48 " window.chrome.searchBox &&"
62 " window.chrome.searchBox.onresize &&" 49 " window.chrome.searchBox.onresize &&"
63 " typeof window.chrome.searchBox.onresize == 'function') {" 50 " typeof window.chrome.searchBox.onresize == 'function') {"
64 " window.chrome.searchBox.onresize();" 51 " window.chrome.searchBox.onresize();"
65 " true;" 52 " true;"
66 "}"; 53 "}";
67 54
68 // Deprecated API support.
69 // TODO(tonyg): Remove these when they are no longer used.
70 // ----------------------------------------------------------------------------
71 // Script sent as the user is typing and the provider supports instant.
72 // Params:
73 // . the text the user typed.
74 // '46' forces the server to give us verbatim results.
75 static const char kUserInputScript[] =
76 "if (window.chrome.userInput)"
77 " window.chrome.userInput("
78 " window.chrome.searchBox.value,"
79 " window.chrome.searchBox.verbatim ? 46 : 0,"
80 " window.chrome.searchBox.selectionStart);";
81
82 // Script sent when the page is committed and the provider supports instant.
83 // Params:
84 // . the text the user typed.
85 // . boolean indicating if the user pressed enter to accept the text.
86 static const char kUserDoneScript[] =
87 "if (window.chrome.userWantsQuery)"
88 " window.chrome.userWantsQuery("
89 " window.chrome.searchBox.value,"
90 " window.chrome.searchBox.verbatim);";
91
92 // Script sent when the bounds of the omnibox changes and the provider supports
93 // instant. The params are the bounds relative to the origin of the preview
94 // (x, y, width, height).
95 static const char kSetOmniboxBoundsScript[] =
96 "if (window.chrome.setDropdownDimensions)"
97 " window.chrome.setDropdownDimensions("
98 " window.chrome.searchBox.x,"
99 " window.chrome.searchBox.y,"
100 " window.chrome.searchBox.width,"
101 " window.chrome.searchBox.height);";
102
103 // We first send this script down to determine if the page supports instant. 55 // We first send this script down to determine if the page supports instant.
104 static const char kSupportsInstantScript[] = 56 static const char kSupportsInstantScript[] =
105 "if (window.chrome.sv) true; else false;"; 57 "if (window.chrome &&"
58 " window.chrome.searchBox &&"
59 " window.chrome.searchBox.onsubmit &&"
60 " typeof window.chrome.searchBox.onsubmit == 'function') {"
61 " true;"
62 "} else {"
63 " false;"
64 "}";
106 65
107 // The google.y.first array is a list of functions which are to be executed
108 // after the external JavaScript used by Google web search loads. The deprecated
109 // API requires setDropdownDimensions and userInput to be invoked after
110 // the external JavaScript loads. So if they are not already registered, we add
111 // them to the array of functions the page will execute after load. This tight
112 // coupling discourages proliferation of the deprecated API.
113 static const char kInitScript[] =
114 "(function() {"
115 "var initScript = function(){%s%s};"
116 "if (window.chrome.setDropdownDimensions)"
117 " initScript();"
118 "else if (window.google && window.google.y)"
119 " window.google.y.first.push(initScript);"
120 "})();";
121 // ---------------------------------------------------------------------------- 66 // ----------------------------------------------------------------------------
122 67
123 class SearchBoxExtensionWrapper : public v8::Extension { 68 class SearchBoxExtensionWrapper : public v8::Extension {
124 public: 69 public:
125 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); 70 explicit SearchBoxExtensionWrapper(const base::StringPiece& code);
126 71
127 // Allows v8's javascript code to call the native functions defined 72 // Allows v8's javascript code to call the native functions defined
128 // in this class for window.chrome. 73 // in this class for window.chrome.
129 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 74 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
130 v8::Handle<v8::String> name); 75 v8::Handle<v8::String> name);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 107
163 // Sets ordered suggestions. Valid for current |value|. 108 // Sets ordered suggestions. Valid for current |value|.
164 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); 109 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args);
165 110
166 private: 111 private:
167 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); 112 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper);
168 }; 113 };
169 114
170 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( 115 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper(
171 const base::StringPiece& code) 116 const base::StringPiece& code)
172 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) {} 117 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) {
118 }
173 119
174 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( 120 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction(
175 v8::Handle<v8::String> name) { 121 v8::Handle<v8::String> name) {
176 if (name->Equals(v8::String::New("GetValue"))) { 122 if (name->Equals(v8::String::New("GetValue"))) {
177 return v8::FunctionTemplate::New(GetValue); 123 return v8::FunctionTemplate::New(GetValue);
178 } else if (name->Equals(v8::String::New("GetVerbatim"))) { 124 } else if (name->Equals(v8::String::New("GetVerbatim"))) {
179 return v8::FunctionTemplate::New(GetVerbatim); 125 return v8::FunctionTemplate::New(GetVerbatim);
180 } else if (name->Equals(v8::String::New("GetSelectionStart"))) { 126 } else if (name->Equals(v8::String::New("GetSelectionStart"))) {
181 return v8::FunctionTemplate::New(GetSelectionStart); 127 return v8::FunctionTemplate::New(GetSelectionStart);
182 } else if (name->Equals(v8::String::New("GetSelectionEnd"))) { 128 } else if (name->Equals(v8::String::New("GetSelectionEnd"))) {
183 return v8::FunctionTemplate::New(GetSelectionEnd); 129 return v8::FunctionTemplate::New(GetSelectionEnd);
184 } else if (name->Equals(v8::String::New("GetX"))) { 130 } else if (name->Equals(v8::String::New("GetX"))) {
185 return v8::FunctionTemplate::New(GetX); 131 return v8::FunctionTemplate::New(GetX);
186 } else if (name->Equals(v8::String::New("GetY"))) { 132 } else if (name->Equals(v8::String::New("GetY"))) {
187 return v8::FunctionTemplate::New(GetY); 133 return v8::FunctionTemplate::New(GetY);
188 } else if (name->Equals(v8::String::New("GetWidth"))) { 134 } else if (name->Equals(v8::String::New("GetWidth"))) {
189 return v8::FunctionTemplate::New(GetWidth); 135 return v8::FunctionTemplate::New(GetWidth);
190 } else if (name->Equals(v8::String::New("GetHeight"))) { 136 } else if (name->Equals(v8::String::New("GetHeight"))) {
191 return v8::FunctionTemplate::New(GetHeight); 137 return v8::FunctionTemplate::New(GetHeight);
192 } else if (name->Equals(v8::String::New("SetSuggestions"))) { 138 } else if (name->Equals(v8::String::New("SetSuggestions"))) {
193 return v8::FunctionTemplate::New(SetSuggestions); 139 return v8::FunctionTemplate::New(SetSuggestions);
194 } 140 }
195 return v8::Handle<v8::FunctionTemplate>(); 141 return v8::Handle<v8::FunctionTemplate>();
196 } 142 }
197 143
198 // static 144 // static
199 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { 145 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() {
200 WebFrame* webframe = WebFrame::frameForEnteredContext(); 146 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForEnteredContext();
201 DCHECK(webframe) << "There should be an active frame since we just got " 147 DCHECK(webframe) << "There should be an active frame since we just got "
202 "a native function called."; 148 "a native function called.";
203 if (!webframe) return NULL; 149 if (!webframe) return NULL;
204 150
205 WebView* webview = webframe->view(); 151 WebKit::WebView* webview = webframe->view();
206 if (!webview) return NULL; // can happen during closing 152 if (!webview) return NULL; // can happen during closing
207 153
208 return content::RenderView::FromWebView(webview); 154 return content::RenderView::FromWebView(webview);
209 } 155 }
210 156
211 // static 157 // static
212 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetValue( 158 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetValue(
213 const v8::Arguments& args) { 159 const v8::Arguments& args) {
214 content::RenderView* render_view = GetRenderView(); 160 content::RenderView* render_view = GetRenderView();
215 if (!render_view) return v8::Undefined(); 161 if (!render_view) return v8::Undefined();
216 return v8::String::New( 162 return v8::String::New(
217 reinterpret_cast<const uint16_t*>( 163 reinterpret_cast<const uint16_t*>(
218 SearchBox::Get(render_view)->value().c_str()), 164 SearchBox::Get(render_view)->value().data()),
219 SearchBox::Get(render_view)->value().length()); 165 SearchBox::Get(render_view)->value().length());
220 } 166 }
221 167
222 // static 168 // static
223 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetVerbatim( 169 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetVerbatim(
224 const v8::Arguments& args) { 170 const v8::Arguments& args) {
225 content::RenderView* render_view = GetRenderView(); 171 content::RenderView* render_view = GetRenderView();
226 if (!render_view) return v8::Undefined(); 172 if (!render_view) return v8::Undefined();
227 return v8::Boolean::New(SearchBox::Get(render_view)->verbatim()); 173 return v8::Boolean::New(SearchBox::Get(render_view)->verbatim());
228 } 174 }
229 175
230 // static 176 // static
231 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetSelectionStart( 177 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetSelectionStart(
232 const v8::Arguments& args) { 178 const v8::Arguments& args) {
233 content::RenderView* render_view = GetRenderView(); 179 content::RenderView* render_view = GetRenderView();
234 if (!render_view) return v8::Undefined(); 180 if (!render_view) return v8::Undefined();
235 return v8::Int32::New(SearchBox::Get(render_view)->selection_start()); 181 return v8::Uint32::New(SearchBox::Get(render_view)->selection_start());
236 } 182 }
237 183
238 // static 184 // static
239 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetSelectionEnd( 185 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetSelectionEnd(
240 const v8::Arguments& args) { 186 const v8::Arguments& args) {
241 content::RenderView* render_view = GetRenderView(); 187 content::RenderView* render_view = GetRenderView();
242 if (!render_view) return v8::Undefined(); 188 if (!render_view) return v8::Undefined();
243 return v8::Int32::New(SearchBox::Get(render_view)->selection_end()); 189 return v8::Uint32::New(SearchBox::Get(render_view)->selection_end());
244 } 190 }
245 191
246 // static 192 // static
247 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetX( 193 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetX(
248 const v8::Arguments& args) { 194 const v8::Arguments& args) {
249 content::RenderView* render_view = GetRenderView(); 195 content::RenderView* render_view = GetRenderView();
250 if (!render_view) return v8::Undefined(); 196 if (!render_view) return v8::Undefined();
251 return v8::Int32::New(SearchBox::Get(render_view)->GetRect().x()); 197 return v8::Int32::New(SearchBox::Get(render_view)->GetRect().x());
252 } 198 }
253 199
(...skipping 14 matching lines...) Expand all
268 } 214 }
269 215
270 // static 216 // static
271 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetHeight( 217 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetHeight(
272 const v8::Arguments& args) { 218 const v8::Arguments& args) {
273 content::RenderView* render_view = GetRenderView(); 219 content::RenderView* render_view = GetRenderView();
274 if (!render_view) return v8::Undefined(); 220 if (!render_view) return v8::Undefined();
275 return v8::Int32::New(SearchBox::Get(render_view)->GetRect().height()); 221 return v8::Int32::New(SearchBox::Get(render_view)->GetRect().height());
276 } 222 }
277 223
278 // Accepts a single argument in form:
279 // {
280 // suggestions: [
281 // {
282 // value: "..."
283 // }
284 // ]
285 // }
286 // static 224 // static
287 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( 225 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions(
288 const v8::Arguments& args) { 226 const v8::Arguments& args) {
289 std::vector<std::string> suggestions; 227 std::vector<string16> suggestions;
290 InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW; 228 InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW;
291 229
292 if (args.Length() && args[0]->IsArray()) { 230 if (args.Length() && args[0]->IsObject()) {
293 // For backwards compatibility, also accept an array of strings. 231 v8::Local<v8::Object> suggestion_json = args[0]->ToObject();
294 // TODO(tonyg): Remove this when it is confirmed to be unused. 232
295 v8::Local<v8::Array> suggestions_array = 233 v8::Local<v8::Value> complete_value =
296 v8::Local<v8::Array>::Cast(args[0]); 234 suggestion_json->Get(v8::String::New("complete_behavior"));
297 uint32_t length = suggestions_array->Length(); 235 if (complete_value->IsString()) {
298 for (uint32_t i = 0; i < length; i++) { 236 if (complete_value->Equals(v8::String::New("now"))) {
299 std::string suggestion = *v8::String::Utf8Value( 237 behavior = INSTANT_COMPLETE_NOW;
300 suggestions_array->Get(v8::Integer::New(i))->ToString()); 238 } else if (complete_value->Equals(v8::String::New("never"))) {
301 if (!suggestion.length()) continue; 239 behavior = INSTANT_COMPLETE_NEVER;
302 suggestions.push_back(suggestion); 240 } else if (complete_value->Equals(v8::String::New("delayed"))) {
241 behavior = INSTANT_COMPLETE_DELAYED;
242 } else {
243 VLOG(1) << "Unsupported complete behavior '"
244 << *v8::String::Utf8Value(complete_value) << "'";
245 }
303 } 246 }
304 } else if (args.Length() && args[0]->IsObject()) { 247
305 // Standard version, object argument.
306 v8::Local<v8::Object> suggestion_json =
307 v8::Local<v8::Object>::Cast(args[0]);
308 v8::Local<v8::Value> suggestions_field = 248 v8::Local<v8::Value> suggestions_field =
309 suggestion_json->Get(v8::String::New("suggestions")); 249 suggestion_json->Get(v8::String::New("suggestions"));
310 250
311 if (suggestions_field->IsArray()) { 251 if (suggestions_field->IsArray()) {
312 v8::Local<v8::Array> suggestions_array = 252 v8::Local<v8::Array> suggestions_array =
313 suggestions_field.As<v8::Array>(); 253 suggestions_field.As<v8::Array>();
314 254
315 uint32_t length = suggestions_array->Length(); 255 size_t length = suggestions_array->Length();
316 for (uint32_t i = 0; i < length; i++) { 256 for (size_t i = 0; i < length; i++) {
317 v8::Local<v8::Value> suggestion_value = 257 v8::Local<v8::Value> suggestion_value = suggestions_array->Get(i);
318 suggestions_array->Get(v8::Integer::New(i));
319 if (!suggestion_value->IsObject()) continue; 258 if (!suggestion_value->IsObject()) continue;
320 259
321 v8::Local<v8::Object> suggestion_object = 260 v8::Local<v8::Object> suggestion_object = suggestion_value->ToObject();
322 suggestion_value.As<v8::Object>();
323 v8::Local<v8::Value> suggestion_object_value = 261 v8::Local<v8::Value> suggestion_object_value =
324 suggestion_object->Get(v8::String::New("value")); 262 suggestion_object->Get(v8::String::New("value"));
325 if (!suggestion_object_value->IsString()) continue; 263 if (!suggestion_object_value->IsString()) continue;
326 264
327 std::string suggestion = *v8::String::Utf8Value( 265 string16 suggestion(reinterpret_cast<char16*>(*v8::String::Value(
328 suggestion_object_value->ToString()); 266 suggestion_object_value->ToString())));
329 if (!suggestion.length()) continue;
330 suggestions.push_back(suggestion); 267 suggestions.push_back(suggestion);
331 } 268 }
332 } 269 }
333 if (suggestion_json->Has(v8::String::New("complete_behavior"))) {
334 v8::Local<v8::Value> complete_value =
335 suggestion_json->Get(v8::String::New("complete_behavior"));
336 if (complete_value->IsString()) {
337 if (complete_value->Equals(v8::String::New("never")))
338 behavior = INSTANT_COMPLETE_NEVER;
339 else if (complete_value->Equals(v8::String::New("delayed")))
340 behavior = INSTANT_COMPLETE_DELAYED;
341 }
342 }
343 } 270 }
344 271
345 if (content::RenderView* render_view = GetRenderView()) 272 if (content::RenderView* render_view = GetRenderView())
346 SearchBox::Get(render_view)->SetSuggestions(suggestions, behavior); 273 SearchBox::Get(render_view)->SetSuggestions(suggestions, behavior);
347 return v8::Undefined(); 274 return v8::Undefined();
348 } 275 }
349 276
350 // static 277 // static
351 void Dispatch(WebFrame* frame, 278 void Dispatch(WebKit::WebFrame* frame, WebKit::WebString script) {
352 WebString event_dispatch_script,
353 WebString no_event_handler_script) {
354 DCHECK(frame) << "Dispatch requires frame"; 279 DCHECK(frame) << "Dispatch requires frame";
355 if (!frame) 280 if (!frame) return;
356 return; 281 frame->executeScript(WebKit::WebScriptSource(script));
357
358 v8::Handle<v8::Value> result = frame->executeScriptAndReturnValue(
359 WebScriptSource(event_dispatch_script));
360 if (result.IsEmpty() || result->IsUndefined() || result->IsNull() ||
361 result->IsFalse()) {
362 frame->executeScript(WebScriptSource(no_event_handler_script));
363 }
364 } 282 }
365 283
366 // static 284 // static
367 void SearchBoxExtension::DispatchChange(WebFrame* frame) { 285 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) {
368 Dispatch(frame, kDispatchChangeEventScript, kUserInputScript); 286 Dispatch(frame, kDispatchChangeEventScript);
369 } 287 }
370 288
371 // static 289 // static
372 void SearchBoxExtension::DispatchSubmit(WebFrame* frame) { 290 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) {
373 Dispatch(frame, kDispatchSubmitEventScript, kUserDoneScript); 291 Dispatch(frame, kDispatchSubmitEventScript);
374 } 292 }
375 293
376 // static 294 // static
377 void SearchBoxExtension::DispatchCancel(WebFrame* frame) { 295 void SearchBoxExtension::DispatchCancel(WebKit::WebFrame* frame) {
378 Dispatch(frame, kDispatchCancelEventScript, kUserDoneScript); 296 Dispatch(frame, kDispatchCancelEventScript);
379 } 297 }
380 298
381 // static 299 // static
382 void SearchBoxExtension::DispatchResize(WebFrame* frame) { 300 void SearchBoxExtension::DispatchResize(WebKit::WebFrame* frame) {
383 Dispatch(frame, kDispatchResizeEventScript, kSetOmniboxBoundsScript); 301 Dispatch(frame, kDispatchResizeEventScript);
384 } 302 }
385 303
386 // static 304 // static
387 bool SearchBoxExtension::PageSupportsInstant(WebFrame* frame) { 305 bool SearchBoxExtension::PageSupportsInstant(WebKit::WebFrame* frame) {
388 DCHECK(frame) << "PageSupportsInstant requires frame"; 306 DCHECK(frame) << "PageSupportsInstant requires frame";
389 if (!frame) return false; 307 if (!frame) return false;
390 308
391 v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue( 309 v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue(
392 WebScriptSource(kSupportsInstantScript)); 310 WebKit::WebScriptSource(kSupportsInstantScript));
393 bool supports_deprecated_api = !v.IsEmpty() && v->BooleanValue(); 311 bool supports_instant = !v.IsEmpty() && v->BooleanValue();
394 // TODO(tonyg): Add way of detecting instant support to SearchBox API.
395 bool supports_searchbox_api = supports_deprecated_api;
396 312
397 // The deprecated API needs to notify the page of events it may have missed. 313 // Send a resize message to tell the page that Chrome is actively using the
398 // This isn't necessary in the SearchBox API, since the page can query the 314 // searchbox API with it. The page uses the message to transition from
399 // API at any time. 315 // "homepage" mode to "search" mode.
400 CR_DEFINE_STATIC_LOCAL(std::string, init_script, 316 if (supports_instant)
401 (StringPrintf(kInitScript, kSetOmniboxBoundsScript, kUserInputScript))); 317 DispatchResize(frame);
402 if (supports_deprecated_api) {
403 frame->executeScript(WebScriptSource(WebString::fromUTF8(init_script)));
404 }
405 318
406 return supports_searchbox_api || supports_deprecated_api; 319 return supports_instant;
407 } 320 }
408 321
409 // static 322 // static
410 v8::Extension* SearchBoxExtension::Get() { 323 v8::Extension* SearchBoxExtension::Get() {
411 const base::StringPiece code = 324 const base::StringPiece code =
412 ResourceBundle::GetSharedInstance().GetRawDataResource( 325 ResourceBundle::GetSharedInstance().GetRawDataResource(
413 IDR_SEARCHBOX_API, ui::SCALE_FACTOR_NONE); 326 IDR_SEARCHBOX_API, ui::SCALE_FACTOR_NONE);
414 return new SearchBoxExtensionWrapper(code); 327 return new SearchBoxExtensionWrapper(code);
415 } 328 }
416 329
417 } // namespace extensions_v8 330 } // namespace extensions_v8
OLDNEW
« no previous file with comments | « chrome/renderer/searchbox_extension.h ('k') | chrome/test/data/instant.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698