Bug 1156715 - Create shell-remote for launching system-remote, r=fabrice

This commit is contained in:
KuoE0 2015-09-29 19:41:00 +02:00
parent e7d19d0c36
commit 9b20d064f9
7 changed files with 191 additions and 0 deletions

View File

@ -1145,3 +1145,8 @@ pref("dom.presentation.device.name", "Firefox OS");
// Enable notification of performance timing
pref("dom.performance.enable_notify_performance_timing", true);
// Multi-screen
pref("b2g.multiscreen.chrome_remote_url", "chrome://b2g/content/shell_remote.html");
pref("b2g.multiscreen.system_remote_url", "index_remote.html");

View File

@ -20,6 +20,7 @@ Cu.import('resource://gre/modules/AlertsHelper.jsm');
Cu.import('resource://gre/modules/RequestSyncService.jsm');
Cu.import('resource://gre/modules/SystemUpdateService.jsm');
#ifdef MOZ_WIDGET_GONK
Cu.import('resource://gre/modules/MultiscreenHandler.jsm');
Cu.import('resource://gre/modules/NetworkStatsService.jsm');
Cu.import('resource://gre/modules/ResourceStatsService.jsm');
#endif

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<!-- 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/. -->
<html xmlns="http://www.w3.org/1999/xhtml"
id="shellRemote"
windowtype="navigator:remote-browser"
sizemode="fullscreen"
>
<head>
<link rel="stylesheet" href="shell.css" type="text/css">
<script type="application/javascript;version=1.8"
src="chrome://b2g/content/shell_remote.js"> </script>
</head>
<body id="container">
</body>
</html>

View File

@ -0,0 +1,71 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* 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/. */
"use strict";
const {utils: Cu} = Components;
Cu.import("resource://gre/modules/Services.jsm");
function debug(aStr) {
// dump(" -*- ShellRemote.js: " + aStr + "\n");
}
let remoteShell = {
get homeURL() {
let systemAppManifestURL = Services.io.newURI(this.systemAppManifestURL, null, null);
let shellRemoteURL = Services.prefs.getCharPref("b2g.multiscreen.system_remote_url");
shellRemoteURL = Services.io.newURI(shellRemoteURL, null, systemAppManifestURL);
return shellRemoteURL.spec;
},
get systemAppManifestURL() {
return Services.prefs.getCharPref("b2g.system_manifest_url");
},
_started: false,
hasStarted: function () {
return this._started;
},
start: function () {
this._started = true;
let homeURL = this.homeURL;
if (!homeURL) {
debug("ERROR! Remote home URL undefined.");
return;
}
let manifestURL = this.systemAppManifestURL;
// <html:iframe id="remote-systemapp"
// mozbrowser="true" allowfullscreen="true"
// src="blank.html"/>
let systemAppFrame =
document.createElementNS("http://www.w3.org/1999/xhtml", "html:iframe");
systemAppFrame.setAttribute("id", "remote-systemapp");
systemAppFrame.setAttribute("mozbrowser", "true");
systemAppFrame.setAttribute("mozapp", manifestURL);
systemAppFrame.setAttribute("allowfullscreen", "true");
systemAppFrame.setAttribute("src", "blank.html");
let container = document.getElementById("container");
this.contentBrowser = container.appendChild(systemAppFrame);
this.contentBrowser.src = homeURL + window.location.hash;
},
stop: function () {
},
};
window.onload = function() {
if (remoteShell.hasStarted() == false) {
remoteShell.start();
}
};

View File

@ -13,6 +13,8 @@ chrome.jar:
* content/shell.html (content/shell.html)
* content/shell.js (content/shell.js)
content/shell.css (content/shell.css)
content/shell_remote.html (content/shell_remote.html)
content/shell_remote.js (content/shell_remote.js)
content/blank.html (content/blank.html)
content/blank.css (content/blank.css)
#ifdef MOZ_WIDGET_GONK

View File

@ -0,0 +1,92 @@
/* 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/. */
"use strict";
this.EXPORTED_SYMBOLS = ["MultiscreenHandler"];
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
function debug(aStr) {
// dump("MultiscreenHandler: " + aStr + "\n");
}
let window = Services.wm.getMostRecentWindow("navigator:browser");
// Multi-screen support on b2g. The following implementation will open a new
// top-level window once we receive a display connected event.
let MultiscreenHandler = {
topLevelWindows: new Map(),
init: function init() {
Services.obs.addObserver(this, "display-changed", false);
Services.obs.addObserver(this, "xpcom-shutdown", false);
},
uninit: function uninit() {
Services.obs.removeObserver(this, "display-changed");
Services.obs.removeObserver(this, "xpcom-shutdown");
},
observe: function observe(aSubject, aTopic, aData) {
switch (aTopic) {
case "display-changed":
this.handleDisplayChangeEvent(aSubject);
break
case "xpcom-shutdown":
this.uninit();
break
}
},
openTopLevelWindow: function openTopLevelWindow(aDisplay) {
if (this.topLevelWindows.get(aDisplay.id)) {
debug("Top level window for display id: " + aDisplay.id + " has been opened.");
return;
}
let flags = Services.prefs.getCharPref("toolkit.defaultChromeFeatures") +
",mozDisplayId=" + aDisplay.id;
let remoteShellURL = Services.prefs.getCharPref("b2g.multiscreen.chrome_remote_url") +
"#" + aDisplay.id;
let win = Services.ww.openWindow(null, remoteShellURL, "myTopWindow" + aDisplay.id, flags, null);
this.topLevelWindows.set(aDisplay.id, win);
},
closeTopLevelWindow: function closeTopLevelWindow(aDisplay) {
let win = this.topLevelWindows.get(aDisplay.id);
if (win) {
win.close();
this.topLevelWindows.delete(aDisplay.id);
}
},
handleDisplayChangeEvent: function handleDisplayChangeEvent(aSubject) {
let display = aSubject.QueryInterface(Ci.nsIDisplayInfo);
let name = "multiscreen.enabled";
let req = window.navigator.mozSettings.createLock().get(name);
req.addEventListener("success", () => {
let isMultiscreenEnabled = req.result[name];
if (display.connected) {
if (isMultiscreenEnabled) {
this.openTopLevelWindow(display);
}
} else {
this.closeTopLevelWindow(display);
}
});
},
};
MultiscreenHandler.init();
this.MultiscreenHandler = MultiscreenHandler;

View File

@ -67,6 +67,7 @@ EXTRA_JS_MODULES += [
'LogCapture.jsm',
'LogParser.jsm',
'LogShake.jsm',
'MultiscreenHandler.jsm',
'OrientationChangeHandler.jsm',
'SafeMode.jsm',
'Screenshot.jsm',