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

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

Issue 2691513002: Fetch: Make Headers' constructor match the current spec IDL. (Closed)
Patch Set: Patch v2 Created 3 years, 10 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/loader/ThreadableLoader.h" 10 #include "core/loader/ThreadableLoader.h"
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // Headers object whose guard is "request"." 298 // Headers object whose guard is "request"."
299 Request* r = Request::create(scriptState, request); 299 Request* r = Request::create(scriptState, request);
300 // Perform the following steps: 300 // Perform the following steps:
301 // - "Let |headers| be a copy of |r|'s Headers object." 301 // - "Let |headers| be a copy of |r|'s Headers object."
302 // - "If |init|'s headers member is present, set |headers| to |init|'s 302 // - "If |init|'s headers member is present, set |headers| to |init|'s
303 // headers member." 303 // headers member."
304 // 304 //
305 // We don't create a copy of r's Headers object when init's headers member 305 // We don't create a copy of r's Headers object when init's headers member
306 // is present. 306 // is present.
307 Headers* headers = nullptr; 307 Headers* headers = nullptr;
308 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { 308 if (!init.headers) {
309 headers = r->getHeaders()->clone(); 309 headers = r->getHeaders()->clone();
310 } 310 }
311 // "Empty |r|'s request's header list." 311 // "Empty |r|'s request's header list."
312 r->m_request->headerList()->clearList(); 312 r->m_request->headerList()->clearList();
313 // "If |r|'s request's mode is "no-cors", run these substeps: 313 // "If |r|'s request's mode is "no-cors", run these substeps:
314 if (r->getRequest()->mode() == WebURLRequest::FetchRequestModeNoCORS) { 314 if (r->getRequest()->mode() == WebURLRequest::FetchRequestModeNoCORS) {
315 // "If |r|'s request's method is not a simple method, throw a 315 // "If |r|'s request's method is not a simple method, throw a
316 // TypeError." 316 // TypeError."
317 if (!FetchUtils::isSimpleMethod(r->getRequest()->method())) { 317 if (!FetchUtils::isSimpleMethod(r->getRequest()->method())) {
318 exceptionState.throwTypeError("'" + r->getRequest()->method() + 318 exceptionState.throwTypeError("'" + r->getRequest()->method() +
319 "' is unsupported in no-cors mode."); 319 "' is unsupported in no-cors mode.");
320 return nullptr; 320 return nullptr;
321 } 321 }
322 // "If |request|'s integrity metadata is not the empty string, throw a 322 // "If |request|'s integrity metadata is not the empty string, throw a
323 // TypeError." 323 // TypeError."
324 if (!request->integrity().isEmpty()) { 324 if (!request->integrity().isEmpty()) {
325 exceptionState.throwTypeError( 325 exceptionState.throwTypeError(
326 "The integrity attribute is unsupported in no-cors mode."); 326 "The integrity attribute is unsupported in no-cors mode.");
327 return nullptr; 327 return nullptr;
328 } 328 }
329 // "Set |r|'s Headers object's guard to "request-no-cors"." 329 // "Set |r|'s Headers object's guard to "request-no-cors"."
330 r->getHeaders()->setGuard(Headers::RequestNoCORSGuard); 330 r->getHeaders()->setGuard(Headers::RequestNoCORSGuard);
331 } 331 }
332 // "Fill |r|'s Headers object with |headers|. Rethrow any exceptions." 332 // "Fill |r|'s Headers object with |headers|. Rethrow any exceptions."
333 if (init.headers) { 333 if (init.headers) {
334 ASSERT(init.headersDictionary.isUndefinedOrNull());
335 r->getHeaders()->fillWith(init.headers.get(), exceptionState); 334 r->getHeaders()->fillWith(init.headers.get(), exceptionState);
336 } else if (!init.headersDictionary.isUndefinedOrNull()) {
337 r->getHeaders()->fillWith(init.headersDictionary, exceptionState);
338 } else { 335 } else {
339 ASSERT(headers); 336 ASSERT(headers);
340 r->getHeaders()->fillWith(headers, exceptionState); 337 r->getHeaders()->fillWith(headers, exceptionState);
341 } 338 }
342 if (exceptionState.hadException()) 339 if (exceptionState.hadException())
343 return nullptr; 340 return nullptr;
344 341
345 // "If either |init|'s body member is present or |temporaryBody| is 342 // "If either |init|'s body member is present or |temporaryBody| is
346 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. 343 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError.
347 if (init.body || temporaryBody || 344 if (init.body || temporaryBody ||
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 V8HiddenValue::internalBodyBuffer(scriptState->isolate()), bodyBuffer); 730 V8HiddenValue::internalBodyBuffer(scriptState->isolate()), bodyBuffer);
734 } 731 }
735 732
736 DEFINE_TRACE(Request) { 733 DEFINE_TRACE(Request) {
737 Body::trace(visitor); 734 Body::trace(visitor);
738 visitor->trace(m_request); 735 visitor->trace(m_request);
739 visitor->trace(m_headers); 736 visitor->trace(m_headers);
740 } 737 }
741 738
742 } // namespace blink 739 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698