Bug 1488507: Disable extension/worker debugging except this firefox. r=jdescottes
☠☠ backed out by 12569187299b ☠ ☠
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Mon, 01 Oct 2018 12:41:02 +0900
changeset 487883 650ac3a6c73de80182fca223666e3f7595e1676e
parent 487882 149ed1ed1f7313ed89e78059d48d464084cd0efb
child 487884 34ab0ef2419d31981551a98398efe10f4cc3d705
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersjdescottes
bugs1488507
milestone64.0a1
Bug 1488507: Disable extension/worker debugging except this firefox. r=jdescottes Summary: Depends on D7038 Reviewers: jdescottes Subscribers: MarcoM Bug #: 1488507 Differential Revision: https://phabricator.services.mozilla.com/D7039
devtools/client/aboutdebugging-new/src/actions/runtimes.js
devtools/client/aboutdebugging-new/src/components/RuntimePage.js
devtools/client/aboutdebugging-new/src/modules/debug-target-support.js
devtools/client/aboutdebugging-new/src/modules/moz.build
--- a/devtools/client/aboutdebugging-new/src/actions/runtimes.js
+++ b/devtools/client/aboutdebugging-new/src/actions/runtimes.js
@@ -8,21 +8,23 @@ const { ADB } = require("devtools/shared
 const { DebuggerClient } = require("devtools/shared/client/debugger-client");
 const { DebuggerServer } = require("devtools/server/main");
 
 const Actions = require("./index");
 
 const {
   findRuntimeById,
 } = require("../modules/runtimes-state-helper");
+const { isSupportedDebugTarget } = require("../modules/debug-target-support");
 
 const {
   CONNECT_RUNTIME_FAILURE,
   CONNECT_RUNTIME_START,
   CONNECT_RUNTIME_SUCCESS,
+  DEBUG_TARGETS,
   DISCONNECT_RUNTIME_FAILURE,
   DISCONNECT_RUNTIME_START,
   DISCONNECT_RUNTIME_SUCCESS,
   RUNTIMES,
   UNWATCH_RUNTIME_FAILURE,
   UNWATCH_RUNTIME_START,
   UNWATCH_RUNTIME_SUCCESS,
   USB_RUNTIMES_UPDATED,
@@ -62,28 +64,29 @@ async function createClientForRuntime(ru
   } else if (type === RUNTIMES.USB) {
     return createUSBClient(runtime.socketPath);
   }
 
   return null;
 }
 
 async function getRuntimeInfo(runtime, client) {
-  const { model } = runtime;
+  const { model, type } = runtime;
   const deviceFront = await client.mainRoot.getFront("device");
   const { brandName: name, channel, version } = await deviceFront.getDescription();
   const icon =
     (channel === "release" || channel === "beta" || channel === "aurora")
       ? `chrome://devtools/skin/images/aboutdebugging-firefox-${ channel }.svg`
       : "chrome://devtools/skin/images/aboutdebugging-firefox-nightly.svg";
 
   return {
     icon,
     model,
     name,
+    type,
     version,
   };
 }
 
 function connectRuntime(id) {
   return async (dispatch, getState) => {
     dispatch({ type: CONNECT_RUNTIME_START });
     try {
@@ -138,19 +141,27 @@ function watchRuntime(id) {
         // THIS_FIREFOX connects and disconnects on the fly when opening the page.
         await dispatch(connectRuntime(RUNTIMES.THIS_FIREFOX));
       }
 
       // The selected runtime should already have a connected client assigned.
       const runtime = findRuntimeById(id, getState().runtimes);
       await dispatch({ type: WATCH_RUNTIME_SUCCESS, runtime });
 
-      dispatch(Actions.requestExtensions());
-      dispatch(Actions.requestTabs());
-      dispatch(Actions.requestWorkers());
+      if (isSupportedDebugTarget(runtime.type, DEBUG_TARGETS.EXTENSION)) {
+        dispatch(Actions.requestExtensions());
+      }
+
+      if (isSupportedDebugTarget(runtime.type, DEBUG_TARGETS.TAB)) {
+        dispatch(Actions.requestTabs());
+      }
+
+      if (isSupportedDebugTarget(runtime.type, DEBUG_TARGETS.WORKER)) {
+        dispatch(Actions.requestWorkers());
+      }
     } catch (e) {
       dispatch({ type: WATCH_RUNTIME_FAILURE, error: e.message });
     }
   };
 }
 
 function unwatchRuntime(id) {
   return async (dispatch, getState) => {
--- a/devtools/client/aboutdebugging-new/src/components/RuntimePage.js
+++ b/devtools/client/aboutdebugging-new/src/components/RuntimePage.js
@@ -20,35 +20,60 @@ const ServiceWorkerAction = createFactor
 const TabDetail = createFactory(require("./debugtarget/TabDetail"));
 const TemporaryExtensionAction = createFactory(require("./debugtarget/TemporaryExtensionAction"));
 const TemporaryExtensionInstaller =
   createFactory(require("./debugtarget/TemporaryExtensionInstaller"));
 const WorkerDetail = createFactory(require("./debugtarget/WorkerDetail"));
 
 const { DEBUG_TARGET_PANE } = require("../constants");
 const { getCurrentRuntimeInfo } = require("../modules/runtimes-state-helper");
+const { isSupportedDebugTargetPane } = require("../modules/debug-target-support");
 
 class RuntimePage extends PureComponent {
   static get propTypes() {
     return {
       collapsibilities: PropTypes.object.isRequired,
       dispatch: PropTypes.func.isRequired,
       installedExtensions: PropTypes.arrayOf(PropTypes.object).isRequired,
       otherWorkers: PropTypes.arrayOf(PropTypes.object).isRequired,
       runtimeInfo: PropTypes.object,
       serviceWorkers: PropTypes.arrayOf(PropTypes.object).isRequired,
       sharedWorkers: PropTypes.arrayOf(PropTypes.object).isRequired,
       tabs: PropTypes.arrayOf(PropTypes.object).isRequired,
       temporaryExtensions: PropTypes.arrayOf(PropTypes.object).isRequired,
     };
   }
 
+  renderDebugTargetPane(name, targets, actionComponent,
+                        detailComponent, paneKey, localizationId) {
+    const { collapsibilities, dispatch, runtimeInfo } = this.props;
+
+    if (!isSupportedDebugTargetPane(runtimeInfo.type, paneKey)) {
+      return null;
+    }
+
+    return Localized(
+      {
+        id: localizationId,
+        attrs: { name: true }
+      },
+      DebugTargetPane({
+        actionComponent,
+        collapsibilityKey: paneKey,
+        detailComponent,
+        dispatch,
+        isCollapsed: collapsibilities.get(paneKey),
+        name,
+        targets,
+      })
+    );
+  }
+
   render() {
     const {
-      collapsibilities,
       dispatch,
       installedExtensions,
       otherWorkers,
       runtimeInfo,
       serviceWorkers,
       sharedWorkers,
       tabs,
       temporaryExtensions,
@@ -60,107 +85,55 @@ class RuntimePage extends PureComponent 
       return null;
     }
 
     return dom.article(
       {
         className: "page js-runtime-page",
       },
       RuntimeInfo(runtimeInfo),
-      TemporaryExtensionInstaller({ dispatch }),
-      Localized(
-        {
-          id: "about-debugging-runtime-temporary-extensions",
-          attrs: { name: true }
-        },
-        DebugTargetPane({
-          actionComponent: TemporaryExtensionAction,
-          collapsibilityKey: DEBUG_TARGET_PANE.TEMPORARY_EXTENSION,
-          detailComponent: ExtensionDetail,
-          dispatch,
-          isCollapsed: collapsibilities.get(DEBUG_TARGET_PANE.TEMPORARY_EXTENSION),
-          name: "Temporary Extensions",
-          targets: temporaryExtensions,
-        })
-      ),
-      Localized(
-        {
-          id: "about-debugging-runtime-extensions",
-          attrs: { name: true }
-        },
-        DebugTargetPane({
-          actionComponent: InspectAction,
-          collapsibilityKey: DEBUG_TARGET_PANE.INSTALLED_EXTENSION,
-          detailComponent: ExtensionDetail,
-          dispatch,
-          isCollapsed: collapsibilities.get(DEBUG_TARGET_PANE.INSTALLED_EXTENSION),
-          name: "Extensions",
-          targets: installedExtensions,
-        })
-      ),
-      Localized(
-        {
-          id: "about-debugging-runtime-tabs",
-          attrs: { name: true }
-        },
-        DebugTargetPane({
-          actionComponent: InspectAction,
-          collapsibilityKey: DEBUG_TARGET_PANE.TAB,
-          detailComponent: TabDetail,
-          dispatch,
-          isCollapsed: collapsibilities.get(DEBUG_TARGET_PANE.TAB),
-          name: "Tabs",
-          targets: tabs
-        })
-      ),
-      Localized(
-        {
-          id: "about-debugging-runtime-service-workers",
-          attrs: { name: true }
-        },
-        DebugTargetPane({
-          actionComponent: ServiceWorkerAction,
-          collapsibilityKey: DEBUG_TARGET_PANE.SERVICE_WORKER,
-          detailComponent: WorkerDetail,
-          dispatch,
-          isCollapsed: collapsibilities.get(DEBUG_TARGET_PANE.SERVICE_WORKER),
-          name: "Service Workers",
-          targets: serviceWorkers
-        })
-      ),
-      Localized(
-        {
-          id: "about-debugging-runtime-shared-workers",
-          attrs: { name: true }
-        },
-        DebugTargetPane({
-          actionComponent: InspectAction,
-          collapsibilityKey: DEBUG_TARGET_PANE.SHARED_WORKER,
-          detailComponent: WorkerDetail,
-          dispatch,
-          isCollapsed: collapsibilities.get(DEBUG_TARGET_PANE.SHARED_WORKER),
-          name: "Shared Workers",
-          targets: sharedWorkers
-        })
-      ),
-      Localized(
-        {
-          id: "about-debugging-runtime-other-workers",
-          attrs: { name: true }
-        },
-        DebugTargetPane({
-          actionComponent: InspectAction,
-          collapsibilityKey: DEBUG_TARGET_PANE.OTHER_WORKER,
-          detailComponent: WorkerDetail,
-          dispatch,
-          isCollapsed: collapsibilities.get(DEBUG_TARGET_PANE.OTHER_WORKER),
-          name: "Other Workers",
-          targets: otherWorkers
-        })
-      ),
+      isSupportedDebugTargetPane(runtimeInfo.type, DEBUG_TARGET_PANE.TEMPORARY_EXTENSION)
+        ? TemporaryExtensionInstaller({ dispatch })
+        : null,
+      this.renderDebugTargetPane("Temporary Extensions",
+                                 temporaryExtensions,
+                                 TemporaryExtensionAction,
+                                 ExtensionDetail,
+                                 DEBUG_TARGET_PANE.TEMPORARY_EXTENSION,
+                                 "about-debugging-runtime-temporary-extensions"),
+      this.renderDebugTargetPane("Extensions",
+                                 installedExtensions,
+                                 InspectAction,
+                                 ExtensionDetail,
+                                 DEBUG_TARGET_PANE.INSTALLED_EXTENSION,
+                                 "about-debugging-runtime-extensions"),
+      this.renderDebugTargetPane("Tabs",
+                                 tabs,
+                                 InspectAction,
+                                 TabDetail,
+                                 DEBUG_TARGET_PANE.TAB,
+                                 "about-debugging-runtime-tabs"),
+      this.renderDebugTargetPane("Service Workers",
+                                 serviceWorkers,
+                                 ServiceWorkerAction,
+                                 WorkerDetail,
+                                 DEBUG_TARGET_PANE.SERVICE_WORKER,
+                                 "about-debugging-runtime-service-workers"),
+      this.renderDebugTargetPane("Shared Workers",
+                                 sharedWorkers,
+                                 InspectAction,
+                                 WorkerDetail,
+                                 DEBUG_TARGET_PANE.SHARED_WORKER,
+                                 "about-debugging-runtime-shared-workers"),
+      this.renderDebugTargetPane("Other Workers",
+                                 otherWorkers,
+                                 InspectAction,
+                                 WorkerDetail,
+                                 DEBUG_TARGET_PANE.OTHER_WORKER,
+                                 "about-debugging-runtime-other-workers"),
     );
   }
 }
 
 const mapStateToProps = state => {
   return {
     collapsibilities: state.ui.debugTargetCollapsibilities,
     installedExtensions: state.debugTargets.installedExtensions,
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/src/modules/debug-target-support.js
@@ -0,0 +1,25 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { DEBUG_TARGETS, DEBUG_TARGET_PANE, RUNTIMES } = require("../constants");
+
+function isSupportedDebugTarget(runtimeType, debugTargetType) {
+  if (runtimeType === RUNTIMES.THIS_FIREFOX) {
+    return true;
+  }
+
+  return debugTargetType === DEBUG_TARGETS.TAB;
+}
+exports.isSupportedDebugTarget = isSupportedDebugTarget;
+
+function isSupportedDebugTargetPane(runtimeType, debugTargetPaneKey) {
+  if (runtimeType === RUNTIMES.THIS_FIREFOX) {
+    return true;
+  }
+
+  return debugTargetPaneKey === DEBUG_TARGET_PANE.TAB;
+}
+exports.isSupportedDebugTargetPane = isSupportedDebugTargetPane;
--- a/devtools/client/aboutdebugging-new/src/modules/moz.build
+++ b/devtools/client/aboutdebugging-new/src/modules/moz.build
@@ -1,11 +1,12 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DevToolsModules(
     'debug-target-collapsibilities.js',
+    'debug-target-support.js',
     'extensions-helper.js',
     'network-locations.js',
     'runtimes-state-helper.js',
     'usb-runtimes.js',
 )