tor-browser

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

Thread.js (2502B)


      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 import React, { Component } from "devtools/client/shared/vendor/react";
      6 import { div, span } from "devtools/client/shared/vendor/react-dom-factories";
      7 import PropTypes from "devtools/client/shared/vendor/react-prop-types";
      8 import { connect } from "devtools/client/shared/vendor/react-redux";
      9 
     10 import actions from "../../actions/index";
     11 import { getCurrentThread, getIsPaused } from "../../selectors/index";
     12 import DebuggerImage from "../shared/DebuggerImage";
     13 
     14 const classnames = require("resource://devtools/client/shared/classnames.js");
     15 
     16 export class Thread extends Component {
     17  static get propTypes() {
     18    return {
     19      currentThread: PropTypes.string.isRequired,
     20      isPaused: PropTypes.bool.isRequired,
     21      selectThread: PropTypes.func.isRequired,
     22      thread: PropTypes.object.isRequired,
     23    };
     24  }
     25 
     26  onSelectThread = () => {
     27    this.props.selectThread(this.props.thread.actor);
     28  };
     29 
     30  render() {
     31    const { currentThread, isPaused, thread } = this.props;
     32 
     33    const { targetType } = thread;
     34    let iconClassname;
     35    if (targetType.includes("worker")) {
     36      iconClassname = "worker";
     37    } else if (targetType.includes("content_script")) {
     38      iconClassname = "extension";
     39    } else {
     40      iconClassname = "window";
     41    }
     42    let label = thread.name;
     43    if (thread.serviceWorkerStatus) {
     44      label += ` (${thread.serviceWorkerStatus})`;
     45    }
     46    return div(
     47      {
     48        className: classnames("thread", {
     49          selected: thread.actor == currentThread,
     50          paused: isPaused,
     51        }),
     52        key: thread.actor,
     53        onClick: this.onSelectThread,
     54      },
     55      div(
     56        {
     57          className: "icon",
     58        },
     59        React.createElement(DebuggerImage, {
     60          name: iconClassname,
     61        })
     62      ),
     63      div(
     64        {
     65          className: "label",
     66        },
     67        label
     68      ),
     69      isPaused
     70        ? span(
     71            {
     72              className: "pause-badge",
     73              role: "status",
     74            },
     75            L10N.getStr("pausedThread")
     76          )
     77        : null
     78    );
     79  }
     80 }
     81 
     82 const mapStateToProps = (state, props) => ({
     83  currentThread: getCurrentThread(state),
     84  isPaused: getIsPaused(state, props.thread.actor),
     85 });
     86 
     87 export default connect(mapStateToProps, {
     88  selectThread: actions.selectThread,
     89 })(Thread);