Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/webbrowserpersist/WebBrowserPersistSerializeChild.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 "WebBrowserPersistSerializeChild.h"
8
9
#include <algorithm>
10
11
#include "nsThreadUtils.h"
12
#include "ipc/IPCMessageUtils.h"
13
14
namespace mozilla {
15
16
NS_IMPL_ISUPPORTS(WebBrowserPersistSerializeChild,
17
                  nsIWebBrowserPersistWriteCompletion,
18
                  nsIWebBrowserPersistURIMap,
19
                  nsIOutputStream)
20
21
WebBrowserPersistSerializeChild::WebBrowserPersistSerializeChild(const WebBrowserPersistURIMap& aMap)
22
: mMap(aMap)
23
0
{
24
0
}
25
26
0
WebBrowserPersistSerializeChild::~WebBrowserPersistSerializeChild() = default;
27
28
NS_IMETHODIMP
29
WebBrowserPersistSerializeChild::OnFinish(nsIWebBrowserPersistDocument* aDocument,
30
                                          nsIOutputStream* aStream,
31
                                          const nsACString& aContentType,
32
                                          nsresult aStatus)
33
0
{
34
0
    MOZ_ASSERT(aStream == this);
35
0
    nsCString contentType(aContentType);
36
0
    Send__delete__(this, contentType, aStatus);
37
0
    return NS_OK;
38
0
}
39
40
NS_IMETHODIMP
41
WebBrowserPersistSerializeChild::GetNumMappedURIs(uint32_t* aNum)
42
0
{
43
0
    *aNum = static_cast<uint32_t>(mMap.mapURIs().Length());
44
0
    return NS_OK;
45
0
}
46
47
NS_IMETHODIMP
48
WebBrowserPersistSerializeChild::GetURIMapping(uint32_t aIndex,
49
                                               nsACString& aMapFrom,
50
                                               nsACString& aMapTo)
51
0
{
52
0
    if (aIndex >= mMap.mapURIs().Length()) {
53
0
        return NS_ERROR_INVALID_ARG;
54
0
    }
55
0
    aMapFrom = mMap.mapURIs()[aIndex].mapFrom();
56
0
    aMapTo = mMap.mapURIs()[aIndex].mapTo();
57
0
    return NS_OK;
58
0
}
59
60
NS_IMETHODIMP
61
WebBrowserPersistSerializeChild::GetTargetBaseURI(nsACString& aURI)
62
0
{
63
0
    aURI = mMap.targetBaseURI();
64
0
    return NS_OK;
65
0
}
66
67
NS_IMETHODIMP
68
WebBrowserPersistSerializeChild::Close()
69
0
{
70
0
    NS_WARNING("WebBrowserPersistSerializeChild::Close()");
71
0
    return NS_ERROR_NOT_IMPLEMENTED;
72
0
}
73
74
NS_IMETHODIMP
75
WebBrowserPersistSerializeChild::Flush()
76
0
{
77
0
    NS_WARNING("WebBrowserPersistSerializeChild::Flush()");
78
0
    return NS_ERROR_NOT_IMPLEMENTED;
79
0
}
80
81
NS_IMETHODIMP
82
WebBrowserPersistSerializeChild::Write(const char* aBuf, uint32_t aCount,
83
                                       uint32_t* aWritten)
84
0
{
85
0
    // Normally an nsIOutputStream would have to be thread-safe, but
86
0
    // nsDocumentEncoder currently doesn't call this off the main
87
0
    // thread (which also means it's difficult to test the
88
0
    // thread-safety code this class doesn't yet have).
89
0
    //
90
0
    // This is *not* an NS_ERROR_NOT_IMPLEMENTED, because at this
91
0
    // point we've probably already misused the non-thread-safe
92
0
    // refcounting.
93
0
    MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Fix this class to be thread-safe.");
94
0
95
0
    // Work around bug 1181433 by sending multiple messages if
96
0
    // necessary to write the entire aCount bytes, even though
97
0
    // nsIOutputStream.idl says we're allowed to do a short write.
98
0
    const char* buf = aBuf;
99
0
    uint32_t count = aCount;
100
0
    *aWritten = 0;
101
0
    while (count > 0) {
102
0
        uint32_t toWrite = std::min(IPC::MAX_MESSAGE_SIZE, count);
103
0
        nsTArray<uint8_t> arrayBuf;
104
0
        // It would be nice if this extra copy could be avoided.
105
0
        arrayBuf.AppendElements(buf, toWrite);
106
0
        SendWriteData(std::move(arrayBuf));
107
0
        *aWritten += toWrite;
108
0
        buf += toWrite;
109
0
        count -= toWrite;
110
0
    }
111
0
    return NS_OK;
112
0
}
113
114
NS_IMETHODIMP
115
WebBrowserPersistSerializeChild::WriteFrom(nsIInputStream* aFrom,
116
                                           uint32_t aCount,
117
                                           uint32_t* aWritten)
118
0
{
119
0
    NS_WARNING("WebBrowserPersistSerializeChild::WriteFrom()");
120
0
    return NS_ERROR_NOT_IMPLEMENTED;
121
0
}
122
123
NS_IMETHODIMP
124
WebBrowserPersistSerializeChild::WriteSegments(nsReadSegmentFun aFun,
125
                                               void* aCtx,
126
                                               uint32_t aCount,
127
                                               uint32_t* aWritten)
128
0
{
129
0
    NS_WARNING("WebBrowserPersistSerializeChild::WriteSegments()");
130
0
    return NS_ERROR_NOT_IMPLEMENTED;
131
0
}
132
133
NS_IMETHODIMP
134
WebBrowserPersistSerializeChild::IsNonBlocking(bool* aNonBlocking)
135
0
{
136
0
    // Writes will never fail with NS_BASE_STREAM_WOULD_BLOCK, so:
137
0
    *aNonBlocking = false;
138
0
    return NS_OK;
139
0
}
140
141
} // namespace mozilla