chore: remove native_mate (Part 12) (#20869)

* refactor: move mate::Event to gin

* refactor: move mate::Locker to gin

* refactor: convert contextBridge to gin

* refactor: convert contentTracing to gin

* refactor: remove callback converter of native_mate

* refactor: remove file_dialog_converter and native_window_converter from native_mate

* refactor: convert webFrame to gin

* refactor: move blink_converter to gin

* refactor: remove net_converter from native_mate

* refactor: remove event_emitter_caller_deprecated

* refactor: remove gurl_converter from native_mate

* refactor: remove file_path and string16_converter from native_mate

* refactor: remove image_converter from native_mate

* refactor: move value_converter to gin
This commit is contained in:
Cheng Zhao 2019-10-31 16:56:00 +09:00 committed by GitHub
parent 6781d5e3c8
commit 3ae3233e65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
96 changed files with 622 additions and 1711 deletions

View file

@ -25,9 +25,6 @@ source_set("native_mate") {
"native_mate/handle.h",
"native_mate/object_template_builder.cc",
"native_mate/object_template_builder_deprecated.h",
"native_mate/persistent_dictionary.cc",
"native_mate/persistent_dictionary.h",
"native_mate/scoped_persistent.h",
"native_mate/wrappable.cc",
"native_mate/wrappable.h",
"native_mate/wrappable_base.h",

View file

@ -40,12 +40,6 @@ class Dictionary {
static Dictionary CreateEmpty(v8::Isolate* isolate);
bool Has(base::StringPiece key) const {
v8::Local<v8::Context> context = isolate_->GetCurrentContext();
v8::Local<v8::String> v8_key = StringToV8(isolate_, key);
return internal::IsTrue(GetHandle()->Has(context, v8_key));
}
template <typename T>
bool Get(base::StringPiece key, T* out) const {
// Check for existence before getting, otherwise this method will always
@ -82,17 +76,6 @@ class Dictionary {
return !result.IsNothing() && result.FromJust();
}
template <typename T>
bool SetReadOnlyNonConfigurable(base::StringPiece key, T val) {
v8::Local<v8::Value> v8_value;
if (!TryConvertToV8(isolate_, val, &v8_value))
return false;
v8::Maybe<bool> result = GetHandle()->DefineOwnProperty(
isolate_->GetCurrentContext(), StringToV8(isolate_, key), v8_value,
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
return !result.IsNothing() && result.FromJust();
}
template <typename T>
bool SetMethod(base::StringPiece key, const T& callback) {
return GetHandle()

View file

@ -1,35 +0,0 @@
// Copyright 2014 Cheng Zhao. All rights reserved.
// Use of this source code is governed by MIT license that can be found in the
// LICENSE file.
#include "native_mate/persistent_dictionary.h"
namespace mate {
PersistentDictionary::PersistentDictionary() = default;
PersistentDictionary::PersistentDictionary(v8::Isolate* isolate,
v8::Local<v8::Object> object)
: handle_(new RefCountedPersistent<v8::Object>(isolate, object)) {
isolate_ = isolate;
}
PersistentDictionary::PersistentDictionary(const PersistentDictionary& other) =
default;
PersistentDictionary::~PersistentDictionary() = default;
v8::Local<v8::Object> PersistentDictionary::GetHandle() const {
return handle_->NewHandle();
}
bool Converter<PersistentDictionary>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
PersistentDictionary* out) {
if (!val->IsObject())
return false;
*out = PersistentDictionary(isolate, v8::Local<v8::Object>::Cast(val));
return true;
}
} // namespace mate

View file

@ -1,51 +0,0 @@
// Copyright 2014 Cheng Zhao. All rights reserved.
// Use of this source code is governed by MIT license that can be found in the
// LICENSE file.
#ifndef NATIVE_MATE_NATIVE_MATE_PERSISTENT_DICTIONARY_H_
#define NATIVE_MATE_NATIVE_MATE_PERSISTENT_DICTIONARY_H_
#include "native_mate/dictionary.h"
#include "native_mate/scoped_persistent.h"
namespace mate {
// Like Dictionary, but stores object in persistent handle so you can keep it
// safely on heap.
class PersistentDictionary : public Dictionary {
public:
PersistentDictionary();
PersistentDictionary(v8::Isolate* isolate, v8::Local<v8::Object> object);
PersistentDictionary(const PersistentDictionary& other);
~PersistentDictionary() override;
v8::Local<v8::Object> GetHandle() const override;
private:
scoped_refptr<RefCountedPersistent<v8::Object>> handle_;
};
template <>
struct Converter<PersistentDictionary> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
PersistentDictionary* out);
};
} // namespace mate
namespace gin {
// Keep compatibility with gin.
template <>
struct Converter<mate::PersistentDictionary> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
mate::PersistentDictionary* out) {
return mate::ConvertFromV8(isolate, val, out);
}
};
} // namespace gin
#endif // NATIVE_MATE_NATIVE_MATE_PERSISTENT_DICTIONARY_H_

View file

@ -1,102 +0,0 @@
// Copyright 2014 Cheng Zhao. All rights reserved.
// Use of this source code is governed by MIT license that can be found in the
// LICENSE file.
#ifndef NATIVE_MATE_NATIVE_MATE_SCOPED_PERSISTENT_H_
#define NATIVE_MATE_NATIVE_MATE_SCOPED_PERSISTENT_H_
#include "base/memory/ref_counted.h"
#include "native_mate/converter.h"
#include "v8/include/v8.h"
namespace mate {
// A v8::Persistent handle to a V8 value which destroys and clears the
// underlying handle on destruction.
template <typename T>
class ScopedPersistent {
public:
ScopedPersistent() : isolate_(v8::Isolate::GetCurrent()) {}
ScopedPersistent(v8::Isolate* isolate, v8::Local<v8::Value> handle)
: isolate_(isolate) {
reset(isolate, v8::Local<T>::Cast(handle));
}
~ScopedPersistent() { reset(); }
void reset(v8::Isolate* isolate, v8::Local<T> handle) {
if (!handle.IsEmpty()) {
isolate_ = isolate;
handle_.Reset(isolate, handle);
} else {
reset();
}
}
void reset() { handle_.Reset(); }
bool IsEmpty() const { return handle_.IsEmpty(); }
v8::Local<T> NewHandle() const { return NewHandle(isolate_); }
v8::Local<T> NewHandle(v8::Isolate* isolate) const {
if (handle_.IsEmpty())
return v8::Local<T>();
return v8::Local<T>::New(isolate, handle_);
}
template <typename P, typename C>
void SetWeak(P* parameter, C callback) {
handle_.SetWeak(parameter, callback);
}
v8::Isolate* isolate() const { return isolate_; }
private:
v8::Isolate* isolate_ = nullptr;
v8::Persistent<T> handle_;
DISALLOW_COPY_AND_ASSIGN(ScopedPersistent);
};
template <typename T>
class RefCountedPersistent : public ScopedPersistent<T>,
public base::RefCounted<RefCountedPersistent<T>> {
public:
RefCountedPersistent() = default;
RefCountedPersistent(v8::Isolate* isolate, v8::Local<v8::Value> handle)
: ScopedPersistent<T>(isolate, handle) {}
protected:
friend class base::RefCounted<RefCountedPersistent<T>>;
~RefCountedPersistent() = default;
private:
DISALLOW_COPY_AND_ASSIGN(RefCountedPersistent);
};
template <typename T>
struct Converter<ScopedPersistent<T>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const ScopedPersistent<T>& val) {
return val.NewHandle(isolate);
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
ScopedPersistent<T>* out) {
v8::Local<T> converted;
if (!Converter<v8::Local<T>>::FromV8(isolate, val, &converted))
return false;
out->reset(isolate, converted);
return true;
}
};
} // namespace mate
#endif // NATIVE_MATE_NATIVE_MATE_SCOPED_PERSISTENT_H_