tor-browser

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

RequestListColumnInitiator.js (2115B)


      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  Component,
      9 } = require("resource://devtools/client/shared/vendor/react.mjs");
     10 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
     11 const {
     12  getUrlBaseName,
     13 } = require("resource://devtools/client/netmonitor/src/utils/request-utils.js");
     14 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs");
     15 
     16 class RequestListColumnInitiator extends Component {
     17  static get propTypes() {
     18    return {
     19      item: PropTypes.object.isRequired,
     20      onInitiatorBadgeMouseDown: PropTypes.func.isRequired,
     21    };
     22  }
     23 
     24  shouldComponentUpdate(nextProps) {
     25    return this.props.item.cause !== nextProps.item.cause;
     26  }
     27 
     28  render() {
     29    const {
     30      item: { cause },
     31      onInitiatorBadgeMouseDown,
     32    } = this.props;
     33 
     34    let initiator = "";
     35    let lineNumber = "";
     36 
     37    const lastFrameExists = cause && cause.lastFrame;
     38    if (lastFrameExists) {
     39      const { filename, lineNumber: _lineNumber } = cause.lastFrame;
     40      initiator = getUrlBaseName(filename);
     41      lineNumber = ":" + _lineNumber;
     42    }
     43 
     44    // Legacy server might send a numeric value. Display it as "unknown"
     45    const causeType = typeof cause.type === "string" ? cause.type : "unknown";
     46    const causeStr = lastFrameExists ? " (" + causeType + ")" : causeType;
     47    return dom.td(
     48      {
     49        className: "requests-list-column requests-list-initiator",
     50        title: initiator + lineNumber + causeStr,
     51      },
     52      dom.div(
     53        {
     54          className: "requests-list-initiator-lastframe",
     55          onMouseDown: onInitiatorBadgeMouseDown,
     56        },
     57        dom.span({ className: "requests-list-initiator-filename" }, initiator),
     58        dom.span({ className: "requests-list-initiator-line" }, lineNumber)
     59      ),
     60      dom.div({ className: "requests-list-initiator-cause" }, causeStr)
     61    );
     62  }
     63 }
     64 
     65 module.exports = RequestListColumnInitiator;