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"
|
|
|
|
#include "mozilla/dom/ipc/BlobParent.h"
|
2015-01-15 19:58:40 +03:00
|
|
|
#include "mozilla/ipc/BackgroundParent.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-05-06 13:07:06 +03:00
|
|
|
#include "nsIScriptSecurityManager.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();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-01-15 19:58:41 +03:00
|
|
|
BroadcastChannelParent::RecvPostMessage(const ClonedMessageData& aData)
|
2015-01-15 19:58:40 +03:00
|
|
|
{
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!mService)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-30 11:48:40 +03:00
|
|
|
mService->PostMessage(this, aData, mOriginChannelKey);
|
2015-01-15 19:58:40 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BroadcastChannelParent::RecvClose()
|
|
|
|
{
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!mService)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-05-30 11:48:40 +03:00
|
|
|
BroadcastChannelParent::Deliver(const ClonedMessageData& aData)
|
2015-01-15 19:58:40 +03:00
|
|
|
{
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
2016-05-30 11:48:40 +03:00
|
|
|
// Duplicate the data for this parent.
|
|
|
|
ClonedMessageData newData(aData);
|
2015-01-15 19:58:41 +03:00
|
|
|
|
2016-05-30 11:48:40 +03:00
|
|
|
// Create new BlobParent objects for this message.
|
|
|
|
for (uint32_t i = 0, len = newData.blobsParent().Length(); i < len; ++i) {
|
|
|
|
RefPtr<BlobImpl> impl =
|
|
|
|
static_cast<BlobParent*>(newData.blobsParent()[i])->GetBlobImpl();
|
2015-01-15 19:58:41 +03:00
|
|
|
|
2016-05-30 11:48:40 +03:00
|
|
|
PBlobParent* blobParent =
|
|
|
|
BackgroundParent::GetOrCreateActorForBlobImpl(Manager(), impl);
|
|
|
|
if (!blobParent) {
|
|
|
|
return;
|
2015-01-15 19:58:41 +03:00
|
|
|
}
|
|
|
|
|
2016-05-30 11:48:40 +03:00
|
|
|
newData.blobsParent()[i] = blobParent;
|
2015-01-15 19:58:40 +03:00
|
|
|
}
|
2016-05-30 11:48:40 +03:00
|
|
|
|
|
|
|
Unused << SendNotify(newData);
|
2015-01-15 19:58:40 +03:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|