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 #include "BroadcastChannelParent.h"
8 #include "BroadcastChannelService.h"
9 #include "mozilla/dom/File.h"
10 #include "mozilla/dom/IPCBlobUtils.h"
11 #include "mozilla/ipc/BackgroundParent.h"
12 #include "mozilla/ipc/IPCStreamUtils.h"
13 #include "mozilla/Unused.h"
21 BroadcastChannelParent::BroadcastChannelParent(
22 const nsAString
& aOriginChannelKey
)
23 : mService(BroadcastChannelService::GetOrCreate()),
24 mOriginChannelKey(aOriginChannelKey
) {
25 AssertIsOnBackgroundThread();
26 mService
->RegisterActor(this, mOriginChannelKey
);
29 BroadcastChannelParent::~BroadcastChannelParent() {
30 AssertIsOnBackgroundThread();
33 mozilla::ipc::IPCResult
BroadcastChannelParent::RecvPostMessage(
34 const MessageData
& aData
) {
35 AssertIsOnBackgroundThread();
37 if (NS_WARN_IF(!mService
)) {
38 return IPC_FAIL_NO_REASON(this);
41 mService
->PostMessage(this, aData
, mOriginChannelKey
);
45 mozilla::ipc::IPCResult
BroadcastChannelParent::RecvClose() {
46 AssertIsOnBackgroundThread();
48 if (NS_WARN_IF(!mService
)) {
49 return IPC_FAIL_NO_REASON(this);
52 mService
->UnregisterActor(this, mOriginChannelKey
);
55 Unused
<< Send__delete__(this);
60 void BroadcastChannelParent::ActorDestroy(ActorDestroyReason aWhy
) {
61 AssertIsOnBackgroundThread();
64 // This object is about to be released and with it, also mService will be
66 mService
->UnregisterActor(this, mOriginChannelKey
);
71 } // namespace mozilla