Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/webbrowserpersist/WebBrowserPersistResourcesParent.cpp
Line
Count
Source (jump to first uncovered line)
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 "WebBrowserPersistResourcesParent.h"
8
9
#include "nsThreadUtils.h"
10
11
namespace mozilla {
12
13
NS_IMPL_ISUPPORTS(WebBrowserPersistResourcesParent,
14
                  nsIWebBrowserPersistDocumentReceiver)
15
16
WebBrowserPersistResourcesParent::WebBrowserPersistResourcesParent(
17
        nsIWebBrowserPersistDocument* aDocument,
18
        nsIWebBrowserPersistResourceVisitor* aVisitor)
19
: mDocument(aDocument)
20
, mVisitor(aVisitor)
21
0
{
22
0
    MOZ_ASSERT(aDocument);
23
0
    MOZ_ASSERT(aVisitor);
24
0
}
25
26
0
WebBrowserPersistResourcesParent::~WebBrowserPersistResourcesParent() = default;
27
28
void
29
WebBrowserPersistResourcesParent::ActorDestroy(ActorDestroyReason aWhy)
30
0
{
31
0
    if (aWhy != Deletion && mVisitor) {
32
0
        // See comment in WebBrowserPersistDocumentParent::ActorDestroy
33
0
        // (or bug 1202887) for why this is deferred.
34
0
        nsCOMPtr<nsIRunnable> errorLater =
35
0
          NewRunnableMethod<nsCOMPtr<nsIWebBrowserPersistDocument>, nsresult>(
36
0
            "nsIWebBrowserPersistResourceVisitor::EndVisit",
37
0
            mVisitor,
38
0
            &nsIWebBrowserPersistResourceVisitor::EndVisit,
39
0
            mDocument,
40
0
            NS_ERROR_FAILURE);
41
0
        NS_DispatchToCurrentThread(errorLater);
42
0
    }
43
0
    mVisitor = nullptr;
44
0
}
45
46
mozilla::ipc::IPCResult
47
WebBrowserPersistResourcesParent::Recv__delete__(const nsresult& aStatus)
48
0
{
49
0
    mVisitor->EndVisit(mDocument, aStatus);
50
0
    mVisitor = nullptr;
51
0
    return IPC_OK();
52
0
}
53
54
mozilla::ipc::IPCResult
55
WebBrowserPersistResourcesParent::RecvVisitResource(const nsCString& aURI)
56
0
{
57
0
    mVisitor->VisitResource(mDocument, aURI);
58
0
    return IPC_OK();
59
0
}
60
61
mozilla::ipc::IPCResult
62
WebBrowserPersistResourcesParent::RecvVisitDocument(PWebBrowserPersistDocumentParent* aSubDocument)
63
0
{
64
0
    // Don't expose the subdocument to the visitor until it's ready
65
0
    // (until the actor isn't in START state).
66
0
    static_cast<WebBrowserPersistDocumentParent*>(aSubDocument)
67
0
        ->SetOnReady(this);
68
0
    return IPC_OK();
69
0
}
70
71
NS_IMETHODIMP
72
WebBrowserPersistResourcesParent::OnDocumentReady(nsIWebBrowserPersistDocument* aSubDocument)
73
0
{
74
0
    if (!mVisitor) {
75
0
        return NS_ERROR_FAILURE;
76
0
    }
77
0
    mVisitor->VisitDocument(mDocument, aSubDocument);
78
0
    return NS_OK;
79
0
}
80
81
NS_IMETHODIMP
82
WebBrowserPersistResourcesParent::OnError(nsresult aFailure)
83
0
{
84
0
    // Nothing useful to do but ignore the failed document.
85
0
    return NS_OK;
86
0
}
87
88
} // namespace mozilla