electron chrome内核定制
1,
src\third_party\WebKit\Source\core\dom\events\Event.h:
src\third_party\blink\renderer\core\dom\events\event.h bool isTrusted() const { return is_trusted_; } void SetTrusted(bool value) { is_trusted_ = value; }
2,屏蔽所有弹出框:
electron/shell/browser/atom_javascript_dialog_manager.cc line 58: #if 0 if (dialog_type != JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_ALERT && dialog_type != JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_CONFIRM) { #else if(true){ std::move(callback).Run(false, base::string16()); return; } #endif
3,禁用
// Don't enforce the same-origin policy. (Used by people testing their sites.) --disable-site-isolation-trials --disable-web-security --disable-features=IsolateOrigins, site-per-proecess const wchar_t kDisableWebSecurity[] = L"disable-web-security";
4,开关 switch设置
electron的main
1)D:\dev\electron9\src\electron\shell\app\electron_main.cc
int main(int argc, char* argv[]) { FixStdioStreams(); #if BUILDFLAG(ENABLE_RUN_AS_NODE) if (IsEnvSet(electron::kRunAsNode)) { base::i18n::InitializeICU(); base::AtExitManager atexit_manager; return electron::NodeMain(argc, argv); } #endif electron::ElectronMainDelegate delegate; content::ContentMainParams params(&delegate); params.argc = argc; params.argv = const_cast<const char**>(argv); electron::ElectronCommandLine::Init(argc, argv); return content::ContentMain(params); }
2)D:\dev\electron9\src\content\app\content_main.cc

int ContentMain(const ContentMainParams& params) { ContentServiceManagerMainDelegate delegate(params); service_manager::MainParams main_params(&delegate); #if !defined(OS_WIN) && !defined(OS_ANDROID) main_params.argc = params.argc; main_params.argv = params.argv; #endif return service_manager::Main(main_params); }
在ContentMainParams 中有个重要数据 delegate,将真正的实现转交到外部。比如chrome在chrome/app/chrome_main_delegate.cc中。而electron在electron/shell/app/electron_main_delegate.cc中。:
// content\public\app\content_main.h struct ContentMainParams { explicit ContentMainParams(ContentMainDelegate* delegate) : delegate(delegate) {} ContentMainDelegate* delegate; ......
D:\dev\electron9\src\chrome\app\chrome_main_delegate.h
// Copyright (c) 2012 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. #ifndef CONTENT_PUBLIC_APP_CONTENT_MAIN_DELEGATE_H_ #define CONTENT_PUBLIC_APP_CONTENT_MAIN_DELEGATE_H_ #include <memory> #include <string> #include <vector> #include "base/callback_forward.h" #include "build/build_config.h" #include "content/common/content_export.h" #include "services/service_manager/embedder/process_type.h" namespace base { class CommandLine; } namespace service_manager { class BackgroundServiceManager; class Identity; class ZygoteForkDelegate; } // namespace service_manager namespace content { class ContentBrowserClient; class ContentClient; class ContentGpuClient; class ContentRendererClient; class ContentUtilityClient; struct MainFunctionParams; class CONTENT_EXPORT ContentMainDelegate { public: virtual ~ContentMainDelegate() {} // Tells the embedder that the absolute basic startup has been done, i.e. // it's now safe to create singletons and check the command line. Return true // if the process should exit afterwards, and if so, |exit_code| should be // set. This is the place for embedder to do the things that must happen at // the start. Most of its startup code should be in the methods below. virtual bool BasicStartupComplete(int* exit_code); // This is where the embedder puts all of its startup code that needs to run // before the sandbox is engaged. virtual void PreSandboxStartup() {} // This is where the embedder can add startup code to run after the sandbox // has been initialized. virtual void SandboxInitialized(const std::string& process_type) {} // Asks the embedder to start a process. Return -1 for the default behavior. virtual int RunProcess( const std::string& process_type, const MainFunctionParams& main_function_params); // Called right before the process exits. virtual void ProcessExiting(const std::string& process_type) {} #if defined(OS_LINUX) // Tells the embedder that the zygote process is starting, and allows it to // specify one or more zygote delegates if it wishes by storing them in // |*delegates|. virtual void ZygoteStarting( std::vector<std::unique_ptr<service_manager::ZygoteForkDelegate>>* delegates); // Called every time the zygote process forks. virtual void ZygoteForked() {} #endif // defined(OS_LINUX) // Fatal errors during initialization are reported by this function, so that // the embedder can implement graceful exit by displaying some message and // returning initialization error code. Default behavior is CHECK(false). virtual int TerminateForFatalInitializationError(); // Allows the embedder to prevent locking the scheme registry. The scheme // registry is the list of URL schemes we recognize, with some additional // information about each scheme such as whether it expects a host. The // scheme registry is not thread-safe, so by default it is locked before any // threads are created to ensure single-threaded access. An embedder can // override this to prevent the scheme registry from being locked during // startup, but if they do so then they are responsible for making sure that // the registry is only accessed in a thread-safe way, and for calling // url::LockSchemeRegistries() when initialization is complete. If possible, // prefer registering additional schemes through // ContentClient::AddAdditionalSchemes over preventing the scheme registry // from being locked. virtual bool ShouldLockSchemeRegistry(); // Overrides the Service Manager process type to use for the currently running // process. virtual service_manager::ProcessType OverrideProcessType(); // Allows the content embedder to adjust arbitrary command line arguments for // any service process started by the Service Manager. virtual void AdjustServiceProcessCommandLine( const service_manager::Identity& identity, base::CommandLine* command_line); // Allows the embedder to perform arbitrary initialization within the Service // Manager process immediately before the Service Manager runs its main loop. // // |quit_closure| is a callback the embedder may retain and invoke at any time // to cleanly terminate Service Manager execution. virtual void OnServiceManagerInitialized( base::OnceClosure quit_closure, service_manager::BackgroundServiceManager* service_manager); // Allows the embedder to perform platform-specific initialization before // creating the main message loop. virtual void PreCreateMainMessageLoop() {} // Returns true if content should create field trials and initialize the // FeatureList instance for this process. Default implementation returns true. // Embedders that need to control when and/or how FeatureList should be // created should override and return false. virtual bool ShouldCreateFeatureList(); // Allows the embedder to perform initialization once field trials/FeatureList // initialization has completed if ShouldCreateFeatureList() returns true. // Otherwise, the embedder is responsible for calling this method once feature // list initialization is complete. virtual void PostFieldTrialInitialization() {} // Allows the embedder to perform its own initialization after early content // initialization. At this point, it is possible to post to base::ThreadPool // or to the main thread loop via base::ThreadTaskRunnerHandle, but the tasks // won't run immediately. // // If ShouldCreateFeatureList() returns true, the field trials and FeatureList // have been initialized. Otherwise, the implementation must initialize the // field trials and FeatureList and call PostFieldTrialInitialization(). // // |is_running_tests| indicates whether it is running in tests. virtual void PostEarlyInitialization(bool is_running_tests) {} protected: friend class ContentClientCreator; friend class ContentClientInitializer; friend class BrowserTestBase; // Called once per relevant process type to allow the embedder to customize // content. If an embedder wants the default (empty) implementation, don't // override this. virtual ContentClient* CreateContentClient(); virtual ContentBrowserClient* CreateContentBrowserClient(); virtual ContentGpuClient* CreateContentGpuClient(); virtual ContentRendererClient* CreateContentRendererClient(); virtual ContentUtilityClient* CreateContentUtilityClient(); }; } // namespace content #endif // CONTENT_PUBLIC_APP_CONTENT_MAIN_DELEGATE_H_
这里的依赖类比如ContentGpuClient,会实现在外部。electron中
D:\dev\electron9\src\electron\shell\browser\electron_gpu_client.h
class ElectronGpuClient : public content::ContentGpuClient { public: ElectronGpuClient(); // content::ContentGpuClient: void PreCreateMessageLoop() override;
实现:
D:\dev\electron9\src\electron\shell\app\electron_main_delegate.cc
content::ContentGpuClient* ElectronMainDelegate::CreateContentGpuClient() { gpu_client_ = std::make_unique<ElectronGpuClient>(); return gpu_client_.get(); }
一些外部实现的client:
D:\dev\electron9\src\electron\shell\browser\electron_browser_client.cc
3)D:\dev\electron9\src\services\service_manager\embedder\main.cc
D:\dev\electron9\src\electron\shell\common\options_switches.cc
D:\dev\electron9\src\electron\shell\browser\web_contents_preferences.cc
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2017-06-02 从问题看本质: 研究TCP close_wait的内幕
2017-06-02 linux server 产生大量 Too many open files CLOSE_WAIT激增
2017-06-02 wildfly tomcat 服务器不响应 不返回 死住了 查看tcp CLOSE_WAIT 暴多