2020-03-12 01:07:54 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jeremy Apthorp <nornagon@nornagon.net>
|
|
|
|
Date: Fri, 25 Oct 2019 11:23:03 -0700
|
|
|
|
Subject: add WebMessagePortConverter::EntangleAndInjectMessagePortChannel
|
|
|
|
|
|
|
|
This adds a method to the public Blink API that would otherwise require
|
|
|
|
accessing Blink internals. Its inverse, which already exists, is used in
|
|
|
|
Android WebView.
|
|
|
|
|
|
|
|
diff --git a/third_party/blink/public/web/web_message_port_converter.h b/third_party/blink/public/web/web_message_port_converter.h
|
2024-02-14 17:33:32 +00:00
|
|
|
index e7c4464f1b5aa19cbe441d94d88c949798ccb1e3..bd804d509ad5f3581154c6ede8653e7521cb71b8 100644
|
2020-03-12 01:07:54 +00:00
|
|
|
--- a/third_party/blink/public/web/web_message_port_converter.h
|
|
|
|
+++ b/third_party/blink/public/web/web_message_port_converter.h
|
2024-02-14 17:33:32 +00:00
|
|
|
@@ -13,6 +13,7 @@
|
2023-07-01 20:22:55 +00:00
|
|
|
namespace v8 {
|
|
|
|
class Isolate;
|
2020-03-12 01:07:54 +00:00
|
|
|
class Value;
|
|
|
|
+class Context;
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
namespace blink {
|
2024-02-14 17:33:32 +00:00
|
|
|
@@ -25,6 +26,9 @@ class BLINK_EXPORT WebMessagePortConverter {
|
2020-03-12 01:07:54 +00:00
|
|
|
// neutered, it will return nullopt.
|
2024-02-14 17:33:32 +00:00
|
|
|
static std::optional<MessagePortChannel>
|
2020-03-12 01:07:54 +00:00
|
|
|
DisentangleAndExtractMessagePortChannel(v8::Isolate*, v8::Local<v8::Value>);
|
|
|
|
+
|
|
|
|
+ BLINK_EXPORT static v8::Local<v8::Value>
|
|
|
|
+ EntangleAndInjectMessagePortChannel(v8::Local<v8::Context>, MessagePortChannel);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace blink
|
|
|
|
diff --git a/third_party/blink/renderer/core/exported/web_message_port_converter.cc b/third_party/blink/renderer/core/exported/web_message_port_converter.cc
|
2024-02-14 17:33:32 +00:00
|
|
|
index 3270da19f73077b1fab7522144b9f3d52d9f6a5a..e6c5764c54a18b31223ac8c5b8f2d6ef732225d6 100644
|
2020-03-12 01:07:54 +00:00
|
|
|
--- a/third_party/blink/renderer/core/exported/web_message_port_converter.cc
|
|
|
|
+++ b/third_party/blink/renderer/core/exported/web_message_port_converter.cc
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -6,6 +6,7 @@
|
|
|
|
|
|
|
|
#include "third_party/blink/public/common/messaging/message_port_channel.h"
|
|
|
|
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
|
|
|
|
+#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
|
|
|
|
#include "third_party/blink/renderer/bindings/core/v8/v8_message_port.h"
|
|
|
|
#include "third_party/blink/renderer/core/messaging/message_port.h"
|
|
|
|
|
|
|
|
@@ -21,4 +22,15 @@ WebMessagePortConverter::DisentangleAndExtractMessagePortChannel(
|
2020-03-12 01:07:54 +00:00
|
|
|
return port->Disentangle();
|
|
|
|
}
|
|
|
|
|
|
|
|
+v8::Local<v8::Value>
|
|
|
|
+WebMessagePortConverter::EntangleAndInjectMessagePortChannel(
|
|
|
|
+ v8::Local<v8::Context> context,
|
|
|
|
+ MessagePortChannel port_channel) {
|
|
|
|
+ auto* execution_context = ToExecutionContext(context);
|
|
|
|
+ CHECK(execution_context);
|
|
|
|
+ auto* port = MakeGarbageCollected<MessagePort>(*execution_context);
|
|
|
|
+ port->Entangle(std::move(port_channel));
|
2024-01-25 17:46:30 +00:00
|
|
|
+ return port->ToV8(context->GetIsolate(), context->Global());
|
2020-03-12 01:07:54 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
} // namespace blink
|