| 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 "config.h" | 5 #include "config.h" |
| 6 #include "FetchManager.h" | 6 #include "FetchManager.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| 11 #include "bindings/core/v8/V8ThrowException.h" | 11 #include "bindings/core/v8/V8ThrowException.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/fetch/FetchUtils.h" |
| 13 #include "core/fileapi/Blob.h" | 14 #include "core/fileapi/Blob.h" |
| 14 #include "core/loader/ThreadableLoader.h" | 15 #include "core/loader/ThreadableLoader.h" |
| 15 #include "core/loader/ThreadableLoaderClient.h" | 16 #include "core/loader/ThreadableLoaderClient.h" |
| 16 #include "core/xml/XMLHttpRequest.h" | |
| 17 #include "modules/serviceworkers/FetchRequestData.h" | 17 #include "modules/serviceworkers/FetchRequestData.h" |
| 18 #include "modules/serviceworkers/Response.h" | 18 #include "modules/serviceworkers/Response.h" |
| 19 #include "modules/serviceworkers/ResponseInit.h" | 19 #include "modules/serviceworkers/ResponseInit.h" |
| 20 #include "platform/network/ResourceRequest.h" | 20 #include "platform/network/ResourceRequest.h" |
| 21 #include "platform/weborigin/SecurityOrigin.h" | 21 #include "platform/weborigin/SecurityOrigin.h" |
| 22 #include "public/platform/WebURLRequest.h" | 22 #include "public/platform/WebURLRequest.h" |
| 23 #include "wtf/HashSet.h" | 23 #include "wtf/HashSet.h" |
| 24 | 24 |
| 25 namespace blink { | 25 namespace blink { |
| 26 | 26 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 performNetworkError(); | 193 performNetworkError(); |
| 194 return; | 194 return; |
| 195 } | 195 } |
| 196 | 196 |
| 197 // "- |request|'s mode is |CORS-with-forced-preflight|. | 197 // "- |request|'s mode is |CORS-with-forced-preflight|. |
| 198 // "- |request|'s unsafe request flag is set and either |request|'s method | 198 // "- |request|'s unsafe request flag is set and either |request|'s method |
| 199 // is not a simple method or a header in |request|'s header list is not a | 199 // is not a simple method or a header in |request|'s header list is not a |
| 200 // simple header" | 200 // simple header" |
| 201 if (m_request->mode() == FetchRequestData::CORSWithForcedPreflight | 201 if (m_request->mode() == FetchRequestData::CORSWithForcedPreflight |
| 202 || (m_request->unsafeRequestFlag() | 202 || (m_request->unsafeRequestFlag() |
| 203 && (!isSimpleMethod(m_request->method()) | 203 && (!FetchUtils::isSimpleMethod(m_request->method()) |
| 204 || m_request->headerList()->containsNonSimpleHeader()))) { | 204 || m_request->headerList()->containsNonSimpleHeader()))) { |
| 205 // "Set |request|'s response tainting to |CORS|." | 205 // "Set |request|'s response tainting to |CORS|." |
| 206 m_request->setResponseTainting(FetchRequestData::CORSTainting); | 206 m_request->setResponseTainting(FetchRequestData::CORSTainting); |
| 207 // "The result of performing an HTTP fetch using |request| with the | 207 // "The result of performing an HTTP fetch using |request| with the |
| 208 // |CORS flag| and |CORS preflight flag| set." | 208 // |CORS flag| and |CORS preflight flag| set." |
| 209 m_corsFlag = true; | 209 m_corsFlag = true; |
| 210 m_corsPreflightFlag = true; | 210 m_corsPreflightFlag = true; |
| 211 performHTTPFetch(); | 211 performHTTPFetch(); |
| 212 return; | 212 return; |
| 213 } | 213 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 Loader* loader = m_loaders.add(ownLoader.release()).storedValue->get(); | 345 Loader* loader = m_loaders.add(ownLoader.release()).storedValue->get(); |
| 346 loader->start(); | 346 loader->start(); |
| 347 return promise; | 347 return promise; |
| 348 } | 348 } |
| 349 | 349 |
| 350 void FetchManager::onLoaderFinished(Loader* loader) | 350 void FetchManager::onLoaderFinished(Loader* loader) |
| 351 { | 351 { |
| 352 m_loaders.remove(loader); | 352 m_loaders.remove(loader); |
| 353 } | 353 } |
| 354 | 354 |
| 355 bool FetchManager::isSimpleMethod(const String& method) | |
| 356 { | |
| 357 // "A simple method is a method that is `GET`, `HEAD`, or `POST`." | |
| 358 return isOnAccessControlSimpleRequestMethodWhitelist(method); | |
| 359 } | |
| 360 | |
| 361 bool FetchManager::isForbiddenMethod(const String& method) | |
| 362 { | |
| 363 // "A forbidden method is a method that is a byte case-insensitive match for | |
| 364 // one of `CONNECT`, `TRACE`, and `TRACK`." | |
| 365 return !XMLHttpRequest::isAllowedHTTPMethod(method); | |
| 366 } | |
| 367 | |
| 368 bool FetchManager::isUsefulMethod(const String& method) | |
| 369 { | |
| 370 // "A useful method is a method that is not a forbidden method." | |
| 371 // "A forbidden method is a method that is a byte case-insensitive match for | |
| 372 // one of `CONNECT`, `TRACE`, and `TRACK`." | |
| 373 return XMLHttpRequest::isAllowedHTTPMethod(method); | |
| 374 } | |
| 375 | |
| 376 } // namespace blink | 355 } // namespace blink |
| OLD | NEW |