3ae3233e65
* 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
61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
// Copyright (c) 2014 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/browser/api/event.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "gin/object_template_builder.h"
|
|
#include "shell/common/gin_converters/blink_converter.h"
|
|
|
|
namespace gin_helper {
|
|
|
|
gin::WrapperInfo Event::kWrapperInfo = {gin::kEmbedderNativeGin};
|
|
|
|
Event::Event() {}
|
|
|
|
Event::~Event() = default;
|
|
|
|
void Event::SetCallback(InvokeCallback callback) {
|
|
DCHECK(!callback_);
|
|
callback_ = std::move(callback);
|
|
}
|
|
|
|
void Event::PreventDefault(v8::Isolate* isolate) {
|
|
v8::Local<v8::Object> self = GetWrapper(isolate).ToLocalChecked();
|
|
self->Set(isolate->GetCurrentContext(),
|
|
gin::StringToV8(isolate, "defaultPrevented"), v8::True(isolate))
|
|
.Check();
|
|
}
|
|
|
|
bool Event::SendReply(v8::Isolate* isolate, v8::Local<v8::Value> result) {
|
|
if (!callback_)
|
|
return false;
|
|
|
|
blink::CloneableMessage message;
|
|
if (!gin::ConvertFromV8(isolate, result, &message)) {
|
|
return false;
|
|
}
|
|
|
|
std::move(callback_).Run(std::move(message));
|
|
return true;
|
|
}
|
|
|
|
gin::ObjectTemplateBuilder Event::GetObjectTemplateBuilder(
|
|
v8::Isolate* isolate) {
|
|
return gin::Wrappable<Event>::GetObjectTemplateBuilder(isolate)
|
|
.SetMethod("preventDefault", &Event::PreventDefault)
|
|
.SetMethod("sendReply", &Event::SendReply);
|
|
}
|
|
|
|
const char* Event::GetTypeName() {
|
|
return "WebRequest";
|
|
}
|
|
|
|
// static
|
|
gin::Handle<Event> Event::Create(v8::Isolate* isolate) {
|
|
return gin::CreateHandle(isolate, new Event());
|
|
}
|
|
|
|
} // namespace gin_helper
|