2014-12-29 09:35:08 -08:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 12:19:40 -08:00
|
|
|
#include "shell/app/electron_main_delegate.h"
|
2014-12-29 09:35:08 -08:00
|
|
|
|
2019-05-02 14:05:37 +02:00
|
|
|
#include <string>
|
|
|
|
|
2014-12-29 09:35:08 -08:00
|
|
|
#include "base/files/file_path.h"
|
2015-04-14 13:51:08 +08:00
|
|
|
#include "base/files/file_util.h"
|
2018-04-20 14:47:04 -04:00
|
|
|
#include "base/mac/bundle_locations.h"
|
2016-05-18 16:42:26 +09:00
|
|
|
#include "base/mac/foundation_util.h"
|
|
|
|
#include "base/mac/scoped_nsautorelease_pool.h"
|
2014-12-29 09:35:08 -08:00
|
|
|
#include "base/path_service.h"
|
2016-05-19 10:57:57 +09:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2019-07-02 18:22:09 -07:00
|
|
|
#include "content/common/mac_helpers.h"
|
2014-12-29 09:35:08 -08:00
|
|
|
#include "content/public/common/content_paths.h"
|
2020-04-28 23:16:10 -07:00
|
|
|
#include "ppapi/buildflags/buildflags.h"
|
2020-02-04 12:19:40 -08:00
|
|
|
#include "shell/browser/mac/electron_application.h"
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/common/application_info.h"
|
|
|
|
#include "shell/common/mac/main_application_bundle.h"
|
2014-12-29 09:35:08 -08:00
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2014-12-29 09:35:08 -08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
base::FilePath GetFrameworksPath() {
|
2018-10-24 12:49:10 +02:00
|
|
|
return MainApplicationBundlePath().Append("Contents").Append("Frameworks");
|
2014-12-29 09:35:08 -08:00
|
|
|
}
|
|
|
|
|
2015-04-17 15:10:48 +08:00
|
|
|
base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path,
|
2015-04-14 13:51:08 +08:00
|
|
|
const std::string& name) {
|
2019-07-02 18:22:09 -07:00
|
|
|
// 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;
|
2019-07-24 15:58:51 -07:00
|
|
|
} else if (base::EndsWith(path.value(), content::kMacHelperSuffix_gpu,
|
|
|
|
base::CompareCase::SENSITIVE)) {
|
|
|
|
helper_name += content::kMacHelperSuffix_gpu;
|
2020-04-28 23:16:10 -07:00
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS)
|
2019-07-02 18:22:09 -07:00
|
|
|
} else if (base::EndsWith(path.value(), content::kMacHelperSuffix_plugin,
|
|
|
|
base::CompareCase::SENSITIVE)) {
|
|
|
|
helper_name += content::kMacHelperSuffix_plugin;
|
2020-04-28 23:16:10 -07:00
|
|
|
#endif
|
2019-07-02 18:22:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return frameworks_path.Append(name + " " + helper_name + ".app")
|
2018-04-20 14:47:04 -04:00
|
|
|
.Append("Contents")
|
|
|
|
.Append("MacOS")
|
2019-07-02 18:22:09 -07:00
|
|
|
.Append(name + " " + helper_name);
|
2015-04-14 13:51:08 +08:00
|
|
|
}
|
|
|
|
|
2014-12-29 09:35:08 -08:00
|
|
|
} // namespace
|
|
|
|
|
2020-02-04 12:19:40 -08:00
|
|
|
void ElectronMainDelegate::OverrideFrameworkBundlePath() {
|
2014-12-29 09:35:08 -08:00
|
|
|
base::mac::SetOverrideFrameworkBundlePath(
|
2019-06-17 13:37:55 -07:00
|
|
|
GetFrameworksPath().Append(ELECTRON_PRODUCT_NAME " Framework.framework"));
|
2014-12-29 09:35:08 -08:00
|
|
|
}
|
|
|
|
|
2020-02-04 12:19:40 -08:00
|
|
|
void ElectronMainDelegate::OverrideChildProcessPath() {
|
2015-04-14 13:51:08 +08:00
|
|
|
base::FilePath frameworks_path = GetFrameworksPath();
|
2018-04-20 14:47:04 -04:00
|
|
|
base::FilePath helper_path =
|
2019-06-17 13:37:55 -07:00
|
|
|
GetHelperAppPath(frameworks_path, ELECTRON_PRODUCT_NAME);
|
2015-04-14 13:51:08 +08:00
|
|
|
if (!base::PathExists(helper_path))
|
2018-10-24 12:49:10 +02:00
|
|
|
helper_path = GetHelperAppPath(frameworks_path, GetApplicationName());
|
2015-04-14 13:51:08 +08:00
|
|
|
if (!base::PathExists(helper_path))
|
|
|
|
LOG(FATAL) << "Unable to find helper app";
|
2018-09-14 17:09:42 -07:00
|
|
|
base::PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
|
2014-12-29 09:35:08 -08:00
|
|
|
}
|
|
|
|
|
2020-02-04 12:19:40 -08:00
|
|
|
void ElectronMainDelegate::SetUpBundleOverrides() {
|
2016-05-18 16:42:26 +09:00
|
|
|
base::mac::ScopedNSAutoreleasePool pool;
|
2018-10-24 12:49:10 +02:00
|
|
|
NSBundle* bundle = MainApplicationBundle();
|
2016-05-19 10:57:57 +09:00
|
|
|
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());
|
2016-05-18 16:42:26 +09:00
|
|
|
}
|
|
|
|
|
2018-10-03 13:49:18 -07:00
|
|
|
void RegisterAtomCrApp() {
|
|
|
|
// Force the NSApplication subclass to be used.
|
2020-02-21 11:05:03 -08:00
|
|
|
[AtomApplication sharedApplication];
|
2018-10-03 13:49:18 -07:00
|
|
|
}
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|