michael@0: var Ci = SpecialPowers.Ci; michael@0: ok(Ci != null, "Access Ci"); michael@0: var Cc = SpecialPowers.Cc; michael@0: ok(Cc != null, "Access Cc"); michael@0: michael@0: var didDialog; michael@0: michael@0: var timer; // keep in outer scope so it's not GC'd before firing michael@0: function startCallbackTimer() { michael@0: didDialog = false; michael@0: michael@0: // Delay before the callback twiddles the prompt. michael@0: const dialogDelay = 10; michael@0: michael@0: // Use a timer to invoke a callback to twiddle the authentication dialog michael@0: timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); michael@0: timer.init(observer, dialogDelay, Ci.nsITimer.TYPE_ONE_SHOT); michael@0: } michael@0: michael@0: michael@0: var observer = SpecialPowers.wrapCallbackObject({ michael@0: QueryInterface : function (iid) { michael@0: const interfaces = [Ci.nsIObserver, michael@0: Ci.nsISupports, Ci.nsISupportsWeakReference]; michael@0: michael@0: if (!interfaces.some( function(v) { return iid.equals(v) } )) michael@0: throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE; michael@0: return this; michael@0: }, michael@0: michael@0: observe : function (subject, topic, data) { michael@0: var doc = getDialogDoc(); michael@0: if (doc) michael@0: handleDialog(doc, testNum); michael@0: else michael@0: startCallbackTimer(); // try again in a bit michael@0: } michael@0: }); michael@0: michael@0: function getDialogDoc() { michael@0: // Find the which contains notifyWindow, by looking michael@0: // through all the open windows and all the in each. michael@0: var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. michael@0: getService(Ci.nsIWindowMediator); michael@0: //var enumerator = wm.getEnumerator("navigator:browser"); michael@0: var enumerator = wm.getXULWindowEnumerator(null); michael@0: michael@0: while (enumerator.hasMoreElements()) { michael@0: var win = enumerator.getNext(); michael@0: var windowDocShell = win.QueryInterface(Ci.nsIXULWindow).docShell; michael@0: michael@0: var containedDocShells = windowDocShell.getDocShellEnumerator( michael@0: Ci.nsIDocShellTreeItem.typeChrome, michael@0: Ci.nsIDocShell.ENUMERATE_FORWARDS); michael@0: while (containedDocShells.hasMoreElements()) { michael@0: // Get the corresponding document for this docshell michael@0: var childDocShell = containedDocShells.getNext(); michael@0: // We don't want it if it's not done loading. michael@0: if (childDocShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE) michael@0: continue; michael@0: var childDoc = childDocShell.QueryInterface(Ci.nsIDocShell) michael@0: .contentViewer michael@0: .DOMDocument; michael@0: michael@0: //ok(true, "Got window: " + childDoc.location.href); michael@0: if (childDoc.location.href == "chrome://global/content/commonDialog.xul") michael@0: return childDoc; michael@0: } michael@0: } michael@0: michael@0: return null; michael@0: }