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..bc85c9d1f028c26d0c93299f6381f4ae0a8452c7 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,6 +126,10 @@ 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) { |
+ if (params.ping) { |
Mathieu
2014/07/31 18:56:05
A possibility, while avoiding a separate request j
Jered
2014/08/01 16:09:44
Can you provide a bit more context for this change
|
+ generatePing(DOMAIN_ORIGIN + params.ping); |
+ } |
+ |
var ntpApiHandle = chrome.embeddedSearch.newTabPage; |
if ('pos' in params && isFinite(params.pos)) { |
ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10), |
@@ -175,7 +184,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 +221,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(); |
+ } |
+} |