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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 case Resource::XSLStyleSheet: | 519 case Resource::XSLStyleSheet: |
520 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); | 520 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); |
521 case Resource::SVGDocument: | 521 case Resource::SVGDocument: |
522 if (!securityOrigin->canRequest(url)) { | 522 if (!securityOrigin->canRequest(url)) { |
523 printAccessDeniedMessage(url); | 523 printAccessDeniedMessage(url); |
524 return ResourceRequestBlockedReasonOrigin; | 524 return ResourceRequestBlockedReasonOrigin; |
525 } | 525 } |
526 break; | 526 break; |
527 } | 527 } |
528 | 528 |
529 if (contentSecurityPolicyBlocksRequest(type, resourceRequest, url, options,
forPreload, redirectStatus)) | 529 // FIXME: Convert this to check the isolated world's Content Security Policy
once webkit.org/b/104520 is solved. |
530 return ResourceRequestBlockedReasonCSP; | 530 bool shouldBypassMainWorldCSP = frame()->script().shouldBypassMainWorldCSP()
|| options.contentSecurityPolicyOption == DoNotCheckContentSecurityPolicy; |
| 531 |
| 532 // Don't send CSP messages for preloads, we might never actually display tho
se items. |
| 533 ContentSecurityPolicy::ReportingStatus cspReporting = forPreload ? |
| 534 ContentSecurityPolicy::SuppressReport : ContentSecurityPolicy::SendRepor
t; |
| 535 |
| 536 if (m_document) { |
| 537 DCHECK(m_document->contentSecurityPolicy()); |
| 538 if (!shouldBypassMainWorldCSP && !m_document->contentSecurityPolicy()->a
llowRequest(resourceRequest.requestContext(), url, options.contentSecurityPolicy
Nonce, redirectStatus, cspReporting)) |
| 539 return ResourceRequestBlockedReasonCSP; |
| 540 } |
531 | 541 |
532 if (type == Resource::Script || type == Resource::ImportResource) { | 542 if (type == Resource::Script || type == Resource::ImportResource) { |
533 ASSERT(frame()); | 543 ASSERT(frame()); |
534 if (!frame()->loader().client()->allowScriptFromSource(!frame()->setting
s() || frame()->settings()->scriptEnabled(), url)) { | 544 if (!frame()->loader().client()->allowScriptFromSource(!frame()->setting
s() || frame()->settings()->scriptEnabled(), url)) { |
535 frame()->loader().client()->didNotAllowScript(); | 545 frame()->loader().client()->didNotAllowScript(); |
536 // TODO(estark): Use a different ResourceRequestBlockedReason | 546 // TODO(estark): Use a different ResourceRequestBlockedReason |
537 // here, since this check has nothing to do with | 547 // here, since this check has nothing to do with |
538 // CSP. https://crbug.com/600795 | 548 // CSP. https://crbug.com/600795 |
539 return ResourceRequestBlockedReasonCSP; | 549 return ResourceRequestBlockedReasonCSP; |
540 } | 550 } |
(...skipping 28 matching lines...) Expand all Loading... |
569 return ResourceRequestBlockedReasonMixedContent; | 579 return ResourceRequestBlockedReasonMixedContent; |
570 | 580 |
571 // Let the client have the final say into whether or not the load should pro
ceed. | 581 // Let the client have the final say into whether or not the load should pro
ceed. |
572 DocumentLoader* documentLoader = masterDocumentLoader(); | 582 DocumentLoader* documentLoader = masterDocumentLoader(); |
573 if (documentLoader && documentLoader->subresourceFilter() && type != Resourc
e::MainResource && type != Resource::ImportResource && !documentLoader->subresou
rceFilter()->allowLoad(url, resourceRequest.requestContext())) | 583 if (documentLoader && documentLoader->subresourceFilter() && type != Resourc
e::MainResource && type != Resource::ImportResource && !documentLoader->subresou
rceFilter()->allowLoad(url, resourceRequest.requestContext())) |
574 return ResourceRequestBlockedReasonSubresourceFilter; | 584 return ResourceRequestBlockedReasonSubresourceFilter; |
575 | 585 |
576 return ResourceRequestBlockedReasonNone; | 586 return ResourceRequestBlockedReasonNone; |
577 } | 587 } |
578 | 588 |
579 bool FrameFetchContext::contentSecurityPolicyBlocksRequest(Resource::Type type,
const ResourceRequest& resourceRequest, const KURL& url, const ResourceLoaderOpt
ions& options, bool forPreload, ResourceRequest::RedirectStatus redirectStatus)
const | |
580 { | |
581 // FIXME: Convert this to check the isolated world's Content Security Policy
once webkit.org/b/104520 is solved. | |
582 if (!frame()->script().shouldBypassMainWorldCSP() && options.contentSecurity
PolicyOption == CheckContentSecurityPolicy) { | |
583 // Don't send CSP messages for preloads, we might never actually display
those items. | |
584 ContentSecurityPolicy::ReportingStatus cspReporting = forPreload ? Conte
ntSecurityPolicy::SuppressReport : ContentSecurityPolicy::SendReport; | |
585 if (m_document) { | |
586 DCHECK(m_document->contentSecurityPolicy()); | |
587 if (!m_document->contentSecurityPolicy()->allowRequest(resourceReque
st.requestContext(), url, options.contentSecurityPolicyNonce, redirectStatus, cs
pReporting)) | |
588 return true; | |
589 } else if (type == Resource::MainResource) { | |
590 // When loading the main document of an iframe, we won't have a docu
ment | |
591 // yet. We instead need to grab the frame's parent's policy in order
to | |
592 // perform 'frame-src' checks: | |
593 if (Frame* parentFrame = frame()->tree().parent()) { | |
594 if (!parentFrame->securityContext()->contentSecurityPolicy()->al
lowChildFrameFromSource(url, redirectStatus, cspReporting)) { | |
595 // TODO(mkwst): If we cancel the request after a redirect, w
e never instantiate | |
596 // a document, and therefore don't inherit the loader's sand
box flags, or trigger | |
597 // a load event. This is strange. | |
598 if (redirectStatus == ResourceRequest::RedirectStatus::Follo
wedRedirect) { | |
599 frame()->document()->enforceSandboxFlags(SandboxOrigin); | |
600 frame()->owner()->dispatchLoad(); | |
601 } | |
602 return true; | |
603 } | |
604 } | |
605 } | |
606 } | |
607 return false; | |
608 } | |
609 | |
610 bool FrameFetchContext::isControlledByServiceWorker() const | 589 bool FrameFetchContext::isControlledByServiceWorker() const |
611 { | 590 { |
612 ASSERT(m_documentLoader || frame()->loader().documentLoader()); | 591 ASSERT(m_documentLoader || frame()->loader().documentLoader()); |
613 if (m_documentLoader) | 592 if (m_documentLoader) |
614 return frame()->loader().client()->isControlledByServiceWorker(*m_docume
ntLoader); | 593 return frame()->loader().client()->isControlledByServiceWorker(*m_docume
ntLoader); |
615 // m_documentLoader is null while loading resources from an HTML import. | 594 // m_documentLoader is null while loading resources from an HTML import. |
616 // In such cases whether the request is controlled by ServiceWorker or not | 595 // In such cases whether the request is controlled by ServiceWorker or not |
617 // is determined by the document loader of the frame. | 596 // is determined by the document loader of the frame. |
618 return frame()->loader().client()->isControlledByServiceWorker(*frame()->loa
der().documentLoader()); | 597 return frame()->loader().client()->isControlledByServiceWorker(*frame()->loa
der().documentLoader()); |
619 } | 598 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 } | 773 } |
795 | 774 |
796 DEFINE_TRACE(FrameFetchContext) | 775 DEFINE_TRACE(FrameFetchContext) |
797 { | 776 { |
798 visitor->trace(m_document); | 777 visitor->trace(m_document); |
799 visitor->trace(m_documentLoader); | 778 visitor->trace(m_documentLoader); |
800 FetchContext::trace(visitor); | 779 FetchContext::trace(visitor); |
801 } | 780 } |
802 | 781 |
803 } // namespace blink | 782 } // namespace blink |
OLD | NEW |