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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 }); 149 });
150 }, false); 150 }, false);
151 } 151 }
152 152
153 function openSharePopup(url) 153 function openSharePopup(url)
154 { 154 {
155 var iframe = E("share-popup"); 155 var iframe = E("share-popup");
156 var glassPane = E("glass-pane"); 156 var glassPane = E("glass-pane");
157 var popupMessageReceived = false; 157 var popupMessageReceived = false;
158 158
159 // Firefox 38+ no longer allows messaging using postMessage so we need
160 // to have a fake top level frame to avoid problems with scripts that try to
161 // communicate with the first-run page
162 var isGecko = ("Components" in window);
163 if (isGecko)
164 {
165 try
166 {
167 var Ci = Components.interfaces;
168 iframe.contentWindow
169 .QueryInterface(Ci.nsIInterfaceRequestor)
170 .getInterface(Ci.nsIDocShell)
171 .setIsBrowserInsideApp(Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID);
172 }
173 catch(ex)
174 {
175 console.error(ex);
176 }
177 }
178
179 function resizePopup(width, height)
180 {
181 iframe.width = width;
182 iframe.height = height;
183 iframe.style.marginTop = -height / 2 + "px";
184 iframe.style.marginLeft = -width / 2 + "px";
185 popupMessageReceived = true;
186 window.removeEventListener("message", popupMessageListener);
187 }
188
159 var popupMessageListener = function(event) 189 var popupMessageListener = function(event)
160 { 190 {
161 if (!/[.\/]adblockplus\.org$/.test(event.origin)) 191 if (!/[.\/]adblockplus\.org$/.test(event.origin))
162 return; 192 return;
163 193
164 var width = event.data.width; 194 resizePopup(event.data.width, event.data.height);
165 var height = event.data.height;
166 iframe.width = width;
167 iframe.height = height;
168 iframe.style.marginTop = -height/2 + "px";
169 iframe.style.marginLeft = -width/2 + "px";
170 popupMessageReceived = true;
171 window.removeEventListener("message", popupMessageListener);
172 }; 195 };
173 // Firefox requires last parameter to be true to be triggered by unprivilege d pages 196 // Firefox requires last parameter to be true to be triggered by
197 // unprivileged pages
174 window.addEventListener("message", popupMessageListener, false, true); 198 window.addEventListener("message", popupMessageListener, false, true);
175 199
176 var popupLoadListener = function() 200 var popupLoadListener = function()
177 { 201 {
202 if (!popupMessageReceived && isGecko)
203 {
204 var rootElement = iframe.contentDocument.documentElement;
205 var width = rootElement.dataset.width;
206 var height = rootElement.dataset.height;
207 if (width && height)
208 resizePopup(width, height);
209 }
210
178 if (popupMessageReceived) 211 if (popupMessageReceived)
179 { 212 {
180 iframe.className = "visible"; 213 iframe.className = "visible";
181 214
182 var popupCloseListener = function() 215 var popupCloseListener = function()
183 { 216 {
184 iframe.className = glassPane.className = ""; 217 iframe.className = glassPane.className = "";
185 document.removeEventListener("click", popupCloseListener); 218 document.removeEventListener("click", popupCloseListener);
186 }; 219 };
187 document.addEventListener("click", popupCloseListener, false); 220 document.addEventListener("click", popupCloseListener, false);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 { 320 {
288 var button = E("toggle-" + feature); 321 var button = E("toggle-" + feature);
289 if (isEnabled) 322 if (isEnabled)
290 button.classList.remove("off"); 323 button.classList.remove("off");
291 else 324 else
292 button.classList.add("off"); 325 button.classList.add("off");
293 } 326 }
294 327
295 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); 328 document.addEventListener("DOMContentLoaded", onDOMLoaded, false);
296 })(); 329 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld