Bug 925538 - Import fireDialogEvent method into FilePicker. r=mfinkle
authorWes Johnston <wjohnston@mozilla.com>
Mon, 14 Oct 2013 09:40:59 -0700
changeset 164541 8804ec54fbcbde6e92df7c3464f34a75962ef5b8
parent 164540 8406b4a9ed0d0398d0aa91990973789be467eaae
child 164542 3f69e71fc0cff912d5cfbe7fa4f6aa2e76572915
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs925538
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 925538 - Import fireDialogEvent method into FilePicker. r=mfinkle
mobile/android/components/FilePicker.js
--- a/mobile/android/components/FilePicker.js
+++ b/mobile/android/components/FilePicker.js
@@ -158,29 +158,35 @@ FilePicker.prototype = {
   },
 
   get mode() {
     return this._mode;
   },
 
   show: function() {
     if (this._domWin) {
-      PromptUtils.fireDialogEvent(this._domWin, "DOMWillOpenModalDialog");
+      this.fireDialogEvent(this._domWin, "DOMWillOpenModalDialog");
       let winUtils = this._domWin.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
       winUtils.enterModalState();
     }
 
     this._promptActive = true;
     this._sendMessage();
 
     let thread = Services.tm.currentThread;
     while (this._promptActive)
       thread.processNextEvent(true);
     delete this._promptActive;
 
+    if (this._domWin) {
+      let winUtils = this._domWin.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
+      winUtils.leaveModalState();
+      this.fireDialogEvent(this._domWin, "DOMModalDialogClosed");
+    }
+
     if (this._filePath)
       return Ci.nsIFilePicker.returnOK;
 
     return Ci.nsIFilePicker.returnCancel;
   },
 
   open: function(callback) {
     this._callback = callback;
@@ -240,13 +246,27 @@ FilePicker.prototype = {
         if (this.mIndex >= this.mFiles.length) {
           throw Components.results.NS_ERROR_FAILURE;
         }
         return mapFunction(this.mFiles[this.mIndex++]);
       }
     };
   },
 
+  fireDialogEvent: function(aDomWin, aEventName) {
+    // accessing the document object can throw if this window no longer exists. See bug 789888.
+    try {
+      if (!aDomWin.document)
+        return;
+      let event = aDomWin.document.createEvent("Events");
+      event.initEvent(aEventName, true, true);
+      let winUtils = aDomWin.QueryInterface(Ci.nsIInterfaceRequestor)
+                           .getInterface(Ci.nsIDOMWindowUtils);
+      winUtils.dispatchEventToChromeOnly(aDomWin, event);
+    } catch(ex) {
+    }
+  },
+
   classID: Components.ID("{18a4e042-7c7c-424b-a583-354e68553a7f}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker, Ci.nsIObserver])
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([FilePicker]);