From 0fe6767d6b8992d0ac3036d553ead1e529b854f3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 25 Oct 2019 22:03:28 +0900 Subject: [PATCH] chore: remove native_mate (Part 11) (#20719) * refactor: convert Menu and globalShortcut to gin * refactor: convert api::Cookies to gin * refactor: convert View and WebContentsView to gin * refactor: convert WebContents related classes to gin * refactor: convert powerMonitor to gin * refactor: prepare for header change * refactor: remove last uses of mate::EventEmitter * refactor: remove mate::EventEmitter * refactor: move trackable_object to gin_helper * fix: custom converter should not use Handle * fix: no more need to check if icon is empty It was a bug that the Handle can be non-empty when the image file does not exist. The bug was caused by the converter code writing out the image even when the convertion fails. The bug was work-arounded by adding an additional check, but since the original bug had been fixed, the additional check is no longer needed. * fix: should always set frameId even when callback is null * fix: do not mix gin/mate handles for NativeImage --- filenames.gni | 17 +- shell/browser/api/atom_api_app.h | 3 +- shell/browser/api/atom_api_auto_updater.h | 8 +- shell/browser/api/atom_api_browser_view.cc | 8 +- shell/browser/api/atom_api_browser_view.h | 4 +- shell/browser/api/atom_api_browser_window.cc | 33 ++-- shell/browser/api/atom_api_browser_window.h | 2 +- shell/browser/api/atom_api_cookies.cc | 13 +- shell/browser/api/atom_api_cookies.h | 10 +- shell/browser/api/atom_api_debugger.cc | 21 +-- shell/browser/api/atom_api_debugger.h | 20 +-- shell/browser/api/atom_api_desktop_capturer.h | 8 +- shell/browser/api/atom_api_download_item.cc | 31 ++-- shell/browser/api/atom_api_download_item.h | 10 +- shell/browser/api/atom_api_global_shortcut.cc | 17 +- shell/browser/api/atom_api_global_shortcut.h | 8 +- shell/browser/api/atom_api_in_app_purchase.h | 6 +- shell/browser/api/atom_api_menu.cc | 11 +- shell/browser/api/atom_api_menu.h | 19 +- shell/browser/api/atom_api_native_theme.h | 6 +- shell/browser/api/atom_api_net_log.cc | 35 ++-- shell/browser/api/atom_api_net_log.h | 14 +- shell/browser/api/atom_api_notification.cc | 1 - shell/browser/api/atom_api_notification.h | 4 +- shell/browser/api/atom_api_power_monitor.cc | 30 ++-- shell/browser/api/atom_api_power_monitor.h | 5 +- shell/browser/api/atom_api_protocol.h | 4 +- shell/browser/api/atom_api_screen.h | 3 +- shell/browser/api/atom_api_session.cc | 82 ++++----- shell/browser/api/atom_api_session.h | 43 ++--- .../browser/api/atom_api_system_preferences.h | 8 +- .../browser/api/atom_api_top_level_window.cc | 36 ++-- shell/browser/api/atom_api_top_level_window.h | 20 +-- shell/browser/api/atom_api_tray.h | 8 +- shell/browser/api/atom_api_url_request.cc | 2 +- shell/browser/api/atom_api_url_request.h | 3 +- shell/browser/api/atom_api_view.cc | 17 +- shell/browser/api/atom_api_view.h | 14 +- shell/browser/api/atom_api_web_contents.cc | 170 ++++++++---------- shell/browser/api/atom_api_web_contents.h | 52 +++--- .../browser/api/atom_api_web_contents_view.cc | 18 +- .../browser/api/atom_api_web_contents_view.h | 7 +- .../browser/api/atom_api_web_view_manager.cc | 8 +- shell/browser/api/event_emitter_deprecated.cc | 96 ---------- shell/browser/api/event_emitter_deprecated.h | 128 ------------- .../api/views/atom_api_layout_manager.h | 4 +- shell/browser/atom_browser_main_parts.cc | 2 +- shell/browser/lib/bluetooth_chooser.cc | 14 +- shell/browser/native_window.cc | 6 +- shell/browser/native_window.h | 13 +- shell/browser/native_window_mac.h | 2 +- shell/browser/native_window_mac.mm | 10 +- shell/browser/native_window_views.cc | 8 +- shell/browser/native_window_views.h | 3 +- shell/browser/net/atom_url_loader_factory.cc | 4 +- shell/browser/web_contents_preferences.cc | 10 +- shell/browser/web_contents_preferences.h | 4 +- shell/common/api/atom_api_native_image.cc | 89 +++++---- shell/common/api/atom_api_native_image.h | 69 +++---- shell/common/api/atom_api_native_image_mac.mm | 2 +- shell/common/api/atom_api_v8_util.cc | 12 +- .../accelerator_converter.cc | 6 +- .../accelerator_converter.h | 12 +- .../blink_converter_gin_adapter.h | 49 +++++ .../content_converter.cc | 97 +++++++--- .../content_converter.h | 22 ++- .../common/gin_converters/image_converter.cc | 8 +- shell/common/gin_converters/net_converter.cc | 52 ++++++ shell/common/gin_converters/net_converter.h | 10 ++ shell/common/gin_converters/std_converter.h | 7 + shell/common/gin_helper/event_emitter.cc | 26 +++ shell/common/gin_helper/event_emitter.h | 42 ++++- .../gin_helper}/trackable_object.cc | 11 +- .../gin_helper}/trackable_object.h | 35 ++-- .../native_mate_converters/blink_converter.cc | 38 +--- .../native_mate_converters/blink_converter.h | 13 -- .../network_converter.cc | 94 ---------- .../network_converter.h | 29 --- .../ui_base_types_converter.h | 34 ---- spec-main/api-web-contents-spec.ts | 10 +- 80 files changed, 823 insertions(+), 1087 deletions(-) delete mode 100644 shell/browser/api/event_emitter_deprecated.cc delete mode 100644 shell/browser/api/event_emitter_deprecated.h rename shell/common/{native_mate_converters => gin_converters}/accelerator_converter.cc (83%) rename shell/common/{native_mate_converters => gin_converters}/accelerator_converter.h (56%) rename shell/common/{native_mate_converters => gin_converters}/content_converter.cc (71%) rename shell/common/{native_mate_converters => gin_converters}/content_converter.h (78%) rename shell/{browser/api => common/gin_helper}/trackable_object.cc (83%) rename shell/{browser/api => common/gin_helper}/trackable_object.h (76%) delete mode 100644 shell/common/native_mate_converters/network_converter.cc delete mode 100644 shell/common/native_mate_converters/network_converter.h delete mode 100644 shell/common/native_mate_converters/ui_base_types_converter.h diff --git a/filenames.gni b/filenames.gni index e298a27501..7c3fdf0d4d 100644 --- a/filenames.gni +++ b/filenames.gni @@ -112,10 +112,6 @@ filenames = { "shell/browser/api/atom_api_browser_window_views.cc", "shell/browser/api/event.cc", "shell/browser/api/event.h", - "shell/browser/api/event_emitter_deprecated.cc", - "shell/browser/api/event_emitter_deprecated.h", - "shell/browser/api/trackable_object.cc", - "shell/browser/api/trackable_object.h", "shell/browser/api/frame_subscriber.cc", "shell/browser/api/frame_subscriber.h", "shell/browser/api/gpu_info_enumerator.cc", @@ -468,7 +464,11 @@ filenames = { "shell/common/crash_reporter/linux/crash_dump_handler.h", "shell/common/crash_reporter/win/crash_service_main.cc", "shell/common/crash_reporter/win/crash_service_main.h", + "shell/common/gin_converters/accelerator_converter.cc", + "shell/common/gin_converters/accelerator_converter.h", "shell/common/gin_converters/callback_converter.h", + "shell/common/gin_converters/content_converter.cc", + "shell/common/gin_converters/content_converter.h", "shell/common/gin_converters/file_dialog_converter.cc", "shell/common/gin_converters/file_dialog_converter.h", "shell/common/gin_converters/file_path_converter.h", @@ -502,6 +502,8 @@ filenames = { "shell/common/gin_helper/function_template.h", "shell/common/gin_helper/object_template_builder.cc", "shell/common/gin_helper/object_template_builder.h", + "shell/common/gin_helper/trackable_object.cc", + "shell/common/gin_helper/trackable_object.h", "shell/common/heap_snapshot.cc", "shell/common/heap_snapshot.h", "shell/common/key_weak_map.h", @@ -513,25 +515,18 @@ filenames = { "shell/common/mouse_util.h", "shell/common/mac/main_application_bundle.h", "shell/common/mac/main_application_bundle.mm", - "shell/common/native_mate_converters/accelerator_converter.cc", - "shell/common/native_mate_converters/accelerator_converter.h", "shell/common/native_mate_converters/blink_converter.cc", "shell/common/native_mate_converters/blink_converter.h", "shell/common/native_mate_converters/callback_converter_deprecated.cc", "shell/common/native_mate_converters/callback_converter_deprecated.h", - "shell/common/native_mate_converters/content_converter.cc", - "shell/common/native_mate_converters/content_converter.h", "shell/common/native_mate_converters/file_dialog_converter.h", "shell/common/native_mate_converters/file_path_converter.h", "shell/common/native_mate_converters/gurl_converter.h", "shell/common/native_mate_converters/image_converter.h", "shell/common/native_mate_converters/native_window_converter.h", "shell/common/native_mate_converters/net_converter.h", - "shell/common/native_mate_converters/network_converter.cc", - "shell/common/native_mate_converters/network_converter.h", "shell/common/native_mate_converters/once_callback.h", "shell/common/native_mate_converters/string16_converter.h", - "shell/common/native_mate_converters/ui_base_types_converter.h", "shell/common/native_mate_converters/v8_value_converter.cc", "shell/common/native_mate_converters/v8_value_converter.h", "shell/common/native_mate_converters/value_converter.cc", diff --git a/shell/browser/api/atom_api_app.h b/shell/browser/api/atom_api_app.h index c3b7a7461e..43bfe219ba 100644 --- a/shell/browser/api/atom_api_app.h +++ b/shell/browser/api/atom_api_app.h @@ -18,7 +18,6 @@ #include "content/public/browser/gpu_data_manager_observer.h" #include "content/public/browser/render_process_host.h" #include "gin/handle.h" -#include "native_mate/wrappable.h" #include "net/base/completion_once_callback.h" #include "net/base/completion_repeating_callback.h" #include "net/ssl/client_cert_identity.h" @@ -48,7 +47,7 @@ enum class JumpListResult : int; namespace api { class App : public AtomBrowserClient::Delegate, - public gin_helper::EventEmitter>, + public gin_helper::EventEmitter, public BrowserObserver, public content::GpuDataManagerObserver, public content::BrowserChildProcessObserver { diff --git a/shell/browser/api/atom_api_auto_updater.h b/shell/browser/api/atom_api_auto_updater.h index 5664491031..3e69fe385e 100644 --- a/shell/browser/api/atom_api_auto_updater.h +++ b/shell/browser/api/atom_api_auto_updater.h @@ -8,7 +8,6 @@ #include #include "gin/handle.h" -#include "native_mate/wrappable.h" #include "shell/browser/auto_updater.h" #include "shell/browser/window_list_observer.h" #include "shell/common/gin_helper/event_emitter.h" @@ -17,10 +16,9 @@ namespace electron { namespace api { -class AutoUpdater - : public gin_helper::EventEmitter>, - public auto_updater::Delegate, - public WindowListObserver { +class AutoUpdater : public gin_helper::EventEmitter, + public auto_updater::Delegate, + public WindowListObserver { public: static gin::Handle Create(v8::Isolate* isolate); diff --git a/shell/browser/api/atom_api_browser_view.cc b/shell/browser/api/atom_api_browser_view.cc index a246092a35..d59f2ed4df 100644 --- a/shell/browser/api/atom_api_browser_view.cc +++ b/shell/browser/api/atom_api_browser_view.cc @@ -4,7 +4,6 @@ #include "shell/browser/api/atom_api_browser_view.h" -#include "native_mate/dictionary.h" #include "shell/browser/api/atom_api_web_contents.h" #include "shell/browser/browser.h" #include "shell/browser/native_browser_view.h" @@ -64,11 +63,8 @@ BrowserView::BrowserView(gin::Arguments* args, gin::Dictionary::CreateEmpty(isolate); options.Get(options::kWebPreferences, &web_preferences); web_preferences.Set("type", "browserView"); - mate::Handle web_contents = WebContents::Create( - isolate, - // TODO(zcbenz): No need to do convertion after converting constructor - // of WebContents to gin. - mate::Dictionary(isolate, web_preferences.GetHandle())); + gin::Handle web_contents = + WebContents::Create(isolate, web_preferences); web_contents_.Reset(isolate, web_contents.ToV8()); api_web_contents_ = web_contents.get(); diff --git a/shell/browser/api/atom_api_browser_view.h b/shell/browser/api/atom_api_browser_view.h index 61fc836063..fe8c2ef733 100644 --- a/shell/browser/api/atom_api_browser_view.h +++ b/shell/browser/api/atom_api_browser_view.h @@ -10,9 +10,9 @@ #include "content/public/browser/web_contents_observer.h" #include "gin/handle.h" -#include "shell/browser/api/trackable_object.h" #include "shell/browser/native_browser_view.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/trackable_object.h" namespace gfx { class Rect; @@ -30,7 +30,7 @@ namespace api { class WebContents; -class BrowserView : public mate::TrackableObject, +class BrowserView : public gin_helper::TrackableObject, public content::WebContentsObserver { public: static mate::WrappableBase* New(gin_helper::ErrorThrower thrower, diff --git a/shell/browser/api/atom_api_browser_window.cc b/shell/browser/api/atom_api_browser_window.cc index 4e85062dc9..436c345d07 100644 --- a/shell/browser/api/atom_api_browser_window.cc +++ b/shell/browser/api/atom_api_browser_window.cc @@ -12,15 +12,15 @@ #include "content/browser/web_contents/web_contents_impl.h" // nogncheck #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" -#include "gin/converter.h" -#include "native_mate/dictionary.h" #include "shell/browser/browser.h" #include "shell/browser/unresponsive_suppressor.h" #include "shell/browser/web_contents_preferences.h" #include "shell/browser/window_list.h" #include "shell/common/api/constructor.h" #include "shell/common/color_util.h" -#include "shell/common/native_mate_converters/value_converter.h" +#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" #include "shell/common/options_switches.h" #include "ui/gl/gpu_switching_manager.h" @@ -30,13 +30,14 @@ namespace electron { namespace api { BrowserWindow::BrowserWindow(gin::Arguments* args, - const mate::Dictionary& options) + const gin_helper::Dictionary& options) : TopLevelWindow(args->isolate(), options), weak_factory_(this) { - mate::Handle web_contents; + gin::Handle web_contents; // Use options.webPreferences in WebContents. v8::Isolate* isolate = args->isolate(); - mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary web_preferences = + gin::Dictionary::CreateEmpty(isolate); options.Get(options::kWebPreferences, &web_preferences); // Copy the backgroundColor to webContents. @@ -66,8 +67,8 @@ BrowserWindow::BrowserWindow(gin::Arguments* args, auto* existing_preferences = WebContentsPreferences::From(web_contents->web_contents()); base::DictionaryValue web_preferences_dict; - if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(), - &web_preferences_dict)) { + if (gin::ConvertFromV8(isolate, web_preferences.GetHandle(), + &web_preferences_dict)) { existing_preferences->Clear(); existing_preferences->Merge(web_preferences_dict); } @@ -82,7 +83,7 @@ BrowserWindow::BrowserWindow(gin::Arguments* args, Observe(api_web_contents_->web_contents()); // Keep a copy of the options for later use. - mate::Dictionary(isolate, web_contents->GetWrapper()) + gin_helper::Dictionary(isolate, web_contents->GetWrapper()) .Set("browserWindowOptions", options); // Associate with BrowserWindow. @@ -195,8 +196,8 @@ void BrowserWindow::OnCloseContents() { v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); for (v8::Local value : child_windows_.Values(isolate())) { - mate::Handle child; - if (mate::ConvertFromV8(isolate(), value, &child) && !child.IsEmpty()) + gin::Handle child; + if (gin::ConvertFromV8(isolate(), value, &child) && !child.IsEmpty()) child->window()->CloseImmediately(); } @@ -456,9 +457,9 @@ mate::WrappableBase* BrowserWindow::New(gin_helper::ErrorThrower thrower, return nullptr; } - mate::Dictionary options; + gin_helper::Dictionary options; if (!(args->Length() == 1 && args->GetNext(&options))) { - options = mate::Dictionary::CreateEmpty(args->isolate()); + options = gin::Dictionary::CreateEmpty(args->isolate()); } return new BrowserWindow(args, options); @@ -467,8 +468,8 @@ mate::WrappableBase* BrowserWindow::New(gin_helper::ErrorThrower thrower, // static void BrowserWindow::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow")); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + prototype->SetClassName(gin::StringToV8(isolate, "BrowserWindow")); + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("focusOnWebView", &BrowserWindow::FocusOnWebView) .SetMethod("blurWebView", &BrowserWindow::BlurWebView) .SetMethod("isWebViewFocused", &BrowserWindow::IsWebViewFocused) @@ -499,7 +500,7 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); + gin_helper::Dictionary dict(isolate, exports); dict.Set("BrowserWindow", mate::CreateConstructor( isolate, base::BindRepeating(&BrowserWindow::New))); diff --git a/shell/browser/api/atom_api_browser_window.h b/shell/browser/api/atom_api_browser_window.h index c0a9900b59..644c91a2c8 100644 --- a/shell/browser/api/atom_api_browser_window.h +++ b/shell/browser/api/atom_api_browser_window.h @@ -38,7 +38,7 @@ class BrowserWindow : public TopLevelWindow, } protected: - BrowserWindow(gin::Arguments* args, const mate::Dictionary& options); + BrowserWindow(gin::Arguments* args, const gin_helper::Dictionary& options); ~BrowserWindow() override; // content::RenderWidgetHost::InputEventObserver: diff --git a/shell/browser/api/atom_api_cookies.cc b/shell/browser/api/atom_api_cookies.cc index fc392b5d23..6042249d21 100644 --- a/shell/browser/api/atom_api_cookies.cc +++ b/shell/browser/api/atom_api_cookies.cc @@ -15,14 +15,15 @@ #include "content/public/browser/storage_partition.h" #include "gin/dictionary.h" #include "gin/object_template_builder.h" -#include "native_mate/dictionary.h" #include "net/cookies/canonical_cookie.h" #include "net/cookies/cookie_store.h" #include "net/cookies/cookie_util.h" #include "shell/browser/atom_browser_context.h" #include "shell/browser/cookie_change_notifier.h" -#include "shell/common/native_mate_converters/gurl_converter.h" -#include "shell/common/native_mate_converters/value_converter.h" +#include "shell/common/gin_converters/gurl_converter.h" +#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/object_template_builder.h" using content::BrowserThread; @@ -175,7 +176,7 @@ Cookies::Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context) Cookies::~Cookies() = default; -v8::Local Cookies::Get(const mate::Dictionary& filter) { +v8::Local Cookies::Get(const gin_helper::Dictionary& filter) { util::Promise promise(isolate()); v8::Local handle = promise.GetHandle(); @@ -184,7 +185,7 @@ v8::Local Cookies::Get(const mate::Dictionary& filter) { auto* manager = storage_partition->GetCookieManagerForBrowserProcess(); base::DictionaryValue dict; - mate::ConvertFromV8(isolate(), filter.GetHandle(), &dict); + gin::ConvertFromV8(isolate(), filter.GetHandle(), &dict); std::string url; filter.Get("url", &url); @@ -339,7 +340,7 @@ gin::Handle Cookies::Create(v8::Isolate* isolate, void Cookies::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { prototype->SetClassName(gin::StringToV8(isolate, "Cookies")); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("get", &Cookies::Get) .SetMethod("remove", &Cookies::Remove) .SetMethod("set", &Cookies::Set) diff --git a/shell/browser/api/atom_api_cookies.h b/shell/browser/api/atom_api_cookies.h index eba0fb6229..bf39c334d9 100644 --- a/shell/browser/api/atom_api_cookies.h +++ b/shell/browser/api/atom_api_cookies.h @@ -11,15 +11,15 @@ #include "base/callback_list.h" #include "gin/handle.h" #include "net/cookies/canonical_cookie.h" -#include "shell/browser/api/trackable_object.h" #include "shell/browser/net/cookie_details.h" +#include "shell/common/gin_helper/trackable_object.h" #include "shell/common/promise_util.h" namespace base { class DictionaryValue; } -namespace mate { +namespace gin_helper { class Dictionary; } @@ -33,12 +33,12 @@ class AtomBrowserContext; namespace api { -class Cookies : public mate::TrackableObject { +class Cookies : public gin_helper::TrackableObject { public: static gin::Handle Create(v8::Isolate* isolate, AtomBrowserContext* browser_context); - // mate::TrackableObject: + // gin_helper::TrackableObject: static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); @@ -46,7 +46,7 @@ class Cookies : public mate::TrackableObject { Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context); ~Cookies() override; - v8::Local Get(const mate::Dictionary& filter); + v8::Local Get(const gin_helper::Dictionary& filter); v8::Local Set(const base::DictionaryValue& details); v8::Local Remove(const GURL& url, const std::string& name); v8::Local FlushStore(); diff --git a/shell/browser/api/atom_api_debugger.cc b/shell/browser/api/atom_api_debugger.cc index 083342802b..f4f6c91146 100644 --- a/shell/browser/api/atom_api_debugger.cc +++ b/shell/browser/api/atom_api_debugger.cc @@ -12,8 +12,9 @@ #include "base/json/json_writer.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/web_contents.h" -#include "native_mate/dictionary.h" -#include "shell/common/native_mate_converters/value_converter.h" +#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" using content::DevToolsAgentHost; @@ -93,7 +94,7 @@ void Debugger::RenderFrameHostChanged(content::RenderFrameHost* old_rfh, } } -void Debugger::Attach(mate::Arguments* args) { +void Debugger::Attach(gin_helper::Arguments* args) { std::string protocol_version; args->GetNext(&protocol_version); @@ -128,7 +129,7 @@ void Debugger::Detach() { AgentHostClosed(agent_host_.get()); } -v8::Local Debugger::SendCommand(mate::Arguments* args) { +v8::Local Debugger::SendCommand(gin_helper::Arguments* args) { electron::util::Promise promise(isolate()); v8::Local handle = promise.GetHandle(); @@ -168,16 +169,16 @@ void Debugger::ClearPendingRequests() { } // static -mate::Handle Debugger::Create(v8::Isolate* isolate, - content::WebContents* web_contents) { - return mate::CreateHandle(isolate, new Debugger(isolate, web_contents)); +gin::Handle Debugger::Create(v8::Isolate* isolate, + content::WebContents* web_contents) { + return gin::CreateHandle(isolate, new Debugger(isolate, web_contents)); } // static void Debugger::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "Debugger")); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + prototype->SetClassName(gin::StringToV8(isolate, "Debugger")); + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("attach", &Debugger::Attach) .SetMethod("isAttached", &Debugger::IsAttached) .SetMethod("detach", &Debugger::Detach) @@ -197,7 +198,7 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary(isolate, exports) + gin_helper::Dictionary(isolate, exports) .Set("Debugger", Debugger::GetConstructor(isolate) ->GetFunction(context) .ToLocalChecked()); diff --git a/shell/browser/api/atom_api_debugger.h b/shell/browser/api/atom_api_debugger.h index 4bf882ea2c..83f23388ca 100644 --- a/shell/browser/api/atom_api_debugger.h +++ b/shell/browser/api/atom_api_debugger.h @@ -12,8 +12,8 @@ #include "base/values.h" #include "content/public/browser/devtools_agent_host_client.h" #include "content/public/browser/web_contents_observer.h" -#include "native_mate/handle.h" -#include "shell/browser/api/trackable_object.h" +#include "gin/handle.h" +#include "shell/common/gin_helper/trackable_object.h" #include "shell/common/promise_util.h" namespace content { @@ -21,22 +21,18 @@ class DevToolsAgentHost; class WebContents; } // namespace content -namespace mate { -class Arguments; -} - namespace electron { namespace api { -class Debugger : public mate::TrackableObject, +class Debugger : public gin_helper::TrackableObject, public content::DevToolsAgentHostClient, public content::WebContentsObserver { public: - static mate::Handle Create(v8::Isolate* isolate, - content::WebContents* web_contents); + static gin::Handle Create(v8::Isolate* isolate, + content::WebContents* web_contents); - // mate::TrackableObject: + // gin_helper::TrackableObject: static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); @@ -57,10 +53,10 @@ class Debugger : public mate::TrackableObject, using PendingRequestMap = std::map>; - void Attach(mate::Arguments* args); + void Attach(gin_helper::Arguments* args); bool IsAttached(); void Detach(); - v8::Local SendCommand(mate::Arguments* args); + v8::Local SendCommand(gin_helper::Arguments* args); void ClearPendingRequests(); content::WebContents* web_contents_; // Weak Reference. diff --git a/shell/browser/api/atom_api_desktop_capturer.h b/shell/browser/api/atom_api_desktop_capturer.h index 77360c4bc7..3481b8d2a0 100644 --- a/shell/browser/api/atom_api_desktop_capturer.h +++ b/shell/browser/api/atom_api_desktop_capturer.h @@ -12,17 +12,13 @@ #include "chrome/browser/media/webrtc/desktop_media_list_observer.h" #include "chrome/browser/media/webrtc/native_desktop_media_list.h" #include "gin/handle.h" -#include "shell/browser/api/trackable_object.h" -#include "shell/common/gin_helper/event_emitter.h" +#include "shell/common/gin_helper/trackable_object.h" namespace electron { namespace api { -class DesktopCapturer - : public mate::TrackableObject< - DesktopCapturer, - gin_helper::EventEmitter>> { +class DesktopCapturer : public gin_helper::TrackableObject { public: struct Source { DesktopMediaList::Source media_list_source; diff --git a/shell/browser/api/atom_api_download_item.cc b/shell/browser/api/atom_api_download_item.cc index 7a2649013b..b72e095ff6 100644 --- a/shell/browser/api/atom_api_download_item.cc +++ b/shell/browser/api/atom_api_download_item.cc @@ -8,15 +8,16 @@ #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_task_runner_handle.h" -#include "native_mate/dictionary.h" #include "net/base/filename_util.h" #include "shell/browser/atom_browser_main_parts.h" -#include "shell/common/native_mate_converters/file_dialog_converter.h" -#include "shell/common/native_mate_converters/file_path_converter.h" -#include "shell/common/native_mate_converters/gurl_converter.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/object_template_builder.h" #include "shell/common/node_includes.h" -namespace mate { +namespace gin { template <> struct Converter { @@ -44,7 +45,7 @@ struct Converter { } }; -} // namespace mate +} // namespace gin namespace electron { @@ -52,7 +53,7 @@ namespace api { namespace { -std::map> g_download_item_objects; +std::map> g_download_item_objects; } // namespace @@ -188,9 +189,9 @@ double DownloadItem::GetStartTime() const { // static void DownloadItem::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "DownloadItem")); + prototype->SetClassName(gin::StringToV8(isolate, "DownloadItem")); gin_helper::Destroyable::MakeDestroyable(isolate, prototype); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("pause", &DownloadItem::Pause) .SetMethod("isPaused", &DownloadItem::IsPaused) .SetMethod("resume", &DownloadItem::Resume) @@ -218,17 +219,17 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate, } // static -mate::Handle DownloadItem::Create(v8::Isolate* isolate, - download::DownloadItem* item) { +gin::Handle DownloadItem::Create(v8::Isolate* isolate, + download::DownloadItem* item) { auto* existing = TrackableObject::FromWrappedClass(isolate, item); if (existing) - return mate::CreateHandle(isolate, static_cast(existing)); + return gin::CreateHandle(isolate, static_cast(existing)); - auto handle = mate::CreateHandle(isolate, new DownloadItem(isolate, item)); + auto handle = gin::CreateHandle(isolate, new DownloadItem(isolate, item)); // Reference this object in case it got garbage collected. g_download_item_objects[handle->weak_map_id()] = - v8::Global(isolate, handle.ToV8()); + v8::Global(isolate, handle.ToV8()); return handle; } @@ -243,7 +244,7 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary(isolate, exports) + gin_helper::Dictionary(isolate, exports) .Set("DownloadItem", electron::api::DownloadItem::GetConstructor(isolate) ->GetFunction(context) .ToLocalChecked()); diff --git a/shell/browser/api/atom_api_download_item.h b/shell/browser/api/atom_api_download_item.h index e2310e5666..33fbf97ac2 100644 --- a/shell/browser/api/atom_api_download_item.h +++ b/shell/browser/api/atom_api_download_item.h @@ -10,20 +10,20 @@ #include "base/files/file_path.h" #include "components/download/public/common/download_item.h" -#include "native_mate/handle.h" -#include "shell/browser/api/trackable_object.h" +#include "gin/handle.h" #include "shell/browser/ui/file_dialog.h" +#include "shell/common/gin_helper/trackable_object.h" #include "url/gurl.h" namespace electron { namespace api { -class DownloadItem : public mate::TrackableObject, +class DownloadItem : public gin_helper::TrackableObject, public download::DownloadItem::Observer { public: - static mate::Handle Create(v8::Isolate* isolate, - download::DownloadItem* item); + static gin::Handle Create(v8::Isolate* isolate, + download::DownloadItem* item); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); diff --git a/shell/browser/api/atom_api_global_shortcut.cc b/shell/browser/api/atom_api_global_shortcut.cc index 09e5f1c387..8bf7a0662e 100644 --- a/shell/browser/api/atom_api_global_shortcut.cc +++ b/shell/browser/api/atom_api_global_shortcut.cc @@ -9,10 +9,11 @@ #include "base/stl_util.h" #include "base/strings/utf_string_conversions.h" -#include "native_mate/dictionary.h" #include "shell/browser/api/atom_api_system_preferences.h" -#include "shell/common/native_mate_converters/accelerator_converter.h" -#include "shell/common/native_mate_converters/callback_converter_deprecated.h" +#include "shell/common/gin_converters/accelerator_converter.h" +#include "shell/common/gin_converters/callback_converter.h" +#include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" #if defined(OS_MACOSX) @@ -131,15 +132,15 @@ void GlobalShortcut::UnregisterAll() { } // static -mate::Handle GlobalShortcut::Create(v8::Isolate* isolate) { - return mate::CreateHandle(isolate, new GlobalShortcut(isolate)); +gin::Handle GlobalShortcut::Create(v8::Isolate* isolate) { + return gin::CreateHandle(isolate, new GlobalShortcut(isolate)); } // static void GlobalShortcut::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "GlobalShortcut")); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + prototype->SetClassName(gin::StringToV8(isolate, "GlobalShortcut")); + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("registerAll", &GlobalShortcut::RegisterAll) .SetMethod("register", &GlobalShortcut::Register) .SetMethod("isRegistered", &GlobalShortcut::IsRegistered) @@ -158,7 +159,7 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); + gin_helper::Dictionary dict(isolate, exports); dict.Set("globalShortcut", electron::api::GlobalShortcut::Create(isolate)); } diff --git a/shell/browser/api/atom_api_global_shortcut.h b/shell/browser/api/atom_api_global_shortcut.h index 456a554524..d614227211 100644 --- a/shell/browser/api/atom_api_global_shortcut.h +++ b/shell/browser/api/atom_api_global_shortcut.h @@ -11,8 +11,8 @@ #include "base/callback.h" #include "chrome/browser/extensions/global_shortcut_listener.h" -#include "native_mate/handle.h" -#include "shell/browser/api/trackable_object.h" +#include "gin/handle.h" +#include "shell/common/gin_helper/trackable_object.h" #include "ui/base/accelerators/accelerator.h" namespace electron { @@ -20,9 +20,9 @@ namespace electron { namespace api { class GlobalShortcut : public extensions::GlobalShortcutListener::Observer, - public mate::TrackableObject { + public gin_helper::TrackableObject { public: - static mate::Handle Create(v8::Isolate* isolate); + static gin::Handle Create(v8::Isolate* isolate); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); diff --git a/shell/browser/api/atom_api_in_app_purchase.h b/shell/browser/api/atom_api_in_app_purchase.h index 0226f0ae76..dec89ebad3 100644 --- a/shell/browser/api/atom_api_in_app_purchase.h +++ b/shell/browser/api/atom_api_in_app_purchase.h @@ -9,7 +9,6 @@ #include #include "gin/handle.h" -#include "native_mate/wrappable.h" #include "shell/browser/mac/in_app_purchase.h" #include "shell/browser/mac/in_app_purchase_observer.h" #include "shell/browser/mac/in_app_purchase_product.h" @@ -20,9 +19,8 @@ namespace electron { namespace api { -class InAppPurchase - : public gin_helper::EventEmitter>, - public in_app_purchase::TransactionObserver { +class InAppPurchase : public gin_helper::EventEmitter, + public in_app_purchase::TransactionObserver { public: static gin::Handle Create(v8::Isolate* isolate); diff --git a/shell/browser/api/atom_api_menu.cc b/shell/browser/api/atom_api_menu.cc index d28439eabc..2199dbeec9 100644 --- a/shell/browser/api/atom_api_menu.cc +++ b/shell/browser/api/atom_api_menu.cc @@ -6,13 +6,12 @@ #include -#include "native_mate/constructor.h" #include "shell/browser/native_window.h" +#include "shell/common/gin_converters/accelerator_converter.h" #include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/image_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" -#include "shell/common/native_mate_converters/accelerator_converter.h" #include "shell/common/node_includes.h" namespace { @@ -88,7 +87,7 @@ bool Menu::GetAcceleratorForCommandIdWithParams( v8::HandleScope handle_scope(isolate()); v8::Local val = get_accelerator_.Run(GetWrapper(), command_id, use_default_accelerator); - return mate::ConvertFromV8(isolate(), val, accelerator); + return gin::ConvertFromV8(isolate(), val, accelerator); } bool Menu::ShouldRegisterAcceleratorForCommandId(int command_id) const { @@ -100,9 +99,9 @@ bool Menu::ShouldRegisterAcceleratorForCommandId(int command_id) const { void Menu::ExecuteCommand(int command_id, int flags) { v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); - execute_command_.Run(GetWrapper(), - mate::internal::CreateEventFromFlags(isolate(), flags), - command_id); + execute_command_.Run( + GetWrapper(), + gin_helper::internal::CreateEventFromFlags(isolate(), flags), command_id); } void Menu::OnMenuWillShow(ui::SimpleMenuModel* source) { diff --git a/shell/browser/api/atom_api_menu.h b/shell/browser/api/atom_api_menu.h index b67eb925f1..4263f8c844 100644 --- a/shell/browser/api/atom_api_menu.h +++ b/shell/browser/api/atom_api_menu.h @@ -11,14 +11,14 @@ #include "base/callback.h" #include "gin/arguments.h" #include "shell/browser/api/atom_api_top_level_window.h" -#include "shell/browser/api/trackable_object.h" #include "shell/browser/ui/atom_menu_model.h" +#include "shell/common/gin_helper/trackable_object.h" namespace electron { namespace api { -class Menu : public mate::TrackableObject, +class Menu : public gin_helper::TrackableObject, public AtomMenuModel::Delegate, public AtomMenuModel::Observer { public: @@ -122,7 +122,7 @@ class Menu : public mate::TrackableObject, } // namespace electron -namespace mate { +namespace gin { template <> struct Converter { @@ -143,6 +143,19 @@ struct Converter { } }; +} // namespace gin + +namespace mate { + +template <> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + electron::AtomMenuModel** out) { + return gin::ConvertFromV8(isolate, val, out); + } +}; + } // namespace mate #endif // SHELL_BROWSER_API_ATOM_API_MENU_H_ diff --git a/shell/browser/api/atom_api_native_theme.h b/shell/browser/api/atom_api_native_theme.h index 99e307655e..632e651fa5 100644 --- a/shell/browser/api/atom_api_native_theme.h +++ b/shell/browser/api/atom_api_native_theme.h @@ -5,7 +5,6 @@ #ifndef SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_ #define SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_ -#include "native_mate/wrappable.h" #include "shell/common/gin_helper/event_emitter.h" #include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme_observer.h" @@ -14,9 +13,8 @@ namespace electron { namespace api { -class NativeTheme - : public gin_helper::EventEmitter>, - public ui::NativeThemeObserver { +class NativeTheme : public gin_helper::EventEmitter, + public ui::NativeThemeObserver { public: static v8::Local Create(v8::Isolate* isolate); diff --git a/shell/browser/api/atom_api_net_log.cc b/shell/browser/api/atom_api_net_log.cc index 5400089f4f..fde65f9022 100644 --- a/shell/browser/api/atom_api_net_log.cc +++ b/shell/browser/api/atom_api_net_log.cc @@ -11,15 +11,14 @@ #include "components/net_log/chrome_net_log.h" #include "content/public/browser/storage_partition.h" #include "electron/electron_version.h" -#include "native_mate/converter.h" -#include "native_mate/dictionary.h" -#include "native_mate/handle.h" #include "shell/browser/atom_browser_context.h" #include "shell/browser/net/system_network_context_manager.h" -#include "shell/common/native_mate_converters/file_path_converter.h" +#include "shell/common/gin_converters/file_path_converter.h" +#include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" -namespace mate { +namespace gin { template <> struct Converter { @@ -41,7 +40,7 @@ struct Converter { } }; -} // namespace mate +} // namespace gin namespace electron { @@ -84,7 +83,7 @@ NetLog::NetLog(v8::Isolate* isolate, AtomBrowserContext* browser_context) NetLog::~NetLog() = default; v8::Local NetLog::StartLogging(base::FilePath log_path, - mate::Arguments* args) { + gin_helper::Arguments* args) { if (log_path.empty()) { args->ThrowError("The first parameter must be a valid string"); return v8::Local(); @@ -93,20 +92,20 @@ v8::Local NetLog::StartLogging(base::FilePath log_path, net::NetLogCaptureMode capture_mode = net::NetLogCaptureMode::kDefault; uint64_t max_file_size = network::mojom::NetLogExporter::kUnlimitedFileSize; - mate::Dictionary dict; + gin_helper::Dictionary dict; if (args->GetNext(&dict)) { v8::Local capture_mode_v8; if (dict.Get("captureMode", &capture_mode_v8)) { - if (!mate::ConvertFromV8(args->isolate(), capture_mode_v8, - &capture_mode)) { + if (!gin::ConvertFromV8(args->isolate(), capture_mode_v8, + &capture_mode)) { args->ThrowError("Invalid value for captureMode"); return v8::Local(); } } v8::Local max_file_size_v8; if (dict.Get("maxFileSize", &max_file_size_v8)) { - if (!mate::ConvertFromV8(args->isolate(), max_file_size_v8, - &max_file_size)) { + if (!gin::ConvertFromV8(args->isolate(), max_file_size_v8, + &max_file_size)) { args->ThrowError("Invalid value for maxFileSize"); return v8::Local(); } @@ -187,7 +186,7 @@ bool NetLog::IsCurrentlyLogging() const { return !!net_log_exporter_; } -v8::Local NetLog::StopLogging(mate::Arguments* args) { +v8::Local NetLog::StopLogging(gin_helper::Arguments* args) { util::Promise promise(isolate()); v8::Local handle = promise.GetHandle(); @@ -211,16 +210,16 @@ v8::Local NetLog::StopLogging(mate::Arguments* args) { } // static -mate::Handle NetLog::Create(v8::Isolate* isolate, - AtomBrowserContext* browser_context) { - return mate::CreateHandle(isolate, new NetLog(isolate, browser_context)); +gin::Handle NetLog::Create(v8::Isolate* isolate, + AtomBrowserContext* browser_context) { + return gin::CreateHandle(isolate, new NetLog(isolate, browser_context)); } // static void NetLog::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "NetLog")); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + prototype->SetClassName(gin::StringToV8(isolate, "NetLog")); + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetProperty("currentlyLogging", &NetLog::IsCurrentlyLogging) .SetMethod("startLogging", &NetLog::StartLogging) .SetMethod("stopLogging", &NetLog::StopLogging); diff --git a/shell/browser/api/atom_api_net_log.h b/shell/browser/api/atom_api_net_log.h index 3618a3a6dd..aac501b708 100644 --- a/shell/browser/api/atom_api_net_log.h +++ b/shell/browser/api/atom_api_net_log.h @@ -12,9 +12,9 @@ #include "base/callback.h" #include "base/optional.h" #include "base/values.h" -#include "native_mate/handle.h" +#include "gin/handle.h" #include "services/network/public/mojom/net_log.mojom.h" -#include "shell/browser/api/trackable_object.h" +#include "shell/common/gin_helper/trackable_object.h" #include "shell/common/promise_util.h" namespace electron { @@ -23,17 +23,17 @@ class AtomBrowserContext; namespace api { -class NetLog : public mate::TrackableObject { +class NetLog : public gin_helper::TrackableObject { public: - static mate::Handle Create(v8::Isolate* isolate, - AtomBrowserContext* browser_context); + static gin::Handle Create(v8::Isolate* isolate, + AtomBrowserContext* browser_context); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); v8::Local StartLogging(base::FilePath log_path, - mate::Arguments* args); - v8::Local StopLogging(mate::Arguments* args); + gin_helper::Arguments* args); + v8::Local StopLogging(gin_helper::Arguments* args); bool IsCurrentlyLogging() const; protected: diff --git a/shell/browser/api/atom_api_notification.cc b/shell/browser/api/atom_api_notification.cc index 769f6f95cb..149674807d 100644 --- a/shell/browser/api/atom_api_notification.cc +++ b/shell/browser/api/atom_api_notification.cc @@ -6,7 +6,6 @@ #include "base/guid.h" #include "base/strings/utf_string_conversions.h" -#include "native_mate/constructor.h" #include "shell/browser/api/atom_api_menu.h" #include "shell/browser/atom_browser_client.h" #include "shell/browser/browser.h" diff --git a/shell/browser/api/atom_api_notification.h b/shell/browser/api/atom_api_notification.h index 23f5a7b458..8d06809356 100644 --- a/shell/browser/api/atom_api_notification.h +++ b/shell/browser/api/atom_api_notification.h @@ -10,11 +10,11 @@ #include #include "base/strings/utf_string_conversions.h" -#include "shell/browser/api/trackable_object.h" #include "shell/browser/notifications/notification.h" #include "shell/browser/notifications/notification_delegate.h" #include "shell/browser/notifications/notification_presenter.h" #include "shell/common/gin_helper/error_thrower.h" +#include "shell/common/gin_helper/trackable_object.h" #include "ui/gfx/image/image.h" namespace gin { @@ -25,7 +25,7 @@ namespace electron { namespace api { -class Notification : public mate::TrackableObject, +class Notification : public gin_helper::TrackableObject, public NotificationDelegate { public: static mate::WrappableBase* New(gin_helper::ErrorThrower thrower, diff --git a/shell/browser/api/atom_api_power_monitor.cc b/shell/browser/api/atom_api_power_monitor.cc index 4240795eef..642e879a95 100644 --- a/shell/browser/api/atom_api_power_monitor.cc +++ b/shell/browser/api/atom_api_power_monitor.cc @@ -7,29 +7,33 @@ #include "base/power_monitor/power_monitor.h" #include "base/power_monitor/power_monitor_device_source.h" #include "gin/dictionary.h" +#include "gin/handle.h" #include "shell/browser/browser.h" #include "shell/common/gin_converters/callback_converter.h" +#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" -namespace mate { +namespace gin { + template <> struct Converter { static v8::Local ToV8(v8::Isolate* isolate, const ui::IdleState& in) { switch (in) { case ui::IDLE_STATE_ACTIVE: - return mate::StringToV8(isolate, "active"); + return StringToV8(isolate, "active"); case ui::IDLE_STATE_IDLE: - return mate::StringToV8(isolate, "idle"); + return StringToV8(isolate, "idle"); case ui::IDLE_STATE_LOCKED: - return mate::StringToV8(isolate, "locked"); + return StringToV8(isolate, "locked"); case ui::IDLE_STATE_UNKNOWN: default: - return mate::StringToV8(isolate, "unknown"); + return StringToV8(isolate, "unknown"); } } }; -} // namespace mate + +} // namespace gin namespace electron { @@ -88,7 +92,7 @@ ui::IdleState PowerMonitor::GetSystemIdleState(v8::Isolate* isolate, if (idle_threshold > 0) { return ui::CalculateIdleState(idle_threshold); } else { - isolate->ThrowException(v8::Exception::TypeError(mate::StringToV8( + isolate->ThrowException(v8::Exception::TypeError(gin::StringToV8( isolate, "Invalid idle threshold, must be greater than 0"))); return ui::IDLE_STATE_UNKNOWN; } @@ -102,21 +106,21 @@ int PowerMonitor::GetSystemIdleTime() { v8::Local PowerMonitor::Create(v8::Isolate* isolate) { if (!Browser::Get()->is_ready()) { isolate->ThrowException(v8::Exception::Error( - mate::StringToV8(isolate, - "The 'powerMonitor' module can't be used before the " - "app 'ready' event"))); + gin::StringToV8(isolate, + "The 'powerMonitor' module can't be used before the " + "app 'ready' event"))); return v8::Null(isolate); } - return mate::CreateHandle(isolate, new PowerMonitor(isolate)).ToV8(); + return gin::CreateHandle(isolate, new PowerMonitor(isolate)).ToV8(); } // static void PowerMonitor::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "PowerMonitor")); + prototype->SetClassName(gin::StringToV8(isolate, "PowerMonitor")); gin_helper::Destroyable::MakeDestroyable(isolate, prototype); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) #if defined(OS_LINUX) .SetMethod("blockShutdown", &PowerMonitor::BlockShutdown) .SetMethod("unblockShutdown", &PowerMonitor::UnblockShutdown) diff --git a/shell/browser/api/atom_api_power_monitor.h b/shell/browser/api/atom_api_power_monitor.h index 075e7d6943..762fc153a0 100644 --- a/shell/browser/api/atom_api_power_monitor.h +++ b/shell/browser/api/atom_api_power_monitor.h @@ -6,16 +6,15 @@ #define SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_ #include "base/compiler_specific.h" -#include "native_mate/handle.h" -#include "shell/browser/api/trackable_object.h" #include "shell/browser/lib/power_observer.h" +#include "shell/common/gin_helper/trackable_object.h" #include "ui/base/idle/idle.h" namespace electron { namespace api { -class PowerMonitor : public mate::TrackableObject, +class PowerMonitor : public gin_helper::TrackableObject, public PowerObserver { public: static v8::Local Create(v8::Isolate* isolate); diff --git a/shell/browser/api/atom_api_protocol.h b/shell/browser/api/atom_api_protocol.h index 20d6c09b46..0fd7c5d0e5 100644 --- a/shell/browser/api/atom_api_protocol.h +++ b/shell/browser/api/atom_api_protocol.h @@ -10,9 +10,9 @@ #include "content/public/browser/content_browser_client.h" #include "gin/handle.h" -#include "shell/browser/api/trackable_object.h" #include "shell/browser/net/atom_url_loader_factory.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/trackable_object.h" namespace electron { @@ -35,7 +35,7 @@ enum class ProtocolError { }; // Protocol implementation based on network services. -class Protocol : public mate::TrackableObject { +class Protocol : public gin_helper::TrackableObject { public: static gin::Handle Create(v8::Isolate* isolate, AtomBrowserContext* browser_context); diff --git a/shell/browser/api/atom_api_screen.h b/shell/browser/api/atom_api_screen.h index 1326e798f2..fe6a7e540d 100644 --- a/shell/browser/api/atom_api_screen.h +++ b/shell/browser/api/atom_api_screen.h @@ -7,7 +7,6 @@ #include -#include "native_mate/wrappable.h" #include "shell/common/gin_helper/error_thrower.h" #include "shell/common/gin_helper/event_emitter.h" #include "ui/display/display_observer.h" @@ -23,7 +22,7 @@ namespace electron { namespace api { -class Screen : public gin_helper::EventEmitter>, +class Screen : public gin_helper::EventEmitter, public display::DisplayObserver { public: static v8::Local Create(gin_helper::ErrorThrower error_thrower); diff --git a/shell/browser/api/atom_api_session.cc b/shell/browser/api/atom_api_session.cc index d05239e2ca..027b967e13 100644 --- a/shell/browser/api/atom_api_session.cc +++ b/shell/browser/api/atom_api_session.cc @@ -32,8 +32,6 @@ #include "content/public/browser/storage_partition.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h" -#include "native_mate/dictionary.h" -#include "native_mate/object_template_builder_deprecated.h" #include "net/base/completion_repeating_callback.h" #include "net/base/load_flags.h" #include "net/http/http_auth_handler_factory.h" @@ -54,13 +52,14 @@ #include "shell/browser/media/media_device_id_salt.h" #include "shell/browser/net/cert_verifier_client.h" #include "shell/browser/session_preferences.h" -#include "shell/common/native_mate_converters/callback_converter_deprecated.h" -#include "shell/common/native_mate_converters/content_converter.h" -#include "shell/common/native_mate_converters/file_path_converter.h" -#include "shell/common/native_mate_converters/gurl_converter.h" -#include "shell/common/native_mate_converters/net_converter.h" -#include "shell/common/native_mate_converters/once_callback.h" -#include "shell/common/native_mate_converters/value_converter.h" +#include "shell/common/gin_converters/callback_converter.h" +#include "shell/common/gin_converters/content_converter.h" +#include "shell/common/gin_converters/file_path_converter.h" +#include "shell/common/gin_converters/gurl_converter.h" +#include "shell/common/gin_converters/net_converter.h" +#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" #include "shell/common/options_switches.h" #include "ui/base/l10n/l10n_util.h" @@ -122,14 +121,14 @@ uint32_t GetQuotaMask(const std::vector& quota_types) { } // namespace -namespace mate { +namespace gin { template <> struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Local val, ClearStorageDataOptions* out) { - mate::Dictionary options; + gin_helper::Dictionary options; if (!ConvertFromV8(isolate, val, &options)) return false; options.Get("origin", &out->origin); @@ -142,7 +141,7 @@ struct Converter { } }; -} // namespace mate +} // namespace gin namespace electron { @@ -153,7 +152,7 @@ namespace { const char kPersistPrefix[] = "persist:"; // Referenced session objects. -std::map> g_sessions; +std::map> g_sessions; void DownloadIdCallback(content::DownloadManager* download_manager, const base::FilePath& path, @@ -239,7 +238,7 @@ void Session::OnDownloadCreated(content::DownloadManager* manager, } } -v8::Local Session::ResolveProxy(mate::Arguments* args) { +v8::Local Session::ResolveProxy(gin_helper::Arguments* args) { v8::Isolate* isolate = args->isolate(); util::Promise promise(isolate); v8::Local handle = promise.GetHandle(); @@ -292,7 +291,7 @@ v8::Local Session::ClearCache() { return handle; } -v8::Local Session::ClearStorageData(mate::Arguments* args) { +v8::Local Session::ClearStorageData(gin_helper::Arguments* args) { v8::Isolate* isolate = args->isolate(); util::Promise promise(isolate); v8::Local handle = promise.GetHandle(); @@ -322,12 +321,12 @@ void Session::FlushStorageData() { storage_partition->Flush(); } -v8::Local Session::SetProxy(mate::Arguments* args) { +v8::Local Session::SetProxy(gin_helper::Arguments* args) { v8::Isolate* isolate = args->isolate(); util::Promise promise(isolate); v8::Local handle = promise.GetHandle(); - mate::Dictionary options; + gin_helper::Dictionary options; args->GetNext(&options); if (!browser_context_->in_memory_pref_store()) { @@ -368,7 +367,7 @@ void Session::SetDownloadPath(const base::FilePath& path) { path); } -void Session::EnableNetworkEmulation(const mate::Dictionary& options) { +void Session::EnableNetworkEmulation(const gin_helper::Dictionary& options) { auto conditions = network::mojom::NetworkConditions::New(); options.Get("offline", &conditions->offline); @@ -395,9 +394,9 @@ void Session::DisableNetworkEmulation() { } void Session::SetCertVerifyProc(v8::Local val, - mate::Arguments* args) { + gin_helper::Arguments* args) { CertVerifierClient::CertVerifyProc proc; - if (!(val->IsNull() || mate::ConvertFromV8(args->isolate(), val, &proc))) { + if (!(val->IsNull() || gin::ConvertFromV8(args->isolate(), val, &proc))) { args->ThrowError("Must pass null or function"); return; } @@ -418,7 +417,7 @@ void Session::SetCertVerifyProc(v8::Local val, } void Session::SetPermissionRequestHandler(v8::Local val, - mate::Arguments* args) { + gin_helper::Arguments* args) { auto* permission_manager = static_cast( browser_context()->GetPermissionControllerDelegate()); if (val->IsNull()) { @@ -427,7 +426,7 @@ void Session::SetPermissionRequestHandler(v8::Local val, return; } auto handler = std::make_unique(); - if (!mate::ConvertFromV8(args->isolate(), val, handler.get())) { + if (!gin::ConvertFromV8(args->isolate(), val, handler.get())) { args->ThrowError("Must pass null or function"); return; } @@ -445,9 +444,9 @@ void Session::SetPermissionRequestHandler(v8::Local val, } void Session::SetPermissionCheckHandler(v8::Local val, - mate::Arguments* args) { + gin_helper::Arguments* args) { AtomPermissionManager::CheckHandler handler; - if (!(val->IsNull() || mate::ConvertFromV8(args->isolate(), val, &handler))) { + if (!(val->IsNull() || gin::ConvertFromV8(args->isolate(), val, &handler))) { args->ThrowError("Must pass null or function"); return; } @@ -456,7 +455,8 @@ void Session::SetPermissionCheckHandler(v8::Local val, permission_manager->SetPermissionCheckHandler(handler); } -v8::Local Session::ClearHostResolverCache(mate::Arguments* args) { +v8::Local Session::ClearHostResolverCache( + gin_helper::Arguments* args) { v8::Isolate* isolate = args->isolate(); util::Promise promise(isolate); v8::Local handle = promise.GetHandle(); @@ -494,7 +494,7 @@ void Session::AllowNTLMCredentialsForDomains(const std::string& domains) { } void Session::SetUserAgent(const std::string& user_agent, - mate::Arguments* args) { + gin_helper::Arguments* args) { browser_context_->SetUserAgent(user_agent); content::BrowserContext::GetDefaultStoragePartition(browser_context_.get()) ->GetNetworkContext() @@ -525,7 +525,7 @@ void Session::DownloadURL(const GURL& url) { download_manager->DownloadUrl(std::move(download_params)); } -void Session::CreateInterruptedDownload(const mate::Dictionary& options) { +void Session::CreateInterruptedDownload(const gin_helper::Dictionary& options) { int64_t offset = 0, length = 0; double start_time = base::Time::Now().ToDoubleT(); std::string mime_type, last_modified, etag; @@ -540,12 +540,12 @@ void Session::CreateInterruptedDownload(const mate::Dictionary& options) { options.Get("eTag", &etag); options.Get("startTime", &start_time); if (path.empty() || url_chain.empty() || length == 0) { - isolate()->ThrowException(v8::Exception::Error(mate::StringToV8( + isolate()->ThrowException(v8::Exception::Error(gin::StringToV8( isolate(), "Must pass non-empty path, urlChain and length."))); return; } if (offset >= length) { - isolate()->ThrowException(v8::Exception::Error(mate::StringToV8( + isolate()->ThrowException(v8::Exception::Error(gin::StringToV8( isolate(), "Must pass an offset value less than length."))); return; } @@ -619,8 +619,8 @@ static void StartPreconnectOnUI( browser_context->GetPreconnectManager()->Start(url, requests); } -void Session::Preconnect(const mate::Dictionary& options, - mate::Arguments* args) { +void Session::Preconnect(const gin_helper::Dictionary& options, + gin_helper::Arguments* args) { GURL url; if (!options.Get("url", &url) || !url.is_valid()) { args->ThrowError("Must pass non-empty valid url to session.preconnect."); @@ -647,25 +647,25 @@ void Session::Preconnect(const mate::Dictionary& options, } // static -mate::Handle Session::CreateFrom(v8::Isolate* isolate, - AtomBrowserContext* browser_context) { +gin::Handle Session::CreateFrom(v8::Isolate* isolate, + AtomBrowserContext* browser_context) { auto* existing = TrackableObject::FromWrappedClass(isolate, browser_context); if (existing) - return mate::CreateHandle(isolate, static_cast(existing)); + return gin::CreateHandle(isolate, static_cast(existing)); auto handle = - mate::CreateHandle(isolate, new Session(isolate, browser_context)); + gin::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. g_sessions[handle->weak_map_id()] = - v8::Global(isolate, handle.ToV8()); + v8::Global(isolate, handle.ToV8()); return handle; } // static -mate::Handle Session::FromPartition( +gin::Handle Session::FromPartition( v8::Isolate* isolate, const std::string& partition, const base::DictionaryValue& options) { @@ -685,9 +685,9 @@ mate::Handle Session::FromPartition( // static void Session::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "Session")); + prototype->SetClassName(gin::StringToV8(isolate, "Session")); gin_helper::Destroyable::MakeDestroyable(isolate, prototype); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("resolveProxy", &Session::ResolveProxy) .SetMethod("getCacheSize", &Session::GetCacheSize) .SetMethod("clearCache", &Session::ClearCache) @@ -736,7 +736,7 @@ using electron::api::Protocol; using electron::api::Session; v8::Local FromPartition(const std::string& partition, - mate::Arguments* args) { + gin_helper::Arguments* args) { if (!electron::Browser::Get()->is_ready()) { args->ThrowError("Session can only be received when app is ready"); return v8::Null(args->isolate()); @@ -751,7 +751,7 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); + gin_helper::Dictionary dict(isolate, exports); dict.Set( "Session", Session::GetConstructor(isolate)->GetFunction(context).ToLocalChecked()); diff --git a/shell/browser/api/atom_api_session.h b/shell/browser/api/atom_api_session.h index 1e18ba2733..2bfadd200d 100644 --- a/shell/browser/api/atom_api_session.h +++ b/shell/browser/api/atom_api_session.h @@ -11,9 +11,9 @@ #include "base/values.h" #include "content/public/browser/download_manager.h" #include "electron/buildflags/buildflags.h" -#include "native_mate/handle.h" -#include "shell/browser/api/trackable_object.h" +#include "gin/handle.h" #include "shell/browser/net/resolve_proxy_helper.h" +#include "shell/common/gin_helper/trackable_object.h" #include "shell/common/promise_util.h" class GURL; @@ -22,10 +22,9 @@ namespace base { class FilePath; } -namespace mate { -class Arguments; +namespace gin_helper { class Dictionary; -} // namespace mate +} namespace net { class ProxyConfig; @@ -37,56 +36,58 @@ class AtomBrowserContext; namespace api { -class Session : public mate::TrackableObject, +class Session : public gin_helper::TrackableObject, public content::DownloadManager::Observer { public: // Gets or creates Session from the |browser_context|. - static mate::Handle CreateFrom(v8::Isolate* isolate, - AtomBrowserContext* browser_context); + static gin::Handle CreateFrom(v8::Isolate* isolate, + AtomBrowserContext* browser_context); // Gets the Session of |partition|. - static mate::Handle FromPartition( + static gin::Handle FromPartition( v8::Isolate* isolate, const std::string& partition, const base::DictionaryValue& options = base::DictionaryValue()); AtomBrowserContext* browser_context() const { return browser_context_.get(); } - // mate::TrackableObject: + // gin_helper::TrackableObject: static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); // Methods. - v8::Local ResolveProxy(mate::Arguments* args); + v8::Local ResolveProxy(gin_helper::Arguments* args); v8::Local GetCacheSize(); v8::Local ClearCache(); - v8::Local ClearStorageData(mate::Arguments* args); + v8::Local ClearStorageData(gin_helper::Arguments* args); void FlushStorageData(); - v8::Local SetProxy(mate::Arguments* args); + v8::Local SetProxy(gin_helper::Arguments* args); void SetDownloadPath(const base::FilePath& path); - void EnableNetworkEmulation(const mate::Dictionary& options); + void EnableNetworkEmulation(const gin_helper::Dictionary& options); void DisableNetworkEmulation(); - void SetCertVerifyProc(v8::Local proc, mate::Arguments* args); + void SetCertVerifyProc(v8::Local proc, + gin_helper::Arguments* args); void SetPermissionRequestHandler(v8::Local val, - mate::Arguments* args); + gin_helper::Arguments* args); void SetPermissionCheckHandler(v8::Local val, - mate::Arguments* args); - v8::Local ClearHostResolverCache(mate::Arguments* args); + gin_helper::Arguments* args); + v8::Local ClearHostResolverCache(gin_helper::Arguments* args); v8::Local ClearAuthCache(); void AllowNTLMCredentialsForDomains(const std::string& domains); - void SetUserAgent(const std::string& user_agent, mate::Arguments* args); + void SetUserAgent(const std::string& user_agent, gin_helper::Arguments* args); std::string GetUserAgent(); v8::Local GetBlobData(v8::Isolate* isolate, const std::string& uuid); void DownloadURL(const GURL& url); - void CreateInterruptedDownload(const mate::Dictionary& options); + void CreateInterruptedDownload(const gin_helper::Dictionary& options); void SetPreloads(const std::vector& preloads); std::vector GetPreloads() const; v8::Local Cookies(v8::Isolate* isolate); v8::Local Protocol(v8::Isolate* isolate); v8::Local WebRequest(v8::Isolate* isolate); v8::Local NetLog(v8::Isolate* isolate); - void Preconnect(const mate::Dictionary& options, mate::Arguments* args); + void Preconnect(const gin_helper::Dictionary& options, + gin_helper::Arguments* args); #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) void LoadChromeExtension(const base::FilePath extension_path); diff --git a/shell/browser/api/atom_api_system_preferences.h b/shell/browser/api/atom_api_system_preferences.h index b18cfafe0c..0ba11d4115 100644 --- a/shell/browser/api/atom_api_system_preferences.h +++ b/shell/browser/api/atom_api_system_preferences.h @@ -9,7 +9,6 @@ #include #include "gin/handle.h" -#include "native_mate/wrappable.h" #include "shell/common/gin_helper/error_thrower.h" #include "shell/common/gin_helper/event_emitter.h" #include "shell/common/promise_util.h" @@ -36,12 +35,11 @@ enum NotificationCenterKind { }; #endif -class SystemPreferences - : public gin_helper::EventEmitter> +class SystemPreferences : public gin_helper::EventEmitter #if defined(OS_WIN) , - public BrowserObserver, - public gfx::SysColorChangeListener + public BrowserObserver, + public gfx::SysColorChangeListener #endif { public: diff --git a/shell/browser/api/atom_api_top_level_window.cc b/shell/browser/api/atom_api_top_level_window.cc index 62d4886074..58b314b392 100644 --- a/shell/browser/api/atom_api_top_level_window.cc +++ b/shell/browser/api/atom_api_top_level_window.cc @@ -74,10 +74,10 @@ v8::Local ToBuffer(v8::Isolate* isolate, void* val, int size) { } // namespace TopLevelWindow::TopLevelWindow(v8::Isolate* isolate, - const mate::Dictionary& options) + const gin_helper::Dictionary& options) : weak_factory_(this) { // The parent window. - mate::Handle parent; + gin::Handle parent; if (options.Get("parent", &parent) && !parent.IsEmpty()) parent_window_.Reset(isolate, parent.ToV8()); @@ -98,14 +98,14 @@ TopLevelWindow::TopLevelWindow(v8::Isolate* isolate, #if defined(TOOLKIT_VIEWS) // Sets the window icon. - mate::Handle icon; + gin::Handle icon; if (options.Get(options::kIcon, &icon) && !icon.IsEmpty()) SetIcon(icon); #endif } TopLevelWindow::TopLevelWindow(gin_helper::Arguments* args, - const mate::Dictionary& options) + const gin_helper::Dictionary& options) : TopLevelWindow(args->isolate(), options) { InitWithArgs(args); // Init window after everything has been setup. @@ -124,15 +124,12 @@ TopLevelWindow::~TopLevelWindow() { void TopLevelWindow::InitWith(v8::Isolate* isolate, v8::Local wrapper) { AttachAsUserData(window_.get()); - mate::TrackableObject< - TopLevelWindow, gin_helper::EventEmitter< - mate::Wrappable>>::InitWith(isolate, - wrapper); + gin_helper::TrackableObject::InitWith(isolate, 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()) { - mate::Handle parent; + gin::Handle parent; gin::ConvertFromV8(isolate, GetParentWindow(), &parent); DCHECK(!parent.IsEmpty()); parent->child_windows_.Set(isolate, weak_map_id(), wrapper); @@ -299,7 +296,7 @@ void TopLevelWindow::OnWindowMessage(UINT message, } #endif -void TopLevelWindow::SetContentView(mate::Handle view) { +void TopLevelWindow::SetContentView(gin::Handle view) { ResetBrowserViews(); content_view_.Reset(isolate(), view.ToV8()); window_->SetContentView(view->view()); @@ -676,7 +673,7 @@ void TopLevelWindow::SetFocusable(bool focusable) { void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local value) { auto context = isolate->GetCurrentContext(); - mate::Handle menu; + gin::Handle menu; v8::Local object; if (value->IsObject() && value->ToObject(context).ToLocal(&object) && gin::V8ToString(isolate, object->GetConstructorName()) == "Menu" && @@ -704,12 +701,12 @@ void TopLevelWindow::SetParentWindow(v8::Local value, return; } - mate::Handle parent; + gin::Handle parent; if (value->IsNull() || value->IsUndefined()) { RemoveFromParentChildWindows(); parent_window_.Reset(); window_->SetParentWindow(nullptr); - } else if (mate::ConvertFromV8(isolate(), value, &parent)) { + } else if (gin::ConvertFromV8(isolate(), value, &parent)) { RemoveFromParentChildWindows(); parent_window_.Reset(isolate(), value); window_->SetParentWindow(parent->window_.get()); @@ -725,7 +722,7 @@ void TopLevelWindow::SetBrowserView(v8::Local value) { } void TopLevelWindow::AddBrowserView(v8::Local value) { - mate::Handle browser_view; + gin::Handle browser_view; if (value->IsObject() && gin::ConvertFromV8(isolate(), value, &browser_view)) { auto get_that_view = browser_views_.find(browser_view->weak_map_id()); @@ -738,7 +735,7 @@ void TopLevelWindow::AddBrowserView(v8::Local value) { } void TopLevelWindow::RemoveBrowserView(v8::Local value) { - mate::Handle browser_view; + gin::Handle browser_view; if (value->IsObject() && gin::ConvertFromV8(isolate(), value, &browser_view)) { auto get_that_view = browser_views_.find(browser_view->weak_map_id()); @@ -960,7 +957,7 @@ bool TopLevelWindow::SetThumbarButtons(gin_helper::Arguments* args) { } #if defined(TOOLKIT_VIEWS) -void TopLevelWindow::SetIcon(mate::Handle icon) { +void TopLevelWindow::SetIcon(gin::Handle icon) { #if defined(OS_WIN) static_cast(window_.get()) ->SetIcon(icon->GetHICON(GetSystemMetrics(SM_CXSMICON)), @@ -1028,7 +1025,7 @@ int32_t TopLevelWindow::GetID() const { void TopLevelWindow::ResetBrowserViews() { for (auto& item : browser_views_) { - mate::Handle browser_view; + gin::Handle browser_view; if (gin::ConvertFromV8(isolate(), v8::Local::New(isolate(), item.second), &browser_view) && @@ -1047,7 +1044,7 @@ void TopLevelWindow::RemoveFromParentChildWindows() { if (parent_window_.IsEmpty()) return; - mate::Handle parent; + gin::Handle parent; if (!gin::ConvertFromV8(isolate(), GetParentWindow(), &parent) || parent.IsEmpty()) { return; @@ -1058,7 +1055,8 @@ void TopLevelWindow::RemoveFromParentChildWindows() { // static mate::WrappableBase* TopLevelWindow::New(gin_helper::Arguments* args) { - mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate()); + gin_helper::Dictionary options = + gin::Dictionary::CreateEmpty(args->isolate()); args->GetNext(&options); return new TopLevelWindow(args, options); diff --git a/shell/browser/api/atom_api_top_level_window.h b/shell/browser/api/atom_api_top_level_window.h index e60d25eb2e..c3e28cba20 100644 --- a/shell/browser/api/atom_api_top_level_window.h +++ b/shell/browser/api/atom_api_top_level_window.h @@ -13,11 +13,11 @@ #include "base/task/post_task.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" -#include "shell/browser/api/trackable_object.h" +#include "gin/handle.h" #include "shell/browser/native_window.h" #include "shell/browser/native_window_observer.h" #include "shell/common/api/atom_api_native_image.h" -#include "shell/common/gin_helper/event_emitter.h" +#include "shell/common/gin_helper/trackable_object.h" namespace electron { @@ -25,11 +25,8 @@ namespace api { class View; -class TopLevelWindow - : public mate::TrackableObject< - TopLevelWindow, - gin_helper::EventEmitter>>, - public NativeWindowObserver { +class TopLevelWindow : public gin_helper::TrackableObject, + public NativeWindowObserver { public: static mate::WrappableBase* New(gin_helper::Arguments* args); @@ -44,9 +41,10 @@ class TopLevelWindow protected: // Common constructor. - TopLevelWindow(v8::Isolate* isolate, const mate::Dictionary& options); + TopLevelWindow(v8::Isolate* isolate, const gin_helper::Dictionary& options); // Creating independent TopLevelWindow instance. - TopLevelWindow(gin_helper::Arguments* args, const mate::Dictionary& options); + TopLevelWindow(gin_helper::Arguments* args, + const gin_helper::Dictionary& options); ~TopLevelWindow() override; // TrackableObject: @@ -91,7 +89,7 @@ class TopLevelWindow #endif // Public APIs of NativeWindow. - void SetContentView(mate::Handle view); + void SetContentView(gin::Handle view); void Close(); virtual void Focus(); virtual void Blur(); @@ -215,7 +213,7 @@ class TopLevelWindow // Extra APIs added in JS. bool SetThumbarButtons(gin_helper::Arguments* args); #if defined(TOOLKIT_VIEWS) - void SetIcon(mate::Handle icon); + void SetIcon(gin::Handle icon); #endif #if defined(OS_WIN) typedef base::RepeatingCallback, diff --git a/shell/browser/api/atom_api_tray.h b/shell/browser/api/atom_api_tray.h index 748d1916a5..b6c888e232 100644 --- a/shell/browser/api/atom_api_tray.h +++ b/shell/browser/api/atom_api_tray.h @@ -10,11 +10,10 @@ #include #include "gin/handle.h" -#include "shell/browser/api/trackable_object.h" #include "shell/browser/ui/tray_icon.h" #include "shell/browser/ui/tray_icon_observer.h" #include "shell/common/gin_helper/error_thrower.h" -#include "shell/common/gin_helper/event_emitter.h" +#include "shell/common/gin_helper/trackable_object.h" namespace gfx { class Image; @@ -33,10 +32,7 @@ namespace api { class Menu; class NativeImage; -class Tray : public mate::TrackableObject< - Tray, - gin_helper::EventEmitter>>, - public TrayIconObserver { +class Tray : public gin_helper::TrackableObject, public TrayIconObserver { public: static mate::WrappableBase* New(gin_helper::ErrorThrower thrower, gin::Handle image, diff --git a/shell/browser/api/atom_api_url_request.cc b/shell/browser/api/atom_api_url_request.cc index 45289eb9e5..4fb2d91bfc 100644 --- a/shell/browser/api/atom_api_url_request.cc +++ b/shell/browser/api/atom_api_url_request.cc @@ -177,7 +177,7 @@ URLRequest::URLRequest(gin::Arguments* args) : weak_factory_(this) { } std::string partition; - mate::Handle session; + gin::Handle session; if (!dict.Get("session", &session)) { if (dict.Get("partition", &partition)) session = Session::FromPartition(args->isolate(), partition); diff --git a/shell/browser/api/atom_api_url_request.h b/shell/browser/api/atom_api_url_request.h index dca9762466..f8a276ea7d 100644 --- a/shell/browser/api/atom_api_url_request.h +++ b/shell/browser/api/atom_api_url_request.h @@ -13,7 +13,6 @@ #include "gin/arguments.h" #include "gin/dictionary.h" #include "mojo/public/cpp/system/data_pipe_producer.h" -#include "native_mate/wrappable.h" #include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/simple_url_loader.h" #include "services/network/public/cpp/simple_url_loader_stream_consumer.h" @@ -26,7 +25,7 @@ namespace api { class UploadDataPipeGetter; -class URLRequest : public gin_helper::EventEmitter>, +class URLRequest : public gin_helper::EventEmitter, public network::SimpleURLLoaderStreamConsumer { public: static mate::WrappableBase* New(gin::Arguments* args); diff --git a/shell/browser/api/atom_api_view.cc b/shell/browser/api/atom_api_view.cc index 78d5938f6f..3f6a2ffe65 100644 --- a/shell/browser/api/atom_api_view.cc +++ b/shell/browser/api/atom_api_view.cc @@ -4,7 +4,8 @@ #include "shell/browser/api/atom_api_view.h" -#include "native_mate/dictionary.h" +#include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" namespace electron { @@ -23,16 +24,16 @@ View::~View() { } #if BUILDFLAG(ENABLE_VIEW_API) -void View::SetLayoutManager(mate::Handle layout_manager) { +void View::SetLayoutManager(gin::Handle layout_manager) { layout_manager_.Reset(isolate(), layout_manager->GetWrapper()); view()->SetLayoutManager(layout_manager->TakeOver()); } -void View::AddChildView(mate::Handle child) { +void View::AddChildView(gin::Handle child) { AddChildViewAt(child, child_views_.size()); } -void View::AddChildViewAt(mate::Handle child, size_t index) { +void View::AddChildViewAt(gin::Handle child, size_t index) { if (index > child_views_.size()) return; child_views_.emplace(child_views_.begin() + index, // index @@ -51,9 +52,9 @@ mate::WrappableBase* View::New(gin::Arguments* args) { // static void View::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "View")); + prototype->SetClassName(gin::StringToV8(isolate, "View")); #if BUILDFLAG(ENABLE_VIEW_API) - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("setLayoutManager", &View::SetLayoutManager) .SetMethod("addChildView", &View::AddChildView) .SetMethod("addChildViewAt", &View::AddChildViewAt); @@ -75,11 +76,11 @@ void Initialize(v8::Local exports, v8::Isolate* isolate = context->GetIsolate(); View::SetConstructor(isolate, base::BindRepeating(&View::New)); - mate::Dictionary constructor( + gin_helper::Dictionary constructor( isolate, View::GetConstructor(isolate)->GetFunction(context).ToLocalChecked()); - mate::Dictionary dict(isolate, exports); + gin_helper::Dictionary dict(isolate, exports); dict.Set("View", constructor); } diff --git a/shell/browser/api/atom_api_view.h b/shell/browser/api/atom_api_view.h index b0f4cd4f77..ff7ed2f572 100644 --- a/shell/browser/api/atom_api_view.h +++ b/shell/browser/api/atom_api_view.h @@ -9,7 +9,7 @@ #include #include "electron/buildflags/buildflags.h" -#include "native_mate/handle.h" +#include "gin/handle.h" #include "shell/browser/api/views/atom_api_layout_manager.h" #include "ui/views/view.h" @@ -17,7 +17,7 @@ namespace electron { namespace api { -class View : public mate::TrackableObject { +class View : public gin_helper::TrackableObject { public: static mate::WrappableBase* New(gin::Arguments* args); @@ -25,9 +25,9 @@ class View : public mate::TrackableObject { v8::Local prototype); #if BUILDFLAG(ENABLE_VIEW_API) - void SetLayoutManager(mate::Handle layout_manager); - void AddChildView(mate::Handle view); - void AddChildViewAt(mate::Handle view, size_t index); + void SetLayoutManager(gin::Handle layout_manager); + void AddChildView(gin::Handle view); + void AddChildViewAt(gin::Handle view, size_t index); #endif views::View* view() const { return view_; } @@ -54,7 +54,7 @@ class View : public mate::TrackableObject { } // namespace electron -namespace mate { +namespace gin { template <> struct Converter { @@ -69,6 +69,6 @@ struct Converter { } }; -} // namespace mate +} // namespace gin #endif // SHELL_BROWSER_API_ATOM_API_VIEW_H_ diff --git a/shell/browser/api/atom_api_web_contents.cc b/shell/browser/api/atom_api_web_contents.cc index f7e16ffafb..42b0aae7a7 100644 --- a/shell/browser/api/atom_api_web_contents.cc +++ b/shell/browser/api/atom_api_web_contents.cc @@ -45,9 +45,6 @@ #include "electron/buildflags/buildflags.h" #include "electron/shell/common/api/api.mojom.h" #include "mojo/public/cpp/system/platform_handle.h" -#include "native_mate/converter.h" -#include "native_mate/dictionary.h" -#include "native_mate/object_template_builder_deprecated.h" #include "ppapi/buildflags/buildflags.h" #include "shell/browser/api/atom_api_browser_window.h" #include "shell/browser/api/atom_api_debugger.h" @@ -72,20 +69,18 @@ #include "shell/browser/web_view_guest_delegate.h" #include "shell/common/api/atom_api_native_image.h" #include "shell/common/color_util.h" +#include "shell/common/gin_converters/blink_converter_gin_adapter.h" #include "shell/common/gin_converters/callback_converter.h" +#include "shell/common/gin_converters/content_converter.h" +#include "shell/common/gin_converters/file_path_converter.h" #include "shell/common/gin_converters/gfx_converter.h" +#include "shell/common/gin_converters/gurl_converter.h" +#include "shell/common/gin_converters/image_converter.h" +#include "shell/common/gin_converters/net_converter.h" +#include "shell/common/gin_converters/value_converter_gin_adapter.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/mouse_util.h" -#include "shell/common/native_mate_converters/blink_converter.h" -#include "shell/common/native_mate_converters/content_converter.h" -#include "shell/common/native_mate_converters/file_path_converter.h" -#include "shell/common/native_mate_converters/gurl_converter.h" -#include "shell/common/native_mate_converters/image_converter.h" -#include "shell/common/native_mate_converters/net_converter.h" -#include "shell/common/native_mate_converters/network_converter.h" -#include "shell/common/native_mate_converters/once_callback.h" -#include "shell/common/native_mate_converters/string16_converter.h" -#include "shell/common/native_mate_converters/value_converter.h" #include "shell/common/node_includes.h" #include "shell/common/options_switches.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" @@ -125,7 +120,7 @@ #include "shell/browser/extensions/atom_extension_web_contents_observer.h" #endif -namespace mate { +namespace gin { #if BUILDFLAG(ENABLE_PRINTING) template <> @@ -221,7 +216,7 @@ struct Converter { default: break; } - return mate::ConvertToV8(isolate, disposition); + return gin::ConvertToV8(isolate, disposition); } }; @@ -275,7 +270,7 @@ struct Converter { default: break; } - return mate::ConvertToV8(isolate, type); + return gin::ConvertToV8(isolate, type); } static bool FromV8(v8::Isolate* isolate, @@ -307,14 +302,14 @@ struct Converter> { static v8::Local ToV8( v8::Isolate* isolate, const scoped_refptr& val) { - mate::Dictionary dict(isolate, v8::Object::New(isolate)); + gin_helper::Dictionary dict(isolate, v8::Object::New(isolate)); dict.Set("id", val->GetId()); dict.Set("url", val->GetURL().spec()); return dict.GetHandle(); } }; -} // namespace mate +} // namespace gin namespace electron { @@ -326,7 +321,7 @@ namespace { void OnCapturePageDone(util::Promise promise, const SkBitmap& bitmap) { // Hack to enable transparency in captured image - promise.Resolve(gfx::Image::CreateFrom1xBitmap(bitmap)); + promise.ResolveWithGin(gfx::Image::CreateFrom1xBitmap(bitmap)); } base::Optional GetCursorBlinkInterval() { @@ -359,7 +354,7 @@ WebContents::WebContents(v8::Isolate* isolate, false); Init(isolate); AttachAsUserData(web_contents); - InitZoomController(web_contents, mate::Dictionary::CreateEmpty(isolate)); + InitZoomController(web_contents, gin::Dictionary::CreateEmpty(isolate)); registry_.AddInterface(base::BindRepeating(&WebContents::BindElectronBrowser, base::Unretained(this))); bindings_.set_connection_error_handler(base::BindRepeating( @@ -377,10 +372,11 @@ WebContents::WebContents(v8::Isolate* isolate, auto session = Session::CreateFrom(isolate, GetBrowserContext()); session_.Reset(isolate, session.ToV8()); InitWithSessionAndOptions(isolate, std::move(web_contents), session, - mate::Dictionary::CreateEmpty(isolate)); + gin::Dictionary::CreateEmpty(isolate)); } -WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) +WebContents::WebContents(v8::Isolate* isolate, + const gin_helper::Dictionary& options) : weak_factory_(this) { // Read options. options.Get("backgroundThrottling", &background_throttling_); @@ -405,7 +401,7 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) // Obtain the session. std::string partition; - mate::Handle session; + gin::Handle session; if (options.Get("session", &session) && !session.IsEmpty()) { } else if (options.Get("partition", &partition)) { session = Session::FromPartition(isolate, partition); @@ -465,7 +461,7 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) } void WebContents::InitZoomController(content::WebContents* web_contents, - const mate::Dictionary& options) { + const gin_helper::Dictionary& options) { WebContentsZoomController::CreateForWebContents(web_contents); zoom_controller_ = WebContentsZoomController::FromWebContents(web_contents); double zoom_factor; @@ -476,8 +472,8 @@ void WebContents::InitZoomController(content::WebContents* web_contents, void WebContents::InitWithSessionAndOptions( v8::Isolate* isolate, std::unique_ptr owned_web_contents, - mate::Handle session, - const mate::Dictionary& options) { + gin::Handle session, + const gin_helper::Dictionary& options) { Observe(owned_web_contents.get()); // TODO(zcbenz): Make InitWithWebContents take unique_ptr. // At the time of writing we are going through a refactoring and I don't want @@ -672,8 +668,7 @@ void WebContents::BeforeUnloadFired(content::WebContents* tab, void WebContents::SetContentsBounds(content::WebContents* source, const gfx::Rect& pos) { - // TODO(zcbenz): Use implicit convertion after removing mate::EventEmitter. - Emit("move", gin::ConvertToV8(isolate(), pos)); + Emit("move", pos); } void WebContents::CloseContents(content::WebContents* source) { @@ -1054,7 +1049,7 @@ void WebContents::MessageTo(bool internal, int32_t web_contents_id, const std::string& channel, blink::CloneableMessage arguments) { - auto* web_contents = mate::TrackableObject::FromWeakMapID( + auto* web_contents = gin_helper::TrackableObject::FromWeakMapID( isolate(), web_contents_id); if (web_contents) { @@ -1346,7 +1341,8 @@ bool WebContents::Equal(const WebContents* web_contents) const { return ID() == web_contents->ID(); } -void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { +void WebContents::LoadURL(const GURL& url, + const gin_helper::Dictionary& options) { if (!url.is_valid() || url.spec().size() > url::kMaxURLChars) { Emit("did-fail-load", static_cast(net::ERR_INVALID_URL), net::ErrorToShortString(net::ERR_INVALID_URL), @@ -1487,7 +1483,7 @@ bool WebContents::IsCrashed() const { } void WebContents::SetUserAgent(const std::string& user_agent, - mate::Arguments* args) { + gin_helper::Arguments* args) { web_contents()->SetUserAgentOverride(user_agent, false); } @@ -1507,7 +1503,7 @@ v8::Local WebContents::SavePage( return handle; } -void WebContents::OpenDevTools(mate::Arguments* args) { +void WebContents::OpenDevTools(gin_helper::Arguments* args) { if (type_ == Type::REMOTE) return; @@ -1520,7 +1516,7 @@ void WebContents::OpenDevTools(mate::Arguments* args) { } bool activate = true; if (args && args->Length() == 1) { - mate::Dictionary options; + gin_helper::Dictionary options; if (args->GetNext(&options)) { options.Get("mode", &state); options.Get("activate", &activate); @@ -1693,8 +1689,9 @@ bool WebContents::IsCurrentlyAudible() { } #if BUILDFLAG(ENABLE_PRINTING) -void WebContents::Print(mate::Arguments* args) { - mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate()); +void WebContents::Print(gin_helper::Arguments* args) { + gin_helper::Dictionary options = + gin::Dictionary::CreateEmpty(args->isolate()); base::DictionaryValue settings; if (args->Length() >= 1 && !args->GetNext(&options)) { @@ -1719,7 +1716,8 @@ void WebContents::Print(mate::Arguments* args) { print_background); // Set custom margin settings - mate::Dictionary margins = mate::Dictionary::CreateEmpty(args->isolate()); + gin_helper::Dictionary margins = + gin::Dictionary::CreateEmpty(args->isolate()); if (options.Get("margins", &margins)) { printing::MarginType margin_type = printing::DEFAULT_MARGINS; margins.Get("marginType", &margin_type); @@ -1805,7 +1803,7 @@ void WebContents::Print(mate::Arguments* args) { settings.SetBoolean(printing::kSettingRasterizePdf, false); // Set custom page ranges to print - std::vector page_ranges; + std::vector page_ranges; if (options.Get("pageRanges", &page_ranges)) { std::unique_ptr page_range_list(new base::ListValue()); for (auto& range : page_ranges) { @@ -1830,7 +1828,7 @@ void WebContents::Print(mate::Arguments* args) { settings.SetInteger(printing::kSettingDuplexMode, duplex_mode); // Set custom dots per inch (dpi) - mate::Dictionary dpi_settings; + gin_helper::Dictionary dpi_settings; int dpi = 72; if (options.Get("dpi", &dpi_settings)) { int horizontal = 72; @@ -1878,7 +1876,7 @@ v8::Local WebContents::PrintToPDF( } #endif -void WebContents::AddWorkSpace(mate::Arguments* args, +void WebContents::AddWorkSpace(gin_helper::Arguments* args, const base::FilePath& path) { if (path.empty()) { args->ThrowError("path cannot be empty"); @@ -1887,7 +1885,7 @@ void WebContents::AddWorkSpace(mate::Arguments* args, DevToolsAddFileSystem(std::string(), path); } -void WebContents::RemoveWorkSpace(mate::Arguments* args, +void WebContents::RemoveWorkSpace(gin_helper::Arguments* args, const base::FilePath& path) { if (path.empty()) { args->ThrowError("path cannot be empty"); @@ -1940,7 +1938,7 @@ void WebContents::ReplaceMisspelling(const base::string16& word) { web_contents()->ReplaceMisspelling(word); } -uint32_t WebContents::FindInPage(mate::Arguments* args) { +uint32_t WebContents::FindInPage(gin_helper::Arguments* args) { base::string16 search_text; if (!args->GetNext(&search_text) || search_text.empty()) { args->ThrowError("Must provide a non-empty search content"); @@ -1948,7 +1946,7 @@ uint32_t WebContents::FindInPage(mate::Arguments* args) { } uint32_t request_id = GetNextRequestId(); - mate::Dictionary dict; + gin_helper::Dictionary dict; auto options = blink::mojom::FindOptions::New(); if (args->GetNext(&dict)) { dict.Get("forward", &options->forward); @@ -2007,9 +2005,9 @@ bool WebContents::SendIPCMessage(bool internal, const std::string& channel, v8::Local args) { blink::CloneableMessage message; - if (!mate::ConvertFromV8(isolate(), args, &message)) { + if (!gin::ConvertFromV8(isolate(), args, &message)) { isolate()->ThrowException(v8::Exception::Error( - mate::StringToV8(isolate(), "Failed to serialize arguments"))); + gin::StringToV8(isolate(), "Failed to serialize arguments"))); return false; } return SendIPCMessageWithSender(internal, send_to_all, channel, @@ -2046,9 +2044,9 @@ bool WebContents::SendIPCMessageToFrame(bool internal, const std::string& channel, v8::Local args) { blink::CloneableMessage message; - if (!mate::ConvertFromV8(isolate(), args, &message)) { + if (!gin::ConvertFromV8(isolate(), args, &message)) { isolate()->ThrowException(v8::Exception::Error( - mate::StringToV8(isolate(), "Failed to serialize arguments"))); + gin::StringToV8(isolate(), "Failed to serialize arguments"))); return false; } auto frames = web_contents()->GetAllFrames(); @@ -2094,7 +2092,7 @@ void WebContents::SendInputEvent(v8::Isolate* isolate, content::NativeWebKeyboardEvent keyboard_event( blink::WebKeyboardEvent::kRawKeyDown, blink::WebInputEvent::kNoModifiers, ui::EventTimeForNow()); - if (mate::ConvertFromV8(isolate, input_event, &keyboard_event)) { + if (gin::ConvertFromV8(isolate, input_event, &keyboard_event)) { rwh->ForwardKeyboardEvent(keyboard_event); return; } @@ -2127,14 +2125,10 @@ void WebContents::SendInputEvent(v8::Isolate* isolate, } isolate->ThrowException( - v8::Exception::Error(mate::StringToV8(isolate, "Invalid event object"))); + v8::Exception::Error(gin::StringToV8(isolate, "Invalid event object"))); } -void WebContents::BeginFrameSubscription(mate::Arguments* mate_args) { - // TODO(zcbenz): Remove this after converting WebContents to gin. - gin::Arguments gin_args(mate_args->info()); - gin_helper::Arguments* args = static_cast(&gin_args); - +void WebContents::BeginFrameSubscription(gin_helper::Arguments* args) { bool only_dirty = false; FrameSubscriber::FrameCaptureCallback callback; @@ -2152,32 +2146,19 @@ void WebContents::EndFrameSubscription() { frame_subscriber_.reset(); } -void WebContents::StartDrag(const mate::Dictionary& item, - mate::Arguments* args) { +void WebContents::StartDrag(const gin_helper::Dictionary& item, + gin_helper::Arguments* args) { base::FilePath file; std::vector files; if (!item.Get("files", &files) && item.Get("file", &file)) { files.push_back(file); } - mate::Handle icon; - if (!item.Get("icon", &icon) && !file.empty()) { - // TODO(zcbenz): Set default icon from file. - } - - // Error checking. - if (icon.IsEmpty()) { - args->ThrowError("Must specify 'icon' option"); - return; - } - -#if defined(OS_MACOSX) - // NSWindow.dragImage requires a non-empty NSImage - if (icon->image().IsEmpty()) { + gin::Handle icon; + if (!item.Get("icon", &icon)) { args->ThrowError("Must specify non-empty 'icon' option"); return; } -#endif // Start dragging. if (!files.empty()) { @@ -2188,11 +2169,7 @@ void WebContents::StartDrag(const mate::Dictionary& item, } } -v8::Local WebContents::CapturePage(mate::Arguments* mate_args) { - // TODO(zcbenz): Remove this after converting WebContents to gin. - gin::Arguments gin_args(mate_args->info()); - gin::Arguments* args = &gin_args; - +v8::Local WebContents::CapturePage(gin_helper::Arguments* args) { gfx::Rect rect; util::Promise promise(isolate()); v8::Local handle = promise.GetHandle(); @@ -2202,7 +2179,7 @@ v8::Local WebContents::CapturePage(mate::Arguments* mate_args) { auto* const view = web_contents()->GetRenderWidgetHostView(); if (!view) { - promise.Resolve(gfx::Image()); + promise.ResolveWithGin(gfx::Image()); return handle; } @@ -2233,11 +2210,8 @@ void WebContents::OnCursorChange(const content::WebCursor& cursor) { Emit("cursor-changed", CursorTypeToString(info), gfx::Image::CreateFrom1xBitmap(info.custom_image), info.image_scale_factor, - // TODO(zcbenz): Use implicit convertion after removing - // mate::EventEmitter. - gin::ConvertToV8(isolate(), gfx::Size(info.custom_image.width(), - info.custom_image.height())), - gin::ConvertToV8(isolate(), info.hotspot)); + gfx::Size(info.custom_image.width(), info.custom_image.height()), + info.hotspot); } else { Emit("cursor-changed", CursorTypeToString(info)); } @@ -2374,7 +2348,7 @@ v8::Local WebContents::GetWebPreferences( auto* web_preferences = WebContentsPreferences::From(web_contents()); if (!web_preferences) return v8::Null(isolate); - return mate::ConvertToV8(isolate, *web_preferences->preference()); + return gin::ConvertToV8(isolate, *web_preferences->preference()); } v8::Local WebContents::GetLastWebPreferences( @@ -2382,7 +2356,7 @@ v8::Local WebContents::GetLastWebPreferences( auto* web_preferences = WebContentsPreferences::From(web_contents()); if (!web_preferences) return v8::Null(isolate); - return mate::ConvertToV8(isolate, *web_preferences->last_preference()); + return gin::ConvertToV8(isolate, *web_preferences->last_preference()); } v8::Local WebContents::GetOwnerBrowserWindow() const { @@ -2505,9 +2479,9 @@ v8::Local WebContents::TakeHeapSnapshot( // static void WebContents::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "WebContents")); + prototype->SetClassName(gin::StringToV8(isolate, "WebContents")); gin_helper::Destroyable::MakeDestroyable(isolate, prototype); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("setBackgroundThrottling", &WebContents::SetBackgroundThrottling) .SetMethod("getProcessId", &WebContents::GetProcessID) @@ -2631,40 +2605,40 @@ AtomBrowserContext* WebContents::GetBrowserContext() const { } // static -mate::Handle WebContents::Create(v8::Isolate* isolate, - const mate::Dictionary& options) { - return mate::CreateHandle(isolate, new WebContents(isolate, options)); +gin::Handle WebContents::Create( + v8::Isolate* isolate, + const gin_helper::Dictionary& options) { + return gin::CreateHandle(isolate, new WebContents(isolate, options)); } // static -mate::Handle WebContents::CreateAndTake( +gin::Handle WebContents::CreateAndTake( v8::Isolate* isolate, std::unique_ptr web_contents, Type type) { - return mate::CreateHandle( + return gin::CreateHandle( isolate, new WebContents(isolate, std::move(web_contents), type)); } // static -mate::Handle WebContents::From( - v8::Isolate* isolate, - content::WebContents* web_contents) { +gin::Handle WebContents::From(v8::Isolate* isolate, + content::WebContents* web_contents) { auto* existing = TrackableObject::FromWrappedClass(isolate, web_contents); if (existing) - return mate::CreateHandle(isolate, static_cast(existing)); + return gin::CreateHandle(isolate, static_cast(existing)); else - return mate::Handle(); + return gin::Handle(); } // static -mate::Handle WebContents::FromOrCreate( +gin::Handle WebContents::FromOrCreate( v8::Isolate* isolate, content::WebContents* web_contents) { auto existing = From(isolate, web_contents); if (!existing.IsEmpty()) return existing; else - return mate::CreateHandle(isolate, new WebContents(isolate, web_contents)); + return gin::CreateHandle(isolate, new WebContents(isolate, web_contents)); } } // namespace api @@ -2680,7 +2654,7 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); + gin_helper::Dictionary dict(isolate, exports); dict.Set("WebContents", WebContents::GetConstructor(isolate) ->GetFunction(context) .ToLocalChecked()); diff --git a/shell/browser/api/atom_api_web_contents.h b/shell/browser/api/atom_api_web_contents.h index a3e2644d14..8343fca07f 100644 --- a/shell/browser/api/atom_api_web_contents.h +++ b/shell/browser/api/atom_api_web_contents.h @@ -22,13 +22,13 @@ #include "content/public/common/favicon_url.h" #include "electron/buildflags/buildflags.h" #include "electron/shell/common/api/api.mojom.h" -#include "native_mate/handle.h" +#include "gin/handle.h" #include "printing/buildflags/buildflags.h" #include "services/service_manager/public/cpp/binder_registry.h" #include "shell/browser/api/frame_subscriber.h" #include "shell/browser/api/save_page_handler.h" -#include "shell/browser/api/trackable_object.h" #include "shell/browser/common_web_contents_delegate.h" +#include "shell/common/gin_helper/trackable_object.h" #include "ui/gfx/image/image.h" #if BUILDFLAG(ENABLE_PRINTING) @@ -40,10 +40,9 @@ namespace blink { struct WebDeviceEmulationParams; } -namespace mate { -class Arguments; +namespace gin_helper { class Dictionary; -} // namespace mate +} namespace network { class ResourceRequestBody; @@ -78,7 +77,7 @@ class ExtendedWebContentsObserver : public base::CheckedObserver { }; // Wrapper around the content::WebContents. -class WebContents : public mate::TrackableObject, +class WebContents : public gin_helper::TrackableObject, public CommonWebContentsDelegate, public content::WebContentsObserver, public mojom::ElectronBrowser { @@ -93,26 +92,26 @@ class WebContents : public mate::TrackableObject, }; // Create a new WebContents and return the V8 wrapper of it. - static mate::Handle Create(v8::Isolate* isolate, - const mate::Dictionary& options); + static gin::Handle Create(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 mate::Handle CreateAndTake( + static gin::Handle CreateAndTake( v8::Isolate* isolate, std::unique_ptr web_contents, Type type); // Get the V8 wrapper of |web_content|, return empty handle if not wrapped. - static mate::Handle From(v8::Isolate* isolate, - content::WebContents* web_content); + static gin::Handle From(v8::Isolate* isolate, + content::WebContents* web_content); // Get the V8 wrapper of the |web_contents|, or create one if not existed. // // The lifetime of |web_contents| is NOT managed by this class, and the type // of this wrapper is always REMOTE. - static mate::Handle FromOrCreate( + static gin::Handle FromOrCreate( v8::Isolate* isolate, content::WebContents* web_contents); @@ -143,7 +142,7 @@ class WebContents : public mate::TrackableObject, const std::string& document_url) const; Type GetType() const; bool Equal(const WebContents* web_contents) const; - void LoadURL(const GURL& url, const mate::Dictionary& options); + void LoadURL(const GURL& url, const gin_helper::Dictionary& options); void DownloadURL(const GURL& url); GURL GetURL() const; base::string16 GetTitle() const; @@ -158,12 +157,12 @@ class WebContents : public mate::TrackableObject, const std::string GetWebRTCIPHandlingPolicy() const; void SetWebRTCIPHandlingPolicy(const std::string& webrtc_ip_handling_policy); bool IsCrashed() const; - void SetUserAgent(const std::string& user_agent, mate::Arguments* args); + void SetUserAgent(const std::string& user_agent, gin_helper::Arguments* args); std::string GetUserAgent(); void InsertCSS(const std::string& css); v8::Local SavePage(const base::FilePath& full_file_path, const content::SavePageType& save_type); - void OpenDevTools(mate::Arguments* args); + void OpenDevTools(gin_helper::Arguments* args); void CloseDevTools(); bool IsDevToolsOpened(); bool IsDevToolsFocused(); @@ -184,15 +183,15 @@ class WebContents : public mate::TrackableObject, v8::Local GetNativeView() const; #if BUILDFLAG(ENABLE_PRINTING) - void Print(mate::Arguments* args); + void Print(gin_helper::Arguments* args); std::vector GetPrinterList(); // Print current page as PDF. v8::Local PrintToPDF(const base::DictionaryValue& settings); #endif // DevTools workspace api. - void AddWorkSpace(mate::Arguments* args, const base::FilePath& path); - void RemoveWorkSpace(mate::Arguments* args, const base::FilePath& path); + void AddWorkSpace(gin_helper::Arguments* args, const base::FilePath& path); + void RemoveWorkSpace(gin_helper::Arguments* args, const base::FilePath& path); // Editing commands. void Undo(); @@ -206,7 +205,7 @@ class WebContents : public mate::TrackableObject, void Unselect(); void Replace(const base::string16& word); void ReplaceMisspelling(const base::string16& word); - uint32_t FindInPage(mate::Arguments* args); + uint32_t FindInPage(gin_helper::Arguments* args); void StopFindInPage(content::StopFindAction action); void ShowDefinitionForSelection(); void CopyImageAt(int x, int y); @@ -238,15 +237,16 @@ class WebContents : public mate::TrackableObject, void SendInputEvent(v8::Isolate* isolate, v8::Local input_event); // Subscribe to the frame updates. - void BeginFrameSubscription(mate::Arguments* args); + void BeginFrameSubscription(gin_helper::Arguments* args); void EndFrameSubscription(); // Dragging native items. - void StartDrag(const mate::Dictionary& item, mate::Arguments* args); + void StartDrag(const gin_helper::Dictionary& item, + gin_helper::Arguments* args); // Captures the page with |rect|, |callback| would be called when capturing is // done. - v8::Local CapturePage(mate::Arguments* args); + v8::Local CapturePage(gin_helper::Arguments* args); // Methods for creating . bool IsGuest() const; @@ -335,14 +335,14 @@ class WebContents : public mate::TrackableObject, std::unique_ptr web_contents, Type type); // Creates a new content::WebContents. - WebContents(v8::Isolate* isolate, const mate::Dictionary& options); + WebContents(v8::Isolate* isolate, const gin_helper::Dictionary& options); ~WebContents() override; void InitWithSessionAndOptions( v8::Isolate* isolate, std::unique_ptr web_contents, - mate::Handle session, - const mate::Dictionary& options); + gin::Handle session, + const gin_helper::Dictionary& options); // content::WebContentsDelegate: bool DidAddMessageToConsole(content::WebContents* source, @@ -526,7 +526,7 @@ class WebContents : public mate::TrackableObject, IPC::Message* reply_msg); void InitZoomController(content::WebContents* web_contents, - const mate::Dictionary& options); + const gin_helper::Dictionary& options); v8::Global session_; v8::Global devtools_web_contents_; diff --git a/shell/browser/api/atom_api_web_contents_view.cc b/shell/browser/api/atom_api_web_contents_view.cc index 28e84b5795..1aae461cde 100644 --- a/shell/browser/api/atom_api_web_contents_view.cc +++ b/shell/browser/api/atom_api_web_contents_view.cc @@ -5,11 +5,11 @@ #include "shell/browser/api/atom_api_web_contents_view.h" #include "content/public/browser/web_contents_user_data.h" -#include "native_mate/dictionary.h" #include "shell/browser/api/atom_api_web_contents.h" #include "shell/browser/browser.h" #include "shell/browser/ui/inspectable_web_contents_view.h" #include "shell/common/api/constructor.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" #if defined(OS_MACOSX) @@ -44,7 +44,7 @@ namespace electron { namespace api { WebContentsView::WebContentsView(v8::Isolate* isolate, - mate::Handle web_contents, + gin::Handle web_contents, InspectableWebContents* iwc) #if defined(OS_MACOSX) : View(new DelayedNativeViewHost(iwc->GetView()->GetNativeView())), @@ -80,22 +80,18 @@ void WebContentsView::WebContentsDestroyed() { // static mate::WrappableBase* WebContentsView::New( - gin::Arguments* args, - mate::Handle web_contents) { + gin_helper::Arguments* args, + gin::Handle web_contents) { // Currently we only support InspectableWebContents, e.g. the WebContents // created by users directly. To support devToolsWebContents we need to create // a wrapper view. if (!web_contents->managed_web_contents()) { - const char* error = "The WebContents must be created by user"; - args->isolate()->ThrowException( - v8::Exception::Error(mate::StringToV8(args->isolate(), error))); + args->ThrowError("The WebContents must be created by user"); return nullptr; } // Check if the WebContents has already been added to a view. if (WebContentsViewRelay::FromWebContents(web_contents->web_contents())) { - const char* error = "The WebContents has already been added to a View"; - args->isolate()->ThrowException( - v8::Exception::Error(mate::StringToV8(args->isolate(), error))); + args->ThrowError("The WebContents has already been added to a View"); return nullptr; } // Constructor call. @@ -123,7 +119,7 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); + gin_helper::Dictionary dict(isolate, exports); dict.Set("WebContentsView", mate::CreateConstructor( isolate, base::BindRepeating(&WebContentsView::New))); diff --git a/shell/browser/api/atom_api_web_contents_view.h b/shell/browser/api/atom_api_web_contents_view.h index 6502cb7dd6..134717c5a7 100644 --- a/shell/browser/api/atom_api_web_contents_view.h +++ b/shell/browser/api/atom_api_web_contents_view.h @@ -6,7 +6,6 @@ #define SHELL_BROWSER_API_ATOM_API_WEB_CONTENTS_VIEW_H_ #include "content/public/browser/web_contents_observer.h" -#include "native_mate/handle.h" #include "shell/browser/api/atom_api_view.h" namespace electron { @@ -19,15 +18,15 @@ class WebContents; class WebContentsView : public View, public content::WebContentsObserver { public: - static mate::WrappableBase* New(gin::Arguments* args, - mate::Handle web_contents); + static mate::WrappableBase* New(gin_helper::Arguments* args, + gin::Handle web_contents); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); protected: WebContentsView(v8::Isolate* isolate, - mate::Handle web_contents, + gin::Handle web_contents, InspectableWebContents* iwc); ~WebContentsView() override; diff --git a/shell/browser/api/atom_api_web_view_manager.cc b/shell/browser/api/atom_api_web_view_manager.cc index a21e2ef724..3f89e636bb 100644 --- a/shell/browser/api/atom_api_web_view_manager.cc +++ b/shell/browser/api/atom_api_web_view_manager.cc @@ -3,12 +3,12 @@ // found in the LICENSE file. #include "content/public/browser/browser_context.h" -#include "native_mate/dictionary.h" #include "shell/browser/web_contents_preferences.h" #include "shell/browser/web_contents_zoom_controller.h" #include "shell/browser/web_view_manager.h" -#include "shell/common/native_mate_converters/content_converter.h" -#include "shell/common/native_mate_converters/value_converter.h" +#include "shell/common/gin_converters/content_converter.h" +#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" #include "shell/common/options_switches.h" @@ -45,7 +45,7 @@ void Initialize(v8::Local exports, v8::Local unused, v8::Local context, void* priv) { - mate::Dictionary dict(context->GetIsolate(), exports); + gin_helper::Dictionary dict(context->GetIsolate(), exports); dict.SetMethod("addGuest", &AddGuest); dict.SetMethod("removeGuest", &RemoveGuest); } diff --git a/shell/browser/api/event_emitter_deprecated.cc b/shell/browser/api/event_emitter_deprecated.cc deleted file mode 100644 index 7d31bddc57..0000000000 --- a/shell/browser/api/event_emitter_deprecated.cc +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) 2014 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "shell/browser/api/event_emitter_deprecated.h" - -#include - -#include "content/public/browser/render_frame_host.h" -#include "native_mate/arguments.h" -#include "native_mate/dictionary.h" -#include "native_mate/object_template_builder_deprecated.h" -#include "shell/browser/api/event.h" -#include "shell/common/node_includes.h" -#include "ui/events/event_constants.h" - -namespace mate { - -namespace { - -v8::Persistent event_template; - -void PreventDefault(mate::Arguments* args) { - mate::Dictionary self(args->isolate(), args->GetThis()); - self.Set("defaultPrevented", true); -} - -// Create a pure JavaScript Event object. -v8::Local CreateEventObject(v8::Isolate* isolate) { - if (event_template.IsEmpty()) { - event_template.Reset( - isolate, - ObjectTemplateBuilder(isolate, v8::ObjectTemplate::New(isolate)) - .SetMethod("preventDefault", &PreventDefault) - .Build()); - } - - return v8::Local::New(isolate, event_template) - ->NewInstance(isolate->GetCurrentContext()) - .ToLocalChecked(); -} - -} // namespace - -namespace internal { - -v8::Local CreateJSEvent( - v8::Isolate* isolate, - v8::Local object, - content::RenderFrameHost* sender, - base::Optional - callback) { - v8::Local event; - bool use_native_event = sender && callback; - - if (use_native_event) { - mate::Handle native_event = mate::Event::Create(isolate); - native_event->SetCallback(std::move(callback)); - event = v8::Local::Cast(native_event.ToV8()); - } else { - event = CreateEventObject(isolate); - } - mate::Dictionary dict(isolate, event); - dict.Set("sender", object); - if (sender) - dict.Set("frameId", sender->GetRoutingID()); - return event; -} - -v8::Local CreateCustomEvent(v8::Isolate* isolate, - v8::Local object, - v8::Local custom_event) { - v8::Local event = CreateEventObject(isolate); - (void)event->SetPrototype(custom_event->CreationContext(), custom_event); - mate::Dictionary(isolate, event).Set("sender", object); - return event; -} - -v8::Local CreateEventFromFlags(v8::Isolate* isolate, int flags) { - const int mouse_button_flags = - (ui::EF_RIGHT_MOUSE_BUTTON | ui::EF_LEFT_MOUSE_BUTTON | - ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_BACK_MOUSE_BUTTON | - ui::EF_FORWARD_MOUSE_BUTTON); - const int is_mouse_click = static_cast(flags & mouse_button_flags); - mate::Dictionary obj = mate::Dictionary::CreateEmpty(isolate); - obj.Set("shiftKey", static_cast(flags & ui::EF_SHIFT_DOWN)); - obj.Set("ctrlKey", static_cast(flags & ui::EF_CONTROL_DOWN)); - obj.Set("altKey", static_cast(flags & ui::EF_ALT_DOWN)); - obj.Set("metaKey", static_cast(flags & ui::EF_COMMAND_DOWN)); - obj.Set("triggeredByAccelerator", !is_mouse_click); - return obj.GetHandle(); -} - -} // namespace internal - -} // namespace mate diff --git a/shell/browser/api/event_emitter_deprecated.h b/shell/browser/api/event_emitter_deprecated.h deleted file mode 100644 index 3f909463b6..0000000000 --- a/shell/browser/api/event_emitter_deprecated.h +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) 2014 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef SHELL_BROWSER_API_EVENT_EMITTER_DEPRECATED_H_ -#define SHELL_BROWSER_API_EVENT_EMITTER_DEPRECATED_H_ - -#include -#include - -#include "base/optional.h" -#include "content/public/browser/browser_thread.h" -#include "electron/shell/common/api/api.mojom.h" -#include "native_mate/wrappable.h" -#include "shell/common/api/event_emitter_caller_deprecated.h" - -namespace content { -class RenderFrameHost; -} - -namespace mate { - -namespace internal { - -v8::Local CreateJSEvent( - v8::Isolate* isolate, - v8::Local object, - content::RenderFrameHost* sender, - base::Optional - callback); -v8::Local CreateCustomEvent(v8::Isolate* isolate, - v8::Local object, - v8::Local event); -v8::Local CreateEventFromFlags(v8::Isolate* isolate, int flags); - -} // namespace internal - -// Provide helperers to emit event in JavaScript. -template -class EventEmitter : public Wrappable { - public: - typedef std::vector> ValueArray; - - // Make the convinient methods visible: - // https://isocpp.org/wiki/faq/templates#nondependent-name-lookup-members - v8::Isolate* isolate() const { return Wrappable::isolate(); } - v8::Local GetWrapper() const { - return Wrappable::GetWrapper(); - } - v8::MaybeLocal GetWrapper(v8::Isolate* isolate) const { - return Wrappable::GetWrapper(isolate); - } - - // this.emit(name, event, args...); - template - bool EmitCustomEvent(base::StringPiece name, - v8::Local event, - Args&&... args) { - return EmitWithEvent( - name, internal::CreateCustomEvent(isolate(), GetWrapper(), event), - std::forward(args)...); - } - - // this.emit(name, new Event(flags), args...); - template - bool EmitWithFlags(base::StringPiece name, int flags, Args&&... args) { - return EmitCustomEvent(name, - internal::CreateEventFromFlags(isolate(), flags), - std::forward(args)...); - } - - // this.emit(name, new Event(), args...); - template - bool Emit(base::StringPiece name, Args&&... args) { - return EmitWithSender(name, nullptr, base::nullopt, - std::forward(args)...); - } - - // this.emit(name, new Event(sender, message), args...); - template - bool EmitWithSender( - base::StringPiece name, - content::RenderFrameHost* sender, - base::Optional callback, - Args&&... args) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - v8::Locker locker(isolate()); - v8::HandleScope handle_scope(isolate()); - v8::Local wrapper = GetWrapper(); - if (wrapper.IsEmpty()) { - return false; - } - v8::Local event = internal::CreateJSEvent( - isolate(), wrapper, sender, std::move(callback)); - return EmitWithEvent(name, event, std::forward(args)...); - } - - protected: - EventEmitter() {} - - private: - // this.emit(name, event, args...); - template - bool EmitWithEvent(base::StringPiece name, - v8::Local event, - Args&&... args) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - // It's possible that |this| will be deleted by EmitEvent, so save anything - // we need from |this| before calling EmitEvent. - auto* isolate = this->isolate(); - v8::Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - auto context = isolate->GetCurrentContext(); - EmitEvent(isolate, GetWrapper(), name, event, std::forward(args)...); - v8::Local defaultPrevented; - if (event->Get(context, StringToV8(isolate, "defaultPrevented")) - .ToLocal(&defaultPrevented)) { - return defaultPrevented->BooleanValue(isolate); - } - return false; - } - - DISALLOW_COPY_AND_ASSIGN(EventEmitter); -}; - -} // namespace mate - -#endif // SHELL_BROWSER_API_EVENT_EMITTER_DEPRECATED_H_ diff --git a/shell/browser/api/views/atom_api_layout_manager.h b/shell/browser/api/views/atom_api_layout_manager.h index 9281e58ef5..c8dd957bf2 100644 --- a/shell/browser/api/views/atom_api_layout_manager.h +++ b/shell/browser/api/views/atom_api_layout_manager.h @@ -7,14 +7,14 @@ #include -#include "shell/browser/api/trackable_object.h" +#include "shell/common/gin_helper/trackable_object.h" #include "ui/views/layout/layout_manager.h" namespace electron { namespace api { -class LayoutManager : public mate::TrackableObject { +class LayoutManager : public gin_helper::TrackableObject { public: static mate::WrappableBase* New(mate::Arguments* args); diff --git a/shell/browser/atom_browser_main_parts.cc b/shell/browser/atom_browser_main_parts.cc index b5f5c1209c..e54951818f 100644 --- a/shell/browser/atom_browser_main_parts.cc +++ b/shell/browser/atom_browser_main_parts.cc @@ -34,7 +34,6 @@ #include "services/service_manager/public/cpp/connector.h" #include "shell/app/atom_main_delegate.h" #include "shell/browser/api/atom_api_app.h" -#include "shell/browser/api/trackable_object.h" #include "shell/browser/atom_browser_client.h" #include "shell/browser/atom_browser_context.h" #include "shell/browser/atom_paths.h" @@ -49,6 +48,7 @@ #include "shell/common/api/electron_bindings.h" #include "shell/common/application_info.h" #include "shell/common/asar/asar_util.h" +#include "shell/common/gin_helper/trackable_object.h" #include "shell/common/node_bindings.h" #include "shell/common/node_includes.h" #include "ui/base/idle/idle.h" diff --git a/shell/browser/lib/bluetooth_chooser.cc b/shell/browser/lib/bluetooth_chooser.cc index 70cd75ae00..37494953f5 100644 --- a/shell/browser/lib/bluetooth_chooser.cc +++ b/shell/browser/lib/bluetooth_chooser.cc @@ -3,25 +3,25 @@ // found in the LICENSE file. #include "shell/browser/lib/bluetooth_chooser.h" -#include "native_mate/dictionary.h" -#include "shell/common/native_mate_converters/once_callback.h" -#include "shell/common/native_mate_converters/string16_converter.h" -namespace mate { +#include "shell/common/gin_converters/callback_converter.h" +#include "shell/common/gin_helper/dictionary.h" + +namespace gin { template <> struct Converter { static v8::Local ToV8( v8::Isolate* isolate, const electron::BluetoothChooser::DeviceInfo& val) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); dict.Set("deviceName", val.device_name); dict.Set("deviceId", val.device_id); - return mate::ConvertToV8(isolate, dict); + return gin::ConvertToV8(isolate, dict); } }; -} // namespace mate +} // namespace gin namespace electron { diff --git a/shell/browser/native_window.cc b/shell/browser/native_window.cc index d707326159..9e83001720 100644 --- a/shell/browser/native_window.cc +++ b/shell/browser/native_window.cc @@ -11,10 +11,10 @@ #include "base/memory/ptr_util.h" #include "base/strings/utf_string_conversions.h" -#include "native_mate/dictionary.h" #include "shell/browser/browser.h" #include "shell/browser/window_list.h" #include "shell/common/color_util.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/options_switches.h" #include "ui/views/widget/widget.h" @@ -45,7 +45,7 @@ gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) { } // namespace -NativeWindow::NativeWindow(const mate::Dictionary& options, +NativeWindow::NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent) : widget_(new views::Widget), parent_(parent), weak_factory_(this) { options.Get(options::kFrame, &has_frame_); @@ -67,7 +67,7 @@ NativeWindow::~NativeWindow() { NotifyWindowClosed(); } -void NativeWindow::InitFromOptions(const mate::Dictionary& options) { +void NativeWindow::InitFromOptions(const gin_helper::Dictionary& options) { // Setup window from options. int x = -1, y = -1; bool center; diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index 6f87855faa..e7afbf6dae 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -37,10 +37,13 @@ class RectF; class Size; } // namespace gfx -namespace mate { +namespace gin_helper { class Dictionary; +} + +namespace mate { class PersistentDictionary; -} // namespace mate +} namespace electron { @@ -60,10 +63,10 @@ class NativeWindow : public base::SupportsUserData, // Create window with existing WebContents, the caller is responsible for // managing the window's live. - static NativeWindow* Create(const mate::Dictionary& options, + static NativeWindow* Create(const gin_helper::Dictionary& options, NativeWindow* parent = nullptr); - void InitFromOptions(const mate::Dictionary& options); + void InitFromOptions(const gin_helper::Dictionary& options); virtual void SetContentView(views::View* view) = 0; @@ -304,7 +307,7 @@ class NativeWindow : public base::SupportsUserData, std::list browser_views() const { return browser_views_; } protected: - NativeWindow(const mate::Dictionary& options, NativeWindow* parent); + NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent); // views::WidgetDelegate: views::Widget* GetWidget() override; diff --git a/shell/browser/native_window_mac.h b/shell/browser/native_window_mac.h index c570eb212a..a1130b39e4 100644 --- a/shell/browser/native_window_mac.h +++ b/shell/browser/native_window_mac.h @@ -28,7 +28,7 @@ class RootViewMac; class NativeWindowMac : public NativeWindow { public: - NativeWindowMac(const mate::Dictionary& options, NativeWindow* parent); + NativeWindowMac(const gin_helper::Dictionary& options, NativeWindow* parent); ~NativeWindowMac() override; // NativeWindow: diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index e449f1973e..dc8171878c 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -17,7 +17,6 @@ #include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h" #include "content/public/browser/browser_accessibility_state.h" #include "content/public/browser/desktop_media_id.h" -#include "native_mate/dictionary.h" #include "shell/browser/native_browser_view_mac.h" #include "shell/browser/ui/cocoa/atom_native_widget_mac.h" #include "shell/browser/ui/cocoa/atom_ns_window.h" @@ -29,6 +28,7 @@ #include "shell/browser/ui/inspectable_web_contents_view.h" #include "shell/browser/window_list.h" #include "shell/common/deprecate_util.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/options_switches.h" #include "skia/ext/skia_utils_mac.h" #include "third_party/webrtc/modules/desktop_capture/mac/window_list_utils.h" @@ -244,7 +244,7 @@ @end -namespace mate { +namespace gin { template <> struct Converter { @@ -268,7 +268,7 @@ struct Converter { } }; -} // namespace mate +} // namespace gin namespace electron { @@ -318,7 +318,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) { } // namespace -NativeWindowMac::NativeWindowMac(const mate::Dictionary& options, +NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options, NativeWindow* parent) : NativeWindow(options, parent), root_view_(new RootViewMac(this)) { int width = 800, height = 600; @@ -1659,7 +1659,7 @@ void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) { } // static -NativeWindow* NativeWindow::Create(const mate::Dictionary& options, +NativeWindow* NativeWindow::Create(const gin_helper::Dictionary& options, NativeWindow* parent) { return new NativeWindowMac(options, parent); } diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 1e58e15e40..8e8dd0ef45 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -18,7 +18,6 @@ #include "base/strings/utf_string_conversions.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/desktop_media_id.h" -#include "native_mate/dictionary.h" #include "shell/browser/api/atom_api_web_contents.h" #include "shell/browser/native_browser_view_views.h" #include "shell/browser/ui/inspectable_web_contents.h" @@ -28,7 +27,8 @@ #include "shell/browser/web_view_manager.h" #include "shell/browser/window_list.h" #include "shell/common/atom_constants.h" -#include "shell/common/native_mate_converters/image_converter.h" +#include "shell/common/gin_converters/image_converter.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/options_switches.h" #include "ui/aura/window_tree_host.h" #include "ui/base/hit_test.h" @@ -126,7 +126,7 @@ class NativeWindowClientView : public views::ClientView { } // namespace -NativeWindowViews::NativeWindowViews(const mate::Dictionary& options, +NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options, NativeWindow* parent) : NativeWindow(options, parent), root_view_(new RootView(this)), @@ -1454,7 +1454,7 @@ void NativeWindowViews::MoveBehindTaskBarIfNeeded() { } // static -NativeWindow* NativeWindow::Create(const mate::Dictionary& options, +NativeWindow* NativeWindow::Create(const gin_helper::Dictionary& options, NativeWindow* parent) { return new NativeWindowViews(options, parent); } diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 8b8d973916..078885cd41 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -37,7 +37,8 @@ class NativeWindowViews : public NativeWindow, public views::WidgetObserver, public ui::EventHandler { public: - NativeWindowViews(const mate::Dictionary& options, NativeWindow* parent); + NativeWindowViews(const gin_helper::Dictionary& options, + NativeWindow* parent); ~NativeWindowViews() override; // NativeWindow: diff --git a/shell/browser/net/atom_url_loader_factory.cc b/shell/browser/net/atom_url_loader_factory.cc index 7898c8ea5b..e56b09f942 100644 --- a/shell/browser/net/atom_url_loader_factory.cc +++ b/shell/browser/net/atom_url_loader_factory.cc @@ -388,8 +388,8 @@ void AtomURLLoaderFactory::StartLoadingHttp( if (value->IsNull()) { browser_context = AtomBrowserContext::From(base::GenerateGUID(), true); } else { - mate::Handle session; - if (mate::ConvertFromV8(dict.isolate(), value, &session) && + gin::Handle session; + if (gin::ConvertFromV8(dict.isolate(), value, &session) && !session.IsEmpty()) { browser_context = session->browser_context(); } diff --git a/shell/browser/web_contents_preferences.cc b/shell/browser/web_contents_preferences.cc index e247641773..af325d1b1f 100644 --- a/shell/browser/web_contents_preferences.cc +++ b/shell/browser/web_contents_preferences.cc @@ -19,12 +19,12 @@ #include "content/public/common/content_switches.h" #include "content/public/common/web_preferences.h" #include "electron/buildflags/buildflags.h" -#include "native_mate/dictionary.h" #include "net/base/filename_util.h" #include "services/service_manager/sandbox/switches.h" #include "shell/browser/native_window.h" #include "shell/browser/web_view_manager.h" -#include "shell/common/native_mate_converters/value_converter.h" +#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/options_switches.h" #if defined(OS_WIN) @@ -101,16 +101,16 @@ std::vector WebContentsPreferences::instances_; WebContentsPreferences::WebContentsPreferences( content::WebContents* web_contents, - const mate::Dictionary& web_preferences) + const gin_helper::Dictionary& web_preferences) : web_contents_(web_contents) { v8::Isolate* isolate = web_preferences.isolate(); - mate::Dictionary copied(isolate, web_preferences.GetHandle()->Clone()); + gin_helper::Dictionary copied(isolate, web_preferences.GetHandle()->Clone()); // Following fields should not be stored. copied.Delete("embedder"); copied.Delete("session"); copied.Delete("type"); - mate::ConvertFromV8(isolate, copied.GetHandle(), &preference_); + gin::ConvertFromV8(isolate, copied.GetHandle(), &preference_); web_contents->SetUserData(UserDataKey(), base::WrapUnique(this)); instances_.push_back(this); diff --git a/shell/browser/web_contents_preferences.h b/shell/browser/web_contents_preferences.h index 993c2f420e..915ab7ddcd 100644 --- a/shell/browser/web_contents_preferences.h +++ b/shell/browser/web_contents_preferences.h @@ -19,7 +19,7 @@ namespace content { struct WebPreferences; } -namespace mate { +namespace gin_helper { class Dictionary; } @@ -33,7 +33,7 @@ class WebContentsPreferences static WebContentsPreferences* From(content::WebContents* web_contents); WebContentsPreferences(content::WebContents* web_contents, - const mate::Dictionary& web_preferences); + const gin_helper::Dictionary& web_preferences); ~WebContentsPreferences() override; // Set WebPreferences defaults onto the JS object. diff --git a/shell/common/api/atom_api_native_image.cc b/shell/common/api/atom_api_native_image.cc index 2f7c3be865..47061a5533 100644 --- a/shell/common/api/atom_api_native_image.cc +++ b/shell/common/api/atom_api_native_image.cc @@ -259,7 +259,7 @@ float NativeImage::GetAspectRatio() { return static_cast(size.width()) / static_cast(size.height()); } -mate::Handle NativeImage::Resize( +gin::Handle NativeImage::Resize( v8::Isolate* isolate, const base::DictionaryValue& options) { gfx::Size size = GetSize(); @@ -290,16 +290,16 @@ mate::Handle NativeImage::Resize( gfx::ImageSkia resized = gfx::ImageSkiaOperations::CreateResizedImage( image_.AsImageSkia(), method, size); - return mate::CreateHandle(isolate, - new NativeImage(isolate, gfx::Image(resized))); + return gin::CreateHandle(isolate, + new NativeImage(isolate, gfx::Image(resized))); } -mate::Handle NativeImage::Crop(v8::Isolate* isolate, - const gfx::Rect& rect) { +gin::Handle NativeImage::Crop(v8::Isolate* isolate, + const gfx::Rect& rect) { gfx::ImageSkia cropped = gfx::ImageSkiaOperations::ExtractSubset(image_.AsImageSkia(), rect); - return mate::CreateHandle(isolate, - new NativeImage(isolate, gfx::Image(cropped))); + return gin::CreateHandle(isolate, + new NativeImage(isolate, gfx::Image(cropped))); } void NativeImage::AddRepresentation(const gin_helper::Dictionary& options) { @@ -350,48 +350,48 @@ bool NativeImage::IsTemplateImage() { #endif // static -mate::Handle NativeImage::CreateEmpty(v8::Isolate* isolate) { - return mate::CreateHandle(isolate, new NativeImage(isolate, gfx::Image())); +gin::Handle NativeImage::CreateEmpty(v8::Isolate* isolate) { + return gin::CreateHandle(isolate, new NativeImage(isolate, gfx::Image())); } // static -mate::Handle NativeImage::Create(v8::Isolate* isolate, - const gfx::Image& image) { - return mate::CreateHandle(isolate, new NativeImage(isolate, image)); +gin::Handle NativeImage::Create(v8::Isolate* isolate, + const gfx::Image& image) { + return gin::CreateHandle(isolate, new NativeImage(isolate, image)); } // static -mate::Handle NativeImage::CreateFromPNG(v8::Isolate* isolate, - const char* buffer, - size_t length) { +gin::Handle NativeImage::CreateFromPNG(v8::Isolate* isolate, + const char* buffer, + size_t length) { gfx::Image image = gfx::Image::CreateFrom1xPNGBytes( reinterpret_cast(buffer), length); return Create(isolate, image); } // static -mate::Handle NativeImage::CreateFromJPEG(v8::Isolate* isolate, - const char* buffer, - size_t length) { +gin::Handle NativeImage::CreateFromJPEG(v8::Isolate* isolate, + const char* buffer, + size_t length) { gfx::Image image = gfx::ImageFrom1xJPEGEncodedData( reinterpret_cast(buffer), length); return Create(isolate, image); } // static -mate::Handle NativeImage::CreateFromPath( +gin::Handle NativeImage::CreateFromPath( v8::Isolate* isolate, const base::FilePath& path) { base::FilePath image_path = NormalizePath(path); #if defined(OS_WIN) if (image_path.MatchesExtension(FILE_PATH_LITERAL(".ico"))) { - return mate::CreateHandle(isolate, new NativeImage(isolate, image_path)); + return gin::CreateHandle(isolate, new NativeImage(isolate, image_path)); } #endif gfx::ImageSkia image_skia; electron::util::PopulateImageSkiaRepsFromPath(&image_skia, image_path); gfx::Image image(image_skia); - mate::Handle handle = Create(isolate, image); + gin::Handle handle = Create(isolate, image); #if defined(OS_MACOSX) if (IsTemplateFilename(image_path)) handle->SetTemplateImage(true); @@ -400,13 +400,13 @@ mate::Handle NativeImage::CreateFromPath( } // static -mate::Handle NativeImage::CreateFromBitmap( +gin::Handle NativeImage::CreateFromBitmap( gin_helper::ErrorThrower thrower, v8::Local buffer, const gin_helper::Dictionary& options) { if (!node::Buffer::HasInstance(buffer)) { thrower.ThrowError("buffer must be a node Buffer"); - return mate::Handle(); + return gin::Handle(); } unsigned int width = 0; @@ -415,12 +415,12 @@ mate::Handle NativeImage::CreateFromBitmap( if (!options.Get("width", &width)) { thrower.ThrowError("width is required"); - return mate::Handle(); + return gin::Handle(); } if (!options.Get("height", &height)) { thrower.ThrowError("height is required"); - return mate::Handle(); + return gin::Handle(); } auto info = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType); @@ -428,7 +428,7 @@ mate::Handle NativeImage::CreateFromBitmap( if (size_bytes != node::Buffer::Length(buffer)) { thrower.ThrowError("invalid buffer size"); - return mate::Handle(); + return gin::Handle(); } options.Get("scaleFactor", &scale_factor); @@ -448,13 +448,13 @@ mate::Handle NativeImage::CreateFromBitmap( } // static -mate::Handle NativeImage::CreateFromBuffer( +gin::Handle NativeImage::CreateFromBuffer( gin_helper::ErrorThrower thrower, v8::Local buffer, gin::Arguments* args) { if (!node::Buffer::HasInstance(buffer)) { thrower.ThrowError("buffer must be a node Buffer"); - return mate::Handle(); + return gin::Handle(); } int width = 0; @@ -476,8 +476,8 @@ mate::Handle NativeImage::CreateFromBuffer( } // static -mate::Handle NativeImage::CreateFromDataURL(v8::Isolate* isolate, - const GURL& url) { +gin::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") @@ -490,7 +490,7 @@ mate::Handle NativeImage::CreateFromDataURL(v8::Isolate* isolate, } #if !defined(OS_MACOSX) -mate::Handle NativeImage::CreateFromNamedImage( +gin::Handle NativeImage::CreateFromNamedImage( gin::Arguments* args, const std::string& name) { return CreateEmpty(args->isolate()); @@ -526,32 +526,31 @@ void NativeImage::BuildPrototype(v8::Isolate* isolate, namespace gin { -v8::Local Converter>::ToV8( +v8::Local Converter::ToV8( v8::Isolate* isolate, - const mate::Handle& val) { - return val.ToV8(); + electron::api::NativeImage* val) { + if (val) + return val->GetWrapper(); + else + return v8::Null(isolate); } -bool Converter>::FromV8( +bool Converter::FromV8( v8::Isolate* isolate, v8::Local val, - mate::Handle* out) { + electron::api::NativeImage** out) { // Try converting from file path. base::FilePath path; if (ConvertFromV8(isolate, val, &path)) { - *out = electron::api::NativeImage::CreateFromPath(isolate, path); + *out = electron::api::NativeImage::CreateFromPath(isolate, path).get(); // Should throw when failed to initialize from path. return !(*out)->image().IsEmpty(); } - auto* wrapper = static_cast( - mate::internal::FromV8Impl(isolate, val)); - if (!wrapper) - return false; - - *out = mate::CreateHandle(isolate, - static_cast(wrapper)); - return true; + *out = static_cast( + static_cast( + mate::internal::FromV8Impl(isolate, val))); + return *out != nullptr; } } // namespace gin diff --git a/shell/common/api/atom_api_native_image.h b/shell/common/api/atom_api_native_image.h index dc2c8b1914..6d1029b178 100644 --- a/shell/common/api/atom_api_native_image.h +++ b/shell/common/api/atom_api_native_image.h @@ -9,7 +9,7 @@ #include #include "base/values.h" -#include "native_mate/handle.h" +#include "gin/handle.h" #include "native_mate/wrappable.h" #include "shell/common/gin_helper/error_thrower.h" #include "ui/gfx/image/image.h" @@ -40,30 +40,29 @@ namespace api { class NativeImage : public mate::Wrappable { public: - static mate::Handle CreateEmpty(v8::Isolate* isolate); - static mate::Handle Create(v8::Isolate* isolate, - const gfx::Image& image); - static mate::Handle CreateFromPNG(v8::Isolate* isolate, + 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, + const char* buffer, + size_t length); + static gin::Handle CreateFromJPEG(v8::Isolate* isolate, const char* buffer, size_t length); - static mate::Handle CreateFromJPEG(v8::Isolate* isolate, - const char* buffer, - size_t length); - static mate::Handle CreateFromPath(v8::Isolate* isolate, - const base::FilePath& path); - static mate::Handle CreateFromBitmap( + static gin::Handle CreateFromPath(v8::Isolate* isolate, + const base::FilePath& path); + static gin::Handle CreateFromBitmap( gin_helper::ErrorThrower thrower, v8::Local buffer, const gin_helper::Dictionary& options); - static mate::Handle CreateFromBuffer( + static gin::Handle CreateFromBuffer( gin_helper::ErrorThrower thrower, v8::Local buffer, gin::Arguments* args); - static mate::Handle CreateFromDataURL(v8::Isolate* isolate, - const GURL& url); - static mate::Handle CreateFromNamedImage( - gin::Arguments* args, - const std::string& name); + static gin::Handle CreateFromDataURL(v8::Isolate* isolate, + const GURL& url); + static gin::Handle CreateFromNamedImage(gin::Arguments* args, + const std::string& name); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); @@ -87,9 +86,9 @@ class NativeImage : public mate::Wrappable { v8::Local ToBitmap(gin::Arguments* args); v8::Local GetBitmap(gin::Arguments* args); v8::Local GetNativeHandle(gin_helper::ErrorThrower thrower); - mate::Handle Resize(v8::Isolate* isolate, - const base::DictionaryValue& options); - mate::Handle Crop(v8::Isolate* isolate, const gfx::Rect& rect); + gin::Handle Resize(v8::Isolate* isolate, + const base::DictionaryValue& options); + gin::Handle Crop(v8::Isolate* isolate, const gfx::Rect& rect); std::string ToDataURL(gin::Arguments* args); bool IsEmpty(); gfx::Size GetSize(); @@ -119,36 +118,14 @@ namespace gin { // A custom converter that allows converting path to NativeImage. template <> -struct Converter> { - static v8::Local ToV8( - v8::Isolate* isolate, - const mate::Handle& val); +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + electron::api::NativeImage* val); static bool FromV8(v8::Isolate* isolate, v8::Local val, - mate::Handle* out); + electron::api::NativeImage** out); }; } // namespace gin -namespace mate { - -// Keep compatibility with native_mate code. -// -// TODO(zcbenz): Remove this after removing native_mate. -template <> -struct Converter> { - static v8::Local ToV8( - v8::Isolate* isolate, - const mate::Handle& val) { - return gin::ConvertToV8(isolate, val); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - mate::Handle* out) { - return gin::ConvertFromV8(isolate, val, out); - } -}; - -} // namespace mate - #endif // SHELL_COMMON_API_ATOM_API_NATIVE_IMAGE_H_ diff --git a/shell/common/api/atom_api_native_image_mac.mm b/shell/common/api/atom_api_native_image_mac.mm index 5396cbf9cf..1d0a7fd07b 100644 --- a/shell/common/api/atom_api_native_image_mac.mm +++ b/shell/common/api/atom_api_native_image_mac.mm @@ -33,7 +33,7 @@ double safeShift(double in, double def) { return def; } -mate::Handle NativeImage::CreateFromNamedImage( +gin::Handle NativeImage::CreateFromNamedImage( gin::Arguments* args, const std::string& name) { @autoreleasepool { diff --git a/shell/common/api/atom_api_v8_util.cc b/shell/common/api/atom_api_v8_util.cc index 67e4ad73be..a683f3dc54 100644 --- a/shell/common/api/atom_api_v8_util.cc +++ b/shell/common/api/atom_api_v8_util.cc @@ -7,6 +7,7 @@ #include "base/hash/hash.h" #include "electron/buildflags/buildflags.h" +#include "shell/common/gin_converters/content_converter.h" #include "shell/common/gin_converters/gurl_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" @@ -19,10 +20,6 @@ #include "shell/common/api/remote/remote_object_freer.h" #endif -// TODO(zcbenz): Remove the includes after removing native_mate. -#include "native_mate/dictionary.h" -#include "shell/common/native_mate_converters/content_converter.h" - namespace std { // The hash function used by DoubleIDWeakMap. @@ -125,11 +122,8 @@ void Initialize(v8::Local exports, dict.SetMethod("getObjectHash", &GetObjectHash); dict.SetMethod("takeHeapSnapshot", &TakeHeapSnapshot); #if BUILDFLAG(ENABLE_REMOTE_MODULE) - // TODO(zcbenz): Use gin_helper::Dictionary when content_converter.h is moved - // to gin. - mate::Dictionary mdict(context->GetIsolate(), exports); - mdict.SetMethod("setRemoteCallbackFreer", - &electron::RemoteCallbackFreer::BindTo); + dict.SetMethod("setRemoteCallbackFreer", + &electron::RemoteCallbackFreer::BindTo); dict.SetMethod("setRemoteObjectFreer", &electron::RemoteObjectFreer::BindTo); dict.SetMethod("addRemoteObjectRef", &electron::RemoteObjectFreer::AddRef); dict.SetMethod("createIDWeakMap", diff --git a/shell/common/native_mate_converters/accelerator_converter.cc b/shell/common/gin_converters/accelerator_converter.cc similarity index 83% rename from shell/common/native_mate_converters/accelerator_converter.cc rename to shell/common/gin_converters/accelerator_converter.cc index 7b33caca06..4d883ae8a3 100644 --- a/shell/common/native_mate_converters/accelerator_converter.cc +++ b/shell/common/gin_converters/accelerator_converter.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#include "shell/common/native_mate_converters/accelerator_converter.h" +#include "shell/common/gin_converters/accelerator_converter.h" #include #include "shell/browser/ui/accelerator_util.h" -namespace mate { +namespace gin { // static bool Converter::FromV8(v8::Isolate* isolate, @@ -20,4 +20,4 @@ bool Converter::FromV8(v8::Isolate* isolate, return accelerator_util::StringToAccelerator(keycode, out); } -} // namespace mate +} // namespace gin diff --git a/shell/common/native_mate_converters/accelerator_converter.h b/shell/common/gin_converters/accelerator_converter.h similarity index 56% rename from shell/common/native_mate_converters/accelerator_converter.h rename to shell/common/gin_converters/accelerator_converter.h index 89251c29b5..6c2131e298 100644 --- a/shell/common/native_mate_converters/accelerator_converter.h +++ b/shell/common/gin_converters/accelerator_converter.h @@ -2,16 +2,16 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_ACCELERATOR_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_ACCELERATOR_CONVERTER_H_ +#ifndef SHELL_COMMON_GIN_CONVERTERS_ACCELERATOR_CONVERTER_H_ +#define SHELL_COMMON_GIN_CONVERTERS_ACCELERATOR_CONVERTER_H_ -#include "native_mate/converter.h" +#include "gin/converter.h" namespace ui { class Accelerator; } -namespace mate { +namespace gin { template <> struct Converter { @@ -20,6 +20,6 @@ struct Converter { ui::Accelerator* out); }; -} // namespace mate +} // namespace gin -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_ACCELERATOR_CONVERTER_H_ +#endif // SHELL_COMMON_GIN_CONVERTERS_ACCELERATOR_CONVERTER_H_ diff --git a/shell/common/gin_converters/blink_converter_gin_adapter.h b/shell/common/gin_converters/blink_converter_gin_adapter.h index 4776cb4f26..e0ca6a21df 100644 --- a/shell/common/gin_converters/blink_converter_gin_adapter.h +++ b/shell/common/gin_converters/blink_converter_gin_adapter.h @@ -12,6 +12,15 @@ namespace gin { +template <> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + blink::WebKeyboardEvent* out) { + return mate::ConvertFromV8(isolate, val, out); + } +}; + template <> struct Converter { static bool FromV8(v8::Isolate* isolate, @@ -25,6 +34,46 @@ struct Converter { } }; +template <> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + blink::WebDeviceEmulationParams* out) { + return mate::ConvertFromV8(isolate, val, out); + } +}; + +template <> +struct Converter { + static v8::Local ToV8( + v8::Isolate* isolate, + const blink::WebContextMenuData::MediaType& in) { + return mate::ConvertToV8(isolate, in); + } +}; + +template <> +struct Converter { + static v8::Local ToV8( + v8::Isolate* isolate, + const blink::WebContextMenuData::InputFieldType& in) { + return mate::ConvertToV8(isolate, in); + } +}; + +template <> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + const network::mojom::ReferrerPolicy& in) { + return mate::ConvertToV8(isolate, in); + } + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + network::mojom::ReferrerPolicy* out) { + return mate::ConvertFromV8(isolate, val, out); + } +}; + } // namespace gin #endif // SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_GIN_ADAPTER_H_ diff --git a/shell/common/native_mate_converters/content_converter.cc b/shell/common/gin_converters/content_converter.cc similarity index 71% rename from shell/common/native_mate_converters/content_converter.cc rename to shell/common/gin_converters/content_converter.cc index c07c801492..0161a5112f 100644 --- a/shell/common/native_mate_converters/content_converter.cc +++ b/shell/common/gin_converters/content_converter.cc @@ -2,22 +2,22 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#include "shell/common/native_mate_converters/content_converter.h" +#include "shell/common/gin_converters/content_converter.h" #include #include +#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/web_contents.h" #include "content/public/common/context_menu_params.h" -#include "native_mate/dictionary.h" #include "shell/browser/api/atom_api_web_contents.h" #include "shell/browser/web_contents_permission_helper.h" -#include "shell/common/native_mate_converters/blink_converter.h" -#include "shell/common/native_mate_converters/callback_converter_deprecated.h" -#include "shell/common/native_mate_converters/gurl_converter.h" -#include "shell/common/native_mate_converters/string16_converter.h" -#include "shell/common/native_mate_converters/ui_base_types_converter.h" -#include "shell/common/native_mate_converters/value_converter.h" +#include "shell/common/gin_converters/blink_converter_gin_adapter.h" +#include "shell/common/gin_converters/callback_converter.h" +#include "shell/common/gin_converters/gurl_converter.h" +#include "shell/common/gin_helper/dictionary.h" +#include "ui/events/keycodes/dom/keycode_converter.h" +#include "ui/events/keycodes/keyboard_code_conversion.h" namespace { @@ -38,7 +38,7 @@ v8::Local MenuItemToV8( content::WebContents* web_contents, const content::CustomContextMenuContext& context, const content::MenuItem& item) { - mate::Dictionary v8_item = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary v8_item = gin::Dictionary::CreateEmpty(isolate); switch (item.type) { case content::MenuItem::CHECKABLE_OPTION: case content::MenuItem::GROUP: @@ -69,12 +69,31 @@ v8::Local MenuToV8(v8::Isolate* isolate, v8_menu.reserve(menu.size()); for (const auto& menu_item : menu) v8_menu.push_back(MenuItemToV8(isolate, web_contents, context, menu_item)); - return mate::ConvertToV8(isolate, v8_menu); + return gin::ConvertToV8(isolate, v8_menu); } } // namespace -namespace mate { +namespace gin { + +template <> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + const ui::MenuSourceType& in) { + switch (in) { + case ui::MENU_SOURCE_MOUSE: + return StringToV8(isolate, "mouse"); + case ui::MENU_SOURCE_KEYBOARD: + return StringToV8(isolate, "keyboard"); + case ui::MENU_SOURCE_TOUCH: + return StringToV8(isolate, "touch"); + case ui::MENU_SOURCE_TOUCH_EDIT_MENU: + return StringToV8(isolate, "touchMenu"); + default: + return StringToV8(isolate, "none"); + } + } +}; // static v8::Local Converter::ToV8( @@ -100,7 +119,7 @@ v8::Local Converter::ToV8( v8::Isolate* isolate, const ContextMenuParamsWithWebContents& val) { const auto& params = val.first; - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); dict.Set("x", params.x); dict.Set("y", params.y); dict.Set("linkURL", params.link_url); @@ -109,13 +128,13 @@ v8::Local Converter::ToV8( dict.Set("frameURL", params.frame_url); dict.Set("srcURL", params.src_url); dict.Set("mediaType", params.media_type); - dict.Set("mediaFlags", MediaFlagsToV8(isolate, params.media_flags)); + dict.Set("mediaFlags", mate::MediaFlagsToV8(isolate, params.media_flags)); bool has_image_contents = (params.media_type == blink::WebContextMenuData::kMediaTypeImage) && params.has_image_contents; dict.Set("hasImageContents", has_image_contents); dict.Set("isEditable", params.is_editable); - dict.Set("editFlags", EditFlagsToV8(isolate, params.edit_flags)); + dict.Set("editFlags", mate::EditFlagsToV8(isolate, params.edit_flags)); dict.Set("selectionText", params.selection_text); dict.Set("titleText", params.title_text); dict.Set("misspelledWord", params.misspelled_word); @@ -126,7 +145,7 @@ v8::Local Converter::ToV8( if (params.custom_context.is_pepper_menu) dict.Set("menu", MenuToV8(isolate, val.second, params.custom_context, params.custom_items)); - return mate::ConvertToV8(isolate, dict); + return gin::ConvertToV8(isolate, dict); } // static @@ -215,7 +234,7 @@ bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, content::WebContents** out) { electron::api::WebContents* web_contents = nullptr; - if (!ConvertFromV8(isolate, val, &web_contents) || !web_contents) + if (!gin::ConvertFromV8(isolate, val, &web_contents) || !web_contents) return false; *out = web_contents->web_contents(); @@ -226,17 +245,17 @@ bool Converter::FromV8(v8::Isolate* isolate, v8::Local Converter::ToV8( v8::Isolate* isolate, const content::Referrer& val) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); dict.Set("url", ConvertToV8(isolate, val.url)); dict.Set("policy", ConvertToV8(isolate, val.policy)); - return mate::ConvertToV8(isolate, dict); + return gin::ConvertToV8(isolate, dict); } // static bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, content::Referrer* out) { - mate::Dictionary dict; + gin_helper::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; @@ -249,4 +268,42 @@ bool Converter::FromV8(v8::Isolate* isolate, return true; } -} // namespace mate +// static +bool Converter::FromV8( + v8::Isolate* isolate, + v8::Local val, + content::NativeWebKeyboardEvent* out) { + gin_helper::Dictionary dict; + if (!ConvertFromV8(isolate, val, &dict)) + return false; + if (!ConvertFromV8(isolate, val, static_cast(out))) + return false; + dict.Get("skipInBrowser", &out->skip_in_browser); + return true; +} + +// static +v8::Local Converter::ToV8( + v8::Isolate* isolate, + const content::NativeWebKeyboardEvent& in) { + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); + + if (in.GetType() == blink::WebInputEvent::Type::kRawKeyDown) + dict.Set("type", "keyDown"); + else if (in.GetType() == blink::WebInputEvent::Type::kKeyUp) + dict.Set("type", "keyUp"); + dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.dom_key)); + dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString( + static_cast(in.dom_code))); + + using Modifiers = blink::WebInputEvent::Modifiers; + dict.Set("isAutoRepeat", (in.GetModifiers() & Modifiers::kIsAutoRepeat) != 0); + dict.Set("shift", (in.GetModifiers() & Modifiers::kShiftKey) != 0); + dict.Set("control", (in.GetModifiers() & Modifiers::kControlKey) != 0); + dict.Set("alt", (in.GetModifiers() & Modifiers::kAltKey) != 0); + dict.Set("meta", (in.GetModifiers() & Modifiers::kMetaKey) != 0); + + return dict.GetHandle(); +} + +} // namespace gin diff --git a/shell/common/native_mate_converters/content_converter.h b/shell/common/gin_converters/content_converter.h similarity index 78% rename from shell/common/native_mate_converters/content_converter.h rename to shell/common/gin_converters/content_converter.h index 86adb092cd..ed1f0fae08 100644 --- a/shell/common/native_mate_converters/content_converter.h +++ b/shell/common/gin_converters/content_converter.h @@ -2,8 +2,8 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_CONTENT_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_CONTENT_CONVERTER_H_ +#ifndef SHELL_COMMON_GIN_CONVERTERS_CONTENT_CONVERTER_H_ +#define SHELL_COMMON_GIN_CONVERTERS_CONTENT_CONVERTER_H_ #include @@ -11,18 +11,19 @@ #include "content/public/common/menu_item.h" #include "content/public/common/referrer.h" #include "content/public/common/stop_find_action.h" -#include "native_mate/converter.h" +#include "gin/converter.h" #include "third_party/blink/public/mojom/permissions/permission_status.mojom.h" namespace content { struct ContextMenuParams; +struct NativeWebKeyboardEvent; class WebContents; } // namespace content using ContextMenuParamsWithWebContents = std::pair; -namespace mate { +namespace gin { template <> struct Converter { @@ -74,6 +75,15 @@ struct Converter { content::Referrer* out); }; -} // namespace mate +template <> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + content::NativeWebKeyboardEvent* out); + static v8::Local ToV8(v8::Isolate* isolate, + const content::NativeWebKeyboardEvent& in); +}; -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_CONTENT_CONVERTER_H_ +} // namespace gin + +#endif // SHELL_COMMON_GIN_CONVERTERS_CONTENT_CONVERTER_H_ diff --git a/shell/common/gin_converters/image_converter.cc b/shell/common/gin_converters/image_converter.cc index 78bcfa96bc..46477bb4d4 100644 --- a/shell/common/gin_converters/image_converter.cc +++ b/shell/common/gin_converters/image_converter.cc @@ -27,9 +27,8 @@ bool Converter::FromV8(v8::Isolate* isolate, if (val->IsNull()) return true; - // TODO(deermichel): remove mate:: after dropping mate - mate::Handle native_image; - if (!mate::ConvertFromV8(isolate, val, &native_image)) + gin::Handle native_image; + if (!gin::ConvertFromV8(isolate, val, &native_image)) return false; *out = native_image->image(); @@ -38,7 +37,8 @@ bool Converter::FromV8(v8::Isolate* isolate, v8::Local Converter::ToV8(v8::Isolate* isolate, const gfx::Image& val) { - return ConvertToV8(isolate, electron::api::NativeImage::Create(isolate, val)); + return gin::ConvertToV8(isolate, + electron::api::NativeImage::Create(isolate, val)); } } // namespace gin diff --git a/shell/common/gin_converters/net_converter.cc b/shell/common/gin_converters/net_converter.cc index 4369406a84..27551c6b5e 100644 --- a/shell/common/gin_converters/net_converter.cc +++ b/shell/common/gin_converters/net_converter.cc @@ -285,6 +285,58 @@ v8::Local Converter::ToV8( return arr; } +// static +v8::Local +Converter>::ToV8( + v8::Isolate* isolate, + const scoped_refptr& val) { + if (!val) + return v8::Null(isolate); + return ConvertToV8(isolate, *val); +} + +// static +bool Converter>::FromV8( + v8::Isolate* isolate, + v8::Local val, + scoped_refptr* out) { + auto list = std::make_unique(); + if (!ConvertFromV8(isolate, val, list.get())) + return false; + *out = new network::ResourceRequestBody(); + for (size_t i = 0; i < list->GetSize(); ++i) { + base::DictionaryValue* dict = nullptr; + std::string type; + if (!list->GetDictionary(i, &dict)) + return false; + dict->GetString("type", &type); + if (type == "rawData") { + base::Value* bytes = nullptr; + dict->GetBinary("bytes", &bytes); + (*out)->AppendBytes( + reinterpret_cast(bytes->GetBlob().data()), + base::checked_cast(bytes->GetBlob().size())); + } else if (type == "file") { + std::string file; + int offset = 0, length = -1; + double modification_time = 0.0; + dict->GetStringWithoutPathExpansion("filePath", &file); + dict->GetInteger("offset", &offset); + dict->GetInteger("file", &length); + dict->GetDouble("modificationTime", &modification_time); + (*out)->AppendFileRange(base::FilePath::FromUTF8Unsafe(file), + static_cast(offset), + static_cast(length), + base::Time::FromDoubleT(modification_time)); + } else if (type == "blob") { + std::string uuid; + dict->GetString("blobUUID", &uuid); + (*out)->AppendBlob(uuid); + } + } + return true; +} + // static v8::Local Converter::ToV8( v8::Isolate* isolate, diff --git a/shell/common/gin_converters/net_converter.h b/shell/common/gin_converters/net_converter.h index aad273f9cf..b506584299 100644 --- a/shell/common/gin_converters/net_converter.h +++ b/shell/common/gin_converters/net_converter.h @@ -75,6 +75,16 @@ struct Converter { const network::ResourceRequestBody& val); }; +template <> +struct Converter> { + static v8::Local ToV8( + v8::Isolate* isolate, + const scoped_refptr& val); + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + scoped_refptr* out); +}; + template <> struct Converter { static v8::Local ToV8(v8::Isolate* isolate, diff --git a/shell/common/gin_converters/std_converter.h b/shell/common/gin_converters/std_converter.h index 9e58c25078..7a4240b621 100644 --- a/shell/common/gin_converters/std_converter.h +++ b/shell/common/gin_converters/std_converter.h @@ -39,6 +39,13 @@ struct Converter { // NOLINT(runtime/int) }; #endif +template <> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, std::nullptr_t val) { + return v8::Null(isolate); + } +}; + template <> struct Converter { static v8::Local ToV8(v8::Isolate* isolate, const char* val) { diff --git a/shell/common/gin_helper/event_emitter.cc b/shell/common/gin_helper/event_emitter.cc index 4f86c32a8e..596a81b811 100644 --- a/shell/common/gin_helper/event_emitter.cc +++ b/shell/common/gin_helper/event_emitter.cc @@ -4,6 +4,8 @@ #include "shell/common/gin_helper/event_emitter.h" +#include "content/public/browser/render_frame_host.h" +#include "shell/browser/api/event.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" #include "ui/events/event_constants.h" @@ -62,6 +64,30 @@ v8::Local CreateEventFromFlags(v8::Isolate* isolate, int flags) { return obj.GetHandle(); } +v8::Local CreateNativeEvent( + v8::Isolate* isolate, + v8::Local sender, + content::RenderFrameHost* frame, + base::Optional + callback) { + v8::Local event; + if (frame && callback) { + mate::Handle native_event = mate::Event::Create(isolate); + native_event->SetCallback(std::move(callback)); + event = v8::Local::Cast(native_event.ToV8()); + } else { + // No need to create native event if we do not need to send reply. + event = CreateEvent(isolate); + } + + Dictionary dict(isolate, event); + dict.Set("sender", sender); + // Should always set frameId even when callback is null. + if (frame) + dict.Set("frameId", frame->GetRoutingID()); + return event; +} + } // namespace internal } // namespace gin_helper diff --git a/shell/common/gin_helper/event_emitter.h b/shell/common/gin_helper/event_emitter.h index c71c1ebb29..3213c339bc 100644 --- a/shell/common/gin_helper/event_emitter.h +++ b/shell/common/gin_helper/event_emitter.h @@ -9,9 +9,15 @@ #include #include "base/optional.h" +#include "content/public/browser/browser_thread.h" #include "electron/shell/common/api/api.mojom.h" +#include "native_mate/wrappable.h" #include "shell/common/gin_helper/event_emitter_caller.h" +namespace content { +class RenderFrameHost; +} + namespace gin_helper { namespace internal { @@ -21,16 +27,21 @@ v8::Local CreateEvent( v8::Local sender = v8::Local(), v8::Local custom_event = v8::Local()); v8::Local CreateEventFromFlags(v8::Isolate* isolate, int flags); +v8::Local CreateNativeEvent( + v8::Isolate* isolate, + v8::Local sender, + content::RenderFrameHost* frame, + base::Optional + callback); } // namespace internal // Provide helperers to emit event in JavaScript. -// -// TODO(zcbenz): Inherit from Wrappable directly after removing native_mate. -template -class EventEmitter : public Base { +template +class EventEmitter : public mate::Wrappable { public: - typedef std::vector> ValueArray; + using Base = mate::Wrappable; + using ValueArray = std::vector>; // Make the convinient methods visible: // https://isocpp.org/wiki/faq/templates#nondependent-name-lookup-members @@ -64,13 +75,30 @@ class EventEmitter : public Base { v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); v8::Local wrapper = GetWrapper(); - if (wrapper.IsEmpty()) { + if (wrapper.IsEmpty()) return false; - } v8::Local event = internal::CreateEvent(isolate(), wrapper); return EmitWithEvent(name, event, std::forward(args)...); } + // this.emit(name, new Event(sender, message), args...); + template + bool EmitWithSender( + base::StringPiece name, + content::RenderFrameHost* sender, + base::Optional callback, + Args&&... args) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + v8::Locker locker(isolate()); + v8::HandleScope handle_scope(isolate()); + v8::Local wrapper = GetWrapper(); + if (wrapper.IsEmpty()) + return false; + v8::Local event = internal::CreateNativeEvent( + isolate(), wrapper, sender, std::move(callback)); + return EmitWithEvent(name, event, std::forward(args)...); + } + protected: EventEmitter() {} diff --git a/shell/browser/api/trackable_object.cc b/shell/common/gin_helper/trackable_object.cc similarity index 83% rename from shell/browser/api/trackable_object.cc rename to shell/common/gin_helper/trackable_object.cc index 62a9af2c66..61297b269a 100644 --- a/shell/browser/api/trackable_object.cc +++ b/shell/common/gin_helper/trackable_object.cc @@ -2,15 +2,16 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#include "shell/browser/api/trackable_object.h" +#include "shell/common/gin_helper/trackable_object.h" #include #include "base/bind.h" #include "base/supports_user_data.h" #include "shell/browser/atom_browser_main_parts.h" +#include "shell/common/api/locker.h" -namespace mate { +namespace gin_helper { namespace { @@ -31,6 +32,10 @@ class IDUserData : public base::SupportsUserData::Data { } // namespace TrackableObjectBase::TrackableObjectBase() : weak_factory_(this) { + // TODO(zcbenz): Make TrackedObject work in renderer process. + DCHECK(mate::Locker::IsBrowserProcess()) + << "This class only works for browser process"; + electron::AtomBrowserMainParts::Get()->RegisterDestructionCallback( GetDestroyClosure()); } @@ -63,4 +68,4 @@ int32_t TrackableObjectBase::GetIDFromWrappedClass( return 0; } -} // namespace mate +} // namespace gin_helper diff --git a/shell/browser/api/trackable_object.h b/shell/common/gin_helper/trackable_object.h similarity index 76% rename from shell/browser/api/trackable_object.h rename to shell/common/gin_helper/trackable_object.h index 307fef7b3d..87fb5eef9d 100644 --- a/shell/browser/api/trackable_object.h +++ b/shell/common/gin_helper/trackable_object.h @@ -2,22 +2,21 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#ifndef SHELL_BROWSER_API_TRACKABLE_OBJECT_H_ -#define SHELL_BROWSER_API_TRACKABLE_OBJECT_H_ +#ifndef SHELL_COMMON_GIN_HELPER_TRACKABLE_OBJECT_H_ +#define SHELL_COMMON_GIN_HELPER_TRACKABLE_OBJECT_H_ #include #include "base/bind.h" #include "base/memory/weak_ptr.h" -#include "native_mate/object_template_builder_deprecated.h" -#include "shell/browser/api/event_emitter_deprecated.h" +#include "shell/common/gin_helper/event_emitter.h" #include "shell/common/key_weak_map.h" namespace base { class SupportsUserData; } -namespace mate { +namespace gin_helper { // Users should use TrackableObject instead. class TrackableObjectBase { @@ -51,21 +50,19 @@ class TrackableObjectBase { // All instances of TrackableObject will be kept in a weak map and can be got // from its ID. -// -// TODO(zcbenz): Remove "typename B" after removing native_mate. -template > -class TrackableObject : public TrackableObjectBase, public B { +template +class TrackableObject : public TrackableObjectBase, public EventEmitter { public: // Mark the JS object as destroyed. void MarkDestroyed() { - v8::Local wrapper = Wrappable::GetWrapper(); + v8::Local wrapper = mate::Wrappable::GetWrapper(); if (!wrapper.IsEmpty()) { wrapper->SetAlignedPointerInInternalField(0, nullptr); } } bool IsDestroyed() { - v8::Local wrapper = Wrappable::GetWrapper(); + v8::Local wrapper = mate::Wrappable::GetWrapper(); return wrapper->InternalFieldCount() == 0 || wrapper->GetAlignedPointerFromInternalField(0) == nullptr; } @@ -80,7 +77,7 @@ class TrackableObject : public TrackableObjectBase, public B { return nullptr; T* self = nullptr; - mate::ConvertFromV8(isolate, object.ToLocalChecked(), &self); + gin::ConvertFromV8(isolate, object.ToLocalChecked(), &self); return self; } @@ -113,7 +110,7 @@ class TrackableObject : public TrackableObjectBase, public B { ~TrackableObject() override { RemoveFromWeakMap(); } void InitWith(v8::Isolate* isolate, v8::Local wrapper) override { - WrappableBase::InitWith(isolate, wrapper); + mate::WrappableBase::InitWith(isolate, wrapper); if (!weak_map_) { weak_map_ = new electron::KeyWeakMap; } @@ -127,12 +124,12 @@ class TrackableObject : public TrackableObjectBase, public B { DISALLOW_COPY_AND_ASSIGN(TrackableObject); }; -template -int32_t TrackableObject::next_id_ = 0; +template +int32_t TrackableObject::next_id_ = 0; -template -electron::KeyWeakMap* TrackableObject::weak_map_ = nullptr; +template +electron::KeyWeakMap* TrackableObject::weak_map_ = nullptr; -} // namespace mate +} // namespace gin_helper -#endif // SHELL_BROWSER_API_TRACKABLE_OBJECT_H_ +#endif // SHELL_COMMON_GIN_HELPER_TRACKABLE_OBJECT_H_ diff --git a/shell/common/native_mate_converters/blink_converter.cc b/shell/common/native_mate_converters/blink_converter.cc index 4d915809eb..42a2b77168 100644 --- a/shell/common/native_mate_converters/blink_converter.cc +++ b/shell/common/native_mate_converters/blink_converter.cc @@ -11,7 +11,6 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" -#include "content/public/browser/native_web_keyboard_event.h" #include "gin/converter.h" #include "mojo/public/cpp/base/values_mojom_traits.h" #include "mojo/public/mojom/base/values.mojom.h" @@ -20,6 +19,7 @@ #include "shell/common/keyboard_util.h" #include "shell/common/native_mate_converters/value_converter.h" #include "third_party/blink/public/platform/web_input_event.h" +#include "third_party/blink/public/platform/web_keyboard_event.h" #include "third_party/blink/public/platform/web_mouse_event.h" #include "third_party/blink/public/platform/web_mouse_wheel_event.h" #include "third_party/blink/public/web/web_device_emulation_params.h" @@ -216,42 +216,6 @@ bool Converter::FromV8(v8::Isolate* isolate, return true; } -bool Converter::FromV8( - v8::Isolate* isolate, - v8::Local val, - content::NativeWebKeyboardEvent* out) { - mate::Dictionary dict; - if (!ConvertFromV8(isolate, val, &dict)) - return false; - if (!ConvertFromV8(isolate, val, static_cast(out))) - return false; - dict.Get("skipInBrowser", &out->skip_in_browser); - return true; -} - -v8::Local Converter::ToV8( - v8::Isolate* isolate, - const content::NativeWebKeyboardEvent& in) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); - - if (in.GetType() == blink::WebInputEvent::Type::kRawKeyDown) - dict.Set("type", "keyDown"); - else if (in.GetType() == blink::WebInputEvent::Type::kKeyUp) - dict.Set("type", "keyUp"); - dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.dom_key)); - dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString( - static_cast(in.dom_code))); - - using Modifiers = blink::WebInputEvent::Modifiers; - dict.Set("isAutoRepeat", (in.GetModifiers() & Modifiers::kIsAutoRepeat) != 0); - dict.Set("shift", (in.GetModifiers() & Modifiers::kShiftKey) != 0); - dict.Set("control", (in.GetModifiers() & Modifiers::kControlKey) != 0); - dict.Set("alt", (in.GetModifiers() & Modifiers::kAltKey) != 0); - dict.Set("meta", (in.GetModifiers() & Modifiers::kMetaKey) != 0); - - return dict.GetHandle(); -} - bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, blink::WebMouseEvent* out) { diff --git a/shell/common/native_mate_converters/blink_converter.h b/shell/common/native_mate_converters/blink_converter.h index 60d2a323d8..2f8e418e55 100644 --- a/shell/common/native_mate_converters/blink_converter.h +++ b/shell/common/native_mate_converters/blink_converter.h @@ -21,10 +21,6 @@ struct WebPoint; struct WebSize; } // namespace blink -namespace content { -struct NativeWebKeyboardEvent; -} - namespace mate { blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate, @@ -44,15 +40,6 @@ struct Converter { blink::WebKeyboardEvent* out); }; -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - content::NativeWebKeyboardEvent* out); - static v8::Local ToV8(v8::Isolate* isolate, - const content::NativeWebKeyboardEvent& in); -}; - template <> struct Converter { static bool FromV8(v8::Isolate* isolate, diff --git a/shell/common/native_mate_converters/network_converter.cc b/shell/common/native_mate_converters/network_converter.cc deleted file mode 100644 index d9ed0e0494..0000000000 --- a/shell/common/native_mate_converters/network_converter.cc +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2018 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "shell/common/native_mate_converters/network_converter.h" - -#include -#include -#include -#include - -#include "base/numerics/safe_conversions.h" -#include "native_mate/dictionary.h" -#include "services/network/public/cpp/resource_request_body.h" -#include "shell/common/native_mate_converters/value_converter.h" - -namespace mate { - -// static -v8::Local -Converter>::ToV8( - v8::Isolate* isolate, - const scoped_refptr& val) { - if (!val) - return v8::Null(isolate); - auto list = std::make_unique(); - for (const auto& element : *(val->elements())) { - auto post_data_dict = std::make_unique(); - auto type = element.type(); - if (type == network::mojom::DataElementType::kBytes) { - auto bytes = std::make_unique(std::vector( - element.bytes(), element.bytes() + (element.length()))); - post_data_dict->SetString("type", "rawData"); - post_data_dict->Set("bytes", std::move(bytes)); - } else if (type == network::mojom::DataElementType::kFile) { - post_data_dict->SetString("type", "file"); - post_data_dict->SetKey("filePath", - base::Value(element.path().AsUTF8Unsafe())); - post_data_dict->SetInteger("offset", static_cast(element.offset())); - post_data_dict->SetInteger("length", static_cast(element.length())); - post_data_dict->SetDouble( - "modificationTime", element.expected_modification_time().ToDoubleT()); - } else if (type == network::mojom::DataElementType::kBlob) { - post_data_dict->SetString("type", "blob"); - post_data_dict->SetString("blobUUID", element.blob_uuid()); - } - list->Append(std::move(post_data_dict)); - } - return ConvertToV8(isolate, *list); -} - -// static -bool Converter>::FromV8( - v8::Isolate* isolate, - v8::Local val, - scoped_refptr* out) { - auto list = std::make_unique(); - if (!ConvertFromV8(isolate, val, list.get())) - return false; - *out = new network::ResourceRequestBody(); - for (size_t i = 0; i < list->GetSize(); ++i) { - base::DictionaryValue* dict = nullptr; - std::string type; - if (!list->GetDictionary(i, &dict)) - return false; - dict->GetString("type", &type); - if (type == "rawData") { - base::Value* bytes = nullptr; - dict->GetBinary("bytes", &bytes); - (*out)->AppendBytes( - reinterpret_cast(bytes->GetBlob().data()), - base::checked_cast(bytes->GetBlob().size())); - } else if (type == "file") { - std::string file; - int offset = 0, length = -1; - double modification_time = 0.0; - dict->GetStringWithoutPathExpansion("filePath", &file); - dict->GetInteger("offset", &offset); - dict->GetInteger("file", &length); - dict->GetDouble("modificationTime", &modification_time); - (*out)->AppendFileRange(base::FilePath::FromUTF8Unsafe(file), - static_cast(offset), - static_cast(length), - base::Time::FromDoubleT(modification_time)); - } else if (type == "blob") { - std::string uuid; - dict->GetString("blobUUID", &uuid); - (*out)->AppendBlob(uuid); - } - } - return true; -} - -} // namespace mate diff --git a/shell/common/native_mate_converters/network_converter.h b/shell/common/native_mate_converters/network_converter.h deleted file mode 100644 index 13a82db6d6..0000000000 --- a/shell/common/native_mate_converters/network_converter.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2018 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_NETWORK_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_NETWORK_CONVERTER_H_ - -#include "base/memory/scoped_refptr.h" -#include "native_mate/converter.h" - -namespace network { -class ResourceRequestBody; -} - -namespace mate { - -template <> -struct Converter> { - static v8::Local ToV8( - v8::Isolate* isolate, - const scoped_refptr& val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - scoped_refptr* out); -}; - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_NETWORK_CONVERTER_H_ diff --git a/shell/common/native_mate_converters/ui_base_types_converter.h b/shell/common/native_mate_converters/ui_base_types_converter.h deleted file mode 100644 index a762ea7495..0000000000 --- a/shell/common/native_mate_converters/ui_base_types_converter.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2016 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_UI_BASE_TYPES_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_UI_BASE_TYPES_CONVERTER_H_ - -#include "native_mate/converter.h" -#include "ui/base/ui_base_types.h" - -namespace mate { - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const ui::MenuSourceType& in) { - switch (in) { - case ui::MENU_SOURCE_MOUSE: - return mate::StringToV8(isolate, "mouse"); - case ui::MENU_SOURCE_KEYBOARD: - return mate::StringToV8(isolate, "keyboard"); - case ui::MENU_SOURCE_TOUCH: - return mate::StringToV8(isolate, "touch"); - case ui::MENU_SOURCE_TOUCH_EDIT_MENU: - return mate::StringToV8(isolate, "touchMenu"); - default: - return mate::StringToV8(isolate, "none"); - } - } -}; - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_UI_BASE_TYPES_CONVERTER_H_ diff --git a/spec-main/api-web-contents-spec.ts b/spec-main/api-web-contents-spec.ts index 9ac84deff1..6649d44cf0 100644 --- a/spec-main/api-web-contents-spec.ts +++ b/spec-main/api-web-contents-spec.ts @@ -689,13 +689,11 @@ describe('webContents module', () => { expect(() => { w.webContents.startDrag({ file: __filename } as any) - }).to.throw(`Must specify 'icon' option`) + }).to.throw(`Must specify non-empty 'icon' option`) - if (process.platform === 'darwin') { - expect(() => { - w.webContents.startDrag({ file: __filename, icon: __filename }) - }).to.throw(`Must specify non-empty 'icon' option`) - } + expect(() => { + w.webContents.startDrag({ file: __filename, icon: __filename }) + }).to.throw(`Must specify non-empty 'icon' option`) }) })