diff --git a/browser/mac/sparkle_glue.h b/browser/mac/sparkle_glue.h index 8fa99cf1469d..540d0f0f48f5 100644 --- a/browser/mac/sparkle_glue.h +++ b/browser/mac/sparkle_glue.h @@ -53,6 +53,8 @@ extern NSString* const kBraveAutoupdateStatusErrorMessages; - (void)checkForUpdates; +- (void)relaunch; + - (AutoupdateStatus)recentStatus; - (NSNotification*)recentNotification; diff --git a/browser/mac/sparkle_glue.mm b/browser/mac/sparkle_glue.mm index 2dde411a6f0a..10f2978b1b77 100644 --- a/browser/mac/sparkle_glue.mm +++ b/browser/mac/sparkle_glue.mm @@ -147,6 +147,8 @@ - (BOOL)loadSparkleFramework { if ([self isOnReadOnlyFilesystem]) return NO; + DCHECK(!su_updater_); + NSString* sparkle_path = [[base::mac::FrameworkBundle() privateFrameworksPath] stringByAppendingPathComponent:@"Sparkle.framework"]; @@ -164,6 +166,11 @@ - (BOOL)loadSparkleFramework { } - (void)registerWithSparkle { + // This can be called by BraveBrowserMainPartsMac::PreMainMessageLoopStart() + // again when browser is relaunched. + if (registered_) + return; + DCHECK(brave::UpdateEnabled()); DCHECK(su_updater_); @@ -218,6 +225,11 @@ - (void)checkForUpdates { [su_updater_ checkForUpdatesInBackground]; } +- (void)relaunch { + [su_updater_.driver installWithToolAndRelaunch:YES + displayingUserInterface:NO]; +} + - (void)checkForUpdatesInBackground { DCHECK(registered_); [su_updater_ checkForUpdatesInBackground]; diff --git a/browser/mac/su_updater.h b/browser/mac/su_updater.h index 3980c35d098f..62aee0d5a7d2 100644 --- a/browser/mac/su_updater.h +++ b/browser/mac/su_updater.h @@ -7,8 +7,17 @@ #import +@interface SUUpdateDriver; + +- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface + :(BOOL)showUI; + +@end + @interface SUUpdater : NSObject +@property (strong) SUUpdateDriver *driver; + + (SUUpdater *)sharedUpdater; - (void)checkForUpdates:(id)sender; diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 856b8fa19464..58cd1a5d2b31 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -73,6 +73,8 @@ source_set("ui") { "webui/brave_welcome_ui.h", "webui/settings/brave_privacy_handler.cc", "webui/settings/brave_privacy_handler.h", + "webui/settings/brave_relaunch_handler_mac.mm", + "webui/settings/brave_relaunch_handler_mac.h", "webui/settings/default_brave_shields_handler.cc", "webui/settings/default_brave_shields_handler.h", "webui/sync/sync_ui.cc", diff --git a/browser/ui/webui/brave_md_settings_ui.cc b/browser/ui/webui/brave_md_settings_ui.cc index 7133c9608f53..9501655979af 100644 --- a/browser/ui/webui/brave_md_settings_ui.cc +++ b/browser/ui/webui/brave_md_settings_ui.cc @@ -12,12 +12,21 @@ #include "chrome/browser/ui/webui/settings/metrics_reporting_handler.h" #include "content/public/browser/web_ui_data_source.h" +#if defined(OS_MACOSX) +#include "brave/browser/ui/webui/settings/brave_relaunch_handler_mac.h" +#endif + BraveMdSettingsUI::BraveMdSettingsUI(content::WebUI* web_ui, const std::string& host) : MdSettingsUI(web_ui) { web_ui->AddMessageHandler(std::make_unique()); web_ui->AddMessageHandler(std::make_unique()); web_ui->AddMessageHandler(std::make_unique()); + + #if defined(OS_MACOSX) + // Use sparkle's relaunch api for browser relaunch on update. + web_ui->AddMessageHandler(std::make_unique()); + #endif } BraveMdSettingsUI::~BraveMdSettingsUI() { diff --git a/browser/ui/webui/settings/brave_relaunch_handler_mac.h b/browser/ui/webui/settings/brave_relaunch_handler_mac.h new file mode 100644 index 000000000000..594dd1f2909e --- /dev/null +++ b/browser/ui/webui/settings/brave_relaunch_handler_mac.h @@ -0,0 +1,28 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_RELAUNCH_HANDLER_H_ +#define BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_RELAUNCH_HANDLER_H_ + +#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" + +class Profile; + +class BraveRelaunchHandler : public settings::SettingsPageUIHandler { + public: + BraveRelaunchHandler() = default; + ~BraveRelaunchHandler() override = default; + + private: + // SettingsPageUIHandler overrides: + void RegisterMessages() override; + void OnJavascriptAllowed() override {} + void OnJavascriptDisallowed() override {} + + void Relaunch(const base::ListValue* args); + + DISALLOW_COPY_AND_ASSIGN(BraveRelaunchHandler); +}; + +#endif // BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_RELAUNCH_HANDLER_H_ diff --git a/browser/ui/webui/settings/brave_relaunch_handler_mac.mm b/browser/ui/webui/settings/brave_relaunch_handler_mac.mm new file mode 100644 index 000000000000..c1996bb52c65 --- /dev/null +++ b/browser/ui/webui/settings/brave_relaunch_handler_mac.mm @@ -0,0 +1,19 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/webui/settings/brave_relaunch_handler_mac.h" + +#include "base/bind.h" +#import "brave/browser/mac/sparkle_glue.h" + +void BraveRelaunchHandler::RegisterMessages() { + web_ui()->RegisterMessageCallback( + "relaunchOnMac", + base::BindRepeating(&BraveRelaunchHandler::Relaunch, + base::Unretained(this))); +} + +void BraveRelaunchHandler::Relaunch(const base::ListValue* args) { + [[SparkleGlue sharedSparkleGlue] relaunch]; +} diff --git a/patches/chrome-browser-resources-settings-about_page-about_page.js.patch b/patches/chrome-browser-resources-settings-about_page-about_page.js.patch new file mode 100644 index 000000000000..46fc6782d3e9 --- /dev/null +++ b/patches/chrome-browser-resources-settings-about_page-about_page.js.patch @@ -0,0 +1,19 @@ +diff --git a/chrome/browser/resources/settings/about_page/about_page.js b/chrome/browser/resources/settings/about_page/about_page.js +index 70e53fcf3166560520b31ecaa906120f44e3315a..6f31f72f1d0ffe8e8add29ebe1f0027bfc7be2dc 100644 +--- a/chrome/browser/resources/settings/about_page/about_page.js ++++ b/chrome/browser/resources/settings/about_page/about_page.js +@@ -271,7 +271,14 @@ Polymer({ + + /** @private */ + onRelaunchTap_: function() { ++ // ++ // Sparkle framework's relaunch api is used. ++ this.lifetimeBrowserProxy_.relaunchOnMac(); ++ // ++ ++ // + this.lifetimeBrowserProxy_.relaunch(); ++ // + }, + + /** @private */ diff --git a/patches/chrome-browser-resources-settings-lifetime_browser_proxy.js.patch b/patches/chrome-browser-resources-settings-lifetime_browser_proxy.js.patch new file mode 100644 index 000000000000..4ad57b3dd854 --- /dev/null +++ b/patches/chrome-browser-resources-settings-lifetime_browser_proxy.js.patch @@ -0,0 +1,32 @@ +diff --git a/chrome/browser/resources/settings/lifetime_browser_proxy.js b/chrome/browser/resources/settings/lifetime_browser_proxy.js +index 396539708ffed08cc0fc084fde54bba2496598fe..afa73c21c35d4ab6d54797b63a96eec993d93f73 100644 +--- a/chrome/browser/resources/settings/lifetime_browser_proxy.js ++++ b/chrome/browser/resources/settings/lifetime_browser_proxy.js +@@ -11,6 +11,13 @@ cr.define('settings', function() { + // Triggers a browser relaunch. + relaunch() {} + ++ // ++ // Use separate api for relaunch after update on Mac. ++ // Chromium's relaunch api isn't compatible with sparkle framework. ++ // So, sparkle framework's relaunch api is used on Mac. ++ relaunchOnMac() {} ++ // ++ + // + // First signs out current user and then performs a restart. + signOutAndRestart() {} +@@ -39,6 +46,13 @@ cr.define('settings', function() { + chrome.send('relaunch'); + } + ++ // ++ /** @override */ ++ relaunchOnMac() { ++ chrome.send('relaunchOnMac'); ++ } ++ // ++ + // + /** @override */ + signOutAndRestart() {