OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 LocalFrame* FrameFetchContext::frame() const { | 239 LocalFrame* FrameFetchContext::frame() const { |
240 if (!m_documentLoader) | 240 if (!m_documentLoader) |
241 return frameOfImportsController(); | 241 return frameOfImportsController(); |
242 | 242 |
243 LocalFrame* frame = m_documentLoader->frame(); | 243 LocalFrame* frame = m_documentLoader->frame(); |
244 DCHECK(frame); | 244 DCHECK(frame); |
245 return frame; | 245 return frame; |
246 } | 246 } |
247 | 247 |
248 FrameLoaderClient* FrameFetchContext::frameLoaderClient() const { | 248 LocalFrameClient* FrameFetchContext::localFrameClient() const { |
249 return frame()->client(); | 249 return frame()->client(); |
250 } | 250 } |
251 | 251 |
252 void FrameFetchContext::addAdditionalRequestHeaders(ResourceRequest& request, | 252 void FrameFetchContext::addAdditionalRequestHeaders(ResourceRequest& request, |
253 FetchResourceType type) { | 253 FetchResourceType type) { |
254 bool isMainResource = type == FetchMainResource; | 254 bool isMainResource = type == FetchMainResource; |
255 if (!isMainResource) { | 255 if (!isMainResource) { |
256 if (!request.didSetHTTPReferrer()) { | 256 if (!request.didSetHTTPReferrer()) { |
257 DCHECK(m_document); | 257 DCHECK(m_document); |
258 request.setHTTPReferrer(SecurityPolicy::generateReferrer( | 258 request.setHTTPReferrer(SecurityPolicy::generateReferrer( |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 int intraPriorityValue) { | 416 int intraPriorityValue) { |
417 TRACE_EVENT1( | 417 TRACE_EVENT1( |
418 "devtools.timeline", "ResourceChangePriority", "data", | 418 "devtools.timeline", "ResourceChangePriority", "data", |
419 InspectorChangeResourcePriorityEvent::data(identifier, loadPriority)); | 419 InspectorChangeResourcePriorityEvent::data(identifier, loadPriority)); |
420 InspectorInstrumentation::didChangeResourcePriority(frame(), identifier, | 420 InspectorInstrumentation::didChangeResourcePriority(frame(), identifier, |
421 loadPriority); | 421 loadPriority); |
422 } | 422 } |
423 | 423 |
424 void FrameFetchContext::prepareRequest(ResourceRequest& request) { | 424 void FrameFetchContext::prepareRequest(ResourceRequest& request) { |
425 frame()->loader().applyUserAgent(request); | 425 frame()->loader().applyUserAgent(request); |
426 frameLoaderClient()->dispatchWillSendRequest(request); | 426 localFrameClient()->dispatchWillSendRequest(request); |
427 } | 427 } |
428 | 428 |
429 void FrameFetchContext::dispatchWillSendRequest( | 429 void FrameFetchContext::dispatchWillSendRequest( |
430 unsigned long identifier, | 430 unsigned long identifier, |
431 ResourceRequest& request, | 431 ResourceRequest& request, |
432 const ResourceResponse& redirectResponse, | 432 const ResourceResponse& redirectResponse, |
433 const FetchInitiatorInfo& initiatorInfo) { | 433 const FetchInitiatorInfo& initiatorInfo) { |
434 TRACE_EVENT1("devtools.timeline", "ResourceSendRequest", "data", | 434 TRACE_EVENT1("devtools.timeline", "ResourceSendRequest", "data", |
435 InspectorSendRequestEvent::data(identifier, frame(), request)); | 435 InspectorSendRequestEvent::data(identifier, frame(), request)); |
436 // For initial requests, prepareRequest() is called in | 436 // For initial requests, prepareRequest() is called in |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 } | 520 } |
521 | 521 |
522 void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache( | 522 void FrameFetchContext::dispatchDidLoadResourceFromMemoryCache( |
523 unsigned long identifier, | 523 unsigned long identifier, |
524 Resource* resource, | 524 Resource* resource, |
525 WebURLRequest::FrameType frameType, | 525 WebURLRequest::FrameType frameType, |
526 WebURLRequest::RequestContext requestContext) { | 526 WebURLRequest::RequestContext requestContext) { |
527 ResourceRequest request(resource->url()); | 527 ResourceRequest request(resource->url()); |
528 request.setFrameType(frameType); | 528 request.setFrameType(frameType); |
529 request.setRequestContext(requestContext); | 529 request.setRequestContext(requestContext); |
530 frameLoaderClient()->dispatchDidLoadResourceFromMemoryCache( | 530 localFrameClient()->dispatchDidLoadResourceFromMemoryCache( |
531 request, resource->response()); | 531 request, resource->response()); |
532 dispatchWillSendRequest(identifier, request, ResourceResponse(), | 532 dispatchWillSendRequest(identifier, request, ResourceResponse(), |
533 resource->options().initiatorInfo); | 533 resource->options().initiatorInfo); |
534 | 534 |
535 InspectorInstrumentation::markResourceAsCached(frame(), identifier); | 535 InspectorInstrumentation::markResourceAsCached(frame(), identifier); |
536 if (!resource->response().isNull()) { | 536 if (!resource->response().isNull()) { |
537 dispatchDidReceiveResponseInternal(identifier, resource->response(), | 537 dispatchDidReceiveResponseInternal(identifier, resource->response(), |
538 frameType, requestContext, resource, | 538 frameType, requestContext, resource, |
539 LinkLoader::DoNotLoadResources); | 539 LinkLoader::DoNotLoadResources); |
540 } | 540 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 Document* initiatorDocument = m_document && info.isMainResource() | 616 Document* initiatorDocument = m_document && info.isMainResource() |
617 ? m_document->parentDocument() | 617 ? m_document->parentDocument() |
618 : m_document.get(); | 618 : m_document.get(); |
619 if (!initiatorDocument || !initiatorDocument->domWindow()) | 619 if (!initiatorDocument || !initiatorDocument->domWindow()) |
620 return; | 620 return; |
621 DOMWindowPerformance::performance(*initiatorDocument->domWindow()) | 621 DOMWindowPerformance::performance(*initiatorDocument->domWindow()) |
622 ->addResourceTiming(info); | 622 ->addResourceTiming(info); |
623 } | 623 } |
624 | 624 |
625 bool FrameFetchContext::allowImage(bool imagesEnabled, const KURL& url) const { | 625 bool FrameFetchContext::allowImage(bool imagesEnabled, const KURL& url) const { |
626 return frameLoaderClient()->allowImage(imagesEnabled, url); | 626 return localFrameClient()->allowImage(imagesEnabled, url); |
627 } | 627 } |
628 | 628 |
629 void FrameFetchContext::printAccessDeniedMessage(const KURL& url) const { | 629 void FrameFetchContext::printAccessDeniedMessage(const KURL& url) const { |
630 if (url.isNull()) | 630 if (url.isNull()) |
631 return; | 631 return; |
632 | 632 |
633 String message; | 633 String message; |
634 if (!m_document || m_document->url().isNull()) { | 634 if (!m_document || m_document->url().isNull()) { |
635 message = "Unsafe attempt to load URL " + url.elidedString() + '.'; | 635 message = "Unsafe attempt to load URL " + url.elidedString() + '.'; |
636 } else if (url.isLocalFile() || m_document->url().isLocalFile()) { | 636 } else if (url.isLocalFile() || m_document->url().isLocalFile()) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 if (!shouldBypassMainWorldCSP && | 758 if (!shouldBypassMainWorldCSP && |
759 !m_document->contentSecurityPolicy()->allowRequest( | 759 !m_document->contentSecurityPolicy()->allowRequest( |
760 resourceRequest.requestContext(), url, | 760 resourceRequest.requestContext(), url, |
761 options.contentSecurityPolicyNonce, options.integrityMetadata, | 761 options.contentSecurityPolicyNonce, options.integrityMetadata, |
762 options.parserDisposition, redirectStatus, cspReporting)) | 762 options.parserDisposition, redirectStatus, cspReporting)) |
763 return ResourceRequestBlockedReason::CSP; | 763 return ResourceRequestBlockedReason::CSP; |
764 } | 764 } |
765 | 765 |
766 if (type == Resource::Script || type == Resource::ImportResource) { | 766 if (type == Resource::Script || type == Resource::ImportResource) { |
767 DCHECK(frame()); | 767 DCHECK(frame()); |
768 if (!frameLoaderClient()->allowScriptFromSource( | 768 if (!localFrameClient()->allowScriptFromSource( |
769 !frame()->settings() || frame()->settings()->getScriptEnabled(), | 769 !frame()->settings() || frame()->settings()->getScriptEnabled(), |
770 url)) { | 770 url)) { |
771 frameLoaderClient()->didNotAllowScript(); | 771 localFrameClient()->didNotAllowScript(); |
772 // TODO(estark): Use a different ResourceRequestBlockedReason here, since | 772 // TODO(estark): Use a different ResourceRequestBlockedReason here, since |
773 // this check has nothing to do with CSP. https://crbug.com/600795 | 773 // this check has nothing to do with CSP. https://crbug.com/600795 |
774 return ResourceRequestBlockedReason::CSP; | 774 return ResourceRequestBlockedReason::CSP; |
775 } | 775 } |
776 } else if (type == Resource::Media || type == Resource::TextTrack) { | 776 } else if (type == Resource::Media || type == Resource::TextTrack) { |
777 DCHECK(frame()); | 777 DCHECK(frame()); |
778 if (!frameLoaderClient()->allowMedia(url)) | 778 if (!localFrameClient()->allowMedia(url)) |
779 return ResourceRequestBlockedReason::Other; | 779 return ResourceRequestBlockedReason::Other; |
780 } | 780 } |
781 | 781 |
782 // SVG Images have unique security rules that prevent all subresource requests | 782 // SVG Images have unique security rules that prevent all subresource requests |
783 // except for data urls. | 783 // except for data urls. |
784 if (type != Resource::MainResource && | 784 if (type != Resource::MainResource && |
785 frame()->chromeClient().isSVGImageChromeClient() && !url.protocolIsData()) | 785 frame()->chromeClient().isSVGImageChromeClient() && !url.protocolIsData()) |
786 return ResourceRequestBlockedReason::Origin; | 786 return ResourceRequestBlockedReason::Origin; |
787 | 787 |
788 // Measure the number of legacy URL schemes ('ftp://') and the number of | 788 // Measure the number of legacy URL schemes ('ftp://') and the number of |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 | 867 |
868 if (m_documentLoader) { | 868 if (m_documentLoader) { |
869 return m_documentLoader->frame() | 869 return m_documentLoader->frame() |
870 ->loader() | 870 ->loader() |
871 .client() | 871 .client() |
872 ->isControlledByServiceWorker(*m_documentLoader); | 872 ->isControlledByServiceWorker(*m_documentLoader); |
873 } | 873 } |
874 // m_documentLoader is null while loading resources from an HTML import. In | 874 // m_documentLoader is null while loading resources from an HTML import. In |
875 // such cases whether the request is controlled by ServiceWorker or not is | 875 // such cases whether the request is controlled by ServiceWorker or not is |
876 // determined by the document loader of the frame. | 876 // determined by the document loader of the frame. |
877 return frameLoaderClient()->isControlledByServiceWorker( | 877 return localFrameClient()->isControlledByServiceWorker( |
878 *frame()->loader().documentLoader()); | 878 *frame()->loader().documentLoader()); |
879 } | 879 } |
880 | 880 |
881 int64_t FrameFetchContext::serviceWorkerID() const { | 881 int64_t FrameFetchContext::serviceWorkerID() const { |
882 DCHECK(m_documentLoader || frame()->loader().documentLoader()); | 882 DCHECK(m_documentLoader || frame()->loader().documentLoader()); |
883 if (m_documentLoader) { | 883 if (m_documentLoader) { |
884 return m_documentLoader->frame()->client()->serviceWorkerID( | 884 return m_documentLoader->frame()->client()->serviceWorkerID( |
885 *m_documentLoader); | 885 *m_documentLoader); |
886 } | 886 } |
887 // m_documentLoader is null while loading resources from an HTML import. | 887 // m_documentLoader is null while loading resources from an HTML import. |
888 // In such cases a service worker ID could be retrieved from the document | 888 // In such cases a service worker ID could be retrieved from the document |
889 // loader of the frame. | 889 // loader of the frame. |
890 return frameLoaderClient()->serviceWorkerID( | 890 return localFrameClient()->serviceWorkerID( |
891 *frame()->loader().documentLoader()); | 891 *frame()->loader().documentLoader()); |
892 } | 892 } |
893 | 893 |
894 bool FrameFetchContext::isMainFrame() const { | 894 bool FrameFetchContext::isMainFrame() const { |
895 return frame()->isMainFrame(); | 895 return frame()->isMainFrame(); |
896 } | 896 } |
897 | 897 |
898 bool FrameFetchContext::defersLoading() const { | 898 bool FrameFetchContext::defersLoading() const { |
899 return frame()->page()->suspended(); | 899 return frame()->page()->suspended(); |
900 } | 900 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 response.httpHeaderField(HTTPNames::Link), response.url(), | 1094 response.httpHeaderField(HTTPNames::Link), response.url(), |
1095 frame()->document(), NetworkHintsInterfaceImpl(), resourceLoadingPolicy, | 1095 frame()->document(), NetworkHintsInterfaceImpl(), resourceLoadingPolicy, |
1096 LinkLoader::LoadAll, nullptr); | 1096 LinkLoader::LoadAll, nullptr); |
1097 | 1097 |
1098 if (response.hasMajorCertificateErrors()) { | 1098 if (response.hasMajorCertificateErrors()) { |
1099 MixedContentChecker::handleCertificateError(frame(), response, frameType, | 1099 MixedContentChecker::handleCertificateError(frame(), response, frameType, |
1100 requestContext); | 1100 requestContext); |
1101 } | 1101 } |
1102 | 1102 |
1103 frame()->loader().progress().incrementProgress(identifier, response); | 1103 frame()->loader().progress().incrementProgress(identifier, response); |
1104 frameLoaderClient()->dispatchDidReceiveResponse(response); | 1104 localFrameClient()->dispatchDidReceiveResponse(response); |
1105 DocumentLoader* documentLoader = masterDocumentLoader(); | 1105 DocumentLoader* documentLoader = masterDocumentLoader(); |
1106 InspectorInstrumentation::didReceiveResourceResponse( | 1106 InspectorInstrumentation::didReceiveResourceResponse( |
1107 frame(), identifier, documentLoader, response, resource); | 1107 frame(), identifier, documentLoader, response, resource); |
1108 // It is essential that inspector gets resource response BEFORE console. | 1108 // It is essential that inspector gets resource response BEFORE console. |
1109 frame()->console().reportResourceResponseReceived(documentLoader, identifier, | 1109 frame()->console().reportResourceResponseReceived(documentLoader, identifier, |
1110 response); | 1110 response); |
1111 } | 1111 } |
1112 | 1112 |
1113 DEFINE_TRACE(FrameFetchContext) { | 1113 DEFINE_TRACE(FrameFetchContext) { |
1114 visitor->trace(m_document); | 1114 visitor->trace(m_document); |
1115 visitor->trace(m_documentLoader); | 1115 visitor->trace(m_documentLoader); |
1116 FetchContext::trace(visitor); | 1116 FetchContext::trace(visitor); |
1117 } | 1117 } |
1118 | 1118 |
1119 } // namespace blink | 1119 } // namespace blink |
OLD | NEW |