2013-07-26 22:40:04 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
let outOfProcess = __marionetteParams[0]
|
|
|
|
let mochitestUrl = __marionetteParams[1]
|
|
|
|
|
|
|
|
const CHILD_SCRIPT = "chrome://specialpowers/content/specialpowers.js";
|
|
|
|
const CHILD_SCRIPT_API = "chrome://specialpowers/content/specialpowersAPI.js";
|
|
|
|
const CHILD_LOGGER_SCRIPT = "chrome://specialpowers/content/MozillaLogger.js";
|
|
|
|
|
2013-08-29 01:35:34 +04:00
|
|
|
let homescreen = document.getElementById('systemapp');
|
2013-07-26 22:40:04 +04:00
|
|
|
let container = homescreen.contentWindow.document.getElementById('test-container');
|
|
|
|
|
|
|
|
function openWindow(aEvent) {
|
|
|
|
var popupIframe = aEvent.detail.frameElement;
|
2013-09-25 21:09:30 +04:00
|
|
|
popupIframe.setAttribute('style', 'position: absolute; left: 0; top: 0px; background: white;');
|
|
|
|
|
|
|
|
// This is to size the iframe to what is requested in the window.open call,
|
|
|
|
// e.g. window.open("", "", "width=600,height=600");
|
|
|
|
if (aEvent.detail.features.indexOf('width') != -1) {
|
|
|
|
let width = aEvent.detail.features.substr(aEvent.detail.features.indexOf('width')+6);
|
|
|
|
width = width.substr(0,width.indexOf(',') == -1 ? width.length : width.indexOf(','));
|
|
|
|
popupIframe.style.width = width + 'px';
|
|
|
|
}
|
|
|
|
if (aEvent.detail.features.indexOf('height') != -1) {
|
|
|
|
let height = aEvent.detail.features.substr(aEvent.detail.features.indexOf('height')+7);
|
|
|
|
height = height.substr(0, height.indexOf(',') == -1 ? height.length : height.indexOf(','));
|
|
|
|
popupIframe.style.height = height + 'px';
|
|
|
|
}
|
2013-07-26 22:40:04 +04:00
|
|
|
|
|
|
|
popupIframe.addEventListener('mozbrowserclose', function(e) {
|
|
|
|
container.parentNode.removeChild(popupIframe);
|
|
|
|
container.focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
// yes, the popup can call window.open too!
|
|
|
|
popupIframe.addEventListener('mozbrowseropenwindow', openWindow);
|
|
|
|
|
|
|
|
popupIframe.addEventListener('mozbrowserloadstart', function(e) {
|
|
|
|
popupIframe.focus();
|
2013-09-25 21:09:30 +04:00
|
|
|
let mm = popupIframe.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
|
|
|
|
mm.loadFrameScript(CHILD_LOGGER_SCRIPT, true);
|
|
|
|
mm.loadFrameScript(CHILD_SCRIPT_API, true);
|
|
|
|
mm.loadFrameScript(CHILD_SCRIPT, true);
|
|
|
|
mm.loadFrameScript('data:,attachSpecialPowersToWindow%28content%29%3B', true);
|
2013-07-26 22:40:04 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
container.parentNode.appendChild(popupIframe);
|
|
|
|
}
|
|
|
|
container.addEventListener('mozbrowseropenwindow', openWindow);
|
|
|
|
|
2013-08-14 21:57:43 +04:00
|
|
|
if (outOfProcess) {
|
|
|
|
let specialpowers = {};
|
|
|
|
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
|
|
|
|
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js", specialpowers);
|
|
|
|
let specialPowersObserver = new specialpowers.SpecialPowersObserver();
|
|
|
|
|
|
|
|
let mm = container.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
|
2013-12-20 05:04:20 +04:00
|
|
|
specialPowersObserver.init(mm);
|
|
|
|
|
2013-08-14 21:57:43 +04:00
|
|
|
mm.addMessageListener("SPPrefService", specialPowersObserver);
|
|
|
|
mm.addMessageListener("SPProcessCrashService", specialPowersObserver);
|
|
|
|
mm.addMessageListener("SPPingService", specialPowersObserver);
|
|
|
|
mm.addMessageListener("SpecialPowers.Quit", specialPowersObserver);
|
|
|
|
mm.addMessageListener("SpecialPowers.Focus", specialPowersObserver);
|
|
|
|
mm.addMessageListener("SPPermissionManager", specialPowersObserver);
|
2013-09-15 06:09:13 +04:00
|
|
|
mm.addMessageListener("SPLoadChromeScript", specialPowersObserver);
|
|
|
|
mm.addMessageListener("SPChromeScriptMessage", specialPowersObserver);
|
2013-08-14 21:57:43 +04:00
|
|
|
|
|
|
|
mm.loadFrameScript(CHILD_LOGGER_SCRIPT, true);
|
|
|
|
mm.loadFrameScript(CHILD_SCRIPT_API, true);
|
|
|
|
mm.loadFrameScript(CHILD_SCRIPT, true);
|
2013-08-21 02:41:18 +04:00
|
|
|
//Workaround for bug 848411, once that bug is fixed, the following line can be removed
|
2013-08-23 01:31:24 +04:00
|
|
|
mm.loadFrameScript('data:,addEventListener%28%22DOMWindowCreated%22%2C%20function%28e%29%20%7B%0A%20%20removeEventListener%28%22DOMWindowCreated%22%2C%20arguments.callee%2C%20false%29%3B%0A%20%20var%20window%20%3D%20e.target.defaultView%3B%0A%20%20window.wrappedJSObject.SpecialPowers.addPermission%28%22allowXULXBL%22%2C%20true%2C%20window.document%29%3B%0A%7D%0A%29%3B', true);
|
2013-08-21 02:41:18 +04:00
|
|
|
|
2013-08-14 21:57:43 +04:00
|
|
|
specialPowersObserver._isFrameScriptLoaded = true;
|
|
|
|
}
|
2013-07-26 22:40:04 +04:00
|
|
|
|
2014-01-28 03:20:00 +04:00
|
|
|
container.src = mochitestUrl;
|