Commit 61e4b831 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Replace use of std container with WTF's equivalent in third_party/blink/renderer/core/frame/csp/

This CL replaces the use of std::vector with WTF::Vector and
access a blink:WebVector member of struct directly in
third_party/blink/renderer/core/frame/csp/.

Bug: 952716
Change-Id: Ia94053b4f29b2637ef8a4a6fcac09306a96f05f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1661326Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#669959}
parent 8062b17f
...@@ -1615,14 +1615,11 @@ bool ContentSecurityPolicy::IsValidCSPAttr(const String& attr, ...@@ -1615,14 +1615,11 @@ bool ContentSecurityPolicy::IsValidCSPAttr(const String& attr,
WebContentSecurityPolicyList WebContentSecurityPolicyList
ContentSecurityPolicy::ExposeForNavigationalChecks() const { ContentSecurityPolicy::ExposeForNavigationalChecks() const {
std::vector<WebContentSecurityPolicy> policies; WebContentSecurityPolicyList list;
for (const auto& policy : policies_) { for (const auto& policy : policies_) {
policies.push_back(policy->ExposeForNavigationalChecks()); list.policies.emplace_back(policy->ExposeForNavigationalChecks());
} }
WebContentSecurityPolicyList list;
list.policies = policies;
if (self_source_) if (self_source_)
list.self_source = self_source_->ExposeForNavigationalChecks(); list.self_source = self_source_->ExposeForNavigationalChecks();
......
...@@ -1575,31 +1575,26 @@ WebContentSecurityPolicy CSPDirectiveList::ExposeForNavigationalChecks() const { ...@@ -1575,31 +1575,26 @@ WebContentSecurityPolicy CSPDirectiveList::ExposeForNavigationalChecks() const {
policy.disposition = policy.disposition =
static_cast<mojom::ContentSecurityPolicyType>(header_type_); static_cast<mojom::ContentSecurityPolicyType>(header_type_);
policy.source = static_cast<WebContentSecurityPolicySource>(header_source_); policy.source = static_cast<WebContentSecurityPolicySource>(header_source_);
std::vector<WebContentSecurityPolicyDirective> directives;
for (const auto& directive : for (const auto& directive :
{child_src_, default_src_, form_action_, frame_src_, navigate_to_}) { {child_src_, default_src_, form_action_, frame_src_, navigate_to_}) {
if (directive) { if (directive) {
directives.push_back(WebContentSecurityPolicyDirective{ policy.directives.emplace_back(WebContentSecurityPolicyDirective{
directive->DirectiveName(), directive->DirectiveName(),
directive->ExposeForNavigationalChecks()}); directive->ExposeForNavigationalChecks()});
} }
} }
if (upgrade_insecure_requests_) { if (upgrade_insecure_requests_) {
directives.push_back(WebContentSecurityPolicyDirective{ policy.directives.emplace_back(WebContentSecurityPolicyDirective{
blink::WebString("upgrade-insecure-requests"), blink::WebString("upgrade-insecure-requests"),
WebContentSecurityPolicySourceList()}); WebContentSecurityPolicySourceList()});
} }
policy.directives = directives;
std::vector<WebString> report_endpoints;
for (const auto& report_endpoint : ReportEndpoints()) { for (const auto& report_endpoint : ReportEndpoints()) {
report_endpoints.push_back(report_endpoint); policy.report_endpoints.emplace_back(report_endpoint);
} }
policy.use_reporting_api = use_reporting_api_; policy.use_reporting_api = use_reporting_api_;
policy.report_endpoints = report_endpoints;
policy.header = Header(); policy.header = Header();
return policy; return policy;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <list> #include <list>
#include <string> #include <string>
#include <vector>
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
...@@ -665,7 +664,7 @@ TEST_F(CSPDirectiveListTest, SubsumesBasedOnCSPSourcesOnly) { ...@@ -665,7 +664,7 @@ TEST_F(CSPDirectiveListTest, SubsumesBasedOnCSPSourcesOnly) {
kContentSecurityPolicyHeaderTypeEnforce); kContentSecurityPolicyHeaderTypeEnforce);
struct TestCase { struct TestCase {
const std::vector<const char*> policies; const Vector<const char*> policies;
bool expected; bool expected;
bool expected_first_policy_opposite; bool expected_first_policy_opposite;
} cases[] = { } cases[] = {
...@@ -743,7 +742,7 @@ TEST_F(CSPDirectiveListTest, SubsumesBasedOnCSPSourcesOnly) { ...@@ -743,7 +742,7 @@ TEST_F(CSPDirectiveListTest, SubsumesBasedOnCSPSourcesOnly) {
TEST_F(CSPDirectiveListTest, SubsumesIfNoneIsPresent) { TEST_F(CSPDirectiveListTest, SubsumesIfNoneIsPresent) {
struct TestCase { struct TestCase {
const char* policy_a; const char* policy_a;
const std::vector<const char*> policies_b; const Vector<const char*> policies_b;
bool expected; bool expected;
} cases[] = { } cases[] = {
// `policyA` subsumes any vector of policies. // `policyA` subsumes any vector of policies.
...@@ -844,7 +843,7 @@ TEST_F(CSPDirectiveListTest, SubsumesIfNoneIsPresent) { ...@@ -844,7 +843,7 @@ TEST_F(CSPDirectiveListTest, SubsumesIfNoneIsPresent) {
TEST_F(CSPDirectiveListTest, SubsumesPluginTypes) { TEST_F(CSPDirectiveListTest, SubsumesPluginTypes) {
struct TestCase { struct TestCase {
const char* policy_a; const char* policy_a;
const std::vector<const char*> policies_b; const Vector<const char*> policies_b;
bool expected; bool expected;
} cases[] = { } cases[] = {
// `policyA` subsumes `policiesB`. // `policyA` subsumes `policiesB`.
...@@ -926,7 +925,7 @@ TEST_F(CSPDirectiveListTest, SubsumesPluginTypes) { ...@@ -926,7 +925,7 @@ TEST_F(CSPDirectiveListTest, SubsumesPluginTypes) {
TEST_F(CSPDirectiveListTest, OperativeDirectiveGivenType) { TEST_F(CSPDirectiveListTest, OperativeDirectiveGivenType) {
struct TestCase { struct TestCase {
ContentSecurityPolicy::DirectiveType directive; ContentSecurityPolicy::DirectiveType directive;
std::vector<ContentSecurityPolicy::DirectiveType> fallback_list; Vector<ContentSecurityPolicy::DirectiveType> fallback_list;
} cases[] = { } cases[] = {
// Directives with default directive. // Directives with default directive.
{ContentSecurityPolicy::DirectiveType::kChildSrc, {ContentSecurityPolicy::DirectiveType::kChildSrc,
...@@ -986,12 +985,12 @@ TEST_F(CSPDirectiveListTest, OperativeDirectiveGivenType) { ...@@ -986,12 +985,12 @@ TEST_F(CSPDirectiveListTest, OperativeDirectiveGivenType) {
EXPECT_FALSE(empty->OperativeDirective(test.directive)); EXPECT_FALSE(empty->OperativeDirective(test.directive));
// Add the directive itself as it should be the first one to be returned. // Add the directive itself as it should be the first one to be returned.
test.fallback_list.insert(test.fallback_list.begin(), test.directive); test.fallback_list.push_front(test.directive);
// Start the tests with all directives present. // Start the tests with all directives present.
directive_string = all_directives.str(); directive_string = all_directives.str();
while (!test.fallback_list.empty()) { while (!test.fallback_list.IsEmpty()) {
directive_list = CreateList(directive_string.c_str(), directive_list = CreateList(directive_string.c_str(),
kContentSecurityPolicyHeaderTypeEnforce); kContentSecurityPolicyHeaderTypeEnforce);
...@@ -1032,7 +1031,7 @@ TEST_F(CSPDirectiveListTest, OperativeDirectiveGivenType) { ...@@ -1032,7 +1031,7 @@ TEST_F(CSPDirectiveListTest, OperativeDirectiveGivenType) {
} }
TEST_F(CSPDirectiveListTest, GetSourceVector) { TEST_F(CSPDirectiveListTest, GetSourceVector) {
const std::vector<const char*> policies = { const Vector<const char*> policies = {
// Policy 1 // Policy 1
"default-src https://default-src.com", "default-src https://default-src.com",
// Policy 2 // Policy 2
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h" #include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink { namespace blink {
...@@ -26,12 +27,12 @@ TEST_F(MediaListDirectiveTest, GetIntersect) { ...@@ -26,12 +27,12 @@ TEST_F(MediaListDirectiveTest, GetIntersect) {
struct TestCase { struct TestCase {
const char* policy_b; const char* policy_b;
const std::vector<const char*> expected; const Vector<const char*> expected;
} cases[] = { } cases[] = {
{"", std::vector<const char*>()}, {"", Vector<const char*>()},
{"text/", std::vector<const char*>()}, {"text/", Vector<const char*>()},
{"text/*", std::vector<const char*>()}, {"text/*", Vector<const char*>()},
{"*/plain", std::vector<const char*>()}, {"*/plain", Vector<const char*>()},
{"text/plain */plain", {"text/plain"}}, {"text/plain */plain", {"text/plain"}},
{"text/plain application/*", {"text/plain"}}, {"text/plain application/*", {"text/plain"}},
{"text/plain", {"text/plain"}}, {"text/plain", {"text/plain"}},
...@@ -73,7 +74,7 @@ TEST_F(MediaListDirectiveTest, Subsumes) { ...@@ -73,7 +74,7 @@ TEST_F(MediaListDirectiveTest, Subsumes) {
csp.Get()); csp.Get());
struct TestCase { struct TestCase {
const std::vector<const char*> policies_b; const Vector<const char*> policies_b;
bool subsumed; bool subsumed;
bool subsumed_by_empty_a; bool subsumed_by_empty_a;
} cases[] = { } cases[] = {
...@@ -119,7 +120,7 @@ TEST_F(MediaListDirectiveTest, Subsumes) { ...@@ -119,7 +120,7 @@ TEST_F(MediaListDirectiveTest, Subsumes) {
true, true,
true}, true},
// `A` does not subsumes `policiesB`. // `A` does not subsumes `policiesB`.
{std::vector<const char*>(), false, false}, {Vector<const char*>(), false, false},
{{"application/x-blink-test-plugin"}, false, false}, {{"application/x-blink-test-plugin"}, false, false},
{{"application/x-shockwave-flash text/plain " {{"application/x-shockwave-flash text/plain "
"application/x-blink-test-plugin"}, "application/x-blink-test-plugin"},
......
...@@ -353,7 +353,7 @@ TEST_F(SourceListDirectiveTest, Subsumes) { ...@@ -353,7 +353,7 @@ TEST_F(SourceListDirectiveTest, Subsumes) {
SourceListDirective required("script-src", required_sources, csp.Get()); SourceListDirective required("script-src", required_sources, csp.Get());
struct TestCase { struct TestCase {
std::vector<String> sources_vector; Vector<String> sources_vector;
bool expected; bool expected;
} cases[] = { } cases[] = {
// Non-intersecting source lists give an effective policy of 'none', which // Non-intersecting source lists give an effective policy of 'none', which
...@@ -436,7 +436,7 @@ TEST_F(SourceListDirectiveTest, SubsumesWithSelf) { ...@@ -436,7 +436,7 @@ TEST_F(SourceListDirectiveTest, SubsumesWithSelf) {
csp.Get()); csp.Get());
struct TestCase { struct TestCase {
std::vector<const char*> sources_b; Vector<const char*> sources_b;
const char* origin_b; const char* origin_b;
bool expected; bool expected;
} cases[] = { } cases[] = {
...@@ -607,7 +607,7 @@ TEST_F(SourceListDirectiveTest, SubsumesAllowAllInline) { ...@@ -607,7 +607,7 @@ TEST_F(SourceListDirectiveTest, SubsumesAllowAllInline) {
struct TestCase { struct TestCase {
bool is_script_src; bool is_script_src;
String sources_a; String sources_a;
std::vector<String> sources_b; Vector<String> sources_b;
bool expected; bool expected;
} cases[] = { } cases[] = {
// `sourcesA` allows all inline behavior. // `sourcesA` allows all inline behavior.
...@@ -716,7 +716,7 @@ TEST_F(SourceListDirectiveTest, SubsumesUnsafeAttributes) { ...@@ -716,7 +716,7 @@ TEST_F(SourceListDirectiveTest, SubsumesUnsafeAttributes) {
struct TestCase { struct TestCase {
bool is_script_src; bool is_script_src;
String sources_a; String sources_a;
std::vector<String> sources_b; Vector<String> sources_b;
bool expected; bool expected;
} cases[] = { } cases[] = {
// A or policiesB contain `unsafe-eval`. // A or policiesB contain `unsafe-eval`.
...@@ -920,7 +920,7 @@ TEST_F(SourceListDirectiveTest, SubsumesNoncesAndHashes) { ...@@ -920,7 +920,7 @@ TEST_F(SourceListDirectiveTest, SubsumesNoncesAndHashes) {
struct TestCase { struct TestCase {
bool is_script_src; bool is_script_src;
String sources_a; String sources_a;
std::vector<String> sources_b; Vector<String> sources_b;
bool expected; bool expected;
} cases[] = { } cases[] = {
// Check nonces. // Check nonces.
...@@ -1068,7 +1068,7 @@ TEST_F(SourceListDirectiveTest, SubsumesStrictDynamic) { ...@@ -1068,7 +1068,7 @@ TEST_F(SourceListDirectiveTest, SubsumesStrictDynamic) {
struct TestCase { struct TestCase {
bool is_script_src; bool is_script_src;
String sources_a; String sources_a;
std::vector<String> sources_b; Vector<String> sources_b;
bool expected; bool expected;
} cases[] = { } cases[] = {
// Neither A nor effective policy of list B has `strict-dynamic`. // Neither A nor effective policy of list B has `strict-dynamic`.
...@@ -1243,7 +1243,7 @@ TEST_F(SourceListDirectiveTest, SubsumesStrictDynamic) { ...@@ -1243,7 +1243,7 @@ TEST_F(SourceListDirectiveTest, SubsumesStrictDynamic) {
TEST_F(SourceListDirectiveTest, SubsumesListWildcard) { TEST_F(SourceListDirectiveTest, SubsumesListWildcard) {
struct TestCase { struct TestCase {
const char* sources_a; const char* sources_a;
std::vector<const char*> sources_b; Vector<const char*> sources_b;
bool expected; bool expected;
} cases[] = { } cases[] = {
// `A` subsumes `policiesB`.. // `A` subsumes `policiesB`..
...@@ -1274,7 +1274,7 @@ TEST_F(SourceListDirectiveTest, SubsumesListWildcard) { ...@@ -1274,7 +1274,7 @@ TEST_F(SourceListDirectiveTest, SubsumesListWildcard) {
{"*", "http://a.com ws://b.com ftp://c.com"}, {"*", "http://a.com ws://b.com ftp://c.com"},
true}, true},
// `A` does not subsume `policiesB`.. // `A` does not subsume `policiesB`..
{"*", std::vector<const char*>(), false}, {"*", Vector<const char*>(), false},
{"", {"*"}, false}, {"", {"*"}, false},
{"'none'", {"*"}, false}, {"'none'", {"*"}, false},
{"*", {"data:"}, false}, {"*", {"data:"}, false},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment