| 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 "if (window.chrome &&" | 342 "if (window.chrome &&" |
| 343 " window.chrome.embeddedSearch &&" | 343 " window.chrome.embeddedSearch &&" |
| 344 " window.chrome.embeddedSearch.searchBox &&" | 344 " window.chrome.embeddedSearch.searchBox &&" |
| 345 " window.chrome.embeddedSearch.searchBox.onkeycapturechange &&" | 345 " window.chrome.embeddedSearch.searchBox.onkeycapturechange &&" |
| 346 " typeof window.chrome.embeddedSearch.searchBox.onkeycapturechange ==" | 346 " typeof window.chrome.embeddedSearch.searchBox.onkeycapturechange ==" |
| 347 " 'function') {" | 347 " 'function') {" |
| 348 " window.chrome.embeddedSearch.searchBox.onkeycapturechange();" | 348 " window.chrome.embeddedSearch.searchBox.onkeycapturechange();" |
| 349 " true;" | 349 " true;" |
| 350 "}"; | 350 "}"; |
| 351 | 351 |
| 352 static const char kDispatchMarginChangeEventScript[] = | |
| 353 "if (window.chrome &&" | |
| 354 " window.chrome.embeddedSearch &&" | |
| 355 " window.chrome.embeddedSearch.searchBox &&" | |
| 356 " window.chrome.embeddedSearch.searchBox.onmarginchange &&" | |
| 357 " typeof window.chrome.embeddedSearch.searchBox.onmarginchange ==" | |
| 358 " 'function') {" | |
| 359 " window.chrome.embeddedSearch.searchBox.onmarginchange();" | |
| 360 " true;" | |
| 361 "}"; | |
| 362 | |
| 363 static const char kDispatchMostVisitedChangedScript[] = | 352 static const char kDispatchMostVisitedChangedScript[] = |
| 364 "if (window.chrome &&" | 353 "if (window.chrome &&" |
| 365 " window.chrome.embeddedSearch &&" | 354 " window.chrome.embeddedSearch &&" |
| 366 " window.chrome.embeddedSearch.newTabPage &&" | 355 " window.chrome.embeddedSearch.newTabPage &&" |
| 367 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange &&" | 356 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange &&" |
| 368 " typeof window.chrome.embeddedSearch.newTabPage.onmostvisitedchange ==" | 357 " typeof window.chrome.embeddedSearch.newTabPage.onmostvisitedchange ==" |
| 369 " 'function') {" | 358 " 'function') {" |
| 370 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange();" | 359 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange();" |
| 371 " true;" | 360 " true;" |
| 372 "}"; | 361 "}"; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 // Gets the submitted value of the user's search query. | 444 // Gets the submitted value of the user's search query. |
| 456 static void GetQuery(const v8::FunctionCallbackInfo<v8::Value>& args); | 445 static void GetQuery(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 457 | 446 |
| 458 // Returns true if the Searchbox itself is oriented right-to-left. | 447 // Returns true if the Searchbox itself is oriented right-to-left. |
| 459 static void GetRightToLeft(const v8::FunctionCallbackInfo<v8::Value>& args); | 448 static void GetRightToLeft(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 460 | 449 |
| 461 // Gets the Embedded Search request params. Used for logging purposes. | 450 // Gets the Embedded Search request params. Used for logging purposes. |
| 462 static void GetSearchRequestParams( | 451 static void GetSearchRequestParams( |
| 463 const v8::FunctionCallbackInfo<v8::Value>& args); | 452 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 464 | 453 |
| 465 // Gets the start-edge margin to use with extended Instant. | |
| 466 static void GetStartMargin(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 467 | |
| 468 // Gets the current top suggestion to prefetch search results. | 454 // Gets the current top suggestion to prefetch search results. |
| 469 static void GetSuggestionToPrefetch( | 455 static void GetSuggestionToPrefetch( |
| 470 const v8::FunctionCallbackInfo<v8::Value>& args); | 456 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 471 | 457 |
| 472 // Gets the background info of the theme currently adopted by browser. | 458 // Gets the background info of the theme currently adopted by browser. |
| 473 // Call only when overlay is showing NTP page. | 459 // Call only when overlay is showing NTP page. |
| 474 static void GetThemeBackgroundInfo( | 460 static void GetThemeBackgroundInfo( |
| 475 const v8::FunctionCallbackInfo<v8::Value>& args); | 461 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 476 | 462 |
| 477 // Gets whether the omnibox has focus or not. | 463 // Gets whether the omnibox has focus or not. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 void SearchBoxExtension::DispatchInputStart(blink::WebFrame* frame) { | 566 void SearchBoxExtension::DispatchInputStart(blink::WebFrame* frame) { |
| 581 Dispatch(frame, kDispatchInputStartScript); | 567 Dispatch(frame, kDispatchInputStartScript); |
| 582 } | 568 } |
| 583 | 569 |
| 584 // static | 570 // static |
| 585 void SearchBoxExtension::DispatchKeyCaptureChange(blink::WebFrame* frame) { | 571 void SearchBoxExtension::DispatchKeyCaptureChange(blink::WebFrame* frame) { |
| 586 Dispatch(frame, kDispatchKeyCaptureChangeScript); | 572 Dispatch(frame, kDispatchKeyCaptureChangeScript); |
| 587 } | 573 } |
| 588 | 574 |
| 589 // static | 575 // static |
| 590 void SearchBoxExtension::DispatchMarginChange(blink::WebFrame* frame) { | |
| 591 Dispatch(frame, kDispatchMarginChangeEventScript); | |
| 592 } | |
| 593 | |
| 594 // static | |
| 595 void SearchBoxExtension::DispatchMostVisitedChanged( | 576 void SearchBoxExtension::DispatchMostVisitedChanged( |
| 596 blink::WebFrame* frame) { | 577 blink::WebFrame* frame) { |
| 597 Dispatch(frame, kDispatchMostVisitedChangedScript); | 578 Dispatch(frame, kDispatchMostVisitedChangedScript); |
| 598 } | 579 } |
| 599 | 580 |
| 600 // static | 581 // static |
| 601 void SearchBoxExtension::DispatchSubmit(blink::WebFrame* frame) { | 582 void SearchBoxExtension::DispatchSubmit(blink::WebFrame* frame) { |
| 602 Dispatch(frame, kDispatchSubmitEventScript); | 583 Dispatch(frame, kDispatchSubmitEventScript); |
| 603 } | 584 } |
| 604 | 585 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems"))) | 619 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems"))) |
| 639 return v8::FunctionTemplate::New(isolate, GetMostVisitedItems); | 620 return v8::FunctionTemplate::New(isolate, GetMostVisitedItems); |
| 640 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItemData"))) | 621 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItemData"))) |
| 641 return v8::FunctionTemplate::New(isolate, GetMostVisitedItemData); | 622 return v8::FunctionTemplate::New(isolate, GetMostVisitedItemData); |
| 642 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetQuery"))) | 623 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetQuery"))) |
| 643 return v8::FunctionTemplate::New(isolate, GetQuery); | 624 return v8::FunctionTemplate::New(isolate, GetQuery); |
| 644 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetRightToLeft"))) | 625 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetRightToLeft"))) |
| 645 return v8::FunctionTemplate::New(isolate, GetRightToLeft); | 626 return v8::FunctionTemplate::New(isolate, GetRightToLeft); |
| 646 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetSearchRequestParams"))) | 627 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetSearchRequestParams"))) |
| 647 return v8::FunctionTemplate::New(isolate, GetSearchRequestParams); | 628 return v8::FunctionTemplate::New(isolate, GetSearchRequestParams); |
| 648 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetStartMargin"))) | |
| 649 return v8::FunctionTemplate::New(isolate, GetStartMargin); | |
| 650 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetSuggestionToPrefetch"))) | 629 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetSuggestionToPrefetch"))) |
| 651 return v8::FunctionTemplate::New(isolate, GetSuggestionToPrefetch); | 630 return v8::FunctionTemplate::New(isolate, GetSuggestionToPrefetch); |
| 652 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetThemeBackgroundInfo"))) | 631 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetThemeBackgroundInfo"))) |
| 653 return v8::FunctionTemplate::New(isolate, GetThemeBackgroundInfo); | 632 return v8::FunctionTemplate::New(isolate, GetThemeBackgroundInfo); |
| 654 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsFocused"))) | 633 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsFocused"))) |
| 655 return v8::FunctionTemplate::New(isolate, IsFocused); | 634 return v8::FunctionTemplate::New(isolate, IsFocused); |
| 656 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsInputInProgress"))) | 635 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsInputInProgress"))) |
| 657 return v8::FunctionTemplate::New(isolate, IsInputInProgress); | 636 return v8::FunctionTemplate::New(isolate, IsInputInProgress); |
| 658 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsKeyCaptureEnabled"))) | 637 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsKeyCaptureEnabled"))) |
| 659 return v8::FunctionTemplate::New(isolate, IsKeyCaptureEnabled); | 638 return v8::FunctionTemplate::New(isolate, IsKeyCaptureEnabled); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 UTF16ToV8String(isolate, params.input_encoding)); | 862 UTF16ToV8String(isolate, params.input_encoding)); |
| 884 } | 863 } |
| 885 if (!params.assisted_query_stats.empty()) { | 864 if (!params.assisted_query_stats.empty()) { |
| 886 data->Set(v8::String::NewFromUtf8(isolate, kAssistedQueryStatsKey), | 865 data->Set(v8::String::NewFromUtf8(isolate, kAssistedQueryStatsKey), |
| 887 UTF16ToV8String(isolate, params.assisted_query_stats)); | 866 UTF16ToV8String(isolate, params.assisted_query_stats)); |
| 888 } | 867 } |
| 889 args.GetReturnValue().Set(data); | 868 args.GetReturnValue().Set(data); |
| 890 } | 869 } |
| 891 | 870 |
| 892 // static | 871 // static |
| 893 void SearchBoxExtensionWrapper::GetStartMargin( | |
| 894 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 895 content::RenderView* render_view = GetRenderView(); | |
| 896 if (!render_view) return; | |
| 897 args.GetReturnValue().Set(static_cast<int32_t>( | |
| 898 SearchBox::Get(render_view)->start_margin())); | |
| 899 } | |
| 900 | |
| 901 // static | |
| 902 void SearchBoxExtensionWrapper::GetSuggestionToPrefetch( | 872 void SearchBoxExtensionWrapper::GetSuggestionToPrefetch( |
| 903 const v8::FunctionCallbackInfo<v8::Value>& args) { | 873 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 904 content::RenderView* render_view = GetRenderView(); | 874 content::RenderView* render_view = GetRenderView(); |
| 905 if (!render_view) return; | 875 if (!render_view) return; |
| 906 | 876 |
| 907 const InstantSuggestion& suggestion = | 877 const InstantSuggestion& suggestion = |
| 908 SearchBox::Get(render_view)->suggestion(); | 878 SearchBox::Get(render_view)->suggestion(); |
| 909 v8::Isolate* isolate = args.GetIsolate(); | 879 v8::Isolate* isolate = args.GetIsolate(); |
| 910 v8::Local<v8::Object> data = v8::Object::New(isolate); | 880 v8::Local<v8::Object> data = v8::Object::New(isolate); |
| 911 data->Set(v8::String::NewFromUtf8(isolate, "text"), | 881 data->Set(v8::String::NewFromUtf8(isolate, "text"), |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 if (!render_view) return; | 1240 if (!render_view) return; |
| 1271 | 1241 |
| 1272 bool display_instant_results = | 1242 bool display_instant_results = |
| 1273 SearchBox::Get(render_view)->display_instant_results(); | 1243 SearchBox::Get(render_view)->display_instant_results(); |
| 1274 DVLOG(1) << render_view << " GetDisplayInstantResults" << | 1244 DVLOG(1) << render_view << " GetDisplayInstantResults" << |
| 1275 display_instant_results; | 1245 display_instant_results; |
| 1276 args.GetReturnValue().Set(display_instant_results); | 1246 args.GetReturnValue().Set(display_instant_results); |
| 1277 } | 1247 } |
| 1278 | 1248 |
| 1279 } // namespace extensions_v8 | 1249 } // namespace extensions_v8 |
| OLD | NEW |