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

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

Issue 1060033002: Implement Request.context for Fetch API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « Source/modules/fetch/Request.h ('k') | Source/modules/fetch/Request.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "modules/fetch/Request.h" 6 #include "modules/fetch/Request.h"
7 7
8 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/ExecutionContext.h" 10 #include "core/dom/ExecutionContext.h"
(...skipping 16 matching lines...) Expand all
27 request->setURL(original->url()); 27 request->setURL(original->url());
28 request->setMethod(original->method()); 28 request->setMethod(original->method());
29 request->setHeaderList(original->headerList()->clone()); 29 request->setHeaderList(original->headerList()->clone());
30 request->setUnsafeRequestFlag(true); 30 request->setUnsafeRequestFlag(true);
31 request->setBlobDataHandle(original->blobDataHandle()); 31 request->setBlobDataHandle(original->blobDataHandle());
32 // FIXME: Set client. 32 // FIXME: Set client.
33 request->setOrigin(SecurityOrigin::create(context->url())); 33 request->setOrigin(SecurityOrigin::create(context->url()));
34 // FIXME: Set ForceOriginHeaderFlag. 34 // FIXME: Set ForceOriginHeaderFlag.
35 request->setSameOriginDataURLFlag(true); 35 request->setSameOriginDataURLFlag(true);
36 request->mutableReferrer()->setClient(); 36 request->mutableReferrer()->setClient();
37 request->setContext(WebURLRequest::RequestContextFetch);
38 request->setMode(original->mode()); 37 request->setMode(original->mode());
39 request->setCredentials(original->credentials()); 38 request->setCredentials(original->credentials());
40 // FIXME: Set cache mode. 39 // FIXME: Set cache mode.
41 return request; 40 return request;
42 } 41 }
43 42
44 Request* Request::createRequestWithRequestOrString(ExecutionContext* context, Re quest* inputRequest, const String& inputString, const RequestInit& init, Excepti onState& exceptionState) 43 Request* Request::createRequestWithRequestOrString(ExecutionContext* context, Re quest* inputRequest, const String& inputString, const RequestInit& init, Excepti onState& exceptionState)
45 { 44 {
46 // "1. If input is a Request object, run these substeps:" 45 // "1. If input is a Request object, run these substeps:"
47 if (inputRequest) { 46 if (inputRequest) {
48 // "1. If input's used flag is set, throw a TypeError." 47 // "1. If input's used flag is set, throw a TypeError."
49 if (inputRequest->bodyUsed()) { 48 if (inputRequest->bodyUsed()) {
50 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used."); 49 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used.");
51 return 0; 50 return 0;
52 } 51 }
53 // "2. Set input's used flag." 52 // "2. Set input's used flag."
54 inputRequest->lockBody(PassBody); 53 inputRequest->lockBody(PassBody);
55 } 54 }
56 55
57 // "2. Let |request| be |input|'s associated request, if |input| is a 56 // "2. Let |request| be |input|'s associated request, if |input| is a
58 // Request object, and a new request otherwise." 57 // Request object, and a new request otherwise."
59 // "3. Set |request| to a new request whose url is |request|'s url, method 58 // "3. Set |request| to a new request whose url is |request|'s url, method
yhirano 2015/04/14 07:07:11 (Mainly for module/fetch reviewers) As the spec ch
60 // is |request|'s method, header list is a copy of |request|'s header list, 59 // is |request|'s method, header list is a copy of |request|'s header list,
61 // unsafe request flag is set, body is |request|'s body, client is entry 60 // unsafe request flag is set, body is |request|'s body, client is entry
62 // settings object, origin is entry settings object's origin, force Origin 61 // settings object, origin is entry settings object's origin, force Origin
63 // header flag is set, same-origin data URL flag is set, referrer is client, 62 // header flag is set, same-origin data URL flag is set, referrer is client,
64 // context is fetch, mode is |request|'s mode, credentials mode is 63 // context is fetch, mode is |request|'s mode, credentials mode is
65 // |request|'s credentials mode, and cache mode is |request|'s cache mode." 64 // |request|'s credentials mode, and cache mode is |request|'s cache mode."
66 FetchRequestData* request = createCopyOfFetchRequestDataForFetch(context, in putRequest ? inputRequest->request() : FetchRequestData::create()); 65 FetchRequestData* request = createCopyOfFetchRequestDataForFetch(context, in putRequest ? inputRequest->request() : FetchRequestData::create());
67 66
68 if (inputRequest && inputRequest->blobDataHandle() && inputRequest->isBodyCo nsumed()) { 67 if (inputRequest && inputRequest->blobDataHandle() && inputRequest->isBodyCo nsumed()) {
69 // Currently the only methods that can consume body data without 68 // Currently the only methods that can consume body data without
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 KURL Request::url() const 286 KURL Request::url() const
288 { 287 {
289 // The url attribute's getter must return request's url, serialized with the exclude fragment flag set. 288 // The url attribute's getter must return request's url, serialized with the exclude fragment flag set.
290 if (!m_request->url().hasFragmentIdentifier()) 289 if (!m_request->url().hasFragmentIdentifier())
291 return m_request->url(); 290 return m_request->url();
292 KURL url(m_request->url()); 291 KURL url(m_request->url());
293 url.removeFragmentIdentifier(); 292 url.removeFragmentIdentifier();
294 return url; 293 return url;
295 } 294 }
296 295
296 String Request::context() const
297 {
298 // "The context attribute's getter must return request's context"
299 switch (m_request->context()) {
300 case WebURLRequest::RequestContextUnspecified:
301 return "";
302 case WebURLRequest::RequestContextAudio:
303 return "audio";
304 case WebURLRequest::RequestContextBeacon:
305 return "beacon";
306 case WebURLRequest::RequestContextCSPReport:
307 return "cspreport";
308 case WebURLRequest::RequestContextDownload:
309 return "download";
310 case WebURLRequest::RequestContextEmbed:
311 return "embed";
312 case WebURLRequest::RequestContextEventSource:
313 return "eventsource";
314 case WebURLRequest::RequestContextFavicon:
315 return "favicon";
316 case WebURLRequest::RequestContextFetch:
317 return "fetch";
318 case WebURLRequest::RequestContextFont:
319 return "font";
320 case WebURLRequest::RequestContextForm:
321 return "form";
322 case WebURLRequest::RequestContextFrame:
323 return "frame";
324 case WebURLRequest::RequestContextHyperlink:
325 return "hyperlink";
326 case WebURLRequest::RequestContextIframe:
327 return "iframe";
328 case WebURLRequest::RequestContextImage:
329 return "image";
330 case WebURLRequest::RequestContextImageSet:
331 return "imageset";
332 case WebURLRequest::RequestContextImport:
333 return "import";
334 case WebURLRequest::RequestContextInternal:
335 return "internal";
336 case WebURLRequest::RequestContextLocation:
337 return "location";
338 case WebURLRequest::RequestContextManifest:
339 return "manifest";
340 case WebURLRequest::RequestContextObject:
341 return "object";
342 case WebURLRequest::RequestContextPing:
343 return "ping";
344 case WebURLRequest::RequestContextPlugin:
345 return "plugin";
346 case WebURLRequest::RequestContextPrefetch:
347 return "prefetch";
348 case WebURLRequest::RequestContextScript:
349 return "script";
350 case WebURLRequest::RequestContextServiceWorker:
351 return "serviceworker";
352 case WebURLRequest::RequestContextSharedWorker:
353 return "sharedworker";
354 case WebURLRequest::RequestContextSubresource:
355 return "subresource";
356 case WebURLRequest::RequestContextStyle:
357 return "style";
358 case WebURLRequest::RequestContextTrack:
359 return "track";
360 case WebURLRequest::RequestContextVideo:
361 return "video";
362 case WebURLRequest::RequestContextWorker:
363 return "worker";
364 case WebURLRequest::RequestContextXMLHttpRequest:
365 return "xmlhttprequest";
366 case WebURLRequest::RequestContextXSLT:
367 return "xslt";
368 }
369 ASSERT_NOT_REACHED();
370 return "";
371 }
372
297 String Request::referrer() const 373 String Request::referrer() const
298 { 374 {
299 // "The referrer attribute's getter must return the empty string if 375 // "The referrer attribute's getter must return the empty string if
300 // request's referrer is no referrer, "about:client" if request's referrer 376 // request's referrer is no referrer, "about:client" if request's referrer
301 // is client and request's referrer, serialized, otherwise." 377 // is client and request's referrer, serialized, otherwise."
302 if (m_request->referrer().isNoReferrer()) 378 if (m_request->referrer().isNoReferrer())
303 return String(); 379 return String();
304 if (m_request->referrer().isClient()) 380 if (m_request->referrer().isClient())
305 return String("about:client"); 381 return String("about:client");
306 return m_request->referrer().referrer().referrer; 382 return m_request->referrer().referrer().referrer;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 FetchRequestData* Request::passRequestData() 445 FetchRequestData* Request::passRequestData()
370 { 446 {
371 ASSERT(!bodyUsed()); 447 ASSERT(!bodyUsed());
372 lockBody(PassBody); 448 lockBody(PassBody);
373 return m_request->pass(); 449 return m_request->pass();
374 } 450 }
375 451
376 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const 452 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques t) const
377 { 453 {
378 webRequest.setMethod(method()); 454 webRequest.setMethod(method());
455 webRequest.setRequestContext(m_request->context());
379 // This strips off the fragment part. 456 // This strips off the fragment part.
380 webRequest.setURL(url()); 457 webRequest.setURL(url());
381 458
382 const FetchHeaderList* headerList = m_headers->headerList(); 459 const FetchHeaderList* headerList = m_headers->headerList();
383 for (size_t i = 0, size = headerList->size(); i < size; ++i) { 460 for (size_t i = 0, size = headerList->size(); i < size; ++i) {
384 const FetchHeaderList::Header& header = headerList->entry(i); 461 const FetchHeaderList::Header& header = headerList->entry(i);
385 webRequest.appendHeader(header.first, header.second); 462 webRequest.appendHeader(header.first, header.second);
386 } 463 }
387 464
388 webRequest.setReferrer(m_request->referrer().referrer().referrer, static_cas t<WebReferrerPolicy>(m_request->referrer().referrer().referrerPolicy)); 465 webRequest.setReferrer(m_request->referrer().referrer().referrer, static_cas t<WebReferrerPolicy>(m_request->referrer().referrer().referrerPolicy));
(...skipping 28 matching lines...) Expand all
417 } 494 }
418 495
419 DEFINE_TRACE(Request) 496 DEFINE_TRACE(Request)
420 { 497 {
421 Body::trace(visitor); 498 Body::trace(visitor);
422 visitor->trace(m_request); 499 visitor->trace(m_request);
423 visitor->trace(m_headers); 500 visitor->trace(m_headers);
424 } 501 }
425 502
426 } // namespace blink 503 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/fetch/Request.h ('k') | Source/modules/fetch/Request.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698