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/. */
7 #ifndef mozilla_dom_BroadcastChannel_h
8 #define mozilla_dom_BroadcastChannel_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/DOMEventTargetHelper.h"
13 #include "mozilla/RefPtr.h"
15 class nsIGlobalObject
;
25 class BroadcastChannelChild
;
26 class RefMessageBodyService
;
29 class BroadcastChannel final
: public DOMEventTargetHelper
{
30 friend class BroadcastChannelChild
;
32 using PrincipalInfo
= mozilla::ipc::PrincipalInfo
;
35 NS_DECL_ISUPPORTS_INHERITED
37 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BroadcastChannel
,
40 virtual JSObject
* WrapObject(JSContext
* aCx
,
41 JS::Handle
<JSObject
*> aGivenProto
) override
;
43 static already_AddRefed
<BroadcastChannel
> Constructor(
44 const GlobalObject
& aGlobal
, const nsAString
& aChannel
, ErrorResult
& aRv
);
46 void GetName(nsAString
& aName
) const { aName
= mChannel
; }
48 void PostMessage(JSContext
* aCx
, JS::Handle
<JS::Value
> aMessage
,
53 IMPL_EVENT_HANDLER(message
)
54 IMPL_EVENT_HANDLER(messageerror
)
59 BroadcastChannel(nsIGlobalObject
* aGlobal
, const nsAString
& aChannel
,
60 const nsID
& aPortUUID
);
64 void MessageReceived(const MessageData
& aData
);
66 void MessageDelivered(const nsID
& aMessageID
, uint32_t aOtherBCs
);
68 void RemoveDocFromBFCache();
70 void DisconnectFromOwner() override
;
72 void DispatchError(JSContext
* aCx
);
74 RefPtr
<BroadcastChannelChild
> mActor
;
76 RefPtr
<RefMessageBodyService
> mRefMessageBodyService
;
78 RefPtr
<WorkerRef
> mWorkerRef
;
81 nsString mOriginForEvents
;
83 enum { StateActive
, StateClosed
} mState
;
85 // This ID is used to identify the messages-by-reference sent by this port.
86 // See RefMessageBodyService.
91 } // namespace mozilla
93 #endif // mozilla_dom_BroadcastChannel_h