Bug 1454441 - 4. Fix Fennec remote debugging; r=esawin
☠☠ backed out by aac9f21986a7 ☠ ☠
authorJim Chen <nchen@mozilla.com>
Mon, 23 Apr 2018 12:07:34 -0400
changeset 468568 d4fcd301a168054a9631f1a1b808553c4e320feb
parent 468567 79fa5c2950a38565c66ec618c35e6e137ca1bff9
child 468569 6f652d798a0cf15e7b63cf1b2e68358b9dc023f2
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1454441
milestone61.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 1454441 - 4. Fix Fennec remote debugging; r=esawin Currently Fennec remote debugging has a bug where custom tabs / PWA can permanently override debugging of Fennec tabs. Fix that bug by switching between the browser/geckoview window types depending on if the Fennec window is gaining or losing focus. MozReview-Commit-ID: 2BhAOPFz3c0
mobile/android/chrome/content/RemoteDebugger.js
mobile/android/chrome/content/browser.js
mobile/android/tests/browser/chrome/test_debugger_server.html
--- a/mobile/android/chrome/content/RemoteDebugger.js
+++ b/mobile/android/chrome/content/RemoteDebugger.js
@@ -7,19 +7,40 @@
 
 XPCOMUtils.defineLazyGetter(this, "DebuggerServer", () => {
   let { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
   let { DebuggerServer } = require("devtools/server/main");
   return DebuggerServer;
 });
 
 var RemoteDebugger = {
-  init() {
+  init(aWindow) {
+    this._windowType = "navigator:browser";
+
     USBRemoteDebugger.init();
     WiFiRemoteDebugger.init();
+
+    const listener = (event) => {
+      if (event.target !== aWindow) {
+        return;
+      }
+
+      const newType = (event.type === "activate") ? "navigator:browser"
+                                                  : "navigator:geckoview";
+      if (this._windowType === newType) {
+        return;
+      }
+
+      this._windowType = newType;
+      if (this.isAnyEnabled) {
+        this.initServer();
+      }
+    };
+    aWindow.addEventListener("activate", listener, { mozSystemGroup: true });
+    aWindow.addEventListener("deactivate", listener, { mozSystemGroup: true });
   },
 
   get isAnyEnabled() {
     return USBRemoteDebugger.isEnabled || WiFiRemoteDebugger.isEnabled;
   },
 
   /**
    * Prompt the user to accept or decline the incoming connection.
@@ -179,16 +200,17 @@ var RemoteDebugger = {
     DebuggerServer.init();
 
     // Add browser and Fennec specific actors
     DebuggerServer.registerAllActors();
     DebuggerServer.registerModule("resource://gre/modules/dbg-browser-actors.js");
 
     // Allow debugging of chrome for any process
     DebuggerServer.allowChromeProcess = true;
+    DebuggerServer.chromeWindowType = this._windowType;
   }
 };
 
 RemoteDebugger.allowConnection =
   RemoteDebugger.allowConnection.bind(RemoteDebugger);
 RemoteDebugger.receiveOOB =
   RemoteDebugger.receiveOOB.bind(RemoteDebugger);
 
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -423,17 +423,17 @@ var BrowserApp = {
       }
     });
 
     NativeWindow.init();
     IndexedDB.init();
     XPInstallObserver.init();
     CharacterEncoding.init();
     ActivityObserver.init();
-    RemoteDebugger.init();
+    RemoteDebugger.init(window);
     DesktopUserAgent.init();
     Distribution.init();
     Tabs.init();
     SearchEngines.init();
     Experiments.init();
 
     // XXX maybe we don't do this if the launch was kicked off from external
     Services.io.offline = false;
--- a/mobile/android/tests/browser/chrome/test_debugger_server.html
+++ b/mobile/android/tests/browser/chrome/test_debugger_server.html
@@ -18,17 +18,17 @@ Migrated from Robocop: https://bugzilla.
 
   ChromeUtils.import("resource://gre/modules/Services.jsm");
   const { require } =
     ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
   const { DebuggerServer } = require("devtools/server/main");
 
   let win = Services.wm.getMostRecentWindow("navigator:browser");
 
-  win.RemoteDebugger.init();
+  win.RemoteDebugger.init(win);
 
   SimpleTest.registerCleanupFunction(function() {
     Services.prefs.clearUserPref(DEBUGGER_USB_ENABLED);
   });
 
   // Enable the debugger via the pref it listens for
   Services.prefs.setBoolPref(DEBUGGER_USB_ENABLED, true);