summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/modules/fetch/FetchRequestData.h
blob: fd20e4fbef8bd0c052706fe924a94f7ecec3db15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FetchRequestData_h
#define FetchRequestData_h

#include "platform/heap/Handle.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/Referrer.h"
#include "platform/weborigin/ReferrerPolicy.h"
#include "public/platform/WebURLRequest.h"
#include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/text/AtomicString.h"
#include "wtf/text/WTFString.h"

namespace blink {

class BodyStreamBuffer;
class ExecutionContext;
class FetchHeaderList;
class SecurityOrigin;
class WebServiceWorkerRequest;

class FetchRequestData final : public GarbageCollectedFinalized<FetchRequestData> {
    WTF_MAKE_NONCOPYABLE(FetchRequestData);
public:
    enum Tainting { BasicTainting, CORSTainting, OpaqueTainting };

    static FetchRequestData* create();
    static FetchRequestData* create(ExecutionContext*, const WebServiceWorkerRequest&);
    // Call Request::refreshBody() after calling clone() or pass().
    FetchRequestData* clone(ExecutionContext*);
    FetchRequestData* pass(ExecutionContext*);
    ~FetchRequestData();

    void setMethod(AtomicString method) { m_method = method; }
    const AtomicString& method() const { return m_method; }
    void setURL(const KURL& url) { m_url = url; }
    const KURL& url() const { return m_url; }
    bool unsafeRequestFlag() const { return m_unsafeRequestFlag; }
    void setUnsafeRequestFlag(bool flag) { m_unsafeRequestFlag = flag; }
    WebURLRequest::RequestContext context() const { return m_context; }
    void setContext(WebURLRequest::RequestContext context) { m_context = context; }
    PassRefPtr<SecurityOrigin> origin() { return m_origin; }
    void setOrigin(PassRefPtr<SecurityOrigin> origin) { m_origin = origin; }
    bool sameOriginDataURLFlag() { return m_sameOriginDataURLFlag; }
    void setSameOriginDataURLFlag(bool flag) { m_sameOriginDataURLFlag = flag; }
    const Referrer& referrer() const { return m_referrer; }
    void setReferrer(const Referrer& r) { m_referrer = r; }
    const AtomicString& referrerString() const { return m_referrer.referrer; }
    void setReferrerString(const AtomicString& s) { m_referrer.referrer = s; }
    ReferrerPolicy referrerPolicy() const { return m_referrer.referrerPolicy; }
    void setReferrerPolicy(ReferrerPolicy p) { m_referrer.referrerPolicy = p; }
    void setMode(WebURLRequest::FetchRequestMode mode) { m_mode = mode; }
    WebURLRequest::FetchRequestMode mode() const { return m_mode; }
    void setCredentials(WebURLRequest::FetchCredentialsMode credentials) { m_credentials = credentials; }
    WebURLRequest::FetchCredentialsMode credentials() const { return m_credentials; }
    void setRedirect(WebURLRequest::FetchRedirectMode redirect) { m_redirect = redirect; }
    WebURLRequest::FetchRedirectMode redirect() const { return m_redirect; }
    void setResponseTainting(Tainting tainting) { m_responseTainting = tainting; }
    Tainting tainting() const { return m_responseTainting; }
    FetchHeaderList* headerList() const { return m_headerList.get(); }
    void setHeaderList(FetchHeaderList* headerList) { m_headerList = headerList; }
    BodyStreamBuffer* buffer() const { return m_buffer; }
    // Call Request::refreshBody() after calling setBuffer().
    void setBuffer(BodyStreamBuffer* buffer) { m_buffer = buffer; }
    String mimeType() const { return m_mimeType; }
    void setMIMEType(const String& type) { m_mimeType = type; }
    String integrity() const { return m_integrity; }
    void setIntegrity(const String& integrity) { m_integrity = integrity; }

    // We use these strings instead of "no-referrer" and "client" in the spec.
    static AtomicString noReferrerString() { return AtomicString(); }
    static AtomicString clientReferrerString() { return AtomicString("about:client", AtomicString::ConstructFromLiteral); }

    DECLARE_TRACE();

private:
    FetchRequestData();

    FetchRequestData* cloneExceptBody();

    AtomicString m_method;
    KURL m_url;
    Member<FetchHeaderList> m_headerList;
    bool m_unsafeRequestFlag;
    // FIXME: Support m_skipServiceWorkerFlag;
    WebURLRequest::RequestContext m_context;
    RefPtr<SecurityOrigin> m_origin;
    // FIXME: Support m_forceOriginHeaderFlag;
    bool m_sameOriginDataURLFlag;
    // |m_referrer| consists of referrer string and referrer policy.
    // We use |noReferrerString()| and |clientReferrerString()| as
    // "no-referrer" and "client" strings in the spec.
    Referrer m_referrer;
    // FIXME: Support m_authenticationFlag;
    // FIXME: Support m_synchronousFlag;
    WebURLRequest::FetchRequestMode m_mode;
    WebURLRequest::FetchCredentialsMode m_credentials;
    WebURLRequest::FetchRedirectMode m_redirect;
    // FIXME: Support m_useURLCredentialsFlag;
    // FIXME: Support m_redirectCount;
    Tainting m_responseTainting;
    Member<BodyStreamBuffer> m_buffer;
    String m_mimeType;
    String m_integrity;
};

} // namespace blink

#endif // FetchRequestData_h