mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1235123 - Part 2 - Update architecture of shell_remote.js to align shell.js, r=schien
This commit is contained in:
parent
7730573efe
commit
378e659f60
@ -6,9 +6,10 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var {utils: Cu} = Components;
|
||||
var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/SystemAppProxy.jsm");
|
||||
|
||||
function debug(aStr) {
|
||||
// dump(" -*- ShellRemote.js: " + aStr + "\n");
|
||||
@ -16,6 +17,8 @@ function debug(aStr) {
|
||||
|
||||
var remoteShell = {
|
||||
|
||||
_started: false,
|
||||
|
||||
get homeURL() {
|
||||
let systemAppManifestURL = Services.io.newURI(this.systemAppManifestURL, null, null);
|
||||
let shellRemoteURL = Services.prefs.getCharPref("b2g.multiscreen.system_remote_url");
|
||||
@ -27,14 +30,14 @@ var remoteShell = {
|
||||
return Services.prefs.getCharPref("b2g.system_manifest_url");
|
||||
},
|
||||
|
||||
_started: false,
|
||||
|
||||
hasStarted: function () {
|
||||
return this._started;
|
||||
},
|
||||
|
||||
start: function () {
|
||||
this._started = true;
|
||||
this._isEventListenerReady = false;
|
||||
this.id = window.location.hash.substring(1);
|
||||
|
||||
let homeURL = this.homeURL;
|
||||
if (!homeURL) {
|
||||
@ -42,12 +45,13 @@ var remoteShell = {
|
||||
return;
|
||||
}
|
||||
let manifestURL = this.systemAppManifestURL;
|
||||
// <html:iframe id="remote-systemapp"
|
||||
// mozbrowser="true" allowfullscreen="true"
|
||||
// <html:iframe id="this.id"
|
||||
// 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("id", this.id);
|
||||
systemAppFrame.setAttribute("mozbrowser", "true");
|
||||
systemAppFrame.setAttribute("mozapp", manifestURL);
|
||||
systemAppFrame.setAttribute("allowfullscreen", "true");
|
||||
@ -56,11 +60,75 @@ var remoteShell = {
|
||||
let container = document.getElementById("container");
|
||||
this.contentBrowser = container.appendChild(systemAppFrame);
|
||||
this.contentBrowser.src = homeURL + window.location.hash;
|
||||
|
||||
window.addEventListener("unload", this);
|
||||
this.contentBrowser.addEventListener("mozbrowserloadstart", this);
|
||||
},
|
||||
|
||||
stop: function () {
|
||||
window.removeEventListener("unload", this);
|
||||
this.contentBrowser.removeEventListener("mozbrowserloadstart", this);
|
||||
this.contentBrowser.removeEventListener("mozbrowserlocationchange", this, true);
|
||||
SystemAppProxy.unregisterFrameWithId(this.id);
|
||||
},
|
||||
|
||||
notifyContentStart: function(evt) {
|
||||
this.contentBrowser.removeEventListener("mozbrowserloadstart", this);
|
||||
this.contentBrowser.removeEventListener("mozbrowserlocationchange", this, true);
|
||||
|
||||
SystemAppProxy.registerFrameWithId(remoteShell.id, remoteShell.contentBrowser);
|
||||
SystemAppProxy.addEventListenerWithId(this.id, "mozContentEvent", this);
|
||||
|
||||
let content = this.contentBrowser.contentWindow;
|
||||
content.addEventListener("load", this, true);
|
||||
},
|
||||
|
||||
notifyContentWindowLoaded: function () {
|
||||
SystemAppProxy.setIsLoadedWithId(this.id);
|
||||
},
|
||||
|
||||
notifyEventListenerReady: function () {
|
||||
if (this._isEventListenerReady) {
|
||||
Cu.reportError("shell_remote.js: SystemApp has already been declared as being ready.");
|
||||
return;
|
||||
}
|
||||
this._isEventListenerReady = true;
|
||||
SystemAppProxy.setIsReadyWithId(this.id);
|
||||
},
|
||||
|
||||
handleEvent: function(evt) {
|
||||
debug("Got an event: " + evt.type);
|
||||
let content = this.contentBrowser.contentWindow;
|
||||
|
||||
switch(evt.type) {
|
||||
case "mozContentEvent":
|
||||
if (evt.detail.type === "system-message-listener-ready") {
|
||||
this.notifyEventListenerReady();
|
||||
}
|
||||
break;
|
||||
case "load":
|
||||
if (content.document.location == "about:blank") {
|
||||
return;
|
||||
}
|
||||
content.removeEventListener("load", this, true);
|
||||
this.notifyContentWindowLoaded();
|
||||
break;
|
||||
case "mozbrowserloadstart":
|
||||
if (content.document.location == "about:blank") {
|
||||
this.contentBrowser.addEventListener("mozbrowserlocationchange", this, true);
|
||||
return;
|
||||
}
|
||||
case "mozbrowserlocationchange":
|
||||
if (content.document.location == "about:blank") {
|
||||
return;
|
||||
}
|
||||
this.notifyContentStart();
|
||||
break;
|
||||
case "unload":
|
||||
this.stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
|
Loading…
Reference in New Issue
Block a user