refactor: native_mate => gin (cookies API) (#18036)
* convert cookie converters to gin * event_emitter GetWrapper
This commit is contained in:
parent
e9d88e965e
commit
fdf5f838f4
5 changed files with 36 additions and 21 deletions
|
@ -18,8 +18,8 @@
|
||||||
#include "content/public/browser/browser_task_traits.h"
|
#include "content/public/browser/browser_task_traits.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/storage_partition.h"
|
#include "content/public/browser/storage_partition.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "gin/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "gin/object_template_builder.h"
|
||||||
#include "net/cookies/canonical_cookie.h"
|
#include "net/cookies/canonical_cookie.h"
|
||||||
#include "net/cookies/cookie_store.h"
|
#include "net/cookies/cookie_store.h"
|
||||||
#include "net/cookies/cookie_util.h"
|
#include "net/cookies/cookie_util.h"
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
|
|
||||||
namespace mate {
|
namespace gin {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<atom::api::Cookies::Error> {
|
struct Converter<atom::api::Cookies::Error> {
|
||||||
|
@ -45,7 +45,7 @@ template <>
|
||||||
struct Converter<net::CanonicalCookie> {
|
struct Converter<net::CanonicalCookie> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
const net::CanonicalCookie& val) {
|
const net::CanonicalCookie& val) {
|
||||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
gin::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||||
dict.Set("name", val.Name());
|
dict.Set("name", val.Name());
|
||||||
dict.Set("value", val.Value());
|
dict.Set("value", val.Value());
|
||||||
dict.Set("domain", val.Domain());
|
dict.Set("domain", val.Domain());
|
||||||
|
@ -56,7 +56,7 @@ struct Converter<net::CanonicalCookie> {
|
||||||
dict.Set("session", !val.IsPersistent());
|
dict.Set("session", !val.IsPersistent());
|
||||||
if (val.IsPersistent())
|
if (val.IsPersistent())
|
||||||
dict.Set("expirationDate", val.ExpiryDate().ToDoubleT());
|
dict.Set("expirationDate", val.ExpiryDate().ToDoubleT());
|
||||||
return dict.GetHandle();
|
return ConvertToV8(isolate, dict).As<v8::Object>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,22 +68,22 @@ struct Converter<network::mojom::CookieChangeCause> {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case network::mojom::CookieChangeCause::INSERTED:
|
case network::mojom::CookieChangeCause::INSERTED:
|
||||||
case network::mojom::CookieChangeCause::EXPLICIT:
|
case network::mojom::CookieChangeCause::EXPLICIT:
|
||||||
return mate::StringToV8(isolate, "explicit");
|
return gin::StringToV8(isolate, "explicit");
|
||||||
case network::mojom::CookieChangeCause::OVERWRITE:
|
case network::mojom::CookieChangeCause::OVERWRITE:
|
||||||
return mate::StringToV8(isolate, "overwrite");
|
return gin::StringToV8(isolate, "overwrite");
|
||||||
case network::mojom::CookieChangeCause::EXPIRED:
|
case network::mojom::CookieChangeCause::EXPIRED:
|
||||||
return mate::StringToV8(isolate, "expired");
|
return gin::StringToV8(isolate, "expired");
|
||||||
case network::mojom::CookieChangeCause::EVICTED:
|
case network::mojom::CookieChangeCause::EVICTED:
|
||||||
return mate::StringToV8(isolate, "evicted");
|
return gin::StringToV8(isolate, "evicted");
|
||||||
case network::mojom::CookieChangeCause::EXPIRED_OVERWRITE:
|
case network::mojom::CookieChangeCause::EXPIRED_OVERWRITE:
|
||||||
return mate::StringToV8(isolate, "expired-overwrite");
|
return gin::StringToV8(isolate, "expired-overwrite");
|
||||||
default:
|
default:
|
||||||
return mate::StringToV8(isolate, "unknown");
|
return gin::StringToV8(isolate, "unknown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace gin
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ void FilterCookies(const base::Value& filter,
|
||||||
result.push_back(cookie);
|
result.push_back(cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.Resolve(result);
|
promise.Resolve(gin::ConvertToV8(promise.isolate(), result));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string InclusionStatusToString(
|
std::string InclusionStatusToString(
|
||||||
|
@ -330,19 +330,21 @@ v8::Local<v8::Promise> Cookies::FlushStore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cookies::OnCookieChanged(const CookieDetails* details) {
|
void Cookies::OnCookieChanged(const CookieDetails* details) {
|
||||||
Emit("changed", *(details->cookie), details->cause, details->removed);
|
Emit("changed", gin::ConvertToV8(isolate(), *(details->cookie)),
|
||||||
|
gin::ConvertToV8(isolate(), details->cause),
|
||||||
|
gin::ConvertToV8(isolate(), details->removed));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<Cookies> Cookies::Create(v8::Isolate* isolate,
|
gin::Handle<Cookies> Cookies::Create(v8::Isolate* isolate,
|
||||||
AtomBrowserContext* browser_context) {
|
AtomBrowserContext* browser_context) {
|
||||||
return mate::CreateHandle(isolate, new Cookies(isolate, browser_context));
|
return gin::CreateHandle(isolate, new Cookies(isolate, browser_context));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Cookies::BuildPrototype(v8::Isolate* isolate,
|
void Cookies::BuildPrototype(v8::Isolate* isolate,
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
v8::Local<v8::FunctionTemplate> prototype) {
|
||||||
prototype->SetClassName(mate::StringToV8(isolate, "Cookies"));
|
prototype->SetClassName(gin::StringToV8(isolate, "Cookies"));
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||||
.SetMethod("get", &Cookies::Get)
|
.SetMethod("get", &Cookies::Get)
|
||||||
.SetMethod("remove", &Cookies::Remove)
|
.SetMethod("remove", &Cookies::Remove)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "atom/browser/net/cookie_details.h"
|
#include "atom/browser/net/cookie_details.h"
|
||||||
#include "atom/common/promise_util.h"
|
#include "atom/common/promise_util.h"
|
||||||
#include "base/callback_list.h"
|
#include "base/callback_list.h"
|
||||||
#include "native_mate/handle.h"
|
#include "gin/handle.h"
|
||||||
#include "net/cookies/canonical_cookie.h"
|
#include "net/cookies/canonical_cookie.h"
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
|
@ -36,7 +36,7 @@ class Cookies : public mate::TrackableObject<Cookies> {
|
||||||
FAILED,
|
FAILED,
|
||||||
};
|
};
|
||||||
|
|
||||||
static mate::Handle<Cookies> Create(v8::Isolate* isolate,
|
static gin::Handle<Cookies> Create(v8::Isolate* isolate,
|
||||||
AtomBrowserContext* browser_context);
|
AtomBrowserContext* browser_context);
|
||||||
|
|
||||||
// mate::TrackableObject:
|
// mate::TrackableObject:
|
||||||
|
|
|
@ -46,6 +46,9 @@ class EventEmitter : public Wrappable<T> {
|
||||||
v8::Local<v8::Object> GetWrapper() const {
|
v8::Local<v8::Object> GetWrapper() const {
|
||||||
return Wrappable<T>::GetWrapper();
|
return Wrappable<T>::GetWrapper();
|
||||||
}
|
}
|
||||||
|
v8::MaybeLocal<v8::Object> GetWrapper(v8::Isolate* isolate) const {
|
||||||
|
return Wrappable<T>::GetWrapper(isolate);
|
||||||
|
}
|
||||||
|
|
||||||
// this.emit(name, event, args...);
|
// this.emit(name, event, args...);
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
|
|
|
@ -28,6 +28,15 @@ v8::Local<v8::Object> WrappableBase::GetWrapper() const {
|
||||||
return v8::Local<v8::Object>();
|
return v8::Local<v8::Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::MaybeLocal<v8::Object> WrappableBase::GetWrapper(
|
||||||
|
v8::Isolate* isolate) const {
|
||||||
|
if (!wrapper_.IsEmpty())
|
||||||
|
return v8::MaybeLocal<v8::Object>(
|
||||||
|
v8::Local<v8::Object>::New(isolate, wrapper_));
|
||||||
|
else
|
||||||
|
return v8::MaybeLocal<v8::Object>();
|
||||||
|
}
|
||||||
|
|
||||||
void WrappableBase::InitWith(v8::Isolate* isolate,
|
void WrappableBase::InitWith(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> wrapper) {
|
v8::Local<v8::Object> wrapper) {
|
||||||
CHECK(wrapper_.IsEmpty());
|
CHECK(wrapper_.IsEmpty());
|
||||||
|
|
|
@ -30,6 +30,7 @@ class WrappableBase {
|
||||||
|
|
||||||
// Retrieve the v8 wrapper object cooresponding to this object.
|
// Retrieve the v8 wrapper object cooresponding to this object.
|
||||||
v8::Local<v8::Object> GetWrapper() const;
|
v8::Local<v8::Object> GetWrapper() const;
|
||||||
|
v8::MaybeLocal<v8::Object> GetWrapper(v8::Isolate* isolate) const;
|
||||||
|
|
||||||
// Returns the Isolate this object is created in.
|
// Returns the Isolate this object is created in.
|
||||||
v8::Isolate* isolate() const { return isolate_; }
|
v8::Isolate* isolate() const { return isolate_; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue