2015-08-06 00:25:39 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* 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 "WebBrowserPersistDocumentChild.h"
|
|
|
|
|
2017-03-09 16:09:11 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
#include "mozilla/ipc/IPCStreamUtils.h"
|
2015-08-06 00:25:39 +03:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "WebBrowserPersistLocalDocument.h"
|
|
|
|
#include "WebBrowserPersistResourcesChild.h"
|
|
|
|
#include "WebBrowserPersistSerializeChild.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
WebBrowserPersistDocumentChild::WebBrowserPersistDocumentChild()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-22 15:56:19 +03:00
|
|
|
WebBrowserPersistDocumentChild::~WebBrowserPersistDocumentChild() = default;
|
2015-08-06 00:25:39 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
WebBrowserPersistDocumentChild::Start(nsIDocument* aDocument)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebBrowserPersistLocalDocument> doc;
|
2015-08-06 00:25:39 +03:00
|
|
|
if (aDocument) {
|
|
|
|
doc = new WebBrowserPersistLocalDocument(aDocument);
|
|
|
|
}
|
|
|
|
Start(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebBrowserPersistDocumentChild::Start(nsIWebBrowserPersistDocument* aDocument)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mDocument);
|
|
|
|
if (!aDocument) {
|
|
|
|
SendInitFailure(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebBrowserPersistDocumentAttrs attrs;
|
|
|
|
nsCOMPtr<nsIInputStream> postDataStream;
|
|
|
|
#define ENSURE(e) do { \
|
|
|
|
nsresult rv = (e); \
|
|
|
|
if (NS_FAILED(rv)) { \
|
|
|
|
SendInitFailure(rv); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
ENSURE(aDocument->GetIsPrivate(&(attrs.isPrivate())));
|
|
|
|
ENSURE(aDocument->GetDocumentURI(attrs.documentURI()));
|
|
|
|
ENSURE(aDocument->GetBaseURI(attrs.baseURI()));
|
|
|
|
ENSURE(aDocument->GetContentType(attrs.contentType()));
|
|
|
|
ENSURE(aDocument->GetCharacterSet(attrs.characterSet()));
|
|
|
|
ENSURE(aDocument->GetTitle(attrs.title()));
|
|
|
|
ENSURE(aDocument->GetReferrer(attrs.referrer()));
|
|
|
|
ENSURE(aDocument->GetContentDisposition(attrs.contentDisposition()));
|
|
|
|
ENSURE(aDocument->GetCacheKey(&(attrs.cacheKey())));
|
|
|
|
ENSURE(aDocument->GetPersistFlags(&(attrs.persistFlags())));
|
|
|
|
ENSURE(aDocument->GetPostData(getter_AddRefs(postDataStream)));
|
|
|
|
#undef ENSURE
|
2017-03-09 16:09:11 +03:00
|
|
|
|
|
|
|
mozilla::ipc::AutoIPCStream autoStream;
|
|
|
|
autoStream.Serialize(postDataStream,
|
|
|
|
static_cast<mozilla::dom::ContentChild*>(Manager()));
|
|
|
|
|
2015-08-06 00:25:39 +03:00
|
|
|
mDocument = aDocument;
|
2017-03-09 16:09:11 +03:00
|
|
|
SendAttributes(attrs, autoStream.TakeOptionalValue());
|
2015-08-06 00:25:39 +03:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2015-08-06 00:25:39 +03:00
|
|
|
WebBrowserPersistDocumentChild::RecvSetPersistFlags(const uint32_t& aNewFlags)
|
|
|
|
{
|
|
|
|
mDocument->SetPersistFlags(aNewFlags);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-08-06 00:25:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PWebBrowserPersistResourcesChild*
|
|
|
|
WebBrowserPersistDocumentChild::AllocPWebBrowserPersistResourcesChild()
|
|
|
|
{
|
|
|
|
auto* actor = new WebBrowserPersistResourcesChild();
|
|
|
|
NS_ADDREF(actor);
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2015-08-06 00:25:39 +03:00
|
|
|
WebBrowserPersistDocumentChild::RecvPWebBrowserPersistResourcesConstructor(PWebBrowserPersistResourcesChild* aActor)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebBrowserPersistResourcesChild> visitor =
|
2015-08-06 00:25:39 +03:00
|
|
|
static_cast<WebBrowserPersistResourcesChild*>(aActor);
|
|
|
|
nsresult rv = mDocument->ReadResources(visitor);
|
|
|
|
if (NS_FAILED(rv)) {
|
2015-09-21 15:54:00 +03:00
|
|
|
// This is a sync failure on the child side but an async
|
|
|
|
// failure on the parent side -- it already got NS_OK from
|
|
|
|
// ReadResources, so the error has to be reported via the
|
|
|
|
// visitor instead.
|
2015-08-06 00:25:39 +03:00
|
|
|
visitor->EndVisit(mDocument, rv);
|
|
|
|
}
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-08-06 00:25:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebBrowserPersistDocumentChild::DeallocPWebBrowserPersistResourcesChild(PWebBrowserPersistResourcesChild* aActor)
|
|
|
|
{
|
|
|
|
auto* castActor =
|
|
|
|
static_cast<WebBrowserPersistResourcesChild*>(aActor);
|
|
|
|
NS_RELEASE(castActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PWebBrowserPersistSerializeChild*
|
|
|
|
WebBrowserPersistDocumentChild::AllocPWebBrowserPersistSerializeChild(
|
|
|
|
const WebBrowserPersistURIMap& aMap,
|
|
|
|
const nsCString& aRequestedContentType,
|
|
|
|
const uint32_t& aEncoderFlags,
|
|
|
|
const uint32_t& aWrapColumn)
|
|
|
|
{
|
|
|
|
auto* actor = new WebBrowserPersistSerializeChild(aMap);
|
|
|
|
NS_ADDREF(actor);
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2015-08-06 00:25:39 +03:00
|
|
|
WebBrowserPersistDocumentChild::RecvPWebBrowserPersistSerializeConstructor(
|
|
|
|
PWebBrowserPersistSerializeChild* aActor,
|
|
|
|
const WebBrowserPersistURIMap& aMap,
|
|
|
|
const nsCString& aRequestedContentType,
|
|
|
|
const uint32_t& aEncoderFlags,
|
|
|
|
const uint32_t& aWrapColumn)
|
|
|
|
{
|
|
|
|
auto* castActor =
|
|
|
|
static_cast<WebBrowserPersistSerializeChild*>(aActor);
|
|
|
|
// This actor performs the roles of: completion, URI map, and output stream.
|
|
|
|
nsresult rv = mDocument->WriteContent(castActor,
|
|
|
|
castActor,
|
|
|
|
aRequestedContentType,
|
|
|
|
aEncoderFlags,
|
|
|
|
aWrapColumn,
|
|
|
|
castActor);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
castActor->OnFinish(mDocument, castActor, aRequestedContentType, rv);
|
|
|
|
}
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-08-06 00:25:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebBrowserPersistDocumentChild::DeallocPWebBrowserPersistSerializeChild(PWebBrowserPersistSerializeChild* aActor)
|
|
|
|
{
|
|
|
|
auto* castActor =
|
|
|
|
static_cast<WebBrowserPersistSerializeChild*>(aActor);
|
|
|
|
NS_RELEASE(castActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|