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"
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
);
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
,
40 NS_DispatchToCurrentThread(errorLater
);
45 mozilla::ipc::IPCResult
WebBrowserPersistResourcesParent::Recv__delete__(
46 const nsresult
& aStatus
) {
47 mVisitor
->EndVisit(mDocument
, aStatus
);
52 mozilla::ipc::IPCResult
WebBrowserPersistResourcesParent::RecvVisitResource(
53 const nsCString
& aURI
, const nsContentPolicyType
& aContentPolicyType
) {
54 mVisitor
->VisitResource(mDocument
, aURI
, aContentPolicyType
);
58 mozilla::ipc::IPCResult
WebBrowserPersistResourcesParent::RecvVisitDocument(
59 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
)->SetOnReady(this);
66 mozilla::ipc::IPCResult
67 WebBrowserPersistResourcesParent::RecvVisitBrowsingContext(
68 const dom::MaybeDiscarded
<dom::BrowsingContext
>& aContext
) {
69 if (aContext
.IsNullOrDiscarded()) {
70 // Nothing useful to do but ignore the discarded context.
74 mVisitor
->VisitBrowsingContext(mDocument
, aContext
.get());
79 WebBrowserPersistResourcesParent::OnDocumentReady(
80 nsIWebBrowserPersistDocument
* aSubDocument
) {
82 return NS_ERROR_FAILURE
;
84 mVisitor
->VisitDocument(mDocument
, aSubDocument
);
89 WebBrowserPersistResourcesParent::OnError(nsresult aFailure
) {
90 // Nothing useful to do but ignore the failed document.
94 } // namespace mozilla