Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/webbrowserpersist/WebBrowserPersistDocumentParent.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 "WebBrowserPersistDocumentParent.h"
8
9
#include "mozilla/ipc/IPCStreamUtils.h"
10
#include "mozilla/dom/PContentParent.h"
11
#include "nsIInputStream.h"
12
#include "nsThreadUtils.h"
13
#include "WebBrowserPersistResourcesParent.h"
14
#include "WebBrowserPersistSerializeParent.h"
15
#include "WebBrowserPersistRemoteDocument.h"
16
17
namespace mozilla {
18
19
WebBrowserPersistDocumentParent::WebBrowserPersistDocumentParent()
20
: mReflection(nullptr)
21
0
{
22
0
}
23
24
void
25
WebBrowserPersistDocumentParent::SetOnReady(nsIWebBrowserPersistDocumentReceiver* aOnReady)
26
0
{
27
0
    MOZ_ASSERT(aOnReady);
28
0
    MOZ_ASSERT(!mOnReady);
29
0
    MOZ_ASSERT(!mReflection);
30
0
    mOnReady = aOnReady;
31
0
}
32
33
void
34
WebBrowserPersistDocumentParent::ActorDestroy(ActorDestroyReason aWhy)
35
0
{
36
0
    if (mReflection) {
37
0
        mReflection->ActorDestroy();
38
0
        mReflection = nullptr;
39
0
    }
40
0
    if (mOnReady) {
41
0
        // Bug 1202887: If this is part of a subtree destruction, then
42
0
        // anything which could cause another actor in that subtree to
43
0
        // be Send__delete__()ed will cause use-after-free -- such as
44
0
        // dropping the last reference to another document's
45
0
        // WebBrowserPersistRemoteDocument.  To avoid that, defer the
46
0
        // callback until after the entire subtree is destroyed.
47
0
        nsCOMPtr<nsIRunnable> errorLater = NewRunnableMethod<nsresult>(
48
0
          "nsIWebBrowserPersistDocumentReceiver::OnError",
49
0
          mOnReady,
50
0
          &nsIWebBrowserPersistDocumentReceiver::OnError,
51
0
          NS_ERROR_FAILURE);
52
0
        NS_DispatchToCurrentThread(errorLater);
53
0
        mOnReady = nullptr;
54
0
    }
55
0
}
56
57
WebBrowserPersistDocumentParent::~WebBrowserPersistDocumentParent()
58
0
{
59
0
    MOZ_RELEASE_ASSERT(!mReflection);
60
0
    MOZ_ASSERT(!mOnReady);
61
0
}
62
63
mozilla::ipc::IPCResult
64
WebBrowserPersistDocumentParent::RecvAttributes(const Attrs& aAttrs,
65
                                                const OptionalIPCStream& aPostStream)
66
0
{
67
0
    // Deserialize the postData unconditionally so that fds aren't leaked.
68
0
    nsCOMPtr<nsIInputStream> postData = mozilla::ipc::DeserializeIPCStream(aPostStream);
69
0
    if (!mOnReady || mReflection) {
70
0
        return IPC_FAIL_NO_REASON(this);
71
0
    }
72
0
    mReflection = new WebBrowserPersistRemoteDocument(this, aAttrs, postData);
73
0
    RefPtr<WebBrowserPersistRemoteDocument> reflection = mReflection;
74
0
    mOnReady->OnDocumentReady(reflection);
75
0
    mOnReady = nullptr;
76
0
    return IPC_OK();
77
0
}
78
79
mozilla::ipc::IPCResult
80
WebBrowserPersistDocumentParent::RecvInitFailure(const nsresult& aFailure)
81
0
{
82
0
    if (!mOnReady || mReflection) {
83
0
        return IPC_FAIL_NO_REASON(this);
84
0
    }
85
0
    mOnReady->OnError(aFailure);
86
0
    mOnReady = nullptr;
87
0
    // Warning: Send__delete__ deallocates this object.
88
0
    IProtocol* mgr = Manager();
89
0
    if (!Send__delete__(this)) {
90
0
        return IPC_FAIL_NO_REASON(mgr);
91
0
    }
92
0
    return IPC_OK();
93
0
}
94
95
PWebBrowserPersistResourcesParent*
96
WebBrowserPersistDocumentParent::AllocPWebBrowserPersistResourcesParent()
97
0
{
98
0
    MOZ_CRASH("Don't use this; construct the actor directly and AddRef.");
99
0
    return nullptr;
100
0
}
101
102
bool
103
WebBrowserPersistDocumentParent::DeallocPWebBrowserPersistResourcesParent(PWebBrowserPersistResourcesParent* aActor)
104
0
{
105
0
    // Turn the ref held by IPC back into an nsRefPtr.
106
0
    RefPtr<WebBrowserPersistResourcesParent> actor =
107
0
        already_AddRefed<WebBrowserPersistResourcesParent>(
108
0
            static_cast<WebBrowserPersistResourcesParent*>(aActor));
109
0
    return true;
110
0
}
111
112
PWebBrowserPersistSerializeParent*
113
WebBrowserPersistDocumentParent::AllocPWebBrowserPersistSerializeParent(
114
        const WebBrowserPersistURIMap& aMap,
115
        const nsCString& aRequestedContentType,
116
        const uint32_t& aEncoderFlags,
117
        const uint32_t& aWrapColumn)
118
0
{
119
0
    MOZ_CRASH("Don't use this; construct the actor directly.");
120
0
    return nullptr;
121
0
}
122
123
bool
124
WebBrowserPersistDocumentParent::DeallocPWebBrowserPersistSerializeParent(PWebBrowserPersistSerializeParent* aActor)
125
0
{
126
0
    delete aActor;
127
0
    return true;
128
0
}
129
130
} // namespace mozilla