Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 #include "core/timing/DOMWindowPerformance.h" | 62 #include "core/timing/DOMWindowPerformance.h" |
| 63 #include "core/timing/Performance.h" | 63 #include "core/timing/Performance.h" |
| 64 #include "platform/Logging.h" | 64 #include "platform/Logging.h" |
| 65 #include "platform/TracedValue.h" | 65 #include "platform/TracedValue.h" |
| 66 #include "platform/mhtml/MHTMLArchive.h" | 66 #include "platform/mhtml/MHTMLArchive.h" |
| 67 #include "platform/network/ResourceLoadPriority.h" | 67 #include "platform/network/ResourceLoadPriority.h" |
| 68 #include "platform/network/ResourceTimingInfo.h" | 68 #include "platform/network/ResourceTimingInfo.h" |
| 69 #include "platform/weborigin/SchemeRegistry.h" | 69 #include "platform/weborigin/SchemeRegistry.h" |
| 70 #include "platform/weborigin/SecurityPolicy.h" | 70 #include "platform/weborigin/SecurityPolicy.h" |
| 71 #include "public/platform/WebCachePolicy.h" | 71 #include "public/platform/WebCachePolicy.h" |
| 72 #include "public/platform/WebDocumentSubresourceFilter.h" | |
| 72 #include "public/platform/WebFrameScheduler.h" | 73 #include "public/platform/WebFrameScheduler.h" |
| 73 | 74 |
| 74 #include <algorithm> | 75 #include <algorithm> |
| 75 | 76 |
| 76 namespace blink { | 77 namespace blink { |
| 77 | 78 |
| 78 namespace { | 79 namespace { |
| 79 | 80 |
| 80 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch Request::DeferOption defer, const Document& document) | 81 bool shouldDisallowFetchForMainFrameScript(const ResourceRequest& request, Fetch Request::DeferOption defer, const Document& document) |
| 81 { | 82 { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 } | 273 } |
| 273 return memoryCachePolicyToResourceRequestCachePolicy(getCachePolicy()); | 274 return memoryCachePolicyToResourceRequestCachePolicy(getCachePolicy()); |
| 274 } | 275 } |
| 275 return WebCachePolicy::UseProtocolCachePolicy; | 276 return WebCachePolicy::UseProtocolCachePolicy; |
| 276 } | 277 } |
| 277 | 278 |
| 278 // FIXME(http://crbug.com/274173): | 279 // FIXME(http://crbug.com/274173): |
| 279 // |loader| can be null if the resource is loaded from imported document. | 280 // |loader| can be null if the resource is loaded from imported document. |
| 280 // This means inspector, which uses DocumentLoader as an grouping entity, | 281 // This means inspector, which uses DocumentLoader as an grouping entity, |
| 281 // cannot see imported documents. | 282 // cannot see imported documents. |
| 282 inline DocumentLoader* FrameFetchContext::ensureLoaderForNotifications() const | 283 inline DocumentLoader* FrameFetchContext::effectiveDocumentLoader() const |
| 283 { | 284 { |
| 284 return m_documentLoader ? m_documentLoader.get() : frame()->loader().documen tLoader(); | 285 return m_documentLoader ? m_documentLoader.get() : frame()->loader().documen tLoader(); |
| 285 } | 286 } |
| 286 | 287 |
| 287 void FrameFetchContext::dispatchDidChangeResourcePriority(unsigned long identifi er, ResourceLoadPriority loadPriority, int intraPriorityValue) | 288 void FrameFetchContext::dispatchDidChangeResourcePriority(unsigned long identifi er, ResourceLoadPriority loadPriority, int intraPriorityValue) |
| 288 { | 289 { |
| 289 frame()->loader().client()->dispatchDidChangeResourcePriority(identifier, lo adPriority, intraPriorityValue); | 290 frame()->loader().client()->dispatchDidChangeResourcePriority(identifier, lo adPriority, intraPriorityValue); |
| 290 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceChangePriority", TRACE_EV ENT_SCOPE_THREAD, "data", InspectorChangeResourcePriorityEvent::data(identifier, loadPriority)); | 291 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceChangePriority", TRACE_EV ENT_SCOPE_THREAD, "data", InspectorChangeResourcePriorityEvent::data(identifier, loadPriority)); |
| 291 InspectorInstrumentation::didChangeResourcePriority(frame(), identifier, loa dPriority); | 292 InspectorInstrumentation::didChangeResourcePriority(frame(), identifier, loa dPriority); |
| 292 } | 293 } |
| 293 | 294 |
| 294 void FrameFetchContext::dispatchWillSendRequest(unsigned long identifier, Resour ceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiat orInfo& initiatorInfo) | 295 void FrameFetchContext::dispatchWillSendRequest(unsigned long identifier, Resour ceRequest& request, const ResourceResponse& redirectResponse, const FetchInitiat orInfo& initiatorInfo) |
| 295 { | 296 { |
| 296 frame()->loader().applyUserAgent(request); | 297 frame()->loader().applyUserAgent(request); |
| 297 frame()->loader().client()->dispatchWillSendRequest(m_documentLoader, identi fier, request, redirectResponse); | 298 frame()->loader().client()->dispatchWillSendRequest(m_documentLoader, identi fier, request, redirectResponse); |
| 298 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceSendRequest", TRACE_EVENT _SCOPE_THREAD, "data", InspectorSendRequestEvent::data(identifier, frame(), requ est)); | 299 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceSendRequest", TRACE_EVENT _SCOPE_THREAD, "data", InspectorSendRequestEvent::data(identifier, frame(), requ est)); |
| 299 InspectorInstrumentation::willSendRequest(frame(), identifier, ensureLoaderF orNotifications(), request, redirectResponse, initiatorInfo); | 300 InspectorInstrumentation::willSendRequest(frame(), identifier, effectiveDocu mentLoader(), request, redirectResponse, initiatorInfo); |
| 300 } | 301 } |
| 301 | 302 |
| 302 void FrameFetchContext::dispatchDidReceiveResponse(unsigned long identifier, con st ResourceResponse& response, WebURLRequest::FrameType frameType, WebURLRequest ::RequestContext requestContext, ResourceLoader* resourceLoader) | 303 void FrameFetchContext::dispatchDidReceiveResponse(unsigned long identifier, con st ResourceResponse& response, WebURLRequest::FrameType frameType, WebURLRequest ::RequestContext requestContext, ResourceLoader* resourceLoader) |
| 303 { | 304 { |
| 304 LinkLoader::CanLoadResources resourceLoadingPolicy = LinkLoader::LoadResourc esAndPreconnect; | 305 LinkLoader::CanLoadResources resourceLoadingPolicy = LinkLoader::LoadResourc esAndPreconnect; |
| 305 MixedContentChecker::checkMixedPrivatePublic(frame(), response.remoteIPAddre ss()); | 306 MixedContentChecker::checkMixedPrivatePublic(frame(), response.remoteIPAddre ss()); |
| 306 if (m_documentLoader == frame()->loader().provisionalDocumentLoader()) { | 307 if (m_documentLoader == frame()->loader().provisionalDocumentLoader()) { |
| 307 ResourceFetcher* fetcher = nullptr; | 308 ResourceFetcher* fetcher = nullptr; |
| 308 if (frame()->document()) | 309 if (frame()->document()) |
| 309 fetcher = frame()->document()->fetcher(); | 310 fetcher = frame()->document()->fetcher(); |
| 310 m_documentLoader->clientHintsPreferences().updateFromAcceptClientHintsHe ader(response.httpHeaderField(HTTPNames::Accept_CH), fetcher); | 311 m_documentLoader->clientHintsPreferences().updateFromAcceptClientHintsHe ader(response.httpHeaderField(HTTPNames::Accept_CH), fetcher); |
| 311 // When response is received with a provisional docloader, the resource haven't committed yet, and we cannot load resources, only preconnect. | 312 // When response is received with a provisional docloader, the resource haven't committed yet, and we cannot load resources, only preconnect. |
| 312 resourceLoadingPolicy = LinkLoader::DoNotLoadResources; | 313 resourceLoadingPolicy = LinkLoader::DoNotLoadResources; |
| 313 } | 314 } |
| 314 LinkLoader::loadLinksFromHeader(response.httpHeaderField(HTTPNames::Link), r esponse.url(), frame()->document(), NetworkHintsInterfaceImpl(), resourceLoading Policy, nullptr); | 315 LinkLoader::loadLinksFromHeader(response.httpHeaderField(HTTPNames::Link), r esponse.url(), frame()->document(), NetworkHintsInterfaceImpl(), resourceLoading Policy, nullptr); |
| 315 | 316 |
| 316 if (response.hasMajorCertificateErrors()) | 317 if (response.hasMajorCertificateErrors()) |
| 317 MixedContentChecker::handleCertificateError(frame(), response, frameType , requestContext); | 318 MixedContentChecker::handleCertificateError(frame(), response, frameType , requestContext); |
| 318 | 319 |
| 319 frame()->loader().progress().incrementProgress(identifier, response); | 320 frame()->loader().progress().incrementProgress(identifier, response); |
| 320 frame()->loader().client()->dispatchDidReceiveResponse(m_documentLoader, ide ntifier, response); | 321 frame()->loader().client()->dispatchDidReceiveResponse(m_documentLoader, ide ntifier, response); |
| 321 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceReceiveResponse", TRACE_E VENT_SCOPE_THREAD, "data", InspectorReceiveResponseEvent::data(identifier, frame (), response)); | 322 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceReceiveResponse", TRACE_E VENT_SCOPE_THREAD, "data", InspectorReceiveResponseEvent::data(identifier, frame (), response)); |
| 322 DocumentLoader* documentLoader = ensureLoaderForNotifications(); | 323 DocumentLoader* documentLoader = effectiveDocumentLoader(); |
| 323 InspectorInstrumentation::didReceiveResourceResponse(frame(), identifier, do cumentLoader, response, resourceLoader); | 324 InspectorInstrumentation::didReceiveResourceResponse(frame(), identifier, do cumentLoader, response, resourceLoader); |
| 324 // It is essential that inspector gets resource response BEFORE console. | 325 // It is essential that inspector gets resource response BEFORE console. |
| 325 frame()->console().reportResourceResponseReceived(documentLoader, identifier , response); | 326 frame()->console().reportResourceResponseReceived(documentLoader, identifier , response); |
| 326 } | 327 } |
| 327 | 328 |
| 328 void FrameFetchContext::dispatchDidReceiveData(unsigned long identifier, const c har* data, int dataLength, int encodedDataLength) | 329 void FrameFetchContext::dispatchDidReceiveData(unsigned long identifier, const c har* data, int dataLength, int encodedDataLength) |
| 329 { | 330 { |
| 330 frame()->loader().progress().incrementProgress(identifier, dataLength); | 331 frame()->loader().progress().incrementProgress(identifier, dataLength); |
| 331 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceReceivedData", TRACE_EVEN T_SCOPE_THREAD, "data", InspectorReceiveDataEvent::data(identifier, frame(), enc odedDataLength)); | 332 TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceReceivedData", TRACE_EVEN T_SCOPE_THREAD, "data", InspectorReceiveDataEvent::data(identifier, frame(), enc odedDataLength)); |
| 332 InspectorInstrumentation::didReceiveData(frame(), identifier, data, dataLeng th, encodedDataLength); | 333 InspectorInstrumentation::didReceiveData(frame(), identifier, data, dataLeng th, encodedDataLength); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 | 446 |
| 446 bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r esourceRequest, const KURL& url, const ResourceLoaderOptions& options, bool forP reload, FetchRequest::OriginRestriction originRestriction) const | 447 bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r esourceRequest, const KURL& url, const ResourceLoaderOptions& options, bool forP reload, FetchRequest::OriginRestriction originRestriction) const |
| 447 { | 448 { |
| 448 // As of CSP2, for requests that are the results of redirects, the match | 449 // As of CSP2, for requests that are the results of redirects, the match |
| 449 // algorithm should ignore the path component of the URL. | 450 // algorithm should ignore the path component of the URL. |
| 450 ContentSecurityPolicy::RedirectStatus redirectStatus = resourceRequest.follo wedRedirect() ? ContentSecurityPolicy::DidRedirect : ContentSecurityPolicy::DidN otRedirect; | 451 ContentSecurityPolicy::RedirectStatus redirectStatus = resourceRequest.follo wedRedirect() ? ContentSecurityPolicy::DidRedirect : ContentSecurityPolicy::DidN otRedirect; |
| 451 | 452 |
| 452 ResourceRequestBlockedReason reason = canRequestInternal(type, resourceReque st, url, options, forPreload, originRestriction, redirectStatus); | 453 ResourceRequestBlockedReason reason = canRequestInternal(type, resourceReque st, url, options, forPreload, originRestriction, redirectStatus); |
| 453 if (reason != ResourceRequestBlockedReasonNone) { | 454 if (reason != ResourceRequestBlockedReasonNone) { |
| 454 if (!forPreload) | 455 if (!forPreload) |
| 455 InspectorInstrumentation::didBlockRequest(frame(), resourceRequest, ensureLoaderForNotifications(), options.initiatorInfo, reason); | 456 InspectorInstrumentation::didBlockRequest(frame(), resourceRequest, effectiveDocumentLoader(), options.initiatorInfo, reason); |
| 456 return false; | 457 return false; |
| 457 } | 458 } |
| 458 return true; | 459 return true; |
| 459 } | 460 } |
| 460 | 461 |
| 461 bool FrameFetchContext::allowResponse(Resource::Type type, const ResourceRequest & resourceRequest, const KURL& url, const ResourceLoaderOptions& options) const | 462 bool FrameFetchContext::allowResponse(Resource::Type type, const ResourceRequest & resourceRequest, const KURL& url, const ResourceLoaderOptions& options) const |
| 462 { | 463 { |
| 463 ResourceRequestBlockedReason reason = canRequestInternal(type, resourceReque st, url, options, false, FetchRequest::UseDefaultOriginRestrictionForType, Conte ntSecurityPolicy::DidRedirect); | 464 ResourceRequestBlockedReason reason = canRequestInternal(type, resourceReque st, url, options, false, FetchRequest::UseDefaultOriginRestrictionForType, Conte ntSecurityPolicy::DidRedirect); |
| 464 if (reason != ResourceRequestBlockedReasonNone) { | 465 if (reason != ResourceRequestBlockedReasonNone) { |
| 465 InspectorInstrumentation::didBlockRequest(frame(), resourceRequest, ensu reLoaderForNotifications(), options.initiatorInfo, reason); | 466 InspectorInstrumentation::didBlockRequest(frame(), resourceRequest, effe ctiveDocumentLoader(), options.initiatorInfo, reason); |
| 466 return false; | 467 return false; |
| 467 } | 468 } |
| 468 return true; | 469 return true; |
| 469 } | 470 } |
| 470 | 471 |
| 471 ResourceRequestBlockedReason FrameFetchContext::canRequestInternal(Resource::Typ e type, const ResourceRequest& resourceRequest, const KURL& url, const ResourceL oaderOptions& options, bool forPreload, FetchRequest::OriginRestriction originRe striction, ContentSecurityPolicy::RedirectStatus redirectStatus) const | 472 ResourceRequestBlockedReason FrameFetchContext::canRequestInternal(Resource::Typ e type, const ResourceRequest& resourceRequest, const KURL& url, const ResourceL oaderOptions& options, bool forPreload, FetchRequest::OriginRestriction originRe striction, ContentSecurityPolicy::RedirectStatus redirectStatus) const |
| 472 { | 473 { |
| 473 if (InspectorInstrumentation::shouldBlockRequest(frame(), resourceRequest)) | 474 if (InspectorInstrumentation::shouldBlockRequest(frame(), resourceRequest)) |
| 474 return ResourceRequestBlockedReasonInspector; | 475 return ResourceRequestBlockedReasonInspector; |
| 475 | 476 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 } | 567 } |
| 567 | 568 |
| 568 // Measure the number of pages that load resources after a redirect | 569 // Measure the number of pages that load resources after a redirect |
| 569 // when a CSP is active, to see if implementing CSP | 570 // when a CSP is active, to see if implementing CSP |
| 570 // 'unsafe-redirect' is feasible. | 571 // 'unsafe-redirect' is feasible. |
| 571 if (csp && csp->isActive() && resourceRequest.frameType() != WebURLRequest:: FrameTypeTopLevel && resourceRequest.frameType() != WebURLRequest::FrameTypeAuxi liary && redirectStatus == ContentSecurityPolicy::DidRedirect) { | 572 if (csp && csp->isActive() && resourceRequest.frameType() != WebURLRequest:: FrameTypeTopLevel && resourceRequest.frameType() != WebURLRequest::FrameTypeAuxi liary && redirectStatus == ContentSecurityPolicy::DidRedirect) { |
| 572 ASSERT(frame()->document()); | 573 ASSERT(frame()->document()); |
| 573 UseCounter::count(frame()->document(), UseCounter::ResourceLoadedAfterRe directWithCSP); | 574 UseCounter::count(frame()->document(), UseCounter::ResourceLoadedAfterRe directWithCSP); |
| 574 } | 575 } |
| 575 | 576 |
| 576 // Last of all, check for mixed content. We do this last so that when | 577 // Check for mixed content. We do this second-to-last so that when folks blo ck |
| 577 // folks block mixed content with a CSP policy, they don't get a warning. | 578 // mixed content with a CSP policy, they don't get a warning. They'll still |
| 578 // They'll still get a warning in the console about CSP blocking the load. | 579 // get a warning in the console about CSP blocking the load. |
| 579 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? | 580 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? |
| 580 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; | 581 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; |
| 581 if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url, mix edContentReporting)) | 582 if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url, mix edContentReporting)) |
| 582 return ResourceRequestBlockedReasonMixedContent; | 583 return ResourceRequestBlockedReasonMixedContent; |
| 583 | 584 |
| 585 // Let the client have the final say into whether or not the load should pro ceed. | |
| 586 DocumentLoader* documentLoader = effectiveDocumentLoader(); | |
| 587 if (documentLoader && documentLoader->subresourceFilter() && type != Resourc e::MainResource && type != Resource::ImportResource && !documentLoader->subresou rceFilter()->allowLoad(url, resourceRequest.requestContext())) | |
|
Mike West
2016/06/01 13:43:18
Why exclude `Resource::MainResource` and `Resource
engedy
2016/06/02 23:07:19
We never want to filter the mainframe document loa
| |
| 588 return ResourceRequestBlockedReasonClient; | |
| 589 | |
| 584 return ResourceRequestBlockedReasonNone; | 590 return ResourceRequestBlockedReasonNone; |
| 585 } | 591 } |
| 586 | 592 |
| 587 bool FrameFetchContext::isControlledByServiceWorker() const | 593 bool FrameFetchContext::isControlledByServiceWorker() const |
| 588 { | 594 { |
| 589 ASSERT(m_documentLoader || frame()->loader().documentLoader()); | 595 ASSERT(m_documentLoader || frame()->loader().documentLoader()); |
| 590 if (m_documentLoader) | 596 if (m_documentLoader) |
| 591 return frame()->loader().client()->isControlledByServiceWorker(*m_docume ntLoader); | 597 return frame()->loader().client()->isControlledByServiceWorker(*m_docume ntLoader); |
| 592 // m_documentLoader is null while loading resources from an HTML import. | 598 // m_documentLoader is null while loading resources from an HTML import. |
| 593 // In such cases whether the request is controlled by ServiceWorker or not | 599 // In such cases whether the request is controlled by ServiceWorker or not |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 } | 820 } |
| 815 | 821 |
| 816 DEFINE_TRACE(FrameFetchContext) | 822 DEFINE_TRACE(FrameFetchContext) |
| 817 { | 823 { |
| 818 visitor->trace(m_document); | 824 visitor->trace(m_document); |
| 819 visitor->trace(m_documentLoader); | 825 visitor->trace(m_documentLoader); |
| 820 FetchContext::trace(visitor); | 826 FetchContext::trace(visitor); |
| 821 } | 827 } |
| 822 | 828 |
| 823 } // namespace blink | 829 } // namespace blink |
| OLD | NEW |