Index: Source/core/loader/FrameFetchContext.cpp |
diff --git a/Source/core/loader/FrameFetchContext.cpp b/Source/core/loader/FrameFetchContext.cpp |
index 51e9019a40d16b6a15d2fca86fb429d4bb4d5c60..3ddb43b2d47b00f45d33accbbccf5c07baa7595a 100644 |
--- a/Source/core/loader/FrameFetchContext.cpp |
+++ b/Source/core/loader/FrameFetchContext.cpp |
@@ -347,10 +347,39 @@ void FrameFetchContext::printAccessDeniedMessage(const KURL& url) const |
bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& resourceRequest, const KURL& url, const ResourceLoaderOptions& options, bool forPreload, FetchRequest::OriginRestriction originRestriction) const |
{ |
+ class BlockedRequestInspectorNotification { |
pfeldman
2015/09/02 02:49:21
Why not return the enum?
dgozman
2015/09/02 22:59:56
Updated.
|
+ public: |
+ BlockedRequestInspectorNotification(LocalFrame* frame, const ResourceRequest& request, DocumentLoader* loader, const FetchInitiatorInfo& initiatorInfo) |
+ : m_frame(frame) |
+ , m_request(request) |
+ , m_loader(loader) |
+ , m_initiatorInfo(initiatorInfo) |
+ , m_reason(InspectorRequestBlockedReasonNone) {} |
+ |
+ ~BlockedRequestInspectorNotification() |
+ { |
+ if (m_reason != InspectorRequestBlockedReasonNone) |
+ InspectorInstrumentation::didBlockRequest(m_frame, m_request, m_loader, m_initiatorInfo, m_reason); |
+ } |
+ |
+ void setReason(InspectorRequestBlockedReason reason) { m_reason = reason; } |
+ |
+ private: |
+ LocalFrame* m_frame; |
+ const ResourceRequest& m_request; |
+ DocumentLoader* m_loader; |
+ const FetchInitiatorInfo& m_initiatorInfo; |
+ InspectorRequestBlockedReason m_reason; |
+ |
+ } inspectorNotification(frame(), resourceRequest, ensureLoaderForNotifications(), options.initiatorInfo); |
+ // Note: any return from this function must call inspectorNotification.setReason. |
+ |
InstrumentingAgents* agents = InspectorInstrumentation::instrumentingAgentsFor(frame()); |
if (agents && agents->inspectorResourceAgent()) { |
- if (agents->inspectorResourceAgent()->shouldBlockRequest(frame(), resourceRequest, ensureLoaderForNotifications(), options.initiatorInfo)) |
+ if (agents->inspectorResourceAgent()->shouldBlockRequest(resourceRequest)) { |
+ inspectorNotification.setReason(InspectorRequestBlockedReasonInspector); |
return false; |
+ } |
} |
SecurityOrigin* securityOrigin = options.securityOrigin.get(); |
@@ -361,6 +390,7 @@ bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r |
if (!forPreload) |
FrameLoader::reportLocalLoadFailed(frame(), url.elidedString()); |
WTF_LOG(ResourceLoading, "ResourceFetcher::requestResource URL was not allowed by SecurityOrigin::canDisplay"); |
+ inspectorNotification.setReason(InspectorRequestBlockedReasonOther); |
return false; |
} |
@@ -384,6 +414,7 @@ bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r |
// FIXME: Are we sure about Resource::Font? |
if (originRestriction == FetchRequest::RestrictToSameOrigin && !securityOrigin->canRequest(url)) { |
printAccessDeniedMessage(url); |
+ inspectorNotification.setReason(InspectorRequestBlockedReasonOrigin); |
return false; |
} |
break; |
@@ -392,6 +423,7 @@ bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r |
case Resource::SVGDocument: |
if (!securityOrigin->canRequest(url)) { |
printAccessDeniedMessage(url); |
+ inspectorNotification.setReason(InspectorRequestBlockedReasonOrigin); |
return false; |
} |
break; |
@@ -412,6 +444,7 @@ bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r |
// ImageResourceTest.MultipartImage crashes w/o the m_document null check. |
// I believe it's the Resource::Raw case. |
const ContentSecurityPolicy* csp = m_document ? m_document->contentSecurityPolicy() : nullptr; |
+ inspectorNotification.setReason(InspectorRequestBlockedReasonCSP); |
// FIXME: This would be cleaner if moved this switch into an allowFromSource() |
// helper on this object which took a Resource::Type, then this block would |
@@ -463,20 +496,26 @@ bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r |
if (!shouldBypassMainWorldCSP && !csp->allowMediaFromSource(url, redirectStatus, cspReporting)) |
return false; |
- if (!frame()->loader().client()->allowMedia(url)) |
+ if (!frame()->loader().client()->allowMedia(url)) { |
+ inspectorNotification.setReason(InspectorRequestBlockedReasonOther); |
return false; |
+ } |
break; |
} |
// SVG Images have unique security rules that prevent all subresource requests |
// except for data urls. |
- if (type != Resource::MainResource && frame()->chromeClient().isSVGImageChromeClient() && !url.protocolIsData()) |
+ if (type != Resource::MainResource && frame()->chromeClient().isSVGImageChromeClient() && !url.protocolIsData()) { |
+ inspectorNotification.setReason(InspectorRequestBlockedReasonOrigin); |
return false; |
+ } |
// FIXME: Once we use RequestContext for CSP (http://crbug.com/390497), remove this extra check. |
if (resourceRequest.requestContext() == WebURLRequest::RequestContextManifest) { |
- if (!shouldBypassMainWorldCSP && !csp->allowManifestFromSource(url, redirectStatus, cspReporting)) |
+ if (!shouldBypassMainWorldCSP && !csp->allowManifestFromSource(url, redirectStatus, cspReporting)) { |
+ inspectorNotification.setReason(InspectorRequestBlockedReasonCSP); |
return false; |
+ } |
} |
// Measure the number of legacy URL schemes ('ftp://') and the number of embedded-credential |
@@ -503,7 +542,13 @@ bool FrameFetchContext::canRequest(Resource::Type type, const ResourceRequest& r |
// They'll still get a warning in the console about CSP blocking the load. |
MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? |
MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; |
- return !MixedContentChecker::shouldBlockFetch(MixedContentChecker::effectiveFrameForFrameType(frame(), resourceRequest.frameType()), resourceRequest, url, mixedContentReporting); |
+ if (MixedContentChecker::shouldBlockFetch(MixedContentChecker::effectiveFrameForFrameType(frame(), resourceRequest.frameType()), resourceRequest, url, mixedContentReporting)) { |
+ inspectorNotification.setReason(InspectorRequestBlockedReasonMixedContent); |
+ return false; |
+ } |
+ |
+ inspectorNotification.setReason(InspectorRequestBlockedReasonNone); |
+ return true; |
} |
bool FrameFetchContext::isControlledByServiceWorker() const |