1 | /* |
2 | * Copyright (C) 2017 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 | #pragma once |
27 | |
28 | #include "WebProcessProxy.h" |
29 | #include <WebCore/ResourceRequest.h> |
30 | #include <WebCore/ResourceResponse.h> |
31 | #include <WebCore/SharedBuffer.h> |
32 | #include <wtf/CompletionHandler.h> |
33 | #include <wtf/InstanceCounted.h> |
34 | #include <wtf/RefCounted.h> |
35 | #include <wtf/RefPtr.h> |
36 | |
37 | namespace IPC { |
38 | class DataReference; |
39 | } |
40 | |
41 | namespace WebCore { |
42 | class ResourceError; |
43 | class ResourceResponse; |
44 | class SharedBuffer; |
45 | } |
46 | |
47 | namespace WebKit { |
48 | |
49 | class WebURLSchemeHandler; |
50 | class WebPageProxy; |
51 | |
52 | using SyncLoadCompletionHandler = CompletionHandler<void(const WebCore::ResourceResponse&, const WebCore::ResourceError&, const IPC::DataReference&)>; |
53 | |
54 | class WebURLSchemeTask : public RefCounted<WebURLSchemeTask>, public InstanceCounted<WebURLSchemeTask> { |
55 | WTF_MAKE_NONCOPYABLE(WebURLSchemeTask); |
56 | public: |
57 | static Ref<WebURLSchemeTask> create(WebURLSchemeHandler&, WebPageProxy&, WebProcessProxy&, uint64_t identifier, WebCore::ResourceRequest&&, SyncLoadCompletionHandler&&); |
58 | |
59 | uint64_t identifier() const { return m_identifier; } |
60 | WebCore::PageIdentifier pageID() const { return m_pageIdentifier; } |
61 | WebProcessProxy* process() const { return m_process.get(); } |
62 | |
63 | const WebCore::ResourceRequest& request() const { return m_request; } |
64 | |
65 | enum class ExceptionType { |
66 | DataAlreadySent, |
67 | CompleteAlreadyCalled, |
68 | RedirectAfterResponse, |
69 | TaskAlreadyStopped, |
70 | NoResponseSent, |
71 | None, |
72 | }; |
73 | ExceptionType didPerformRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&); |
74 | ExceptionType didReceiveResponse(const WebCore::ResourceResponse&); |
75 | ExceptionType didReceiveData(Ref<WebCore::SharedBuffer>&&); |
76 | ExceptionType didComplete(const WebCore::ResourceError&); |
77 | |
78 | void stop(); |
79 | void pageDestroyed(); |
80 | |
81 | private: |
82 | WebURLSchemeTask(WebURLSchemeHandler&, WebPageProxy&, WebProcessProxy&, uint64_t identifier, WebCore::ResourceRequest&&, SyncLoadCompletionHandler&&); |
83 | |
84 | bool isSync() const { return !!m_syncCompletionHandler; } |
85 | |
86 | Ref<WebURLSchemeHandler> m_urlSchemeHandler; |
87 | WebPageProxy* m_page; |
88 | RefPtr<WebProcessProxy> m_process; |
89 | uint64_t m_identifier; |
90 | WebCore::PageIdentifier m_pageIdentifier; |
91 | WebCore::ResourceRequest m_request; |
92 | bool m_stopped { false }; |
93 | bool m_responseSent { false }; |
94 | bool m_dataSent { false }; |
95 | bool m_completed { false }; |
96 | |
97 | SyncLoadCompletionHandler m_syncCompletionHandler; |
98 | WebCore::ResourceResponse m_syncResponse; |
99 | RefPtr<WebCore::SharedBuffer> m_syncData; |
100 | }; |
101 | |
102 | } // namespace WebKit |
103 | |