feat: context bridge support VideoFrame (#47316)

* feat: context bridge support VideoFrame

* docs: add VideoFrame to docs
This commit is contained in:
reito 2025-08-08 04:41:49 +08:00 committed by GitHub
commit 095e622a6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View file

@ -157,6 +157,7 @@ has been included below for completeness:
| [Cloneable Types](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) | Simple | ✅ | ✅ | See the linked document on cloneable types |
| `Element` | Complex | ✅ | ✅ | Prototype modifications are dropped. Sending custom elements will not work. |
| `Blob` | Complex | ✅ | ✅ | N/A |
| `VideoFrame` | Complex | ✅ | ✅ | N/A |
| `Symbol` | N/A | ❌ | ❌ | Symbols cannot be copied across contexts so they are dropped |
If the type you care about is not in the above table, it is probably not supported.

View file

@ -28,7 +28,9 @@
#include "third_party/blink/public/web/web_blob.h"
#include "third_party/blink/public/web/web_element.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_video_frame.h" // nogncheck
#include "third_party/blink/renderer/core/execution_context/execution_context.h" // nogncheck
#include "third_party/blink/renderer/modules/webcodecs/video_frame.h" // nogncheck
namespace features {
BASE_FEATURE(kContextBridgeMutability,
@ -414,6 +416,17 @@ v8::MaybeLocal<v8::Value> PassValueToOtherContextInner(
v8::Context::Scope destination_context_scope(destination_context);
return v8::MaybeLocal<v8::Value>(blob.ToV8Value(destination_isolate));
}
// Custom logic to "clone" VideoFrame references
blink::VideoFrame* video_frame =
blink::V8VideoFrame::ToWrappable(source_context->GetIsolate(), value);
if (video_frame != nullptr) {
blink::ScriptState* script_state = blink::ScriptState::ForCurrentRealm(
destination_context->GetIsolate());
return v8::MaybeLocal<v8::Value>(
blink::ToV8Traits<blink::VideoFrame>::ToV8(script_state,
video_frame));
}
}
// Proxy all objects