| 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 | 5 |
| 6 /** | 6 /** |
| 7 * @fileoverview The local InstantExtended NTP. | 7 * @fileoverview The local InstantExtended NTP. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 | 10 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 /** | 333 /** |
| 334 * Callback for embeddedSearch.newTabPage.onmostvisitedchange. Called when the | 334 * Callback for embeddedSearch.newTabPage.onmostvisitedchange. Called when the |
| 335 * NTP tiles are updated. | 335 * NTP tiles are updated. |
| 336 */ | 336 */ |
| 337 function onMostVisitedChange() { | 337 function onMostVisitedChange() { |
| 338 reloadTiles(); | 338 reloadTiles(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 | 341 |
| 342 /** | 342 /** |
| 343 * Fetches new data, creates, and renders tiles. | 343 * Fetches new data (RIDs) from the embeddedSearch.newTabPage API and passes |
| 344 * them to the iframe. |
| 344 */ | 345 */ |
| 345 function reloadTiles() { | 346 function reloadTiles() { |
| 346 var pages = ntpApiHandle.mostVisited; | 347 var pages = ntpApiHandle.mostVisited; |
| 347 var cmds = []; | 348 var cmds = []; |
| 348 for (var i = 0; i < Math.min(MAX_NUM_TILES_TO_SHOW, pages.length); ++i) { | 349 for (var i = 0; i < Math.min(MAX_NUM_TILES_TO_SHOW, pages.length); ++i) { |
| 349 cmds.push({cmd: 'tile', rid: pages[i].rid}); | 350 cmds.push({cmd: 'tile', rid: pages[i].rid}); |
| 350 } | 351 } |
| 351 cmds.push({cmd: 'show', maxVisible: numColumnsShown * NUM_ROWS}); | 352 cmds.push({cmd: 'show', maxVisible: numColumnsShown * NUM_ROWS}); |
| 352 | 353 |
| 353 $(IDS.TILES_IFRAME).contentWindow.postMessage(cmds, '*'); | 354 $(IDS.TILES_IFRAME).contentWindow.postMessage(cmds, '*'); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 if (NTP_DESIGN.numTitleLines > 1) | 645 if (NTP_DESIGN.numTitleLines > 1) |
| 645 args.push('ntl=' + NTP_DESIGN.numTitleLines); | 646 args.push('ntl=' + NTP_DESIGN.numTitleLines); |
| 646 | 647 |
| 647 args.push('removeTooltip=' + | 648 args.push('removeTooltip=' + |
| 648 encodeURIComponent(configData.translatedStrings.removeThumbnailTooltip)); | 649 encodeURIComponent(configData.translatedStrings.removeThumbnailTooltip)); |
| 649 | 650 |
| 650 // Create the most visited iframe. | 651 // Create the most visited iframe. |
| 651 var iframe = document.createElement('iframe'); | 652 var iframe = document.createElement('iframe'); |
| 652 iframe.id = IDS.TILES_IFRAME; | 653 iframe.id = IDS.TILES_IFRAME; |
| 653 iframe.tabIndex = 1; | 654 iframe.tabIndex = 1; |
| 654 iframe.src = '//most-visited/single.html?' + args.join('&'); | 655 iframe.src = 'chrome-search://most-visited/single.html?' + args.join('&'); |
| 655 $(IDS.TILES).appendChild(iframe); | 656 $(IDS.TILES).appendChild(iframe); |
| 656 | 657 |
| 657 iframe.onload = function() { | 658 iframe.onload = function() { |
| 658 reloadTiles(); | 659 reloadTiles(); |
| 659 renderTheme(); | 660 renderTheme(); |
| 660 }; | 661 }; |
| 661 | 662 |
| 662 window.addEventListener('message', handlePostMessage); | 663 window.addEventListener('message', handlePostMessage); |
| 663 } | 664 } |
| 664 | 665 |
| 665 | 666 |
| 666 /** | 667 /** |
| 667 * Binds event listeners. | 668 * Binds event listeners. |
| 668 */ | 669 */ |
| 669 function listen() { | 670 function listen() { |
| 670 document.addEventListener('DOMContentLoaded', init); | 671 document.addEventListener('DOMContentLoaded', init); |
| 671 } | 672 } |
| 672 | 673 |
| 673 return { | 674 return { |
| 674 init: init, // Exposed for testing. | 675 init: init, // Exposed for testing. |
| 675 listen: listen | 676 listen: listen |
| 676 }; | 677 }; |
| 677 | 678 |
| 678 } | 679 } |
| 679 | 680 |
| 680 if (!window.localNTPUnitTest) { | 681 if (!window.localNTPUnitTest) { |
| 681 LocalNTP().listen(); | 682 LocalNTP().listen(); |
| 682 } | 683 } |
| OLD | NEW |