Line data Source code
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 : #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"
14 : #include "nsIScriptSecurityManager.h"
15 :
16 : namespace mozilla {
17 :
18 : using namespace ipc;
19 :
20 : namespace dom {
21 :
22 0 : BroadcastChannelParent::BroadcastChannelParent(const nsAString& aOriginChannelKey)
23 0 : : mService(BroadcastChannelService::GetOrCreate())
24 0 : , mOriginChannelKey(aOriginChannelKey)
25 : {
26 0 : AssertIsOnBackgroundThread();
27 0 : mService->RegisterActor(this, mOriginChannelKey);
28 0 : }
29 :
30 0 : BroadcastChannelParent::~BroadcastChannelParent()
31 : {
32 0 : AssertIsOnBackgroundThread();
33 0 : }
34 :
35 : mozilla::ipc::IPCResult
36 0 : BroadcastChannelParent::RecvPostMessage(const ClonedMessageData& aData)
37 : {
38 0 : AssertIsOnBackgroundThread();
39 :
40 0 : if (NS_WARN_IF(!mService)) {
41 0 : return IPC_FAIL_NO_REASON(this);
42 : }
43 :
44 0 : mService->PostMessage(this, aData, mOriginChannelKey);
45 0 : return IPC_OK();
46 : }
47 :
48 : mozilla::ipc::IPCResult
49 0 : BroadcastChannelParent::RecvClose()
50 : {
51 0 : AssertIsOnBackgroundThread();
52 :
53 0 : if (NS_WARN_IF(!mService)) {
54 0 : return IPC_FAIL_NO_REASON(this);
55 : }
56 :
57 0 : mService->UnregisterActor(this, mOriginChannelKey);
58 0 : mService = nullptr;
59 :
60 0 : Unused << Send__delete__(this);
61 :
62 0 : return IPC_OK();
63 : }
64 :
65 : void
66 0 : BroadcastChannelParent::ActorDestroy(ActorDestroyReason aWhy)
67 : {
68 0 : AssertIsOnBackgroundThread();
69 :
70 0 : if (mService) {
71 : // This object is about to be released and with it, also mService will be
72 : // released too.
73 0 : mService->UnregisterActor(this, mOriginChannelKey);
74 : }
75 0 : }
76 :
77 : } // namespace dom
78 : } // namespace mozilla
|