diff options
| author | treib <treib@chromium.org> | 2016-02-23 05:41:59 -0800 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-02-23 13:43:31 +0000 |
| commit | bd04e200b72d72e1152cd6c4e1bcd03825101615 (patch) | |
| tree | 4ed155b597e40a16c87f602c565f3038a5a97fa7 | |
| parent | 2efb8d651d7baf2313253a01df19cbfeabd690b6 (diff) | |
| download | chromium_src-bd04e200b72d72e1152cd6c4e1bcd03825101615.zip chromium_src-bd04e200b72d72e1152cd6c4e1bcd03825101615.tar.gz chromium_src-bd04e200b72d72e1152cd6c4e1bcd03825101615.tar.bz2 | |
navigateContentWindow API: use only the rid version, remove URL support
BUG=584461
Review URL: https://codereview.chromium.org/1686253004
Cr-Commit-Position: refs/heads/master@{#376974}
5 files changed, 43 insertions, 29 deletions
diff --git a/chrome/browser/resources/local_ntp/most_visited_single.js b/chrome/browser/resources/local_ntp/most_visited_single.js index 98ebea5..d6a1d5c 100644 --- a/chrome/browser/resources/local_ntp/most_visited_single.js +++ b/chrome/browser/resources/local_ntp/most_visited_single.js @@ -379,7 +379,7 @@ var renderTile = function(data) { ev.button == 1, // MIDDLE BUTTON ev.altKey, ev.ctrlKey, ev.metaKey, ev.shiftKey); - window.chrome.embeddedSearch.newTabPage.navigateContentWindow(this.href, + window.chrome.embeddedSearch.newTabPage.navigateContentWindow(data.rid, disp); }); } diff --git a/chrome/browser/resources/local_ntp/most_visited_util.js b/chrome/browser/resources/local_ntp/most_visited_util.js index 9c00c58..d0338ab 100644 --- a/chrome/browser/resources/local_ntp/most_visited_util.js +++ b/chrome/browser/resources/local_ntp/most_visited_util.js @@ -165,9 +165,10 @@ function createMostVisitedLink(params, href, title, text, direction, provider) { provider || ''); } - if (!isServerSuggestion) { + if ('rid' in params) { e.preventDefault(); - ntpApiHandle.navigateContentWindow(href, getDispositionFromEvent(e)); + ntpApiHandle.navigateContentWindow(params.rid, + getDispositionFromEvent(e)); } // Else follow <a> normally, so transition type would be LINK. }; diff --git a/chrome/renderer/resources/extensions/searchbox_api.js b/chrome/renderer/resources/extensions/searchbox_api.js index 5120ff6..751d16a 100644 --- a/chrome/renderer/resources/extensions/searchbox_api.js +++ b/chrome/renderer/resources/extensions/searchbox_api.js @@ -177,8 +177,8 @@ if (!chrome.embeddedSearch) { LogMostVisitedNavigation(position, provider); }; - this.navigateContentWindow = function(destination, disposition) { - NavigateContentWindow(destination, disposition); + this.navigateContentWindow = function(rid, disposition) { + NavigateContentWindow(rid, disposition); }; this.undoAllMostVisitedDeletions = function() { diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc index b8c5e6c..66665ec 100644 --- a/chrome/renderer/searchbox/searchbox_extension.cc +++ b/chrome/renderer/searchbox/searchbox_extension.cc @@ -239,12 +239,6 @@ content::RenderView* GetRenderViewWithCheckedOrigin(const GURL& origin) { return render_view; } -// Returns the current URL. -GURL GetCurrentURL(content::RenderView* render_view) { - blink::WebView* webview = render_view->GetWebView(); - return webview ? GURL(webview->mainFrame()->document().url()) : GURL(); -} - } // namespace namespace internal { // for testing. @@ -486,8 +480,7 @@ class SearchBoxExtensionWrapper : public v8::Extension { static void LogMostVisitedNavigation( const v8::FunctionCallbackInfo<v8::Value>& args); - // Navigates the window to a URL represented by either a URL string or a - // restricted ID. + // Navigates the window to a URL represented by a restricted ID. static void NavigateContentWindow( const v8::FunctionCallbackInfo<v8::Value>& args); @@ -1140,25 +1133,17 @@ void SearchBoxExtensionWrapper::NavigateContentWindow( content::RenderView* render_view = GetRenderView(); if (!render_view) return; - if (!args.Length()) { + if (!args.Length() || !args[0]->IsNumber()) { ThrowInvalidParameters(args); return; } - GURL destination_url; - // Check if the url is a rid - if (args[0]->IsNumber()) { - InstantMostVisitedItem item; - if (SearchBox::Get(render_view)->GetMostVisitedItemWithID( - args[0]->IntegerValue(), &item)) { - destination_url = item.url; - } - } else { - // Resolve the URL - const base::string16& possibly_relative_url = V8ValueToUTF16(args[0]); - GURL current_url = GetCurrentURL(render_view); - destination_url = internal::ResolveURL(current_url, possibly_relative_url); - } + InstantRestrictedID rid = args[0]->Int32Value(); + InstantMostVisitedItem item; + if (!SearchBox::Get(render_view)->GetMostVisitedItemWithID(rid, &item)) + return; + + GURL destination_url = item.url; DVLOG(1) << render_view << " NavigateContentWindow: " << destination_url; diff --git a/chrome/test/data/local_ntp_browsertest.js b/chrome/test/data/local_ntp_browsertest.js index a7b6640..62a673b 100644 --- a/chrome/test/data/local_ntp_browsertest.js +++ b/chrome/test/data/local_ntp_browsertest.js @@ -101,7 +101,8 @@ function testMostVisitedLinkCallsNavigateContentWindow() { navigateContentWindowCalls++; } - var params = {}; + // Most Visited links have an rid (restricted id). + var params = { 'rid' : 1 }; var href = 'file:///some/local/file'; var title = 'Title'; var text = 'text'; @@ -113,3 +114,30 @@ function testMostVisitedLinkCallsNavigateContentWindow() { ntpHandle.navigateContentWindow = originalNavigateContentWindow; assert(navigateContentWindowCalls > 0); } + + +/** + * Tests that clicking on a Most Likely link does not call + * navigateContentWindow (it's a regular link). + */ +function testMostLikelyLinkDoesNotCallNavigateContentWindow() { + var ntpHandle = chrome.embeddedSearch.newTabPage; + var originalNavigateContentWindow = ntpHandle.navigateContentWindow; + + var navigateContentWindowCalls = 0; + ntpHandle.navigateContentWindow = function() { + navigateContentWindowCalls++; + } + + var params = {}; + var href = 'https://www.site.com'; + var title = 'Title'; + var text = 'text'; + var provider = 'foobar'; + var link = createMostVisitedLink(params, href, title, text, provider); + + link.click(); + + ntpHandle.navigateContentWindow = originalNavigateContentWindow; + assert(navigateContentWindowCalls == 0); +} |
