diff --git a/filenames.gni b/filenames.gni index a3984c7873a4..60b06800b24d 100644 --- a/filenames.gni +++ b/filenames.gni @@ -653,6 +653,7 @@ filenames = { "shell/common/gin_helper/function_template.cc", "shell/common/gin_helper/function_template.h", "shell/common/gin_helper/function_template_extensions.h", + "shell/common/gin_helper/handle.h", "shell/common/gin_helper/locker.cc", "shell/common/gin_helper/locker.h", "shell/common/gin_helper/object_template_builder.cc", diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index fdaaac369f29..2b3346d648f1 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -41,7 +41,6 @@ #include "content/public/browser/render_frame_host.h" #include "crypto/crypto_buildflags.h" #include "electron/mas.h" -#include "gin/handle.h" #include "media/audio/audio_manager.h" #include "net/dns/public/dns_over_https_config.h" #include "net/dns/public/dns_over_https_server_config.h" @@ -76,6 +75,7 @@ #include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/language_util.h" #include "shell/common/node_includes.h" @@ -1701,8 +1701,8 @@ App* App::Get() { } // static -gin::Handle App::Create(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, Get()); +gin_helper::Handle App::Create(v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, Get()); } gin::ObjectTemplateBuilder App::GetObjectTemplateBuilder(v8::Isolate* isolate) { diff --git a/shell/browser/api/electron_api_app.h b/shell/browser/api/electron_api_app.h index dcf259ec29f0..5124851f632a 100644 --- a/shell/browser/api/electron_api_app.h +++ b/shell/browser/api/electron_api_app.h @@ -37,14 +37,11 @@ namespace base { class FilePath; } -namespace gin { -template -class Handle; -} // namespace gin - namespace gin_helper { class Dictionary; class ErrorThrower; +template +class Handle; } // namespace gin_helper namespace electron { @@ -64,7 +61,7 @@ class App final : public ElectronBrowserClient::Delegate, private content::GpuDataManagerObserver, private content::BrowserChildProcessObserver { public: - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); static App* Get(); // gin_helper::Wrappable diff --git a/shell/browser/api/electron_api_auto_updater.cc b/shell/browser/api/electron_api_auto_updater.cc index f509912749bd..519b76aae295 100644 --- a/shell/browser/api/electron_api_auto_updater.cc +++ b/shell/browser/api/electron_api_auto_updater.cc @@ -5,7 +5,6 @@ #include "shell/browser/api/electron_api_auto_updater.h" #include "base/time/time.h" -#include "gin/handle.h" #include "shell/browser/javascript_environment.h" #include "shell/browser/native_window.h" #include "shell/browser/window_list.h" @@ -13,6 +12,7 @@ #include "shell/common/gin_converters/time_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/event_emitter_caller.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" @@ -120,8 +120,8 @@ void AutoUpdater::QuitAndInstall() { } // static -gin::Handle AutoUpdater::Create(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, new AutoUpdater()); +gin_helper::Handle AutoUpdater::Create(v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, new AutoUpdater()); } gin::ObjectTemplateBuilder AutoUpdater::GetObjectTemplateBuilder( diff --git a/shell/browser/api/electron_api_auto_updater.h b/shell/browser/api/electron_api_auto_updater.h index be1f50ca5564..34e9b92ef20d 100644 --- a/shell/browser/api/electron_api_auto_updater.h +++ b/shell/browser/api/electron_api_auto_updater.h @@ -12,10 +12,10 @@ #include "shell/browser/window_list_observer.h" #include "shell/common/gin_helper/wrappable.h" -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron::api { @@ -24,7 +24,7 @@ class AutoUpdater final : public gin_helper::DeprecatedWrappable, public auto_updater::Delegate, private WindowListObserver { public: - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); // gin_helper::Wrappable static gin::DeprecatedWrapperInfo kWrapperInfo; diff --git a/shell/browser/api/electron_api_base_window.cc b/shell/browser/api/electron_api_base_window.cc index 4b09ec419a5e..a6ebfb156b98 100644 --- a/shell/browser/api/electron_api_base_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -13,7 +13,6 @@ #include "content/public/common/color_parser.h" #include "electron/buildflags/buildflags.h" #include "gin/dictionary.h" -#include "gin/handle.h" #include "shell/browser/api/electron_api_menu.h" #include "shell/browser/api/electron_api_view.h" #include "shell/browser/api/electron_api_web_contents.h" @@ -28,6 +27,7 @@ #include "shell/common/gin_converters/optional_converter.h" #include "shell/common/gin_converters/value_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/gin_helper/persistent_dictionary.h" #include "shell/common/node_includes.h" @@ -96,7 +96,7 @@ v8::Local ToBuffer(v8::Isolate* isolate, BaseWindow::BaseWindow(v8::Isolate* isolate, const gin_helper::Dictionary& options) { // The parent window. - gin::Handle parent; + gin_helper::Handle parent; if (options.Get("parent", &parent) && !parent.IsEmpty()) parent_window_.Reset(isolate, parent.ToV8()); @@ -150,7 +150,7 @@ void BaseWindow::InitWith(v8::Isolate* isolate, v8::Local wrapper) { // We can only append this window to parent window's child windows after this // window's JS wrapper gets initialized. if (!parent_window_.IsEmpty()) { - gin::Handle parent; + gin_helper::Handle parent; gin::ConvertFromV8(isolate, GetParentWindow(), &parent); DCHECK(!parent.IsEmpty()); parent->child_windows_.Set(isolate, weak_map_id(), wrapper); @@ -194,7 +194,7 @@ void BaseWindow::OnWindowQueryEndSession( v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin::Handle event = + gin_helper::Handle event = gin_helper::internal::Event::New(isolate); v8::Local event_object = event.ToV8().As(); @@ -211,7 +211,7 @@ void BaseWindow::OnWindowEndSession(const std::vector& reasons) { v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin::Handle event = + gin_helper::Handle event = gin_helper::internal::Event::New(isolate); v8::Local event_object = event.ToV8().As(); @@ -356,7 +356,7 @@ void BaseWindow::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) { } #endif -void BaseWindow::SetContentView(gin::Handle view) { +void BaseWindow::SetContentView(gin_helper::Handle view) { content_view_.Reset(JavascriptEnvironment::GetIsolate(), view.ToV8()); window_->SetContentView(view->view()); } @@ -730,7 +730,7 @@ bool BaseWindow::IsFocusable() const { void BaseWindow::SetMenu(v8::Isolate* isolate, v8::Local value) { auto context = isolate->GetCurrentContext(); - gin::Handle menu; + gin_helper::Handle menu; v8::Local object; if (value->IsObject() && value->ToObject(context).ToLocal(&object) && gin::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) { @@ -763,7 +763,7 @@ void BaseWindow::SetParentWindow(v8::Local value, return; } - gin::Handle parent; + gin_helper::Handle parent; if (value->IsNull() || value->IsUndefined()) { RemoveFromParentChildWindows(); parent_window_.Reset(); @@ -1132,7 +1132,7 @@ void BaseWindow::RemoveFromParentChildWindows() { v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin::Handle parent; + gin_helper::Handle parent; if (!gin::ConvertFromV8(isolate, GetParentWindow(), &parent) || parent.IsEmpty()) { return; diff --git a/shell/browser/api/electron_api_base_window.h b/shell/browser/api/electron_api_base_window.h index 3aff31d9054c..53ddd8cee191 100644 --- a/shell/browser/api/electron_api_base_window.h +++ b/shell/browser/api/electron_api_base_window.h @@ -98,7 +98,7 @@ class BaseWindow : public gin_helper::TrackableObject, #endif // Public APIs of NativeWindow. - void SetContentView(gin::Handle view); + void SetContentView(gin_helper::Handle view); void Close(); virtual void CloseImmediately(); virtual void Focus(); diff --git a/shell/browser/api/electron_api_browser_window.cc b/shell/browser/api/electron_api_browser_window.cc index 625c4229845a..943530e697e4 100644 --- a/shell/browser/api/electron_api_browser_window.cc +++ b/shell/browser/api/electron_api_browser_window.cc @@ -65,14 +65,14 @@ BrowserWindow::BrowserWindow(gin::Arguments* args, web_preferences.Set(options::kShow, true); // Creates the WebContentsView. - gin::Handle web_contents_view = + gin_helper::Handle web_contents_view = WebContentsView::Create(isolate, web_preferences); DCHECK(web_contents_view.get()); window()->AddDraggableRegionProvider(web_contents_view.get()); web_contents_view_.Reset(isolate, web_contents_view.ToV8()); // Save a reference of the WebContents. - gin::Handle web_contents = + gin_helper::Handle web_contents = web_contents_view->GetWebContents(isolate); web_contents_.Reset(isolate, web_contents.ToV8()); api_web_contents_ = web_contents->GetWeakPtr(); @@ -211,7 +211,7 @@ void BrowserWindow::CloseImmediately() { // Close all child windows before closing current window. v8::HandleScope handle_scope(isolate()); for (v8::Local value : GetChildWindows()) { - gin::Handle child; + gin_helper::Handle child; if (gin::ConvertFromV8(isolate(), value, &child) && !child.IsEmpty()) child->window()->CloseImmediately(); } diff --git a/shell/browser/api/electron_api_cookies.cc b/shell/browser/api/electron_api_cookies.cc index 780278588f31..c9ef35106eb2 100644 --- a/shell/browser/api/electron_api_cookies.cc +++ b/shell/browser/api/electron_api_cookies.cc @@ -17,7 +17,6 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/storage_partition.h" #include "gin/dictionary.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "net/cookies/canonical_cookie.h" #include "net/cookies/cookie_change_dispatcher.h" @@ -30,6 +29,7 @@ #include "shell/common/gin_converters/gurl_converter.h" #include "shell/common/gin_converters/value_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/gin_helper/promise.h" @@ -442,9 +442,10 @@ void Cookies::OnCookieChanged(const net::CookieChangeInfo& change) { } // static -gin::Handle Cookies::Create(v8::Isolate* isolate, - ElectronBrowserContext* browser_context) { - return gin::CreateHandle(isolate, new Cookies{browser_context}); +gin_helper::Handle Cookies::Create( + v8::Isolate* isolate, + ElectronBrowserContext* browser_context) { + return gin_helper::CreateHandle(isolate, new Cookies{browser_context}); } gin::ObjectTemplateBuilder Cookies::GetObjectTemplateBuilder( diff --git a/shell/browser/api/electron_api_cookies.h b/shell/browser/api/electron_api_cookies.h index 4a6a52c97204..53261f35a4b6 100644 --- a/shell/browser/api/electron_api_cookies.h +++ b/shell/browser/api/electron_api_cookies.h @@ -15,13 +15,10 @@ class GURL; -namespace gin { -template -class Handle; -} // namespace gin - namespace gin_helper { class Dictionary; +template +class Handle; } // namespace gin_helper namespace net { @@ -37,8 +34,9 @@ namespace api { class Cookies final : public gin_helper::DeprecatedWrappable, public gin_helper::EventEmitterMixin { public: - static gin::Handle Create(v8::Isolate* isolate, - ElectronBrowserContext* browser_context); + static gin_helper::Handle Create( + v8::Isolate* isolate, + ElectronBrowserContext* browser_context); // gin_helper::Wrappable static gin::DeprecatedWrapperInfo kWrapperInfo; diff --git a/shell/browser/api/electron_api_data_pipe_holder.cc b/shell/browser/api/electron_api_data_pipe_holder.cc index 05dec182d450..672ae1c9ffbc 100644 --- a/shell/browser/api/electron_api_data_pipe_holder.cc +++ b/shell/browser/api/electron_api_data_pipe_holder.cc @@ -11,10 +11,10 @@ #include "base/no_destructor.h" #include "base/strings/string_number_conversions.h" #include "base/task/sequenced_task_runner.h" -#include "gin/handle.h" #include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/simple_watcher.h" #include "net/base/net_errors.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/key_weak_map.h" #include "shell/common/node_util.h" @@ -171,21 +171,21 @@ const char* DataPipeHolder::GetTypeName() { } // static -gin::Handle DataPipeHolder::Create( +gin_helper::Handle DataPipeHolder::Create( v8::Isolate* isolate, const network::DataElement& element) { - auto handle = gin::CreateHandle(isolate, new DataPipeHolder(element)); + auto handle = gin_helper::CreateHandle(isolate, new DataPipeHolder(element)); AllDataPipeHolders().Set(isolate, handle->id(), handle->GetWrapper(isolate).ToLocalChecked()); return handle; } // static -gin::Handle DataPipeHolder::From(v8::Isolate* isolate, - const std::string& id) { +gin_helper::Handle DataPipeHolder::From(v8::Isolate* isolate, + const std::string& id) { v8::MaybeLocal object = AllDataPipeHolders().Get(isolate, id); if (!object.IsEmpty()) { - gin::Handle handle; + gin_helper::Handle handle; if (gin::ConvertFromV8(isolate, object.ToLocalChecked(), &handle)) return handle; } diff --git a/shell/browser/api/electron_api_data_pipe_holder.h b/shell/browser/api/electron_api_data_pipe_holder.h index 22bbf0c28a37..491343867524 100644 --- a/shell/browser/api/electron_api_data_pipe_holder.h +++ b/shell/browser/api/electron_api_data_pipe_holder.h @@ -12,10 +12,10 @@ #include "services/network/public/mojom/data_pipe_getter.mojom.h" #include "shell/common/gin_helper/wrappable.h" -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron::api { @@ -27,11 +27,11 @@ class DataPipeHolder final static gin::DeprecatedWrapperInfo kWrapperInfo; const char* GetTypeName() override; - static gin::Handle Create( + static gin_helper::Handle Create( v8::Isolate* isolate, const network::DataElement& element); - static gin::Handle From(v8::Isolate* isolate, - const std::string& id); + static gin_helper::Handle From(v8::Isolate* isolate, + const std::string& id); // Read all data at once. // diff --git a/shell/browser/api/electron_api_debugger.cc b/shell/browser/api/electron_api_debugger.cc index 37a8aae71dc8..b76063916627 100644 --- a/shell/browser/api/electron_api_debugger.cc +++ b/shell/browser/api/electron_api_debugger.cc @@ -13,11 +13,11 @@ #include "base/json/json_writer.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/web_contents.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "gin/per_isolate_data.h" #include "shell/browser/javascript_environment.h" #include "shell/common/gin_converters/value_converter.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/promise.h" using content::DevToolsAgentHost; @@ -178,9 +178,10 @@ void Debugger::ClearPendingRequests() { } // static -gin::Handle Debugger::Create(v8::Isolate* isolate, - content::WebContents* web_contents) { - return gin::CreateHandle(isolate, new Debugger(isolate, web_contents)); +gin_helper::Handle Debugger::Create( + v8::Isolate* isolate, + content::WebContents* web_contents) { + return gin_helper::CreateHandle(isolate, new Debugger(isolate, web_contents)); } gin::ObjectTemplateBuilder Debugger::GetObjectTemplateBuilder( diff --git a/shell/browser/api/electron_api_debugger.h b/shell/browser/api/electron_api_debugger.h index f9d82997e545..4a017244d361 100644 --- a/shell/browser/api/electron_api_debugger.h +++ b/shell/browser/api/electron_api_debugger.h @@ -37,8 +37,9 @@ class Debugger final : public gin_helper::DeprecatedWrappable, public content::DevToolsAgentHostClient, private content::WebContentsObserver { public: - static gin::Handle Create(v8::Isolate* isolate, - content::WebContents* web_contents); + static gin_helper::Handle Create( + v8::Isolate* isolate, + content::WebContents* web_contents); // gin_helper::Wrappable static gin::DeprecatedWrapperInfo kWrapperInfo; diff --git a/shell/browser/api/electron_api_desktop_capturer.cc b/shell/browser/api/electron_api_desktop_capturer.cc index b1ed74eb7f08..36d930ea6a6b 100644 --- a/shell/browser/api/electron_api_desktop_capturer.cc +++ b/shell/browser/api/electron_api_desktop_capturer.cc @@ -17,13 +17,13 @@ #include "chrome/browser/media/webrtc/window_icon_util.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/desktop_capture.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/javascript_environment.h" #include "shell/common/api/electron_api_native_image.h" #include "shell/common/gin_converters/gfx_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/event_emitter_caller.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/node_includes.h" #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" @@ -504,8 +504,9 @@ void DesktopCapturer::HandleFailure() { } // static -gin::Handle DesktopCapturer::Create(v8::Isolate* isolate) { - auto handle = gin::CreateHandle(isolate, new DesktopCapturer(isolate)); +gin_helper::Handle DesktopCapturer::Create( + v8::Isolate* isolate) { + auto handle = gin_helper::CreateHandle(isolate, new DesktopCapturer(isolate)); // Keep reference alive until capturing has finished. handle->Pin(isolate); diff --git a/shell/browser/api/electron_api_desktop_capturer.h b/shell/browser/api/electron_api_desktop_capturer.h index c5953eb45d5c..459c97425d9b 100644 --- a/shell/browser/api/electron_api_desktop_capturer.h +++ b/shell/browser/api/electron_api_desktop_capturer.h @@ -14,10 +14,10 @@ #include "shell/common/gin_helper/pinnable.h" #include "shell/common/gin_helper/wrappable.h" -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron::api { @@ -35,7 +35,7 @@ class DesktopCapturer final bool fetch_icon = false; }; - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); static bool IsDisplayMediaSystemPickerAvailable(); diff --git a/shell/browser/api/electron_api_download_item.cc b/shell/browser/api/electron_api_download_item.cc index 5407b580bbfd..bbbaea52519e 100644 --- a/shell/browser/api/electron_api_download_item.cc +++ b/shell/browser/api/electron_api_download_item.cc @@ -7,13 +7,13 @@ #include #include "base/strings/utf_string_conversions.h" -#include "gin/handle.h" #include "net/base/filename_util.h" #include "shell/browser/electron_browser_main_parts.h" #include "shell/common/gin_converters/file_dialog_converter.h" #include "shell/common/gin_converters/file_path_converter.h" #include "shell/common/gin_converters/gurl_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 "url/gurl.h" @@ -307,14 +307,15 @@ const char* DownloadItem::GetTypeName() { } // static -gin::Handle DownloadItem::FromOrCreate( +gin_helper::Handle DownloadItem::FromOrCreate( v8::Isolate* isolate, download::DownloadItem* item) { DownloadItem* existing = FromDownloadItem(item); if (existing) - return gin::CreateHandle(isolate, existing); + return gin_helper::CreateHandle(isolate, existing); - auto handle = gin::CreateHandle(isolate, new DownloadItem(isolate, item)); + auto handle = + gin_helper::CreateHandle(isolate, new DownloadItem(isolate, item)); handle->Pin(isolate); diff --git a/shell/browser/api/electron_api_download_item.h b/shell/browser/api/electron_api_download_item.h index 9a4ac3ad1ee8..fba240c1492e 100644 --- a/shell/browser/api/electron_api_download_item.h +++ b/shell/browser/api/electron_api_download_item.h @@ -18,10 +18,10 @@ class GURL; -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron::api { @@ -30,8 +30,9 @@ class DownloadItem final : public gin_helper::DeprecatedWrappable, public gin_helper::EventEmitterMixin, private download::DownloadItem::Observer { public: - static gin::Handle FromOrCreate(v8::Isolate* isolate, - download::DownloadItem* item); + static gin_helper::Handle FromOrCreate( + v8::Isolate* isolate, + download::DownloadItem* item); static DownloadItem* FromDownloadItem(download::DownloadItem* item); diff --git a/shell/browser/api/electron_api_extensions.cc b/shell/browser/api/electron_api_extensions.cc index 0414138b12a0..d1ee396da503 100644 --- a/shell/browser/api/electron_api_extensions.cc +++ b/shell/browser/api/electron_api_extensions.cc @@ -7,7 +7,6 @@ #include "chrome/browser/browser_process.h" #include "extensions/browser/extension_registry.h" #include "gin/data_object_builder.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/api/electron_api_extensions.h" #include "shell/browser/electron_browser_context.h" @@ -18,6 +17,7 @@ #include "shell/common/gin_converters/gurl_converter.h" #include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/node_util.h" @@ -36,10 +36,11 @@ Extensions::~Extensions() { } // static -gin::Handle Extensions::Create( +gin_helper::Handle Extensions::Create( v8::Isolate* isolate, ElectronBrowserContext* browser_context) { - return gin::CreateHandle(isolate, new Extensions(isolate, browser_context)); + return gin_helper::CreateHandle(isolate, + new Extensions(isolate, browser_context)); } v8::Local Extensions::LoadExtension( diff --git a/shell/browser/api/electron_api_extensions.h b/shell/browser/api/electron_api_extensions.h index f4cc15161401..eab97a69e78a 100644 --- a/shell/browser/api/electron_api_extensions.h +++ b/shell/browser/api/electron_api_extensions.h @@ -11,10 +11,10 @@ #include "shell/browser/event_emitter_mixin.h" #include "shell/common/gin_helper/wrappable.h" -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron { @@ -26,7 +26,7 @@ class Extensions final : public gin_helper::DeprecatedWrappable, public gin_helper::EventEmitterMixin, private extensions::ExtensionRegistryObserver { public: - static gin::Handle Create( + static gin_helper::Handle Create( v8::Isolate* isolate, ElectronBrowserContext* browser_context); diff --git a/shell/browser/api/electron_api_global_shortcut.cc b/shell/browser/api/electron_api_global_shortcut.cc index 22f1f1008ba1..2ae2f853f70e 100644 --- a/shell/browser/api/electron_api_global_shortcut.cc +++ b/shell/browser/api/electron_api_global_shortcut.cc @@ -15,12 +15,12 @@ #include "electron/shell/common/electron_constants.h" #include "extensions/common/command.h" #include "gin/dictionary.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/api/electron_api_system_preferences.h" #include "shell/browser/browser.h" #include "shell/common/gin_converters/accelerator_converter.h" #include "shell/common/gin_converters/callback_converter.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/node_includes.h" #if BUILDFLAG(IS_MAC) @@ -219,8 +219,9 @@ void GlobalShortcut::UnregisterAll() { } // static -gin::Handle GlobalShortcut::Create(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, new GlobalShortcut()); +gin_helper::Handle GlobalShortcut::Create( + v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, new GlobalShortcut()); } // static diff --git a/shell/browser/api/electron_api_global_shortcut.h b/shell/browser/api/electron_api_global_shortcut.h index 6500cbcdae02..a7f42c445d1b 100644 --- a/shell/browser/api/electron_api_global_shortcut.h +++ b/shell/browser/api/electron_api_global_shortcut.h @@ -14,10 +14,10 @@ #include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/global_accelerator_listener/global_accelerator_listener.h" -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron::api { @@ -25,7 +25,7 @@ class GlobalShortcut final : private ui::GlobalAcceleratorListener::Observer, public gin_helper::DeprecatedWrappable { public: - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); // gin_helper::Wrappable static gin::DeprecatedWrapperInfo kWrapperInfo; diff --git a/shell/browser/api/electron_api_in_app_purchase.cc b/shell/browser/api/electron_api_in_app_purchase.cc index ca3df5b56594..fe95d984f6de 100644 --- a/shell/browser/api/electron_api_in_app_purchase.cc +++ b/shell/browser/api/electron_api_in_app_purchase.cc @@ -8,8 +8,8 @@ #include #include -#include "gin/handle.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/gin_helper/promise.h" #include "shell/common/node_includes.h" @@ -135,8 +135,8 @@ gin::DeprecatedWrapperInfo InAppPurchase::kWrapperInfo = { #if BUILDFLAG(IS_MAC) // static -gin::Handle InAppPurchase::Create(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, new InAppPurchase()); +gin_helper::Handle InAppPurchase::Create(v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, new InAppPurchase()); } gin::ObjectTemplateBuilder InAppPurchase::GetObjectTemplateBuilder( diff --git a/shell/browser/api/electron_api_in_app_purchase.h b/shell/browser/api/electron_api_in_app_purchase.h index 4af31903aab8..67ac9e2b350f 100644 --- a/shell/browser/api/electron_api_in_app_purchase.h +++ b/shell/browser/api/electron_api_in_app_purchase.h @@ -15,10 +15,10 @@ #include "shell/common/gin_helper/wrappable.h" #include "v8/include/v8-forward.h" -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron::api { @@ -27,7 +27,7 @@ class InAppPurchase final public gin_helper::EventEmitterMixin, private in_app_purchase::TransactionObserver { public: - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); // gin_helper::Wrappable static gin::DeprecatedWrapperInfo kWrapperInfo; diff --git a/shell/browser/api/electron_api_menu.h b/shell/browser/api/electron_api_menu.h index 6e2de66e4b9d..ba92e230e3f4 100644 --- a/shell/browser/api/electron_api_menu.h +++ b/shell/browser/api/electron_api_menu.h @@ -33,7 +33,7 @@ class Menu : public gin_helper::DeprecatedWrappable, private ElectronMenuModel::Observer { public: // gin_helper::Constructible - static gin::Handle New(gin::Arguments* args); + static gin_helper::Handle New(gin::Arguments* args); static void FillObjectTemplate(v8::Isolate*, v8::Local); static const char* GetClassName() { return "Menu"; } diff --git a/shell/browser/api/electron_api_menu_mac.mm b/shell/browser/api/electron_api_menu_mac.mm index 76a34b1a6a7f..a70725d983d9 100644 --- a/shell/browser/api/electron_api_menu_mac.mm +++ b/shell/browser/api/electron_api_menu_mac.mm @@ -288,9 +288,9 @@ void Menu::SendActionToFirstResponder(const std::string& action) { } // static -gin::Handle Menu::New(gin::Arguments* args) { - auto handle = - gin::CreateHandle(args->isolate(), static_cast(new MenuMac(args))); +gin_helper::Handle Menu::New(gin::Arguments* args) { + auto handle = gin_helper::CreateHandle(args->isolate(), + static_cast(new MenuMac(args))); gin_helper::CallMethod(args->isolate(), handle.get(), "_init"); return handle; } diff --git a/shell/browser/api/electron_api_menu_views.cc b/shell/browser/api/electron_api_menu_views.cc index e760e06bc4cc..8a496f9f8587 100644 --- a/shell/browser/api/electron_api_menu_views.cc +++ b/shell/browser/api/electron_api_menu_views.cc @@ -84,9 +84,9 @@ void MenuViews::OnClosed(int32_t window_id, base::OnceClosure callback) { } // static -gin::Handle Menu::New(gin::Arguments* args) { - auto handle = gin::CreateHandle(args->isolate(), - static_cast(new MenuViews(args))); +gin_helper::Handle Menu::New(gin::Arguments* args) { + auto handle = gin_helper::CreateHandle( + args->isolate(), static_cast(new MenuViews(args))); gin_helper::CallMethod(args->isolate(), handle.get(), "_init"); return handle; } diff --git a/shell/browser/api/electron_api_native_theme.cc b/shell/browser/api/electron_api_native_theme.cc index 6fbadcf4f0f4..adccf5f8e50b 100644 --- a/shell/browser/api/electron_api_native_theme.cc +++ b/shell/browser/api/electron_api_native_theme.cc @@ -8,9 +8,9 @@ #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" -#include "gin/handle.h" #include "shell/common/gin_converters/std_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/native_theme/native_theme.h" @@ -98,11 +98,11 @@ bool NativeTheme::ShouldUseInvertedColorScheme() { } // static -gin::Handle NativeTheme::Create(v8::Isolate* isolate) { +gin_helper::Handle NativeTheme::Create(v8::Isolate* isolate) { ui::NativeTheme* ui_theme = ui::NativeTheme::GetInstanceForNativeUi(); ui::NativeTheme* web_theme = ui::NativeTheme::GetInstanceForWeb(); - return gin::CreateHandle(isolate, - new NativeTheme(isolate, ui_theme, web_theme)); + return gin_helper::CreateHandle( + isolate, new NativeTheme(isolate, ui_theme, web_theme)); } gin::ObjectTemplateBuilder NativeTheme::GetObjectTemplateBuilder( diff --git a/shell/browser/api/electron_api_native_theme.h b/shell/browser/api/electron_api_native_theme.h index 8bcfd57f93b1..04351ffb944a 100644 --- a/shell/browser/api/electron_api_native_theme.h +++ b/shell/browser/api/electron_api_native_theme.h @@ -11,10 +11,10 @@ #include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme_observer.h" -namespace gin { +namespace gin_helper { template -class handle; -} // namespace gin +class Handle; +} // namespace gin_helper namespace electron::api { @@ -22,7 +22,7 @@ class NativeTheme final : public gin_helper::DeprecatedWrappable, public gin_helper::EventEmitterMixin, private ui::NativeThemeObserver { public: - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); // gin_helper::Wrappable static gin::DeprecatedWrapperInfo kWrapperInfo; diff --git a/shell/browser/api/electron_api_net_log.cc b/shell/browser/api/electron_api_net_log.cc index 5dd60751ca93..29c04d585ea2 100644 --- a/shell/browser/api/electron_api_net_log.cc +++ b/shell/browser/api/electron_api_net_log.cc @@ -15,13 +15,13 @@ #include "components/net_log/chrome_net_log.h" #include "content/public/browser/storage_partition.h" #include "electron/electron_version.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "net/log/net_log_capture_mode.h" #include "shell/browser/electron_browser_context.h" #include "shell/browser/net/system_network_context_manager.h" #include "shell/common/gin_converters/file_path_converter.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/handle.h" namespace gin { @@ -231,9 +231,11 @@ const char* NetLog::GetTypeName() { } // static -gin::Handle NetLog::Create(v8::Isolate* isolate, - ElectronBrowserContext* browser_context) { - return gin::CreateHandle(isolate, new NetLog(isolate, browser_context)); +gin_helper::Handle NetLog::Create( + v8::Isolate* isolate, + ElectronBrowserContext* browser_context) { + return gin_helper::CreateHandle(isolate, + new NetLog(isolate, browser_context)); } } // namespace api diff --git a/shell/browser/api/electron_api_net_log.h b/shell/browser/api/electron_api_net_log.h index 846b3bdf8989..d056ad3062e3 100644 --- a/shell/browser/api/electron_api_net_log.h +++ b/shell/browser/api/electron_api_net_log.h @@ -23,10 +23,12 @@ class TaskRunner; namespace gin { class Arguments; +} // namespace gin +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron { @@ -37,8 +39,9 @@ namespace api { // The code is referenced from the net_log::NetExportFileWriter class. class NetLog final : public gin_helper::DeprecatedWrappable { public: - static gin::Handle Create(v8::Isolate* isolate, - ElectronBrowserContext* browser_context); + static gin_helper::Handle Create( + v8::Isolate* isolate, + ElectronBrowserContext* browser_context); v8::Local StartLogging(base::FilePath log_path, gin::Arguments* args); diff --git a/shell/browser/api/electron_api_notification.cc b/shell/browser/api/electron_api_notification.cc index 6ceae2e950fb..9229abe86f0a 100644 --- a/shell/browser/api/electron_api_notification.cc +++ b/shell/browser/api/electron_api_notification.cc @@ -5,13 +5,13 @@ #include "shell/browser/api/electron_api_notification.h" #include "base/uuid.h" -#include "gin/handle.h" #include "shell/browser/api/electron_api_menu.h" #include "shell/browser/browser.h" #include "shell/browser/electron_browser_client.h" #include "shell/common/gin_converters/image_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" #include "url/gurl.h" @@ -78,13 +78,14 @@ Notification::~Notification() { } // static -gin::Handle Notification::New(gin_helper::ErrorThrower thrower, - gin::Arguments* args) { +gin_helper::Handle Notification::New( + gin_helper::ErrorThrower thrower, + gin::Arguments* args) { if (!Browser::Get()->is_ready()) { thrower.ThrowError("Cannot create Notification before app is ready"); return {}; } - return gin::CreateHandle(thrower.isolate(), new Notification(args)); + return gin_helper::CreateHandle(thrower.isolate(), new Notification(args)); } // Setters diff --git a/shell/browser/api/electron_api_notification.h b/shell/browser/api/electron_api_notification.h index dbe45939241c..9d9201e0f981 100644 --- a/shell/browser/api/electron_api_notification.h +++ b/shell/browser/api/electron_api_notification.h @@ -20,12 +20,12 @@ namespace gin { class Arguments; -template -class Handle; } // namespace gin namespace gin_helper { class ErrorThrower; +template +class Handle; } // namespace gin_helper namespace electron::api { @@ -39,8 +39,8 @@ class Notification final : public gin_helper::DeprecatedWrappable, static bool IsSupported(); // gin_helper::Constructible - static gin::Handle New(gin_helper::ErrorThrower thrower, - gin::Arguments* args); + static gin_helper::Handle New(gin_helper::ErrorThrower thrower, + gin::Arguments* args); static void FillObjectTemplate(v8::Isolate*, v8::Local); static const char* GetClassName() { return "Notification"; } diff --git a/shell/browser/api/electron_api_power_monitor.cc b/shell/browser/api/electron_api_power_monitor.cc index 1d723bf492f4..5956489ab4ee 100644 --- a/shell/browser/api/electron_api_power_monitor.cc +++ b/shell/browser/api/electron_api_power_monitor.cc @@ -8,11 +8,11 @@ #include "base/power_monitor/power_monitor_device_source.h" #include "base/power_monitor/power_observer.h" #include "gin/data_object_builder.h" -#include "gin/handle.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" @@ -144,7 +144,7 @@ void PowerMonitor::SetListeningForShutdown(bool is_listening) { // static v8::Local PowerMonitor::Create(v8::Isolate* isolate) { auto* pm = new PowerMonitor(isolate); - auto handle = gin::CreateHandle(isolate, pm).ToV8(); + auto handle = gin_helper::CreateHandle(isolate, pm).ToV8(); pm->Pin(isolate); return handle; } diff --git a/shell/browser/api/electron_api_power_save_blocker.cc b/shell/browser/api/electron_api_power_save_blocker.cc index eea85095573e..57995578704f 100644 --- a/shell/browser/api/electron_api_power_save_blocker.cc +++ b/shell/browser/api/electron_api_power_save_blocker.cc @@ -10,11 +10,11 @@ #include "content/public/browser/device_service.h" #include "gin/dictionary.h" #include "gin/function_template.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "services/device/public/mojom/wake_lock_provider.mojom.h" #include "services/service_manager/public/cpp/connector.h" #include "shell/browser/javascript_environment.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/node_includes.h" namespace gin { @@ -115,8 +115,9 @@ bool PowerSaveBlocker::IsStarted(int id) const { } // static -gin::Handle PowerSaveBlocker::Create(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, new PowerSaveBlocker(isolate)); +gin_helper::Handle PowerSaveBlocker::Create( + v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, new PowerSaveBlocker(isolate)); } gin::ObjectTemplateBuilder PowerSaveBlocker::GetObjectTemplateBuilder( diff --git a/shell/browser/api/electron_api_power_save_blocker.h b/shell/browser/api/electron_api_power_save_blocker.h index 9eb20d5e41bc..ae7d8c2cbfdd 100644 --- a/shell/browser/api/electron_api_power_save_blocker.h +++ b/shell/browser/api/electron_api_power_save_blocker.h @@ -12,17 +12,19 @@ namespace gin { class ObjectTemplateBuilder; +} // namespace gin +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron::api { class PowerSaveBlocker final : public gin_helper::DeprecatedWrappable { public: - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); // gin_helper::Wrappable static gin::DeprecatedWrapperInfo kWrapperInfo; diff --git a/shell/browser/api/electron_api_protocol.cc b/shell/browser/api/electron_api_protocol.cc index 98307d5a9072..1d1f1a209ec8 100644 --- a/shell/browser/api/electron_api_protocol.cc +++ b/shell/browser/api/electron_api_protocol.cc @@ -11,7 +11,6 @@ #include "base/containers/contains.h" #include "content/common/url_schemes.h" #include "content/public/browser/child_process_security_policy.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/browser.h" #include "shell/browser/javascript_environment.h" @@ -19,6 +18,7 @@ #include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/net_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/gin_helper/promise.h" #include "shell/common/node_includes.h" @@ -288,13 +288,14 @@ void Protocol::HandleOptionalCallback(gin::Arguments* args, Error error) { } // static -gin::Handle Protocol::Create(v8::Isolate* isolate, - ProtocolRegistry* protocol_registry) { - return gin::CreateHandle(isolate, new Protocol{protocol_registry}); +gin_helper::Handle Protocol::Create( + v8::Isolate* isolate, + ProtocolRegistry* protocol_registry) { + return gin_helper::CreateHandle(isolate, new Protocol{protocol_registry}); } // static -gin::Handle Protocol::New(gin_helper::ErrorThrower thrower) { +gin_helper::Handle Protocol::New(gin_helper::ErrorThrower thrower) { thrower.ThrowError("Protocol cannot be created from JS"); return {}; } diff --git a/shell/browser/api/electron_api_protocol.h b/shell/browser/api/electron_api_protocol.h index 08c4ce7792a7..dfb935c17563 100644 --- a/shell/browser/api/electron_api_protocol.h +++ b/shell/browser/api/electron_api_protocol.h @@ -16,9 +16,12 @@ namespace gin { class Arguments; +} // namespace gin + +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron { @@ -38,11 +41,12 @@ void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower, class Protocol final : public gin_helper::DeprecatedWrappable, public gin_helper::Constructible { public: - static gin::Handle Create(v8::Isolate* isolate, - ProtocolRegistry* protocol_registry); + static gin_helper::Handle Create( + v8::Isolate* isolate, + ProtocolRegistry* protocol_registry); // gin_helper::Constructible - static gin::Handle New(gin_helper::ErrorThrower thrower); + static gin_helper::Handle New(gin_helper::ErrorThrower thrower); static v8::Local FillObjectTemplate( v8::Isolate* isolate, v8::Local tmpl); diff --git a/shell/browser/api/electron_api_push_notifications.cc b/shell/browser/api/electron_api_push_notifications.cc index 55fa9e1a190a..0dc6501d7894 100644 --- a/shell/browser/api/electron_api_push_notifications.cc +++ b/shell/browser/api/electron_api_push_notifications.cc @@ -4,9 +4,9 @@ #include "shell/browser/api/electron_api_push_notifications.h" -#include "gin/handle.h" #include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/node_includes.h" namespace electron::api { @@ -30,8 +30,9 @@ PushNotifications* PushNotifications::Get() { } // static -gin::Handle PushNotifications::Create(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, PushNotifications::Get()); +gin_helper::Handle PushNotifications::Create( + v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, PushNotifications::Get()); } // static diff --git a/shell/browser/api/electron_api_push_notifications.h b/shell/browser/api/electron_api_push_notifications.h index b813a904f749..a9e7161dba20 100644 --- a/shell/browser/api/electron_api_push_notifications.h +++ b/shell/browser/api/electron_api_push_notifications.h @@ -14,10 +14,10 @@ #include "shell/common/gin_helper/promise.h" #include "shell/common/gin_helper/wrappable.h" -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron::api { @@ -28,7 +28,7 @@ class PushNotifications final private BrowserObserver { public: static PushNotifications* Get(); - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); // gin_helper::Wrappable static gin::DeprecatedWrapperInfo kWrapperInfo; diff --git a/shell/browser/api/electron_api_screen.cc b/shell/browser/api/electron_api_screen.cc index cdd0a888dfa6..5dc8389480ea 100644 --- a/shell/browser/api/electron_api_screen.cc +++ b/shell/browser/api/electron_api_screen.cc @@ -8,13 +8,13 @@ #include #include "base/functional/bind.h" -#include "gin/handle.h" #include "shell/browser/browser.h" #include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/gfx_converter.h" #include "shell/common/gin_converters/native_window_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.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/display/display.h" @@ -185,8 +185,8 @@ v8::Local Screen::Create(gin_helper::ErrorThrower error_thrower) { return v8::Null(error_thrower.isolate()); } - return gin::CreateHandle(error_thrower.isolate(), - new Screen(error_thrower.isolate(), screen)) + return gin_helper::CreateHandle(error_thrower.isolate(), + new Screen(error_thrower.isolate(), screen)) .ToV8(); } diff --git a/shell/browser/api/electron_api_service_worker_context.cc b/shell/browser/api/electron_api_service_worker_context.cc index f049b9bbdf44..86cae2c03954 100644 --- a/shell/browser/api/electron_api_service_worker_context.cc +++ b/shell/browser/api/electron_api_service_worker_context.cc @@ -12,7 +12,6 @@ #include "content/public/browser/console_message.h" #include "content/public/browser/storage_partition.h" #include "gin/data_object_builder.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/api/electron_api_service_worker_main.h" #include "shell/browser/electron_browser_context.h" @@ -21,6 +20,7 @@ #include "shell/common/gin_converters/service_worker_converter.h" #include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/node_util.h" @@ -210,14 +210,14 @@ v8::Local ServiceWorkerContext::GetWorkerFromVersionID( .ToV8(); } -gin::Handle +gin_helper::Handle ServiceWorkerContext::GetWorkerFromVersionIDIfExists(v8::Isolate* isolate, int64_t version_id) { ServiceWorkerMain* worker = ServiceWorkerMain::FromVersionID(version_id, storage_partition_); if (!worker) - return gin::Handle(); - return gin::CreateHandle(isolate, worker); + return gin_helper::Handle(); + return gin_helper::CreateHandle(isolate, worker); } v8::Local ServiceWorkerContext::StartWorkerForScope( @@ -272,11 +272,11 @@ v8::Local ServiceWorkerContext::StopAllWorkers( } // static -gin::Handle ServiceWorkerContext::Create( +gin_helper::Handle ServiceWorkerContext::Create( v8::Isolate* isolate, ElectronBrowserContext* browser_context) { - return gin::CreateHandle(isolate, - new ServiceWorkerContext(isolate, browser_context)); + return gin_helper::CreateHandle( + isolate, new ServiceWorkerContext(isolate, browser_context)); } // static diff --git a/shell/browser/api/electron_api_service_worker_context.h b/shell/browser/api/electron_api_service_worker_context.h index b8a08ea13955..15605ea197cb 100644 --- a/shell/browser/api/electron_api_service_worker_context.h +++ b/shell/browser/api/electron_api_service_worker_context.h @@ -16,12 +16,9 @@ namespace content { class StoragePartition; } -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin - -namespace gin_helper { template class Promise; } // namespace gin_helper @@ -39,7 +36,7 @@ class ServiceWorkerContext final public gin_helper::EventEmitterMixin, private content::ServiceWorkerContextObserver { public: - static gin::Handle Create( + static gin_helper::Handle Create( v8::Isolate* isolate, ElectronBrowserContext* browser_context); @@ -50,7 +47,7 @@ class ServiceWorkerContext final int64_t version_id); v8::Local GetWorkerFromVersionID(v8::Isolate* isolate, int64_t version_id); - gin::Handle GetWorkerFromVersionIDIfExists( + gin_helper::Handle GetWorkerFromVersionIDIfExists( v8::Isolate* isolate, int64_t version_id); v8::Local StartWorkerForScope(v8::Isolate* isolate, GURL scope); diff --git a/shell/browser/api/electron_api_service_worker_main.cc b/shell/browser/api/electron_api_service_worker_main.cc index 4cf5791c2773..c6cc18a7cf1a 100644 --- a/shell/browser/api/electron_api_service_worker_main.cc +++ b/shell/browser/api/electron_api_service_worker_main.cc @@ -11,7 +11,6 @@ #include "base/no_destructor.h" #include "content/browser/service_worker/service_worker_context_wrapper.h" // nogncheck #include "content/browser/service_worker/service_worker_version.h" // nogncheck -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "services/service_manager/public/cpp/interface_provider.h" #include "shell/browser/api/message_port.h" @@ -23,6 +22,7 @@ #include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/node_includes.h" @@ -289,12 +289,13 @@ GURL ServiceWorkerMain::ScriptURL() const { } // static -gin::Handle ServiceWorkerMain::New(v8::Isolate* isolate) { - return gin::Handle(); +gin_helper::Handle ServiceWorkerMain::New( + v8::Isolate* isolate) { + return gin_helper::Handle(); } // static -gin::Handle ServiceWorkerMain::From( +gin_helper::Handle ServiceWorkerMain::From( v8::Isolate* isolate, content::ServiceWorkerContext* sw_context, const content::StoragePartition* storage_partition, @@ -303,15 +304,15 @@ gin::Handle ServiceWorkerMain::From( auto* service_worker = FromServiceWorkerKey(service_worker_key); if (service_worker) - return gin::CreateHandle(isolate, service_worker); + return gin_helper::CreateHandle(isolate, service_worker); // Ensure ServiceWorkerVersion exists and is not redundant (pending deletion) auto* live_version = GetLiveVersion(sw_context, version_id); if (!live_version || live_version->is_redundant()) { - return gin::Handle(); + return gin_helper::Handle(); } - auto handle = gin::CreateHandle( + auto handle = gin_helper::CreateHandle( isolate, new ServiceWorkerMain(sw_context, version_id, service_worker_key)); diff --git a/shell/browser/api/electron_api_service_worker_main.h b/shell/browser/api/electron_api_service_worker_main.h index 4807ab6fcf12..9cd79653ecb8 100644 --- a/shell/browser/api/electron_api_service_worker_main.h +++ b/shell/browser/api/electron_api_service_worker_main.h @@ -85,9 +85,9 @@ class ServiceWorkerMain final public gin_helper::Constructible { public: // Create a new ServiceWorkerMain and return the V8 wrapper of it. - static gin::Handle New(v8::Isolate* isolate); + static gin_helper::Handle New(v8::Isolate* isolate); - static gin::Handle From( + static gin_helper::Handle From( v8::Isolate* isolate, content::ServiceWorkerContext* sw_context, const content::StoragePartition* storage_partition, diff --git a/shell/browser/api/electron_api_session.cc b/shell/browser/api/electron_api_session.cc index 582515e2673d..e6c24a092e9d 100644 --- a/shell/browser/api/electron_api_session.cc +++ b/shell/browser/api/electron_api_session.cc @@ -44,7 +44,6 @@ #include "content/public/browser/storage_partition.h" #include "gin/arguments.h" #include "gin/converter.h" -#include "gin/handle.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "net/base/completion_repeating_callback.h" @@ -89,6 +88,7 @@ #include "shell/common/gin_helper/cleaned_up_at_exit.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/node_includes.h" @@ -1004,7 +1004,8 @@ bool Session::IsPersistent() { v8::Local Session::GetBlobData(v8::Isolate* isolate, const std::string& uuid) { - gin::Handle holder = DataPipeHolder::From(isolate, uuid); + gin_helper::Handle holder = + DataPipeHolder::From(isolate, uuid); if (holder.IsEmpty()) { gin_helper::Promise> promise(isolate); promise.RejectWithErrorMessage("Could not get blob data handle"); @@ -1662,15 +1663,15 @@ Session* Session::FromBrowserContext(content::BrowserContext* context) { } // static -gin::Handle Session::CreateFrom( +gin_helper::Handle Session::CreateFrom( v8::Isolate* isolate, ElectronBrowserContext* browser_context) { Session* existing = FromBrowserContext(browser_context); if (existing) - return gin::CreateHandle(isolate, existing); + return gin_helper::CreateHandle(isolate, existing); auto handle = - gin::CreateHandle(isolate, new Session(isolate, browser_context)); + gin_helper::CreateHandle(isolate, new Session(isolate, browser_context)); // The Sessions should never be garbage collected, since the common pattern is // to use partition strings, instead of using the Session object directly. @@ -1688,9 +1689,9 @@ gin::Handle Session::CreateFrom( } // static -gin::Handle Session::FromPartition(v8::Isolate* isolate, - const std::string& partition, - base::Value::Dict options) { +gin_helper::Handle Session::FromPartition(v8::Isolate* isolate, + const std::string& partition, + base::Value::Dict options) { ElectronBrowserContext* browser_context; if (partition.empty()) { browser_context = @@ -1707,7 +1708,7 @@ gin::Handle Session::FromPartition(v8::Isolate* isolate, } // static -std::optional> Session::FromPath( +std::optional> Session::FromPath( v8::Isolate* isolate, const base::FilePath& path, base::Value::Dict options) { @@ -1731,7 +1732,7 @@ std::optional> Session::FromPath( } // static -gin::Handle Session::New() { +gin_helper::Handle Session::New() { gin_helper::ErrorThrower(JavascriptEnvironment::GetIsolate()) .ThrowError("Session objects cannot be created with 'new'"); return {}; @@ -1854,7 +1855,7 @@ v8::Local FromPath(const base::FilePath& path, } base::Value::Dict options; args->GetNext(&options); - std::optional> session_handle = + std::optional> session_handle = Session::FromPath(args->isolate(), path, std::move(options)); if (session_handle) diff --git a/shell/browser/api/electron_api_session.h b/shell/browser/api/electron_api_session.h index 02eb31c9da63..12d71ac63423 100644 --- a/shell/browser/api/electron_api_session.h +++ b/shell/browser/api/electron_api_session.h @@ -37,9 +37,12 @@ class FilePath; namespace gin { class Arguments; +} // namespace gin + +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace gin_helper { class Dictionary; @@ -69,20 +72,21 @@ class Session final : public gin_helper::DeprecatedWrappable, private content::DownloadManager::Observer { public: // Gets or creates Session from the |browser_context|. - static gin::Handle CreateFrom( + static gin_helper::Handle CreateFrom( v8::Isolate* isolate, ElectronBrowserContext* browser_context); - static gin::Handle New(); // Dummy, do not use! + static gin_helper::Handle New(); // Dummy, do not use! static Session* FromBrowserContext(content::BrowserContext* context); // Gets the Session of |partition|. - static gin::Handle FromPartition(v8::Isolate* isolate, - const std::string& partition, - base::Value::Dict options = {}); + static gin_helper::Handle FromPartition( + v8::Isolate* isolate, + const std::string& partition, + base::Value::Dict options = {}); // Gets the Session based on |path|. - static std::optional> FromPath( + static std::optional> FromPath( v8::Isolate* isolate, const base::FilePath& path, base::Value::Dict options = {}); diff --git a/shell/browser/api/electron_api_system_preferences.cc b/shell/browser/api/electron_api_system_preferences.cc index 05771ddbe681..ca3c95775973 100644 --- a/shell/browser/api/electron_api_system_preferences.cc +++ b/shell/browser/api/electron_api_system_preferences.cc @@ -4,11 +4,11 @@ #include "shell/browser/api/electron_api_system_preferences.h" -#include "gin/handle.h" #include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/node_includes.h" #include "ui/gfx/animation/animation.h" @@ -46,8 +46,9 @@ v8::Local SystemPreferences::GetAnimationSettings( } // static -gin::Handle SystemPreferences::Create(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, new SystemPreferences()); +gin_helper::Handle SystemPreferences::Create( + v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, new SystemPreferences()); } gin::ObjectTemplateBuilder SystemPreferences::GetObjectTemplateBuilder( diff --git a/shell/browser/api/electron_api_system_preferences.h b/shell/browser/api/electron_api_system_preferences.h index c2b2fdc847f3..7582a68faec1 100644 --- a/shell/browser/api/electron_api_system_preferences.h +++ b/shell/browser/api/electron_api_system_preferences.h @@ -18,10 +18,10 @@ #include "ui/gfx/sys_color_change_listener.h" #endif -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace gin_helper { class ErrorThrower; @@ -47,7 +47,7 @@ class SystemPreferences final #endif { public: - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); // gin_helper::Wrappable static gin::DeprecatedWrapperInfo kWrapperInfo; diff --git a/shell/browser/api/electron_api_tray.cc b/shell/browser/api/electron_api_tray.cc index 4c6c30008e74..c8494e4b7337 100644 --- a/shell/browser/api/electron_api_tray.cc +++ b/shell/browser/api/electron_api_tray.cc @@ -9,7 +9,6 @@ #include "base/containers/fixed_flat_map.h" #include "gin/dictionary.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/api/electron_api_menu.h" #include "shell/browser/api/ui_event.h" @@ -22,6 +21,7 @@ #include "shell/common/gin_converters/image_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/node_includes.h" namespace gin { @@ -61,10 +61,10 @@ Tray::Tray(v8::Isolate* isolate, Tray::~Tray() = default; // static -gin::Handle Tray::New(gin_helper::ErrorThrower thrower, - v8::Local image, - std::optional guid, - gin::Arguments* args) { +gin_helper::Handle Tray::New(gin_helper::ErrorThrower thrower, + v8::Local image, + std::optional guid, + gin::Arguments* args) { if (!Browser::Get()->is_ready()) { thrower.ThrowError("Cannot create Tray before app is ready"); return {}; @@ -88,7 +88,7 @@ gin::Handle Tray::New(gin_helper::ErrorThrower thrower, return {}; } - auto handle = gin::CreateHandle(args->isolate(), tray); + auto handle = gin_helper::CreateHandle(args->isolate(), tray); handle->Pin(args->isolate()); return handle; } @@ -342,7 +342,7 @@ void Tray::Focus() { void Tray::PopUpContextMenu(gin::Arguments* args) { if (!CheckAlive()) return; - gin::Handle menu; + gin_helper::Handle menu; gfx::Point pos; v8::Local first_arg; @@ -374,7 +374,7 @@ void Tray::SetContextMenu(gin_helper::ErrorThrower thrower, v8::Local arg) { if (!CheckAlive()) return; - gin::Handle menu; + gin_helper::Handle menu; if (arg->IsNull()) { menu_.Reset(); tray_icon_->SetContextMenu(nullptr); diff --git a/shell/browser/api/electron_api_tray.h b/shell/browser/api/electron_api_tray.h index 25094341edb0..94128348f0dd 100644 --- a/shell/browser/api/electron_api_tray.h +++ b/shell/browser/api/electron_api_tray.h @@ -24,14 +24,11 @@ class Image; class Image; } // namespace gfx -namespace gin { -template -class Handle; -} // namespace gin - namespace gin_helper { class Dictionary; class ErrorThrower; +template +class Handle; } // namespace gin_helper namespace electron::api { @@ -46,10 +43,10 @@ class Tray final : public gin_helper::DeprecatedWrappable, private TrayIconObserver { public: // gin_helper::Constructible - static gin::Handle New(gin_helper::ErrorThrower thrower, - v8::Local image, - std::optional guid, - gin::Arguments* args); + static gin_helper::Handle New(gin_helper::ErrorThrower thrower, + v8::Local image, + std::optional guid, + gin::Arguments* args); static void FillObjectTemplate(v8::Isolate*, v8::Local); static const char* GetClassName() { return "Tray"; } diff --git a/shell/browser/api/electron_api_utility_process.cc b/shell/browser/api/electron_api_utility_process.cc index dd3b1791e732..fe6bde85eecc 100644 --- a/shell/browser/api/electron_api_utility_process.cc +++ b/shell/browser/api/electron_api_utility_process.cc @@ -17,7 +17,6 @@ #include "content/public/browser/child_process_host.h" #include "content/public/browser/service_process_host.h" #include "content/public/common/result_codes.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "shell/browser/api/message_port.h" @@ -28,6 +27,7 @@ #include "shell/common/gin_converters/file_path_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" #include "shell/common/v8_util.h" @@ -347,7 +347,7 @@ void UtilityProcessWrapper::PostMessage(gin::Arguments* args) { } v8::Local transferables; - std::vector> wrapped_ports; + std::vector> wrapped_ports; if (args->GetNext(&transferables)) { std::vector> wrapped_port_values; if (!gin::ConvertFromV8(args->isolate(), transferables, @@ -435,7 +435,7 @@ raw_ptr UtilityProcessWrapper::FromProcessId( } // static -gin::Handle UtilityProcessWrapper::Create( +gin_helper::Handle UtilityProcessWrapper::Create( gin::Arguments* args) { if (!Browser::Get()->is_ready()) { gin_helper::ErrorThrower(args->isolate()) @@ -498,7 +498,7 @@ gin::Handle UtilityProcessWrapper::Create( opts.Get("allowLoadingUnsignedLibraries", &use_plugin_helper); #endif } - auto handle = gin::CreateHandle( + auto handle = gin_helper::CreateHandle( args->isolate(), new UtilityProcessWrapper( std::move(params), display_name, std::move(stdio), env_map, current_working_directory, diff --git a/shell/browser/api/electron_api_utility_process.h b/shell/browser/api/electron_api_utility_process.h index b1bb6bc97833..c62fb967950c 100644 --- a/shell/browser/api/electron_api_utility_process.h +++ b/shell/browser/api/electron_api_utility_process.h @@ -25,9 +25,12 @@ namespace gin { class Arguments; +} // namespace gin + +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace base { class Process; @@ -51,7 +54,7 @@ class UtilityProcessWrapper final enum class IOType { IO_PIPE, IO_INHERIT, IO_IGNORE }; ~UtilityProcessWrapper() override; - static gin::Handle Create(gin::Arguments* args); + static gin_helper::Handle Create(gin::Arguments* args); static raw_ptr FromProcessId(base::ProcessId pid); void Shutdown(uint64_t exit_code); diff --git a/shell/browser/api/electron_api_view.cc b/shell/browser/api/electron_api_view.cc index c5c6c96754f1..986ec06c84fa 100644 --- a/shell/browser/api/electron_api_view.cc +++ b/shell/browser/api/electron_api_view.cc @@ -12,12 +12,12 @@ #include "ash/style/rounded_rect_cutout_path_builder.h" #include "gin/data_object_builder.h" -#include "gin/handle.h" #include "gin/wrappable.h" #include "shell/browser/javascript_environment.h" #include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/gfx_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/views/background.h" @@ -38,7 +38,7 @@ struct Converter { gin_helper::Dictionary dict; if (!gin::ConvertFromV8(isolate, val, &dict)) return false; - gin::Handle view; + gin_helper::Handle view; if (!dict.Get("view", &view)) return false; out->child_view = view->view(); @@ -184,7 +184,7 @@ View::~View() { view_.ClearAndDelete(); } -void View::ReorderChildView(gin::Handle child, size_t index) { +void View::ReorderChildView(gin_helper::Handle child, size_t index) { view_->ReorderChildView(child->view(), index); const auto i = @@ -207,7 +207,7 @@ void View::ReorderChildView(gin::Handle child, size_t index) { } } -void View::AddChildViewAt(gin::Handle child, +void View::AddChildViewAt(gin_helper::Handle child, std::optional maybe_index) { // TODO(nornagon): !view_ is only for supporting the weird case of // WebContentsView's view being deleted when the underlying WebContents is @@ -258,7 +258,7 @@ void View::AddChildViewAt(gin::Handle child, view_->AddChildViewAt(child->view(), index); } -void View::RemoveChildView(gin::Handle child) { +void View::RemoveChildView(gin_helper::Handle child) { if (!view_) return; @@ -432,11 +432,11 @@ v8::Local View::GetConstructor(v8::Isolate* isolate) { } // static -gin::Handle View::Create(v8::Isolate* isolate) { +gin_helper::Handle View::Create(v8::Isolate* isolate) { v8::Local context = isolate->GetCurrentContext(); v8::Local obj; if (GetConstructor(isolate)->NewInstance(context, 0, nullptr).ToLocal(&obj)) { - gin::Handle view; + gin_helper::Handle view; if (gin::ConvertFromV8(isolate, obj, &view)) return view; } diff --git a/shell/browser/api/electron_api_view.h b/shell/browser/api/electron_api_view.h index 298a5772a74e..2d1318e1344e 100644 --- a/shell/browser/api/electron_api_view.h +++ b/shell/browser/api/electron_api_view.h @@ -14,10 +14,10 @@ #include "ui/views/view_observer.h" #include "v8/include/v8-value.h" -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron::api { @@ -25,7 +25,7 @@ class View : public gin_helper::EventEmitter, private views::ViewObserver { public: static gin_helper::WrappableBase* New(gin::Arguments* args); - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); // Return the cached constructor function. static v8::Local GetConstructor(v8::Isolate* isolate); @@ -33,8 +33,9 @@ class View : public gin_helper::EventEmitter, static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); - void AddChildViewAt(gin::Handle child, std::optional index); - void RemoveChildView(gin::Handle child); + void AddChildViewAt(gin_helper::Handle child, + std::optional index); + void RemoveChildView(gin_helper::Handle child); void SetBounds(const gfx::Rect& bounds); gfx::Rect GetBounds() const; @@ -70,7 +71,7 @@ class View : public gin_helper::EventEmitter, views::View* child) override; void ApplyBorderRadius(); - void ReorderChildView(gin::Handle child, size_t index); + void ReorderChildView(gin_helper::Handle child, size_t index); std::vector child_views_; std::optional border_radius_; diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index e814c4d2991c..5e14a9f4d344 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -75,7 +75,6 @@ #include "electron/mas.h" #include "gin/arguments.h" #include "gin/data_object_builder.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "gin/wrappable.h" #include "media/base/mime_util.h" @@ -132,6 +131,7 @@ #include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/locker.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/gin_helper/promise.h" @@ -829,7 +829,7 @@ WebContents::WebContents(v8::Isolate* isolate, // Obtain the session. std::string partition; - gin::Handle session; + gin_helper::Handle session; if (options.Get("session", &session) && !session.IsEmpty()) { } else if (options.Get("partition", &partition)) { session = Session::FromPartition(isolate, partition); @@ -907,7 +907,7 @@ void WebContents::InitZoomController(content::WebContents* web_contents, void WebContents::InitWithSessionAndOptions( v8::Isolate* isolate, std::unique_ptr owned_web_contents, - gin::Handle session, + gin_helper::Handle session, const gin_helper::Dictionary& options) { Observe(owned_web_contents.get()); InitWithWebContents(std::move(owned_web_contents), session->browser_context(), @@ -1118,7 +1118,7 @@ void WebContents::OnDidAddMessageToConsole( v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin::Handle event = + gin_helper::Handle event = gin_helper::internal::Event::New(isolate); v8::Local event_object = event.ToV8().As(); @@ -1487,7 +1487,7 @@ void WebContents::RendererUnresponsive( base::RepeatingClosure hang_monitor_restarter) { v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin::Handle event = + gin_helper::Handle event = gin_helper::internal::Event::New(isolate); v8::Local event_object = event.ToV8().As(); gin::Dictionary dict(isolate, event_object); @@ -1672,7 +1672,7 @@ content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager( void WebContents::OnAudioStateChanged(bool audible) { v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin::Handle event = + gin_helper::Handle event = gin_helper::internal::Event::New(isolate); v8::Local event_object = event.ToV8().As(); gin::Dictionary dict(isolate, event_object); @@ -1940,7 +1940,7 @@ bool WebContents::EmitNavigationEvent( v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin::Handle event = + gin_helper::Handle event = gin_helper::internal::Event::New(isolate); v8::Local event_object = event.ToV8().As(); @@ -3599,7 +3599,7 @@ void WebContents::OnPaint(const gfx::Rect& dirty_rect, v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin::Handle event = + gin_helper::Handle event = gin_helper::internal::Event::New(isolate); v8::Local event_object = event.ToV8().As(); gin_helper::Dictionary dict(isolate, event_object); @@ -4514,11 +4514,11 @@ ElectronBrowserContext* WebContents::GetBrowserContext() const { } // static -gin::Handle WebContents::New( +gin_helper::Handle WebContents::New( v8::Isolate* isolate, const gin_helper::Dictionary& options) { - gin::Handle handle = - gin::CreateHandle(isolate, new WebContents(isolate, options)); + gin_helper::Handle handle = + gin_helper::CreateHandle(isolate, new WebContents(isolate, options)); v8::TryCatch try_catch(isolate); gin_helper::CallMethod(isolate, handle.get(), "_init"); if (try_catch.HasCaught()) { @@ -4528,11 +4528,11 @@ gin::Handle WebContents::New( } // static -gin::Handle WebContents::CreateAndTake( +gin_helper::Handle WebContents::CreateAndTake( v8::Isolate* isolate, std::unique_ptr web_contents, Type type) { - gin::Handle handle = gin::CreateHandle( + gin_helper::Handle handle = gin_helper::CreateHandle( isolate, new WebContents(isolate, std::move(web_contents), type)); v8::TryCatch try_catch(isolate); gin_helper::CallMethod(isolate, handle.get(), "_init"); @@ -4552,7 +4552,7 @@ WebContents* WebContents::From(content::WebContents* web_contents) { } // static -gin::Handle WebContents::FromOrCreate( +gin_helper::Handle WebContents::FromOrCreate( v8::Isolate* isolate, content::WebContents* web_contents) { WebContents* api_web_contents = From(web_contents); @@ -4564,15 +4564,15 @@ gin::Handle WebContents::FromOrCreate( node::errors::TriggerUncaughtException(isolate, try_catch); } } - return gin::CreateHandle(isolate, api_web_contents); + return gin_helper::CreateHandle(isolate, api_web_contents); } // static -gin::Handle WebContents::CreateFromWebPreferences( +gin_helper::Handle WebContents::CreateFromWebPreferences( v8::Isolate* isolate, const gin_helper::Dictionary& web_preferences) { // Check if webPreferences has |webContents| option. - gin::Handle web_contents; + gin_helper::Handle web_contents; if (web_preferences.GetHidden("webContents", &web_contents) && !web_contents.IsEmpty()) { // Set webPreferences from options if using an existing webContents. @@ -4627,37 +4627,38 @@ using electron::api::GetAllWebContents; using electron::api::WebContents; using electron::api::WebFrameMain; -gin::Handle WebContentsFromID(v8::Isolate* isolate, int32_t id) { +gin_helper::Handle WebContentsFromID(v8::Isolate* isolate, + int32_t id) { WebContents* contents = WebContents::FromID(id); - return contents ? gin::CreateHandle(isolate, contents) - : gin::Handle(); + return contents ? gin_helper::CreateHandle(isolate, contents) + : gin_helper::Handle(); } -gin::Handle WebContentsFromFrame(v8::Isolate* isolate, - WebFrameMain* web_frame) { +gin_helper::Handle WebContentsFromFrame(v8::Isolate* isolate, + WebFrameMain* web_frame) { content::RenderFrameHost* rfh = web_frame->render_frame_host(); content::WebContents* source = content::WebContents::FromRenderFrameHost(rfh); WebContents* contents = WebContents::From(source); - return contents ? gin::CreateHandle(isolate, contents) - : gin::Handle(); + return contents ? gin_helper::CreateHandle(isolate, contents) + : gin_helper::Handle(); } -gin::Handle WebContentsFromDevToolsTargetID( +gin_helper::Handle WebContentsFromDevToolsTargetID( v8::Isolate* isolate, std::string target_id) { auto agent_host = content::DevToolsAgentHost::GetForId(target_id); WebContents* contents = agent_host ? WebContents::From(agent_host->GetWebContents()) : nullptr; - return contents ? gin::CreateHandle(isolate, contents) - : gin::Handle(); + return contents ? gin_helper::CreateHandle(isolate, contents) + : gin_helper::Handle(); } -std::vector> GetAllWebContentsAsV8( +std::vector> GetAllWebContentsAsV8( v8::Isolate* isolate) { - std::vector> list; + std::vector> list; for (auto iter = base::IDMap::iterator(&GetAllWebContents()); !iter.IsAtEnd(); iter.Advance()) { - list.push_back(gin::CreateHandle(isolate, iter.GetCurrentValue())); + list.push_back(gin_helper::CreateHandle(isolate, iter.GetCurrentValue())); } return list; } diff --git a/shell/browser/api/electron_api_web_contents.h b/shell/browser/api/electron_api_web_contents.h index 92628e4af5aa..09262988ea6a 100644 --- a/shell/browser/api/electron_api_web_contents.h +++ b/shell/browser/api/electron_api_web_contents.h @@ -30,7 +30,6 @@ #include "content/public/browser/web_contents_observer.h" #include "content/public/common/stop_find_action.h" #include "electron/buildflags/buildflags.h" -#include "gin/handle.h" #include "printing/buildflags/buildflags.h" #include "shell/browser/api/save_page_handler.h" #include "shell/browser/background_throttling_source.h" @@ -43,6 +42,7 @@ #include "shell/common/api/api.mojom.h" #include "shell/common/gin_helper/cleaned_up_at_exit.h" #include "shell/common/gin_helper/constructible.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/pinnable.h" #include "shell/common/gin_helper/wrappable.h" #include "shell/common/web_contents_utility.mojom.h" @@ -135,13 +135,14 @@ class WebContents final : public ExclusiveAccessContext, }; // Create a new WebContents and return the V8 wrapper of it. - static gin::Handle New(v8::Isolate* isolate, - const gin_helper::Dictionary& options); + static gin_helper::Handle New( + v8::Isolate* isolate, + const gin_helper::Dictionary& options); // Create a new V8 wrapper for an existing |web_content|. // // The lifetime of |web_contents| will be managed by this class. - static gin::Handle CreateAndTake( + static gin_helper::Handle CreateAndTake( v8::Isolate* isolate, std::unique_ptr web_contents, Type type); @@ -160,11 +161,11 @@ class WebContents final : public ExclusiveAccessContext, // // The lifetime of |web_contents| is NOT managed by this class, and the type // of this wrapper is always REMOTE. - static gin::Handle FromOrCreate( + static gin_helper::Handle FromOrCreate( v8::Isolate* isolate, content::WebContents* web_contents); - static gin::Handle CreateFromWebPreferences( + static gin_helper::Handle CreateFromWebPreferences( v8::Isolate* isolate, const gin_helper::Dictionary& web_preferences); @@ -478,7 +479,7 @@ class WebContents final : public ExclusiveAccessContext, void InitWithSessionAndOptions( v8::Isolate* isolate, std::unique_ptr web_contents, - gin::Handle session, + gin_helper::Handle session, const gin_helper::Dictionary& options); #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) diff --git a/shell/browser/api/electron_api_web_contents_view.cc b/shell/browser/api/electron_api_web_contents_view.cc index 6fdf5d050795..0b9be9bd55dc 100644 --- a/shell/browser/api/electron_api_web_contents_view.cc +++ b/shell/browser/api/electron_api_web_contents_view.cc @@ -30,7 +30,7 @@ namespace electron::api { WebContentsView::WebContentsView(v8::Isolate* isolate, - gin::Handle web_contents) + gin_helper::Handle web_contents) : View(web_contents->inspectable_web_contents()->GetView()), web_contents_(isolate, web_contents.ToV8()), api_web_contents_(web_contents.get()) { @@ -47,9 +47,10 @@ WebContentsView::~WebContentsView() { api_web_contents_->Destroy(); } -gin::Handle WebContentsView::GetWebContents(v8::Isolate* isolate) { +gin_helper::Handle WebContentsView::GetWebContents( + v8::Isolate* isolate) { if (api_web_contents_) - return gin::CreateHandle(isolate, api_web_contents_.get()); + return gin_helper::CreateHandle(isolate, api_web_contents_.get()); else return {}; } @@ -122,7 +123,7 @@ void WebContentsView::OnViewRemovedFromWidget(views::View* observed_view) { } // static -gin::Handle WebContentsView::Create( +gin_helper::Handle WebContentsView::Create( v8::Isolate* isolate, const gin_helper::Dictionary& web_preferences) { v8::Local context = isolate->GetCurrentContext(); @@ -133,7 +134,7 @@ gin::Handle WebContentsView::Create( if (GetConstructor(isolate) ->NewInstance(context, 1, &arg) .ToLocal(&web_contents_view_obj)) { - gin::Handle web_contents_view; + gin_helper::Handle web_contents_view; if (gin::ConvertFromV8(isolate, web_contents_view_obj, &web_contents_view)) return web_contents_view; } @@ -173,7 +174,7 @@ gin_helper::WrappableBase* WebContentsView::New(gin_helper::Arguments* args) { } if (options.Get("webContents", &existing_web_contents_value)) { - gin::Handle existing_web_contents; + gin_helper::Handle existing_web_contents; if (!gin::ConvertFromV8(args->isolate(), existing_web_contents_value, &existing_web_contents)) { args->ThrowError("options.webContents must be a WebContents"); diff --git a/shell/browser/api/electron_api_web_contents_view.h b/shell/browser/api/electron_api_web_contents_view.h index f4248193e5a3..51c67231e117 100644 --- a/shell/browser/api/electron_api_web_contents_view.h +++ b/shell/browser/api/electron_api_web_contents_view.h @@ -25,7 +25,7 @@ class WebContentsView : public View, public DraggableRegionProvider { public: // Create a new instance of WebContentsView. - static gin::Handle Create( + static gin_helper::Handle Create( v8::Isolate* isolate, const gin_helper::Dictionary& web_preferences); @@ -37,7 +37,7 @@ class WebContentsView : public View, v8::Local prototype); // Public APIs. - gin::Handle GetWebContents(v8::Isolate* isolate); + gin_helper::Handle GetWebContents(v8::Isolate* isolate); void SetBackgroundColor(std::optional color); void SetBorderRadius(int radius); @@ -45,7 +45,8 @@ class WebContentsView : public View, protected: // Takes an existing WebContents. - WebContentsView(v8::Isolate* isolate, gin::Handle web_contents); + WebContentsView(v8::Isolate* isolate, + gin_helper::Handle web_contents); ~WebContentsView() override; // content::WebContentsObserver: diff --git a/shell/browser/api/electron_api_web_frame_main.cc b/shell/browser/api/electron_api_web_frame_main.cc index 2888ebaa09da..e1d42e06c436 100644 --- a/shell/browser/api/electron_api_web_frame_main.cc +++ b/shell/browser/api/electron_api_web_frame_main.cc @@ -17,7 +17,6 @@ #include "content/public/browser/frame_tree_node_id.h" #include "content/public/browser/render_frame_host.h" #include "content/public/common/isolated_world_ids.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "services/service_manager/public/cpp/interface_provider.h" #include "shell/browser/api/message_port.h" @@ -31,6 +30,7 @@ #include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/node_includes.h" @@ -347,7 +347,7 @@ void WebFrameMain::PostMessage(v8::Isolate* isolate, return; } - std::vector> wrapped_ports; + std::vector> wrapped_ports; if (transfer && !transfer.value()->IsUndefined()) { if (!gin::ConvertFromV8(isolate, *transfer, &wrapped_ports)) { isolate->ThrowException(v8::Exception::Error( @@ -539,13 +539,14 @@ void WebFrameMain::DOMContentLoaded() { } // static -gin::Handle WebFrameMain::New(v8::Isolate* isolate) { +gin_helper::Handle WebFrameMain::New(v8::Isolate* isolate) { return {}; } // static -gin::Handle WebFrameMain::From(v8::Isolate* isolate, - content::RenderFrameHost* rfh) { +gin_helper::Handle WebFrameMain::From( + v8::Isolate* isolate, + content::RenderFrameHost* rfh) { if (!rfh) return {}; @@ -575,9 +576,9 @@ gin::Handle WebFrameMain::From(v8::Isolate* isolate, } if (web_frame) - return gin::CreateHandle(isolate, web_frame); + return gin_helper::CreateHandle(isolate, web_frame); - auto handle = gin::CreateHandle(isolate, new WebFrameMain(rfh)); + auto handle = gin_helper::CreateHandle(isolate, new WebFrameMain(rfh)); // Prevent garbage collection of frame until it has been deleted internally. handle->Pin(isolate); @@ -678,7 +679,7 @@ v8::Local FromIdIfExists(gin_helper::ErrorThrower thrower, WebFrameMain* web_frame = WebFrameMain::FromRenderFrameHost(rfh); if (!web_frame) return v8::Null(thrower.isolate()); - return gin::CreateHandle(thrower.isolate(), web_frame).ToV8(); + return gin_helper::CreateHandle(thrower.isolate(), web_frame).ToV8(); } v8::Local FromFtnIdIfExists(gin_helper::ErrorThrower thrower, @@ -691,7 +692,7 @@ v8::Local FromFtnIdIfExists(gin_helper::ErrorThrower thrower, content::FrameTreeNodeId(frame_tree_node_id)); if (!web_frame) return v8::Null(thrower.isolate()); - return gin::CreateHandle(thrower.isolate(), web_frame).ToV8(); + return gin_helper::CreateHandle(thrower.isolate(), web_frame).ToV8(); } void Initialize(v8::Local exports, diff --git a/shell/browser/api/electron_api_web_frame_main.h b/shell/browser/api/electron_api_web_frame_main.h index 8cdc87ab613c..56dc7497ac01 100644 --- a/shell/browser/api/electron_api_web_frame_main.h +++ b/shell/browser/api/electron_api_web_frame_main.h @@ -32,10 +32,12 @@ class RenderFrameHost; namespace gin { class Arguments; +} // namespace gin +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace gin_helper { template @@ -53,9 +55,9 @@ class WebFrameMain final : public gin_helper::DeprecatedWrappable, public gin_helper::Constructible { public: // Create a new WebFrameMain and return the V8 wrapper of it. - static gin::Handle New(v8::Isolate* isolate); + static gin_helper::Handle New(v8::Isolate* isolate); - static gin::Handle From( + static gin_helper::Handle From( v8::Isolate* isolate, content::RenderFrameHost* render_frame_host); static WebFrameMain* FromFrameTreeNodeId( diff --git a/shell/browser/api/electron_api_web_request.cc b/shell/browser/api/electron_api_web_request.cc index c194be2bf1f5..b2b0a7f405aa 100644 --- a/shell/browser/api/electron_api_web_request.cc +++ b/shell/browser/api/electron_api_web_request.cc @@ -19,7 +19,6 @@ #include "extensions/common/url_pattern.h" #include "gin/converter.h" #include "gin/dictionary.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/api/electron_api_session.h" #include "shell/browser/api/electron_api_web_contents.h" @@ -33,6 +32,7 @@ #include "shell/common/gin_converters/std_converter.h" #include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/node_util.h" static constexpr auto ResourceTypes = @@ -733,10 +733,10 @@ void WebRequest::HandleSimpleEvent(SimpleEvent event, } // static -gin::Handle WebRequest::FromOrCreate( +gin_helper::Handle WebRequest::FromOrCreate( v8::Isolate* isolate, content::BrowserContext* browser_context) { - gin::Handle handle = From(isolate, browser_context); + gin_helper::Handle handle = From(isolate, browser_context); if (handle.IsEmpty()) { // Make sure the |Session| object has the |webRequest| property created. v8::Local web_request = @@ -750,16 +750,17 @@ gin::Handle WebRequest::FromOrCreate( } // static -gin::Handle WebRequest::Create( +gin_helper::Handle WebRequest::Create( v8::Isolate* isolate, content::BrowserContext* browser_context) { DCHECK(From(isolate, browser_context).IsEmpty()) << "WebRequest already created"; - return gin::CreateHandle(isolate, new WebRequest(isolate, browser_context)); + return gin_helper::CreateHandle(isolate, + new WebRequest(isolate, browser_context)); } // static -gin::Handle WebRequest::From( +gin_helper::Handle WebRequest::From( v8::Isolate* isolate, content::BrowserContext* browser_context) { if (!browser_context) @@ -768,7 +769,7 @@ gin::Handle WebRequest::From( static_cast(browser_context->GetUserData(kUserDataKey)); if (!user_data) return {}; - return gin::CreateHandle(isolate, user_data->data.get()); + return gin_helper::CreateHandle(isolate, user_data->data.get()); } } // namespace electron::api diff --git a/shell/browser/api/electron_api_web_request.h b/shell/browser/api/electron_api_web_request.h index ad8a740ff2ae..c2e97e6dc6d0 100644 --- a/shell/browser/api/electron_api_web_request.h +++ b/shell/browser/api/electron_api_web_request.h @@ -24,10 +24,12 @@ enum class WebRequestResourceType : uint8_t; namespace gin { class Arguments; +} // namespace gin +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron::api { @@ -38,18 +40,19 @@ class WebRequest final : public gin_helper::DeprecatedWrappable, // is no one. // Note that the lifetime of WebRequest object is managed by Session, instead // of the caller. - static gin::Handle FromOrCreate( + static gin_helper::Handle FromOrCreate( v8::Isolate* isolate, content::BrowserContext* browser_context); // Return a new WebRequest object, this should only be called by Session. - static gin::Handle Create( + static gin_helper::Handle Create( v8::Isolate* isolate, content::BrowserContext* browser_context); // Find the WebRequest object attached to |browser_context|. - static gin::Handle From(v8::Isolate* isolate, - content::BrowserContext* browser_context); + static gin_helper::Handle From( + v8::Isolate* isolate, + content::BrowserContext* browser_context); static const char* GetClassName() { return "WebRequest"; } diff --git a/shell/browser/api/ipc_dispatcher.h b/shell/browser/api/ipc_dispatcher.h index b4b013f936b6..1a53f79d9c7a 100644 --- a/shell/browser/api/ipc_dispatcher.h +++ b/shell/browser/api/ipc_dispatcher.h @@ -9,13 +9,13 @@ #include "base/trace_event/trace_event.h" #include "base/values.h" -#include "gin/handle.h" #include "shell/browser/api/message_port.h" #include "shell/browser/javascript_environment.h" #include "shell/common/api/api.mojom.h" #include "shell/common/gin_converters/blink_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/event.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/reply_channel.h" #include "shell/common/v8_util.h" @@ -26,14 +26,14 @@ namespace electron { template class IpcDispatcher { public: - void Message(gin::Handle& event, + void Message(gin_helper::Handle& event, const std::string& channel, blink::CloneableMessage args) { TRACE_EVENT1("electron", "IpcDispatcher::Message", "channel", channel); emitter()->EmitWithoutEvent("-ipc-message", event, channel, args); } - void Invoke(gin::Handle& event, + void Invoke(gin_helper::Handle& event, const std::string& channel, blink::CloneableMessage arguments) { TRACE_EVENT1("electron", "IpcDispatcher::Invoke", "channel", channel); @@ -41,9 +41,10 @@ class IpcDispatcher { std::move(arguments)); } - void ReceivePostMessage(gin::Handle& event, - const std::string& channel, - blink::TransferableMessage message) { + void ReceivePostMessage( + gin_helper::Handle& event, + const std::string& channel, + blink::TransferableMessage message) { TRACE_EVENT1("electron", "IpcDispatcher::ReceivePostMessage", "channel", channel); v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); @@ -56,7 +57,7 @@ class IpcDispatcher { std::move(wrapped_ports)); } - void MessageSync(gin::Handle& event, + void MessageSync(gin_helper::Handle& event, const std::string& channel, blink::CloneableMessage arguments) { TRACE_EVENT1("electron", "IpcDispatcher::MessageSync", "channel", channel); @@ -64,7 +65,7 @@ class IpcDispatcher { std::move(arguments)); } - void MessageHost(gin::Handle& event, + void MessageHost(gin_helper::Handle& event, const std::string& channel, blink::CloneableMessage arguments) { TRACE_EVENT1("electron", "IpcDispatcher::MessageHost", "channel", channel); diff --git a/shell/browser/api/message_port.cc b/shell/browser/api/message_port.cc index 021395ecc179..c8c065db49f6 100644 --- a/shell/browser/api/message_port.cc +++ b/shell/browser/api/message_port.cc @@ -12,12 +12,12 @@ #include "base/task/single_thread_task_runner.h" #include "gin/arguments.h" #include "gin/data_object_builder.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/javascript_environment.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" #include "shell/common/gin_helper/event_emitter_caller.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/wrappable.h" #include "shell/common/node_includes.h" #include "shell/common/v8_util.h" @@ -42,8 +42,8 @@ MessagePort::~MessagePort() { } // static -gin::Handle MessagePort::Create(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, new MessagePort()); +gin_helper::Handle MessagePort::Create(v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, new MessagePort()); } bool MessagePort::IsEntangled() const { @@ -73,7 +73,7 @@ void MessagePort::PostMessage(gin::Arguments* args) { } v8::Local transferables; - std::vector> wrapped_ports; + std::vector> wrapped_ports; if (args->GetNext(&transferables)) { std::vector> wrapped_port_values; if (!gin::ConvertFromV8(args->isolate(), transferables, @@ -190,10 +190,10 @@ bool MessagePort::HasPendingActivity() const { } // static -std::vector> MessagePort::EntanglePorts( +std::vector> MessagePort::EntanglePorts( v8::Isolate* isolate, std::vector channels) { - std::vector> wrapped_ports; + std::vector> wrapped_ports; for (auto& port : channels) { auto wrapped_port = MessagePort::Create(isolate); wrapped_port->Entangle(std::move(port)); @@ -205,7 +205,7 @@ std::vector> MessagePort::EntanglePorts( // static std::vector MessagePort::DisentanglePorts( v8::Isolate* isolate, - const std::vector>& ports, + const std::vector>& ports, bool* threw_exception) { if (ports.empty()) return {}; diff --git a/shell/browser/api/message_port.h b/shell/browser/api/message_port.h index ab092f2d47aa..62726790afc3 100644 --- a/shell/browser/api/message_port.h +++ b/shell/browser/api/message_port.h @@ -16,9 +16,12 @@ namespace gin { class Arguments; +} // namespace gin + +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace mojo { class Connector; @@ -32,7 +35,7 @@ class MessagePort final : public gin_helper::DeprecatedWrappable, private mojo::MessageReceiver { public: ~MessagePort() override; - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); void PostMessage(gin::Arguments* args); void Start(); @@ -46,13 +49,13 @@ class MessagePort final : public gin_helper::DeprecatedWrappable, [[nodiscard]] bool IsEntangled() const; [[nodiscard]] bool IsNeutered() const; - static std::vector> EntanglePorts( + static std::vector> EntanglePorts( v8::Isolate* isolate, std::vector channels); static std::vector DisentanglePorts( v8::Isolate* isolate, - const std::vector>& ports, + const std::vector>& ports, bool* threw_exception); // gin_helper::Wrappable diff --git a/shell/browser/api/views/electron_api_image_view.h b/shell/browser/api/views/electron_api_image_view.h index f614edbd6eb6..78d913c046b1 100644 --- a/shell/browser/api/views/electron_api_image_view.h +++ b/shell/browser/api/views/electron_api_image_view.h @@ -5,8 +5,8 @@ #ifndef ELECTRON_SHELL_BROWSER_API_VIEWS_ELECTRON_API_IMAGE_VIEW_H_ #define ELECTRON_SHELL_BROWSER_API_VIEWS_ELECTRON_API_IMAGE_VIEW_H_ -#include "gin/handle.h" #include "shell/browser/api/electron_api_view.h" +#include "shell/common/gin_helper/handle.h" #include "ui/views/controls/image_view.h" namespace gfx { diff --git a/shell/browser/electron_api_ipc_handler_impl.cc b/shell/browser/electron_api_ipc_handler_impl.cc index 6ca82991996d..8a69482c1294 100644 --- a/shell/browser/electron_api_ipc_handler_impl.cc +++ b/shell/browser/electron_api_ipc_handler_impl.cc @@ -9,12 +9,12 @@ #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/web_contents.h" -#include "gin/handle.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "shell/browser/api/electron_api_session.h" #include "shell/common/gin_converters/content_converter.h" #include "shell/common/gin_converters/frame_converter.h" #include "shell/common/gin_helper/event.h" +#include "shell/common/gin_helper/handle.h" namespace electron { ElectronApiIPCHandlerImpl::ElectronApiIPCHandlerImpl( @@ -111,7 +111,7 @@ api::Session* ElectronApiIPCHandlerImpl::GetSession() { : nullptr; } -gin::Handle +gin_helper::Handle ElectronApiIPCHandlerImpl::MakeIPCEvent( v8::Isolate* isolate, api::Session* session, @@ -147,7 +147,7 @@ ElectronApiIPCHandlerImpl::MakeIPCEvent( } content::RenderFrameHost* frame = GetRenderFrameHost(); - gin::Handle event = + gin_helper::Handle event = gin_helper::internal::Event::New(isolate); gin_helper::Dictionary dict(isolate, event.ToV8().As()); dict.Set("type", "frame"); diff --git a/shell/browser/electron_api_ipc_handler_impl.h b/shell/browser/electron_api_ipc_handler_impl.h index 973d20473481..a3e730f1efb2 100644 --- a/shell/browser/electron_api_ipc_handler_impl.h +++ b/shell/browser/electron_api_ipc_handler_impl.h @@ -67,7 +67,7 @@ class ElectronApiIPCHandlerImpl : public mojom::ElectronApiIPC, content::RenderFrameHost* GetRenderFrameHost(); api::Session* GetSession(); - gin::Handle MakeIPCEvent( + gin_helper::Handle MakeIPCEvent( v8::Isolate* isolate, api::Session* session, bool internal, diff --git a/shell/browser/electron_api_sw_ipc_handler_impl.cc b/shell/browser/electron_api_sw_ipc_handler_impl.cc index 94d1e95bc3f9..98ca9bab184e 100644 --- a/shell/browser/electron_api_sw_ipc_handler_impl.cc +++ b/shell/browser/electron_api_sw_ipc_handler_impl.cc @@ -134,7 +134,7 @@ api::Session* ElectronApiSWIPCHandlerImpl::GetSession() { return api::Session::FromBrowserContext(GetBrowserContext()); } -gin::Handle +gin_helper::Handle ElectronApiSWIPCHandlerImpl::MakeIPCEvent( v8::Isolate* isolate, api::Session* session, @@ -149,7 +149,7 @@ ElectronApiSWIPCHandlerImpl::MakeIPCEvent( return {}; } - gin::Handle event = + gin_helper::Handle event = gin_helper::internal::Event::New(isolate); v8::Local event_object = event.ToV8().As(); diff --git a/shell/browser/electron_api_sw_ipc_handler_impl.h b/shell/browser/electron_api_sw_ipc_handler_impl.h index d3cf6d95090c..47bff37a0dc9 100644 --- a/shell/browser/electron_api_sw_ipc_handler_impl.h +++ b/shell/browser/electron_api_sw_ipc_handler_impl.h @@ -11,9 +11,9 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_process_host_observer.h" #include "electron/shell/common/api/api.mojom.h" -#include "gin/handle.h" #include "mojo/public/cpp/bindings/associated_receiver.h" #include "shell/common/gin_helper/event.h" +#include "shell/common/gin_helper/handle.h" namespace content { class RenderProcessHost; @@ -70,7 +70,7 @@ class ElectronApiSWIPCHandlerImpl : public mojom::ElectronApiIPC, ElectronBrowserContext* GetBrowserContext(); api::Session* GetSession(); - gin::Handle MakeIPCEvent( + gin_helper::Handle MakeIPCEvent( v8::Isolate* isolate, api::Session* session, bool internal, diff --git a/shell/browser/electron_crypto_module_delegate_nss.cc b/shell/browser/electron_crypto_module_delegate_nss.cc index 207ca1fadc4b..fb08ab7c0039 100644 --- a/shell/browser/electron_crypto_module_delegate_nss.cc +++ b/shell/browser/electron_crypto_module_delegate_nss.cc @@ -48,7 +48,7 @@ void ElectronNSSCryptoModuleDelegate::RequestPasswordOnUIThread( v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin::Handle event = + gin_helper::Handle event = gin_helper::internal::Event::New(isolate); v8::Local event_object = event.ToV8().As(); gin_helper::Dictionary dict(isolate, event_object); diff --git a/shell/browser/event_emitter_mixin.h b/shell/browser/event_emitter_mixin.h index 36a066ffedc2..03c0c63d7f14 100644 --- a/shell/browser/event_emitter_mixin.h +++ b/shell/browser/event_emitter_mixin.h @@ -8,11 +8,11 @@ #include #include -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/javascript_environment.h" #include "shell/common/gin_helper/event.h" #include "shell/common/gin_helper/event_emitter.h" +#include "shell/common/gin_helper/handle.h" namespace gin_helper { @@ -32,7 +32,7 @@ class EventEmitterMixin { v8::Local wrapper; if (!static_cast(this)->GetWrapper(isolate).ToLocal(&wrapper)) return false; - gin::Handle event = internal::Event::New(isolate); + gin_helper::Handle event = internal::Event::New(isolate); gin_helper::EmitEvent(isolate, wrapper, name, event, std::forward(args)...); return event->GetDefaultPrevented(); diff --git a/shell/browser/net/electron_url_loader_factory.cc b/shell/browser/net/electron_url_loader_factory.cc index b1cc4d72142b..0e7e04459b56 100644 --- a/shell/browser/net/electron_url_loader_factory.cc +++ b/shell/browser/net/electron_url_loader_factory.cc @@ -670,7 +670,7 @@ void ElectronURLLoaderFactory::StartLoadingHttp( request->method != net::HttpRequestHeaders::kHeadMethod) dict.Get("uploadData", &upload_data); - gin::Handle session; + gin_helper::Handle session; auto* browser_context = dict.Get("session", &session) && !session.IsEmpty() ? session->browser_context() diff --git a/shell/common/api/electron_api_asar.cc b/shell/common/api/electron_api_asar.cc index 9cf46892b19e..2e872759d0dc 100644 --- a/shell/common/api/electron_api_asar.cc +++ b/shell/common/api/electron_api_asar.cc @@ -4,11 +4,11 @@ #include -#include "gin/handle.h" #include "shell/common/asar/archive.h" #include "shell/common/asar/asar_util.h" #include "shell/common/gin_converters/file_path_converter.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/node_includes.h" namespace { diff --git a/shell/common/api/electron_api_native_image.cc b/shell/common/api/electron_api_native_image.cc index ad2afb911f13..5827ce104305 100644 --- a/shell/common/api/electron_api_native_image.cc +++ b/shell/common/api/electron_api_native_image.cc @@ -16,7 +16,6 @@ #include "base/strings/pattern.h" #include "base/strings/utf_string_conversions.h" #include "gin/arguments.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "gin/per_isolate_data.h" #include "net/base/data_url.h" @@ -29,6 +28,7 @@ #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" #include "shell/common/gin_helper/function_template_extensions.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" #include "shell/common/node_util.h" @@ -338,8 +338,8 @@ float NativeImage::GetAspectRatio(const std::optional scale_factor) { return static_cast(size.width()) / static_cast(size.height()); } -gin::Handle NativeImage::Resize(gin::Arguments* args, - base::Value::Dict options) { +gin_helper::Handle NativeImage::Resize(gin::Arguments* args, + base::Value::Dict options) { float scale_factor = GetScaleFactorFromOptions(args); gfx::Size size = GetSize(scale_factor); @@ -375,8 +375,8 @@ gin::Handle NativeImage::Resize(gin::Arguments* args, image_.AsImageSkia(), method, size)}); } -gin::Handle NativeImage::Crop(v8::Isolate* isolate, - const gfx::Rect& rect) { +gin_helper::Handle NativeImage::Crop(v8::Isolate* isolate, + const gfx::Rect& rect) { return Create(isolate, gfx::Image{gfx::ImageSkiaOperations::ExtractSubset( image_.AsImageSkia(), rect)}); } @@ -424,18 +424,18 @@ bool NativeImage::IsTemplateImage() { #endif // static -gin::Handle NativeImage::CreateEmpty(v8::Isolate* isolate) { +gin_helper::Handle NativeImage::CreateEmpty(v8::Isolate* isolate) { return Create(isolate, gfx::Image{}); } // static -gin::Handle NativeImage::Create(v8::Isolate* isolate, - const gfx::Image& image) { - return gin::CreateHandle(isolate, new NativeImage(isolate, image)); +gin_helper::Handle NativeImage::Create(v8::Isolate* isolate, + const gfx::Image& image) { + return gin_helper::CreateHandle(isolate, new NativeImage(isolate, image)); } // static -gin::Handle NativeImage::CreateFromPNG( +gin_helper::Handle NativeImage::CreateFromPNG( v8::Isolate* isolate, const base::span data) { gfx::ImageSkia image_skia; @@ -444,7 +444,7 @@ gin::Handle NativeImage::CreateFromPNG( } // static -gin::Handle NativeImage::CreateFromJPEG( +gin_helper::Handle NativeImage::CreateFromJPEG( v8::Isolate* isolate, const base::span buffer) { gfx::ImageSkia image_skia; @@ -453,19 +453,20 @@ gin::Handle NativeImage::CreateFromJPEG( } // static -gin::Handle NativeImage::CreateFromPath( +gin_helper::Handle NativeImage::CreateFromPath( v8::Isolate* isolate, const base::FilePath& path) { base::FilePath image_path = NormalizePath(path); #if BUILDFLAG(IS_WIN) if (image_path.MatchesExtension(FILE_PATH_LITERAL(".ico"))) { - return gin::CreateHandle(isolate, new NativeImage(isolate, image_path)); + return gin_helper::CreateHandle(isolate, + new NativeImage(isolate, image_path)); } #endif gfx::ImageSkia image_skia; electron::util::PopulateImageSkiaRepsFromPath(&image_skia, image_path); gfx::Image image(image_skia); - gin::Handle handle = Create(isolate, image); + gin_helper::Handle handle = Create(isolate, image); #if BUILDFLAG(IS_MAC) if (IsTemplateFilename(image_path)) handle->SetTemplateImage(true); @@ -474,7 +475,7 @@ gin::Handle NativeImage::CreateFromPath( } // static -gin::Handle NativeImage::CreateFromBitmap( +gin_helper::Handle NativeImage::CreateFromBitmap( gin_helper::ErrorThrower thrower, v8::Local buffer, const gin_helper::Dictionary& options) { @@ -520,7 +521,7 @@ gin::Handle NativeImage::CreateFromBitmap( } // static -gin::Handle NativeImage::CreateFromBuffer( +gin_helper::Handle NativeImage::CreateFromBuffer( gin_helper::ErrorThrower thrower, v8::Local buffer, gin::Arguments* args) { @@ -548,8 +549,9 @@ gin::Handle NativeImage::CreateFromBuffer( } // static -gin::Handle NativeImage::CreateFromDataURL(v8::Isolate* isolate, - const GURL& url) { +gin_helper::Handle NativeImage::CreateFromDataURL( + v8::Isolate* isolate, + const GURL& url) { std::string mime_type, charset, data; if (net::DataURL::Parse(url, &mime_type, &charset, &data)) { if (mime_type == "image/png") @@ -562,8 +564,9 @@ gin::Handle NativeImage::CreateFromDataURL(v8::Isolate* isolate, } #if !BUILDFLAG(IS_MAC) -gin::Handle NativeImage::CreateFromNamedImage(gin::Arguments* args, - std::string name) { +gin_helper::Handle NativeImage::CreateFromNamedImage( + gin::Arguments* args, + std::string name) { return CreateEmpty(args->isolate()); } #endif diff --git a/shell/common/api/electron_api_native_image.h b/shell/common/api/electron_api_native_image.h index d82f54bef724..ad70f4637f31 100644 --- a/shell/common/api/electron_api_native_image.h +++ b/shell/common/api/electron_api_native_image.h @@ -34,14 +34,13 @@ class Size; namespace gin { class Arguments; - -template -class Handle; } // namespace gin namespace gin_helper { class Dictionary; class ErrorThrower; +template +class Handle; } // namespace gin_helper namespace electron::api { @@ -58,28 +57,31 @@ class NativeImage final : public gin_helper::DeprecatedWrappable { NativeImage(const NativeImage&) = delete; NativeImage& operator=(const NativeImage&) = delete; - static gin::Handle CreateEmpty(v8::Isolate* isolate); - static gin::Handle Create(v8::Isolate* isolate, - const gfx::Image& image); - static gin::Handle CreateFromPNG(v8::Isolate* isolate, - base::span data); - static gin::Handle CreateFromJPEG( + static gin_helper::Handle CreateEmpty(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate, + const gfx::Image& image); + static gin_helper::Handle CreateFromPNG( v8::Isolate* isolate, base::span data); - static gin::Handle CreateFromPath(v8::Isolate* isolate, - const base::FilePath& path); - static gin::Handle CreateFromBitmap( + static gin_helper::Handle CreateFromJPEG( + v8::Isolate* isolate, + base::span data); + static gin_helper::Handle CreateFromPath( + v8::Isolate* isolate, + const base::FilePath& path); + static gin_helper::Handle CreateFromBitmap( gin_helper::ErrorThrower thrower, v8::Local buffer, const gin_helper::Dictionary& options); - static gin::Handle CreateFromBuffer( + static gin_helper::Handle CreateFromBuffer( gin_helper::ErrorThrower thrower, v8::Local buffer, gin::Arguments* args); - static gin::Handle CreateFromDataURL(v8::Isolate* isolate, - const GURL& url); - static gin::Handle CreateFromNamedImage(gin::Arguments* args, - std::string name); + static gin_helper::Handle CreateFromDataURL(v8::Isolate* isolate, + const GURL& url); + static gin_helper::Handle CreateFromNamedImage( + gin::Arguments* args, + std::string name); #if !BUILDFLAG(IS_LINUX) static v8::Local CreateThumbnailFromPath( v8::Isolate* isolate, @@ -114,9 +116,10 @@ class NativeImage final : public gin_helper::DeprecatedWrappable { std::vector GetScaleFactors(); v8::Local GetBitmap(gin::Arguments* args); v8::Local GetNativeHandle(gin_helper::ErrorThrower thrower); - gin::Handle Resize(gin::Arguments* args, - base::Value::Dict options); - gin::Handle Crop(v8::Isolate* isolate, const gfx::Rect& rect); + gin_helper::Handle Resize(gin::Arguments* args, + base::Value::Dict options); + gin_helper::Handle Crop(v8::Isolate* isolate, + const gfx::Rect& rect); std::string ToDataURL(gin::Arguments* args); bool IsEmpty(); gfx::Size GetSize(const std::optional scale_factor); diff --git a/shell/common/api/electron_api_native_image_mac.mm b/shell/common/api/electron_api_native_image_mac.mm index f3e766c896fc..f25a4e0b640d 100644 --- a/shell/common/api/electron_api_native_image_mac.mm +++ b/shell/common/api/electron_api_native_image_mac.mm @@ -16,8 +16,8 @@ #include "base/strings/sys_string_conversions.h" #include "base/task/bind_post_task.h" #include "gin/arguments.h" -#include "gin/handle.h" #include "shell/common/gin_converters/image_converter.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/mac_util.h" #include "ui/gfx/color_utils.h" @@ -103,8 +103,9 @@ v8::Local NativeImage::CreateThumbnailFromPath( return handle; } -gin::Handle NativeImage::CreateFromNamedImage(gin::Arguments* args, - std::string name) { +gin_helper::Handle NativeImage::CreateFromNamedImage( + gin::Arguments* args, + std::string name) { @autoreleasepool { std::vector hsl_shift; diff --git a/shell/common/api/electron_api_net.cc b/shell/common/api/electron_api_net.cc index 818de5802e68..4194445c9407 100644 --- a/shell/common/api/electron_api_net.cc +++ b/shell/common/api/electron_api_net.cc @@ -4,7 +4,6 @@ #include -#include "gin/handle.h" #include "net/base/filename_util.h" #include "net/base/network_change_notifier.h" #include "net/http/http_util.h" @@ -17,6 +16,7 @@ #include "shell/common/gin_converters/net_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/node_includes.h" diff --git a/shell/common/api/electron_api_url_loader.cc b/shell/common/api/electron_api_url_loader.cc index e1f261b948ba..946afe3a2c53 100644 --- a/shell/common/api/electron_api_url_loader.cc +++ b/shell/common/api/electron_api_url_loader.cc @@ -17,7 +17,6 @@ #include "base/memory/raw_ptr.h" #include "base/notreached.h" #include "base/sequence_checker.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/system/data_pipe_producer.h" @@ -43,6 +42,7 @@ #include "shell/common/gin_converters/gurl_converter.h" #include "shell/common/gin_converters/net_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/gin_helper/promise.h" #include "shell/common/node_includes.h" @@ -167,12 +167,12 @@ class JSChunkedDataPipeGetter final : public gin_helper::DeprecatedWrappable, public network::mojom::ChunkedDataPipeGetter { public: - static gin::Handle Create( + static gin_helper::Handle Create( v8::Isolate* isolate, v8::Local body_func, mojo::PendingReceiver chunked_data_pipe_getter) { - return gin::CreateHandle( + return gin_helper::CreateHandle( isolate, new JSChunkedDataPipeGetter( isolate, body_func, std::move(chunked_data_pipe_getter))); } @@ -390,7 +390,8 @@ void SimpleURLLoaderWrapper::Start() { void SimpleURLLoaderWrapper::Pin() { // Prevent ourselves from being GC'd until the request is complete. Must be - // called after gin::CreateHandle, otherwise the wrapper isn't initialized. + // called after gin_helper::CreateHandle, otherwise the wrapper isn't + // initialized. v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); pinned_wrapper_.Reset(isolate, GetWrapper(isolate).ToLocalChecked()); } @@ -522,7 +523,7 @@ SimpleURLLoaderWrapper::GetURLLoaderFactoryForURL(const GURL& url) { } // static -gin::Handle SimpleURLLoaderWrapper::Create( +gin_helper::Handle SimpleURLLoaderWrapper::Create( gin::Arguments* args) { gin_helper::Dictionary opts; if (!args->GetNext(&opts)) { @@ -697,7 +698,7 @@ gin::Handle SimpleURLLoaderWrapper::Create( ElectronBrowserContext* browser_context = nullptr; if (electron::IsBrowserProcess()) { std::string partition; - gin::Handle session; + gin_helper::Handle session; if (!opts.Get("session", &session)) { if (opts.Get("partition", &partition)) session = Session::FromPartition(args->isolate(), partition); @@ -707,7 +708,7 @@ gin::Handle SimpleURLLoaderWrapper::Create( browser_context = session->browser_context(); } - auto ret = gin::CreateHandle( + auto ret = gin_helper::CreateHandle( args->isolate(), new SimpleURLLoaderWrapper(browser_context, std::move(request), options)); ret->Pin(); diff --git a/shell/common/api/electron_api_url_loader.h b/shell/common/api/electron_api_url_loader.h index 918c1e5b31f5..405dccdbda3e 100644 --- a/shell/common/api/electron_api_url_loader.h +++ b/shell/common/api/electron_api_url_loader.h @@ -27,9 +27,12 @@ namespace gin { class Arguments; +} // namespace gin + +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace net { class AuthChallengeInfo; @@ -56,7 +59,8 @@ class SimpleURLLoaderWrapper final private network::mojom::URLLoaderNetworkServiceObserver { public: ~SimpleURLLoaderWrapper() override; - static gin::Handle Create(gin::Arguments* args); + static gin_helper::Handle Create( + gin::Arguments* args); void Cancel(); diff --git a/shell/common/gin_converters/image_converter.cc b/shell/common/gin_converters/image_converter.cc index 36bbf7b592e6..9426b13b5d6c 100644 --- a/shell/common/gin_converters/image_converter.cc +++ b/shell/common/gin_converters/image_converter.cc @@ -4,9 +4,9 @@ #include "shell/common/gin_converters/image_converter.h" -#include "gin/handle.h" #include "shell/common/api/electron_api_native_image.h" #include "shell/common/gin_converters/file_path_converter.h" +#include "shell/common/gin_helper/handle.h" #include "ui/gfx/image/image_skia.h" namespace gin { diff --git a/shell/common/gin_converters/net_converter.cc b/shell/common/gin_converters/net_converter.cc index c961d1f5fd26..e28d92fab4cd 100644 --- a/shell/common/gin_converters/net_converter.cc +++ b/shell/common/gin_converters/net_converter.cc @@ -15,7 +15,6 @@ #include "base/values.h" #include "gin/converter.h" #include "gin/dictionary.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "net/cert/x509_certificate.h" #include "net/cert/x509_util.h" @@ -32,6 +31,7 @@ #include "shell/common/gin_converters/gurl_converter.h" #include "shell/common/gin_converters/std_converter.h" #include "shell/common/gin_converters/value_converter.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/node_includes.h" #include "shell/common/node_util.h" @@ -259,12 +259,13 @@ namespace { class ChunkedDataPipeReadableStream final : public gin_helper::DeprecatedWrappable { public: - static gin::Handle Create( + static gin_helper::Handle Create( v8::Isolate* isolate, network::ResourceRequestBody* request, network::DataElementChunkedDataPipe* data_element) { - return gin::CreateHandle(isolate, new ChunkedDataPipeReadableStream( - isolate, request, data_element)); + return gin_helper::CreateHandle( + isolate, + new ChunkedDataPipeReadableStream(isolate, request, data_element)); } // gin_helper::Wrappable diff --git a/shell/common/gin_helper/constructible.h b/shell/common/gin_helper/constructible.h index 3081ee261774..d854c66bef72 100644 --- a/shell/common/gin_helper/constructible.h +++ b/shell/common/gin_helper/constructible.h @@ -23,7 +23,7 @@ class EventEmitterMixin; // class Example : public gin_helper::DeprecatedWrappable, // public gin_helper::Constructible { // public: -// static gin::Handle New(...usual gin method arguments...); +// static gin_helper::Handle New(...usual gin method arguments...); // static void FillObjectTemplate( // v8::Isolate*, // v8::Local); diff --git a/shell/common/gin_helper/event.cc b/shell/common/gin_helper/event.cc index 7b5ad8e75e6e..03bb2580d3dc 100644 --- a/shell/common/gin_helper/event.cc +++ b/shell/common/gin_helper/event.cc @@ -4,14 +4,14 @@ #include "shell/common/gin_helper/event.h" #include "gin/dictionary.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" +#include "shell/common/gin_helper/handle.h" namespace gin_helper::internal { // static -gin::Handle Event::New(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, new Event()); +gin_helper::Handle Event::New(v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, new Event()); } // static v8::Local Event::FillObjectTemplate( diff --git a/shell/common/gin_helper/event.h b/shell/common/gin_helper/event.h index 8657d52bcac2..28dd2eaa1205 100644 --- a/shell/common/gin_helper/event.h +++ b/shell/common/gin_helper/event.h @@ -8,10 +8,10 @@ #include "shell/common/gin_helper/constructible.h" #include "shell/common/gin_helper/wrappable.h" -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace v8 { class Isolate; @@ -27,7 +27,7 @@ class Event final : public gin_helper::DeprecatedWrappable, public gin_helper::Constructible { public: // gin_helper::Constructible - static gin::Handle New(v8::Isolate* isolate); + static gin_helper::Handle New(v8::Isolate* isolate); static v8::Local FillObjectTemplate( v8::Isolate* isolate, v8::Local prototype); diff --git a/shell/common/gin_helper/event_emitter.h b/shell/common/gin_helper/event_emitter.h index 2a9485696dd4..ff074d3a6507 100644 --- a/shell/common/gin_helper/event_emitter.h +++ b/shell/common/gin_helper/event_emitter.h @@ -8,9 +8,9 @@ #include #include -#include "gin/handle.h" #include "shell/common/gin_helper/event.h" #include "shell/common/gin_helper/event_emitter_caller.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/wrappable.h" namespace content { @@ -31,7 +31,7 @@ class EventEmitter : public gin_helper::Wrappable { v8::Local wrapper = this->GetWrapper(); if (wrapper.IsEmpty()) return false; - gin::Handle event = internal::Event::New(isolate); + gin_helper::Handle event = internal::Event::New(isolate); // It's possible that |this| will be deleted by EmitEvent, so save anything // we need from |this| before calling EmitEvent. EmitEvent(isolate, wrapper, name, event, std::forward(args)...); diff --git a/shell/common/gin_helper/handle.h b/shell/common/gin_helper/handle.h new file mode 100644 index 000000000000..2eff8b60f46b --- /dev/null +++ b/shell/common/gin_helper/handle.h @@ -0,0 +1,77 @@ +// Copyright (c) 2025 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ELECTRON_SHELL_COMMON_GIN_HELPER_HANDLE_H_ +#define ELECTRON_SHELL_COMMON_GIN_HELPER_HANDLE_H_ + +#include "base/memory/raw_ptr.h" +#include "gin/converter.h" + +namespace gin_helper { + +// You can use gin_helper::Handle on the stack to retain a gin_helper::Wrappable +// object. Currently we don't have a mechanism for retaining a +// gin_helper::Wrappable object in the C++ heap because strong references from +// C++ to V8 can cause memory leaks. Copied from +// https://chromium-review.googlesource.com/c/chromium/src/+/6734440 Should be +// removed once https://github.com/electron/electron/issues/47922 is complete. +template +class Handle { + public: + Handle() : object_(nullptr) {} + + Handle(v8::Local wrapper, T* object) + : wrapper_(wrapper), object_(object) {} + + bool IsEmpty() const { return !object_; } + + void Clear() { + wrapper_.Clear(); + object_ = NULL; + } + + T* operator->() const { return object_; } + v8::Local ToV8() const { return wrapper_; } + T* get() const { return object_; } + + private: + v8::Local wrapper_; + raw_ptr object_; +}; + +// This function is a convenient way to create a handle from a raw pointer +// without having to write out the type of the object explicitly. +template +gin_helper::Handle CreateHandle(v8::Isolate* isolate, T* object) { + v8::Local wrapper; + if (!object->GetWrapper(isolate).ToLocal(&wrapper) || wrapper.IsEmpty()) + return gin_helper::Handle(); + return gin_helper::Handle(wrapper, object); +} + +} // namespace gin_helper + +namespace gin { + +template +struct Converter> { + static v8::Local ToV8(v8::Isolate* isolate, + const gin_helper::Handle& val) { + return val.ToV8(); + } + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + gin_helper::Handle* out) { + T* object = NULL; + if (!Converter::FromV8(isolate, val, &object)) { + return false; + } + *out = gin_helper::Handle(val, object); + return true; + } +}; + +} // namespace gin + +#endif // ELECTRON_SHELL_COMMON_GIN_HELPER_HANDLE_H_ diff --git a/shell/common/gin_helper/reply_channel.cc b/shell/common/gin_helper/reply_channel.cc index 57958f5be14a..b11cc4403dd5 100644 --- a/shell/common/gin_helper/reply_channel.cc +++ b/shell/common/gin_helper/reply_channel.cc @@ -6,18 +6,19 @@ #include "base/debug/stack_trace.h" #include "gin/data_object_builder.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/javascript_environment.h" #include "shell/common/gin_converters/blink_converter.h" +#include "shell/common/gin_helper/handle.h" namespace gin_helper::internal { // static using InvokeCallback = electron::mojom::ElectronApiIPC::InvokeCallback; -gin::Handle ReplyChannel::Create(v8::Isolate* isolate, - InvokeCallback callback) { - return gin::CreateHandle(isolate, new ReplyChannel(std::move(callback))); +gin_helper::Handle ReplyChannel::Create(v8::Isolate* isolate, + InvokeCallback callback) { + return gin_helper::CreateHandle(isolate, + new ReplyChannel(std::move(callback))); } gin::ObjectTemplateBuilder ReplyChannel::GetObjectTemplateBuilder( diff --git a/shell/common/gin_helper/reply_channel.h b/shell/common/gin_helper/reply_channel.h index b51c9327c577..2c87d769a2cc 100644 --- a/shell/common/gin_helper/reply_channel.h +++ b/shell/common/gin_helper/reply_channel.h @@ -8,10 +8,10 @@ #include "shell/common/api/api.mojom.h" #include "shell/common/gin_helper/wrappable.h" -namespace gin { +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace v8 { class Isolate; @@ -29,8 +29,8 @@ namespace gin_helper::internal { class ReplyChannel : public gin_helper::DeprecatedWrappable { public: using InvokeCallback = electron::mojom::ElectronApiIPC::InvokeCallback; - static gin::Handle Create(v8::Isolate* isolate, - InvokeCallback callback); + static gin_helper::Handle Create(v8::Isolate* isolate, + InvokeCallback callback); // gin_helper::Wrappable static gin::DeprecatedWrapperInfo kWrapperInfo; diff --git a/shell/common/gin_helper/wrappable_base.h b/shell/common/gin_helper/wrappable_base.h index 293e24cdf59c..35a9de3f21d1 100644 --- a/shell/common/gin_helper/wrappable_base.h +++ b/shell/common/gin_helper/wrappable_base.h @@ -17,7 +17,7 @@ struct DeprecatedWrapperInfo; namespace gin_helper { // Wrappable is a base class for C++ objects that have corresponding v8 wrapper -// objects. To retain a Wrappable object on the stack, use a gin::Handle. +// objects. To retain a Wrappable object on the stack, use a gin_helper::Handle. // // USAGE: // // my_class.h @@ -27,9 +27,9 @@ namespace gin_helper { // }; // // Subclasses should also typically have private constructors and expose a -// static Create function that returns a gin::Handle. Forcing creators through -// this static Create function will enforce that clients actually create a -// wrapper for the object. If clients fail to create a wrapper for a wrappable +// static Create function that returns a gin_helper::Handle. Forcing creators +// through this static Create function will enforce that clients actually create +// a wrapper for the object. If clients fail to create a wrapper for a wrappable // object, the object will leak because we use the weak callback from the // wrapper as the signal to delete the wrapped object. class WrappableBase { diff --git a/shell/renderer/api/electron_api_ipc_renderer.cc b/shell/renderer/api/electron_api_ipc_renderer.cc index 3a8e3b714c3d..61cade3c982c 100644 --- a/shell/renderer/api/electron_api_ipc_renderer.cc +++ b/shell/renderer/api/electron_api_ipc_renderer.cc @@ -8,7 +8,6 @@ #include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/worker_thread.h" #include "gin/dictionary.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "services/service_manager/public/cpp/interface_provider.h" #include "shell/common/api/api.mojom.h" @@ -17,6 +16,7 @@ #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" #include "shell/common/gin_helper/function_template_extensions.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/gin_helper/wrappable.h" #include "shell/common/node_bindings.h" @@ -59,8 +59,8 @@ class IPCBase : public gin_helper::DeprecatedWrappable { public: static gin::DeprecatedWrapperInfo kWrapperInfo; - static gin::Handle Create(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, new T(isolate)); + static gin_helper::Handle Create(v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, new T(isolate)); } void SendMessage(v8::Isolate* isolate, diff --git a/shell/renderer/api/electron_api_web_frame.cc b/shell/renderer/api/electron_api_web_frame.cc index 111de920a365..44ff3b647d96 100644 --- a/shell/renderer/api/electron_api_web_frame.cc +++ b/shell/renderer/api/electron_api_web_frame.cc @@ -17,7 +17,6 @@ #include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_visitor.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "services/service_manager/public/cpp/interface_provider.h" #include "shell/common/api/api.mojom.h" @@ -29,6 +28,7 @@ #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" #include "shell/common/gin_helper/function_template_extensions.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/gin_helper/promise.h" #include "shell/common/gin_helper/wrappable.h" @@ -383,14 +383,17 @@ class WebFrameRenderer final .Build(); } static const char* GetClassName() { return "WebFrame"; } - static gin::Handle New(v8::Isolate* isolate) { return {}; } + static gin_helper::Handle New(v8::Isolate* isolate) { + return {}; + } static gin::DeprecatedWrapperInfo kWrapperInfo; - static gin::Handle Create( + static gin_helper::Handle Create( v8::Isolate* isolate, content::RenderFrame* render_frame) { - return gin::CreateHandle(isolate, new WebFrameRenderer(render_frame)); + return gin_helper::CreateHandle(isolate, + new WebFrameRenderer(render_frame)); } explicit WebFrameRenderer(content::RenderFrame* render_frame) diff --git a/shell/services/node/parent_port.cc b/shell/services/node/parent_port.cc index 2474558551ee..1a717fd79942 100644 --- a/shell/services/node/parent_port.cc +++ b/shell/services/node/parent_port.cc @@ -8,12 +8,12 @@ #include "base/no_destructor.h" #include "gin/data_object_builder.h" -#include "gin/handle.h" #include "gin/object_template_builder.h" #include "shell/browser/api/message_port.h" #include "shell/browser/javascript_environment.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/event_emitter_caller.h" +#include "shell/common/gin_helper/handle.h" #include "shell/common/node_includes.h" #include "shell/common/v8_util.h" #include "third_party/blink/public/common/messaging/transferable_message_mojom_traits.h" @@ -107,8 +107,8 @@ bool ParentPort::Accept(mojo::Message* mojo_message) { } // static -gin::Handle ParentPort::Create(v8::Isolate* isolate) { - return gin::CreateHandle(isolate, ParentPort::GetInstance()); +gin_helper::Handle ParentPort::Create(v8::Isolate* isolate) { + return gin_helper::CreateHandle(isolate, ParentPort::GetInstance()); } // static diff --git a/shell/services/node/parent_port.h b/shell/services/node/parent_port.h index 53a611db505a..e39dad502781 100644 --- a/shell/services/node/parent_port.h +++ b/shell/services/node/parent_port.h @@ -22,9 +22,12 @@ class Isolate; namespace gin { class Arguments; +} // namespace gin + +namespace gin_helper { template class Handle; -} // namespace gin +} // namespace gin_helper namespace electron { @@ -36,7 +39,7 @@ class ParentPort final : public gin_helper::DeprecatedWrappable, private mojo::MessageReceiver { public: static ParentPort* GetInstance(); - static gin::Handle Create(v8::Isolate* isolate); + static gin_helper::Handle Create(v8::Isolate* isolate); ParentPort(const ParentPort&) = delete; ParentPort& operator=(const ParentPort&) = delete;