| 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 <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // Gets whether the search box is focused. | 195 // Gets whether the search box is focused. |
| 196 static v8::Handle<v8::Value> GetIsFocused(const v8::Arguments& args); | 196 static v8::Handle<v8::Value> GetIsFocused(const v8::Arguments& args); |
| 197 | 197 |
| 198 // Gets the current session context. | 198 // Gets the current session context. |
| 199 static v8::Handle<v8::Value> GetContext(const v8::Arguments& args); | 199 static v8::Handle<v8::Value> GetContext(const v8::Arguments& args); |
| 200 | 200 |
| 201 // Navigates the window to a URL represented by either a URL string or a | 201 // Navigates the window to a URL represented by either a URL string or a |
| 202 // restricted ID. | 202 // restricted ID. |
| 203 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args); | 203 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args); |
| 204 | 204 |
| 205 // Sets a boolean flag indicating that the search provider wishes to display a |
| 206 // custom logo on the new tab page. |
| 207 static v8::Handle<v8::Value> SetHasCustomLogo(const v8::Arguments& args); |
| 208 |
| 205 // Sets ordered suggestions. Valid for current |value|. | 209 // Sets ordered suggestions. Valid for current |value|. |
| 206 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); | 210 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); |
| 207 | 211 |
| 208 // Sets the text to be autocompleted into the search box. | 212 // Sets the text to be autocompleted into the search box. |
| 209 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args); | 213 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args); |
| 210 | 214 |
| 211 // Like |SetQuerySuggestion| but uses a restricted ID to identify the text. | 215 // Like |SetQuerySuggestion| but uses a restricted ID to identify the text. |
| 212 static v8::Handle<v8::Value> SetQuerySuggestionFromAutocompleteResult( | 216 static v8::Handle<v8::Value> SetQuerySuggestionFromAutocompleteResult( |
| 213 const v8::Arguments& args); | 217 const v8::Arguments& args); |
| 214 | 218 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } else if (name->Equals(v8::String::New("GetHeight"))) { | 254 } else if (name->Equals(v8::String::New("GetHeight"))) { |
| 251 return v8::FunctionTemplate::New(GetHeight); | 255 return v8::FunctionTemplate::New(GetHeight); |
| 252 } else if (name->Equals(v8::String::New("GetAutocompleteResults"))) { | 256 } else if (name->Equals(v8::String::New("GetAutocompleteResults"))) { |
| 253 return v8::FunctionTemplate::New(GetAutocompleteResults); | 257 return v8::FunctionTemplate::New(GetAutocompleteResults); |
| 254 } else if (name->Equals(v8::String::New("GetIsFocused"))) { | 258 } else if (name->Equals(v8::String::New("GetIsFocused"))) { |
| 255 return v8::FunctionTemplate::New(GetIsFocused); | 259 return v8::FunctionTemplate::New(GetIsFocused); |
| 256 } else if (name->Equals(v8::String::New("GetContext"))) { | 260 } else if (name->Equals(v8::String::New("GetContext"))) { |
| 257 return v8::FunctionTemplate::New(GetContext); | 261 return v8::FunctionTemplate::New(GetContext); |
| 258 } else if (name->Equals(v8::String::New("NavigateContentWindow"))) { | 262 } else if (name->Equals(v8::String::New("NavigateContentWindow"))) { |
| 259 return v8::FunctionTemplate::New(NavigateContentWindow); | 263 return v8::FunctionTemplate::New(NavigateContentWindow); |
| 264 } else if (name->Equals(v8::String::New("SetHasCustomLogo"))) { |
| 265 return v8::FunctionTemplate::New(SetHasCustomLogo); |
| 260 } else if (name->Equals(v8::String::New("SetSuggestions"))) { | 266 } else if (name->Equals(v8::String::New("SetSuggestions"))) { |
| 261 return v8::FunctionTemplate::New(SetSuggestions); | 267 return v8::FunctionTemplate::New(SetSuggestions); |
| 262 } else if (name->Equals(v8::String::New("SetQuerySuggestion"))) { | 268 } else if (name->Equals(v8::String::New("SetQuerySuggestion"))) { |
| 263 return v8::FunctionTemplate::New(SetQuerySuggestion); | 269 return v8::FunctionTemplate::New(SetQuerySuggestion); |
| 264 } else if (name->Equals(v8::String::New( | 270 } else if (name->Equals(v8::String::New( |
| 265 "SetQuerySuggestionFromAutocompleteResult"))) { | 271 "SetQuerySuggestionFromAutocompleteResult"))) { |
| 266 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); | 272 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); |
| 267 } else if (name->Equals(v8::String::New("SetQuery"))) { | 273 } else if (name->Equals(v8::String::New("SetQuery"))) { |
| 268 return v8::FunctionTemplate::New(SetQuery); | 274 return v8::FunctionTemplate::New(SetQuery); |
| 269 } else if (name->Equals(v8::String::New("SetQueryFromAutocompleteResult"))) { | 275 } else if (name->Equals(v8::String::New("SetQueryFromAutocompleteResult"))) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } | 424 } |
| 419 // Navigate the main frame. | 425 // Navigate the main frame. |
| 420 if (destination_url.is_valid()) { | 426 if (destination_url.is_valid()) { |
| 421 WebKit::WebURLRequest request(destination_url); | 427 WebKit::WebURLRequest request(destination_url); |
| 422 render_view->GetWebView()->mainFrame()->loadRequest(request); | 428 render_view->GetWebView()->mainFrame()->loadRequest(request); |
| 423 } | 429 } |
| 424 return v8::Undefined(); | 430 return v8::Undefined(); |
| 425 } | 431 } |
| 426 | 432 |
| 427 // static | 433 // static |
| 434 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetHasCustomLogo( |
| 435 const v8::Arguments& args) { |
| 436 if (args.Length() == 1 && args[0]->IsBoolean()) { |
| 437 if (content::RenderView* render_view = GetRenderView()) |
| 438 SearchBox::Get(render_view)->SetHasCustomLogo(args[0]->BooleanValue()); |
| 439 } |
| 440 return v8::Undefined(); |
| 441 } |
| 442 |
| 443 // static |
| 428 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( | 444 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( |
| 429 const v8::Arguments& args) { | 445 const v8::Arguments& args) { |
| 430 std::vector<InstantSuggestion> suggestions; | 446 std::vector<InstantSuggestion> suggestions; |
| 431 | 447 |
| 432 if (args.Length() && args[0]->IsObject()) { | 448 if (args.Length() && args[0]->IsObject()) { |
| 433 v8::Handle<v8::Object> suggestion_json = args[0]->ToObject(); | 449 v8::Handle<v8::Object> suggestion_json = args[0]->ToObject(); |
| 434 | 450 |
| 435 InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW; | 451 InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW; |
| 436 InstantSuggestionType type = INSTANT_SUGGESTION_SEARCH; | 452 InstantSuggestionType type = INSTANT_SUGGESTION_SEARCH; |
| 437 v8::Handle<v8::Value> complete_value = | 453 v8::Handle<v8::Value> complete_value = |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 | 701 |
| 686 // static | 702 // static |
| 687 v8::Extension* SearchBoxExtension::Get() { | 703 v8::Extension* SearchBoxExtension::Get() { |
| 688 const base::StringPiece code = | 704 const base::StringPiece code = |
| 689 ResourceBundle::GetSharedInstance().GetRawDataResource( | 705 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 690 IDR_SEARCHBOX_API, ui::SCALE_FACTOR_NONE); | 706 IDR_SEARCHBOX_API, ui::SCALE_FACTOR_NONE); |
| 691 return new SearchBoxExtensionWrapper(code); | 707 return new SearchBoxExtensionWrapper(code); |
| 692 } | 708 } |
| 693 | 709 |
| 694 } // namespace extensions_v8 | 710 } // namespace extensions_v8 |
| OLD | NEW |