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 // The suggestion is coming from the server. | 19 // The suggestion is coming from the server. |
20 NTP_SERVER_SIDE_SUGGESTION: 0, | 20 NTP_SERVER_SIDE_SUGGESTION: 0, |
21 // The suggestion is coming from the client. | 21 // The suggestion is coming from the client. |
22 NTP_CLIENT_SIDE_SUGGESTION: 1, | 22 NTP_CLIENT_SIDE_SUGGESTION: 1, |
23 // Indicates a tile was rendered, no matter if it's a thumbnail, a gray tile | 23 // Indicates a tile was rendered, no matter if it's a thumbnail, a gray tile |
24 // or an external tile. | 24 // or an external tile. |
25 NTP_TILE: 2, | 25 NTP_TILE: 2, |
26 // A NTP Tile has finished loading (successfully or failing). | 26 // All NTP Tiles have finished loading (successfully or failing). |
27 NTP_TILE_LOADED: 10, | 27 NTP_ALL_TILES_LOADED: 11, |
28 }; | 28 }; |
29 | 29 |
30 | 30 |
31 /** | 31 /** |
32 * The different sources that an NTP tile can have. | 32 * The different sources that an NTP tile can have. |
33 * Note: Keep in sync with common/ntp_logging_events.h | 33 * Note: Keep in sync with common/ntp_logging_events.h |
34 * @enum {number} | 34 * @enum {number} |
35 * @const | 35 * @const |
36 */ | 36 */ |
37 var NTPLoggingTileSource = { | 37 var NTPLoggingTileSource = { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 126 |
127 /** | 127 /** |
128 * Down counts the DOM elements that we are waiting for the page to load. | 128 * Down counts the DOM elements that we are waiting for the page to load. |
129 * When we get to 0, we send a message to the parent window. | 129 * When we get to 0, we send a message to the parent window. |
130 * This is usually used as an EventListener of onload/onerror. | 130 * This is usually used as an EventListener of onload/onerror. |
131 */ | 131 */ |
132 var countLoad = function() { | 132 var countLoad = function() { |
133 loadedCounter -= 1; | 133 loadedCounter -= 1; |
134 if (loadedCounter <= 0) { | 134 if (loadedCounter <= 0) { |
135 showTiles(); | 135 showTiles(); |
136 logEvent(LOG_TYPE.NTP_TILE_LOADED); | 136 logEvent(LOG_TYPE.NTP_ALL_TILES_LOADED); |
137 window.parent.postMessage({cmd: 'loaded'}, DOMAIN_ORIGIN); | 137 window.parent.postMessage({cmd: 'loaded'}, DOMAIN_ORIGIN); |
138 loadedCounter = 1; | 138 loadedCounter = 1; |
139 } | 139 } |
140 }; | 140 }; |
141 | 141 |
142 | 142 |
143 /** | 143 /** |
144 * Handles postMessages coming from the host page to the iframe. | 144 * Handles postMessages coming from the host page to the iframe. |
145 * Mostly, it dispatches every command to handleCommand. | 145 * Mostly, it dispatches every command to handleCommand. |
146 */ | 146 */ |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 var html = document.querySelector('html'); | 610 var html = document.querySelector('html'); |
611 html.dir = 'rtl'; | 611 html.dir = 'rtl'; |
612 } | 612 } |
613 | 613 |
614 window.addEventListener('message', handlePostMessage); | 614 window.addEventListener('message', handlePostMessage); |
615 }; | 615 }; |
616 | 616 |
617 | 617 |
618 window.addEventListener('DOMContentLoaded', init); | 618 window.addEventListener('DOMContentLoaded', init); |
619 })(); | 619 })(); |
OLD | NEW |