| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013, Intel Corporation | 3 * Copyright (C) 2013, Intel Corporation |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // Max number of CORS redirects handled in DocumentThreadableLoader. | 99 // Max number of CORS redirects handled in DocumentThreadableLoader. |
| 100 // Same number as net/url_request/url_request.cc, and | 100 // Same number as net/url_request/url_request.cc, and |
| 101 // same number as https://fetch.spec.whatwg.org/#concept-http-fetch, Step 4. | 101 // same number as https://fetch.spec.whatwg.org/#concept-http-fetch, Step 4. |
| 102 // FIXME: currently the number of redirects is counted and limited here and in | 102 // FIXME: currently the number of redirects is counted and limited here and in |
| 103 // net/url_request/url_request.cc separately. | 103 // net/url_request/url_request.cc separately. |
| 104 static const int kMaxCORSRedirects = 20; | 104 static const int kMaxCORSRedirects = 20; |
| 105 | 105 |
| 106 void DocumentThreadableLoader::loadResourceSynchronously(Document& document, con
st ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoa
derOptions& options, const ResourceLoaderOptions& resourceLoaderOptions) | 106 void DocumentThreadableLoader::loadResourceSynchronously(Document& document, con
st ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoa
derOptions& options, const ResourceLoaderOptions& resourceLoaderOptions) |
| 107 { | 107 { |
| 108 // The loader will be deleted as soon as this function exits. | 108 // The loader will be deleted as soon as this function exits. |
| 109 RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoa
der(document, &client, LoadSynchronously, options, resourceLoaderOptions)); | 109 OwnPtr<DocumentThreadableLoader> loader = adoptPtr(new DocumentThreadableLoa
der(document, &client, LoadSynchronously, options, resourceLoaderOptions)); |
| 110 loader->start(request); | 110 loader->start(request); |
| 111 ASSERT(loader->hasOneRef()); | |
| 112 } | 111 } |
| 113 | 112 |
| 114 PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document&
document, ThreadableLoaderClient* client, const ThreadableLoaderOptions& options
, const ResourceLoaderOptions& resourceLoaderOptions) | 113 PassOwnPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document&
document, ThreadableLoaderClient* client, const ThreadableLoaderOptions& options
, const ResourceLoaderOptions& resourceLoaderOptions) |
| 115 { | 114 { |
| 116 return adoptRef(new DocumentThreadableLoader(document, client, LoadAsynchron
ously, options, resourceLoaderOptions)); | 115 return adoptPtr(new DocumentThreadableLoader(document, client, LoadAsynchron
ously, options, resourceLoaderOptions)); |
| 117 } | 116 } |
| 118 | 117 |
| 119 DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl
eLoaderClient* client, BlockingBehavior blockingBehavior, const ThreadableLoader
Options& options, const ResourceLoaderOptions& resourceLoaderOptions) | 118 DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl
eLoaderClient* client, BlockingBehavior blockingBehavior, const ThreadableLoader
Options& options, const ResourceLoaderOptions& resourceLoaderOptions) |
| 120 : m_client(client) | 119 : m_client(client) |
| 121 , m_document(&document) | 120 , m_document(&document) |
| 122 , m_options(options) | 121 , m_options(options) |
| 123 , m_resourceLoaderOptions(resourceLoaderOptions) | 122 , m_resourceLoaderOptions(resourceLoaderOptions) |
| 124 , m_forceDoNotAllowStoredCredentials(false) | 123 , m_forceDoNotAllowStoredCredentials(false) |
| 125 , m_securityOrigin(m_resourceLoaderOptions.securityOrigin) | 124 , m_securityOrigin(m_resourceLoaderOptions.securityOrigin) |
| 126 , m_sameOriginRequest(false) | 125 , m_sameOriginRequest(false) |
| 127 , m_crossOriginNonSimpleRequest(false) | 126 , m_crossOriginNonSimpleRequest(false) |
| 128 , m_isUsingDataConsumerHandle(false) | 127 , m_isUsingDataConsumerHandle(false) |
| 129 , m_async(blockingBehavior == LoadAsynchronously) | 128 , m_async(blockingBehavior == LoadAsynchronously) |
| 130 , m_requestContext(WebURLRequest::RequestContextUnspecified) | 129 , m_requestContext(WebURLRequest::RequestContextUnspecified) |
| 131 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout) | 130 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout) |
| 132 , m_requestStartedSeconds(0.0) | 131 , m_requestStartedSeconds(0.0) |
| 133 , m_corsRedirectLimit(kMaxCORSRedirects) | 132 , m_corsRedirectLimit(kMaxCORSRedirects) |
| 134 , m_redirectMode(WebURLRequest::FetchRedirectModeFollow) | 133 , m_redirectMode(WebURLRequest::FetchRedirectModeFollow) |
| 134 , m_weakFactory(this) |
| 135 { | 135 { |
| 136 ASSERT(client); | 136 ASSERT(client); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void DocumentThreadableLoader::start(const ResourceRequest& request) | 139 void DocumentThreadableLoader::start(const ResourceRequest& request) |
| 140 { | 140 { |
| 141 // Setting an outgoing referer is only supported in the async code path. | 141 // Setting an outgoing referer is only supported in the async code path. |
| 142 ASSERT(m_async || request.httpReferrer().isEmpty()); | 142 ASSERT(m_async || request.httpReferrer().isEmpty()); |
| 143 | 143 |
| 144 m_sameOriginRequest = securityOrigin()->canRequestNoSuborigin(request.url())
; | 144 m_sameOriginRequest = securityOrigin()->canRequestNoSuborigin(request.url())
; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 // |this| may be dead here. | 387 // |this| may be dead here. |
| 388 | 388 |
| 389 request = ResourceRequest(); | 389 request = ResourceRequest(); |
| 390 | 390 |
| 391 return; | 391 return; |
| 392 } | 392 } |
| 393 | 393 |
| 394 if (m_redirectMode == WebURLRequest::FetchRedirectModeManual) { | 394 if (m_redirectMode == WebURLRequest::FetchRedirectModeManual) { |
| 395 // Keep |this| alive even if the client release a reference in | 395 // Keep |this| alive even if the client release a reference in |
| 396 // responseReceived(). | 396 // responseReceived(). |
| 397 RefPtr<DocumentThreadableLoader> protect(this); | 397 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); |
| 398 | 398 |
| 399 // We use |m_redirectMode| to check the original redirect mode. | 399 // We use |m_redirectMode| to check the original redirect mode. |
| 400 // |request| is a new request for redirect. So we don't set the redirect | 400 // |request| is a new request for redirect. So we don't set the redirect |
| 401 // mode of it in WebURLLoaderImpl::Context::OnReceivedRedirect(). | 401 // mode of it in WebURLLoaderImpl::Context::OnReceivedRedirect(). |
| 402 ASSERT(request.useStreamOnResponse()); | 402 ASSERT(request.useStreamOnResponse()); |
| 403 // There is no need to read the body of redirect response because there | 403 // There is no need to read the body of redirect response because there |
| 404 // is no way to read the body of opaque-redirect filtered response's | 404 // is no way to read the body of opaque-redirect filtered response's |
| 405 // internal response. | 405 // internal response. |
| 406 // TODO(horo): If we support any API which expose the internal body, we | 406 // TODO(horo): If we support any API which expose the internal body, we |
| 407 // will have to read the body. And also HTTPCache changes will be needed | 407 // will have to read the body. And also HTTPCache changes will be needed |
| 408 // because it doesn't store the body of redirect responses. | 408 // because it doesn't store the body of redirect responses. |
| 409 responseReceived(resource, redirectResponse, adoptPtr(new EmptyDataHandl
e())); | 409 responseReceived(resource, redirectResponse, adoptPtr(new EmptyDataHandl
e())); |
| 410 | 410 |
| 411 if (!self) { |
| 412 request = ResourceRequest(); |
| 413 return; |
| 414 } |
| 415 |
| 411 if (m_client) { | 416 if (m_client) { |
| 412 ASSERT(m_actualRequest.isNull()); | 417 ASSERT(m_actualRequest.isNull()); |
| 413 notifyFinished(resource); | 418 notifyFinished(resource); |
| 414 } | 419 } |
| 415 | 420 |
| 416 request = ResourceRequest(); | 421 request = ResourceRequest(); |
| 417 | 422 |
| 418 return; | 423 return; |
| 419 } | 424 } |
| 420 | 425 |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 return m_securityOrigin ? m_securityOrigin.get() : document().securityOrigin
(); | 921 return m_securityOrigin ? m_securityOrigin.get() : document().securityOrigin
(); |
| 917 } | 922 } |
| 918 | 923 |
| 919 Document& DocumentThreadableLoader::document() const | 924 Document& DocumentThreadableLoader::document() const |
| 920 { | 925 { |
| 921 ASSERT(m_document); | 926 ASSERT(m_document); |
| 922 return *m_document; | 927 return *m_document; |
| 923 } | 928 } |
| 924 | 929 |
| 925 } // namespace blink | 930 } // namespace blink |
| OLD | NEW |