tor-browser

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

StackTracePanel.js (2440B)


      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  createFactory,
     10 } = require("resource://devtools/client/shared/vendor/react.mjs");
     11 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
     12 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs");
     13 const {
     14  fetchNetworkUpdatePacket,
     15 } = require("resource://devtools/client/netmonitor/src/utils/request-utils.js");
     16 
     17 const { div } = dom;
     18 
     19 // Components
     20 const StackTrace = createFactory(
     21  require("resource://devtools/client/shared/components/StackTrace.js")
     22 );
     23 
     24 /**
     25 * This component represents a side panel responsible for
     26 * rendering stack-trace info for selected request.
     27 */
     28 class StackTracePanel extends Component {
     29  static get propTypes() {
     30    return {
     31      connector: PropTypes.object.isRequired,
     32      request: PropTypes.object.isRequired,
     33      sourceMapURLService: PropTypes.object,
     34      openLink: PropTypes.func,
     35    };
     36  }
     37 
     38  /**
     39   * `componentDidMount` is called when opening the StackTracePanel
     40   * for the first time
     41   */
     42  componentDidMount() {
     43    const { request, connector } = this.props;
     44    if (!request.stacktrace) {
     45      fetchNetworkUpdatePacket(connector.requestData, request, ["stackTrace"]);
     46    }
     47  }
     48 
     49  /**
     50   * `componentWillReceiveProps` is the only method called when
     51   * switching between two requests while this panel is displayed.
     52   */
     53  // FIXME: https://bugzilla.mozilla.org/show_bug.cgi?id=1774507
     54  UNSAFE_componentWillReceiveProps(nextProps) {
     55    const { request, connector } = nextProps;
     56    // Only try to fetch the stacktrace if we don't already have the stacktrace yet
     57    if (!request.stacktrace) {
     58      fetchNetworkUpdatePacket(connector.requestData, request, ["stackTrace"]);
     59    }
     60  }
     61 
     62  render() {
     63    const { connector, openLink, request, sourceMapURLService } = this.props;
     64 
     65    const { stacktrace } = request;
     66 
     67    return div(
     68      { className: "panel-container" },
     69      StackTrace({
     70        stacktrace: stacktrace || [],
     71        onViewSourceInDebugger: ({ url, line, column }) => {
     72          return connector.viewSourceInDebugger(url, line, column);
     73        },
     74        sourceMapURLService,
     75        openLink,
     76      })
     77    );
     78  }
     79 }
     80 
     81 module.exports = StackTracePanel;