youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 Canon Inc. |
commit-queue@webkit.org | a57234a | 2017-08-31 20:03:42 +0000 | [diff] [blame] | 3 | * Copyright (C) 2017 Apple Inc. |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 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. |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 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" |
commit-queue@webkit.org | a57234a | 2017-08-31 20:03:42 +0000 | [diff] [blame] | 28 | #include "FetchBodySource.h" |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 29 | |
jlewis3@apple.com | c9f6abb | 2017-08-04 18:28:23 +0000 | [diff] [blame] | 30 | #if ENABLE(STREAMS_API) |
| 31 | |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 32 | #include "FetchResponse.h" |
| 33 | |
| 34 | namespace WebCore { |
| 35 | |
commit-queue@webkit.org | a57234a | 2017-08-31 20:03:42 +0000 | [diff] [blame] | 36 | FetchBodySource::FetchBodySource(FetchBodyOwner& bodyOwner) |
youenn@apple.com | 8684834b | 2018-07-20 16:58:54 +0000 | [diff] [blame] | 37 | : m_bodyOwner(&bodyOwner) |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
commit-queue@webkit.org | a57234a | 2017-08-31 20:03:42 +0000 | [diff] [blame] | 41 | void FetchBodySource::setActive() |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 42 | { |
youenn@apple.com | 8684834b | 2018-07-20 16:58:54 +0000 | [diff] [blame] | 43 | ASSERT(m_bodyOwner); |
| 44 | if (m_bodyOwner) |
darin@apple.com | 9ee6097 | 2019-01-21 19:01:19 +0000 | [diff] [blame] | 45 | m_bodyOwner->setPendingActivity(*m_bodyOwner); |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 46 | } |
| 47 | |
commit-queue@webkit.org | a57234a | 2017-08-31 20:03:42 +0000 | [diff] [blame] | 48 | void FetchBodySource::setInactive() |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 49 | { |
youenn@apple.com | 8684834b | 2018-07-20 16:58:54 +0000 | [diff] [blame] | 50 | ASSERT(m_bodyOwner); |
| 51 | if (m_bodyOwner) |
darin@apple.com | 9ee6097 | 2019-01-21 19:01:19 +0000 | [diff] [blame] | 52 | m_bodyOwner->unsetPendingActivity(*m_bodyOwner); |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 53 | } |
| 54 | |
commit-queue@webkit.org | a57234a | 2017-08-31 20:03:42 +0000 | [diff] [blame] | 55 | void FetchBodySource::doStart() |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 56 | { |
youenn@apple.com | 8684834b | 2018-07-20 16:58:54 +0000 | [diff] [blame] | 57 | ASSERT(m_bodyOwner); |
| 58 | if (m_bodyOwner) |
| 59 | m_bodyOwner->consumeBodyAsStream(); |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 60 | } |
| 61 | |
commit-queue@webkit.org | a57234a | 2017-08-31 20:03:42 +0000 | [diff] [blame] | 62 | void FetchBodySource::doPull() |
commit-queue@webkit.org | f4555b72 | 2016-07-13 16:08:51 +0000 | [diff] [blame] | 63 | { |
youenn@apple.com | 8684834b | 2018-07-20 16:58:54 +0000 | [diff] [blame] | 64 | ASSERT(m_bodyOwner); |
| 65 | if (m_bodyOwner) |
| 66 | m_bodyOwner->feedStream(); |
commit-queue@webkit.org | f4555b72 | 2016-07-13 16:08:51 +0000 | [diff] [blame] | 67 | } |
| 68 | |
commit-queue@webkit.org | a57234a | 2017-08-31 20:03:42 +0000 | [diff] [blame] | 69 | void FetchBodySource::doCancel() |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 70 | { |
| 71 | m_isCancelling = true; |
youenn@apple.com | 8684834b | 2018-07-20 16:58:54 +0000 | [diff] [blame] | 72 | ASSERT(m_bodyOwner || m_isClosed); |
| 73 | if (!m_bodyOwner) |
| 74 | return; |
| 75 | |
| 76 | m_bodyOwner->cancel(); |
| 77 | m_bodyOwner = nullptr; |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 78 | } |
| 79 | |
commit-queue@webkit.org | a57234a | 2017-08-31 20:03:42 +0000 | [diff] [blame] | 80 | void FetchBodySource::close() |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 81 | { |
mark.lam@apple.com | 6572436 | 2020-01-06 22:24:50 +0000 | [diff] [blame] | 82 | #if ASSERT_ENABLED |
youenn@apple.com | 8684834b | 2018-07-20 16:58:54 +0000 | [diff] [blame] | 83 | m_isClosed = true; |
| 84 | #endif |
| 85 | |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 86 | controller().close(); |
| 87 | clean(); |
youenn@apple.com | 8684834b | 2018-07-20 16:58:54 +0000 | [diff] [blame] | 88 | m_bodyOwner = nullptr; |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 89 | } |
commit-queue@webkit.org | 5690f0b | 2017-09-09 03:32:59 +0000 | [diff] [blame] | 90 | |
youenn@apple.com | 68dd54b | 2019-01-05 00:01:43 +0000 | [diff] [blame] | 91 | void FetchBodySource::error(const Exception& value) |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 92 | { |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 93 | controller().error(value); |
| 94 | clean(); |
youenn@apple.com | 8684834b | 2018-07-20 16:58:54 +0000 | [diff] [blame] | 95 | m_bodyOwner = nullptr; |
youenn.fablet@crf.canon.fr | 51223ca | 2016-04-17 18:04:20 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | } // namespace WebCore |
jlewis3@apple.com | c9f6abb | 2017-08-04 18:28:23 +0000 | [diff] [blame] | 99 | |
| 100 | #endif // ENABLE(STREAMS_API) |