michael@0: this.EXPORTED_SYMBOLS = [ "PromptUtils" ]; michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cr = Components.results; michael@0: const Cu = Components.utils; michael@0: michael@0: this.PromptUtils = { michael@0: // Fire a dialog open/close event. Used by tabbrowser to focus the michael@0: // tab which is triggering a prompt. michael@0: // For remote dialogs, we pass in a different DOM window and a separate michael@0: // target. If the caller doesn't pass in the target, then we'll simply use michael@0: // the passed-in DOM window. michael@0: fireDialogEvent : function (domWin, eventName, maybeTarget) { michael@0: let target = maybeTarget || domWin; michael@0: let event = domWin.document.createEvent("Events"); michael@0: event.initEvent(eventName, true, true); michael@0: let winUtils = domWin.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIDOMWindowUtils); michael@0: winUtils.dispatchEventToChromeOnly(target, event); michael@0: }, michael@0: michael@0: objectToPropBag : function (obj) { michael@0: let bag = Cc["@mozilla.org/hash-property-bag;1"]. michael@0: createInstance(Ci.nsIWritablePropertyBag2); michael@0: bag.QueryInterface(Ci.nsIWritablePropertyBag); michael@0: michael@0: for (let propName in obj) michael@0: bag.setProperty(propName, obj[propName]); michael@0: michael@0: return bag; michael@0: }, michael@0: michael@0: propBagToObject : function (propBag, obj) { michael@0: // Here we iterate over the object's original properties, not the bag michael@0: // (ie, the prompt can't return more/different properties than were michael@0: // passed in). This just helps ensure that the caller provides default michael@0: // values, lest the prompt forget to set them. michael@0: for (let propName in obj) michael@0: obj[propName] = propBag.getProperty(propName); michael@0: }, michael@0: };