Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / webbrowserpersist / WebBrowserPersistResourcesParent.cpp
blob888e79fcd73defafc8679d5f35a9f9d6e58b338d
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 "WebBrowserPersistResourcesParent.h"
9 #include "nsThreadUtils.h"
11 #include "mozilla/dom/BrowserParent.h"
12 #include "mozilla/dom/CanonicalBrowsingContext.h"
13 #include "mozilla/dom/ContentParent.h"
14 #include "mozilla/dom/WindowGlobalParent.h"
16 namespace mozilla {
18 NS_IMPL_ISUPPORTS(WebBrowserPersistResourcesParent,
19 nsIWebBrowserPersistDocumentReceiver)
21 WebBrowserPersistResourcesParent::WebBrowserPersistResourcesParent(
22 nsIWebBrowserPersistDocument* aDocument,
23 nsIWebBrowserPersistResourceVisitor* aVisitor)
24 : mDocument(aDocument), mVisitor(aVisitor) {
25 MOZ_ASSERT(aDocument);
26 MOZ_ASSERT(aVisitor);
29 WebBrowserPersistResourcesParent::~WebBrowserPersistResourcesParent() = default;
31 void WebBrowserPersistResourcesParent::ActorDestroy(ActorDestroyReason aWhy) {
32 if (aWhy != Deletion && mVisitor) {
33 // See comment in WebBrowserPersistDocumentParent::ActorDestroy
34 // (or bug 1202887) for why this is deferred.
35 nsCOMPtr<nsIRunnable> errorLater =
36 NewRunnableMethod<nsCOMPtr<nsIWebBrowserPersistDocument>, nsresult>(
37 "nsIWebBrowserPersistResourceVisitor::EndVisit", mVisitor,
38 &nsIWebBrowserPersistResourceVisitor::EndVisit, mDocument,
39 NS_ERROR_FAILURE);
40 NS_DispatchToCurrentThread(errorLater);
42 mVisitor = nullptr;
45 mozilla::ipc::IPCResult WebBrowserPersistResourcesParent::Recv__delete__(
46 const nsresult& aStatus) {
47 mVisitor->EndVisit(mDocument, aStatus);
48 mVisitor = nullptr;
49 return IPC_OK();
52 mozilla::ipc::IPCResult WebBrowserPersistResourcesParent::RecvVisitResource(
53 const nsACString& aURI, const nsContentPolicyType& aContentPolicyType) {
54 mVisitor->VisitResource(mDocument, aURI, aContentPolicyType);
55 return IPC_OK();
58 mozilla::ipc::IPCResult WebBrowserPersistResourcesParent::RecvVisitDocument(
59 NotNull<PWebBrowserPersistDocumentParent*> aSubDocument) {
60 // Don't expose the subdocument to the visitor until it's ready
61 // (until the actor isn't in START state).
62 static_cast<WebBrowserPersistDocumentParent*>(aSubDocument.get())
63 ->SetOnReady(this);
64 return IPC_OK();
67 mozilla::ipc::IPCResult
68 WebBrowserPersistResourcesParent::RecvVisitBrowsingContext(
69 const dom::MaybeDiscarded<dom::BrowsingContext>& aContext) {
70 if (aContext.IsNullOrDiscarded()) {
71 // Nothing useful to do but ignore the discarded context.
72 return IPC_OK();
75 mVisitor->VisitBrowsingContext(mDocument, aContext.get());
76 return IPC_OK();
79 NS_IMETHODIMP
80 WebBrowserPersistResourcesParent::OnDocumentReady(
81 nsIWebBrowserPersistDocument* aSubDocument) {
82 if (!mVisitor) {
83 return NS_ERROR_FAILURE;
85 mVisitor->VisitDocument(mDocument, aSubDocument);
86 return NS_OK;
89 NS_IMETHODIMP
90 WebBrowserPersistResourcesParent::OnError(nsresult aFailure) {
91 // Nothing useful to do but ignore the failed document.
92 return NS_OK;
95 } // namespace mozilla