1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 #ifndef WebBrowserPersistDocumentParent_h__
8 #define WebBrowserPersistDocumentParent_h__
9 
10 #include "mozilla/Maybe.h"
11 #include "mozilla/PWebBrowserPersistDocumentParent.h"
12 #include "nsCOMPtr.h"
13 #include "nsIWebBrowserPersistDocument.h"
14 
15 // This class is the IPC half of the glue between the
16 // nsIWebBrowserPersistDocument interface and a remote document.  When
17 // (and if) it receives the Attributes message it constructs an
18 // WebBrowserPersistRemoteDocument and releases it into the XPCOM
19 // universe; otherwise, it invokes the document receiver's error
20 // callback.
21 //
22 // This object's lifetime is the normal IPC lifetime; on destruction,
23 // it calls its XPCOM reflection (if it exists yet) to remove that
24 // reference.  Normal deletion occurs when the XPCOM object is being
25 // destroyed or after an InitFailure is received and handled.
26 //
27 // See also: BrowserParent::StartPersistence.
28 
29 namespace mozilla {
30 
31 class WebBrowserPersistRemoteDocument;
32 
33 class WebBrowserPersistDocumentParent final
34     : public PWebBrowserPersistDocumentParent {
35  public:
36   WebBrowserPersistDocumentParent();
37   virtual ~WebBrowserPersistDocumentParent();
38 
39   // Set a callback to be invoked when the actor leaves the START
40   // state.  This method must be called exactly once while the actor
41   // is still in the START state (or is unconstructed).
42   void SetOnReady(nsIWebBrowserPersistDocumentReceiver* aOnReady);
43 
44   using Attrs = WebBrowserPersistDocumentAttrs;
45 
46   // IPDL methods:
47   mozilla::ipc::IPCResult RecvAttributes(const Attrs& aAttrs,
48                                          const Maybe<IPCStream>& aPostStream);
49   mozilla::ipc::IPCResult RecvInitFailure(const nsresult& aFailure);
50 
51   PWebBrowserPersistResourcesParent* AllocPWebBrowserPersistResourcesParent();
52   bool DeallocPWebBrowserPersistResourcesParent(
53       PWebBrowserPersistResourcesParent* aActor);
54 
55   PWebBrowserPersistSerializeParent* AllocPWebBrowserPersistSerializeParent(
56       const WebBrowserPersistURIMap& aMap,
57       const nsCString& aRequestedContentType, const uint32_t& aEncoderFlags,
58       const uint32_t& aWrapColumn);
59   bool DeallocPWebBrowserPersistSerializeParent(
60       PWebBrowserPersistSerializeParent* aActor);
61 
62   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
63 
64  private:
65   // This is reset to nullptr when the callback is invoked.
66   nsCOMPtr<nsIWebBrowserPersistDocumentReceiver> mOnReady;
67   WebBrowserPersistRemoteDocument* mReflection;
68 };
69 
70 }  // namespace mozilla
71 
72 #endif  // WebBrowserPersistDocumentParent_h__
73