1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "WebBrowserPersistDocumentChild.h"
9 #include "mozilla/dom/ContentChild.h"
10 #include "mozilla/ipc/IPCStreamUtils.h"
11 #include "mozilla/dom/Document.h"
12 #include "nsIInputStream.h"
13 #include "WebBrowserPersistLocalDocument.h"
14 #include "WebBrowserPersistResourcesChild.h"
15 #include "WebBrowserPersistSerializeChild.h"
16 #include "mozilla/StaticPrefs_fission.h"
17 #include "mozilla/net/CookieJarSettings.h"
21 WebBrowserPersistDocumentChild::WebBrowserPersistDocumentChild() = default;
23 WebBrowserPersistDocumentChild::~WebBrowserPersistDocumentChild() = default;
25 void WebBrowserPersistDocumentChild::Start(dom::Document
* aDocument
) {
26 RefPtr
<WebBrowserPersistLocalDocument
> doc
;
28 doc
= new WebBrowserPersistLocalDocument(aDocument
);
33 void WebBrowserPersistDocumentChild::Start(
34 nsIWebBrowserPersistDocument
* aDocument
) {
35 MOZ_ASSERT(!mDocument
);
37 SendInitFailure(NS_ERROR_FAILURE
);
41 nsCOMPtr
<nsIPrincipal
> principal
;
42 nsCOMPtr
<nsIReferrerInfo
> referrerInfo
;
43 nsCOMPtr
<nsICookieJarSettings
> cookieJarSettings
;
44 WebBrowserPersistDocumentAttrs attrs
;
45 nsCOMPtr
<nsIInputStream
> postDataStream
;
49 if (NS_FAILED(rv)) { \
50 SendInitFailure(rv); \
54 ENSURE(aDocument
->GetIsPrivate(&(attrs
.isPrivate())));
55 ENSURE(aDocument
->GetDocumentURI(attrs
.documentURI()));
56 ENSURE(aDocument
->GetBaseURI(attrs
.baseURI()));
57 ENSURE(aDocument
->GetContentType(attrs
.contentType()));
58 ENSURE(aDocument
->GetCharacterSet(attrs
.characterSet()));
59 ENSURE(aDocument
->GetTitle(attrs
.title()));
60 ENSURE(aDocument
->GetContentDisposition(attrs
.contentDisposition()));
62 attrs
.sessionHistoryCacheKey() = aDocument
->GetCacheKey();
64 ENSURE(aDocument
->GetPersistFlags(&(attrs
.persistFlags())));
66 ENSURE(aDocument
->GetPrincipal(getter_AddRefs(principal
)));
67 ENSURE(ipc::PrincipalToPrincipalInfo(principal
, &(attrs
.principal())));
69 ENSURE(aDocument
->GetReferrerInfo(getter_AddRefs(referrerInfo
)));
70 attrs
.referrerInfo() = referrerInfo
;
72 ENSURE(aDocument
->GetCookieJarSettings(getter_AddRefs(cookieJarSettings
)));
73 net::CookieJarSettings::Cast(cookieJarSettings
)
74 ->Serialize(attrs
.cookieJarSettings());
76 ENSURE(aDocument
->GetPostData(getter_AddRefs(postDataStream
)));
79 mozilla::ipc::AutoIPCStream autoStream
;
80 autoStream
.Serialize(postDataStream
,
81 static_cast<mozilla::dom::ContentChild
*>(Manager()));
83 mDocument
= aDocument
;
84 SendAttributes(attrs
, autoStream
.TakeOptionalValue());
87 mozilla::ipc::IPCResult
WebBrowserPersistDocumentChild::RecvSetPersistFlags(
88 const uint32_t& aNewFlags
) {
89 mDocument
->SetPersistFlags(aNewFlags
);
93 PWebBrowserPersistResourcesChild
*
94 WebBrowserPersistDocumentChild::AllocPWebBrowserPersistResourcesChild() {
95 auto* actor
= new WebBrowserPersistResourcesChild();
100 mozilla::ipc::IPCResult
101 WebBrowserPersistDocumentChild::RecvPWebBrowserPersistResourcesConstructor(
102 PWebBrowserPersistResourcesChild
* aActor
) {
103 RefPtr
<WebBrowserPersistResourcesChild
> visitor
=
104 static_cast<WebBrowserPersistResourcesChild
*>(aActor
);
105 nsresult rv
= mDocument
->ReadResources(visitor
);
107 // This is a sync failure on the child side but an async
108 // failure on the parent side -- it already got NS_OK from
109 // ReadResources, so the error has to be reported via the
111 visitor
->EndVisit(mDocument
, rv
);
116 bool WebBrowserPersistDocumentChild::DeallocPWebBrowserPersistResourcesChild(
117 PWebBrowserPersistResourcesChild
* aActor
) {
118 auto* castActor
= static_cast<WebBrowserPersistResourcesChild
*>(aActor
);
119 NS_RELEASE(castActor
);
123 PWebBrowserPersistSerializeChild
*
124 WebBrowserPersistDocumentChild::AllocPWebBrowserPersistSerializeChild(
125 const WebBrowserPersistURIMap
& aMap
, const nsCString
& aRequestedContentType
,
126 const uint32_t& aEncoderFlags
, const uint32_t& aWrapColumn
) {
127 auto* actor
= new WebBrowserPersistSerializeChild(aMap
);
132 mozilla::ipc::IPCResult
133 WebBrowserPersistDocumentChild::RecvPWebBrowserPersistSerializeConstructor(
134 PWebBrowserPersistSerializeChild
* aActor
,
135 const WebBrowserPersistURIMap
& aMap
, const nsCString
& aRequestedContentType
,
136 const uint32_t& aEncoderFlags
, const uint32_t& aWrapColumn
) {
137 auto* castActor
= static_cast<WebBrowserPersistSerializeChild
*>(aActor
);
138 // This actor performs the roles of: completion, URI map, and output stream.
140 mDocument
->WriteContent(castActor
, castActor
, aRequestedContentType
,
141 aEncoderFlags
, aWrapColumn
, castActor
);
143 castActor
->OnFinish(mDocument
, castActor
, aRequestedContentType
, rv
);
148 bool WebBrowserPersistDocumentChild::DeallocPWebBrowserPersistSerializeChild(
149 PWebBrowserPersistSerializeChild
* aActor
) {
150 auto* castActor
= static_cast<WebBrowserPersistSerializeChild
*>(aActor
);
151 NS_RELEASE(castActor
);
155 } // namespace mozilla