From 50403d66e0ef3e0702aefd12f76263dc8b8d5bf7 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 17 Dec 2015 10:02:38 -0500
Subject: [PATCH] Fix PDF support detection in Firefox > 19 (#1490610)

---
 CHANGELOG                   |    1 +
 program/resources/dummy.pdf |    0 
 program/js/app.js           |   33 ++++++++++++++++++++-------------
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 545d339..81302d4 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,7 @@
 - Fix HTML sanitizer to skip <!-- node type X --> in output (#1490583)
 - Fix charset encoding of message/rfc822 part bodies (#1490606)
 - Fix handling of message/rfc822 attachments on replies and forwards (#1490607)
+- Fix PDF support detection in Firefox > 19 (#1490610)
 
 RELEASE 1.0.7
 -------------
diff --git a/program/js/app.js b/program/js/app.js
index 3d3eeea..e639448 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -7646,14 +7646,10 @@
     if (!this.env.browser_capabilities)
       this.env.browser_capabilities = {};
 
-    if (this.env.browser_capabilities.pdf === undefined)
-      this.env.browser_capabilities.pdf = this.pdf_support_check();
-
-    if (this.env.browser_capabilities.flash === undefined)
-      this.env.browser_capabilities.flash = this.flash_support_check();
-
-    if (this.env.browser_capabilities.tif === undefined)
-      this.tif_support_check();
+    $.each(['pdf', 'flash', 'tif'], function() {
+      if (ref.env.browser_capabilities[this] === undefined)
+        ref.env.browser_capabilities[this] = ref[this + '_support_check']();
+    });
   };
 
   // Returns browser capabilities string
@@ -7672,16 +7668,19 @@
 
   this.tif_support_check = function()
   {
-    var img = new Image();
+    window.setTimeout(function() {
+      var img = new Image();
+      img.onload = function() { ref.env.browser_capabilities.tif = 1; };
+      img.onerror = function() { ref.env.browser_capabilities.tif = 0; };
+      img.src = 'program/resources/blank.tif';
+    }, 10);
 
-    img.onload = function() { rcmail.env.browser_capabilities.tif = 1; };
-    img.onerror = function() { rcmail.env.browser_capabilities.tif = 0; };
-    img.src = 'program/resources/blank.tif';
+    return 0;
   };
 
   this.pdf_support_check = function()
   {
-    var plugin = navigator.mimeTypes ? navigator.mimeTypes["application/pdf"] : {},
+    var i, plugin = navigator.mimeTypes ? navigator.mimeTypes["application/pdf"] : {},
       plugins = navigator.plugins,
       len = plugins.length,
       regex = /Adobe Reader|PDF|Acrobat/i;
@@ -7712,6 +7711,14 @@
         return 1;
     }
 
+    window.setTimeout(function() {
+      $('<object>').css({position: 'absolute', left: '-10000px'})
+        .attr({data: 'program/resources/dummy.pdf', width: 1, height: 1, type: 'application/pdf'})
+        .load(function() { ref.env.browser_capabilities.pdf = 1; })
+        .error(function() { ref.env.browser_capabilities.pdf = 0; })
+        .appendTo($('body'));
+      }, 10);
+
     return 0;
   };
 
diff --git a/program/resources/dummy.pdf b/program/resources/dummy.pdf
new file mode 100644
index 0000000..8c5ca54
--- /dev/null
+++ b/program/resources/dummy.pdf
Binary files differ

--
Gitblit v1.9.1