
chore: move gin::DeprecatedWrappable to gin_helper (#47958) * chore: move gin::DeprecatedWrappable to gin_helper This is in preparation for migrating to gin::Wrappable based on cppgc #47922 The upstream class will be deleted soon via roller PR but the cppgc migration should happen outside the roll, this change retains the current functionality by copying the implementation into //electron/shell/common/gin_helper. The class can be deleted once the cppgc migration is complete. * chore: fix lint:cpp Co-authored-by: Robo <hop2deep@gmail.com>
54 lines
1.6 KiB
C++
54 lines
1.6 KiB
C++
// Copyright (c) 2023 Salesforce, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef ELECTRON_SHELL_COMMON_GIN_HELPER_REPLY_CHANNEL_H_
|
|
#define ELECTRON_SHELL_COMMON_GIN_HELPER_REPLY_CHANNEL_H_
|
|
|
|
#include "shell/common/api/api.mojom.h"
|
|
#include "shell/common/gin_helper/wrappable.h"
|
|
|
|
namespace gin {
|
|
template <typename T>
|
|
class Handle;
|
|
} // namespace gin
|
|
|
|
namespace v8 {
|
|
class Isolate;
|
|
template <typename T>
|
|
class Local;
|
|
class Object;
|
|
class ObjectTemplate;
|
|
} // namespace v8
|
|
|
|
namespace gin_helper::internal {
|
|
|
|
// This object wraps the InvokeCallback so that if it gets GC'd by V8, we can
|
|
// still call the callback and send an error. Not doing so causes a Mojo DCHECK,
|
|
// since Mojo requires callbacks to be called before they are destroyed.
|
|
class ReplyChannel : public gin_helper::DeprecatedWrappable<ReplyChannel> {
|
|
public:
|
|
using InvokeCallback = electron::mojom::ElectronApiIPC::InvokeCallback;
|
|
static gin::Handle<ReplyChannel> Create(v8::Isolate* isolate,
|
|
InvokeCallback callback);
|
|
|
|
// gin_helper::Wrappable
|
|
static gin::DeprecatedWrapperInfo kWrapperInfo;
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
v8::Isolate* isolate) override;
|
|
const char* GetTypeName() override;
|
|
|
|
void SendError(const std::string& msg);
|
|
|
|
private:
|
|
explicit ReplyChannel(InvokeCallback callback);
|
|
~ReplyChannel() override;
|
|
|
|
bool SendReply(v8::Isolate* isolate, v8::Local<v8::Value> arg);
|
|
|
|
InvokeCallback callback_;
|
|
};
|
|
|
|
} // namespace gin_helper::internal
|
|
|
|
#endif // ELECTRON_SHELL_COMMON_GIN_HELPER_REPLY_CHANNEL_H_
|