| 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); |
| 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 27 matching lines...) Expand all Loading... |
| 320 if (ev.propertyName != 'width') return; | 312 if (ev.propertyName != 'width') return; |
| 321 | 313 |
| 322 window.parent.postMessage({cmd: 'tileBlacklisted', | 314 window.parent.postMessage({cmd: 'tileBlacklisted', |
| 323 tid: Number(tile.getAttribute('data-tid'))}, | 315 tid: Number(tile.getAttribute('data-tid'))}, |
| 324 DOMAIN_ORIGIN); | 316 DOMAIN_ORIGIN); |
| 325 }); | 317 }); |
| 326 }; | 318 }; |
| 327 | 319 |
| 328 | 320 |
| 329 /** | 321 /** |
| 322 * Returns whether the given URL has a known, safe scheme. |
| 323 * @param {string} url URL to check. |
| 324 */ |
| 325 var isSchemeAllowed = function(url) { |
| 326 return url.startsWith('http://') || url.startsWith('https://') || |
| 327 url.startsWith('ftp://') || url.startsWith('file://') || |
| 328 url.startsWith('chrome-extension://'); |
| 329 }; |
| 330 |
| 331 |
| 332 /** |
| 330 * Renders a MostVisited tile to the DOM. | 333 * Renders a MostVisited tile to the DOM. |
| 331 * @param {object} data Object containing rid, url, title, favicon, thumbnail. | 334 * @param {object} data Object containing rid, url, title, favicon, thumbnail. |
| 332 * data is null if you want to construct an empty tile. | 335 * data is null if you want to construct an empty tile. |
| 333 */ | 336 */ |
| 334 var renderTile = function(data) { | 337 var renderTile = function(data) { |
| 335 var tile = document.createElement('a'); | 338 var tile = document.createElement('a'); |
| 336 | 339 |
| 337 if (data == null) { | 340 if (data == null) { |
| 338 tile.className = 'mv-empty-tile'; | 341 tile.className = 'mv-empty-tile'; |
| 339 return tile; | 342 return tile; |
| 340 } | 343 } |
| 341 | 344 |
| 342 logEvent(LOG_TYPE.NTP_TILE); | 345 logEvent(LOG_TYPE.NTP_TILE); |
| 343 | 346 |
| 344 tile.className = 'mv-tile'; | 347 tile.className = 'mv-tile'; |
| 345 tile.setAttribute('data-tid', data.tid); | 348 tile.setAttribute('data-tid', data.tid); |
| 346 var tooltip = queryArgs['removeTooltip'] || ''; | |
| 347 var html = []; | 349 var html = []; |
| 348 if (!USE_ICONS) { | 350 if (!USE_ICONS) { |
| 349 html.push('<div class="mv-favicon"></div>'); | 351 html.push('<div class="mv-favicon"></div>'); |
| 350 } | 352 } |
| 351 html.push('<div class="mv-title"></div><div class="mv-thumb"></div>'); | 353 html.push('<div class="mv-title"></div><div class="mv-thumb"></div>'); |
| 352 html.push('<div title="' + tooltip + '" class="mv-x"></div>'); | 354 html.push('<div class="mv-x"></div>'); |
| 353 tile.innerHTML = html.join(''); | 355 tile.innerHTML = html.join(''); |
| 356 tile.lastElementChild.title = queryArgs['removeTooltip'] || ''; |
| 354 | 357 |
| 355 tile.href = data.url; | 358 if (isSchemeAllowed(data.url)) { |
| 359 tile.href = data.url; |
| 360 } |
| 356 tile.title = data.title; | 361 tile.title = data.title; |
| 357 if (data.impressionUrl) { | 362 if (data.impressionUrl) { |
| 358 impressionUrl = data.impressionUrl; | 363 impressionUrl = data.impressionUrl; |
| 359 } | 364 } |
| 360 if (data.pingUrl) { | 365 if (data.pingUrl) { |
| 361 tile.addEventListener('click', function(ev) { | 366 tile.addEventListener('click', function(ev) { |
| 362 if (navigator.sendBeacon) { | 367 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 }); | 368 }); |
| 372 } | 369 } |
| 373 // For local suggestions, we use navigateContentWindow instead of the default | 370 // For local suggestions, we use navigateContentWindow instead of the default |
| 374 // action, since it includes support for file:// urls. | 371 // action, since it includes support for file:// urls. |
| 375 if (data.rid) { | 372 if (data.rid) { |
| 376 tile.addEventListener('click', function(ev) { | 373 tile.addEventListener('click', function(ev) { |
| 377 ev.preventDefault(); | 374 ev.preventDefault(); |
| 378 var disp = chrome.embeddedSearch.newTabPage.getDispositionFromClick( | 375 var disp = chrome.embeddedSearch.newTabPage.getDispositionFromClick( |
| 379 ev.button == 1, // MIDDLE BUTTON | 376 ev.button == 1, // MIDDLE BUTTON |
| 380 ev.altKey, ev.ctrlKey, ev.metaKey, ev.shiftKey); | 377 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'); | 627 var html = document.querySelector('html'); |
| 631 html.dir = 'rtl'; | 628 html.dir = 'rtl'; |
| 632 } | 629 } |
| 633 | 630 |
| 634 window.addEventListener('message', handlePostMessage); | 631 window.addEventListener('message', handlePostMessage); |
| 635 }; | 632 }; |
| 636 | 633 |
| 637 | 634 |
| 638 window.addEventListener('DOMContentLoaded', init); | 635 window.addEventListener('DOMContentLoaded', init); |
| 639 })(); | 636 })(); |
| OLD | NEW |