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 <include src="instant_iframe_validation.js"> | 10 <include src="instant_iframe_validation.js"> |
11 | 11 |
12 /** | 12 /** |
13 * Enum for the different types of events that are logged from the NTP. | 13 * The different types of events that are logged from the NTP. This enum is |
| 14 * used to transfer information from the NTP javascript to the renderer and is |
| 15 * not used as a UMA enum histogram's logged value. |
| 16 * Note: Keep in sync with common/ntp_logging_events.h |
14 * @enum {number} | 17 * @enum {number} |
15 * @const | 18 * @const |
16 */ | 19 */ |
17 var NTP_LOGGING_EVENT_TYPE = { | 20 var NTP_LOGGING_EVENT_TYPE = { |
18 // The user moused over an NTP tile or title. | 21 // The suggestion is coming from the server. |
19 NTP_MOUSEOVER: 0, | 22 NTP_SERVER_SIDE_SUGGESTION: 0, |
20 // The page attempted to load a thumbnail image. | 23 // The suggestion is coming from the client. |
21 NTP_THUMBNAIL_ATTEMPT: 1, | 24 NTP_CLIENT_SIDE_SUGGESTION: 1, |
| 25 // Indicates a tile was rendered, no matter if it's a thumbnail, a gray tile |
| 26 // or an external tile. |
| 27 NTP_TILE: 2, |
| 28 // The tile uses a local thumbnail image. |
| 29 NTP_THUMBNAIL_TILE: 3, |
| 30 // Used when no thumbnail is specified and a gray tile with the domain is used |
| 31 // as the main tile. |
| 32 NTP_GRAY_TILE: 4, |
| 33 // The visuals of that tile are handled externally by the page itself. |
| 34 NTP_EXTERNAL_TILE: 5, |
22 // There was an error in loading both the thumbnail image and the fallback | 35 // There was an error in loading both the thumbnail image and the fallback |
23 // (if it was provided), resulting in a grey tile. | 36 // (if it was provided), resulting in a grey tile. |
24 NTP_THUMBNAIL_ERROR: 2, | 37 NTP_THUMBNAIL_ERROR: 6, |
25 // The page attempted to load a thumbnail URL while a fallback thumbnail was | 38 // Used a gray tile with the domain as the fallback for a failed thumbnail. |
26 // provided. | 39 NTP_GRAY_TILE_FALLBACK: 7, |
27 NTP_FALLBACK_THUMBNAIL_REQUESTED: 3, | 40 // The visuals of that tile's fallback are handled externally. |
28 // The primary thumbnail image failed to load and caused us to use the | 41 NTP_EXTERNAL_TILE_FALLBACK: 8, |
29 // secondary thumbnail as a fallback. | 42 // The user moused over an NTP tile or title. |
30 NTP_FALLBACK_THUMBNAIL_USED: 4, | 43 NTP_MOUSEOVER: 9 |
31 // The suggestion is coming from the server. | |
32 NTP_SERVER_SIDE_SUGGESTION: 5, | |
33 // The suggestion is coming from the client. | |
34 NTP_CLIENT_SIDE_SUGGESTION: 6, | |
35 // The visuals of that tile are handled externally by the page itself. | |
36 NTP_EXTERNAL_TILE: 7 | |
37 }; | 44 }; |
38 | 45 |
39 /** | 46 /** |
40 * Type of the impression provider for a generic client-provided suggestion. | 47 * Type of the impression provider for a generic client-provided suggestion. |
41 * @type {string} | 48 * @type {string} |
42 * @const | 49 * @const |
43 */ | 50 */ |
44 var CLIENT_PROVIDER_NAME = 'client'; | 51 var CLIENT_PROVIDER_NAME = 'client'; |
45 | 52 |
46 /** | 53 /** |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return; | 176 return; |
170 // Log whether the suggestion was obtained from the server or the client. | 177 // Log whether the suggestion was obtained from the server or the client. |
171 chrome.embeddedSearch.newTabPage.logEvent(params.url ? | 178 chrome.embeddedSearch.newTabPage.logEvent(params.url ? |
172 NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION : | 179 NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION : |
173 NTP_LOGGING_EVENT_TYPE.NTP_CLIENT_SIDE_SUGGESTION); | 180 NTP_LOGGING_EVENT_TYPE.NTP_CLIENT_SIDE_SUGGESTION); |
174 var data = {}; | 181 var data = {}; |
175 if (params.url) { | 182 if (params.url) { |
176 // Means that the suggestion data comes from the server. Create data object. | 183 // Means that the suggestion data comes from the server. Create data object. |
177 data.url = params.url; | 184 data.url = params.url; |
178 data.thumbnailUrl = params.tu || ''; | 185 data.thumbnailUrl = params.tu || ''; |
179 data.thumbnailUrl2 = params.tu2 || ''; | |
180 data.title = params.ti || ''; | 186 data.title = params.ti || ''; |
181 data.direction = params.di || ''; | 187 data.direction = params.di || ''; |
182 data.domain = params.dom || ''; | 188 data.domain = params.dom || ''; |
183 data.ping = params.ping || ''; | 189 data.ping = params.ping || ''; |
184 data.provider = params.pr || SERVER_PROVIDER_NAME; | 190 data.provider = params.pr || SERVER_PROVIDER_NAME; |
185 | 191 |
186 // Log the fact that suggestion was obtained from the server. | 192 // Log the fact that suggestion was obtained from the server. |
187 var ntpApiHandle = chrome.embeddedSearch.newTabPage; | 193 var ntpApiHandle = chrome.embeddedSearch.newTabPage; |
188 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION); | 194 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION); |
189 } else { | 195 } else { |
190 var apiHandle = chrome.embeddedSearch.searchBox; | 196 var apiHandle = chrome.embeddedSearch.searchBox; |
191 data = apiHandle.getMostVisitedItemData(params.rid); | 197 data = apiHandle.getMostVisitedItemData(params.rid); |
192 if (!data) | 198 if (!data) |
193 return; | 199 return; |
194 data.provider = CLIENT_PROVIDER_NAME; | 200 data.provider = CLIENT_PROVIDER_NAME; |
195 delete data.ping; | 201 delete data.ping; |
196 } | 202 } |
197 if (/^javascript:/i.test(data.url) || | 203 if (/^javascript:/i.test(data.url) || |
198 /^javascript:/i.test(data.thumbnailUrl) || | 204 /^javascript:/i.test(data.thumbnailUrl) || |
199 /^javascript:/i.test(data.thumbnailUrl2) || | |
200 !/^[a-z0-9]{0,8}$/i.test(data.provider)) | 205 !/^[a-z0-9]{0,8}$/i.test(data.provider)) |
201 return; | 206 return; |
202 if (data.direction) | 207 if (data.direction) |
203 document.body.dir = data.direction; | 208 document.body.dir = data.direction; |
204 fill(params, data); | 209 fill(params, data); |
205 } | 210 } |
OLD | NEW |