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"
15 class DOMEventTargetHelper
;
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
{
30 explicit EventWithOptionsRunnable(
31 Worker
& aWorker
, const char* aName
= "EventWithOptionsRunnable");
32 void InitOptions(JSContext
* aCx
, JS::Handle
<JS::Value
> aOptions
,
33 const Sequence
<JSObject
*>& aTransferable
, ErrorResult
& aRv
);
35 // Called on the worker thread. The event returned will be fired on the
36 // worker's global scope. If a StrongWorkerRef needs to be retained, the
37 // implementation can do so with the WorkerPrivate.
38 virtual already_AddRefed
<Event
> BuildEvent(
39 JSContext
* aCx
, nsIGlobalObject
* aGlobal
, EventTarget
* aTarget
,
40 JS::Handle
<JS::Value
> aOptions
) = 0;
42 // Called on the worker thread
43 virtual void OptionsDeserializeFailed(ErrorResult
& aRv
) {}
46 virtual ~EventWithOptionsRunnable();
49 bool WorkerRun(JSContext
* aCx
, WorkerPrivate
* aWorkerPrivate
) override
;
50 bool BuildAndFireEvent(JSContext
* aCx
, WorkerPrivate
* aWorkerPrivate
,
51 DOMEventTargetHelper
* aTarget
);
54 } // namespace mozilla
56 #endif // MOZILLA_DOM_WORKERS_EVENTWITHOPTIONSRUNNABLE_H_