1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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 "WebBrowserPersistRemoteDocument.h"
#include "WebBrowserPersistDocumentParent.h"
#include "WebBrowserPersistResourcesParent.h"
#include "WebBrowserPersistSerializeParent.h"
#include "mozilla/Unused.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/net/CookieJarSettings.h"
#include "nsDebug.h"
#include "nsIPrincipal.h"
#include "nsISHEntry.h"
namespace mozilla {
NS_IMPL_ISUPPORTS(WebBrowserPersistRemoteDocument, nsIWebBrowserPersistDocument)
WebBrowserPersistRemoteDocument ::WebBrowserPersistRemoteDocument(
WebBrowserPersistDocumentParent* aActor, const Attrs& aAttrs,
nsIInputStream* aPostData)
: mActor(aActor), mAttrs(aAttrs), mPostData(aPostData) {
auto principalOrErr = ipc::PrincipalInfoToPrincipal(mAttrs.principal());
if (principalOrErr.isOk()) {
mPrincipal = principalOrErr.unwrap();
} else {
NS_WARNING("Failed to obtain principal!");
}
net::CookieJarSettings::Deserialize(mAttrs.cookieJarSettings(),
getter_AddRefs(mCookieJarSettings));
}
WebBrowserPersistRemoteDocument::~WebBrowserPersistRemoteDocument() {
if (mActor) {
Unused << WebBrowserPersistDocumentParent::Send__delete__(mActor);
// That will call mActor->ActorDestroy, which calls this->ActorDestroy
// (whether or not the IPC send succeeds).
}
MOZ_ASSERT(!mActor);
}
void WebBrowserPersistRemoteDocument::ActorDestroy(void) { mActor = nullptr; }
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetIsClosed(bool* aIsClosed) {
*aIsClosed = !mActor;
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetIsPrivate(bool* aIsPrivate) {
*aIsPrivate = mAttrs.isPrivate();
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetDocumentURI(nsACString& aURISpec) {
aURISpec = mAttrs.documentURI();
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetBaseURI(nsACString& aURISpec) {
aURISpec = mAttrs.baseURI();
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetContentType(nsACString& aContentType) {
aContentType = mAttrs.contentType();
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetCharacterSet(nsACString& aCharSet) {
aCharSet = mAttrs.characterSet();
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetTitle(nsAString& aTitle) {
aTitle = mAttrs.title();
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetReferrerInfo(
nsIReferrerInfo** aReferrerInfo) {
*aReferrerInfo = mAttrs.referrerInfo();
NS_IF_ADDREF(*aReferrerInfo);
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetCookieJarSettings(
nsICookieJarSettings** aCookieJarSettings) {
nsCOMPtr<nsICookieJarSettings> cookieJarSettings = mCookieJarSettings;
cookieJarSettings.forget(aCookieJarSettings);
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetContentDisposition(nsAString& aDisp) {
aDisp = mAttrs.contentDisposition();
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetCacheKey(uint32_t* aCacheKey) {
*aCacheKey = mAttrs.sessionHistoryCacheKey();
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetPersistFlags(uint32_t* aFlags) {
*aFlags = mAttrs.persistFlags();
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::SetPersistFlags(uint32_t aFlags) {
if (!mActor) {
return NS_ERROR_FAILURE;
}
if (!mActor->SendSetPersistFlags(aFlags)) {
return NS_ERROR_FAILURE;
}
mAttrs.persistFlags() = aFlags;
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetPostData(nsIInputStream** aStream) {
nsCOMPtr<nsIInputStream> stream = mPostData;
stream.forget(aStream);
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetPrincipal(nsIPrincipal** aPrincipal) {
nsCOMPtr<nsIPrincipal> nodePrincipal = mPrincipal;
nodePrincipal.forget(aPrincipal);
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::ReadResources(
nsIWebBrowserPersistResourceVisitor* aVisitor) {
if (!mActor) {
return NS_ERROR_FAILURE;
}
RefPtr<WebBrowserPersistResourcesParent> subActor =
new WebBrowserPersistResourcesParent(this, aVisitor);
return mActor->SendPWebBrowserPersistResourcesConstructor(
subActor.forget().take())
? NS_OK
: NS_ERROR_FAILURE;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::WriteContent(
nsIOutputStream* aStream, nsIWebBrowserPersistURIMap* aMap,
const nsACString& aRequestedContentType, uint32_t aEncoderFlags,
uint32_t aWrapColumn, nsIWebBrowserPersistWriteCompletion* aCompletion) {
if (!mActor) {
return NS_ERROR_FAILURE;
}
nsresult rv;
WebBrowserPersistURIMap map;
uint32_t numMappedURIs;
if (aMap) {
rv = aMap->GetTargetBaseURI(map.targetBaseURI());
NS_ENSURE_SUCCESS(rv, rv);
rv = aMap->GetNumMappedURIs(&numMappedURIs);
NS_ENSURE_SUCCESS(rv, rv);
for (uint32_t i = 0; i < numMappedURIs; ++i) {
WebBrowserPersistURIMapEntry& nextEntry =
*(map.mapURIs().AppendElement());
rv = aMap->GetURIMapping(i, nextEntry.mapFrom(), nextEntry.mapTo());
NS_ENSURE_SUCCESS(rv, rv);
}
}
auto* subActor =
new WebBrowserPersistSerializeParent(this, aStream, aCompletion);
nsCString requestedContentType(aRequestedContentType); // Sigh.
return mActor->SendPWebBrowserPersistSerializeConstructor(
subActor, map, requestedContentType, aEncoderFlags, aWrapColumn)
? NS_OK
: NS_ERROR_FAILURE;
}
// Forcing WebBrowserPersistRemoteDocument to implement GetHistory is the
// easiest way to ensure that we can call GetHistory in
// WebBrowserPersistDocumentChild::Start
already_AddRefed<nsISHEntry> WebBrowserPersistRemoteDocument::GetHistory() {
MOZ_CRASH("We should not call GetHistory on WebBrowserPersistRemoteDocument");
return nullptr;
}
} // namespace mozilla
|