1 | /* |
2 | * Copyright (C) 2016 Canon Inc. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted, provided that the following conditions |
6 | * are required to be met: |
7 | * |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * 3. Neither the name of Canon Inc. nor the names of |
14 | * its contributors may be used to endorse or promote products derived |
15 | * from this software without specific prior written permission. |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY CANON INC. AND ITS CONTRIBUTORS "AS IS" AND ANY |
18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
20 | * DISCLAIMED. IN NO EVENT SHALL CANON INC. AND ITS CONTRIBUTORS BE LIABLE FOR |
21 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | |
29 | #pragma once |
30 | |
31 | #include "AbortSignal.h" |
32 | #include "ExceptionOr.h" |
33 | #include "FetchBodyOwner.h" |
34 | #include "FetchOptions.h" |
35 | #include "FetchRequestInit.h" |
36 | #include "ResourceRequest.h" |
37 | #include <wtf/Optional.h> |
38 | |
39 | namespace WebCore { |
40 | |
41 | class Blob; |
42 | class ScriptExecutionContext; |
43 | class URLSearchParams; |
44 | |
45 | class FetchRequest final : public FetchBodyOwner { |
46 | public: |
47 | using Init = FetchRequestInit; |
48 | using Info = Variant<RefPtr<FetchRequest>, String>; |
49 | |
50 | using Cache = FetchOptions::Cache; |
51 | using Credentials = FetchOptions::Credentials; |
52 | using Destination = FetchOptions::Destination; |
53 | using Mode = FetchOptions::Mode; |
54 | using Redirect = FetchOptions::Redirect; |
55 | |
56 | static ExceptionOr<Ref<FetchRequest>> create(ScriptExecutionContext&, Info&&, Init&&); |
57 | static Ref<FetchRequest> create(ScriptExecutionContext& context, Optional<FetchBody>&& body, Ref<FetchHeaders>&& , ResourceRequest&& request, FetchOptions&& options, String&& referrer) { return adoptRef(*new FetchRequest(context, WTFMove(body), WTFMove(headers), WTFMove(request), WTFMove(options), WTFMove(referrer))); } |
58 | |
59 | const String& method() const { return m_request.httpMethod(); } |
60 | const String& urlString() const; |
61 | FetchHeaders& () { return m_headers.get(); } |
62 | const FetchHeaders& () const { return m_headers.get(); } |
63 | |
64 | Destination destination() const { return m_options.destination; } |
65 | String referrer() const; |
66 | ReferrerPolicy referrerPolicy() const { return m_options.referrerPolicy; } |
67 | Mode mode() const { return m_options.mode; } |
68 | Credentials credentials() const { return m_options.credentials; } |
69 | Cache cache() const { return m_options.cache; } |
70 | Redirect redirect() const { return m_options.redirect; } |
71 | bool keepalive() const { return m_options.keepAlive; }; |
72 | AbortSignal& signal() { return m_signal.get(); } |
73 | |
74 | const String& integrity() const { return m_options.integrity; } |
75 | |
76 | ExceptionOr<Ref<FetchRequest>> clone(ScriptExecutionContext&); |
77 | |
78 | const FetchOptions& fetchOptions() const { return m_options; } |
79 | const ResourceRequest& internalRequest() const { return m_request; } |
80 | const String& internalRequestReferrer() const { return m_referrer; } |
81 | const URL& url() const { return m_request.url(); } |
82 | |
83 | ResourceRequest resourceRequest() const; |
84 | |
85 | private: |
86 | FetchRequest(ScriptExecutionContext&, Optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceRequest&&, FetchOptions&&, String&& referrer); |
87 | |
88 | ExceptionOr<void> initializeOptions(const Init&); |
89 | ExceptionOr<void> initializeWith(FetchRequest&, Init&&); |
90 | ExceptionOr<void> initializeWith(const String&, Init&&); |
91 | ExceptionOr<void> setBody(FetchBody::Init&&); |
92 | ExceptionOr<void> setBody(FetchRequest&); |
93 | |
94 | const char* activeDOMObjectName() const final; |
95 | bool canSuspendForDocumentSuspension() const final; |
96 | |
97 | ResourceRequest m_request; |
98 | FetchOptions m_options; |
99 | String m_referrer; |
100 | mutable String m_requestURL; |
101 | Ref<AbortSignal> m_signal; |
102 | }; |
103 | |
104 | inline FetchRequest::FetchRequest(ScriptExecutionContext& context, Optional<FetchBody>&& body, Ref<FetchHeaders>&& , ResourceRequest&& request, FetchOptions&& options, String&& referrer) |
105 | : FetchBodyOwner(context, WTFMove(body), WTFMove(headers)) |
106 | , m_request(WTFMove(request)) |
107 | , m_options(WTFMove(options)) |
108 | , m_referrer(WTFMove(referrer)) |
109 | , m_signal(AbortSignal::create(context)) |
110 | { |
111 | updateContentType(); |
112 | } |
113 | |
114 | } // namespace WebCore |
115 | |