toolkit/components/prompts/src/SharedPromptUtils.jsm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 this.EXPORTED_SYMBOLS = [ "PromptUtils" ];
     3 const Cc = Components.classes;
     4 const Ci = Components.interfaces;
     5 const Cr = Components.results;
     6 const Cu = Components.utils;
     8 this.PromptUtils = {
     9     // Fire a dialog open/close event. Used by tabbrowser to focus the
    10     // tab which is triggering a prompt.
    11     // For remote dialogs, we pass in a different DOM window and a separate
    12     // target. If the caller doesn't pass in the target, then we'll simply use
    13     // the passed-in DOM window.
    14     fireDialogEvent : function (domWin, eventName, maybeTarget) {
    15         let target = maybeTarget || domWin;
    16         let event = domWin.document.createEvent("Events");
    17         event.initEvent(eventName, true, true);
    18         let winUtils = domWin.QueryInterface(Ci.nsIInterfaceRequestor)
    19                              .getInterface(Ci.nsIDOMWindowUtils);
    20         winUtils.dispatchEventToChromeOnly(target, event);
    21     },
    23     objectToPropBag : function (obj) {
    24         let bag = Cc["@mozilla.org/hash-property-bag;1"].
    25                   createInstance(Ci.nsIWritablePropertyBag2);
    26         bag.QueryInterface(Ci.nsIWritablePropertyBag);
    28         for (let propName in obj)
    29             bag.setProperty(propName, obj[propName]);
    31         return bag;
    32     },
    34     propBagToObject : function (propBag, obj) {
    35         // Here we iterate over the object's original properties, not the bag
    36         // (ie, the prompt can't return more/different properties than were
    37         // passed in). This just helps ensure that the caller provides default
    38         // values, lest the prompt forget to set them.
    39         for (let propName in obj)
    40             obj[propName] = propBag.getProperty(propName);
    41     },
    42 };

mercurial