Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support opening new regular, private, private with Tor window in Tor window #3813

Merged
merged 2 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions browser/ui/brave_browser_command_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,43 @@

#include "brave/browser/ui/brave_browser_command_controller.h"

#include <vector>

#include "brave/app/brave_command_ids.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/browser/ui/brave_pages.h"
#include "brave/browser/ui/browser_commands.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_sync/buildflags/buildflags.h"
#include "brave/components/brave_wallet/browser/buildflags/buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"

#if BUILDFLAG(ENABLE_BRAVE_SYNC)
#include "brave/components/brave_sync/switches.h"
#endif

namespace {

bool IsBraveCommands(int id) {
return id >= IDC_BRAVE_COMMANDS_START && id <= IDC_BRAVE_COMMANDS_LAST;
}

bool IsBraveOverrideCommands(int id) {
static std::vector<int> override_commands({
IDC_NEW_WINDOW,
IDC_NEW_INCOGNITO_WINDOW,
});
return std::find(override_commands.begin(), override_commands.end(), id) !=
override_commands.end();
}

} // namespace

namespace chrome {

BraveBrowserCommandController::BraveBrowserCommandController(Browser* browser)
Expand All @@ -51,8 +67,8 @@ bool BraveBrowserCommandController::ExecuteCommandWithDisposition(
int id,
WindowOpenDisposition disposition,
base::TimeTicks time_stamp) {
return IsBraveCommands(id)
? ExecuteBraveCommandWithDisposition(id, disposition)
return IsBraveCommands(id) || IsBraveOverrideCommands(id)
? ExecuteBraveCommandWithDisposition(id, disposition, time_stamp)
: BrowserCommandController::ExecuteCommandWithDisposition(
id, disposition, time_stamp);
}
Expand Down Expand Up @@ -130,17 +146,32 @@ void BraveBrowserCommandController::UpdateCommandForBraveWallet() {
}

bool BraveBrowserCommandController::ExecuteBraveCommandWithDisposition(
int id, WindowOpenDisposition disposition) {
int id,
WindowOpenDisposition disposition,
base::TimeTicks time_stamp) {
if (!SupportsCommand(id) || !IsCommandEnabled(id))
return false;

if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
return true;

DCHECK(brave_command_updater_.IsCommandEnabled(id))
<< "Invalid/disabled command " << id;
DCHECK(IsCommandEnabled(id)) << "Invalid/disabled command " << id;

switch (id) {
case IDC_NEW_WINDOW:
// Use chromium's action for non-Tor profiles.
if (!brave::IsTorProfile(browser_->profile()))
return BrowserCommandController::ExecuteCommandWithDisposition(
id, disposition, time_stamp);
NewEmptyWindow(brave::GetParentProfile(browser_->profile()));
break;
case IDC_NEW_INCOGNITO_WINDOW:
// Use chromium's action for non-Tor profiles.
if (!brave::IsTorProfile(browser_->profile()))
return BrowserCommandController::ExecuteCommandWithDisposition(
id, disposition, time_stamp);
NewIncognitoWindow(brave::GetParentProfile(browser_->profile()));
break;
case IDC_SHOW_BRAVE_REWARDS:
brave::ShowBraveRewards(browser_);
break;
Expand Down
3 changes: 2 additions & 1 deletion browser/ui/brave_browser_command_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class BraveBrowserCommandController : public chrome::BrowserCommandController {
void UpdateCommandForBraveWallet();

bool ExecuteBraveCommandWithDisposition(int id,
WindowOpenDisposition disposition);
WindowOpenDisposition disposition,
base::TimeTicks time_stamp);

Browser* const browser_;

Expand Down
7 changes: 7 additions & 0 deletions browser/ui/browser_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "brave/browser/ui/browser_commands.h"

#include "brave/browser/profiles/profile_util.h"
#include "brave/browser/tor/tor_profile_service.h"
#include "brave/browser/tor/tor_profile_service_factory.h"
#include "chrome/browser/browser_process.h"
Expand All @@ -13,6 +14,7 @@
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
Expand All @@ -26,6 +28,11 @@ namespace {
namespace brave {

void NewOffTheRecordWindowTor(Browser* browser) {
if (brave::IsTorProfile(browser->profile())) {
chrome::NewEmptyWindow(browser->profile());
return;
}
Comment on lines +31 to +34
Copy link
Member Author

@yrliou yrliou Oct 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're already in Tor window, open a new empty Tor window.


profiles::SwitchToTorProfile(ProfileManager::CreateCallback());
}

Expand Down
9 changes: 4 additions & 5 deletions browser/ui/toolbar/brave_app_menu_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ void BraveAppMenuModel::InsertBraveMenuItems() {
GetIndexOfCommandId(IDC_NEW_WINDOW),
IDC_NEW_TOR_CONNECTION_FOR_SITE,
IDS_NEW_TOR_CONNECTION_FOR_SITE);
} else {
InsertItemWithStringIdAt(
GetIndexOfCommandId(IDC_NEW_INCOGNITO_WINDOW) + 1,
IDC_NEW_OFFTHERECORD_WINDOW_TOR,
IDS_NEW_OFFTHERECORD_WINDOW_TOR);
}

InsertItemWithStringIdAt(GetIndexOfCommandId(IDC_NEW_INCOGNITO_WINDOW) + 1,
IDC_NEW_OFFTHERECORD_WINDOW_TOR,
IDS_NEW_OFFTHERECORD_WINDOW_TOR);
Comment on lines +82 to +84
Copy link
Member Author

@yrliou yrliou Oct 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show this option in Tor window too.

}