Skip to content

Commit

Permalink
Merge pull request #1041 from brave/fix_relaunch_fail_after_update_on…
Browse files Browse the repository at this point in the history
…_mac

Fix relaunch fail after update on mac
  • Loading branch information
simonhong committed Dec 7, 2018
2 parents 838117f + 88e4277 commit 383fb12
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 0 deletions.
2 changes: 2 additions & 0 deletions browser/mac/sparkle_glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ extern NSString* const kBraveAutoupdateStatusErrorMessages;

- (void)checkForUpdates;

- (void)relaunch;

- (AutoupdateStatus)recentStatus;
- (NSNotification*)recentNotification;

Expand Down
12 changes: 12 additions & 0 deletions browser/mac/sparkle_glue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ - (BOOL)loadSparkleFramework {
if ([self isOnReadOnlyFilesystem])
return NO;

DCHECK(!su_updater_);

NSString* sparkle_path =
[[base::mac::FrameworkBundle() privateFrameworksPath]
stringByAppendingPathComponent:@"Sparkle.framework"];
Expand All @@ -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_);

Expand Down Expand Up @@ -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];
Expand Down
9 changes: 9 additions & 0 deletions browser/mac/su_updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@

#import <Foundation/Foundation.h>

@interface SUUpdateDriver;

- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface
:(BOOL)showUI;

@end

@interface SUUpdater : NSObject

@property (strong) SUUpdateDriver *driver;

+ (SUUpdater *)sharedUpdater;

- (void)checkForUpdates:(id)sender;
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions browser/ui/webui/brave_md_settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<settings::MetricsReportingHandler>());
web_ui->AddMessageHandler(std::make_unique<BravePrivacyHandler>());
web_ui->AddMessageHandler(std::make_unique<DefaultBraveShieldsHandler>());

#if defined(OS_MACOSX)
// Use sparkle's relaunch api for browser relaunch on update.
web_ui->AddMessageHandler(std::make_unique<BraveRelaunchHandler>());
#endif
}

BraveMdSettingsUI::~BraveMdSettingsUI() {
Expand Down
28 changes: 28 additions & 0 deletions browser/ui/webui/settings/brave_relaunch_handler_mac.h
Original file line number Diff line number Diff line change
@@ -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_
19 changes: 19 additions & 0 deletions browser/ui/webui/settings/brave_relaunch_handler_mac.mm
Original file line number Diff line number Diff line change
@@ -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];
}
Original file line number Diff line number Diff line change
@@ -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() {
+ // <if expr="is_macosx">
+ // Sparkle framework's relaunch api is used.
+ this.lifetimeBrowserProxy_.relaunchOnMac();
+ // </if>
+
+ // <if expr="not is_macosx">
this.lifetimeBrowserProxy_.relaunch();
+ // </if>
},

/** @private */
Original file line number Diff line number Diff line change
@@ -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() {}

+ // <if expr="is_macosx">
+ // 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() {}
+ // </if>
+
// <if expr="chromeos">
// First signs out current user and then performs a restart.
signOutAndRestart() {}
@@ -39,6 +46,13 @@ cr.define('settings', function() {
chrome.send('relaunch');
}

+ // <if expr="is_macosx">
+ /** @override */
+ relaunchOnMac() {
+ chrome.send('relaunchOnMac');
+ }
+ // </if>
+
// <if expr="chromeos">
/** @override */
signOutAndRestart() {

0 comments on commit 383fb12

Please sign in to comment.