Unverified Commit c962f24a authored by Richard Pospesel's avatar Richard Pospesel Committed by Matthew Finkel
Browse files

fixup! Bug 27476: Implement about:torconnect captive portal within Tor Browser

parent 9049bf03
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ var TorBootstrapUrlbar = {
        inputContainer: gURLBar._inputContainer,
      })
      this.elements.torConnectBox.addEventListener("click", () => {
        window.openTrustedLinkIn("about:torconnect", "tab");
        TorConnect.openTorConnect();
      });
      Services.obs.addObserver(this, TorConnectTopics.StateChange);
      this.observing = true;
+34 −17
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ const { TorProtocolService } = ChromeUtils.import(
  "resource:///modules/TorProtocolService.jsm"
);

const { TorConnect } = ChromeUtils.import(
const { TorConnect, TorConnectTopics, TorConnectState } = ChromeUtils.import(
  "resource:///modules/TorConnect.jsm"
);

@@ -159,35 +159,42 @@ const gTorPane = (function() {
      this._messageBoxButton = prefpane.querySelector(selectors.messageBox.button);
      // wire up connect button
      this._messageBoxButton.addEventListener("click", () => {
        TorConnect.beginBootstrap().then((result) => {
          let win = Services.wm.getMostRecentWindow("navigator:browser");
          // switch to existing about:torconnect tab or create a new one
          win.switchToTabHavingURI("about:torconnect", true);
        });
        TorConnect.beginBootstrap();
        TorConnect.openTorConnect();
      });

      let populateMessagebox = () => {
        if (TorConnect.shouldShowTorConnect) {
      this._populateMessagebox = () => {
        if (TorConnect.shouldShowTorConnect &&
            TorConnect.state === TorConnectState.Configuring) {
          // set messagebox style and text
          if (TorProtocolService.torBootstrapErrorOccurred()) {
            this._messageBox.parentNode.style.display = null;
            this._messageBox.className = "error";
            this._messageBoxMessage.innerText = TorStrings.torConnect.tryAgainMessage;
            this._messageBoxButton.innerText = TorStrings.torConnect.tryAgain;
          } else {
            this._messageBox.parentNode.style.display = null;
            this._messageBox.className = "warning";
            this._messageBoxMessage.innerText = TorStrings.torConnect.connectMessage;
            this._messageBoxButton.innerText = TorStrings.torConnect.torConnectButton;
          }
        } else {
          // we need to explicitly hide the groupbox, as switching between
          // the tor pane and other panes will 'unhide' (via the 'hidden'
          // attribute) the groupbox, offsetting all of the content down
          // by the groupbox's margin (even if content is 0 height)
          this._messageBox.parentNode.style.display = "none";
          this._messageBox.className = "hidden";
          this._messageBoxMessage.innerText = "";
          this._messageBoxButton.innerText = "";
        }
      }
      populateMessagebox();
      this._populateMessagebox();
      Services.obs.addObserver(this, TorConnectTopics.StateChange);

      // update the messagebox whenever we come back to the page
      window.addEventListener("focus", val => {
        populateMessagebox();
        this._populateMessagebox();
      });

      // Heading
@@ -571,6 +578,7 @@ const gTorPane = (function() {
    uninit() {
      // unregister our observer topics
      Services.obs.removeObserver(TorSettingsTopics.SettingChanged, this);
      Services.obs.removeObserver(TorConnectTopics.StateChange, this);
    },

    // whether the page should be present in about:preferences
@@ -582,9 +590,10 @@ const gTorPane = (function() {
    // Callbacks
    //

    // callback for when the quickstart pref changes
    observe(subject, topic, data) {
      if (topic === TorSettingsTopics.SettingChanged) {
      switch (topic) {
       // triggered when a TorSettings param has changed
        case TorSettingsTopics.SettingChanged: {
          let obj = subject?.wrappedJSObject;
          switch(data) {
            case TorSettingsData.QuickStartEnabled: {
@@ -592,6 +601,14 @@ const gTorPane = (function() {
              break;
            }
          }
          break;
        }
        // triggered when tor connect state changes and we may
        // need to update the messagebox
        case TorConnectTopics.StateChange: {
          this._populateMessagebox();
          break;
        }
      }
    },

+4 −5
Original line number Diff line number Diff line
@@ -87,14 +87,15 @@

  border-radius: 2px;
  border: 0;
  padding-left: 8px;
  padding-right: 8px;
  padding: 0px 8px;
  margin-left: auto;
  margin-right: 0px;

  font-size: 11px;
  font-weight: 400;
  font-weight: 600;
  white-space: nowrap;

  color: white;
}

#torPreferences-connectMessageBox.error #torPreferences-connectMessageBox-button {
@@ -115,12 +116,10 @@

#torPreferences-connectMessageBox.warning #torPreferences-connectMessageBox-button:hover {
  background-color: var(--purple-80);
  color: white!important;
}

#torPreferences-connectMessageBox.warning #torPreferences-connectMessageBox-button:active {
  background-color: var(--purple-90);
  color: white!important;
}

/* Advanced Settings */
+9 −4
Original line number Diff line number Diff line
@@ -329,8 +329,8 @@ const TorConnect = (() => {
            return (TorProtocolService.ownsTorDaemon &&
                   // and we're not using the legacy launcher
                   !TorLauncherUtil.useLegacyLauncher &&
                   // legacy checks, TODO: maybe this should be in terms of our own state?
                   (TorProtocolService.isNetworkDisabled() || !TorProtocolService.isBootstrapDone()));
                   // if we have succesfully bootstraped, then no need to show TorConnect
                   this.state != TorConnectState.Bootstrapped);
        },

        get shouldQuickStart() {
@@ -420,8 +420,13 @@ const TorConnect = (() => {
        Further external commands and helper methods
        */
        openTorPreferences: function() {
            const win = BrowserWindowTracker.getTopWindow()
            win.openTrustedLinkIn("about:preferences#tor", "tab");
            const win = BrowserWindowTracker.getTopWindow();
            win.switchToTabHavingURI("about:preferences#tor", true);
        },

        openTorConnect: function() {
            const win = BrowserWindowTracker.getTopWindow();
            win.switchToTabHavingURI("about:torconnect", true, {ignoreQueryString: true});
        },

        copyTorLogs: function() {