Bug 1149987 - Part 7: Send the full ErrorResult in the AddAllResponse IPC message; r=bkelly

This is needed so that we can throw a TypeError from
FetchPut::FetchComplete.  In order to be able to do this, we need to
store the entire ErrorResult in the FetchPut object and deliver it to
the other side.
This commit is contained in:
Ehsan Akhgari 2015-04-06 23:56:44 -04:00
parent f56fe99956
commit 643ab9ca43
9 changed files with 31 additions and 18 deletions

10
dom/cache/Cache.cpp vendored
View File

@ -452,12 +452,16 @@ Cache::RecvMatchAllResponse(RequestId aRequestId, nsresult aRv,
}
void
Cache::RecvAddAllResponse(RequestId aRequestId, nsresult aRv)
Cache::RecvAddAllResponse(RequestId aRequestId,
const mozilla::ErrorResult& aError)
{
nsRefPtr<Promise> promise = RemoveRequestPromise(aRequestId);
if (NS_FAILED(aRv)) {
promise->MaybeReject(aRv);
if (aError.Failed()) {
// TODO: Remove this const_cast (bug 1152078).
// It is safe for now since this ErrorResult is handed off to us by IPDL
// and is thrown into the trash afterwards.
promise->MaybeReject(const_cast<ErrorResult&>(aError));
return;
}

3
dom/cache/Cache.h vendored
View File

@ -81,7 +81,8 @@ public:
const PCacheResponseOrVoid& aResponse);
void RecvMatchAllResponse(RequestId aRequestId, nsresult aRv,
const nsTArray<PCacheResponse>& aResponses);
void RecvAddAllResponse(RequestId aRequestId, nsresult aRv);
void RecvAddAllResponse(RequestId aRequestId,
const mozilla::ErrorResult& aError);
void RecvPutResponse(RequestId aRequestId, nsresult aRv);
void RecvDeleteResponse(RequestId aRequestId, nsresult aRv,

View File

@ -146,12 +146,13 @@ CacheChild::RecvMatchAllResponse(const RequestId& requestId, const nsresult& aRv
}
bool
CacheChild::RecvAddAllResponse(const RequestId& requestId, const nsresult& aRv)
CacheChild::RecvAddAllResponse(const RequestId& requestId,
const mozilla::ErrorResult& aError)
{
NS_ASSERT_OWNINGTHREAD(CacheChild);
nsRefPtr<Cache> listener = mListener;
if (listener) {
listener->RecvAddAllResponse(requestId, aRv);
listener->RecvAddAllResponse(requestId, aError);
}
return true;
}

View File

@ -55,7 +55,7 @@ private:
nsTArray<PCacheResponse>&& responses) override;
virtual bool
RecvAddAllResponse(const RequestId& requestId,
const nsresult& aRv) override;
const mozilla::ErrorResult& aError) override;
virtual bool
RecvPutResponse(const RequestId& aRequestId,
const nsresult& aRv) override;

View File

@ -23,6 +23,7 @@ namespace mozilla {
namespace dom {
namespace cache {
using mozilla::dom::ErrNum;
using mozilla::ipc::FileDescriptorSetParent;
using mozilla::ipc::PFileDescriptorSetParent;
@ -121,7 +122,10 @@ CacheParent::RecvAddAll(const RequestId& aRequestId,
aRequests, requestStreams,
getter_AddRefs(fetchPut));
if (NS_WARN_IF(NS_FAILED(rv))) {
if (!SendAddAllResponse(aRequestId, rv)) {
MOZ_ASSERT(rv != NS_ERROR_TYPE_ERR);
ErrorResult error;
error.Throw(rv);
if (!SendAddAllResponse(aRequestId, error)) {
// child process is gone, warn and allow actor to clean up normally
NS_WARNING("Cache failed to send AddAll response.");
}
@ -256,7 +260,7 @@ CacheParent::OnCacheKeys(RequestId aRequestId, nsresult aRv,
}
void
CacheParent::OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, nsresult aRv)
CacheParent::OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, const ErrorResult& aRv)
{
aFetchPut->ClearListener();
mFetchPutList.RemoveElement(aFetchPut);

View File

@ -70,7 +70,7 @@ private:
// FetchPut::Listener methods
virtual void OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId,
nsresult aRv) override;
const mozilla::ErrorResult& aRv) override;
already_AddRefed<nsIInputStream>
DeserializeCacheStream(const PCacheReadStreamOrVoid& aStreamOrVoid);

View File

@ -144,7 +144,6 @@ FetchPut::FetchPut(Listener* aListener, Manager* aManager,
, mInitiatingThread(NS_GetCurrentThread())
, mStateList(aRequests.Length())
, mPendingCount(0)
, mResult(NS_OK)
{
MOZ_ASSERT(mListener);
MOZ_ASSERT(mManager);
@ -165,6 +164,7 @@ FetchPut::~FetchPut()
MOZ_ASSERT(!mListener);
mManager->RemoveListener(this);
mManager->ReleaseCacheId(mCacheId);
mResult.ClearMessage(); // This may contain a TypeError.
}
nsresult
@ -257,7 +257,7 @@ FetchPut::FetchComplete(FetchObserver* aObserver,
{
MOZ_ASSERT(NS_IsMainThread());
if (aInternalResponse->IsError() && NS_SUCCEEDED(mResult)) {
if (aInternalResponse->IsError() && !mResult.Failed()) {
MaybeSetError(NS_ERROR_FAILURE);
}
@ -299,7 +299,7 @@ FetchPut::DoPutOnWorkerThread()
{
MOZ_ASSERT(mInitiatingThread == NS_GetCurrentThread());
if (NS_FAILED(mResult)) {
if (mResult.Failed()) {
MaybeNotifyListener();
return;
}
@ -436,10 +436,10 @@ FetchPut::OnCachePutAll(RequestId aRequestId, nsresult aRv)
void
FetchPut::MaybeSetError(nsresult aRv)
{
if (NS_FAILED(mResult) || NS_SUCCEEDED(aRv)) {
if (mResult.Failed() || NS_SUCCEEDED(aRv)) {
return;
}
mResult = aRv;
mResult.Throw(aRv);
}
void
@ -454,6 +454,7 @@ FetchPut::MaybeNotifyListener()
// doesn't happen until this method returns.
nsRefPtr<FetchPut> kungFuDeathGrip(this);
mListener->OnFetchPut(this, mRequestId, mResult);
mResult.ClearMessage(); // This may contain a TypeError.
}
nsIGlobalObject*

View File

@ -9,6 +9,7 @@
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/cache/Manager.h"
#include "mozilla/dom/cache/PCacheTypes.h"
#include "mozilla/dom/cache/Types.h"
@ -39,7 +40,7 @@ public:
{
public:
virtual void
OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, nsresult aRv) = 0;
OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, const ErrorResult& aRv) = 0;
};
static nsresult
@ -105,7 +106,7 @@ private:
nsCOMPtr<nsIThread> mInitiatingThread;
nsTArray<State> mStateList;
uint32_t mPendingCount;
nsresult mResult;
ErrorResult mResult;
nsCOMPtr<nsIRunnable> mRunnable;
public:

View File

@ -11,6 +11,7 @@ include protocol PBlob; // FIXME: bug 792908
include protocol PCacheStreamControl;
using mozilla::dom::cache::RequestId from "mozilla/dom/cache/Types.h";
using mozilla::ErrorResult from "ipc/ErrorIPCUtils.h";
include "mozilla/dom/cache/IPCUtils.h";
namespace mozilla {
@ -35,7 +36,7 @@ parent:
child:
MatchResponse(RequestId requestId, nsresult aRv, PCacheResponseOrVoid aResponse);
MatchAllResponse(RequestId requestId, nsresult aRv, PCacheResponse[] responses);
AddAllResponse(RequestId requestId, nsresult aRv);
AddAllResponse(RequestId requestId, ErrorResult aRv);
PutResponse(RequestId requestId, nsresult aRv);
DeleteResponse(RequestId requestId, nsresult aRv, bool success);
KeysResponse(RequestId requestId, nsresult aRv, PCacheRequest[] requests);