1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "FetchRequestData.h"
7
8 #include "core/dom/Document.h"
9 #include "core/dom/ExecutionContext.h"
10 #include "core/fetch/ResourceLoaderOptions.h"
11 #include "core/loader/ThreadableLoader.h"
12 #include "modules/serviceworkers/FetchHeaderList.h"
13 #include "platform/network/ResourceRequest.h"
14 #include "public/platform/WebServiceWorkerRequest.h"
15
16 namespace blink {
17
create()18 FetchRequestData* FetchRequestData::create()
19 {
20 return new FetchRequestData();
21 }
22
create(ExecutionContext * context)23 FetchRequestData* FetchRequestData::create(ExecutionContext* context)
24 {
25 FetchRequestData* request = FetchRequestData::create();
26 if (context->isDocument())
27 request->m_referrer.setClient(blink::Referrer(context->url().strippedForUseAsReferrer(), toDocument(context)->referrerPolicy()));
28 else
29 request->m_referrer.setClient(blink::Referrer(context->url().strippedForUseAsReferrer(), ReferrerPolicyDefault));
30 return request;
31 }
32
create(const WebServiceWorkerRequest & webRequest)33 FetchRequestData* FetchRequestData::create(const WebServiceWorkerRequest& webRequest)
34 {
35 FetchRequestData* request = FetchRequestData::create();
36 request->m_url = webRequest.url();
37 request->m_method = webRequest.method();
38 for (HTTPHeaderMap::const_iterator it = webRequest.headers().begin(); it != webRequest.headers().end(); ++it)
39 request->m_headerList->append(it->key, it->value);
40 request->m_blobDataHandle = webRequest.blobDataHandle();
41 request->m_referrer.setURL(webRequest.referrer());
42 return request;
43 }
44
createRestrictedCopy(ExecutionContext * context,PassRefPtr<SecurityOrigin> origin) const45 FetchRequestData* FetchRequestData::createRestrictedCopy(ExecutionContext* context, PassRefPtr<SecurityOrigin> origin) const
46 {
47 // "To make a restricted copy of a request |request|, run these steps:
48 // 1. Let |r| be a new request whose url is |request|'s url, method is
49 // |request|'s method, header list is a copy of |request|'s header list,
50 // body is a tee of |request|'s body, client is entry settings object's
51 // global object, origin is entry settings object's origin, referrer is
52 // |client|, context is |connect|, mode is |request|'s mode, and credentials
53 // mode is |request|'s credentials mode."
54 FetchRequestData* request = FetchRequestData::create();
55 request->m_url = m_url;
56 request->m_method = m_method;
57 request->m_headerList = m_headerList->createCopy();
58 request->m_blobDataHandle = m_blobDataHandle;
59 request->m_origin = origin;
60 if (context->isDocument())
61 request->m_referrer.setClient(blink::Referrer(context->url().strippedForUseAsReferrer(), toDocument(context)->referrerPolicy()));
62 else
63 request->m_referrer.setClient(blink::Referrer(context->url().strippedForUseAsReferrer(), ReferrerPolicyDefault));
64 request->m_context = ConnectContext;
65 request->m_mode = m_mode;
66 request->m_credentials = m_credentials;
67 // "2. Return |r|."
68 return request;
69 }
70
createCopy() const71 FetchRequestData* FetchRequestData::createCopy() const
72 {
73 FetchRequestData* request = FetchRequestData::create();
74 request->m_url = m_url;
75 request->m_method = m_method;
76 request->m_headerList = m_headerList->createCopy();
77 request->m_unsafeRequestFlag = m_unsafeRequestFlag;
78 request->m_blobDataHandle = m_blobDataHandle;
79 request->m_origin = m_origin;
80 request->m_sameOriginDataURLFlag = m_sameOriginDataURLFlag;
81 request->m_context = m_context;
82 request->m_referrer = m_referrer;
83 request->m_mode = m_mode;
84 request->m_credentials = m_credentials;
85 request->m_responseTainting = m_responseTainting;
86 return request;
87 }
88
~FetchRequestData()89 FetchRequestData::~FetchRequestData()
90 {
91 }
92
FetchRequestData()93 FetchRequestData::FetchRequestData()
94 : m_method("GET")
95 , m_headerList(FetchHeaderList::create())
96 , m_unsafeRequestFlag(false)
97 , m_context(NullContext)
98 , m_sameOriginDataURLFlag(false)
99 , m_mode(NoCORSMode)
100 , m_credentials(OmitCredentials)
101 , m_responseTainting(BasicTainting)
102 {
103 }
104
trace(Visitor * visitor)105 void FetchRequestData::trace(Visitor* visitor)
106 {
107 visitor->trace(m_headerList);
108 }
109
110 } // namespace blink
111