Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / webbrowserpersist / WebBrowserPersistResourcesChild.cpp
blob901473d8c7a873984abbb1e2429401202a81ec56
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 "WebBrowserPersistResourcesChild.h"
9 #include "WebBrowserPersistDocumentChild.h"
10 #include "mozilla/dom/PContentChild.h"
12 namespace mozilla {
14 NS_IMPL_ISUPPORTS(WebBrowserPersistResourcesChild,
15 nsIWebBrowserPersistResourceVisitor)
17 WebBrowserPersistResourcesChild::WebBrowserPersistResourcesChild() = default;
19 WebBrowserPersistResourcesChild::~WebBrowserPersistResourcesChild() = default;
21 NS_IMETHODIMP
22 WebBrowserPersistResourcesChild::VisitResource(
23 nsIWebBrowserPersistDocument* aDocument, const nsACString& aURI,
24 nsContentPolicyType aContentPolicyType) {
25 nsCString copiedURI(aURI); // Yay, XPIDL/IPDL mismatch.
26 SendVisitResource(copiedURI, aContentPolicyType);
27 return NS_OK;
30 NS_IMETHODIMP
31 WebBrowserPersistResourcesChild::VisitDocument(
32 nsIWebBrowserPersistDocument* aDocument,
33 nsIWebBrowserPersistDocument* aSubDocument) {
34 RefPtr<WebBrowserPersistDocumentChild> subActor =
35 new WebBrowserPersistDocumentChild();
36 // As a consequence of how PWebBrowserPersistDocumentConstructor
37 // can be sent by both the parent and the child, we must pass the
38 // aBrowser and outerWindowID arguments here, but the values are
39 // ignored by the parent. In particular, the BrowserChild in which
40 // persistence started does not necessarily exist at this point;
41 // see bug 1203602.
42 if (!Manager()->Manager()->SendPWebBrowserPersistDocumentConstructor(
43 subActor, nullptr, nullptr)) {
44 return NS_ERROR_FAILURE;
47 // The order of these two messages will be preserved, because
48 // they're the same toplevel protocol and priority.
50 // With this ordering, it's always the transition out of START
51 // state that causes a document's parent actor to be exposed to
52 // XPCOM (for both parent->child and child->parent construction),
53 // which simplifies the lifetime management.
54 SendVisitDocument(WrapNotNull(subActor));
55 subActor->Start(aSubDocument);
56 return NS_OK;
59 NS_IMETHODIMP
60 WebBrowserPersistResourcesChild::VisitBrowsingContext(
61 nsIWebBrowserPersistDocument* aDocument,
62 dom::BrowsingContext* aBrowsingContext) {
63 SendVisitBrowsingContext(aBrowsingContext);
64 return NS_OK;
67 NS_IMETHODIMP
68 WebBrowserPersistResourcesChild::EndVisit(
69 nsIWebBrowserPersistDocument* aDocument, nsresult aStatus) {
70 Send__delete__(this, aStatus);
71 return NS_OK;
74 } // namespace mozilla