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/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 // Gets whether the browser is capturing key strokes. | 287 // Gets whether the browser is capturing key strokes. |
| 288 static v8::Handle<v8::Value> IsKeyCaptureEnabled(const v8::Arguments& args); | 288 static v8::Handle<v8::Value> IsKeyCaptureEnabled(const v8::Arguments& args); |
| 289 | 289 |
| 290 // Gets the font family of the text in the omnibox. | 290 // Gets the font family of the text in the omnibox. |
| 291 static v8::Handle<v8::Value> GetFont(const v8::Arguments& args); | 291 static v8::Handle<v8::Value> GetFont(const v8::Arguments& args); |
| 292 | 292 |
| 293 // Gets the font size of the text in the omnibox. | 293 // Gets the font size of the text in the omnibox. |
| 294 static v8::Handle<v8::Value> GetFontSize(const v8::Arguments& args); | 294 static v8::Handle<v8::Value> GetFontSize(const v8::Arguments& args); |
| 295 | 295 |
| 296 // Navigates the window to a URL represented by either a URL string or a | 296 // Navigates the window to a URL represented by either a URL string or a |
| 297 // restricted ID. | 297 // restricted ID. The two variants handle restricted IDs in their |
| 298 // respective namespaces. | |
| 299 static v8::Handle<v8::Value> NavigateSearchBox(const v8::Arguments& args); | |
| 300 static v8::Handle<v8::Value> NavigateNewTabPage(const v8::Arguments& args); | |
| 301 // DEPRECATED: TODO(sreeram): Remove when google.com no longer uses this. | |
| 298 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args); | 302 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args); |
| 299 | 303 |
| 300 // Sets ordered suggestions. Valid for current |value|. | 304 // Sets ordered suggestions. Valid for current |value|. |
| 301 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); | 305 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); |
| 302 | 306 |
| 303 // Sets the text to be autocompleted into the search box. | 307 // Sets the text to be autocompleted into the search box. |
| 304 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args); | 308 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args); |
| 305 | 309 |
| 306 // Like |SetQuerySuggestion| but uses a restricted ID to identify the text. | 310 // Like |SetQuerySuggestion| but uses a restricted ID to identify the text. |
|
David Black
2013/03/11 20:44:46
Please find-replace all instances of "restricted I
sreeram
2013/03/11 21:14:04
Done.
| |
| 307 static v8::Handle<v8::Value> SetQuerySuggestionFromAutocompleteResult( | 311 static v8::Handle<v8::Value> SetQuerySuggestionFromAutocompleteResult( |
| 308 const v8::Arguments& args); | 312 const v8::Arguments& args); |
| 309 | 313 |
| 310 // Sets the search box text, completely replacing what the user typed. | 314 // Sets the search box text, completely replacing what the user typed. |
| 311 static v8::Handle<v8::Value> SetQuery(const v8::Arguments& args); | 315 static v8::Handle<v8::Value> SetQuery(const v8::Arguments& args); |
| 312 | 316 |
| 313 // Like |SetQuery| but uses a restricted ID to identify the text. | 317 // Like |SetQuery| but uses a restricted ID to identify the text. |
| 314 static v8::Handle<v8::Value> SetQueryFromAutocompleteResult( | 318 static v8::Handle<v8::Value> SetQueryFromAutocompleteResult( |
| 315 const v8::Arguments& args); | 319 const v8::Arguments& args); |
| 316 | 320 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 if (name->Equals(v8::String::New("GetDisplayInstantResults"))) | 380 if (name->Equals(v8::String::New("GetDisplayInstantResults"))) |
| 377 return v8::FunctionTemplate::New(GetDisplayInstantResults); | 381 return v8::FunctionTemplate::New(GetDisplayInstantResults); |
| 378 if (name->Equals(v8::String::New("GetThemeBackgroundInfo"))) | 382 if (name->Equals(v8::String::New("GetThemeBackgroundInfo"))) |
| 379 return v8::FunctionTemplate::New(GetThemeBackgroundInfo); | 383 return v8::FunctionTemplate::New(GetThemeBackgroundInfo); |
| 380 if (name->Equals(v8::String::New("IsKeyCaptureEnabled"))) | 384 if (name->Equals(v8::String::New("IsKeyCaptureEnabled"))) |
| 381 return v8::FunctionTemplate::New(IsKeyCaptureEnabled); | 385 return v8::FunctionTemplate::New(IsKeyCaptureEnabled); |
| 382 if (name->Equals(v8::String::New("GetFont"))) | 386 if (name->Equals(v8::String::New("GetFont"))) |
| 383 return v8::FunctionTemplate::New(GetFont); | 387 return v8::FunctionTemplate::New(GetFont); |
| 384 if (name->Equals(v8::String::New("GetFontSize"))) | 388 if (name->Equals(v8::String::New("GetFontSize"))) |
| 385 return v8::FunctionTemplate::New(GetFontSize); | 389 return v8::FunctionTemplate::New(GetFontSize); |
| 390 if (name->Equals(v8::String::New("NavigateSearchBox"))) | |
| 391 return v8::FunctionTemplate::New(NavigateSearchBox); | |
| 392 if (name->Equals(v8::String::New("NavigateNewTabPage"))) | |
| 393 return v8::FunctionTemplate::New(NavigateNewTabPage); | |
| 386 if (name->Equals(v8::String::New("NavigateContentWindow"))) | 394 if (name->Equals(v8::String::New("NavigateContentWindow"))) |
| 387 return v8::FunctionTemplate::New(NavigateContentWindow); | 395 return v8::FunctionTemplate::New(NavigateContentWindow); |
| 388 if (name->Equals(v8::String::New("SetSuggestions"))) | 396 if (name->Equals(v8::String::New("SetSuggestions"))) |
| 389 return v8::FunctionTemplate::New(SetSuggestions); | 397 return v8::FunctionTemplate::New(SetSuggestions); |
| 390 if (name->Equals(v8::String::New("SetQuerySuggestion"))) | 398 if (name->Equals(v8::String::New("SetQuerySuggestion"))) |
| 391 return v8::FunctionTemplate::New(SetQuerySuggestion); | 399 return v8::FunctionTemplate::New(SetQuerySuggestion); |
| 392 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) | 400 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) |
| 393 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); | 401 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); |
| 394 if (name->Equals(v8::String::New("SetQuery"))) | 402 if (name->Equals(v8::String::New("SetQuery"))) |
| 395 return v8::FunctionTemplate::New(SetQuery); | 403 return v8::FunctionTemplate::New(SetQuery); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 673 // static | 681 // static |
| 674 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetFontSize( | 682 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetFontSize( |
| 675 const v8::Arguments& args) { | 683 const v8::Arguments& args) { |
| 676 content::RenderView* render_view = GetRenderView(); | 684 content::RenderView* render_view = GetRenderView(); |
| 677 if (!render_view) return v8::Undefined(); | 685 if (!render_view) return v8::Undefined(); |
| 678 | 686 |
| 679 return v8::Uint32::New(SearchBox::Get(render_view)->omnibox_font_size()); | 687 return v8::Uint32::New(SearchBox::Get(render_view)->omnibox_font_size()); |
| 680 } | 688 } |
| 681 | 689 |
| 682 // static | 690 // static |
| 683 v8::Handle<v8::Value> SearchBoxExtensionWrapper::NavigateContentWindow( | 691 v8::Handle<v8::Value> SearchBoxExtensionWrapper::NavigateSearchBox( |
| 684 const v8::Arguments& args) { | 692 const v8::Arguments& args) { |
| 685 content::RenderView* render_view = GetRenderView(); | 693 content::RenderView* render_view = GetRenderView(); |
| 686 if (!render_view || !args.Length()) return v8::Undefined(); | 694 if (!render_view || !args.Length()) return v8::Undefined(); |
| 687 | 695 |
| 688 GURL destination_url; | 696 GURL destination_url; |
| 689 content::PageTransition transition = content::PAGE_TRANSITION_TYPED; | 697 content::PageTransition transition = content::PAGE_TRANSITION_TYPED; |
| 690 if (args[0]->IsNumber()) { | 698 if (args[0]->IsNumber()) { |
| 691 const InstantAutocompleteResult* result = SearchBox::Get(render_view)-> | 699 const InstantAutocompleteResult* result = SearchBox::Get(render_view)-> |
| 692 GetAutocompleteResultWithId(args[0]->Uint32Value()); | 700 GetAutocompleteResultWithId(args[0]->Uint32Value()); |
| 693 if (result) { | 701 if (result) { |
| 694 destination_url = GURL(result->destination_url); | 702 destination_url = GURL(result->destination_url); |
| 695 transition = result->transition; | 703 transition = result->transition; |
| 696 } | 704 } |
| 697 } else { | 705 } else { |
| 698 destination_url = GURL(V8ValueToUTF16(args[0])); | 706 destination_url = GURL(V8ValueToUTF16(args[0])); |
| 699 } | 707 } |
| 700 | 708 |
| 709 DVLOG(1) << render_view << " NavigateSearchBox: " << destination_url; | |
| 710 | |
| 701 // Navigate the main frame. | 711 // Navigate the main frame. |
| 702 if (destination_url.is_valid()) { | 712 if (destination_url.is_valid()) { |
| 703 WindowOpenDisposition disposition = CURRENT_TAB; | 713 WindowOpenDisposition disposition = CURRENT_TAB; |
| 704 if (args[1]->Uint32Value() == 2) | 714 if (args[1]->Uint32Value() == 2) |
| 705 disposition = NEW_BACKGROUND_TAB; | 715 disposition = NEW_BACKGROUND_TAB; |
| 706 SearchBox::Get(render_view)->NavigateToURL( | 716 SearchBox::Get(render_view)->NavigateToURL( |
| 707 destination_url, transition, disposition); | 717 destination_url, transition, disposition); |
| 708 } | 718 } |
| 709 return v8::Undefined(); | 719 return v8::Undefined(); |
| 710 } | 720 } |
| 711 | 721 |
| 712 // static | 722 // static |
| 723 v8::Handle<v8::Value> SearchBoxExtensionWrapper::NavigateNewTabPage( | |
| 724 const v8::Arguments& args) { | |
| 725 content::RenderView* render_view = GetRenderView(); | |
| 726 if (!render_view || !args.Length()) return v8::Undefined(); | |
| 727 | |
| 728 GURL destination_url; | |
| 729 content::PageTransition transition = content::PAGE_TRANSITION_TYPED; | |
| 730 if (args[0]->IsNumber()) { | |
| 731 destination_url = GURL(SearchBox::Get(render_view)->RestrictedIdToURL( | |
| 732 args[0]->Uint32Value())); | |
| 733 } else { | |
| 734 destination_url = GURL(V8ValueToUTF16(args[0])); | |
| 735 } | |
| 736 | |
| 737 DVLOG(1) << render_view << " NavigateNewTabPage: " << destination_url; | |
| 738 | |
| 739 // Navigate the main frame. | |
| 740 if (destination_url.is_valid()) { | |
| 741 WindowOpenDisposition disposition = CURRENT_TAB; | |
| 742 if (args[1]->Uint32Value() == 2) | |
| 743 disposition = NEW_BACKGROUND_TAB; | |
| 744 SearchBox::Get(render_view)->NavigateToURL( | |
| 745 destination_url, transition, disposition); | |
| 746 } | |
| 747 return v8::Undefined(); | |
| 748 } | |
| 749 | |
| 750 // static | |
| 751 v8::Handle<v8::Value> SearchBoxExtensionWrapper::NavigateContentWindow( | |
| 752 const v8::Arguments& args) { | |
| 753 content::RenderView* render_view = GetRenderView(); | |
| 754 if (!render_view || !args.Length()) return v8::Undefined(); | |
| 755 | |
| 756 DVLOG(1) << render_view << " NavigateContentWindow; query=" | |
| 757 << SearchBox::Get(render_view)->query(); | |
| 758 | |
| 759 if (SearchBox::Get(render_view)->query().empty() && | |
|
David Black
2013/03/11 20:44:46
Oh geez this is hacky. I guess it's going away as
sreeram
2013/03/11 21:14:04
Done.
| |
| 760 !SearchBox::Get(render_view)->verbatim()) | |
| 761 return NavigateNewTabPage(args); | |
| 762 return NavigateSearchBox(args); | |
| 763 } | |
| 764 | |
| 765 // static | |
| 713 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( | 766 v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( |
| 714 const v8::Arguments& args) { | 767 const v8::Arguments& args) { |
| 715 content::RenderView* render_view = GetRenderView(); | 768 content::RenderView* render_view = GetRenderView(); |
| 716 if (!render_view || !args.Length()) return v8::Undefined(); | 769 if (!render_view || !args.Length()) return v8::Undefined(); |
| 717 | 770 |
| 718 DVLOG(1) << render_view << " SetSuggestions"; | 771 DVLOG(1) << render_view << " SetSuggestions"; |
| 719 v8::Handle<v8::Object> suggestion_json = args[0]->ToObject(); | 772 v8::Handle<v8::Object> suggestion_json = args[0]->ToObject(); |
| 720 | 773 |
| 721 InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW; | 774 InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW; |
| 722 InstantSuggestionType type = INSTANT_SUGGESTION_SEARCH; | 775 InstantSuggestionType type = INSTANT_SUGGESTION_SEARCH; |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1067 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { | 1120 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { |
| 1068 Dispatch(frame, kDispatchThemeChangeEventScript); | 1121 Dispatch(frame, kDispatchThemeChangeEventScript); |
| 1069 } | 1122 } |
| 1070 | 1123 |
| 1071 // static | 1124 // static |
| 1072 void SearchBoxExtension::DispatchMostVisitedChanged( | 1125 void SearchBoxExtension::DispatchMostVisitedChanged( |
| 1073 WebKit::WebFrame* frame) { | 1126 WebKit::WebFrame* frame) { |
| 1074 Dispatch(frame, kDispatchMostVisitedChangedScript); | 1127 Dispatch(frame, kDispatchMostVisitedChangedScript); |
| 1075 } | 1128 } |
| 1076 } // namespace extensions_v8 | 1129 } // namespace extensions_v8 |
| OLD | NEW |