| 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 21 matching lines...) Expand all Loading... |
| 32 #include "core/loader/DocumentThreadableLoader.h" | 32 #include "core/loader/DocumentThreadableLoader.h" |
| 33 | 33 |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/fetch/CrossOriginAccessControl.h" | 35 #include "core/fetch/CrossOriginAccessControl.h" |
| 36 #include "core/fetch/FetchRequest.h" | 36 #include "core/fetch/FetchRequest.h" |
| 37 #include "core/fetch/FetchUtils.h" | 37 #include "core/fetch/FetchUtils.h" |
| 38 #include "core/fetch/Resource.h" | 38 #include "core/fetch/Resource.h" |
| 39 #include "core/fetch/ResourceFetcher.h" | 39 #include "core/fetch/ResourceFetcher.h" |
| 40 #include "core/frame/FrameConsole.h" | 40 #include "core/frame/FrameConsole.h" |
| 41 #include "core/frame/LocalFrame.h" | 41 #include "core/frame/LocalFrame.h" |
| 42 #include "core/frame/csp/ContentSecurityPolicy.h" | |
| 43 #include "core/inspector/InspectorInstrumentation.h" | 42 #include "core/inspector/InspectorInstrumentation.h" |
| 44 #include "core/inspector/InspectorTraceEvents.h" | 43 #include "core/inspector/InspectorTraceEvents.h" |
| 45 #include "core/loader/CrossOriginPreflightResultCache.h" | 44 #include "core/loader/CrossOriginPreflightResultCache.h" |
| 46 #include "core/loader/DocumentThreadableLoaderClient.h" | 45 #include "core/loader/DocumentThreadableLoaderClient.h" |
| 47 #include "core/loader/FrameLoader.h" | 46 #include "core/loader/FrameLoader.h" |
| 48 #include "core/loader/FrameLoaderClient.h" | 47 #include "core/loader/FrameLoaderClient.h" |
| 49 #include "core/loader/ThreadableLoaderClient.h" | 48 #include "core/loader/ThreadableLoaderClient.h" |
| 50 #include "core/page/ChromeClient.h" | 49 #include "core/page/ChromeClient.h" |
| 51 #include "core/page/Page.h" | 50 #include "core/page/Page.h" |
| 52 #include "platform/SharedBuffer.h" | 51 #include "platform/SharedBuffer.h" |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 if (m_client) { | 433 if (m_client) { |
| 435 ASSERT(m_actualRequest.isNull()); | 434 ASSERT(m_actualRequest.isNull()); |
| 436 notifyFinished(resource); | 435 notifyFinished(resource); |
| 437 } | 436 } |
| 438 | 437 |
| 439 request = ResourceRequest(); | 438 request = ResourceRequest(); |
| 440 | 439 |
| 441 return; | 440 return; |
| 442 } | 441 } |
| 443 | 442 |
| 444 if (m_redirectMode == WebURLRequest::FetchRedirectModeError || !isAllowedByC
ontentSecurityPolicy(request.url(), ContentSecurityPolicy::DidRedirect)) { | 443 if (m_redirectMode == WebURLRequest::FetchRedirectModeError) { |
| 445 ThreadableLoaderClient* client = m_client; | 444 ThreadableLoaderClient* client = m_client; |
| 446 clear(); | 445 clear(); |
| 447 client->didFailRedirectCheck(); | 446 client->didFailRedirectCheck(); |
| 448 // |this| may be dead here. | 447 // |this| may be dead here. |
| 449 | 448 |
| 450 request = ResourceRequest(); | 449 request = ResourceRequest(); |
| 451 | 450 |
| 452 return; | 451 return; |
| 453 } | 452 } |
| 454 | 453 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 } else { | 521 } else { |
| 523 ThreadableLoaderClient* client = m_client; | 522 ThreadableLoaderClient* client = m_client; |
| 524 clear(); | 523 clear(); |
| 525 client->didFailRedirectCheck(); | 524 client->didFailRedirectCheck(); |
| 526 // |this| may be dead here. | 525 // |this| may be dead here. |
| 527 } | 526 } |
| 528 | 527 |
| 529 request = ResourceRequest(); | 528 request = ResourceRequest(); |
| 530 } | 529 } |
| 531 | 530 |
| 531 void DocumentThreadableLoader::redirectBlocked() |
| 532 { |
| 533 // Tells the client that a redirect was received but not followed (for an un
known reason). |
| 534 ThreadableLoaderClient* client = m_client; |
| 535 clear(); |
| 536 client->didFailRedirectCheck(); |
| 537 // |this| may be dead here |
| 538 } |
| 539 |
| 532 void DocumentThreadableLoader::dataSent(Resource* resource, unsigned long long b
ytesSent, unsigned long long totalBytesToBeSent) | 540 void DocumentThreadableLoader::dataSent(Resource* resource, unsigned long long b
ytesSent, unsigned long long totalBytesToBeSent) |
| 533 { | 541 { |
| 534 ASSERT(m_client); | 542 ASSERT(m_client); |
| 535 ASSERT_UNUSED(resource, resource == this->resource()); | 543 ASSERT_UNUSED(resource, resource == this->resource()); |
| 536 ASSERT(m_async); | 544 ASSERT(m_async); |
| 537 | 545 |
| 538 m_client->didSendData(bytesSent, totalBytesToBeSent); | 546 m_client->didSendData(bytesSent, totalBytesToBeSent); |
| 539 // |this| may be dead here. | 547 // |this| may be dead here. |
| 540 } | 548 } |
| 541 | 549 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 // No exception for file:/// resources, see <rdar://problem/4962298>. | 882 // No exception for file:/// resources, see <rdar://problem/4962298>. |
| 875 // Also, if we have an HTTP response, then it wasn't a network error in fact
. | 883 // Also, if we have an HTTP response, then it wasn't a network error in fact
. |
| 876 if (!error.isNull() && !requestURL.isLocalFile() && response.httpStatusCode(
) <= 0) { | 884 if (!error.isNull() && !requestURL.isLocalFile() && response.httpStatusCode(
) <= 0) { |
| 877 m_client->didFail(error); | 885 m_client->didFail(error); |
| 878 return; | 886 return; |
| 879 } | 887 } |
| 880 | 888 |
| 881 // FIXME: A synchronous request does not tell us whether a redirect happened
or not, so we guess by comparing the | 889 // FIXME: A synchronous request does not tell us whether a redirect happened
or not, so we guess by comparing the |
| 882 // request and response URLs. This isn't a perfect test though, since a serv
er can serve a redirect to the same URL that was | 890 // request and response URLs. This isn't a perfect test though, since a serv
er can serve a redirect to the same URL that was |
| 883 // requested. Also comparing the request and response URLs as strings will f
ail if the requestURL still has its credentials. | 891 // requested. Also comparing the request and response URLs as strings will f
ail if the requestURL still has its credentials. |
| 884 if (requestURL != response.url() && (!isAllowedByContentSecurityPolicy(respo
nse.url(), ContentSecurityPolicy::DidRedirect) || !isAllowedRedirect(response.ur
l()))) { | 892 if (requestURL != response.url() && !isAllowedRedirect(response.url())) { |
| 885 m_client->didFailRedirectCheck(); | 893 m_client->didFailRedirectCheck(); |
| 886 return; | 894 return; |
| 887 } | 895 } |
| 888 | 896 |
| 889 handleResponse(identifier, response, nullptr); | 897 handleResponse(identifier, response, nullptr); |
| 890 | 898 |
| 891 // handleResponse() may detect an error. In such a case (check |m_client| | 899 // handleResponse() may detect an error. In such a case (check |m_client| |
| 892 // as it gets reset by clear() call), skip the rest. | 900 // as it gets reset by clear() call), skip the rest. |
| 893 // | 901 // |
| 894 // |this| is alive here since loadResourceSynchronously() keeps it alive | 902 // |this| is alive here since loadResourceSynchronously() keeps it alive |
| (...skipping 14 matching lines...) Expand all Loading... |
| 909 } | 917 } |
| 910 | 918 |
| 911 bool DocumentThreadableLoader::isAllowedRedirect(const KURL& url) const | 919 bool DocumentThreadableLoader::isAllowedRedirect(const KURL& url) const |
| 912 { | 920 { |
| 913 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) | 921 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) |
| 914 return true; | 922 return true; |
| 915 | 923 |
| 916 return m_sameOriginRequest && getSecurityOrigin()->canRequest(url); | 924 return m_sameOriginRequest && getSecurityOrigin()->canRequest(url); |
| 917 } | 925 } |
| 918 | 926 |
| 919 bool DocumentThreadableLoader::isAllowedByContentSecurityPolicy(const KURL& url,
ContentSecurityPolicy::RedirectStatus redirectStatus) const | |
| 920 { | |
| 921 if (m_options.contentSecurityPolicyEnforcement != EnforceContentSecurityPoli
cy) | |
| 922 return true; | |
| 923 | |
| 924 return document().contentSecurityPolicy()->allowRequest(m_requestContext, ur
l, redirectStatus); | |
| 925 } | |
| 926 | |
| 927 StoredCredentials DocumentThreadableLoader::effectiveAllowCredentials() const | 927 StoredCredentials DocumentThreadableLoader::effectiveAllowCredentials() const |
| 928 { | 928 { |
| 929 if (m_forceDoNotAllowStoredCredentials) | 929 if (m_forceDoNotAllowStoredCredentials) |
| 930 return DoNotAllowStoredCredentials; | 930 return DoNotAllowStoredCredentials; |
| 931 return m_resourceLoaderOptions.allowCredentials; | 931 return m_resourceLoaderOptions.allowCredentials; |
| 932 } | 932 } |
| 933 | 933 |
| 934 SecurityOrigin* DocumentThreadableLoader::getSecurityOrigin() const | 934 SecurityOrigin* DocumentThreadableLoader::getSecurityOrigin() const |
| 935 { | 935 { |
| 936 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri
gin(); | 936 return m_securityOrigin ? m_securityOrigin.get() : document().getSecurityOri
gin(); |
| 937 } | 937 } |
| 938 | 938 |
| 939 Document& DocumentThreadableLoader::document() const | 939 Document& DocumentThreadableLoader::document() const |
| 940 { | 940 { |
| 941 ASSERT(m_document); | 941 ASSERT(m_document); |
| 942 return *m_document; | 942 return *m_document; |
| 943 } | 943 } |
| 944 | 944 |
| 945 } // namespace blink | 945 } // namespace blink |
| OLD | NEW |