| Index: chrome/browser/resources/ntp_search/thumbnail_page.js
|
| diff --git a/chrome/browser/resources/ntp_search/thumbnail_page.js b/chrome/browser/resources/ntp_search/thumbnail_page.js
|
| index 5213864e84d0258940ebe2a54d0d444e8c6f9ddc..a5e63cc4def101f4d5b920cc110ea13dbf7103cf 100644
|
| --- a/chrome/browser/resources/ntp_search/thumbnail_page.js
|
| +++ b/chrome/browser/resources/ntp_search/thumbnail_page.js
|
| @@ -110,7 +110,8 @@ cr.define('ntp', function() {
|
| // If the thumbnail image fails to load, show the favicon and URL instead.
|
| // TODO(jeremycho): Move to a separate function?
|
| image.onerror = function() {
|
| - banner = self.ownerDocument.createElement('div');
|
| + banner = thumbnailImage.querySelector('.thumbnail-banner') ||
|
| + self.ownerDocument.createElement('div');
|
| banner.className = 'thumbnail-banner';
|
|
|
| // For now, just strip leading http://www and trailing backslash.
|
| @@ -118,7 +119,8 @@ cr.define('ntp', function() {
|
| banner.textContent = dataUrl.replace(/^(http:\/\/)?(www\.)?|\/$/gi, '');
|
| thumbnailImage.appendChild(banner);
|
|
|
| - favicon = self.ownerDocument.createElement('div');
|
| + favicon = thumbnailImage.querySelector('.thumbnail-favicon') ||
|
| + self.ownerDocument.createElement('div');
|
| favicon.className = 'thumbnail-favicon';
|
| favicon.style.backgroundImage =
|
| url('chrome://favicon/size/16/' + dataUrl);
|
| @@ -192,7 +194,7 @@ cr.define('ntp', function() {
|
| this.layout_();
|
|
|
| var maxTileCount = this.config_.maxTileCount;
|
| - var data = this.data_;
|
| + var data = this.getValidData_();
|
| var tiles = this.tiles;
|
| for (var i = 0; i < maxTileCount; i++) {
|
| var page = data[i];
|
| @@ -210,14 +212,65 @@ cr.define('ntp', function() {
|
| },
|
|
|
| /**
|
| - * Array of thumbnail data objects.
|
| - * @type {Array}
|
| + * Returns an array of thumbnail data objects.
|
| + * @return {Array} An array of thumbnail data objects.
|
| */
|
| - get data() {
|
| + getData: function() {
|
| return this.data_;
|
| },
|
| - set data(data) {
|
| - console.error('ThumbnailPage: data_ setter is not implemented.');
|
| +
|
| + /**
|
| + * Sets the data that will be used to create Thumbnails.
|
| + * @param {Array} data The array of data.
|
| + */
|
| + setData: function(data) {
|
| + var maxTileCount = this.config_.maxTileCount;
|
| +
|
| + if (!this.data_)
|
| + this.data_ = data.slice(0, maxTileCount);
|
| + else
|
| + this.data_ = this.refreshData_(this.data_, data, maxTileCount);
|
| +
|
| + var validDataLength = this.getValidData_().length;
|
| + var tileCount = this.tileCount;
|
| + // Create or remove tiles if necessary.
|
| + if (tileCount < validDataLength)
|
| + this.createTiles_(validDataLength - tileCount);
|
| + else if (tileCount > validDataLength) {
|
| + // TODO(jeremycho): Consider rewriting removeTile to be compatible with
|
| + // pages other than Apps and calling it here.
|
| + for (var i = 0; i < tileCount - validDataLength; i++)
|
| + this.tiles_.pop();
|
| + }
|
| +
|
| + // TODO(pedrosimonetti): Fix this as part of a larger restructuring of
|
| + // the layout/render logic.
|
| + if (validDataLength != tileCount && this.hasBeenRendered())
|
| + this.renderGrid_();
|
| + this.updateTiles_();
|
| + },
|
| +
|
| + /**
|
| + * Given an array of new data, returns the data that should replace the
|
| + * current array of data. Here we simply return the new data.
|
| + * @param {Array} oldData The current page list.
|
| + * @param {Array} newData The new page list.
|
| + * @param {number} maxTileCount The maximum number of tiles to render.
|
| + * @return {Array} The merged page list that should replace the current page
|
| + * list.
|
| + * @private
|
| + */
|
| + refreshData_: function(oldData, newData, maxTileCount) {
|
| + return newData.slice(0, maxTileCount);
|
| + },
|
| +
|
| + /**
|
| + * Returns all data entries that should be used when updating the tiles.
|
| + * @private
|
| + * @return {Array} Data entries for updating tiles.
|
| + */
|
| + getValidData_: function() {
|
| + return this.data_;
|
| },
|
|
|
| /** @inheritDoc */
|
|
|