9645f7f6d8
* chore: bump chromium in DEPS to 117.0.5866.0 * chore: bump chromium in DEPS to 117.0.5868.0 * chore: update mas_no_private_api.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4634925 Minor manual patch syncing due to upstream code shear * chore: update mas_disable_remote_layer.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4647191 Manually sync patch to minor upstream code shear * chore: update mas_disable_remote_accessibility.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4641746 No manual changes; patch applied with fuzz * chore: update mas_avoid_usage_of_private_macos_apis.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4634925 Manually sync base/process/launch_mac.cc to minor upstream shear Manually sync base/mac/foundation_util.mm to upstream changes: _CFIsObjC use has been removed upstream, so we no longer need to remove it 🎉 * chore: update printing.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4658496 Manually sync patch to minor upstream code shear * chore: update disable_color_correct_rendering.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4625254 Manually sync patch to minor upstream code shear * chore: update feat_expose_raw_response_headers_from_urlloader.patch Xref: services/network/public/cpp/resource_request.cc No manual changes; patch applied with fuzz * chore: update add_electron_deps_to_license_credits_file.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4634961 No manual changes; patch applied with fuzz * chore: update build_only_use_the_mas_build_config_in_the_required_components.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4648411 No manual changes; patch applied with fuzz * chore: update patches * fixup! chore: update add_electron_deps_to_license_credits_file.patch chore: license files must be an array * chore: bump chromium in DEPS to 117.0.5870.0 * chore: update patches * chore: run ./script/gen-libc++-filenames.js * chore: update json_parse_errors_made_user-friendly.patch Xref: https://chromium-review.googlesource.com/c/v8/v8/+/4652014 v8 error message changed upstream; update Node test to match it * chore: bump chromium in DEPS to 117.0.5872.0 * chore: update patches * chore: explicitly cast x11::Window to unsigned int Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4661049 This is an `enum class Window : uint32_t` defined in ui/gfx/x/xproto.h. Previous versions of clang let this implicit cast happen, but it generates a warning in the new clang roll. * chore: remove unused #include Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4650453 header was removed upstream, so FTBFS unless removed here * chore: add include guard patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4628373 h/t @jkleinsc * chore: bump chromium in DEPS to 117.0.5874.0 * chore: update render_widget_host_view_mac.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4661244 Manually sync patch to minor upstream code * chore: update mas_disable_remote_accessibility.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4653209 Manually sync patch to upstream code shear * chore: update build_only_use_the_mas_build_config_in_the_required_components.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4653209 Manually sync patch to minor upstream code shear * chore: update GetInitiatorProcessId() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4641991 trivial upstream naming change: s/ProcessID/ProcessId/ * chore: sync to upstream SetInputRegion() changes Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4665245 Simple upstream chang: SetInputRegion() used to take a gfx::Rect* where `nullptr` meant "no opaque region". The function signature changed to absl::optional<gfx::Rect> w/the same meaning. * chore: sync to upstream SetOpaqueRegion() changes Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4656738 Simple upstream chang: SetOpaqueRegion() used to take a vector<Rect>* where `nullptr` meant "no opaque region". The function signature changed to absl::optional<std::vector<gfx::Rect>> w/the same meaning. * chore: update patches * chore: bump chromium in DEPS to 117.0.5876.0 * chore: update mas_disable_remote_accessibility.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4658375 We no longer need to patch out a field that's now removed upstream. RenderWidgetHostNSViewBridgeOwner.remote_accessibility_element_ * chore: update feat_filter_out_non-shareable_windows_in_the_current_application_in.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4658680 Manually sync patch to upstream code shear (ARC adoption). * chore: update patches * fix: -Werror,-Wshadow error in Node.js * chore: bump chromium in DEPS to 117.0.5878.0 * chore: bump chromium in DEPS to 117.0.5880.0 * chore: bump chromium in DEPS to 117.0.5880.4 * chore: update patches * 4658680: Convert /content/browser to use ARC https://chromium-review.googlesource.com/c/chromium/src/+/4658680 * 4669995: Remove CFToNSCast and NSToCFCast https://chromium-review.googlesource.com/c/chromium/src/+/4669995 * WIP: 4658680: Convert /content/browser to use ARC https://chromium-review.googlesource.com/c/chromium/src/+/4658680 * chore: update printing patch after rebase * chore: bump chromium in DEPS to 117.0.5882.0 * Revert "WIP: 4658680: Convert /content/browser to use ARC" This reverts commit c8559ea448ad93123865a6fa8af6fe2767e43396. * Revert "4669995: Remove CFToNSCast and NSToCFCast" This reverts commit 38e145f33d844e077b09e1fb119fae9d5d7bbc3e. * chore: bump chromium in DEPS to 117.0.5874.0 * 4661244: Convert /content/browser/renderer_host to use ARC https://chromium-review.googlesource.com/c/chromium/src/+/4661244 * 4653209: Convert /ui/views:views to use ARC https://chromium-review.googlesource.com/c/chromium/src/+/4653209 * chore: fixup mas_disable_remote_accessibility.patch * chore: fixup render_widget_host_view_mac.patch * chore: update to newer clang * chore: bump chromium in DEPS to 117.0.5884.1 (cherry picked from commit a3879acfde8f3d962d58d6ad0632164ccb88ee63) * 4669995: Remove CFToNSCast and NSToCFCast https://chromium-review.googlesource.com/c/chromium/src/+/4669995 (cherry picked from commit 38e145f33d844e077b09e1fb119fae9d5d7bbc3e) (cherry picked from commit b1224ab7e00aedbd0e5dc78ebb3c6162573b28c4) * 4658680: Convert /content/browser to use ARC https://chromium-review.googlesource.com/c/chromium/src/+/4658680 (cherry picked from commit 77039a323b9ebb3e8edb3a92a3b94a8d7d026a32) * Rename and cleanup ExtensionsBrowserClient functions | https://chromium-review.googlesource.com/c/chromium/src/+/4665670 (cherry picked from commit 677a2e646a8d82da60dc252b08b320c3ddff6be6) * chore: bump chromium in DEPS to 117.0.5886.0 * chore: update patches * Revert "chore: update patches" This reverts commit db9294f9446492d4a3d63f5f3ecc551aeeeb2e26. * Revert "chore: bump chromium in DEPS to 117.0.5886.0" This reverts commit a7de0276e6e0eeecfdbb17f9bbc27c01b4bbfc24. * build: use built toolchains instead of locally installed VSCode * fixup: build: use built toolchains instead of locally installed VSCode * chore: add missing mojo dep --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
195 lines
6.5 KiB
Text
195 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 cf_url = reinterpret_cast<CFURLRef>(ns_url);
|
|
CFURLRef ref =
|
|
LSCopyDefaultApplicationURLForURL(cf_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
|