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

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

Issue 1844053003: CREDENTIAL: Rework the integration with Fetch (1/2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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 "modules/fetch/Request.h" 5 #include "modules/fetch/Request.h"
6 6
7 #include "bindings/core/v8/Dictionary.h" 7 #include "bindings/core/v8/Dictionary.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.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"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // "Let |credentials| be |init|'s credentials member if it is present, and 209 // "Let |credentials| be |init|'s credentials member if it is present, and
210 // |fallbackCredentials| otherwise." 210 // |fallbackCredentials| otherwise."
211 // "If |credentials| is non-null, set |request|'s credentials mode to 211 // "If |credentials| is non-null, set |request|'s credentials mode to
212 // |credentials|." 212 // |credentials|."
213 if (init.credentials == "omit") { 213 if (init.credentials == "omit") {
214 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); 214 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit);
215 } else if (init.credentials == "same-origin") { 215 } else if (init.credentials == "same-origin") {
216 request->setCredentials(WebURLRequest::FetchCredentialsModeSameOrigin); 216 request->setCredentials(WebURLRequest::FetchCredentialsModeSameOrigin);
217 } else if (init.credentials == "include") { 217 } else if (init.credentials == "include") {
218 request->setCredentials(WebURLRequest::FetchCredentialsModeInclude); 218 request->setCredentials(WebURLRequest::FetchCredentialsModeInclude);
219 } else if (init.credentials == "password") {
220 if (!init.attachedCredential.get()) {
221 exceptionState.throwTypeError("Cannot construct a Request with a cre dential mode of 'password' without a PasswordCredential.");
222 return nullptr;
223 }
224 request->setCredentials(WebURLRequest::FetchCredentialsModePassword);
225 request->setAttachedCredentialBuffer(new BodyStreamBuffer(init.attachedC redential.release()));
226 request->setRedirect(WebURLRequest::FetchRedirectModeManual);
horo 2016/04/04 05:26:00 Please add layout tests to check the manual redire
Mike West 2016/04/04 08:04:20 Done. I also drove-by a small fix to set the opaqu
219 } else { 227 } else {
220 if (!inputRequest) 228 if (!inputRequest)
221 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); 229 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit);
222 } 230 }
223 231
224 // TODO(yhirano): Implement the following step: 232 // TODO(yhirano): Implement the following step:
225 // "If |init|'s cache member is present, set |request|'s cache mode to 233 // "If |init|'s cache member is present, set |request|'s cache mode to
226 // it." 234 // it."
227 235
228 // "If |init|'s redirect member is present, set |request|'s redirect mode 236 // "If |init|'s redirect member is present, set |request|'s redirect mode
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 r->getHeaders()->fillWith(init.headersDictionary, exceptionState); 306 r->getHeaders()->fillWith(init.headersDictionary, exceptionState);
299 } else { 307 } else {
300 ASSERT(headers); 308 ASSERT(headers);
301 r->getHeaders()->fillWith(headers, exceptionState); 309 r->getHeaders()->fillWith(headers, exceptionState);
302 } 310 }
303 if (exceptionState.hadException()) 311 if (exceptionState.hadException())
304 return nullptr; 312 return nullptr;
305 313
306 // "If either |init|'s body member is present or |temporaryBody| is 314 // "If either |init|'s body member is present or |temporaryBody| is
307 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. 315 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError.
308 if (init.body || temporaryBody) { 316 if (init.body || temporaryBody || request->credentials() == WebURLRequest::F etchCredentialsModePassword) {
309 if (request->method() == HTTPNames::GET || request->method() == HTTPName s::HEAD) { 317 if (request->method() == HTTPNames::GET || request->method() == HTTPName s::HEAD) {
310 exceptionState.throwTypeError("Request with GET/HEAD method cannot h ave body."); 318 exceptionState.throwTypeError("Request with GET/HEAD method cannot h ave body.");
311 return nullptr; 319 return nullptr;
312 } 320 }
313 } 321 }
314 322
323 // TODO(mkwst): See the comment in RequestInit about serializing the attache d credential
324 // prior to hitting the Service Worker machinery.
325 if (request->credentials() == WebURLRequest::FetchCredentialsModePassword) {
326 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, excep tionState);
327
328 // TODO(mkwst): This should be a registrable-domain match.
329 if (!origin->canRequest(r->url())) {
330 exceptionState.throwTypeError("Credentials may only be submitted to same-origin endpoints.");
331 return nullptr;
332 }
333 }
334
315 // "If |init|'s body member is present, run these substeps:" 335 // "If |init|'s body member is present, run these substeps:"
316 if (init.body) { 336 if (init.body) {
317 // Perform the following steps: 337 // Perform the following steps:
318 // - "Let |stream| and |Content-Type| be the result of extracting 338 // - "Let |stream| and |Content-Type| be the result of extracting
319 // |init|'s body member." 339 // |init|'s body member."
320 // - "Set |temporaryBody| to |stream|. 340 // - "Set |temporaryBody| to |stream|.
321 // - "If |Content-Type| is non-null and |r|'s request's header list 341 // - "If |Content-Type| is non-null and |r|'s request's header list
322 // contains no header named `Content-Type`, append 342 // contains no header named `Content-Type`, append
323 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any 343 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any
324 // exception." 344 // exception."
325 temporaryBody = new BodyStreamBuffer(init.body.release()); 345 temporaryBody = new BodyStreamBuffer(init.body.release());
326 if (!init.contentType.isEmpty() && !r->getHeaders()->has(HTTPNames::Cont ent_Type, exceptionState)) { 346 if (!init.contentType.isEmpty() && !r->getHeaders()->has(HTTPNames::Cont ent_Type, exceptionState)) {
327 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, e xceptionState); 347 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, e xceptionState);
328 } 348 }
329 if (exceptionState.hadException()) 349 if (exceptionState.hadException())
330 return nullptr; 350 return nullptr;
331 } 351 }
332 352
333 // "Set |r|'s request's body to |temporaryBody|. 353 // "Set |r|'s request's body to |temporaryBody|.
334 if (temporaryBody) 354 if (temporaryBody)
335 r->m_request->setBuffer(temporaryBody); 355 r->m_request->setBuffer(temporaryBody);
336 356
337 // https://w3c.github.io/webappsec-credential-management/#monkey-patching-fe tch-3
338 // "If |init|'s body member is a 'Credential' object:"
339 if (init.isCredentialRequest) {
340 // "1. If |r|'s url is not the same as |r|'s client’s origin, throw a Ty peError."
341 if (!origin->canRequest(r->url())) {
342 exceptionState.throwTypeError("Credentials may only be submitted to same-origin endpoints.");
343 return nullptr;
344 }
345 // "2. Set |r|'s redirect mode to "error"."
346 r->m_request->setRedirect(WebURLRequest::FetchRedirectModeError);
347 // "3. Set |r|'s skip-service-worker flag."
348 // TODO(mkwst): Set this flag.
349 // "4. Set |r|'s opaque flag."
350 r->setOpaque();
351 }
352
353 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s 357 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s
354 // request's header list." 358 // request's header list."
355 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); 359 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType());
356 360
357 // "If |input| is a Request object and |input|'s request's body is 361 // "If |input| is a Request object and |input|'s request's body is
358 // non-null, run these substeps:" 362 // non-null, run these substeps:"
359 if (inputRequest && inputRequest->bodyBuffer()) { 363 if (inputRequest && inputRequest->bodyBuffer()) {
360 // "Set |input|'s body to an empty byte stream." 364 // "Set |input|'s body to an empty byte stream."
361 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC onsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); 365 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC onsumerHandleFromWebHandle(createDoneDataConsumerHandle())));
362 // "Set |input|'s disturbed flag." 366 // "Set |input|'s disturbed flag."
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 // "The credentials attribute's getter must return the value corresponding 557 // "The credentials attribute's getter must return the value corresponding
554 // to the first matching statement, switching on request's credentials 558 // to the first matching statement, switching on request's credentials
555 // mode:" 559 // mode:"
556 switch (m_request->credentials()) { 560 switch (m_request->credentials()) {
557 case WebURLRequest::FetchCredentialsModeOmit: 561 case WebURLRequest::FetchCredentialsModeOmit:
558 return "omit"; 562 return "omit";
559 case WebURLRequest::FetchCredentialsModeSameOrigin: 563 case WebURLRequest::FetchCredentialsModeSameOrigin:
560 return "same-origin"; 564 return "same-origin";
561 case WebURLRequest::FetchCredentialsModeInclude: 565 case WebURLRequest::FetchCredentialsModeInclude:
562 return "include"; 566 return "include";
567 case WebURLRequest::FetchCredentialsModePassword:
568 return "password";
563 } 569 }
564 ASSERT_NOT_REACHED(); 570 ASSERT_NOT_REACHED();
565 return ""; 571 return "";
566 } 572 }
567 573
568 String Request::redirect() const 574 String Request::redirect() const
569 { 575 {
570 // "The redirect attribute's getter must return request's redirect mode." 576 // "The redirect attribute's getter must return request's redirect mode."
571 switch (m_request->redirect()) { 577 switch (m_request->redirect()) {
572 case WebURLRequest::FetchRedirectModeFollow: 578 case WebURLRequest::FetchRedirectModeFollow:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 } 645 }
640 646
641 DEFINE_TRACE(Request) 647 DEFINE_TRACE(Request)
642 { 648 {
643 Body::trace(visitor); 649 Body::trace(visitor);
644 visitor->trace(m_request); 650 visitor->trace(m_request);
645 visitor->trace(m_headers); 651 visitor->trace(m_headers);
646 } 652 }
647 653
648 } // namespace blink 654 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698