electron/shell/app/electron_main_delegate_mac.mm
electron-roller[bot] bbdd037219
chore: bump chromium to 117.0.5892.0 (main) (#39118)
* chore: bump chromium in DEPS to 117.0.5892.0

* 4670267: Don't send javascript: or empty URLs to browser in CreateNewWindow.

https://chromium-review.googlesource.com/c/chromium/src/+/4670267

* 4662090: Add metrics for WebGPU support

https://chromium-review.googlesource.com/c/chromium/src/+/4662090

* 4672599: Use set_defaults for mac_app_bundle

https://chromium-review.googlesource.com/c/chromium/src/+/4672599

* 4663771: usb: Add connection count tracking methods for UsbDelegate

https://chromium-review.googlesource.com/c/chromium/src/+/4663771

* 4664578: Remove unused parameter from ExtensionsGuestViewManagerDelegate ctor

https://chromium-review.googlesource.com/c/chromium/src/+/4664578

* 4622253: usb: Create classes for usb system tray icon

https://chromium-review.googlesource.com/c/chromium/src/+/4622253

* 4678263: Remove ARC support from scoped_nsobject

https://chromium-review.googlesource.com/c/chromium/src/+/4678263

* chore: follow-up ARC changes and missing guard corrections

* chore: don't mark 0-param ctor explicit

Follow up to https://chromium-review.googlesource.com/c/chromium/src/+/4664578

* chore: fixup patch indices

* 4670865: Merge ObjectProxy::CallMethodAndBlock{,WithErrorDetails}.

https://chromium-review.googlesource.com/c/chromium/src/+/4670865

* chore: follow-up ARC changes and missing guard corrections

* fixup: retain ElectronApplicationDelegate

* fix: correct rustc binary

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2023-07-19 00:26:27 +02:00

92 lines
3.1 KiB
Text

// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/app/electron_main_delegate.h"
#include <string>
#include "base/apple/bundle_locations.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/mac/foundation_util.h"
#include "base/path_service.h"
#include "base/strings/sys_string_conversions.h"
#include "content/browser/mac_helpers.h"
#include "content/public/common/content_paths.h"
#include "shell/browser/mac/electron_application.h"
#include "shell/common/application_info.h"
#include "shell/common/mac/main_application_bundle.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace electron {
namespace {
base::FilePath GetFrameworksPath() {
return MainApplicationBundlePath().Append("Contents").Append("Frameworks");
}
base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path,
const std::string& name) {
// Figure out what helper we are running
base::FilePath path;
base::PathService::Get(base::FILE_EXE, &path);
std::string helper_name = "Helper";
if (base::EndsWith(path.value(), content::kMacHelperSuffix_renderer,
base::CompareCase::SENSITIVE)) {
helper_name += content::kMacHelperSuffix_renderer;
} else if (base::EndsWith(path.value(), content::kMacHelperSuffix_gpu,
base::CompareCase::SENSITIVE)) {
helper_name += content::kMacHelperSuffix_gpu;
} else if (base::EndsWith(path.value(), content::kMacHelperSuffix_plugin,
base::CompareCase::SENSITIVE)) {
helper_name += content::kMacHelperSuffix_plugin;
}
return frameworks_path.Append(name + " " + helper_name + ".app")
.Append("Contents")
.Append("MacOS")
.Append(name + " " + helper_name);
}
} // namespace
void ElectronMainDelegate::OverrideFrameworkBundlePath() {
base::apple::SetOverrideFrameworkBundlePath(
GetFrameworksPath().Append(ELECTRON_PRODUCT_NAME " Framework.framework"));
}
void ElectronMainDelegate::OverrideChildProcessPath() {
base::FilePath frameworks_path = GetFrameworksPath();
base::FilePath helper_path =
GetHelperAppPath(frameworks_path, ELECTRON_PRODUCT_NAME);
if (!base::PathExists(helper_path))
helper_path = GetHelperAppPath(frameworks_path, GetApplicationName());
if (!base::PathExists(helper_path))
LOG(FATAL) << "Unable to find helper app";
base::PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
}
void ElectronMainDelegate::SetUpBundleOverrides() {
@autoreleasepool {
NSBundle* bundle = MainApplicationBundle();
std::string base_bundle_id =
base::SysNSStringToUTF8([bundle bundleIdentifier]);
NSString* team_id = [bundle objectForInfoDictionaryKey:@"ElectronTeamID"];
if (team_id)
base_bundle_id = base::SysNSStringToUTF8(team_id) + "." + base_bundle_id;
base::mac::SetBaseBundleID(base_bundle_id.c_str());
}
}
void RegisterAtomCrApp() {
// Force the NSApplication subclass to be used.
[AtomApplication sharedApplication];
}
} // namespace electron