This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some of the changes and proposals from Lloyd, simplification of the m…
…ain.js to not work with Firefox, only xulrunner. Also, a new content-window-nobrowser.js implementation which does not use a toplevel browser -- this enabled the ui/browser-session example to work. Notice the browser-session <browser /> tag uses an under implementation xul:tabbrowser but thing that this is a one browser app. It's the developer interface here that matters, we may revisit the under implementation later -- perhaps even an enhanced modified iframe -- another discussion.
- Loading branch information
Showing
5 changed files
with
181 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
impl/packages/chromeless/packages/chromeless-kit/lib/content-window-nobrowser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
let {Cc, Ci} = require("chrome"); | ||
|
||
var xpcom = require("xpcom"); | ||
|
||
var xulNs = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; | ||
|
||
var blankXul = ('<?xml version="1.0"?>' + | ||
'<?xml-stylesheet href="chrome://global/skin/" ' + | ||
' type="text/css"?>' + | ||
'<window xmlns="' + xulNs + '">' + | ||
'</window>'); | ||
|
||
function Injector(browser, onStartLoad) { | ||
memory.track(this); | ||
|
||
browser.addProgressListener(this, | ||
Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT); | ||
this._onStartLoad = onStartLoad; | ||
} | ||
|
||
Injector.prototype = { | ||
QueryInterface : xpcom.utils.generateQI([Ci.nsIWebProgressListener, | ||
Ci.nsISupportsWeakReference]), | ||
|
||
// Taken from Firebug' content/firebug/tabWatcher.js. | ||
_safeGetName: function(request) { | ||
try { | ||
return request.name; | ||
} catch (exc) { | ||
return null; | ||
} | ||
}, | ||
|
||
// Much of this is taken from Firebug's content/firebug/tabWatcher.js, | ||
// specifically the FrameProgressListener object. | ||
onStateChange : function (aWebProgress, aRequest, | ||
aStateFlags, aStatus) { | ||
if (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_REQUEST) { | ||
// We need to get the hook in as soon as the new DOMWindow is | ||
// created, but before it starts executing any scripts in the | ||
// page. After lengthy analysis, it seems that the start of | ||
// these "dummy" requests is the only state that works. | ||
|
||
// TODO: Firebug's code mentions that XHTML doesn't dispatch | ||
// any of these dummy requests, so we should probably use the | ||
// Firebug's XHTML workaround here. | ||
var safeName = this._safeGetName(aRequest); | ||
var window = aWebProgress.DOMWindow; | ||
if (window && window.wrappedJSObject && | ||
(safeName == "about:layout-dummy-request" || | ||
safeName == "about:document-onload-blocker")) { | ||
// TODO: Firebug's code mentions that about:blank causes strange | ||
// behavior here; I don't think it should apply to our use case, | ||
// though. | ||
|
||
try { | ||
this._onStartLoad.call(undefined, window); | ||
} catch (e) { | ||
console.exception(e); | ||
} | ||
} | ||
} | ||
}, | ||
|
||
// Stubs for the nsIWebProgressListener interfaces which we don't use. | ||
onProgressChange : function() { }, | ||
onLocationChange : function() { }, | ||
onStatusChange : function() { }, | ||
onSecurityChange : function() { } | ||
}; | ||
|
||
var windows = []; | ||
|
||
function Window(options) { | ||
memory.track(this); | ||
|
||
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"] | ||
.getService(Ci.nsIWindowWatcher); | ||
var url = "data:application/vnd.mozilla.xul+xml," + escape(blankXul); | ||
|
||
var features = ["", | ||
"width=" + options.width, | ||
"height=" + options.height, | ||
"centerscreen"]; | ||
|
||
if (options.titleBar == false) | ||
features.push("titlebar=no"); | ||
|
||
/* We now pass the options.url, which is the user app directly | ||
inserting it in the window, instead using the xul browser element | ||
that was here. This helped to make the session history work. | ||
*/ | ||
|
||
var window = ww.openWindow(null, options.url, null, features.join(","), null); | ||
|
||
this._id = windows.push(this) - 1; | ||
this._window = window; | ||
this._browser = null; | ||
this._injector = null; | ||
this.options = options; | ||
|
||
window.addEventListener("close", this, false); | ||
window.addEventListener("DOMContentLoaded", this, false); | ||
} | ||
|
||
Window.prototype = { | ||
handleEvent: function handleEvent(event) { | ||
switch (event.type) { | ||
case "close": | ||
if (event.target == this._window) { | ||
if (windows[this._id]) | ||
delete windows[this._id]; | ||
this._window.removeEventListener("close", this, false); | ||
} | ||
break; | ||
case "DOMContentLoaded": | ||
console.log("!"); | ||
if (event.target == this._window.document) { | ||
this._window.removeEventListener("DOMContentLoaded", this, false); | ||
this.options.onStartLoad(this._window); | ||
} | ||
break; | ||
} | ||
}, | ||
close: function() { | ||
this._window.close(); | ||
} | ||
}; | ||
|
||
require("errors").catchAndLogProps(Window.prototype, "handleEvent"); | ||
|
||
exports.Window = Window; | ||
|
||
require("unload").when( | ||
function() { | ||
windows.slice().forEach(function(window) { window.close(); }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters