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 <include src="window_disposition_util.js"> | |
12 | 11 |
13 | 12 |
14 /** | 13 /** |
15 * The different types of events that are logged from the NTP. This enum is | 14 * The different types of events that are logged from the NTP. This enum is |
16 * used to transfer information from the NTP javascript to the renderer and is | 15 * used to transfer information from the NTP javascript to the renderer and is |
17 * not used as a UMA enum histogram's logged value. | 16 * not used as a UMA enum histogram's logged value. |
18 * Note: Keep in sync with common/ntp_logging_events.h | 17 * Note: Keep in sync with common/ntp_logging_events.h |
19 * @enum {number} | 18 * @enum {number} |
20 * @const | 19 * @const |
21 */ | 20 */ |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 var ntpApiHandle = chrome.embeddedSearch.newTabPage; | 140 var ntpApiHandle = chrome.embeddedSearch.newTabPage; |
142 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER); | 141 ntpApiHandle.logEvent(NTP_LOGGING_EVENT_TYPE.NTP_MOUSEOVER); |
143 }); | 142 }); |
144 link.addEventListener('focus', function() { | 143 link.addEventListener('focus', function() { |
145 window.parent.postMessage('linkFocused', DOMAIN_ORIGIN); | 144 window.parent.postMessage('linkFocused', DOMAIN_ORIGIN); |
146 }); | 145 }); |
147 link.addEventListener('blur', function() { | 146 link.addEventListener('blur', function() { |
148 window.parent.postMessage('linkBlurred', DOMAIN_ORIGIN); | 147 window.parent.postMessage('linkBlurred', DOMAIN_ORIGIN); |
149 }); | 148 }); |
150 | 149 |
151 // Webkit's security policy prevents some Most Visited thumbnails from | |
152 // working (those with schemes different from http and https). Therefore, | |
153 // navigateContentWindow is being used in order to get all schemes working. | |
154 var navigateFunction = function handleNavigation(e) { | 150 var navigateFunction = function handleNavigation(e) { |
155 var isServerSuggestion = 'url' in params; | 151 var isServerSuggestion = 'url' in params; |
156 | 152 |
157 // Ping are only populated for server-side suggestions, never for MV. | 153 // Ping are only populated for server-side suggestions, never for MV. |
158 if (isServerSuggestion && params.ping) { | 154 if (isServerSuggestion && params.ping) { |
159 generatePing(DOMAIN_ORIGIN + params.ping); | 155 generatePing(DOMAIN_ORIGIN + params.ping); |
160 } | 156 } |
161 | 157 |
162 var ntpApiHandle = chrome.embeddedSearch.newTabPage; | 158 var ntpApiHandle = chrome.embeddedSearch.newTabPage; |
163 if ('pos' in params && isFinite(params.pos)) { | 159 if ('pos' in params && isFinite(params.pos)) { |
164 ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10), | 160 ntpApiHandle.logMostVisitedNavigation(parseInt(params.pos, 10), |
165 provider || ''); | 161 provider || ''); |
166 } | 162 } |
167 | 163 |
168 if ('rid' in params) { | 164 // Follow <a> normally, so transition type will be LINK. |
169 e.preventDefault(); | |
170 ntpApiHandle.navigateContentWindow(params.rid, | |
171 getDispositionFromEvent(e)); | |
172 } | |
173 // Else follow <a> normally, so transition type would be LINK. | |
174 }; | 165 }; |
175 | 166 |
176 link.addEventListener('click', navigateFunction); | 167 link.addEventListener('click', navigateFunction); |
177 link.addEventListener('keydown', function(event) { | 168 link.addEventListener('keydown', function(event) { |
178 if (event.keyCode == 46 /* DELETE */ || | 169 if (event.keyCode == 46 /* DELETE */ || |
179 event.keyCode == 8 /* BACKSPACE */) { | 170 event.keyCode == 8 /* BACKSPACE */) { |
180 event.preventDefault(); | 171 event.preventDefault(); |
181 window.parent.postMessage('tileBlacklisted,' + params.pos, DOMAIN_ORIGIN); | 172 window.parent.postMessage('tileBlacklisted,' + params.pos, DOMAIN_ORIGIN); |
182 } else if (event.keyCode == 13 /* ENTER */ || | 173 } else if (event.keyCode == 13 /* ENTER */ || |
183 event.keyCode == 32 /* SPACE */) { | 174 event.keyCode == 32 /* SPACE */) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 if (navigator.sendBeacon) { | 309 if (navigator.sendBeacon) { |
319 navigator.sendBeacon(url); | 310 navigator.sendBeacon(url); |
320 } else { | 311 } else { |
321 // if sendBeacon is not enabled, we fallback for "a ping". | 312 // if sendBeacon is not enabled, we fallback for "a ping". |
322 var a = document.createElement('a'); | 313 var a = document.createElement('a'); |
323 a.href = '#'; | 314 a.href = '#'; |
324 a.ping = url; | 315 a.ping = url; |
325 a.click(); | 316 a.click(); |
326 } | 317 } |
327 } | 318 } |
OLD | NEW |