2017-01-27 01:14:56 +01:00
|
|
|
// Copyright 2017 The Chromium Embedded Framework Authors. Portions copyright
|
|
|
|
// 2011 The Chromium Authors. All rights reserved. Use of this source code is
|
|
|
|
// governed by a BSD-style license that can be found in the LICENSE file.
|
2015-03-25 22:22:47 +01:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/util_mac.h"
|
2017-01-27 01:14:56 +01:00
|
|
|
|
2023-05-30 10:55:32 +02:00
|
|
|
#include "base/apple/bundle_locations.h"
|
2023-09-15 21:51:43 +02:00
|
|
|
#include "base/apple/foundation_util.h"
|
2017-01-27 01:14:56 +01:00
|
|
|
#include "base/base_paths.h"
|
|
|
|
#include "base/command_line.h"
|
2020-07-06 20:14:57 +02:00
|
|
|
#include "base/logging.h"
|
2017-01-27 01:14:56 +01:00
|
|
|
#include "base/path_service.h"
|
2018-07-27 23:28:12 +02:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/cef_switches.h"
|
2020-07-06 20:14:57 +02:00
|
|
|
#include "content/public/common/content_paths.h"
|
|
|
|
#include "content/public/common/content_switches.h"
|
2015-03-25 22:22:47 +01:00
|
|
|
|
|
|
|
namespace util_mac {
|
|
|
|
|
2017-01-27 01:14:56 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Returns the path to the Frameworks directory inside the top-level app bundle.
|
|
|
|
base::FilePath GetFrameworksPath() {
|
|
|
|
base::FilePath bundle_path = GetMainBundlePath();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (bundle_path.empty()) {
|
2017-01-27 01:14:56 +01:00
|
|
|
return base::FilePath();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-27 01:14:56 +01:00
|
|
|
|
|
|
|
return bundle_path.Append(FILE_PATH_LITERAL("Contents"))
|
2017-05-17 11:29:28 +02:00
|
|
|
.Append(FILE_PATH_LITERAL("Frameworks"));
|
2017-01-27 01:14:56 +01:00
|
|
|
}
|
|
|
|
|
2020-07-06 20:14:57 +02:00
|
|
|
void OverrideFrameworkBundlePath() {
|
|
|
|
base::FilePath framework_path = GetFrameworkDirectory();
|
|
|
|
DCHECK(!framework_path.empty());
|
|
|
|
|
2023-05-30 10:55:32 +02:00
|
|
|
base::apple::SetOverrideFrameworkBundlePath(framework_path);
|
2020-07-06 20:14:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OverrideOuterBundlePath() {
|
|
|
|
base::FilePath bundle_path = GetMainBundlePath();
|
|
|
|
DCHECK(!bundle_path.empty());
|
|
|
|
|
2023-05-30 10:55:32 +02:00
|
|
|
base::apple::SetOverrideOuterBundlePath(bundle_path);
|
2020-07-06 20:14:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OverrideBaseBundleID() {
|
|
|
|
std::string bundle_id = GetMainBundleID();
|
|
|
|
DCHECK(!bundle_id.empty());
|
|
|
|
|
2023-09-15 21:51:43 +02:00
|
|
|
base::apple::SetBaseBundleID(bundle_id.c_str());
|
2020-07-06 20:14:57 +02:00
|
|
|
}
|
|
|
|
|
2023-04-21 20:39:17 +02:00
|
|
|
base::FilePath GetNormalChildProcessPath() {
|
|
|
|
base::FilePath frameworks_path = GetFrameworksPath();
|
|
|
|
if (frameworks_path.empty()) {
|
|
|
|
return base::FilePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string exe_name = GetMainProcessPath().BaseName().value();
|
|
|
|
return frameworks_path.Append(FILE_PATH_LITERAL(exe_name + " Helper.app"))
|
|
|
|
.Append(FILE_PATH_LITERAL("Contents"))
|
|
|
|
.Append(FILE_PATH_LITERAL("MacOS"))
|
|
|
|
.Append(FILE_PATH_LITERAL(exe_name + " Helper"));
|
|
|
|
}
|
|
|
|
|
2020-07-06 20:14:57 +02:00
|
|
|
void OverrideChildProcessPath() {
|
|
|
|
base::FilePath child_process_path =
|
|
|
|
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
|
|
|
|
switches::kBrowserSubprocessPath);
|
|
|
|
|
|
|
|
if (child_process_path.empty()) {
|
2023-04-21 20:39:17 +02:00
|
|
|
child_process_path = GetNormalChildProcessPath();
|
|
|
|
CHECK(!child_process_path.empty());
|
2020-07-06 20:14:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Used by ChildProcessHost::GetChildPath and PlatformCrashpadInitialization.
|
2023-08-09 23:17:17 +02:00
|
|
|
base::PathService::OverrideAndCreateIfNeeded(
|
|
|
|
content::CHILD_PROCESS_EXE, child_process_path, /*is_absolute=*/true,
|
|
|
|
/*create=*/false);
|
2020-07-06 20:14:57 +02:00
|
|
|
}
|
|
|
|
|
2017-01-27 01:14:56 +01:00
|
|
|
} // namespace
|
|
|
|
|
2015-03-25 22:22:47 +01:00
|
|
|
bool GetLocalLibraryDirectory(base::FilePath* result) {
|
2023-09-15 21:51:43 +02:00
|
|
|
return base::apple::GetLocalDirectory(NSLibraryDirectory, result);
|
2015-03-25 22:22:47 +01:00
|
|
|
}
|
|
|
|
|
2022-10-04 21:54:13 +02:00
|
|
|
base::FilePath::StringType GetFrameworkName() {
|
|
|
|
return FILE_PATH_LITERAL("Chromium Embedded Framework");
|
|
|
|
}
|
|
|
|
|
2017-01-27 01:14:56 +01:00
|
|
|
base::FilePath GetFrameworkDirectory() {
|
|
|
|
base::FilePath frameworks_path =
|
|
|
|
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
|
|
|
|
switches::kFrameworkDirPath);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!frameworks_path.empty()) {
|
2017-01-27 01:14:56 +01:00
|
|
|
return frameworks_path;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-27 01:14:56 +01:00
|
|
|
|
|
|
|
frameworks_path = GetFrameworksPath();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frameworks_path.empty()) {
|
2017-01-27 01:14:56 +01:00
|
|
|
return base::FilePath();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-27 01:14:56 +01:00
|
|
|
|
2022-10-04 21:54:13 +02:00
|
|
|
return frameworks_path.Append(GetFrameworkName())
|
|
|
|
.AddExtension(FILE_PATH_LITERAL(".framework"));
|
2017-01-27 01:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
base::FilePath GetFrameworkResourcesDirectory() {
|
|
|
|
base::FilePath frameworks_path = GetFrameworkDirectory();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frameworks_path.empty()) {
|
2017-01-27 01:14:56 +01:00
|
|
|
return base::FilePath();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-27 01:14:56 +01:00
|
|
|
|
|
|
|
return frameworks_path.Append(FILE_PATH_LITERAL("Resources"));
|
|
|
|
}
|
|
|
|
|
|
|
|
base::FilePath GetMainProcessPath() {
|
|
|
|
base::FilePath path;
|
2018-05-14 13:24:05 +02:00
|
|
|
base::PathService::Get(base::FILE_EXE, &path);
|
2017-01-27 01:14:56 +01:00
|
|
|
DCHECK(!path.empty());
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2018-07-27 23:28:12 +02:00
|
|
|
base::FilePath GetMainBundlePath() {
|
2019-07-25 17:47:46 +02:00
|
|
|
base::FilePath main_bundle_path =
|
|
|
|
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
|
|
|
|
switches::kMainBundlePath);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!main_bundle_path.empty()) {
|
2019-07-25 17:47:46 +02:00
|
|
|
return main_bundle_path;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-07-25 17:47:46 +02:00
|
|
|
|
2023-09-15 21:51:43 +02:00
|
|
|
return base::apple::GetAppBundlePath(GetMainProcessPath());
|
2018-07-27 23:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetMainBundleID() {
|
2023-05-30 10:55:32 +02:00
|
|
|
NSBundle* bundle = base::apple::OuterBundle();
|
2018-07-27 23:28:12 +02:00
|
|
|
return base::SysNSStringToUTF8([bundle bundleIdentifier]);
|
|
|
|
}
|
|
|
|
|
2017-01-27 01:14:56 +01:00
|
|
|
base::FilePath GetMainResourcesDirectory() {
|
|
|
|
base::FilePath bundle_path = GetMainBundlePath();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (bundle_path.empty()) {
|
2017-01-27 01:14:56 +01:00
|
|
|
return base::FilePath();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-27 01:14:56 +01:00
|
|
|
|
|
|
|
return bundle_path.Append(FILE_PATH_LITERAL("Contents"))
|
2017-05-17 11:29:28 +02:00
|
|
|
.Append(FILE_PATH_LITERAL("Resources"));
|
2017-01-27 01:14:56 +01:00
|
|
|
}
|
|
|
|
|
2020-07-06 20:14:57 +02:00
|
|
|
void PreSandboxStartup() {
|
|
|
|
OverrideChildProcessPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicStartupComplete() {
|
|
|
|
OverrideFrameworkBundlePath();
|
|
|
|
OverrideOuterBundlePath();
|
|
|
|
OverrideBaseBundleID();
|
|
|
|
}
|
|
|
|
|
2015-03-25 22:22:47 +01:00
|
|
|
} // namespace util_mac
|