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..c9b6fd26f5446390a5bbc03edaf50d67f839e180 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,13 @@ var CLIENT_PROVIDER_NAME = 'client'; |
var SERVER_PROVIDER_NAME = 'server'; |
/** |
+ * The origin of this request. |
+ * @type {string} |
+ * @const |
Mathieu
2014/07/30 14:12:54
You can simplify to @const {string}
fserb
2014/07/31 18:18:47
Done.
|
+ */ |
+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 +127,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/30 14:12:54
nit: you can omit braces
fserb
2014/07/31 18:18:47
Acknowledged.
|
+ 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 +185,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 +222,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 { |
+ // sendBeacon is still in experimental, so for now we use 'a ping' |
Mathieu
2014/07/30 14:12:54
you could say: "If sendBeacon is not enabled, use
fserb
2014/07/31 18:18:47
Done.
|
+ var a = document.createElement('a'); |
+ a.href = '#'; |
+ a.ping = url; |
+ a.click(); |
+ } |
+} |