tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RuntimePage.js (11054B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const {
      8  connect,
      9 } = require("resource://devtools/client/shared/vendor/react-redux.js");
     10 const {
     11  createFactory,
     12  PureComponent,
     13 } = require("resource://devtools/client/shared/vendor/react.mjs");
     14 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
     15 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs");
     16 
     17 const FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js");
     18 const Localized = createFactory(FluentReact.Localized);
     19 
     20 const CompatibilityWarning = createFactory(
     21  require("resource://devtools/client/aboutdebugging/src/components/CompatibilityWarning.js")
     22 );
     23 const DebugTargetPane = createFactory(
     24  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/DebugTargetPane.js")
     25 );
     26 const ExtensionDetail = createFactory(
     27  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/ExtensionDetail.js")
     28 );
     29 const InspectAction = createFactory(
     30  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/InspectAction.js")
     31 );
     32 const ProfilerDialog = createFactory(
     33  require("resource://devtools/client/aboutdebugging/src/components/ProfilerDialog.js")
     34 );
     35 const RuntimeActions = createFactory(
     36  require("resource://devtools/client/aboutdebugging/src/components/RuntimeActions.js")
     37 );
     38 const RuntimeInfo = createFactory(
     39  require("resource://devtools/client/aboutdebugging/src/components/RuntimeInfo.js")
     40 );
     41 const ServiceWorkerAction = createFactory(
     42  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/ServiceWorkerAction.js")
     43 );
     44 const ServiceWorkerAdditionalActions = createFactory(
     45  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/ServiceWorkerAdditionalActions.js")
     46 );
     47 const ServiceWorkersWarning = createFactory(
     48  require("resource://devtools/client/aboutdebugging/src/components/ServiceWorkersWarning.js")
     49 );
     50 const ProcessDetail = createFactory(
     51  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/ProcessDetail.js")
     52 );
     53 const TabAction = createFactory(
     54  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/TabAction.js")
     55 );
     56 const TabDetail = createFactory(
     57  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/TabDetail.js")
     58 );
     59 const TemporaryExtensionAdditionalActions = createFactory(
     60  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/TemporaryExtensionAdditionalActions.js")
     61 );
     62 const TemporaryExtensionDetail = createFactory(
     63  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/TemporaryExtensionDetail.js")
     64 );
     65 const TemporaryExtensionInstallSection = createFactory(
     66  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/TemporaryExtensionInstallSection.js")
     67 );
     68 const WorkerDetail = createFactory(
     69  require("resource://devtools/client/aboutdebugging/src/components/debugtarget/WorkerDetail.js")
     70 );
     71 
     72 const Actions = require("resource://devtools/client/aboutdebugging/src/actions/index.js");
     73 const {
     74  DEBUG_TARGETS,
     75  DEBUG_TARGET_PANE,
     76  PAGE_TYPES,
     77 } = require("resource://devtools/client/aboutdebugging/src/constants.js");
     78 const Types = require("resource://devtools/client/aboutdebugging/src/types/index.js");
     79 
     80 const {
     81  getCurrentRuntimeDetails,
     82 } = require("resource://devtools/client/aboutdebugging/src/modules/runtimes-state-helper.js");
     83 const {
     84  isSupportedDebugTargetPane,
     85  supportsTemporaryExtensionInstaller,
     86 } = require("resource://devtools/client/aboutdebugging/src/modules/debug-target-support.js");
     87 
     88 class RuntimePage extends PureComponent {
     89  static get propTypes() {
     90    return {
     91      collapsibilities: Types.collapsibilities.isRequired,
     92      dispatch: PropTypes.func.isRequired,
     93      installedExtensions: PropTypes.arrayOf(PropTypes.object).isRequired,
     94      otherWorkers: PropTypes.arrayOf(PropTypes.object).isRequired,
     95      runtimeDetails: Types.runtimeDetails,
     96      runtimeId: PropTypes.string.isRequired,
     97      processes: PropTypes.arrayOf(PropTypes.object).isRequired,
     98      serviceWorkers: PropTypes.arrayOf(PropTypes.object).isRequired,
     99      sharedWorkers: PropTypes.arrayOf(PropTypes.object).isRequired,
    100      showProfilerDialog: PropTypes.bool.isRequired,
    101      tabs: PropTypes.arrayOf(PropTypes.object).isRequired,
    102      temporaryExtensions: PropTypes.arrayOf(PropTypes.object).isRequired,
    103      temporaryInstallError: PropTypes.object,
    104    };
    105  }
    106 
    107  componentDidMount() {
    108    const { dispatch, runtimeId } = this.props;
    109    dispatch(Actions.selectPage(PAGE_TYPES.RUNTIME, runtimeId));
    110  }
    111 
    112  getIconByType(type) {
    113    switch (type) {
    114      case DEBUG_TARGETS.EXTENSION:
    115        return "chrome://devtools/skin/images/debugging-addons.svg";
    116      case DEBUG_TARGETS.PROCESS:
    117        return "chrome://devtools/skin/images/aboutdebugging-process-icon.svg";
    118      case DEBUG_TARGETS.TAB:
    119        return "chrome://devtools/skin/images/debugging-tabs.svg";
    120      case DEBUG_TARGETS.WORKER:
    121        return "chrome://devtools/skin/images/debugging-workers.svg";
    122    }
    123 
    124    throw new Error(`Unsupported type [${type}]`);
    125  }
    126 
    127  renderDebugTargetPane({
    128    actionComponent,
    129    additionalActionsComponent,
    130    children,
    131    detailComponent,
    132    icon,
    133    localizationId,
    134    name,
    135    paneKey,
    136    targets,
    137  }) {
    138    const { collapsibilities, dispatch, runtimeDetails } = this.props;
    139 
    140    if (!isSupportedDebugTargetPane(runtimeDetails.info.type, paneKey)) {
    141      return null;
    142    }
    143 
    144    return Localized(
    145      {
    146        id: localizationId,
    147        attrs: { name: true },
    148      },
    149      DebugTargetPane(
    150        {
    151          actionComponent,
    152          additionalActionsComponent,
    153          collapsibilityKey: paneKey,
    154          detailComponent,
    155          dispatch,
    156          icon,
    157          isCollapsed: collapsibilities.get(paneKey),
    158          name,
    159          targets,
    160        },
    161        children
    162      )
    163    );
    164  }
    165 
    166  renderTemporaryExtensionInstallSection() {
    167    const runtimeType = this.props.runtimeDetails.info.type;
    168    if (
    169      !isSupportedDebugTargetPane(
    170        runtimeType,
    171        DEBUG_TARGET_PANE.TEMPORARY_EXTENSION
    172      ) ||
    173      !supportsTemporaryExtensionInstaller(runtimeType)
    174    ) {
    175      return null;
    176    }
    177 
    178    const { dispatch, temporaryInstallError } = this.props;
    179    return TemporaryExtensionInstallSection({
    180      dispatch,
    181      temporaryInstallError,
    182    });
    183  }
    184 
    185  render() {
    186    const {
    187      dispatch,
    188      installedExtensions,
    189      otherWorkers,
    190      processes,
    191      runtimeDetails,
    192      runtimeId,
    193      serviceWorkers,
    194      sharedWorkers,
    195      showProfilerDialog,
    196      tabs,
    197      temporaryExtensions,
    198    } = this.props;
    199 
    200    if (!runtimeDetails) {
    201      // runtimeInfo can be null when the selectPage action navigates from a runtime A
    202      // to a runtime B (between unwatchRuntime and watchRuntime).
    203      return null;
    204    }
    205 
    206    const { compatibilityReport } = runtimeDetails;
    207 
    208    return dom.article(
    209      {
    210        className: "page qa-runtime-page",
    211      },
    212      RuntimeInfo({ ...runtimeDetails.info, runtimeId, dispatch }),
    213      RuntimeActions({ dispatch, runtimeId, runtimeDetails }),
    214      runtimeDetails.serviceWorkersAvailable ? null : ServiceWorkersWarning(),
    215      CompatibilityWarning({ compatibilityReport }),
    216      this.renderDebugTargetPane({
    217        actionComponent: TabAction,
    218        detailComponent: TabDetail,
    219        icon: this.getIconByType(DEBUG_TARGETS.TAB),
    220        localizationId: "about-debugging-runtime-tabs",
    221        name: "Tabs",
    222        paneKey: DEBUG_TARGET_PANE.TAB,
    223        targets: tabs,
    224      }),
    225      this.renderDebugTargetPane({
    226        actionComponent: InspectAction,
    227        additionalActionsComponent: TemporaryExtensionAdditionalActions,
    228        children: this.renderTemporaryExtensionInstallSection(),
    229        detailComponent: TemporaryExtensionDetail,
    230        icon: this.getIconByType(DEBUG_TARGETS.EXTENSION),
    231        localizationId: "about-debugging-runtime-temporary-extensions",
    232        name: "Temporary Extensions",
    233        paneKey: DEBUG_TARGET_PANE.TEMPORARY_EXTENSION,
    234        targets: temporaryExtensions,
    235      }),
    236      this.renderDebugTargetPane({
    237        actionComponent: InspectAction,
    238        detailComponent: ExtensionDetail,
    239        icon: this.getIconByType(DEBUG_TARGETS.EXTENSION),
    240        localizationId: "about-debugging-runtime-extensions",
    241        name: "Extensions",
    242        paneKey: DEBUG_TARGET_PANE.INSTALLED_EXTENSION,
    243        targets: installedExtensions,
    244      }),
    245      this.renderDebugTargetPane({
    246        actionComponent: ServiceWorkerAction,
    247        additionalActionsComponent: ServiceWorkerAdditionalActions,
    248        detailComponent: WorkerDetail,
    249        icon: this.getIconByType(DEBUG_TARGETS.WORKER),
    250        localizationId: "about-debugging-runtime-service-workers",
    251        name: "Service Workers",
    252        paneKey: DEBUG_TARGET_PANE.SERVICE_WORKER,
    253        targets: serviceWorkers,
    254      }),
    255      this.renderDebugTargetPane({
    256        actionComponent: InspectAction,
    257        detailComponent: WorkerDetail,
    258        icon: this.getIconByType(DEBUG_TARGETS.WORKER),
    259        localizationId: "about-debugging-runtime-shared-workers",
    260        name: "Shared Workers",
    261        paneKey: DEBUG_TARGET_PANE.SHARED_WORKER,
    262        targets: sharedWorkers,
    263      }),
    264      this.renderDebugTargetPane({
    265        actionComponent: InspectAction,
    266        detailComponent: WorkerDetail,
    267        icon: this.getIconByType(DEBUG_TARGETS.WORKER),
    268        localizationId: "about-debugging-runtime-other-workers",
    269        name: "Other Workers",
    270        paneKey: DEBUG_TARGET_PANE.OTHER_WORKER,
    271        targets: otherWorkers,
    272      }),
    273      this.renderDebugTargetPane({
    274        actionComponent: InspectAction,
    275        detailComponent: ProcessDetail,
    276        icon: this.getIconByType(DEBUG_TARGETS.PROCESS),
    277        localizationId: "about-debugging-runtime-processes",
    278        name: "Processes",
    279        paneKey: DEBUG_TARGET_PANE.PROCESSES,
    280        targets: processes,
    281      }),
    282 
    283      showProfilerDialog ? ProfilerDialog({ dispatch, runtimeDetails }) : null
    284    );
    285  }
    286 }
    287 
    288 const mapStateToProps = state => {
    289  return {
    290    collapsibilities: state.ui.debugTargetCollapsibilities,
    291    installedExtensions: state.debugTargets.installedExtensions,
    292    processes: state.debugTargets.processes,
    293    otherWorkers: state.debugTargets.otherWorkers,
    294    runtimeDetails: getCurrentRuntimeDetails(state.runtimes),
    295    serviceWorkers: state.debugTargets.serviceWorkers,
    296    sharedWorkers: state.debugTargets.sharedWorkers,
    297    showProfilerDialog: state.ui.showProfilerDialog,
    298    tabs: state.debugTargets.tabs,
    299    temporaryExtensions: state.debugTargets.temporaryExtensions,
    300    temporaryInstallError: state.ui.temporaryInstallError,
    301  };
    302 };
    303 
    304 module.exports = connect(mapStateToProps)(RuntimePage);