Bug 1861467 - [wpt-sync] Update web-platform-tests to eedf737ce39c512d0ca3471f988972e...
[gecko.git] / dom / workers / EventWithOptionsRunnable.h
blob424a4e157925d8fd8f986bd25a9cccb6a01dbedd
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/. */
7 #ifndef MOZILLA_DOM_WORKERS_EVENTWITHOPTIONSRUNNABLE_H_
8 #define MOZILLA_DOM_WORKERS_EVENTWITHOPTIONSRUNNABLE_H_
10 #include "WorkerCommon.h"
11 #include "WorkerRunnable.h"
12 #include "mozilla/dom/StructuredCloneHolder.h"
14 namespace mozilla {
15 class DOMEventTargetHelper;
17 namespace dom {
18 class Event;
19 class EventTarget;
20 class Worker;
21 class WorkerPrivate;
23 // Cargo-culted from MesssageEventRunnable.
24 // Intended to be used for the idiom where arbitrary options are transferred to
25 // the worker thread (with optional transfer functions), which are then used to
26 // build an event, which is then fired on the global worker scope.
27 class EventWithOptionsRunnable : public WorkerDebuggeeRunnable,
28 public StructuredCloneHolder {
29 public:
30 explicit EventWithOptionsRunnable(Worker& aWorker);
31 void InitOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions,
32 const Sequence<JSObject*>& aTransferable, ErrorResult& aRv);
34 // Called on the worker thread. The event returned will be fired on the
35 // worker's global scope. If a StrongWorkerRef needs to be retained, the
36 // implementation can do so with the WorkerPrivate.
37 virtual already_AddRefed<Event> BuildEvent(
38 JSContext* aCx, nsIGlobalObject* aGlobal, EventTarget* aTarget,
39 JS::Handle<JS::Value> aOptions) = 0;
41 // Called on the worker thread
42 virtual void OptionsDeserializeFailed(ErrorResult& aRv) {}
44 protected:
45 virtual ~EventWithOptionsRunnable();
47 private:
48 bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
49 bool BuildAndFireEvent(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
50 DOMEventTargetHelper* aTarget);
52 } // namespace dom
53 } // namespace mozilla
55 #endif // MOZILLA_DOM_WORKERS_EVENTWITHOPTIONSRUNNABLE_H_