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

Side by Side Diff: chrome/browser/resources/local_ntp/most_visited_single.js

Issue 1129383003: Adds support for multiple thumbnail files on Single iframe NTP, fallback to the best one that opens. (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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 /** 271 /**
272 * Called when the host page wants to add a suggestion tile. 272 * Called when the host page wants to add a suggestion tile.
273 * For Most Visited, it grabs the data from Chrome and pass on. 273 * For Most Visited, it grabs the data from Chrome and pass on.
274 * For host page generated it just passes the data. 274 * For host page generated it just passes the data.
275 * @param {object} args Data for the tile to be rendered. 275 * @param {object} args Data for the tile to be rendered.
276 */ 276 */
277 var addTile = function(args) { 277 var addTile = function(args) {
278 if (args.rid) { 278 if (args.rid) {
279 var data = chrome.embeddedSearch.searchBox.getMostVisitedItemData(args.rid); 279 var data = chrome.embeddedSearch.searchBox.getMostVisitedItemData(args.rid);
280 data.tid = data.rid; 280 data.tid = data.rid;
281 data.thumbnailUrl = [data.thumbnailUrl];
huangs 2015/05/11 20:31:16 This is hacky, please have: data.thumbnailUrlLis
fserb 2015/05/11 20:39:56 Done.
281 data.faviconUrl = 'chrome-search://favicon/size/16@' + 282 data.faviconUrl = 'chrome-search://favicon/size/16@' +
282 window.devicePixelRatio + 'x/' + data.renderViewId + '/' + data.tid; 283 window.devicePixelRatio + 'x/' + data.renderViewId + '/' + data.tid;
283 tiles.appendChild(renderTile(data)); 284 tiles.appendChild(renderTile(data));
284 logEvent(LOG_TYPE.NTP_CLIENT_SIDE_SUGGESTION); 285 logEvent(LOG_TYPE.NTP_CLIENT_SIDE_SUGGESTION);
285 } else if (args.id) { 286 } else if (args.id) {
286 tiles.appendChild(renderTile(args)); 287 tiles.appendChild(renderTile(args));
287 logEvent(LOG_TYPE.NTP_SERVER_SIDE_SUGGESTION); 288 logEvent(LOG_TYPE.NTP_SERVER_SIDE_SUGGESTION);
288 } else { 289 } else {
289 tiles.appendChild(renderTile(null)); 290 tiles.appendChild(renderTile(null));
290 } 291 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 logEvent(LOG_TYPE.NTP_MOUSEOVER); 350 logEvent(LOG_TYPE.NTP_MOUSEOVER);
350 }); 351 });
351 352
352 var title = tile.querySelector('.mv-title'); 353 var title = tile.querySelector('.mv-title');
353 title.innerText = data.title; 354 title.innerText = data.title;
354 title.style.direction = data.direction || 'ltr'; 355 title.style.direction = data.direction || 'ltr';
355 if (NUM_TITLE_LINES > 1) { 356 if (NUM_TITLE_LINES > 1) {
356 title.classList.add('multiline'); 357 title.classList.add('multiline');
357 } 358 }
358 359
359 var hasIcon = USE_ICONS && data.largeIconUrl; 360 if (USE_ICONS) {
360 var hasThumb = !USE_ICONS && data.thumbnailUrl; 361 var thumb = tile.querySelector('.mv-thumb');
361 var thumb = tile.querySelector('.mv-thumb'); 362 if (data.largeIconUrl) {
362 if (hasIcon || hasThumb) { 363 var img = document.createElement('img');
363 var img = document.createElement('img'); 364 img.title = data.title;
364 img.title = data.title;
365 if (hasIcon) {
366 img.src = data.largeIconUrl; 365 img.src = data.largeIconUrl;
367 img.classList.add('large-icon'); 366 img.classList.add('large-icon');
368 } else { // hasThumb 367 loadedCounter += 1;
369 img.src = data.thumbnailUrl; 368 img.addEventListener('load', countLoad);
370 img.classList.add('thumbnail');
371 }
372 loadedCounter += 1;
373 img.addEventListener('load', countLoad);
374 if (data.largeIconUrl) {
375 img.addEventListener('load', function(ev) { 369 img.addEventListener('load', function(ev) {
376 thumb.classList.add('large-icon-outer'); 370 thumb.classList.add('large-icon-outer');
377 }); 371 });
372 img.addEventListener('error', countLoad);
373 img.addEventListener('error', function(ev) {
374 thumb.classList.add('failed-img');
375 thumb.removeChild(img);
376 logEvent(LOG_TYPE.NTP_THUMBNAIL_ERROR);
377 });
378 thumb.appendChild(img);
379 logEvent(LOG_TYPE.NTP_THUMBNAIL_TILE);
380 } else {
381 thumb.classList.add('failed-img');
378 } 382 }
383 } else { // THUMBNAILS
384 var thumb = tile.querySelector('.mv-thumb');
385
Mathieu 2015/05/11 20:27:24 nit: extra newline
fserb 2015/05/11 20:39:56 Done.
386 var img = document.createElement('img');
387 var loaded = false;
388 var results = [];
Mathieu 2015/05/11 20:27:24 Add a comment like: // Used to keep track of loadi
fserb 2015/05/11 20:39:56 Done.
389
390 var loadBestImage = function() {
391 if (loaded) return;
huangs 2015/05/11 20:31:16 Move return to next line.
fserb 2015/05/11 20:39:56 Done.
392 for (i = 0; i < results.length; ++i) {
393 if (results[i] === null) return;
huangs 2015/05/11 20:31:16 Move return to next line.
fserb 2015/05/11 20:39:56 Done.
394 if (results[i] != false) {
395 img.src = results[i];
396 loaded = true;
397 return;
398 }
399 }
400 thumb.classList.add('failed-img');
401 thumb.removeChild(img);
402 logEvent(LOG_TYPE.NTP_THUMBNAIL_ERROR);
403 };
404
405 var acceptImage = function(idx, url) {
406 return function(ev) {
407 results[idx] = url;
408 loadBestImage();
409 };
410 };
411
412 var rejectImage = function(i) {
huangs 2015/05/11 20:31:16 This |i| is a number.
fserb 2015/05/11 20:39:56 Done.
413 return function(ev) {
414 results[i] = false;
415 loadBestImage();
416 };
417 };
418
419 var images = [];
Mathieu 2015/05/11 20:27:24 remove
fserb 2015/05/11 20:39:56 Done.
420
421 for (var t = 0; t < data.thumbnailUrl.length; ++t) {
Mathieu 2015/05/11 20:27:24 could you add a comment above saying that the best
fserb 2015/05/11 20:39:56 Done.
422 results.push(null);
423 var i = new Image();
huangs 2015/05/11 20:31:16 This |i| is an Image, and |t| is now the index. P
fserb 2015/05/11 20:39:56 Done.
424 i.src = data.thumbnailUrl[t];
Mathieu 2015/05/11 20:28:58 does it completely poop out if data.thumbnailUrl i
fserb 2015/05/11 20:39:56 it does get an onerror for undefined. But I added
425 i.onload = acceptImage(t, data.thumbnailUrl[t]);
426 i.onerror = rejectImage(t);
427 }
428
429 img.title = data.title;
430 img.classList.add('thumbnail');
431 loadedCounter += 1;
432 img.addEventListener('load', countLoad);
379 img.addEventListener('error', countLoad); 433 img.addEventListener('error', countLoad);
380 img.addEventListener('error', function(ev) { 434 img.addEventListener('error', function(ev) {
381 thumb.classList.add('failed-img'); 435 thumb.classList.add('failed-img');
382 thumb.removeChild(img); 436 thumb.removeChild(img);
383 logEvent(LOG_TYPE.NTP_THUMBNAIL_ERROR); 437 logEvent(LOG_TYPE.NTP_THUMBNAIL_ERROR);
384 }); 438 });
385 thumb.appendChild(img); 439 thumb.appendChild(img);
386 logEvent(LOG_TYPE.NTP_THUMBNAIL_TILE); 440 logEvent(LOG_TYPE.NTP_THUMBNAIL_TILE);
387 } else {
388 thumb.classList.add('failed-img');
389 }
390 441
391 if (!USE_ICONS) {
392 var favicon = tile.querySelector('.mv-favicon'); 442 var favicon = tile.querySelector('.mv-favicon');
393 if (data.faviconUrl) { 443 if (data.faviconUrl) {
394 var fi = document.createElement('img'); 444 var fi = document.createElement('img');
395 fi.src = data.faviconUrl; 445 fi.src = data.faviconUrl;
396 // Set the title to empty so screen readers won't say the image name. 446 // Set the title to empty so screen readers won't say the image name.
397 fi.title = ''; 447 fi.title = '';
398 loadedCounter += 1; 448 loadedCounter += 1;
399 fi.addEventListener('load', countLoad); 449 fi.addEventListener('load', countLoad);
400 fi.addEventListener('error', countLoad); 450 fi.addEventListener('error', countLoad);
401 fi.addEventListener('error', function(ev) { 451 fi.addEventListener('error', function(ev) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 var html = document.querySelector('html'); 502 var html = document.querySelector('html');
453 html.dir = 'rtl'; 503 html.dir = 'rtl';
454 } 504 }
455 505
456 window.addEventListener('message', handlePostMessage); 506 window.addEventListener('message', handlePostMessage);
457 }; 507 };
458 508
459 509
460 window.addEventListener('DOMContentLoaded', init); 510 window.addEventListener('DOMContentLoaded', init);
461 })(); 511 })();
OLDNEW
« 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