diff --git a/chromium_src/chrome/browser/ui/browser_navigator.cc b/chromium_src/chrome/browser/ui/browser_navigator.cc index c81d76d03225..557aa351a44f 100644 --- a/chromium_src/chrome/browser/ui/browser_navigator.cc +++ b/chromium_src/chrome/browser/ui/browser_navigator.cc @@ -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) { diff --git a/patches/chrome-browser-ui-browser_navigator.cc.patch b/patches/chrome-browser-ui-browser_navigator.cc.patch index d24bdc6ceabc..ce409274faf0 100644 --- a/patches/chrome-browser-ui-browser_navigator.cc.patch +++ b/patches/chrome-browser-ui-browser_navigator.cc.patch @@ -1,16 +1,17 @@ diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc -index 0d1221f617040499eeff4955458d6139b6baa1b2..6806bcaaef009be13f8c79d3a045bfdd09d72ca7 100644 +index 0d1221f617040499eeff4955458d6139b6baa1b2..4b71fc2c63f9c6259e35dd7a9a6bcd2b3c34a429 100644 --- a/chrome/browser/ui/browser_navigator.cc +++ b/chrome/browser/ui/browser_navigator.cc -@@ -105,6 +105,7 @@ Browser* GetOrCreateBrowser(Profile* profile, bool user_gesture) { +@@ -105,6 +105,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()) { -@@ -724,6 +725,7 @@ void Navigate(NavigateParams* params) { +@@ -724,6 +726,7 @@ void Navigate(NavigateParams* params) { bool IsHostAllowedInIncognito(const GURL& url) { std::string scheme = url.scheme(); base::StringPiece host = url.host_piece();