| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 static void DeleteMostVisitedItem( | 418 static void DeleteMostVisitedItem( |
| 419 const v8::FunctionCallbackInfo<v8::Value>& args); | 419 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 420 | 420 |
| 421 // Focuses the omnibox. | 421 // Focuses the omnibox. |
| 422 static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args); | 422 static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 423 | 423 |
| 424 // Gets whether or not the app launcher is enabled. | 424 // Gets whether or not the app launcher is enabled. |
| 425 static void GetAppLauncherEnabled( | 425 static void GetAppLauncherEnabled( |
| 426 const v8::FunctionCallbackInfo<v8::Value>& args); | 426 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 427 | 427 |
| 428 // Gets the desired navigation behavior from a click event. | |
| 429 static void GetDispositionFromClick( | |
| 430 const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 431 | |
| 432 // Gets Most Visited Items. | 428 // Gets Most Visited Items. |
| 433 static void GetMostVisitedItems( | 429 static void GetMostVisitedItems( |
| 434 const v8::FunctionCallbackInfo<v8::Value>& args); | 430 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 435 | 431 |
| 436 // Gets the raw data for a most visited item including its raw URL. | 432 // Gets the raw data for a most visited item including its raw URL. |
| 437 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin | 433 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin |
| 438 // chrome-search://most-visited can call this function. | 434 // chrome-search://most-visited can call this function. |
| 439 static void GetMostVisitedItemData( | 435 static void GetMostVisitedItemData( |
| 440 const v8::FunctionCallbackInfo<v8::Value>& args); | 436 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 441 | 437 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args); | 469 static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 474 | 470 |
| 475 // Logs an impression on one of the Most Visited tile on the NTP. | 471 // Logs an impression on one of the Most Visited tile on the NTP. |
| 476 static void LogMostVisitedImpression( | 472 static void LogMostVisitedImpression( |
| 477 const v8::FunctionCallbackInfo<v8::Value>& args); | 473 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 478 | 474 |
| 479 // Logs a navigation on one of the Most Visited tile on the NTP. | 475 // Logs a navigation on one of the Most Visited tile on the NTP. |
| 480 static void LogMostVisitedNavigation( | 476 static void LogMostVisitedNavigation( |
| 481 const v8::FunctionCallbackInfo<v8::Value>& args); | 477 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 482 | 478 |
| 483 // Navigates the window to a URL represented by a restricted ID. | |
| 484 static void NavigateContentWindow( | |
| 485 const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 486 | |
| 487 // Pastes provided value or clipboard's content into the omnibox. | 479 // Pastes provided value or clipboard's content into the omnibox. |
| 488 static void Paste(const v8::FunctionCallbackInfo<v8::Value>& args); | 480 static void Paste(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 489 | 481 |
| 490 // Start capturing user key strokes. | 482 // Start capturing user key strokes. |
| 491 static void StartCapturingKeyStrokes( | 483 static void StartCapturingKeyStrokes( |
| 492 const v8::FunctionCallbackInfo<v8::Value>& args); | 484 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 493 | 485 |
| 494 // Stop capturing user key strokes. | 486 // Stop capturing user key strokes. |
| 495 static void StopCapturingKeyStrokes( | 487 static void StopCapturingKeyStrokes( |
| 496 const v8::FunctionCallbackInfo<v8::Value>& args); | 488 const v8::FunctionCallbackInfo<v8::Value>& args); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs); | 596 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs); |
| 605 if (name->Equals( | 597 if (name->Equals( |
| 606 v8::String::NewFromUtf8(isolate, "CheckIsUserSyncingHistory"))) | 598 v8::String::NewFromUtf8(isolate, "CheckIsUserSyncingHistory"))) |
| 607 return v8::FunctionTemplate::New(isolate, CheckIsUserSyncingHistory); | 599 return v8::FunctionTemplate::New(isolate, CheckIsUserSyncingHistory); |
| 608 if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem"))) | 600 if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem"))) |
| 609 return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem); | 601 return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem); |
| 610 if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus"))) | 602 if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus"))) |
| 611 return v8::FunctionTemplate::New(isolate, Focus); | 603 return v8::FunctionTemplate::New(isolate, Focus); |
| 612 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetAppLauncherEnabled"))) | 604 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetAppLauncherEnabled"))) |
| 613 return v8::FunctionTemplate::New(isolate, GetAppLauncherEnabled); | 605 return v8::FunctionTemplate::New(isolate, GetAppLauncherEnabled); |
| 614 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetDispositionFromClick"))) | |
| 615 return v8::FunctionTemplate::New(isolate, GetDispositionFromClick); | |
| 616 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems"))) | 606 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems"))) |
| 617 return v8::FunctionTemplate::New(isolate, GetMostVisitedItems); | 607 return v8::FunctionTemplate::New(isolate, GetMostVisitedItems); |
| 618 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItemData"))) | 608 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItemData"))) |
| 619 return v8::FunctionTemplate::New(isolate, GetMostVisitedItemData); | 609 return v8::FunctionTemplate::New(isolate, GetMostVisitedItemData); |
| 620 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetQuery"))) | 610 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetQuery"))) |
| 621 return v8::FunctionTemplate::New(isolate, GetQuery); | 611 return v8::FunctionTemplate::New(isolate, GetQuery); |
| 622 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetRightToLeft"))) | 612 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetRightToLeft"))) |
| 623 return v8::FunctionTemplate::New(isolate, GetRightToLeft); | 613 return v8::FunctionTemplate::New(isolate, GetRightToLeft); |
| 624 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetSearchRequestParams"))) | 614 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetSearchRequestParams"))) |
| 625 return v8::FunctionTemplate::New(isolate, GetSearchRequestParams); | 615 return v8::FunctionTemplate::New(isolate, GetSearchRequestParams); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 636 if (name->Equals(v8::String::NewFromUtf8(isolate, "LogEvent"))) | 626 if (name->Equals(v8::String::NewFromUtf8(isolate, "LogEvent"))) |
| 637 return v8::FunctionTemplate::New(isolate, LogEvent); | 627 return v8::FunctionTemplate::New(isolate, LogEvent); |
| 638 if (name->Equals( | 628 if (name->Equals( |
| 639 v8::String::NewFromUtf8(isolate, "LogMostVisitedImpression"))) { | 629 v8::String::NewFromUtf8(isolate, "LogMostVisitedImpression"))) { |
| 640 return v8::FunctionTemplate::New(isolate, LogMostVisitedImpression); | 630 return v8::FunctionTemplate::New(isolate, LogMostVisitedImpression); |
| 641 } | 631 } |
| 642 if (name->Equals( | 632 if (name->Equals( |
| 643 v8::String::NewFromUtf8(isolate, "LogMostVisitedNavigation"))) { | 633 v8::String::NewFromUtf8(isolate, "LogMostVisitedNavigation"))) { |
| 644 return v8::FunctionTemplate::New(isolate, LogMostVisitedNavigation); | 634 return v8::FunctionTemplate::New(isolate, LogMostVisitedNavigation); |
| 645 } | 635 } |
| 646 if (name->Equals(v8::String::NewFromUtf8(isolate, "NavigateContentWindow"))) | |
| 647 return v8::FunctionTemplate::New(isolate, NavigateContentWindow); | |
| 648 if (name->Equals(v8::String::NewFromUtf8(isolate, "Paste"))) | 636 if (name->Equals(v8::String::NewFromUtf8(isolate, "Paste"))) |
| 649 return v8::FunctionTemplate::New(isolate, Paste); | 637 return v8::FunctionTemplate::New(isolate, Paste); |
| 650 if (name->Equals( | 638 if (name->Equals( |
| 651 v8::String::NewFromUtf8(isolate, "StartCapturingKeyStrokes"))) | 639 v8::String::NewFromUtf8(isolate, "StartCapturingKeyStrokes"))) |
| 652 return v8::FunctionTemplate::New(isolate, StartCapturingKeyStrokes); | 640 return v8::FunctionTemplate::New(isolate, StartCapturingKeyStrokes); |
| 653 if (name->Equals(v8::String::NewFromUtf8(isolate, "StopCapturingKeyStrokes"))) | 641 if (name->Equals(v8::String::NewFromUtf8(isolate, "StopCapturingKeyStrokes"))) |
| 654 return v8::FunctionTemplate::New(isolate, StopCapturingKeyStrokes); | 642 return v8::FunctionTemplate::New(isolate, StopCapturingKeyStrokes); |
| 655 if (name->Equals( | 643 if (name->Equals( |
| 656 v8::String::NewFromUtf8(isolate, "UndoAllMostVisitedDeletions"))) | 644 v8::String::NewFromUtf8(isolate, "UndoAllMostVisitedDeletions"))) |
| 657 return v8::FunctionTemplate::New(isolate, UndoAllMostVisitedDeletions); | 645 return v8::FunctionTemplate::New(isolate, UndoAllMostVisitedDeletions); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 void SearchBoxExtensionWrapper::GetAppLauncherEnabled( | 721 void SearchBoxExtensionWrapper::GetAppLauncherEnabled( |
| 734 const v8::FunctionCallbackInfo<v8::Value>& args) { | 722 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 735 content::RenderView* render_view = GetRenderView(); | 723 content::RenderView* render_view = GetRenderView(); |
| 736 if (!render_view) return; | 724 if (!render_view) return; |
| 737 | 725 |
| 738 args.GetReturnValue().Set( | 726 args.GetReturnValue().Set( |
| 739 SearchBox::Get(render_view)->app_launcher_enabled()); | 727 SearchBox::Get(render_view)->app_launcher_enabled()); |
| 740 } | 728 } |
| 741 | 729 |
| 742 // static | 730 // static |
| 743 void SearchBoxExtensionWrapper::GetDispositionFromClick( | |
| 744 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 745 content::RenderView* render_view = GetRenderView(); | |
| 746 if (!render_view) return; | |
| 747 | |
| 748 if (args.Length() != 5) { | |
| 749 ThrowInvalidParameters(args); | |
| 750 return; | |
| 751 } | |
| 752 | |
| 753 bool middle_button = args[0]->BooleanValue(); | |
| 754 bool alt_key = args[1]->BooleanValue(); | |
| 755 bool ctrl_key = args[2]->BooleanValue(); | |
| 756 bool meta_key = args[3]->BooleanValue(); | |
| 757 bool shift_key = args[4]->BooleanValue(); | |
| 758 | |
| 759 WindowOpenDisposition disposition = ui::DispositionFromClick(middle_button, | |
| 760 alt_key, | |
| 761 ctrl_key, | |
| 762 meta_key, | |
| 763 shift_key); | |
| 764 v8::Isolate* isolate = args.GetIsolate(); | |
| 765 args.GetReturnValue().Set(v8::Int32::New(isolate, disposition)); | |
| 766 } | |
| 767 | |
| 768 // static | |
| 769 void SearchBoxExtensionWrapper::GetMostVisitedItems( | 731 void SearchBoxExtensionWrapper::GetMostVisitedItems( |
| 770 const v8::FunctionCallbackInfo<v8::Value>& args) { | 732 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 771 content::RenderView* render_view = GetRenderView(); | 733 content::RenderView* render_view = GetRenderView(); |
| 772 if (!render_view) | 734 if (!render_view) |
| 773 return; | 735 return; |
| 774 DVLOG(1) << render_view << " GetMostVisitedItems"; | 736 DVLOG(1) << render_view << " GetMostVisitedItems"; |
| 775 | 737 |
| 776 const SearchBox* search_box = SearchBox::Get(render_view); | 738 const SearchBox* search_box = SearchBox::Get(render_view); |
| 777 | 739 |
| 778 std::vector<InstantMostVisitedItemIDPair> instant_mv_items; | 740 std::vector<InstantMostVisitedItemIDPair> instant_mv_items; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 return; | 1083 return; |
| 1122 } | 1084 } |
| 1123 | 1085 |
| 1124 DVLOG(1) << render_view << " LogMostVisitedNavigation"; | 1086 DVLOG(1) << render_view << " LogMostVisitedNavigation"; |
| 1125 | 1087 |
| 1126 SearchBox::Get(render_view)->LogMostVisitedNavigation( | 1088 SearchBox::Get(render_view)->LogMostVisitedNavigation( |
| 1127 args[0]->IntegerValue(), V8ValueToUTF16(args[1])); | 1089 args[0]->IntegerValue(), V8ValueToUTF16(args[1])); |
| 1128 } | 1090 } |
| 1129 | 1091 |
| 1130 // static | 1092 // static |
| 1131 void SearchBoxExtensionWrapper::NavigateContentWindow( | |
| 1132 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 1133 content::RenderView* render_view = GetRenderView(); | |
| 1134 if (!render_view) return; | |
| 1135 | |
| 1136 if (!args.Length() || !args[0]->IsNumber()) { | |
| 1137 ThrowInvalidParameters(args); | |
| 1138 return; | |
| 1139 } | |
| 1140 | |
| 1141 InstantRestrictedID rid = args[0]->Int32Value(); | |
| 1142 InstantMostVisitedItem item; | |
| 1143 if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID(rid, &item)) | |
| 1144 return; | |
| 1145 | |
| 1146 GURL destination_url = item.url; | |
| 1147 | |
| 1148 DVLOG(1) << render_view << " NavigateContentWindow: " << destination_url; | |
| 1149 | |
| 1150 // Navigate the main frame. Note that the security checks are enforced by the | |
| 1151 // browser process in InstantService::IsValidURLForNavigation(), but some | |
| 1152 // simple checks here are useful for avoiding unnecessary IPCs. | |
| 1153 if (destination_url.is_valid() && | |
| 1154 !destination_url.SchemeIs(url::kJavaScriptScheme)) { | |
| 1155 WindowOpenDisposition disposition = CURRENT_TAB; | |
| 1156 if (args[1]->IsNumber()) { | |
| 1157 disposition = (WindowOpenDisposition) args[1]->Uint32Value(); | |
| 1158 } | |
| 1159 SearchBox::Get(render_view)->NavigateToURL(destination_url, disposition); | |
| 1160 } | |
| 1161 } | |
| 1162 | |
| 1163 // static | |
| 1164 void SearchBoxExtensionWrapper::Paste( | 1093 void SearchBoxExtensionWrapper::Paste( |
| 1165 const v8::FunctionCallbackInfo<v8::Value>& args) { | 1094 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 1166 content::RenderView* render_view = GetRenderView(); | 1095 content::RenderView* render_view = GetRenderView(); |
| 1167 if (!render_view) return; | 1096 if (!render_view) return; |
| 1168 | 1097 |
| 1169 base::string16 text; | 1098 base::string16 text; |
| 1170 if (!args[0]->IsUndefined()) | 1099 if (!args[0]->IsUndefined()) |
| 1171 text = V8ValueToUTF16(args[0]); | 1100 text = V8ValueToUTF16(args[0]); |
| 1172 | 1101 |
| 1173 DVLOG(1) << render_view << " Paste: " << text; | 1102 DVLOG(1) << render_view << " Paste: " << text; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 if (!render_view) return; | 1157 if (!render_view) return; |
| 1229 | 1158 |
| 1230 bool display_instant_results = | 1159 bool display_instant_results = |
| 1231 SearchBox::Get(render_view)->display_instant_results(); | 1160 SearchBox::Get(render_view)->display_instant_results(); |
| 1232 DVLOG(1) << render_view << " GetDisplayInstantResults" << | 1161 DVLOG(1) << render_view << " GetDisplayInstantResults" << |
| 1233 display_instant_results; | 1162 display_instant_results; |
| 1234 args.GetReturnValue().Set(display_instant_results); | 1163 args.GetReturnValue().Set(display_instant_results); |
| 1235 } | 1164 } |
| 1236 | 1165 |
| 1237 } // namespace extensions_v8 | 1166 } // namespace extensions_v8 |
| OLD | NEW |