tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RTCTransformEventRunnable.cpp (3095B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      6 
      7 #include "RTCTransformEventRunnable.h"
      8 
      9 #include "ErrorList.h"
     10 #include "mozilla/AlreadyAddRefed.h"
     11 #include "mozilla/RefPtr.h"
     12 #include "nsDebug.h"
     13 #include "nsError.h"
     14 #include "nsIGlobalObject.h"
     15 #include "nsLiteralString.h"
     16 // This needs to come before RTCTransformEvent.h, since webidl codegen doesn't
     17 // include-what-you-use or forward declare.
     18 #include "js/RootingAPI.h"
     19 #include "js/Value.h"
     20 #include "libwebrtcglue/FrameTransformerProxy.h"
     21 #include "mozilla/dom/Event.h"
     22 #include "mozilla/dom/EventTarget.h"
     23 #include "mozilla/dom/EventWithOptionsRunnable.h"
     24 #include "mozilla/dom/RTCRtpScriptTransformer.h"
     25 #include "mozilla/dom/RTCTransformEvent.h"
     26 #include "mozilla/dom/RTCTransformEventBinding.h"
     27 #include "mozilla/dom/RootedDictionary.h"
     28 
     29 namespace mozilla::dom {
     30 
     31 RTCTransformEventRunnable::RTCTransformEventRunnable(
     32    Worker& aWorker, FrameTransformerProxy* aProxy)
     33    : EventWithOptionsRunnable(aWorker, "RTCTransformEventRunnable"),
     34      mProxy(aProxy) {}
     35 
     36 RTCTransformEventRunnable::~RTCTransformEventRunnable() = default;
     37 
     38 already_AddRefed<Event> RTCTransformEventRunnable::BuildEvent(
     39    JSContext* aCx, nsIGlobalObject* aGlobal, EventTarget* aTarget,
     40    JS::Handle<JS::Value> aTransformerOptions) {
     41  // Let transformerOptions be the result of
     42  // StructuredDeserialize(serializedOptions, the current Realm).
     43 
     44  // NOTE: We do not do this streams stuff. Spec will likely change here.
     45  // The gist here is that we hook [[readable]] and [[writable]] up to the frame
     46  // source/sink, which in out case is FrameTransformerProxy.
     47  // Let readable be the result of StructuredDeserialize(serializedReadable, the
     48  // current Realm). Let writable be the result of
     49  // StructuredDeserialize(serializedWritable, the current Realm).
     50 
     51  // Let transformer be a new RTCRtpScriptTransformer.
     52 
     53  // Set transformer.[[options]] to transformerOptions.
     54 
     55  // Set transformer.[[readable]] to readable.
     56 
     57  // Set transformer.[[writable]] to writable.
     58  RefPtr<RTCRtpScriptTransformer> transformer =
     59      new RTCRtpScriptTransformer(aGlobal);
     60  nsresult nrv = transformer->Init(aCx, aTransformerOptions,
     61                                   GetCurrentThreadWorkerPrivate(), mProxy);
     62  if (NS_WARN_IF(NS_FAILED(nrv))) {
     63    // TODO: Error handling. Currently unspecified.
     64    return nullptr;
     65  }
     66 
     67  // Fire an event named rtctransform using RTCTransformEvent with transformer
     68  // set to transformer on worker’s global scope.
     69  RootedDictionary<RTCTransformEventInit> init(aCx);
     70  init.mBubbles = false;
     71  init.mCancelable = false;
     72  init.mTransformer = transformer;
     73 
     74  RefPtr<RTCTransformEvent> event =
     75      RTCTransformEvent::Constructor(aTarget, u"rtctransform"_ns, init);
     76  event->SetTrusted(true);
     77  return event.forget();
     78 }
     79 
     80 }  // namespace mozilla::dom