1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=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 http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_Worker_h 8 #define mozilla_dom_Worker_h 9 10 #include "mozilla/Attributes.h" 11 #include "mozilla/DOMEventTargetHelper.h" 12 #include "mozilla/RefPtr.h" 13 #include "mozilla/WeakPtr.h" 14 15 #ifdef XP_WIN 16 #undef PostMessage 17 #endif 18 19 namespace mozilla { 20 namespace dom { 21 22 struct WorkerOptions; 23 class WorkerPrivate; 24 25 class Worker : public DOMEventTargetHelper, public SupportsWeakPtr<Worker> { 26 public: 27 NS_DECL_ISUPPORTS_INHERITED 28 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(Worker, 29 DOMEventTargetHelper) 30 MOZ_DECLARE_WEAKREFERENCE_TYPENAME(Worker) 31 32 static already_AddRefed<Worker> Constructor(const GlobalObject& aGlobal, 33 const nsAString& aScriptURL, 34 const WorkerOptions& aOptions, 35 ErrorResult& aRv); 36 37 JSObject* WrapObject(JSContext* aCx, 38 JS::Handle<JSObject*> aGivenProto) override; 39 40 void PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage, 41 const Sequence<JSObject*>& aTransferable, ErrorResult& aRv); 42 43 void Terminate(); 44 45 IMPL_EVENT_HANDLER(error) 46 IMPL_EVENT_HANDLER(message) 47 IMPL_EVENT_HANDLER(messageerror) 48 49 protected: 50 Worker(nsIGlobalObject* aGlobalObject, 51 already_AddRefed<WorkerPrivate> aWorkerPrivate); 52 ~Worker(); 53 54 RefPtr<WorkerPrivate> mWorkerPrivate; 55 }; 56 57 } // namespace dom 58 } // namespace mozilla 59 60 #endif /* mozilla_dom_Worker_h */ 61