Skip to content

Instantly share code, notes, and snippets.

Created December 11, 2012 21:42
Show Gist options
  • Save anonymous/4262442 to your computer and use it in GitHub Desktop.
Save anonymous/4262442 to your computer and use it in GitHub Desktop.
let { Cc, Ci } = require('chrome');
let appShellService = Cc['@mozilla.org/appshell/appShellService;1'].
getService(Ci.nsIAppShellService);
let service = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
let window = appShellService.hiddenDOMWindow;
let document = window.document;
let XUL = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'
// It looks like using browser does not works unless type is set to content-targetable.
let frame = document.createElementNS(XUL, "iframe");
frame.setAttribute("type", "content");
frame.setAttribute("src", "data:;charset=utf-8,");
document.documentElement.appendChild(frame);
let docShell = frame.docShell;
docShell.allowAuth = true;
docShell.allowJavascript = true;
docShell.allowPlugins = true;
// New platform capability is required to add window control
// For details see: Bug 635673
if ("allowWindowControl" in docShell)
docShell.allowWindowControl = false;
frame.setAttribute("flex", 1);
frame.setAttribute("transparent", "transparent");
frame.setAttribute("showcaret", true);
frame.setAttribute("clickthrough", "always");
frame.setAttribute("autocompleteenabled", true);
frame.setAttribute("autoscroll", true);
frame.setAttribute("src", "data:text/html,<script>" +
"setTimeout(function(){" +
"window.location='about:blank'" +
"},450);" +
"</script>");
frame.addEventListener("load", function(event) {
console.log("observe destruction of: ", event.target.URL);
let observeID = frame.contentWindow.
QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils).
currentInnerWindowID;
let observer = {
observe: function(subject, topic, data) {
let windowID = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
console.log("observe: ", observeID, " window: ", windowID)
if (windowID === observeID) {
console.log("<<<< unload >>>>")
service. removeObserver(observer, "inner-window-destroyed");
}
}
}
service.addObserver(observer, "inner-window-destroyed", false);
}, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment