chore: remove native_mate (Part 5) (#20264)
* deprecate native_mate/native_mate/object_template_builder.h * add gin_helper/object_template_builder.h * add patch to avoid ambiguous error * remove usage of object_template_builder_deprecated.h in a few files * add note we should remove gin_helper/object_template_builder.h in future
This commit is contained in:
parent
63f08fcdb0
commit
624ba4f642
39 changed files with 474 additions and 121 deletions
|
@ -30,7 +30,7 @@
|
|||
#include "content/public/common/content_switches.h"
|
||||
#include "gin/arguments.h"
|
||||
#include "media/audio/audio_manager.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "native_mate/object_template_builder_deprecated.h"
|
||||
#include "net/ssl/client_cert_identity.h"
|
||||
#include "net/ssl/ssl_cert_request_info.h"
|
||||
#include "services/service_manager/sandbox/switches.h"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "base/time/time.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "native_mate/object_template_builder_deprecated.h"
|
||||
#include "shell/browser/browser.h"
|
||||
#include "shell/browser/native_window.h"
|
||||
#include "shell/browser/window_list.h"
|
||||
|
|
|
@ -6,24 +6,22 @@
|
|||
|
||||
#include <map>
|
||||
|
||||
#include "gin/dictionary.h"
|
||||
#include "native_mate/constructor.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "shell/browser/native_window.h"
|
||||
#include "shell/common/gin_converters/callback_converter.h"
|
||||
#include "shell/common/gin_converters/image_converter.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "shell/common/gin_helper/object_template_builder.h"
|
||||
#include "shell/common/native_mate_converters/accelerator_converter.h"
|
||||
#include "shell/common/native_mate_converters/image_converter.h"
|
||||
#include "shell/common/native_mate_converters/string16_converter.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
|
||||
// TODO(zcbenz): Remove this after removing mate::ObjectTemplateBuilder.
|
||||
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// We need this map to keep references to currently opened menus.
|
||||
// Without this menus would be destroyed by js garbage collector
|
||||
// even when they are still displayed.
|
||||
std::map<uint32_t, v8::Global<v8::Object>> g_menus;
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
namespace electron {
|
||||
|
@ -224,9 +222,9 @@ void Menu::OnMenuWillShow() {
|
|||
// static
|
||||
void Menu::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "Menu"));
|
||||
prototype->SetClassName(gin::StringToV8(isolate, "Menu"));
|
||||
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.SetMethod("insertItem", &Menu::InsertItemAt)
|
||||
.SetMethod("insertCheckItem", &Menu::InsertCheckItemAt)
|
||||
.SetMethod("insertRadioItem", &Menu::InsertRadioItemAt)
|
||||
|
@ -267,7 +265,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
|||
v8::Isolate* isolate = context->GetIsolate();
|
||||
Menu::SetConstructor(isolate, base::BindRepeating(&Menu::New));
|
||||
|
||||
mate::Dictionary dict(isolate, exports);
|
||||
gin_helper::Dictionary dict(isolate, exports);
|
||||
dict.Set(
|
||||
"Menu",
|
||||
Menu::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||
|
|
|
@ -155,6 +155,20 @@ struct Converter<electron::AtomMenuModel*> {
|
|||
}
|
||||
};
|
||||
|
||||
// TODO(zcbenz): Remove this after converting Menu to gin::Wrapper.
|
||||
template <>
|
||||
struct Converter<electron::api::Menu*> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
electron::api::Menu** out) {
|
||||
return mate::ConvertFromV8(isolate, val, out);
|
||||
}
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
electron::api::Menu* in) {
|
||||
return mate::ConvertToV8(isolate, in);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
||||
#endif // SHELL_BROWSER_API_ATOM_API_MENU_H_
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "native_mate/object_template_builder_deprecated.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
#include "ui/gfx/color_utils.h"
|
||||
#include "ui/native_theme/native_theme.h"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "native_mate/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "native_mate/object_template_builder_deprecated.h"
|
||||
#include "shell/browser/api/atom_api_menu.h"
|
||||
#include "shell/browser/atom_browser_client.h"
|
||||
#include "shell/browser/browser.h"
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
#include "base/bind.h"
|
||||
#include "gin/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "shell/browser/browser.h"
|
||||
#include "shell/common/gin_converters/callback_converter.h"
|
||||
#include "shell/common/gin_helper/object_template_builder.h"
|
||||
#include "shell/common/native_mate_converters/gfx_converter.h"
|
||||
#include "shell/common/native_mate_converters/native_window_converter.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
|
@ -134,22 +134,22 @@ void Screen::OnDisplayMetricsChanged(const display::Display& display,
|
|||
}
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> Screen::Create(v8::Isolate* isolate) {
|
||||
v8::Local<v8::Value> Screen::Create(gin_helper::ErrorThrower error_thrower) {
|
||||
if (!Browser::Get()->is_ready()) {
|
||||
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
|
||||
isolate,
|
||||
"The 'screen' module can't be used before the app 'ready' event")));
|
||||
return v8::Null(isolate);
|
||||
error_thrower.ThrowError(
|
||||
"The 'screen' module can't be used before the app 'ready' event");
|
||||
return v8::Null(error_thrower.isolate());
|
||||
}
|
||||
|
||||
display::Screen* screen = display::Screen::GetScreen();
|
||||
if (!screen) {
|
||||
isolate->ThrowException(v8::Exception::Error(
|
||||
mate::StringToV8(isolate, "Failed to get screen information")));
|
||||
return v8::Null(isolate);
|
||||
error_thrower.ThrowError("Failed to get screen information");
|
||||
return v8::Null(error_thrower.isolate());
|
||||
}
|
||||
|
||||
return mate::CreateHandle(isolate, new Screen(isolate, screen)).ToV8();
|
||||
return mate::CreateHandle(error_thrower.isolate(),
|
||||
new Screen(error_thrower.isolate(), screen))
|
||||
.ToV8();
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include "native_mate/handle.h"
|
||||
#include "shell/browser/api/event_emitter.h"
|
||||
#include "shell/common/gin_helper/error_thrower.h"
|
||||
#include "ui/display/display_observer.h"
|
||||
#include "ui/display/screen.h"
|
||||
|
||||
|
@ -25,7 +25,7 @@ namespace api {
|
|||
class Screen : public mate::EventEmitter<Screen>,
|
||||
public display::DisplayObserver {
|
||||
public:
|
||||
static v8::Local<v8::Value> Create(v8::Isolate* isolate);
|
||||
static v8::Local<v8::Value> Create(gin_helper::ErrorThrower error_thrower);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "native_mate/object_template_builder_deprecated.h"
|
||||
#include "net/base/completion_repeating_callback.h"
|
||||
#include "net/base/load_flags.h"
|
||||
#include "net/http/http_auth_handler_factory.h"
|
||||
|
|
|
@ -121,4 +121,22 @@ class Session : public mate::TrackableObject<Session>,
|
|||
|
||||
} // namespace electron
|
||||
|
||||
namespace gin {
|
||||
|
||||
// TODO(zcbenz): Remove this after converting Session to gin::Wrapper.
|
||||
template <>
|
||||
struct Converter<electron::api::Session*> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
electron::api::Session** out) {
|
||||
return mate::ConvertFromV8(isolate, val, out);
|
||||
}
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
electron::api::Session* in) {
|
||||
return mate::ConvertToV8(isolate, in);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
||||
#endif // SHELL_BROWSER_API_ATOM_API_SESSION_H_
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/threading/sequenced_task_runner_handle.h"
|
||||
#include "base/values.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "native_mate/object_template_builder_deprecated.h"
|
||||
#include "net/base/mac/url_conversions.h"
|
||||
#include "shell/browser/mac/atom_application.h"
|
||||
#include "shell/browser/mac/dict_util.h"
|
||||
|
|
|
@ -266,4 +266,22 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
|
|||
|
||||
} // namespace electron
|
||||
|
||||
namespace gin {
|
||||
|
||||
// TODO(zcbenz): Remove this after converting TopLevelWindow to gin::Wrapper.
|
||||
template <>
|
||||
struct Converter<electron::api::TopLevelWindow*> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
electron::api::TopLevelWindow** out) {
|
||||
return mate::ConvertFromV8(isolate, val, out);
|
||||
}
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
electron::api::TopLevelWindow* in) {
|
||||
return mate::ConvertToV8(isolate, in);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
||||
#endif // SHELL_BROWSER_API_ATOM_API_TOP_LEVEL_WINDOW_H_
|
||||
|
|
|
@ -9,11 +9,12 @@
|
|||
#include "mojo/public/cpp/bindings/receiver_set.h"
|
||||
#include "mojo/public/cpp/system/string_data_source.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "net/http/http_util.h"
|
||||
#include "services/network/public/mojom/chunked_data_pipe_getter.mojom.h"
|
||||
#include "shell/browser/api/atom_api_session.h"
|
||||
#include "shell/browser/atom_browser_context.h"
|
||||
#include "shell/common/gin_helper/event_emitter_caller.h"
|
||||
#include "shell/common/gin_helper/object_template_builder.h"
|
||||
#include "shell/common/native_mate_converters/gurl_converter.h"
|
||||
#include "shell/common/native_mate_converters/net_converter.h"
|
||||
|
||||
|
@ -312,8 +313,8 @@ void URLRequestNS::SetChunkedUpload(bool is_chunked_upload) {
|
|||
is_chunked_upload_ = is_chunked_upload;
|
||||
}
|
||||
|
||||
mate::Dictionary URLRequestNS::GetUploadProgress() {
|
||||
mate::Dictionary progress = mate::Dictionary::CreateEmpty(isolate());
|
||||
gin::Dictionary URLRequestNS::GetUploadProgress() {
|
||||
gin::Dictionary progress = gin::Dictionary::CreateEmpty(isolate());
|
||||
if (loader_) {
|
||||
if (request_)
|
||||
progress.Set("started", false);
|
||||
|
@ -504,7 +505,7 @@ void URLRequestNS::EmitError(EventType type, base::StringPiece message) {
|
|||
else
|
||||
response_state_ |= STATE_FAILED;
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
auto error = v8::Exception::Error(mate::StringToV8(isolate(), message));
|
||||
auto error = v8::Exception::Error(gin::StringToV8(isolate(), message));
|
||||
EmitEvent(type, false, "error", error);
|
||||
}
|
||||
|
||||
|
@ -513,7 +514,7 @@ void URLRequestNS::EmitEvent(EventType type, Args... args) {
|
|||
const char* method =
|
||||
type == EventType::kRequest ? "_emitRequestEvent" : "_emitResponseEvent";
|
||||
v8::HandleScope handle_scope(isolate());
|
||||
mate::CustomEmit(isolate(), GetWrapper(), method, args...);
|
||||
gin_helper::CustomEmit(isolate(), GetWrapper(), method, args...);
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -524,9 +525,9 @@ mate::WrappableBase* URLRequestNS::New(mate::Arguments* args) {
|
|||
// static
|
||||
void URLRequestNS::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "URLRequest"));
|
||||
prototype->SetClassName(gin::StringToV8(isolate, "URLRequest"));
|
||||
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.SetMethod("write", &URLRequestNS::Write)
|
||||
.SetMethod("cancel", &URLRequestNS::Cancel)
|
||||
.SetMethod("setExtraHeader", &URLRequestNS::SetExtraHeader)
|
||||
|
|
|
@ -10,8 +10,9 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gin/arguments.h"
|
||||
#include "gin/dictionary.h"
|
||||
#include "mojo/public/cpp/system/data_pipe_producer.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "services/network/public/cpp/shared_url_loader_factory.h"
|
||||
#include "services/network/public/cpp/simple_url_loader.h"
|
||||
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
|
||||
|
@ -47,7 +48,7 @@ class URLRequestNS : public mate::EventEmitter<URLRequestNS>,
|
|||
bool SetExtraHeader(const std::string& name, const std::string& value);
|
||||
void RemoveExtraHeader(const std::string& name);
|
||||
void SetChunkedUpload(bool is_chunked_upload);
|
||||
mate::Dictionary GetUploadProgress();
|
||||
gin::Dictionary GetUploadProgress();
|
||||
int StatusCode() const;
|
||||
std::string StatusMessage() const;
|
||||
net::HttpResponseHeaders* RawResponseHeaders() const;
|
||||
|
@ -140,4 +141,22 @@ class URLRequestNS : public mate::EventEmitter<URLRequestNS>,
|
|||
|
||||
} // namespace electron
|
||||
|
||||
namespace gin {
|
||||
|
||||
// TODO(zcbenz): Remove this after converting URLRequestNS to gin::Wrapper.
|
||||
template <>
|
||||
struct Converter<electron::api::URLRequestNS*> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
electron::api::URLRequestNS** out) {
|
||||
return mate::ConvertFromV8(isolate, val, out);
|
||||
}
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
electron::api::URLRequestNS* in) {
|
||||
return mate::ConvertToV8(isolate, in);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
||||
#endif // SHELL_BROWSER_API_ATOM_API_URL_REQUEST_NS_H_
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
#include "mojo/public/cpp/system/platform_handle.h"
|
||||
#include "native_mate/converter.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "native_mate/object_template_builder_deprecated.h"
|
||||
#include "shell/browser/api/atom_api_browser_window.h"
|
||||
#include "shell/browser/api/atom_api_debugger.h"
|
||||
#include "shell/browser/api/atom_api_session.h"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <utility>
|
||||
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "native_mate/object_template_builder_deprecated.h"
|
||||
#include "shell/common/native_mate_converters/value_converter.h"
|
||||
|
||||
namespace mate {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "native_mate/arguments.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "native_mate/object_template_builder_deprecated.h"
|
||||
#include "shell/browser/api/event.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
#include "ui/events/event_constants.h"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "base/bind.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "native_mate/object_template_builder_deprecated.h"
|
||||
#include "shell/browser/api/event_emitter.h"
|
||||
#include "shell/common/key_weak_map.h"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue