Skip to content

Commit

Permalink
fix merge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
blueboxd committed Jul 22, 2023
1 parent 6fc8028 commit 1220d7a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 39 deletions.
12 changes: 9 additions & 3 deletions base/threading/platform_thread_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ void SetCurrentThreadTypeImpl(ThreadType thread_type,
break;
case ThreadType::kUtility:
priority = ThreadPriorityForTest::kUtility;
pthread_set_qos_class_self_np(QOS_CLASS_UTILITY, 0);
if (pthread_set_qos_class_self_np_FuncPtr) {
pthread_set_qos_class_self_np_FuncPtr(QOS_CLASS_UTILITY, 0);
}
break;
case ThreadType::kResourceEfficient:
if (pthread_set_qos_class_self_np_FuncPtr) {
Expand All @@ -347,10 +349,14 @@ void SetCurrentThreadTypeImpl(ThreadType thread_type,
case ThreadType::kCompositing:
if (g_user_interactive_compositing.load(std::memory_order_relaxed)) {
priority = ThreadPriorityForTest::kDisplay;
pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0);
if (pthread_set_qos_class_self_np_FuncPtr){
pthread_set_qos_class_self_np_FuncPtr(QOS_CLASS_USER_INTERACTIVE, 0);
}
} else {
priority = ThreadPriorityForTest::kNormal;
pthread_set_qos_class_self_np(QOS_CLASS_USER_INITIATED, 0);
if (pthread_set_qos_class_self_np_FuncPtr){
pthread_set_qos_class_self_np_FuncPtr(QOS_CLASS_USER_INITIATED, 0);
}
}
break;
case ThreadType::kDisplayCritical: {
Expand Down
87 changes: 51 additions & 36 deletions chrome/browser/app_controller_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/memory/raw_ptr.h"

#import "chrome/browser/app_controller_mac.h"

#include <dispatch/dispatch.h>
Expand All @@ -15,15 +17,13 @@
#include "base/allocator/partition_allocator/shim/allocator_shim.h"
#include "base/allocator/buildflags.h"
#include "base/auto_reset.h"
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/debug/dump_without_crashing.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/mac/foundation_util.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_objc_class_swizzler.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/run_loop.h"
#include "base/scoped_multi_source_observation.h"
Expand Down Expand Up @@ -597,18 +597,6 @@ @implementation AppController

@synthesize startupComplete = _startupComplete;

+ (AppController*)sharedController {
static AppController* sharedController = []() -> AppController* {
AppController* sharedController = [[AppController alloc] init];
NSApp.delegate = sharedController;
return sharedController;
}();

CHECK_NE(nil, sharedController);
CHECK_EQ(NSApp.delegate, sharedController);
return sharedController;
}

- (instancetype)init {
if (self = [super init]) {
// -[NSMenu cr_menuItemForKeyEquivalentEvent:] lives in /content, but
Expand All @@ -617,15 +605,18 @@ - (instancetype)init {
[NSMenu cr_setMenuItemForKeyEquivalentEventPreSearchBlock:^{
// We avoid calling -[NSMenuDelegate menuNeedsUpdate:] on each submenu's
// delegate as that can be slow. Instead, we update the relevant
// NSMenuItems.
[AppController.sharedController updateMenuItemKeyEquivalents];
// NSMenuItems if [NSApp delegate] is an instance of AppController. See
// https://crbug.com/851260#c4 .
[base::mac::ObjCCast<AppController>([NSApp delegate])
updateMenuItemKeyEquivalents];
}];
}
return self;
}

- (void)dealloc {
NOTREACHED();
[[_closeTabMenuItem menu] setDelegate:nil];
[NSMenu cr_setMenuItemForKeyEquivalentEventPreSearchBlock:nil];
[super dealloc];
}

Expand Down Expand Up @@ -997,7 +988,7 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notify {
_quitWithAppsController = new QuitWithAppsController();

// Dynamically update shortcuts for "Close Window" and "Close Tab" menu items.
_closeTabMenuItem.menu.delegate = self;
[[_closeTabMenuItem menu] setDelegate:self];

// Instantiate the ProfileAttributesStorage observer so that we can get
// notified when a profile is deleted.
Expand Down Expand Up @@ -1120,14 +1111,14 @@ - (BOOL)shouldQuitWithInProgressDownloads {

for (size_t i = 0; i < profiles.size(); ++i) {
DownloadCoreService* download_core_service =
DownloadCoreServiceFactory::GetForBrowserContext(profiles[i]);
// `DownloadCoreService` can be nullptr for some irregular profiles, e.g.
// the System Profile.
content::DownloadManager* download_manager =
download_core_service &&
download_core_service->HasCreatedDownloadManager()
? profiles[i]->GetDownloadManager()
: nullptr;
DownloadCoreServiceFactory::GetForBrowserContext(profiles[i]);
// `DownloadCoreService` can be nullptr for some irregular profiles, e.g.
// the System Profile.
content::DownloadManager* download_manager =
download_core_service &&
download_core_service->HasCreatedDownloadManager()
? profiles[i]->GetDownloadManager()
: nullptr;
if (download_manager && download_manager->BlockingShutdownCount() > 0) {
int downloadCount = download_manager->BlockingShutdownCount();
if ([self userWillWaitForInProgressDownloads:downloadCount]) {
Expand Down Expand Up @@ -1982,6 +1973,14 @@ - (void)updateMenuItemKeyEquivalents {
[self adjustCloseTabMenuItemKeyEquivalent:enableCloseTabShortcut];
}

// This only has an effect on macOS 12+, and requests any state restoration
// archive to be created with secure encoding. See the article at
// https://sector7.computest.nl/post/2022-08-process-injection-breaking-all-macos-security-layers-with-a-single-vulnerability/
// for more details.
- (BOOL)applicationSupportsSecureRestorableState:(NSApplication*)app {
return YES;
}

- (BOOL)application:(NSApplication*)application
willContinueUserActivityWithType:(NSString*)userActivityType {
static NSString * const*NSUserActivityTypeBrowsingWebStr = reinterpret_cast<NSString**>(dlsym(((void *) -2), "NSUserActivityTypeBrowsingWeb"));
Expand Down Expand Up @@ -2142,10 +2141,11 @@ - (void)setLastProfileForTesting:(Profile*)profile {
namespace {

void UpdateProfileInUse(Profile* profile) {
if (!profile) {
if (!profile)
return;
}
[AppController.sharedController setLastProfile:profile];
AppController* controller =
base::mac::ObjCCastStrict<AppController>([NSApp delegate]);
[controller setLastProfile:profile];
}

void OpenUrlsInBrowserWithProfile(const std::vector<GURL>& urls,
Expand Down Expand Up @@ -2190,9 +2190,14 @@ void OpenUrlsInBrowserWithProfile(const std::vector<GURL>& urls,

// Returns the profile to be used for new windows (or nullptr if it fails).
Profile* GetSafeProfile(Profile* loaded_profile) {
if (!loaded_profile)
return nullptr;
AppController* controller =
base::mac::ObjCCastStrict<AppController>([NSApp delegate]);
if (!controller)
return nullptr;
DCHECK(loaded_profile);
return
[AppController.sharedController safeProfileForNewWindows:loaded_profile];
return [controller safeProfileForNewWindows:loaded_profile];
}

// Called when the profile has been loaded for RunIn*ProfileSafely(). This
Expand Down Expand Up @@ -2230,16 +2235,26 @@ void CreateGuestProfileIfNeeded() {
}

void EnterpriseStartupDialogClosed() {
NSNotification* notify = [NSNotification
notificationWithName:NSApplicationDidFinishLaunchingNotification
object:NSApp];
[AppController.sharedController applicationDidFinishLaunching:notify];
AppController* controller =
base::mac::ObjCCastStrict<AppController>([NSApp delegate]);
if (controller != nil) {
NSNotification* notify = [NSNotification
notificationWithName:NSApplicationDidFinishLaunchingNotification
object:NSApp];
[controller applicationDidFinishLaunching:notify];
}
}

void RunInLastProfileSafely(base::OnceCallback<void(Profile*)> callback,
ProfileLoadFailureBehavior on_failure) {
DCHECK(callback);
if (Profile* profile = [AppController.sharedController lastProfileIfLoaded]) {
AppController* controller =
base::mac::ObjCCastStrict<AppController>([NSApp delegate]);
if (!controller) {
OnProfileLoaded(std::move(callback), on_failure, nullptr);
return;
}
if (Profile* profile = [controller lastProfileIfLoaded]) {
OnProfileLoaded(std::move(callback), on_failure, profile);
return;
}
Expand Down

0 comments on commit 1220d7a

Please sign in to comment.