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

Unified Diff: chrome/browser/resources/local_ntp/most_visited_util.js

Issue 426093002: Adds support for thumbnail click pings for Most Visited (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only ping for server suggestions Created 6 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/search/most_visited_iframe_source.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/local_ntp/most_visited_util.js
diff --git a/chrome/browser/resources/local_ntp/most_visited_util.js b/chrome/browser/resources/local_ntp/most_visited_util.js
index 5c2b8723b1f99fa7bec04581797b52bb1e97d3be..3c5cee72ee7827da01dc479508cc116676376e2f 100644
--- a/chrome/browser/resources/local_ntp/most_visited_util.js
+++ b/chrome/browser/resources/local_ntp/most_visited_util.js
@@ -45,7 +45,6 @@ var NTP_LOGGING_EVENT_TYPE = {
NTP_MOUSEOVER: 9
};
-
/**
* Type of the impression provider for a generic client-provided suggestion.
* @type {string}
@@ -61,6 +60,12 @@ var CLIENT_PROVIDER_NAME = 'client';
var SERVER_PROVIDER_NAME = 'server';
/**
+ * The origin of this request.
+ * @const {string}
+ */
+var DOMAIN_ORIGIN = '{{ORIGIN}}';
+
+/**
* Parses query parameters from Location.
* @param {string} location The URL to generate the CSS url for.
* @return {Object} Dictionary containing name value pairs for URL.
@@ -121,12 +126,19 @@ function createMostVisitedLink(params, href, title, text, provider) {
// working (those with schemes different from http and https). Therefore,
// navigateContentWindow is being used in order to get all schemes working.
link.addEventListener('click', function handleNavigation(e) {
+ var isServerSuggestion = 'url' in params;
+
+ // Ping are only populated for server-side suggestions, never for MV.
+ if (isServerSuggestion && params.ping) {
+ generatePing(DOMAIN_ORIGIN + params.ping);
+ }
+
var ntpApiHandle = chrome.embeddedSearch.newTabPage;
if ('pos' in params && isFinite(params.pos)) {
ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10),
provider || '');
}
- var isServerSuggestion = 'url' in params;
+
if (!isServerSuggestion) {
e.preventDefault();
ntpApiHandle.navigateContentWindow(href, getDispositionFromEvent(e));
@@ -175,7 +187,7 @@ function getMostVisitedStyles(params, isTitle) {
* data to fill.
*/
function fillMostVisited(location, fill) {
- var params = parseQueryParams(document.location);
+ var params = parseQueryParams(location);
params.rid = parseInt(params.rid, 10);
if (!isFinite(params.rid) && !params.url)
return;
@@ -212,3 +224,20 @@ function fillMostVisited(location, fill) {
document.body.dir = data.direction;
fill(params, data);
}
+
+
+/**
+ * Sends a POST request to ping url.
+ * @param {string} url URL to be pinged.
+ */
+function generatePing(url) {
+ if (navigator.sendBeacon) {
+ navigator.sendBeacon(url);
+ } else {
+ // if sendBeacon is not enabled, we fallback for "a ping".
+ var a = document.createElement('a');
+ a.href = '#';
+ a.ping = url;
+ a.click();
+ }
+}
« no previous file with comments | « no previous file | chrome/browser/search/most_visited_iframe_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698