Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: firstRun.js

Issue 29322728: Issue 2710 - Worked around Firefox preventing postMessage to privileged frame (Closed)
Patch Set: Created July 21, 2015, 3:58 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: firstRun.js
===================================================================
--- a/firstRun.js
+++ b/firstRun.js
@@ -156,25 +156,58 @@
var glassPane = E("glass-pane");
var popupMessageReceived = false;
+ // 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)
+ {
+ try
+ {
+ var Ci = Components.interfaces;
+ iframe.contentWindow
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDocShell)
+ .setIsBrowserInsideApp(Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID);
+ }
+ catch(ex)
+ {
+ console.error(ex);
+ }
+ }
+
+ function resizePopup(width, height)
+ {
+ iframe.width = width;
+ iframe.height = height;
+ 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;
- var width = event.data.width;
- var height = event.data.height;
- iframe.width = width;
- iframe.height = height;
- iframe.style.marginTop = -height/2 + "px";
- iframe.style.marginLeft = -width/2 + "px";
- popupMessageReceived = true;
- window.removeEventListener("message", popupMessageListener);
+ 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";
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld