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

Side by Side 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, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/search/most_visited_iframe_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 /** 6 /**
7 * @fileoverview Utilities for rendering most visited thumbnails and titles. 7 * @fileoverview Utilities for rendering most visited thumbnails and titles.
8 */ 8 */
9 9
10 <include src="instant_iframe_validation.js"> 10 <include src="instant_iframe_validation.js">
(...skipping 27 matching lines...) Expand all
38 // (if it was provided), resulting in a grey tile. 38 // (if it was provided), resulting in a grey tile.
39 NTP_THUMBNAIL_ERROR: 6, 39 NTP_THUMBNAIL_ERROR: 6,
40 // Used a gray tile with the domain as the fallback for a failed thumbnail. 40 // Used a gray tile with the domain as the fallback for a failed thumbnail.
41 NTP_GRAY_TILE_FALLBACK: 7, 41 NTP_GRAY_TILE_FALLBACK: 7,
42 // The visuals of that tile's fallback are handled externally. 42 // The visuals of that tile's fallback are handled externally.
43 NTP_EXTERNAL_TILE_FALLBACK: 8, 43 NTP_EXTERNAL_TILE_FALLBACK: 8,
44 // The user moused over an NTP tile or title. 44 // The user moused over an NTP tile or title.
45 NTP_MOUSEOVER: 9 45 NTP_MOUSEOVER: 9
46 }; 46 };
47 47
48
49 /** 48 /**
50 * Type of the impression provider for a generic client-provided suggestion. 49 * Type of the impression provider for a generic client-provided suggestion.
51 * @type {string} 50 * @type {string}
52 * @const 51 * @const
53 */ 52 */
54 var CLIENT_PROVIDER_NAME = 'client'; 53 var CLIENT_PROVIDER_NAME = 'client';
55 54
56 /** 55 /**
57 * Type of the impression provider for a generic server-provided suggestion. 56 * Type of the impression provider for a generic server-provided suggestion.
58 * @type {string} 57 * @type {string}
59 * @const 58 * @const
60 */ 59 */
61 var SERVER_PROVIDER_NAME = 'server'; 60 var SERVER_PROVIDER_NAME = 'server';
62 61
63 /** 62 /**
63 * The origin of this request.
64 * @const {string}
65 */
66 var DOMAIN_ORIGIN = '{{ORIGIN}}';
67
68 /**
64 * Parses query parameters from Location. 69 * Parses query parameters from Location.
65 * @param {string} location The URL to generate the CSS url for. 70 * @param {string} location The URL to generate the CSS url for.
66 * @return {Object} Dictionary containing name value pairs for URL. 71 * @return {Object} Dictionary containing name value pairs for URL.
67 */ 72 */
68 function parseQueryParams(location) { 73 function parseQueryParams(location) {
69 var params = Object.create(null); 74 var params = Object.create(null);
70 var query = location.search.substring(1); 75 var query = location.search.substring(1);
71 var vars = query.split('&'); 76 var vars = query.split('&');
72 for (var i = 0; i < vars.length; i++) { 77 for (var i = 0; i < vars.length; i++) {
73 var pair = vars[i].split('='); 78 var pair = vars[i].split('=');
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 link.textContent = text; 119 link.textContent = text;
115 link.addEventListener('mouseover', function() { 120 link.addEventListener('mouseover', function() {
116 var ntpApiHandle = chrome.embeddedSearch.newTabPage; 121 var ntpApiHandle = chrome.embeddedSearch.newTabPage;
117 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER); 122 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER);
118 }); 123 });
119 124
120 // Webkit's security policy prevents some Most Visited thumbnails from 125 // Webkit's security policy prevents some Most Visited thumbnails from
121 // working (those with schemes different from http and https). Therefore, 126 // working (those with schemes different from http and https). Therefore,
122 // navigateContentWindow is being used in order to get all schemes working. 127 // navigateContentWindow is being used in order to get all schemes working.
123 link.addEventListener('click', function handleNavigation(e) { 128 link.addEventListener('click', function handleNavigation(e) {
129 var isServerSuggestion = 'url' in params;
130
131 // Ping are only populated for server-side suggestions, never for MV.
132 if (isServerSuggestion && params.ping) {
133 generatePing(DOMAIN_ORIGIN + params.ping);
134 }
135
124 var ntpApiHandle = chrome.embeddedSearch.newTabPage; 136 var ntpApiHandle = chrome.embeddedSearch.newTabPage;
125 if ('pos' in params && isFinite(params.pos)) { 137 if ('pos' in params && isFinite(params.pos)) {
126 ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10), 138 ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10),
127 provider || ''); 139 provider || '');
128 } 140 }
129 var isServerSuggestion = 'url' in params; 141
130 if (!isServerSuggestion) { 142 if (!isServerSuggestion) {
131 e.preventDefault(); 143 e.preventDefault();
132 ntpApiHandle.navigateContentWindow(href, getDispositionFromEvent(e)); 144 ntpApiHandle.navigateContentWindow(href, getDispositionFromEvent(e));
133 } 145 }
134 // Else follow <a> normally, so transition type would be LINK. 146 // Else follow <a> normally, so transition type would be LINK.
135 }); 147 });
136 148
137 return link; 149 return link;
138 } 150 }
139 151
(...skipping 28 matching lines...) Expand all
168 return styles; 180 return styles;
169 } 181 }
170 182
171 183
172 /** 184 /**
173 * @param {string} location A location containing URL parameters. 185 * @param {string} location A location containing URL parameters.
174 * @param {function(Object, Object)} fill A function called with styles and 186 * @param {function(Object, Object)} fill A function called with styles and
175 * data to fill. 187 * data to fill.
176 */ 188 */
177 function fillMostVisited(location, fill) { 189 function fillMostVisited(location, fill) {
178 var params = parseQueryParams(document.location); 190 var params = parseQueryParams(location);
179 params.rid = parseInt(params.rid, 10); 191 params.rid = parseInt(params.rid, 10);
180 if (!isFinite(params.rid) && !params.url) 192 if (!isFinite(params.rid) && !params.url)
181 return; 193 return;
182 // Log whether the suggestion was obtained from the server or the client. 194 // Log whether the suggestion was obtained from the server or the client.
183 chrome.embeddedSearch.newTabPage.logEvent(params.url ? 195 chrome.embeddedSearch.newTabPage.logEvent(params.url ?
184 NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION : 196 NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION :
185 NTP_LOGGING_EVENT_TYPE.NTP_CLIENT_SIDE_SUGGESTION); 197 NTP_LOGGING_EVENT_TYPE.NTP_CLIENT_SIDE_SUGGESTION);
186 var data = {}; 198 var data = {};
187 if (params.url) { 199 if (params.url) {
188 // Means that the suggestion data comes from the server. Create data object. 200 // Means that the suggestion data comes from the server. Create data object.
(...skipping 16 matching lines...) Expand all
205 data.provider = params.pr || CLIENT_PROVIDER_NAME; 217 data.provider = params.pr || CLIENT_PROVIDER_NAME;
206 } 218 }
207 if (/^javascript:/i.test(data.url) || 219 if (/^javascript:/i.test(data.url) ||
208 /^javascript:/i.test(data.thumbnailUrl) || 220 /^javascript:/i.test(data.thumbnailUrl) ||
209 !/^[a-z0-9]{0,8}$/i.test(data.provider)) 221 !/^[a-z0-9]{0,8}$/i.test(data.provider))
210 return; 222 return;
211 if (data.direction) 223 if (data.direction)
212 document.body.dir = data.direction; 224 document.body.dir = data.direction;
213 fill(params, data); 225 fill(params, data);
214 } 226 }
227
228
229 /**
230 * Sends a POST request to ping url.
231 * @param {string} url URL to be pinged.
232 */
233 function generatePing(url) {
234 if (navigator.sendBeacon) {
235 navigator.sendBeacon(url);
236 } else {
237 // if sendBeacon is not enabled, we fallback for "a ping".
238 var a = document.createElement('a');
239 a.href = '#';
240 a.ping = url;
241 a.click();
242 }
243 }
OLDNEW
« 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