handle app notifications
This commit is contained in:
@@ -41,5 +41,6 @@ source_set("app") {
|
||||
|
||||
frameworks = [
|
||||
"Foundation.framework",
|
||||
"UIKit.framework",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ OBJC_EXPORT
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
- (instancetype)initWithSyncServiceURL:(NSString *)syncServiceURL;
|
||||
- (instancetype)initWithSyncServiceURL:(NSString*)syncServiceURL;
|
||||
|
||||
- (void)scheduleLowPriorityStartupTasks;
|
||||
|
||||
- (void)setUserAgent:(NSString *)userAgent;
|
||||
- (void)setUserAgent:(NSString*)userAgent;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
|
||||
#import "brave/ios/app/brave_core_main.h"
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "brave/ios/app/brave_main_delegate.h"
|
||||
#import "brave/ios/browser/brave_web_client.h"
|
||||
#include "ios/chrome/app/startup/provider_registration.h"
|
||||
#import "ios/chrome/app/startup_tasks.h"
|
||||
#include "ios/chrome/browser/application_context.h"
|
||||
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
|
||||
#include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h"
|
||||
#include "ios/chrome/app/startup/provider_registration.h"
|
||||
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
|
||||
#include "ios/web/public/init/web_main.h"
|
||||
|
||||
@interface BraveCoreMain()
|
||||
{
|
||||
@interface BraveCoreMain () {
|
||||
std::unique_ptr<BraveWebClient> _webClient;
|
||||
std::unique_ptr<BraveMainDelegate> _delegate;
|
||||
std::unique_ptr<web::WebMain> _webMain;
|
||||
@@ -31,8 +32,27 @@
|
||||
return [self initWithSyncServiceURL:@""];
|
||||
}
|
||||
|
||||
- (instancetype)initWithSyncServiceURL:(NSString *)syncServiceURL {
|
||||
- (instancetype)initWithSyncServiceURL:(NSString*)syncServiceURL {
|
||||
if ((self = [super init])) {
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(onAppEnterBackground:)
|
||||
name:UIApplicationDidEnterBackgroundNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(onAppEnterForeground:)
|
||||
name:UIApplicationWillEnterForegroundNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(onAppWillTerminate:)
|
||||
name:UIApplicationWillTerminateNotification
|
||||
object:nil];
|
||||
|
||||
|
||||
|
||||
|
||||
// Register all providers before calling any Chromium code.
|
||||
[ProviderRegistration registerProviders];
|
||||
|
||||
@@ -43,7 +63,6 @@
|
||||
_delegate->SetSyncServiceURL(base::SysNSStringToUTF8(syncServiceURL));
|
||||
|
||||
web::WebMainParams params(_delegate.get());
|
||||
|
||||
_webMain = std::make_unique<web::WebMain>(std::move(params));
|
||||
|
||||
ios::GetChromeBrowserProvider()->Initialize();
|
||||
@@ -57,19 +76,35 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)onAppEnterBackground:(NSNotification*)notification {
|
||||
auto* context = GetApplicationContext();
|
||||
if (context)
|
||||
context->OnAppEnterBackground();
|
||||
}
|
||||
|
||||
- (void)onAppEnterForeground:(NSNotification*)notification {
|
||||
auto* context = GetApplicationContext();
|
||||
if (context)
|
||||
context->OnAppEnterForeground();
|
||||
}
|
||||
|
||||
- (void)onAppWillTerminate:(NSNotification*)notification {
|
||||
_webMain.reset();
|
||||
}
|
||||
|
||||
- (void)scheduleLowPriorityStartupTasks {
|
||||
[StartupTasks
|
||||
scheduleDeferredBrowserStateInitialization:_mainBrowserState];
|
||||
[StartupTasks scheduleDeferredBrowserStateInitialization:_mainBrowserState];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
_mainBrowserState = nullptr;
|
||||
_webMain.reset();
|
||||
_delegate.reset();
|
||||
_webClient.reset();
|
||||
}
|
||||
|
||||
- (void)setUserAgent:(NSString *)userAgent {
|
||||
- (void)setUserAgent:(NSString*)userAgent {
|
||||
_webClient->SetUserAgent(base::SysNSStringToUTF8(userAgent));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user