OLD | NEW |
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 "bindings/core/v8/V8PrivateProperty.h" | 8 #include "bindings/core/v8/V8PrivateProperty.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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 // Headers object whose guard is "request"." | 302 // Headers object whose guard is "request"." |
303 Request* r = Request::Create(script_state, request); | 303 Request* r = Request::Create(script_state, request); |
304 // Perform the following steps: | 304 // Perform the following steps: |
305 // - "Let |headers| be a copy of |r|'s Headers object." | 305 // - "Let |headers| be a copy of |r|'s Headers object." |
306 // - "If |init|'s headers member is present, set |headers| to |init|'s | 306 // - "If |init|'s headers member is present, set |headers| to |init|'s |
307 // headers member." | 307 // headers member." |
308 // | 308 // |
309 // We don't create a copy of r's Headers object when init's headers member | 309 // We don't create a copy of r's Headers object when init's headers member |
310 // is present. | 310 // is present. |
311 Headers* headers = nullptr; | 311 Headers* headers = nullptr; |
312 if (!init.headers && init.headers_dictionary.IsUndefinedOrNull()) { | 312 if (!init.headers) { |
313 headers = r->getHeaders()->Clone(); | 313 headers = r->getHeaders()->Clone(); |
314 } | 314 } |
315 // "Empty |r|'s request's header list." | 315 // "Empty |r|'s request's header list." |
316 r->request_->HeaderList()->ClearList(); | 316 r->request_->HeaderList()->ClearList(); |
317 // "If |r|'s request's mode is "no-cors", run these substeps: | 317 // "If |r|'s request's mode is "no-cors", run these substeps: |
318 if (r->GetRequest()->Mode() == WebURLRequest::kFetchRequestModeNoCORS) { | 318 if (r->GetRequest()->Mode() == WebURLRequest::kFetchRequestModeNoCORS) { |
319 // "If |r|'s request's method is not a simple method, throw a | 319 // "If |r|'s request's method is not a simple method, throw a |
320 // TypeError." | 320 // TypeError." |
321 if (!FetchUtils::IsSimpleMethod(r->GetRequest()->Method())) { | 321 if (!FetchUtils::IsSimpleMethod(r->GetRequest()->Method())) { |
322 exception_state.ThrowTypeError("'" + r->GetRequest()->Method() + | 322 exception_state.ThrowTypeError("'" + r->GetRequest()->Method() + |
323 "' is unsupported in no-cors mode."); | 323 "' is unsupported in no-cors mode."); |
324 return nullptr; | 324 return nullptr; |
325 } | 325 } |
326 // "If |request|'s integrity metadata is not the empty string, throw a | 326 // "If |request|'s integrity metadata is not the empty string, throw a |
327 // TypeError." | 327 // TypeError." |
328 if (!request->Integrity().IsEmpty()) { | 328 if (!request->Integrity().IsEmpty()) { |
329 exception_state.ThrowTypeError( | 329 exception_state.ThrowTypeError( |
330 "The integrity attribute is unsupported in no-cors mode."); | 330 "The integrity attribute is unsupported in no-cors mode."); |
331 return nullptr; | 331 return nullptr; |
332 } | 332 } |
333 // "Set |r|'s Headers object's guard to "request-no-cors"." | 333 // "Set |r|'s Headers object's guard to "request-no-cors"." |
334 r->getHeaders()->SetGuard(Headers::kRequestNoCORSGuard); | 334 r->getHeaders()->SetGuard(Headers::kRequestNoCORSGuard); |
335 } | 335 } |
336 // "Fill |r|'s Headers object with |headers|. Rethrow any exceptions." | 336 // "Fill |r|'s Headers object with |headers|. Rethrow any exceptions." |
337 if (init.headers) { | 337 if (init.headers) { |
338 ASSERT(init.headers_dictionary.IsUndefinedOrNull()); | |
339 r->getHeaders()->FillWith(init.headers.Get(), exception_state); | 338 r->getHeaders()->FillWith(init.headers.Get(), exception_state); |
340 } else if (!init.headers_dictionary.IsUndefinedOrNull()) { | |
341 r->getHeaders()->FillWith(init.headers_dictionary, exception_state); | |
342 } else { | 339 } else { |
343 ASSERT(headers); | 340 ASSERT(headers); |
344 r->getHeaders()->FillWith(headers, exception_state); | 341 r->getHeaders()->FillWith(headers, exception_state); |
345 } | 342 } |
346 if (exception_state.HadException()) | 343 if (exception_state.HadException()) |
347 return nullptr; | 344 return nullptr; |
348 | 345 |
349 // "If either |init|'s body member is present or |temporaryBody| is | 346 // "If either |init|'s body member is present or |temporaryBody| is |
350 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. | 347 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. |
351 if (init.body || temporary_body || | 348 if (init.body || temporary_body || |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 .Set(request.As<v8::Object>(), body_buffer); | 733 .Set(request.As<v8::Object>(), body_buffer); |
737 } | 734 } |
738 | 735 |
739 DEFINE_TRACE(Request) { | 736 DEFINE_TRACE(Request) { |
740 Body::Trace(visitor); | 737 Body::Trace(visitor); |
741 visitor->Trace(request_); | 738 visitor->Trace(request_); |
742 visitor->Trace(headers_); | 739 visitor->Trace(headers_); |
743 } | 740 } |
744 | 741 |
745 } // namespace blink | 742 } // namespace blink |
OLD | NEW |