Bug 1776444 [wpt PR 34582] - Revert "Add TimedHTMLParserBudget to fieldtrial_testing_...
[gecko.git] / dom / broadcastchannel / BroadcastChannel.h
blob280913e8f8ddfcf95e4dcf1966977c559b4df14d
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"
12 #include "nsTArray.h"
13 #include "mozilla/RefPtr.h"
15 class nsIGlobalObject;
17 namespace mozilla {
19 namespace ipc {
20 class PrincipalInfo;
21 } // namespace ipc
23 namespace dom {
25 class BroadcastChannelChild;
26 class RefMessageBodyService;
27 class WorkerRef;
29 class BroadcastChannel final : public DOMEventTargetHelper {
30 friend class BroadcastChannelChild;
32 using PrincipalInfo = mozilla::ipc::PrincipalInfo;
34 public:
35 NS_DECL_ISUPPORTS_INHERITED
37 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BroadcastChannel,
38 DOMEventTargetHelper)
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,
49 ErrorResult& aRv);
51 void Close();
53 IMPL_EVENT_HANDLER(message)
54 IMPL_EVENT_HANDLER(messageerror)
56 void Shutdown();
58 private:
59 BroadcastChannel(nsIGlobalObject* aGlobal, const nsAString& aChannel,
60 const nsID& aPortUUID);
62 ~BroadcastChannel();
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;
80 nsString mChannel;
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.
87 nsID mPortUUID;
90 } // namespace dom
91 } // namespace mozilla
93 #endif // mozilla_dom_BroadcastChannel_h