Bug 849723 - Introduce API to use the private hidden window correctly. r=ehsan

This commit is contained in:
Josh Matthews 2013-03-14 17:51:49 -04:00
Родитель 4b8a273c58
Коммит 6b6213dba0
2 изменённых файлов: 22 добавлений и 8 удалений

Просмотреть файл

@ -29,13 +29,7 @@ var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
// We need to wait for the hidden window to load, but can't access
// an event target for a regular event listener.
var hidden = mainWindow.Services.appShell.hiddenPrivateDOMWindow;
var tmp = setTimeout(function poll() {
if (hidden.location.href != "resource://gre-resources/hiddenWindow.html" ||
!hidden.document.body) {
setTimeout(poll, 100);
return;
}
mainWindow.PrivateBrowsingUtils.whenHiddenPrivateWindowReady(function(hidden) {
var iframe = hidden.document.createElement('iframe');
iframe.src = 'generic.html';
hidden.document.body.appendChild(iframe);
@ -46,7 +40,7 @@ var tmp = setTimeout(function poll() {
win.close();
win = null;
}, false);
}, 100);
});
function observer(aSubject, aTopic, aData) {
is(aTopic, "last-pb-context-exited", "Unexpected observer topic");

Просмотреть файл

@ -42,6 +42,26 @@ this.PrivateBrowsingUtils = {
},
get isInTemporaryAutoStartMode() {
return gTemporaryAutoStartMode;
},
whenHiddenPrivateWindowReady: function pbu_whenHiddenPrivateWindowReady(cb) {
Components.utils.import("resource://gre/modules/Timer.jsm", Timer);
let win = Services.appShell.hiddenPrivateDOMWindow;
function isNotLoaded() {
return ["complete", "interactive"].indexOf(win.document.readyState) == -1;
}
if (isNotLoaded()) {
setTimeout(function poll() {
if (isNotLoaded()) {
setTimeout(poll, 100);
return;
}
cb(Services.appShell.hiddenPrivateDOMWindow);
}, 4);
} else {
cb(Services.appShell.hiddenPrivateDOMWindow);
}
}
};