browser/metro/components/PromptService.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5 const Ci = Components.interfaces;
michael@0 6 const Cc = Components.classes;
michael@0 7 const Cr = Components.results;
michael@0 8 const Cu = Components.utils;
michael@0 9
michael@0 10 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 11 Cu.import("resource://gre/modules/Services.jsm");
michael@0 12
michael@0 13 function PromptService() {
michael@0 14
michael@0 15 }
michael@0 16
michael@0 17 PromptService.prototype = {
michael@0 18 classID: Components.ID("{9a61149b-2276-4a0a-b79c-be994ad106cf}"),
michael@0 19
michael@0 20 QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptFactory, Ci.nsIPromptService, Ci.nsIPromptService2]),
michael@0 21
michael@0 22 /* ---------- nsIPromptFactory ---------- */
michael@0 23
michael@0 24 getPrompt: function getPrompt(domWin, iid) {
michael@0 25 if (!domWin) {
michael@0 26 let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
michael@0 27 if (!chromeWin) {
michael@0 28 let msg = "PromptService.js: Attempted create a prompt but no DOM Window specified and failed to find one";
michael@0 29 Cu.reportError(msg);
michael@0 30 throw(msg);
michael@0 31 }
michael@0 32 domWin = chromeWin.getBrowser().contentWindow;
michael@0 33 }
michael@0 34
michael@0 35 let factory =
michael@0 36 Components.classesByID["{1c978d25-b37f-43a8-a2d6-0c7a239ead87}"]
michael@0 37 .createInstance(Ci.nsIPromptFactory);
michael@0 38
michael@0 39 let prompt = factory.getPrompt(domWin, iid);
michael@0 40 try {
michael@0 41 let bag = prompt.QueryInterface(Ci.nsIWritablePropertyBag2);
michael@0 42 bag.setPropertyAsBool("allowTabModal", true);
michael@0 43 } catch(e) {
michael@0 44 }
michael@0 45 return prompt;
michael@0 46 },
michael@0 47
michael@0 48 /* ---------- private memebers ---------- */
michael@0 49
michael@0 50 callProxy: function(aName, aArgs) {
michael@0 51 let domWin = aArgs[0];
michael@0 52 let prompt = this.getPrompt(domWin, Ci.nsIPrompt);
michael@0 53 if (aName == 'promptAuth' || aName == 'promptAuthAsync') {
michael@0 54 let adapterFactory =
michael@0 55 Components.classesByID["{6e134924-6c3a-4d86-81ac-69432dd971dc}"]
michael@0 56 .createInstance(Ci.nsIAuthPromptAdapterFactory);
michael@0 57 prompt = adapterFactory.createAdapter(prompt);
michael@0 58 }
michael@0 59
michael@0 60 return prompt[aName].apply(prompt, Array.prototype.slice.call(aArgs, 1));
michael@0 61 },
michael@0 62
michael@0 63 /* ---------- nsIPromptService ---------- */
michael@0 64
michael@0 65 alert: function() {
michael@0 66 return this.callProxy("alert", arguments);
michael@0 67 },
michael@0 68 alertCheck: function() {
michael@0 69 return this.callProxy("alertCheck", arguments);
michael@0 70 },
michael@0 71 confirm: function() {
michael@0 72 return this.callProxy("confirm", arguments);
michael@0 73 },
michael@0 74 confirmCheck: function() {
michael@0 75 return this.callProxy("confirmCheck", arguments);
michael@0 76 },
michael@0 77 confirmEx: function() {
michael@0 78 return this.callProxy("confirmEx", arguments);
michael@0 79 },
michael@0 80 prompt: function() {
michael@0 81 return this.callProxy("prompt", arguments);
michael@0 82 },
michael@0 83 promptUsernameAndPassword: function() {
michael@0 84 return this.callProxy("promptUsernameAndPassword", arguments);
michael@0 85 },
michael@0 86 promptPassword: function() {
michael@0 87 return this.callProxy("promptPassword", arguments);
michael@0 88 },
michael@0 89 select: function() {
michael@0 90 return this.callProxy("select", arguments);
michael@0 91 },
michael@0 92
michael@0 93 /* ---------- nsIPromptService2 ---------- */
michael@0 94
michael@0 95 promptAuth: function() {
michael@0 96 return this.callProxy("promptAuth", arguments);
michael@0 97 },
michael@0 98 asyncPromptAuth: function() {
michael@0 99 return this.callProxy("asyncPromptAuth", arguments);
michael@0 100 }
michael@0 101 };
michael@0 102
michael@0 103 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PromptService]);

mercurial