Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / dom / broadcastchannel / BroadcastChannelParent.cpp
blob56c528c9334ca989e0bf2afab5f6e64acde7b593
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"
15 namespace mozilla {
17 using namespace ipc;
19 namespace dom {
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);
42 return IPC_OK();
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);
53 mService = nullptr;
55 Unused << Send__delete__(this);
57 return IPC_OK();
60 void BroadcastChannelParent::ActorDestroy(ActorDestroyReason aWhy) {
61 AssertIsOnBackgroundThread();
63 if (mService) {
64 // This object is about to be released and with it, also mService will be
65 // released too.
66 mService->UnregisterActor(this, mOriginChannelKey);
70 } // namespace dom
71 } // namespace mozilla