2015-03-02 16:20:00 +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: */
|
|
|
|
/* 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 "mozilla/dom/cache/CacheStorageParent.h"
|
|
|
|
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-03-02 16:20:00 +03:00
|
|
|
#include "mozilla/dom/cache/ActorUtils.h"
|
2015-04-16 22:00:15 +03:00
|
|
|
#include "mozilla/dom/cache/CacheOpParent.h"
|
2015-03-02 16:20:00 +03:00
|
|
|
#include "mozilla/dom/cache/ManagerId.h"
|
2019-02-23 19:03:40 +03:00
|
|
|
#include "mozilla/dom/quota/QuotaManager.h"
|
2015-03-02 16:20:00 +03:00
|
|
|
#include "mozilla/ipc/PBackgroundParent.h"
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom::cache {
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2019-02-23 19:03:40 +03:00
|
|
|
using mozilla::dom::quota::QuotaManager;
|
2015-03-02 16:20:00 +03:00
|
|
|
using mozilla::ipc::PBackgroundParent;
|
|
|
|
using mozilla::ipc::PrincipalInfo;
|
|
|
|
|
|
|
|
// declared in ActorUtils.h
|
|
|
|
PCacheStorageParent* AllocPCacheStorageParent(
|
|
|
|
PBackgroundParent* aManagingActor, Namespace aNamespace,
|
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipalInfo) {
|
2019-02-23 19:03:40 +03:00
|
|
|
if (NS_WARN_IF(!QuotaManager::IsPrincipalInfoValid(aPrincipalInfo))) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
return new CacheStorageParent(aManagingActor, aNamespace, aPrincipalInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
// declared in ActorUtils.h
|
|
|
|
void DeallocPCacheStorageParent(PCacheStorageParent* aActor) { delete aActor; }
|
|
|
|
|
|
|
|
CacheStorageParent::CacheStorageParent(PBackgroundParent* aManagingActor,
|
|
|
|
Namespace aNamespace,
|
|
|
|
const PrincipalInfo& aPrincipalInfo)
|
|
|
|
: mNamespace(aNamespace), mVerifiedStatus(NS_OK) {
|
|
|
|
MOZ_COUNT_CTOR(cache::CacheStorageParent);
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aManagingActor);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
// Start the async principal verification process immediately.
|
2021-01-21 14:58:37 +03:00
|
|
|
mVerifier = PrincipalVerifier::CreateAndDispatch(*this, aManagingActor,
|
2015-03-02 16:20:00 +03:00
|
|
|
aPrincipalInfo);
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mVerifier);
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CacheStorageParent::~CacheStorageParent() {
|
|
|
|
MOZ_COUNT_DTOR(cache::CacheStorageParent);
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mVerifier);
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CacheStorageParent::ActorDestroy(ActorDestroyReason aReason) {
|
|
|
|
if (mVerifier) {
|
2021-01-21 14:58:37 +03:00
|
|
|
mVerifier->RemoveListener(*this);
|
2015-03-02 16:20:00 +03:00
|
|
|
mVerifier = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
PCacheOpParent* CacheStorageParent::AllocPCacheOpParent(
|
|
|
|
const CacheOpArgs& aOpArgs) {
|
|
|
|
if (aOpArgs.type() != CacheOpArgs::TStorageMatchArgs &&
|
|
|
|
aOpArgs.type() != CacheOpArgs::TStorageHasArgs &&
|
|
|
|
aOpArgs.type() != CacheOpArgs::TStorageOpenArgs &&
|
|
|
|
aOpArgs.type() != CacheOpArgs::TStorageDeleteArgs &&
|
|
|
|
aOpArgs.type() != CacheOpArgs::TStorageKeysArgs) {
|
|
|
|
MOZ_CRASH("Invalid operation sent to CacheStorage actor!");
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
return new CacheOpParent(Manager(), mNamespace, aOpArgs);
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
bool CacheStorageParent::DeallocPCacheOpParent(PCacheOpParent* aActor) {
|
|
|
|
delete aActor;
|
2015-04-15 01:27:48 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
mozilla::ipc::IPCResult CacheStorageParent::RecvPCacheOpConstructor(
|
|
|
|
PCacheOpParent* aActor, const CacheOpArgs& aOpArgs) {
|
|
|
|
auto actor = static_cast<CacheOpParent*>(aActor);
|
2015-04-15 10:55:53 +03:00
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
if (mVerifier) {
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mManagerId);
|
2015-04-16 22:00:15 +03:00
|
|
|
actor->WaitForVerification(mVerifier);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-04-15 10:55:53 +03:00
|
|
|
}
|
|
|
|
|
2015-05-01 18:15:52 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(mVerifiedStatus))) {
|
2016-07-01 07:17:00 +03:00
|
|
|
ErrorResult result(mVerifiedStatus);
|
2021-10-06 16:59:09 +03:00
|
|
|
|
|
|
|
QM_WARNONLY_TRY(OkIf(
|
|
|
|
CacheOpParent::Send__delete__(actor, std::move(result), void_t())));
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-04-15 10:55:53 +03:00
|
|
|
}
|
|
|
|
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mManagerId);
|
2015-04-16 22:00:15 +03:00
|
|
|
actor->Execute(mManagerId);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-04-15 10:55:53 +03:00
|
|
|
}
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
mozilla::ipc::IPCResult CacheStorageParent::RecvTeardown() {
|
2021-03-24 15:27:53 +03:00
|
|
|
// If child process is gone, warn and allow actor to clean up normally
|
|
|
|
QM_WARNONLY_TRY(OkIf(Send__delete__(this)));
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-03-02 16:20:00 +03:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:13:07 +03:00
|
|
|
void CacheStorageParent::OnPrincipalVerified(
|
|
|
|
nsresult aRv, const SafeRefPtr<ManagerId>& aManagerId) {
|
2017-01-06 23:41:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mVerifier);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mManagerId);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(mVerifiedStatus));
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(aRv))) {
|
|
|
|
mVerifiedStatus = aRv;
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:13:07 +03:00
|
|
|
mManagerId = aManagerId.clonePtr();
|
2021-01-21 14:58:37 +03:00
|
|
|
mVerifier->RemoveListener(*this);
|
2015-03-02 16:20:00 +03:00
|
|
|
mVerifier = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom::cache
|