blob: 941da6b8d287f20ac758d3426fd72f7a43649455 [file] [log] [blame]
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +00001/*
2 * Copyright (C) 2016 Canon Inc.
commit-queue@webkit.orga57234a2017-08-31 20:03:42 +00003 * Copyright (C) 2017 Apple Inc.
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +00004 *
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.fr51223ca2016-04-17 18:04:20 +000014 *
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.orga57234a2017-08-31 20:03:42 +000028#include "FetchBodySource.h"
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000029
jlewis3@apple.comc9f6abb2017-08-04 18:28:23 +000030#if ENABLE(STREAMS_API)
31
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000032#include "FetchResponse.h"
33
34namespace WebCore {
35
commit-queue@webkit.orga57234a2017-08-31 20:03:42 +000036FetchBodySource::FetchBodySource(FetchBodyOwner& bodyOwner)
youenn@apple.com8684834b2018-07-20 16:58:54 +000037 : m_bodyOwner(&bodyOwner)
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000038{
39}
40
commit-queue@webkit.orga57234a2017-08-31 20:03:42 +000041void FetchBodySource::setActive()
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000042{
youenn@apple.com8684834b2018-07-20 16:58:54 +000043 ASSERT(m_bodyOwner);
44 if (m_bodyOwner)
darin@apple.com9ee60972019-01-21 19:01:19 +000045 m_bodyOwner->setPendingActivity(*m_bodyOwner);
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000046}
47
commit-queue@webkit.orga57234a2017-08-31 20:03:42 +000048void FetchBodySource::setInactive()
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000049{
youenn@apple.com8684834b2018-07-20 16:58:54 +000050 ASSERT(m_bodyOwner);
51 if (m_bodyOwner)
darin@apple.com9ee60972019-01-21 19:01:19 +000052 m_bodyOwner->unsetPendingActivity(*m_bodyOwner);
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000053}
54
commit-queue@webkit.orga57234a2017-08-31 20:03:42 +000055void FetchBodySource::doStart()
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000056{
youenn@apple.com8684834b2018-07-20 16:58:54 +000057 ASSERT(m_bodyOwner);
58 if (m_bodyOwner)
59 m_bodyOwner->consumeBodyAsStream();
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000060}
61
commit-queue@webkit.orga57234a2017-08-31 20:03:42 +000062void FetchBodySource::doPull()
commit-queue@webkit.orgf4555b722016-07-13 16:08:51 +000063{
youenn@apple.com8684834b2018-07-20 16:58:54 +000064 ASSERT(m_bodyOwner);
65 if (m_bodyOwner)
66 m_bodyOwner->feedStream();
commit-queue@webkit.orgf4555b722016-07-13 16:08:51 +000067}
68
commit-queue@webkit.orga57234a2017-08-31 20:03:42 +000069void FetchBodySource::doCancel()
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000070{
71 m_isCancelling = true;
youenn@apple.com8684834b2018-07-20 16:58:54 +000072 ASSERT(m_bodyOwner || m_isClosed);
73 if (!m_bodyOwner)
74 return;
75
76 m_bodyOwner->cancel();
77 m_bodyOwner = nullptr;
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000078}
79
commit-queue@webkit.orga57234a2017-08-31 20:03:42 +000080void FetchBodySource::close()
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000081{
mark.lam@apple.com65724362020-01-06 22:24:50 +000082#if ASSERT_ENABLED
youenn@apple.com8684834b2018-07-20 16:58:54 +000083 m_isClosed = true;
84#endif
85
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000086 controller().close();
87 clean();
youenn@apple.com8684834b2018-07-20 16:58:54 +000088 m_bodyOwner = nullptr;
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000089}
commit-queue@webkit.org5690f0b2017-09-09 03:32:59 +000090
youenn@apple.com68dd54b2019-01-05 00:01:43 +000091void FetchBodySource::error(const Exception& value)
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000092{
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000093 controller().error(value);
94 clean();
youenn@apple.com8684834b2018-07-20 16:58:54 +000095 m_bodyOwner = nullptr;
youenn.fablet@crf.canon.fr51223ca2016-04-17 18:04:20 +000096}
97
98} // namespace WebCore
jlewis3@apple.comc9f6abb2017-08-04 18:28:23 +000099
100#endif // ENABLE(STREAMS_API)