michael@0: // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: const Cr = Components.results; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function PromptService() { michael@0: michael@0: } michael@0: michael@0: PromptService.prototype = { michael@0: classID: Components.ID("{9a61149b-2276-4a0a-b79c-be994ad106cf}"), michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptFactory, Ci.nsIPromptService, Ci.nsIPromptService2]), michael@0: michael@0: /* ---------- nsIPromptFactory ---------- */ michael@0: michael@0: getPrompt: function getPrompt(domWin, iid) { michael@0: if (!domWin) { michael@0: let chromeWin = Services.wm.getMostRecentWindow("navigator:browser"); michael@0: if (!chromeWin) { michael@0: let msg = "PromptService.js: Attempted create a prompt but no DOM Window specified and failed to find one"; michael@0: Cu.reportError(msg); michael@0: throw(msg); michael@0: } michael@0: domWin = chromeWin.getBrowser().contentWindow; michael@0: } michael@0: michael@0: let factory = michael@0: Components.classesByID["{1c978d25-b37f-43a8-a2d6-0c7a239ead87}"] michael@0: .createInstance(Ci.nsIPromptFactory); michael@0: michael@0: let prompt = factory.getPrompt(domWin, iid); michael@0: try { michael@0: let bag = prompt.QueryInterface(Ci.nsIWritablePropertyBag2); michael@0: bag.setPropertyAsBool("allowTabModal", true); michael@0: } catch(e) { michael@0: } michael@0: return prompt; michael@0: }, michael@0: michael@0: /* ---------- private memebers ---------- */ michael@0: michael@0: callProxy: function(aName, aArgs) { michael@0: let domWin = aArgs[0]; michael@0: let prompt = this.getPrompt(domWin, Ci.nsIPrompt); michael@0: if (aName == 'promptAuth' || aName == 'promptAuthAsync') { michael@0: let adapterFactory = michael@0: Components.classesByID["{6e134924-6c3a-4d86-81ac-69432dd971dc}"] michael@0: .createInstance(Ci.nsIAuthPromptAdapterFactory); michael@0: prompt = adapterFactory.createAdapter(prompt); michael@0: } michael@0: michael@0: return prompt[aName].apply(prompt, Array.prototype.slice.call(aArgs, 1)); michael@0: }, michael@0: michael@0: /* ---------- nsIPromptService ---------- */ michael@0: michael@0: alert: function() { michael@0: return this.callProxy("alert", arguments); michael@0: }, michael@0: alertCheck: function() { michael@0: return this.callProxy("alertCheck", arguments); michael@0: }, michael@0: confirm: function() { michael@0: return this.callProxy("confirm", arguments); michael@0: }, michael@0: confirmCheck: function() { michael@0: return this.callProxy("confirmCheck", arguments); michael@0: }, michael@0: confirmEx: function() { michael@0: return this.callProxy("confirmEx", arguments); michael@0: }, michael@0: prompt: function() { michael@0: return this.callProxy("prompt", arguments); michael@0: }, michael@0: promptUsernameAndPassword: function() { michael@0: return this.callProxy("promptUsernameAndPassword", arguments); michael@0: }, michael@0: promptPassword: function() { michael@0: return this.callProxy("promptPassword", arguments); michael@0: }, michael@0: select: function() { michael@0: return this.callProxy("select", arguments); michael@0: }, michael@0: michael@0: /* ---------- nsIPromptService2 ---------- */ michael@0: michael@0: promptAuth: function() { michael@0: return this.callProxy("promptAuth", arguments); michael@0: }, michael@0: asyncPromptAuth: function() { michael@0: return this.callProxy("asyncPromptAuth", arguments); michael@0: } michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PromptService]);