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 | #include "config.h" |
28 | #include "FetchBodySource.h" |
29 | |
30 | #if ENABLE(STREAMS_API) |
31 | |
32 | #include "FetchResponse.h" |
33 | |
34 | namespace WebCore { |
35 | |
36 | FetchBodySource::FetchBodySource(FetchBodyOwner& bodyOwner) |
37 | : m_bodyOwner(&bodyOwner) |
38 | { |
39 | } |
40 | |
41 | void FetchBodySource::setActive() |
42 | { |
43 | ASSERT(m_bodyOwner); |
44 | if (m_bodyOwner) |
45 | m_bodyOwner->setPendingActivity(*m_bodyOwner); |
46 | } |
47 | |
48 | void FetchBodySource::setInactive() |
49 | { |
50 | ASSERT(m_bodyOwner); |
51 | if (m_bodyOwner) |
52 | m_bodyOwner->unsetPendingActivity(*m_bodyOwner); |
53 | } |
54 | |
55 | void FetchBodySource::doStart() |
56 | { |
57 | ASSERT(m_bodyOwner); |
58 | if (m_bodyOwner) |
59 | m_bodyOwner->consumeBodyAsStream(); |
60 | } |
61 | |
62 | void FetchBodySource::doPull() |
63 | { |
64 | ASSERT(m_bodyOwner); |
65 | if (m_bodyOwner) |
66 | m_bodyOwner->feedStream(); |
67 | } |
68 | |
69 | void FetchBodySource::doCancel() |
70 | { |
71 | m_isCancelling = true; |
72 | ASSERT(m_bodyOwner || m_isClosed); |
73 | if (!m_bodyOwner) |
74 | return; |
75 | |
76 | m_bodyOwner->cancel(); |
77 | m_bodyOwner = nullptr; |
78 | } |
79 | |
80 | void FetchBodySource::close() |
81 | { |
82 | #ifndef NDEBUG |
83 | m_isClosed = true; |
84 | #endif |
85 | |
86 | controller().close(); |
87 | clean(); |
88 | m_bodyOwner = nullptr; |
89 | } |
90 | |
91 | void FetchBodySource::error(const Exception& value) |
92 | { |
93 | controller().error(value); |
94 | clean(); |
95 | m_bodyOwner = nullptr; |
96 | } |
97 | |
98 | } // namespace WebCore |
99 | |
100 | #endif // ENABLE(STREAMS_API) |
101 | |