feat: Electron Fuses, package time feature toggles (#24241)
* feat: add new 'fuses' feature for package-time build-flag style feature control * feat: put ENABLE_RUN_AS_NODE behind a fuse as well * chore: address PR feedback * build: move FUSE_EXPORT to headers * build: use hex codes for kFuseWire char[] * docs: add fuse wire documentation * chore: update fuses.json info * Apply suggestions from code review Co-authored-by: Jeremy Rose <jeremya@chromium.org> * chore: add link to fuse schema * Update shell/app/electron_library_main.mm Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org>
This commit is contained in:
parent
422190e1ff
commit
dbf2931f0e
8 changed files with 195 additions and 5 deletions
|
@ -9,6 +9,7 @@
|
|||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "content/public/app/content_main.h"
|
||||
#include "electron/fuses.h"
|
||||
#include "shell/app/electron_main_delegate.h"
|
||||
#include "shell/app/node_main.h"
|
||||
#include "shell/common/electron_command_line.h"
|
||||
|
@ -25,6 +26,11 @@ int ElectronMain(int argc, char* argv[]) {
|
|||
|
||||
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
||||
int ElectronInitializeICUandStartNode(int argc, char* argv[]) {
|
||||
if (!electron::fuses::IsRunAsNodeEnabled()) {
|
||||
CHECK(false) << "run_as_node fuse is disabled";
|
||||
return 1;
|
||||
}
|
||||
|
||||
base::AtExitManager atexit_manager;
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
base::mac::SetOverrideFrameworkBundlePath(
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "base/at_exit.h"
|
||||
#include "base/i18n/icu_util.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "electron/fuses.h"
|
||||
#include "shell/app/node_main.h"
|
||||
#include "shell/common/electron_command_line.h"
|
||||
#include "shell/common/electron_constants.h"
|
||||
|
@ -128,7 +129,8 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
|||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
||||
bool run_as_node = IsEnvSet(electron::kRunAsNode);
|
||||
bool run_as_node =
|
||||
electron::fuses::IsRunAsNodeEnabled() && IsEnvSet(electron::kRunAsNode);
|
||||
#else
|
||||
bool run_as_node = false;
|
||||
#endif
|
||||
|
@ -141,7 +143,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
|||
std::transform(arguments.argv, arguments.argv + arguments.argc, argv.begin(),
|
||||
[](auto& a) { return _strdup(base::WideToUTF8(a).c_str()); });
|
||||
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
||||
if (run_as_node) {
|
||||
if (electron::fuses::IsRunAsNodeEnabled() && run_as_node) {
|
||||
base::AtExitManager atexit_manager;
|
||||
base::i18n::InitializeICU();
|
||||
auto ret = electron::NodeMain(argv.size(), argv.data());
|
||||
|
@ -216,7 +218,7 @@ int main(int argc, char* argv[]) {
|
|||
FixStdioStreams();
|
||||
|
||||
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
||||
if (IsEnvSet(electron::kRunAsNode)) {
|
||||
if (electron::fuses::IsRunAsNodeEnabled() && IsEnvSet(electron::kRunAsNode)) {
|
||||
base::i18n::InitializeICU();
|
||||
base::AtExitManager atexit_manager;
|
||||
return electron::NodeMain(argc, argv);
|
||||
|
@ -237,7 +239,7 @@ int main(int argc, char* argv[]) {
|
|||
FixStdioStreams();
|
||||
|
||||
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
||||
if (IsEnvSet(electron::kRunAsNode)) {
|
||||
if (electron::fuses::IsRunAsNodeEnabled() && IsEnvSet(electron::kRunAsNode)) {
|
||||
return ElectronInitializeICUandStartNode(argc, argv);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// found in the LICENSE file.
|
||||
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "electron/fuses.h"
|
||||
#include "printing/buildflags/buildflags.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
|
@ -30,7 +31,7 @@ bool IsPDFViewerEnabled() {
|
|||
}
|
||||
|
||||
bool IsRunAsNodeEnabled() {
|
||||
return BUILDFLAG(ENABLE_RUN_AS_NODE);
|
||||
return electron::fuses::IsRunAsNodeEnabled() && BUILDFLAG(ENABLE_RUN_AS_NODE);
|
||||
}
|
||||
|
||||
bool IsFakeLocationProviderEnabled() {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "base/strings/string_split.h"
|
||||
#include "components/crash/core/common/crash_key.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "electron/fuses.h"
|
||||
#include "shell/common/electron_constants.h"
|
||||
#include "shell/common/options_switches.h"
|
||||
#include "third_party/crashpad/crashpad/client/annotation.h"
|
||||
|
@ -100,6 +101,9 @@ void GetCrashKeys(std::map<std::string, std::string>* keys) {
|
|||
namespace {
|
||||
bool IsRunningAsNode() {
|
||||
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
||||
if (!electron::fuses::IsRunAsNodeEnabled())
|
||||
return false;
|
||||
|
||||
return base::Environment::Create()->HasVar(electron::kRunAsNode);
|
||||
#else
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue