2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-04-17 17:12:27 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#ifndef SHELL_BROWSER_API_EVENT_H_
|
|
|
|
#define SHELL_BROWSER_API_EVENT_H_
|
2014-04-17 17:12:27 +08:00
|
|
|
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "electron/shell/common/api/api.mojom.h"
|
2019-10-31 16:56:00 +09:00
|
|
|
#include "gin/handle.h"
|
|
|
|
#include "gin/wrappable.h"
|
2014-04-17 17:12:27 +08:00
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
class Message;
|
|
|
|
}
|
|
|
|
|
2019-10-31 16:56:00 +09:00
|
|
|
namespace gin_helper {
|
2014-04-17 17:12:27 +08:00
|
|
|
|
2019-10-31 16:56:00 +09:00
|
|
|
class Event : public gin::Wrappable<Event> {
|
2014-04-17 17:12:27 +08:00
|
|
|
public:
|
2019-10-09 10:59:08 -07:00
|
|
|
using InvokeCallback = electron::mojom::ElectronBrowser::InvokeCallback;
|
2014-04-17 17:12:27 +08:00
|
|
|
|
2019-10-31 16:56:00 +09:00
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
|
|
|
|
|
|
static gin::Handle<Event> Create(v8::Isolate* isolate);
|
2016-04-25 10:17:54 +09:00
|
|
|
|
2019-08-01 00:20:28 +02:00
|
|
|
// Pass the callback to be invoked.
|
2019-10-31 16:56:00 +09:00
|
|
|
void SetCallback(InvokeCallback callback);
|
2014-04-17 17:12:27 +08:00
|
|
|
|
|
|
|
// event.PreventDefault().
|
2014-10-27 17:55:28 +08:00
|
|
|
void PreventDefault(v8::Isolate* isolate);
|
2014-04-17 17:12:27 +08:00
|
|
|
|
2019-05-31 10:25:19 -07:00
|
|
|
// event.sendReply(value), used for replying to synchronous messages and
|
|
|
|
// `invoke` calls.
|
2019-10-09 10:59:08 -07:00
|
|
|
bool SendReply(v8::Isolate* isolate, v8::Local<v8::Value> result);
|
2014-04-17 17:12:27 +08:00
|
|
|
|
|
|
|
protected:
|
2019-10-31 16:56:00 +09:00
|
|
|
Event();
|
2016-04-25 10:17:54 +09:00
|
|
|
~Event() override;
|
2014-04-17 17:12:27 +08:00
|
|
|
|
2019-10-31 16:56:00 +09:00
|
|
|
// gin::Wrappable:
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
|
|
|
const char* GetTypeName() override;
|
|
|
|
|
2014-04-17 17:12:27 +08:00
|
|
|
private:
|
|
|
|
// Replyer for the synchronous messages.
|
2019-10-31 16:56:00 +09:00
|
|
|
InvokeCallback callback_;
|
2014-04-17 17:12:27 +08:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Event);
|
|
|
|
};
|
|
|
|
|
2019-10-31 16:56:00 +09:00
|
|
|
} // namespace gin_helper
|
2014-04-17 17:12:27 +08:00
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#endif // SHELL_BROWSER_API_EVENT_H_
|