mirror of
https://github.com/electron/electron.git
synced 2026-01-08 23:18:06 -05:00
* chore: bump chromium in DEPS to 140.0.7296.0 * chore: update patches * 6702959: Remove OwnedByWidgetPassKey usage from content analysis dialog tests | https://chromium-review.googlesource.com/c/chromium/src/+/6702959 * 6722750: Remove un-used `stream_id` argument for `AidaCodeComplete` | https://chromium-review.googlesource.com/c/chromium/src/+/6722750 * 6696478: Reland Reland [video pip] Add fade in/out animation to controls visibility changes | https://chromium-review.googlesource.com/c/chromium/src/+/6696478 * chore: update libc++-filenames * build: explicitly include cstdlib in Boyer-Moore patch * chore: bump chromium in DEPS to 140.0.7297.0 * chore: update patches * 6729537: [FPF] Pipe flag state from the browser to the renderer | https://chromium-review.googlesource.com/c/chromium/src/+/6729537 * 6727996: [Win] Detect pre-IPC crashes in sandboxed utility processes | https://chromium-review.googlesource.com/c/chromium/src/+/6727996 * 6707182: Move wtf/cross_thread_copier*.* to "blink" namespace | https://chromium-review.googlesource.com/c/chromium/src/+/6707182 * 6730796: extensions: Extract safe browsing/telemetry methods to new client class | https://chromium-review.googlesource.com/c/chromium/src/+/6730796 * chore: bump chromium in DEPS to 140.0.7299.0 * chore: update patches * chore: update main patches * build: reset the minimum macOS SDK to 15 to match upstream This reverts commit499e987c77. * 6730215: Remove IPC_MESSAGE_LOG_ENABLED ifdef blocks. | https://chromium-review.googlesource.com/c/chromium/src/+/6730215 * 6690442: Delete ppapi/buildflags/buildflags.h | https://chromium-review.googlesource.com/c/chromium/src/+/6690442 * [wip]: 6667681: Use more binaries from clang toolchain in mac build | https://chromium-review.googlesource.com/c/chromium/src/+/6667681 * chore: bump chromium in DEPS to 140.0.7301.0 * chore: update patches * 6656309: extensions: Port proxy API to desktop Android | https://chromium-review.googlesource.com/c/chromium/src/+/6656309 * 6758510: Reland 'Move GN enable_plugins variable out of //ppapi' | https://chromium-review.googlesource.com/c/chromium/src/+/6758510 * 6701466: [Extensions] Remove NaCl arch info from Update Client URLs | https://chromium-review.googlesource.com/c/chromium/src/+/6701466 * 6735979: [FSA] Replace `request_writable` with a new enum `FileSystemAccessPermissionMode`. | https://chromium-review.googlesource.com/c/chromium/src/+/6735979 * 6712080: Reland "Turn on gender translation PAK generation everywhere" | https://chromium-review.googlesource.com/c/chromium/src/+/6712080 * 6730796: extensions: Extract safe browsing/telemetry methods to new client class | https://chromium-review.googlesource.com/c/chromium/src/+/6730796 * build: restore minimum macOS SDK to 10, restore patch This reverts commita04c579b99. * fixup! 6701466: [Extensions] Remove NaCl arch info from Update Client URLs | https://chromium-review.googlesource.com/c/chromium/src/+/6701466 * chore: correct node patches * fixup! 6667681: Use more binaries from clang toolchain in mac build | https://chromium-review.googlesource.com/c/chromium/src/+/6667681 --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Keeley Hammond <khammond@slack-corp.com> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org> Co-authored-by: patchup[bot] <73610968+patchup[bot]@users.noreply.github.com>
143 lines
4.5 KiB
C++
143 lines
4.5 KiB
C++
// Copyright (c) 2022 Microsoft, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/services/node/parent_port.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "base/no_destructor.h"
|
|
#include "gin/data_object_builder.h"
|
|
#include "gin/handle.h"
|
|
#include "gin/object_template_builder.h"
|
|
#include "shell/browser/api/message_port.h"
|
|
#include "shell/browser/javascript_environment.h"
|
|
#include "shell/common/gin_helper/dictionary.h"
|
|
#include "shell/common/gin_helper/event_emitter_caller.h"
|
|
#include "shell/common/node_includes.h"
|
|
#include "shell/common/v8_util.h"
|
|
#include "third_party/blink/public/common/messaging/transferable_message_mojom_traits.h"
|
|
#include "third_party/blink/public/mojom/blob/blob.mojom.h"
|
|
|
|
namespace electron {
|
|
|
|
gin::DeprecatedWrapperInfo ParentPort::kWrapperInfo = {gin::kEmbedderNativeGin};
|
|
|
|
ParentPort* ParentPort::GetInstance() {
|
|
static ParentPort* instance = new ParentPort();
|
|
return instance;
|
|
}
|
|
|
|
ParentPort::ParentPort() = default;
|
|
ParentPort::~ParentPort() = default;
|
|
|
|
void ParentPort::Initialize(blink::MessagePortDescriptor port) {
|
|
port_ = std::move(port);
|
|
connector_ = std::make_unique<mojo::Connector>(
|
|
port_.TakeHandleToEntangleWithEmbedder(),
|
|
mojo::Connector::SINGLE_THREADED_SEND,
|
|
base::SingleThreadTaskRunner::GetCurrentDefault());
|
|
connector_->PauseIncomingMethodCallProcessing();
|
|
connector_->set_incoming_receiver(this);
|
|
connector_->set_connection_error_handler(
|
|
base::BindOnce(&ParentPort::Close, base::Unretained(this)));
|
|
}
|
|
|
|
void ParentPort::PostMessage(v8::Local<v8::Value> message_value) {
|
|
if (!connector_closed_ && connector_ && connector_->is_valid()) {
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
blink::TransferableMessage transferable_message;
|
|
|
|
if (!electron::SerializeV8Value(isolate, message_value,
|
|
&transferable_message)) {
|
|
// SerializeV8Value sets an exception.
|
|
return;
|
|
}
|
|
|
|
mojo::Message mojo_message =
|
|
blink::mojom::TransferableMessage::WrapAsMessage(
|
|
std::move(transferable_message));
|
|
connector_->Accept(&mojo_message);
|
|
}
|
|
}
|
|
|
|
void ParentPort::Close() {
|
|
if (!connector_closed_ && connector_->is_valid()) {
|
|
port_.GiveDisentangledHandle(connector_->PassMessagePipe());
|
|
connector_ = nullptr;
|
|
port_.Reset();
|
|
connector_closed_ = true;
|
|
}
|
|
}
|
|
|
|
void ParentPort::Start() {
|
|
if (!connector_closed_ && connector_ && connector_->is_valid()) {
|
|
connector_->ResumeIncomingMethodCallProcessing();
|
|
}
|
|
}
|
|
|
|
void ParentPort::Pause() {
|
|
if (!connector_closed_ && connector_ && connector_->is_valid()) {
|
|
connector_->PauseIncomingMethodCallProcessing();
|
|
}
|
|
}
|
|
|
|
bool ParentPort::Accept(mojo::Message* mojo_message) {
|
|
blink::TransferableMessage message;
|
|
if (!blink::mojom::TransferableMessage::DeserializeFromMessage(
|
|
std::move(*mojo_message), &message)) {
|
|
return false;
|
|
}
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
v8::HandleScope handle_scope(isolate);
|
|
auto wrapped_ports =
|
|
MessagePort::EntanglePorts(isolate, std::move(message.ports));
|
|
v8::Local<v8::Value> message_value =
|
|
electron::DeserializeV8Value(isolate, message);
|
|
v8::Local<v8::Object> self;
|
|
if (!GetWrapper(isolate).ToLocal(&self))
|
|
return false;
|
|
auto event = gin::DataObjectBuilder(isolate)
|
|
.Set("data", message_value)
|
|
.Set("ports", wrapped_ports)
|
|
.Build();
|
|
gin_helper::EmitEvent(isolate, self, "message", event);
|
|
return true;
|
|
}
|
|
|
|
// static
|
|
gin::Handle<ParentPort> ParentPort::Create(v8::Isolate* isolate) {
|
|
return gin::CreateHandle(isolate, ParentPort::GetInstance());
|
|
}
|
|
|
|
// static
|
|
gin::ObjectTemplateBuilder ParentPort::GetObjectTemplateBuilder(
|
|
v8::Isolate* isolate) {
|
|
return gin::DeprecatedWrappable<ParentPort>::GetObjectTemplateBuilder(isolate)
|
|
.SetMethod("postMessage", &ParentPort::PostMessage)
|
|
.SetMethod("start", &ParentPort::Start)
|
|
.SetMethod("pause", &ParentPort::Pause);
|
|
}
|
|
|
|
const char* ParentPort::GetTypeName() {
|
|
return "ParentPort";
|
|
}
|
|
|
|
} // namespace electron
|
|
|
|
namespace {
|
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
v8::Local<v8::Value> unused,
|
|
v8::Local<v8::Context> context,
|
|
void* priv) {
|
|
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
|
|
gin_helper::Dictionary dict{isolate, exports};
|
|
dict.SetMethod("createParentPort", &electron::ParentPort::Create);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
NODE_LINKED_BINDING_CONTEXT_AWARE(electron_utility_parent_port, Initialize)
|