Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: chrome/renderer/searchbox/searchbox_extension.cc

Issue 178253008: Redoing Issue 36073011: Allowing file:/// in Instant Extended's Most Visited links. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding and using logNavigation(); updating tests; removing ping and the log.html page. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/json/string_escape.h" 8 #include "base/json/string_escape.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/common/autocomplete_match_type.h" 13 #include "chrome/common/autocomplete_match_type.h"
14 #include "chrome/common/instant_types.h" 14 #include "chrome/common/instant_types.h"
15 #include "chrome/common/ntp_logging_events.h" 15 #include "chrome/common/ntp_logging_events.h"
16 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "chrome/renderer/searchbox/searchbox.h" 17 #include "chrome/renderer/searchbox/searchbox.h"
18 #include "content/public/common/url_constants.h"
18 #include "content/public/renderer/render_view.h" 19 #include "content/public/renderer/render_view.h"
19 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
20 #include "grit/renderer_resources.h" 21 #include "grit/renderer_resources.h"
21 #include "third_party/WebKit/public/platform/WebURLRequest.h" 22 #include "third_party/WebKit/public/platform/WebURLRequest.h"
22 #include "third_party/WebKit/public/web/WebDocument.h" 23 #include "third_party/WebKit/public/web/WebDocument.h"
23 #include "third_party/WebKit/public/web/WebFrame.h" 24 #include "third_party/WebKit/public/web/WebFrame.h"
24 #include "third_party/WebKit/public/web/WebScriptSource.h" 25 #include "third_party/WebKit/public/web/WebScriptSource.h"
25 #include "third_party/WebKit/public/web/WebView.h" 26 #include "third_party/WebKit/public/web/WebView.h"
26 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/base/window_open_disposition.h" 28 #include "ui/base/window_open_disposition.h"
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 static void DeleteMostVisitedItem( 356 static void DeleteMostVisitedItem(
356 const v8::FunctionCallbackInfo<v8::Value>& args); 357 const v8::FunctionCallbackInfo<v8::Value>& args);
357 358
358 // Focuses the omnibox. 359 // Focuses the omnibox.
359 static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args); 360 static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args);
360 361
361 // Gets whether or not the app launcher is enabled. 362 // Gets whether or not the app launcher is enabled.
362 static void GetAppLauncherEnabled( 363 static void GetAppLauncherEnabled(
363 const v8::FunctionCallbackInfo<v8::Value>& args); 364 const v8::FunctionCallbackInfo<v8::Value>& args);
364 365
366 // Gets the desired navigation behavior from a click event.
367 static void GetDispositionFromClick(
368 const v8::FunctionCallbackInfo<v8::Value>& args);
369
365 // Gets Most Visited Items. 370 // Gets Most Visited Items.
366 static void GetMostVisitedItems( 371 static void GetMostVisitedItems(
367 const v8::FunctionCallbackInfo<v8::Value>& args); 372 const v8::FunctionCallbackInfo<v8::Value>& args);
368 373
369 // Gets the raw data for a most visited item including its raw URL. 374 // Gets the raw data for a most visited item including its raw URL.
370 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin 375 // GetRenderViewWithCheckedOrigin() enforces that only code in the origin
371 // chrome-search://most-visited can call this function. 376 // chrome-search://most-visited can call this function.
372 static void GetMostVisitedItemData( 377 static void GetMostVisitedItemData(
373 const v8::FunctionCallbackInfo<v8::Value>& args); 378 const v8::FunctionCallbackInfo<v8::Value>& args);
374 379
(...skipping 25 matching lines...) Expand all
400 // Gets whether the browser is capturing key strokes. 405 // Gets whether the browser is capturing key strokes.
401 static void IsKeyCaptureEnabled( 406 static void IsKeyCaptureEnabled(
402 const v8::FunctionCallbackInfo<v8::Value>& args); 407 const v8::FunctionCallbackInfo<v8::Value>& args);
403 408
404 // Logs information from the iframes/titles on the NTP. 409 // Logs information from the iframes/titles on the NTP.
405 static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args); 410 static void LogEvent(const v8::FunctionCallbackInfo<v8::Value>& args);
406 411
407 // Logs an impression on one of the Most Visited tile on the NTP. 412 // Logs an impression on one of the Most Visited tile on the NTP.
408 static void LogImpression(const v8::FunctionCallbackInfo<v8::Value>& args); 413 static void LogImpression(const v8::FunctionCallbackInfo<v8::Value>& args);
409 414
415 // Logs a navigation on one of the Most Visited tile on the NTP.
416 static void LogNavigation(const v8::FunctionCallbackInfo<v8::Value>& args);
417
410 // Navigates the window to a URL represented by either a URL string or a 418 // Navigates the window to a URL represented by either a URL string or a
411 // restricted ID. 419 // restricted ID.
412 static void NavigateContentWindow( 420 static void NavigateContentWindow(
413 const v8::FunctionCallbackInfo<v8::Value>& args); 421 const v8::FunctionCallbackInfo<v8::Value>& args);
414 422
415 // Pastes provided value or clipboard's content into the omnibox. 423 // Pastes provided value or clipboard's content into the omnibox.
416 static void Paste(const v8::FunctionCallbackInfo<v8::Value>& args); 424 static void Paste(const v8::FunctionCallbackInfo<v8::Value>& args);
417 425
418 // Indicates whether the page supports voice search. 426 // Indicates whether the page supports voice search.
419 static void SetVoiceSearchSupported( 427 static void SetVoiceSearchSupported(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 v8::Handle<v8::String> name) { 542 v8::Handle<v8::String> name) {
535 if (name->Equals( 543 if (name->Equals(
536 v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs"))) 544 v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs")))
537 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs); 545 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs);
538 if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem"))) 546 if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem")))
539 return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem); 547 return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem);
540 if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus"))) 548 if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus")))
541 return v8::FunctionTemplate::New(isolate, Focus); 549 return v8::FunctionTemplate::New(isolate, Focus);
542 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetAppLauncherEnabled"))) 550 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetAppLauncherEnabled")))
543 return v8::FunctionTemplate::New(isolate, GetAppLauncherEnabled); 551 return v8::FunctionTemplate::New(isolate, GetAppLauncherEnabled);
552 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetDispositionFromClick")))
553 return v8::FunctionTemplate::New(isolate, GetDispositionFromClick);
544 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems"))) 554 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems")))
545 return v8::FunctionTemplate::New(isolate, GetMostVisitedItems); 555 return v8::FunctionTemplate::New(isolate, GetMostVisitedItems);
546 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItemData"))) 556 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItemData")))
547 return v8::FunctionTemplate::New(isolate, GetMostVisitedItemData); 557 return v8::FunctionTemplate::New(isolate, GetMostVisitedItemData);
548 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetQuery"))) 558 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetQuery")))
549 return v8::FunctionTemplate::New(isolate, GetQuery); 559 return v8::FunctionTemplate::New(isolate, GetQuery);
550 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetRightToLeft"))) 560 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetRightToLeft")))
551 return v8::FunctionTemplate::New(isolate, GetRightToLeft); 561 return v8::FunctionTemplate::New(isolate, GetRightToLeft);
552 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetStartMargin"))) 562 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetStartMargin")))
553 return v8::FunctionTemplate::New(isolate, GetStartMargin); 563 return v8::FunctionTemplate::New(isolate, GetStartMargin);
554 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetSuggestionToPrefetch"))) 564 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetSuggestionToPrefetch")))
555 return v8::FunctionTemplate::New(isolate, GetSuggestionToPrefetch); 565 return v8::FunctionTemplate::New(isolate, GetSuggestionToPrefetch);
556 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetThemeBackgroundInfo"))) 566 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetThemeBackgroundInfo")))
557 return v8::FunctionTemplate::New(isolate, GetThemeBackgroundInfo); 567 return v8::FunctionTemplate::New(isolate, GetThemeBackgroundInfo);
558 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsFocused"))) 568 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsFocused")))
559 return v8::FunctionTemplate::New(isolate, IsFocused); 569 return v8::FunctionTemplate::New(isolate, IsFocused);
560 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsInputInProgress"))) 570 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsInputInProgress")))
561 return v8::FunctionTemplate::New(isolate, IsInputInProgress); 571 return v8::FunctionTemplate::New(isolate, IsInputInProgress);
562 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsKeyCaptureEnabled"))) 572 if (name->Equals(v8::String::NewFromUtf8(isolate, "IsKeyCaptureEnabled")))
563 return v8::FunctionTemplate::New(isolate, IsKeyCaptureEnabled); 573 return v8::FunctionTemplate::New(isolate, IsKeyCaptureEnabled);
564 if (name->Equals(v8::String::NewFromUtf8(isolate, "LogEvent"))) 574 if (name->Equals(v8::String::NewFromUtf8(isolate, "LogEvent")))
565 return v8::FunctionTemplate::New(isolate, LogEvent); 575 return v8::FunctionTemplate::New(isolate, LogEvent);
566 if (name->Equals(v8::String::NewFromUtf8(isolate, "LogImpression"))) 576 if (name->Equals(v8::String::NewFromUtf8(isolate, "LogImpression")))
567 return v8::FunctionTemplate::New(isolate, LogImpression); 577 return v8::FunctionTemplate::New(isolate, LogImpression);
578 if (name->Equals(v8::String::NewFromUtf8(isolate, "LogNavigation")))
579 return v8::FunctionTemplate::New(isolate, LogNavigation);
568 if (name->Equals(v8::String::NewFromUtf8(isolate, "NavigateContentWindow"))) 580 if (name->Equals(v8::String::NewFromUtf8(isolate, "NavigateContentWindow")))
569 return v8::FunctionTemplate::New(isolate, NavigateContentWindow); 581 return v8::FunctionTemplate::New(isolate, NavigateContentWindow);
570 if (name->Equals(v8::String::NewFromUtf8(isolate, "Paste"))) 582 if (name->Equals(v8::String::NewFromUtf8(isolate, "Paste")))
571 return v8::FunctionTemplate::New(isolate, Paste); 583 return v8::FunctionTemplate::New(isolate, Paste);
572 if (name->Equals(v8::String::NewFromUtf8(isolate, "SetVoiceSearchSupported"))) 584 if (name->Equals(v8::String::NewFromUtf8(isolate, "SetVoiceSearchSupported")))
573 return v8::FunctionTemplate::New(isolate, SetVoiceSearchSupported); 585 return v8::FunctionTemplate::New(isolate, SetVoiceSearchSupported);
574 if (name->Equals( 586 if (name->Equals(
575 v8::String::NewFromUtf8(isolate, "StartCapturingKeyStrokes"))) 587 v8::String::NewFromUtf8(isolate, "StartCapturingKeyStrokes")))
576 return v8::FunctionTemplate::New(isolate, StartCapturingKeyStrokes); 588 return v8::FunctionTemplate::New(isolate, StartCapturingKeyStrokes);
577 if (name->Equals(v8::String::NewFromUtf8(isolate, "StopCapturingKeyStrokes"))) 589 if (name->Equals(v8::String::NewFromUtf8(isolate, "StopCapturingKeyStrokes")))
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 void SearchBoxExtensionWrapper::GetAppLauncherEnabled( 646 void SearchBoxExtensionWrapper::GetAppLauncherEnabled(
635 const v8::FunctionCallbackInfo<v8::Value>& args) { 647 const v8::FunctionCallbackInfo<v8::Value>& args) {
636 content::RenderView* render_view = GetRenderView(); 648 content::RenderView* render_view = GetRenderView();
637 if (!render_view) return; 649 if (!render_view) return;
638 650
639 args.GetReturnValue().Set( 651 args.GetReturnValue().Set(
640 SearchBox::Get(render_view)->app_launcher_enabled()); 652 SearchBox::Get(render_view)->app_launcher_enabled());
641 } 653 }
642 654
643 // static 655 // static
656 void SearchBoxExtensionWrapper::GetDispositionFromClick(
657 const v8::FunctionCallbackInfo<v8::Value>& args) {
658 content::RenderView* render_view = GetRenderView();
659 if (!render_view || args.Length() != 5) return;
660
661 bool middle_button = args[0]->BooleanValue();
662 bool alt_key = args[1]->BooleanValue();
663 bool ctrl_key = args[2]->BooleanValue();
664 bool meta_key = args[3]->BooleanValue();
665 bool shift_key = args[4]->BooleanValue();
666
667 WindowOpenDisposition disposition = ui::DispositionFromClick(middle_button,
668 alt_key,
669 ctrl_key,
670 meta_key,
671 shift_key);
672 v8::Isolate* isolate = args.GetIsolate();
673 args.GetReturnValue().Set(v8::Int32::New(isolate, disposition));
674 }
675
676 // static
644 void SearchBoxExtensionWrapper::GetMostVisitedItems( 677 void SearchBoxExtensionWrapper::GetMostVisitedItems(
645 const v8::FunctionCallbackInfo<v8::Value>& args) { 678 const v8::FunctionCallbackInfo<v8::Value>& args) {
646 content::RenderView* render_view = GetRenderView(); 679 content::RenderView* render_view = GetRenderView();
647 if (!render_view) 680 if (!render_view)
648 return; 681 return;
649 DVLOG(1) << render_view << " GetMostVisitedItems"; 682 DVLOG(1) << render_view << " GetMostVisitedItems";
650 683
651 const SearchBox* search_box = SearchBox::Get(render_view); 684 const SearchBox* search_box = SearchBox::Get(render_view);
652 685
653 std::vector<InstantMostVisitedItemIDPair> instant_mv_items; 686 std::vector<InstantMostVisitedItemIDPair> instant_mv_items;
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 if (args.Length() < 2 || !args[0]->IsNumber() || args[1]->IsUndefined()) 981 if (args.Length() < 2 || !args[0]->IsNumber() || args[1]->IsUndefined())
949 return; 982 return;
950 983
951 DVLOG(1) << render_view << " LogImpression"; 984 DVLOG(1) << render_view << " LogImpression";
952 985
953 SearchBox::Get(render_view)->LogImpression(args[0]->IntegerValue(), 986 SearchBox::Get(render_view)->LogImpression(args[0]->IntegerValue(),
954 V8ValueToUTF16(args[1])); 987 V8ValueToUTF16(args[1]));
955 } 988 }
956 989
957 // static 990 // static
991 void SearchBoxExtensionWrapper::LogNavigation(
992 const v8::FunctionCallbackInfo<v8::Value>& args) {
993 content::RenderView* render_view = GetRenderViewWithCheckedOrigin(
994 GURL(chrome::kChromeSearchMostVisitedUrl));
995 if (!render_view) return;
996
997 if (args.Length() < 2 || !args[0]->IsNumber() || args[1]->IsUndefined())
998 return;
999
1000 DVLOG(1) << render_view << " LogNavigation";
1001
1002 SearchBox::Get(render_view)->LogNavigation(args[0]->IntegerValue(),
1003 V8ValueToUTF16(args[1]));
1004 }
1005
1006 // static
958 void SearchBoxExtensionWrapper::NavigateContentWindow( 1007 void SearchBoxExtensionWrapper::NavigateContentWindow(
959 const v8::FunctionCallbackInfo<v8::Value>& args) { 1008 const v8::FunctionCallbackInfo<v8::Value>& args) {
960 content::RenderView* render_view = GetRenderView(); 1009 content::RenderView* render_view = GetRenderView();
961 if (!render_view || !args.Length()) return; 1010 if (!render_view || !args.Length()) return;
962 1011
963 GURL destination_url; 1012 GURL destination_url;
964 bool is_most_visited_item_url = false; 1013 bool is_most_visited_item_url = false;
965 // Check if the url is a rid 1014 // Check if the url is a rid
966 if (args[0]->IsNumber()) { 1015 if (args[0]->IsNumber()) {
967 InstantMostVisitedItem item; 1016 InstantMostVisitedItem item;
968 if (SearchBox::Get(render_view)->GetMostVisitedItemWithID( 1017 if (SearchBox::Get(render_view)->GetMostVisitedItemWithID(
969 args[0]->IntegerValue(), &item)) { 1018 args[0]->IntegerValue(), &item)) {
970 destination_url = item.url; 1019 destination_url = item.url;
971 is_most_visited_item_url = true; 1020 is_most_visited_item_url = true;
972 } 1021 }
973 } else { 1022 } else {
974 // Resolve the URL 1023 // Resolve the URL
975 const base::string16& possibly_relative_url = V8ValueToUTF16(args[0]); 1024 const base::string16& possibly_relative_url = V8ValueToUTF16(args[0]);
976 GURL current_url = GetCurrentURL(render_view); 1025 GURL current_url = GetCurrentURL(render_view);
977 destination_url = internal::ResolveURL(current_url, possibly_relative_url); 1026 destination_url = internal::ResolveURL(current_url, possibly_relative_url);
978 } 1027 }
979 1028
980 DVLOG(1) << render_view << " NavigateContentWindow: " << destination_url; 1029 DVLOG(1) << render_view << " NavigateContentWindow: " << destination_url;
981 1030
982 // Navigate the main frame. 1031 // Navigate the main frame.
983 if (destination_url.is_valid()) { 1032 if (destination_url.is_valid() &&
1033 !destination_url.SchemeIs(content::kJavaScriptScheme)) {
beaudoin 2014/03/04 21:33:15 Any other scheme we should prevent against? I'd de
984 WindowOpenDisposition disposition = CURRENT_TAB; 1034 WindowOpenDisposition disposition = CURRENT_TAB;
985 if (args[1]->Uint32Value() == 2) 1035 if (args[1]->IsNumber()) {
986 disposition = NEW_BACKGROUND_TAB; 1036 disposition = (WindowOpenDisposition) args[1]->Uint32Value();
1037 }
987 SearchBox::Get(render_view)->NavigateToURL(destination_url, disposition, 1038 SearchBox::Get(render_view)->NavigateToURL(destination_url, disposition,
988 is_most_visited_item_url); 1039 is_most_visited_item_url);
989 } 1040 }
990 } 1041 }
991 1042
992 // static 1043 // static
993 void SearchBoxExtensionWrapper::Paste( 1044 void SearchBoxExtensionWrapper::Paste(
994 const v8::FunctionCallbackInfo<v8::Value>& args) { 1045 const v8::FunctionCallbackInfo<v8::Value>& args) {
995 content::RenderView* render_view = GetRenderView(); 1046 content::RenderView* render_view = GetRenderView();
996 if (!render_view) return; 1047 if (!render_view) return;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 if (!render_view) return; 1111 if (!render_view) return;
1061 1112
1062 bool display_instant_results = 1113 bool display_instant_results =
1063 SearchBox::Get(render_view)->display_instant_results(); 1114 SearchBox::Get(render_view)->display_instant_results();
1064 DVLOG(1) << render_view << " GetDisplayInstantResults" << 1115 DVLOG(1) << render_view << " GetDisplayInstantResults" <<
1065 display_instant_results; 1116 display_instant_results;
1066 args.GetReturnValue().Set(display_instant_results); 1117 args.GetReturnValue().Set(display_instant_results);
1067 } 1118 }
1068 1119
1069 } // namespace extensions_v8 1120 } // namespace extensions_v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698