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 27 matching lines...) Expand all Loading... |
38 #include "core/fetch/RawResource.h" | 38 #include "core/fetch/RawResource.h" |
39 #include "core/fetch/Resource.h" | 39 #include "core/fetch/Resource.h" |
40 #include "core/fetch/ResourceFetcher.h" | 40 #include "core/fetch/ResourceFetcher.h" |
41 #include "core/inspector/InspectorInstrumentation.h" | 41 #include "core/inspector/InspectorInstrumentation.h" |
42 #include "core/loader/CrossOriginPreflightResultCache.h" | 42 #include "core/loader/CrossOriginPreflightResultCache.h" |
43 #include "core/loader/DocumentThreadableLoaderClient.h" | 43 #include "core/loader/DocumentThreadableLoaderClient.h" |
44 #include "core/loader/FrameLoader.h" | 44 #include "core/loader/FrameLoader.h" |
45 #include "core/loader/ThreadableLoaderClient.h" | 45 #include "core/loader/ThreadableLoaderClient.h" |
46 #include "core/page/ContentSecurityPolicy.h" | 46 #include "core/page/ContentSecurityPolicy.h" |
47 #include "core/page/Frame.h" | 47 #include "core/page/Frame.h" |
| 48 #include "core/platform/SharedBuffer.h" |
48 #include "core/platform/network/ResourceError.h" | 49 #include "core/platform/network/ResourceError.h" |
49 #include "core/platform/network/ResourceRequest.h" | 50 #include "core/platform/network/ResourceRequest.h" |
50 #include "weborigin/SchemeRegistry.h" | 51 #include "weborigin/SchemeRegistry.h" |
51 #include "weborigin/SecurityOrigin.h" | 52 #include "weborigin/SecurityOrigin.h" |
52 #include "wtf/Assertions.h" | 53 #include "wtf/Assertions.h" |
53 | 54 |
54 namespace WebCore { | 55 namespace WebCore { |
55 | 56 |
56 void DocumentThreadableLoader::loadResourceSynchronously(Document* document, con
st ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoa
derOptions& options) | 57 void DocumentThreadableLoader::loadResourceSynchronously(Document* document, con
st ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoa
derOptions& options) |
57 { | 58 { |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 if (m_resource) { | 434 if (m_resource) { |
434 if (m_resource->loader()) { | 435 if (m_resource->loader()) { |
435 unsigned long identifier = m_resource->identifier(); | 436 unsigned long identifier = m_resource->identifier(); |
436 InspectorInstrumentation::documentThreadableLoaderStartedLoading
ForClient(m_document, identifier, m_client); | 437 InspectorInstrumentation::documentThreadableLoaderStartedLoading
ForClient(m_document, identifier, m_client); |
437 } | 438 } |
438 m_resource->addClient(this); | 439 m_resource->addClient(this); |
439 } | 440 } |
440 return; | 441 return; |
441 } | 442 } |
442 | 443 |
443 // FIXME: ThreadableLoaderOptions.sniffContent is not supported for synchron
ous requests. | 444 FetchRequest fetchRequest(request, m_options.initiator, options); |
444 Vector<char> data; | 445 ResourcePtr<Resource> resource = m_document->fetcher()->fetchSynchronously(f
etchRequest); |
445 ResourceError error; | 446 ResourceResponse response = resource ? resource->response() : ResourceRespon
se(); |
446 ResourceResponse response; | 447 unsigned long identifier = resource ? resource->identifier() : std::numeric_
limits<unsigned long>::max(); |
447 unsigned long identifier = std::numeric_limits<unsigned long>::max(); | 448 ResourceError error = resource ? resource->resourceError() : ResourceError()
; |
448 if (Frame* frame = m_document->frame()) { | |
449 if (!m_document->fetcher()->checkInsecureContent(Resource::Raw, requestU
RL, options.mixedContentBlockingTreatment)) { | |
450 m_client->didFail(error); | |
451 return; | |
452 } | |
453 identifier = m_document->fetcher()->fetchSynchronously(request, m_option
s.allowCredentials, error, response, data); | |
454 } | |
455 | 449 |
456 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient(m_
document, identifier, m_client); | 450 InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient(m_
document, identifier, m_client); |
457 | 451 |
| 452 if (!resource) { |
| 453 m_client->didFail(error); |
| 454 return; |
| 455 } |
| 456 |
458 // No exception for file:/// resources, see <rdar://problem/4962298>. | 457 // No exception for file:/// resources, see <rdar://problem/4962298>. |
459 // Also, if we have an HTTP response, then it wasn't a network error in fact
. | 458 // Also, if we have an HTTP response, then it wasn't a network error in fact
. |
460 if (!error.isNull() && !requestURL.isLocalFile() && response.httpStatusCode(
) <= 0) { | 459 if (!error.isNull() && !requestURL.isLocalFile() && response.httpStatusCode(
) <= 0) { |
461 m_client->didFail(error); | 460 m_client->didFail(error); |
462 return; | 461 return; |
463 } | 462 } |
464 | 463 |
465 // FIXME: FrameLoader::loadSynchronously() does not tell us whether a redire
ct happened or not, so we guess by comparing the | 464 // FIXME: A synchronous request does not tell us whether a redirect happened
or not, so we guess by comparing the |
466 // 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 | 465 // 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 |
467 // requested. Also comparing the request and response URLs as strings will f
ail if the requestURL still has its credentials. | 466 // requested. Also comparing the request and response URLs as strings will f
ail if the requestURL still has its credentials. |
468 if (requestURL != response.url() && (!isAllowedByPolicy(response.url()) || !
isAllowedRedirect(response.url()))) { | 467 if (requestURL != response.url() && (!isAllowedByPolicy(response.url()) || !
isAllowedRedirect(response.url()))) { |
469 m_client->didFailRedirectCheck(); | 468 m_client->didFailRedirectCheck(); |
470 return; | 469 return; |
471 } | 470 } |
472 | 471 |
473 didReceiveResponse(identifier, response); | 472 didReceiveResponse(identifier, response); |
474 | 473 |
475 const char* bytes = static_cast<const char*>(data.data()); | 474 SharedBuffer* data = resource->resourceBuffer(); |
476 int len = static_cast<int>(data.size()); | 475 if (data) |
477 didReceiveData(identifier, bytes, len); | 476 didReceiveData(identifier, data->data(), data->size()); |
478 | 477 |
479 didFinishLoading(identifier, 0.0); | 478 didFinishLoading(identifier, 0.0); |
480 } | 479 } |
481 | 480 |
482 bool DocumentThreadableLoader::isAllowedRedirect(const KURL& url) const | 481 bool DocumentThreadableLoader::isAllowedRedirect(const KURL& url) const |
483 { | 482 { |
484 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) | 483 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) |
485 return true; | 484 return true; |
486 | 485 |
487 return m_sameOriginRequest && securityOrigin()->canRequest(url); | 486 return m_sameOriginRequest && securityOrigin()->canRequest(url); |
(...skipping 20 matching lines...) Expand all Loading... |
508 | 507 |
509 if (!(requestUrl.user().isEmpty() && requestUrl.pass().isEmpty())) { | 508 if (!(requestUrl.user().isEmpty() && requestUrl.pass().isEmpty())) { |
510 errorDescription = "The request was redirected to a URL ('" + requestUrl
.string() + "') containing userinfo, which is disallowed for cross-origin reques
ts."; | 509 errorDescription = "The request was redirected to a URL ('" + requestUrl
.string() + "') containing userinfo, which is disallowed for cross-origin reques
ts."; |
511 return false; | 510 return false; |
512 } | 511 } |
513 | 512 |
514 return true; | 513 return true; |
515 } | 514 } |
516 | 515 |
517 } // namespace WebCore | 516 } // namespace WebCore |
OLD | NEW |