diff --git a/patches/chromium/chore_add_electron_objects_to_wrappablepointertag.patch b/patches/chromium/chore_add_electron_objects_to_wrappablepointertag.patch index c88a6e9ea7..10cf42a246 100644 --- a/patches/chromium/chore_add_electron_objects_to_wrappablepointertag.patch +++ b/patches/chromium/chore_add_electron_objects_to_wrappablepointertag.patch @@ -8,20 +8,21 @@ electron objects that extend gin::Wrappable and gets allocated on the cpp heap diff --git a/gin/public/wrappable_pointer_tags.h b/gin/public/wrappable_pointer_tags.h -index 573bcb2e56068a2ade6d8ab28964b077487874fd..41759b87e1aec4ec125560b9a52828fb44bc5999 100644 +index 573bcb2e56068a2ade6d8ab28964b077487874fd..acb0c0b44f6530e49b32ea7602c25d498ae4f210 100644 --- a/gin/public/wrappable_pointer_tags.h +++ b/gin/public/wrappable_pointer_tags.h -@@ -74,7 +74,18 @@ enum WrappablePointerTag : uint16_t { +@@ -74,7 +74,19 @@ enum WrappablePointerTag : uint16_t { kTextInputControllerBindings, // content::TextInputControllerBindings kWebAXObjectProxy, // content::WebAXObjectProxy kWrappedExceptionHandler, // extensions::WrappedExceptionHandler - kLastPointerTag = kWrappedExceptionHandler, + kElectronApp, // electron::api::App -+ kElectronDebugger, // electron::api::Debugger + kElectronDataPipeHolder, // electron::api::DataPipeHolder ++ kElectronDebugger, // electron::api::Debugger + kElectronEvent, // gin_helper::internal::Event + kElectronMenu, // electron::api::Menu + kElectronNetLog, // electron::api::NetLog ++ kElectronPowerMonitor, // electron::api::PowerMonitor + kElectronPowerSaveBlocker, // electron::api::PowerSaveBlocker + kElectronReplyChannel, // gin_helper::internal::ReplyChannel + kElectronScreen, // electron::api::Screen diff --git a/shell/browser/api/electron_api_power_monitor.cc b/shell/browser/api/electron_api_power_monitor.cc index 5956489ab4..f61a3e8151 100644 --- a/shell/browser/api/electron_api_power_monitor.cc +++ b/shell/browser/api/electron_api_power_monitor.cc @@ -5,16 +5,15 @@ #include "shell/browser/api/electron_api_power_monitor.h" #include "base/power_monitor/power_monitor.h" -#include "base/power_monitor/power_monitor_device_source.h" #include "base/power_monitor/power_observer.h" #include "gin/data_object_builder.h" #include "shell/browser/browser.h" #include "shell/browser/javascript_environment.h" -#include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_helper/dictionary.h" -#include "shell/common/gin_helper/handle.h" -#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" +#include "ui/base/idle/idle.h" +#include "v8/include/cppgc/allocation.h" +#include "v8/include/v8-cppgc.h" namespace gin { @@ -60,10 +59,11 @@ struct Converter { namespace electron::api { -gin::DeprecatedWrapperInfo PowerMonitor::kWrapperInfo = { - gin::kEmbedderNativeGin}; +const gin::WrapperInfo PowerMonitor::kWrapperInfo = { + {gin::kEmbedderNativeGin}, + gin::kElectronPowerMonitor}; -PowerMonitor::PowerMonitor(v8::Isolate* isolate) { +PowerMonitor::PowerMonitor() { #if BUILDFLAG(IS_MAC) Browser::Get()->SetShutdownHandler(base::BindRepeating( &PowerMonitor::ShouldShutdown, base::Unretained(this))); @@ -142,11 +142,9 @@ void PowerMonitor::SetListeningForShutdown(bool is_listening) { #endif // static -v8::Local PowerMonitor::Create(v8::Isolate* isolate) { - auto* pm = new PowerMonitor(isolate); - auto handle = gin_helper::CreateHandle(isolate, pm).ToV8(); - pm->Pin(isolate); - return handle; +PowerMonitor* PowerMonitor::Create(v8::Isolate* isolate) { + return cppgc::MakeGarbageCollected( + isolate->GetCppHeap()->GetAllocationHandle()); } gin::ObjectTemplateBuilder PowerMonitor::GetObjectTemplateBuilder( @@ -161,8 +159,12 @@ gin::ObjectTemplateBuilder PowerMonitor::GetObjectTemplateBuilder( return builder; } -const char* PowerMonitor::GetTypeName() { - return "PowerMonitor"; +const gin::WrapperInfo* PowerMonitor::wrapper_info() const { + return &kWrapperInfo; +} + +const char* PowerMonitor::GetHumanReadableName() const { + return "Electron / PowerMonitor"; } } // namespace electron::api diff --git a/shell/browser/api/electron_api_power_monitor.h b/shell/browser/api/electron_api_power_monitor.h index 1d45585893..292b1a649b 100644 --- a/shell/browser/api/electron_api_power_monitor.h +++ b/shell/browser/api/electron_api_power_monitor.h @@ -6,40 +6,45 @@ #define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_POWER_MONITOR_H_ #include "base/power_monitor/power_observer.h" +#include "gin/wrappable.h" #include "shell/browser/event_emitter_mixin.h" -#include "shell/common/gin_helper/pinnable.h" -#include "shell/common/gin_helper/wrappable.h" -#include "ui/base/idle/idle.h" +#include "shell/common/gin_helper/self_keep_alive.h" #if BUILDFLAG(IS_LINUX) #include "shell/browser/lib/power_observer_linux.h" #endif +namespace gin { +class ObjectTemplateBuilder; +} // namespace gin + namespace electron::api { -class PowerMonitor final : public gin_helper::DeprecatedWrappable, +class PowerMonitor final : public gin::Wrappable, public gin_helper::EventEmitterMixin, - public gin_helper::Pinnable, private base::PowerStateObserver, private base::PowerSuspendObserver, private base::PowerThermalObserver { public: - static v8::Local Create(v8::Isolate* isolate); + static PowerMonitor* Create(v8::Isolate* isolate); - // gin_helper::Wrappable - static gin::DeprecatedWrapperInfo kWrapperInfo; + // gin::Wrappable + static const gin::WrapperInfo kWrapperInfo; + const gin::WrapperInfo* wrapper_info() const override; + const char* GetHumanReadableName() const override; gin::ObjectTemplateBuilder GetObjectTemplateBuilder( v8::Isolate* isolate) override; - const char* GetTypeName() override; + const char* GetClassName() const { return "PowerMonitor"; } + + // Make public for cppgc::MakeGarbageCollected. + PowerMonitor(); + ~PowerMonitor() override; // disable copy PowerMonitor(const PowerMonitor&) = delete; PowerMonitor& operator=(const PowerMonitor&) = delete; private: - explicit PowerMonitor(v8::Isolate* isolate); - ~PowerMonitor() override; - #if BUILDFLAG(IS_LINUX) void SetListeningForShutdown(bool); #endif @@ -88,6 +93,8 @@ class PowerMonitor final : public gin_helper::DeprecatedWrappable, #if BUILDFLAG(IS_LINUX) PowerObserverLinux power_observer_linux_{this}; #endif + + gin_helper::SelfKeepAlive keep_alive_{this}; }; } // namespace electron::api