Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: chrome/browser/resources/local_ntp/most_visited_util.js

Issue 178253008: Redoing Issue 36073011: Allowing file:/// in Instant Extended's Most Visited links. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused consts. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <include src="window_disposition_util.js">
12
11 13
12 /** 14 /**
13 * The different types of events that are logged from the NTP. This enum is 15 * 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 16 * used to transfer information from the NTP javascript to the renderer and is
15 * not used as a UMA enum histogram's logged value. 17 * not used as a UMA enum histogram's logged value.
16 * Note: Keep in sync with common/ntp_logging_events.h 18 * Note: Keep in sync with common/ntp_logging_events.h
17 * @enum {number} 19 * @enum {number}
18 * @const 20 * @const
19 */ 21 */
20 var NTP_LOGGING_EVENT_TYPE = { 22 var NTP_LOGGING_EVENT_TYPE = {
(...skipping 15 matching lines...) Expand all
36 // (if it was provided), resulting in a grey tile. 38 // (if it was provided), resulting in a grey tile.
37 NTP_THUMBNAIL_ERROR: 6, 39 NTP_THUMBNAIL_ERROR: 6,
38 // Used a gray tile with the domain as the fallback for a failed thumbnail. 40 // Used a gray tile with the domain as the fallback for a failed thumbnail.
39 NTP_GRAY_TILE_FALLBACK: 7, 41 NTP_GRAY_TILE_FALLBACK: 7,
40 // The visuals of that tile's fallback are handled externally. 42 // The visuals of that tile's fallback are handled externally.
41 NTP_EXTERNAL_TILE_FALLBACK: 8, 43 NTP_EXTERNAL_TILE_FALLBACK: 8,
42 // The user moused over an NTP tile or title. 44 // The user moused over an NTP tile or title.
43 NTP_MOUSEOVER: 9 45 NTP_MOUSEOVER: 9
44 }; 46 };
45 47
48
46 /** 49 /**
47 * Type of the impression provider for a generic client-provided suggestion. 50 * Type of the impression provider for a generic client-provided suggestion.
48 * @type {string} 51 * @type {string}
49 * @const 52 * @const
50 */ 53 */
51 var CLIENT_PROVIDER_NAME = 'client'; 54 var CLIENT_PROVIDER_NAME = 'client';
52 55
53 /** 56 /**
54 * Type of the impression provider for a generic server-provided suggestion. 57 * Type of the impression provider for a generic server-provided suggestion.
55 * @type {string} 58 * @type {string}
(...skipping 25 matching lines...) Expand all
81 return params; 84 return params;
82 } 85 }
83 86
84 87
85 /** 88 /**
86 * Creates a new most visited link element. 89 * Creates a new most visited link element.
87 * @param {Object} params URL parameters containing styles for the link. 90 * @param {Object} params URL parameters containing styles for the link.
88 * @param {string} href The destination for the link. 91 * @param {string} href The destination for the link.
89 * @param {string} title The title for the link. 92 * @param {string} title The title for the link.
90 * @param {string|undefined} text The text for the link or none. 93 * @param {string|undefined} text The text for the link or none.
91 * @param {string|undefined} ping If specified, a location relative to the
92 * referrer of this iframe, to ping when the link is clicked. Only works if
93 * the referrer is HTTPS.
94 * @param {string|undefined} provider A provider name (max 8 alphanumeric 94 * @param {string|undefined} provider A provider name (max 8 alphanumeric
95 * characters) used for logging. Undefined if suggestion is not coming from 95 * characters) used for logging. Undefined if suggestion is not coming from
96 * the server. 96 * the server.
97 * @return {HTMLAnchorElement} A new link element. 97 * @return {HTMLAnchorElement} A new link element.
98 */ 98 */
99 function createMostVisitedLink(params, href, title, text, ping, provider) { 99 function createMostVisitedLink(params, href, title, text, provider) {
100 var styles = getMostVisitedStyles(params, !!text); 100 var styles = getMostVisitedStyles(params, !!text);
101 var link = document.createElement('a'); 101 var link = document.createElement('a');
102 link.style.color = styles.color; 102 link.style.color = styles.color;
103 link.style.fontSize = styles.fontSize + 'px'; 103 link.style.fontSize = styles.fontSize + 'px';
104 if (styles.fontFamily) 104 if (styles.fontFamily)
105 link.style.fontFamily = styles.fontFamily; 105 link.style.fontFamily = styles.fontFamily;
106
106 link.href = href; 107 link.href = href;
107 if ('pos' in params && isFinite(params.pos)) {
108 link.ping = '/log.html?pos=' + params.pos;
109 if (provider)
110 link.ping += '&pr=' + provider;
111 // If a ping parameter was specified, add it to the list of pings, relative
112 // to the referrer of this iframe, which is the default search provider.
113 if (ping) {
114 var parentUrl = document.createElement('a');
115 parentUrl.href = document.referrer;
116 if (parentUrl.protocol == 'https:') {
117 link.ping += ' ' + parentUrl.origin + '/' + ping;
118 }
119 }
120 }
121 link.title = title; 108 link.title = title;
122 link.target = '_top'; 109 link.target = '_top';
123 // Exclude links from the tab order. The tabIndex is added to the thumbnail 110 // Exclude links from the tab order. The tabIndex is added to the thumbnail
124 // parent container instead. 111 // parent container instead.
125 link.tabIndex = '-1'; 112 link.tabIndex = '-1';
126 if (text) 113 if (text)
127 link.textContent = text; 114 link.textContent = text;
128 link.addEventListener('mouseover', function() { 115 link.addEventListener('mouseover', function() {
129 var ntpApiHandle = chrome.embeddedSearch.newTabPage; 116 var ntpApiHandle = chrome.embeddedSearch.newTabPage;
130 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER); 117 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER);
131 }); 118 });
119
120 // Webkit's security policy prevents some Most Visited thumbnails from
121 // working (those with schemes different from http and https). Therefore,
122 // navigateContentWindow is being used in order to get all schemes working.
123 link.addEventListener('click', function handleNavigation(e) {
124 e.preventDefault();
125 var ntpApiHandle = chrome.embeddedSearch.newTabPage;
126 if ('pos' in params && isFinite(params.pos)) {
127 ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10),
128 provider || '');
129 }
130 ntpApiHandle.navigateContentWindow(href, getDispositionFromEvent(e));
131 });
132
132 return link; 133 return link;
133 } 134 }
134 135
135 136
136 /** 137 /**
137 * Decodes most visited styles from URL parameters. 138 * Decodes most visited styles from URL parameters.
138 * - f: font-family 139 * - f: font-family
139 * - fs: font-size as a number in pixels. 140 * - fs: font-size as a number in pixels.
140 * - c: A hexadecimal number interpreted as a hex color code. 141 * - c: A hexadecimal number interpreted as a hex color code.
141 * @param {Object.<string, string>} params URL parameters specifying style. 142 * @param {Object.<string, string>} params URL parameters specifying style.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION : 180 NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION :
180 NTP_LOGGING_EVENT_TYPE.NTP_CLIENT_SIDE_SUGGESTION); 181 NTP_LOGGING_EVENT_TYPE.NTP_CLIENT_SIDE_SUGGESTION);
181 var data = {}; 182 var data = {};
182 if (params.url) { 183 if (params.url) {
183 // Means that the suggestion data comes from the server. Create data object. 184 // Means that the suggestion data comes from the server. Create data object.
184 data.url = params.url; 185 data.url = params.url;
185 data.thumbnailUrl = params.tu || ''; 186 data.thumbnailUrl = params.tu || '';
186 data.title = params.ti || ''; 187 data.title = params.ti || '';
187 data.direction = params.di || ''; 188 data.direction = params.di || '';
188 data.domain = params.dom || ''; 189 data.domain = params.dom || '';
189 data.ping = params.ping || '';
190 data.provider = params.pr || SERVER_PROVIDER_NAME; 190 data.provider = params.pr || SERVER_PROVIDER_NAME;
191 191
192 // Log the fact that suggestion was obtained from the server. 192 // Log the fact that suggestion was obtained from the server.
193 var ntpApiHandle = chrome.embeddedSearch.newTabPage; 193 var ntpApiHandle = chrome.embeddedSearch.newTabPage;
194 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION); 194 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_SERVER_SIDE_SUGGESTION);
195 } else { 195 } else {
196 var apiHandle = chrome.embeddedSearch.searchBox; 196 var apiHandle = chrome.embeddedSearch.searchBox;
197 data = apiHandle.getMostVisitedItemData(params.rid); 197 data = apiHandle.getMostVisitedItemData(params.rid);
198 if (!data) 198 if (!data)
199 return; 199 return;
200 // Allow server-side provider override. 200 // Allow server-side provider override.
201 data.provider = params.pr || CLIENT_PROVIDER_NAME; 201 data.provider = params.pr || CLIENT_PROVIDER_NAME;
202 delete data.ping;
203 } 202 }
204 if (/^javascript:/i.test(data.url) || 203 if (/^javascript:/i.test(data.url) ||
205 /^javascript:/i.test(data.thumbnailUrl) || 204 /^javascript:/i.test(data.thumbnailUrl) ||
206 !/^[a-z0-9]{0,8}$/i.test(data.provider)) 205 !/^[a-z0-9]{0,8}$/i.test(data.provider))
207 return; 206 return;
208 if (data.direction) 207 if (data.direction)
209 document.body.dir = data.direction; 208 document.body.dir = data.direction;
210 fill(params, data); 209 fill(params, data);
211 } 210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698