1/*
2 * Copyright (C) 2016 Canon Inc.
3 * Copyright (C) 2017 Apple Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted, provided that the following conditions
7 * are required to be met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY CANON INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL CANON INC. AND ITS CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#if ENABLE(STREAMS_API)
30
31#include "ReadableStreamSource.h"
32
33namespace JSC {
34class ArrayBuffer;
35};
36
37namespace WebCore {
38
39class FetchBodyOwner;
40
41class FetchBodySource final : public ReadableStreamSource {
42public:
43 FetchBodySource(FetchBodyOwner&);
44
45 bool enqueue(RefPtr<JSC::ArrayBuffer>&& chunk) { return controller().enqueue(WTFMove(chunk)); }
46 void close();
47 void error(const Exception&);
48
49 bool isCancelling() const { return m_isCancelling; }
50
51 void resolvePullPromise() { pullFinished(); }
52 void detach() { m_bodyOwner = nullptr; }
53
54private:
55 void doStart() final;
56 void doPull() final;
57 void doCancel() final;
58 void setActive() final;
59 void setInactive() final;
60
61 FetchBodyOwner* m_bodyOwner;
62 bool m_isCancelling { false };
63#ifndef NDEBUG
64 bool m_isClosed { false };
65#endif
66};
67
68} // namespace WebCore
69
70#endif // ENABLE(STREAMS_API)
71