Line data Source code
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 "WebBrowserPersistResourcesChild.h"
8 :
9 : #include "WebBrowserPersistDocumentChild.h"
10 : #include "mozilla/dom/ContentChild.h"
11 :
12 : namespace mozilla {
13 :
14 0 : NS_IMPL_ISUPPORTS(WebBrowserPersistResourcesChild,
15 : nsIWebBrowserPersistResourceVisitor)
16 :
17 0 : WebBrowserPersistResourcesChild::WebBrowserPersistResourcesChild()
18 : {
19 0 : }
20 :
21 : WebBrowserPersistResourcesChild::~WebBrowserPersistResourcesChild() = default;
22 :
23 : NS_IMETHODIMP
24 0 : WebBrowserPersistResourcesChild::VisitResource(nsIWebBrowserPersistDocument *aDocument,
25 : const nsACString& aURI)
26 : {
27 0 : nsCString copiedURI(aURI); // Yay, XPIDL/IPDL mismatch.
28 0 : SendVisitResource(copiedURI);
29 0 : return NS_OK;
30 : }
31 :
32 : NS_IMETHODIMP
33 0 : WebBrowserPersistResourcesChild::VisitDocument(nsIWebBrowserPersistDocument* aDocument,
34 : nsIWebBrowserPersistDocument* aSubDocument)
35 : {
36 0 : auto* subActor = new WebBrowserPersistDocumentChild();
37 : // As a consequence of how PWebBrowserPersistDocumentConstructor
38 : // can be sent by both the parent and the child, we must pass the
39 : // aBrowser and outerWindowID arguments here, but the values are
40 : // ignored by the parent. In particular, the TabChild in which
41 : // persistence started does not necessarily exist at this point;
42 : // see bug 1203602.
43 0 : if (!Manager()->Manager()
44 0 : ->SendPWebBrowserPersistDocumentConstructor(subActor, nullptr, 0)) {
45 : // NOTE: subActor is freed at this point.
46 0 : return NS_ERROR_FAILURE;
47 : }
48 : // ...but here, IPC won't free subActor until after this returns
49 : // to the event loop.
50 :
51 : // The order of these two messages will be preserved, because
52 : // they're the same toplevel protocol and priority.
53 : //
54 : // With this ordering, it's always the transition out of START
55 : // state that causes a document's parent actor to be exposed to
56 : // XPCOM (for both parent->child and child->parent construction),
57 : // which simplifies the lifetime management.
58 0 : SendVisitDocument(subActor);
59 0 : subActor->Start(aSubDocument);
60 0 : return NS_OK;
61 : }
62 :
63 : NS_IMETHODIMP
64 0 : WebBrowserPersistResourcesChild::EndVisit(nsIWebBrowserPersistDocument *aDocument,
65 : nsresult aStatus)
66 : {
67 0 : Send__delete__(this, aStatus);
68 0 : return NS_OK;
69 : }
70 :
71 : } // namespace mozilla
|