2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-01-15 19:58:40 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "BroadcastChannelParent.h"
|
|
|
|
#include "BroadcastChannelService.h"
|
2015-01-15 19:58:41 +03:00
|
|
|
#include "mozilla/dom/File.h"
|
2017-04-24 13:09:40 +03:00
|
|
|
#include "mozilla/dom/IPCBlobUtils.h"
|
2015-01-15 19:58:40 +03:00
|
|
|
#include "mozilla/ipc/BackgroundParent.h"
|
2017-04-24 13:09:40 +03:00
|
|
|
#include "mozilla/ipc/IPCStreamUtils.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace ipc;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2016-05-30 11:48:40 +03:00
|
|
|
BroadcastChannelParent::BroadcastChannelParent(
|
|
|
|
const nsAString& aOriginChannelKey)
|
2015-01-15 19:58:40 +03:00
|
|
|
: mService(BroadcastChannelService::GetOrCreate()),
|
2016-05-30 11:48:40 +03:00
|
|
|
mOriginChannelKey(aOriginChannelKey) {
|
2015-01-15 19:58:40 +03:00
|
|
|
AssertIsOnBackgroundThread();
|
2016-05-30 11:48:40 +03:00
|
|
|
mService->RegisterActor(this, mOriginChannelKey);
|
2015-01-15 19:58:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BroadcastChannelParent::~BroadcastChannelParent() {
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
}
|
|
|
|
|
2015-01-15 19:58:41 +03:00
|
|
|
mozilla::ipc::IPCResult BroadcastChannelParent::RecvPostMessage(
|
2020-01-24 11:00:08 +03:00
|
|
|
const MessageData& aData) {
|
2015-01-15 19:58:40 +03:00
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!mService)) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2015-01-15 19:58:40 +03:00
|
|
|
}
|
|
|
|
|
2016-05-30 11:48:40 +03:00
|
|
|
mService->PostMessage(this, aData, mOriginChannelKey);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-01-15 19:58:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult BroadcastChannelParent::RecvClose() {
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!mService)) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2015-01-15 19:58:40 +03:00
|
|
|
}
|
|
|
|
|
2016-05-30 11:48:40 +03:00
|
|
|
mService->UnregisterActor(this, mOriginChannelKey);
|
2015-01-15 19:58:40 +03:00
|
|
|
mService = nullptr;
|
|
|
|
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << Send__delete__(this);
|
2015-01-15 19:58:40 +03:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-01-15 19:58:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BroadcastChannelParent::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
|
|
|
if (mService) {
|
|
|
|
// This object is about to be released and with it, also mService will be
|
|
|
|
// released too.
|
2016-05-30 11:48:40 +03:00
|
|
|
mService->UnregisterActor(this, mOriginChannelKey);
|
2015-01-15 19:58:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|