Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* Copyright 2015 The Chromium Authors. All rights reserved. | 1 /* Copyright 2015 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 // Single iframe for NTP tiles. | 5 // Single iframe for NTP tiles. |
| 6 (function() { | 6 (function() { |
| 7 'use strict'; | 7 'use strict'; |
| 8 | 8 |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 // We want the CSS transition to trigger, so need to add to the DOM before | 264 // We want the CSS transition to trigger, so need to add to the DOM before |
| 265 // setting the style. | 265 // setting the style. |
| 266 setTimeout(function() { | 266 setTimeout(function() { |
| 267 cur.style.opacity = 1.0; | 267 cur.style.opacity = 1.0; |
| 268 }, 0); | 268 }, 0); |
| 269 | 269 |
| 270 // Make sure the tiles variable contain the next tileset we may use. | 270 // Make sure the tiles variable contain the next tileset we may use. |
| 271 tiles = document.createElement('div'); | 271 tiles = document.createElement('div'); |
| 272 | 272 |
| 273 if (impressionUrl) { | 273 if (impressionUrl) { |
| 274 if (navigator.sendBeacon) { | 274 navigator.sendBeacon(impressionUrl); |
|
Marc Treib
2016/03/09 15:24:02
navigator.sendBeacon has existed since Chrome 39,
| |
| 275 navigator.sendBeacon(impressionUrl); | |
| 276 } else { | |
| 277 // if sendBeacon is not enabled, we fallback to "a ping". | |
| 278 var a = document.createElement('a'); | |
| 279 a.href = '#'; | |
| 280 a.ping = impressionUrl; | |
| 281 a.click(); | |
| 282 } | |
| 283 impressionUrl = null; | 275 impressionUrl = null; |
| 284 } | 276 } |
| 285 }; | 277 }; |
| 286 | 278 |
| 287 | 279 |
| 288 /** | 280 /** |
| 289 * Called when the host page wants to add a suggestion tile. | 281 * Called when the host page wants to add a suggestion tile. |
| 290 * For Most Visited, it grabs the data from Chrome and pass on. | 282 * For Most Visited, it grabs the data from Chrome and pass on. |
| 291 * For host page generated it just passes the data. | 283 * For host page generated it just passes the data. |
| 292 * @param {object} args Data for the tile to be rendered. | 284 * @param {object} args Data for the tile to be rendered. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 | 328 |
| 337 if (data == null) { | 329 if (data == null) { |
| 338 tile.className = 'mv-empty-tile'; | 330 tile.className = 'mv-empty-tile'; |
| 339 return tile; | 331 return tile; |
| 340 } | 332 } |
| 341 | 333 |
| 342 logEvent(LOG_TYPE.NTP_TILE); | 334 logEvent(LOG_TYPE.NTP_TILE); |
| 343 | 335 |
| 344 tile.className = 'mv-tile'; | 336 tile.className = 'mv-tile'; |
| 345 tile.setAttribute('data-tid', data.tid); | 337 tile.setAttribute('data-tid', data.tid); |
| 346 var tooltip = queryArgs['removeTooltip'] || ''; | |
| 347 var html = []; | 338 var html = []; |
| 348 if (!USE_ICONS) { | 339 if (!USE_ICONS) { |
| 349 html.push('<div class="mv-favicon"></div>'); | 340 html.push('<div class="mv-favicon"></div>'); |
| 350 } | 341 } |
| 351 html.push('<div class="mv-title"></div><div class="mv-thumb"></div>'); | 342 html.push('<div class="mv-title"></div><div class="mv-thumb"></div>'); |
| 352 html.push('<div title="' + tooltip + '" class="mv-x"></div>'); | 343 html.push('<div class="mv-x"></div>'); |
| 353 tile.innerHTML = html.join(''); | 344 tile.innerHTML = html.join(''); |
| 345 tile.lastElementChild.title = queryArgs['removeTooltip'] || ''; | |
| 354 | 346 |
| 355 tile.href = data.url; | 347 if (!data.url.startsWith('javascript:')) { |
|
jochen (gone - plz use gerrit)
2016/03/09 15:26:41
what about blob URLs etc? Would prefer a whitelist
Marc Treib
2016/03/09 16:28:34
I agree that a whitelist is generally nicer, but I
| |
| 348 tile.href = data.url; | |
| 349 } | |
| 356 tile.title = data.title; | 350 tile.title = data.title; |
| 357 if (data.impressionUrl) { | 351 if (data.impressionUrl) { |
| 358 impressionUrl = data.impressionUrl; | 352 impressionUrl = data.impressionUrl; |
| 359 } | 353 } |
| 360 if (data.pingUrl) { | 354 if (data.pingUrl) { |
| 361 tile.addEventListener('click', function(ev) { | 355 tile.addEventListener('click', function(ev) { |
| 362 if (navigator.sendBeacon) { | 356 navigator.sendBeacon(data.pingUrl); |
| 363 navigator.sendBeacon(data.pingUrl); | |
| 364 } else { | |
| 365 // if sendBeacon is not enabled, we fallback to "a ping". | |
| 366 var a = document.createElement('a'); | |
| 367 a.href = '#'; | |
| 368 a.ping = data.pingUrl; | |
| 369 a.click(); | |
| 370 } | |
| 371 }); | 357 }); |
| 372 } | 358 } |
| 373 // For local suggestions, we use navigateContentWindow instead of the default | 359 // For local suggestions, we use navigateContentWindow instead of the default |
| 374 // action, since it includes support for file:// urls. | 360 // action, since it includes support for file:// urls. |
| 375 if (data.rid) { | 361 if (data.rid) { |
| 376 tile.addEventListener('click', function(ev) { | 362 tile.addEventListener('click', function(ev) { |
| 377 ev.preventDefault(); | 363 ev.preventDefault(); |
| 378 var disp = chrome.embeddedSearch.newTabPage.getDispositionFromClick( | 364 var disp = chrome.embeddedSearch.newTabPage.getDispositionFromClick( |
| 379 ev.button == 1, // MIDDLE BUTTON | 365 ev.button == 1, // MIDDLE BUTTON |
| 380 ev.altKey, ev.ctrlKey, ev.metaKey, ev.shiftKey); | 366 ev.altKey, ev.ctrlKey, ev.metaKey, ev.shiftKey); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 var html = document.querySelector('html'); | 616 var html = document.querySelector('html'); |
| 631 html.dir = 'rtl'; | 617 html.dir = 'rtl'; |
| 632 } | 618 } |
| 633 | 619 |
| 634 window.addEventListener('message', handlePostMessage); | 620 window.addEventListener('message', handlePostMessage); |
| 635 }; | 621 }; |
| 636 | 622 |
| 637 | 623 |
| 638 window.addEventListener('DOMContentLoaded', init); | 624 window.addEventListener('DOMContentLoaded', init); |
| 639 })(); | 625 })(); |
| OLD | NEW |