OLD | NEW |
1 /* Copyright 2015 The Chromium Authors. All rights reserved. | 1 /* Copyright 2015 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 // Single iframe for NTP tiles. | 5 // Single iframe for NTP tiles. |
6 (function() { | 6 (function() { |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 | 9 |
10 /** | 10 /** |
11 * The different types of events that are logged from the NTP. This enum is | 11 * The different types of events that are logged from the NTP. This enum is |
12 * used to transfer information from the NTP JavaScript to the renderer and is | 12 * used to transfer information from the NTP JavaScript to the renderer and is |
13 * not used as a UMA enum histogram's logged value. | 13 * not used as a UMA enum histogram's logged value. |
14 * Note: Keep in sync with common/ntp_logging_events.h | 14 * Note: Keep in sync with common/ntp_logging_events.h |
15 * @enum {number} | 15 * @enum {number} |
16 * @const | 16 * @const |
17 */ | 17 */ |
18 var LOG_TYPE = { | 18 var LOG_TYPE = { |
19 // A suggestion coming from the server was rendered. | |
20 NTP_SERVER_SIDE_SUGGESTION: 0, | |
21 // A suggestion coming from the client was rendered. | |
22 NTP_CLIENT_SIDE_SUGGESTION: 1, | |
23 // All NTP Tiles have finished loading (successfully or failing). | 19 // All NTP Tiles have finished loading (successfully or failing). |
24 NTP_ALL_TILES_LOADED: 11, | 20 NTP_ALL_TILES_LOADED: 11, |
25 }; | 21 }; |
26 | 22 |
27 | 23 |
28 /** | 24 /** |
29 * The different sources that an NTP tile can have. | 25 * The different sources that an NTP tile can have. |
30 * Note: Keep in sync with common/ntp_logging_events.h | 26 * Note: Keep in sync with common/ntp_logging_events.h |
31 * @enum {number} | 27 * @enum {number} |
32 * @const | 28 * @const |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 var data = chrome.embeddedSearch.searchBox.getMostVisitedItemData(args.rid); | 299 var data = chrome.embeddedSearch.searchBox.getMostVisitedItemData(args.rid); |
304 if (!data) | 300 if (!data) |
305 return; | 301 return; |
306 | 302 |
307 data.tid = data.rid; | 303 data.tid = data.rid; |
308 data.tileSource = NTPLoggingTileSource.CLIENT; | 304 data.tileSource = NTPLoggingTileSource.CLIENT; |
309 if (!data.faviconUrl) { | 305 if (!data.faviconUrl) { |
310 data.faviconUrl = 'chrome-search://favicon/size/16@' + | 306 data.faviconUrl = 'chrome-search://favicon/size/16@' + |
311 window.devicePixelRatio + 'x/' + data.renderViewId + '/' + data.tid; | 307 window.devicePixelRatio + 'x/' + data.renderViewId + '/' + data.tid; |
312 } | 308 } |
313 logEvent(LOG_TYPE.NTP_CLIENT_SIDE_SUGGESTION); | |
314 tiles.appendChild(renderTile(data)); | 309 tiles.appendChild(renderTile(data)); |
315 } else if (args.url) { | 310 } else if (args.url) { |
316 // If a URL is passed: a server-side suggestion. | 311 // If a URL is passed: a server-side suggestion. |
317 args.tileSource = NTPLoggingTileSource.SERVER; | 312 args.tileSource = NTPLoggingTileSource.SERVER; |
318 // check sanity of the arguments | 313 // check sanity of the arguments |
319 if (/^javascript:/i.test(args.url) || | 314 if (/^javascript:/i.test(args.url) || |
320 /^javascript:/i.test(args.thumbnailUrl)) | 315 /^javascript:/i.test(args.thumbnailUrl)) |
321 return; | 316 return; |
322 logEvent(LOG_TYPE.NTP_SERVER_SIDE_SUGGESTION); | |
323 tiles.appendChild(renderTile(args)); | 317 tiles.appendChild(renderTile(args)); |
324 } else { // an empty tile | 318 } else { // an empty tile |
325 tiles.appendChild(renderTile(null)); | 319 tiles.appendChild(renderTile(null)); |
326 } | 320 } |
327 }; | 321 }; |
328 | 322 |
329 /** | 323 /** |
330 * Called when the user decided to add a tile to the blacklist. | 324 * Called when the user decided to add a tile to the blacklist. |
331 * It sets of the animation for the blacklist and sends the blacklisted id | 325 * It sets of the animation for the blacklist and sends the blacklisted id |
332 * to the host page. | 326 * to the host page. |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 var html = document.querySelector('html'); | 605 var html = document.querySelector('html'); |
612 html.dir = 'rtl'; | 606 html.dir = 'rtl'; |
613 } | 607 } |
614 | 608 |
615 window.addEventListener('message', handlePostMessage); | 609 window.addEventListener('message', handlePostMessage); |
616 }; | 610 }; |
617 | 611 |
618 | 612 |
619 window.addEventListener('DOMContentLoaded', init); | 613 window.addEventListener('DOMContentLoaded', init); |
620 })(); | 614 })(); |
OLD | NEW |