| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "web/WebAssociatedURLLoaderImpl.h" | 31 #include "web/WebAssociatedURLLoaderImpl.h" |
| 32 | 32 |
| 33 #include "core/dom/ContextLifecycleObserver.h" | 33 #include "core/dom/ContextLifecycleObserver.h" |
| 34 #include "core/dom/TaskRunnerHelper.h" |
| 34 #include "core/fetch/CrossOriginAccessControl.h" | 35 #include "core/fetch/CrossOriginAccessControl.h" |
| 35 #include "core/fetch/FetchUtils.h" | 36 #include "core/fetch/FetchUtils.h" |
| 36 #include "core/loader/DocumentThreadableLoader.h" | 37 #include "core/loader/DocumentThreadableLoader.h" |
| 37 #include "core/loader/DocumentThreadableLoaderClient.h" | 38 #include "core/loader/DocumentThreadableLoaderClient.h" |
| 38 #include "platform/Timer.h" | 39 #include "platform/Timer.h" |
| 39 #include "platform/exported/WrappedResourceRequest.h" | 40 #include "platform/exported/WrappedResourceRequest.h" |
| 40 #include "platform/exported/WrappedResourceResponse.h" | 41 #include "platform/exported/WrappedResourceResponse.h" |
| 41 #include "platform/network/HTTPParsers.h" | 42 #include "platform/network/HTTPParsers.h" |
| 42 #include "platform/network/ResourceError.h" | 43 #include "platform/network/ResourceError.h" |
| 43 #include "public/platform/WebHTTPHeaderVisitor.h" | 44 #include "public/platform/WebHTTPHeaderVisitor.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // It forwards its ThreadableLoaderClient notifications to a | 86 // It forwards its ThreadableLoaderClient notifications to a |
| 86 // WebAssociatedURLLoaderClient. | 87 // WebAssociatedURLLoaderClient. |
| 87 class WebAssociatedURLLoaderImpl::ClientAdapter final | 88 class WebAssociatedURLLoaderImpl::ClientAdapter final |
| 88 : public DocumentThreadableLoaderClient { | 89 : public DocumentThreadableLoaderClient { |
| 89 WTF_MAKE_NONCOPYABLE(ClientAdapter); | 90 WTF_MAKE_NONCOPYABLE(ClientAdapter); |
| 90 | 91 |
| 91 public: | 92 public: |
| 92 static std::unique_ptr<ClientAdapter> create( | 93 static std::unique_ptr<ClientAdapter> create( |
| 93 WebAssociatedURLLoaderImpl*, | 94 WebAssociatedURLLoaderImpl*, |
| 94 WebAssociatedURLLoaderClient*, | 95 WebAssociatedURLLoaderClient*, |
| 95 const WebAssociatedURLLoaderOptions&); | 96 const WebAssociatedURLLoaderOptions&, |
| 97 RefPtr<WebTaskRunner>); |
| 96 | 98 |
| 97 // ThreadableLoaderClient | 99 // ThreadableLoaderClient |
| 98 void didSendData(unsigned long long /*bytesSent*/, | 100 void didSendData(unsigned long long /*bytesSent*/, |
| 99 unsigned long long /*totalBytesToBeSent*/) override; | 101 unsigned long long /*totalBytesToBeSent*/) override; |
| 100 void didReceiveResponse(unsigned long, | 102 void didReceiveResponse(unsigned long, |
| 101 const ResourceResponse&, | 103 const ResourceResponse&, |
| 102 std::unique_ptr<WebDataConsumerHandle>) override; | 104 std::unique_ptr<WebDataConsumerHandle>) override; |
| 103 void didDownloadData(int /*dataLength*/) override; | 105 void didDownloadData(int /*dataLength*/) override; |
| 104 void didReceiveData(const char*, unsigned /*dataLength*/) override; | 106 void didReceiveData(const char*, unsigned /*dataLength*/) override; |
| 105 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; | 107 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 126 // possible. | 128 // possible. |
| 127 WebAssociatedURLLoaderClient* releaseClient() { | 129 WebAssociatedURLLoaderClient* releaseClient() { |
| 128 WebAssociatedURLLoaderClient* client = m_client; | 130 WebAssociatedURLLoaderClient* client = m_client; |
| 129 m_client = nullptr; | 131 m_client = nullptr; |
| 130 return client; | 132 return client; |
| 131 } | 133 } |
| 132 | 134 |
| 133 private: | 135 private: |
| 134 ClientAdapter(WebAssociatedURLLoaderImpl*, | 136 ClientAdapter(WebAssociatedURLLoaderImpl*, |
| 135 WebAssociatedURLLoaderClient*, | 137 WebAssociatedURLLoaderClient*, |
| 136 const WebAssociatedURLLoaderOptions&); | 138 const WebAssociatedURLLoaderOptions&, |
| 139 RefPtr<WebTaskRunner>); |
| 137 | 140 |
| 138 void notifyError(TimerBase*); | 141 void notifyError(TimerBase*); |
| 139 | 142 |
| 140 WebAssociatedURLLoaderImpl* m_loader; | 143 WebAssociatedURLLoaderImpl* m_loader; |
| 141 WebAssociatedURLLoaderClient* m_client; | 144 WebAssociatedURLLoaderClient* m_client; |
| 142 WebAssociatedURLLoaderOptions m_options; | 145 WebAssociatedURLLoaderOptions m_options; |
| 143 WebURLError m_error; | 146 WebURLError m_error; |
| 144 | 147 |
| 145 Timer<ClientAdapter> m_errorTimer; | 148 TaskRunnerTimer<ClientAdapter> m_errorTimer; |
| 146 bool m_enableErrorNotifications; | 149 bool m_enableErrorNotifications; |
| 147 bool m_didFail; | 150 bool m_didFail; |
| 148 }; | 151 }; |
| 149 | 152 |
| 150 std::unique_ptr<WebAssociatedURLLoaderImpl::ClientAdapter> | 153 std::unique_ptr<WebAssociatedURLLoaderImpl::ClientAdapter> |
| 151 WebAssociatedURLLoaderImpl::ClientAdapter::create( | 154 WebAssociatedURLLoaderImpl::ClientAdapter::create( |
| 152 WebAssociatedURLLoaderImpl* loader, | 155 WebAssociatedURLLoaderImpl* loader, |
| 153 WebAssociatedURLLoaderClient* client, | 156 WebAssociatedURLLoaderClient* client, |
| 154 const WebAssociatedURLLoaderOptions& options) { | 157 const WebAssociatedURLLoaderOptions& options, |
| 155 return WTF::wrapUnique(new ClientAdapter(loader, client, options)); | 158 RefPtr<WebTaskRunner> taskRunner) { |
| 159 return WTF::wrapUnique( |
| 160 new ClientAdapter(loader, client, options, taskRunner)); |
| 156 } | 161 } |
| 157 | 162 |
| 158 WebAssociatedURLLoaderImpl::ClientAdapter::ClientAdapter( | 163 WebAssociatedURLLoaderImpl::ClientAdapter::ClientAdapter( |
| 159 WebAssociatedURLLoaderImpl* loader, | 164 WebAssociatedURLLoaderImpl* loader, |
| 160 WebAssociatedURLLoaderClient* client, | 165 WebAssociatedURLLoaderClient* client, |
| 161 const WebAssociatedURLLoaderOptions& options) | 166 const WebAssociatedURLLoaderOptions& options, |
| 167 RefPtr<WebTaskRunner> taskRunner) |
| 162 : m_loader(loader), | 168 : m_loader(loader), |
| 163 m_client(client), | 169 m_client(client), |
| 164 m_options(options), | 170 m_options(options), |
| 165 m_errorTimer(this, &ClientAdapter::notifyError), | 171 m_errorTimer(std::move(taskRunner), this, &ClientAdapter::notifyError), |
| 166 m_enableErrorNotifications(false), | 172 m_enableErrorNotifications(false), |
| 167 m_didFail(false) { | 173 m_didFail(false) { |
| 168 DCHECK(m_loader); | 174 DCHECK(m_loader); |
| 169 DCHECK(m_client); | 175 DCHECK(m_client); |
| 170 } | 176 } |
| 171 | 177 |
| 172 bool WebAssociatedURLLoaderImpl::ClientAdapter::willFollowRedirect( | 178 bool WebAssociatedURLLoaderImpl::ClientAdapter::willFollowRedirect( |
| 173 const ResourceRequest& newRequest, | 179 const ResourceRequest& newRequest, |
| 174 const ResourceResponse& redirectResponse) { | 180 const ResourceResponse& redirectResponse) { |
| 175 if (!m_client) | 181 if (!m_client) |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 allowLoad = m_observer && isValidHTTPToken(method) && | 381 allowLoad = m_observer && isValidHTTPToken(method) && |
| 376 FetchUtils::isUsefulMethod(method); | 382 FetchUtils::isUsefulMethod(method); |
| 377 if (allowLoad) { | 383 if (allowLoad) { |
| 378 newRequest.setHTTPMethod(FetchUtils::normalizeMethod(method)); | 384 newRequest.setHTTPMethod(FetchUtils::normalizeMethod(method)); |
| 379 HTTPRequestHeaderValidator validator; | 385 HTTPRequestHeaderValidator validator; |
| 380 newRequest.visitHTTPHeaderFields(&validator); | 386 newRequest.visitHTTPHeaderFields(&validator); |
| 381 allowLoad = validator.isSafe(); | 387 allowLoad = validator.isSafe(); |
| 382 } | 388 } |
| 383 } | 389 } |
| 384 | 390 |
| 391 RefPtr<WebTaskRunner> taskRunner = TaskRunnerHelper::get( |
| 392 TaskType::UnspecedLoading, |
| 393 m_observer ? toDocument(m_observer->lifecycleContext()) : nullptr); |
| 385 m_client = client; | 394 m_client = client; |
| 386 m_clientAdapter = ClientAdapter::create(this, client, m_options); | 395 m_clientAdapter = |
| 396 ClientAdapter::create(this, client, m_options, std::move(taskRunner)); |
| 387 | 397 |
| 388 if (allowLoad) { | 398 if (allowLoad) { |
| 389 ThreadableLoaderOptions options; | 399 ThreadableLoaderOptions options; |
| 390 options.preflightPolicy = | 400 options.preflightPolicy = |
| 391 static_cast<PreflightPolicy>(m_options.preflightPolicy); | 401 static_cast<PreflightPolicy>(m_options.preflightPolicy); |
| 392 options.crossOriginRequestPolicy = static_cast<CrossOriginRequestPolicy>( | 402 options.crossOriginRequestPolicy = static_cast<CrossOriginRequestPolicy>( |
| 393 m_options.crossOriginRequestPolicy); | 403 m_options.crossOriginRequestPolicy); |
| 394 | 404 |
| 395 ResourceLoaderOptions resourceLoaderOptions; | 405 ResourceLoaderOptions resourceLoaderOptions; |
| 396 resourceLoaderOptions.allowCredentials = m_options.allowCredentials | 406 resourceLoaderOptions.allowCredentials = m_options.allowCredentials |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 // there could be a WebURLLoader instance behind the | 499 // there could be a WebURLLoader instance behind the |
| 490 // DocumentThreadableLoader instance. So, for safety, we chose to just | 500 // DocumentThreadableLoader instance. So, for safety, we chose to just |
| 491 // crash here. | 501 // crash here. |
| 492 CHECK(ThreadState::current()); | 502 CHECK(ThreadState::current()); |
| 493 | 503 |
| 494 m_observer->dispose(); | 504 m_observer->dispose(); |
| 495 m_observer = nullptr; | 505 m_observer = nullptr; |
| 496 } | 506 } |
| 497 | 507 |
| 498 } // namespace blink | 508 } // namespace blink |
| OLD | NEW |