Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
refactor: prevent RemoveFromLoginItems() from mounting volumes from l…
Browse files Browse the repository at this point in the history
…ogin items (electron#34068)
  • Loading branch information
codebytere authored and khalwa committed Feb 22, 2023
1 parent 3992a31 commit 8bfb282
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions shell/browser/browser_mac.mm
Expand Up @@ -318,26 +318,32 @@
return settings;
}

// Some logic here copied from GetLoginItemForApp in base/mac/mac_util.mm
void RemoveFromLoginItems() {
#pragma clang diagnostic push // https://crbug.com/1154377
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// logic to find the login item copied from GetLoginItemForApp in
// base/mac/mac_util.mm
base::ScopedCFTypeRef<LSSharedFileListRef> login_items(
LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL));
if (!login_items.get()) {
LOG(ERROR) << "Couldn't get a Login Items list.";
return;
}

base::scoped_nsobject<NSArray> login_items_array(
base::mac::CFToNSCast(LSSharedFileListCopySnapshot(login_items, NULL)));
NSURL* url = [NSURL fileURLWithPath:[base::mac::MainBundle() bundlePath]];
for (NSUInteger i = 0; i < [login_items_array count]; ++i) {
for (id login_item in login_items_array.get()) {
LSSharedFileListItemRef item =
reinterpret_cast<LSSharedFileListItemRef>(login_items_array[i]);
reinterpret_cast<LSSharedFileListItemRef>(login_item);

// kLSSharedFileListDoNotMountVolumes is used so that we don't trigger
// mounting when it's not expected by a user. Just listing the login
// items should not cause any side-effects.
base::ScopedCFTypeRef<CFErrorRef> error;
CFURLRef item_url_ref =
LSSharedFileListItemCopyResolvedURL(item, 0, error.InitializeInto());
base::ScopedCFTypeRef<CFURLRef> item_url_ref(
LSSharedFileListItemCopyResolvedURL(
item, kLSSharedFileListDoNotMountVolumes, error.InitializeInto()));

if (!error && item_url_ref) {
base::ScopedCFTypeRef<CFURLRef> item_url(item_url_ref);
if (CFEqual(item_url, url)) {
Expand Down

0 comments on commit 8bfb282

Please sign in to comment.