tor-browser

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

ManifestJsonLink.js (1877B)


      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 { openDocLink } = require("resource://devtools/client/shared/link.js");
      8 
      9 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs");
     10 const {
     11  createFactory,
     12  PureComponent,
     13 } = require("resource://devtools/client/shared/vendor/react.mjs");
     14 
     15 const {
     16  a,
     17  p,
     18 } = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
     19 
     20 const FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js");
     21 const Localized = createFactory(FluentReact.Localized);
     22 
     23 /**
     24 * This component displays an "Open JSON" link for the Manifest
     25 */
     26 class ManifestJsonLink extends PureComponent {
     27  static get propTypes() {
     28    return {
     29      url: PropTypes.string.isRequired,
     30    };
     31  }
     32 
     33  get shouldRenderLink() {
     34    const { url } = this.props;
     35    // Firefox blocks the loading of Data URLs with mimetypes manifest+json unless
     36    // explicitly typed by the user in the address bar.
     37    // So we are not showing the link in this case.
     38    // See more details in this post:
     39    // https://blog.mozilla.org/security/2017/11/27/blocking-top-level-navigations-data-urls-firefox-59/
     40    return !url.startsWith("data:");
     41  }
     42 
     43  renderLink() {
     44    const { url } = this.props;
     45 
     46    return a(
     47      {
     48        className: "js-manifest-json-link devtools-ellipsis-text",
     49        href: "#",
     50        title: url,
     51        onClick: () => openDocLink(url),
     52      },
     53      url
     54    );
     55  }
     56 
     57  render() {
     58    return p(
     59      { className: "manifest-json-link" },
     60      this.shouldRenderLink
     61        ? this.renderLink()
     62        : Localized({ id: "manifest-json-link-data-url" })
     63    );
     64  }
     65 }
     66 
     67 module.exports = ManifestJsonLink;