Skip to content

Commit

Permalink
Reload state when panel is opened
Browse files Browse the repository at this point in the history
It's important that we make the call each time the panel opens to
request credentials
  • Loading branch information
bsclifton committed Apr 1, 2022
1 parent d8c000a commit e78ea82
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
12 changes: 10 additions & 2 deletions browser/ui/webui/brave_vpn/vpn_panel_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@

#include <utility>

#include "brave/browser/brave_vpn/brave_vpn_service_factory.h"
#include "brave/components/brave_vpn/brave_vpn_service.h"

VPNPanelHandler::VPNPanelHandler(
mojo::PendingReceiver<brave_vpn::mojom::PanelHandler> receiver,
ui::MojoBubbleWebUIController* webui_controller)
ui::MojoBubbleWebUIController* webui_controller,
Profile* profile)
: receiver_(this, std::move(receiver)),
webui_controller_(webui_controller) {}
webui_controller_(webui_controller),
profile_(profile) {}

VPNPanelHandler::~VPNPanelHandler() = default;

void VPNPanelHandler::ShowUI() {
auto embedder = webui_controller_->embedder();
BraveVpnService* vpn_service_desktop =
BraveVpnServiceFactory::GetForProfile(profile_);
if (embedder) {
embedder->ShowUI();
vpn_service_desktop->OnPanelVisible();
}
}

Expand Down
5 changes: 4 additions & 1 deletion browser/ui/webui/brave_vpn/vpn_panel_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <vector>

#include "brave/components/brave_vpn/brave_vpn.mojom.h"
#include "chrome/browser/profiles/profile.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "ui/webui/mojo_bubble_web_ui_controller.h"
Expand All @@ -25,7 +26,8 @@ class VPNPanelHandler : public brave_vpn::mojom::PanelHandler {

VPNPanelHandler(
mojo::PendingReceiver<brave_vpn::mojom::PanelHandler> receiver,
ui::MojoBubbleWebUIController* webui_controller);
ui::MojoBubbleWebUIController* webui_controller,
Profile* profile);

VPNPanelHandler(const VPNPanelHandler&) = delete;
VPNPanelHandler& operator=(const VPNPanelHandler&) = delete;
Expand All @@ -38,6 +40,7 @@ class VPNPanelHandler : public brave_vpn::mojom::PanelHandler {
private:
mojo::Receiver<brave_vpn::mojom::PanelHandler> receiver_;
ui::MojoBubbleWebUIController* const webui_controller_;
Profile* profile_;
};

#endif // BRAVE_BROWSER_UI_WEBUI_BRAVE_VPN_VPN_PANEL_HANDLER_H_
4 changes: 2 additions & 2 deletions browser/ui/webui/brave_vpn/vpn_panel_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ void VPNPanelUI::CreatePanelHandler(
auto* profile = Profile::FromWebUI(web_ui());
DCHECK(profile);

panel_handler_ =
std::make_unique<VPNPanelHandler>(std::move(panel_receiver), this);
panel_handler_ = std::make_unique<VPNPanelHandler>(std::move(panel_receiver),
this, profile);

BraveVpnService* vpn_service_desktop =
BraveVpnServiceFactory::GetForProfile(profile);
Expand Down
5 changes: 5 additions & 0 deletions components/brave_vpn/brave_vpn_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ void BraveVpnService::BindInterface(
receivers_.Add(this, std::move(receiver));
}

void BraveVpnService::OnPanelVisible() {
// TODO(bsclifton): clean this up
LoadPurchasedState();
}

void BraveVpnService::GetConnectionState(
GetConnectionStateCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Expand Down
1 change: 1 addition & 0 deletions components/brave_vpn/brave_vpn_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class BraveVpnService :

void BindInterface(
mojo::PendingReceiver<brave_vpn::mojom::ServiceHandler> receiver);
void OnPanelVisible();

// mojom::vpn::ServiceHandler
void GetConnectionState(GetConnectionStateCallback callback) override;
Expand Down

0 comments on commit e78ea82

Please sign in to comment.