![trop[bot]](/assets/img/avatar_default.png)
* refactor: avoid redundant GetIsolate() calls in NodeBindings::CreateEnvironment() Xref: https://chromium-review.googlesource.com/c/v8/v8/+/6563615 Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: use v8::Isolate::GetCurrent() in Initialize() methods Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add v8::Isolate* arg to NodeBindings::CreateEnvironment() Co-authored-by: Charles Kerr <charles@charleskerr.com> * fixup! refactor: use v8::Isolate::GetCurrent() in Initialize() methods Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add v8::Isolate* arg to RendererClientBase::DidCreateScriptContext() Co-authored-by: Charles Kerr <charles@charleskerr.com> * fixup! refactor: add v8::Isolate* arg to NodeBindings::CreateEnvironment() Co-authored-by: Charles Kerr <charles@charleskerr.com> * fixup! fixup! refactor: use v8::Isolate::GetCurrent() in Initialize() methods refactor: prefer JavascriptEnvironment::GetIsolate() in the browser layer Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
73 lines
2.1 KiB
C++
73 lines
2.1 KiB
C++
// Copyright (c) 2022 Asana, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/browser/api/electron_api_push_notifications.h"
|
|
|
|
#include "gin/handle.h"
|
|
#include "shell/common/gin_converters/value_converter.h"
|
|
#include "shell/common/gin_helper/dictionary.h"
|
|
#include "shell/common/node_includes.h"
|
|
|
|
namespace electron::api {
|
|
|
|
PushNotifications* g_push_notifications = nullptr;
|
|
|
|
gin::DeprecatedWrapperInfo PushNotifications::kWrapperInfo = {
|
|
gin::kEmbedderNativeGin};
|
|
|
|
PushNotifications::PushNotifications() = default;
|
|
|
|
PushNotifications::~PushNotifications() {
|
|
g_push_notifications = nullptr;
|
|
}
|
|
|
|
// static
|
|
PushNotifications* PushNotifications::Get() {
|
|
if (!g_push_notifications)
|
|
g_push_notifications = new PushNotifications();
|
|
return g_push_notifications;
|
|
}
|
|
|
|
// static
|
|
gin::Handle<PushNotifications> PushNotifications::Create(v8::Isolate* isolate) {
|
|
return gin::CreateHandle(isolate, PushNotifications::Get());
|
|
}
|
|
|
|
// static
|
|
gin::ObjectTemplateBuilder PushNotifications::GetObjectTemplateBuilder(
|
|
v8::Isolate* isolate) {
|
|
auto builder = gin_helper::EventEmitterMixin<
|
|
PushNotifications>::GetObjectTemplateBuilder(isolate);
|
|
#if BUILDFLAG(IS_MAC)
|
|
builder
|
|
.SetMethod("registerForAPNSNotifications",
|
|
&PushNotifications::RegisterForAPNSNotifications)
|
|
.SetMethod("unregisterForAPNSNotifications",
|
|
&PushNotifications::UnregisterForAPNSNotifications);
|
|
#endif
|
|
return builder;
|
|
}
|
|
|
|
const char* PushNotifications::GetTypeName() {
|
|
return "PushNotifications";
|
|
}
|
|
|
|
} // namespace electron::api
|
|
|
|
namespace {
|
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
v8::Local<v8::Value> unused,
|
|
v8::Local<v8::Context> context,
|
|
void* priv) {
|
|
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
|
gin::Dictionary dict(isolate, exports);
|
|
dict.Set("pushNotifications",
|
|
electron::api::PushNotifications::Create(isolate));
|
|
}
|
|
|
|
} // namespace
|
|
|
|
NODE_LINKED_BINDING_CONTEXT_AWARE(electron_browser_push_notifications,
|
|
Initialize)
|