1 | /* |
2 | * Copyright (C) 2019 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "ServiceWorkerFetchTask.h" |
28 | |
29 | #if ENABLE(SERVICE_WORKER) |
30 | |
31 | #include "Connection.h" |
32 | #include "DataReference.h" |
33 | #include "FormDataReference.h" |
34 | #include "Logging.h" |
35 | #include "ServiceWorkerClientFetchMessages.h" |
36 | #include "WebCoreArgumentCoders.h" |
37 | |
38 | #define RELEASE_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(m_sessionID.isAlwaysOnLoggingAllowed(), ServiceWorker, "%p - ServiceWorkerFetchTask::" fmt, this, ##__VA_ARGS__) |
39 | #define RELEASE_LOG_ERROR_IF_ALLOWED(fmt, ...) RELEASE_LOG_ERROR_IF(m_sessionID.isAlwaysOnLoggingAllowed(), ServiceWorker, "%p - ServiceWorkerFetchTask::" fmt, this, ##__VA_ARGS__) |
40 | |
41 | using namespace WebCore; |
42 | |
43 | namespace WebKit { |
44 | |
45 | void ServiceWorkerFetchTask::didReceiveRedirectResponse(const ResourceResponse& response) |
46 | { |
47 | RELEASE_LOG_IF_ALLOWED("didReceiveRedirectResponse: %s" , m_identifier.fetchIdentifier.loggingString().utf8().data()); |
48 | m_connection->send(Messages::ServiceWorkerClientFetch::DidReceiveRedirectResponse { response }, m_identifier.fetchIdentifier); |
49 | } |
50 | |
51 | void ServiceWorkerFetchTask::didReceiveResponse(const ResourceResponse& response, bool needsContinueDidReceiveResponseMessage) |
52 | { |
53 | m_connection->send(Messages::ServiceWorkerClientFetch::DidReceiveResponse { response, needsContinueDidReceiveResponseMessage }, m_identifier.fetchIdentifier); |
54 | } |
55 | |
56 | void ServiceWorkerFetchTask::didReceiveData(const IPC::DataReference& data, int64_t encodedDataLength) |
57 | { |
58 | m_connection->send(Messages::ServiceWorkerClientFetch::DidReceiveData { data, encodedDataLength }, m_identifier.fetchIdentifier); |
59 | } |
60 | |
61 | void ServiceWorkerFetchTask::didReceiveFormData(const IPC::FormDataReference& formData) |
62 | { |
63 | m_connection->send(Messages::ServiceWorkerClientFetch::DidReceiveFormData { formData }, m_identifier.fetchIdentifier); |
64 | } |
65 | |
66 | void ServiceWorkerFetchTask::didFinish() |
67 | { |
68 | RELEASE_LOG_IF_ALLOWED("didFinishFetch: fetchIdentifier: %s" , m_identifier.fetchIdentifier.loggingString().utf8().data()); |
69 | m_connection->send(Messages::ServiceWorkerClientFetch::DidFinish { }, m_identifier.fetchIdentifier); |
70 | } |
71 | |
72 | void ServiceWorkerFetchTask::didFail(const ResourceError& error) |
73 | { |
74 | RELEASE_LOG_ERROR_IF_ALLOWED("didFailFetch: fetchIdentifier: %s" , m_identifier.fetchIdentifier.loggingString().utf8().data()); |
75 | m_connection->send(Messages::ServiceWorkerClientFetch::DidFail { error }, m_identifier.fetchIdentifier); |
76 | } |
77 | |
78 | void ServiceWorkerFetchTask::didNotHandle() |
79 | { |
80 | RELEASE_LOG_IF_ALLOWED("didNotHandleFetch: fetchIdentifier: %s" , m_identifier.fetchIdentifier.loggingString().utf8().data()); |
81 | m_connection->send(Messages::ServiceWorkerClientFetch::DidNotHandle { }, m_identifier.fetchIdentifier); |
82 | } |
83 | |
84 | } // namespace WebKit |
85 | |
86 | #endif // ENABLE(SERVICE_WORKER) |
87 | |