Commit 4a0e239f authored by Alex Catarineu's avatar Alex Catarineu Committed by Pier Angelo Vendrame
Browse files

Bug 21952: Implement Onion-Location

Whenever a valid Onion-Location HTTP header (or corresponding HTML
<meta> http-equiv attribute) is found in a document load, we either
redirect to it (if the user opted-in via preference) or notify the
presence of an onionsite alternative with a badge in the urlbar.
parent 1a8b2bcf
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
  ExtensionsUI: "resource:///modules/ExtensionsUI.jsm",
  HomePage: "resource:///modules/HomePage.jsm",
  NetUtil: "resource://gre/modules/NetUtil.jsm",
  OnionLocationParent: "resource:///modules/OnionLocationParent.jsm",
  OpenInTabsUtils: "resource:///modules/OpenInTabsUtils.jsm",
  PageActions: "resource:///modules/PageActions.jsm",
  ProcessHangMonitor: "resource:///modules/ProcessHangMonitor.jsm",
@@ -5472,6 +5473,7 @@ var XULBrowserWindow = {
    CFRPageActions.updatePageActions(gBrowser.selectedBrowser);

    AboutReaderParent.updateReaderButton(gBrowser.selectedBrowser);
    OnionLocationParent.updateOnionLocationBadge(gBrowser.selectedBrowser);
    TranslationsParent.onLocationChange(gBrowser.selectedBrowser);

    PictureInPicture.updateUrlbarToggle(gBrowser.selectedBrowser);
@@ -6000,6 +6002,16 @@ var CombinedStopReload = {

var TabsProgressListener = {
  onStateChange(aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
    // Clear OnionLocation UI
    if (
      aStateFlags & Ci.nsIWebProgressListener.STATE_START &&
      aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK &&
      aRequest &&
      aWebProgress.isTopLevel
    ) {
      OnionLocationParent.onStateChange(aBrowser);
    }

    // Collect telemetry data about tab load times.
    if (
      aWebProgress.isTopLevel &&
+2 −0
Original line number Diff line number Diff line
@@ -429,6 +429,8 @@
                  hidden="true">
              <label id="tor-connect-urlbar-button-label"/>
            </hbox>

#include ../../components/onionservices/content/onionlocation-urlbar.inc.xhtml
          </hbox>
        </hbox>
        <toolbartabstop/>
+9 −0
Original line number Diff line number Diff line
@@ -8,6 +8,15 @@
           noautofocus="true"
           role="alert"/>

    <!-- Shown when visiting first web page with an onion-available header.
       - This allows us to add some extra content to the popup.
       - See tor-browser#21952 and tor-browser#41341 -->
    <popupnotification id="onion-location-notification" hidden="true">
      <popupnotificationcontent orient="vertical">
        <description id="onion-location-body-text"/>
      </popupnotificationcontent>
    </popupnotification>

    <popupnotification id="webRTC-shareDevices-notification" hidden="true"
                       descriptionid="webRTC-shareDevices-notification-description">
      <popupnotificationcontent id="webRTC-selectCamera" orient="vertical">
+13 −0
Original line number Diff line number Diff line
@@ -760,6 +760,19 @@ let JSWINDOWACTORS = {
    ],
  },

  OnionLocation: {
    parent: {
      moduleURI: "resource:///modules/OnionLocationParent.jsm",
    },
    child: {
      moduleURI: "resource:///modules/OnionLocationChild.jsm",
      events: {
        pageshow: { mozSystemGroup: true },
      },
    },
    messageManagerGroups: ["browsers"],
  },

  PageInfo: {
    child: {
      esModuleURI: "resource:///actors/PageInfoChild.sys.mjs",
+48 −0
Original line number Diff line number Diff line
// Copyright (c) 2020, The Tor Project, Inc.

"use strict";

var EXPORTED_SYMBOLS = ["OnionLocationChild"];

const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");

class OnionLocationChild extends JSWindowActorChild {
  handleEvent(event) {
    this.onPageShow(event);
  }

  onPageShow(event) {
    if (event.target != this.document) {
      return;
    }
    const onionLocationURI = this.document.onionLocationURI;
    if (onionLocationURI) {
      this.sendAsyncMessage("OnionLocation:Set");
    }
  }

  receiveMessage(aMessage) {
    if (aMessage.name == "OnionLocation:Refresh") {
      const doc = this.document;
      const docShell = this.docShell;
      let onionLocationURI = doc.onionLocationURI;
      const refreshURI = docShell.QueryInterface(Ci.nsIRefreshURI);
      if (onionLocationURI && refreshURI) {
        const docUrl = new URL(doc.URL);
        let onionUrl = new URL(onionLocationURI.asciiSpec);
        // Keep consistent with Location
        if (!onionUrl.hash && docUrl.hash) {
          onionUrl.hash = docUrl.hash;
          onionLocationURI = Services.io.newURI(onionUrl.toString());
        }
        refreshURI.refreshURI(
          onionLocationURI,
          doc.nodePrincipal,
          0,
          false,
          true
        );
      }
    }
  }
}
Loading