chore: remove native_mate (Part 11) (#20719)

* refactor: convert Menu and globalShortcut to gin

* refactor: convert api::Cookies to gin

* refactor: convert View and WebContentsView to gin

* refactor: convert WebContents related classes to gin

* refactor: convert powerMonitor to gin

* refactor: prepare for header change

* refactor: remove last uses of mate::EventEmitter

* refactor: remove mate::EventEmitter

* refactor: move trackable_object to gin_helper

* fix: custom converter should not use Handle

* fix: no more need to check if icon is empty

It was a bug that the Handle<NativeImage> can be non-empty when the
image file does not exist. The bug was caused by the converter code
writing out the image even when the convertion fails.

The bug was work-arounded by adding an additional check, but since the
original bug had been fixed, the additional check is no longer needed.

* fix: should always set frameId even when callback is null

* fix: do not mix gin/mate handles for NativeImage
This commit is contained in:
Cheng Zhao 2019-10-25 22:03:28 +09:00 committed by GitHub
parent 0e0d4fe990
commit 0fe6767d6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
80 changed files with 823 additions and 1087 deletions

View file

@ -112,10 +112,6 @@ filenames = {
"shell/browser/api/atom_api_browser_window_views.cc",
"shell/browser/api/event.cc",
"shell/browser/api/event.h",
"shell/browser/api/event_emitter_deprecated.cc",
"shell/browser/api/event_emitter_deprecated.h",
"shell/browser/api/trackable_object.cc",
"shell/browser/api/trackable_object.h",
"shell/browser/api/frame_subscriber.cc",
"shell/browser/api/frame_subscriber.h",
"shell/browser/api/gpu_info_enumerator.cc",
@ -468,7 +464,11 @@ filenames = {
"shell/common/crash_reporter/linux/crash_dump_handler.h",
"shell/common/crash_reporter/win/crash_service_main.cc",
"shell/common/crash_reporter/win/crash_service_main.h",
"shell/common/gin_converters/accelerator_converter.cc",
"shell/common/gin_converters/accelerator_converter.h",
"shell/common/gin_converters/callback_converter.h",
"shell/common/gin_converters/content_converter.cc",
"shell/common/gin_converters/content_converter.h",
"shell/common/gin_converters/file_dialog_converter.cc",
"shell/common/gin_converters/file_dialog_converter.h",
"shell/common/gin_converters/file_path_converter.h",
@ -502,6 +502,8 @@ filenames = {
"shell/common/gin_helper/function_template.h",
"shell/common/gin_helper/object_template_builder.cc",
"shell/common/gin_helper/object_template_builder.h",
"shell/common/gin_helper/trackable_object.cc",
"shell/common/gin_helper/trackable_object.h",
"shell/common/heap_snapshot.cc",
"shell/common/heap_snapshot.h",
"shell/common/key_weak_map.h",
@ -513,25 +515,18 @@ filenames = {
"shell/common/mouse_util.h",
"shell/common/mac/main_application_bundle.h",
"shell/common/mac/main_application_bundle.mm",
"shell/common/native_mate_converters/accelerator_converter.cc",
"shell/common/native_mate_converters/accelerator_converter.h",
"shell/common/native_mate_converters/blink_converter.cc",
"shell/common/native_mate_converters/blink_converter.h",
"shell/common/native_mate_converters/callback_converter_deprecated.cc",
"shell/common/native_mate_converters/callback_converter_deprecated.h",
"shell/common/native_mate_converters/content_converter.cc",
"shell/common/native_mate_converters/content_converter.h",
"shell/common/native_mate_converters/file_dialog_converter.h",
"shell/common/native_mate_converters/file_path_converter.h",
"shell/common/native_mate_converters/gurl_converter.h",
"shell/common/native_mate_converters/image_converter.h",
"shell/common/native_mate_converters/native_window_converter.h",
"shell/common/native_mate_converters/net_converter.h",
"shell/common/native_mate_converters/network_converter.cc",
"shell/common/native_mate_converters/network_converter.h",
"shell/common/native_mate_converters/once_callback.h",
"shell/common/native_mate_converters/string16_converter.h",
"shell/common/native_mate_converters/ui_base_types_converter.h",
"shell/common/native_mate_converters/v8_value_converter.cc",
"shell/common/native_mate_converters/v8_value_converter.h",
"shell/common/native_mate_converters/value_converter.cc",

View file

@ -18,7 +18,6 @@
#include "content/public/browser/gpu_data_manager_observer.h"
#include "content/public/browser/render_process_host.h"
#include "gin/handle.h"
#include "native_mate/wrappable.h"
#include "net/base/completion_once_callback.h"
#include "net/base/completion_repeating_callback.h"
#include "net/ssl/client_cert_identity.h"
@ -48,7 +47,7 @@ enum class JumpListResult : int;
namespace api {
class App : public AtomBrowserClient::Delegate,
public gin_helper::EventEmitter<mate::Wrappable<App>>,
public gin_helper::EventEmitter<App>,
public BrowserObserver,
public content::GpuDataManagerObserver,
public content::BrowserChildProcessObserver {

View file

@ -8,7 +8,6 @@
#include <string>
#include "gin/handle.h"
#include "native_mate/wrappable.h"
#include "shell/browser/auto_updater.h"
#include "shell/browser/window_list_observer.h"
#include "shell/common/gin_helper/event_emitter.h"
@ -17,10 +16,9 @@ namespace electron {
namespace api {
class AutoUpdater
: public gin_helper::EventEmitter<mate::Wrappable<AutoUpdater>>,
public auto_updater::Delegate,
public WindowListObserver {
class AutoUpdater : public gin_helper::EventEmitter<AutoUpdater>,
public auto_updater::Delegate,
public WindowListObserver {
public:
static gin::Handle<AutoUpdater> Create(v8::Isolate* isolate);

View file

@ -4,7 +4,6 @@
#include "shell/browser/api/atom_api_browser_view.h"
#include "native_mate/dictionary.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/browser.h"
#include "shell/browser/native_browser_view.h"
@ -64,11 +63,8 @@ BrowserView::BrowserView(gin::Arguments* args,
gin::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences);
web_preferences.Set("type", "browserView");
mate::Handle<class WebContents> web_contents = WebContents::Create(
isolate,
// TODO(zcbenz): No need to do convertion after converting constructor
// of WebContents to gin.
mate::Dictionary(isolate, web_preferences.GetHandle()));
gin::Handle<class WebContents> web_contents =
WebContents::Create(isolate, web_preferences);
web_contents_.Reset(isolate, web_contents.ToV8());
api_web_contents_ = web_contents.get();

View file

@ -10,9 +10,9 @@
#include "content/public/browser/web_contents_observer.h"
#include "gin/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/native_browser_view.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/trackable_object.h"
namespace gfx {
class Rect;
@ -30,7 +30,7 @@ namespace api {
class WebContents;
class BrowserView : public mate::TrackableObject<BrowserView>,
class BrowserView : public gin_helper::TrackableObject<BrowserView>,
public content::WebContentsObserver {
public:
static mate::WrappableBase* New(gin_helper::ErrorThrower thrower,

View file

@ -12,15 +12,15 @@
#include "content/browser/web_contents/web_contents_impl.h" // nogncheck
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "gin/converter.h"
#include "native_mate/dictionary.h"
#include "shell/browser/browser.h"
#include "shell/browser/unresponsive_suppressor.h"
#include "shell/browser/web_contents_preferences.h"
#include "shell/browser/window_list.h"
#include "shell/common/api/constructor.h"
#include "shell/common/color_util.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#include "ui/gl/gpu_switching_manager.h"
@ -30,13 +30,14 @@ namespace electron {
namespace api {
BrowserWindow::BrowserWindow(gin::Arguments* args,
const mate::Dictionary& options)
const gin_helper::Dictionary& options)
: TopLevelWindow(args->isolate(), options), weak_factory_(this) {
mate::Handle<class WebContents> web_contents;
gin::Handle<class WebContents> web_contents;
// Use options.webPreferences in WebContents.
v8::Isolate* isolate = args->isolate();
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary web_preferences =
gin::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences);
// Copy the backgroundColor to webContents.
@ -66,8 +67,8 @@ BrowserWindow::BrowserWindow(gin::Arguments* args,
auto* existing_preferences =
WebContentsPreferences::From(web_contents->web_contents());
base::DictionaryValue web_preferences_dict;
if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(),
&web_preferences_dict)) {
if (gin::ConvertFromV8(isolate, web_preferences.GetHandle(),
&web_preferences_dict)) {
existing_preferences->Clear();
existing_preferences->Merge(web_preferences_dict);
}
@ -82,7 +83,7 @@ BrowserWindow::BrowserWindow(gin::Arguments* args,
Observe(api_web_contents_->web_contents());
// Keep a copy of the options for later use.
mate::Dictionary(isolate, web_contents->GetWrapper())
gin_helper::Dictionary(isolate, web_contents->GetWrapper())
.Set("browserWindowOptions", options);
// Associate with BrowserWindow.
@ -195,8 +196,8 @@ void BrowserWindow::OnCloseContents() {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
for (v8::Local<v8::Value> value : child_windows_.Values(isolate())) {
mate::Handle<BrowserWindow> child;
if (mate::ConvertFromV8(isolate(), value, &child) && !child.IsEmpty())
gin::Handle<BrowserWindow> child;
if (gin::ConvertFromV8(isolate(), value, &child) && !child.IsEmpty())
child->window()->CloseImmediately();
}
@ -456,9 +457,9 @@ mate::WrappableBase* BrowserWindow::New(gin_helper::ErrorThrower thrower,
return nullptr;
}
mate::Dictionary options;
gin_helper::Dictionary options;
if (!(args->Length() == 1 && args->GetNext(&options))) {
options = mate::Dictionary::CreateEmpty(args->isolate());
options = gin::Dictionary::CreateEmpty(args->isolate());
}
return new BrowserWindow(args, options);
@ -467,8 +468,8 @@ mate::WrappableBase* BrowserWindow::New(gin_helper::ErrorThrower thrower,
// static
void BrowserWindow::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
prototype->SetClassName(gin::StringToV8(isolate, "BrowserWindow"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("focusOnWebView", &BrowserWindow::FocusOnWebView)
.SetMethod("blurWebView", &BrowserWindow::BlurWebView)
.SetMethod("isWebViewFocused", &BrowserWindow::IsWebViewFocused)
@ -499,7 +500,7 @@ void Initialize(v8::Local<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.Set("BrowserWindow",
mate::CreateConstructor<BrowserWindow>(
isolate, base::BindRepeating(&BrowserWindow::New)));

View file

@ -38,7 +38,7 @@ class BrowserWindow : public TopLevelWindow,
}
protected:
BrowserWindow(gin::Arguments* args, const mate::Dictionary& options);
BrowserWindow(gin::Arguments* args, const gin_helper::Dictionary& options);
~BrowserWindow() override;
// content::RenderWidgetHost::InputEventObserver:

View file

@ -15,14 +15,15 @@
#include "content/public/browser/storage_partition.h"
#include "gin/dictionary.h"
#include "gin/object_template_builder.h"
#include "native_mate/dictionary.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_store.h"
#include "net/cookies/cookie_util.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/cookie_change_notifier.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
using content::BrowserThread;
@ -175,7 +176,7 @@ Cookies::Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context)
Cookies::~Cookies() = default;
v8::Local<v8::Promise> Cookies::Get(const mate::Dictionary& filter) {
v8::Local<v8::Promise> Cookies::Get(const gin_helper::Dictionary& filter) {
util::Promise<net::CookieList> promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
@ -184,7 +185,7 @@ v8::Local<v8::Promise> Cookies::Get(const mate::Dictionary& filter) {
auto* manager = storage_partition->GetCookieManagerForBrowserProcess();
base::DictionaryValue dict;
mate::ConvertFromV8(isolate(), filter.GetHandle(), &dict);
gin::ConvertFromV8(isolate(), filter.GetHandle(), &dict);
std::string url;
filter.Get("url", &url);
@ -339,7 +340,7 @@ gin::Handle<Cookies> Cookies::Create(v8::Isolate* isolate,
void Cookies::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(gin::StringToV8(isolate, "Cookies"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("get", &Cookies::Get)
.SetMethod("remove", &Cookies::Remove)
.SetMethod("set", &Cookies::Set)

View file

@ -11,15 +11,15 @@
#include "base/callback_list.h"
#include "gin/handle.h"
#include "net/cookies/canonical_cookie.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/net/cookie_details.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "shell/common/promise_util.h"
namespace base {
class DictionaryValue;
}
namespace mate {
namespace gin_helper {
class Dictionary;
}
@ -33,12 +33,12 @@ class AtomBrowserContext;
namespace api {
class Cookies : public mate::TrackableObject<Cookies> {
class Cookies : public gin_helper::TrackableObject<Cookies> {
public:
static gin::Handle<Cookies> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
// mate::TrackableObject:
// gin_helper::TrackableObject:
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
@ -46,7 +46,7 @@ class Cookies : public mate::TrackableObject<Cookies> {
Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context);
~Cookies() override;
v8::Local<v8::Promise> Get(const mate::Dictionary& filter);
v8::Local<v8::Promise> Get(const gin_helper::Dictionary& filter);
v8::Local<v8::Promise> Set(const base::DictionaryValue& details);
v8::Local<v8::Promise> Remove(const GURL& url, const std::string& name);
v8::Local<v8::Promise> FlushStore();

View file

@ -12,8 +12,9 @@
#include "base/json/json_writer.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/web_contents.h"
#include "native_mate/dictionary.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
using content::DevToolsAgentHost;
@ -93,7 +94,7 @@ void Debugger::RenderFrameHostChanged(content::RenderFrameHost* old_rfh,
}
}
void Debugger::Attach(mate::Arguments* args) {
void Debugger::Attach(gin_helper::Arguments* args) {
std::string protocol_version;
args->GetNext(&protocol_version);
@ -128,7 +129,7 @@ void Debugger::Detach() {
AgentHostClosed(agent_host_.get());
}
v8::Local<v8::Promise> Debugger::SendCommand(mate::Arguments* args) {
v8::Local<v8::Promise> Debugger::SendCommand(gin_helper::Arguments* args) {
electron::util::Promise<base::DictionaryValue> promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
@ -168,16 +169,16 @@ void Debugger::ClearPendingRequests() {
}
// static
mate::Handle<Debugger> Debugger::Create(v8::Isolate* isolate,
content::WebContents* web_contents) {
return mate::CreateHandle(isolate, new Debugger(isolate, web_contents));
gin::Handle<Debugger> Debugger::Create(v8::Isolate* isolate,
content::WebContents* web_contents) {
return gin::CreateHandle(isolate, new Debugger(isolate, web_contents));
}
// static
void Debugger::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Debugger"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
prototype->SetClassName(gin::StringToV8(isolate, "Debugger"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("attach", &Debugger::Attach)
.SetMethod("isAttached", &Debugger::IsAttached)
.SetMethod("detach", &Debugger::Detach)
@ -197,7 +198,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary(isolate, exports)
gin_helper::Dictionary(isolate, exports)
.Set("Debugger", Debugger::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());

View file

@ -12,8 +12,8 @@
#include "base/values.h"
#include "content/public/browser/devtools_agent_host_client.h"
#include "content/public/browser/web_contents_observer.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "gin/handle.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "shell/common/promise_util.h"
namespace content {
@ -21,22 +21,18 @@ class DevToolsAgentHost;
class WebContents;
} // namespace content
namespace mate {
class Arguments;
}
namespace electron {
namespace api {
class Debugger : public mate::TrackableObject<Debugger>,
class Debugger : public gin_helper::TrackableObject<Debugger>,
public content::DevToolsAgentHostClient,
public content::WebContentsObserver {
public:
static mate::Handle<Debugger> Create(v8::Isolate* isolate,
content::WebContents* web_contents);
static gin::Handle<Debugger> Create(v8::Isolate* isolate,
content::WebContents* web_contents);
// mate::TrackableObject:
// gin_helper::TrackableObject:
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
@ -57,10 +53,10 @@ class Debugger : public mate::TrackableObject<Debugger>,
using PendingRequestMap =
std::map<int, electron::util::Promise<base::DictionaryValue>>;
void Attach(mate::Arguments* args);
void Attach(gin_helper::Arguments* args);
bool IsAttached();
void Detach();
v8::Local<v8::Promise> SendCommand(mate::Arguments* args);
v8::Local<v8::Promise> SendCommand(gin_helper::Arguments* args);
void ClearPendingRequests();
content::WebContents* web_contents_; // Weak Reference.

View file

@ -12,17 +12,13 @@
#include "chrome/browser/media/webrtc/desktop_media_list_observer.h"
#include "chrome/browser/media/webrtc/native_desktop_media_list.h"
#include "gin/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/common/gin_helper/event_emitter.h"
#include "shell/common/gin_helper/trackable_object.h"
namespace electron {
namespace api {
class DesktopCapturer
: public mate::TrackableObject<
DesktopCapturer,
gin_helper::EventEmitter<mate::Wrappable<DesktopCapturer>>> {
class DesktopCapturer : public gin_helper::TrackableObject<DesktopCapturer> {
public:
struct Source {
DesktopMediaList::Source media_list_source;

View file

@ -8,15 +8,16 @@
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "native_mate/dictionary.h"
#include "net/base/filename_util.h"
#include "shell/browser/atom_browser_main_parts.h"
#include "shell/common/native_mate_converters/file_dialog_converter.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/gin_converters/file_dialog_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
namespace mate {
namespace gin {
template <>
struct Converter<download::DownloadItem::DownloadState> {
@ -44,7 +45,7 @@ struct Converter<download::DownloadItem::DownloadState> {
}
};
} // namespace mate
} // namespace gin
namespace electron {
@ -52,7 +53,7 @@ namespace api {
namespace {
std::map<uint32_t, v8::Global<v8::Object>> g_download_item_objects;
std::map<uint32_t, v8::Global<v8::Value>> g_download_item_objects;
} // namespace
@ -188,9 +189,9 @@ double DownloadItem::GetStartTime() const {
// static
void DownloadItem::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "DownloadItem"));
prototype->SetClassName(gin::StringToV8(isolate, "DownloadItem"));
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("pause", &DownloadItem::Pause)
.SetMethod("isPaused", &DownloadItem::IsPaused)
.SetMethod("resume", &DownloadItem::Resume)
@ -218,17 +219,17 @@ void DownloadItem::BuildPrototype(v8::Isolate* isolate,
}
// static
mate::Handle<DownloadItem> DownloadItem::Create(v8::Isolate* isolate,
download::DownloadItem* item) {
gin::Handle<DownloadItem> DownloadItem::Create(v8::Isolate* isolate,
download::DownloadItem* item) {
auto* existing = TrackableObject::FromWrappedClass(isolate, item);
if (existing)
return mate::CreateHandle(isolate, static_cast<DownloadItem*>(existing));
return gin::CreateHandle(isolate, static_cast<DownloadItem*>(existing));
auto handle = mate::CreateHandle(isolate, new DownloadItem(isolate, item));
auto handle = gin::CreateHandle(isolate, new DownloadItem(isolate, item));
// Reference this object in case it got garbage collected.
g_download_item_objects[handle->weak_map_id()] =
v8::Global<v8::Object>(isolate, handle.ToV8());
v8::Global<v8::Value>(isolate, handle.ToV8());
return handle;
}
@ -243,7 +244,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary(isolate, exports)
gin_helper::Dictionary(isolate, exports)
.Set("DownloadItem", electron::api::DownloadItem::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());

View file

@ -10,20 +10,20 @@
#include "base/files/file_path.h"
#include "components/download/public/common/download_item.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "gin/handle.h"
#include "shell/browser/ui/file_dialog.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "url/gurl.h"
namespace electron {
namespace api {
class DownloadItem : public mate::TrackableObject<DownloadItem>,
class DownloadItem : public gin_helper::TrackableObject<DownloadItem>,
public download::DownloadItem::Observer {
public:
static mate::Handle<DownloadItem> Create(v8::Isolate* isolate,
download::DownloadItem* item);
static gin::Handle<DownloadItem> Create(v8::Isolate* isolate,
download::DownloadItem* item);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);

View file

@ -9,10 +9,11 @@
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "native_mate/dictionary.h"
#include "shell/browser/api/atom_api_system_preferences.h"
#include "shell/common/native_mate_converters/accelerator_converter.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/gin_converters/accelerator_converter.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
#if defined(OS_MACOSX)
@ -131,15 +132,15 @@ void GlobalShortcut::UnregisterAll() {
}
// static
mate::Handle<GlobalShortcut> GlobalShortcut::Create(v8::Isolate* isolate) {
return mate::CreateHandle(isolate, new GlobalShortcut(isolate));
gin::Handle<GlobalShortcut> GlobalShortcut::Create(v8::Isolate* isolate) {
return gin::CreateHandle(isolate, new GlobalShortcut(isolate));
}
// static
void GlobalShortcut::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "GlobalShortcut"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
prototype->SetClassName(gin::StringToV8(isolate, "GlobalShortcut"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("registerAll", &GlobalShortcut::RegisterAll)
.SetMethod("register", &GlobalShortcut::Register)
.SetMethod("isRegistered", &GlobalShortcut::IsRegistered)
@ -158,7 +159,7 @@ void Initialize(v8::Local<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.Set("globalShortcut", electron::api::GlobalShortcut::Create(isolate));
}

View file

@ -11,8 +11,8 @@
#include "base/callback.h"
#include "chrome/browser/extensions/global_shortcut_listener.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "gin/handle.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "ui/base/accelerators/accelerator.h"
namespace electron {
@ -20,9 +20,9 @@ namespace electron {
namespace api {
class GlobalShortcut : public extensions::GlobalShortcutListener::Observer,
public mate::TrackableObject<GlobalShortcut> {
public gin_helper::TrackableObject<GlobalShortcut> {
public:
static mate::Handle<GlobalShortcut> Create(v8::Isolate* isolate);
static gin::Handle<GlobalShortcut> Create(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);

View file

@ -9,7 +9,6 @@
#include <vector>
#include "gin/handle.h"
#include "native_mate/wrappable.h"
#include "shell/browser/mac/in_app_purchase.h"
#include "shell/browser/mac/in_app_purchase_observer.h"
#include "shell/browser/mac/in_app_purchase_product.h"
@ -20,9 +19,8 @@ namespace electron {
namespace api {
class InAppPurchase
: public gin_helper::EventEmitter<mate::Wrappable<InAppPurchase>>,
public in_app_purchase::TransactionObserver {
class InAppPurchase : public gin_helper::EventEmitter<InAppPurchase>,
public in_app_purchase::TransactionObserver {
public:
static gin::Handle<InAppPurchase> Create(v8::Isolate* isolate);

View file

@ -6,13 +6,12 @@
#include <map>
#include "native_mate/constructor.h"
#include "shell/browser/native_window.h"
#include "shell/common/gin_converters/accelerator_converter.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/image_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/native_mate_converters/accelerator_converter.h"
#include "shell/common/node_includes.h"
namespace {
@ -88,7 +87,7 @@ bool Menu::GetAcceleratorForCommandIdWithParams(
v8::HandleScope handle_scope(isolate());
v8::Local<v8::Value> val =
get_accelerator_.Run(GetWrapper(), command_id, use_default_accelerator);
return mate::ConvertFromV8(isolate(), val, accelerator);
return gin::ConvertFromV8(isolate(), val, accelerator);
}
bool Menu::ShouldRegisterAcceleratorForCommandId(int command_id) const {
@ -100,9 +99,9 @@ bool Menu::ShouldRegisterAcceleratorForCommandId(int command_id) const {
void Menu::ExecuteCommand(int command_id, int flags) {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
execute_command_.Run(GetWrapper(),
mate::internal::CreateEventFromFlags(isolate(), flags),
command_id);
execute_command_.Run(
GetWrapper(),
gin_helper::internal::CreateEventFromFlags(isolate(), flags), command_id);
}
void Menu::OnMenuWillShow(ui::SimpleMenuModel* source) {

View file

@ -11,14 +11,14 @@
#include "base/callback.h"
#include "gin/arguments.h"
#include "shell/browser/api/atom_api_top_level_window.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/ui/atom_menu_model.h"
#include "shell/common/gin_helper/trackable_object.h"
namespace electron {
namespace api {
class Menu : public mate::TrackableObject<Menu>,
class Menu : public gin_helper::TrackableObject<Menu>,
public AtomMenuModel::Delegate,
public AtomMenuModel::Observer {
public:
@ -122,7 +122,7 @@ class Menu : public mate::TrackableObject<Menu>,
} // namespace electron
namespace mate {
namespace gin {
template <>
struct Converter<electron::AtomMenuModel*> {
@ -143,6 +143,19 @@ struct Converter<electron::AtomMenuModel*> {
}
};
} // namespace gin
namespace mate {
template <>
struct Converter<electron::AtomMenuModel*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
electron::AtomMenuModel** out) {
return gin::ConvertFromV8(isolate, val, out);
}
};
} // namespace mate
#endif // SHELL_BROWSER_API_ATOM_API_MENU_H_

View file

@ -5,7 +5,6 @@
#ifndef SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_
#define SHELL_BROWSER_API_ATOM_API_NATIVE_THEME_H_
#include "native_mate/wrappable.h"
#include "shell/common/gin_helper/event_emitter.h"
#include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_observer.h"
@ -14,9 +13,8 @@ namespace electron {
namespace api {
class NativeTheme
: public gin_helper::EventEmitter<mate::Wrappable<NativeTheme>>,
public ui::NativeThemeObserver {
class NativeTheme : public gin_helper::EventEmitter<NativeTheme>,
public ui::NativeThemeObserver {
public:
static v8::Local<v8::Value> Create(v8::Isolate* isolate);

View file

@ -11,15 +11,14 @@
#include "components/net_log/chrome_net_log.h"
#include "content/public/browser/storage_partition.h"
#include "electron/electron_version.h"
#include "native_mate/converter.h"
#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/net/system_network_context_manager.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
namespace mate {
namespace gin {
template <>
struct Converter<net::NetLogCaptureMode> {
@ -41,7 +40,7 @@ struct Converter<net::NetLogCaptureMode> {
}
};
} // namespace mate
} // namespace gin
namespace electron {
@ -84,7 +83,7 @@ NetLog::NetLog(v8::Isolate* isolate, AtomBrowserContext* browser_context)
NetLog::~NetLog() = default;
v8::Local<v8::Promise> NetLog::StartLogging(base::FilePath log_path,
mate::Arguments* args) {
gin_helper::Arguments* args) {
if (log_path.empty()) {
args->ThrowError("The first parameter must be a valid string");
return v8::Local<v8::Promise>();
@ -93,20 +92,20 @@ v8::Local<v8::Promise> NetLog::StartLogging(base::FilePath log_path,
net::NetLogCaptureMode capture_mode = net::NetLogCaptureMode::kDefault;
uint64_t max_file_size = network::mojom::NetLogExporter::kUnlimitedFileSize;
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (args->GetNext(&dict)) {
v8::Local<v8::Value> capture_mode_v8;
if (dict.Get("captureMode", &capture_mode_v8)) {
if (!mate::ConvertFromV8(args->isolate(), capture_mode_v8,
&capture_mode)) {
if (!gin::ConvertFromV8(args->isolate(), capture_mode_v8,
&capture_mode)) {
args->ThrowError("Invalid value for captureMode");
return v8::Local<v8::Promise>();
}
}
v8::Local<v8::Value> max_file_size_v8;
if (dict.Get("maxFileSize", &max_file_size_v8)) {
if (!mate::ConvertFromV8(args->isolate(), max_file_size_v8,
&max_file_size)) {
if (!gin::ConvertFromV8(args->isolate(), max_file_size_v8,
&max_file_size)) {
args->ThrowError("Invalid value for maxFileSize");
return v8::Local<v8::Promise>();
}
@ -187,7 +186,7 @@ bool NetLog::IsCurrentlyLogging() const {
return !!net_log_exporter_;
}
v8::Local<v8::Promise> NetLog::StopLogging(mate::Arguments* args) {
v8::Local<v8::Promise> NetLog::StopLogging(gin_helper::Arguments* args) {
util::Promise<void*> promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
@ -211,16 +210,16 @@ v8::Local<v8::Promise> NetLog::StopLogging(mate::Arguments* args) {
}
// static
mate::Handle<NetLog> NetLog::Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context) {
return mate::CreateHandle(isolate, new NetLog(isolate, browser_context));
gin::Handle<NetLog> NetLog::Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context) {
return gin::CreateHandle(isolate, new NetLog(isolate, browser_context));
}
// static
void NetLog::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "NetLog"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
prototype->SetClassName(gin::StringToV8(isolate, "NetLog"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetProperty("currentlyLogging", &NetLog::IsCurrentlyLogging)
.SetMethod("startLogging", &NetLog::StartLogging)
.SetMethod("stopLogging", &NetLog::StopLogging);

View file

@ -12,9 +12,9 @@
#include "base/callback.h"
#include "base/optional.h"
#include "base/values.h"
#include "native_mate/handle.h"
#include "gin/handle.h"
#include "services/network/public/mojom/net_log.mojom.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "shell/common/promise_util.h"
namespace electron {
@ -23,17 +23,17 @@ class AtomBrowserContext;
namespace api {
class NetLog : public mate::TrackableObject<NetLog> {
class NetLog : public gin_helper::TrackableObject<NetLog> {
public:
static mate::Handle<NetLog> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
static gin::Handle<NetLog> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
v8::Local<v8::Promise> StartLogging(base::FilePath log_path,
mate::Arguments* args);
v8::Local<v8::Promise> StopLogging(mate::Arguments* args);
gin_helper::Arguments* args);
v8::Local<v8::Promise> StopLogging(gin_helper::Arguments* args);
bool IsCurrentlyLogging() const;
protected:

View file

@ -6,7 +6,6 @@
#include "base/guid.h"
#include "base/strings/utf_string_conversions.h"
#include "native_mate/constructor.h"
#include "shell/browser/api/atom_api_menu.h"
#include "shell/browser/atom_browser_client.h"
#include "shell/browser/browser.h"

View file

@ -10,11 +10,11 @@
#include <vector>
#include "base/strings/utf_string_conversions.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/notifications/notification.h"
#include "shell/browser/notifications/notification_delegate.h"
#include "shell/browser/notifications/notification_presenter.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "ui/gfx/image/image.h"
namespace gin {
@ -25,7 +25,7 @@ namespace electron {
namespace api {
class Notification : public mate::TrackableObject<Notification>,
class Notification : public gin_helper::TrackableObject<Notification>,
public NotificationDelegate {
public:
static mate::WrappableBase* New(gin_helper::ErrorThrower thrower,

View file

@ -7,29 +7,33 @@
#include "base/power_monitor/power_monitor.h"
#include "base/power_monitor/power_monitor_device_source.h"
#include "gin/dictionary.h"
#include "gin/handle.h"
#include "shell/browser/browser.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
namespace mate {
namespace gin {
template <>
struct Converter<ui::IdleState> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const ui::IdleState& in) {
switch (in) {
case ui::IDLE_STATE_ACTIVE:
return mate::StringToV8(isolate, "active");
return StringToV8(isolate, "active");
case ui::IDLE_STATE_IDLE:
return mate::StringToV8(isolate, "idle");
return StringToV8(isolate, "idle");
case ui::IDLE_STATE_LOCKED:
return mate::StringToV8(isolate, "locked");
return StringToV8(isolate, "locked");
case ui::IDLE_STATE_UNKNOWN:
default:
return mate::StringToV8(isolate, "unknown");
return StringToV8(isolate, "unknown");
}
}
};
} // namespace mate
} // namespace gin
namespace electron {
@ -88,7 +92,7 @@ ui::IdleState PowerMonitor::GetSystemIdleState(v8::Isolate* isolate,
if (idle_threshold > 0) {
return ui::CalculateIdleState(idle_threshold);
} else {
isolate->ThrowException(v8::Exception::TypeError(mate::StringToV8(
isolate->ThrowException(v8::Exception::TypeError(gin::StringToV8(
isolate, "Invalid idle threshold, must be greater than 0")));
return ui::IDLE_STATE_UNKNOWN;
}
@ -102,21 +106,21 @@ int PowerMonitor::GetSystemIdleTime() {
v8::Local<v8::Value> PowerMonitor::Create(v8::Isolate* isolate) {
if (!Browser::Get()->is_ready()) {
isolate->ThrowException(v8::Exception::Error(
mate::StringToV8(isolate,
"The 'powerMonitor' module can't be used before the "
"app 'ready' event")));
gin::StringToV8(isolate,
"The 'powerMonitor' module can't be used before the "
"app 'ready' event")));
return v8::Null(isolate);
}
return mate::CreateHandle(isolate, new PowerMonitor(isolate)).ToV8();
return gin::CreateHandle(isolate, new PowerMonitor(isolate)).ToV8();
}
// static
void PowerMonitor::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "PowerMonitor"));
prototype->SetClassName(gin::StringToV8(isolate, "PowerMonitor"));
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
#if defined(OS_LINUX)
.SetMethod("blockShutdown", &PowerMonitor::BlockShutdown)
.SetMethod("unblockShutdown", &PowerMonitor::UnblockShutdown)

View file

@ -6,16 +6,15 @@
#define SHELL_BROWSER_API_ATOM_API_POWER_MONITOR_H_
#include "base/compiler_specific.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/lib/power_observer.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "ui/base/idle/idle.h"
namespace electron {
namespace api {
class PowerMonitor : public mate::TrackableObject<PowerMonitor>,
class PowerMonitor : public gin_helper::TrackableObject<PowerMonitor>,
public PowerObserver {
public:
static v8::Local<v8::Value> Create(v8::Isolate* isolate);

View file

@ -10,9 +10,9 @@
#include "content/public/browser/content_browser_client.h"
#include "gin/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/net/atom_url_loader_factory.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/trackable_object.h"
namespace electron {
@ -35,7 +35,7 @@ enum class ProtocolError {
};
// Protocol implementation based on network services.
class Protocol : public mate::TrackableObject<Protocol> {
class Protocol : public gin_helper::TrackableObject<Protocol> {
public:
static gin::Handle<Protocol> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);

View file

@ -7,7 +7,6 @@
#include <vector>
#include "native_mate/wrappable.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/event_emitter.h"
#include "ui/display/display_observer.h"
@ -23,7 +22,7 @@ namespace electron {
namespace api {
class Screen : public gin_helper::EventEmitter<mate::Wrappable<Screen>>,
class Screen : public gin_helper::EventEmitter<Screen>,
public display::DisplayObserver {
public:
static v8::Local<v8::Value> Create(gin_helper::ErrorThrower error_thrower);

View file

@ -32,8 +32,6 @@
#include "content/public/browser/storage_partition.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "net/base/completion_repeating_callback.h"
#include "net/base/load_flags.h"
#include "net/http/http_auth_handler_factory.h"
@ -54,13 +52,14 @@
#include "shell/browser/media/media_device_id_salt.h"
#include "shell/browser/net/cert_verifier_client.h"
#include "shell/browser/session_preferences.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/native_mate_converters/content_converter.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/net_converter.h"
#include "shell/common/native_mate_converters/once_callback.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/content_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/net_converter.h"
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#include "ui/base/l10n/l10n_util.h"
@ -122,14 +121,14 @@ uint32_t GetQuotaMask(const std::vector<std::string>& quota_types) {
} // namespace
namespace mate {
namespace gin {
template <>
struct Converter<ClearStorageDataOptions> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
ClearStorageDataOptions* out) {
mate::Dictionary options;
gin_helper::Dictionary options;
if (!ConvertFromV8(isolate, val, &options))
return false;
options.Get("origin", &out->origin);
@ -142,7 +141,7 @@ struct Converter<ClearStorageDataOptions> {
}
};
} // namespace mate
} // namespace gin
namespace electron {
@ -153,7 +152,7 @@ namespace {
const char kPersistPrefix[] = "persist:";
// Referenced session objects.
std::map<uint32_t, v8::Global<v8::Object>> g_sessions;
std::map<uint32_t, v8::Global<v8::Value>> g_sessions;
void DownloadIdCallback(content::DownloadManager* download_manager,
const base::FilePath& path,
@ -239,7 +238,7 @@ void Session::OnDownloadCreated(content::DownloadManager* manager,
}
}
v8::Local<v8::Promise> Session::ResolveProxy(mate::Arguments* args) {
v8::Local<v8::Promise> Session::ResolveProxy(gin_helper::Arguments* args) {
v8::Isolate* isolate = args->isolate();
util::Promise<std::string> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
@ -292,7 +291,7 @@ v8::Local<v8::Promise> Session::ClearCache() {
return handle;
}
v8::Local<v8::Promise> Session::ClearStorageData(mate::Arguments* args) {
v8::Local<v8::Promise> Session::ClearStorageData(gin_helper::Arguments* args) {
v8::Isolate* isolate = args->isolate();
util::Promise<void*> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
@ -322,12 +321,12 @@ void Session::FlushStorageData() {
storage_partition->Flush();
}
v8::Local<v8::Promise> Session::SetProxy(mate::Arguments* args) {
v8::Local<v8::Promise> Session::SetProxy(gin_helper::Arguments* args) {
v8::Isolate* isolate = args->isolate();
util::Promise<void*> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
mate::Dictionary options;
gin_helper::Dictionary options;
args->GetNext(&options);
if (!browser_context_->in_memory_pref_store()) {
@ -368,7 +367,7 @@ void Session::SetDownloadPath(const base::FilePath& path) {
path);
}
void Session::EnableNetworkEmulation(const mate::Dictionary& options) {
void Session::EnableNetworkEmulation(const gin_helper::Dictionary& options) {
auto conditions = network::mojom::NetworkConditions::New();
options.Get("offline", &conditions->offline);
@ -395,9 +394,9 @@ void Session::DisableNetworkEmulation() {
}
void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
mate::Arguments* args) {
gin_helper::Arguments* args) {
CertVerifierClient::CertVerifyProc proc;
if (!(val->IsNull() || mate::ConvertFromV8(args->isolate(), val, &proc))) {
if (!(val->IsNull() || gin::ConvertFromV8(args->isolate(), val, &proc))) {
args->ThrowError("Must pass null or function");
return;
}
@ -418,7 +417,7 @@ void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
}
void Session::SetPermissionRequestHandler(v8::Local<v8::Value> val,
mate::Arguments* args) {
gin_helper::Arguments* args) {
auto* permission_manager = static_cast<AtomPermissionManager*>(
browser_context()->GetPermissionControllerDelegate());
if (val->IsNull()) {
@ -427,7 +426,7 @@ void Session::SetPermissionRequestHandler(v8::Local<v8::Value> val,
return;
}
auto handler = std::make_unique<AtomPermissionManager::RequestHandler>();
if (!mate::ConvertFromV8(args->isolate(), val, handler.get())) {
if (!gin::ConvertFromV8(args->isolate(), val, handler.get())) {
args->ThrowError("Must pass null or function");
return;
}
@ -445,9 +444,9 @@ void Session::SetPermissionRequestHandler(v8::Local<v8::Value> val,
}
void Session::SetPermissionCheckHandler(v8::Local<v8::Value> val,
mate::Arguments* args) {
gin_helper::Arguments* args) {
AtomPermissionManager::CheckHandler handler;
if (!(val->IsNull() || mate::ConvertFromV8(args->isolate(), val, &handler))) {
if (!(val->IsNull() || gin::ConvertFromV8(args->isolate(), val, &handler))) {
args->ThrowError("Must pass null or function");
return;
}
@ -456,7 +455,8 @@ void Session::SetPermissionCheckHandler(v8::Local<v8::Value> val,
permission_manager->SetPermissionCheckHandler(handler);
}
v8::Local<v8::Promise> Session::ClearHostResolverCache(mate::Arguments* args) {
v8::Local<v8::Promise> Session::ClearHostResolverCache(
gin_helper::Arguments* args) {
v8::Isolate* isolate = args->isolate();
util::Promise<void*> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
@ -494,7 +494,7 @@ void Session::AllowNTLMCredentialsForDomains(const std::string& domains) {
}
void Session::SetUserAgent(const std::string& user_agent,
mate::Arguments* args) {
gin_helper::Arguments* args) {
browser_context_->SetUserAgent(user_agent);
content::BrowserContext::GetDefaultStoragePartition(browser_context_.get())
->GetNetworkContext()
@ -525,7 +525,7 @@ void Session::DownloadURL(const GURL& url) {
download_manager->DownloadUrl(std::move(download_params));
}
void Session::CreateInterruptedDownload(const mate::Dictionary& options) {
void Session::CreateInterruptedDownload(const gin_helper::Dictionary& options) {
int64_t offset = 0, length = 0;
double start_time = base::Time::Now().ToDoubleT();
std::string mime_type, last_modified, etag;
@ -540,12 +540,12 @@ void Session::CreateInterruptedDownload(const mate::Dictionary& options) {
options.Get("eTag", &etag);
options.Get("startTime", &start_time);
if (path.empty() || url_chain.empty() || length == 0) {
isolate()->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate()->ThrowException(v8::Exception::Error(gin::StringToV8(
isolate(), "Must pass non-empty path, urlChain and length.")));
return;
}
if (offset >= length) {
isolate()->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate()->ThrowException(v8::Exception::Error(gin::StringToV8(
isolate(), "Must pass an offset value less than length.")));
return;
}
@ -619,8 +619,8 @@ static void StartPreconnectOnUI(
browser_context->GetPreconnectManager()->Start(url, requests);
}
void Session::Preconnect(const mate::Dictionary& options,
mate::Arguments* args) {
void Session::Preconnect(const gin_helper::Dictionary& options,
gin_helper::Arguments* args) {
GURL url;
if (!options.Get("url", &url) || !url.is_valid()) {
args->ThrowError("Must pass non-empty valid url to session.preconnect.");
@ -647,25 +647,25 @@ void Session::Preconnect(const mate::Dictionary& options,
}
// static
mate::Handle<Session> Session::CreateFrom(v8::Isolate* isolate,
AtomBrowserContext* browser_context) {
gin::Handle<Session> Session::CreateFrom(v8::Isolate* isolate,
AtomBrowserContext* browser_context) {
auto* existing = TrackableObject::FromWrappedClass(isolate, browser_context);
if (existing)
return mate::CreateHandle(isolate, static_cast<Session*>(existing));
return gin::CreateHandle(isolate, static_cast<Session*>(existing));
auto handle =
mate::CreateHandle(isolate, new Session(isolate, browser_context));
gin::CreateHandle(isolate, new Session(isolate, browser_context));
// The Sessions should never be garbage collected, since the common pattern is
// to use partition strings, instead of using the Session object directly.
g_sessions[handle->weak_map_id()] =
v8::Global<v8::Object>(isolate, handle.ToV8());
v8::Global<v8::Value>(isolate, handle.ToV8());
return handle;
}
// static
mate::Handle<Session> Session::FromPartition(
gin::Handle<Session> Session::FromPartition(
v8::Isolate* isolate,
const std::string& partition,
const base::DictionaryValue& options) {
@ -685,9 +685,9 @@ mate::Handle<Session> Session::FromPartition(
// static
void Session::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Session"));
prototype->SetClassName(gin::StringToV8(isolate, "Session"));
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("resolveProxy", &Session::ResolveProxy)
.SetMethod("getCacheSize", &Session::GetCacheSize)
.SetMethod("clearCache", &Session::ClearCache)
@ -736,7 +736,7 @@ using electron::api::Protocol;
using electron::api::Session;
v8::Local<v8::Value> FromPartition(const std::string& partition,
mate::Arguments* args) {
gin_helper::Arguments* args) {
if (!electron::Browser::Get()->is_ready()) {
args->ThrowError("Session can only be received when app is ready");
return v8::Null(args->isolate());
@ -751,7 +751,7 @@ void Initialize(v8::Local<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.Set(
"Session",
Session::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());

View file

@ -11,9 +11,9 @@
#include "base/values.h"
#include "content/public/browser/download_manager.h"
#include "electron/buildflags/buildflags.h"
#include "native_mate/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "gin/handle.h"
#include "shell/browser/net/resolve_proxy_helper.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "shell/common/promise_util.h"
class GURL;
@ -22,10 +22,9 @@ namespace base {
class FilePath;
}
namespace mate {
class Arguments;
namespace gin_helper {
class Dictionary;
} // namespace mate
}
namespace net {
class ProxyConfig;
@ -37,56 +36,58 @@ class AtomBrowserContext;
namespace api {
class Session : public mate::TrackableObject<Session>,
class Session : public gin_helper::TrackableObject<Session>,
public content::DownloadManager::Observer {
public:
// Gets or creates Session from the |browser_context|.
static mate::Handle<Session> CreateFrom(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
static gin::Handle<Session> CreateFrom(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
// Gets the Session of |partition|.
static mate::Handle<Session> FromPartition(
static gin::Handle<Session> FromPartition(
v8::Isolate* isolate,
const std::string& partition,
const base::DictionaryValue& options = base::DictionaryValue());
AtomBrowserContext* browser_context() const { return browser_context_.get(); }
// mate::TrackableObject:
// gin_helper::TrackableObject:
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
// Methods.
v8::Local<v8::Promise> ResolveProxy(mate::Arguments* args);
v8::Local<v8::Promise> ResolveProxy(gin_helper::Arguments* args);
v8::Local<v8::Promise> GetCacheSize();
v8::Local<v8::Promise> ClearCache();
v8::Local<v8::Promise> ClearStorageData(mate::Arguments* args);
v8::Local<v8::Promise> ClearStorageData(gin_helper::Arguments* args);
void FlushStorageData();
v8::Local<v8::Promise> SetProxy(mate::Arguments* args);
v8::Local<v8::Promise> SetProxy(gin_helper::Arguments* args);
void SetDownloadPath(const base::FilePath& path);
void EnableNetworkEmulation(const mate::Dictionary& options);
void EnableNetworkEmulation(const gin_helper::Dictionary& options);
void DisableNetworkEmulation();
void SetCertVerifyProc(v8::Local<v8::Value> proc, mate::Arguments* args);
void SetCertVerifyProc(v8::Local<v8::Value> proc,
gin_helper::Arguments* args);
void SetPermissionRequestHandler(v8::Local<v8::Value> val,
mate::Arguments* args);
gin_helper::Arguments* args);
void SetPermissionCheckHandler(v8::Local<v8::Value> val,
mate::Arguments* args);
v8::Local<v8::Promise> ClearHostResolverCache(mate::Arguments* args);
gin_helper::Arguments* args);
v8::Local<v8::Promise> ClearHostResolverCache(gin_helper::Arguments* args);
v8::Local<v8::Promise> ClearAuthCache();
void AllowNTLMCredentialsForDomains(const std::string& domains);
void SetUserAgent(const std::string& user_agent, mate::Arguments* args);
void SetUserAgent(const std::string& user_agent, gin_helper::Arguments* args);
std::string GetUserAgent();
v8::Local<v8::Promise> GetBlobData(v8::Isolate* isolate,
const std::string& uuid);
void DownloadURL(const GURL& url);
void CreateInterruptedDownload(const mate::Dictionary& options);
void CreateInterruptedDownload(const gin_helper::Dictionary& options);
void SetPreloads(const std::vector<base::FilePath::StringType>& preloads);
std::vector<base::FilePath::StringType> GetPreloads() const;
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
v8::Local<v8::Value> NetLog(v8::Isolate* isolate);
void Preconnect(const mate::Dictionary& options, mate::Arguments* args);
void Preconnect(const gin_helper::Dictionary& options,
gin_helper::Arguments* args);
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
void LoadChromeExtension(const base::FilePath extension_path);

View file

@ -9,7 +9,6 @@
#include <string>
#include "gin/handle.h"
#include "native_mate/wrappable.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/event_emitter.h"
#include "shell/common/promise_util.h"
@ -36,12 +35,11 @@ enum NotificationCenterKind {
};
#endif
class SystemPreferences
: public gin_helper::EventEmitter<mate::Wrappable<SystemPreferences>>
class SystemPreferences : public gin_helper::EventEmitter<SystemPreferences>
#if defined(OS_WIN)
,
public BrowserObserver,
public gfx::SysColorChangeListener
public BrowserObserver,
public gfx::SysColorChangeListener
#endif
{
public:

View file

@ -74,10 +74,10 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
} // namespace
TopLevelWindow::TopLevelWindow(v8::Isolate* isolate,
const mate::Dictionary& options)
const gin_helper::Dictionary& options)
: weak_factory_(this) {
// The parent window.
mate::Handle<TopLevelWindow> parent;
gin::Handle<TopLevelWindow> parent;
if (options.Get("parent", &parent) && !parent.IsEmpty())
parent_window_.Reset(isolate, parent.ToV8());
@ -98,14 +98,14 @@ TopLevelWindow::TopLevelWindow(v8::Isolate* isolate,
#if defined(TOOLKIT_VIEWS)
// Sets the window icon.
mate::Handle<NativeImage> icon;
gin::Handle<NativeImage> icon;
if (options.Get(options::kIcon, &icon) && !icon.IsEmpty())
SetIcon(icon);
#endif
}
TopLevelWindow::TopLevelWindow(gin_helper::Arguments* args,
const mate::Dictionary& options)
const gin_helper::Dictionary& options)
: TopLevelWindow(args->isolate(), options) {
InitWithArgs(args);
// Init window after everything has been setup.
@ -124,15 +124,12 @@ TopLevelWindow::~TopLevelWindow() {
void TopLevelWindow::InitWith(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper) {
AttachAsUserData(window_.get());
mate::TrackableObject<
TopLevelWindow, gin_helper::EventEmitter<
mate::Wrappable<TopLevelWindow>>>::InitWith(isolate,
wrapper);
gin_helper::TrackableObject<TopLevelWindow>::InitWith(isolate, wrapper);
// We can only append this window to parent window's child windows after this
// window's JS wrapper gets initialized.
if (!parent_window_.IsEmpty()) {
mate::Handle<TopLevelWindow> parent;
gin::Handle<TopLevelWindow> parent;
gin::ConvertFromV8(isolate, GetParentWindow(), &parent);
DCHECK(!parent.IsEmpty());
parent->child_windows_.Set(isolate, weak_map_id(), wrapper);
@ -299,7 +296,7 @@ void TopLevelWindow::OnWindowMessage(UINT message,
}
#endif
void TopLevelWindow::SetContentView(mate::Handle<View> view) {
void TopLevelWindow::SetContentView(gin::Handle<View> view) {
ResetBrowserViews();
content_view_.Reset(isolate(), view.ToV8());
window_->SetContentView(view->view());
@ -676,7 +673,7 @@ void TopLevelWindow::SetFocusable(bool focusable) {
void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
auto context = isolate->GetCurrentContext();
mate::Handle<Menu> menu;
gin::Handle<Menu> menu;
v8::Local<v8::Object> object;
if (value->IsObject() && value->ToObject(context).ToLocal(&object) &&
gin::V8ToString(isolate, object->GetConstructorName()) == "Menu" &&
@ -704,12 +701,12 @@ void TopLevelWindow::SetParentWindow(v8::Local<v8::Value> value,
return;
}
mate::Handle<TopLevelWindow> parent;
gin::Handle<TopLevelWindow> parent;
if (value->IsNull() || value->IsUndefined()) {
RemoveFromParentChildWindows();
parent_window_.Reset();
window_->SetParentWindow(nullptr);
} else if (mate::ConvertFromV8(isolate(), value, &parent)) {
} else if (gin::ConvertFromV8(isolate(), value, &parent)) {
RemoveFromParentChildWindows();
parent_window_.Reset(isolate(), value);
window_->SetParentWindow(parent->window_.get());
@ -725,7 +722,7 @@ void TopLevelWindow::SetBrowserView(v8::Local<v8::Value> value) {
}
void TopLevelWindow::AddBrowserView(v8::Local<v8::Value> value) {
mate::Handle<BrowserView> browser_view;
gin::Handle<BrowserView> browser_view;
if (value->IsObject() &&
gin::ConvertFromV8(isolate(), value, &browser_view)) {
auto get_that_view = browser_views_.find(browser_view->weak_map_id());
@ -738,7 +735,7 @@ void TopLevelWindow::AddBrowserView(v8::Local<v8::Value> value) {
}
void TopLevelWindow::RemoveBrowserView(v8::Local<v8::Value> value) {
mate::Handle<BrowserView> browser_view;
gin::Handle<BrowserView> browser_view;
if (value->IsObject() &&
gin::ConvertFromV8(isolate(), value, &browser_view)) {
auto get_that_view = browser_views_.find(browser_view->weak_map_id());
@ -960,7 +957,7 @@ bool TopLevelWindow::SetThumbarButtons(gin_helper::Arguments* args) {
}
#if defined(TOOLKIT_VIEWS)
void TopLevelWindow::SetIcon(mate::Handle<NativeImage> icon) {
void TopLevelWindow::SetIcon(gin::Handle<NativeImage> icon) {
#if defined(OS_WIN)
static_cast<NativeWindowViews*>(window_.get())
->SetIcon(icon->GetHICON(GetSystemMetrics(SM_CXSMICON)),
@ -1028,7 +1025,7 @@ int32_t TopLevelWindow::GetID() const {
void TopLevelWindow::ResetBrowserViews() {
for (auto& item : browser_views_) {
mate::Handle<BrowserView> browser_view;
gin::Handle<BrowserView> browser_view;
if (gin::ConvertFromV8(isolate(),
v8::Local<v8::Value>::New(isolate(), item.second),
&browser_view) &&
@ -1047,7 +1044,7 @@ void TopLevelWindow::RemoveFromParentChildWindows() {
if (parent_window_.IsEmpty())
return;
mate::Handle<TopLevelWindow> parent;
gin::Handle<TopLevelWindow> parent;
if (!gin::ConvertFromV8(isolate(), GetParentWindow(), &parent) ||
parent.IsEmpty()) {
return;
@ -1058,7 +1055,8 @@ void TopLevelWindow::RemoveFromParentChildWindows() {
// static
mate::WrappableBase* TopLevelWindow::New(gin_helper::Arguments* args) {
mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
gin_helper::Dictionary options =
gin::Dictionary::CreateEmpty(args->isolate());
args->GetNext(&options);
return new TopLevelWindow(args, options);

View file

@ -13,11 +13,11 @@
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "shell/browser/api/trackable_object.h"
#include "gin/handle.h"
#include "shell/browser/native_window.h"
#include "shell/browser/native_window_observer.h"
#include "shell/common/api/atom_api_native_image.h"
#include "shell/common/gin_helper/event_emitter.h"
#include "shell/common/gin_helper/trackable_object.h"
namespace electron {
@ -25,11 +25,8 @@ namespace api {
class View;
class TopLevelWindow
: public mate::TrackableObject<
TopLevelWindow,
gin_helper::EventEmitter<mate::Wrappable<TopLevelWindow>>>,
public NativeWindowObserver {
class TopLevelWindow : public gin_helper::TrackableObject<TopLevelWindow>,
public NativeWindowObserver {
public:
static mate::WrappableBase* New(gin_helper::Arguments* args);
@ -44,9 +41,10 @@ class TopLevelWindow
protected:
// Common constructor.
TopLevelWindow(v8::Isolate* isolate, const mate::Dictionary& options);
TopLevelWindow(v8::Isolate* isolate, const gin_helper::Dictionary& options);
// Creating independent TopLevelWindow instance.
TopLevelWindow(gin_helper::Arguments* args, const mate::Dictionary& options);
TopLevelWindow(gin_helper::Arguments* args,
const gin_helper::Dictionary& options);
~TopLevelWindow() override;
// TrackableObject:
@ -91,7 +89,7 @@ class TopLevelWindow
#endif
// Public APIs of NativeWindow.
void SetContentView(mate::Handle<View> view);
void SetContentView(gin::Handle<View> view);
void Close();
virtual void Focus();
virtual void Blur();
@ -215,7 +213,7 @@ class TopLevelWindow
// Extra APIs added in JS.
bool SetThumbarButtons(gin_helper::Arguments* args);
#if defined(TOOLKIT_VIEWS)
void SetIcon(mate::Handle<NativeImage> icon);
void SetIcon(gin::Handle<NativeImage> icon);
#endif
#if defined(OS_WIN)
typedef base::RepeatingCallback<void(v8::Local<v8::Value>,

View file

@ -10,11 +10,10 @@
#include <vector>
#include "gin/handle.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/ui/tray_icon.h"
#include "shell/browser/ui/tray_icon_observer.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "shell/common/gin_helper/event_emitter.h"
#include "shell/common/gin_helper/trackable_object.h"
namespace gfx {
class Image;
@ -33,10 +32,7 @@ namespace api {
class Menu;
class NativeImage;
class Tray : public mate::TrackableObject<
Tray,
gin_helper::EventEmitter<mate::Wrappable<Tray>>>,
public TrayIconObserver {
class Tray : public gin_helper::TrackableObject<Tray>, public TrayIconObserver {
public:
static mate::WrappableBase* New(gin_helper::ErrorThrower thrower,
gin::Handle<NativeImage> image,

View file

@ -177,7 +177,7 @@ URLRequest::URLRequest(gin::Arguments* args) : weak_factory_(this) {
}
std::string partition;
mate::Handle<api::Session> session;
gin::Handle<api::Session> session;
if (!dict.Get("session", &session)) {
if (dict.Get("partition", &partition))
session = Session::FromPartition(args->isolate(), partition);

View file

@ -13,7 +13,6 @@
#include "gin/arguments.h"
#include "gin/dictionary.h"
#include "mojo/public/cpp/system/data_pipe_producer.h"
#include "native_mate/wrappable.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
@ -26,7 +25,7 @@ namespace api {
class UploadDataPipeGetter;
class URLRequest : public gin_helper::EventEmitter<mate::Wrappable<URLRequest>>,
class URLRequest : public gin_helper::EventEmitter<URLRequest>,
public network::SimpleURLLoaderStreamConsumer {
public:
static mate::WrappableBase* New(gin::Arguments* args);

View file

@ -4,7 +4,8 @@
#include "shell/browser/api/atom_api_view.h"
#include "native_mate/dictionary.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
namespace electron {
@ -23,16 +24,16 @@ View::~View() {
}
#if BUILDFLAG(ENABLE_VIEW_API)
void View::SetLayoutManager(mate::Handle<LayoutManager> layout_manager) {
void View::SetLayoutManager(gin::Handle<LayoutManager> layout_manager) {
layout_manager_.Reset(isolate(), layout_manager->GetWrapper());
view()->SetLayoutManager(layout_manager->TakeOver());
}
void View::AddChildView(mate::Handle<View> child) {
void View::AddChildView(gin::Handle<View> child) {
AddChildViewAt(child, child_views_.size());
}
void View::AddChildViewAt(mate::Handle<View> child, size_t index) {
void View::AddChildViewAt(gin::Handle<View> child, size_t index) {
if (index > child_views_.size())
return;
child_views_.emplace(child_views_.begin() + index, // index
@ -51,9 +52,9 @@ mate::WrappableBase* View::New(gin::Arguments* args) {
// static
void View::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "View"));
prototype->SetClassName(gin::StringToV8(isolate, "View"));
#if BUILDFLAG(ENABLE_VIEW_API)
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("setLayoutManager", &View::SetLayoutManager)
.SetMethod("addChildView", &View::AddChildView)
.SetMethod("addChildViewAt", &View::AddChildViewAt);
@ -75,11 +76,11 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Isolate* isolate = context->GetIsolate();
View::SetConstructor(isolate, base::BindRepeating(&View::New));
mate::Dictionary constructor(
gin_helper::Dictionary constructor(
isolate,
View::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
mate::Dictionary dict(isolate, exports);
gin_helper::Dictionary dict(isolate, exports);
dict.Set("View", constructor);
}

View file

@ -9,7 +9,7 @@
#include <vector>
#include "electron/buildflags/buildflags.h"
#include "native_mate/handle.h"
#include "gin/handle.h"
#include "shell/browser/api/views/atom_api_layout_manager.h"
#include "ui/views/view.h"
@ -17,7 +17,7 @@ namespace electron {
namespace api {
class View : public mate::TrackableObject<View> {
class View : public gin_helper::TrackableObject<View> {
public:
static mate::WrappableBase* New(gin::Arguments* args);
@ -25,9 +25,9 @@ class View : public mate::TrackableObject<View> {
v8::Local<v8::FunctionTemplate> prototype);
#if BUILDFLAG(ENABLE_VIEW_API)
void SetLayoutManager(mate::Handle<LayoutManager> layout_manager);
void AddChildView(mate::Handle<View> view);
void AddChildViewAt(mate::Handle<View> view, size_t index);
void SetLayoutManager(gin::Handle<LayoutManager> layout_manager);
void AddChildView(gin::Handle<View> view);
void AddChildViewAt(gin::Handle<View> view, size_t index);
#endif
views::View* view() const { return view_; }
@ -54,7 +54,7 @@ class View : public mate::TrackableObject<View> {
} // namespace electron
namespace mate {
namespace gin {
template <>
struct Converter<views::View*> {
@ -69,6 +69,6 @@ struct Converter<views::View*> {
}
};
} // namespace mate
} // namespace gin
#endif // SHELL_BROWSER_API_ATOM_API_VIEW_H_

View file

@ -45,9 +45,6 @@
#include "electron/buildflags/buildflags.h"
#include "electron/shell/common/api/api.mojom.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "native_mate/converter.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "ppapi/buildflags/buildflags.h"
#include "shell/browser/api/atom_api_browser_window.h"
#include "shell/browser/api/atom_api_debugger.h"
@ -72,20 +69,18 @@
#include "shell/browser/web_view_guest_delegate.h"
#include "shell/common/api/atom_api_native_image.h"
#include "shell/common/color_util.h"
#include "shell/common/gin_converters/blink_converter_gin_adapter.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/content_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_converters/gfx_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/image_converter.h"
#include "shell/common/gin_converters/net_converter.h"
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/mouse_util.h"
#include "shell/common/native_mate_converters/blink_converter.h"
#include "shell/common/native_mate_converters/content_converter.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/native_mate_converters/net_converter.h"
#include "shell/common/native_mate_converters/network_converter.h"
#include "shell/common/native_mate_converters/once_callback.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
@ -125,7 +120,7 @@
#include "shell/browser/extensions/atom_extension_web_contents_observer.h"
#endif
namespace mate {
namespace gin {
#if BUILDFLAG(ENABLE_PRINTING)
template <>
@ -221,7 +216,7 @@ struct Converter<WindowOpenDisposition> {
default:
break;
}
return mate::ConvertToV8(isolate, disposition);
return gin::ConvertToV8(isolate, disposition);
}
};
@ -275,7 +270,7 @@ struct Converter<electron::api::WebContents::Type> {
default:
break;
}
return mate::ConvertToV8(isolate, type);
return gin::ConvertToV8(isolate, type);
}
static bool FromV8(v8::Isolate* isolate,
@ -307,14 +302,14 @@ struct Converter<scoped_refptr<content::DevToolsAgentHost>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const scoped_refptr<content::DevToolsAgentHost>& val) {
mate::Dictionary dict(isolate, v8::Object::New(isolate));
gin_helper::Dictionary dict(isolate, v8::Object::New(isolate));
dict.Set("id", val->GetId());
dict.Set("url", val->GetURL().spec());
return dict.GetHandle();
}
};
} // namespace mate
} // namespace gin
namespace electron {
@ -326,7 +321,7 @@ namespace {
void OnCapturePageDone(util::Promise<gfx::Image> promise,
const SkBitmap& bitmap) {
// Hack to enable transparency in captured image
promise.Resolve(gfx::Image::CreateFrom1xBitmap(bitmap));
promise.ResolveWithGin(gfx::Image::CreateFrom1xBitmap(bitmap));
}
base::Optional<base::TimeDelta> GetCursorBlinkInterval() {
@ -359,7 +354,7 @@ WebContents::WebContents(v8::Isolate* isolate,
false);
Init(isolate);
AttachAsUserData(web_contents);
InitZoomController(web_contents, mate::Dictionary::CreateEmpty(isolate));
InitZoomController(web_contents, gin::Dictionary::CreateEmpty(isolate));
registry_.AddInterface(base::BindRepeating(&WebContents::BindElectronBrowser,
base::Unretained(this)));
bindings_.set_connection_error_handler(base::BindRepeating(
@ -377,10 +372,11 @@ WebContents::WebContents(v8::Isolate* isolate,
auto session = Session::CreateFrom(isolate, GetBrowserContext());
session_.Reset(isolate, session.ToV8());
InitWithSessionAndOptions(isolate, std::move(web_contents), session,
mate::Dictionary::CreateEmpty(isolate));
gin::Dictionary::CreateEmpty(isolate));
}
WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
WebContents::WebContents(v8::Isolate* isolate,
const gin_helper::Dictionary& options)
: weak_factory_(this) {
// Read options.
options.Get("backgroundThrottling", &background_throttling_);
@ -405,7 +401,7 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
// Obtain the session.
std::string partition;
mate::Handle<api::Session> session;
gin::Handle<api::Session> session;
if (options.Get("session", &session) && !session.IsEmpty()) {
} else if (options.Get("partition", &partition)) {
session = Session::FromPartition(isolate, partition);
@ -465,7 +461,7 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options)
}
void WebContents::InitZoomController(content::WebContents* web_contents,
const mate::Dictionary& options) {
const gin_helper::Dictionary& options) {
WebContentsZoomController::CreateForWebContents(web_contents);
zoom_controller_ = WebContentsZoomController::FromWebContents(web_contents);
double zoom_factor;
@ -476,8 +472,8 @@ void WebContents::InitZoomController(content::WebContents* web_contents,
void WebContents::InitWithSessionAndOptions(
v8::Isolate* isolate,
std::unique_ptr<content::WebContents> owned_web_contents,
mate::Handle<api::Session> session,
const mate::Dictionary& options) {
gin::Handle<api::Session> session,
const gin_helper::Dictionary& options) {
Observe(owned_web_contents.get());
// TODO(zcbenz): Make InitWithWebContents take unique_ptr.
// At the time of writing we are going through a refactoring and I don't want
@ -672,8 +668,7 @@ void WebContents::BeforeUnloadFired(content::WebContents* tab,
void WebContents::SetContentsBounds(content::WebContents* source,
const gfx::Rect& pos) {
// TODO(zcbenz): Use implicit convertion after removing mate::EventEmitter.
Emit("move", gin::ConvertToV8(isolate(), pos));
Emit("move", pos);
}
void WebContents::CloseContents(content::WebContents* source) {
@ -1054,7 +1049,7 @@ void WebContents::MessageTo(bool internal,
int32_t web_contents_id,
const std::string& channel,
blink::CloneableMessage arguments) {
auto* web_contents = mate::TrackableObject<WebContents>::FromWeakMapID(
auto* web_contents = gin_helper::TrackableObject<WebContents>::FromWeakMapID(
isolate(), web_contents_id);
if (web_contents) {
@ -1346,7 +1341,8 @@ bool WebContents::Equal(const WebContents* web_contents) const {
return ID() == web_contents->ID();
}
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
void WebContents::LoadURL(const GURL& url,
const gin_helper::Dictionary& options) {
if (!url.is_valid() || url.spec().size() > url::kMaxURLChars) {
Emit("did-fail-load", static_cast<int>(net::ERR_INVALID_URL),
net::ErrorToShortString(net::ERR_INVALID_URL),
@ -1487,7 +1483,7 @@ bool WebContents::IsCrashed() const {
}
void WebContents::SetUserAgent(const std::string& user_agent,
mate::Arguments* args) {
gin_helper::Arguments* args) {
web_contents()->SetUserAgentOverride(user_agent, false);
}
@ -1507,7 +1503,7 @@ v8::Local<v8::Promise> WebContents::SavePage(
return handle;
}
void WebContents::OpenDevTools(mate::Arguments* args) {
void WebContents::OpenDevTools(gin_helper::Arguments* args) {
if (type_ == Type::REMOTE)
return;
@ -1520,7 +1516,7 @@ void WebContents::OpenDevTools(mate::Arguments* args) {
}
bool activate = true;
if (args && args->Length() == 1) {
mate::Dictionary options;
gin_helper::Dictionary options;
if (args->GetNext(&options)) {
options.Get("mode", &state);
options.Get("activate", &activate);
@ -1693,8 +1689,9 @@ bool WebContents::IsCurrentlyAudible() {
}
#if BUILDFLAG(ENABLE_PRINTING)
void WebContents::Print(mate::Arguments* args) {
mate::Dictionary options = mate::Dictionary::CreateEmpty(args->isolate());
void WebContents::Print(gin_helper::Arguments* args) {
gin_helper::Dictionary options =
gin::Dictionary::CreateEmpty(args->isolate());
base::DictionaryValue settings;
if (args->Length() >= 1 && !args->GetNext(&options)) {
@ -1719,7 +1716,8 @@ void WebContents::Print(mate::Arguments* args) {
print_background);
// Set custom margin settings
mate::Dictionary margins = mate::Dictionary::CreateEmpty(args->isolate());
gin_helper::Dictionary margins =
gin::Dictionary::CreateEmpty(args->isolate());
if (options.Get("margins", &margins)) {
printing::MarginType margin_type = printing::DEFAULT_MARGINS;
margins.Get("marginType", &margin_type);
@ -1805,7 +1803,7 @@ void WebContents::Print(mate::Arguments* args) {
settings.SetBoolean(printing::kSettingRasterizePdf, false);
// Set custom page ranges to print
std::vector<mate::Dictionary> page_ranges;
std::vector<gin_helper::Dictionary> page_ranges;
if (options.Get("pageRanges", &page_ranges)) {
std::unique_ptr<base::ListValue> page_range_list(new base::ListValue());
for (auto& range : page_ranges) {
@ -1830,7 +1828,7 @@ void WebContents::Print(mate::Arguments* args) {
settings.SetInteger(printing::kSettingDuplexMode, duplex_mode);
// Set custom dots per inch (dpi)
mate::Dictionary dpi_settings;
gin_helper::Dictionary dpi_settings;
int dpi = 72;
if (options.Get("dpi", &dpi_settings)) {
int horizontal = 72;
@ -1878,7 +1876,7 @@ v8::Local<v8::Promise> WebContents::PrintToPDF(
}
#endif
void WebContents::AddWorkSpace(mate::Arguments* args,
void WebContents::AddWorkSpace(gin_helper::Arguments* args,
const base::FilePath& path) {
if (path.empty()) {
args->ThrowError("path cannot be empty");
@ -1887,7 +1885,7 @@ void WebContents::AddWorkSpace(mate::Arguments* args,
DevToolsAddFileSystem(std::string(), path);
}
void WebContents::RemoveWorkSpace(mate::Arguments* args,
void WebContents::RemoveWorkSpace(gin_helper::Arguments* args,
const base::FilePath& path) {
if (path.empty()) {
args->ThrowError("path cannot be empty");
@ -1940,7 +1938,7 @@ void WebContents::ReplaceMisspelling(const base::string16& word) {
web_contents()->ReplaceMisspelling(word);
}
uint32_t WebContents::FindInPage(mate::Arguments* args) {
uint32_t WebContents::FindInPage(gin_helper::Arguments* args) {
base::string16 search_text;
if (!args->GetNext(&search_text) || search_text.empty()) {
args->ThrowError("Must provide a non-empty search content");
@ -1948,7 +1946,7 @@ uint32_t WebContents::FindInPage(mate::Arguments* args) {
}
uint32_t request_id = GetNextRequestId();
mate::Dictionary dict;
gin_helper::Dictionary dict;
auto options = blink::mojom::FindOptions::New();
if (args->GetNext(&dict)) {
dict.Get("forward", &options->forward);
@ -2007,9 +2005,9 @@ bool WebContents::SendIPCMessage(bool internal,
const std::string& channel,
v8::Local<v8::Value> args) {
blink::CloneableMessage message;
if (!mate::ConvertFromV8(isolate(), args, &message)) {
if (!gin::ConvertFromV8(isolate(), args, &message)) {
isolate()->ThrowException(v8::Exception::Error(
mate::StringToV8(isolate(), "Failed to serialize arguments")));
gin::StringToV8(isolate(), "Failed to serialize arguments")));
return false;
}
return SendIPCMessageWithSender(internal, send_to_all, channel,
@ -2046,9 +2044,9 @@ bool WebContents::SendIPCMessageToFrame(bool internal,
const std::string& channel,
v8::Local<v8::Value> args) {
blink::CloneableMessage message;
if (!mate::ConvertFromV8(isolate(), args, &message)) {
if (!gin::ConvertFromV8(isolate(), args, &message)) {
isolate()->ThrowException(v8::Exception::Error(
mate::StringToV8(isolate(), "Failed to serialize arguments")));
gin::StringToV8(isolate(), "Failed to serialize arguments")));
return false;
}
auto frames = web_contents()->GetAllFrames();
@ -2094,7 +2092,7 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
content::NativeWebKeyboardEvent keyboard_event(
blink::WebKeyboardEvent::kRawKeyDown,
blink::WebInputEvent::kNoModifiers, ui::EventTimeForNow());
if (mate::ConvertFromV8(isolate, input_event, &keyboard_event)) {
if (gin::ConvertFromV8(isolate, input_event, &keyboard_event)) {
rwh->ForwardKeyboardEvent(keyboard_event);
return;
}
@ -2127,14 +2125,10 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
}
isolate->ThrowException(
v8::Exception::Error(mate::StringToV8(isolate, "Invalid event object")));
v8::Exception::Error(gin::StringToV8(isolate, "Invalid event object")));
}
void WebContents::BeginFrameSubscription(mate::Arguments* mate_args) {
// TODO(zcbenz): Remove this after converting WebContents to gin.
gin::Arguments gin_args(mate_args->info());
gin_helper::Arguments* args = static_cast<gin_helper::Arguments*>(&gin_args);
void WebContents::BeginFrameSubscription(gin_helper::Arguments* args) {
bool only_dirty = false;
FrameSubscriber::FrameCaptureCallback callback;
@ -2152,32 +2146,19 @@ void WebContents::EndFrameSubscription() {
frame_subscriber_.reset();
}
void WebContents::StartDrag(const mate::Dictionary& item,
mate::Arguments* args) {
void WebContents::StartDrag(const gin_helper::Dictionary& item,
gin_helper::Arguments* args) {
base::FilePath file;
std::vector<base::FilePath> files;
if (!item.Get("files", &files) && item.Get("file", &file)) {
files.push_back(file);
}
mate::Handle<NativeImage> icon;
if (!item.Get("icon", &icon) && !file.empty()) {
// TODO(zcbenz): Set default icon from file.
}
// Error checking.
if (icon.IsEmpty()) {
args->ThrowError("Must specify 'icon' option");
return;
}
#if defined(OS_MACOSX)
// NSWindow.dragImage requires a non-empty NSImage
if (icon->image().IsEmpty()) {
gin::Handle<NativeImage> icon;
if (!item.Get("icon", &icon)) {
args->ThrowError("Must specify non-empty 'icon' option");
return;
}
#endif
// Start dragging.
if (!files.empty()) {
@ -2188,11 +2169,7 @@ void WebContents::StartDrag(const mate::Dictionary& item,
}
}
v8::Local<v8::Promise> WebContents::CapturePage(mate::Arguments* mate_args) {
// TODO(zcbenz): Remove this after converting WebContents to gin.
gin::Arguments gin_args(mate_args->info());
gin::Arguments* args = &gin_args;
v8::Local<v8::Promise> WebContents::CapturePage(gin_helper::Arguments* args) {
gfx::Rect rect;
util::Promise<gfx::Image> promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
@ -2202,7 +2179,7 @@ v8::Local<v8::Promise> WebContents::CapturePage(mate::Arguments* mate_args) {
auto* const view = web_contents()->GetRenderWidgetHostView();
if (!view) {
promise.Resolve(gfx::Image());
promise.ResolveWithGin(gfx::Image());
return handle;
}
@ -2233,11 +2210,8 @@ void WebContents::OnCursorChange(const content::WebCursor& cursor) {
Emit("cursor-changed", CursorTypeToString(info),
gfx::Image::CreateFrom1xBitmap(info.custom_image),
info.image_scale_factor,
// TODO(zcbenz): Use implicit convertion after removing
// mate::EventEmitter.
gin::ConvertToV8(isolate(), gfx::Size(info.custom_image.width(),
info.custom_image.height())),
gin::ConvertToV8(isolate(), info.hotspot));
gfx::Size(info.custom_image.width(), info.custom_image.height()),
info.hotspot);
} else {
Emit("cursor-changed", CursorTypeToString(info));
}
@ -2374,7 +2348,7 @@ v8::Local<v8::Value> WebContents::GetWebPreferences(
auto* web_preferences = WebContentsPreferences::From(web_contents());
if (!web_preferences)
return v8::Null(isolate);
return mate::ConvertToV8(isolate, *web_preferences->preference());
return gin::ConvertToV8(isolate, *web_preferences->preference());
}
v8::Local<v8::Value> WebContents::GetLastWebPreferences(
@ -2382,7 +2356,7 @@ v8::Local<v8::Value> WebContents::GetLastWebPreferences(
auto* web_preferences = WebContentsPreferences::From(web_contents());
if (!web_preferences)
return v8::Null(isolate);
return mate::ConvertToV8(isolate, *web_preferences->last_preference());
return gin::ConvertToV8(isolate, *web_preferences->last_preference());
}
v8::Local<v8::Value> WebContents::GetOwnerBrowserWindow() const {
@ -2505,9 +2479,9 @@ v8::Local<v8::Promise> WebContents::TakeHeapSnapshot(
// static
void WebContents::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "WebContents"));
prototype->SetClassName(gin::StringToV8(isolate, "WebContents"));
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("setBackgroundThrottling",
&WebContents::SetBackgroundThrottling)
.SetMethod("getProcessId", &WebContents::GetProcessID)
@ -2631,40 +2605,40 @@ AtomBrowserContext* WebContents::GetBrowserContext() const {
}
// static
mate::Handle<WebContents> WebContents::Create(v8::Isolate* isolate,
const mate::Dictionary& options) {
return mate::CreateHandle(isolate, new WebContents(isolate, options));
gin::Handle<WebContents> WebContents::Create(
v8::Isolate* isolate,
const gin_helper::Dictionary& options) {
return gin::CreateHandle(isolate, new WebContents(isolate, options));
}
// static
mate::Handle<WebContents> WebContents::CreateAndTake(
gin::Handle<WebContents> WebContents::CreateAndTake(
v8::Isolate* isolate,
std::unique_ptr<content::WebContents> web_contents,
Type type) {
return mate::CreateHandle(
return gin::CreateHandle(
isolate, new WebContents(isolate, std::move(web_contents), type));
}
// static
mate::Handle<WebContents> WebContents::From(
v8::Isolate* isolate,
content::WebContents* web_contents) {
gin::Handle<WebContents> WebContents::From(v8::Isolate* isolate,
content::WebContents* web_contents) {
auto* existing = TrackableObject::FromWrappedClass(isolate, web_contents);
if (existing)
return mate::CreateHandle(isolate, static_cast<WebContents*>(existing));
return gin::CreateHandle(isolate, static_cast<WebContents*>(existing));
else
return mate::Handle<WebContents>();
return gin::Handle<WebContents>();
}
// static
mate::Handle<WebContents> WebContents::FromOrCreate(
gin::Handle<WebContents> WebContents::FromOrCreate(
v8::Isolate* isolate,
content::WebContents* web_contents) {
auto existing = From(isolate, web_contents);
if (!existing.IsEmpty())
return existing;
else
return mate::CreateHandle(isolate, new WebContents(isolate, web_contents));
return gin::CreateHandle(isolate, new WebContents(isolate, web_contents));
}
} // namespace api
@ -2680,7 +2654,7 @@ void Initialize(v8::Local<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.Set("WebContents", WebContents::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());

View file

@ -22,13 +22,13 @@
#include "content/public/common/favicon_url.h"
#include "electron/buildflags/buildflags.h"
#include "electron/shell/common/api/api.mojom.h"
#include "native_mate/handle.h"
#include "gin/handle.h"
#include "printing/buildflags/buildflags.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "shell/browser/api/frame_subscriber.h"
#include "shell/browser/api/save_page_handler.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/common_web_contents_delegate.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "ui/gfx/image/image.h"
#if BUILDFLAG(ENABLE_PRINTING)
@ -40,10 +40,9 @@ namespace blink {
struct WebDeviceEmulationParams;
}
namespace mate {
class Arguments;
namespace gin_helper {
class Dictionary;
} // namespace mate
}
namespace network {
class ResourceRequestBody;
@ -78,7 +77,7 @@ class ExtendedWebContentsObserver : public base::CheckedObserver {
};
// Wrapper around the content::WebContents.
class WebContents : public mate::TrackableObject<WebContents>,
class WebContents : public gin_helper::TrackableObject<WebContents>,
public CommonWebContentsDelegate,
public content::WebContentsObserver,
public mojom::ElectronBrowser {
@ -93,26 +92,26 @@ class WebContents : public mate::TrackableObject<WebContents>,
};
// Create a new WebContents and return the V8 wrapper of it.
static mate::Handle<WebContents> Create(v8::Isolate* isolate,
const mate::Dictionary& options);
static gin::Handle<WebContents> Create(v8::Isolate* isolate,
const gin_helper::Dictionary& options);
// Create a new V8 wrapper for an existing |web_content|.
//
// The lifetime of |web_contents| will be managed by this class.
static mate::Handle<WebContents> CreateAndTake(
static gin::Handle<WebContents> CreateAndTake(
v8::Isolate* isolate,
std::unique_ptr<content::WebContents> web_contents,
Type type);
// Get the V8 wrapper of |web_content|, return empty handle if not wrapped.
static mate::Handle<WebContents> From(v8::Isolate* isolate,
content::WebContents* web_content);
static gin::Handle<WebContents> From(v8::Isolate* isolate,
content::WebContents* web_content);
// Get the V8 wrapper of the |web_contents|, or create one if not existed.
//
// The lifetime of |web_contents| is NOT managed by this class, and the type
// of this wrapper is always REMOTE.
static mate::Handle<WebContents> FromOrCreate(
static gin::Handle<WebContents> FromOrCreate(
v8::Isolate* isolate,
content::WebContents* web_contents);
@ -143,7 +142,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
const std::string& document_url) const;
Type GetType() const;
bool Equal(const WebContents* web_contents) const;
void LoadURL(const GURL& url, const mate::Dictionary& options);
void LoadURL(const GURL& url, const gin_helper::Dictionary& options);
void DownloadURL(const GURL& url);
GURL GetURL() const;
base::string16 GetTitle() const;
@ -158,12 +157,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
const std::string GetWebRTCIPHandlingPolicy() const;
void SetWebRTCIPHandlingPolicy(const std::string& webrtc_ip_handling_policy);
bool IsCrashed() const;
void SetUserAgent(const std::string& user_agent, mate::Arguments* args);
void SetUserAgent(const std::string& user_agent, gin_helper::Arguments* args);
std::string GetUserAgent();
void InsertCSS(const std::string& css);
v8::Local<v8::Promise> SavePage(const base::FilePath& full_file_path,
const content::SavePageType& save_type);
void OpenDevTools(mate::Arguments* args);
void OpenDevTools(gin_helper::Arguments* args);
void CloseDevTools();
bool IsDevToolsOpened();
bool IsDevToolsFocused();
@ -184,15 +183,15 @@ class WebContents : public mate::TrackableObject<WebContents>,
v8::Local<v8::Value> GetNativeView() const;
#if BUILDFLAG(ENABLE_PRINTING)
void Print(mate::Arguments* args);
void Print(gin_helper::Arguments* args);
std::vector<printing::PrinterBasicInfo> GetPrinterList();
// Print current page as PDF.
v8::Local<v8::Promise> PrintToPDF(const base::DictionaryValue& settings);
#endif
// DevTools workspace api.
void AddWorkSpace(mate::Arguments* args, const base::FilePath& path);
void RemoveWorkSpace(mate::Arguments* args, const base::FilePath& path);
void AddWorkSpace(gin_helper::Arguments* args, const base::FilePath& path);
void RemoveWorkSpace(gin_helper::Arguments* args, const base::FilePath& path);
// Editing commands.
void Undo();
@ -206,7 +205,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
void Unselect();
void Replace(const base::string16& word);
void ReplaceMisspelling(const base::string16& word);
uint32_t FindInPage(mate::Arguments* args);
uint32_t FindInPage(gin_helper::Arguments* args);
void StopFindInPage(content::StopFindAction action);
void ShowDefinitionForSelection();
void CopyImageAt(int x, int y);
@ -238,15 +237,16 @@ class WebContents : public mate::TrackableObject<WebContents>,
void SendInputEvent(v8::Isolate* isolate, v8::Local<v8::Value> input_event);
// Subscribe to the frame updates.
void BeginFrameSubscription(mate::Arguments* args);
void BeginFrameSubscription(gin_helper::Arguments* args);
void EndFrameSubscription();
// Dragging native items.
void StartDrag(const mate::Dictionary& item, mate::Arguments* args);
void StartDrag(const gin_helper::Dictionary& item,
gin_helper::Arguments* args);
// Captures the page with |rect|, |callback| would be called when capturing is
// done.
v8::Local<v8::Promise> CapturePage(mate::Arguments* args);
v8::Local<v8::Promise> CapturePage(gin_helper::Arguments* args);
// Methods for creating <webview>.
bool IsGuest() const;
@ -335,14 +335,14 @@ class WebContents : public mate::TrackableObject<WebContents>,
std::unique_ptr<content::WebContents> web_contents,
Type type);
// Creates a new content::WebContents.
WebContents(v8::Isolate* isolate, const mate::Dictionary& options);
WebContents(v8::Isolate* isolate, const gin_helper::Dictionary& options);
~WebContents() override;
void InitWithSessionAndOptions(
v8::Isolate* isolate,
std::unique_ptr<content::WebContents> web_contents,
mate::Handle<class Session> session,
const mate::Dictionary& options);
gin::Handle<class Session> session,
const gin_helper::Dictionary& options);
// content::WebContentsDelegate:
bool DidAddMessageToConsole(content::WebContents* source,
@ -526,7 +526,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
IPC::Message* reply_msg);
void InitZoomController(content::WebContents* web_contents,
const mate::Dictionary& options);
const gin_helper::Dictionary& options);
v8::Global<v8::Value> session_;
v8::Global<v8::Value> devtools_web_contents_;

View file

@ -5,11 +5,11 @@
#include "shell/browser/api/atom_api_web_contents_view.h"
#include "content/public/browser/web_contents_user_data.h"
#include "native_mate/dictionary.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/browser.h"
#include "shell/browser/ui/inspectable_web_contents_view.h"
#include "shell/common/api/constructor.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
#if defined(OS_MACOSX)
@ -44,7 +44,7 @@ namespace electron {
namespace api {
WebContentsView::WebContentsView(v8::Isolate* isolate,
mate::Handle<WebContents> web_contents,
gin::Handle<WebContents> web_contents,
InspectableWebContents* iwc)
#if defined(OS_MACOSX)
: View(new DelayedNativeViewHost(iwc->GetView()->GetNativeView())),
@ -80,22 +80,18 @@ void WebContentsView::WebContentsDestroyed() {
// static
mate::WrappableBase* WebContentsView::New(
gin::Arguments* args,
mate::Handle<WebContents> web_contents) {
gin_helper::Arguments* args,
gin::Handle<WebContents> web_contents) {
// Currently we only support InspectableWebContents, e.g. the WebContents
// created by users directly. To support devToolsWebContents we need to create
// a wrapper view.
if (!web_contents->managed_web_contents()) {
const char* error = "The WebContents must be created by user";
args->isolate()->ThrowException(
v8::Exception::Error(mate::StringToV8(args->isolate(), error)));
args->ThrowError("The WebContents must be created by user");
return nullptr;
}
// Check if the WebContents has already been added to a view.
if (WebContentsViewRelay::FromWebContents(web_contents->web_contents())) {
const char* error = "The WebContents has already been added to a View";
args->isolate()->ThrowException(
v8::Exception::Error(mate::StringToV8(args->isolate(), error)));
args->ThrowError("The WebContents has already been added to a View");
return nullptr;
}
// Constructor call.
@ -123,7 +119,7 @@ void Initialize(v8::Local<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.Set("WebContentsView",
mate::CreateConstructor<WebContentsView>(
isolate, base::BindRepeating(&WebContentsView::New)));

View file

@ -6,7 +6,6 @@
#define SHELL_BROWSER_API_ATOM_API_WEB_CONTENTS_VIEW_H_
#include "content/public/browser/web_contents_observer.h"
#include "native_mate/handle.h"
#include "shell/browser/api/atom_api_view.h"
namespace electron {
@ -19,15 +18,15 @@ class WebContents;
class WebContentsView : public View, public content::WebContentsObserver {
public:
static mate::WrappableBase* New(gin::Arguments* args,
mate::Handle<WebContents> web_contents);
static mate::WrappableBase* New(gin_helper::Arguments* args,
gin::Handle<WebContents> web_contents);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
WebContentsView(v8::Isolate* isolate,
mate::Handle<WebContents> web_contents,
gin::Handle<WebContents> web_contents,
InspectableWebContents* iwc);
~WebContentsView() override;

View file

@ -3,12 +3,12 @@
// found in the LICENSE file.
#include "content/public/browser/browser_context.h"
#include "native_mate/dictionary.h"
#include "shell/browser/web_contents_preferences.h"
#include "shell/browser/web_contents_zoom_controller.h"
#include "shell/browser/web_view_manager.h"
#include "shell/common/native_mate_converters/content_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/gin_converters/content_converter.h"
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
@ -45,7 +45,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports);
gin_helper::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("addGuest", &AddGuest);
dict.SetMethod("removeGuest", &RemoveGuest);
}

View file

@ -1,96 +0,0 @@
// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/event_emitter_deprecated.h"
#include <utility>
#include "content/public/browser/render_frame_host.h"
#include "native_mate/arguments.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "shell/browser/api/event.h"
#include "shell/common/node_includes.h"
#include "ui/events/event_constants.h"
namespace mate {
namespace {
v8::Persistent<v8::ObjectTemplate> event_template;
void PreventDefault(mate::Arguments* args) {
mate::Dictionary self(args->isolate(), args->GetThis());
self.Set("defaultPrevented", true);
}
// Create a pure JavaScript Event object.
v8::Local<v8::Object> CreateEventObject(v8::Isolate* isolate) {
if (event_template.IsEmpty()) {
event_template.Reset(
isolate,
ObjectTemplateBuilder(isolate, v8::ObjectTemplate::New(isolate))
.SetMethod("preventDefault", &PreventDefault)
.Build());
}
return v8::Local<v8::ObjectTemplate>::New(isolate, event_template)
->NewInstance(isolate->GetCurrentContext())
.ToLocalChecked();
}
} // namespace
namespace internal {
v8::Local<v8::Object> CreateJSEvent(
v8::Isolate* isolate,
v8::Local<v8::Object> object,
content::RenderFrameHost* sender,
base::Optional<electron::mojom::ElectronBrowser::MessageSyncCallback>
callback) {
v8::Local<v8::Object> event;
bool use_native_event = sender && callback;
if (use_native_event) {
mate::Handle<mate::Event> native_event = mate::Event::Create(isolate);
native_event->SetCallback(std::move(callback));
event = v8::Local<v8::Object>::Cast(native_event.ToV8());
} else {
event = CreateEventObject(isolate);
}
mate::Dictionary dict(isolate, event);
dict.Set("sender", object);
if (sender)
dict.Set("frameId", sender->GetRoutingID());
return event;
}
v8::Local<v8::Object> CreateCustomEvent(v8::Isolate* isolate,
v8::Local<v8::Object> object,
v8::Local<v8::Object> custom_event) {
v8::Local<v8::Object> event = CreateEventObject(isolate);
(void)event->SetPrototype(custom_event->CreationContext(), custom_event);
mate::Dictionary(isolate, event).Set("sender", object);
return event;
}
v8::Local<v8::Object> CreateEventFromFlags(v8::Isolate* isolate, int flags) {
const int mouse_button_flags =
(ui::EF_RIGHT_MOUSE_BUTTON | ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_BACK_MOUSE_BUTTON |
ui::EF_FORWARD_MOUSE_BUTTON);
const int is_mouse_click = static_cast<bool>(flags & mouse_button_flags);
mate::Dictionary obj = mate::Dictionary::CreateEmpty(isolate);
obj.Set("shiftKey", static_cast<bool>(flags & ui::EF_SHIFT_DOWN));
obj.Set("ctrlKey", static_cast<bool>(flags & ui::EF_CONTROL_DOWN));
obj.Set("altKey", static_cast<bool>(flags & ui::EF_ALT_DOWN));
obj.Set("metaKey", static_cast<bool>(flags & ui::EF_COMMAND_DOWN));
obj.Set("triggeredByAccelerator", !is_mouse_click);
return obj.GetHandle();
}
} // namespace internal
} // namespace mate

View file

@ -1,128 +0,0 @@
// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_EVENT_EMITTER_DEPRECATED_H_
#define SHELL_BROWSER_API_EVENT_EMITTER_DEPRECATED_H_
#include <utility>
#include <vector>
#include "base/optional.h"
#include "content/public/browser/browser_thread.h"
#include "electron/shell/common/api/api.mojom.h"
#include "native_mate/wrappable.h"
#include "shell/common/api/event_emitter_caller_deprecated.h"
namespace content {
class RenderFrameHost;
}
namespace mate {
namespace internal {
v8::Local<v8::Object> CreateJSEvent(
v8::Isolate* isolate,
v8::Local<v8::Object> object,
content::RenderFrameHost* sender,
base::Optional<electron::mojom::ElectronBrowser::MessageSyncCallback>
callback);
v8::Local<v8::Object> CreateCustomEvent(v8::Isolate* isolate,
v8::Local<v8::Object> object,
v8::Local<v8::Object> event);
v8::Local<v8::Object> CreateEventFromFlags(v8::Isolate* isolate, int flags);
} // namespace internal
// Provide helperers to emit event in JavaScript.
template <typename T>
class EventEmitter : public Wrappable<T> {
public:
typedef std::vector<v8::Local<v8::Value>> ValueArray;
// Make the convinient methods visible:
// https://isocpp.org/wiki/faq/templates#nondependent-name-lookup-members
v8::Isolate* isolate() const { return Wrappable<T>::isolate(); }
v8::Local<v8::Object> GetWrapper() const {
return Wrappable<T>::GetWrapper();
}
v8::MaybeLocal<v8::Object> GetWrapper(v8::Isolate* isolate) const {
return Wrappable<T>::GetWrapper(isolate);
}
// this.emit(name, event, args...);
template <typename... Args>
bool EmitCustomEvent(base::StringPiece name,
v8::Local<v8::Object> event,
Args&&... args) {
return EmitWithEvent(
name, internal::CreateCustomEvent(isolate(), GetWrapper(), event),
std::forward<Args>(args)...);
}
// this.emit(name, new Event(flags), args...);
template <typename... Args>
bool EmitWithFlags(base::StringPiece name, int flags, Args&&... args) {
return EmitCustomEvent(name,
internal::CreateEventFromFlags(isolate(), flags),
std::forward<Args>(args)...);
}
// this.emit(name, new Event(), args...);
template <typename... Args>
bool Emit(base::StringPiece name, Args&&... args) {
return EmitWithSender(name, nullptr, base::nullopt,
std::forward<Args>(args)...);
}
// this.emit(name, new Event(sender, message), args...);
template <typename... Args>
bool EmitWithSender(
base::StringPiece name,
content::RenderFrameHost* sender,
base::Optional<electron::mojom::ElectronBrowser::InvokeCallback> callback,
Args&&... args) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
v8::Local<v8::Object> wrapper = GetWrapper();
if (wrapper.IsEmpty()) {
return false;
}
v8::Local<v8::Object> event = internal::CreateJSEvent(
isolate(), wrapper, sender, std::move(callback));
return EmitWithEvent(name, event, std::forward<Args>(args)...);
}
protected:
EventEmitter() {}
private:
// this.emit(name, event, args...);
template <typename... Args>
bool EmitWithEvent(base::StringPiece name,
v8::Local<v8::Object> event,
Args&&... args) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// It's possible that |this| will be deleted by EmitEvent, so save anything
// we need from |this| before calling EmitEvent.
auto* isolate = this->isolate();
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
auto context = isolate->GetCurrentContext();
EmitEvent(isolate, GetWrapper(), name, event, std::forward<Args>(args)...);
v8::Local<v8::Value> defaultPrevented;
if (event->Get(context, StringToV8(isolate, "defaultPrevented"))
.ToLocal(&defaultPrevented)) {
return defaultPrevented->BooleanValue(isolate);
}
return false;
}
DISALLOW_COPY_AND_ASSIGN(EventEmitter);
};
} // namespace mate
#endif // SHELL_BROWSER_API_EVENT_EMITTER_DEPRECATED_H_

View file

@ -7,14 +7,14 @@
#include <memory>
#include "shell/browser/api/trackable_object.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "ui/views/layout/layout_manager.h"
namespace electron {
namespace api {
class LayoutManager : public mate::TrackableObject<LayoutManager> {
class LayoutManager : public gin_helper::TrackableObject<LayoutManager> {
public:
static mate::WrappableBase* New(mate::Arguments* args);

View file

@ -34,7 +34,6 @@
#include "services/service_manager/public/cpp/connector.h"
#include "shell/app/atom_main_delegate.h"
#include "shell/browser/api/atom_api_app.h"
#include "shell/browser/api/trackable_object.h"
#include "shell/browser/atom_browser_client.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/atom_paths.h"
@ -49,6 +48,7 @@
#include "shell/common/api/electron_bindings.h"
#include "shell/common/application_info.h"
#include "shell/common/asar/asar_util.h"
#include "shell/common/gin_helper/trackable_object.h"
#include "shell/common/node_bindings.h"
#include "shell/common/node_includes.h"
#include "ui/base/idle/idle.h"

View file

@ -3,25 +3,25 @@
// found in the LICENSE file.
#include "shell/browser/lib/bluetooth_chooser.h"
#include "native_mate/dictionary.h"
#include "shell/common/native_mate_converters/once_callback.h"
#include "shell/common/native_mate_converters/string16_converter.h"
namespace mate {
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_helper/dictionary.h"
namespace gin {
template <>
struct Converter<electron::BluetoothChooser::DeviceInfo> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const electron::BluetoothChooser::DeviceInfo& val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.Set("deviceName", val.device_name);
dict.Set("deviceId", val.device_id);
return mate::ConvertToV8(isolate, dict);
return gin::ConvertToV8(isolate, dict);
}
};
} // namespace mate
} // namespace gin
namespace electron {

View file

@ -11,10 +11,10 @@
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "native_mate/dictionary.h"
#include "shell/browser/browser.h"
#include "shell/browser/window_list.h"
#include "shell/common/color_util.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/options_switches.h"
#include "ui/views/widget/widget.h"
@ -45,7 +45,7 @@ gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) {
} // namespace
NativeWindow::NativeWindow(const mate::Dictionary& options,
NativeWindow::NativeWindow(const gin_helper::Dictionary& options,
NativeWindow* parent)
: widget_(new views::Widget), parent_(parent), weak_factory_(this) {
options.Get(options::kFrame, &has_frame_);
@ -67,7 +67,7 @@ NativeWindow::~NativeWindow() {
NotifyWindowClosed();
}
void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
void NativeWindow::InitFromOptions(const gin_helper::Dictionary& options) {
// Setup window from options.
int x = -1, y = -1;
bool center;

View file

@ -37,10 +37,13 @@ class RectF;
class Size;
} // namespace gfx
namespace mate {
namespace gin_helper {
class Dictionary;
}
namespace mate {
class PersistentDictionary;
} // namespace mate
}
namespace electron {
@ -60,10 +63,10 @@ class NativeWindow : public base::SupportsUserData,
// Create window with existing WebContents, the caller is responsible for
// managing the window's live.
static NativeWindow* Create(const mate::Dictionary& options,
static NativeWindow* Create(const gin_helper::Dictionary& options,
NativeWindow* parent = nullptr);
void InitFromOptions(const mate::Dictionary& options);
void InitFromOptions(const gin_helper::Dictionary& options);
virtual void SetContentView(views::View* view) = 0;
@ -304,7 +307,7 @@ class NativeWindow : public base::SupportsUserData,
std::list<NativeBrowserView*> browser_views() const { return browser_views_; }
protected:
NativeWindow(const mate::Dictionary& options, NativeWindow* parent);
NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent);
// views::WidgetDelegate:
views::Widget* GetWidget() override;

View file

@ -28,7 +28,7 @@ class RootViewMac;
class NativeWindowMac : public NativeWindow {
public:
NativeWindowMac(const mate::Dictionary& options, NativeWindow* parent);
NativeWindowMac(const gin_helper::Dictionary& options, NativeWindow* parent);
~NativeWindowMac() override;
// NativeWindow:

View file

@ -17,7 +17,6 @@
#include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
#include "content/public/browser/browser_accessibility_state.h"
#include "content/public/browser/desktop_media_id.h"
#include "native_mate/dictionary.h"
#include "shell/browser/native_browser_view_mac.h"
#include "shell/browser/ui/cocoa/atom_native_widget_mac.h"
#include "shell/browser/ui/cocoa/atom_ns_window.h"
@ -29,6 +28,7 @@
#include "shell/browser/ui/inspectable_web_contents_view.h"
#include "shell/browser/window_list.h"
#include "shell/common/deprecate_util.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/options_switches.h"
#include "skia/ext/skia_utils_mac.h"
#include "third_party/webrtc/modules/desktop_capture/mac/window_list_utils.h"
@ -244,7 +244,7 @@
@end
namespace mate {
namespace gin {
template <>
struct Converter<electron::NativeWindowMac::TitleBarStyle> {
@ -268,7 +268,7 @@ struct Converter<electron::NativeWindowMac::TitleBarStyle> {
}
};
} // namespace mate
} // namespace gin
namespace electron {
@ -318,7 +318,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
} // namespace
NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
NativeWindow* parent)
: NativeWindow(options, parent), root_view_(new RootViewMac(this)) {
int width = 800, height = 600;
@ -1659,7 +1659,7 @@ void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) {
}
// static
NativeWindow* NativeWindow::Create(const mate::Dictionary& options,
NativeWindow* NativeWindow::Create(const gin_helper::Dictionary& options,
NativeWindow* parent) {
return new NativeWindowMac(options, parent);
}

View file

@ -18,7 +18,6 @@
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/desktop_media_id.h"
#include "native_mate/dictionary.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/native_browser_view_views.h"
#include "shell/browser/ui/inspectable_web_contents.h"
@ -28,7 +27,8 @@
#include "shell/browser/web_view_manager.h"
#include "shell/browser/window_list.h"
#include "shell/common/atom_constants.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/gin_converters/image_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/options_switches.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/hit_test.h"
@ -126,7 +126,7 @@ class NativeWindowClientView : public views::ClientView {
} // namespace
NativeWindowViews::NativeWindowViews(const mate::Dictionary& options,
NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
NativeWindow* parent)
: NativeWindow(options, parent),
root_view_(new RootView(this)),
@ -1454,7 +1454,7 @@ void NativeWindowViews::MoveBehindTaskBarIfNeeded() {
}
// static
NativeWindow* NativeWindow::Create(const mate::Dictionary& options,
NativeWindow* NativeWindow::Create(const gin_helper::Dictionary& options,
NativeWindow* parent) {
return new NativeWindowViews(options, parent);
}

View file

@ -37,7 +37,8 @@ class NativeWindowViews : public NativeWindow,
public views::WidgetObserver,
public ui::EventHandler {
public:
NativeWindowViews(const mate::Dictionary& options, NativeWindow* parent);
NativeWindowViews(const gin_helper::Dictionary& options,
NativeWindow* parent);
~NativeWindowViews() override;
// NativeWindow:

View file

@ -388,8 +388,8 @@ void AtomURLLoaderFactory::StartLoadingHttp(
if (value->IsNull()) {
browser_context = AtomBrowserContext::From(base::GenerateGUID(), true);
} else {
mate::Handle<api::Session> session;
if (mate::ConvertFromV8(dict.isolate(), value, &session) &&
gin::Handle<api::Session> session;
if (gin::ConvertFromV8(dict.isolate(), value, &session) &&
!session.IsEmpty()) {
browser_context = session->browser_context();
}

View file

@ -19,12 +19,12 @@
#include "content/public/common/content_switches.h"
#include "content/public/common/web_preferences.h"
#include "electron/buildflags/buildflags.h"
#include "native_mate/dictionary.h"
#include "net/base/filename_util.h"
#include "services/service_manager/sandbox/switches.h"
#include "shell/browser/native_window.h"
#include "shell/browser/web_view_manager.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/gin_converters/value_converter_gin_adapter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/options_switches.h"
#if defined(OS_WIN)
@ -101,16 +101,16 @@ std::vector<WebContentsPreferences*> WebContentsPreferences::instances_;
WebContentsPreferences::WebContentsPreferences(
content::WebContents* web_contents,
const mate::Dictionary& web_preferences)
const gin_helper::Dictionary& web_preferences)
: web_contents_(web_contents) {
v8::Isolate* isolate = web_preferences.isolate();
mate::Dictionary copied(isolate, web_preferences.GetHandle()->Clone());
gin_helper::Dictionary copied(isolate, web_preferences.GetHandle()->Clone());
// Following fields should not be stored.
copied.Delete("embedder");
copied.Delete("session");
copied.Delete("type");
mate::ConvertFromV8(isolate, copied.GetHandle(), &preference_);
gin::ConvertFromV8(isolate, copied.GetHandle(), &preference_);
web_contents->SetUserData(UserDataKey(), base::WrapUnique(this));
instances_.push_back(this);

View file

@ -19,7 +19,7 @@ namespace content {
struct WebPreferences;
}
namespace mate {
namespace gin_helper {
class Dictionary;
}
@ -33,7 +33,7 @@ class WebContentsPreferences
static WebContentsPreferences* From(content::WebContents* web_contents);
WebContentsPreferences(content::WebContents* web_contents,
const mate::Dictionary& web_preferences);
const gin_helper::Dictionary& web_preferences);
~WebContentsPreferences() override;
// Set WebPreferences defaults onto the JS object.

View file

@ -259,7 +259,7 @@ float NativeImage::GetAspectRatio() {
return static_cast<float>(size.width()) / static_cast<float>(size.height());
}
mate::Handle<NativeImage> NativeImage::Resize(
gin::Handle<NativeImage> NativeImage::Resize(
v8::Isolate* isolate,
const base::DictionaryValue& options) {
gfx::Size size = GetSize();
@ -290,16 +290,16 @@ mate::Handle<NativeImage> NativeImage::Resize(
gfx::ImageSkia resized = gfx::ImageSkiaOperations::CreateResizedImage(
image_.AsImageSkia(), method, size);
return mate::CreateHandle(isolate,
new NativeImage(isolate, gfx::Image(resized)));
return gin::CreateHandle(isolate,
new NativeImage(isolate, gfx::Image(resized)));
}
mate::Handle<NativeImage> NativeImage::Crop(v8::Isolate* isolate,
const gfx::Rect& rect) {
gin::Handle<NativeImage> NativeImage::Crop(v8::Isolate* isolate,
const gfx::Rect& rect) {
gfx::ImageSkia cropped =
gfx::ImageSkiaOperations::ExtractSubset(image_.AsImageSkia(), rect);
return mate::CreateHandle(isolate,
new NativeImage(isolate, gfx::Image(cropped)));
return gin::CreateHandle(isolate,
new NativeImage(isolate, gfx::Image(cropped)));
}
void NativeImage::AddRepresentation(const gin_helper::Dictionary& options) {
@ -350,48 +350,48 @@ bool NativeImage::IsTemplateImage() {
#endif
// static
mate::Handle<NativeImage> NativeImage::CreateEmpty(v8::Isolate* isolate) {
return mate::CreateHandle(isolate, new NativeImage(isolate, gfx::Image()));
gin::Handle<NativeImage> NativeImage::CreateEmpty(v8::Isolate* isolate) {
return gin::CreateHandle(isolate, new NativeImage(isolate, gfx::Image()));
}
// static
mate::Handle<NativeImage> NativeImage::Create(v8::Isolate* isolate,
const gfx::Image& image) {
return mate::CreateHandle(isolate, new NativeImage(isolate, image));
gin::Handle<NativeImage> NativeImage::Create(v8::Isolate* isolate,
const gfx::Image& image) {
return gin::CreateHandle(isolate, new NativeImage(isolate, image));
}
// static
mate::Handle<NativeImage> NativeImage::CreateFromPNG(v8::Isolate* isolate,
const char* buffer,
size_t length) {
gin::Handle<NativeImage> NativeImage::CreateFromPNG(v8::Isolate* isolate,
const char* buffer,
size_t length) {
gfx::Image image = gfx::Image::CreateFrom1xPNGBytes(
reinterpret_cast<const unsigned char*>(buffer), length);
return Create(isolate, image);
}
// static
mate::Handle<NativeImage> NativeImage::CreateFromJPEG(v8::Isolate* isolate,
const char* buffer,
size_t length) {
gin::Handle<NativeImage> NativeImage::CreateFromJPEG(v8::Isolate* isolate,
const char* buffer,
size_t length) {
gfx::Image image = gfx::ImageFrom1xJPEGEncodedData(
reinterpret_cast<const unsigned char*>(buffer), length);
return Create(isolate, image);
}
// static
mate::Handle<NativeImage> NativeImage::CreateFromPath(
gin::Handle<NativeImage> NativeImage::CreateFromPath(
v8::Isolate* isolate,
const base::FilePath& path) {
base::FilePath image_path = NormalizePath(path);
#if defined(OS_WIN)
if (image_path.MatchesExtension(FILE_PATH_LITERAL(".ico"))) {
return mate::CreateHandle(isolate, new NativeImage(isolate, image_path));
return gin::CreateHandle(isolate, new NativeImage(isolate, image_path));
}
#endif
gfx::ImageSkia image_skia;
electron::util::PopulateImageSkiaRepsFromPath(&image_skia, image_path);
gfx::Image image(image_skia);
mate::Handle<NativeImage> handle = Create(isolate, image);
gin::Handle<NativeImage> handle = Create(isolate, image);
#if defined(OS_MACOSX)
if (IsTemplateFilename(image_path))
handle->SetTemplateImage(true);
@ -400,13 +400,13 @@ mate::Handle<NativeImage> NativeImage::CreateFromPath(
}
// static
mate::Handle<NativeImage> NativeImage::CreateFromBitmap(
gin::Handle<NativeImage> NativeImage::CreateFromBitmap(
gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> buffer,
const gin_helper::Dictionary& options) {
if (!node::Buffer::HasInstance(buffer)) {
thrower.ThrowError("buffer must be a node Buffer");
return mate::Handle<NativeImage>();
return gin::Handle<NativeImage>();
}
unsigned int width = 0;
@ -415,12 +415,12 @@ mate::Handle<NativeImage> NativeImage::CreateFromBitmap(
if (!options.Get("width", &width)) {
thrower.ThrowError("width is required");
return mate::Handle<NativeImage>();
return gin::Handle<NativeImage>();
}
if (!options.Get("height", &height)) {
thrower.ThrowError("height is required");
return mate::Handle<NativeImage>();
return gin::Handle<NativeImage>();
}
auto info = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType);
@ -428,7 +428,7 @@ mate::Handle<NativeImage> NativeImage::CreateFromBitmap(
if (size_bytes != node::Buffer::Length(buffer)) {
thrower.ThrowError("invalid buffer size");
return mate::Handle<NativeImage>();
return gin::Handle<NativeImage>();
}
options.Get("scaleFactor", &scale_factor);
@ -448,13 +448,13 @@ mate::Handle<NativeImage> NativeImage::CreateFromBitmap(
}
// static
mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
gin::Handle<NativeImage> NativeImage::CreateFromBuffer(
gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> buffer,
gin::Arguments* args) {
if (!node::Buffer::HasInstance(buffer)) {
thrower.ThrowError("buffer must be a node Buffer");
return mate::Handle<NativeImage>();
return gin::Handle<NativeImage>();
}
int width = 0;
@ -476,8 +476,8 @@ mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
}
// static
mate::Handle<NativeImage> NativeImage::CreateFromDataURL(v8::Isolate* isolate,
const GURL& url) {
gin::Handle<NativeImage> NativeImage::CreateFromDataURL(v8::Isolate* isolate,
const GURL& url) {
std::string mime_type, charset, data;
if (net::DataURL::Parse(url, &mime_type, &charset, &data)) {
if (mime_type == "image/png")
@ -490,7 +490,7 @@ mate::Handle<NativeImage> NativeImage::CreateFromDataURL(v8::Isolate* isolate,
}
#if !defined(OS_MACOSX)
mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(
gin::Arguments* args,
const std::string& name) {
return CreateEmpty(args->isolate());
@ -526,32 +526,31 @@ void NativeImage::BuildPrototype(v8::Isolate* isolate,
namespace gin {
v8::Local<v8::Value> Converter<mate::Handle<electron::api::NativeImage>>::ToV8(
v8::Local<v8::Value> Converter<electron::api::NativeImage*>::ToV8(
v8::Isolate* isolate,
const mate::Handle<electron::api::NativeImage>& val) {
return val.ToV8();
electron::api::NativeImage* val) {
if (val)
return val->GetWrapper();
else
return v8::Null(isolate);
}
bool Converter<mate::Handle<electron::api::NativeImage>>::FromV8(
bool Converter<electron::api::NativeImage*>::FromV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val,
mate::Handle<electron::api::NativeImage>* out) {
electron::api::NativeImage** out) {
// Try converting from file path.
base::FilePath path;
if (ConvertFromV8(isolate, val, &path)) {
*out = electron::api::NativeImage::CreateFromPath(isolate, path);
*out = electron::api::NativeImage::CreateFromPath(isolate, path).get();
// Should throw when failed to initialize from path.
return !(*out)->image().IsEmpty();
}
auto* wrapper = static_cast<mate::WrappableBase*>(
mate::internal::FromV8Impl(isolate, val));
if (!wrapper)
return false;
*out = mate::CreateHandle(isolate,
static_cast<electron::api::NativeImage*>(wrapper));
return true;
*out = static_cast<electron::api::NativeImage*>(
static_cast<mate::WrappableBase*>(
mate::internal::FromV8Impl(isolate, val)));
return *out != nullptr;
}
} // namespace gin

View file

@ -9,7 +9,7 @@
#include <string>
#include "base/values.h"
#include "native_mate/handle.h"
#include "gin/handle.h"
#include "native_mate/wrappable.h"
#include "shell/common/gin_helper/error_thrower.h"
#include "ui/gfx/image/image.h"
@ -40,30 +40,29 @@ namespace api {
class NativeImage : public mate::Wrappable<NativeImage> {
public:
static mate::Handle<NativeImage> CreateEmpty(v8::Isolate* isolate);
static mate::Handle<NativeImage> Create(v8::Isolate* isolate,
const gfx::Image& image);
static mate::Handle<NativeImage> CreateFromPNG(v8::Isolate* isolate,
static gin::Handle<NativeImage> CreateEmpty(v8::Isolate* isolate);
static gin::Handle<NativeImage> Create(v8::Isolate* isolate,
const gfx::Image& image);
static gin::Handle<NativeImage> CreateFromPNG(v8::Isolate* isolate,
const char* buffer,
size_t length);
static gin::Handle<NativeImage> CreateFromJPEG(v8::Isolate* isolate,
const char* buffer,
size_t length);
static mate::Handle<NativeImage> CreateFromJPEG(v8::Isolate* isolate,
const char* buffer,
size_t length);
static mate::Handle<NativeImage> CreateFromPath(v8::Isolate* isolate,
const base::FilePath& path);
static mate::Handle<NativeImage> CreateFromBitmap(
static gin::Handle<NativeImage> CreateFromPath(v8::Isolate* isolate,
const base::FilePath& path);
static gin::Handle<NativeImage> CreateFromBitmap(
gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> buffer,
const gin_helper::Dictionary& options);
static mate::Handle<NativeImage> CreateFromBuffer(
static gin::Handle<NativeImage> CreateFromBuffer(
gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> buffer,
gin::Arguments* args);
static mate::Handle<NativeImage> CreateFromDataURL(v8::Isolate* isolate,
const GURL& url);
static mate::Handle<NativeImage> CreateFromNamedImage(
gin::Arguments* args,
const std::string& name);
static gin::Handle<NativeImage> CreateFromDataURL(v8::Isolate* isolate,
const GURL& url);
static gin::Handle<NativeImage> CreateFromNamedImage(gin::Arguments* args,
const std::string& name);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
@ -87,9 +86,9 @@ class NativeImage : public mate::Wrappable<NativeImage> {
v8::Local<v8::Value> ToBitmap(gin::Arguments* args);
v8::Local<v8::Value> GetBitmap(gin::Arguments* args);
v8::Local<v8::Value> GetNativeHandle(gin_helper::ErrorThrower thrower);
mate::Handle<NativeImage> Resize(v8::Isolate* isolate,
const base::DictionaryValue& options);
mate::Handle<NativeImage> Crop(v8::Isolate* isolate, const gfx::Rect& rect);
gin::Handle<NativeImage> Resize(v8::Isolate* isolate,
const base::DictionaryValue& options);
gin::Handle<NativeImage> Crop(v8::Isolate* isolate, const gfx::Rect& rect);
std::string ToDataURL(gin::Arguments* args);
bool IsEmpty();
gfx::Size GetSize();
@ -119,36 +118,14 @@ namespace gin {
// A custom converter that allows converting path to NativeImage.
template <>
struct Converter<mate::Handle<electron::api::NativeImage>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const mate::Handle<electron::api::NativeImage>& val);
struct Converter<electron::api::NativeImage*> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::api::NativeImage* val);
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
mate::Handle<electron::api::NativeImage>* out);
electron::api::NativeImage** out);
};
} // namespace gin
namespace mate {
// Keep compatibility with native_mate code.
//
// TODO(zcbenz): Remove this after removing native_mate.
template <>
struct Converter<mate::Handle<electron::api::NativeImage>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const mate::Handle<electron::api::NativeImage>& val) {
return gin::ConvertToV8(isolate, val);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
mate::Handle<electron::api::NativeImage>* out) {
return gin::ConvertFromV8(isolate, val, out);
}
};
} // namespace mate
#endif // SHELL_COMMON_API_ATOM_API_NATIVE_IMAGE_H_

View file

@ -33,7 +33,7 @@ double safeShift(double in, double def) {
return def;
}
mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
gin::Handle<NativeImage> NativeImage::CreateFromNamedImage(
gin::Arguments* args,
const std::string& name) {
@autoreleasepool {

View file

@ -7,6 +7,7 @@
#include "base/hash/hash.h"
#include "electron/buildflags/buildflags.h"
#include "shell/common/gin_converters/content_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
@ -19,10 +20,6 @@
#include "shell/common/api/remote/remote_object_freer.h"
#endif
// TODO(zcbenz): Remove the includes after removing native_mate.
#include "native_mate/dictionary.h"
#include "shell/common/native_mate_converters/content_converter.h"
namespace std {
// The hash function used by DoubleIDWeakMap.
@ -125,11 +122,8 @@ void Initialize(v8::Local<v8::Object> exports,
dict.SetMethod("getObjectHash", &GetObjectHash);
dict.SetMethod("takeHeapSnapshot", &TakeHeapSnapshot);
#if BUILDFLAG(ENABLE_REMOTE_MODULE)
// TODO(zcbenz): Use gin_helper::Dictionary when content_converter.h is moved
// to gin.
mate::Dictionary mdict(context->GetIsolate(), exports);
mdict.SetMethod("setRemoteCallbackFreer",
&electron::RemoteCallbackFreer::BindTo);
dict.SetMethod("setRemoteCallbackFreer",
&electron::RemoteCallbackFreer::BindTo);
dict.SetMethod("setRemoteObjectFreer", &electron::RemoteObjectFreer::BindTo);
dict.SetMethod("addRemoteObjectRef", &electron::RemoteObjectFreer::AddRef);
dict.SetMethod("createIDWeakMap",

View file

@ -2,13 +2,13 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/common/native_mate_converters/accelerator_converter.h"
#include "shell/common/gin_converters/accelerator_converter.h"
#include <string>
#include "shell/browser/ui/accelerator_util.h"
namespace mate {
namespace gin {
// static
bool Converter<ui::Accelerator>::FromV8(v8::Isolate* isolate,
@ -20,4 +20,4 @@ bool Converter<ui::Accelerator>::FromV8(v8::Isolate* isolate,
return accelerator_util::StringToAccelerator(keycode, out);
}
} // namespace mate
} // namespace gin

View file

@ -2,16 +2,16 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_ACCELERATOR_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_ACCELERATOR_CONVERTER_H_
#ifndef SHELL_COMMON_GIN_CONVERTERS_ACCELERATOR_CONVERTER_H_
#define SHELL_COMMON_GIN_CONVERTERS_ACCELERATOR_CONVERTER_H_
#include "native_mate/converter.h"
#include "gin/converter.h"
namespace ui {
class Accelerator;
}
namespace mate {
namespace gin {
template <>
struct Converter<ui::Accelerator> {
@ -20,6 +20,6 @@ struct Converter<ui::Accelerator> {
ui::Accelerator* out);
};
} // namespace mate
} // namespace gin
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_ACCELERATOR_CONVERTER_H_
#endif // SHELL_COMMON_GIN_CONVERTERS_ACCELERATOR_CONVERTER_H_

View file

@ -12,6 +12,15 @@
namespace gin {
template <>
struct Converter<blink::WebKeyboardEvent> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebKeyboardEvent* out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
template <>
struct Converter<blink::CloneableMessage> {
static bool FromV8(v8::Isolate* isolate,
@ -25,6 +34,46 @@ struct Converter<blink::CloneableMessage> {
}
};
template <>
struct Converter<blink::WebDeviceEmulationParams> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebDeviceEmulationParams* out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
template <>
struct Converter<blink::WebContextMenuData::MediaType> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const blink::WebContextMenuData::MediaType& in) {
return mate::ConvertToV8(isolate, in);
}
};
template <>
struct Converter<blink::WebContextMenuData::InputFieldType> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const blink::WebContextMenuData::InputFieldType& in) {
return mate::ConvertToV8(isolate, in);
}
};
template <>
struct Converter<network::mojom::ReferrerPolicy> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const network::mojom::ReferrerPolicy& in) {
return mate::ConvertToV8(isolate, in);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
network::mojom::ReferrerPolicy* out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
} // namespace gin
#endif // SHELL_COMMON_GIN_CONVERTERS_BLINK_CONVERTER_GIN_ADAPTER_H_

View file

@ -2,22 +2,22 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/common/native_mate_converters/content_converter.h"
#include "shell/common/gin_converters/content_converter.h"
#include <string>
#include <vector>
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/context_menu_params.h"
#include "native_mate/dictionary.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/web_contents_permission_helper.h"
#include "shell/common/native_mate_converters/blink_converter.h"
#include "shell/common/native_mate_converters/callback_converter_deprecated.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/string16_converter.h"
#include "shell/common/native_mate_converters/ui_base_types_converter.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/gin_converters/blink_converter_gin_adapter.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"
namespace {
@ -38,7 +38,7 @@ v8::Local<v8::Value> MenuItemToV8(
content::WebContents* web_contents,
const content::CustomContextMenuContext& context,
const content::MenuItem& item) {
mate::Dictionary v8_item = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary v8_item = gin::Dictionary::CreateEmpty(isolate);
switch (item.type) {
case content::MenuItem::CHECKABLE_OPTION:
case content::MenuItem::GROUP:
@ -69,12 +69,31 @@ v8::Local<v8::Value> MenuToV8(v8::Isolate* isolate,
v8_menu.reserve(menu.size());
for (const auto& menu_item : menu)
v8_menu.push_back(MenuItemToV8(isolate, web_contents, context, menu_item));
return mate::ConvertToV8(isolate, v8_menu);
return gin::ConvertToV8(isolate, v8_menu);
}
} // namespace
namespace mate {
namespace gin {
template <>
struct Converter<ui::MenuSourceType> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const ui::MenuSourceType& in) {
switch (in) {
case ui::MENU_SOURCE_MOUSE:
return StringToV8(isolate, "mouse");
case ui::MENU_SOURCE_KEYBOARD:
return StringToV8(isolate, "keyboard");
case ui::MENU_SOURCE_TOUCH:
return StringToV8(isolate, "touch");
case ui::MENU_SOURCE_TOUCH_EDIT_MENU:
return StringToV8(isolate, "touchMenu");
default:
return StringToV8(isolate, "none");
}
}
};
// static
v8::Local<v8::Value> Converter<content::MenuItem::Type>::ToV8(
@ -100,7 +119,7 @@ v8::Local<v8::Value> Converter<ContextMenuParamsWithWebContents>::ToV8(
v8::Isolate* isolate,
const ContextMenuParamsWithWebContents& val) {
const auto& params = val.first;
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.Set("x", params.x);
dict.Set("y", params.y);
dict.Set("linkURL", params.link_url);
@ -109,13 +128,13 @@ v8::Local<v8::Value> Converter<ContextMenuParamsWithWebContents>::ToV8(
dict.Set("frameURL", params.frame_url);
dict.Set("srcURL", params.src_url);
dict.Set("mediaType", params.media_type);
dict.Set("mediaFlags", MediaFlagsToV8(isolate, params.media_flags));
dict.Set("mediaFlags", mate::MediaFlagsToV8(isolate, params.media_flags));
bool has_image_contents =
(params.media_type == blink::WebContextMenuData::kMediaTypeImage) &&
params.has_image_contents;
dict.Set("hasImageContents", has_image_contents);
dict.Set("isEditable", params.is_editable);
dict.Set("editFlags", EditFlagsToV8(isolate, params.edit_flags));
dict.Set("editFlags", mate::EditFlagsToV8(isolate, params.edit_flags));
dict.Set("selectionText", params.selection_text);
dict.Set("titleText", params.title_text);
dict.Set("misspelledWord", params.misspelled_word);
@ -126,7 +145,7 @@ v8::Local<v8::Value> Converter<ContextMenuParamsWithWebContents>::ToV8(
if (params.custom_context.is_pepper_menu)
dict.Set("menu", MenuToV8(isolate, val.second, params.custom_context,
params.custom_items));
return mate::ConvertToV8(isolate, dict);
return gin::ConvertToV8(isolate, dict);
}
// static
@ -215,7 +234,7 @@ bool Converter<content::WebContents*>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
content::WebContents** out) {
electron::api::WebContents* web_contents = nullptr;
if (!ConvertFromV8(isolate, val, &web_contents) || !web_contents)
if (!gin::ConvertFromV8(isolate, val, &web_contents) || !web_contents)
return false;
*out = web_contents->web_contents();
@ -226,17 +245,17 @@ bool Converter<content::WebContents*>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> Converter<content::Referrer>::ToV8(
v8::Isolate* isolate,
const content::Referrer& val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
dict.Set("url", ConvertToV8(isolate, val.url));
dict.Set("policy", ConvertToV8(isolate, val.policy));
return mate::ConvertToV8(isolate, dict);
return gin::ConvertToV8(isolate, dict);
}
// static
bool Converter<content::Referrer>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
content::Referrer* out) {
mate::Dictionary dict;
gin_helper::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
@ -249,4 +268,42 @@ bool Converter<content::Referrer>::FromV8(v8::Isolate* isolate,
return true;
}
} // namespace mate
// static
bool Converter<content::NativeWebKeyboardEvent>::FromV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val,
content::NativeWebKeyboardEvent* out) {
gin_helper::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (!ConvertFromV8(isolate, val, static_cast<blink::WebKeyboardEvent*>(out)))
return false;
dict.Get("skipInBrowser", &out->skip_in_browser);
return true;
}
// static
v8::Local<v8::Value> Converter<content::NativeWebKeyboardEvent>::ToV8(
v8::Isolate* isolate,
const content::NativeWebKeyboardEvent& in) {
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
if (in.GetType() == blink::WebInputEvent::Type::kRawKeyDown)
dict.Set("type", "keyDown");
else if (in.GetType() == blink::WebInputEvent::Type::kKeyUp)
dict.Set("type", "keyUp");
dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.dom_key));
dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString(
static_cast<ui::DomCode>(in.dom_code)));
using Modifiers = blink::WebInputEvent::Modifiers;
dict.Set("isAutoRepeat", (in.GetModifiers() & Modifiers::kIsAutoRepeat) != 0);
dict.Set("shift", (in.GetModifiers() & Modifiers::kShiftKey) != 0);
dict.Set("control", (in.GetModifiers() & Modifiers::kControlKey) != 0);
dict.Set("alt", (in.GetModifiers() & Modifiers::kAltKey) != 0);
dict.Set("meta", (in.GetModifiers() & Modifiers::kMetaKey) != 0);
return dict.GetHandle();
}
} // namespace gin

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_CONTENT_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_CONTENT_CONVERTER_H_
#ifndef SHELL_COMMON_GIN_CONVERTERS_CONTENT_CONVERTER_H_
#define SHELL_COMMON_GIN_CONVERTERS_CONTENT_CONVERTER_H_
#include <utility>
@ -11,18 +11,19 @@
#include "content/public/common/menu_item.h"
#include "content/public/common/referrer.h"
#include "content/public/common/stop_find_action.h"
#include "native_mate/converter.h"
#include "gin/converter.h"
#include "third_party/blink/public/mojom/permissions/permission_status.mojom.h"
namespace content {
struct ContextMenuParams;
struct NativeWebKeyboardEvent;
class WebContents;
} // namespace content
using ContextMenuParamsWithWebContents =
std::pair<content::ContextMenuParams, content::WebContents*>;
namespace mate {
namespace gin {
template <>
struct Converter<content::MenuItem::Type> {
@ -74,6 +75,15 @@ struct Converter<content::Referrer> {
content::Referrer* out);
};
} // namespace mate
template <>
struct Converter<content::NativeWebKeyboardEvent> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
content::NativeWebKeyboardEvent* out);
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const content::NativeWebKeyboardEvent& in);
};
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_CONTENT_CONVERTER_H_
} // namespace gin
#endif // SHELL_COMMON_GIN_CONVERTERS_CONTENT_CONVERTER_H_

View file

@ -27,9 +27,8 @@ bool Converter<gfx::Image>::FromV8(v8::Isolate* isolate,
if (val->IsNull())
return true;
// TODO(deermichel): remove mate:: after dropping mate
mate::Handle<electron::api::NativeImage> native_image;
if (!mate::ConvertFromV8(isolate, val, &native_image))
gin::Handle<electron::api::NativeImage> native_image;
if (!gin::ConvertFromV8(isolate, val, &native_image))
return false;
*out = native_image->image();
@ -38,7 +37,8 @@ bool Converter<gfx::Image>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> Converter<gfx::Image>::ToV8(v8::Isolate* isolate,
const gfx::Image& val) {
return ConvertToV8(isolate, electron::api::NativeImage::Create(isolate, val));
return gin::ConvertToV8(isolate,
electron::api::NativeImage::Create(isolate, val));
}
} // namespace gin

View file

@ -285,6 +285,58 @@ v8::Local<v8::Value> Converter<network::ResourceRequestBody>::ToV8(
return arr;
}
// static
v8::Local<v8::Value>
Converter<scoped_refptr<network::ResourceRequestBody>>::ToV8(
v8::Isolate* isolate,
const scoped_refptr<network::ResourceRequestBody>& val) {
if (!val)
return v8::Null(isolate);
return ConvertToV8(isolate, *val);
}
// static
bool Converter<scoped_refptr<network::ResourceRequestBody>>::FromV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val,
scoped_refptr<network::ResourceRequestBody>* out) {
auto list = std::make_unique<base::ListValue>();
if (!ConvertFromV8(isolate, val, list.get()))
return false;
*out = new network::ResourceRequestBody();
for (size_t i = 0; i < list->GetSize(); ++i) {
base::DictionaryValue* dict = nullptr;
std::string type;
if (!list->GetDictionary(i, &dict))
return false;
dict->GetString("type", &type);
if (type == "rawData") {
base::Value* bytes = nullptr;
dict->GetBinary("bytes", &bytes);
(*out)->AppendBytes(
reinterpret_cast<const char*>(bytes->GetBlob().data()),
base::checked_cast<int>(bytes->GetBlob().size()));
} else if (type == "file") {
std::string file;
int offset = 0, length = -1;
double modification_time = 0.0;
dict->GetStringWithoutPathExpansion("filePath", &file);
dict->GetInteger("offset", &offset);
dict->GetInteger("file", &length);
dict->GetDouble("modificationTime", &modification_time);
(*out)->AppendFileRange(base::FilePath::FromUTF8Unsafe(file),
static_cast<uint64_t>(offset),
static_cast<uint64_t>(length),
base::Time::FromDoubleT(modification_time));
} else if (type == "blob") {
std::string uuid;
dict->GetString("blobUUID", &uuid);
(*out)->AppendBlob(uuid);
}
}
return true;
}
// static
v8::Local<v8::Value> Converter<network::ResourceRequest>::ToV8(
v8::Isolate* isolate,

View file

@ -75,6 +75,16 @@ struct Converter<network::ResourceRequestBody> {
const network::ResourceRequestBody& val);
};
template <>
struct Converter<scoped_refptr<network::ResourceRequestBody>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const scoped_refptr<network::ResourceRequestBody>& val);
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
scoped_refptr<network::ResourceRequestBody>* out);
};
template <>
struct Converter<network::ResourceRequest> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,

View file

@ -39,6 +39,13 @@ struct Converter<unsigned long> { // NOLINT(runtime/int)
};
#endif
template <>
struct Converter<std::nullptr_t> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, std::nullptr_t val) {
return v8::Null(isolate);
}
};
template <>
struct Converter<const char*> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, const char* val) {

View file

@ -4,6 +4,8 @@
#include "shell/common/gin_helper/event_emitter.h"
#include "content/public/browser/render_frame_host.h"
#include "shell/browser/api/event.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "ui/events/event_constants.h"
@ -62,6 +64,30 @@ v8::Local<v8::Object> CreateEventFromFlags(v8::Isolate* isolate, int flags) {
return obj.GetHandle();
}
v8::Local<v8::Object> CreateNativeEvent(
v8::Isolate* isolate,
v8::Local<v8::Object> sender,
content::RenderFrameHost* frame,
base::Optional<electron::mojom::ElectronBrowser::MessageSyncCallback>
callback) {
v8::Local<v8::Object> event;
if (frame && callback) {
mate::Handle<mate::Event> native_event = mate::Event::Create(isolate);
native_event->SetCallback(std::move(callback));
event = v8::Local<v8::Object>::Cast(native_event.ToV8());
} else {
// No need to create native event if we do not need to send reply.
event = CreateEvent(isolate);
}
Dictionary dict(isolate, event);
dict.Set("sender", sender);
// Should always set frameId even when callback is null.
if (frame)
dict.Set("frameId", frame->GetRoutingID());
return event;
}
} // namespace internal
} // namespace gin_helper

View file

@ -9,9 +9,15 @@
#include <vector>
#include "base/optional.h"
#include "content/public/browser/browser_thread.h"
#include "electron/shell/common/api/api.mojom.h"
#include "native_mate/wrappable.h"
#include "shell/common/gin_helper/event_emitter_caller.h"
namespace content {
class RenderFrameHost;
}
namespace gin_helper {
namespace internal {
@ -21,16 +27,21 @@ v8::Local<v8::Object> CreateEvent(
v8::Local<v8::Object> sender = v8::Local<v8::Object>(),
v8::Local<v8::Object> custom_event = v8::Local<v8::Object>());
v8::Local<v8::Object> CreateEventFromFlags(v8::Isolate* isolate, int flags);
v8::Local<v8::Object> CreateNativeEvent(
v8::Isolate* isolate,
v8::Local<v8::Object> sender,
content::RenderFrameHost* frame,
base::Optional<electron::mojom::ElectronBrowser::MessageSyncCallback>
callback);
} // namespace internal
// Provide helperers to emit event in JavaScript.
//
// TODO(zcbenz): Inherit from Wrappable directly after removing native_mate.
template <typename Base>
class EventEmitter : public Base {
template <typename T>
class EventEmitter : public mate::Wrappable<T> {
public:
typedef std::vector<v8::Local<v8::Value>> ValueArray;
using Base = mate::Wrappable<T>;
using ValueArray = std::vector<v8::Local<v8::Value>>;
// Make the convinient methods visible:
// https://isocpp.org/wiki/faq/templates#nondependent-name-lookup-members
@ -64,13 +75,30 @@ class EventEmitter : public Base {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
v8::Local<v8::Object> wrapper = GetWrapper();
if (wrapper.IsEmpty()) {
if (wrapper.IsEmpty())
return false;
}
v8::Local<v8::Object> event = internal::CreateEvent(isolate(), wrapper);
return EmitWithEvent(name, event, std::forward<Args>(args)...);
}
// this.emit(name, new Event(sender, message), args...);
template <typename... Args>
bool EmitWithSender(
base::StringPiece name,
content::RenderFrameHost* sender,
base::Optional<electron::mojom::ElectronBrowser::InvokeCallback> callback,
Args&&... args) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
v8::Local<v8::Object> wrapper = GetWrapper();
if (wrapper.IsEmpty())
return false;
v8::Local<v8::Object> event = internal::CreateNativeEvent(
isolate(), wrapper, sender, std::move(callback));
return EmitWithEvent(name, event, std::forward<Args>(args)...);
}
protected:
EventEmitter() {}

View file

@ -2,15 +2,16 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/api/trackable_object.h"
#include "shell/common/gin_helper/trackable_object.h"
#include <memory>
#include "base/bind.h"
#include "base/supports_user_data.h"
#include "shell/browser/atom_browser_main_parts.h"
#include "shell/common/api/locker.h"
namespace mate {
namespace gin_helper {
namespace {
@ -31,6 +32,10 @@ class IDUserData : public base::SupportsUserData::Data {
} // namespace
TrackableObjectBase::TrackableObjectBase() : weak_factory_(this) {
// TODO(zcbenz): Make TrackedObject work in renderer process.
DCHECK(mate::Locker::IsBrowserProcess())
<< "This class only works for browser process";
electron::AtomBrowserMainParts::Get()->RegisterDestructionCallback(
GetDestroyClosure());
}
@ -63,4 +68,4 @@ int32_t TrackableObjectBase::GetIDFromWrappedClass(
return 0;
}
} // namespace mate
} // namespace gin_helper

View file

@ -2,22 +2,21 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_TRACKABLE_OBJECT_H_
#define SHELL_BROWSER_API_TRACKABLE_OBJECT_H_
#ifndef SHELL_COMMON_GIN_HELPER_TRACKABLE_OBJECT_H_
#define SHELL_COMMON_GIN_HELPER_TRACKABLE_OBJECT_H_
#include <vector>
#include "base/bind.h"
#include "base/memory/weak_ptr.h"
#include "native_mate/object_template_builder_deprecated.h"
#include "shell/browser/api/event_emitter_deprecated.h"
#include "shell/common/gin_helper/event_emitter.h"
#include "shell/common/key_weak_map.h"
namespace base {
class SupportsUserData;
}
namespace mate {
namespace gin_helper {
// Users should use TrackableObject instead.
class TrackableObjectBase {
@ -51,21 +50,19 @@ class TrackableObjectBase {
// All instances of TrackableObject will be kept in a weak map and can be got
// from its ID.
//
// TODO(zcbenz): Remove "typename B" after removing native_mate.
template <typename T, typename B = mate::EventEmitter<T>>
class TrackableObject : public TrackableObjectBase, public B {
template <typename T>
class TrackableObject : public TrackableObjectBase, public EventEmitter<T> {
public:
// Mark the JS object as destroyed.
void MarkDestroyed() {
v8::Local<v8::Object> wrapper = Wrappable<T>::GetWrapper();
v8::Local<v8::Object> wrapper = mate::Wrappable<T>::GetWrapper();
if (!wrapper.IsEmpty()) {
wrapper->SetAlignedPointerInInternalField(0, nullptr);
}
}
bool IsDestroyed() {
v8::Local<v8::Object> wrapper = Wrappable<T>::GetWrapper();
v8::Local<v8::Object> wrapper = mate::Wrappable<T>::GetWrapper();
return wrapper->InternalFieldCount() == 0 ||
wrapper->GetAlignedPointerFromInternalField(0) == nullptr;
}
@ -80,7 +77,7 @@ class TrackableObject : public TrackableObjectBase, public B {
return nullptr;
T* self = nullptr;
mate::ConvertFromV8(isolate, object.ToLocalChecked(), &self);
gin::ConvertFromV8(isolate, object.ToLocalChecked(), &self);
return self;
}
@ -113,7 +110,7 @@ class TrackableObject : public TrackableObjectBase, public B {
~TrackableObject() override { RemoveFromWeakMap(); }
void InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) override {
WrappableBase::InitWith(isolate, wrapper);
mate::WrappableBase::InitWith(isolate, wrapper);
if (!weak_map_) {
weak_map_ = new electron::KeyWeakMap<int32_t>;
}
@ -127,12 +124,12 @@ class TrackableObject : public TrackableObjectBase, public B {
DISALLOW_COPY_AND_ASSIGN(TrackableObject);
};
template <typename T, typename B>
int32_t TrackableObject<T, B>::next_id_ = 0;
template <typename T>
int32_t TrackableObject<T>::next_id_ = 0;
template <typename T, typename B>
electron::KeyWeakMap<int32_t>* TrackableObject<T, B>::weak_map_ = nullptr;
template <typename T>
electron::KeyWeakMap<int32_t>* TrackableObject<T>::weak_map_ = nullptr;
} // namespace mate
} // namespace gin_helper
#endif // SHELL_BROWSER_API_TRACKABLE_OBJECT_H_
#endif // SHELL_COMMON_GIN_HELPER_TRACKABLE_OBJECT_H_

View file

@ -11,7 +11,6 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "gin/converter.h"
#include "mojo/public/cpp/base/values_mojom_traits.h"
#include "mojo/public/mojom/base/values.mojom.h"
@ -20,6 +19,7 @@
#include "shell/common/keyboard_util.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "third_party/blink/public/platform/web_input_event.h"
#include "third_party/blink/public/platform/web_keyboard_event.h"
#include "third_party/blink/public/platform/web_mouse_event.h"
#include "third_party/blink/public/platform/web_mouse_wheel_event.h"
#include "third_party/blink/public/web/web_device_emulation_params.h"
@ -216,42 +216,6 @@ bool Converter<blink::WebKeyboardEvent>::FromV8(v8::Isolate* isolate,
return true;
}
bool Converter<content::NativeWebKeyboardEvent>::FromV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val,
content::NativeWebKeyboardEvent* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (!ConvertFromV8(isolate, val, static_cast<blink::WebKeyboardEvent*>(out)))
return false;
dict.Get("skipInBrowser", &out->skip_in_browser);
return true;
}
v8::Local<v8::Value> Converter<content::NativeWebKeyboardEvent>::ToV8(
v8::Isolate* isolate,
const content::NativeWebKeyboardEvent& in) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
if (in.GetType() == blink::WebInputEvent::Type::kRawKeyDown)
dict.Set("type", "keyDown");
else if (in.GetType() == blink::WebInputEvent::Type::kKeyUp)
dict.Set("type", "keyUp");
dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.dom_key));
dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString(
static_cast<ui::DomCode>(in.dom_code)));
using Modifiers = blink::WebInputEvent::Modifiers;
dict.Set("isAutoRepeat", (in.GetModifiers() & Modifiers::kIsAutoRepeat) != 0);
dict.Set("shift", (in.GetModifiers() & Modifiers::kShiftKey) != 0);
dict.Set("control", (in.GetModifiers() & Modifiers::kControlKey) != 0);
dict.Set("alt", (in.GetModifiers() & Modifiers::kAltKey) != 0);
dict.Set("meta", (in.GetModifiers() & Modifiers::kMetaKey) != 0);
return dict.GetHandle();
}
bool Converter<blink::WebMouseEvent>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
blink::WebMouseEvent* out) {

View file

@ -21,10 +21,6 @@ struct WebPoint;
struct WebSize;
} // namespace blink
namespace content {
struct NativeWebKeyboardEvent;
}
namespace mate {
blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate,
@ -44,15 +40,6 @@ struct Converter<blink::WebKeyboardEvent> {
blink::WebKeyboardEvent* out);
};
template <>
struct Converter<content::NativeWebKeyboardEvent> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
content::NativeWebKeyboardEvent* out);
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const content::NativeWebKeyboardEvent& in);
};
template <>
struct Converter<blink::WebMouseEvent> {
static bool FromV8(v8::Isolate* isolate,

View file

@ -1,94 +0,0 @@
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/common/native_mate_converters/network_converter.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/numerics/safe_conversions.h"
#include "native_mate/dictionary.h"
#include "services/network/public/cpp/resource_request_body.h"
#include "shell/common/native_mate_converters/value_converter.h"
namespace mate {
// static
v8::Local<v8::Value>
Converter<scoped_refptr<network::ResourceRequestBody>>::ToV8(
v8::Isolate* isolate,
const scoped_refptr<network::ResourceRequestBody>& val) {
if (!val)
return v8::Null(isolate);
auto list = std::make_unique<base::ListValue>();
for (const auto& element : *(val->elements())) {
auto post_data_dict = std::make_unique<base::DictionaryValue>();
auto type = element.type();
if (type == network::mojom::DataElementType::kBytes) {
auto bytes = std::make_unique<base::Value>(std::vector<char>(
element.bytes(), element.bytes() + (element.length())));
post_data_dict->SetString("type", "rawData");
post_data_dict->Set("bytes", std::move(bytes));
} else if (type == network::mojom::DataElementType::kFile) {
post_data_dict->SetString("type", "file");
post_data_dict->SetKey("filePath",
base::Value(element.path().AsUTF8Unsafe()));
post_data_dict->SetInteger("offset", static_cast<int>(element.offset()));
post_data_dict->SetInteger("length", static_cast<int>(element.length()));
post_data_dict->SetDouble(
"modificationTime", element.expected_modification_time().ToDoubleT());
} else if (type == network::mojom::DataElementType::kBlob) {
post_data_dict->SetString("type", "blob");
post_data_dict->SetString("blobUUID", element.blob_uuid());
}
list->Append(std::move(post_data_dict));
}
return ConvertToV8(isolate, *list);
}
// static
bool Converter<scoped_refptr<network::ResourceRequestBody>>::FromV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val,
scoped_refptr<network::ResourceRequestBody>* out) {
auto list = std::make_unique<base::ListValue>();
if (!ConvertFromV8(isolate, val, list.get()))
return false;
*out = new network::ResourceRequestBody();
for (size_t i = 0; i < list->GetSize(); ++i) {
base::DictionaryValue* dict = nullptr;
std::string type;
if (!list->GetDictionary(i, &dict))
return false;
dict->GetString("type", &type);
if (type == "rawData") {
base::Value* bytes = nullptr;
dict->GetBinary("bytes", &bytes);
(*out)->AppendBytes(
reinterpret_cast<const char*>(bytes->GetBlob().data()),
base::checked_cast<int>(bytes->GetBlob().size()));
} else if (type == "file") {
std::string file;
int offset = 0, length = -1;
double modification_time = 0.0;
dict->GetStringWithoutPathExpansion("filePath", &file);
dict->GetInteger("offset", &offset);
dict->GetInteger("file", &length);
dict->GetDouble("modificationTime", &modification_time);
(*out)->AppendFileRange(base::FilePath::FromUTF8Unsafe(file),
static_cast<uint64_t>(offset),
static_cast<uint64_t>(length),
base::Time::FromDoubleT(modification_time));
} else if (type == "blob") {
std::string uuid;
dict->GetString("blobUUID", &uuid);
(*out)->AppendBlob(uuid);
}
}
return true;
}
} // namespace mate

View file

@ -1,29 +0,0 @@
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_NETWORK_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_NETWORK_CONVERTER_H_
#include "base/memory/scoped_refptr.h"
#include "native_mate/converter.h"
namespace network {
class ResourceRequestBody;
}
namespace mate {
template <>
struct Converter<scoped_refptr<network::ResourceRequestBody>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
const scoped_refptr<network::ResourceRequestBody>& val);
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
scoped_refptr<network::ResourceRequestBody>* out);
};
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_NETWORK_CONVERTER_H_

View file

@ -1,34 +0,0 @@
// Copyright (c) 2016 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_COMMON_NATIVE_MATE_CONVERTERS_UI_BASE_TYPES_CONVERTER_H_
#define SHELL_COMMON_NATIVE_MATE_CONVERTERS_UI_BASE_TYPES_CONVERTER_H_
#include "native_mate/converter.h"
#include "ui/base/ui_base_types.h"
namespace mate {
template <>
struct Converter<ui::MenuSourceType> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const ui::MenuSourceType& in) {
switch (in) {
case ui::MENU_SOURCE_MOUSE:
return mate::StringToV8(isolate, "mouse");
case ui::MENU_SOURCE_KEYBOARD:
return mate::StringToV8(isolate, "keyboard");
case ui::MENU_SOURCE_TOUCH:
return mate::StringToV8(isolate, "touch");
case ui::MENU_SOURCE_TOUCH_EDIT_MENU:
return mate::StringToV8(isolate, "touchMenu");
default:
return mate::StringToV8(isolate, "none");
}
}
};
} // namespace mate
#endif // SHELL_COMMON_NATIVE_MATE_CONVERTERS_UI_BASE_TYPES_CONVERTER_H_

View file

@ -689,13 +689,11 @@ describe('webContents module', () => {
expect(() => {
w.webContents.startDrag({ file: __filename } as any)
}).to.throw(`Must specify 'icon' option`)
}).to.throw(`Must specify non-empty 'icon' option`)
if (process.platform === 'darwin') {
expect(() => {
w.webContents.startDrag({ file: __filename, icon: __filename })
}).to.throw(`Must specify non-empty 'icon' option`)
}
expect(() => {
w.webContents.startDrag({ file: __filename, icon: __filename })
}).to.throw(`Must specify non-empty 'icon' option`)
})
})