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"
|
|
|
|
#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-24 10:37:23 +03:00
|
|
|
BroadcastChannelParent::BroadcastChannelParent(const nsACString& aOrigin,
|
|
|
|
const nsAString& aChannel,
|
|
|
|
bool aPrivateBrowsing)
|
2015-01-15 19:58:40 +03:00
|
|
|
: mService(BroadcastChannelService::GetOrCreate())
|
2016-05-24 10:37:23 +03:00
|
|
|
, mOrigin(aOrigin)
|
|
|
|
, mChannel(aChannel)
|
|
|
|
, mPrivateBrowsing(aPrivateBrowsing)
|
2015-01-15 19:58:40 +03:00
|
|
|
{
|
|
|
|
AssertIsOnBackgroundThread();
|
2016-05-24 10:37:23 +03:00
|
|
|
mService->RegisterActor(this);
|
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-24 10:37:23 +03:00
|
|
|
mService->PostMessage(this, aData, mOrigin, mChannel, mPrivateBrowsing);
|
2015-01-15 19:58:40 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BroadcastChannelParent::RecvClose()
|
|
|
|
{
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!mService)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-24 10:37:23 +03:00
|
|
|
mService->UnregisterActor(this);
|
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-24 10:37:23 +03:00
|
|
|
mService->UnregisterActor(this);
|
2015-01-15 19:58:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-05-24 10:37:23 +03:00
|
|
|
BroadcastChannelParent::CheckAndDeliver(const ClonedMessageData& aData,
|
|
|
|
const nsCString& aOrigin,
|
|
|
|
const nsString& aChannel,
|
|
|
|
bool aPrivateBrowsing)
|
2015-01-15 19:58:40 +03:00
|
|
|
{
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
2016-05-24 10:37:23 +03:00
|
|
|
if (aOrigin == mOrigin &&
|
|
|
|
aChannel == mChannel &&
|
|
|
|
aPrivateBrowsing == mPrivateBrowsing) {
|
|
|
|
// Duplicate the data for this parent.
|
|
|
|
ClonedMessageData newData(aData);
|
2015-01-15 19:58:41 +03:00
|
|
|
|
2016-05-24 10:37:23 +03:00
|
|
|
// Ricreate the BlobParent for this new 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-24 10:37:23 +03:00
|
|
|
PBlobParent* blobParent =
|
|
|
|
BackgroundParent::GetOrCreateActorForBlobImpl(Manager(), impl);
|
|
|
|
if (!blobParent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newData.blobsParent()[i] = blobParent;
|
2015-01-15 19:58:41 +03:00
|
|
|
}
|
|
|
|
|
2016-05-24 10:37:23 +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
|