Bug 1519335 - [marionette] Simplify frame handling in listener.js. r=marionette-reviewers,maja_zf
☠☠ backed out by 6ffead9985f0 ☠ ☠
authorHenrik Skupin <mail@hskupin.info>
Tue, 02 Jun 2020 16:20:47 +0000
changeset 533655 315a7ffd643bb48c6e2daa92b72e8bc2e9a1f9bf
parent 533654 7c82cbd6f034991a2122d441df49898dfe769741
child 533656 80a0c09b0211cb649ce3613e660ef3b17751e405
push id37475
push userbtara@mozilla.com
push dateWed, 03 Jun 2020 16:12:12 +0000
treeherdermozilla-central@ea34fd156c89 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarionette-reviewers, maja_zf
bugs1519335
milestone79.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 1519335 - [marionette] Simplify frame handling in listener.js. r=marionette-reviewers,maja_zf Differential Revision: https://phabricator.services.mozilla.com/D77281
testing/marionette/driver.js
testing/marionette/listener.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -600,40 +600,40 @@ GeckoDriver.prototype.registerBrowser = 
   return id;
 };
 
 GeckoDriver.prototype.registerPromise = function() {
   const li = "Marionette:Register";
 
   return new Promise(resolve => {
     let cb = ({ json, target }) => {
-      let { outerWindowID } = json;
-      this.registerBrowser(outerWindowID, target);
+      let { frameId } = json;
+      this.registerBrowser(frameId, target);
 
       if (this.curBrowser.frameRegsPending > 0) {
         this.curBrowser.frameRegsPending--;
       }
 
       if (this.curBrowser.frameRegsPending === 0) {
         this.mm.removeMessageListener(li, cb);
         resolve();
       }
 
-      return { outerWindowID };
+      return { frameId };
     };
     this.mm.addMessageListener(li, cb);
   });
 };
 
 GeckoDriver.prototype.listeningPromise = function() {
   const li = "Marionette:ListenersAttached";
 
   return new Promise(resolve => {
     let cb = msg => {
-      if (msg.json.outerWindowID === this.curBrowser.curFrameId) {
+      if (msg.json.frameId === this.curBrowser.curFrameId) {
         this.mm.removeMessageListener(li, cb);
         resolve();
       }
     };
     this.mm.addMessageListener(li, cb);
   });
 };
 
@@ -3567,22 +3567,22 @@ GeckoDriver.prototype.receiveMessage = f
           );
         } else {
           this.currentFrameElement = null;
         }
       }
       break;
 
     case "Marionette:Register":
-      let { outerWindowID } = message.json;
-      this.registerBrowser(outerWindowID, message.target);
-      return { outerWindowID };
+      let { frameId } = message.json;
+      this.registerBrowser(frameId, message.target);
+      return { frameId };
 
     case "Marionette:ListenersAttached":
-      if (message.json.outerWindowID === this.curBrowser.curFrameId) {
+      if (message.json.frameId === this.curBrowser.curFrameId) {
         this.curBrowser.flushPendingCommands();
       }
       break;
 
     case "Marionette:WebDriver:GetCapabilities":
       return this.capabilities.toJSON();
   }
 };
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -53,23 +53,37 @@ const { legacyaction } = ChromeUtils.imp
   "chrome://marionette/content/legacyaction.js"
 );
 const { Log } = ChromeUtils.import("chrome://marionette/content/log.js");
 const { navigate } = ChromeUtils.import(
   "chrome://marionette/content/navigate.js"
 );
 const { proxy } = ChromeUtils.import("chrome://marionette/content/proxy.js");
 
-XPCOMUtils.defineLazyGetter(this, "logger", () =>
-  Log.getWithPrefix(outerWindowID)
-);
+XPCOMUtils.defineLazyGetter(this, "logger", () => Log.getWithPrefix(contentId));
+
 XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]);
 
-let { outerWindowID } = winUtil;
-let curContainer = { frame: content, shadowRoot: null };
+const contentId = winUtil.outerWindowID;
+
+const curContainer = {
+  _frame: null,
+  shadowRoot: null,
+
+  get frame() {
+    return this._frame;
+  },
+
+  set frame(frame) {
+    this._frame = frame;
+
+    this.id = this._frame.windowUtils.outerWindowID;
+    this.shadowRoot = null;
+  },
+};
 
 // Listen for click event to indicate one click has happened, so actions
 // code can send dblclick event
 addEventListener("click", event.DoubleClickTracker.setClick);
 addEventListener("dblclick", event.DoubleClickTracker.resetClick);
 addEventListener("unload", event.DoubleClickTracker.resetClick, true);
 
 const seenEls = new element.Store();
@@ -368,27 +382,25 @@ const loadListener = {
           new TimeoutError(`Timeout loading page after ${this.timeout}ms`),
           this.commandID
         );
         break;
     }
   },
 
   observe(subject, topic) {
-    const win = curContainer.frame;
     const winID = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
-    const curWinID = win.windowUtils.outerWindowID;
 
     logger.trace(`Received observer notification ${topic}`);
 
     switch (topic) {
       // In the case when the currently selected frame is closed,
       // there will be no further load events. Stop listening immediately.
       case "outer-window-destroyed":
-        if (curWinID === winID) {
+        if (winID == curContainer.id) {
           this.stop();
           sendOk(this.commandID);
         }
         break;
     }
   },
 
   /**
@@ -476,35 +488,37 @@ const loadListener = {
 /**
  * Called when listener is first started up.  The listener sends its
  * unique window ID and its current URI to the actor.  If the actor returns
  * an ID, we start the listeners. Otherwise, nothing happens.
  */
 function registerSelf() {
   logger.trace("Frame script loaded");
 
+  curContainer.frame = content;
+
   sandboxes.clear();
-  curContainer = {
-    frame: content,
-    shadowRoot: null,
-  };
   legacyactions.mouseEventsOnly = false;
   action.inputStateMap = new Map();
   action.inputsToCancel = [];
 
-  let reply = sendSyncMessage("Marionette:Register", { outerWindowID });
+  let reply = sendSyncMessage("Marionette:Register", {
+    frameId: contentId,
+  });
   if (reply.length == 0) {
     logger.error("No reply from Marionette:Register");
     return;
   }
 
-  if (reply[0].outerWindowID === outerWindowID) {
+  if (reply[0].frameId === contentId) {
     logger.trace("Frame script registered");
     startListeners();
-    sendAsyncMessage("Marionette:ListenersAttached", { outerWindowID });
+    sendAsyncMessage("Marionette:ListenersAttached", {
+      frameId: contentId,
+    });
   }
 }
 
 // Eventually we will not have a closure for every single command,
 // but use a generic dispatch for all listener commands.
 //
 // Worth nothing that this shares many characteristics with
 // server.TCPConnection#execute.  Perhaps this could be generalised
@@ -661,19 +675,21 @@ function deregister() {
   removeMessageListener("Marionette:switchToFrame", switchToFrame);
   removeMessageListener("Marionette:switchToParentFrame", switchToParentFrame);
   removeMessageListener("Marionette:switchToShadowRoot", switchToShadowRootFn);
   removeMessageListener("Marionette:waitForPageLoaded", waitForPageLoaded);
 }
 
 function deleteSession() {
   seenEls.clear();
+
   // reset container frame to the top-most frame
-  curContainer = { frame: content, shadowRoot: null };
+  curContainer.frame = content;
   curContainer.frame.focus();
+
   legacyactions.touchIds = {};
   if (action.inputStateMap !== undefined) {
     action.inputStateMap.clear();
   }
   if (action.inputsToCancel !== undefined) {
     action.inputsToCancel.length = 0;
   }
 }
@@ -744,18 +760,17 @@ function emitTouchEvent(type, touch) {
     `Emitting Touch event of type ${type} ` +
       `to element with id: ${touch.target.id} ` +
       `and tag name: ${touch.target.tagName} ` +
       `at coordinates (${touch.clientX}), ` +
       `${touch.clientY}) relative to the viewport`
   );
 
   const win = curContainer.frame;
-  let docShell = win.docShell;
-  if (docShell.asyncPanZoomEnabled && legacyactions.scrolling) {
+  if (win.docShell.asyncPanZoomEnabled && legacyactions.scrolling) {
     let ev = {
       index: 0,
       type,
       id: touch.identifier,
       clientX: touch.clientX,
       clientY: touch.clientY,
       screenX: touch.screenX,
       screenY: touch.screenY,