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

Side by Side Diff: chrome/browser/resources/md_downloads/icon_loader.js

Issue 1224623013: Port downloads.ItemView to a Polymer component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@p-dl-rough-draft2
Patch Set: actually include i18n changes Created 5 years, 5 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 cr.define('downloads', function() {
6 // TODO(dbeam): does this need to be a function + @constructor?
7 var IconLoader = {};
8
9 /** @private {Array<{img: HTMLImageElement, url: string}>} */
10 IconLoader.iconsToLoad_ = [];
11
12 /**
13 * Load the provided |url| into |img.src| after appending ?scale=.
14 * @param {!HTMLImageElement} img An <img> to show the loaded image in.
15 * @param {string} url A remote image URL to load.
16 */
17 IconLoader.loadScaledIcon = function(img, url) {
18 var scale = '?scale=' + window.devicePixelRatio + 'x';
19 IconLoader.iconsToLoad_.push({img: img, url: url + scale});
20 IconLoader.loadNextIcon_();
21 };
22
23 /** @private */
24 IconLoader.loadNextIcon_ = function() {
25 if (IconLoader.isIconLoading_)
26 return;
27
28 IconLoader.isIconLoading_ = true;
29
30 while (IconLoader.iconsToLoad_.length) {
31 var request = IconLoader.iconsToLoad_.shift();
32 var img = request.img;
33
34 if (img.src == request.url)
35 continue;
36
37 img.onabort = img.onerror = img.onload = function() {
38 IconLoader.isIconLoading_ = false;
39 IconLoader.loadNextIcon_();
40 };
41
42 img.src = request.url;
43 return;
44 }
45
46 // If we reached here, there's no more work to do.
47 IconLoader.isIconLoading_ = false;
48 };
49
50 return {IconLoader: IconLoader};
51 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698