chore: remove native_mate (Part 7) (#20561)

* refactor: use gin converters in api::Protocol

* refactor: convert JS constructor impl to gin

* refactor: use InitWithArgs helper

* fix: gin_helper::Dictionary should behave the same with mate

* fix cpplint warnings

* refactor: no more need to patch gin/dictionary.h
This commit is contained in:
Cheng Zhao 2019-10-15 10:15:23 +09:00 committed by GitHub
parent 6c6bff81ac
commit 1ecfcc8c70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 274 additions and 368 deletions

View file

@ -57,15 +57,9 @@ namespace electron {
namespace api {
BrowserView::BrowserView(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
BrowserView::BrowserView(gin::Arguments* args,
const mate::Dictionary& options) {
Init(isolate, wrapper, options);
}
void BrowserView::Init(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
const mate::Dictionary& options) {
v8::Isolate* isolate = args->isolate();
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences);
web_preferences.Set("type", "browserView");
@ -79,7 +73,7 @@ void BrowserView::Init(v8::Isolate* isolate,
view_.reset(
NativeBrowserView::Create(api_web_contents_->managed_web_contents()));
InitWith(isolate, wrapper);
InitWithArgs(args);
}
BrowserView::~BrowserView() {
@ -96,16 +90,17 @@ void BrowserView::WebContentsDestroyed() {
}
// static
mate::WrappableBase* BrowserView::New(mate::Arguments* args) {
mate::WrappableBase* BrowserView::New(gin_helper::ErrorThrower thrower,
gin::Arguments* args) {
if (!Browser::Get()->is_ready()) {
args->ThrowError("Cannot create BrowserView before app is ready");
thrower.ThrowError("Cannot create BrowserView before app is ready");
return nullptr;
}
mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
args->GetNext(&options);
return new BrowserView(args->isolate(), args->GetThis(), options);
return new BrowserView(args, options);
}
int32_t BrowserView::ID() const {

View file

@ -12,6 +12,7 @@
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/native_browser_view.h"
#include "shell/common/gin_helper/error_thrower.h"
namespace gfx {
class Rect;
@ -33,7 +34,8 @@ class WebContents;
class BrowserView : public mate::TrackableObject<BrowserView>,
public content::WebContentsObserver {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static mate::WrappableBase* New(gin_helper::ErrorThrower thrower,
gin::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
@ -44,19 +46,13 @@ class BrowserView : public mate::TrackableObject<BrowserView>,
int32_t ID() const;
protected:
BrowserView(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
const mate::Dictionary& options);
BrowserView(gin::Arguments* args, const mate::Dictionary& options);
~BrowserView() override;
// content::WebContentsObserver:
void WebContentsDestroyed() override;
private:
void Init(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
const mate::Dictionary& options);
void SetAutoResize(AutoResizeFlags flags);
void SetBounds(const gfx::Rect& bounds);
gfx::Rect GetBounds();

View file

@ -29,13 +29,13 @@ namespace electron {
namespace api {
BrowserWindow::BrowserWindow(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
BrowserWindow::BrowserWindow(gin::Arguments* args,
const mate::Dictionary& options)
: TopLevelWindow(isolate, options), weak_factory_(this) {
: TopLevelWindow(args->isolate(), options), weak_factory_(this) {
mate::Handle<class WebContents> web_contents;
// Use options.webPreferences in WebContents.
v8::Isolate* isolate = args->isolate();
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences);
@ -92,7 +92,7 @@ BrowserWindow::BrowserWindow(v8::Isolate* isolate,
if (host)
host->GetWidget()->AddInputEventObserver(this);
InitWith(isolate, wrapper);
InitWithArgs(args);
#if defined(OS_MACOSX)
OverrideNSWindowContentView(web_contents->managed_web_contents());
@ -444,9 +444,10 @@ void BrowserWindow::OnWindowHide() {
}
// static
mate::WrappableBase* BrowserWindow::New(mate::Arguments* args) {
mate::WrappableBase* BrowserWindow::New(gin_helper::ErrorThrower thrower,
gin::Arguments* args) {
if (!Browser::Get()->is_ready()) {
args->ThrowError("Cannot create BrowserWindow before app is ready");
thrower.ThrowError("Cannot create BrowserWindow before app is ready");
return nullptr;
}
@ -460,7 +461,7 @@ mate::WrappableBase* BrowserWindow::New(mate::Arguments* args) {
options = mate::Dictionary::CreateEmpty(args->isolate());
}
return new BrowserWindow(args->isolate(), args->GetThis(), options);
return new BrowserWindow(args, options);
}
// static

View file

@ -12,6 +12,7 @@
#include "base/cancelable_callback.h"
#include "shell/browser/api/atom_api_top_level_window.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/common/gin_helper/error_thrower.h"
namespace electron {
@ -22,7 +23,8 @@ class BrowserWindow : public TopLevelWindow,
public content::WebContentsObserver,
public ExtendedWebContentsObserver {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static mate::WrappableBase* New(gin_helper::ErrorThrower thrower,
gin::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
@ -36,9 +38,7 @@ class BrowserWindow : public TopLevelWindow,
}
protected:
BrowserWindow(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
const mate::Dictionary& options);
BrowserWindow(gin::Arguments* args, const mate::Dictionary& options);
~BrowserWindow() override;
// content::RenderWidgetHost::InputEventObserver:

View file

@ -28,9 +28,8 @@ namespace electron {
namespace api {
Menu::Menu(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
: model_(new AtomMenuModel(this)) {
InitWith(isolate, wrapper);
Menu::Menu(gin::Arguments* args) : model_(new AtomMenuModel(this)) {
InitWithArgs(args);
model_->AddObserver(this);
}

View file

@ -9,6 +9,7 @@
#include <string>
#include "base/callback.h"
#include "gin/arguments.h"
#include "shell/browser/api/atom_api_top_level_window.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/ui/atom_menu_model.h"
@ -21,7 +22,7 @@ class Menu : public mate::TrackableObject<Menu>,
public AtomMenuModel::Delegate,
public AtomMenuModel::Observer {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static mate::WrappableBase* New(gin::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
@ -37,7 +38,7 @@ class Menu : public mate::TrackableObject<Menu>,
AtomMenuModel* model() const { return model_.get(); }
protected:
Menu(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
explicit Menu(gin::Arguments* args);
~Menu() override;
// mate::Wrappable:
@ -144,31 +145,4 @@ struct Converter<electron::AtomMenuModel*> {
} // namespace mate
namespace gin {
template <>
struct Converter<electron::AtomMenuModel*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::AtomMenuModel** out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
// 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_

View file

@ -20,7 +20,7 @@ namespace api {
class MenuMac : public Menu {
protected:
MenuMac(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
explicit MenuMac(gin::Arguments* args);
~MenuMac() override;
void PopupAt(TopLevelWindow* window,

View file

@ -30,8 +30,7 @@ namespace electron {
namespace api {
MenuMac::MenuMac(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
: Menu(isolate, wrapper), weak_factory_(this) {}
MenuMac::MenuMac(gin::Arguments* args) : Menu(args), weak_factory_(this) {}
MenuMac::~MenuMac() = default;
@ -173,8 +172,8 @@ void Menu::SendActionToFirstResponder(const std::string& action) {
}
// static
mate::WrappableBase* Menu::New(mate::Arguments* args) {
return new MenuMac(args->isolate(), args->GetThis());
mate::WrappableBase* Menu::New(gin::Arguments* args) {
return new MenuMac(args);
}
} // namespace api

View file

@ -16,8 +16,7 @@ namespace electron {
namespace api {
MenuViews::MenuViews(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
: Menu(isolate, wrapper), weak_factory_(this) {}
MenuViews::MenuViews(gin::Arguments* args) : Menu(args), weak_factory_(this) {}
MenuViews::~MenuViews() = default;
@ -75,8 +74,8 @@ void MenuViews::OnClosed(int32_t window_id, base::Closure callback) {
}
// static
mate::WrappableBase* Menu::New(mate::Arguments* args) {
return new MenuViews(args->isolate(), args->GetThis());
mate::WrappableBase* Menu::New(gin::Arguments* args) {
return new MenuViews(args);
}
} // namespace api

View file

@ -19,7 +19,7 @@ namespace api {
class MenuViews : public Menu {
public:
MenuViews(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
explicit MenuViews(gin::Arguments* args);
~MenuViews() override;
protected:

View file

@ -60,20 +60,6 @@ struct Converter<ui::NativeTheme::ThemeSource> {
ui::NativeTheme::ThemeSource* out);
};
// TODO(zcbenz): Remove this after converting NativeTheme to gin::Wrapper.
template <>
struct Converter<electron::api::NativeTheme*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::api::NativeTheme** out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::NativeTheme* in) {
return mate::ConvertToV8(isolate, in);
}
};
} // namespace gin
#endif // SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_

View file

@ -49,9 +49,8 @@ namespace electron {
namespace api {
Notification::Notification(v8::Local<v8::Object> wrapper,
gin::Arguments* args) {
InitWith(args->isolate(), wrapper);
Notification::Notification(gin::Arguments* args) {
InitWithArgs(args);
presenter_ = static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
->GetNotificationPresenter();
@ -82,13 +81,13 @@ Notification::~Notification() {
}
// static
mate::WrappableBase* Notification::New(mate::Arguments* args) {
mate::WrappableBase* Notification::New(gin_helper::ErrorThrower thrower,
gin::Arguments* args) {
if (!Browser::Get()->is_ready()) {
args->ThrowError("Cannot create Notification before app is ready");
thrower.ThrowError("Cannot create Notification before app is ready");
return nullptr;
}
gin::Arguments gin_args(args->info());
return new Notification(args->GetThis(), &gin_args);
return new Notification(args);
}
// Getters

View file

@ -14,6 +14,7 @@
#include "shell/browser/notifications/notification.h"
#include "shell/browser/notifications/notification_delegate.h"
#include "shell/browser/notifications/notification_presenter.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "ui/gfx/image/image.h"
namespace gin {
@ -27,7 +28,8 @@ namespace api {
class Notification : public mate::TrackableObject<Notification>,
public NotificationDelegate {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static mate::WrappableBase* New(gin_helper::ErrorThrower thrower,
gin::Arguments* args);
static bool IsSupported();
static void BuildPrototype(v8::Isolate* isolate,
@ -42,7 +44,7 @@ class Notification : public mate::TrackableObject<Notification>,
void NotificationClosed() override;
protected:
Notification(v8::Local<v8::Object> wrapper, gin::Arguments* args);
explicit Notification(gin::Arguments* args);
~Notification() override;
void Show();
@ -101,22 +103,4 @@ class Notification : public mate::TrackableObject<Notification>,
} // namespace electron
namespace gin {
// TODO(zcbenz): Remove this after converting Notification to gin::Wrapper.
template <>
struct Converter<electron::api::Notification*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::api::Notification** out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::Notification* in) {
return mate::ConvertToV8(isolate, in);
}
};
} // namespace gin
#endif // SHELL_BROWSER_API_ATOM_API_NOTIFICATION_H_

View file

@ -13,8 +13,10 @@
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/browser.h"
#include "shell/common/deprecate_util.h"
#include "shell/common/native_mate_converters/net_converter.h"
#include "shell/common/native_mate_converters/once_callback.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/net_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/options_switches.h"
#include "shell/common/promise_util.h"
@ -39,19 +41,19 @@ struct CustomScheme {
} // namespace
namespace mate {
namespace gin {
template <>
struct Converter<CustomScheme> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
CustomScheme* out) {
mate::Dictionary dict;
gin::Dictionary dict(isolate);
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (!dict.Get("scheme", &(out->scheme)))
return false;
mate::Dictionary opt;
gin::Dictionary opt(isolate);
// options are optional. Default values specified in SchemeOptions are used
if (dict.Get("privileges", &opt)) {
opt.Get("standard", &(out->options.standard));
@ -66,7 +68,7 @@ struct Converter<CustomScheme> {
}
};
} // namespace mate
} // namespace gin
namespace electron {
namespace api {
@ -75,11 +77,11 @@ std::vector<std::string> GetStandardSchemes() {
return g_standard_schemes;
}
void RegisterSchemesAsPrivileged(v8::Local<v8::Value> val,
mate::Arguments* args) {
void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> val) {
std::vector<CustomScheme> custom_schemes;
if (!mate::ConvertFromV8(args->isolate(), val, &custom_schemes)) {
args->ThrowError("Argument must be an array of custom schemes.");
if (!gin::ConvertFromV8(thrower.isolate(), val, &custom_schemes)) {
thrower.ThrowError("Argument must be an array of custom schemes.");
return;
}
@ -181,7 +183,7 @@ ProtocolError ProtocolNS::RegisterProtocol(ProtocolType type,
}
void ProtocolNS::UnregisterProtocol(const std::string& scheme,
mate::Arguments* args) {
gin::Arguments* args) {
const bool removed = handlers_.erase(scheme) != 0;
const auto error =
removed ? ProtocolError::OK : ProtocolError::NOT_REGISTERED;
@ -201,7 +203,7 @@ ProtocolError ProtocolNS::InterceptProtocol(ProtocolType type,
}
void ProtocolNS::UninterceptProtocol(const std::string& scheme,
mate::Arguments* args) {
gin::Arguments* args) {
const bool removed = intercept_handlers_.erase(scheme) != 0;
const auto error =
removed ? ProtocolError::OK : ProtocolError::NOT_INTERCEPTED;
@ -213,7 +215,7 @@ bool ProtocolNS::IsProtocolIntercepted(const std::string& scheme) {
}
v8::Local<v8::Promise> ProtocolNS::IsProtocolHandled(const std::string& scheme,
mate::Arguments* args) {
gin::Arguments* args) {
node::Environment* env = node::Environment::GetCurrent(args->isolate());
EmitDeprecationWarning(
env,
@ -234,7 +236,7 @@ v8::Local<v8::Promise> ProtocolNS::IsProtocolHandled(const std::string& scheme,
base::Contains(kBuiltinSchemes, scheme));
}
void ProtocolNS::HandleOptionalCallback(mate::Arguments* args,
void ProtocolNS::HandleOptionalCallback(gin::Arguments* args,
ProtocolError error) {
CompletionCallback callback;
if (args->GetNext(&callback)) {
@ -247,22 +249,22 @@ void ProtocolNS::HandleOptionalCallback(mate::Arguments* args,
callback.Run(v8::Null(args->isolate()));
else
callback.Run(v8::Exception::Error(
mate::StringToV8(isolate(), ErrorCodeToString(error))));
gin::StringToV8(isolate(), ErrorCodeToString(error))));
}
}
// static
mate::Handle<ProtocolNS> ProtocolNS::Create(
gin::Handle<ProtocolNS> ProtocolNS::Create(
v8::Isolate* isolate,
AtomBrowserContext* browser_context) {
return mate::CreateHandle(isolate, new ProtocolNS(isolate, browser_context));
return gin::CreateHandle(isolate, new ProtocolNS(isolate, browser_context));
}
// static
void ProtocolNS::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Protocol"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
prototype->SetClassName(gin::StringToV8(isolate, "Protocol"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("registerStringProtocol",
&ProtocolNS::RegisterProtocolFor<ProtocolType::kString>)
.SetMethod("registerBufferProtocol",
@ -299,16 +301,16 @@ void ProtocolNS::BuildPrototype(v8::Isolate* isolate,
namespace {
void RegisterSchemesAsPrivileged(v8::Local<v8::Value> val,
mate::Arguments* args) {
void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> val) {
if (electron::Browser::Get()->is_ready()) {
args->ThrowError(
thrower.ThrowError(
"protocol.registerSchemesAsPrivileged should be called before "
"app is ready");
return;
}
electron::api::RegisterSchemesAsPrivileged(val, args);
electron::api::RegisterSchemesAsPrivileged(thrower, val);
}
void Initialize(v8::Local<v8::Object> exports,
@ -316,7 +318,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
gin_helper::Dictionary dict(isolate, exports);
dict.SetMethod("registerSchemesAsPrivileged", &RegisterSchemesAsPrivileged);
dict.SetMethod("getStandardSchemes", &electron::api::GetStandardSchemes);
}

View file

@ -9,10 +9,10 @@
#include <vector>
#include "content/public/browser/content_browser_client.h"
#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
#include "gin/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/net/atom_url_loader_factory.h"
#include "shell/common/gin_helper/dictionary.h"
namespace electron {
@ -22,8 +22,8 @@ namespace api {
std::vector<std::string> GetStandardSchemes();
void RegisterSchemesAsPrivileged(v8::Local<v8::Value> val,
mate::Arguments* args);
void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> val);
// Possible errors.
enum class ProtocolError {
@ -37,8 +37,8 @@ enum class ProtocolError {
// Protocol implementation based on network services.
class ProtocolNS : public mate::TrackableObject<ProtocolNS> {
public:
static mate::Handle<ProtocolNS> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
static gin::Handle<ProtocolNS> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
@ -61,35 +61,35 @@ class ProtocolNS : public mate::TrackableObject<ProtocolNS> {
ProtocolError RegisterProtocol(ProtocolType type,
const std::string& scheme,
const ProtocolHandler& handler);
void UnregisterProtocol(const std::string& scheme, mate::Arguments* args);
void UnregisterProtocol(const std::string& scheme, gin::Arguments* args);
bool IsProtocolRegistered(const std::string& scheme);
ProtocolError InterceptProtocol(ProtocolType type,
const std::string& scheme,
const ProtocolHandler& handler);
void UninterceptProtocol(const std::string& scheme, mate::Arguments* args);
void UninterceptProtocol(const std::string& scheme, gin::Arguments* args);
bool IsProtocolIntercepted(const std::string& scheme);
// Old async version of IsProtocolRegistered.
v8::Local<v8::Promise> IsProtocolHandled(const std::string& scheme,
mate::Arguments* args);
gin::Arguments* args);
// Helper for converting old registration APIs to new RegisterProtocol API.
template <ProtocolType type>
void RegisterProtocolFor(const std::string& scheme,
const ProtocolHandler& handler,
mate::Arguments* args) {
gin::Arguments* args) {
HandleOptionalCallback(args, RegisterProtocol(type, scheme, handler));
}
template <ProtocolType type>
void InterceptProtocolFor(const std::string& scheme,
const ProtocolHandler& handler,
mate::Arguments* args) {
gin::Arguments* args) {
HandleOptionalCallback(args, InterceptProtocol(type, scheme, handler));
}
// Be compatible with old interface, which accepts optional callback.
void HandleOptionalCallback(mate::Arguments* args, ProtocolError error);
void HandleOptionalCallback(gin::Arguments* args, ProtocolError error);
HandlersMap handlers_;
HandlersMap intercept_handlers_;

View file

@ -121,22 +121,4 @@ 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_

View file

@ -108,11 +108,10 @@ TopLevelWindow::TopLevelWindow(v8::Isolate* isolate,
#endif
}
TopLevelWindow::TopLevelWindow(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
TopLevelWindow::TopLevelWindow(gin::Arguments* args,
const mate::Dictionary& options)
: TopLevelWindow(isolate, options) {
InitWith(isolate, wrapper);
: TopLevelWindow(args->isolate(), options) {
InitWithArgs(args);
// Init window after everything has been setup.
window()->InitFromOptions(options);
}
@ -1057,11 +1056,11 @@ void TopLevelWindow::RemoveFromParentChildWindows() {
}
// static
mate::WrappableBase* TopLevelWindow::New(mate::Arguments* args) {
mate::WrappableBase* TopLevelWindow::New(gin::Arguments* args) {
mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
args->GetNext(&options);
return new TopLevelWindow(args->isolate(), args->GetThis(), options);
return new TopLevelWindow(args, options);
}
// static

View file

@ -28,7 +28,7 @@ class View;
class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
public NativeWindowObserver {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static mate::WrappableBase* New(gin::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
@ -43,9 +43,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
// Common constructor.
TopLevelWindow(v8::Isolate* isolate, const mate::Dictionary& options);
// Creating independent TopLevelWindow instance.
TopLevelWindow(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
const mate::Dictionary& options);
TopLevelWindow(gin::Arguments* args, const mate::Dictionary& options);
~TopLevelWindow() override;
// TrackableObject:
@ -266,22 +264,4 @@ 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_

View file

@ -55,26 +55,25 @@ namespace electron {
namespace api {
Tray::Tray(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
mate::Handle<NativeImage> image)
Tray::Tray(mate::Handle<NativeImage> image, gin::Arguments* args)
: tray_icon_(TrayIcon::Create()) {
SetImage(isolate, image);
SetImage(args->isolate(), image);
tray_icon_->AddObserver(this);
InitWith(isolate, wrapper);
InitWithArgs(args);
}
Tray::~Tray() = default;
// static
mate::WrappableBase* Tray::New(mate::Handle<NativeImage> image,
mate::Arguments* args) {
mate::WrappableBase* Tray::New(gin_helper::ErrorThrower thrower,
mate::Handle<NativeImage> image,
gin::Arguments* args) {
if (!Browser::Get()->is_ready()) {
args->ThrowError("Cannot create Tray before app is ready");
thrower.ThrowError("Cannot create Tray before app is ready");
return nullptr;
}
return new Tray(args->isolate(), args->GetThis(), image);
return new Tray(image, args);
}
void Tray::OnClicked(const gfx::Rect& bounds,

View file

@ -13,6 +13,7 @@
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/ui/tray_icon.h"
#include "shell/browser/ui/tray_icon_observer.h"
#include "shell/common/gin_helper/error_thrower.h"
namespace gfx {
class Image;
@ -34,16 +35,15 @@ class NativeImage;
class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
public:
static mate::WrappableBase* New(mate::Handle<NativeImage> image,
mate::Arguments* args);
static mate::WrappableBase* New(gin_helper::ErrorThrower thrower,
mate::Handle<NativeImage> image,
gin::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
Tray(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
mate::Handle<NativeImage> image);
Tray(mate::Handle<NativeImage> image, gin::Arguments* args);
~Tray() override;
// TrayIconObserver:

View file

@ -6,21 +6,22 @@
#include <utility>
#include "gin/handle.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/system/string_data_source.h"
#include "native_mate/dictionary.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_converters/gurl_converter.h"
#include "shell/common/gin_converters/net_converter.h"
#include "shell/common/gin_helper/dictionary.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"
#include "shell/common/node_includes.h"
namespace mate {
namespace gin {
template <>
struct Converter<network::mojom::RedirectMode> {
@ -42,7 +43,7 @@ struct Converter<network::mojom::RedirectMode> {
}
};
} // namespace mate
} // namespace gin
namespace electron {
@ -165,9 +166,9 @@ class ChunkedDataPipeGetter : public UploadDataPipeGetter,
mojo::ReceiverSet<network::mojom::ChunkedDataPipeGetter> receiver_set_;
};
URLRequestNS::URLRequestNS(mate::Arguments* args) : weak_factory_(this) {
URLRequestNS::URLRequestNS(gin::Arguments* args) : weak_factory_(this) {
request_ = std::make_unique<network::ResourceRequest>();
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (args->GetNext(&dict)) {
dict.Get("method", &request_->method);
dict.Get("url", &request_->url);
@ -186,7 +187,7 @@ URLRequestNS::URLRequestNS(mate::Arguments* args) : weak_factory_(this) {
url_loader_factory_ = session->browser_context()->GetURLLoaderFactory();
InitWith(args->isolate(), args->GetThis());
InitWithArgs(args);
}
URLRequestNS::~URLRequestNS() = default;
@ -518,7 +519,7 @@ void URLRequestNS::EmitEvent(EventType type, Args... args) {
}
// static
mate::WrappableBase* URLRequestNS::New(mate::Arguments* args) {
mate::WrappableBase* URLRequestNS::New(gin::Arguments* args) {
return new URLRequestNS(args);
}

View file

@ -28,13 +28,13 @@ class UploadDataPipeGetter;
class URLRequestNS : public mate::EventEmitter<URLRequestNS>,
public network::SimpleURLLoaderStreamConsumer {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static mate::WrappableBase* New(gin::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
explicit URLRequestNS(mate::Arguments* args);
explicit URLRequestNS(gin::Arguments* args);
~URLRequestNS() override;
bool NotStarted() const;
@ -141,22 +141,4 @@ 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_

View file

@ -42,9 +42,9 @@ void View::AddChildViewAt(mate::Handle<View> child, size_t index) {
#endif
// static
mate::WrappableBase* View::New(mate::Arguments* args) {
mate::WrappableBase* View::New(gin::Arguments* args) {
auto* view = new View();
view->InitWith(args->isolate(), args->GetThis());
view->InitWithArgs(args);
return view;
}

View file

@ -19,7 +19,7 @@ namespace api {
class View : public mate::TrackableObject<View> {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static mate::WrappableBase* New(gin::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);

View file

@ -575,22 +575,4 @@ class WebContents : public mate::TrackableObject<WebContents>,
} // namespace electron
namespace gin {
// TODO(zcbenz): Remove this after converting WebContents to gin::Wrapper.
template <>
struct Converter<electron::api::WebContents*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::api::WebContents** out) {
return mate::ConvertFromV8(isolate, val, out);
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::WebContents* in) {
return mate::ConvertToV8(isolate, in);
}
};
} // namespace gin
#endif // SHELL_BROWSER_API_ATOM_API_WEB_CONTENTS_H_

View file

@ -80,7 +80,7 @@ void WebContentsView::WebContentsDestroyed() {
// static
mate::WrappableBase* WebContentsView::New(
mate::Arguments* args,
gin::Arguments* args,
mate::Handle<WebContents> web_contents) {
// Currently we only support InspectableWebContents, e.g. the WebContents
// created by users directly. To support devToolsWebContents we need to create
@ -101,7 +101,7 @@ mate::WrappableBase* WebContentsView::New(
// Constructor call.
auto* view = new WebContentsView(args->isolate(), web_contents,
web_contents->managed_web_contents());
view->InitWith(args->isolate(), args->GetThis());
view->InitWithArgs(args);
return view;
}

View file

@ -19,7 +19,7 @@ class WebContents;
class WebContentsView : public View, public content::WebContentsObserver {
public:
static mate::WrappableBase* New(mate::Arguments* args,
static mate::WrappableBase* New(gin::Arguments* args,
mate::Handle<WebContents> web_contents);
static void BuildPrototype(v8::Isolate* isolate,

View file

@ -13,8 +13,6 @@
#include "gin/arguments.h"
#include "gin/handle.h"
#include "gin/wrappable.h"
#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
#include "shell/browser/net/proxying_url_loader_factory.h"
namespace content {