Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: Source/modules/serviceworkers/Request.cpp

Issue 478693005: Oilpan: Ship Oilpan for serviceworkers/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "Request.h" 6 #include "Request.h"
7 7
8 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.h"
9 #include "core/dom/ExecutionContext.h" 9 #include "core/dom/ExecutionContext.h"
10 #include "core/fetch/FetchUtils.h" 10 #include "core/fetch/FetchUtils.h"
11 #include "core/fetch/ResourceLoaderOptions.h" 11 #include "core/fetch/ResourceLoaderOptions.h"
12 #include "core/loader/ThreadableLoader.h" 12 #include "core/loader/ThreadableLoader.h"
13 #include "core/xml/XMLHttpRequest.h" 13 #include "core/xml/XMLHttpRequest.h"
14 #include "modules/serviceworkers/FetchManager.h" 14 #include "modules/serviceworkers/FetchManager.h"
15 #include "modules/serviceworkers/RequestInit.h" 15 #include "modules/serviceworkers/RequestInit.h"
16 #include "platform/NotImplemented.h" 16 #include "platform/NotImplemented.h"
17 #include "platform/network/HTTPParsers.h" 17 #include "platform/network/HTTPParsers.h"
18 #include "platform/network/ResourceRequest.h" 18 #include "platform/network/ResourceRequest.h"
19 #include "platform/weborigin/Referrer.h" 19 #include "platform/weborigin/Referrer.h"
20 #include "public/platform/WebServiceWorkerRequest.h" 20 #include "public/platform/WebServiceWorkerRequest.h"
21 21
22 namespace blink { 22 namespace blink {
23 23
24 namespace { 24 namespace {
25 25
26 PassRefPtrWillBeRawPtr<Request> createRequestWithRequestData(PassRefPtrWillBeRaw Ptr<FetchRequestData> request, const RequestInit& init, FetchRequestData::Mode m ode, FetchRequestData::Credentials credentials, ExceptionState& exceptionState) 26 Request* createRequestWithRequestData(FetchRequestData* request, const RequestIn it& init, FetchRequestData::Mode mode, FetchRequestData::Credentials credentials , ExceptionState& exceptionState)
27 { 27 {
28 // "6. Let |mode| be |init|'s mode member if it is present, and 28 // "6. Let |mode| be |init|'s mode member if it is present, and
29 // |fallbackMode| otherwise." 29 // |fallbackMode| otherwise."
30 // "7. If |mode| is non-null, set |request|'s mode to |mode|." 30 // "7. If |mode| is non-null, set |request|'s mode to |mode|."
31 if (init.mode == "same-origin") { 31 if (init.mode == "same-origin") {
32 request->setMode(FetchRequestData::SameOriginMode); 32 request->setMode(FetchRequestData::SameOriginMode);
33 } else if (init.mode == "no-cors") { 33 } else if (init.mode == "no-cors") {
34 request->setMode(mode = FetchRequestData::NoCORSMode); 34 request->setMode(mode = FetchRequestData::NoCORSMode);
35 } else if (init.mode == "cors") { 35 } else if (init.mode == "cors") {
36 request->setMode(FetchRequestData::CORSMode); 36 request->setMode(FetchRequestData::CORSMode);
(...skipping 18 matching lines...) Expand all
55 // current credentials in Request::create(). So we just set here. 55 // current credentials in Request::create(). So we just set here.
56 request->setCredentials(credentials); 56 request->setCredentials(credentials);
57 } 57 }
58 58
59 // "10. If |init|'s method member is present, let |method| be it and run 59 // "10. If |init|'s method member is present, let |method| be it and run
60 // these substeps:" 60 // these substeps:"
61 if (!init.method.isEmpty()) { 61 if (!init.method.isEmpty()) {
62 // "1. If |method| is not a useful method, throw a TypeError." 62 // "1. If |method| is not a useful method, throw a TypeError."
63 if (!FetchUtils::isUsefulMethod(init.method)) { 63 if (!FetchUtils::isUsefulMethod(init.method)) {
64 exceptionState.throwTypeError("'" + init.method + "' HTTP method is unsupported."); 64 exceptionState.throwTypeError("'" + init.method + "' HTTP method is unsupported.");
65 return nullptr; 65 return 0;
66 } 66 }
67 if (!isValidHTTPToken(init.method)) { 67 if (!isValidHTTPToken(init.method)) {
68 exceptionState.throwTypeError("'" + init.method + "' is not a valid HTTP method."); 68 exceptionState.throwTypeError("'" + init.method + "' is not a valid HTTP method.");
69 return nullptr; 69 return 0;
70 } 70 }
71 // FIXME: "2. Add case correction as in XMLHttpRequest?" 71 // FIXME: "2. Add case correction as in XMLHttpRequest?"
72 // "3. Set |request|'s method to |method|." 72 // "3. Set |request|'s method to |method|."
73 request->setMethod(XMLHttpRequest::uppercaseKnownHTTPMethod(AtomicString (init.method))); 73 request->setMethod(XMLHttpRequest::uppercaseKnownHTTPMethod(AtomicString (init.method)));
74 } 74 }
75 // "11. Let |r| be a new Request object associated with |request|, Headers 75 // "11. Let |r| be a new Request object associated with |request|, Headers
76 // object, and FetchBodyStream object." 76 // object, and FetchBodyStream object."
77 RefPtrWillBeRawPtr<Request> r = Request::create(request); 77 Request* r = Request::create(request);
78 78
79 // "12. Let |headers| be a copy of |r|'s Headers object." 79 // "12. Let |headers| be a copy of |r|'s Headers object."
80 // "13. If |init|'s headers member is present, set |headers| to |init|'s 80 // "13. If |init|'s headers member is present, set |headers| to |init|'s
81 // headers member." 81 // headers member."
82 // We don't create a copy of r's Headers object when init's headers member 82 // We don't create a copy of r's Headers object when init's headers member
83 // is present. 83 // is present.
84 RefPtrWillBeRawPtr<Headers> headers = nullptr; 84 Headers* headers = 0;
85 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { 85 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) {
86 headers = r->headers()->createCopy(); 86 headers = r->headers()->createCopy();
87 } 87 }
88 // "14. Empty |r|'s request's header list." 88 // "14. Empty |r|'s request's header list."
89 r->request()->headerList()->clearList(); 89 r->request()->headerList()->clearList();
90 90
91 // "15. If |r|'s request's mode is no CORS, run these substeps: 91 // "15. If |r|'s request's mode is no CORS, run these substeps:
92 if (r->request()->mode() == FetchRequestData::NoCORSMode) { 92 if (r->request()->mode() == FetchRequestData::NoCORSMode) {
93 // "1. If |r|'s request's method is not a simple method, throw a 93 // "1. If |r|'s request's method is not a simple method, throw a
94 // TypeError." 94 // TypeError."
95 if (!FetchUtils::isSimpleMethod(r->request()->method())) { 95 if (!FetchUtils::isSimpleMethod(r->request()->method())) {
96 exceptionState.throwTypeError("'" + r->request()->method() + "' is u nsupported in no-cors mode."); 96 exceptionState.throwTypeError("'" + r->request()->method() + "' is u nsupported in no-cors mode.");
97 return nullptr; 97 return 0;
98 } 98 }
99 // "Set |r|'s Headers object's guard to |request-no-CORS|. 99 // "Set |r|'s Headers object's guard to |request-no-CORS|.
100 r->headers()->setGuard(Headers::RequestNoCORSGuard); 100 r->headers()->setGuard(Headers::RequestNoCORSGuard);
101 } 101 }
102 102
103 // "16. Fill |r|'s Headers object with |headers|. Rethrow any exceptions." 103 // "16. Fill |r|'s Headers object with |headers|. Rethrow any exceptions."
104 if (init.headers) { 104 if (init.headers) {
105 ASSERT(init.headersDictionary.isUndefinedOrNull()); 105 ASSERT(init.headersDictionary.isUndefinedOrNull());
106 r->headers()->fillWith(init.headers.get(), exceptionState); 106 r->headers()->fillWith(init.headers.get(), exceptionState);
107 } else if (!init.headersDictionary.isUndefinedOrNull()) { 107 } else if (!init.headersDictionary.isUndefinedOrNull()) {
108 r->headers()->fillWith(init.headersDictionary, exceptionState); 108 r->headers()->fillWith(init.headersDictionary, exceptionState);
109 } else { 109 } else {
110 ASSERT(headers); 110 ASSERT(headers);
111 r->headers()->fillWith(headers.get(), exceptionState); 111 r->headers()->fillWith(headers, exceptionState);
112 } 112 }
113 if (exceptionState.hadException()) 113 if (exceptionState.hadException())
114 return nullptr; 114 return 0;
115 // FIXME: Support body. 115 // FIXME: Support body.
116 // "20. Return |r|." 116 // "20. Return |r|."
117 return r.release(); 117 return r;
118 } 118 }
119 119
120 120
121 } // namespace 121 } // namespace
122 122
123 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Request); 123 Request* Request::create(ExecutionContext* context, const String& input, Excepti onState& exceptionState)
124
125 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const String& input, ExceptionState& exceptionState)
126 { 124 {
127 return create(context, input, Dictionary(), exceptionState); 125 return create(context, input, Dictionary(), exceptionState);
128 } 126 }
129 127
130 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const String& input, const Dictionary& init, ExceptionState& exceptionState) 128 Request* Request::create(ExecutionContext* context, const String& input, const D ictionary& init, ExceptionState& exceptionState)
131 { 129 {
132 // "1. Let |request| be |input|'s associated request, if |input| is a 130 // "1. Let |request| be |input|'s associated request, if |input| is a
133 // Request object, and a new request otherwise." 131 // Request object, and a new request otherwise."
134 RefPtrWillBeRawPtr<FetchRequestData> request(FetchRequestData::create(contex t)); 132 FetchRequestData* request(FetchRequestData::create(context));
135 // "2. Set |request| to a restricted copy of itself." 133 // "2. Set |request| to a restricted copy of itself."
136 request = request->createRestrictedCopy(context, SecurityOrigin::create(cont ext->url())); 134 request = request->createRestrictedCopy(context, SecurityOrigin::create(cont ext->url()));
137 // "5. If |input| is a string, run these substeps:" 135 // "5. If |input| is a string, run these substeps:"
138 // "1. Let |parsedURL| be the result of parsing |input| with entry settings 136 // "1. Let |parsedURL| be the result of parsing |input| with entry settings
139 // object's API base URL." 137 // object's API base URL."
140 KURL parsedURL = context->completeURL(input); 138 KURL parsedURL = context->completeURL(input);
141 // "2. If |parsedURL| is failure, throw a TypeError." 139 // "2. If |parsedURL| is failure, throw a TypeError."
142 if (!parsedURL.isValid()) { 140 if (!parsedURL.isValid()) {
143 exceptionState.throwTypeError("Invalid URL"); 141 exceptionState.throwTypeError("Invalid URL");
144 return nullptr; 142 return 0;
145 } 143 }
146 // "3. Set |request|'s url to |parsedURL|." 144 // "3. Set |request|'s url to |parsedURL|."
147 request->setURL(parsedURL); 145 request->setURL(parsedURL);
148 // "4. Set |fallbackMode| to CORS." 146 // "4. Set |fallbackMode| to CORS."
149 // "5. Set |fallbackCredentials| to omit." 147 // "5. Set |fallbackCredentials| to omit."
150 return createRequestWithRequestData(request.release(), RequestInit(init), Fe tchRequestData::CORSMode, FetchRequestData::OmitCredentials, exceptionState); 148 return createRequestWithRequestData(request, RequestInit(init), FetchRequest Data::CORSMode, FetchRequestData::OmitCredentials, exceptionState);
151 } 149 }
152 150
153 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque st* input, ExceptionState& exceptionState) 151 Request* Request::create(ExecutionContext* context, Request* input, ExceptionSta te& exceptionState)
154 { 152 {
155 return create(context, input, Dictionary(), exceptionState); 153 return create(context, input, Dictionary(), exceptionState);
156 } 154 }
157 155
158 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque st* input, const Dictionary& init, ExceptionState& exceptionState) 156 Request* Request::create(ExecutionContext* context, Request* input, const Dictio nary& init, ExceptionState& exceptionState)
159 { 157 {
160 // "1. Let |request| be |input|'s associated request, if |input| is a 158 // "1. Let |request| be |input|'s associated request, if |input| is a
161 // Request object, and a new request otherwise." 159 // Request object, and a new request otherwise."
162 // "2. Set |request| to a restricted copy of itself." 160 // "2. Set |request| to a restricted copy of itself."
163 RefPtrWillBeRawPtr<FetchRequestData> request(input->request()->createRestric tedCopy(context, SecurityOrigin::create(context->url()))); 161 FetchRequestData* request(input->request()->createRestrictedCopy(context, Se curityOrigin::create(context->url())));
164 // "3. Let |fallbackMode| be null." 162 // "3. Let |fallbackMode| be null."
165 // "4. Let |fallbackCredentials| be null." 163 // "4. Let |fallbackCredentials| be null."
166 // Instead of using null as a special fallback value, just pass the current 164 // Instead of using null as a special fallback value, just pass the current
167 // mode and credentials; it has the same effect. 165 // mode and credentials; it has the same effect.
168 const FetchRequestData::Mode currentMode = request->mode(); 166 const FetchRequestData::Mode currentMode = request->mode();
169 const FetchRequestData::Credentials currentCredentials = request->credential s(); 167 const FetchRequestData::Credentials currentCredentials = request->credential s();
170 return createRequestWithRequestData(request.release(), RequestInit(init), cu rrentMode, currentCredentials, exceptionState); 168 return createRequestWithRequestData(request, RequestInit(init), currentMode, currentCredentials, exceptionState);
171 } 169 }
172 170
173 PassRefPtrWillBeRawPtr<Request> Request::create(PassRefPtrWillBeRawPtr<FetchRequ estData> request) 171 Request* Request::create(FetchRequestData* request)
174 { 172 {
175 return adoptRefWillBeNoop(new Request(request)); 173 return new Request(request);
176 } 174 }
177 175
178 Request::Request(PassRefPtrWillBeRawPtr<FetchRequestData> request) 176 Request::Request(FetchRequestData* request)
179 : m_request(request) 177 : m_request(request)
180 , m_headers(Headers::create(m_request->headerList())) 178 , m_headers(Headers::create(m_request->headerList()))
181 { 179 {
182 m_headers->setGuard(Headers::RequestGuard); 180 m_headers->setGuard(Headers::RequestGuard);
183 ScriptWrappable::init(this); 181 ScriptWrappable::init(this);
184 } 182 }
185 183
186 PassRefPtrWillBeRawPtr<Request> Request::create(const WebServiceWorkerRequest& w ebRequest) 184 Request* Request::create(const WebServiceWorkerRequest& webRequest)
187 { 185 {
188 return adoptRefWillBeNoop(new Request(webRequest)); 186 return new Request(webRequest);
189 } 187 }
190 188
191 Request::Request(const WebServiceWorkerRequest& webRequest) 189 Request::Request(const WebServiceWorkerRequest& webRequest)
192 : m_request(FetchRequestData::create(webRequest)) 190 : m_request(FetchRequestData::create(webRequest))
193 , m_headers(Headers::create(m_request->headerList())) 191 , m_headers(Headers::create(m_request->headerList()))
194 { 192 {
195 m_headers->setGuard(Headers::RequestGuard); 193 m_headers->setGuard(Headers::RequestGuard);
196 ScriptWrappable::init(this); 194 ScriptWrappable::init(this);
197 } 195 }
198 196
199 String Request::method() const 197 String Request::method() const
200 { 198 {
201 // "The method attribute's getter must return request's method." 199 // "The method attribute's getter must return request's method."
202 return m_request->method(); 200 return m_request->method();
203 } 201 }
204 202
205 String Request::url() const 203 String Request::url() const
206 { 204 {
207 // The url attribute's getter must return request's url, serialized with the exclude fragment flag set. 205 // The url attribute's getter must return request's url, serialized with the exclude fragment flag set.
208 if (!m_request->url().hasFragmentIdentifier()) 206 if (!m_request->url().hasFragmentIdentifier())
209 return m_request->url(); 207 return m_request->url();
210 KURL url(m_request->url()); 208 KURL url(m_request->url());
211 url.removeFragmentIdentifier(); 209 url.removeFragmentIdentifier();
212 return url; 210 return url;
213 } 211 }
214 212
215 PassRefPtrWillBeRawPtr<FetchBodyStream> Request::body(ExecutionContext* context) 213 FetchBodyStream* Request::body(ExecutionContext* context)
216 { 214 {
217 if (!m_request->blobDataHandle()) 215 if (!m_request->blobDataHandle())
218 return nullptr; 216 return 0;
219 if (!m_fetchBodyStream) 217 if (!m_fetchBodyStream)
220 m_fetchBodyStream = FetchBodyStream::create(context, m_request->blobData Handle()); 218 m_fetchBodyStream = FetchBodyStream::create(context, m_request->blobData Handle());
221 return m_fetchBodyStream; 219 return m_fetchBodyStream;
222 } 220 }
223 221
224 222
225 String Request::referrer() const 223 String Request::referrer() const
226 { 224 {
227 // "The referrer attribute's getter must return the empty string if 225 // "The referrer attribute's getter must return the empty string if
228 // request's referrer is none, and request's referrer, serialized, 226 // request's referrer is none, and request's referrer, serialized,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 263 }
266 264
267 void Request::trace(Visitor* visitor) 265 void Request::trace(Visitor* visitor)
268 { 266 {
269 visitor->trace(m_request); 267 visitor->trace(m_request);
270 visitor->trace(m_headers); 268 visitor->trace(m_headers);
271 visitor->trace(m_fetchBodyStream); 269 visitor->trace(m_fetchBodyStream);
272 } 270 }
273 271
274 } // namespace blink 272 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698