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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 /** | 78 /** |
79 * Creates a new most visited link element. | 79 * Creates a new most visited link element. |
80 * @param {Object} params URL parameters containing styles for the link. | 80 * @param {Object} params URL parameters containing styles for the link. |
81 * @param {string} href The destination for the link. | 81 * @param {string} href The destination for the link. |
82 * @param {string} title The title for the link. | 82 * @param {string} title The title for the link. |
83 * @param {string|undefined} text The text for the link or none. | 83 * @param {string|undefined} text The text for the link or none. |
84 * @param {string|undefined} ping If specified, a location relative to the | 84 * @param {string|undefined} ping If specified, a location relative to the |
85 * referrer of this iframe, to ping when the link is clicked. Only works if | 85 * referrer of this iframe, to ping when the link is clicked. Only works if |
86 * the referrer is HTTPS. | 86 * the referrer is HTTPS. |
| 87 * @param {string|undefined} provider A provider name (max 8 alphanumeric |
| 88 * characters) used for logging. Undefined if suggestion is not coming from |
| 89 * the server. |
87 * @return {HTMLAnchorElement} A new link element. | 90 * @return {HTMLAnchorElement} A new link element. |
88 */ | 91 */ |
89 function createMostVisitedLink(params, href, title, text, ping) { | 92 function createMostVisitedLink(params, href, title, text, ping, provider) { |
90 var styles = getMostVisitedStyles(params, !!text); | 93 var styles = getMostVisitedStyles(params, !!text); |
91 var link = document.createElement('a'); | 94 var link = document.createElement('a'); |
92 link.style.color = styles.color; | 95 link.style.color = styles.color; |
93 link.style.fontSize = styles.fontSize + 'px'; | 96 link.style.fontSize = styles.fontSize + 'px'; |
94 if (styles.fontFamily) | 97 if (styles.fontFamily) |
95 link.style.fontFamily = styles.fontFamily; | 98 link.style.fontFamily = styles.fontFamily; |
96 link.href = href; | 99 link.href = href; |
97 if ('pos' in params && isFinite(params.pos)) { | 100 if ('pos' in params && isFinite(params.pos)) { |
98 link.ping = '/log.html?pos=' + params.pos; | 101 link.ping = '/log.html?pos=' + params.pos; |
| 102 if (provider) |
| 103 link.ping += '&pr=' + provider; |
99 // If a ping parameter was specified, add it to the list of pings, relative | 104 // If a ping parameter was specified, add it to the list of pings, relative |
100 // to the referrer of this iframe, which is the default search provider. | 105 // to the referrer of this iframe, which is the default search provider. |
101 if (ping) { | 106 if (ping) { |
102 var parentUrl = document.createElement('a'); | 107 var parentUrl = document.createElement('a'); |
103 parentUrl.href = document.referrer; | 108 parentUrl.href = document.referrer; |
104 if (parentUrl.protocol == 'https:') { | 109 if (parentUrl.protocol == 'https:') { |
105 link.ping += ' ' + parentUrl.origin + '/' + ping; | 110 link.ping += ' ' + parentUrl.origin + '/' + ping; |
106 } | 111 } |
107 } | 112 } |
108 } | 113 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 var apiHandle = chrome.embeddedSearch.searchBox; | 190 var apiHandle = chrome.embeddedSearch.searchBox; |
186 data = apiHandle.getMostVisitedItemData(params.rid); | 191 data = apiHandle.getMostVisitedItemData(params.rid); |
187 if (!data) | 192 if (!data) |
188 return; | 193 return; |
189 data.provider = CLIENT_PROVIDER_NAME; | 194 data.provider = CLIENT_PROVIDER_NAME; |
190 delete data.ping; | 195 delete data.ping; |
191 } | 196 } |
192 if (/^javascript:/i.test(data.url) || | 197 if (/^javascript:/i.test(data.url) || |
193 /^javascript:/i.test(data.thumbnailUrl) || | 198 /^javascript:/i.test(data.thumbnailUrl) || |
194 /^javascript:/i.test(data.thumbnailUrl2) || | 199 /^javascript:/i.test(data.thumbnailUrl2) || |
195 (data.provider && !/^[a-z0-9]{0,8}$/i.test(data.provider))) | 200 !/^[a-z0-9]{0,8}$/i.test(data.provider)) |
196 return; | 201 return; |
197 if (data.direction) | 202 if (data.direction) |
198 document.body.dir = data.direction; | 203 document.body.dir = data.direction; |
199 fill(params, data); | 204 fill(params, data); |
200 } | 205 } |
OLD | NEW |