diff --git a/filenames.gni b/filenames.gni index f8773eef3ab..11937539229 100644 --- a/filenames.gni +++ b/filenames.gni @@ -430,11 +430,7 @@ filenames = { "shell/common/api/electron_bindings.cc", "shell/common/api/electron_bindings.h", "shell/common/api/constructor.h", - "shell/common/api/event_emitter_caller_deprecated.cc", - "shell/common/api/event_emitter_caller_deprecated.h", "shell/common/api/features.cc", - "shell/common/api/locker.cc", - "shell/common/api/locker.h", "shell/common/asar/archive.cc", "shell/common/asar/archive.h", "shell/common/asar/asar_util.cc", @@ -466,6 +462,8 @@ filenames = { "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/blink_converter.cc", + "shell/common/gin_converters/blink_converter.h", "shell/common/gin_converters/callback_converter.h", "shell/common/gin_converters/content_converter.cc", "shell/common/gin_converters/content_converter.h", @@ -483,8 +481,8 @@ filenames = { "shell/common/gin_converters/net_converter.cc", "shell/common/gin_converters/net_converter.h", "shell/common/gin_converters/std_converter.h", - "shell/common/gin_converters/blink_converter_gin_adapter.h", - "shell/common/gin_converters/value_converter_gin_adapter.h", + "shell/common/gin_converters/value_converter.cc", + "shell/common/gin_converters/value_converter.h", "shell/common/gin_helper/arguments.cc", "shell/common/gin_helper/arguments.h", "shell/common/gin_helper/callback.cc", @@ -500,8 +498,12 @@ filenames = { "shell/common/gin_helper/event_emitter.h", "shell/common/gin_helper/function_template.cc", "shell/common/gin_helper/function_template.h", + "shell/common/gin_helper/locker.cc", + "shell/common/gin_helper/locker.h", "shell/common/gin_helper/object_template_builder.cc", "shell/common/gin_helper/object_template_builder.h", + "shell/common/gin_helper/persistent_dictionary.cc", + "shell/common/gin_helper/persistent_dictionary.h", "shell/common/gin_helper/trackable_object.cc", "shell/common/gin_helper/trackable_object.h", "shell/common/heap_snapshot.cc", @@ -515,22 +517,6 @@ 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/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/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/once_callback.h", - "shell/common/native_mate_converters/string16_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", - "shell/common/native_mate_converters/value_converter.h", "shell/common/node_bindings.cc", "shell/common/node_bindings.h", "shell/common/node_bindings_linux.cc", @@ -552,6 +538,8 @@ filenames = { "shell/common/promise_util.cc", "shell/common/skia_util.h", "shell/common/skia_util.cc", + "shell/common/v8_value_converter.cc", + "shell/common/v8_value_converter.h", "shell/renderer/api/context_bridge/render_frame_context_bridge_store.cc", "shell/renderer/api/context_bridge/render_frame_context_bridge_store.h", "shell/renderer/api/atom_api_context_bridge.cc", diff --git a/native_mate/BUILD.gn b/native_mate/BUILD.gn index 26dde6b20ef..f6bc5ac5407 100644 --- a/native_mate/BUILD.gn +++ b/native_mate/BUILD.gn @@ -25,9 +25,6 @@ source_set("native_mate") { "native_mate/handle.h", "native_mate/object_template_builder.cc", "native_mate/object_template_builder_deprecated.h", - "native_mate/persistent_dictionary.cc", - "native_mate/persistent_dictionary.h", - "native_mate/scoped_persistent.h", "native_mate/wrappable.cc", "native_mate/wrappable.h", "native_mate/wrappable_base.h", diff --git a/native_mate/native_mate/dictionary.h b/native_mate/native_mate/dictionary.h index 47977effe79..412acd25a95 100644 --- a/native_mate/native_mate/dictionary.h +++ b/native_mate/native_mate/dictionary.h @@ -40,12 +40,6 @@ class Dictionary { static Dictionary CreateEmpty(v8::Isolate* isolate); - bool Has(base::StringPiece key) const { - v8::Local context = isolate_->GetCurrentContext(); - v8::Local v8_key = StringToV8(isolate_, key); - return internal::IsTrue(GetHandle()->Has(context, v8_key)); - } - template bool Get(base::StringPiece key, T* out) const { // Check for existence before getting, otherwise this method will always @@ -82,17 +76,6 @@ class Dictionary { return !result.IsNothing() && result.FromJust(); } - template - bool SetReadOnlyNonConfigurable(base::StringPiece key, T val) { - v8::Local v8_value; - if (!TryConvertToV8(isolate_, val, &v8_value)) - return false; - v8::Maybe result = GetHandle()->DefineOwnProperty( - isolate_->GetCurrentContext(), StringToV8(isolate_, key), v8_value, - static_cast(v8::ReadOnly | v8::DontDelete)); - return !result.IsNothing() && result.FromJust(); - } - template bool SetMethod(base::StringPiece key, const T& callback) { return GetHandle() diff --git a/native_mate/native_mate/persistent_dictionary.cc b/native_mate/native_mate/persistent_dictionary.cc deleted file mode 100644 index 0d2d15e2e73..00000000000 --- a/native_mate/native_mate/persistent_dictionary.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2014 Cheng Zhao. All rights reserved. -// Use of this source code is governed by MIT license that can be found in the -// LICENSE file. - -#include "native_mate/persistent_dictionary.h" - -namespace mate { - -PersistentDictionary::PersistentDictionary() = default; - -PersistentDictionary::PersistentDictionary(v8::Isolate* isolate, - v8::Local object) - : handle_(new RefCountedPersistent(isolate, object)) { - isolate_ = isolate; -} - -PersistentDictionary::PersistentDictionary(const PersistentDictionary& other) = - default; - -PersistentDictionary::~PersistentDictionary() = default; - -v8::Local PersistentDictionary::GetHandle() const { - return handle_->NewHandle(); -} - -bool Converter::FromV8(v8::Isolate* isolate, - v8::Local val, - PersistentDictionary* out) { - if (!val->IsObject()) - return false; - *out = PersistentDictionary(isolate, v8::Local::Cast(val)); - return true; -} - -} // namespace mate diff --git a/native_mate/native_mate/persistent_dictionary.h b/native_mate/native_mate/persistent_dictionary.h deleted file mode 100644 index 6cf86d6c3a5..00000000000 --- a/native_mate/native_mate/persistent_dictionary.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2014 Cheng Zhao. All rights reserved. -// Use of this source code is governed by MIT license that can be found in the -// LICENSE file. - -#ifndef NATIVE_MATE_NATIVE_MATE_PERSISTENT_DICTIONARY_H_ -#define NATIVE_MATE_NATIVE_MATE_PERSISTENT_DICTIONARY_H_ - -#include "native_mate/dictionary.h" -#include "native_mate/scoped_persistent.h" - -namespace mate { - -// Like Dictionary, but stores object in persistent handle so you can keep it -// safely on heap. -class PersistentDictionary : public Dictionary { - public: - PersistentDictionary(); - PersistentDictionary(v8::Isolate* isolate, v8::Local object); - PersistentDictionary(const PersistentDictionary& other); - ~PersistentDictionary() override; - - v8::Local GetHandle() const override; - - private: - scoped_refptr> handle_; -}; - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - PersistentDictionary* out); -}; - -} // namespace mate - -namespace gin { - -// Keep compatibility with gin. -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - mate::PersistentDictionary* out) { - return mate::ConvertFromV8(isolate, val, out); - } -}; - -} // namespace gin - -#endif // NATIVE_MATE_NATIVE_MATE_PERSISTENT_DICTIONARY_H_ diff --git a/native_mate/native_mate/scoped_persistent.h b/native_mate/native_mate/scoped_persistent.h deleted file mode 100644 index 2925fa0b87c..00000000000 --- a/native_mate/native_mate/scoped_persistent.h +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2014 Cheng Zhao. All rights reserved. -// Use of this source code is governed by MIT license that can be found in the -// LICENSE file. - -#ifndef NATIVE_MATE_NATIVE_MATE_SCOPED_PERSISTENT_H_ -#define NATIVE_MATE_NATIVE_MATE_SCOPED_PERSISTENT_H_ - -#include "base/memory/ref_counted.h" -#include "native_mate/converter.h" -#include "v8/include/v8.h" - -namespace mate { - -// A v8::Persistent handle to a V8 value which destroys and clears the -// underlying handle on destruction. -template -class ScopedPersistent { - public: - ScopedPersistent() : isolate_(v8::Isolate::GetCurrent()) {} - - ScopedPersistent(v8::Isolate* isolate, v8::Local handle) - : isolate_(isolate) { - reset(isolate, v8::Local::Cast(handle)); - } - - ~ScopedPersistent() { reset(); } - - void reset(v8::Isolate* isolate, v8::Local handle) { - if (!handle.IsEmpty()) { - isolate_ = isolate; - handle_.Reset(isolate, handle); - } else { - reset(); - } - } - - void reset() { handle_.Reset(); } - - bool IsEmpty() const { return handle_.IsEmpty(); } - - v8::Local NewHandle() const { return NewHandle(isolate_); } - - v8::Local NewHandle(v8::Isolate* isolate) const { - if (handle_.IsEmpty()) - return v8::Local(); - return v8::Local::New(isolate, handle_); - } - - template - void SetWeak(P* parameter, C callback) { - handle_.SetWeak(parameter, callback); - } - - v8::Isolate* isolate() const { return isolate_; } - - private: - v8::Isolate* isolate_ = nullptr; - v8::Persistent handle_; - - DISALLOW_COPY_AND_ASSIGN(ScopedPersistent); -}; - -template -class RefCountedPersistent : public ScopedPersistent, - public base::RefCounted> { - public: - RefCountedPersistent() = default; - - RefCountedPersistent(v8::Isolate* isolate, v8::Local handle) - : ScopedPersistent(isolate, handle) {} - - protected: - friend class base::RefCounted>; - - ~RefCountedPersistent() = default; - - private: - DISALLOW_COPY_AND_ASSIGN(RefCountedPersistent); -}; - -template -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - const ScopedPersistent& val) { - return val.NewHandle(isolate); - } - - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - ScopedPersistent* out) { - v8::Local converted; - if (!Converter>::FromV8(isolate, val, &converted)) - return false; - - out->reset(isolate, converted); - return true; - } -}; - -} // namespace mate - -#endif // NATIVE_MATE_NATIVE_MATE_SCOPED_PERSISTENT_H_ diff --git a/shell/browser/api/atom_api_app.cc b/shell/browser/api/atom_api_app.cc index fe0564732d9..4dd6bd8c44f 100644 --- a/shell/browser/api/atom_api_app.cc +++ b/shell/browser/api/atom_api_app.cc @@ -48,7 +48,7 @@ #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_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" diff --git a/shell/browser/api/atom_api_browser_window.cc b/shell/browser/api/atom_api_browser_window.cc index 436c345d07b..350544dafce 100644 --- a/shell/browser/api/atom_api_browser_window.cc +++ b/shell/browser/api/atom_api_browser_window.cc @@ -18,7 +18,7 @@ #include "shell/browser/window_list.h" #include "shell/common/api/constructor.h" #include "shell/common/color_util.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" diff --git a/shell/browser/api/atom_api_content_tracing.cc b/shell/browser/api/atom_api_content_tracing.cc index e780ae2d7a0..838c8d934fc 100644 --- a/shell/browser/api/atom_api_content_tracing.cc +++ b/shell/browser/api/atom_api_content_tracing.cc @@ -6,21 +6,20 @@ #include #include -#include "base/bind.h" #include "base/files/file_util.h" #include "base/optional.h" #include "base/threading/thread_restrictions.h" #include "content/public/browser/tracing_controller.h" -#include "native_mate/dictionary.h" -#include "shell/common/native_mate_converters/callback_converter_deprecated.h" -#include "shell/common/native_mate_converters/file_path_converter.h" -#include "shell/common/native_mate_converters/value_converter.h" +#include "shell/common/gin_converters/callback_converter.h" +#include "shell/common/gin_converters/file_path_converter.h" +#include "shell/common/gin_converters/value_converter.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" #include "shell/common/promise_util.h" using content::TracingController; -namespace mate { +namespace gin { template <> struct Converter { @@ -31,7 +30,7 @@ struct Converter { // has to be checked first because none of the fields // in the `memory_dump_config` dict below are mandatory // and we cannot check the config format. - Dictionary options; + gin_helper::Dictionary options; if (ConvertFromV8(isolate, val, &options)) { std::string category_filter, trace_options; if (options.Get("categoryFilter", &category_filter) && @@ -51,7 +50,7 @@ struct Converter { } }; -} // namespace mate +} // namespace gin namespace { @@ -79,7 +78,7 @@ void StopTracing(electron::util::Promise promise, } } -v8::Local StopRecording(mate::Arguments* args) { +v8::Local StopRecording(gin_helper::Arguments* args) { electron::util::Promise promise(args->isolate()); v8::Local handle = promise.GetHandle(); @@ -131,18 +130,18 @@ v8::Local StartTracing( } void OnTraceBufferUsageAvailable( - electron::util::Promise promise, + electron::util::Promise promise, float percent_full, size_t approximate_count) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(promise.isolate()); + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate()); dict.Set("percentage", percent_full); dict.Set("value", approximate_count); - promise.Resolve(dict); + promise.ResolveWithGin(dict); } v8::Local GetTraceBufferUsage(v8::Isolate* isolate) { - electron::util::Promise promise(isolate); + electron::util::Promise promise(isolate); v8::Local handle = promise.GetHandle(); // Note: This method always succeeds. @@ -155,7 +154,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("getCategories", &GetCategories); dict.SetMethod("startRecording", &StartTracing); dict.SetMethod("stopRecording", &StopRecording); diff --git a/shell/browser/api/atom_api_cookies.cc b/shell/browser/api/atom_api_cookies.cc index 88a2c6770a6..491a1bf5e06 100644 --- a/shell/browser/api/atom_api_cookies.cc +++ b/shell/browser/api/atom_api_cookies.cc @@ -21,7 +21,7 @@ #include "shell/browser/atom_browser_context.h" #include "shell/browser/cookie_change_notifier.h" #include "shell/common/gin_converters/gurl_converter.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" diff --git a/shell/browser/api/atom_api_debugger.cc b/shell/browser/api/atom_api_debugger.cc index f4f6c91146d..bf0ffd4a627 100644 --- a/shell/browser/api/atom_api_debugger.cc +++ b/shell/browser/api/atom_api_debugger.cc @@ -12,7 +12,7 @@ #include "base/json/json_writer.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/web_contents.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" @@ -80,7 +80,7 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host, if (dict->GetDictionary("result", &result_body)) { result.Swap(result_body); } - promise.Resolve(result); + promise.ResolveWithGin(result); } } } diff --git a/shell/browser/api/atom_api_event.cc b/shell/browser/api/atom_api_event.cc index ddc92226c53..c5084fc548f 100644 --- a/shell/browser/api/atom_api_event.cc +++ b/shell/browser/api/atom_api_event.cc @@ -20,7 +20,7 @@ void Initialize(v8::Local exports, void* priv) { gin_helper::Dictionary dict(context->GetIsolate(), exports); dict.SetMethod("createWithSender", &CreateWithSender); - dict.SetMethod("createEmpty", &mate::Event::Create); + dict.SetMethod("createEmpty", &gin_helper::Event::Create); } } // namespace diff --git a/shell/browser/api/atom_api_menu.h b/shell/browser/api/atom_api_menu.h index a31b1827880..67e97aeafe2 100644 --- a/shell/browser/api/atom_api_menu.h +++ b/shell/browser/api/atom_api_menu.h @@ -12,7 +12,7 @@ #include "gin/arguments.h" #include "shell/browser/api/atom_api_top_level_window.h" #include "shell/browser/ui/atom_menu_model.h" -#include "shell/common/api/locker.h" +#include "shell/common/gin_helper/locker.h" #include "shell/common/gin_helper/trackable_object.h" namespace electron { diff --git a/shell/browser/api/atom_api_menu_mac.mm b/shell/browser/api/atom_api_menu_mac.mm index 7cda00005ad..7151c97f499 100644 --- a/shell/browser/api/atom_api_menu_mac.mm +++ b/shell/browser/api/atom_api_menu_mac.mm @@ -56,7 +56,7 @@ void MenuMac::PopupOnUI(const base::WeakPtr& native_window, int y, int positioning_item, base::Closure callback) { - mate::Locker locker(isolate()); + gin_helper::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); if (!native_window) diff --git a/shell/browser/api/atom_api_menu_views.cc b/shell/browser/api/atom_api_menu_views.cc index f2f6aa7f963..6d71cafa074 100644 --- a/shell/browser/api/atom_api_menu_views.cc +++ b/shell/browser/api/atom_api_menu_views.cc @@ -25,7 +25,7 @@ void MenuViews::PopupAt(TopLevelWindow* window, int y, int positioning_item, const base::Closure& callback) { - mate::Locker locker(isolate()); + gin_helper::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); auto* native_window = static_cast(window->window()); diff --git a/shell/browser/api/atom_api_session.cc b/shell/browser/api/atom_api_session.cc index 77ce0306ea0..424a8142def 100644 --- a/shell/browser/api/atom_api_session.cc +++ b/shell/browser/api/atom_api_session.cc @@ -57,7 +57,7 @@ #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_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" diff --git a/shell/browser/api/atom_api_system_preferences.cc b/shell/browser/api/atom_api_system_preferences.cc index 3c9230600a4..ddf946928c0 100644 --- a/shell/browser/api/atom_api_system_preferences.cc +++ b/shell/browser/api/atom_api_system_preferences.cc @@ -5,7 +5,7 @@ #include "shell/browser/api/atom_api_system_preferences.h" #include "shell/common/gin_converters/callback_converter.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" diff --git a/shell/browser/api/atom_api_system_preferences_mac.mm b/shell/browser/api/atom_api_system_preferences_mac.mm index ee5fe9f4afd..981ee4464ab 100644 --- a/shell/browser/api/atom_api_system_preferences_mac.mm +++ b/shell/browser/api/atom_api_system_preferences_mac.mm @@ -27,7 +27,7 @@ #include "shell/browser/ui/cocoa/NSColor+Hex.h" #include "shell/common/deprecate_util.h" #include "shell/common/gin_converters/gurl_converter.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "ui/native_theme/native_theme.h" namespace gin { diff --git a/shell/browser/api/atom_api_top_level_window.cc b/shell/browser/api/atom_api_top_level_window.cc index 58b314b3925..e1bbfdbf242 100644 --- a/shell/browser/api/atom_api_top_level_window.cc +++ b/shell/browser/api/atom_api_top_level_window.cc @@ -5,11 +5,11 @@ #include "shell/browser/api/atom_api_top_level_window.h" #include +#include #include #include "electron/buildflags/buildflags.h" #include "gin/dictionary.h" -#include "native_mate/persistent_dictionary.h" #include "shell/browser/api/atom_api_browser_view.h" #include "shell/browser/api/atom_api_menu.h" #include "shell/browser/api/atom_api_view.h" @@ -20,9 +20,10 @@ #include "shell/common/gin_converters/gfx_converter.h" #include "shell/common/gin_converters/image_converter.h" #include "shell/common/gin_converters/native_window_converter.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" +#include "shell/common/gin_helper/persistent_dictionary.h" #include "shell/common/node_includes.h" #include "shell/common/options_switches.h" @@ -809,8 +810,8 @@ void TopLevelWindow::SetVibrancy(v8::Isolate* isolate, } void TopLevelWindow::SetTouchBar( - const std::vector& items) { - window_->SetTouchBar(items); + std::vector items) { + window_->SetTouchBar(std::move(items)); } void TopLevelWindow::RefreshTouchBarItem(const std::string& item_id) { @@ -818,8 +819,8 @@ void TopLevelWindow::RefreshTouchBarItem(const std::string& item_id) { } void TopLevelWindow::SetEscapeTouchBarItem( - const mate::PersistentDictionary& item) { - window_->SetEscapeTouchBarItem(item); + gin_helper::PersistentDictionary item) { + window_->SetEscapeTouchBarItem(std::move(item)); } void TopLevelWindow::SelectPreviousTab() { diff --git a/shell/browser/api/atom_api_top_level_window.h b/shell/browser/api/atom_api_top_level_window.h index c3e28cba201..d89b0ee2ba0 100644 --- a/shell/browser/api/atom_api_top_level_window.h +++ b/shell/browser/api/atom_api_top_level_window.h @@ -184,9 +184,9 @@ class TopLevelWindow : public gin_helper::TrackableObject, bool IsVisibleOnAllWorkspaces(); void SetAutoHideCursor(bool auto_hide); virtual void SetVibrancy(v8::Isolate* isolate, v8::Local value); - void SetTouchBar(const std::vector& items); + void SetTouchBar(std::vector items); void RefreshTouchBarItem(const std::string& item_id); - void SetEscapeTouchBarItem(const mate::PersistentDictionary& item); + void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item); void SelectPreviousTab(); void SelectNextTab(); void MergeAllWindows(); diff --git a/shell/browser/api/atom_api_web_contents.cc b/shell/browser/api/atom_api_web_contents.cc index 3d0275ea4af..2bf6b11934a 100644 --- a/shell/browser/api/atom_api_web_contents.cc +++ b/shell/browser/api/atom_api_web_contents.cc @@ -70,7 +70,7 @@ #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/blink_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" @@ -78,7 +78,7 @@ #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_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/mouse_util.h" @@ -1023,7 +1023,7 @@ void WebContents::Message(bool internal, blink::CloneableMessage arguments) { // webContents.emit('-ipc-message', new Event(), internal, channel, // arguments); - EmitWithSender("-ipc-message", bindings_.dispatch_context(), base::nullopt, + EmitWithSender("-ipc-message", bindings_.dispatch_context(), InvokeCallback(), internal, channel, std::move(arguments)); } @@ -1064,7 +1064,7 @@ void WebContents::MessageHost(const std::string& channel, blink::CloneableMessage arguments) { // webContents.emit('ipc-message-host', new Event(), channel, args); EmitWithSender("ipc-message-host", bindings_.dispatch_context(), - base::nullopt, channel, std::move(arguments)); + InvokeCallback(), channel, std::move(arguments)); } #if BUILDFLAG(ENABLE_REMOTE_MODULE) @@ -1075,7 +1075,7 @@ void WebContents::DereferenceRemoteJSObject(const std::string& context_id, args.Append(context_id); args.Append(object_id); args.Append(ref_count); - EmitWithSender("-ipc-message", bindings_.dispatch_context(), base::nullopt, + EmitWithSender("-ipc-message", bindings_.dispatch_context(), InvokeCallback(), /* internal */ true, "ELECTRON_BROWSER_DEREFERENCE", std::move(args)); } @@ -2071,10 +2071,10 @@ void WebContents::SendInputEvent(v8::Isolate* isolate, content::RenderWidgetHost* rwh = view->GetRenderWidgetHost(); blink::WebInputEvent::Type type = - mate::GetWebInputEventType(isolate, input_event); + gin::GetWebInputEventType(isolate, input_event); if (blink::WebInputEvent::IsMouseEventType(type)) { blink::WebMouseEvent mouse_event; - if (mate::ConvertFromV8(isolate, input_event, &mouse_event)) { + if (gin::ConvertFromV8(isolate, input_event, &mouse_event)) { if (IsOffScreen()) { #if BUILDFLAG(ENABLE_OSR) GetOffScreenRenderWidgetHostView()->SendMouseEvent(mouse_event); @@ -2094,7 +2094,7 @@ void WebContents::SendInputEvent(v8::Isolate* isolate, } } else if (type == blink::WebInputEvent::kMouseWheel) { blink::WebMouseWheelEvent mouse_wheel_event; - if (mate::ConvertFromV8(isolate, input_event, &mouse_wheel_event)) { + if (gin::ConvertFromV8(isolate, input_event, &mouse_wheel_event)) { if (IsOffScreen()) { #if BUILDFLAG(ENABLE_OSR) GetOffScreenRenderWidgetHostView()->SendMouseWheelEvent( diff --git a/shell/browser/api/atom_api_web_request.cc b/shell/browser/api/atom_api_web_request.cc index d35dce38940..acac3564a4b 100644 --- a/shell/browser/api/atom_api_web_request.cc +++ b/shell/browser/api/atom_api_web_request.cc @@ -20,7 +20,7 @@ #include "shell/common/gin_converters/gurl_converter.h" #include "shell/common/gin_converters/net_converter.h" #include "shell/common/gin_converters/std_converter.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" namespace gin { diff --git a/shell/browser/api/atom_api_web_view_manager.cc b/shell/browser/api/atom_api_web_view_manager.cc index 3f89e636bbf..71f8082826d 100644 --- a/shell/browser/api/atom_api_web_view_manager.cc +++ b/shell/browser/api/atom_api_web_view_manager.cc @@ -7,7 +7,7 @@ #include "shell/browser/web_contents_zoom_controller.h" #include "shell/browser/web_view_manager.h" #include "shell/common/gin_converters/content_converter.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" #include "shell/common/options_switches.h" diff --git a/shell/browser/api/event.cc b/shell/browser/api/event.cc index ac17b7bdc23..da8af70d7e7 100644 --- a/shell/browser/api/event.cc +++ b/shell/browser/api/event.cc @@ -6,26 +6,26 @@ #include -#include "native_mate/object_template_builder_deprecated.h" -#include "shell/common/native_mate_converters/blink_converter.h" +#include "gin/object_template_builder.h" +#include "shell/common/gin_converters/blink_converter.h" -namespace mate { +namespace gin_helper { -Event::Event(v8::Isolate* isolate) { - Init(isolate); -} +gin::WrapperInfo Event::kWrapperInfo = {gin::kEmbedderNativeGin}; + +Event::Event() {} Event::~Event() = default; -void Event::SetCallback(base::Optional callback) { +void Event::SetCallback(InvokeCallback callback) { DCHECK(!callback_); callback_ = std::move(callback); } void Event::PreventDefault(v8::Isolate* isolate) { - GetWrapper() - ->Set(isolate->GetCurrentContext(), - StringToV8(isolate, "defaultPrevented"), v8::True(isolate)) + v8::Local self = GetWrapper(isolate).ToLocalChecked(); + self->Set(isolate->GetCurrentContext(), + gin::StringToV8(isolate, "defaultPrevented"), v8::True(isolate)) .Check(); } @@ -34,27 +34,28 @@ bool Event::SendReply(v8::Isolate* isolate, v8::Local result) { return false; blink::CloneableMessage message; - if (!ConvertFromV8(isolate, result, &message)) { + if (!gin::ConvertFromV8(isolate, result, &message)) { return false; } - std::move(*callback_).Run(std::move(message)); - callback_.reset(); + std::move(callback_).Run(std::move(message)); return true; } -// static -Handle Event::Create(v8::Isolate* isolate) { - return mate::CreateHandle(isolate, new Event(isolate)); -} - -// static -void Event::BuildPrototype(v8::Isolate* isolate, - v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "Event")); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) +gin::ObjectTemplateBuilder Event::GetObjectTemplateBuilder( + v8::Isolate* isolate) { + return gin::Wrappable::GetObjectTemplateBuilder(isolate) .SetMethod("preventDefault", &Event::PreventDefault) .SetMethod("sendReply", &Event::SendReply); } -} // namespace mate +const char* Event::GetTypeName() { + return "WebRequest"; +} + +// static +gin::Handle Event::Create(v8::Isolate* isolate) { + return gin::CreateHandle(isolate, new Event()); +} + +} // namespace gin_helper diff --git a/shell/browser/api/event.h b/shell/browser/api/event.h index b60e23bb909..d10e9b47a3a 100644 --- a/shell/browser/api/event.h +++ b/shell/browser/api/event.h @@ -5,27 +5,26 @@ #ifndef SHELL_BROWSER_API_EVENT_H_ #define SHELL_BROWSER_API_EVENT_H_ -#include "base/optional.h" #include "electron/shell/common/api/api.mojom.h" -#include "native_mate/handle.h" -#include "native_mate/wrappable.h" +#include "gin/handle.h" +#include "gin/wrappable.h" namespace IPC { class Message; } -namespace mate { +namespace gin_helper { -class Event : public Wrappable { +class Event : public gin::Wrappable { public: using InvokeCallback = electron::mojom::ElectronBrowser::InvokeCallback; - static Handle Create(v8::Isolate* isolate); - static void BuildPrototype(v8::Isolate* isolate, - v8::Local prototype); + static gin::WrapperInfo kWrapperInfo; + + static gin::Handle Create(v8::Isolate* isolate); // Pass the callback to be invoked. - void SetCallback(base::Optional callback); + void SetCallback(InvokeCallback callback); // event.PreventDefault(). void PreventDefault(v8::Isolate* isolate); @@ -35,16 +34,21 @@ class Event : public Wrappable { bool SendReply(v8::Isolate* isolate, v8::Local result); protected: - explicit Event(v8::Isolate* isolate); + Event(); ~Event() override; + // gin::Wrappable: + gin::ObjectTemplateBuilder GetObjectTemplateBuilder( + v8::Isolate* isolate) override; + const char* GetTypeName() override; + private: // Replyer for the synchronous messages. - base::Optional callback_; + InvokeCallback callback_; DISALLOW_COPY_AND_ASSIGN(Event); }; -} // namespace mate +} // namespace gin_helper #endif // SHELL_BROWSER_API_EVENT_H_ diff --git a/shell/browser/api/gpuinfo_manager.cc b/shell/browser/api/gpuinfo_manager.cc index 686d7ac0bbd..177275943d7 100644 --- a/shell/browser/api/gpuinfo_manager.cc +++ b/shell/browser/api/gpuinfo_manager.cc @@ -11,6 +11,7 @@ #include "content/public/browser/browser_thread.h" #include "gpu/config/gpu_info_collector.h" #include "shell/browser/api/gpu_info_enumerator.h" +#include "shell/common/gin_converters/value_converter.h" namespace electron { @@ -46,7 +47,7 @@ void GPUInfoManager::ProcessCompleteInfo() { // We have received the complete information, resolve all promises that // were waiting for this info. for (auto& promise : complete_info_promise_set_) { - promise.Resolve(*result); + promise.ResolveWithGin(*result); } complete_info_promise_set_.clear(); } @@ -86,7 +87,7 @@ void GPUInfoManager::FetchBasicInfo( util::Promise promise) { gpu::GPUInfo gpu_info; CollectBasicGraphicsInfo(&gpu_info); - promise.Resolve(*EnumerateGPUInfo(gpu_info)); + promise.ResolveWithGin(*EnumerateGPUInfo(gpu_info)); } std::unique_ptr GPUInfoManager::EnumerateGPUInfo( diff --git a/shell/browser/api/gpuinfo_manager.h b/shell/browser/api/gpuinfo_manager.h index 8495951e758..f013b19df68 100644 --- a/shell/browser/api/gpuinfo_manager.h +++ b/shell/browser/api/gpuinfo_manager.h @@ -12,7 +12,6 @@ #include "content/browser/gpu/gpu_data_manager_impl.h" // nogncheck #include "content/public/browser/gpu_data_manager.h" #include "content/public/browser/gpu_data_manager_observer.h" -#include "shell/common/native_mate_converters/value_converter.h" #include "shell/common/promise_util.h" namespace electron { diff --git a/shell/browser/auto_updater_mac.mm b/shell/browser/auto_updater_mac.mm index d2abbc042d7..a9ebb601bf8 100644 --- a/shell/browser/auto_updater_mac.mm +++ b/shell/browser/auto_updater_mac.mm @@ -16,7 +16,7 @@ #include "base/time/time.h" #include "gin/arguments.h" #include "shell/browser/browser.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" diff --git a/shell/browser/login_handler.cc b/shell/browser/login_handler.cc index 45c3ca8b097..7ede5072792 100644 --- a/shell/browser/login_handler.cc +++ b/shell/browser/login_handler.cc @@ -5,7 +5,9 @@ #include "shell/browser/login_handler.h" #include +#include #include +#include #include "base/task/post_task.h" #include "base/values.h" @@ -13,13 +15,71 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents.h" #include "net/base/auth.h" +#include "net/base/upload_bytes_element_reader.h" +#include "net/base/upload_data_stream.h" +#include "net/base/upload_element_reader.h" +#include "net/base/upload_file_element_reader.h" #include "shell/browser/browser.h" -#include "shell/common/native_mate_converters/net_converter.h" +#include "shell/common/gin_converters/net_converter.h" using content::BrowserThread; namespace electron { +namespace { + +void GetUploadData(base::ListValue* upload_data_list, + const net::URLRequest* request) { + const net::UploadDataStream* upload_data = request->get_upload_for_testing(); + if (!upload_data) + return; + const std::vector>* readers = + upload_data->GetElementReaders(); + for (const auto& reader : *readers) { + auto upload_data_dict = std::make_unique(); + if (reader->AsBytesReader()) { + const net::UploadBytesElementReader* bytes_reader = + reader->AsBytesReader(); + auto bytes = std::make_unique( + std::vector(bytes_reader->bytes(), + bytes_reader->bytes() + bytes_reader->length())); + upload_data_dict->Set("bytes", std::move(bytes)); + } else if (reader->AsFileReader()) { + const net::UploadFileElementReader* file_reader = reader->AsFileReader(); + auto file_path = file_reader->path().AsUTF8Unsafe(); + upload_data_dict->SetKey("file", base::Value(file_path)); + } + // else { + // const storage::UploadBlobElementReader* blob_reader = + // static_cast(reader.get()); + // upload_data_dict->SetString("blobUUID", blob_reader->uuid()); + // } + upload_data_list->Append(std::move(upload_data_dict)); + } +} + +void FillRequestDetails(base::DictionaryValue* details, + const net::URLRequest* request) { + details->SetString("method", request->method()); + std::string url; + if (!request->url_chain().empty()) + url = request->url().spec(); + details->SetKey("url", base::Value(url)); + details->SetString("referrer", request->referrer()); + auto list = std::make_unique(); + GetUploadData(list.get(), request); + if (!list->empty()) + details->Set("uploadData", std::move(list)); + auto headers_value = std::make_unique(); + for (net::HttpRequestHeaders::Iterator it(request->extra_request_headers()); + it.GetNext();) { + headers_value->SetString(it.name(), it.value()); + } + details->Set("headers", std::move(headers_value)); +} + +} // namespace + LoginHandler::LoginHandler(net::URLRequest* request, const net::AuthChallengeInfo& auth_info, // net::NetworkDelegate::AuthCallback callback, @@ -32,6 +92,7 @@ LoginHandler::LoginHandler(net::URLRequest* request, std::unique_ptr request_details( new base::DictionaryValue); + // TODO(zcbenz): Use the converters from net_converter. FillRequestDetails(request_details.get(), request); // TODO(deepak1556): fix with network service diff --git a/shell/browser/native_window.cc b/shell/browser/native_window.cc index 9e83001720a..45ded7b4f49 100644 --- a/shell/browser/native_window.cc +++ b/shell/browser/native_window.cc @@ -15,6 +15,7 @@ #include "shell/browser/window_list.h" #include "shell/common/color_util.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/persistent_dictionary.h" #include "shell/common/options_switches.h" #include "ui/views/widget/widget.h" @@ -346,12 +347,12 @@ bool NativeWindow::AddTabbedWindow(NativeWindow* window) { void NativeWindow::SetVibrancy(const std::string& filename) {} void NativeWindow::SetTouchBar( - const std::vector& items) {} + std::vector items) {} void NativeWindow::RefreshTouchBarItem(const std::string& item_id) {} void NativeWindow::SetEscapeTouchBarItem( - const mate::PersistentDictionary& item) {} + gin_helper::PersistentDictionary item) {} void NativeWindow::SetAutoHideMenuBar(bool auto_hide) {} diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index e7afbf6daec..4e80ba5a873 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -39,11 +39,8 @@ class Size; namespace gin_helper { class Dictionary; -} - -namespace mate { class PersistentDictionary; -} +} // namespace gin_helper namespace electron { @@ -198,10 +195,9 @@ class NativeWindow : public base::SupportsUserData, virtual void SetVibrancy(const std::string& type); // Touchbar API - virtual void SetTouchBar( - const std::vector& items); + virtual void SetTouchBar(std::vector items); virtual void RefreshTouchBarItem(const std::string& item_id); - virtual void SetEscapeTouchBarItem(const mate::PersistentDictionary& item); + virtual void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item); // Native Tab API virtual void SelectPreviousTab(); diff --git a/shell/browser/native_window_mac.h b/shell/browser/native_window_mac.h index a1130b39e41..761dc09041a 100644 --- a/shell/browser/native_window_mac.h +++ b/shell/browser/native_window_mac.h @@ -133,9 +133,9 @@ class NativeWindowMac : public NativeWindow { void SetVibrancy(const std::string& type) override; void SetTouchBar( - const std::vector& items) override; + std::vector items) override; void RefreshTouchBarItem(const std::string& item_id) override; - void SetEscapeTouchBarItem(const mate::PersistentDictionary& item) override; + void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item) override; void SetGTKDarkThemeEnabled(bool use_dark_theme) override {} gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override; diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index dc8171878c2..f6ea715c14c 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1462,12 +1462,12 @@ void NativeWindowMac::SetVibrancy(const std::string& type) { } void NativeWindowMac::SetTouchBar( - const std::vector& items) { + std::vector items) { if (@available(macOS 10.12.2, *)) { touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:window_delegate_.get() window:this - settings:items]); + settings:std::move(items)]); [window_ setTouchBar:nil]; } } @@ -1480,10 +1480,11 @@ void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) { } void NativeWindowMac::SetEscapeTouchBarItem( - const mate::PersistentDictionary& item) { + gin_helper::PersistentDictionary item) { if (@available(macOS 10.12.2, *)) { if (touch_bar_ && [window_ touchBar]) - [touch_bar_ setEscapeTouchBarItem:item forTouchBar:[window_ touchBar]]; + [touch_bar_ setEscapeTouchBarItem:std::move(item) + forTouchBar:[window_ touchBar]]; } } diff --git a/shell/browser/net/atom_url_loader_factory.cc b/shell/browser/net/atom_url_loader_factory.cc index 787b5ea91f7..c25eb46188f 100644 --- a/shell/browser/net/atom_url_loader_factory.cc +++ b/shell/browser/net/atom_url_loader_factory.cc @@ -27,7 +27,7 @@ #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_converters/value_converter.h" #include "shell/common/node_includes.h" diff --git a/shell/browser/net/cert_verifier_client.cc b/shell/browser/net/cert_verifier_client.cc index 6d2968cd12a..78a7fcef0d2 100644 --- a/shell/browser/net/cert_verifier_client.cc +++ b/shell/browser/net/cert_verifier_client.cc @@ -5,7 +5,6 @@ #include #include "shell/browser/net/cert_verifier_client.h" -#include "shell/common/native_mate_converters/net_converter.h" namespace electron { diff --git a/shell/browser/printing/print_preview_message_handler.cc b/shell/browser/printing/print_preview_message_handler.cc index ae744a1ad75..fa3c0e34d5d 100644 --- a/shell/browser/printing/print_preview_message_handler.cc +++ b/shell/browser/printing/print_preview_message_handler.cc @@ -23,7 +23,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" -#include "shell/common/api/locker.h" +#include "shell/common/gin_helper/locker.h" #include "shell/common/node_includes.h" @@ -175,7 +175,7 @@ void PrintPreviewMessageHandler::ResolvePromise( util::Promise> promise = GetPromise(request_id); v8::Isolate* isolate = promise.isolate(); - mate::Locker locker(isolate); + gin_helper::Locker locker(isolate); v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope( v8::Local::New(isolate, promise.GetContext())); diff --git a/shell/browser/renderer_host/electron_render_message_filter.cc b/shell/browser/renderer_host/electron_render_message_filter.cc index 678bddb4653..315464f8bea 100644 --- a/shell/browser/renderer_host/electron_render_message_filter.cc +++ b/shell/browser/renderer_host/electron_render_message_filter.cc @@ -19,7 +19,7 @@ #include "content/public/browser/browser_context.h" #include "shell/browser/api/atom_api_session.h" #include "shell/browser/atom_browser_context.h" -#include "shell/common/native_mate_converters/gurl_converter.h" +#include "shell/common/gin_converters/gurl_converter.h" using content::BrowserThread; diff --git a/shell/browser/ui/cocoa/atom_touch_bar.h b/shell/browser/ui/cocoa/atom_touch_bar.h index 0de32f72443..134c6df5bca 100644 --- a/shell/browser/ui/cocoa/atom_touch_bar.h +++ b/shell/browser/ui/cocoa/atom_touch_bar.h @@ -12,35 +12,34 @@ #include #include "base/mac/scoped_nsobject.h" -#include "native_mate/constructor.h" -#include "native_mate/persistent_dictionary.h" #include "shell/browser/native_window.h" +#include "shell/common/gin_helper/persistent_dictionary.h" @interface AtomTouchBar : NSObject { @protected - std::vector ordered_settings_; - std::map settings_; + std::vector ordered_settings_; + std::map settings_; id delegate_; electron::NativeWindow* window_; } - (id)initWithDelegate:(id)delegate window:(electron::NativeWindow*)window - settings:(const std::vector&)settings; + settings:(std::vector)settings; - (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)); - (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items API_AVAILABLE(macosx(10.12.2)); - (NSMutableArray*)identifiersFromSettings: - (const std::vector&)settings; + (const std::vector&)settings; - (void)refreshTouchBarItem:(NSTouchBar*)touchBar id:(const std::string&)item_id API_AVAILABLE(macosx(10.12.2)); - (void)addNonDefaultTouchBarItems: - (const std::vector&)items; -- (void)setEscapeTouchBarItem:(const mate::PersistentDictionary&)item + (const std::vector&)items; +- (void)setEscapeTouchBarItem:(gin_helper::PersistentDictionary)item forTouchBar:(NSTouchBar*)touchBar API_AVAILABLE(macosx(10.12.2)); @@ -80,19 +79,19 @@ // Helpers to update touch bar items - (void)updateButton:(NSCustomTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings + withSettings:(const gin_helper::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)); - (void)updateLabel:(NSCustomTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings + withSettings:(const gin_helper::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)); - (void)updateColorPicker:(NSColorPickerTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings + withSettings:(const gin_helper::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)); - (void)updateSlider:(NSSliderTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings + withSettings:(const gin_helper::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)); - (void)updatePopover:(NSPopoverTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings + withSettings:(const gin_helper::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)); @end diff --git a/shell/browser/ui/cocoa/atom_touch_bar.mm b/shell/browser/ui/cocoa/atom_touch_bar.mm index 3e1660d2fbf..151c4de2bf3 100644 --- a/shell/browser/ui/cocoa/atom_touch_bar.mm +++ b/shell/browser/ui/cocoa/atom_touch_bar.mm @@ -9,7 +9,7 @@ #include "base/strings/sys_string_conversions.h" #include "shell/common/color_util.h" -#include "shell/common/native_mate_converters/image_converter.h" +#include "shell/common/gin_converters/image_converter.h" #include "skia/ext/skia_utils_mac.h" #include "ui/gfx/image/image.h" @@ -37,12 +37,11 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; - (id)initWithDelegate:(id)delegate window:(electron::NativeWindow*)window - settings: - (const std::vector&)settings { + settings:(std::vector)settings { if ((self = [super init])) { delegate_ = delegate; window_ = window; - ordered_settings_ = settings; + ordered_settings_ = std::move(settings); } return self; } @@ -61,7 +60,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (NSMutableArray*)identifiersFromSettings: - (const std::vector&)dicts { + (const std::vector&)dicts { NSMutableArray* identifiers = [NSMutableArray array]; if (@available(macOS 10.12.2, *)) { @@ -133,7 +132,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; - (void)refreshTouchBarItem:(NSTouchBar*)touchBar id:(NSTouchBarItemIdentifier)identifier withType:(const std::string&)item_type - withSettings:(const mate::PersistentDictionary&)settings + withSettings:(const gin_helper::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)) { NSTouchBarItem* item = [touchBar itemForIdentifier:identifier]; if (!item) @@ -161,11 +160,11 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)addNonDefaultTouchBarItems: - (const std::vector&)items { + (const std::vector&)items { [self identifiersFromSettings:items]; } -- (void)setEscapeTouchBarItem:(const mate::PersistentDictionary&)item +- (void)setEscapeTouchBarItem:(gin_helper::PersistentDictionary)item forTouchBar:(NSTouchBar*)touchBar { if (![touchBar respondsToSelector:@selector(escapeKeyReplacementItemIdentifier)]) @@ -177,7 +176,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; identifier = [self identifierFromID:item_id type:type]; } if (identifier) { - [self addNonDefaultTouchBarItems:{item}]; + [self addNonDefaultTouchBarItems:{std::move(item)}]; touchBar.escapeKeyReplacementItemIdentifier = identifier; } else { touchBar.escapeKeyReplacementItemIdentifier = nil; @@ -189,7 +188,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:item_id]) return; - mate::PersistentDictionary settings = settings_[item_id]; + gin_helper::PersistentDictionary settings = settings_[item_id]; std::string item_type; settings.Get("type", &item_type); @@ -197,7 +196,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (!identifier) return; - std::vector parents; + std::vector parents; settings.Get("_parents", &parents); for (auto& parent : parents) { std::string parent_type; @@ -339,7 +338,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:s_id]) return nil; - mate::PersistentDictionary settings = settings_[s_id]; + gin_helper::PersistentDictionary settings = settings_[s_id]; base::scoped_nsobject item( [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]); NSButton* button = [NSButton buttonWithTitle:@"" @@ -352,7 +351,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updateButton:(NSCustomTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings { + withSettings:(const gin_helper::PersistentDictionary&)settings { NSButton* button = (NSButton*)item.view; std::string backgroundColor; @@ -393,7 +392,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:s_id]) return nil; - mate::PersistentDictionary settings = settings_[s_id]; + gin_helper::PersistentDictionary settings = settings_[s_id]; base::scoped_nsobject item( [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]); [item setView:[NSTextField labelWithString:@""]]; @@ -402,7 +401,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updateLabel:(NSCustomTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings { + withSettings:(const gin_helper::PersistentDictionary&)settings { NSTextField* text_field = (NSTextField*)item.view; std::string label; @@ -427,7 +426,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:s_id]) return nil; - mate::PersistentDictionary settings = settings_[s_id]; + gin_helper::PersistentDictionary settings = settings_[s_id]; base::scoped_nsobject item( [[NSColorPickerTouchBarItem alloc] initWithIdentifier:identifier]); [item setTarget:self]; @@ -437,7 +436,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updateColorPicker:(NSColorPickerTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings { + withSettings:(const gin_helper::PersistentDictionary&)settings { std::vector colors; if (settings.Get("availableColors", &colors) && !colors.empty()) { NSColorList* color_list = @@ -462,7 +461,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:s_id]) return nil; - mate::PersistentDictionary settings = settings_[s_id]; + gin_helper::PersistentDictionary settings = settings_[s_id]; base::scoped_nsobject item( [[NSSliderTouchBarItem alloc] initWithIdentifier:identifier]); [item setTarget:self]; @@ -472,7 +471,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updateSlider:(NSSliderTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings { + withSettings:(const gin_helper::PersistentDictionary&)settings { std::string label; settings.Get("label", &label); item.label = base::SysUTF8ToNSString(label); @@ -495,7 +494,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:s_id]) return nil; - mate::PersistentDictionary settings = settings_[s_id]; + gin_helper::PersistentDictionary settings = settings_[s_id]; base::scoped_nsobject item( [[NSPopoverTouchBarItem alloc] initWithIdentifier:identifier]); [self updatePopover:item withSettings:settings]; @@ -503,7 +502,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updatePopover:(NSPopoverTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings { + withSettings:(const gin_helper::PersistentDictionary&)settings { std::string label; settings.Get("label", &label); item.collapsedRepresentationLabel = base::SysUTF8ToNSString(label); @@ -517,8 +516,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; settings.Get("showCloseButton", &showCloseButton); item.showsCloseButton = showCloseButton; - mate::PersistentDictionary child; - std::vector items; + gin_helper::PersistentDictionary child; + std::vector items; if (settings.Get("child", &child) && child.Get("ordereredItems", &items)) { item.popoverTouchBar = [self touchBarFromItemIdentifiers:[self identifiersFromSettings:items]]; @@ -530,12 +529,12 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; std::string s_id([id UTF8String]); if (![self hasItemWithID:s_id]) return nil; - mate::PersistentDictionary settings = settings_[s_id]; + gin_helper::PersistentDictionary settings = settings_[s_id]; - mate::PersistentDictionary child; + gin_helper::PersistentDictionary child; if (!settings.Get("child", &child)) return nil; - std::vector items; + std::vector items; if (!child.Get("ordereredItems", &items)) return nil; @@ -556,12 +555,12 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updateGroup:(NSGroupTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings + withSettings:(const gin_helper::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)) { - mate::PersistentDictionary child; + gin_helper::PersistentDictionary child; if (!settings.Get("child", &child)) return; - std::vector items; + std::vector items; if (!child.Get("ordereredItems", &items)) return; @@ -576,7 +575,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:s_id]) return nil; - mate::PersistentDictionary settings = settings_[s_id]; + gin_helper::PersistentDictionary settings = settings_[s_id]; base::scoped_nsobject item( [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]); @@ -593,7 +592,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updateSegmentedControl:(NSCustomTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings + withSettings:(const gin_helper::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)) { NSSegmentedControl* control = item.view; @@ -625,7 +624,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; else control.trackingMode = NSSegmentSwitchTrackingSelectOne; - std::vector segments; + std::vector segments; settings.Get("segments", &segments); control.segmentCount = segments.size(); @@ -661,7 +660,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:s_id]) return nil; - mate::PersistentDictionary settings = settings_[s_id]; + gin_helper::PersistentDictionary settings = settings_[s_id]; base::scoped_nsobject item( [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]); @@ -684,7 +683,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; } - (void)updateScrubber:(NSCustomTouchBarItem*)item - withSettings:(const mate::PersistentDictionary&)settings + withSettings:(const gin_helper::PersistentDictionary&)settings API_AVAILABLE(macosx(10.12.2)) { NSScrubber* scrubber = item.view; @@ -738,8 +737,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:s_id]) return 0; - mate::PersistentDictionary settings = settings_[s_id]; - std::vector items; + gin_helper::PersistentDictionary settings = settings_[s_id]; + std::vector items; settings.Get("items", &items); return items.size(); } @@ -751,15 +750,15 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:s_id]) return nil; - mate::PersistentDictionary settings = settings_[s_id]; - std::vector items; + gin_helper::PersistentDictionary settings = settings_[s_id]; + std::vector items; if (!settings.Get("items", &items)) return nil; if (index >= static_cast(items.size())) return nil; - mate::PersistentDictionary item = items[index]; + gin_helper::PersistentDictionary item = items[index]; NSScrubberItemView* itemView; std::string title; @@ -795,15 +794,15 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item"; if (![self hasItemWithID:s_id]) return defaultSize; - mate::PersistentDictionary settings = settings_[s_id]; - std::vector items; + gin_helper::PersistentDictionary settings = settings_[s_id]; + std::vector items; if (!settings.Get("items", &items)) return defaultSize; if (itemIndex >= static_cast(items.size())) return defaultSize; - mate::PersistentDictionary item = items[itemIndex]; + gin_helper::PersistentDictionary item = items[itemIndex]; std::string title; if (item.Get("label", &title)) { diff --git a/shell/browser/web_contents_permission_helper.cc b/shell/browser/web_contents_permission_helper.cc index 887a9c175a2..49a3ac06ed0 100644 --- a/shell/browser/web_contents_permission_helper.cc +++ b/shell/browser/web_contents_permission_helper.cc @@ -12,7 +12,6 @@ #include "content/public/browser/render_process_host.h" #include "shell/browser/atom_permission_manager.h" #include "shell/browser/media/media_stream_devices_controller.h" -#include "shell/common/native_mate_converters/gurl_converter.h" namespace { diff --git a/shell/browser/web_contents_preferences.cc b/shell/browser/web_contents_preferences.cc index af325d1b1f3..45f9bf25a02 100644 --- a/shell/browser/web_contents_preferences.cc +++ b/shell/browser/web_contents_preferences.cc @@ -23,7 +23,7 @@ #include "services/service_manager/sandbox/switches.h" #include "shell/browser/native_window.h" #include "shell/browser/web_view_manager.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/options_switches.h" diff --git a/shell/browser/web_view_guest_delegate.cc b/shell/browser/web_view_guest_delegate.cc index bd92bbc830c..5c26848ca43 100644 --- a/shell/browser/web_view_guest_delegate.cc +++ b/shell/browser/web_view_guest_delegate.cc @@ -14,7 +14,6 @@ #include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host_view.h" #include "shell/browser/api/atom_api_web_contents.h" -#include "shell/common/native_mate_converters/gurl_converter.h" #include "third_party/blink/public/common/page/page_zoom.h" namespace electron { diff --git a/shell/common/api/atom_api_asar.cc b/shell/common/api/atom_api_asar.cc index ed28c8980c3..b6345fa92b6 100644 --- a/shell/common/api/atom_api_asar.cc +++ b/shell/common/api/atom_api_asar.cc @@ -6,15 +6,13 @@ #include -#include "native_mate/arguments.h" -#include "native_mate/dictionary.h" -#include "native_mate/object_template_builder_deprecated.h" #include "native_mate/wrappable.h" #include "shell/common/asar/archive.h" #include "shell/common/asar/asar_util.h" #include "shell/common/gin_converters/callback_converter.h" +#include "shell/common/gin_converters/file_path_converter.h" #include "shell/common/gin_helper/dictionary.h" -#include "shell/common/native_mate_converters/file_path_converter.h" +#include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" #include "shell/common/node_util.h" namespace { @@ -31,8 +29,8 @@ class Archive : public mate::Wrappable { static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "Archive")); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + prototype->SetClassName(gin::StringToV8(isolate, "Archive")); + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetProperty("path", &Archive::GetPath) .SetMethod("getFileInfo", &Archive::GetFileInfo) .SetMethod("stat", &Archive::Stat) @@ -84,7 +82,7 @@ class Archive : public mate::Wrappable { std::vector files; if (!archive_ || !archive_->Readdir(path, &files)) return v8::False(isolate); - return mate::ConvertToV8(isolate, files); + return gin::ConvertToV8(isolate, files); } // Returns the path of file with symbol link resolved. @@ -93,7 +91,7 @@ class Archive : public mate::Wrappable { base::FilePath realpath; if (!archive_ || !archive_->Realpath(path, &realpath)) return v8::False(isolate); - return mate::ConvertToV8(isolate, realpath); + return gin::ConvertToV8(isolate, realpath); } // Copy the file out into a temporary file and returns the new path. @@ -102,7 +100,7 @@ class Archive : public mate::Wrappable { base::FilePath new_path; if (!archive_ || !archive_->CopyFileOut(path, &new_path)) return v8::False(isolate); - return mate::ConvertToV8(isolate, new_path); + return gin::ConvertToV8(isolate, new_path); } // Return the file descriptor. @@ -130,7 +128,7 @@ void InitAsarSupport(v8::Isolate* isolate, v8::Local require) { v8::Local SplitPath(v8::Isolate* isolate, const base::FilePath& path) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); base::FilePath asar_path, file_path; if (asar::GetAsarArchivePath(path, &asar_path, &file_path, true)) { dict.Set("isAsar", true); diff --git a/shell/common/api/atom_api_clipboard.cc b/shell/common/api/atom_api_clipboard.cc index 134dc06ad9c..ffc5e2f4697 100644 --- a/shell/common/api/atom_api_clipboard.cc +++ b/shell/common/api/atom_api_clipboard.cc @@ -5,8 +5,8 @@ #include "shell/common/api/atom_api_clipboard.h" #include "base/strings/utf_string_conversions.h" -#include "shell/common/native_mate_converters/image_converter.h" -#include "shell/common/native_mate_converters/string16_converter.h" +#include "shell/common/gin_converters/image_converter.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkImageInfo.h" @@ -18,7 +18,7 @@ namespace electron { namespace api { -ui::ClipboardBuffer Clipboard::GetClipboardBuffer(mate::Arguments* args) { +ui::ClipboardBuffer Clipboard::GetClipboardBuffer(gin_helper::Arguments* args) { std::string type; if (args->GetNext(&type) && type == "selection") return ui::ClipboardBuffer::kSelection; @@ -26,7 +26,8 @@ ui::ClipboardBuffer Clipboard::GetClipboardBuffer(mate::Arguments* args) { return ui::ClipboardBuffer::kCopyPaste; } -std::vector Clipboard::AvailableFormats(mate::Arguments* args) { +std::vector Clipboard::AvailableFormats( + gin_helper::Arguments* args) { std::vector format_types; bool ignore; ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); @@ -35,7 +36,8 @@ std::vector Clipboard::AvailableFormats(mate::Arguments* args) { return format_types; } -bool Clipboard::Has(const std::string& format_string, mate::Arguments* args) { +bool Clipboard::Has(const std::string& format_string, + gin_helper::Arguments* args) { ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); ui::ClipboardFormatType format( ui::ClipboardFormatType::GetType(format_string)); @@ -53,7 +55,7 @@ std::string Clipboard::Read(const std::string& format_string) { } v8::Local Clipboard::ReadBuffer(const std::string& format_string, - mate::Arguments* args) { + gin_helper::Arguments* args) { std::string data = Read(format_string); return node::Buffer::Copy(args->isolate(), data.data(), data.length()) .ToLocalChecked(); @@ -61,7 +63,7 @@ v8::Local Clipboard::ReadBuffer(const std::string& format_string, void Clipboard::WriteBuffer(const std::string& format, const v8::Local buffer, - mate::Arguments* args) { + gin_helper::Arguments* args) { if (!node::Buffer::HasInstance(buffer)) { args->ThrowError("buffer must be a node Buffer"); return; @@ -76,7 +78,8 @@ void Clipboard::WriteBuffer(const std::string& format, mojo_base::BigBuffer(payload_span)); } -void Clipboard::Write(const mate::Dictionary& data, mate::Arguments* args) { +void Clipboard::Write(const gin_helper::Dictionary& data, + gin_helper::Arguments* args) { ui::ScopedClipboardWriter writer(GetClipboardBuffer(args)); base::string16 text, html, bookmark; gfx::Image image; @@ -100,7 +103,7 @@ void Clipboard::Write(const mate::Dictionary& data, mate::Arguments* args) { writer.WriteImage(image.AsBitmap()); } -base::string16 Clipboard::ReadText(mate::Arguments* args) { +base::string16 Clipboard::ReadText(gin_helper::Arguments* args) { base::string16 data; ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); auto type = GetClipboardBuffer(args); @@ -116,24 +119,25 @@ base::string16 Clipboard::ReadText(mate::Arguments* args) { return data; } -void Clipboard::WriteText(const base::string16& text, mate::Arguments* args) { +void Clipboard::WriteText(const base::string16& text, + gin_helper::Arguments* args) { ui::ScopedClipboardWriter writer(GetClipboardBuffer(args)); writer.WriteText(text); } -base::string16 Clipboard::ReadRTF(mate::Arguments* args) { +base::string16 Clipboard::ReadRTF(gin_helper::Arguments* args) { std::string data; ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); clipboard->ReadRTF(GetClipboardBuffer(args), &data); return base::UTF8ToUTF16(data); } -void Clipboard::WriteRTF(const std::string& text, mate::Arguments* args) { +void Clipboard::WriteRTF(const std::string& text, gin_helper::Arguments* args) { ui::ScopedClipboardWriter writer(GetClipboardBuffer(args)); writer.WriteRTF(text); } -base::string16 Clipboard::ReadHTML(mate::Arguments* args) { +base::string16 Clipboard::ReadHTML(gin_helper::Arguments* args) { base::string16 data; base::string16 html; std::string url; @@ -145,15 +149,17 @@ base::string16 Clipboard::ReadHTML(mate::Arguments* args) { return data; } -void Clipboard::WriteHTML(const base::string16& html, mate::Arguments* args) { +void Clipboard::WriteHTML(const base::string16& html, + gin_helper::Arguments* args) { ui::ScopedClipboardWriter writer(GetClipboardBuffer(args)); writer.WriteHTML(html, std::string()); } -v8::Local Clipboard::ReadBookmark(mate::Arguments* args) { +v8::Local Clipboard::ReadBookmark(gin_helper::Arguments* args) { base::string16 title; std::string url; - mate::Dictionary dict = mate::Dictionary::CreateEmpty(args->isolate()); + gin_helper::Dictionary dict = + gin_helper::Dictionary::CreateEmpty(args->isolate()); ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); clipboard->ReadBookmark(&title, &url); dict.Set("title", title); @@ -163,18 +169,19 @@ v8::Local Clipboard::ReadBookmark(mate::Arguments* args) { void Clipboard::WriteBookmark(const base::string16& title, const std::string& url, - mate::Arguments* args) { + gin_helper::Arguments* args) { ui::ScopedClipboardWriter writer(GetClipboardBuffer(args)); writer.WriteBookmark(title, url); } -gfx::Image Clipboard::ReadImage(mate::Arguments* args) { +gfx::Image Clipboard::ReadImage(gin_helper::Arguments* args) { ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); SkBitmap bitmap = clipboard->ReadImage(GetClipboardBuffer(args)); return gfx::Image::CreateFrom1xBitmap(bitmap); } -void Clipboard::WriteImage(const gfx::Image& image, mate::Arguments* args) { +void Clipboard::WriteImage(const gfx::Image& image, + gin_helper::Arguments* args) { ui::ScopedClipboardWriter writer(GetClipboardBuffer(args)); SkBitmap orig = image.AsBitmap(); SkBitmap bmp; @@ -192,7 +199,7 @@ base::string16 Clipboard::ReadFindText() { } #endif -void Clipboard::Clear(mate::Arguments* args) { +void Clipboard::Clear(gin_helper::Arguments* args) { ui::Clipboard::GetForCurrentThread()->Clear(GetClipboardBuffer(args)); } @@ -206,7 +213,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("availableFormats", &electron::api::Clipboard::AvailableFormats); dict.SetMethod("has", &electron::api::Clipboard::Has); diff --git a/shell/common/api/atom_api_clipboard.h b/shell/common/api/atom_api_clipboard.h index 9c7fd008a00..2198558fae8 100644 --- a/shell/common/api/atom_api_clipboard.h +++ b/shell/common/api/atom_api_clipboard.h @@ -8,10 +8,14 @@ #include #include -#include "native_mate/arguments.h" -#include "native_mate/dictionary.h" #include "ui/base/clipboard/clipboard.h" #include "ui/gfx/image/image.h" +#include "v8/include/v8.h" + +namespace gin_helper { +class Arguments; +class Dictionary; +} // namespace gin_helper namespace electron { @@ -19,39 +23,44 @@ namespace api { class Clipboard { public: - static ui::ClipboardBuffer GetClipboardBuffer(mate::Arguments* args); - static std::vector AvailableFormats(mate::Arguments* args); - static bool Has(const std::string& format_string, mate::Arguments* args); - static void Clear(mate::Arguments* args); + static ui::ClipboardBuffer GetClipboardBuffer(gin_helper::Arguments* args); + static std::vector AvailableFormats( + gin_helper::Arguments* args); + static bool Has(const std::string& format_string, + gin_helper::Arguments* args); + static void Clear(gin_helper::Arguments* args); static std::string Read(const std::string& format_string); - static void Write(const mate::Dictionary& data, mate::Arguments* args); + static void Write(const gin_helper::Dictionary& data, + gin_helper::Arguments* args); - static base::string16 ReadText(mate::Arguments* args); - static void WriteText(const base::string16& text, mate::Arguments* args); + static base::string16 ReadText(gin_helper::Arguments* args); + static void WriteText(const base::string16& text, + gin_helper::Arguments* args); - static base::string16 ReadRTF(mate::Arguments* args); - static void WriteRTF(const std::string& text, mate::Arguments* args); + static base::string16 ReadRTF(gin_helper::Arguments* args); + static void WriteRTF(const std::string& text, gin_helper::Arguments* args); - static base::string16 ReadHTML(mate::Arguments* args); - static void WriteHTML(const base::string16& html, mate::Arguments* args); + static base::string16 ReadHTML(gin_helper::Arguments* args); + static void WriteHTML(const base::string16& html, + gin_helper::Arguments* args); - static v8::Local ReadBookmark(mate::Arguments* args); + static v8::Local ReadBookmark(gin_helper::Arguments* args); static void WriteBookmark(const base::string16& title, const std::string& url, - mate::Arguments* args); + gin_helper::Arguments* args); - static gfx::Image ReadImage(mate::Arguments* args); - static void WriteImage(const gfx::Image& image, mate::Arguments* args); + static gfx::Image ReadImage(gin_helper::Arguments* args); + static void WriteImage(const gfx::Image& image, gin_helper::Arguments* args); static base::string16 ReadFindText(); static void WriteFindText(const base::string16& text); static v8::Local ReadBuffer(const std::string& format_string, - mate::Arguments* args); + gin_helper::Arguments* args); static void WriteBuffer(const std::string& format_string, const v8::Local buffer, - mate::Arguments* args); + gin_helper::Arguments* args); private: DISALLOW_COPY_AND_ASSIGN(Clipboard); diff --git a/shell/common/api/atom_api_command_line.cc b/shell/common/api/atom_api_command_line.cc index 9a00c2b447c..656ea0b1498 100644 --- a/shell/common/api/atom_api_command_line.cc +++ b/shell/common/api/atom_api_command_line.cc @@ -5,11 +5,9 @@ #include "base/command_line.h" #include "base/files/file_path.h" #include "base/strings/string_util.h" -#include "native_mate/converter.h" -#include "native_mate/dictionary.h" #include "services/network/public/cpp/network_switches.h" -#include "shell/common/native_mate_converters/file_path_converter.h" -#include "shell/common/native_mate_converters/string16_converter.h" +#include "shell/common/gin_converters/file_path_converter.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" namespace { @@ -23,7 +21,8 @@ base::CommandLine::StringType GetSwitchValue(const std::string& name) { name.c_str()); } -void AppendSwitch(const std::string& switch_string, mate::Arguments* args) { +void AppendSwitch(const std::string& switch_string, + gin_helper::Arguments* args) { auto* command_line = base::CommandLine::ForCurrentProcess(); if (base::EndsWith(switch_string, "-path", @@ -47,7 +46,7 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { auto* command_line = base::CommandLine::ForCurrentProcess(); - mate::Dictionary dict(context->GetIsolate(), exports); + gin_helper::Dictionary dict(context->GetIsolate(), exports); dict.SetMethod("hasSwitch", &HasSwitch); dict.SetMethod("getSwitchValue", &GetSwitchValue); dict.SetMethod("appendSwitch", &AppendSwitch); diff --git a/shell/common/api/atom_api_native_image.cc b/shell/common/api/atom_api_native_image.cc index 7cbd459816c..64ec66e844e 100644 --- a/shell/common/api/atom_api_native_image.cc +++ b/shell/common/api/atom_api_native_image.cc @@ -18,7 +18,7 @@ #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/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" diff --git a/shell/common/api/atom_api_shell.cc b/shell/common/api/atom_api_shell.cc index 4a6fe31940a..dd07ede80ac 100644 --- a/shell/common/api/atom_api_shell.cc +++ b/shell/common/api/atom_api_shell.cc @@ -6,10 +6,9 @@ #include "shell/common/gin_converters/callback_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/error_thrower.h" -#include "shell/common/native_mate_converters/gurl_converter.h" -#include "shell/common/native_mate_converters/string16_converter.h" #include "shell/common/node_includes.h" #include "shell/common/platform_util.h" #include "shell/common/promise_util.h" diff --git a/shell/common/api/electron_bindings.cc b/shell/common/api/electron_bindings.cc index 71e6c23cc01..ba278eaa889 100644 --- a/shell/common/api/electron_bindings.cc +++ b/shell/common/api/electron_bindings.cc @@ -18,16 +18,14 @@ #include "base/threading/thread_restrictions.h" #include "chrome/common/chrome_version.h" #include "electron/electron_version.h" -#include "native_mate/dictionary.h" #include "services/resource_coordinator/public/cpp/memory_instrumentation/global_memory_dump.h" #include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h" #include "shell/browser/browser.h" -#include "shell/common/api/locker.h" #include "shell/common/application_info.h" +#include "shell/common/gin_converters/file_path_converter.h" #include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/locker.h" #include "shell/common/heap_snapshot.h" -#include "shell/common/native_mate_converters/file_path_converter.h" -#include "shell/common/native_mate_converters/string16_converter.h" #include "shell/common/node_includes.h" #include "shell/common/promise_util.h" #include "third_party/blink/renderer/platform/heap/process_heap.h" // nogncheck @@ -57,7 +55,7 @@ ElectronBindings::~ElectronBindings() { // static void ElectronBindings::BindProcess(v8::Isolate* isolate, - mate::Dictionary* process, + gin_helper::Dictionary* process, base::ProcessMetrics* metrics) { // These bindings are shared between sandboxed & unsandboxed renderers process->SetMethod("crash", &Crash); @@ -89,7 +87,7 @@ void ElectronBindings::BindTo(v8::Isolate* isolate, v8::Local process) { isolate->SetFatalErrorHandler(FatalErrorCallback); - mate::Dictionary dict(isolate, process); + gin_helper::Dictionary dict(isolate, process); BindProcess(isolate, &dict, metrics_.get()); dict.SetMethod("takeHeapSnapshot", &TakeHeapSnapshot); @@ -100,7 +98,7 @@ void ElectronBindings::BindTo(v8::Isolate* isolate, base::BindRepeating(&ElectronBindings::ActivateUVLoop, base::Unretained(this))); - mate::Dictionary versions; + gin_helper::Dictionary versions; if (dict.Get("versions", &versions)) { versions.SetReadOnly(ELECTRON_PROJECT_NAME, ELECTRON_VERSION_STRING); versions.SetReadOnly("chrome", CHROME_VERSION_STRING); @@ -131,7 +129,7 @@ void ElectronBindings::OnCallNextTick(uv_async_t* handle) { self->pending_next_ticks_.begin(); it != self->pending_next_ticks_.end(); ++it) { node::Environment* env = *it; - mate::Locker locker(env->isolate()); + gin_helper::Locker locker(env->isolate()); v8::Context::Scope context_scope(env->context()); node::InternalCallbackScope scope( env, v8::Local(), {0, 0}, @@ -201,7 +199,7 @@ v8::Local ElectronBindings::GetCreationTime(v8::Isolate* isolate) { // static v8::Local ElectronBindings::GetSystemMemoryInfo( v8::Isolate* isolate, - mate::Arguments* args) { + gin_helper::Arguments* args) { base::SystemMemoryInfoKB mem_info; if (!base::GetSystemMemoryInfo(&mem_info)) { args->ThrowError("Unable to retrieve system memory information"); @@ -233,10 +231,10 @@ v8::Local ElectronBindings::GetSystemMemoryInfo( // static v8::Local ElectronBindings::GetProcessMemoryInfo( v8::Isolate* isolate) { - util::Promise promise(isolate); + util::Promise promise(isolate); v8::Local handle = promise.GetHandle(); - if (mate::Locker::IsBrowserProcess() && !Browser::Get()->is_ready()) { + if (gin_helper::Locker::IsBrowserProcess() && !Browser::Get()->is_ready()) { promise.RejectWithErrorMessage( "Memory Info is available only after app ready"); return handle; @@ -267,11 +265,11 @@ v8::Local ElectronBindings::GetBlinkMemoryInfo( // static void ElectronBindings::DidReceiveMemoryDump( v8::Global context, - util::Promise promise, + util::Promise promise, bool success, std::unique_ptr global_dump) { v8::Isolate* isolate = promise.isolate(); - mate::Locker locker(isolate); + gin_helper::Locker locker(isolate); v8::HandleScope handle_scope(isolate); v8::MicrotasksScope script_scope(isolate, v8::MicrotasksScope::kRunMicrotasks); @@ -287,14 +285,14 @@ void ElectronBindings::DidReceiveMemoryDump( for (const memory_instrumentation::GlobalMemoryDump::ProcessDump& dump : global_dump->process_dumps()) { if (base::GetCurrentProcId() == dump.pid()) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); const auto& osdump = dump.os_dump(); #if defined(OS_LINUX) || defined(OS_WIN) dict.Set("residentSet", osdump.resident_set_kb); #endif dict.Set("private", osdump.private_footprint_kb); dict.Set("shared", osdump.shared_footprint_kb); - promise.Resolve(dict); + promise.ResolveWithGin(dict); resolved = true; break; } diff --git a/shell/common/api/electron_bindings.h b/shell/common/api/electron_bindings.h index 98e0d2f1827..4547ef14b7d 100644 --- a/shell/common/api/electron_bindings.h +++ b/shell/common/api/electron_bindings.h @@ -13,14 +13,13 @@ #include "base/memory/scoped_refptr.h" #include "base/process/process_metrics.h" #include "base/strings/string16.h" -#include "native_mate/arguments.h" #include "shell/common/promise_util.h" #include "uv.h" // NOLINT(build/include) -#include "v8/include/v8.h" -namespace mate { +namespace gin_helper { +class Arguments; class Dictionary; -} +} // namespace gin_helper namespace memory_instrumentation { class GlobalMemoryDump; @@ -45,7 +44,7 @@ class ElectronBindings { void EnvironmentDestroyed(node::Environment* env); static void BindProcess(v8::Isolate* isolate, - mate::Dictionary* process, + gin_helper::Dictionary* process, base::ProcessMetrics* metrics); static void Log(const base::string16& message); @@ -56,7 +55,7 @@ class ElectronBindings { static v8::Local GetHeapStatistics(v8::Isolate* isolate); static v8::Local GetCreationTime(v8::Isolate* isolate); static v8::Local GetSystemMemoryInfo(v8::Isolate* isolate, - mate::Arguments* args); + gin_helper::Arguments* args); static v8::Local GetProcessMemoryInfo(v8::Isolate* isolate); static v8::Local GetBlinkMemoryInfo(v8::Isolate* isolate); static v8::Local GetCPUUsage(base::ProcessMetrics* metrics, @@ -71,7 +70,7 @@ class ElectronBindings { static void DidReceiveMemoryDump( v8::Global context, - util::Promise promise, + util::Promise promise, bool success, std::unique_ptr dump); diff --git a/shell/common/api/event_emitter_caller_deprecated.cc b/shell/common/api/event_emitter_caller_deprecated.cc deleted file mode 100644 index f73f21d8888..00000000000 --- a/shell/common/api/event_emitter_caller_deprecated.cc +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2015 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "shell/common/api/event_emitter_caller_deprecated.h" - -#include "shell/common/api/locker.h" -#include "shell/common/node_includes.h" - -namespace mate { - -namespace internal { - -v8::Local CallMethodWithArgs(v8::Isolate* isolate, - v8::Local obj, - const char* method, - ValueVector* args) { - // Perform microtask checkpoint after running JavaScript. - v8::MicrotasksScope script_scope(isolate, - v8::MicrotasksScope::kRunMicrotasks); - // Use node::MakeCallback to call the callback, and it will also run pending - // tasks in Node.js. - v8::MaybeLocal ret = node::MakeCallback( - isolate, obj, method, args->size(), &args->front(), {0, 0}); - // If the JS function throws an exception (doesn't return a value) the result - // of MakeCallback will be empty and therefore ToLocal will be false, in this - // case we need to return "false" as that indicates that the event emitter did - // not handle the event - v8::Local localRet; - if (ret.ToLocal(&localRet)) { - return localRet; - } - return v8::Boolean::New(isolate, false); -} - -} // namespace internal - -} // namespace mate diff --git a/shell/common/api/event_emitter_caller_deprecated.h b/shell/common/api/event_emitter_caller_deprecated.h deleted file mode 100644 index 328514a09a7..00000000000 --- a/shell/common/api/event_emitter_caller_deprecated.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2015 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef SHELL_COMMON_API_EVENT_EMITTER_CALLER_DEPRECATED_H_ -#define SHELL_COMMON_API_EVENT_EMITTER_CALLER_DEPRECATED_H_ - -// =============================== NOTICE =============================== -// Do not add code here, native_mate is being removed. Any new code -// should use gin_helper version instead. - -#include -#include - -#include "native_mate/converter.h" -#include "shell/common/native_mate_converters/string16_converter.h" - -namespace mate { - -namespace internal { - -using ValueVector = std::vector>; - -v8::Local CallMethodWithArgs(v8::Isolate* isolate, - v8::Local obj, - const char* method, - ValueVector* args); - -} // namespace internal - -// obj.emit.apply(obj, name, args...); -// The caller is responsible of allocating a HandleScope. -template -v8::Local EmitEvent(v8::Isolate* isolate, - v8::Local obj, - const StringType& name, - const internal::ValueVector& args) { - internal::ValueVector concatenated_args = {StringToV8(isolate, name)}; - concatenated_args.reserve(1 + args.size()); - concatenated_args.insert(concatenated_args.end(), args.begin(), args.end()); - return internal::CallMethodWithArgs(isolate, obj, "emit", &concatenated_args); -} - -// obj.emit(name, args...); -// The caller is responsible of allocating a HandleScope. -template -v8::Local EmitEvent(v8::Isolate* isolate, - v8::Local obj, - const StringType& name, - Args&&... args) { - internal::ValueVector converted_args = { - StringToV8(isolate, name), - ConvertToV8(isolate, std::forward(args))..., - }; - return internal::CallMethodWithArgs(isolate, obj, "emit", &converted_args); -} - -// obj.custom_emit(args...) -template -v8::Local CustomEmit(v8::Isolate* isolate, - v8::Local object, - const char* custom_emit, - Args&&... args) { - internal::ValueVector converted_args = { - ConvertToV8(isolate, std::forward(args))..., - }; - return internal::CallMethodWithArgs(isolate, object, custom_emit, - &converted_args); -} - -} // namespace mate - -#endif // SHELL_COMMON_API_EVENT_EMITTER_CALLER_DEPRECATED_H_ diff --git a/shell/common/api/remote/remote_object_freer.cc b/shell/common/api/remote/remote_object_freer.cc index 21ae01389a7..e82bbe5b717 100644 --- a/shell/common/api/remote/remote_object_freer.cc +++ b/shell/common/api/remote/remote_object_freer.cc @@ -7,10 +7,8 @@ #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "content/public/renderer/render_frame.h" -#include "electron/shell/common/api/api.mojom.h" -#include "electron/shell/common/native_mate_converters/blink_converter.h" -#include "electron/shell/common/native_mate_converters/value_converter.h" #include "services/service_manager/public/cpp/interface_provider.h" +#include "shell/common/api/api.mojom.h" #include "third_party/blink/public/web/web_local_frame.h" using blink::WebLocalFrame; diff --git a/shell/common/native_mate_converters/blink_converter.cc b/shell/common/gin_converters/blink_converter.cc similarity index 92% rename from shell/common/native_mate_converters/blink_converter.cc rename to shell/common/gin_converters/blink_converter.cc index 8e4df91ca47..31dea72d1b9 100644 --- a/shell/common/native_mate_converters/blink_converter.cc +++ b/shell/common/gin_converters/blink_converter.cc @@ -2,7 +2,7 @@ // 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/blink_converter.h" +#include "shell/common/gin_converters/blink_converter.h" #include #include @@ -14,10 +14,10 @@ #include "gin/converter.h" #include "mojo/public/cpp/base/values_mojom_traits.h" #include "mojo/public/mojom/base/values.mojom.h" -#include "native_mate/dictionary.h" #include "shell/common/deprecate_util.h" +#include "shell/common/gin_converters/value_converter.h" +#include "shell/common/gin_helper/dictionary.h" #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" @@ -39,7 +39,7 @@ int VectorToBitArray(const std::vector& vec) { } // namespace -namespace mate { +namespace gin { template <> struct Converter { @@ -149,7 +149,7 @@ struct Converter { blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate, v8::Local val) { blink::WebInputEvent::Type type = blink::WebInputEvent::kUndefined; - mate::Dictionary dict; + gin_helper::Dictionary dict; ConvertFromV8(isolate, val, &dict) && dict.Get("type", &type); return type; } @@ -157,7 +157,7 @@ blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate, bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, blink::WebInputEvent* out) { - mate::Dictionary dict; + gin_helper::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; blink::WebInputEvent::Type type; @@ -174,7 +174,7 @@ bool Converter::FromV8(v8::Isolate* isolate, bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, blink::WebKeyboardEvent* out) { - mate::Dictionary dict; + gin_helper::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; if (!ConvertFromV8(isolate, val, static_cast(out))) @@ -219,7 +219,7 @@ bool Converter::FromV8(v8::Isolate* isolate, bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, blink::WebMouseEvent* out) { - mate::Dictionary dict; + gin_helper::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; if (!ConvertFromV8(isolate, val, static_cast(out))) @@ -250,7 +250,7 @@ bool Converter::FromV8( v8::Isolate* isolate, v8::Local val, blink::WebMouseWheelEvent* out) { - mate::Dictionary dict; + gin_helper::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; if (!ConvertFromV8(isolate, val, static_cast(out))) @@ -285,7 +285,7 @@ bool Converter::FromV8( bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, blink::WebFloatPoint* out) { - mate::Dictionary dict; + gin_helper::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; return dict.Get("x", &out->x) && dict.Get("y", &out->y); @@ -296,7 +296,7 @@ struct Converter> { static bool FromV8(v8::Isolate* isolate, v8::Local val, base::Optional* out) { - mate::Dictionary dict; + gin_helper::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; blink::WebPoint point; @@ -311,7 +311,7 @@ struct Converter> { bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, blink::WebSize* out) { - mate::Dictionary dict; + gin_helper::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; return dict.Get("width", &out->width) && dict.Get("height", &out->height); @@ -321,7 +321,7 @@ bool Converter::FromV8( v8::Isolate* isolate, v8::Local val, blink::WebDeviceEmulationParams* out) { - mate::Dictionary dict; + gin_helper::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; @@ -350,19 +350,19 @@ v8::Local Converter::ToV8( const blink::WebContextMenuData::MediaType& in) { switch (in) { case blink::WebContextMenuData::kMediaTypeImage: - return mate::StringToV8(isolate, "image"); + return StringToV8(isolate, "image"); case blink::WebContextMenuData::kMediaTypeVideo: - return mate::StringToV8(isolate, "video"); + return StringToV8(isolate, "video"); case blink::WebContextMenuData::kMediaTypeAudio: - return mate::StringToV8(isolate, "audio"); + return StringToV8(isolate, "audio"); case blink::WebContextMenuData::kMediaTypeCanvas: - return mate::StringToV8(isolate, "canvas"); + return StringToV8(isolate, "canvas"); case blink::WebContextMenuData::kMediaTypeFile: - return mate::StringToV8(isolate, "file"); + return StringToV8(isolate, "file"); case blink::WebContextMenuData::kMediaTypePlugin: - return mate::StringToV8(isolate, "plugin"); + return StringToV8(isolate, "plugin"); default: - return mate::StringToV8(isolate, "none"); + return StringToV8(isolate, "none"); } } @@ -372,18 +372,18 @@ v8::Local Converter::ToV8( const blink::WebContextMenuData::InputFieldType& in) { switch (in) { case blink::WebContextMenuData::kInputFieldTypePlainText: - return mate::StringToV8(isolate, "plainText"); + return StringToV8(isolate, "plainText"); case blink::WebContextMenuData::kInputFieldTypePassword: - return mate::StringToV8(isolate, "password"); + return StringToV8(isolate, "password"); case blink::WebContextMenuData::kInputFieldTypeOther: - return mate::StringToV8(isolate, "other"); + return StringToV8(isolate, "other"); default: - return mate::StringToV8(isolate, "none"); + return StringToV8(isolate, "none"); } } v8::Local EditFlagsToV8(v8::Isolate* isolate, int editFlags) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); dict.Set("canUndo", !!(editFlags & blink::WebContextMenuData::kCanUndo)); dict.Set("canRedo", !!(editFlags & blink::WebContextMenuData::kCanRedo)); dict.Set("canCut", !!(editFlags & blink::WebContextMenuData::kCanCut)); @@ -403,11 +403,11 @@ v8::Local EditFlagsToV8(v8::Isolate* isolate, int editFlags) { dict.Set("canSelectAll", !!(editFlags & blink::WebContextMenuData::kCanSelectAll)); - return mate::ConvertToV8(isolate, dict); + return ConvertToV8(isolate, dict); } v8::Local MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); dict.Set("inError", !!(mediaFlags & blink::WebContextMenuData::kMediaInError)); dict.Set("isPaused", @@ -423,13 +423,13 @@ v8::Local MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags) { !!(mediaFlags & blink::WebContextMenuData::kMediaCanToggleControls)); dict.Set("canRotate", !!(mediaFlags & blink::WebContextMenuData::kMediaCanRotate)); - return mate::ConvertToV8(isolate, dict); + return ConvertToV8(isolate, dict); } v8::Local Converter::ToV8( v8::Isolate* isolate, const blink::WebCacheResourceTypeStat& stat) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); dict.Set("count", static_cast(stat.count)); dict.Set("size", static_cast(stat.size)); dict.Set("liveSize", static_cast(stat.decoded_size)); @@ -439,7 +439,7 @@ v8::Local Converter::ToV8( v8::Local Converter::ToV8( v8::Isolate* isolate, const blink::WebCacheResourceTypeStats& stats) { - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); dict.Set("images", stats.images); dict.Set("scripts", stats.scripts); dict.Set("cssStyleSheets", stats.css_style_sheets); @@ -455,24 +455,24 @@ v8::Local Converter::ToV8( const network::mojom::ReferrerPolicy& in) { switch (in) { case network::mojom::ReferrerPolicy::kDefault: - return mate::StringToV8(isolate, "default"); + return StringToV8(isolate, "default"); case network::mojom::ReferrerPolicy::kAlways: - return mate::StringToV8(isolate, "unsafe-url"); + return StringToV8(isolate, "unsafe-url"); case network::mojom::ReferrerPolicy::kNoReferrerWhenDowngrade: - return mate::StringToV8(isolate, "no-referrer-when-downgrade"); + return StringToV8(isolate, "no-referrer-when-downgrade"); case network::mojom::ReferrerPolicy::kNever: - return mate::StringToV8(isolate, "no-referrer"); + return StringToV8(isolate, "no-referrer"); case network::mojom::ReferrerPolicy::kOrigin: - return mate::StringToV8(isolate, "origin"); + return StringToV8(isolate, "origin"); case network::mojom::ReferrerPolicy:: kNoReferrerWhenDowngradeOriginWhenCrossOrigin: - return mate::StringToV8(isolate, "strict-origin-when-cross-origin"); + return StringToV8(isolate, "strict-origin-when-cross-origin"); case network::mojom::ReferrerPolicy::kSameOrigin: - return mate::StringToV8(isolate, "same-origin"); + return StringToV8(isolate, "same-origin"); case network::mojom::ReferrerPolicy::kStrictOrigin: - return mate::StringToV8(isolate, "strict-origin"); + return StringToV8(isolate, "strict-origin"); default: - return mate::StringToV8(isolate, "no-referrer"); + return StringToV8(isolate, "no-referrer"); } } @@ -523,7 +523,7 @@ class V8Serializer : public v8::ValueSerializer::Delegate { WriteTag(kOldSerializationTag); if (!WriteBaseValue(value)) { isolate_->ThrowException( - mate::StringToV8(isolate_, "An object could not be cloned.")); + StringToV8(isolate_, "An object could not be cloned.")); return false; } } else { @@ -684,4 +684,4 @@ bool Converter::FromV8(v8::Isolate* isolate, return V8Serializer(isolate).Serialize(val, out); } -} // namespace mate +} // namespace gin diff --git a/shell/common/native_mate_converters/blink_converter.h b/shell/common/gin_converters/blink_converter.h similarity index 93% rename from shell/common/native_mate_converters/blink_converter.h rename to shell/common/gin_converters/blink_converter.h index 2f8e418e558..2a2342fb378 100644 --- a/shell/common/native_mate_converters/blink_converter.h +++ b/shell/common/gin_converters/blink_converter.h @@ -2,10 +2,10 @@ // 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_BLINK_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_ +#ifndef SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_H_ +#define SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_H_ -#include "native_mate/converter.h" +#include "gin/converter.h" #include "third_party/blink/public/common/messaging/cloneable_message.h" #include "third_party/blink/public/common/web_cache/web_cache_resource_type_stats.h" #include "third_party/blink/public/platform/web_input_event.h" @@ -21,7 +21,7 @@ struct WebPoint; struct WebSize; } // namespace blink -namespace mate { +namespace gin { blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate, v8::Local val); @@ -130,6 +130,6 @@ struct Converter { v8::Local EditFlagsToV8(v8::Isolate* isolate, int editFlags); v8::Local MediaFlagsToV8(v8::Isolate* isolate, int mediaFlags); -} // namespace mate +} // namespace gin -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_ +#endif // SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_H_ diff --git a/shell/common/gin_converters/blink_converter_gin_adapter.h b/shell/common/gin_converters/blink_converter_gin_adapter.h deleted file mode 100644 index e0ca6a21df9..00000000000 --- a/shell/common/gin_converters/blink_converter_gin_adapter.h +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2019 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_GIN_ADAPTER_H_ -#define SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_GIN_ADAPTER_H_ - -#include "gin/converter.h" -#include "shell/common/native_mate_converters/blink_converter.h" - -// TODO(zcbenz): Move the implementations from native_mate_converters to here. - -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, - v8::Local val, - blink::CloneableMessage* out) { - return mate::ConvertFromV8(isolate, val, out); - } - static v8::Local ToV8(v8::Isolate* isolate, - const blink::CloneableMessage& val) { - return mate::ConvertToV8(isolate, val); - } -}; - -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/gin_converters/content_converter.cc b/shell/common/gin_converters/content_converter.cc index 0161a5112f5..8c192a1863d 100644 --- a/shell/common/gin_converters/content_converter.cc +++ b/shell/common/gin_converters/content_converter.cc @@ -12,7 +12,7 @@ #include "content/public/common/context_menu_params.h" #include "shell/browser/api/atom_api_web_contents.h" #include "shell/browser/web_contents_permission_helper.h" -#include "shell/common/gin_converters/blink_converter_gin_adapter.h" +#include "shell/common/gin_converters/blink_converter.h" #include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/gurl_converter.h" #include "shell/common/gin_helper/dictionary.h" @@ -128,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", mate::MediaFlagsToV8(isolate, params.media_flags)); + dict.Set("mediaFlags", 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", mate::EditFlagsToV8(isolate, params.edit_flags)); + dict.Set("editFlags", EditFlagsToV8(isolate, params.edit_flags)); dict.Set("selectionText", params.selection_text); dict.Set("titleText", params.title_text); dict.Set("misspelledWord", params.misspelled_word); diff --git a/shell/common/gin_converters/file_path_converter.h b/shell/common/gin_converters/file_path_converter.h index 3606929386c..31362229558 100644 --- a/shell/common/gin_converters/file_path_converter.h +++ b/shell/common/gin_converters/file_path_converter.h @@ -9,6 +9,7 @@ #include "gin/converter.h" namespace gin { + template <> struct Converter { static v8::Local ToV8(v8::Isolate* isolate, diff --git a/shell/common/gin_converters/net_converter.cc b/shell/common/gin_converters/net_converter.cc index 27551c6b5e1..fc1c24a6bca 100644 --- a/shell/common/gin_converters/net_converter.cc +++ b/shell/common/gin_converters/net_converter.cc @@ -14,10 +14,6 @@ #include "base/values.h" #include "gin/converter.h" #include "gin/dictionary.h" -#include "net/base/upload_bytes_element_reader.h" -#include "net/base/upload_data_stream.h" -#include "net/base/upload_element_reader.h" -#include "net/base/upload_file_element_reader.h" #include "net/cert/x509_certificate.h" #include "net/cert/x509_util.h" #include "net/http/http_response_headers.h" @@ -25,7 +21,7 @@ #include "shell/browser/api/atom_api_data_pipe_holder.h" #include "shell/common/gin_converters/gurl_converter.h" #include "shell/common/gin_converters/std_converter.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/node_includes.h" namespace gin { @@ -364,57 +360,3 @@ v8::Local Converter::ToV8( } } // namespace gin - -namespace electron { - -void FillRequestDetails(base::DictionaryValue* details, - const net::URLRequest* request) { - details->SetString("method", request->method()); - std::string url; - if (!request->url_chain().empty()) - url = request->url().spec(); - details->SetKey("url", base::Value(url)); - details->SetString("referrer", request->referrer()); - auto list = std::make_unique(); - GetUploadData(list.get(), request); - if (!list->empty()) - details->Set("uploadData", std::move(list)); - auto headers_value = std::make_unique(); - for (net::HttpRequestHeaders::Iterator it(request->extra_request_headers()); - it.GetNext();) { - headers_value->SetString(it.name(), it.value()); - } - details->Set("headers", std::move(headers_value)); -} - -void GetUploadData(base::ListValue* upload_data_list, - const net::URLRequest* request) { - const net::UploadDataStream* upload_data = request->get_upload_for_testing(); - if (!upload_data) - return; - const std::vector>* readers = - upload_data->GetElementReaders(); - for (const auto& reader : *readers) { - auto upload_data_dict = std::make_unique(); - if (reader->AsBytesReader()) { - const net::UploadBytesElementReader* bytes_reader = - reader->AsBytesReader(); - auto bytes = std::make_unique( - std::vector(bytes_reader->bytes(), - bytes_reader->bytes() + bytes_reader->length())); - upload_data_dict->Set("bytes", std::move(bytes)); - } else if (reader->AsFileReader()) { - const net::UploadFileElementReader* file_reader = reader->AsFileReader(); - auto file_path = file_reader->path().AsUTF8Unsafe(); - upload_data_dict->SetKey("file", base::Value(file_path)); - } - // else { - // const storage::UploadBlobElementReader* blob_reader = - // static_cast(reader.get()); - // upload_data_dict->SetString("blobUUID", blob_reader->uuid()); - // } - upload_data_list->Append(std::move(upload_data_dict)); - } -} - -} // namespace electron diff --git a/shell/common/gin_converters/net_converter.h b/shell/common/gin_converters/net_converter.h index b5065842998..a3e9a382a32 100644 --- a/shell/common/gin_converters/net_converter.h +++ b/shell/common/gin_converters/net_converter.h @@ -5,7 +5,6 @@ #ifndef SHELL_COMMON_GIN_CONVERTERS_NET_CONVERTER_H_ #define SHELL_COMMON_GIN_CONVERTERS_NET_CONVERTER_H_ -#include "base/memory/ref_counted.h" #include "gin/converter.h" #include "shell/browser/net/cert_verifier_client.h" @@ -99,14 +98,4 @@ struct Converter { } // namespace gin -namespace electron { - -void FillRequestDetails(base::DictionaryValue* details, - const net::URLRequest* request); - -void GetUploadData(base::ListValue* upload_data_list, - const net::URLRequest* request); - -} // namespace electron - #endif // SHELL_COMMON_GIN_CONVERTERS_NET_CONVERTER_H_ diff --git a/shell/common/native_mate_converters/value_converter.cc b/shell/common/gin_converters/value_converter.cc similarity index 93% rename from shell/common/native_mate_converters/value_converter.cc rename to shell/common/gin_converters/value_converter.cc index d3b384c9626..6ae101c7f46 100644 --- a/shell/common/native_mate_converters/value_converter.cc +++ b/shell/common/gin_converters/value_converter.cc @@ -2,15 +2,15 @@ // 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/value_converter.h" +#include "shell/common/gin_converters/value_converter.h" #include #include #include "base/values.h" -#include "shell/common/native_mate_converters/v8_value_converter.h" +#include "shell/common/v8_value_converter.h" -namespace mate { +namespace gin { bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, @@ -74,4 +74,4 @@ v8::Local Converter::ToV8( return converter.ToV8Value(&val, isolate->GetCurrentContext()); } -} // namespace mate +} // namespace gin diff --git a/shell/common/native_mate_converters/value_converter.h b/shell/common/gin_converters/value_converter.h similarity index 54% rename from shell/common/native_mate_converters/value_converter.h rename to shell/common/gin_converters/value_converter.h index 5d0495808a0..d8c42d100a6 100644 --- a/shell/common/native_mate_converters/value_converter.h +++ b/shell/common/gin_converters/value_converter.h @@ -2,12 +2,10 @@ // 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_VALUE_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_VALUE_CONVERTER_H_ +#ifndef SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_H_ +#define SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_H_ -#include "native_mate/converter.h" - -#include "base/optional.h" +#include "gin/converter.h" namespace base { class DictionaryValue; @@ -15,7 +13,7 @@ class ListValue; class Value; } // namespace base -namespace mate { +namespace gin { template <> struct Converter { @@ -35,29 +33,6 @@ struct Converter { const base::Value& val); }; -template -struct Converter> { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - base::Optional* out) { - if (val->IsNull() || val->IsUndefined()) { - return true; - } - T converted; - if (Converter::FromV8(isolate, val, &converted)) { - return true; - } - out->emplace(converted); - return true; - } - static v8::Local ToV8(v8::Isolate* isolate, - const base::Optional& val) { - if (val.has_value()) - return Converter::ToV8(val.value()); - return v8::Undefined(isolate); - } -}; - template <> struct Converter { static bool FromV8(v8::Isolate* isolate, @@ -67,6 +42,6 @@ struct Converter { const base::ListValue& val); }; -} // namespace mate +} // namespace gin -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_VALUE_CONVERTER_H_ +#endif // SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_H_ diff --git a/shell/common/gin_converters/value_converter_gin_adapter.h b/shell/common/gin_converters/value_converter_gin_adapter.h deleted file mode 100644 index e0baecd61ef..00000000000 --- a/shell/common/gin_converters/value_converter_gin_adapter.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2019 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_GIN_ADAPTER_H_ -#define SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_GIN_ADAPTER_H_ - -#include "gin/converter.h" -#include "shell/common/native_mate_converters/value_converter.h" - -// TODO(zcbenz): Move the implementations from native_mate_converters to here. - -namespace gin { - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - base::DictionaryValue* out) { - return mate::ConvertFromV8(isolate, val, out); - } - static v8::Local ToV8(v8::Isolate* isolate, - const base::DictionaryValue& val) { - return mate::ConvertToV8(isolate, val); - } -}; - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - base::ListValue* out) { - return mate::ConvertFromV8(isolate, val, out); - } - static v8::Local ToV8(v8::Isolate* isolate, - const base::ListValue& val) { - return mate::ConvertToV8(isolate, val); - } -}; - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - base::Value* out) { - return mate::ConvertFromV8(isolate, val, out); - } - static v8::Local ToV8(v8::Isolate* isolate, - const base::Value& in) { - return mate::ConvertToV8(isolate, in); - } -}; - -} // namespace gin - -#endif // SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_GIN_ADAPTER_H_ diff --git a/shell/common/gin_helper/callback.cc b/shell/common/gin_helper/callback.cc index 5425632d567..f75276120b0 100644 --- a/shell/common/gin_helper/callback.cc +++ b/shell/common/gin_helper/callback.cc @@ -69,7 +69,7 @@ void CallTranslater(v8::Local external, struct DeleteOnUIThread { template static void Destruct(const T* x) { - if (mate::Locker::IsBrowserProcess() && + if (gin_helper::Locker::IsBrowserProcess() && !content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE, x); diff --git a/shell/common/gin_helper/callback.h b/shell/common/gin_helper/callback.h index 5175fd30421..97061886ac4 100644 --- a/shell/common/gin_helper/callback.h +++ b/shell/common/gin_helper/callback.h @@ -9,9 +9,9 @@ #include #include "base/bind.h" -#include "shell/common/api/locker.h" #include "shell/common/gin_converters/std_converter.h" #include "shell/common/gin_helper/function_template.h" +#include "shell/common/gin_helper/locker.h" // Implements safe convertions between JS functions and base::Callback. @@ -43,7 +43,7 @@ struct V8FunctionInvoker(ArgTypes...)> { static v8::Local Go(v8::Isolate* isolate, const SafeV8Function& function, ArgTypes... raw) { - mate::Locker locker(isolate); + gin_helper::Locker locker(isolate); v8::EscapableHandleScope handle_scope(isolate); if (!function.IsAlive()) return v8::Null(isolate); @@ -68,7 +68,7 @@ struct V8FunctionInvoker { static void Go(v8::Isolate* isolate, const SafeV8Function& function, ArgTypes... raw) { - mate::Locker locker(isolate); + gin_helper::Locker locker(isolate); v8::HandleScope handle_scope(isolate); if (!function.IsAlive()) return; @@ -91,7 +91,7 @@ struct V8FunctionInvoker { static ReturnType Go(v8::Isolate* isolate, const SafeV8Function& function, ArgTypes... raw) { - mate::Locker locker(isolate); + gin_helper::Locker locker(isolate); v8::HandleScope handle_scope(isolate); ReturnType ret = ReturnType(); if (!function.IsAlive()) diff --git a/shell/common/gin_helper/dictionary.h b/shell/common/gin_helper/dictionary.h index 752a884ccfe..eac30d96211 100644 --- a/shell/common/gin_helper/dictionary.h +++ b/shell/common/gin_helper/dictionary.h @@ -108,6 +108,26 @@ class Dictionary : public gin::Dictionary { return !result.IsNothing() && result.FromJust(); } + // Note: If we plan to add more Set methods, consider adding an option instead + // of copying code. + template + bool SetReadOnlyNonConfigurable(base::StringPiece key, T val) { + v8::Local v8_value; + if (!gin::TryConvertToV8(isolate(), val, &v8_value)) + return false; + v8::Maybe result = GetHandle()->DefineOwnProperty( + isolate()->GetCurrentContext(), gin::StringToV8(isolate(), key), + v8_value, + static_cast(v8::ReadOnly | v8::DontDelete)); + return !result.IsNothing() && result.FromJust(); + } + + bool Has(base::StringPiece key) const { + v8::Maybe result = GetHandle()->Has(isolate()->GetCurrentContext(), + gin::StringToV8(isolate(), key)); + return !result.IsNothing() && result.FromJust(); + } + bool Delete(base::StringPiece key) { v8::Maybe result = GetHandle()->Delete( isolate()->GetCurrentContext(), gin::StringToV8(isolate(), key)); diff --git a/shell/common/gin_helper/event_emitter.cc b/shell/common/gin_helper/event_emitter.cc index 596a81b8110..0737b48802e 100644 --- a/shell/common/gin_helper/event_emitter.cc +++ b/shell/common/gin_helper/event_emitter.cc @@ -68,11 +68,10 @@ v8::Local CreateNativeEvent( v8::Isolate* isolate, v8::Local sender, content::RenderFrameHost* frame, - base::Optional - callback) { + electron::mojom::ElectronBrowser::MessageSyncCallback callback) { v8::Local event; if (frame && callback) { - mate::Handle native_event = mate::Event::Create(isolate); + gin::Handle native_event = Event::Create(isolate); native_event->SetCallback(std::move(callback)); event = v8::Local::Cast(native_event.ToV8()); } else { diff --git a/shell/common/gin_helper/event_emitter.h b/shell/common/gin_helper/event_emitter.h index 3213c339bc7..e5799075730 100644 --- a/shell/common/gin_helper/event_emitter.h +++ b/shell/common/gin_helper/event_emitter.h @@ -8,7 +8,6 @@ #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" @@ -31,8 +30,7 @@ v8::Local CreateNativeEvent( v8::Isolate* isolate, v8::Local sender, content::RenderFrameHost* frame, - base::Optional - callback); + electron::mojom::ElectronBrowser::MessageSyncCallback callback); } // namespace internal @@ -83,11 +81,10 @@ class EventEmitter : public mate::Wrappable { // this.emit(name, new Event(sender, message), args...); template - bool EmitWithSender( - base::StringPiece name, - content::RenderFrameHost* sender, - base::Optional callback, - Args&&... args) { + bool EmitWithSender(base::StringPiece name, + content::RenderFrameHost* sender, + electron::mojom::ElectronBrowser::InvokeCallback callback, + Args&&... args) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); diff --git a/shell/common/gin_helper/event_emitter_caller.cc b/shell/common/gin_helper/event_emitter_caller.cc index f57048e4545..c19479c85fd 100644 --- a/shell/common/gin_helper/event_emitter_caller.cc +++ b/shell/common/gin_helper/event_emitter_caller.cc @@ -4,7 +4,7 @@ #include "shell/common/gin_helper/event_emitter_caller.h" -#include "shell/common/api/locker.h" +#include "shell/common/gin_helper/locker.h" #include "shell/common/node_includes.h" namespace gin_helper { diff --git a/shell/common/api/locker.cc b/shell/common/gin_helper/locker.cc similarity index 77% rename from shell/common/api/locker.cc rename to shell/common/gin_helper/locker.cc index b3770794001..0c7be54cd4e 100644 --- a/shell/common/api/locker.cc +++ b/shell/common/gin_helper/locker.cc @@ -2,11 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE.chromium file. -#include "shell/common/api/locker.h" +#include "shell/common/gin_helper/locker.h" -#include - -namespace mate { +namespace gin_helper { Locker::Locker(v8::Isolate* isolate) { if (IsBrowserProcess()) @@ -15,4 +13,4 @@ Locker::Locker(v8::Isolate* isolate) { Locker::~Locker() = default; -} // namespace mate +} // namespace gin_helper diff --git a/shell/common/api/locker.h b/shell/common/gin_helper/locker.h similarity index 81% rename from shell/common/api/locker.h rename to shell/common/gin_helper/locker.h index 6cafa9fe81e..32c9c626ea9 100644 --- a/shell/common/api/locker.h +++ b/shell/common/gin_helper/locker.h @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE.chromium file. -#ifndef SHELL_COMMON_API_LOCKER_H_ -#define SHELL_COMMON_API_LOCKER_H_ +#ifndef SHELL_COMMON_GIN_HELPER_LOCKER_H_ +#define SHELL_COMMON_GIN_HELPER_LOCKER_H_ #include #include "base/macros.h" #include "v8/include/v8.h" -namespace mate { +namespace gin_helper { // Only lock when lockers are used in current thread. class Locker { @@ -31,6 +31,6 @@ class Locker { DISALLOW_COPY_AND_ASSIGN(Locker); }; -} // namespace mate +} // namespace gin_helper -#endif // SHELL_COMMON_API_LOCKER_H_ +#endif // SHELL_COMMON_GIN_HELPER_LOCKER_H_ diff --git a/shell/common/gin_helper/persistent_dictionary.cc b/shell/common/gin_helper/persistent_dictionary.cc new file mode 100644 index 00000000000..c999f6fac80 --- /dev/null +++ b/shell/common/gin_helper/persistent_dictionary.cc @@ -0,0 +1,32 @@ +// Copyright 2014 Cheng Zhao. All rights reserved. +// Use of this source code is governed by MIT license that can be found in the +// LICENSE file. + +#include "shell/common/gin_helper/persistent_dictionary.h" + +namespace gin_helper { + +PersistentDictionary::PersistentDictionary() = default; + +PersistentDictionary::PersistentDictionary(v8::Isolate* isolate, + v8::Local object) + : isolate_(isolate), handle_(isolate, object) {} + +PersistentDictionary::PersistentDictionary(const PersistentDictionary& other) + : isolate_(other.isolate_), + handle_(isolate_, v8::Local::New(isolate_, other.handle_)) {} + +PersistentDictionary::~PersistentDictionary() = default; + +PersistentDictionary& PersistentDictionary::operator=( + const PersistentDictionary& other) { + isolate_ = other.isolate_; + handle_.Reset(isolate_, v8::Local::New(isolate_, other.handle_)); + return *this; +} + +v8::Local PersistentDictionary::GetHandle() const { + return v8::Local::New(isolate_, handle_); +} + +} // namespace gin_helper diff --git a/shell/common/gin_helper/persistent_dictionary.h b/shell/common/gin_helper/persistent_dictionary.h new file mode 100644 index 00000000000..c201bf23cb9 --- /dev/null +++ b/shell/common/gin_helper/persistent_dictionary.h @@ -0,0 +1,64 @@ +// Copyright 2014 Cheng Zhao. All rights reserved. +// Use of this source code is governed by MIT license that can be found in the +// LICENSE file. + +#ifndef SHELL_COMMON_GIN_HELPER_PERSISTENT_DICTIONARY_H_ +#define SHELL_COMMON_GIN_HELPER_PERSISTENT_DICTIONARY_H_ + +#include "shell/common/gin_helper/dictionary.h" + +namespace gin_helper { + +// Like Dictionary, but stores object in persistent handle so you can keep it +// safely on heap. +// +// TODO(zcbenz): The only user of this class is AtomTouchBar, we should migrate +// away from this class. +class PersistentDictionary { + public: + PersistentDictionary(); + PersistentDictionary(v8::Isolate* isolate, v8::Local object); + PersistentDictionary(const PersistentDictionary& other); + ~PersistentDictionary(); + + PersistentDictionary& operator=(const PersistentDictionary& other); + + v8::Local GetHandle() const; + + template + bool Get(const K& key, V* out) const { + v8::Local context = isolate_->GetCurrentContext(); + v8::Local v8_key = gin::ConvertToV8(isolate_, key); + v8::Local value; + v8::Maybe result = GetHandle()->Has(context, v8_key); + if (result.IsJust() && result.FromJust() && + GetHandle()->Get(context, v8_key).ToLocal(&value)) + return gin::ConvertFromV8(isolate_, value, out); + return false; + } + + private: + v8::Isolate* isolate_ = nullptr; + v8::Global handle_; +}; + +} // namespace gin_helper + +namespace gin { + +template <> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + gin_helper::PersistentDictionary* out) { + if (!val->IsObject()) + return false; + *out = gin_helper::PersistentDictionary(isolate, + v8::Local::Cast(val)); + return true; + } +}; + +} // namespace gin + +#endif // SHELL_COMMON_GIN_HELPER_PERSISTENT_DICTIONARY_H_ diff --git a/shell/common/gin_helper/trackable_object.cc b/shell/common/gin_helper/trackable_object.cc index 61297b269a1..438a565bfa8 100644 --- a/shell/common/gin_helper/trackable_object.cc +++ b/shell/common/gin_helper/trackable_object.cc @@ -9,7 +9,7 @@ #include "base/bind.h" #include "base/supports_user_data.h" #include "shell/browser/atom_browser_main_parts.h" -#include "shell/common/api/locker.h" +#include "shell/common/gin_helper/locker.h" namespace gin_helper { @@ -33,7 +33,7 @@ class IDUserData : public base::SupportsUserData::Data { TrackableObjectBase::TrackableObjectBase() : weak_factory_(this) { // TODO(zcbenz): Make TrackedObject work in renderer process. - DCHECK(mate::Locker::IsBrowserProcess()) + DCHECK(gin_helper::Locker::IsBrowserProcess()) << "This class only works for browser process"; electron::AtomBrowserMainParts::Get()->RegisterDestructionCallback( diff --git a/shell/common/native_mate_converters/callback_converter_deprecated.cc b/shell/common/native_mate_converters/callback_converter_deprecated.cc deleted file mode 100644 index c1fbe3fd526..00000000000 --- a/shell/common/native_mate_converters/callback_converter_deprecated.cc +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (c) 2015 GitHub, Inc. All rights reserved. -// 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/callback_converter_deprecated.h" -#include "base/stl_util.h" -#include "content/public/browser/browser_thread.h" - -#include "native_mate/dictionary.h" - -using content::BrowserThread; - -namespace mate { - -namespace internal { - -namespace { - -struct TranslaterHolder { - explicit TranslaterHolder(v8::Isolate* isolate) - : handle(isolate, v8::External::New(isolate, this)) { - handle.SetWeak(this, &GC, v8::WeakCallbackType::kFinalizer); - } - ~TranslaterHolder() { - if (!handle.IsEmpty()) { - handle.ClearWeak(); - handle.Reset(); - } - } - - static void GC(const v8::WeakCallbackInfo& data) { - delete data.GetParameter(); - } - - v8::Global handle; - Translater translater; -}; - -// Cached JavaScript version of |CallTranslater|. -v8::Persistent g_call_translater; - -void CallTranslater(v8::Local external, - v8::Local state, - mate::Arguments* args) { - // Whether the callback should only be called for once. - v8::Isolate* isolate = args->isolate(); - auto context = isolate->GetCurrentContext(); - bool one_time = - state->Has(context, mate::StringToSymbol(isolate, "oneTime")).ToChecked(); - - // Check if the callback has already been called. - if (one_time) { - auto called_symbol = mate::StringToSymbol(isolate, "called"); - if (state->Has(context, called_symbol).ToChecked()) { - args->ThrowError("callback can only be called for once"); - return; - } else { - state->Set(context, called_symbol, v8::Boolean::New(isolate, true)) - .ToChecked(); - } - } - - TranslaterHolder* holder = static_cast(external->Value()); - holder->translater.Run(args); - - // Free immediately for one-time callback. - if (one_time) - delete holder; -} - -} // namespace - -// Destroy the class on UI thread when possible. -struct DeleteOnUIThread { - template - static void Destruct(const T* x) { - if (Locker::IsBrowserProcess() && - !BrowserThread::CurrentlyOn(BrowserThread::UI)) { - BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, x); - } else { - delete x; - } - } -}; - -// Like v8::Global, but ref-counted. -template -class RefCountedGlobal - : public base::RefCountedThreadSafe, DeleteOnUIThread> { - public: - RefCountedGlobal(v8::Isolate* isolate, v8::Local value) - : handle_(isolate, v8::Local::Cast(value)) {} - - bool IsAlive() const { return !handle_.IsEmpty(); } - - v8::Local NewHandle(v8::Isolate* isolate) const { - return v8::Local::New(isolate, handle_); - } - - private: - v8::Global handle_; - - DISALLOW_COPY_AND_ASSIGN(RefCountedGlobal); -}; - -SafeV8Function::SafeV8Function(v8::Isolate* isolate, v8::Local value) - : v8_function_(new RefCountedGlobal(isolate, value)) {} - -SafeV8Function::SafeV8Function(const SafeV8Function& other) = default; - -SafeV8Function::~SafeV8Function() = default; - -bool SafeV8Function::IsAlive() const { - return v8_function_.get() && v8_function_->IsAlive(); -} - -v8::Local SafeV8Function::NewHandle(v8::Isolate* isolate) const { - return v8_function_->NewHandle(isolate); -} - -v8::Local CreateFunctionFromTranslater(v8::Isolate* isolate, - const Translater& translater, - bool one_time) { - // The FunctionTemplate is cached. - if (g_call_translater.IsEmpty()) - g_call_translater.Reset(isolate, - mate::CreateFunctionTemplate( - isolate, base::BindRepeating(&CallTranslater))); - - v8::Local call_translater = - v8::Local::New(isolate, g_call_translater); - auto* holder = new TranslaterHolder(isolate); - holder->translater = translater; - Dictionary state = mate::Dictionary::CreateEmpty(isolate); - if (one_time) - state.Set("oneTime", true); - auto context = isolate->GetCurrentContext(); - return BindFunctionWith( - isolate, context, call_translater->GetFunction(context).ToLocalChecked(), - holder->handle.Get(isolate), state.GetHandle()); -} - -// func.bind(func, arg1). -// NB(zcbenz): Using C++11 version crashes VS. -v8::Local BindFunctionWith(v8::Isolate* isolate, - v8::Local context, - v8::Local func, - v8::Local arg1, - v8::Local arg2) { - v8::MaybeLocal bind = - func->Get(context, mate::StringToV8(isolate, "bind")); - CHECK(!bind.IsEmpty()); - v8::Local bind_func = - v8::Local::Cast(bind.ToLocalChecked()); - v8::Local converted[] = {func, arg1, arg2}; - return bind_func->Call(context, func, base::size(converted), converted) - .ToLocalChecked(); -} - -} // namespace internal - -} // namespace mate diff --git a/shell/common/native_mate_converters/callback_converter_deprecated.h b/shell/common/native_mate_converters/callback_converter_deprecated.h deleted file mode 100644 index 7edd21bde6a..00000000000 --- a/shell/common/native_mate_converters/callback_converter_deprecated.h +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright (c) 2015 GitHub, Inc. All rights reserved. -// 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_CALLBACK_CONVERTER_DEPRECATED_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_CALLBACK_CONVERTER_DEPRECATED_H_ - -#include -#include - -#include "base/bind.h" -#include "base/callback.h" -#include "base/memory/weak_ptr.h" -#include "base/message_loop/message_loop.h" -#include "native_mate/function_template.h" -#include "native_mate/scoped_persistent.h" -#include "shell/common/api/locker.h" - -// =============================== NOTICE =============================== -// Do not add code here, native_mate is being removed. Any new code -// should use gin instead. - -namespace mate { - -namespace internal { - -template -class RefCountedGlobal; - -// Manages the V8 function with RAII. -class SafeV8Function { - public: - SafeV8Function(v8::Isolate* isolate, v8::Local value); - SafeV8Function(const SafeV8Function& other); - ~SafeV8Function(); - - bool IsAlive() const; - v8::Local NewHandle(v8::Isolate* isolate) const; - - private: - scoped_refptr> v8_function_; -}; - -// Helper to invoke a V8 function with C++ parameters. -template -struct V8FunctionInvoker {}; - -template -struct V8FunctionInvoker(ArgTypes...)> { - static v8::Local Go(v8::Isolate* isolate, - const SafeV8Function& function, - ArgTypes... raw) { - Locker locker(isolate); - v8::EscapableHandleScope handle_scope(isolate); - if (!function.IsAlive()) - return v8::Null(isolate); - v8::MicrotasksScope script_scope(isolate, - v8::MicrotasksScope::kRunMicrotasks); - v8::Local holder = function.NewHandle(isolate); - v8::Local context = holder->CreationContext(); - v8::Context::Scope context_scope(context); - std::vector> args{ - ConvertToV8(isolate, std::forward(raw))...}; - v8::MaybeLocal ret = holder->Call( - context, holder, args.size(), args.empty() ? nullptr : &args.front()); - if (ret.IsEmpty()) - return v8::Undefined(isolate); - else - return handle_scope.Escape(ret.ToLocalChecked()); - } -}; - -template -struct V8FunctionInvoker { - static void Go(v8::Isolate* isolate, - const SafeV8Function& function, - ArgTypes... raw) { - Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - if (!function.IsAlive()) - return; - v8::MicrotasksScope script_scope(isolate, - v8::MicrotasksScope::kRunMicrotasks); - v8::Local holder = function.NewHandle(isolate); - v8::Local context = holder->CreationContext(); - v8::Context::Scope context_scope(context); - std::vector> args{ - ConvertToV8(isolate, std::forward(raw))...}; - holder - ->Call(context, holder, args.size(), - args.empty() ? nullptr : &args.front()) - .IsEmpty(); - } -}; - -template -struct V8FunctionInvoker { - static ReturnType Go(v8::Isolate* isolate, - const SafeV8Function& function, - ArgTypes... raw) { - Locker locker(isolate); - v8::HandleScope handle_scope(isolate); - ReturnType ret = ReturnType(); - if (!function.IsAlive()) - return ret; - v8::MicrotasksScope script_scope(isolate, - v8::MicrotasksScope::kRunMicrotasks); - v8::Local holder = function.NewHandle(isolate); - v8::Local context = holder->CreationContext(); - v8::Context::Scope context_scope(context); - std::vector> args{ - ConvertToV8(isolate, std::forward(raw))...}; - v8::Local result; - auto maybe_result = holder->Call(context, holder, args.size(), - args.empty() ? nullptr : &args.front()); - if (maybe_result.ToLocal(&result)) - Converter::FromV8(isolate, result, &ret); - return ret; - } -}; - -// Helper to pass a C++ funtion to JavaScript. -using Translater = base::Callback; -v8::Local CreateFunctionFromTranslater(v8::Isolate* isolate, - const Translater& translater, - bool one_time); -v8::Local BindFunctionWith(v8::Isolate* isolate, - v8::Local context, - v8::Local func, - v8::Local arg1, - v8::Local arg2); - -// Calls callback with Arguments. -template -struct NativeFunctionInvoker {}; - -template -struct NativeFunctionInvoker { - static void Go(base::Callback val, Arguments* args) { - using Indices = typename IndicesGenerator::type; - Invoker invoker(args, 0); - if (invoker.IsOK()) - invoker.DispatchToCallback(val); - } -}; - -} // namespace internal - -template -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - const base::RepeatingCallback& val) { - // We don't use CreateFunctionTemplate here because it creates a new - // FunctionTemplate everytime, which is cached by V8 and causes leaks. - internal::Translater translater = - base::Bind(&internal::NativeFunctionInvoker::Go, val); - // To avoid memory leak, we ensure that the callback can only be called - // for once. - return internal::CreateFunctionFromTranslater(isolate, translater, true); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - base::RepeatingCallback* out) { - if (!val->IsFunction()) - return false; - - *out = base::BindRepeating(&internal::V8FunctionInvoker::Go, isolate, - internal::SafeV8Function(isolate, val)); - return true; - } -}; - -// Convert a callback to V8 without the call number limitation, this can easily -// cause memory leaks so use it with caution. -template -v8::Local CallbackToV8(v8::Isolate* isolate, - const base::Callback& val) { - internal::Translater translater = - base::Bind(&internal::NativeFunctionInvoker::Go, val); - return internal::CreateFunctionFromTranslater(isolate, translater, false); -} - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_CALLBACK_CONVERTER_DEPRECATED_H_ diff --git a/shell/common/native_mate_converters/file_dialog_converter.h b/shell/common/native_mate_converters/file_dialog_converter.h deleted file mode 100644 index 5a7b7b40d1b..00000000000 --- a/shell/common/native_mate_converters/file_dialog_converter.h +++ /dev/null @@ -1,41 +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_COMMON_NATIVE_MATE_CONVERTERS_FILE_DIALOG_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_FILE_DIALOG_CONVERTER_H_ - -#include "native_mate/converter.h" -#include "shell/common/gin_converters/file_dialog_converter.h" - -namespace mate { - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const file_dialog::Filter& in) { - return gin::ConvertToV8(isolate, in); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - file_dialog::Filter* out) { - return gin::ConvertFromV8(isolate, val, out); - } -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const file_dialog::DialogSettings& in) { - return gin::ConvertToV8(isolate, in); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - file_dialog::DialogSettings* out) { - return gin::ConvertFromV8(isolate, val, out); - } -}; - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_FILE_DIALOG_CONVERTER_H_ diff --git a/shell/common/native_mate_converters/file_path_converter.h b/shell/common/native_mate_converters/file_path_converter.h deleted file mode 100644 index 3b6e1ebe88a..00000000000 --- a/shell/common/native_mate_converters/file_path_converter.h +++ /dev/null @@ -1,28 +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_COMMON_NATIVE_MATE_CONVERTERS_FILE_PATH_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_FILE_PATH_CONVERTER_H_ - -#include "shell/common/gin_converters/file_path_converter.h" - -namespace mate { - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const base::FilePath& val) { - return gin::Converter::ToV8(isolate, - val.value()); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - base::FilePath* out) { - return gin::Converter::FromV8(isolate, val, out); - } -}; - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_FILE_PATH_CONVERTER_H_ diff --git a/shell/common/native_mate_converters/gurl_converter.h b/shell/common/native_mate_converters/gurl_converter.h deleted file mode 100644 index 863ad9c1030..00000000000 --- a/shell/common/native_mate_converters/gurl_converter.h +++ /dev/null @@ -1,27 +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_COMMON_NATIVE_MATE_CONVERTERS_GURL_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_GURL_CONVERTER_H_ - -#include "native_mate/converter.h" -#include "shell/common/gin_converters/gurl_converter.h" - -namespace mate { - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, const GURL& val) { - return gin::ConvertToV8(isolate, val); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - GURL* out) { - return gin::ConvertFromV8(isolate, val, out); - } -}; - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_GURL_CONVERTER_H_ diff --git a/shell/common/native_mate_converters/image_converter.h b/shell/common/native_mate_converters/image_converter.h deleted file mode 100644 index befa1c50ec3..00000000000 --- a/shell/common/native_mate_converters/image_converter.h +++ /dev/null @@ -1,37 +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_COMMON_NATIVE_MATE_CONVERTERS_IMAGE_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_IMAGE_CONVERTER_H_ - -#include "native_mate/converter.h" -#include "shell/common/gin_converters/image_converter.h" - -namespace mate { - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - gfx::ImageSkia* out) { - return gin::ConvertFromV8(isolate, val, out); - } -}; - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - gfx::Image* out) { - return gin::ConvertFromV8(isolate, val, out); - } - static v8::Local ToV8(v8::Isolate* isolate, - const gfx::Image& val) { - return gin::ConvertToV8(isolate, val); - } -}; - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_IMAGE_CONVERTER_H_ diff --git a/shell/common/native_mate_converters/native_window_converter.h b/shell/common/native_mate_converters/native_window_converter.h deleted file mode 100644 index 454fd68aefe..00000000000 --- a/shell/common/native_mate_converters/native_window_converter.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2019 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_NATIVE_WINDOW_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_NATIVE_WINDOW_CONVERTER_H_ - -#include "native_mate/converter.h" -#include "shell/common/gin_converters/native_window_converter.h" - -namespace mate { - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - electron::NativeWindow** out) { - return gin::ConvertFromV8(isolate, val, out); - } -}; - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_NATIVE_WINDOW_CONVERTER_H_ diff --git a/shell/common/native_mate_converters/net_converter.h b/shell/common/native_mate_converters/net_converter.h deleted file mode 100644 index 5a7c2eecab2..00000000000 --- a/shell/common/native_mate_converters/net_converter.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2015 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_NET_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_NET_CONVERTER_H_ - -#include "native_mate/converter.h" -#include "shell/common/gin_converters/net_converter.h" - -namespace mate { - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const net::AuthChallengeInfo& val) { - return gin::ConvertToV8(isolate, val); - } -}; - -template <> -struct Converter> { - static v8::Local ToV8( - v8::Isolate* isolate, - const scoped_refptr& val) { - return gin::ConvertToV8(isolate, val); - } - - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - scoped_refptr* out) { - return gin::ConvertFromV8(isolate, val, out); - } -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const net::CertPrincipal& val) { - return gin::ConvertToV8(isolate, val); - } -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - net::HttpResponseHeaders* headers) { - return gin::ConvertToV8(isolate, headers); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - net::HttpResponseHeaders* out) { - return gin::Converter::FromV8(isolate, val, out); - } -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const network::ResourceRequest& val) { - return gin::ConvertToV8(isolate, val); - } -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - electron::VerifyRequestParams val) { - return gin::ConvertToV8(isolate, val); - } -}; - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_NET_CONVERTER_H_ diff --git a/shell/common/native_mate_converters/once_callback.h b/shell/common/native_mate_converters/once_callback.h deleted file mode 100644 index cb8e46e2563..00000000000 --- a/shell/common/native_mate_converters/once_callback.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2019 GitHub, Inc. All rights reserved. -// 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_ONCE_CALLBACK_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_ONCE_CALLBACK_H_ - -#include - -#include "shell/common/native_mate_converters/callback_converter_deprecated.h" - -namespace mate { - -namespace internal { - -// Manages the OnceCallback with ref-couting. -template -class RefCountedOnceCallback - : public base::RefCounted> { - public: - explicit RefCountedOnceCallback(base::OnceCallback callback) - : callback_(std::move(callback)) {} - - base::OnceCallback GetCallback() { return std::move(callback_); } - - private: - friend class base::RefCounted>; - ~RefCountedOnceCallback() = default; - - base::OnceCallback callback_; -}; - -// Invokes the OnceCallback. -template -struct InvokeOnceCallback {}; - -template -struct InvokeOnceCallback { - static void Go( - scoped_refptr> holder, - ArgTypes... args) { - base::OnceCallback callback = holder->GetCallback(); - DCHECK(!callback.is_null()); - std::move(callback).Run(std::move(args)...); - } -}; - -template -struct InvokeOnceCallback { - static ReturnType Go( - scoped_refptr> holder, - ArgTypes... args) { - base::OnceCallback callback = holder->GetCallback(); - DCHECK(!callback.is_null()); - return std::move(callback).Run(std::move(args)...); - } -}; - -} // namespace internal - -template -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - base::OnceCallback val) { - // Reuse the converter of base::RepeatingCallback by storing the callback - // with a RefCounted. - auto holder = base::MakeRefCounted>( - std::move(val)); - return Converter>::ToV8( - isolate, - base::BindRepeating(&internal::InvokeOnceCallback::Go, holder)); - } - - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - base::OnceCallback* out) { - if (!val->IsFunction()) - return false; - *out = base::BindOnce(&internal::V8FunctionInvoker::Go, isolate, - internal::SafeV8Function(isolate, val)); - return true; - } -}; - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_ONCE_CALLBACK_H_ diff --git a/shell/common/native_mate_converters/string16_converter.h b/shell/common/native_mate_converters/string16_converter.h deleted file mode 100644 index c6cd8e27548..00000000000 --- a/shell/common/native_mate_converters/string16_converter.h +++ /dev/null @@ -1,33 +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_COMMON_NATIVE_MATE_CONVERTERS_STRING16_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_STRING16_CONVERTER_H_ - -#include "gin/converter.h" -#include "native_mate/converter.h" - -namespace mate { - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const base::string16& val) { - return gin::Converter::ToV8(isolate, val); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - base::string16* out) { - return gin::Converter::FromV8(isolate, val, out); - } -}; - -inline v8::Local StringToV8(v8::Isolate* isolate, - const base::string16& input) { - return ConvertToV8(isolate, input).As(); -} - -} // namespace mate - -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_STRING16_CONVERTER_H_ diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index edf93240b4a..a199d0d0e78 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -22,11 +22,11 @@ #include "content/public/browser/browser_thread.h" #include "content/public/common/content_paths.h" #include "electron/buildflags/buildflags.h" -#include "shell/common/api/locker.h" #include "shell/common/atom_command_line.h" #include "shell/common/gin_converters/file_path_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/event_emitter_caller.h" +#include "shell/common/gin_helper/locker.h" #include "shell/common/mac/main_application_bundle.h" #include "shell/common/node_includes.h" @@ -396,7 +396,7 @@ void NodeBindings::UvRunOnce() { return; // Use Locker in browser process. - mate::Locker locker(env->isolate()); + gin_helper::Locker locker(env->isolate()); v8::HandleScope handle_scope(env->isolate()); // Enter node context while dealing with uv events. diff --git a/shell/common/native_mate_converters/v8_value_converter.cc b/shell/common/v8_value_converter.cc similarity index 99% rename from shell/common/native_mate_converters/v8_value_converter.cc rename to shell/common/v8_value_converter.cc index d76ee5c220b..9f0c559bee0 100644 --- a/shell/common/native_mate_converters/v8_value_converter.cc +++ b/shell/common/v8_value_converter.cc @@ -2,7 +2,7 @@ // 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/v8_value_converter.h" +#include "shell/common/v8_value_converter.h" #include #include diff --git a/shell/common/native_mate_converters/v8_value_converter.h b/shell/common/v8_value_converter.h similarity index 92% rename from shell/common/native_mate_converters/v8_value_converter.h rename to shell/common/v8_value_converter.h index 2d6caf15a58..6b99fdde7a4 100644 --- a/shell/common/native_mate_converters/v8_value_converter.h +++ b/shell/common/v8_value_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_V8_VALUE_CONVERTER_H_ -#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_V8_VALUE_CONVERTER_H_ +#ifndef SHELL_COMMON_V8_VALUE_CONVERTER_H_ +#define SHELL_COMMON_V8_VALUE_CONVERTER_H_ #include @@ -74,4 +74,4 @@ class V8ValueConverter { } // namespace electron -#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_V8_VALUE_CONVERTER_H_ +#endif // SHELL_COMMON_V8_VALUE_CONVERTER_H_ diff --git a/shell/renderer/api/atom_api_context_bridge.cc b/shell/renderer/api/atom_api_context_bridge.cc index 5e1fbb5ac1b..e3ca10dd0a0 100644 --- a/shell/renderer/api/atom_api_context_bridge.cc +++ b/shell/renderer/api/atom_api_context_bridge.cc @@ -4,17 +4,25 @@ #include "shell/renderer/api/atom_api_context_bridge.h" +#include #include +#include #include #include #include "base/no_destructor.h" #include "base/strings/string_number_conversions.h" +#include "content/public/renderer/render_frame.h" +#include "content/public/renderer/render_frame_observer.h" #include "shell/common/api/remote/object_life_monitor.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/once_callback.h" +#include "shell/common/gin_converters/blink_converter.h" +#include "shell/common/gin_converters/callback_converter.h" +#include "shell/common/gin_helper/dictionary.h" +#include "shell/common/node_includes.h" #include "shell/common/promise_util.h" +#include "shell/renderer/api/context_bridge/render_frame_context_bridge_store.h" +#include "shell/renderer/atom_render_frame_observer.h" +#include "third_party/blink/public/web/web_local_frame.h" namespace electron { @@ -24,6 +32,11 @@ namespace { static int kMaxRecursion = 1000; +// Returns true if |maybe| is both a value, and that value is true. +inline bool IsTrue(v8::Maybe maybe) { + return maybe.IsJust() && maybe.FromJust(); +} + content::RenderFrame* GetRenderFrame(const v8::Local& value) { v8::Local context = value->CreationContext(); if (context.IsEmpty()) @@ -74,7 +87,7 @@ bool DeepFreeze(const v8::Local& object, return false; } } - return mate::internal::IsTrue( + return IsTrue( object->SetIntegrityLevel(context, v8::IntegrityLevel::kFrozen)); } @@ -130,16 +143,6 @@ class FunctionLifeMonitor final : public ObjectLifeMonitor { } // namespace -template -v8::Local BindRepeatingFunctionToV8( - v8::Isolate* isolate, - const base::RepeatingCallback& val) { - auto translater = - base::BindRepeating(&mate::internal::NativeFunctionInvoker::Go, val); - return mate::internal::CreateFunctionFromTranslater(isolate, translater, - false); -} - v8::MaybeLocal PassValueToOtherContext( v8::Local source_context, v8::Local destination_context, @@ -176,7 +179,7 @@ v8::MaybeLocal PassValueToOtherContext( std::make_tuple(std::move(global_func), std::move(global_source)); v8::Context::Scope destination_scope(destination_context); { - v8::Local proxy_func = BindRepeatingFunctionToV8( + v8::Local proxy_func = gin_helper::CallbackToV8Leaked( destination_context->GetIsolate(), base::BindRepeating(&ProxyFunctionWrapper, store, func_id)); FunctionLifeMonitor::BindTo(destination_context->GetIsolate(), @@ -239,9 +242,9 @@ v8::MaybeLocal PassValueToOtherContext( ignore_result(source_promise->Then( source_context, v8::Local::Cast( - mate::ConvertToV8(destination_context->GetIsolate(), then_cb)), + gin::ConvertToV8(destination_context->GetIsolate(), then_cb)), v8::Local::Cast( - mate::ConvertToV8(destination_context->GetIsolate(), catch_cb)))); + gin::ConvertToV8(destination_context->GetIsolate(), catch_cb)))); store->CacheProxiedObject(value, proxied_promise_handle); return v8::MaybeLocal(proxied_promise_handle); @@ -275,9 +278,8 @@ v8::MaybeLocal PassValueToOtherContext( if (value_for_array.IsEmpty()) return v8::MaybeLocal(); - if (!mate::internal::IsTrue( - cloned_arr->Set(destination_context, static_cast(i), - value_for_array.ToLocalChecked()))) { + if (!IsTrue(cloned_arr->Set(destination_context, static_cast(i), + value_for_array.ToLocalChecked()))) { return v8::MaybeLocal(); } } @@ -303,7 +305,7 @@ v8::MaybeLocal PassValueToOtherContext( v8::Context::Scope source_context_scope(source_context); { // V8 serializer will throw an error if required - if (!mate::ConvertFromV8(source_context->GetIsolate(), value, &ret)) + if (!gin::ConvertFromV8(source_context->GetIsolate(), value, &ret)) return v8::MaybeLocal(); } } @@ -311,7 +313,7 @@ v8::MaybeLocal PassValueToOtherContext( v8::Context::Scope destination_context_scope(destination_context); { v8::Local cloned_value = - mate::ConvertToV8(destination_context->GetIsolate(), ret); + gin::ConvertToV8(destination_context->GetIsolate(), ret); store->CacheProxiedObject(value, cloned_value); return v8::MaybeLocal(cloned_value); } @@ -320,7 +322,7 @@ v8::MaybeLocal PassValueToOtherContext( v8::Local ProxyFunctionWrapper( context_bridge::RenderFramePersistenceStore* store, size_t func_id, - mate::Arguments* args) { + gin_helper::Arguments* args) { // Context the proxy function was called from v8::Local calling_context = args->isolate()->GetCurrentContext(); // Context the function was created in @@ -356,8 +358,8 @@ v8::Local ProxyFunctionWrapper( auto message = try_catch.Message(); if (message.IsEmpty() || - !mate::ConvertFromV8(args->isolate(), message->Get(), - &error_message)) { + !gin::ConvertFromV8(args->isolate(), message->Get(), + &error_message)) { error_message = "An unknown exception occurred in the isolated context, an error " "occurred but a valid exception was not thrown."; @@ -391,9 +393,9 @@ v8::MaybeLocal CreateProxyForAPI( const v8::Local& destination_context, context_bridge::RenderFramePersistenceStore* store, int recursion_depth) { - mate::Dictionary api(source_context->GetIsolate(), api_object); - mate::Dictionary proxy = - mate::Dictionary::CreateEmpty(destination_context->GetIsolate()); + gin_helper::Dictionary api(source_context->GetIsolate(), api_object); + gin_helper::Dictionary proxy = + gin::Dictionary::CreateEmpty(destination_context->GetIsolate()); store->CacheProxiedObject(api.GetHandle(), proxy.GetHandle()); auto maybe_keys = api.GetHandle()->GetOwnPropertyNames( source_context, @@ -411,7 +413,7 @@ v8::MaybeLocal CreateProxyForAPI( v8::Local key = keys->Get(destination_context, i).ToLocalChecked(); // Try get the key as a string - if (!mate::ConvertFromV8(api.isolate(), key, &key_str)) { + if (!gin::ConvertFromV8(api.isolate(), key, &key_str)) { continue; } v8::Local value; @@ -431,10 +433,10 @@ v8::MaybeLocal CreateProxyForAPI( } #ifdef DCHECK_IS_ON -mate::Dictionary DebugGC(mate::Dictionary empty) { +gin_helper::Dictionary DebugGC(gin_helper::Dictionary empty) { auto* render_frame = GetRenderFrame(empty.GetHandle()); auto* store = GetOrCreateStore(render_frame); - mate::Dictionary ret = mate::Dictionary::CreateEmpty(empty.isolate()); + gin_helper::Dictionary ret = gin::Dictionary::CreateEmpty(empty.isolate()); ret.Set("functionCount", store->functions().size()); auto* proxy_map = store->proxy_map(); ret.Set("objectCount", proxy_map->size() * 2); @@ -458,7 +460,7 @@ mate::Dictionary DebugGC(mate::Dictionary empty) { void ExposeAPIInMainWorld(const std::string& key, v8::Local api_object, - mate::Arguments* args) { + gin_helper::Arguments* args) { auto* render_frame = GetRenderFrame(api_object); CHECK(render_frame); context_bridge::RenderFramePersistenceStore* store = @@ -466,7 +468,8 @@ void ExposeAPIInMainWorld(const std::string& key, auto* frame = render_frame->GetWebFrame(); CHECK(frame); v8::Local main_context = frame->MainWorldScriptContext(); - mate::Dictionary global(main_context->GetIsolate(), main_context->Global()); + gin_helper::Dictionary global(main_context->GetIsolate(), + main_context->Global()); if (global.Has(key)) { args->ThrowError( @@ -503,7 +506,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.SetMethod("exposeAPIInMainWorld", &electron::api::ExposeAPIInMainWorld); #ifdef DCHECK_IS_ON dict.SetMethod("_debugGCMaps", &electron::api::DebugGC); diff --git a/shell/renderer/api/atom_api_context_bridge.h b/shell/renderer/api/atom_api_context_bridge.h index a855e68f6ee..88593e1e2df 100644 --- a/shell/renderer/api/atom_api_context_bridge.h +++ b/shell/renderer/api/atom_api_context_bridge.h @@ -5,27 +5,24 @@ #ifndef SHELL_RENDERER_API_ATOM_API_CONTEXT_BRIDGE_H_ #define SHELL_RENDERER_API_ATOM_API_CONTEXT_BRIDGE_H_ -#include -#include -#include +#include "v8/include/v8.h" -#include "content/public/renderer/render_frame.h" -#include "content/public/renderer/render_frame_observer.h" -#include "native_mate/converter.h" -#include "native_mate/dictionary.h" -#include "shell/common/node_includes.h" -#include "shell/renderer/api/context_bridge/render_frame_context_bridge_store.h" -#include "shell/renderer/atom_render_frame_observer.h" -#include "third_party/blink/public/web/web_local_frame.h" +namespace gin_helper { +class Arguments; +} namespace electron { namespace api { +namespace context_bridge { +class RenderFramePersistenceStore; +} + v8::Local ProxyFunctionWrapper( context_bridge::RenderFramePersistenceStore* store, size_t func_id, - mate::Arguments* args); + gin_helper::Arguments* args); v8::MaybeLocal CreateProxyForAPI( const v8::Local& api_object, diff --git a/shell/renderer/api/atom_api_renderer_ipc.cc b/shell/renderer/api/atom_api_renderer_ipc.cc index 3ed4097e7a1..b253a0cbabc 100644 --- a/shell/renderer/api/atom_api_renderer_ipc.cc +++ b/shell/renderer/api/atom_api_renderer_ipc.cc @@ -13,8 +13,8 @@ #include "gin/wrappable.h" #include "services/service_manager/public/cpp/interface_provider.h" #include "shell/common/api/api.mojom.h" -#include "shell/common/gin_converters/blink_converter_gin_adapter.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/blink_converter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/node_bindings.h" #include "shell/common/node_includes.h" #include "shell/common/promise_util.h" @@ -75,7 +75,7 @@ class IPCRenderer : public gin::Wrappable { const std::string& channel, v8::Local arguments) { blink::CloneableMessage message; - if (!mate::ConvertFromV8(isolate, arguments, &message)) { + if (!gin::ConvertFromV8(isolate, arguments, &message)) { return; } electron_browser_ptr_->get()->Message(internal, channel, @@ -87,7 +87,7 @@ class IPCRenderer : public gin::Wrappable { const std::string& channel, v8::Local arguments) { blink::CloneableMessage message; - if (!mate::ConvertFromV8(isolate, arguments, &message)) { + if (!gin::ConvertFromV8(isolate, arguments, &message)) { return v8::Local(); } electron::util::Promise p(isolate); @@ -110,7 +110,7 @@ class IPCRenderer : public gin::Wrappable { const std::string& channel, v8::Local arguments) { blink::CloneableMessage message; - if (!mate::ConvertFromV8(isolate, arguments, &message)) { + if (!gin::ConvertFromV8(isolate, arguments, &message)) { return; } electron_browser_ptr_->get()->MessageTo( @@ -121,7 +121,7 @@ class IPCRenderer : public gin::Wrappable { const std::string& channel, v8::Local arguments) { blink::CloneableMessage message; - if (!mate::ConvertFromV8(isolate, arguments, &message)) { + if (!gin::ConvertFromV8(isolate, arguments, &message)) { return; } electron_browser_ptr_->get()->MessageHost(channel, std::move(message)); @@ -132,7 +132,7 @@ class IPCRenderer : public gin::Wrappable { const std::string& channel, v8::Local arguments) { blink::CloneableMessage message; - if (!mate::ConvertFromV8(isolate, arguments, &message)) { + if (!gin::ConvertFromV8(isolate, arguments, &message)) { return blink::CloneableMessage(); } // We aren't using a true synchronous mojo call here. We're calling an diff --git a/shell/renderer/api/atom_api_spell_check_client.cc b/shell/renderer/api/atom_api_spell_check_client.cc index 4b14c77dc2f..47bbb41e225 100644 --- a/shell/renderer/api/atom_api_spell_check_client.cc +++ b/shell/renderer/api/atom_api_spell_check_client.cc @@ -16,10 +16,8 @@ #include "base/numerics/safe_conversions.h" #include "base/threading/thread_task_runner_handle.h" #include "components/spellcheck/renderer/spellcheck_worditerator.h" -#include "native_mate/converter.h" -#include "native_mate/dictionary.h" -#include "native_mate/function_template.h" -#include "shell/common/native_mate_converters/string16_converter.h" +#include "shell/common/gin_helper/dictionary.h" +#include "shell/common/gin_helper/function_template.h" #include "third_party/blink/public/web/web_text_checking_completion.h" #include "third_party/blink/public/web/web_text_checking_result.h" #include "third_party/icu/source/common/unicode/uscript.h" @@ -84,8 +82,9 @@ SpellCheckClient::SpellCheckClient(const std::string& language, character_attributes_.SetDefaultLanguage(language); // Persistent the method. - mate::Dictionary dict(isolate, provider); - dict.Get("spellCheck", &spell_check_); + v8::Local spell_check; + gin_helper::Dictionary(isolate, provider).Get("spellCheck", &spell_check); + spell_check_.Reset(isolate, spell_check); } SpellCheckClient::~SpellCheckClient() { @@ -221,12 +220,12 @@ void SpellCheckClient::SpellCheckWords(const SpellCheckScope& scope, const std::set& words) { DCHECK(!scope.spell_check_.IsEmpty()); - v8::Local templ = mate::CreateFunctionTemplate( + v8::Local templ = gin_helper::CreateFunctionTemplate( isolate_, base::BindRepeating(&SpellCheckClient::OnSpellCheckDone, AsWeakPtr())); auto context = isolate_->GetCurrentContext(); - v8::Local args[] = {mate::ConvertToV8(isolate_, words), + v8::Local args[] = {gin::ConvertToV8(isolate_, words), templ->GetFunction(context).ToLocalChecked()}; // Call javascript with the words and the callback function scope.spell_check_->Call(context, scope.provider_, 2, args).IsEmpty(); @@ -267,8 +266,9 @@ SpellCheckClient::SpellCheckScope::SpellCheckScope( : handle_scope_(client.isolate_), context_scope_( v8::Local::New(client.isolate_, client.context_)), - provider_(client.provider_.NewHandle()), - spell_check_(client.spell_check_.NewHandle()) {} + provider_(v8::Local::New(client.isolate_, client.provider_)), + spell_check_( + v8::Local::New(client.isolate_, client.spell_check_)) {} SpellCheckClient::SpellCheckScope::~SpellCheckScope() = default; diff --git a/shell/renderer/api/atom_api_spell_check_client.h b/shell/renderer/api/atom_api_spell_check_client.h index 38b8492a4ba..131676059a9 100644 --- a/shell/renderer/api/atom_api_spell_check_client.h +++ b/shell/renderer/api/atom_api_spell_check_client.h @@ -13,10 +13,10 @@ #include "base/callback.h" #include "base/memory/weak_ptr.h" #include "components/spellcheck/renderer/spellcheck_worditerator.h" -#include "native_mate/scoped_persistent.h" #include "third_party/blink/public/platform/web_spell_check_panel_host_client.h" #include "third_party/blink/public/platform/web_vector.h" #include "third_party/blink/public/web/web_text_check_client.h" +#include "v8/include/v8.h" namespace blink { struct WebTextCheckingResult; @@ -100,9 +100,9 @@ class SpellCheckClient : public blink::WebSpellCheckPanelHostClient, std::unique_ptr pending_request_param_; v8::Isolate* isolate_; - v8::Persistent context_; - mate::ScopedPersistent provider_; - mate::ScopedPersistent spell_check_; + v8::Global context_; + v8::Global provider_; + v8::Global spell_check_; DISALLOW_COPY_AND_ASSIGN(SpellCheckClient); }; diff --git a/shell/renderer/api/atom_api_web_frame.cc b/shell/renderer/api/atom_api_web_frame.cc index 6aa3c3258f5..85538961950 100644 --- a/shell/renderer/api/atom_api_web_frame.cc +++ b/shell/renderer/api/atom_api_web_frame.cc @@ -12,11 +12,10 @@ #include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_visitor.h" #include "content/public/renderer/render_view.h" -#include "native_mate/dictionary.h" #include "services/service_manager/public/cpp/interface_provider.h" #include "shell/common/api/api.mojom.h" -#include "shell/common/native_mate_converters/blink_converter.h" -#include "shell/common/native_mate_converters/string16_converter.h" +#include "shell/common/gin_converters/blink_converter.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" #include "shell/common/promise_util.h" #include "shell/renderer/api/atom_api_spell_check_client.h" @@ -36,7 +35,7 @@ #include "third_party/blink/public/web/web_view.h" #include "url/url_util.h" -namespace mate { +namespace gin { template <> struct Converter { @@ -78,7 +77,7 @@ struct Converter { } }; -} // namespace mate +} // namespace gin namespace electron { @@ -308,12 +307,12 @@ int GetWebFrameId(v8::Local window, return render_frame->GetRoutingID(); } -void SetSpellCheckProvider(mate::Arguments* args, +void SetSpellCheckProvider(gin_helper::Arguments* args, v8::Local window, const std::string& language, v8::Local provider) { auto context = args->isolate()->GetCurrentContext(); - if (!provider->Has(context, mate::StringToV8(args->isolate(), "spellCheck")) + if (!provider->Has(context, gin::StringToV8(args->isolate(), "spellCheck")) .ToChecked()) { args->ThrowError("\"spellCheck\" has to be defined"); return; @@ -349,11 +348,11 @@ void InsertText(v8::Local window, const std::string& text) { base::string16 InsertCSS(v8::Local window, const std::string& css, - mate::Arguments* args) { + gin_helper::Arguments* args) { blink::WebDocument::CSSOrigin css_origin = blink::WebDocument::CSSOrigin::kAuthorOrigin; - mate::Dictionary options; + gin_helper::Dictionary options; if (args->GetNext(&options)) options.Get("cssOrigin", &css_origin); @@ -375,7 +374,7 @@ void RemoveInsertedCSS(v8::Local window, const base::string16& key) { } } -v8::Local ExecuteJavaScript(mate::Arguments* args, +v8::Local ExecuteJavaScript(gin_helper::Arguments* args, v8::Local window, const base::string16& code) { v8::Isolate* isolate = args->isolate(); @@ -393,10 +392,10 @@ v8::Local ExecuteJavaScript(mate::Arguments* args, } v8::Local ExecuteJavaScriptInIsolatedWorld( - mate::Arguments* args, + gin_helper::Arguments* args, v8::Local window, int world_id, - const std::vector& scripts) { + const std::vector& scripts) { v8::Isolate* isolate = args->isolate(); util::Promise> promise(isolate); v8::Local handle = promise.GetHandle(); @@ -439,8 +438,8 @@ v8::Local ExecuteJavaScriptInIsolatedWorld( void SetIsolatedWorldInfo(v8::Local window, int world_id, - const mate::Dictionary& options, - mate::Arguments* args) { + const gin_helper::Dictionary& options, + gin_helper::Arguments* args) { std::string origin_url, security_policy, name; options.Get("securityOrigin", &origin_url); options.Get("csp", &security_policy); @@ -574,7 +573,7 @@ void Initialize(v8::Local exports, using namespace electron::api; // NOLINT(build/namespaces) v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); + gin_helper::Dictionary dict(isolate, exports); dict.SetMethod("setName", &SetName); dict.SetMethod("setZoomLevel", &SetZoomLevel); dict.SetMethod("getZoomLevel", &GetZoomLevel); diff --git a/shell/renderer/atom_sandboxed_renderer_client.cc b/shell/renderer/atom_sandboxed_renderer_client.cc index 3ae11753dec..58efed622b0 100644 --- a/shell/renderer/atom_sandboxed_renderer_client.cc +++ b/shell/renderer/atom_sandboxed_renderer_client.cc @@ -11,13 +11,9 @@ #include "base/process/process_handle.h" #include "content/public/renderer/render_frame.h" #include "electron/buildflags/buildflags.h" -#include "gin/converter.h" -#include "native_mate/dictionary.h" #include "shell/common/api/electron_bindings.h" #include "shell/common/application_info.h" #include "shell/common/gin_helper/dictionary.h" -#include "shell/common/native_mate_converters/string16_converter.h" -#include "shell/common/native_mate_converters/value_converter.h" #include "shell/common/node_bindings.h" #include "shell/common/node_includes.h" #include "shell/common/node_util.h" @@ -60,10 +56,10 @@ v8::Local GetModuleCache(v8::Isolate* isolate) { // adapted from node.cc v8::Local GetBinding(v8::Isolate* isolate, v8::Local key, - mate::Arguments* margs) { + gin_helper::Arguments* margs) { v8::Local exports; std::string module_key = gin::V8ToString(isolate, key); - mate::Dictionary cache(isolate, GetModuleCache(isolate)); + gin_helper::Dictionary cache(isolate, GetModuleCache(isolate)); if (cache.Get(module_key.c_str(), &exports)) { return exports; @@ -97,9 +93,8 @@ void InvokeHiddenCallback(v8::Handle context, const std::string& hidden_key, const std::string& callback_name) { auto* isolate = context->GetIsolate(); - auto binding_key = mate::ConvertToV8(isolate, hidden_key) - ->ToString(context) - .ToLocalChecked(); + auto binding_key = + gin::ConvertToV8(isolate, hidden_key)->ToString(context).ToLocalChecked(); auto private_binding_key = v8::Private::ForApi(isolate, binding_key); auto global_object = context->Global(); v8::Local value; @@ -108,7 +103,7 @@ void InvokeHiddenCallback(v8::Handle context, if (value.IsEmpty() || !value->IsObject()) return; auto binding = value->ToObject(context).ToLocalChecked(); - auto callback_key = mate::ConvertToV8(isolate, callback_name) + auto callback_key = gin::ConvertToV8(isolate, callback_name) ->ToString(context) .ToLocalChecked(); auto callback_value = binding->Get(context, callback_key).ToLocalChecked(); @@ -132,11 +127,11 @@ void AtomSandboxedRendererClient::InitializeBindings( v8::Local context, bool is_main_frame) { auto* isolate = context->GetIsolate(); - mate::Dictionary b(isolate, binding); + gin_helper::Dictionary b(isolate, binding); b.SetMethod("get", GetBinding); b.SetMethod("createPreloadScript", CreatePreloadScript); - mate::Dictionary process = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary process = gin::Dictionary::CreateEmpty(isolate); b.Set("process", process); ElectronBindings::BindProcess(isolate, &process, metrics_.get()); @@ -248,7 +243,7 @@ void AtomSandboxedRendererClient::SetupMainWorldOverrides( // an argument. auto* isolate = context->GetIsolate(); - mate::Dictionary process = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary process = gin::Dictionary::CreateEmpty(isolate); process.SetMethod("_linkedBinding", GetBinding); std::vector> isolated_bundle_params = { @@ -272,7 +267,7 @@ void AtomSandboxedRendererClient::SetupExtensionWorldOverrides( #else auto* isolate = context->GetIsolate(); - mate::Dictionary process = mate::Dictionary::CreateEmpty(isolate); + gin_helper::Dictionary process = gin::Dictionary::CreateEmpty(isolate); process.SetMethod("_linkedBinding", GetBinding); std::vector> isolated_bundle_params = { diff --git a/shell/renderer/electron_api_service_impl.cc b/shell/renderer/electron_api_service_impl.cc index b7fc2f27aa2..dbadebd2304 100644 --- a/shell/renderer/electron_api_service_impl.cc +++ b/shell/renderer/electron_api_service_impl.cc @@ -13,8 +13,8 @@ #include "base/threading/thread_restrictions.h" #include "mojo/public/cpp/system/platform_handle.h" #include "shell/common/atom_constants.h" -#include "shell/common/gin_converters/blink_converter_gin_adapter.h" -#include "shell/common/gin_converters/value_converter_gin_adapter.h" +#include "shell/common/gin_converters/blink_converter.h" +#include "shell/common/gin_converters/value_converter.h" #include "shell/common/heap_snapshot.h" #include "shell/common/node_includes.h" #include "shell/common/options_switches.h" diff --git a/shell/renderer/renderer_client_base.cc b/shell/renderer/renderer_client_base.cc index 87b3f8d503c..50c76280141 100644 --- a/shell/renderer/renderer_client_base.cc +++ b/shell/renderer/renderer_client_base.cc @@ -22,7 +22,6 @@ #include "printing/buildflags/buildflags.h" #include "shell/common/color_util.h" #include "shell/common/gin_helper/dictionary.h" -#include "shell/common/native_mate_converters/value_converter.h" #include "shell/common/options_switches.h" #include "shell/renderer/atom_autofill_agent.h" #include "shell/renderer/atom_render_frame_observer.h"