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

Unified 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 side-by-side diff with in-line comments
Download patch
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};
+});

Powered by Google App Engine
This is Rietveld 408576698