BroadcastChannel.h (2533B)
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_BroadcastChannel_h 8 #define mozilla_dom_BroadcastChannel_h 9 10 #include "mozilla/DOMEventTargetHelper.h" 11 #include "mozilla/RefPtr.h" 12 #include "nsTArray.h" 13 14 class nsIGlobalObject; 15 16 namespace mozilla { 17 18 namespace ipc { 19 class PrincipalInfo; 20 } // namespace ipc 21 22 namespace dom { 23 24 class BroadcastChannelChild; 25 class RefMessageBodyService; 26 class WorkerRef; 27 28 class BroadcastChannel final : public DOMEventTargetHelper { 29 friend class BroadcastChannelChild; 30 31 using PrincipalInfo = mozilla::ipc::PrincipalInfo; 32 33 public: 34 NS_DECL_ISUPPORTS_INHERITED 35 36 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BroadcastChannel, 37 DOMEventTargetHelper) 38 39 virtual JSObject* WrapObject(JSContext* aCx, 40 JS::Handle<JSObject*> aGivenProto) override; 41 42 static already_AddRefed<BroadcastChannel> Constructor( 43 const GlobalObject& aGlobal, const nsAString& aChannel, ErrorResult& aRv); 44 45 static already_AddRefed<BroadcastChannel> UnpartitionedTestingChannel( 46 const GlobalObject& aGlobal, const nsAString& aChannel, ErrorResult& aRv); 47 48 void GetName(nsAString& aName) const { aName = mChannel; } 49 50 void PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage, 51 ErrorResult& aRv); 52 53 void Close(); 54 55 IMPL_EVENT_HANDLER(message) 56 IMPL_EVENT_HANDLER(messageerror) 57 58 void Shutdown(); 59 60 private: 61 BroadcastChannel(nsIGlobalObject* aGlobal, const nsAString& aChannel, 62 const nsID& aPortUUID); 63 64 ~BroadcastChannel(); 65 66 void MessageReceived(const MessageData& aData); 67 68 void MessageDelivered(const nsID& aMessageID, uint32_t aOtherBCs); 69 70 void RemoveDocFromBFCache(); 71 72 void DisconnectFromOwner() override; 73 74 void DispatchError(JSContext* aCx); 75 76 RefPtr<BroadcastChannelChild> mActor; 77 78 RefPtr<RefMessageBodyService> mRefMessageBodyService; 79 80 RefPtr<WorkerRef> mWorkerRef; 81 82 nsString mChannel; 83 nsString mOriginForEvents; 84 85 enum { StateActive, StateClosed } mState; 86 87 // This ID is used to identify the messages-by-reference sent by this port. 88 // See RefMessageBodyService. 89 nsID mPortUUID; 90 }; 91 92 } // namespace dom 93 } // namespace mozilla 94 95 #endif // mozilla_dom_BroadcastChannel_h