dom/workers/MessagePort.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef mozilla_dom_workers_messageport_h_
michael@0 7 #define mozilla_dom_workers_messageport_h_
michael@0 8
michael@0 9 #include "Workers.h"
michael@0 10
michael@0 11 #include "mozilla/DOMEventTargetHelper.h"
michael@0 12 #include "mozilla/dom/BindingDeclarations.h"
michael@0 13 #include "mozilla/dom/MessagePort.h"
michael@0 14
michael@0 15 class nsIDOMEvent;
michael@0 16 class nsPIDOMWindow;
michael@0 17
michael@0 18 namespace mozilla {
michael@0 19 class EventChainPreVisitor;
michael@0 20 } // namespace mozilla
michael@0 21
michael@0 22 BEGIN_WORKERS_NAMESPACE
michael@0 23
michael@0 24 class SharedWorker;
michael@0 25 class WorkerPrivate;
michael@0 26
michael@0 27 class MessagePort MOZ_FINAL : public mozilla::dom::MessagePortBase
michael@0 28 {
michael@0 29 friend class SharedWorker;
michael@0 30 friend class WorkerPrivate;
michael@0 31
michael@0 32 typedef mozilla::ErrorResult ErrorResult;
michael@0 33
michael@0 34 nsRefPtr<SharedWorker> mSharedWorker;
michael@0 35 WorkerPrivate* mWorkerPrivate;
michael@0 36 nsTArray<nsCOMPtr<nsIDOMEvent>> mQueuedEvents;
michael@0 37 uint64_t mSerial;
michael@0 38 bool mStarted;
michael@0 39
michael@0 40 public:
michael@0 41 static bool
michael@0 42 PrefEnabled();
michael@0 43
michael@0 44 virtual void
michael@0 45 PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
michael@0 46 const Optional<Sequence<JS::Value>>& aTransferable,
michael@0 47 ErrorResult& aRv) MOZ_OVERRIDE;
michael@0 48
michael@0 49 virtual void
michael@0 50 Start() MOZ_OVERRIDE;
michael@0 51
michael@0 52 virtual void
michael@0 53 Close() MOZ_OVERRIDE;
michael@0 54
michael@0 55 uint64_t
michael@0 56 Serial() const
michael@0 57 {
michael@0 58 return mSerial;
michael@0 59 }
michael@0 60
michael@0 61 void
michael@0 62 QueueEvent(nsIDOMEvent* aEvent);
michael@0 63
michael@0 64 NS_DECL_ISUPPORTS_INHERITED
michael@0 65 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MessagePort, DOMEventTargetHelper)
michael@0 66
michael@0 67 virtual EventHandlerNonNull*
michael@0 68 GetOnmessage() MOZ_OVERRIDE;
michael@0 69
michael@0 70 virtual void
michael@0 71 SetOnmessage(EventHandlerNonNull* aCallback) MOZ_OVERRIDE;
michael@0 72
michael@0 73 virtual already_AddRefed<MessagePortBase>
michael@0 74 Clone() MOZ_OVERRIDE;
michael@0 75
michael@0 76 bool
michael@0 77 IsClosed() const
michael@0 78 {
michael@0 79 return !mSharedWorker && !mWorkerPrivate;
michael@0 80 }
michael@0 81
michael@0 82 virtual JSObject*
michael@0 83 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 84
michael@0 85 virtual nsresult
michael@0 86 PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
michael@0 87
michael@0 88 #ifdef DEBUG
michael@0 89 void
michael@0 90 AssertCorrectThread() const;
michael@0 91 #else
michael@0 92 void
michael@0 93 AssertCorrectThread() const { }
michael@0 94 #endif
michael@0 95
michael@0 96 private:
michael@0 97 // This class can only be created by SharedWorker or WorkerPrivate.
michael@0 98 MessagePort(nsPIDOMWindow* aWindow, SharedWorker* aSharedWorker,
michael@0 99 uint64_t aSerial);
michael@0 100 MessagePort(WorkerPrivate* aWorkerPrivate, uint64_t aSerial);
michael@0 101
michael@0 102 // This class is reference-counted and will be destroyed from Release().
michael@0 103 ~MessagePort();
michael@0 104
michael@0 105 void
michael@0 106 CloseInternal();
michael@0 107 };
michael@0 108
michael@0 109 END_WORKERS_NAMESPACE
michael@0 110
michael@0 111 #endif // mozilla_dom_workers_messageport_h_

mercurial