Skip to content

Commit

Permalink
only enable sparkle by default for official builds on mac (#2705)
Browse files Browse the repository at this point in the history
* only enable sparkle by default for official builds on mac
fix brave/brave-browser#4908
  • Loading branch information
bridiver authored Jun 19, 2019
1 parent 63bce68 commit b317f6e
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 104 deletions.
5 changes: 2 additions & 3 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,14 @@ if (is_mac) {
extra_configs = [ "//build/config/compiler:wexit_time_destructors" ]

deps = [
"//brave/vendor/sparkle:sparkle_resources_bundle_data",
"//chrome:chrome_app_strings_bundle_data",
"//chrome:chrome_resources",
"//chrome:chrome_versioned_bundle_data",
"//chrome/common:version_header",
]

if (is_chrome_branded) {
deps += [ "chrome:chrome_helpers" ]
if (enable_sparkle) {
deps += [ "//brave/vendor/sparkle:sparkle_resources_bundle_data" ]
}

if (enable_stripping) {
Expand Down
22 changes: 18 additions & 4 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import("//brave/build/config.gni")
import("//brave/browser/tor/buildflags/buildflags.gni")
import("//brave/components/brave_ads/browser/buildflags/buildflags.gni")
import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni")
import("//build/buildflag_header.gni")
import("//build/config/features.gni")
import("//extensions/buildflags/buildflags.gni")
import("//third_party/widevine/cdm/widevine.gni")
Expand Down Expand Up @@ -61,9 +62,6 @@ source_set("browser_process") {
"content_settings/brave_cookie_settings_factory.h",
"geolocation/brave_geolocation_permission_context.cc",
"geolocation/brave_geolocation_permission_context.h",
"mac/sparkle_glue.mm",
"mac/sparkle_glue.h",
"mac/su_updater.h",
"metrics/metrics_reporting_util.cc",
"metrics/metrics_reporting_util.h",
"search_engines/guest_window_search_engine_provider_service.cc",
Expand All @@ -82,7 +80,16 @@ source_set("browser_process") {
"update_util.h",
]

if (enable_sparkle) {
sources += [
"mac/sparkle_glue.mm",
"mac/sparkle_glue.h",
"mac/su_updater.h",
]
}

deps = [
":sparkle_buildflags",
":version_info",
"autoplay",
"download",
Expand Down Expand Up @@ -184,6 +191,13 @@ source_set("browser_process") {
}
}

buildflag_header("sparkle_buildflags") {
header = "sparkle_buildflags.h"
flags = [
"ENABLE_SPARKLE=$enable_sparkle",
]
}

source_set("version_info") {
# these are only for version_info.cc and should not be exposed as public configs
configs += [ "//brave/build:version" ]
Expand All @@ -208,7 +222,7 @@ source_set("browser") {
deps = [
"//chrome/browser",
]
if (is_mac) {
if (enable_sparkle) {
deps += [
"//brave/vendor/sparkle:sparkle_framework_bundle_data"
]
Expand Down
6 changes: 6 additions & 0 deletions browser/brave_browser_main_parts_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

#include "brave/browser/brave_browser_main_parts_mac.h"

#include "brave/browser/sparkle_buildflags.h"

#if BUILDFLAG(ENABLE_SPARKLE)
#import "brave/browser/mac/sparkle_glue.h"
#endif

void BraveBrowserMainPartsMac::PreMainMessageLoopStart() {
ChromeBrowserMainPartsMac::PreMainMessageLoopStart();

#if BUILDFLAG(ENABLE_SPARKLE)
// It would be no-op if udpate is disabled.
[[SparkleGlue sharedSparkleGlue] registerWithSparkle];
#endif
}
39 changes: 5 additions & 34 deletions browser/mac/sparkle_glue.h
Original file line number Diff line number Diff line change
@@ -1,48 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* Copyright 2019 The Brave Authors. All rights reserved.
* 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_MAC_SPARKLE_GLUE_H_
#define BRAVE_BROWSER_MAC_SPARKLE_GLUE_H_

#include "base/strings/string16.h"
#import "chrome/browser/mac/keystone_glue.h"

#if defined(__OBJC__)

#import <Foundation/Foundation.h>

// Possible outcomes of various operations. A version may accompany some of
// these, but beware: a version is never required. For statuses that can be
// accompanied by a version, the comment indicates what version is referenced.
// A notification posted containing an asynchronous status will always be
// followed by a notification with a terminal status.
enum AutoupdateStatus {
kAutoupdateNone = 0, // no version (initial state only)
kAutoupdateRegistering, // no version (asynchronous operation in progress)
kAutoupdateRegistered, // no version
kAutoupdateChecking, // no version (asynchronous operation in progress)
kAutoupdateCurrent, // version of the running application
kAutoupdateAvailable, // version of the update that is available
kAutoupdateInstalling, // no version (asynchronous operation in progress)
kAutoupdateInstalled, // version of the update that was installed
kAutoupdateRegisterFailed, // no version
kAutoupdateCheckFailed, // no version
kAutoupdateInstallFailed, // no version
};

// kBraveAutoupdateStatusNotification is the name of the notification posted
// when -checkForUpdate and -installUpdate complete. This notification will be
// sent with with its sender object set to the SparkleGlue instance sending
// the notification. Its userInfo dictionary will contain an AutoupdateStatus
// value as an intValue at key kBraveAutoupdateStatusStatus. If a version is
// available (see AutoupdateStatus), it will be present at key
// kBraveAutoupdateStatusVersion. If any error messages were supplied by
// Sparkle, they will be present at key kBraveAutoupdateStatusErrorMessages.
extern NSString* const kBraveAutoupdateStatusNotification;
extern NSString* const kBraveAutoupdateStatusStatus;
extern NSString* const kBraveAutoupdateStatusVersion;
extern NSString* const kBraveAutoupdateStatusErrorMessages;

@interface SparkleGlue : NSObject

+ (instancetype)sharedSparkleGlue;
Expand All @@ -56,7 +26,8 @@ extern NSString* const kBraveAutoupdateStatusErrorMessages;
- (void)relaunch;

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

- (NSNotification*)recentNotification; // NOLINT - not sure how to fix this

// Returns YES if an asynchronous operation is pending: if an update check or
// installation attempt is currently in progress.
Expand Down
17 changes: 6 additions & 11 deletions browser/mac/sparkle_glue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ void Run() {

} // namespace

NSString* const kBraveAutoupdateStatusNotification = @"AutoupdateStatusNotification";
NSString* const kBraveAutoupdateStatusStatus = @"status";
NSString* const kBraveAutoupdateStatusVersion = @"version";
NSString* const kBraveAutoupdateStatusErrorMessages = @"errormessages";

@implementation SparkleGlue
{
SUUpdater* su_updater_;
Expand All @@ -98,7 +93,7 @@ @implementation SparkleGlue
NSString* new_version_;

std::string channel_;
// The most recent kBraveAutoupdateStatusNotification notification posted.
// The most recent kAutoupdateStatusNotification notification posted.
base::scoped_nsobject<NSNotification> recentNotification_;
}

Expand Down Expand Up @@ -241,16 +236,16 @@ - (void)updateStatus:(AutoupdateStatus)status
NSNumber* statusNumber = [NSNumber numberWithInt:status];
NSMutableDictionary* dictionary =
[NSMutableDictionary dictionaryWithObject:statusNumber
forKey:kBraveAutoupdateStatusStatus];
forKey:kAutoupdateStatusStatus];
if ([version length]) {
[dictionary setObject:version forKey:kBraveAutoupdateStatusVersion];
[dictionary setObject:version forKey:kAutoupdateStatusVersion];
}
if ([error length]) {
[dictionary setObject:error forKey:kBraveAutoupdateStatusErrorMessages];
[dictionary setObject:error forKey:kAutoupdateStatusErrorMessages];
}

NSNotification* notification =
[NSNotification notificationWithName:kBraveAutoupdateStatusNotification
[NSNotification notificationWithName:kAutoupdateStatusNotification
object:self
userInfo:dictionary];
recentNotification_.reset([notification retain]);
Expand Down Expand Up @@ -301,7 +296,7 @@ - (NSDictionary*)infoDictionary {
- (AutoupdateStatus)recentStatus {
NSDictionary* dictionary = [recentNotification_ userInfo];
NSNumber* status = base::mac::ObjCCastStrict<NSNumber>(
[dictionary objectForKey:kBraveAutoupdateStatusStatus]);
[dictionary objectForKey:kAutoupdateStatusStatus]);
return static_cast<AutoupdateStatus>([status intValue]);
}

Expand Down
19 changes: 15 additions & 4 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ source_set("ui") {
"webui/navigation_bar_data_provider.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",
]

if (enable_sparkle) {
sources += [
"webui/settings/brave_relaunch_handler_mac.mm",
"webui/settings/brave_relaunch_handler_mac.h",
]
}
}

if (toolkit_views) {
Expand All @@ -71,9 +76,14 @@ source_set("ui") {
"views/rounded_separator.h",
"views/toolbar/bookmark_button.cc",
"views/toolbar/bookmark_button.h",
"views/update_recommended_message_box_mac.mm",
"views/update_recommended_message_box_mac.h",
]

if (enable_sparkle) {
sources += [
"views/update_recommended_message_box_mac.mm",
"views/update_recommended_message_box_mac.h",
]
}
}

if (is_win || is_mac || is_desktop_linux) {
Expand Down Expand Up @@ -118,6 +128,7 @@ source_set("ui") {
"//brave/components/brave_sync:static_resources",
"//brave/components/brave_sync:generated_resources",
"//brave/components/brave_welcome_ui:generated_resources",
"//brave/browser:sparkle_buildflags",
"//brave/browser/devtools",
"//brave/browser/tor",
"//brave/browser/resources/settings:resources",
Expand Down
11 changes: 7 additions & 4 deletions browser/ui/views/frame/brave_browser_view.cc
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* Copyright 2019 The Brave Authors. All rights reserved.
* 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/views/frame/brave_browser_view.h"

#include "brave/browser/sparkle_buildflags.h"
#include "brave/browser/ui/views/toolbar/bookmark_button.h"
#include "brave/browser/ui/views/toolbar/brave_toolbar_view.h"

#if defined(OS_MACOSX)
#if BUILDFLAG(ENABLE_SPARKLE)
#include "brave/browser/ui/views/update_recommended_message_box_mac.h"
#endif

void BraveBrowserView::SetStarredState(bool is_starred) {
BookmarkButton* button = ((BraveToolbarView *)toolbar())->bookmark_button();
BookmarkButton* button =
static_cast<BraveToolbarView*>(toolbar())->bookmark_button();
if (button)
button->SetToggled(is_starred);
}

void BraveBrowserView::ShowUpdateChromeDialog() {
#if defined(OS_MACOSX)
#if BUILDFLAG(ENABLE_SPARKLE)
// On mac, sparkle frameworks's relaunch api is used.
UpdateRecommendedMessageBoxMac::Show(GetNativeWindow());
#else
Expand Down
6 changes: 4 additions & 2 deletions browser/ui/webui/brave_settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#include "brave/browser/ui/webui/brave_settings_ui.h"

#include <string>

#include "base/command_line.h"
#include "brave/browser/extensions/brave_component_loader.h"
#include "brave/browser/resources/settings/grit/brave_settings_resources.h"
#include "brave/browser/resources/settings/grit/brave_settings_resources_map.h"
#include "brave/browser/sparkle_buildflags.h"
#include "brave/browser/ui/webui/settings/brave_default_extensions_handler.h"
#include "brave/browser/ui/webui/settings/brave_privacy_handler.h"
#include "brave/browser/ui/webui/settings/default_brave_shields_handler.h"
Expand All @@ -20,7 +22,7 @@
#include "chrome/browser/ui/webui/settings/metrics_reporting_handler.h"
#include "content/public/browser/web_ui_data_source.h"

#if defined(OS_MACOSX)
#if BUILDFLAG(ENABLE_SPARKLE)
#include "brave/browser/ui/webui/settings/brave_relaunch_handler_mac.h"
#endif

Expand All @@ -32,7 +34,7 @@ BraveSettingsUI::BraveSettingsUI(content::WebUI* web_ui,
web_ui->AddMessageHandler(std::make_unique<BravePrivacyHandler>());
web_ui->AddMessageHandler(std::make_unique<DefaultBraveShieldsHandler>());
web_ui->AddMessageHandler(std::make_unique<BraveDefaultExtensionsHandler>());
#if defined(OS_MACOSX)
#if BUILDFLAG(ENABLE_SPARKLE)
// Use sparkle's relaunch api for browser relaunch on update.
web_ui->AddMessageHandler(std::make_unique<BraveRelaunchHandler>());
#endif
Expand Down
1 change: 1 addition & 0 deletions build/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare_args() {
brave_channel = ""
is_release_channel = true
base_sparkle_update_url = ""
enable_sparkle = is_official_build && is_mac

brave_dsa_file = "dsa_pub.pem"

Expand Down
31 changes: 31 additions & 0 deletions chromium_src/chrome/browser/mac/keystone_glue.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "brave/browser/sparkle_buildflags.h"

#if BUILDFLAG(ENABLE_SPARKLE)
#include "brave/browser/mac/sparkle_glue.h"
#endif

#define KeystoneEnabled KeystoneEnabled_ChromiumImpl
#define CurrentlyInstalledVersion CurrentlyInstalledVersion_ChromiumImpl
#include "../../../../../chrome/browser/mac/keystone_glue.mm" // NOLINT
#undef KeystoneEnabled
#undef CurrentlyInstalledVersion

namespace keystone_glue {

bool KeystoneEnabled() {
#if BUILDFLAG(ENABLE_SPARKLE)
return sparkle_glue::SparkleEnabled();
#else
return false;
#endif
}

base::string16 CurrentlyInstalledVersion() {
#if BUILDFLAG(ENABLE_SPARKLE)
return sparkle_glue::CurrentlyInstalledVersion();
#else
return base::string16();
#endif
}

} // namespace keystone_glue
Loading

0 comments on commit b317f6e

Please sign in to comment.