| OLD | NEW |
| 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/searchbox_extension.h" | 5 #include "chrome/renderer/searchbox/searchbox_extension.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/renderer/searchbox/searchbox.h" | 9 #include "chrome/renderer/searchbox/searchbox.h" |
| 10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // Gets whether the search box is focused. | 185 // Gets whether the search box is focused. |
| 186 static v8::Handle<v8::Value> GetIsFocused(const v8::Arguments& args); | 186 static v8::Handle<v8::Value> GetIsFocused(const v8::Arguments& args); |
| 187 | 187 |
| 188 // Gets the current session context. | 188 // Gets the current session context. |
| 189 static v8::Handle<v8::Value> GetContext(const v8::Arguments& args); | 189 static v8::Handle<v8::Value> GetContext(const v8::Arguments& args); |
| 190 | 190 |
| 191 // Navigates the window to a URL represented by either a URL string or a | 191 // Navigates the window to a URL represented by either a URL string or a |
| 192 // restricted ID. | 192 // restricted ID. |
| 193 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args); | 193 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args); |
| 194 | 194 |
| 195 // Handle a focus event in the web searchbox. |
| 196 static v8::Handle<v8::Value> WebSearchBoxGotFocus(const v8::Arguments& args); |
| 197 |
| 198 // Handle a blur event in the web searchbox. |
| 199 static v8::Handle<v8::Value> WebSearchBoxLostFocus(const v8::Arguments& args); |
| 200 |
| 195 // Sets ordered suggestions. Valid for current |value|. | 201 // Sets ordered suggestions. Valid for current |value|. |
| 196 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); | 202 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); |
| 197 | 203 |
| 198 // Sets the text to be autocompleted into the search box. | 204 // Sets the text to be autocompleted into the search box. |
| 199 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args); | 205 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args); |
| 200 | 206 |
| 201 // Like |SetQuerySuggestion| but uses a restricted ID to identify the text. | 207 // Like |SetQuerySuggestion| but uses a restricted ID to identify the text. |
| 202 static v8::Handle<v8::Value> SetQuerySuggestionFromAutocompleteResult( | 208 static v8::Handle<v8::Value> SetQuerySuggestionFromAutocompleteResult( |
| 203 const v8::Arguments& args); | 209 const v8::Arguments& args); |
| 204 | 210 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (name->Equals(v8::String::New("GetHeight"))) | 246 if (name->Equals(v8::String::New("GetHeight"))) |
| 241 return v8::FunctionTemplate::New(GetHeight); | 247 return v8::FunctionTemplate::New(GetHeight); |
| 242 if (name->Equals(v8::String::New("GetAutocompleteResults"))) | 248 if (name->Equals(v8::String::New("GetAutocompleteResults"))) |
| 243 return v8::FunctionTemplate::New(GetAutocompleteResults); | 249 return v8::FunctionTemplate::New(GetAutocompleteResults); |
| 244 if (name->Equals(v8::String::New("GetIsFocused"))) | 250 if (name->Equals(v8::String::New("GetIsFocused"))) |
| 245 return v8::FunctionTemplate::New(GetIsFocused); | 251 return v8::FunctionTemplate::New(GetIsFocused); |
| 246 if (name->Equals(v8::String::New("GetContext"))) | 252 if (name->Equals(v8::String::New("GetContext"))) |
| 247 return v8::FunctionTemplate::New(GetContext); | 253 return v8::FunctionTemplate::New(GetContext); |
| 248 if (name->Equals(v8::String::New("NavigateContentWindow"))) | 254 if (name->Equals(v8::String::New("NavigateContentWindow"))) |
| 249 return v8::FunctionTemplate::New(NavigateContentWindow); | 255 return v8::FunctionTemplate::New(NavigateContentWindow); |
| 256 if (name->Equals(v8::String::New("WebSearchBoxGotFocus"))) |
| 257 return v8::FunctionTemplate::New(WebSearchBoxGotFocus); |
| 258 if (name->Equals(v8::String::New("WebSearchBoxLostFocus"))) |
| 259 return v8::FunctionTemplate::New(WebSearchBoxLostFocus); |
| 250 if (name->Equals(v8::String::New("SetSuggestions"))) | 260 if (name->Equals(v8::String::New("SetSuggestions"))) |
| 251 return v8::FunctionTemplate::New(SetSuggestions); | 261 return v8::FunctionTemplate::New(SetSuggestions); |
| 252 if (name->Equals(v8::String::New("SetQuerySuggestion"))) | 262 if (name->Equals(v8::String::New("SetQuerySuggestion"))) |
| 253 return v8::FunctionTemplate::New(SetQuerySuggestion); | 263 return v8::FunctionTemplate::New(SetQuerySuggestion); |
| 254 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) | 264 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) |
| 255 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); | 265 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); |
| 256 if (name->Equals(v8::String::New("SetQuery"))) | 266 if (name->Equals(v8::String::New("SetQuery"))) |
| 257 return v8::FunctionTemplate::New(SetQuery); | 267 return v8::FunctionTemplate::New(SetQuery); |
| 258 if (name->Equals(v8::String::New("SetQueryFromAutocompleteResult"))) | 268 if (name->Equals(v8::String::New("SetQueryFromAutocompleteResult"))) |
| 259 return v8::FunctionTemplate::New(SetQueryFromAutocompleteResult); | 269 return v8::FunctionTemplate::New(SetQueryFromAutocompleteResult); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // Navigate the main frame. | 428 // Navigate the main frame. |
| 419 if (destination_url.is_valid()) { | 429 if (destination_url.is_valid()) { |
| 420 WebKit::WebURLRequest request(destination_url); | 430 WebKit::WebURLRequest request(destination_url); |
| 421 render_view->GetWebView()->mainFrame()->loadRequest(request); | 431 render_view->GetWebView()->mainFrame()->loadRequest(request); |
| 422 } | 432 } |
| 423 | 433 |
| 424 return v8::Undefined(); | 434 return v8::Undefined(); |
| 425 } | 435 } |
| 426 | 436 |
| 427 // static | 437 // static |
| 438 v8::Handle<v8::Value> SearchBoxExtensionWrapper::WebSearchBoxGotFocus( |
| 439 const v8::Arguments& args) { |
| 440 content::RenderView* render_view = GetRenderView(); |
| 441 if (render_view) |
| 442 SearchBox::Get(render_view)->OnWebSearchBoxFocus(); |
| 443 return v8::Undefined(); |
| 444 } |
| 445 |
| 446 // static |
| 447 v8::Handle<v8::Value> SearchBoxExtensionWrapper::WebSearchBoxLostFocus( |
| 448 const v8::Arguments& args) { |
| 449 content::RenderView* render_view = GetRenderView(); |
| 450 if (render_view) |
| 451 SearchBox::Get(render_view)->OnWebSearchBoxBlur(); |
| 452 return v8::Undefined(); |
| 453 } |
| 454 |
| 455 // static |
| 428 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( | 456 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( |
| 429 const v8::Arguments& args) { | 457 const v8::Arguments& args) { |
| 430 content::RenderView* render_view = GetRenderView(); | 458 content::RenderView* render_view = GetRenderView(); |
| 431 if (!render_view || !args.Length()) return v8::Undefined(); | 459 if (!render_view || !args.Length()) return v8::Undefined(); |
| 432 | 460 |
| 433 v8::Handle<v8::Object> suggestion_json = args[0]->ToObject(); | 461 v8::Handle<v8::Object> suggestion_json = args[0]->ToObject(); |
| 434 | 462 |
| 435 InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW; | 463 InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW; |
| 436 InstantSuggestionType type = INSTANT_SUGGESTION_SEARCH; | 464 InstantSuggestionType type = INSTANT_SUGGESTION_SEARCH; |
| 437 v8::Handle<v8::Value> complete_value = | 465 v8::Handle<v8::Value> complete_value = |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 Dispatch(frame, kDispatchContextChangeEventScript); | 670 Dispatch(frame, kDispatchContextChangeEventScript); |
| 643 } | 671 } |
| 644 | 672 |
| 645 // static | 673 // static |
| 646 v8::Extension* SearchBoxExtension::Get() { | 674 v8::Extension* SearchBoxExtension::Get() { |
| 647 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). | 675 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). |
| 648 GetRawDataResource(IDR_SEARCHBOX_API)); | 676 GetRawDataResource(IDR_SEARCHBOX_API)); |
| 649 } | 677 } |
| 650 | 678 |
| 651 } // namespace extensions_v8 | 679 } // namespace extensions_v8 |
| OLD | NEW |