fd5e6fbc14
* chore: bump chromium in DEPS to 116.0.5793.3 * chore: update patches * chore: bump chromium in DEPS to 116.0.5795.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5797.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5799.0 * 4522192: [serial] Allow Bluetooth ports to be requested by service class ID. | https://chromium-review.googlesource.com/c/chromium/src/+/4522192 * 4545385: Create base:🍎:Owned[frameworktype], use it for gfx::NativeEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4545385 * chore: bump chromium in DEPS to 116.0.5801.0 * chore: update patches * 4562796: Use base:🍎:Owned[frameworktype] for ui::PlatformEvent | https://chromium-review.googlesource.com/c/chromium/src/+/4562796 * 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 * chore: bump chromium in DEPS to 116.0.5803.0 * chore: update patches * chore: bump chromium in DEPS to 116.0.5805.2 * chore: update patches * 4547630: Move content/public/common/network_service_util.h to c/p/browser/ | https://chromium-review.googlesource.com/c/chromium/src/+/4547630 * 4510075: Adding extensions to network response experiment | https://chromium-review.googlesource.com/c/chromium/src/+/4510075 * 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: bump chromium in DEPS to 116.0.5807.0 * chore: update patches * 4533536: [Privacy Hub] Geolocation manager used directly | https://chromium-review.googlesource.com/c/chromium/src/+/4533536 * chore: patch out ARC support from /chrome/browser 4571955: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4571955 * chore: bump chromium in DEPS to 116.0.5809.2 * chore: bump chromium in DEPS to 116.0.5811.0 * chore: update patches * 4573627: Adopt base::NoDestructor for KeyedService factories | https://chromium-review.googlesource.com/c/chromium/src/+/4573627 * 4576878: Reland "Shared Storage: Add mojo method for observing response headers" | https://chromium-review.googlesource.com/c/chromium/src/+/4576878 * chore: bump chromium in DEPS to 116.0.5813.0 * chore: update patches * fixup! 4566552: Auto-generate grd file for chrome://accessibility. | https://chromium-review.googlesource.com/c/chromium/src/+/4566552 * chore: fix up lint * test: (debug) use Promise.all in asan tests * chore: manually roll DEPS to 116.0.5815.0 * chore: update patches * 4585150: Convert /printing to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4585150 * test: (asan) extend timeout, clean up debugging * chore: remove ARC chromium patch * chore: update patches after main sync * 4546398: Convert /chrome/browser to use ARC | https://chromium-review.googlesource.com/c/chromium/src/+/4546398 * build: add chrome_lib_arc for chromium_src/BUILD.gn sources * fixup! 4559790: Manual raw_ptr rewrite: //base | https://chromium-review.googlesource.com/c/chromium/src/+/4559790 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
194 lines
6.5 KiB
Text
194 lines
6.5 KiB
Text
// Copyright (c) 2013 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/common/platform_util.h"
|
|
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#import <Carbon/Carbon.h>
|
|
#import <Cocoa/Cocoa.h>
|
|
#import <ServiceManagement/ServiceManagement.h>
|
|
|
|
#include "base/files/file_path.h"
|
|
#include "base/files/file_util.h"
|
|
#include "base/functional/callback.h"
|
|
#include "base/logging.h"
|
|
#include "base/mac/foundation_util.h"
|
|
#include "base/mac/mac_logging.h"
|
|
#include "base/mac/scoped_aedesc.h"
|
|
#include "base/strings/stringprintf.h"
|
|
#include "base/strings/sys_string_conversions.h"
|
|
#include "net/base/mac/url_conversions.h"
|
|
#include "ui/views/widget/widget.h"
|
|
#include "url/gurl.h"
|
|
|
|
namespace {
|
|
|
|
// This may be called from a global dispatch queue, the methods used here are
|
|
// thread safe, including LSGetApplicationForURL (> 10.2) and
|
|
// NSWorkspace#openURLs.
|
|
std::string OpenURL(NSURL* ns_url, bool activate) {
|
|
CFURLRef ref = LSCopyDefaultApplicationURLForURL(
|
|
base::mac::NSToCFCast(ns_url), kLSRolesAll, nullptr);
|
|
|
|
// If no application could be found, NULL is returned and outError
|
|
// (if not NULL) is populated with kLSApplicationNotFoundErr.
|
|
if (ref == NULL)
|
|
return "No application in the Launch Services database matches the input "
|
|
"criteria.";
|
|
|
|
NSUInteger launchOptions = NSWorkspaceLaunchDefault;
|
|
if (!activate)
|
|
launchOptions |= NSWorkspaceLaunchWithoutActivation;
|
|
|
|
bool opened = [[NSWorkspace sharedWorkspace] openURLs:@[ ns_url ]
|
|
withAppBundleIdentifier:nil
|
|
options:launchOptions
|
|
additionalEventParamDescriptor:nil
|
|
launchIdentifiers:nil];
|
|
if (!opened)
|
|
return "Failed to open URL";
|
|
|
|
return "";
|
|
}
|
|
|
|
NSString* GetLoginHelperBundleIdentifier() {
|
|
return [[[NSBundle mainBundle] bundleIdentifier]
|
|
stringByAppendingString:@".loginhelper"];
|
|
}
|
|
|
|
std::string OpenPathOnThread(const base::FilePath& full_path) {
|
|
NSString* path_string = base::SysUTF8ToNSString(full_path.value());
|
|
NSURL* url = [NSURL fileURLWithPath:path_string];
|
|
if (!url)
|
|
return "Invalid path";
|
|
|
|
const NSWorkspaceLaunchOptions launch_options =
|
|
NSWorkspaceLaunchAsync | NSWorkspaceLaunchWithErrorPresentation;
|
|
BOOL success = [[NSWorkspace sharedWorkspace] openURLs:@[ url ]
|
|
withAppBundleIdentifier:nil
|
|
options:launch_options
|
|
additionalEventParamDescriptor:nil
|
|
launchIdentifiers:NULL];
|
|
|
|
return success ? "" : "Failed to open path";
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace platform_util {
|
|
|
|
void ShowItemInFolder(const base::FilePath& path) {
|
|
// The API only takes absolute path.
|
|
base::FilePath full_path =
|
|
path.IsAbsolute() ? path : base::MakeAbsoluteFilePath(path);
|
|
|
|
DCHECK([NSThread isMainThread]);
|
|
NSString* path_string = base::SysUTF8ToNSString(full_path.value());
|
|
if (!path_string || ![[NSWorkspace sharedWorkspace] selectFile:path_string
|
|
inFileViewerRootedAtPath:@""]) {
|
|
LOG(WARNING) << "NSWorkspace failed to select file " << full_path.value();
|
|
}
|
|
}
|
|
|
|
void OpenPath(const base::FilePath& full_path, OpenCallback callback) {
|
|
std::move(callback).Run(OpenPathOnThread(full_path));
|
|
}
|
|
|
|
void OpenExternal(const GURL& url,
|
|
const OpenExternalOptions& options,
|
|
OpenCallback callback) {
|
|
DCHECK([NSThread isMainThread]);
|
|
NSURL* ns_url = net::NSURLWithGURL(url);
|
|
if (!ns_url) {
|
|
std::move(callback).Run("Invalid URL");
|
|
return;
|
|
}
|
|
|
|
bool activate = options.activate;
|
|
__block OpenCallback c = std::move(callback);
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
^{
|
|
__block std::string error = OpenURL(ns_url, activate);
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
std::move(c).Run(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
bool MoveItemToTrashWithError(const base::FilePath& full_path,
|
|
bool delete_on_fail,
|
|
std::string* error) {
|
|
NSString* path_string = base::SysUTF8ToNSString(full_path.value());
|
|
if (!path_string) {
|
|
*error = "Invalid file path: " + full_path.value();
|
|
LOG(WARNING) << *error;
|
|
return false;
|
|
}
|
|
|
|
NSURL* url = [NSURL fileURLWithPath:path_string];
|
|
NSError* err = nil;
|
|
BOOL did_trash = [[NSFileManager defaultManager] trashItemAtURL:url
|
|
resultingItemURL:nil
|
|
error:&err];
|
|
|
|
if (delete_on_fail) {
|
|
// Some volumes may not support a Trash folder or it may be disabled
|
|
// so these methods will report failure by returning NO or nil and
|
|
// an NSError with NSFeatureUnsupportedError.
|
|
// Handle this by deleting the item as a fallback.
|
|
if (!did_trash && [err code] == NSFeatureUnsupportedError) {
|
|
did_trash = [[NSFileManager defaultManager] removeItemAtURL:url
|
|
error:&err];
|
|
}
|
|
}
|
|
|
|
if (!did_trash) {
|
|
*error = base::SysNSStringToUTF8([err localizedDescription]);
|
|
LOG(WARNING) << "NSWorkspace failed to move file " << full_path.value()
|
|
<< " to trash: " << *error;
|
|
}
|
|
|
|
return did_trash;
|
|
}
|
|
|
|
namespace internal {
|
|
|
|
bool PlatformTrashItem(const base::FilePath& full_path, std::string* error) {
|
|
return MoveItemToTrashWithError(full_path, false, error);
|
|
}
|
|
|
|
} // namespace internal
|
|
|
|
void Beep() {
|
|
NSBeep();
|
|
}
|
|
|
|
bool GetLoginItemEnabled() {
|
|
BOOL enabled = NO;
|
|
#pragma clang diagnostic push
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
// SMJobCopyDictionary does not work in sandbox (see rdar://13626319)
|
|
CFArrayRef jobs = SMCopyAllJobDictionaries(kSMDomainUserLaunchd);
|
|
#pragma clang diagnostic pop
|
|
NSArray* jobs_ = CFBridgingRelease(jobs);
|
|
NSString* identifier = GetLoginHelperBundleIdentifier();
|
|
if (jobs_ && [jobs_ count] > 0) {
|
|
for (NSDictionary* job in jobs_) {
|
|
if ([identifier isEqualToString:[job objectForKey:@"Label"]]) {
|
|
enabled = [[job objectForKey:@"OnDemand"] boolValue];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return enabled;
|
|
}
|
|
|
|
bool SetLoginItemEnabled(bool enabled) {
|
|
NSString* identifier = GetLoginHelperBundleIdentifier();
|
|
return SMLoginItemSetEnabled((__bridge CFStringRef)identifier, enabled);
|
|
}
|
|
|
|
} // namespace platform_util
|