Skip to content

Commit

Permalink
WIP: Redirect .onion URLs to a private window with Tor, if possible.
Browse files Browse the repository at this point in the history
fix brave/brave-browser#806

- If there is no private window with Tor open, fail.

  => TODO: This should fail noisily, beyond a console message.

  => One may be tempted to just create a private window with Tor, but:
     . This is not obviously easy to do here.
     . Users may not be happy if simply clicking a link can have the
       effect of using Tor when they didn't intend.

- If there is a private window with Tor open, create a new tab to load
  the page.

  => User expectations around onion services are likely to be that
     they provide anonymity, so opening them in the non-anonymous
     window may be surprising.

  => It is not clear how easy it would be to load in a non-Tor window
     and ensure that everything is nevertheless loaded through Tor --
     and likewise links from it, &c.
  • Loading branch information
riastradh-brave committed May 10, 2019
1 parent aba18b1 commit b23fa02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
22 changes: 21 additions & 1 deletion chromium_src/chrome/browser/ui/browser_navigator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,39 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/profiles/brave_profile_manager.h"
#include "brave/browser/renderer_host/brave_navigation_ui_data.h"
#include "brave/common/webui_url_constants.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/common/webui_url_constants.h"
#include "url/gurl.h"

namespace {
void AdjustNavigateParamsForURLBraveImpl(NavigateParams* params) {
bool AdjustNavigateParamsForURLBraveImpl(NavigateParams* params) {
if (params->url.SchemeIs(content::kBraveUIScheme)) {
GURL::Replacements replacements;
replacements.SetSchemeStr(content::kChromeUIScheme);
params->url = params->url.ReplaceComponents(replacements);
}
if (params->url.SchemeIsHTTPOrHTTPS() &&
params->url.DomainIs("onion")) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
Profile* profile = profile_manager->GetProfileByPath(
BraveProfileManager::GetTorProfilePath());
if (profile) {
Browser* browser = chrome::FindTabbedBrowser(profile, true);
DCHECK(browser);
params->disposition = WindowOpenDisposition::SINGLETON_TAB;
params->browser = browser;
params->window_action = NavigateParams::SHOW_WINDOW;
} else {
LOG(ERROR) << "Tried to load .onion without Tor ready";
return false;
}
}
return true;
}

bool IsHostAllowedInIncognitoBraveImpl(const base::StringPiece& host) {
Expand Down
9 changes: 5 additions & 4 deletions patches/chrome-browser-ui-browser_navigator.cc.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc
index 923eb172b0fcfd9f396f30cce4dc91593960056e..10d6e15e608927bf0c88ba034e3180fd0679acb6 100644
index 923eb172b0fcfd9f396f30cce4dc91593960056e..639380ee99fb3b2fb46c6a74f7901e2e931e8a8c 100644
--- a/chrome/browser/ui/browser_navigator.cc
+++ b/chrome/browser/ui/browser_navigator.cc
@@ -104,6 +104,7 @@ Browser* GetOrCreateBrowser(Profile* profile, bool user_gesture) {
@@ -104,6 +104,8 @@ Browser* GetOrCreateBrowser(Profile* profile, bool user_gesture) {
// Returns true on success. Otherwise, if changing params leads the browser into
// an erroneous state, returns false.
bool AdjustNavigateParamsForURL(NavigateParams* params) {
+ AdjustNavigateParamsForURLBraveImpl(params);
+ if (!AdjustNavigateParamsForURLBraveImpl(params))
+ return false;
if (params->contents_to_insert || params->switch_to_singleton_tab ||
IsURLAllowedInIncognito(params->url, params->initiating_profile) ||
params->initiating_profile->IsGuestSession()) {
@@ -717,6 +718,7 @@ void Navigate(NavigateParams* params) {
@@ -717,6 +719,7 @@ void Navigate(NavigateParams* params) {
bool IsHostAllowedInIncognito(const GURL& url) {
std::string scheme = url.scheme();
base::StringPiece host = url.host_piece();
Expand Down

0 comments on commit b23fa02

Please sign in to comment.