Bug 1459209 P8 Implement RemoteServiceWorkerImpl::PostMessage() across IPC and to the parent-side SWM. r=mrbkap

--HG--
extra : rebase_source : d38628cc7b8822b4213c8034f0c1dd783585ddfb
This commit is contained in:
Ben Kelly 2018-07-09 16:02:40 -07:00
Родитель fd93586372
Коммит 6323d7c413
6 изменённых файлов: 66 добавлений и 1 удалений

Просмотреть файл

@ -4,6 +4,9 @@
include protocol PBackground;
include ClientIPCTypes;
include DOMTypes;
namespace mozilla {
namespace dom {
@ -14,6 +17,8 @@ protocol PServiceWorker
parent:
async Teardown();
async PostMessage(ClonedMessageData aClonedData, ClientInfoAndState aSource);
child:
async __delete__();
};

Просмотреть файл

@ -6,9 +6,12 @@
#include "RemoteServiceWorkerImpl.h"
#include "mozilla/dom/ClientInfo.h"
#include "mozilla/dom/ClientState.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "ServiceWorkerChild.h"
#include "ServiceWorkerCloneData.h"
namespace mozilla {
namespace dom {
@ -67,7 +70,19 @@ RemoteServiceWorkerImpl::PostMessage(RefPtr<ServiceWorkerCloneData>&& aData,
const ClientInfo& aClientInfo,
const ClientState& aClientState)
{
// TODO
NS_ASSERT_OWNINGTHREAD(RemoteServiceWorkerImpl);
if (!mActor) {
return;
}
ClonedMessageData data;
if (!aData->BuildClonedMessageDataForBackgroundChild(mActor->Manager(),
data)) {
return;
}
mActor->SendPostMessage(data, ClientInfoAndState(aClientInfo.ToIPC(),
aClientState.ToIPC()));
}
RemoteServiceWorkerImpl::RemoteServiceWorkerImpl(const ServiceWorkerDescriptor& aDescriptor)

Просмотреть файл

@ -6,11 +6,16 @@
#include "ServiceWorkerParent.h"
#include "ServiceWorkerCloneData.h"
#include "ServiceWorkerProxy.h"
#include "mozilla/dom/ClientInfo.h"
#include "mozilla/dom/ClientState.h"
#include "mozilla/dom/ipc/StructuredCloneData.h"
namespace mozilla {
namespace dom {
using mozilla::dom::ipc::StructuredCloneData;
using mozilla::ipc::IPCResult;
void
@ -29,6 +34,19 @@ ServiceWorkerParent::RecvTeardown()
return IPC_OK();
}
IPCResult
ServiceWorkerParent::RecvPostMessage(const ClonedMessageData& aClonedData,
const ClientInfoAndState& aSource)
{
RefPtr<ServiceWorkerCloneData> data = new ServiceWorkerCloneData();
data->CopyFromClonedMessageDataForBackgroundParent(aClonedData);
mProxy->PostMessage(std::move(data), ClientInfo(aSource.info()),
ClientState::FromIPC(aSource.state()));
return IPC_OK();
}
ServiceWorkerParent::ServiceWorkerParent()
: mDeleteSent(false)
{

Просмотреть файл

@ -27,6 +27,10 @@ class ServiceWorkerParent final : public PServiceWorkerParent
mozilla::ipc::IPCResult
RecvTeardown() override;
mozilla::ipc::IPCResult
RecvPostMessage(const ClonedMessageData& aClonedData,
const ClientInfoAndState& aSource) override;
public:
ServiceWorkerParent();
~ServiceWorkerParent();

Просмотреть файл

@ -115,5 +115,22 @@ ServiceWorkerProxy::RevokeActor(ServiceWorkerParent* aActor)
MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget()));
}
void
ServiceWorkerProxy::PostMessage(RefPtr<ServiceWorkerCloneData>&& aData,
const ClientInfo& aClientInfo,
const ClientState& aClientState)
{
AssertIsOnBackgroundThread();
RefPtr<ServiceWorkerProxy> self = this;
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(__func__,
[self, data = std::move(aData), aClientInfo, aClientState] () mutable {
if (!self->mInfo) {
return;
}
self->mInfo->PostMessage(std::move(data), aClientInfo, aClientState);
});
MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget()));
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -13,6 +13,7 @@
namespace mozilla {
namespace dom {
class ServiceWorkerCloneData;
class ServiceWorkerInfo;
class ServiceWorkerParent;
@ -56,6 +57,11 @@ public:
void
RevokeActor(ServiceWorkerParent* aActor);
void
PostMessage(RefPtr<ServiceWorkerCloneData>&& aData,
const ClientInfo& aClientInfo,
const ClientState& aState);
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServiceWorkerProxy);
};