From 992771de70ec7a8f8ceb8d5c3c276a1ce03ba4b2 Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Tue, 10 Dec 2019 05:41:12 +0800 Subject: [PATCH] Merge pull request #4155 from brave/disable_tor_options_in_guest Disable opening Tor options in guest window --- browser/profiles/profile_util.cc | 13 +++++++++++++ browser/profiles/profile_util.h | 2 ++ browser/ui/brave_browser_command_controller.cc | 7 ++----- .../render_view_context_menu.cc | 3 ++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/browser/profiles/profile_util.cc b/browser/profiles/profile_util.cc index da55cccb4f0d..bced61ffa1be 100644 --- a/browser/profiles/profile_util.cc +++ b/browser/profiles/profile_util.cc @@ -19,6 +19,10 @@ #include "chrome/browser/profiles/profile_key.h" #include "chrome/browser/profiles/profile_manager.h" +#if BUILDFLAG(ENABLE_TOR) +#include "brave/browser/tor/tor_profile_service.h" +#endif + namespace brave { namespace { @@ -195,6 +199,15 @@ bool IsGuestProfile(content::BrowserContext* context) { ->IsGuestSession(); } +bool IsTorDisabledForProfile(Profile* profile) { +#if BUILDFLAG(ENABLE_TOR) + return tor::TorProfileService::IsTorDisabled() || + profile->IsGuestSession(); +#else + return true; +#endif +} + } // namespace brave namespace chrome { diff --git a/browser/profiles/profile_util.h b/browser/profiles/profile_util.h index 8987ea3cba22..7237079724ad 100644 --- a/browser/profiles/profile_util.h +++ b/browser/profiles/profile_util.h @@ -43,6 +43,8 @@ Profile* GetParentProfile(const base::FilePath& path); // the guest profile by calling IsGuestSession and have to use this function. bool IsGuestProfile(content::BrowserContext* profile); +bool IsTorDisabledForProfile(Profile* profile); + } // namespace brave namespace chrome { diff --git a/browser/ui/brave_browser_command_controller.cc b/browser/ui/brave_browser_command_controller.cc index 535d9d3966a7..d558e91cdaf1 100644 --- a/browser/ui/brave_browser_command_controller.cc +++ b/browser/ui/brave_browser_command_controller.cc @@ -27,10 +27,6 @@ #include "brave/components/brave_sync/switches.h" #endif -#if BUILDFLAG(ENABLE_TOR) -#include "brave/browser/tor/tor_profile_service.h" -#endif - namespace { bool IsBraveCommands(int id) { @@ -145,7 +141,8 @@ void BraveBrowserCommandController::UpdateCommandForWebcompatReporter() { void BraveBrowserCommandController::UpdateCommandForTor() { #if BUILDFLAG(ENABLE_TOR) - const bool is_tor_enabled = !tor::TorProfileService::IsTorDisabled(); + const bool is_tor_enabled = + !brave::IsTorDisabledForProfile(browser_->profile()); UpdateCommandEnabled(IDC_NEW_TOR_CONNECTION_FOR_SITE, is_tor_enabled); UpdateCommandEnabled(IDC_NEW_OFFTHERECORD_WINDOW_TOR, is_tor_enabled); #endif diff --git a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc index fb09592705f2..a828069406c9 100644 --- a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc +++ b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc @@ -38,8 +38,9 @@ bool BraveRenderViewContextMenu::IsCommandIdEnabled(int id) const { switch (id) { case IDC_CONTENT_CONTEXT_OPENLINKTOR: #if BUILDFLAG(ENABLE_TOR) - if (tor::TorProfileService::IsTorDisabled()) + if (brave::IsTorDisabledForProfile(GetProfile())) return false; + return params_.link_url.is_valid() && IsURLAllowedInIncognito(params_.link_url, browser_context_) && !brave::IsTorProfile(GetProfile());