michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let outOfProcess = __marionetteParams[0] michael@0: let mochitestUrl = __marionetteParams[1] michael@0: let onDevice = __marionetteParams[2] michael@0: let wifiSettings = __marionetteParams[3] michael@0: let prefs = Components.classes["@mozilla.org/preferences-service;1"]. michael@0: getService(Components.interfaces.nsIPrefBranch) michael@0: let settings = window.navigator.mozSettings; michael@0: michael@0: if (wifiSettings) michael@0: wifiSettings = JSON.parse(wifiSettings); michael@0: michael@0: const CHILD_SCRIPT = "chrome://specialpowers/content/specialpowers.js"; michael@0: const CHILD_SCRIPT_API = "chrome://specialpowers/content/specialpowersAPI.js"; michael@0: const CHILD_LOGGER_SCRIPT = "chrome://specialpowers/content/MozillaLogger.js"; michael@0: michael@0: let homescreen = document.getElementById('systemapp'); michael@0: let container = homescreen.contentWindow.document.getElementById('test-container'); michael@0: michael@0: function openWindow(aEvent) { michael@0: var popupIframe = aEvent.detail.frameElement; michael@0: popupIframe.setAttribute('style', 'position: absolute; left: 0; top: 0px; background: white;'); michael@0: michael@0: // This is to size the iframe to what is requested in the window.open call, michael@0: // e.g. window.open("", "", "width=600,height=600"); michael@0: if (aEvent.detail.features.indexOf('width') != -1) { michael@0: let width = aEvent.detail.features.substr(aEvent.detail.features.indexOf('width')+6); michael@0: width = width.substr(0,width.indexOf(',') == -1 ? width.length : width.indexOf(',')); michael@0: popupIframe.style.width = width + 'px'; michael@0: } michael@0: if (aEvent.detail.features.indexOf('height') != -1) { michael@0: let height = aEvent.detail.features.substr(aEvent.detail.features.indexOf('height')+7); michael@0: height = height.substr(0, height.indexOf(',') == -1 ? height.length : height.indexOf(',')); michael@0: popupIframe.style.height = height + 'px'; michael@0: } michael@0: michael@0: popupIframe.addEventListener('mozbrowserclose', function(e) { michael@0: container.parentNode.removeChild(popupIframe); michael@0: container.focus(); michael@0: }); michael@0: michael@0: // yes, the popup can call window.open too! michael@0: popupIframe.addEventListener('mozbrowseropenwindow', openWindow); michael@0: michael@0: popupIframe.addEventListener('mozbrowserloadstart', function(e) { michael@0: popupIframe.focus(); michael@0: let mm = popupIframe.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager; michael@0: mm.loadFrameScript(CHILD_LOGGER_SCRIPT, true); michael@0: mm.loadFrameScript(CHILD_SCRIPT_API, true); michael@0: mm.loadFrameScript(CHILD_SCRIPT, true); michael@0: mm.loadFrameScript('data:,attachSpecialPowersToWindow%28content%29%3B', true); michael@0: }); michael@0: michael@0: container.parentNode.appendChild(popupIframe); michael@0: } michael@0: container.addEventListener('mozbrowseropenwindow', openWindow); michael@0: michael@0: if (outOfProcess) { michael@0: let specialpowers = {}; michael@0: let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader); michael@0: loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js", specialpowers); michael@0: let specialPowersObserver = new specialpowers.SpecialPowersObserver(); michael@0: michael@0: let mm = container.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager; michael@0: specialPowersObserver.init(mm); michael@0: michael@0: mm.addMessageListener("SPPrefService", specialPowersObserver); michael@0: mm.addMessageListener("SPProcessCrashService", specialPowersObserver); michael@0: mm.addMessageListener("SPPingService", specialPowersObserver); michael@0: mm.addMessageListener("SpecialPowers.Quit", specialPowersObserver); michael@0: mm.addMessageListener("SpecialPowers.Focus", specialPowersObserver); michael@0: mm.addMessageListener("SPPermissionManager", specialPowersObserver); michael@0: mm.addMessageListener("SPLoadChromeScript", specialPowersObserver); michael@0: mm.addMessageListener("SPChromeScriptMessage", specialPowersObserver); michael@0: michael@0: mm.loadFrameScript(CHILD_LOGGER_SCRIPT, true); michael@0: mm.loadFrameScript(CHILD_SCRIPT_API, true); michael@0: mm.loadFrameScript(CHILD_SCRIPT, true); michael@0: //Workaround for bug 848411, once that bug is fixed, the following line can be removed michael@0: 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); michael@0: michael@0: specialPowersObserver._isFrameScriptLoaded = true; michael@0: } michael@0: michael@0: michael@0: if (onDevice) { michael@0: var cpuLock = Cc["@mozilla.org/power/powermanagerservice;1"] michael@0: .getService(Ci.nsIPowerManagerService) michael@0: .newWakeLock("cpu"); michael@0: michael@0: let manager = navigator.mozWifiManager; michael@0: let con = manager.connection; michael@0: manager.setPowerSavingMode(false); michael@0: michael@0: manager.onenabled = function () { michael@0: if(wifiSettings) { michael@0: var req = manager.getKnownNetworks(); michael@0: req.onsuccess = function () { michael@0: var networks = req.result; michael@0: for (var i = 0; i < networks.length; ++i){ michael@0: var network = networks[i]; michael@0: if(network.ssid == wifiSettings.ssid) { michael@0: manager.forget(network); michael@0: } michael@0: } michael@0: manager.associate(wifiSettings); michael@0: }; michael@0: } michael@0: }; michael@0: michael@0: manager.onstatuschange = function (event) { michael@0: prefs.setIntPref("network.proxy.type", 2); michael@0: if (event.status == 'connected') { michael@0: container.src = mochitestUrl; michael@0: } michael@0: }; michael@0: michael@0: if(wifiSettings) { michael@0: var req = settings.createLock().set({ michael@0: 'wifi.enabled': false, michael@0: 'wifi.suspended': false michael@0: }); michael@0: michael@0: req.onsuccess = function () { michael@0: dump("----------------------enabling wifi------------------\n"); michael@0: var req1 = settings.createLock().set({ michael@0: 'wifi.enabled': true, michael@0: 'wifi.suspended': false}); michael@0: }; michael@0: } michael@0: } else { michael@0: container.src = mochitestUrl; michael@0: }