Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / dom / webbrowserpersist / WebBrowserPersistResourcesParent.cpp
blob4582e4523d83bdf54b9c65af3507a5dcbe34af4f
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 nsCString& aURI, const nsContentPolicyType& aContentPolicyType) {
54 mVisitor->VisitResource(mDocument, aURI, aContentPolicyType);
55 return IPC_OK();
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);
63 return IPC_OK();
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.
71 return IPC_OK();
74 mVisitor->VisitBrowsingContext(mDocument, aContext.get());
75 return IPC_OK();
78 NS_IMETHODIMP
79 WebBrowserPersistResourcesParent::OnDocumentReady(
80 nsIWebBrowserPersistDocument* aSubDocument) {
81 if (!mVisitor) {
82 return NS_ERROR_FAILURE;
84 mVisitor->VisitDocument(mDocument, aSubDocument);
85 return NS_OK;
88 NS_IMETHODIMP
89 WebBrowserPersistResourcesParent::OnError(nsresult aFailure) {
90 // Nothing useful to do but ignore the failed document.
91 return NS_OK;
94 } // namespace mozilla