Skip to content

Commit

Permalink
Fixed crash when account.brav.com is loaded
Browse files Browse the repository at this point in the history
fix brave/brave-browser#35395

When VPN feature flag is disabled, SkusJSHandler should not try to
bind to vpn service handler as BraveVpnService is not instantiated.
  • Loading branch information
simonhong committed Jan 22, 2024
1 parent 5a81c91 commit 793f769
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions browser/brave_vpn/brave_vpn_service_factory.cc
Expand Up @@ -111,6 +111,7 @@ BraveVpnService* BraveVpnServiceFactory::GetForProfile(Profile* profile) {
void BraveVpnServiceFactory::BindForContext(
content::BrowserContext* context,
mojo::PendingReceiver<brave_vpn::mojom::ServiceHandler> receiver) {
CHECK(GetInstance());
auto* service = static_cast<BraveVpnService*>(
GetInstance()->GetServiceForBrowserContext(context, true));
if (service) {
Expand Down
8 changes: 7 additions & 1 deletion components/skus/renderer/BUILD.gn
Expand Up @@ -20,7 +20,6 @@ source_set("renderer") {
deps = [
"//base",
"//brave/components/brave_vpn/common/buildflags",
"//brave/components/brave_vpn/common/mojom",
"//brave/components/skus/common",
"//brave/components/skus/common:mojom",
"//content/public/renderer",
Expand All @@ -31,6 +30,13 @@ source_set("renderer") {
"//third_party/blink/public/strings",
"//v8",
]

if (enable_brave_vpn) {
deps += [
"//brave/components/brave_vpn/common",
"//brave/components/brave_vpn/common/mojom",
]
}
}

source_set("unit_tests") {
Expand Down
6 changes: 5 additions & 1 deletion components/skus/renderer/skus_js_handler.cc
Expand Up @@ -28,6 +28,10 @@
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_script_source.h"

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/components/brave_vpn/common/brave_vpn_utils.h"
#endif

namespace skus {

gin::WrapperInfo SkusJSHandler::kWrapperInfo = {gin::kEmbedderNativeGin};
Expand All @@ -44,7 +48,7 @@ bool SkusJSHandler::EnsureConnected() {
}
bool result = skus_service_.is_bound();
#if BUILDFLAG(ENABLE_BRAVE_VPN)
if (!vpn_service_.is_bound()) {
if (brave_vpn::IsBraveVPNFeatureEnabled() && vpn_service_.is_bound()) {
render_frame_->GetBrowserInterfaceBroker()->GetInterface(
vpn_service_.BindNewPipeAndPassReceiver());
}
Expand Down

0 comments on commit 793f769

Please sign in to comment.