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

Side by Side Diff: Source/core/frame/csp/ContentSecurityPolicy.cpp

Issue 332993002: Replace ContentSecurityPolicy::client() with a method returning an ExecutionContext (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google, Inc. All rights reserved. 2 * Copyright (C) 2011 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 return UseCounter::NumberOfFeatures; 123 return UseCounter::NumberOfFeatures;
124 } 124 }
125 125
126 static ReferrerPolicy mergeReferrerPolicies(ReferrerPolicy a, ReferrerPolicy b) 126 static ReferrerPolicy mergeReferrerPolicies(ReferrerPolicy a, ReferrerPolicy b)
127 { 127 {
128 if (a != b) 128 if (a != b)
129 return ReferrerPolicyNever; 129 return ReferrerPolicyNever;
130 return a; 130 return a;
131 } 131 }
132 132
133 ContentSecurityPolicy::ContentSecurityPolicy(ExecutionContextClient* client) 133 ContentSecurityPolicy::ContentSecurityPolicy(ExecutionContext* executionContext)
134 : m_client(client) 134 : m_executionContext(executionContext)
135 , m_overrideInlineStyleAllowed(false) 135 , m_overrideInlineStyleAllowed(false)
136 , m_scriptHashAlgorithmsUsed(ContentSecurityPolicyHashAlgorithmNone) 136 , m_scriptHashAlgorithmsUsed(ContentSecurityPolicyHashAlgorithmNone)
137 , m_styleHashAlgorithmsUsed(ContentSecurityPolicyHashAlgorithmNone) 137 , m_styleHashAlgorithmsUsed(ContentSecurityPolicyHashAlgorithmNone)
138 { 138 {
139 } 139 }
140 140
141 ContentSecurityPolicy::~ContentSecurityPolicy() 141 ContentSecurityPolicy::~ContentSecurityPolicy()
142 { 142 {
143 } 143 }
144 144
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 const UChar* position = begin; 191 const UChar* position = begin;
192 while (position < end) { 192 while (position < end) {
193 skipUntil<UChar>(position, end, ','); 193 skipUntil<UChar>(position, end, ',');
194 194
195 // header1,header2 OR header1 195 // header1,header2 OR header1
196 // ^ ^ 196 // ^ ^
197 OwnPtr<CSPDirectiveList> policy = CSPDirectiveList::create(this, begin, position, type, source); 197 OwnPtr<CSPDirectiveList> policy = CSPDirectiveList::create(this, begin, position, type, source);
198 198
199 // We disable 'eval()' even in the case of report-only policies, and rel y on the check in the V8Initializer::codeGenerationCheckCallbackInMainThread cal lback to determine whether the call should execute or not. 199 // We disable 'eval()' even in the case of report-only policies, and rel y on the check in the V8Initializer::codeGenerationCheckCallbackInMainThread cal lback to determine whether the call should execute or not.
200 if (!policy->allowEval(0, SuppressReport)) 200 if (!policy->allowEval(0, SuppressReport))
201 m_client->disableEval(policy->evalDisabledErrorMessage()); 201 m_executionContext->disableEval(policy->evalDisabledErrorMessage());
202 202
203 m_policies.append(policy.release()); 203 m_policies.append(policy.release());
204 204
205 // Skip the comma, and begin the next header from the current position. 205 // Skip the comma, and begin the next header from the current position.
206 ASSERT(position == end || *position == ','); 206 ASSERT(position == end || *position == ',');
207 skipExactly<UChar>(position, end, ','); 207 skipExactly<UChar>(position, end, ',');
208 begin = position; 208 begin = position;
209 } 209 }
210 210
211 if (document && type != ContentSecurityPolicyHeaderTypeReport && didSetRefer rerPolicy()) 211 if (document && type != ContentSecurityPolicyHeaderTypeReport && didSetRefer rerPolicy())
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 467 }
468 468
469 bool ContentSecurityPolicy::allowChildContextFromSource(const KURL& url, Content SecurityPolicy::ReportingStatus reportingStatus) const 469 bool ContentSecurityPolicy::allowChildContextFromSource(const KURL& url, Content SecurityPolicy::ReportingStatus reportingStatus) const
470 { 470 {
471 return isAllowedByAllWithURL<&CSPDirectiveList::allowChildContextFromSource> (m_policies, url, reportingStatus); 471 return isAllowedByAllWithURL<&CSPDirectiveList::allowChildContextFromSource> (m_policies, url, reportingStatus);
472 } 472 }
473 473
474 bool ContentSecurityPolicy::allowWorkerContextFromSource(const KURL& url, Conten tSecurityPolicy::ReportingStatus reportingStatus) const 474 bool ContentSecurityPolicy::allowWorkerContextFromSource(const KURL& url, Conten tSecurityPolicy::ReportingStatus reportingStatus) const
475 { 475 {
476 // CSP 1.1 moves workers from 'script-src' to the new 'child-src'. Measure t he impact of this backwards-incompatible change. 476 // CSP 1.1 moves workers from 'script-src' to the new 'child-src'. Measure t he impact of this backwards-incompatible change.
477 if (m_client->isDocument()) { 477 if (m_executionContext->isDocument()) {
478 Document* document = static_cast<Document*>(m_client); 478 Document* document = static_cast<Document*>(m_executionContext);
479 UseCounter::count(*document, UseCounter::WorkerSubjectToCSP); 479 UseCounter::count(*document, UseCounter::WorkerSubjectToCSP);
480 if (isAllowedByAllWithURL<&CSPDirectiveList::allowChildContextFromSource >(m_policies, url, SuppressReport) && !isAllowedByAllWithURL<&CSPDirectiveList:: allowScriptFromSource>(m_policies, url, SuppressReport)) 480 if (isAllowedByAllWithURL<&CSPDirectiveList::allowChildContextFromSource >(m_policies, url, SuppressReport) && !isAllowedByAllWithURL<&CSPDirectiveList:: allowScriptFromSource>(m_policies, url, SuppressReport))
481 UseCounter::count(*document, UseCounter::WorkerAllowedByChildBlocked ByScript); 481 UseCounter::count(*document, UseCounter::WorkerAllowedByChildBlocked ByScript);
482 } 482 }
483 483
484 return experimentalFeaturesEnabled() ? 484 return experimentalFeaturesEnabled() ?
485 isAllowedByAllWithURL<&CSPDirectiveList::allowChildContextFromSource>(m_ policies, url, reportingStatus) : 485 isAllowedByAllWithURL<&CSPDirectiveList::allowChildContextFromSource>(m_ policies, url, reportingStatus) :
486 isAllowedByAllWithURL<&CSPDirectiveList::allowScriptFromSource>(m_polici es, url, reportingStatus); 486 isAllowedByAllWithURL<&CSPDirectiveList::allowScriptFromSource>(m_polici es, url, reportingStatus);
487 } 487 }
488 488
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 { 520 {
521 for (size_t i = 0; i < m_policies.size(); ++i) { 521 for (size_t i = 0; i < m_policies.size(); ++i) {
522 if (m_policies[i]->didSetReferrerPolicy()) 522 if (m_policies[i]->didSetReferrerPolicy())
523 return true; 523 return true;
524 } 524 }
525 return false; 525 return false;
526 } 526 }
527 527
528 SecurityOrigin* ContentSecurityPolicy::securityOrigin() const 528 SecurityOrigin* ContentSecurityPolicy::securityOrigin() const
529 { 529 {
530 return m_client->securityContext().securityOrigin(); 530 return m_executionContext->securityContext().securityOrigin();
531 } 531 }
532 532
533 const KURL ContentSecurityPolicy::url() const 533 const KURL ContentSecurityPolicy::url() const
534 { 534 {
535 return m_client->contextURL(); 535 return m_executionContext->contextURL();
536 } 536 }
537 537
538 KURL ContentSecurityPolicy::completeURL(const String& url) const 538 KURL ContentSecurityPolicy::completeURL(const String& url) const
539 { 539 {
540 return m_client->contextCompleteURL(url); 540 return m_executionContext->contextCompleteURL(url);
541 } 541 }
542 542
543 void ContentSecurityPolicy::enforceSandboxFlags(SandboxFlags mask) const 543 void ContentSecurityPolicy::enforceSandboxFlags(SandboxFlags mask) const
544 { 544 {
545 if (Document* document = this->document()) 545 if (Document* document = this->document())
546 document->enforceSandboxFlags(mask); 546 document->enforceSandboxFlags(mask);
547 } 547 }
548 548
549 static String stripURLForUseInReport(Document* document, const KURL& url) 549 static String stripURLForUseInReport(Document* document, const KURL& url)
550 { 550 {
(...skipping 30 matching lines...) Expand all
581 KURL source = KURL(ParsedURLString, callFrame.sourceURL()); 581 KURL source = KURL(ParsedURLString, callFrame.sourceURL());
582 init.sourceFile = stripURLForUseInReport(document, source); 582 init.sourceFile = stripURLForUseInReport(document, source);
583 init.lineNumber = callFrame.lineNumber(); 583 init.lineNumber = callFrame.lineNumber();
584 init.columnNumber = callFrame.columnNumber(); 584 init.columnNumber = callFrame.columnNumber();
585 } 585 }
586 } 586 }
587 587
588 void ContentSecurityPolicy::reportViolation(const String& directiveText, const S tring& effectiveDirective, const String& consoleMessage, const KURL& blockedURL, const Vector<KURL>& reportURIs, const String& header) 588 void ContentSecurityPolicy::reportViolation(const String& directiveText, const S tring& effectiveDirective, const String& consoleMessage, const KURL& blockedURL, const Vector<KURL>& reportURIs, const String& header)
589 { 589 {
590 // FIXME: Support sending reports from worker. 590 // FIXME: Support sending reports from worker.
591 if (!m_client->isDocument()) 591 if (!m_executionContext->isDocument())
592 return; 592 return;
593 593
594 Document* document = this->document(); 594 Document* document = this->document();
595 LocalFrame* frame = document->frame(); 595 LocalFrame* frame = document->frame();
596 if (!frame) 596 if (!frame)
597 return; 597 return;
598 598
599 SecurityPolicyViolationEventInit violationData; 599 SecurityPolicyViolationEventInit violationData;
600 gatherSecurityPolicyViolationEventData(violationData, document, directiveTex t, effectiveDirective, blockedURL, header); 600 gatherSecurityPolicyViolationEventData(violationData, document, directiveTex t, effectiveDirective, blockedURL, header);
601 601
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 logToConsole(message); 742 logToConsole(message);
743 } 743 }
744 744
745 void ContentSecurityPolicy::reportMissingReportURI(const String& policy) const 745 void ContentSecurityPolicy::reportMissingReportURI(const String& policy) const
746 { 746 {
747 logToConsole("The Content Security Policy '" + policy + "' was delivered in report-only mode, but does not specify a 'report-uri'; the policy will have no e ffect. Please either add a 'report-uri' directive, or deliver the policy via the 'Content-Security-Policy' header."); 747 logToConsole("The Content Security Policy '" + policy + "' was delivered in report-only mode, but does not specify a 'report-uri'; the policy will have no e ffect. Please either add a 'report-uri' directive, or deliver the policy via the 'Content-Security-Policy' header.");
748 } 748 }
749 749
750 void ContentSecurityPolicy::logToConsole(const String& message) const 750 void ContentSecurityPolicy::logToConsole(const String& message) const
751 { 751 {
752 m_client->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, messag e); 752 m_executionContext->addConsoleMessage(SecurityMessageSource, ErrorMessageLev el, message);
753 } 753 }
754 754
755 void ContentSecurityPolicy::reportBlockedScriptExecutionToInspector(const String & directiveText) const 755 void ContentSecurityPolicy::reportBlockedScriptExecutionToInspector(const String & directiveText) const
756 { 756 {
757 m_client->reportBlockedScriptExecutionToInspector(directiveText); 757 m_executionContext->reportBlockedScriptExecutionToInspector(directiveText);
758 } 758 }
759 759
760 bool ContentSecurityPolicy::experimentalFeaturesEnabled() const 760 bool ContentSecurityPolicy::experimentalFeaturesEnabled() const
761 { 761 {
762 return RuntimeEnabledFeatures::experimentalContentSecurityPolicyFeaturesEnab led(); 762 return RuntimeEnabledFeatures::experimentalContentSecurityPolicyFeaturesEnab led();
763 } 763 }
764 764
765 bool ContentSecurityPolicy::shouldBypassMainWorld(ExecutionContext* context) 765 bool ContentSecurityPolicy::shouldBypassMainWorld(ExecutionContext* context)
766 { 766 {
767 if (context && context->isDocument()) { 767 if (context && context->isDocument()) {
768 Document* document = toDocument(context); 768 Document* document = toDocument(context);
769 if (document->frame()) 769 if (document->frame())
770 return document->frame()->script().shouldBypassMainWorldContentSecur ityPolicy(); 770 return document->frame()->script().shouldBypassMainWorldContentSecur ityPolicy();
771 } 771 }
772 return false; 772 return false;
773 } 773 }
774 774
775 bool ContentSecurityPolicy::shouldSendViolationReport(const String& report) cons t 775 bool ContentSecurityPolicy::shouldSendViolationReport(const String& report) cons t
776 { 776 {
777 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report. 777 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report.
778 return !m_violationReportsSent.contains(report.impl()->hash()); 778 return !m_violationReportsSent.contains(report.impl()->hash());
779 } 779 }
780 780
781 void ContentSecurityPolicy::didSendViolationReport(const String& report) 781 void ContentSecurityPolicy::didSendViolationReport(const String& report)
782 { 782 {
783 m_violationReportsSent.add(report.impl()->hash()); 783 m_violationReportsSent.add(report.impl()->hash());
784 } 784 }
785 785
786 } // namespace WebCore 786 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698