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

Side by Side Diff: chrome/browser/resources/local_ntp/most_visited_util.js

Issue 2117373002: Cleanup: Change LogMostVisitedImpression|Navigation APIs to take an enum (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ntp_uma_cleanup
Patch Set: rebase Created 4 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 unified diff | Download patch
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">
11 11
12 12
13 // TODO(treib): A number of things from this file (e.g. the "enums" below) are
14 // duplicated in most_visited_single.js. Pull those out into a shared file.
15
16
13 /** 17 /**
14 * The different types of events that are logged from the NTP. This enum is 18 * The different types of events that are logged from the NTP. This enum is
15 * used to transfer information from the NTP javascript to the renderer and is 19 * used to transfer information from the NTP javascript to the renderer and is
16 * not used as a UMA enum histogram's logged value. 20 * not used as a UMA enum histogram's logged value.
17 * Note: Keep in sync with common/ntp_logging_events.h 21 * Note: Keep in sync with common/ntp_logging_events.h
18 * @enum {number} 22 * @enum {number}
19 * @const 23 * @const
20 */ 24 */
21 var NTP_LOGGING_EVENT_TYPE = { 25 var NTP_LOGGING_EVENT_TYPE = {
22 // The suggestion is coming from the server. 26 // The suggestion is coming from the server.
(...skipping 17 matching lines...) Expand all
40 NTP_GRAY_TILE_FALLBACK: 7, 44 NTP_GRAY_TILE_FALLBACK: 7,
41 // The visuals of that tile's fallback are handled externally. 45 // The visuals of that tile's fallback are handled externally.
42 NTP_EXTERNAL_TILE_FALLBACK: 8, 46 NTP_EXTERNAL_TILE_FALLBACK: 8,
43 // The user moused over an NTP tile or title. 47 // The user moused over an NTP tile or title.
44 NTP_MOUSEOVER: 9, 48 NTP_MOUSEOVER: 9,
45 // A NTP Tile has finished loading (successfully or failing). 49 // A NTP Tile has finished loading (successfully or failing).
46 NTP_TILE_LOADED: 10, 50 NTP_TILE_LOADED: 10,
47 }; 51 };
48 52
49 /** 53 /**
50 * Type of the impression provider for a generic client-provided suggestion. 54 * The different sources that an NTP tile can have.
51 * @type {string} 55 * Note: Keep in sync with common/ntp_logging_events.h
56 * @enum {number}
52 * @const 57 * @const
53 */ 58 */
54 var CLIENT_PROVIDER_NAME = 'client'; 59 var NTPLoggingTileSource = {
55 60 CLIENT: 0,
56 /** 61 SERVER: 1,
57 * Type of the impression provider for a generic server-provided suggestion. 62 };
58 * @type {string}
59 * @const
60 */
61 var SERVER_PROVIDER_NAME = 'server';
62 63
63 /** 64 /**
64 * The origin of this request. 65 * The origin of this request.
65 * @const {string} 66 * @const {string}
66 */ 67 */
67 var DOMAIN_ORIGIN = '{{ORIGIN}}'; 68 var DOMAIN_ORIGIN = '{{ORIGIN}}';
68 69
69 /** 70 /**
70 * Parses query parameters from Location. 71 * Parses query parameters from Location.
71 * @param {string} location The URL to generate the CSS url for. 72 * @param {string} location The URL to generate the CSS url for.
(...skipping 19 matching lines...) Expand all
91 } 92 }
92 93
93 94
94 /** 95 /**
95 * Creates a new most visited link element. 96 * Creates a new most visited link element.
96 * @param {Object} params URL parameters containing styles for the link. 97 * @param {Object} params URL parameters containing styles for the link.
97 * @param {string} href The destination for the link. 98 * @param {string} href The destination for the link.
98 * @param {string} title The title for the link. 99 * @param {string} title The title for the link.
99 * @param {string|undefined} text The text for the link or none. 100 * @param {string|undefined} text The text for the link or none.
100 * @param {string|undefined} direction The text direction. 101 * @param {string|undefined} direction The text direction.
101 * @param {string|undefined} provider A provider name (max 8 alphanumeric 102 * @param {number} tileSource The source from NTPLoggingTileSource.
102 * characters) used for logging. Undefined if suggestion is not coming from
103 * the server.
104 * @return {HTMLAnchorElement} A new link element. 103 * @return {HTMLAnchorElement} A new link element.
105 */ 104 */
106 function createMostVisitedLink(params, href, title, text, direction, provider) { 105 function createMostVisitedLink(
106 params, href, title, text, direction, tileSource) {
107 var styles = getMostVisitedStyles(params, !!text); 107 var styles = getMostVisitedStyles(params, !!text);
108 var link = document.createElement('a'); 108 var link = document.createElement('a');
109 link.style.color = styles.color; 109 link.style.color = styles.color;
110 link.style.fontSize = styles.fontSize + 'px'; 110 link.style.fontSize = styles.fontSize + 'px';
111 if (styles.fontFamily) 111 if (styles.fontFamily)
112 link.style.fontFamily = styles.fontFamily; 112 link.style.fontFamily = styles.fontFamily;
113 if (styles.textAlign) 113 if (styles.textAlign)
114 link.style.textAlign = styles.textAlign; 114 link.style.textAlign = styles.textAlign;
115 if (styles.textFadePos) { 115 if (styles.textFadePos) {
116 var dir = /^rtl$/i.test(direction) ? 'to left' : 'to right'; 116 var dir = /^rtl$/i.test(direction) ? 'to left' : 'to right';
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 var isServerSuggestion = 'url' in params; 151 var isServerSuggestion = 'url' in params;
152 152
153 // Ping are only populated for server-side suggestions, never for MV. 153 // Ping are only populated for server-side suggestions, never for MV.
154 if (isServerSuggestion && params.ping) { 154 if (isServerSuggestion && params.ping) {
155 generatePing(DOMAIN_ORIGIN + params.ping); 155 generatePing(DOMAIN_ORIGIN + params.ping);
156 } 156 }
157 157
158 var ntpApiHandle = chrome.embeddedSearch.newTabPage; 158 var ntpApiHandle = chrome.embeddedSearch.newTabPage;
159 if ('pos' in params && isFinite(params.pos)) { 159 if ('pos' in params && isFinite(params.pos)) {
160 ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10), 160 ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10),
161 provider || ''); 161 tileSource);
162 } 162 }
163 163
164 // Follow <a> normally, so transition type will be LINK. 164 // Follow <a> normally, so transition type will be LINK.
165 }; 165 };
166 166
167 link.addEventListener('click', navigateFunction); 167 link.addEventListener('click', navigateFunction);
168 link.addEventListener('keydown', function(event) { 168 link.addEventListener('keydown', function(event) {
169 if (event.keyCode == 46 /* DELETE */ || 169 if (event.keyCode == 46 /* DELETE */ ||
170 event.keyCode == 8 /* BACKSPACE */) { 170 event.keyCode == 8 /* BACKSPACE */) {
171 event.preventDefault(); 171 event.preventDefault();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 var data; 270 var data;
271 if (params.url) { 271 if (params.url) {
272 // Means that the suggestion data comes from the server. Create data object. 272 // Means that the suggestion data comes from the server. Create data object.
273 data = { 273 data = {
274 url: params.url, 274 url: params.url,
275 largeIconUrl: params.liu || '', 275 largeIconUrl: params.liu || '',
276 thumbnailUrl: params.tu || '', 276 thumbnailUrl: params.tu || '',
277 title: params.ti || '', 277 title: params.ti || '',
278 direction: params.di || '', 278 direction: params.di || '',
279 domain: params.dom || '', 279 domain: params.dom || '',
280 provider: params.pr || SERVER_PROVIDER_NAME 280 tileSource: NTPLoggingTileSource.SERVER
281 }; 281 };
282 } else { 282 } else {
283 var apiHandle = chrome.embeddedSearch.searchBox; 283 var apiHandle = chrome.embeddedSearch.searchBox;
284 data = apiHandle.getMostVisitedItemData(params.rid); 284 data = apiHandle.getMostVisitedItemData(params.rid);
285 if (!data) 285 if (!data)
286 return; 286 return;
287 // Allow server-side provider override. 287 data.tileSource: NTPLoggingTileSource.CLIENT;
288 data.provider = params.pr || CLIENT_PROVIDER_NAME;
289 } 288 }
290 289
291 if (isFinite(params.dummy) && parseInt(params.dummy, 10)) { 290 if (isFinite(params.dummy) && parseInt(params.dummy, 10)) {
292 data.dummy = true; 291 data.dummy = true;
293 } 292 }
294 if (/^javascript:/i.test(data.url) || 293 if (/^javascript:/i.test(data.url) ||
295 /^javascript:/i.test(data.thumbnailUrl) || 294 /^javascript:/i.test(data.thumbnailUrl))
296 !/^[a-z0-9]{0,8}$/i.test(data.provider))
297 return; 295 return;
298 if (data.direction) 296 if (data.direction)
299 document.body.dir = data.direction; 297 document.body.dir = data.direction;
300 fill(params, data); 298 fill(params, data);
301 } 299 }
302 300
303 301
304 /** 302 /**
305 * Sends a POST request to ping url. 303 * Sends a POST request to ping url.
306 * @param {string} url URL to be pinged. 304 * @param {string} url URL to be pinged.
307 */ 305 */
308 function generatePing(url) { 306 function generatePing(url) {
309 if (navigator.sendBeacon) { 307 if (navigator.sendBeacon) {
310 navigator.sendBeacon(url); 308 navigator.sendBeacon(url);
311 } else { 309 } else {
312 // if sendBeacon is not enabled, we fallback for "a ping". 310 // if sendBeacon is not enabled, we fallback for "a ping".
313 var a = document.createElement('a'); 311 var a = document.createElement('a');
314 a.href = '#'; 312 a.href = '#';
315 a.ping = url; 313 a.ping = url;
316 a.click(); 314 a.click();
317 } 315 }
318 } 316 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/local_ntp/most_visited_title.js ('k') | chrome/browser/ui/search/search_ipc_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698