From 4cb815f49e9d2cad66f115fe8836e89a66983ee0 Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Thu, 9 Apr 2020 17:21:38 +0900 Subject: [PATCH] Fixed crash when user tries to install ipfs extension from setting When extension install is requested, install dialog is launched. So far, we requsted un-parented install dialog. On linux, custom frame is not allowed for un-parented dialog. Only platform-native frame is used for it. The problem was install dialog tries to set title to custom frame. So, seg fault happened only on linux. And Windows with classic theme will have same issue. On macOS and Windows with aero, crash doesn't happen. But, un-parented dialog has title area that looks ugly. --- .../webui/settings/brave_default_extensions_handler.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/browser/ui/webui/settings/brave_default_extensions_handler.cc b/browser/ui/webui/settings/brave_default_extensions_handler.cc index 486d480d266a..22b391017f1d 100644 --- a/browser/ui/webui/settings/brave_default_extensions_handler.cc +++ b/browser/ui/webui/settings/brave_default_extensions_handler.cc @@ -22,6 +22,9 @@ #include "chrome/browser/media/router/media_router_feature.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/lifetime/application_lifetime.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/browser_window.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "components/flags_ui/flags_ui_constants.h" @@ -274,9 +277,15 @@ void BraveDefaultExtensionsHandler::SetIPFSCompanionEnabled( extensions::ExtensionSystem::Get(profile_)->extension_service(); if (enabled) { if (!IsExtensionInstalled(ipfs_companion_extension_id)) { + // Using FindLastActiveWithProfile() here will be fine. Of course, it can + // return NULL but only return NULL when there was no activated window + // with |profile_| so far. But, it's impossible at here because user can't + // request ipfs install request w/o activating browser. scoped_refptr installer = new extensions::WebstoreInstallWithPrompt( ipfs_companion_extension_id, profile_, + chrome::FindLastActiveWithProfile(profile_)->window()-> + GetNativeWindow(), base::BindOnce(&BraveDefaultExtensionsHandler::OnInstallResult, weak_ptr_factory_.GetWeakPtr(), kIPFSCompanionEnabled));