Bug 1065933 - only handle mozbrowserclose events from current frame, r=jgriffin
authorMalini Das <mdas@mozilla.com>
Wed, 08 Oct 2014 12:43:57 -0400
changeset 232587 71e05880cbb000beab99cee987147766bc82b915
parent 232586 91914270690b322a326a2971c991cd81813dc67c
child 232588 9815045d0c5ac5c9b8a69fdc1b1c974590a0ec19
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs1065933
milestone35.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 1065933 - only handle mozbrowserclose events from current frame, r=jgriffin
testing/marionette/marionette-frame-manager.js
testing/marionette/marionette-server.js
--- a/testing/marionette/marionette-frame-manager.js
+++ b/testing/marionette/marionette-frame-manager.js
@@ -128,32 +128,33 @@ FrameManager.prototype = {
         this.currentRemoteFrame = frame;
         this.addMessageManagerListeners(mm);
         if (!frame.specialPowersObserver) {
           frame.specialPowersObserver = new specialpowers.SpecialPowersObserver();
           frame.specialPowersObserver.init(mm);
         }
 
         mm.sendAsyncMessage("Marionette:restart", {});
-        return;
+        return oopFrame.id;
       }
     }
 
     // If we get here, then we need to load the frame script in this frame,
     // and set the frame's ChromeMessageSender as the active message manager the server will listen to
     this.addMessageManagerListeners(mm);
     logger.info("frame-manager load script: " + mm.toString());
     mm.loadFrameScript(FRAME_SCRIPT, true, true);
     let aFrame = new MarionetteRemoteFrame(message.json.win, message.json.frame);
     aFrame.messageManager = Cu.getWeakReference(mm);
     remoteFrames.push(aFrame);
     this.currentRemoteFrame = aFrame;
 
     aFrame.specialPowersObserver = new specialpowers.SpecialPowersObserver();
     aFrame.specialPowersObserver.init(mm);
+    return oopFrame.id;
   },
 
   /*
    * This function handles switching back to the frame that was interrupted by the modal dialog.
    * This function gets called by the interrupted frame once the dialog is dismissed and the frame resumes its process
    */
   switchToModalOrigin: function FM_switchToModalOrigin() {
     //only handle this if we indeed switched out of the modal's originating frame
--- a/testing/marionette/marionette-server.js
+++ b/testing/marionette/marionette-server.js
@@ -136,16 +136,17 @@ function MarionetteServerConnection(aPre
   this.mainFrame = null; //topmost chrome frame
   this.curFrame = null; // chrome iframe that currently has focus
   this.mainContentFrameId = null;
   this.importedScripts = FileUtils.getFile('TmpD', ['marionetteChromeScripts']);
   this.importedScriptHashes = {"chrome" : [], "content": []};
   this.currentFrameElement = null;
   this.testName = null;
   this.mozBrowserClose = null;
+  this.oopFrameId = null; // frame ID of current remote frame, used for mozbrowserclose events
 }
 
 MarionetteServerConnection.prototype = {
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIMessageListener,
                                          Ci.nsIObserver,
                                          Ci.nsISupportsWeakReference]),
 
@@ -373,20 +374,22 @@ MarionetteServerConnection.prototype = {
     return Services.wm.getEnumerator(type);
   },
 
   /**
   */
   addFrameCloseListener: function MDA_addFrameCloseListener(action) {
     let curWindow = this.getCurrentWindow();
     let self = this;
-    this.mozBrowserClose = function() {
-      curWindow.removeEventListener('mozbrowserclose', self.mozBrowserClose, true);
-      self.switchToGlobalMessageManager();
-      self.sendError("The frame closed during the " + action +  ", recovering to allow further communications", 500, null, self.command_id);
+    this.mozBrowserClose = function(e) {
+      if (e.target.id == self.oopFrameId) {
+        curWindow.removeEventListener('mozbrowserclose', self.mozBrowserClose, true);
+        self.switchToGlobalMessageManager();
+        self.sendError("The frame closed during the " + action +  ", recovering to allow further communications", 500, null, self.command_id);
+      }
     };
     curWindow.addEventListener('mozbrowserclose', this.mozBrowserClose, true);
   },
 
   /**
    * Create a new BrowserObj for window and add to known browsers
    *
    * @param nsIDOMWindow win
@@ -2597,17 +2600,17 @@ MarionetteServerConnection.prototype = {
           this.marionetteLog.addLogs(message.json.log);
         }
         break;
       case "Marionette:runEmulatorCmd":
       case "Marionette:runEmulatorShell":
         this.sendToClient(message.json, -1);
         break;
       case "Marionette:switchToFrame":
-        this.curBrowser.frameManager.switchToFrame(message);
+        this.oopFrameId = this.curBrowser.frameManager.switchToFrame(message);
         this.messageManager = this.curBrowser.frameManager.currentRemoteFrame.messageManager.get();
         break;
       case "Marionette:switchToModalOrigin":
         this.curBrowser.frameManager.switchToModalOrigin(message);
         this.messageManager = this.curBrowser.frameManager.currentRemoteFrame.messageManager.get();
         break;
       case "Marionette:switchedToFrame":
         logger.info("Switched to frame: " + JSON.stringify(message.json));