Bug 1494891 - Fix missing or wrong attachment icons in summary and event dialog. r=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Sat, 29 Sep 2018 16:40:22 +0200
changeset 33410 1be95c892c357bbb9fb2db9f569ffd7755623659
parent 33409 eb34ed5966a0988254f154696eadf14c6c42a680
child 33411 b2ec0ac175e5b9ba9d8378aa95514fea3f76bf02
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersphilipp
bugs1494891
Bug 1494891 - Fix missing or wrong attachment icons in summary and event dialog. r=philipp
calendar/base/content/dialogs/calendar-summary-dialog.js
calendar/lightning/content/lightning-item-iframe.js
--- a/calendar/base/content/dialogs/calendar-summary-dialog.js
+++ b/calendar/base/content/dialogs/calendar-summary-dialog.js
@@ -186,16 +186,28 @@ function onLoad() {
                 attachment.removeAttribute("hidden");
 
                 let label = attachment.getElementsByTagName("label")[0];
                 label.setAttribute("value", aAttachment.uri.spec);
                 label.setAttribute("hashid", aAttachment.hashId);
 
                 let icon = attachment.getElementsByTagName("image")[0];
                 let iconSrc = aAttachment.uri.spec.length ? aAttachment.uri.spec : "dummy.html";
+                if (aAttachment.uri && !aAttachment.uri.schemeIs("file")) {
+                    // using an uri directly with e.g. a http scheme wouldn't render any icon
+                    if (aAttachment.formatType) {
+                        iconSrc = "goat?contentType=" + aAttachment.formatType;
+                    } else {
+                        // let's try to auto-detect
+                        let parts = iconSrc.substr(aAttachment.uri.scheme.length + 2).split("/");
+                        if (parts.length) {
+                            iconSrc = parts[parts.length - 1];
+                        }
+                    }
+                }
                 icon.setAttribute("src", "moz-icon://" + iconSrc);
 
                 document.getElementById("item-attachment-cell").appendChild(attachment);
                 attCounter++;
             }
         });
         if (attCounter > 0) {
             document.getElementById("attachments-row").removeAttribute("hidden");
--- a/calendar/lightning/content/lightning-item-iframe.js
+++ b/calendar/lightning/content/lightning-item-iframe.js
@@ -2280,31 +2280,41 @@ function addAttachment(attachment, cloud
             } else {
                 let leafName = attachment.getParameter("FILENAME");
                 image.setAttribute("src", cloudProvider.iconClass);
                 if (leafName) {
                     listItem.setAttribute("label", leafName);
                 }
             }
         } else if (attachment.uri.schemeIs("file")) {
-            image.setAttribute("src", "moz-icon://" + attachment.uri);
+            image.setAttribute("src", "moz-icon://" + attachment.uri.spec);
         } else {
             let leafName = attachment.getParameter("FILENAME");
             let providerType = attachment.getParameter("PROVIDER");
             let cloudFileEnabled = Preferences.get("mail.cloud_files.enabled", false);
 
             if (leafName) {
                 // TODO security issues?
                 listItem.setAttribute("label", leafName);
             }
             if (providerType && cloudFileEnabled) {
                 let provider = cloudFileAccounts.getProviderForType(providerType);
                 image.setAttribute("src", provider.iconClass);
             } else {
-                image.setAttribute("src", "moz-icon://dummy.html");
+                let iconSrc = attachment.uri.spec.length ? attachment.uri.spec : "dummy.html";
+                if (attachment.formatType) {
+                    iconSrc = "goat?contentType=" + attachment.formatType;
+                } else {
+                    // let's try to auto-detect
+                    let parts = iconSrc.substr(attachment.uri.scheme.length + 2).split("/");
+                    if (parts.length) {
+                        iconSrc = parts[parts.length - 1];
+                    }
+                }
+                image.setAttribute("src", "moz-icon://" + iconSrc);
             }
         }
 
         // Now that everything is set up, add it to the attachment box.
         documentLink.appendChild(listItem);
 
         // full attachment object is stored here
         listItem.attachment = attachment;