[Pkg-mozext-commits] [adblock-plus] 56/74: Issue 2710 - Worked around Firefox preventing postMessage to privileged frame

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 12:07:10 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus.

commit 6e2f3b15e838bf7ea1f876dd30603499e6458d8f
Author: Thomas Greiner <thomas at adblockplus.org>
Date:   Tue Jul 21 20:05:49 2015 +0200

    Issue 2710 - Worked around Firefox preventing postMessage to privileged frame
---
 firstRun.js | 49 +++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 8 deletions(-)

diff --git a/firstRun.js b/firstRun.js
index 3a11a2e..ac3d88d 100644
--- a/firstRun.js
+++ b/firstRun.js
@@ -156,25 +156,58 @@
     var glassPane = E("glass-pane");
     var popupMessageReceived = false;
 
-    var popupMessageListener = function(event)
+    // Firefox 38+ no longer allows messaging using postMessage so we need
+    // to have a fake top level frame to avoid problems with scripts that try to
+    // communicate with the first-run page
+    var isGecko = ("Components" in window);
+    if (isGecko)
     {
-      if (!/[.\/]adblockplus\.org$/.test(event.origin))
-        return;
+      try
+      {
+        var Ci = Components.interfaces;
+        iframe.contentWindow
+          .QueryInterface(Ci.nsIInterfaceRequestor)
+          .getInterface(Ci.nsIDocShell)
+          .setIsBrowserInsideApp(Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID);
+      }
+      catch(ex)
+      {
+        console.error(ex);
+      }
+    }
 
-      var width = event.data.width;
-      var height = event.data.height;
+    function resizePopup(width, height)
+    {
       iframe.width = width;
       iframe.height = height;
-      iframe.style.marginTop = -height/2 + "px";
-      iframe.style.marginLeft = -width/2 + "px";
+      iframe.style.marginTop = -height / 2 + "px";
+      iframe.style.marginLeft = -width / 2 + "px";
       popupMessageReceived = true;
       window.removeEventListener("message", popupMessageListener);
+    }
+
+    var popupMessageListener = function(event)
+    {
+      if (!/[.\/]adblockplus\.org$/.test(event.origin))
+        return;
+
+      resizePopup(event.data.width, event.data.height);
     };
-    // Firefox requires last parameter to be true to be triggered by unprivileged pages
+    // Firefox requires last parameter to be true to be triggered by
+    // unprivileged pages
     window.addEventListener("message", popupMessageListener, false, true);
 
     var popupLoadListener = function()
     {
+      if (!popupMessageReceived && isGecko)
+      {
+        var rootElement = iframe.contentDocument.documentElement;
+        var width = rootElement.dataset.width;
+        var height = rootElement.dataset.height;
+        if (width && height)
+          resizePopup(width, height);
+      }
+
       if (popupMessageReceived)
       {
         iframe.className = "visible";

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git



More information about the Pkg-mozext-commits mailing list