/src/mozilla-central/dom/webbrowserpersist/WebBrowserPersistDocumentChild.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
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/. */ |
6 | | |
7 | | #include "WebBrowserPersistDocumentChild.h" |
8 | | |
9 | | #include "mozilla/dom/ContentChild.h" |
10 | | #include "mozilla/ipc/IPCStreamUtils.h" |
11 | | #include "nsIDocument.h" |
12 | | #include "nsIInputStream.h" |
13 | | #include "WebBrowserPersistLocalDocument.h" |
14 | | #include "WebBrowserPersistResourcesChild.h" |
15 | | #include "WebBrowserPersistSerializeChild.h" |
16 | | |
17 | | namespace mozilla { |
18 | | |
19 | | WebBrowserPersistDocumentChild::WebBrowserPersistDocumentChild() |
20 | 0 | { |
21 | 0 | } |
22 | | |
23 | 0 | WebBrowserPersistDocumentChild::~WebBrowserPersistDocumentChild() = default; |
24 | | |
25 | | void |
26 | | WebBrowserPersistDocumentChild::Start(nsIDocument* aDocument) |
27 | 0 | { |
28 | 0 | RefPtr<WebBrowserPersistLocalDocument> doc; |
29 | 0 | if (aDocument) { |
30 | 0 | doc = new WebBrowserPersistLocalDocument(aDocument); |
31 | 0 | } |
32 | 0 | Start(doc); |
33 | 0 | } |
34 | | |
35 | | void |
36 | | WebBrowserPersistDocumentChild::Start(nsIWebBrowserPersistDocument* aDocument) |
37 | 0 | { |
38 | 0 | MOZ_ASSERT(!mDocument); |
39 | 0 | if (!aDocument) { |
40 | 0 | SendInitFailure(NS_ERROR_FAILURE); |
41 | 0 | return; |
42 | 0 | } |
43 | 0 | |
44 | 0 | nsCOMPtr<nsIPrincipal> principal; |
45 | 0 | WebBrowserPersistDocumentAttrs attrs; |
46 | 0 | nsCOMPtr<nsIInputStream> postDataStream; |
47 | 0 | #define ENSURE(e) do { \ |
48 | 0 | nsresult rv = (e); \ |
49 | 0 | if (NS_FAILED(rv)) { \ |
50 | 0 | SendInitFailure(rv); \ |
51 | 0 | return; \ |
52 | 0 | } \ |
53 | 0 | } while(0) |
54 | 0 | ENSURE(aDocument->GetIsPrivate(&(attrs.isPrivate()))); |
55 | 0 | ENSURE(aDocument->GetDocumentURI(attrs.documentURI())); |
56 | 0 | ENSURE(aDocument->GetBaseURI(attrs.baseURI())); |
57 | 0 | ENSURE(aDocument->GetContentType(attrs.contentType())); |
58 | 0 | ENSURE(aDocument->GetCharacterSet(attrs.characterSet())); |
59 | 0 | ENSURE(aDocument->GetTitle(attrs.title())); |
60 | 0 | ENSURE(aDocument->GetReferrer(attrs.referrer())); |
61 | 0 | ENSURE(aDocument->GetContentDisposition(attrs.contentDisposition())); |
62 | 0 | ENSURE(aDocument->GetCacheKey(&(attrs.cacheKey()))); |
63 | 0 | ENSURE(aDocument->GetPersistFlags(&(attrs.persistFlags()))); |
64 | 0 |
|
65 | 0 | ENSURE(aDocument->GetPrincipal(getter_AddRefs(principal))); |
66 | 0 | ENSURE(ipc::PrincipalToPrincipalInfo(principal, &(attrs.principal()))); |
67 | 0 |
|
68 | 0 | ENSURE(aDocument->GetPostData(getter_AddRefs(postDataStream))); |
69 | 0 | #undef ENSURE |
70 | 0 |
|
71 | 0 | mozilla::ipc::AutoIPCStream autoStream; |
72 | 0 | autoStream.Serialize(postDataStream, |
73 | 0 | static_cast<mozilla::dom::ContentChild*>(Manager())); |
74 | 0 |
|
75 | 0 | mDocument = aDocument; |
76 | 0 | SendAttributes(attrs, autoStream.TakeOptionalValue()); |
77 | 0 | } |
78 | | |
79 | | mozilla::ipc::IPCResult |
80 | | WebBrowserPersistDocumentChild::RecvSetPersistFlags(const uint32_t& aNewFlags) |
81 | 0 | { |
82 | 0 | mDocument->SetPersistFlags(aNewFlags); |
83 | 0 | return IPC_OK(); |
84 | 0 | } |
85 | | |
86 | | PWebBrowserPersistResourcesChild* |
87 | | WebBrowserPersistDocumentChild::AllocPWebBrowserPersistResourcesChild() |
88 | 0 | { |
89 | 0 | auto* actor = new WebBrowserPersistResourcesChild(); |
90 | 0 | NS_ADDREF(actor); |
91 | 0 | return actor; |
92 | 0 | } |
93 | | |
94 | | mozilla::ipc::IPCResult |
95 | | WebBrowserPersistDocumentChild::RecvPWebBrowserPersistResourcesConstructor(PWebBrowserPersistResourcesChild* aActor) |
96 | 0 | { |
97 | 0 | RefPtr<WebBrowserPersistResourcesChild> visitor = |
98 | 0 | static_cast<WebBrowserPersistResourcesChild*>(aActor); |
99 | 0 | nsresult rv = mDocument->ReadResources(visitor); |
100 | 0 | if (NS_FAILED(rv)) { |
101 | 0 | // This is a sync failure on the child side but an async |
102 | 0 | // failure on the parent side -- it already got NS_OK from |
103 | 0 | // ReadResources, so the error has to be reported via the |
104 | 0 | // visitor instead. |
105 | 0 | visitor->EndVisit(mDocument, rv); |
106 | 0 | } |
107 | 0 | return IPC_OK(); |
108 | 0 | } |
109 | | |
110 | | bool |
111 | | WebBrowserPersistDocumentChild::DeallocPWebBrowserPersistResourcesChild(PWebBrowserPersistResourcesChild* aActor) |
112 | 0 | { |
113 | 0 | auto* castActor = |
114 | 0 | static_cast<WebBrowserPersistResourcesChild*>(aActor); |
115 | 0 | NS_RELEASE(castActor); |
116 | 0 | return true; |
117 | 0 | } |
118 | | |
119 | | PWebBrowserPersistSerializeChild* |
120 | | WebBrowserPersistDocumentChild::AllocPWebBrowserPersistSerializeChild( |
121 | | const WebBrowserPersistURIMap& aMap, |
122 | | const nsCString& aRequestedContentType, |
123 | | const uint32_t& aEncoderFlags, |
124 | | const uint32_t& aWrapColumn) |
125 | 0 | { |
126 | 0 | auto* actor = new WebBrowserPersistSerializeChild(aMap); |
127 | 0 | NS_ADDREF(actor); |
128 | 0 | return actor; |
129 | 0 | } |
130 | | |
131 | | mozilla::ipc::IPCResult |
132 | | WebBrowserPersistDocumentChild::RecvPWebBrowserPersistSerializeConstructor( |
133 | | PWebBrowserPersistSerializeChild* aActor, |
134 | | const WebBrowserPersistURIMap& aMap, |
135 | | const nsCString& aRequestedContentType, |
136 | | const uint32_t& aEncoderFlags, |
137 | | const uint32_t& aWrapColumn) |
138 | 0 | { |
139 | 0 | auto* castActor = |
140 | 0 | static_cast<WebBrowserPersistSerializeChild*>(aActor); |
141 | 0 | // This actor performs the roles of: completion, URI map, and output stream. |
142 | 0 | nsresult rv = mDocument->WriteContent(castActor, |
143 | 0 | castActor, |
144 | 0 | aRequestedContentType, |
145 | 0 | aEncoderFlags, |
146 | 0 | aWrapColumn, |
147 | 0 | castActor); |
148 | 0 | if (NS_FAILED(rv)) { |
149 | 0 | castActor->OnFinish(mDocument, castActor, aRequestedContentType, rv); |
150 | 0 | } |
151 | 0 | return IPC_OK(); |
152 | 0 | } |
153 | | |
154 | | bool |
155 | | WebBrowserPersistDocumentChild::DeallocPWebBrowserPersistSerializeChild(PWebBrowserPersistSerializeChild* aActor) |
156 | 0 | { |
157 | 0 | auto* castActor = |
158 | 0 | static_cast<WebBrowserPersistSerializeChild*>(aActor); |
159 | 0 | NS_RELEASE(castActor); |
160 | 0 | return true; |
161 | 0 | } |
162 | | |
163 | | } // namespace mozilla |