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

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: 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..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();
+ }
+}
« 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