Files
palemoon27/dom/cache/CacheParent.cpp
T
roytam1 1c5959ee6e import changes from rmottola/Arctic-Fox:
- Bug 1125750 - Check the overflow region direction to avoid unnecesary reflow for scrollable frame. (6b5067631)
- Bug 1125750 - Add auto test to detect error when using mOuter to check overflow area of a scrollable frame. (4e9c43e31)
- override -> MOZ_OVERRIDE (ed1ecc151)
- Bug 990907 - Don't add text-overflow markers while being actively scrolled by APZ. (523bc5a3e)
- Bug 945584: Part 6 - Implementation of scroll snapping (v10 Patch) (bf64eb0f3)
- Bug 945584: Part 7 - Implement Scroll Snapping for Autoscroll, - Triggering scroll snapping at the end of an autoscroll. - This enables text selection to be unencumbered by scroll snapping, while   restoring the scroll position to a valid snapping position when the drag   operation is completed. (db9ce9811)
- Bug 945584: Part 8 - Implement Scroll Snapping for Middle Mouse Button Scrolls (v2 Patch) (06d1b733d)
- some MacOS 10.5 Leopard support (6a37f6745)
- Bug 945584: Part 9 - Tests for scroll snapping (v4 Patch) (f67175387)
- Bug 1102427 - Ensure scroll parents of an active scrollframe are layerized. (910d43ec5)
- Bug 1142731 followup. Check isInterpreted() before we call environment(), because of the asmjs lambdas. (29b2acdc7)
- Bug 1161627 - part 1 - add move constructor and assignment operator for already_AddRefed&& to RefPtr; This change is prep work for future mass rewriting. (98416d45c)
- Bug 1161627 - part 2 - machine-convert TemporaryRef<T> to already_AddRefed<T>; (336e96af7)
- Bug 1161627 - part 3 - remove TemporaryRef<T> from RefPtr.h (6c3acdaed)
- Bug 940273 - Part 3 - Service Worker Cache webidl. (4b6803d0a)
- Bug 940273 - Part 4 - Initial implementation of Service Worker Cache. (74498c108)
- Bug 1133861 - Bustage fix. (4a81437c2)
2019-02-23 00:31:49 +08:00

292 lines
8.5 KiB
C++

/* -*- 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/CacheParent.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/dom/cache/AutoUtils.h"
#include "mozilla/dom/cache/CacheStreamControlParent.h"
#include "mozilla/dom/cache/ReadStream.h"
#include "mozilla/dom/cache/SavedTypes.h"
#include "mozilla/dom/cache/StreamList.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "mozilla/ipc/PBackgroundParent.h"
#include "mozilla/ipc/FileDescriptorSetParent.h"
#include "mozilla/ipc/PFileDescriptorSetParent.h"
#include "nsCOMPtr.h"
namespace mozilla {
namespace dom {
namespace cache {
using mozilla::ipc::FileDescriptorSetParent;
using mozilla::ipc::PFileDescriptorSetParent;
// Declared in ActorUtils.h
void
DeallocPCacheParent(PCacheParent* aActor)
{
delete aActor;
}
CacheParent::CacheParent(cache::Manager* aManager, CacheId aCacheId)
: mManager(aManager)
, mCacheId(aCacheId)
{
MOZ_COUNT_CTOR(cache::CacheParent);
MOZ_ASSERT(mManager);
mManager->AddRefCacheId(mCacheId);
}
CacheParent::~CacheParent()
{
MOZ_COUNT_DTOR(cache::CacheParent);
MOZ_ASSERT(!mManager);
MOZ_ASSERT(mFetchPutList.IsEmpty());
}
void
CacheParent::ActorDestroy(ActorDestroyReason aReason)
{
MOZ_ASSERT(mManager);
for (uint32_t i = 0; i < mFetchPutList.Length(); ++i) {
mFetchPutList[i]->ClearListener();
}
mFetchPutList.Clear();
mManager->RemoveListener(this);
mManager->ReleaseCacheId(mCacheId);
mManager = nullptr;
}
bool
CacheParent::RecvTeardown()
{
if (!Send__delete__(this)) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to send delete.");
}
return true;
}
bool
CacheParent::RecvMatch(const RequestId& aRequestId, const PCacheRequest& aRequest,
const PCacheQueryParams& aParams)
{
MOZ_ASSERT(mManager);
mManager->CacheMatch(this, aRequestId, mCacheId, aRequest,
aParams);
return true;
}
bool
CacheParent::RecvMatchAll(const RequestId& aRequestId,
const PCacheRequestOrVoid& aRequest,
const PCacheQueryParams& aParams)
{
MOZ_ASSERT(mManager);
mManager->CacheMatchAll(this, aRequestId, mCacheId, aRequest, aParams);
return true;
}
bool
CacheParent::RecvAddAll(const RequestId& aRequestId,
nsTArray<PCacheRequest>&& aRequests)
{
nsAutoTArray<nsCOMPtr<nsIInputStream>, 256> requestStreams;
requestStreams.SetCapacity(aRequests.Length());
for (uint32_t i = 0; i < aRequests.Length(); ++i) {
requestStreams.AppendElement(DeserializeCacheStream(aRequests[i].body()));
}
nsRefPtr<FetchPut> fetchPut;
nsresult rv = FetchPut::Create(this, mManager, aRequestId, mCacheId,
aRequests, requestStreams,
getter_AddRefs(fetchPut));
if (NS_WARN_IF(NS_FAILED(rv))) {
if (!SendAddAllResponse(aRequestId, rv)) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to send AddAll response.");
}
return true;
}
mFetchPutList.AppendElement(fetchPut.forget());
return true;
}
bool
CacheParent::RecvPut(const RequestId& aRequestId,
const CacheRequestResponse& aPut)
{
MOZ_ASSERT(mManager);
nsAutoTArray<CacheRequestResponse, 1> putList;
putList.AppendElement(aPut);
nsAutoTArray<nsCOMPtr<nsIInputStream>, 1> requestStreamList;
nsAutoTArray<nsCOMPtr<nsIInputStream>, 1> responseStreamList;
requestStreamList.AppendElement(
DeserializeCacheStream(aPut.request().body()));
responseStreamList.AppendElement(
DeserializeCacheStream(aPut.response().body()));
mManager->CachePutAll(this, aRequestId, mCacheId, putList, requestStreamList,
responseStreamList);
return true;
}
bool
CacheParent::RecvDelete(const RequestId& aRequestId,
const PCacheRequest& aRequest,
const PCacheQueryParams& aParams)
{
MOZ_ASSERT(mManager);
mManager->CacheDelete(this, aRequestId, mCacheId, aRequest, aParams);
return true;
}
bool
CacheParent::RecvKeys(const RequestId& aRequestId,
const PCacheRequestOrVoid& aRequest,
const PCacheQueryParams& aParams)
{
MOZ_ASSERT(mManager);
mManager->CacheKeys(this, aRequestId, mCacheId, aRequest, aParams);
return true;
}
void
CacheParent::OnCacheMatch(RequestId aRequestId, nsresult aRv,
const SavedResponse* aSavedResponse,
StreamList* aStreamList)
{
AutoParentResponseOrVoid response(Manager());
// no match
if (NS_FAILED(aRv) || !aSavedResponse || !aStreamList) {
if (!SendMatchResponse(aRequestId, aRv, response.SendAsResponseOrVoid())) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to send Match response.");
}
return;
}
if (aSavedResponse) {
response.Add(*aSavedResponse, aStreamList);
}
if (!SendMatchResponse(aRequestId, aRv, response.SendAsResponseOrVoid())) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to send Match response.");
}
}
void
CacheParent::OnCacheMatchAll(RequestId aRequestId, nsresult aRv,
const nsTArray<SavedResponse>& aSavedResponses,
StreamList* aStreamList)
{
AutoParentResponseList responses(Manager(), aSavedResponses.Length());
for (uint32_t i = 0; i < aSavedResponses.Length(); ++i) {
responses.Add(aSavedResponses[i], aStreamList);
}
if (!SendMatchAllResponse(aRequestId, aRv, responses.SendAsResponseList())) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to send MatchAll response.");
}
}
void
CacheParent::OnCachePutAll(RequestId aRequestId, nsresult aRv)
{
if (!SendPutResponse(aRequestId, aRv)) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to send Put response.");
}
}
void
CacheParent::OnCacheDelete(RequestId aRequestId, nsresult aRv, bool aSuccess)
{
if (!SendDeleteResponse(aRequestId, aRv, aSuccess)) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to send Delete response.");
}
}
void
CacheParent::OnCacheKeys(RequestId aRequestId, nsresult aRv,
const nsTArray<SavedRequest>& aSavedRequests,
StreamList* aStreamList)
{
AutoParentRequestList requests(Manager(), aSavedRequests.Length());
for (uint32_t i = 0; i < aSavedRequests.Length(); ++i) {
requests.Add(aSavedRequests[i], aStreamList);
}
if (!SendKeysResponse(aRequestId, aRv, requests.SendAsRequestList())) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to send Keys response.");
}
}
void
CacheParent::OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, nsresult aRv)
{
aFetchPut->ClearListener();
mFetchPutList.RemoveElement(aFetchPut);
if (!SendAddAllResponse(aRequestId, aRv)) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to send AddAll response.");
}
}
already_AddRefed<nsIInputStream>
CacheParent::DeserializeCacheStream(const PCacheReadStreamOrVoid& aStreamOrVoid)
{
if (aStreamOrVoid.type() == PCacheReadStreamOrVoid::Tvoid_t) {
return nullptr;
}
const PCacheReadStream& readStream = aStreamOrVoid.get_PCacheReadStream();
nsCOMPtr<nsIInputStream> stream = ReadStream::Create(readStream);
if (stream) {
return stream.forget();
}
nsAutoTArray<FileDescriptor, 4> fds;
if (readStream.fds().type() ==
OptionalFileDescriptorSet::TPFileDescriptorSetChild) {
FileDescriptorSetParent* fdSetActor =
static_cast<FileDescriptorSetParent*>(readStream.fds().get_PFileDescriptorSetParent());
MOZ_ASSERT(fdSetActor);
fdSetActor->ForgetFileDescriptors(fds);
MOZ_ASSERT(!fds.IsEmpty());
if (!fdSetActor->Send__delete__(fdSetActor)) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to delete fd set actor.");
}
}
return DeserializeInputStream(readStream.params(), fds);
}
} // namespace cache
} // namespace dom
} // namesapce mozilla