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 "WebBrowserPersistRemoteDocument.h"
8 #include "WebBrowserPersistDocumentParent.h"
9 #include "WebBrowserPersistResourcesParent.h"
10 #include "WebBrowserPersistSerializeParent.h"
11 #include "mozilla/Unused.h"
12 #include "mozilla/ipc/BackgroundUtils.h"
13 #include "mozilla/net/CookieJarSettings.h"
16 #include "nsIPrincipal.h"
17 #include "nsISHEntry.h"
21 NS_IMPL_ISUPPORTS(WebBrowserPersistRemoteDocument
, nsIWebBrowserPersistDocument
)
23 WebBrowserPersistRemoteDocument ::WebBrowserPersistRemoteDocument(
24 WebBrowserPersistDocumentParent
* aActor
, const Attrs
& aAttrs
,
25 nsIInputStream
* aPostData
)
26 : mActor(aActor
), mAttrs(aAttrs
), mPostData(aPostData
) {
27 auto principalOrErr
= ipc::PrincipalInfoToPrincipal(mAttrs
.principal());
28 if (principalOrErr
.isOk()) {
29 mPrincipal
= principalOrErr
.unwrap();
31 NS_WARNING("Failed to obtain principal!");
34 net::CookieJarSettings::Deserialize(mAttrs
.cookieJarSettings(),
35 getter_AddRefs(mCookieJarSettings
));
38 WebBrowserPersistRemoteDocument::~WebBrowserPersistRemoteDocument() {
40 Unused
<< WebBrowserPersistDocumentParent::Send__delete__(mActor
);
41 // That will call mActor->ActorDestroy, which calls this->ActorDestroy
42 // (whether or not the IPC send succeeds).
47 void WebBrowserPersistRemoteDocument::ActorDestroy(void) { mActor
= nullptr; }
50 WebBrowserPersistRemoteDocument::GetIsClosed(bool* aIsClosed
) {
56 WebBrowserPersistRemoteDocument::GetIsPrivate(bool* aIsPrivate
) {
57 *aIsPrivate
= mAttrs
.isPrivate();
62 WebBrowserPersistRemoteDocument::GetDocumentURI(nsACString
& aURISpec
) {
63 aURISpec
= mAttrs
.documentURI();
68 WebBrowserPersistRemoteDocument::GetBaseURI(nsACString
& aURISpec
) {
69 aURISpec
= mAttrs
.baseURI();
74 WebBrowserPersistRemoteDocument::GetContentType(nsACString
& aContentType
) {
75 aContentType
= mAttrs
.contentType();
80 WebBrowserPersistRemoteDocument::GetCharacterSet(nsACString
& aCharSet
) {
81 aCharSet
= mAttrs
.characterSet();
86 WebBrowserPersistRemoteDocument::GetTitle(nsAString
& aTitle
) {
87 aTitle
= mAttrs
.title();
92 WebBrowserPersistRemoteDocument::GetReferrerInfo(
93 nsIReferrerInfo
** aReferrerInfo
) {
94 *aReferrerInfo
= mAttrs
.referrerInfo();
95 NS_IF_ADDREF(*aReferrerInfo
);
100 WebBrowserPersistRemoteDocument::GetCookieJarSettings(
101 nsICookieJarSettings
** aCookieJarSettings
) {
102 nsCOMPtr
<nsICookieJarSettings
> cookieJarSettings
= mCookieJarSettings
;
103 cookieJarSettings
.forget(aCookieJarSettings
);
108 WebBrowserPersistRemoteDocument::GetContentDisposition(nsAString
& aDisp
) {
109 aDisp
= mAttrs
.contentDisposition();
114 WebBrowserPersistRemoteDocument::GetCacheKey(uint32_t* aCacheKey
) {
115 *aCacheKey
= mAttrs
.sessionHistoryCacheKey();
120 WebBrowserPersistRemoteDocument::GetPersistFlags(uint32_t* aFlags
) {
121 *aFlags
= mAttrs
.persistFlags();
126 WebBrowserPersistRemoteDocument::SetPersistFlags(uint32_t aFlags
) {
128 return NS_ERROR_FAILURE
;
130 if (!mActor
->SendSetPersistFlags(aFlags
)) {
131 return NS_ERROR_FAILURE
;
133 mAttrs
.persistFlags() = aFlags
;
138 WebBrowserPersistRemoteDocument::GetPostData(nsIInputStream
** aStream
) {
139 nsCOMPtr
<nsIInputStream
> stream
= mPostData
;
140 stream
.forget(aStream
);
145 WebBrowserPersistRemoteDocument::GetPrincipal(nsIPrincipal
** aPrincipal
) {
146 nsCOMPtr
<nsIPrincipal
> nodePrincipal
= mPrincipal
;
147 nodePrincipal
.forget(aPrincipal
);
152 WebBrowserPersistRemoteDocument::ReadResources(
153 nsIWebBrowserPersistResourceVisitor
* aVisitor
) {
155 return NS_ERROR_FAILURE
;
157 RefPtr
<WebBrowserPersistResourcesParent
> subActor
=
158 new WebBrowserPersistResourcesParent(this, aVisitor
);
159 return mActor
->SendPWebBrowserPersistResourcesConstructor(
160 subActor
.forget().take())
166 WebBrowserPersistRemoteDocument::WriteContent(
167 nsIOutputStream
* aStream
, nsIWebBrowserPersistURIMap
* aMap
,
168 const nsACString
& aRequestedContentType
, uint32_t aEncoderFlags
,
169 uint32_t aWrapColumn
, nsIWebBrowserPersistWriteCompletion
* aCompletion
) {
171 return NS_ERROR_FAILURE
;
175 WebBrowserPersistURIMap map
;
176 uint32_t numMappedURIs
;
178 rv
= aMap
->GetTargetBaseURI(map
.targetBaseURI());
179 NS_ENSURE_SUCCESS(rv
, rv
);
180 rv
= aMap
->GetNumMappedURIs(&numMappedURIs
);
181 NS_ENSURE_SUCCESS(rv
, rv
);
182 for (uint32_t i
= 0; i
< numMappedURIs
; ++i
) {
183 WebBrowserPersistURIMapEntry
& nextEntry
=
184 *(map
.mapURIs().AppendElement());
185 rv
= aMap
->GetURIMapping(i
, nextEntry
.mapFrom(), nextEntry
.mapTo());
186 NS_ENSURE_SUCCESS(rv
, rv
);
191 new WebBrowserPersistSerializeParent(this, aStream
, aCompletion
);
192 nsCString
requestedContentType(aRequestedContentType
); // Sigh.
193 return mActor
->SendPWebBrowserPersistSerializeConstructor(
194 subActor
, map
, requestedContentType
, aEncoderFlags
, aWrapColumn
)
199 // Forcing WebBrowserPersistRemoteDocument to implement GetHistory is the
200 // easiest way to ensure that we can call GetHistory in
201 // WebBrowserPersistDocumentChild::Start
202 already_AddRefed
<nsISHEntry
> WebBrowserPersistRemoteDocument::GetHistory() {
203 MOZ_CRASH("We should not call GetHistory on WebBrowserPersistRemoteDocument");
207 } // namespace mozilla