Skip to content

Commit

Permalink
Merge pull request #91 from brave/sparkle_integration
Browse files Browse the repository at this point in the history
Sparkle framework integration
  • Loading branch information
simonhong authored May 17, 2018
2 parents 1761117 + 326026a commit cd07fba
Show file tree
Hide file tree
Showing 18 changed files with 549 additions and 56 deletions.
61 changes: 61 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import("//third_party/icu/config.gni")
import("//build/config/locales.gni")
import("//media/cdm/library_cdm/cdm_paths.gni")

if (is_mac) {
import("//build/config/mac/rules.gni")
import("//brave/build/mac/tweak_info_plist.gni")
}

group("child_dependencies") {
public_deps = [
"//brave/renderer",
Expand Down Expand Up @@ -351,3 +356,59 @@ action("create_dist_zips") {
"--output=$rebase_output",
]
}

if (is_mac) {
brave_tweak_info_plist("brave_app_plist") {
info_plist = "$root_gen_dir/chrome/chrome_app_plist_tweaked.plist"

args = [
"--brave_channel=" + brave_channel,
"--brave_feed_url=" + brave_feed_url,
"--brave_dsa_file=" + brave_dsa_file,
]

deps = [
"//chrome:chrome_app_plist",
]
}

mac_app_bundle("chrome_app") {
output_name = chrome_product_full_name

info_plist_target = ":brave_app_plist"

extra_substitutions = [
"CHROMIUM_BUNDLE_ID=$chrome_mac_bundle_id",
"CHROMIUM_SHORT_NAME=$chrome_product_short_name",
"CHROMIUM_CREATOR=$chrome_mac_creator_code",
]

sources = [
"//chrome/app/chrome_exe_main_mac.cc",
]

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",
"//build/config:exe_and_shlib_deps",
"//chrome/common:version_header",
]

if (is_chrome_branded) {
deps += [ "chrome:chrome_helpers" ]
}

# Remove the default strip configuration (which strips all symbols) so that
# a saves file can be specified.
if (enable_stripping) {
remove_configs = [ "//build/config/mac:strip_all" ]

ldflags =
[ "-Wcrl,strip,-s," + rebase_path("//chrome/app/app.saves", root_build_dir) ]
}
}
}
1 change: 1 addition & 0 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ deps = {
"vendor/requests": "https://github.com/kennethreitz/requests@e4d59bedfd3c7f4f254f4f5d036587bcd8152458",
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
}

hooks = [
Expand Down
2 changes: 1 addition & 1 deletion app/mac/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ action("generate_breakpad_symbols") {
]

deps = [
"//chrome:chrome_app",
"//brave:chrome_app",
"//chrome:chrome_framework",
"//chrome:chrome_helper_app",
"//chrome:chrome_dump_syms",
Expand Down
7 changes: 7 additions & 0 deletions brave_init_settings.gni
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ declare_args() {
# "canary" for canary channel release.
# "" for stable channel release.
brave_channel = ""

# Update feed url on MacOS
# TODO(simonhong): This url is stub. Replace with real update server or your
# test server.
brave_feed_url = "http://localhost:9090"

brave_dsa_file = "dsa_pub.pem"
}
10 changes: 10 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ source_set("browser_process") {
"importer/brave_profile_writer.h",
"importer/chrome_profile_lock.cc",
"importer/chrome_profile_lock.h",
"brave_app_controller_mac.mm",
"brave_app_controller_mac.h",
"sparkle_glue_mac.mm",
"sparkle_glue_mac.h",
]

deps = [
Expand Down Expand Up @@ -53,4 +57,10 @@ source_set("browser") {
"net",
"ui",
]

if (is_mac) {
deps += [
"//brave/vendor/sparkle:sparkle_framework_bundle_data"
]
}
}
18 changes: 18 additions & 0 deletions browser/brave_app_controller_mac.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* 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_BRAVE_APP_CONTROLLER_MAC_H_
#define BRAVE_BROWSER_BRAVE_APP_CONTROLLER_MAC_H_

#if defined(__OBJC__)

#import "chrome/browser/app_controller_mac.h"

@interface BraveAppController : AppController

@end

#endif // __OBJC__

#endif // BRAVE_BROWSER_BRAVE_APP_CONTROLLER_MAC_H_
124 changes: 124 additions & 0 deletions browser/brave_app_controller_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/* 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/. */

#import "brave/browser/brave_app_controller_mac.h"

#include <string>

#import "brave/browser/sparkle_glue_mac.h"
#include "base/command_line.h"
#include "base/strings/sys_string_conversions.h"
#include "brave/common/brave_switches.h"

namespace {

BOOL UpdateEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableBraveUpdateTest);
}

std::string GetDescriptionFromAppcastItem(id item) {
return [SparkleGlue descriptionFromAppcastItem:item];
}

}

@implementation BraveAppController
{
SparkleGlue* sparkle_glue_;
}

- (void)applicationWillFinishLaunching:(NSNotification*)notification {
[super applicationWillFinishLaunching:notification];

if (!UpdateEnabled())
return;

[self initializeBraveUpdater];
}

- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
if ([super validateUserInterfaceItem:item])
return YES;

return [item action] == @selector(updateBrave:) ? UpdateEnabled() : NO;
}

- (IBAction)updateBrave:(id)sender {
DCHECK(UpdateEnabled());

[sparkle_glue_ checkForUpdates:sender];
}

- (void)initializeBraveUpdater {
DCHECK(UpdateEnabled());

sparkle_glue_ = [SparkleGlue sharedSparkleGlue];
[sparkle_glue_ setDelegate:self];
}

#pragma mark - SUUpdaterDelegate

- (void)updater:(id)updater didFinishLoadingAppcast:(id)appcast {
VLOG(0) << "brave update: did finish loading appcast";
}

- (void)updater:(id)updater didFindValidUpdate:(id)item {
VLOG(0) << "brave update: did finish valid update with " +
GetDescriptionFromAppcastItem(item);
}

- (void)updaterDidNotFindUpdate:(id)updater {
VLOG(0) << "brave update: did not find update";
}

- (void)updater:(id)updater
willDownloadUpdate:(id)item
withRequest:(NSMutableURLRequest *)request {
VLOG(0) << "brave update: willDownloadUpdate with " +
GetDescriptionFromAppcastItem(item);
}

- (void)updater:(id)updater
failedToDownloadUpdate:(id)item
error:(NSError *)error {
VLOG(0) << "brave update: failed to download update with " +
GetDescriptionFromAppcastItem(item) +
" with error - " + [[error description] UTF8String];
}

- (void)userDidCancelDownload:(id)updater {
VLOG(0) << "brave update: user did cancel download";
}

- (void)updater:(id)updater willInstallUpdate:(id)item {
VLOG(0) << "brave update: will install update with " +
GetDescriptionFromAppcastItem(item);
}

- (void)updaterWillRelaunchApplication:(id)updater {
VLOG(0) << "brave update: will relaunch application";
}

- (void)updaterDidRelaunchApplication:(id)updater {
VLOG(0) << "brave update: did relaunch application";
}

- (void)updater:(id)updater
willInstallUpdateOnQuit:(id)item
immediateInstallationInvocation:(NSInvocation *)invocation {
VLOG(0) << "brave update: will install update on quit with " +
GetDescriptionFromAppcastItem(item);
}

- (void)updater:(id)updater didCancelInstallUpdateOnQuit:(id)item {
VLOG(0) << "brave update: did cancel install update on quit with " +
GetDescriptionFromAppcastItem(item);
}

- (void)updater:(id)updater didAbortWithError:(NSError *)error {
VLOG(0) << [[error description] UTF8String];
}

@end // @implementation BraveAppController
29 changes: 29 additions & 0 deletions browser/sparkle_glue_mac.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* 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_SPARKLE_GLUE_MAC_H_
#define BRAVE_BROWSER_SPARKLE_GLUE_MAC_H_

#include <string>

#if defined(__OBJC__)

#import <Foundation/Foundation.h>

@interface SparkleGlue : NSObject

+ (instancetype)sharedSparkleGlue;

+ (std::string)descriptionFromAppcastItem:(id)item;

- (instancetype)init;

- (void)setDelegate:(id)delegate;
- (void)checkForUpdates:(id)sender;

@end // @interface SparkleGlue

#endif // __OBJC__

#endif // BRAVE_BROWSER_SPARKLE_GLUE_MAC_H_
62 changes: 62 additions & 0 deletions browser/sparkle_glue_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* 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/. */

#import "brave/browser/sparkle_glue_mac.h"

#include "base/mac/bundle_locations.h"

namespace {

id GetSUUpdater() {
NSString* sparkle_path =
[[base::mac::FrameworkBundle() privateFrameworksPath]
stringByAppendingPathComponent:@"Sparkle.framework"];

NSBundle* sparkle_bundle = [NSBundle bundleWithPath:sparkle_path];
[sparkle_bundle load];

Class sparkle_class = [sparkle_bundle classNamed:@"SUUpdater"];
return [sparkle_class performSelector:NSSelectorFromString(@"sharedUpdater")];
}

}

@implementation SparkleGlue
{
id su_updater_;
}

+ (instancetype)sharedSparkleGlue {
static SparkleGlue* shared;
if (shared == nil)
shared = [[SparkleGlue alloc] init];
return shared;
}

+ (std::string)descriptionFromAppcastItem:(id)item {
NSString* description =
[NSString stringWithFormat:@"AppcastItem(Date: %@, Version: %@)",
[item performSelector:NSSelectorFromString(@"dateString")],
[item performSelector:NSSelectorFromString(@"versionString")]];
return [description UTF8String];
}

- (instancetype)init {
if (self = [super init]) {
su_updater_ = GetSUUpdater();
return self;
} else {
return nil;
}
}

- (void)setDelegate:(id)delegate {
[su_updater_ setDelegate:delegate];
}

- (void)checkForUpdates:(id)sender {
[su_updater_ checkForUpdates:sender];
}

@end
Loading

0 comments on commit cd07fba

Please sign in to comment.