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

Added BraveVPNController to BrowserWindowFeatures #26299

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,11 @@ source_set("ui") {

deps += [ "//brave/browser/brave_vpn/win:wireguard_utils" ]
}

sources += [
"brave_vpn/brave_vpn_controller.cc",
"brave_vpn/brave_vpn_controller.h",
]
}
if (enable_ai_chat) {
sources += [
Expand Down
2 changes: 0 additions & 2 deletions browser/ui/brave_browser_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class BraveBrowserWindow : public BrowserWindow {
virtual void ShowWaybackMachineBubble() {}
#endif

virtual void ShowBraveVPNBubble() {}

// Returns true if all tabs in this window is being dragged.
virtual bool IsInTabDragging() const;
};
Expand Down
35 changes: 35 additions & 0 deletions browser/ui/brave_vpn/brave_vpn_controller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/brave_vpn/brave_vpn_controller.h"

#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/browser/ui/views/frame/brave_browser_view.h"
#include "brave/components/brave_vpn/browser/brave_vpn_service.h"
#include "brave/components/brave_vpn/common/brave_vpn_utils.h"
#include "chrome/browser/ui/singleton_tabs.h"
#include "url/gurl.h"

BraveVPNController::BraveVPNController(BrowserView* browser_view)
: browser_view_(browser_view) {}

BraveVPNController::~BraveVPNController() = default;

void BraveVPNController::ShowBraveVPNBubble() {
GetBraveBrowserView()->ShowBraveVPNBubble();
}

void BraveVPNController::OpenVPNAccountPage() {
auto* browser = browser_view_->browser();
auto* profile = browser->profile();
auto* vpn_service = brave_vpn::BraveVpnServiceFactory::GetForProfile(profile);
const auto url =
brave_vpn::GetManageUrl(vpn_service->GetCurrentEnvironment());
ShowSingletonTab(browser, GURL(url));
}

BraveBrowserView* BraveVPNController::GetBraveBrowserView() {
return static_cast<BraveBrowserView*>(browser_view_);
}
30 changes: 30 additions & 0 deletions browser/ui/brave_vpn/brave_vpn_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_BRAVE_VPN_BRAVE_VPN_CONTROLLER_H_
#define BRAVE_BROWSER_UI_BRAVE_VPN_BRAVE_VPN_CONTROLLER_H_

#include "base/memory/raw_ptr.h"

class BraveBrowserView;
class BrowserView;

class BraveVPNController {
public:
explicit BraveVPNController(BrowserView* browser_view);
~BraveVPNController();
BraveVPNController(const BraveVPNController&) = delete;
BraveVPNController& operator=(const BraveVPNController&) = delete;

void ShowBraveVPNBubble();
void OpenVPNAccountPage();

private:
BraveBrowserView* GetBraveBrowserView();

raw_ptr<BrowserView> browser_view_ = nullptr;
};

#endif // BRAVE_BROWSER_UI_BRAVE_VPN_BRAVE_VPN_CONTROLLER_H_
6 changes: 4 additions & 2 deletions browser/ui/browser_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/browser/ui/brave_vpn/brave_vpn_controller.h"
#include "brave/components/brave_vpn/browser/brave_vpn_service.h"
#include "brave/components/brave_vpn/common/brave_vpn_constants.h"
#include "brave/components/brave_vpn/common/brave_vpn_utils.h"
Expand Down Expand Up @@ -181,8 +182,9 @@ void MaybeDistillAndShowSpeedreaderBubble(Browser* browser) {
}

void ShowBraveVPNBubble(Browser* browser) {
// Ask to browser view.
static_cast<BraveBrowserWindow*>(browser->window())->ShowBraveVPNBubble();
#if BUILDFLAG(ENABLE_BRAVE_VPN)
browser->GetFeatures().GetBraveVPNController()->ShowBraveVPNBubble();
#endif
}

void ToggleBraveVPNTrayIcon() {
Expand Down
3 changes: 2 additions & 1 deletion browser/ui/views/frame/brave_browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class BraveBrowserView : public BrowserView,

void SetStarredState(bool is_starred) override;
void ShowUpdateChromeDialog() override;

void ShowBraveVPNBubble();
void CreateWalletBubble();
void CreateApproveWalletBubble();
void CloseWalletBubble();
Expand Down Expand Up @@ -163,7 +165,6 @@ class BraveBrowserView : public BrowserView,
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override;
void ShowBraveVPNBubble() override;
views::CloseRequestResult OnWindowCloseRequested() override;
void ConfirmBrowserCloseWithPendingDownloads(
int download_count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,41 @@

#include "chrome/browser/ui/browser_window/public/browser_window_features.h"

#include "base/notreached.h"
#include "brave/browser/ui/views/side_panel/brave_side_panel_coordinator.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/browser/ui/brave_vpn/brave_vpn_controller.h"
#endif

#if !BUILDFLAG(ENABLE_BRAVE_VPN)
// Use stub class to avoid incomplete type build error.
class BraveVPNController {};
#endif

#define SidePanelCoordinator BraveSidePanelCoordinator
#define InitPostBrowserViewConstruction \
InitPostBrowserViewConstruction_ChromiumImpl

#include "src/chrome/browser/ui/browser_window/browser_window_features.cc"

#undef InitPostBrowserViewConstruction
#undef SidePanelCoordinator

void BrowserWindowFeatures::InitPostBrowserViewConstruction(
BrowserView* browser_view) {
InitPostBrowserViewConstruction_ChromiumImpl(browser_view);

#if BUILDFLAG(ENABLE_BRAVE_VPN)
brave_vpn_controller_ = std::make_unique<BraveVPNController>(browser_view);
#endif
}

BraveVPNController* BrowserWindowFeatures::GetBraveVPNController() {
#if BUILDFLAG(ENABLE_BRAVE_VPN)
return brave_vpn_controller_.get();
#else
NOTREACHED_NORETURN();
#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_BROWSER_WINDOW_PUBLIC_BROWSER_WINDOW_FEATURES_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_BROWSER_WINDOW_PUBLIC_BROWSER_WINDOW_FEATURES_H_

class BraveVPNController;

#define InitPostBrowserViewConstruction \
InitPostBrowserViewConstruction_ChromiumImpl(BrowserView* browser_view); \
BraveVPNController* GetBraveVPNController(); \
\
private: \
std::unique_ptr<BraveVPNController> brave_vpn_controller_; \
\
public: \
void InitPostBrowserViewConstruction

#include "src/chrome/browser/ui/browser_window/public/browser_window_features.h" // IWYU pragma: export

#undef InitPostBrowserViewConstruction

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_BROWSER_WINDOW_PUBLIC_BROWSER_WINDOW_FEATURES_H_
Loading