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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/searchbox/searchbox_extension.cc
diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc
index f56ce48c84f1e8922f47ef0b17ac13d31baac1fa..2470d5e2d833ac3872926df41f80e88e59d27c65 100644
--- a/chrome/renderer/searchbox/searchbox_extension.cc
+++ b/chrome/renderer/searchbox/searchbox_extension.cc
@@ -15,6 +15,7 @@
#include "chrome/common/ntp_logging_events.h"
#include "chrome/common/url_constants.h"
#include "chrome/renderer/searchbox/searchbox.h"
+#include "content/public/common/url_constants.h"
#include "content/public/renderer/render_view.h"
#include "extensions/common/extension.h"
#include "grit/renderer_resources.h"
@@ -362,6 +363,10 @@ class SearchBoxExtensionWrapper : public v8::Extension {
static void GetAppLauncherEnabled(
const v8::FunctionCallbackInfo<v8::Value>& args);
+ // Gets the desired navigation behavior from a click event.
+ static void GetDispositionFromClick(
+ const v8::FunctionCallbackInfo<v8::Value>& args);
+
// Gets Most Visited Items.
static void GetMostVisitedItems(
const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -407,6 +412,9 @@ class SearchBoxExtensionWrapper : public v8::Extension {
// Logs an impression on one of the Most Visited tile on the NTP.
static void LogImpression(const v8::FunctionCallbackInfo<v8::Value>& args);
+ // Logs a navigation on one of the Most Visited tile on the NTP.
+ static void LogNavigation(const v8::FunctionCallbackInfo<v8::Value>& args);
+
// Navigates the window to a URL represented by either a URL string or a
// restricted ID.
static void NavigateContentWindow(
@@ -541,6 +549,8 @@ SearchBoxExtensionWrapper::GetNativeFunctionTemplate(
return v8::FunctionTemplate::New(isolate, Focus);
if (name->Equals(v8::String::NewFromUtf8(isolate, "GetAppLauncherEnabled")))
return v8::FunctionTemplate::New(isolate, GetAppLauncherEnabled);
+ if (name->Equals(v8::String::NewFromUtf8(isolate, "GetDispositionFromClick")))
+ return v8::FunctionTemplate::New(isolate, GetDispositionFromClick);
if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems")))
return v8::FunctionTemplate::New(isolate, GetMostVisitedItems);
if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItemData")))
@@ -565,6 +575,8 @@ SearchBoxExtensionWrapper::GetNativeFunctionTemplate(
return v8::FunctionTemplate::New(isolate, LogEvent);
if (name->Equals(v8::String::NewFromUtf8(isolate, "LogImpression")))
return v8::FunctionTemplate::New(isolate, LogImpression);
+ if (name->Equals(v8::String::NewFromUtf8(isolate, "LogNavigation")))
+ return v8::FunctionTemplate::New(isolate, LogNavigation);
if (name->Equals(v8::String::NewFromUtf8(isolate, "NavigateContentWindow")))
return v8::FunctionTemplate::New(isolate, NavigateContentWindow);
if (name->Equals(v8::String::NewFromUtf8(isolate, "Paste")))
@@ -641,6 +653,27 @@ void SearchBoxExtensionWrapper::GetAppLauncherEnabled(
}
// static
+void SearchBoxExtensionWrapper::GetDispositionFromClick(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ content::RenderView* render_view = GetRenderView();
+ if (!render_view || args.Length() != 5) return;
+
+ bool middle_button = args[0]->BooleanValue();
+ bool alt_key = args[1]->BooleanValue();
+ bool ctrl_key = args[2]->BooleanValue();
+ bool meta_key = args[3]->BooleanValue();
+ bool shift_key = args[4]->BooleanValue();
+
+ WindowOpenDisposition disposition = ui::DispositionFromClick(middle_button,
+ alt_key,
+ ctrl_key,
+ meta_key,
+ shift_key);
+ v8::Isolate* isolate = args.GetIsolate();
+ args.GetReturnValue().Set(v8::Int32::New(isolate, disposition));
+}
+
+// static
void SearchBoxExtensionWrapper::GetMostVisitedItems(
const v8::FunctionCallbackInfo<v8::Value>& args) {
content::RenderView* render_view = GetRenderView();
@@ -955,6 +988,22 @@ void SearchBoxExtensionWrapper::LogImpression(
}
// static
+void SearchBoxExtensionWrapper::LogNavigation(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ content::RenderView* render_view = GetRenderViewWithCheckedOrigin(
+ GURL(chrome::kChromeSearchMostVisitedUrl));
+ if (!render_view) return;
+
+ if (args.Length() < 2 || !args[0]->IsNumber() || args[1]->IsUndefined())
+ return;
+
+ DVLOG(1) << render_view << " LogNavigation";
+
+ SearchBox::Get(render_view)->LogNavigation(args[0]->IntegerValue(),
+ V8ValueToUTF16(args[1]));
+}
+
+// static
void SearchBoxExtensionWrapper::NavigateContentWindow(
const v8::FunctionCallbackInfo<v8::Value>& args) {
content::RenderView* render_view = GetRenderView();
@@ -973,17 +1022,19 @@ void SearchBoxExtensionWrapper::NavigateContentWindow(
} else {
// Resolve the URL
const base::string16& possibly_relative_url = V8ValueToUTF16(args[0]);
- GURL current_url = GetCurrentURL(render_view);
+ GURL current_url = GetCurrentURL(render_view);
destination_url = internal::ResolveURL(current_url, possibly_relative_url);
}
DVLOG(1) << render_view << " NavigateContentWindow: " << destination_url;
// Navigate the main frame.
- if (destination_url.is_valid()) {
+ if (destination_url.is_valid() &&
+ !destination_url.SchemeIs(content::kJavaScriptScheme)) {
beaudoin 2014/03/04 21:33:15 Any other scheme we should prevent against? I'd de
WindowOpenDisposition disposition = CURRENT_TAB;
- if (args[1]->Uint32Value() == 2)
- disposition = NEW_BACKGROUND_TAB;
+ if (args[1]->IsNumber()) {
+ disposition = (WindowOpenDisposition) args[1]->Uint32Value();
+ }
SearchBox::Get(render_view)->NavigateToURL(destination_url, disposition,
is_most_visited_item_url);
}

Powered by Google App Engine
This is Rietveld 408576698