| OLD | NEW |
| 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 // Don't remove; see crbug.com/678778. | 10 // Don't remove; see crbug.com/678778. |
| 11 // <include src="instant_iframe_validation.js"> | 11 // <include src="instant_iframe_validation.js"> |
| 12 | 12 |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * The different types of events that are logged from the NTP. The multi-iframe | 15 * The different types of events that are logged from the NTP. The multi-iframe |
| 16 * version of the NTP does *not* actually log any statistics anymore; this is | 16 * version of the NTP does *not* actually log any statistics anymore; this is |
| 17 * only required as a workaround for crbug.com/698675. | 17 * only required as a workaround for crbug.com/698675. |
| 18 * Note: Keep in sync with common/ntp_logging_events.h | 18 * Note: Keep in sync with common/ntp_logging_events.h |
| 19 * @enum {number} | 19 * @enum {number} |
| 20 * @const | 20 * @const |
| 21 */ | 21 */ |
| 22 var NTP_LOGGING_EVENT_TYPE = { | 22 var NTP_LOGGING_EVENT_TYPE = { |
| 23 NTP_ALL_TILES_RECEIVED: 12, | 23 NTP_ALL_TILES_RECEIVED: 12, |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * The origin of this request. | 28 * The origin of this request. |
| 29 * @const {string} | 29 * @const {string} |
| 30 */ | 30 */ |
| 31 var DOMAIN_ORIGIN = '{{ORIGIN}}'; | 31 var DOMAIN_ORIGIN = '{{ORIGIN}}'; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 // Follow <a> normally, so transition type will be LINK. | 115 // Follow <a> normally, so transition type will be LINK. |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 link.addEventListener('click', navigateFunction); | 118 link.addEventListener('click', navigateFunction); |
| 119 link.addEventListener('keydown', function(event) { | 119 link.addEventListener('keydown', function(event) { |
| 120 if (event.keyCode == 46 /* DELETE */ || | 120 if (event.keyCode == 46 /* DELETE */ || |
| 121 event.keyCode == 8 /* BACKSPACE */) { | 121 event.keyCode == 8 /* BACKSPACE */) { |
| 122 event.preventDefault(); | 122 event.preventDefault(); |
| 123 window.parent.postMessage('tileBlacklisted,' + params.pos, DOMAIN_ORIGIN); | 123 window.parent.postMessage('tileBlacklisted,' + params.pos, DOMAIN_ORIGIN); |
| 124 } else if (event.keyCode == 13 /* ENTER */ || | 124 } else if ( |
| 125 event.keyCode == 32 /* SPACE */) { | 125 event.keyCode == 13 /* ENTER */ || event.keyCode == 32 /* SPACE */) { |
| 126 // Event target is the <a> tag. Send a click event on it, which will | 126 // Event target is the <a> tag. Send a click event on it, which will |
| 127 // trigger the 'click' event registered above. | 127 // trigger the 'click' event registered above. |
| 128 event.preventDefault(); | 128 event.preventDefault(); |
| 129 event.target.click(); | 129 event.target.click(); |
| 130 } | 130 } |
| 131 }); | 131 }); |
| 132 | 132 |
| 133 return link; | 133 return link; |
| 134 } | 134 } |
| 135 | 135 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 // succeed. | 232 // succeed. |
| 233 apiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_ALL_TILES_RECEIVED); | 233 apiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_ALL_TILES_RECEIVED); |
| 234 data = apiHandle.getMostVisitedItemData(params.rid); | 234 data = apiHandle.getMostVisitedItemData(params.rid); |
| 235 if (!data) | 235 if (!data) |
| 236 return; | 236 return; |
| 237 } | 237 } |
| 238 | 238 |
| 239 if (isFinite(params.dummy) && parseInt(params.dummy, 10)) { | 239 if (isFinite(params.dummy) && parseInt(params.dummy, 10)) { |
| 240 data.dummy = true; | 240 data.dummy = true; |
| 241 } | 241 } |
| 242 if (/^javascript:/i.test(data.url) || | 242 if (/^javascript:/i.test(data.url) || /^javascript:/i.test(data.thumbnailUrl)) |
| 243 /^javascript:/i.test(data.thumbnailUrl)) | |
| 244 return; | 243 return; |
| 245 if (data.direction) | 244 if (data.direction) |
| 246 document.body.dir = data.direction; | 245 document.body.dir = data.direction; |
| 247 fill(params, data); | 246 fill(params, data); |
| 248 } | 247 } |
| 249 | 248 |
| 250 | 249 |
| 251 /** | 250 /** |
| 252 * Sends a POST request to ping url. | 251 * Sends a POST request to ping url. |
| 253 * @param {string} url URL to be pinged. | 252 * @param {string} url URL to be pinged. |
| 254 */ | 253 */ |
| 255 function generatePing(url) { | 254 function generatePing(url) { |
| 256 if (navigator.sendBeacon) { | 255 if (navigator.sendBeacon) { |
| 257 navigator.sendBeacon(url); | 256 navigator.sendBeacon(url); |
| 258 } else { | 257 } else { |
| 259 // if sendBeacon is not enabled, we fallback for "a ping". | 258 // if sendBeacon is not enabled, we fallback for "a ping". |
| 260 var a = document.createElement('a'); | 259 var a = document.createElement('a'); |
| 261 a.href = '#'; | 260 a.href = '#'; |
| 262 a.ping = url; | 261 a.ping = url; |
| 263 a.click(); | 262 a.click(); |
| 264 } | 263 } |
| 265 } | 264 } |
| OLD | NEW |