browser/metro/components/PromptService.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/components/PromptService.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +const Ci = Components.interfaces;
     1.9 +const Cc = Components.classes;
    1.10 +const Cr = Components.results;
    1.11 +const Cu = Components.utils;
    1.12 +
    1.13 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.14 +Cu.import("resource://gre/modules/Services.jsm");
    1.15 +
    1.16 +function PromptService() {
    1.17 +
    1.18 +}
    1.19 +
    1.20 +PromptService.prototype = {
    1.21 +  classID: Components.ID("{9a61149b-2276-4a0a-b79c-be994ad106cf}"),
    1.22 +
    1.23 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptFactory, Ci.nsIPromptService, Ci.nsIPromptService2]),
    1.24 +
    1.25 +  /* ----------  nsIPromptFactory  ---------- */
    1.26 +
    1.27 +  getPrompt: function getPrompt(domWin, iid) {
    1.28 +    if (!domWin) {
    1.29 +      let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
    1.30 +      if (!chromeWin) {
    1.31 +        let msg = "PromptService.js: Attempted create a prompt but no DOM Window specified and failed to find one";
    1.32 +        Cu.reportError(msg);
    1.33 +        throw(msg);
    1.34 +      }
    1.35 +      domWin = chromeWin.getBrowser().contentWindow;
    1.36 +    }
    1.37 +
    1.38 +    let factory =
    1.39 +          Components.classesByID["{1c978d25-b37f-43a8-a2d6-0c7a239ead87}"]
    1.40 +                    .createInstance(Ci.nsIPromptFactory);
    1.41 +
    1.42 +    let prompt = factory.getPrompt(domWin, iid);
    1.43 +    try {
    1.44 +      let bag = prompt.QueryInterface(Ci.nsIWritablePropertyBag2);
    1.45 +      bag.setPropertyAsBool("allowTabModal", true);
    1.46 +    } catch(e) {
    1.47 +    }
    1.48 +    return prompt;
    1.49 +  },
    1.50 +
    1.51 +  /* ----------  private memebers  ---------- */
    1.52 +
    1.53 +  callProxy: function(aName, aArgs) {
    1.54 +    let domWin = aArgs[0];
    1.55 +    let prompt = this.getPrompt(domWin, Ci.nsIPrompt);
    1.56 +    if (aName == 'promptAuth' || aName == 'promptAuthAsync') {
    1.57 +      let adapterFactory =
    1.58 +            Components.classesByID["{6e134924-6c3a-4d86-81ac-69432dd971dc}"]
    1.59 +                      .createInstance(Ci.nsIAuthPromptAdapterFactory);
    1.60 +      prompt = adapterFactory.createAdapter(prompt);
    1.61 +    }
    1.62 +
    1.63 +    return prompt[aName].apply(prompt, Array.prototype.slice.call(aArgs, 1));
    1.64 +  },
    1.65 +
    1.66 +  /* ----------  nsIPromptService  ---------- */
    1.67 +
    1.68 +  alert: function() {
    1.69 +    return this.callProxy("alert", arguments);
    1.70 +  },
    1.71 +  alertCheck: function() {
    1.72 +    return this.callProxy("alertCheck", arguments);
    1.73 +  },
    1.74 +  confirm: function() {
    1.75 +    return this.callProxy("confirm", arguments);
    1.76 +  },
    1.77 +  confirmCheck: function() {
    1.78 +    return this.callProxy("confirmCheck", arguments);
    1.79 +  },
    1.80 +  confirmEx: function() {
    1.81 +    return this.callProxy("confirmEx", arguments);
    1.82 +  },
    1.83 +  prompt: function() {
    1.84 +    return this.callProxy("prompt", arguments);
    1.85 +  },
    1.86 +  promptUsernameAndPassword: function() {
    1.87 +    return this.callProxy("promptUsernameAndPassword", arguments);
    1.88 +  },
    1.89 +  promptPassword: function() {
    1.90 +    return this.callProxy("promptPassword", arguments);
    1.91 +  },
    1.92 +  select: function() {
    1.93 +    return this.callProxy("select", arguments);
    1.94 +  },
    1.95 +
    1.96 +  /* ----------  nsIPromptService2  ---------- */
    1.97 +
    1.98 +  promptAuth: function() {
    1.99 +    return this.callProxy("promptAuth", arguments);
   1.100 +  },
   1.101 +  asyncPromptAuth: function() {
   1.102 +    return this.callProxy("asyncPromptAuth", arguments);
   1.103 +  }
   1.104 +};
   1.105 +
   1.106 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PromptService]);

mercurial