2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2015-08-06 00:25:39 +03:00
|
|
|
*
|
|
|
|
* 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"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2015-08-06 00:25:39 +03:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "WebBrowserPersistLocalDocument.h"
|
|
|
|
#include "WebBrowserPersistResourcesChild.h"
|
|
|
|
#include "WebBrowserPersistSerializeChild.h"
|
2019-10-28 11:46:50 +03:00
|
|
|
#include "mozilla/StaticPrefs_fission.h"
|
2020-11-11 14:14:00 +03:00
|
|
|
#include "mozilla/net/CookieJarSettings.h"
|
2015-08-06 00:25:39 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2020-03-09 17:57:23 +03:00
|
|
|
WebBrowserPersistDocumentChild::WebBrowserPersistDocumentChild() = default;
|
2015-08-06 00:25:39 +03:00
|
|
|
|
2016-11-22 15:56:19 +03:00
|
|
|
WebBrowserPersistDocumentChild::~WebBrowserPersistDocumentChild() = default;
|
2015-08-06 00:25:39 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void WebBrowserPersistDocumentChild::Start(dom::Document* 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;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-06-22 17:41:39 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
2019-07-16 21:02:16 +03:00
|
|
|
nsCOMPtr<nsIReferrerInfo> referrerInfo;
|
2020-11-11 14:14:00 +03:00
|
|
|
nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
|
2015-08-06 00:25:39 +03:00
|
|
|
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->GetContentDisposition(attrs.contentDisposition()));
|
2019-03-21 23:33:51 +03:00
|
|
|
|
2020-09-08 16:06:29 +03:00
|
|
|
attrs.sessionHistoryCacheKey() = aDocument->GetCacheKey();
|
2019-03-21 23:33:51 +03:00
|
|
|
|
2015-08-06 00:25:39 +03:00
|
|
|
ENSURE(aDocument->GetPersistFlags(&(attrs.persistFlags())));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-06-22 17:41:39 +03:00
|
|
|
ENSURE(aDocument->GetPrincipal(getter_AddRefs(principal)));
|
|
|
|
ENSURE(ipc::PrincipalToPrincipalInfo(principal, &(attrs.principal())));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-16 21:02:16 +03:00
|
|
|
ENSURE(aDocument->GetReferrerInfo(getter_AddRefs(referrerInfo)));
|
|
|
|
attrs.referrerInfo() = referrerInfo;
|
|
|
|
|
2020-11-11 14:14:00 +03:00
|
|
|
ENSURE(aDocument->GetCookieJarSettings(getter_AddRefs(cookieJarSettings)));
|
|
|
|
net::CookieJarSettings::Cast(cookieJarSettings)
|
|
|
|
->Serialize(attrs.cookieJarSettings());
|
|
|
|
|
2015-08-06 00:25:39 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult 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
|