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

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

Issue 680393005: Cleanup a few loops into the new C++11 for-each style. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « Source/core/frame/SubresourceIntegrity.cpp ('k') | no next file » | 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) 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 { ContentSecurityPolicyHashAlgorithmSha384, HashAlgorithmSha384 }, 369 { ContentSecurityPolicyHashAlgorithmSha384, HashAlgorithmSha384 },
370 { ContentSecurityPolicyHashAlgorithmSha512, HashAlgorithmSha512 } 370 { ContentSecurityPolicyHashAlgorithmSha512, HashAlgorithmSha512 }
371 }; 371 };
372 372
373 // Only bother normalizing the source/computing digests if there are any che cks to be done. 373 // Only bother normalizing the source/computing digests if there are any che cks to be done.
374 if (hashAlgorithmsUsed == ContentSecurityPolicyHashAlgorithmNone) 374 if (hashAlgorithmsUsed == ContentSecurityPolicyHashAlgorithmNone)
375 return false; 375 return false;
376 376
377 StringUTF8Adaptor normalizedSource(source, StringUTF8Adaptor::Normalize, WTF ::EntitiesForUnencodables); 377 StringUTF8Adaptor normalizedSource(source, StringUTF8Adaptor::Normalize, WTF ::EntitiesForUnencodables);
378 378
379 // See comment in CSPSourceList::parseHash about why we are using this sizeo f 379 for (const auto& algorithmMap : kAlgorithmMap) {
380 // calculation instead of WTF_ARRAY_LENGTH.
381 for (size_t i = 0; i < (sizeof(kAlgorithmMap) / sizeof(kAlgorithmMap[0])); i ++) {
382 DigestValue digest; 380 DigestValue digest;
383 if (kAlgorithmMap[i].cspHashAlgorithm & hashAlgorithmsUsed) { 381 if (algorithmMap.cspHashAlgorithm & hashAlgorithmsUsed) {
384 bool digestSuccess = computeDigest(kAlgorithmMap[i].algorithm, norma lizedSource.data(), normalizedSource.length(), digest); 382 bool digestSuccess = computeDigest(algorithmMap.algorithm, normalize dSource.data(), normalizedSource.length(), digest);
385 if (digestSuccess && isAllowedByAllWithHash<allowed>(policies, CSPHa shValue(kAlgorithmMap[i].cspHashAlgorithm, digest))) 383 if (digestSuccess && isAllowedByAllWithHash<allowed>(policies, CSPHa shValue(algorithmMap.cspHashAlgorithm, digest)))
386 return true; 384 return true;
387 } 385 }
388 } 386 }
389 387
390 return false; 388 return false;
391 } 389 }
392 390
393 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportin gStatus) const 391 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportin gStatus) const
394 { 392 {
395 return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_p olicies, contextURL, contextLine, reportingStatus); 393 return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_p olicies, contextURL, contextLine, reportingStatus);
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report. 872 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report.
875 return !m_violationReportsSent.contains(report.impl()->hash()); 873 return !m_violationReportsSent.contains(report.impl()->hash());
876 } 874 }
877 875
878 void ContentSecurityPolicy::didSendViolationReport(const String& report) 876 void ContentSecurityPolicy::didSendViolationReport(const String& report)
879 { 877 {
880 m_violationReportsSent.add(report.impl()->hash()); 878 m_violationReportsSent.add(report.impl()->hash());
881 } 879 }
882 880
883 } // namespace blink 881 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/SubresourceIntegrity.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698