1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/workers/MessagePort.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_dom_workers_messageport_h_ 1.10 +#define mozilla_dom_workers_messageport_h_ 1.11 + 1.12 +#include "Workers.h" 1.13 + 1.14 +#include "mozilla/DOMEventTargetHelper.h" 1.15 +#include "mozilla/dom/BindingDeclarations.h" 1.16 +#include "mozilla/dom/MessagePort.h" 1.17 + 1.18 +class nsIDOMEvent; 1.19 +class nsPIDOMWindow; 1.20 + 1.21 +namespace mozilla { 1.22 +class EventChainPreVisitor; 1.23 +} // namespace mozilla 1.24 + 1.25 +BEGIN_WORKERS_NAMESPACE 1.26 + 1.27 +class SharedWorker; 1.28 +class WorkerPrivate; 1.29 + 1.30 +class MessagePort MOZ_FINAL : public mozilla::dom::MessagePortBase 1.31 +{ 1.32 + friend class SharedWorker; 1.33 + friend class WorkerPrivate; 1.34 + 1.35 + typedef mozilla::ErrorResult ErrorResult; 1.36 + 1.37 + nsRefPtr<SharedWorker> mSharedWorker; 1.38 + WorkerPrivate* mWorkerPrivate; 1.39 + nsTArray<nsCOMPtr<nsIDOMEvent>> mQueuedEvents; 1.40 + uint64_t mSerial; 1.41 + bool mStarted; 1.42 + 1.43 +public: 1.44 + static bool 1.45 + PrefEnabled(); 1.46 + 1.47 + virtual void 1.48 + PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage, 1.49 + const Optional<Sequence<JS::Value>>& aTransferable, 1.50 + ErrorResult& aRv) MOZ_OVERRIDE; 1.51 + 1.52 + virtual void 1.53 + Start() MOZ_OVERRIDE; 1.54 + 1.55 + virtual void 1.56 + Close() MOZ_OVERRIDE; 1.57 + 1.58 + uint64_t 1.59 + Serial() const 1.60 + { 1.61 + return mSerial; 1.62 + } 1.63 + 1.64 + void 1.65 + QueueEvent(nsIDOMEvent* aEvent); 1.66 + 1.67 + NS_DECL_ISUPPORTS_INHERITED 1.68 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MessagePort, DOMEventTargetHelper) 1.69 + 1.70 + virtual EventHandlerNonNull* 1.71 + GetOnmessage() MOZ_OVERRIDE; 1.72 + 1.73 + virtual void 1.74 + SetOnmessage(EventHandlerNonNull* aCallback) MOZ_OVERRIDE; 1.75 + 1.76 + virtual already_AddRefed<MessagePortBase> 1.77 + Clone() MOZ_OVERRIDE; 1.78 + 1.79 + bool 1.80 + IsClosed() const 1.81 + { 1.82 + return !mSharedWorker && !mWorkerPrivate; 1.83 + } 1.84 + 1.85 + virtual JSObject* 1.86 + WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.87 + 1.88 + virtual nsresult 1.89 + PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; 1.90 + 1.91 +#ifdef DEBUG 1.92 + void 1.93 + AssertCorrectThread() const; 1.94 +#else 1.95 + void 1.96 + AssertCorrectThread() const { } 1.97 +#endif 1.98 + 1.99 +private: 1.100 + // This class can only be created by SharedWorker or WorkerPrivate. 1.101 + MessagePort(nsPIDOMWindow* aWindow, SharedWorker* aSharedWorker, 1.102 + uint64_t aSerial); 1.103 + MessagePort(WorkerPrivate* aWorkerPrivate, uint64_t aSerial); 1.104 + 1.105 + // This class is reference-counted and will be destroyed from Release(). 1.106 + ~MessagePort(); 1.107 + 1.108 + void 1.109 + CloseInternal(); 1.110 +}; 1.111 + 1.112 +END_WORKERS_NAMESPACE 1.113 + 1.114 +#endif // mozilla_dom_workers_messageport_h_