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

Side by Side Diff: chrome/browser/resources/file_manager/js/image_editor/image_util.js

Issue 16124013: Fix infinite loading for small images in Files.app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 7 years, 6 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 | Annotate | Revision Log
« 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 'use strict'; 5 'use strict';
6 6
7 7
8 // Namespace object for the utilities. 8 // Namespace object for the utilities.
9 function ImageUtil() {} 9 function ImageUtil() {}
10 10
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 transformFetcher(url, onTransform.bind(this, e.target)); 475 transformFetcher(url, onTransform.bind(this, e.target));
476 }.bind(this); 476 }.bind(this);
477 // errorCallback has an optional error argument, which in case of general 477 // errorCallback has an optional error argument, which in case of general
478 // error should not be specified 478 // error should not be specified
479 this.image_.onerror = onError.bind(this, 'IMAGE_ERROR'); 479 this.image_.onerror = onError.bind(this, 'IMAGE_ERROR');
480 this.taskId_ = util.loadImage(this.image_, url, {priority: 1}); 480 this.taskId_ = util.loadImage(this.image_, url, {priority: 1});
481 }.bind(this); 481 }.bind(this);
482 482
483 // The clients of this class sometimes request the same url repeatedly. 483 // The clients of this class sometimes request the same url repeatedly.
484 // The onload fires only if the src is different from the previous value. 484 // The onload fires only if the src is different from the previous value.
485 // To work around that we reset the src temporarily to an 1x1 pixel. 485 // To work around that we reset the src temporarily to an 1x1 pixel to force
486 // Load an empty 1x1 pixel image first. 486 // garbage collecting, and then resetting src to an empty value.
487 var resetImage = function(callback) { 487 var resetImage = function(callback) {
488 this.image_.onload = callback; 488 var clearSrc = function() {
489 this.image_.onerror = onError.bind(this, 'IMAGE_ERROR'); 489 this.image_.onload = callback;
490 this.image_.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAA' + 490 this.image_.onerror = callback;
491 this.image_.src = '';
492 }.bind(this);
493 var emptyImage = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAA' +
491 'AAABAAEAAAICTAEAOw=='; 494 'AAABAAEAAAICTAEAOw==';
495 if (this.image_.src != emptyImage) {
496 // Load an empty image, then clear src.
497 this.image_.onload = clearSrc;
498 this.image_.onerror = onError.bind(this, 'IMAGE_ERROR');
499 this.image_.src = emptyImage;
500 } else {
501 // Empty image already loaded, so clear src immediately.
502 clearSrc();
503 }
492 }.bind(this); 504 }.bind(this);
493 505
494 // Loads the image. If already loaded, then forces reloads. 506 // Loads the image. If already loaded, then forces a reload.
495 var startLoad = function() { 507 var startLoad = resetImage.bind(this, loadImage);
496 if (this.image_.src == url)
497 resetImage(loadImage);
498 else
499 loadImage();
500 }.bind(this);
501 508
502 if (opt_delay) { 509 if (opt_delay) {
503 this.timeout_ = setTimeout(startLoad, opt_delay); 510 this.timeout_ = setTimeout(startLoad, opt_delay);
504 } else { 511 } else {
505 startLoad(); 512 startLoad();
506 } 513 }
507 }; 514 };
508 515
509 /** 516 /**
510 * @return {boolean} True if an image is loading. 517 * @return {boolean} True if an image is loading.
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 * @return {string} Full name. 696 * @return {string} Full name.
690 */ 697 */
691 ImageUtil.getMetricName = function(name) { 698 ImageUtil.getMetricName = function(name) {
692 return 'PhotoEditor.' + name; 699 return 'PhotoEditor.' + name;
693 }; 700 };
694 701
695 /** 702 /**
696 * Used for metrics reporting, keep in sync with the histogram description. 703 * Used for metrics reporting, keep in sync with the histogram description.
697 */ 704 */
698 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; 705 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp'];
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