Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: Source/core/fetch/ResourceFetcher.cpp

Issue 353873003: Clean up usage of CSP functions (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix to apply Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/StyleElement.cpp ('k') | Source/core/frame/csp/ContentSecurityPolicy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 if (!securityOrigin && document()) 490 if (!securityOrigin && document())
491 securityOrigin = document()->securityOrigin(); 491 securityOrigin = document()->securityOrigin();
492 492
493 if (securityOrigin && !securityOrigin->canDisplay(url)) { 493 if (securityOrigin && !securityOrigin->canDisplay(url)) {
494 if (!forPreload) 494 if (!forPreload)
495 context().reportLocalLoadFailed(url); 495 context().reportLocalLoadFailed(url);
496 WTF_LOG(ResourceLoading, "ResourceFetcher::requestResource URL was not a llowed by SecurityOrigin::canDisplay"); 496 WTF_LOG(ResourceLoading, "ResourceFetcher::requestResource URL was not a llowed by SecurityOrigin::canDisplay");
497 return 0; 497 return 0;
498 } 498 }
499 499
500 // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
501 bool shouldBypassMainWorldContentSecurityPolicy = (frame() && frame()->scrip t().shouldBypassMainWorldContentSecurityPolicy()) || (options.contentSecurityPol icyOption == DoNotCheckContentSecurityPolicy);
502
503 // Some types of resources can be loaded only from the same origin. Other 500 // Some types of resources can be loaded only from the same origin. Other
504 // types of resources, like Images, Scripts, and CSS, can be loaded from 501 // types of resources, like Images, Scripts, and CSS, can be loaded from
505 // any URL. 502 // any URL.
506 switch (type) { 503 switch (type) {
507 case Resource::MainResource: 504 case Resource::MainResource:
508 case Resource::Image: 505 case Resource::Image:
509 case Resource::CSSStyleSheet: 506 case Resource::CSSStyleSheet:
510 case Resource::Script: 507 case Resource::Script:
511 case Resource::Font: 508 case Resource::Font:
512 case Resource::Raw: 509 case Resource::Raw:
(...skipping 12 matching lines...) Expand all
525 case Resource::XSLStyleSheet: 522 case Resource::XSLStyleSheet:
526 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); 523 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
527 case Resource::SVGDocument: 524 case Resource::SVGDocument:
528 if (!securityOrigin->canRequest(url)) { 525 if (!securityOrigin->canRequest(url)) {
529 printAccessDeniedMessage(url); 526 printAccessDeniedMessage(url);
530 return false; 527 return false;
531 } 528 }
532 break; 529 break;
533 } 530 }
534 531
532 // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
533 bool shouldBypassMainWorldCSP = (frame() && frame()->script().shouldBypassMa inWorldCSP()) || (options.contentSecurityPolicyOption == DoNotCheckContentSecuri tyPolicy);
534
535 // Don't send CSP messages for preloads, we might never actually display tho se items. 535 // Don't send CSP messages for preloads, we might never actually display tho se items.
536 ContentSecurityPolicy::ReportingStatus cspReporting = forPreload ? 536 ContentSecurityPolicy::ReportingStatus cspReporting = forPreload ?
537 ContentSecurityPolicy::SuppressReport : ContentSecurityPolicy::SendRepor t; 537 ContentSecurityPolicy::SuppressReport : ContentSecurityPolicy::SendRepor t;
538 538
539 // m_document can be null, but not in any of the cases where csp is actually used below.
540 // ImageResourceTest.MultipartImage crashes w/o the m_document null check.
541 // I believe it's the Resource::Raw case.
542 const ContentSecurityPolicy* csp = m_document ? m_document->contentSecurityP olicy() : nullptr;
543
544 // FIXME: This would be cleaner if moved this switch into an allowFromSource ()
545 // helper on this object which took a Resource::Type, then this block would
546 // collapse to about 10 lines for handling Raw and Script special cases.
539 switch (type) { 547 switch (type) {
540 case Resource::XSLStyleSheet: 548 case Resource::XSLStyleSheet:
541 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); 549 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
542 if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentS ecurityPolicy()->allowScriptFromSource(url, cspReporting)) 550 if (!shouldBypassMainWorldCSP && !csp->allowScriptFromSource(url, cspRep orting))
543 return false; 551 return false;
544 break; 552 break;
545 case Resource::Script: 553 case Resource::Script:
546 case Resource::ImportResource: 554 case Resource::ImportResource:
547 if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentS ecurityPolicy()->allowScriptFromSource(url, cspReporting)) 555 if (!shouldBypassMainWorldCSP && !csp->allowScriptFromSource(url, cspRep orting))
548 return false; 556 return false;
549 557
550 if (frame()) { 558 if (frame()) {
551 Settings* settings = frame()->settings(); 559 Settings* settings = frame()->settings();
552 if (!frame()->loader().client()->allowScriptFromSource(!settings || settings->scriptEnabled(), url)) { 560 if (!frame()->loader().client()->allowScriptFromSource(!settings || settings->scriptEnabled(), url)) {
553 frame()->loader().client()->didNotAllowScript(); 561 frame()->loader().client()->didNotAllowScript();
554 return false; 562 return false;
555 } 563 }
556 } 564 }
557 break; 565 break;
558 case Resource::CSSStyleSheet: 566 case Resource::CSSStyleSheet:
559 if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentS ecurityPolicy()->allowStyleFromSource(url, cspReporting)) 567 if (!shouldBypassMainWorldCSP && !csp->allowStyleFromSource(url, cspRepo rting))
560 return false; 568 return false;
561 break; 569 break;
562 case Resource::SVGDocument: 570 case Resource::SVGDocument:
563 case Resource::Image: 571 case Resource::Image:
564 if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentS ecurityPolicy()->allowImageFromSource(url, cspReporting)) 572 if (!shouldBypassMainWorldCSP && !csp->allowImageFromSource(url, cspRepo rting))
565 return false; 573 return false;
566 break; 574 break;
567 case Resource::Font: { 575 case Resource::Font: {
568 if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentS ecurityPolicy()->allowFontFromSource(url, cspReporting)) 576 if (!shouldBypassMainWorldCSP && !csp->allowFontFromSource(url, cspRepor ting))
569 return false; 577 return false;
570 break; 578 break;
571 } 579 }
572 case Resource::MainResource: 580 case Resource::MainResource:
573 case Resource::Raw: 581 case Resource::Raw:
574 case Resource::LinkPrefetch: 582 case Resource::LinkPrefetch:
575 case Resource::LinkSubresource: 583 case Resource::LinkSubresource:
576 break; 584 break;
577 case Resource::Media: 585 case Resource::Media:
578 case Resource::TextTrack: 586 case Resource::TextTrack:
579 if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentS ecurityPolicy()->allowMediaFromSource(url, cspReporting)) 587 if (!shouldBypassMainWorldCSP && !csp->allowMediaFromSource(url, cspRepo rting))
580 return false; 588 return false;
581 589
582 if (frame()) { 590 if (frame()) {
583 if (!frame()->loader().client()->allowMedia(url)) 591 if (!frame()->loader().client()->allowMedia(url))
584 return false; 592 return false;
585 } 593 }
586 break; 594 break;
587 } 595 }
588 596
589 // SVG Images have unique security rules that prevent all subresource reques ts 597 // SVG Images have unique security rules that prevent all subresource reques ts
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 } 1498 }
1491 } 1499 }
1492 1500
1493 void ResourceFetcher::trace(Visitor* visitor) 1501 void ResourceFetcher::trace(Visitor* visitor)
1494 { 1502 {
1495 visitor->trace(m_document); 1503 visitor->trace(m_document);
1496 ResourceLoaderHost::trace(visitor); 1504 ResourceLoaderHost::trace(visitor);
1497 } 1505 }
1498 1506
1499 } 1507 }
OLDNEW
« no previous file with comments | « Source/core/dom/StyleElement.cpp ('k') | Source/core/frame/csp/ContentSecurityPolicy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698