Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Unified Diff: chrome/browser/resources/local_ntp/most_visited_single.js

Issue 1132113005: [New Tab Page] Don't show tiles until all images are loaded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/local_ntp/most_visited_single.js
diff --git a/chrome/browser/resources/local_ntp/most_visited_single.js b/chrome/browser/resources/local_ntp/most_visited_single.js
index 916261a7526d06634dcfe8820b52bcb9ff827d5a..ce9fb8100b7e53b495c064bf160e9f8060f29439 100644
--- a/chrome/browser/resources/local_ntp/most_visited_single.js
+++ b/chrome/browser/resources/local_ntp/most_visited_single.js
@@ -114,6 +114,7 @@ var logEvent = function(eventType) {
var countLoad = function() {
loadedCounter -= 1;
if (loadedCounter <= 0) {
+ showTiles();
logEvent(LOG_TYPE.NTP_TILE_LOADED);
window.parent.postMessage({cmd: 'loaded'}, DOMAIN_ORIGIN);
loadedCounter = 1;
@@ -147,9 +148,8 @@ var handleCommand = function(data) {
if (cmd == 'tile') {
addTile(data);
} else if (cmd == 'show') {
- showTiles();
- hideOverflowTiles(data);
countLoad();
+ hideOverflowTiles(data);
} else if (cmd == 'updateTheme') {
updateTheme(data);
} else if (cmd == 'tilesVisible') {
@@ -381,10 +381,6 @@ var renderTile = function(data) {
thumb.classList.add('failed-img');
}
} else { // THUMBNAILS
- var thumb = tile.querySelector('.mv-thumb');
- var img = document.createElement('img');
- var loaded = false;
-
// We keep track of the outcome of loading possible thumbnails for this
// tile. Possible values:
// - null: waiting for load/error
@@ -393,12 +389,15 @@ var renderTile = function(data) {
// This is populated by acceptImage/rejectImage and loadBestImage
// decides the best one to load.
var results = [];
+ var thumb = tile.querySelector('.mv-thumb');
+ var img = document.createElement('img');
+ var loaded = false;
var loadBestImage = function() {
if (loaded) {
return;
}
- for (i = 0; i < results.length; ++i) {
+ for (var i = 0; i < results.length; ++i) {
if (results[i] === null) {
return;
}
@@ -411,6 +410,7 @@ var renderTile = function(data) {
thumb.classList.add('failed-img');
thumb.removeChild(img);
logEvent(LOG_TYPE.NTP_THUMBNAIL_ERROR);
+ countLoad();
};
var acceptImage = function(idx, url) {
@@ -427,6 +427,19 @@ var renderTile = function(data) {
};
};
+ img.title = data.title;
+ img.classList.add('thumbnail');
+ loadedCounter += 1;
+ img.addEventListener('load', countLoad);
+ img.addEventListener('error', countLoad);
+ img.addEventListener('error', function(ev) {
+ thumb.classList.add('failed-img');
+ thumb.removeChild(img);
+ logEvent(LOG_TYPE.NTP_THUMBNAIL_ERROR);
+ });
+ thumb.appendChild(img);
+ logEvent(LOG_TYPE.NTP_THUMBNAIL_TILE);
+
// Get all thumbnailUrls for the tile.
// They are ordered from best one to be used to worst.
for (var i = 0; i < data.thumbnailUrls.length; ++i) {
@@ -443,19 +456,6 @@ var renderTile = function(data) {
}
}
- img.title = data.title;
- img.classList.add('thumbnail');
- loadedCounter += 1;
- img.addEventListener('load', countLoad);
- img.addEventListener('error', countLoad);
- img.addEventListener('error', function(ev) {
- thumb.classList.add('failed-img');
- thumb.removeChild(img);
- logEvent(LOG_TYPE.NTP_THUMBNAIL_ERROR);
- });
- thumb.appendChild(img);
- logEvent(LOG_TYPE.NTP_THUMBNAIL_TILE);
-
var favicon = tile.querySelector('.mv-favicon');
if (data.faviconUrl) {
var fi = document.createElement('img');
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698