| Index: chrome/browser/resources/md_downloads/icon_loader.js
|
| diff --git a/chrome/browser/resources/md_downloads/icon_loader.js b/chrome/browser/resources/md_downloads/icon_loader.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a5bb5c5b156b54b045635f1646ba2777bdf86fb0
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/md_downloads/icon_loader.js
|
| @@ -0,0 +1,51 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +cr.define('downloads', function() {
|
| + // TODO(dbeam): does this need to be a function + @constructor?
|
| + var IconLoader = {};
|
| +
|
| + /** @private {Array<{img: HTMLImageElement, url: string}>} */
|
| + IconLoader.iconsToLoad_ = [];
|
| +
|
| + /**
|
| + * Load the provided |url| into |img.src| after appending ?scale=.
|
| + * @param {!HTMLImageElement} img An <img> to show the loaded image in.
|
| + * @param {string} url A remote image URL to load.
|
| + */
|
| + IconLoader.loadScaledIcon = function(img, url) {
|
| + var scale = '?scale=' + window.devicePixelRatio + 'x';
|
| + IconLoader.iconsToLoad_.push({img: img, url: url + scale});
|
| + IconLoader.loadNextIcon_();
|
| + };
|
| +
|
| + /** @private */
|
| + IconLoader.loadNextIcon_ = function() {
|
| + if (IconLoader.isIconLoading_)
|
| + return;
|
| +
|
| + IconLoader.isIconLoading_ = true;
|
| +
|
| + while (IconLoader.iconsToLoad_.length) {
|
| + var request = IconLoader.iconsToLoad_.shift();
|
| + var img = request.img;
|
| +
|
| + if (img.src == request.url)
|
| + continue;
|
| +
|
| + img.onabort = img.onerror = img.onload = function() {
|
| + IconLoader.isIconLoading_ = false;
|
| + IconLoader.loadNextIcon_();
|
| + };
|
| +
|
| + img.src = request.url;
|
| + return;
|
| + }
|
| +
|
| + // If we reached here, there's no more work to do.
|
| + IconLoader.isIconLoading_ = false;
|
| + };
|
| +
|
| + return {IconLoader: IconLoader};
|
| +});
|
|
|