| 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 "modules/fetch/FetchManager.h" | 6 #include "modules/fetch/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/DOMArrayBuffer.h" | 12 #include "core/dom/DOMArrayBuffer.h" |
| 13 #include "core/dom/Document.h" | 13 #include "core/dom/Document.h" |
| 14 #include "core/dom/ExceptionCode.h" | 14 #include "core/dom/ExceptionCode.h" |
| 15 #include "core/fetch/FetchUtils.h" | 15 #include "core/fetch/FetchUtils.h" |
| 16 #include "core/fileapi/Blob.h" | 16 #include "core/fileapi/Blob.h" |
| 17 #include "core/frame/Frame.h" | 17 #include "core/frame/Frame.h" |
| 18 #include "core/frame/csp/ContentSecurityPolicy.h" | 18 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 19 #include "core/inspector/ConsoleMessage.h" | 19 #include "core/inspector/ConsoleMessage.h" |
| 20 #include "core/inspector/InspectorInstrumentation.h" |
| 20 #include "core/loader/ThreadableLoader.h" | 21 #include "core/loader/ThreadableLoader.h" |
| 21 #include "core/loader/ThreadableLoaderClient.h" | 22 #include "core/loader/ThreadableLoaderClient.h" |
| 22 #include "core/page/ChromeClient.h" | 23 #include "core/page/ChromeClient.h" |
| 23 #include "core/page/Page.h" | 24 #include "core/page/Page.h" |
| 24 #include "modules/fetch/Body.h" | 25 #include "modules/fetch/Body.h" |
| 25 #include "modules/fetch/BodyStreamBuffer.h" | 26 #include "modules/fetch/BodyStreamBuffer.h" |
| 26 #include "modules/fetch/DataConsumerHandleUtil.h" | 27 #include "modules/fetch/DataConsumerHandleUtil.h" |
| 27 #include "modules/fetch/FetchRequestData.h" | 28 #include "modules/fetch/FetchRequestData.h" |
| 28 #include "modules/fetch/Response.h" | 29 #include "modules/fetch/Response.h" |
| 29 #include "modules/fetch/ResponseInit.h" | 30 #include "modules/fetch/ResponseInit.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 150 |
| 150 void FetchManager::Loader::didFinishLoading(unsigned long, double) | 151 void FetchManager::Loader::didFinishLoading(unsigned long, double) |
| 151 { | 152 { |
| 152 ASSERT(!m_failed); | 153 ASSERT(!m_failed); |
| 153 m_finished = true; | 154 m_finished = true; |
| 154 | 155 |
| 155 if (document() && document()->frame() && document()->frame()->page() | 156 if (document() && document()->frame() && document()->frame()->page() |
| 156 && m_responseHttpStatusCode >= 200 && m_responseHttpStatusCode < 300) { | 157 && m_responseHttpStatusCode >= 200 && m_responseHttpStatusCode < 300) { |
| 157 document()->frame()->page()->chromeClient().ajaxSucceeded(document()->fr
ame()); | 158 document()->frame()->page()->chromeClient().ajaxSucceeded(document()->fr
ame()); |
| 158 } | 159 } |
| 159 | 160 InspectorInstrumentation::didFinishFetch(executionContext(), this, m_request
->method(), m_request->url().string()); |
| 160 notifyFinished(); | 161 notifyFinished(); |
| 161 } | 162 } |
| 162 | 163 |
| 163 void FetchManager::Loader::didFail(const ResourceError& error) | 164 void FetchManager::Loader::didFail(const ResourceError& error) |
| 164 { | 165 { |
| 165 if (error.isCancellation() || error.isTimeout() || error.domain() != errorDo
mainBlinkInternal) | 166 if (error.isCancellation() || error.isTimeout() || error.domain() != errorDo
mainBlinkInternal) |
| 166 failed(String()); | 167 failed(String()); |
| 167 else | 168 else |
| 168 failed("Fetch API cannot load " + error.failingURL() + ". " + error.loca
lizedDescription()); | 169 failed("Fetch API cannot load " + error.failingURL() + ". " + error.loca
lizedDescription()); |
| 169 } | 170 } |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 threadableLoaderOptions.crossOriginRequestPolicy = DenyCrossOriginReques
ts; | 375 threadableLoaderOptions.crossOriginRequestPolicy = DenyCrossOriginReques
ts; |
| 375 break; | 376 break; |
| 376 case WebURLRequest::FetchRequestModeNoCORS: | 377 case WebURLRequest::FetchRequestModeNoCORS: |
| 377 threadableLoaderOptions.crossOriginRequestPolicy = AllowCrossOriginReque
sts; | 378 threadableLoaderOptions.crossOriginRequestPolicy = AllowCrossOriginReque
sts; |
| 378 break; | 379 break; |
| 379 case WebURLRequest::FetchRequestModeCORS: | 380 case WebURLRequest::FetchRequestModeCORS: |
| 380 case WebURLRequest::FetchRequestModeCORSWithForcedPreflight: | 381 case WebURLRequest::FetchRequestModeCORSWithForcedPreflight: |
| 381 threadableLoaderOptions.crossOriginRequestPolicy = UseAccessControl; | 382 threadableLoaderOptions.crossOriginRequestPolicy = UseAccessControl; |
| 382 break; | 383 break; |
| 383 } | 384 } |
| 385 InspectorInstrumentation::willStartFetch(executionContext(), this); |
| 384 m_loader = ThreadableLoader::create(*executionContext(), this, request, thre
adableLoaderOptions, resourceLoaderOptions); | 386 m_loader = ThreadableLoader::create(*executionContext(), this, request, thre
adableLoaderOptions, resourceLoaderOptions); |
| 385 if (!m_loader) | 387 if (!m_loader) |
| 386 performNetworkError("Can't create ThreadableLoader"); | 388 performNetworkError("Can't create ThreadableLoader"); |
| 387 } | 389 } |
| 388 | 390 |
| 389 void FetchManager::Loader::failed(const String& message) | 391 void FetchManager::Loader::failed(const String& message) |
| 390 { | 392 { |
| 391 if (m_failed || m_finished) | 393 if (m_failed || m_finished) |
| 392 return; | 394 return; |
| 393 m_failed = true; | 395 m_failed = true; |
| 394 if (!message.isEmpty()) | 396 if (!message.isEmpty()) |
| 395 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSo
urce, ErrorMessageLevel, message)); | 397 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSo
urce, ErrorMessageLevel, message)); |
| 396 if (m_resolver) { | 398 if (m_resolver) { |
| 397 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) | 399 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 398 return; | 400 return; |
| 399 ScriptState* state = m_resolver->scriptState(); | 401 ScriptState* state = m_resolver->scriptState(); |
| 400 ScriptState::Scope scope(state); | 402 ScriptState::Scope scope(state); |
| 401 m_resolver->reject(V8ThrowException::createTypeError(state->isolate(), "
Failed to fetch")); | 403 m_resolver->reject(V8ThrowException::createTypeError(state->isolate(), "
Failed to fetch")); |
| 402 } | 404 } |
| 405 InspectorInstrumentation::didFailFetch(executionContext(), this); |
| 403 notifyFinished(); | 406 notifyFinished(); |
| 404 } | 407 } |
| 405 | 408 |
| 406 void FetchManager::Loader::notifyFinished() | 409 void FetchManager::Loader::notifyFinished() |
| 407 { | 410 { |
| 408 if (m_fetchManager) | 411 if (m_fetchManager) |
| 409 m_fetchManager->onLoaderFinished(this); | 412 m_fetchManager->onLoaderFinished(this); |
| 410 } | 413 } |
| 411 | 414 |
| 412 FetchManager::FetchManager(ExecutionContext* executionContext) | 415 FetchManager::FetchManager(ExecutionContext* executionContext) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 457 |
| 455 DEFINE_TRACE(FetchManager) | 458 DEFINE_TRACE(FetchManager) |
| 456 { | 459 { |
| 457 #if ENABLE(OILPAN) | 460 #if ENABLE(OILPAN) |
| 458 visitor->trace(m_executionContext); | 461 visitor->trace(m_executionContext); |
| 459 visitor->trace(m_loaders); | 462 visitor->trace(m_loaders); |
| 460 #endif | 463 #endif |
| 461 } | 464 } |
| 462 | 465 |
| 463 } // namespace blink | 466 } // namespace blink |
| OLD | NEW |