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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 "if (window.chrome &&" | 397 "if (window.chrome &&" |
398 " window.chrome.embeddedSearch &&" | 398 " window.chrome.embeddedSearch &&" |
399 " window.chrome.embeddedSearch.newTabPage &&" | 399 " window.chrome.embeddedSearch.newTabPage &&" |
400 " window.chrome.embeddedSearch.newTabPage.onthemechange &&" | 400 " window.chrome.embeddedSearch.newTabPage.onthemechange &&" |
401 " typeof window.chrome.embeddedSearch.newTabPage.onthemechange ==" | 401 " typeof window.chrome.embeddedSearch.newTabPage.onthemechange ==" |
402 " 'function') {" | 402 " 'function') {" |
403 " window.chrome.embeddedSearch.newTabPage.onthemechange();" | 403 " window.chrome.embeddedSearch.newTabPage.onthemechange();" |
404 " true;" | 404 " true;" |
405 "}"; | 405 "}"; |
406 | 406 |
| 407 static const char kDispatchToggleVoiceSearchScript[] = |
| 408 "if (window.chrome &&" |
| 409 " window.chrome.embeddedSearch &&" |
| 410 " window.chrome.embeddedSearch.searchBox &&" |
| 411 " window.chrome.embeddedSearch.searchBox.ontogglevoicesearch &&" |
| 412 " typeof window.chrome.embeddedSearch.searchBox.ontogglevoicesearch ==" |
| 413 " 'function') {" |
| 414 " window.chrome.embeddedSearch.searchBox.ontogglevoicesearch();" |
| 415 " true;" |
| 416 "}"; |
| 417 |
407 // ---------------------------------------------------------------------------- | 418 // ---------------------------------------------------------------------------- |
408 | 419 |
409 class SearchBoxExtensionWrapper : public v8::Extension { | 420 class SearchBoxExtensionWrapper : public v8::Extension { |
410 public: | 421 public: |
411 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); | 422 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); |
412 | 423 |
413 // Allows v8's javascript code to call the native functions defined | 424 // Allows v8's javascript code to call the native functions defined |
414 // in this class for window.chrome. | 425 // in this class for window.chrome. |
415 v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( | 426 v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
416 v8::Isolate*, | 427 v8::Isolate*, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 const v8::FunctionCallbackInfo<v8::Value>& args); | 508 const v8::FunctionCallbackInfo<v8::Value>& args); |
498 | 509 |
499 // Navigates the window to a URL represented by either a URL string or a | 510 // Navigates the window to a URL represented by either a URL string or a |
500 // restricted ID. | 511 // restricted ID. |
501 static void NavigateContentWindow( | 512 static void NavigateContentWindow( |
502 const v8::FunctionCallbackInfo<v8::Value>& args); | 513 const v8::FunctionCallbackInfo<v8::Value>& args); |
503 | 514 |
504 // Pastes provided value or clipboard's content into the omnibox. | 515 // Pastes provided value or clipboard's content into the omnibox. |
505 static void Paste(const v8::FunctionCallbackInfo<v8::Value>& args); | 516 static void Paste(const v8::FunctionCallbackInfo<v8::Value>& args); |
506 | 517 |
| 518 // Indicates whether the page supports voice search. |
| 519 static void SetVoiceSearchSupported( |
| 520 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 521 |
507 // Start capturing user key strokes. | 522 // Start capturing user key strokes. |
508 static void StartCapturingKeyStrokes( | 523 static void StartCapturingKeyStrokes( |
509 const v8::FunctionCallbackInfo<v8::Value>& args); | 524 const v8::FunctionCallbackInfo<v8::Value>& args); |
510 | 525 |
511 // Stop capturing user key strokes. | 526 // Stop capturing user key strokes. |
512 static void StopCapturingKeyStrokes( | 527 static void StopCapturingKeyStrokes( |
513 const v8::FunctionCallbackInfo<v8::Value>& args); | 528 const v8::FunctionCallbackInfo<v8::Value>& args); |
514 | 529 |
515 // Undoes the deletion of all Most Visited itens. | 530 // Undoes the deletion of all Most Visited itens. |
516 static void UndoAllMostVisitedDeletions( | 531 static void UndoAllMostVisitedDeletions( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 // static | 620 // static |
606 void SearchBoxExtension::DispatchSuggestionChange(blink::WebFrame* frame) { | 621 void SearchBoxExtension::DispatchSuggestionChange(blink::WebFrame* frame) { |
607 Dispatch(frame, kDispatchSuggestionChangeEventScript); | 622 Dispatch(frame, kDispatchSuggestionChangeEventScript); |
608 } | 623 } |
609 | 624 |
610 // static | 625 // static |
611 void SearchBoxExtension::DispatchThemeChange(blink::WebFrame* frame) { | 626 void SearchBoxExtension::DispatchThemeChange(blink::WebFrame* frame) { |
612 Dispatch(frame, kDispatchThemeChangeEventScript); | 627 Dispatch(frame, kDispatchThemeChangeEventScript); |
613 } | 628 } |
614 | 629 |
| 630 // static |
| 631 void SearchBoxExtension::DispatchToggleVoiceSearch( |
| 632 blink::WebFrame* frame) { |
| 633 Dispatch(frame, kDispatchToggleVoiceSearchScript); |
| 634 } |
| 635 |
615 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( | 636 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( |
616 const base::StringPiece& code) | 637 const base::StringPiece& code) |
617 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { | 638 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { |
618 } | 639 } |
619 | 640 |
620 v8::Local<v8::FunctionTemplate> | 641 v8::Local<v8::FunctionTemplate> |
621 SearchBoxExtensionWrapper::GetNativeFunctionTemplate( | 642 SearchBoxExtensionWrapper::GetNativeFunctionTemplate( |
622 v8::Isolate* isolate, | 643 v8::Isolate* isolate, |
623 v8::Local<v8::String> name) { | 644 v8::Local<v8::String> name) { |
624 if (name->Equals( | 645 if (name->Equals( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 return v8::FunctionTemplate::New(isolate, LogMostVisitedImpression); | 685 return v8::FunctionTemplate::New(isolate, LogMostVisitedImpression); |
665 } | 686 } |
666 if (name->Equals( | 687 if (name->Equals( |
667 v8::String::NewFromUtf8(isolate, "LogMostVisitedNavigation"))) { | 688 v8::String::NewFromUtf8(isolate, "LogMostVisitedNavigation"))) { |
668 return v8::FunctionTemplate::New(isolate, LogMostVisitedNavigation); | 689 return v8::FunctionTemplate::New(isolate, LogMostVisitedNavigation); |
669 } | 690 } |
670 if (name->Equals(v8::String::NewFromUtf8(isolate, "NavigateContentWindow"))) | 691 if (name->Equals(v8::String::NewFromUtf8(isolate, "NavigateContentWindow"))) |
671 return v8::FunctionTemplate::New(isolate, NavigateContentWindow); | 692 return v8::FunctionTemplate::New(isolate, NavigateContentWindow); |
672 if (name->Equals(v8::String::NewFromUtf8(isolate, "Paste"))) | 693 if (name->Equals(v8::String::NewFromUtf8(isolate, "Paste"))) |
673 return v8::FunctionTemplate::New(isolate, Paste); | 694 return v8::FunctionTemplate::New(isolate, Paste); |
| 695 if (name->Equals(v8::String::NewFromUtf8(isolate, "SetVoiceSearchSupported"))) |
| 696 return v8::FunctionTemplate::New(isolate, SetVoiceSearchSupported); |
674 if (name->Equals( | 697 if (name->Equals( |
675 v8::String::NewFromUtf8(isolate, "StartCapturingKeyStrokes"))) | 698 v8::String::NewFromUtf8(isolate, "StartCapturingKeyStrokes"))) |
676 return v8::FunctionTemplate::New(isolate, StartCapturingKeyStrokes); | 699 return v8::FunctionTemplate::New(isolate, StartCapturingKeyStrokes); |
677 if (name->Equals(v8::String::NewFromUtf8(isolate, "StopCapturingKeyStrokes"))) | 700 if (name->Equals(v8::String::NewFromUtf8(isolate, "StopCapturingKeyStrokes"))) |
678 return v8::FunctionTemplate::New(isolate, StopCapturingKeyStrokes); | 701 return v8::FunctionTemplate::New(isolate, StopCapturingKeyStrokes); |
679 if (name->Equals( | 702 if (name->Equals( |
680 v8::String::NewFromUtf8(isolate, "UndoAllMostVisitedDeletions"))) | 703 v8::String::NewFromUtf8(isolate, "UndoAllMostVisitedDeletions"))) |
681 return v8::FunctionTemplate::New(isolate, UndoAllMostVisitedDeletions); | 704 return v8::FunctionTemplate::New(isolate, UndoAllMostVisitedDeletions); |
682 if (name->Equals(v8::String::NewFromUtf8(isolate, "UndoMostVisitedDeletion"))) | 705 if (name->Equals(v8::String::NewFromUtf8(isolate, "UndoMostVisitedDeletion"))) |
683 return v8::FunctionTemplate::New(isolate, UndoMostVisitedDeletion); | 706 return v8::FunctionTemplate::New(isolate, UndoMostVisitedDeletion); |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 void SearchBoxExtensionWrapper::StopCapturingKeyStrokes( | 1253 void SearchBoxExtensionWrapper::StopCapturingKeyStrokes( |
1231 const v8::FunctionCallbackInfo<v8::Value>& args) { | 1254 const v8::FunctionCallbackInfo<v8::Value>& args) { |
1232 content::RenderView* render_view = GetRenderView(); | 1255 content::RenderView* render_view = GetRenderView(); |
1233 if (!render_view) return; | 1256 if (!render_view) return; |
1234 | 1257 |
1235 DVLOG(1) << render_view << " StopCapturingKeyStrokes"; | 1258 DVLOG(1) << render_view << " StopCapturingKeyStrokes"; |
1236 SearchBox::Get(render_view)->StopCapturingKeyStrokes(); | 1259 SearchBox::Get(render_view)->StopCapturingKeyStrokes(); |
1237 } | 1260 } |
1238 | 1261 |
1239 // static | 1262 // static |
| 1263 void SearchBoxExtensionWrapper::SetVoiceSearchSupported( |
| 1264 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 1265 content::RenderView* render_view = GetRenderView(); |
| 1266 if (!render_view) { |
| 1267 return; |
| 1268 } |
| 1269 if (!args.Length()) { |
| 1270 ThrowInvalidParameters(args); |
| 1271 return; |
| 1272 } |
| 1273 |
| 1274 DVLOG(1) << render_view << " SetVoiceSearchSupported"; |
| 1275 SearchBox::Get(render_view)->SetVoiceSearchSupported(args[0]->BooleanValue()); |
| 1276 } |
| 1277 |
| 1278 // static |
1240 void SearchBoxExtensionWrapper::UndoAllMostVisitedDeletions( | 1279 void SearchBoxExtensionWrapper::UndoAllMostVisitedDeletions( |
1241 const v8::FunctionCallbackInfo<v8::Value>& args) { | 1280 const v8::FunctionCallbackInfo<v8::Value>& args) { |
1242 content::RenderView* render_view = GetRenderView(); | 1281 content::RenderView* render_view = GetRenderView(); |
1243 if (!render_view) return; | 1282 if (!render_view) return; |
1244 | 1283 |
1245 DVLOG(1) << render_view << " UndoAllMostVisitedDeletions"; | 1284 DVLOG(1) << render_view << " UndoAllMostVisitedDeletions"; |
1246 SearchBox::Get(render_view)->UndoAllMostVisitedDeletions(); | 1285 SearchBox::Get(render_view)->UndoAllMostVisitedDeletions(); |
1247 } | 1286 } |
1248 | 1287 |
1249 // static | 1288 // static |
(...skipping 20 matching lines...) Expand all Loading... |
1270 if (!render_view) return; | 1309 if (!render_view) return; |
1271 | 1310 |
1272 bool display_instant_results = | 1311 bool display_instant_results = |
1273 SearchBox::Get(render_view)->display_instant_results(); | 1312 SearchBox::Get(render_view)->display_instant_results(); |
1274 DVLOG(1) << render_view << " GetDisplayInstantResults" << | 1313 DVLOG(1) << render_view << " GetDisplayInstantResults" << |
1275 display_instant_results; | 1314 display_instant_results; |
1276 args.GetReturnValue().Set(display_instant_results); | 1315 args.GetReturnValue().Set(display_instant_results); |
1277 } | 1316 } |
1278 | 1317 |
1279 } // namespace extensions_v8 | 1318 } // namespace extensions_v8 |
OLD | NEW |