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"> |
(...skipping 18 matching lines...) Expand all Loading... | |
29 // secondary thumbnail as a fallback. | 29 // secondary thumbnail as a fallback. |
30 NTP_FALLBACK_THUMBNAIL_USED: 4, | 30 NTP_FALLBACK_THUMBNAIL_USED: 4, |
31 // The suggestion is coming from the server. | 31 // The suggestion is coming from the server. |
32 NTP_SERVER_SIDE_SUGGESTION: 5, | 32 NTP_SERVER_SIDE_SUGGESTION: 5, |
33 // The suggestion is coming from the client. | 33 // The suggestion is coming from the client. |
34 NTP_CLIENT_SIDE_SUGGESTION: 6, | 34 NTP_CLIENT_SIDE_SUGGESTION: 6, |
35 // The visuals of that tile are handled externally by the page itself. | 35 // The visuals of that tile are handled externally by the page itself. |
36 NTP_EXTERNAL_TILE: 7 | 36 NTP_EXTERNAL_TILE: 7 |
37 }; | 37 }; |
38 | 38 |
39 /** @type {string} Indicating the suggestion came from the server. */ | |
40 var SERVER_PROVIDER = 'server'; | |
41 | |
42 /** @type {string} Indicating the suggestions came from the client. */ | |
43 var CLIENT_PROVIDER = 'client'; | |
44 | |
39 /** | 45 /** |
40 * Parses query parameters from Location. | 46 * Parses query parameters from Location. |
41 * @param {string} location The URL to generate the CSS url for. | 47 * @param {string} location The URL to generate the CSS url for. |
42 * @return {Object} Dictionary containing name value pairs for URL. | 48 * @return {Object} Dictionary containing name value pairs for URL. |
43 */ | 49 */ |
44 function parseQueryParams(location) { | 50 function parseQueryParams(location) { |
45 var params = Object.create(null); | 51 var params = Object.create(null); |
46 var query = location.search.substring(1); | 52 var query = location.search.substring(1); |
47 var vars = query.split('&'); | 53 var vars = query.split('&'); |
48 for (var i = 0; i < vars.length; i++) { | 54 for (var i = 0; i < vars.length; i++) { |
(...skipping 14 matching lines...) Expand all Loading... | |
63 | 69 |
64 /** | 70 /** |
65 * Creates a new most visited link element. | 71 * Creates a new most visited link element. |
66 * @param {Object} params URL parameters containing styles for the link. | 72 * @param {Object} params URL parameters containing styles for the link. |
67 * @param {string} href The destination for the link. | 73 * @param {string} href The destination for the link. |
68 * @param {string} title The title for the link. | 74 * @param {string} title The title for the link. |
69 * @param {string|undefined} text The text for the link or none. | 75 * @param {string|undefined} text The text for the link or none. |
70 * @param {string|undefined} ping If specified, a location relative to the | 76 * @param {string|undefined} ping If specified, a location relative to the |
71 * referrer of this iframe, to ping when the link is clicked. Only works if | 77 * referrer of this iframe, to ping when the link is clicked. Only works if |
72 * the referrer is HTTPS. | 78 * the referrer is HTTPS. |
79 * @param {string|undefined} provider A provider name (max 8 alphanumeric | |
80 * characters) used for logging. Undefined if suggestion is not coming from | |
81 * the server. | |
73 * @return {HTMLAnchorElement} A new link element. | 82 * @return {HTMLAnchorElement} A new link element. |
74 */ | 83 */ |
75 function createMostVisitedLink(params, href, title, text, ping) { | 84 function createMostVisitedLink(params, href, title, text, ping, provider) { |
76 var styles = getMostVisitedStyles(params, !!text); | 85 var styles = getMostVisitedStyles(params, !!text); |
77 var link = document.createElement('a'); | 86 var link = document.createElement('a'); |
78 link.style.color = styles.color; | 87 link.style.color = styles.color; |
79 link.style.fontSize = styles.fontSize + 'px'; | 88 link.style.fontSize = styles.fontSize + 'px'; |
80 if (styles.fontFamily) | 89 if (styles.fontFamily) |
81 link.style.fontFamily = styles.fontFamily; | 90 link.style.fontFamily = styles.fontFamily; |
82 link.href = href; | 91 link.href = href; |
83 if ('pos' in params && isFinite(params.pos)) { | 92 if ('pos' in params && isFinite(params.pos)) { |
84 link.ping = '/log.html?pos=' + params.pos; | 93 link.ping = '/log.html?pos=' + params.pos; |
94 if (provider) | |
95 link.ping += '&pr=' + provider; | |
85 // If a ping parameter was specified, add it to the list of pings, relative | 96 // If a ping parameter was specified, add it to the list of pings, relative |
86 // to the referrer of this iframe, which is the default search provider. | 97 // to the referrer of this iframe, which is the default search provider. |
87 if (ping) { | 98 if (ping) { |
88 var parentUrl = document.createElement('a'); | 99 var parentUrl = document.createElement('a'); |
89 parentUrl.href = document.referrer; | 100 parentUrl.href = document.referrer; |
90 if (parentUrl.protocol == 'https:') { | 101 if (parentUrl.protocol == 'https:') { |
91 link.ping += ' ' + parentUrl.origin + '/' + ping; | 102 link.ping += ' ' + parentUrl.origin + '/' + ping; |
92 } | 103 } |
93 } | 104 } |
94 } | 105 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 var data = {}; | 166 var data = {}; |
156 if (params.url) { | 167 if (params.url) { |
157 // Means that the suggestion data comes from the server. Create data object. | 168 // Means that the suggestion data comes from the server. Create data object. |
158 data.url = params.url; | 169 data.url = params.url; |
159 data.thumbnailUrl = params.tu || ''; | 170 data.thumbnailUrl = params.tu || ''; |
160 data.thumbnailUrl2 = params.tu2 || ''; | 171 data.thumbnailUrl2 = params.tu2 || ''; |
161 data.title = params.ti || ''; | 172 data.title = params.ti || ''; |
162 data.direction = params.di || ''; | 173 data.direction = params.di || ''; |
163 data.domain = params.dom || ''; | 174 data.domain = params.dom || ''; |
164 data.ping = params.ping || ''; | 175 data.ping = params.ping || ''; |
176 data.provider = params.pr || SERVER_PROVIDER; | |
165 // Log the fact that suggestion was obtained from the server. | 177 // Log the fact that suggestion was obtained from the server. |
166 var ntpApiHandle = chrome.embeddedSearch.newTabPage; | 178 var ntpApiHandle = chrome.embeddedSearch.newTabPage; |
167 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION); | 179 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION); |
168 } else { | 180 } else { |
169 var apiHandle = chrome.embeddedSearch.searchBox; | 181 var apiHandle = chrome.embeddedSearch.searchBox; |
170 data = apiHandle.getMostVisitedItemData(params.rid); | 182 data = apiHandle.getMostVisitedItemData(params.rid); |
171 if (!data) | 183 if (!data) |
172 return; | 184 return; |
185 data.provider = CLIENT_PROVIDER; | |
173 delete data.ping; | 186 delete data.ping; |
174 } | 187 } |
175 if (/^javascript:/i.test(data.url) || | 188 if (/^javascript:/i.test(data.url) || |
176 /^javascript:/i.test(data.thumbnailUrl) || | 189 /^javascript:/i.test(data.thumbnailUrl) || |
177 /^javascript:/i.test(data.thumbnailUrl2)) | 190 /^javascript:/i.test(data.thumbnailUrl2) || |
191 !/^[a-z0-9]{0,8}$/i.test(data.provider)) | |
Jered
2013/12/13 19:39:38
/^[a-z0-9]{0,8}$/i.test(undefined) is false. Did y
Mathieu
2013/12/13 20:00:38
From the if..else above it should never be undefin
| |
178 return; | 192 return; |
179 if (data.direction) | 193 if (data.direction) |
180 document.body.dir = data.direction; | 194 document.body.dir = data.direction; |
181 fill(params, data); | 195 fill(params, data); |
182 } | 196 } |
OLD | NEW |