Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparkle framework integration #91

Merged
merged 23 commits into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2bdc598
Initial Sparkle integration
simonhong Apr 12, 2018
35f8ade
Fix Sparkle library not found error w/o component build
simonhong Apr 13, 2018
d66e89b
Introduce BraveAppController
simonhong Apr 13, 2018
10a64a5
Add --enable-brave-update-test switch for update test
simonhong Apr 16, 2018
e596b4f
Set sparkle update url to Info.plist
simonhong Apr 16, 2018
9e61c71
Implement SUUpdaterDelegate protocol in BraveAppController
simonhong Apr 16, 2018
1d4263f
Add Update Brave item to main menu for update test
simonhong Apr 16, 2018
0a544d6
Cleanup - Make log more descriptive
simonhong Apr 17, 2018
cf04f01
Bundle pub key for DSA signatures and add sparkle to DEPS
simonhong Apr 17, 2018
d5fea0d
Make sparkle build from its source
simonhong Apr 18, 2018
d3c9a1b
Define public dsa file name to brave_init_settings.gni
simonhong Apr 18, 2018
781933e
Update sparkle repo revision
simonhong Apr 18, 2018
0d3241a
Cleanup gn configuration related with Sparkle framework integration
simonhong Apr 20, 2018
3b0ea2c
Second tweaking Info.plist is introduced
simonhong Apr 20, 2018
33a33bf
Move chrome_app and chrome_app_plist target from //chrome to //brave
simonhong Apr 24, 2018
71feac1
Propagate sparkle dependency to test targets
simonhong Apr 24, 2018
4fb017d
Use //chrome:chrome_app_plist instead of copying it to //brave
simonhong Apr 25, 2018
906d332
Use unified sparkle config and add some comment about sparkle
simonhong Apr 25, 2018
607ca79
Use sparkle by using NSBundle
simonhong Apr 26, 2018
27dfdaa
Rebase on Chromium 66
simonhong May 3, 2018
5fcce88
Explicitly disable sparkle system profiling
simonhong May 3, 2018
b843ef7
Add comment to |brave_feed_url| and |kEnableBraveUpdateTest| switch
simonhong May 14, 2018
326026a
Use Sparkle framework of brave repo
simonhong May 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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