Skip to content

Commit

Permalink
Merge pull request #4189 from brave/disable_tor_in_guest_1.3.x
Browse files Browse the repository at this point in the history
Uplift `Disable opening Tor options in guest window` to 1.3.x
  • Loading branch information
yrliou committed Dec 10, 2019
2 parents aa513e0 + 992771d commit 5f47133
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
13 changes: 13 additions & 0 deletions browser/profiles/profile_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions browser/profiles/profile_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions browser/ui/brave_browser_command_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 5f47133

Please sign in to comment.