1
0
Fork 0
firefox/dom/media/webrtc/jsapi/RTCTransformEventRunnable.cpp
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

80 lines
3 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "RTCTransformEventRunnable.h"
#include "nsIGlobalObject.h"
#include "ErrorList.h"
#include "nsError.h"
#include "nsDebug.h"
#include "nsLiteralString.h"
#include "mozilla/RefPtr.h"
#include "mozilla/AlreadyAddRefed.h"
// This needs to come before RTCTransformEvent.h, since webidl codegen doesn't
// include-what-you-use or forward declare.
#include "mozilla/dom/RTCRtpScriptTransformer.h"
#include "mozilla/dom/RTCTransformEvent.h"
#include "mozilla/dom/RTCTransformEventBinding.h"
#include "mozilla/dom/EventWithOptionsRunnable.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/RootedDictionary.h"
#include "js/RootingAPI.h"
#include "js/Value.h"
#include "libwebrtcglue/FrameTransformerProxy.h"
namespace mozilla::dom {
RTCTransformEventRunnable::RTCTransformEventRunnable(
Worker& aWorker, FrameTransformerProxy* aProxy)
: EventWithOptionsRunnable(aWorker, "RTCTransformEventRunnable"),
mProxy(aProxy) {}
RTCTransformEventRunnable::~RTCTransformEventRunnable() = default;
already_AddRefed<Event> RTCTransformEventRunnable::BuildEvent(
JSContext* aCx, nsIGlobalObject* aGlobal, EventTarget* aTarget,
JS::Handle<JS::Value> aTransformerOptions) {
// Let transformerOptions be the result of
// StructuredDeserialize(serializedOptions, the current Realm).
// NOTE: We do not do this streams stuff. Spec will likely change here.
// The gist here is that we hook [[readable]] and [[writable]] up to the frame
// source/sink, which in out case is FrameTransformerProxy.
// Let readable be the result of StructuredDeserialize(serializedReadable, the
// current Realm). Let writable be the result of
// StructuredDeserialize(serializedWritable, the current Realm).
// Let transformer be a new RTCRtpScriptTransformer.
// Set transformer.[[options]] to transformerOptions.
// Set transformer.[[readable]] to readable.
// Set transformer.[[writable]] to writable.
RefPtr<RTCRtpScriptTransformer> transformer =
new RTCRtpScriptTransformer(aGlobal);
nsresult nrv = transformer->Init(aCx, aTransformerOptions,
GetCurrentThreadWorkerPrivate(), mProxy);
if (NS_WARN_IF(NS_FAILED(nrv))) {
// TODO: Error handling. Currently unspecified.
return nullptr;
}
// Fire an event named rtctransform using RTCTransformEvent with transformer
// set to transformer on workers global scope.
RootedDictionary<RTCTransformEventInit> init(aCx);
init.mBubbles = false;
init.mCancelable = false;
init.mTransformer = transformer;
RefPtr<RTCTransformEvent> event =
RTCTransformEvent::Constructor(aTarget, u"rtctransform"_ns, init);
event->SetTrusted(true);
return event.forget();
}
} // namespace mozilla::dom