Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
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 };