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,
WebContentSecurityPolicyList
ContentSecurityPolicy::ExposeForNavigationalChecks() const {
std::vector<WebContentSecurityPolicy> policies;
WebContentSecurityPolicyList list;
for (const auto& policy : policies_) {
policies.push_back(policy->ExposeForNavigationalChecks());
list.policies.emplace_back(policy->ExposeForNavigationalChecks());
}
WebContentSecurityPolicyList list;
list.policies = policies;
if (self_source_)
list.self_source = self_source_->ExposeForNavigationalChecks();
......
......@@ -1575,31 +1575,26 @@ WebContentSecurityPolicy CSPDirectiveList::ExposeForNavigationalChecks() const {
policy.disposition =
static_cast<mojom::ContentSecurityPolicyType>(header_type_);
policy.source = static_cast<WebContentSecurityPolicySource>(header_source_);
std::vector<WebContentSecurityPolicyDirective> directives;
for (const auto& directive :
{child_src_, default_src_, form_action_, frame_src_, navigate_to_}) {
if (directive) {
directives.push_back(WebContentSecurityPolicyDirective{
policy.directives.emplace_back(WebContentSecurityPolicyDirective{
directive->DirectiveName(),
directive->ExposeForNavigationalChecks()});
}
}
if (upgrade_insecure_requests_) {
directives.push_back(WebContentSecurityPolicyDirective{
policy.directives.emplace_back(WebContentSecurityPolicyDirective{
blink::WebString("upgrade-insecure-requests"),
WebContentSecurityPolicySourceList()});
}
policy.directives = directives;
std::vector<WebString> report_endpoints;
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.report_endpoints = report_endpoints;
policy.header = Header();
return policy;
......
......@@ -6,7 +6,6 @@
#include <list>
#include <string>
#include <vector>
#include "base/test/scoped_feature_list.h"
#include "services/network/public/cpp/features.h"
......@@ -665,7 +664,7 @@ TEST_F(CSPDirectiveListTest, SubsumesBasedOnCSPSourcesOnly) {
kContentSecurityPolicyHeaderTypeEnforce);
struct TestCase {
const std::vector<const char*> policies;
const Vector<const char*> policies;
bool expected;
bool expected_first_policy_opposite;
} cases[] = {
......@@ -743,7 +742,7 @@ TEST_F(CSPDirectiveListTest, SubsumesBasedOnCSPSourcesOnly) {
TEST_F(CSPDirectiveListTest, SubsumesIfNoneIsPresent) {
struct TestCase {
const char* policy_a;
const std::vector<const char*> policies_b;
const Vector<const char*> policies_b;
bool expected;
} cases[] = {
// `policyA` subsumes any vector of policies.
......@@ -844,7 +843,7 @@ TEST_F(CSPDirectiveListTest, SubsumesIfNoneIsPresent) {
TEST_F(CSPDirectiveListTest, SubsumesPluginTypes) {
struct TestCase {
const char* policy_a;
const std::vector<const char*> policies_b;
const Vector<const char*> policies_b;
bool expected;
} cases[] = {
// `policyA` subsumes `policiesB`.
......@@ -926,7 +925,7 @@ TEST_F(CSPDirectiveListTest, SubsumesPluginTypes) {
TEST_F(CSPDirectiveListTest, OperativeDirectiveGivenType) {
struct TestCase {
ContentSecurityPolicy::DirectiveType directive;
std::vector<ContentSecurityPolicy::DirectiveType> fallback_list;
Vector<ContentSecurityPolicy::DirectiveType> fallback_list;
} cases[] = {
// Directives with default directive.
{ContentSecurityPolicy::DirectiveType::kChildSrc,
......@@ -986,12 +985,12 @@ TEST_F(CSPDirectiveListTest, OperativeDirectiveGivenType) {
EXPECT_FALSE(empty->OperativeDirective(test.directive));
// 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.
directive_string = all_directives.str();
while (!test.fallback_list.empty()) {
while (!test.fallback_list.IsEmpty()) {
directive_list = CreateList(directive_string.c_str(),
kContentSecurityPolicyHeaderTypeEnforce);
......@@ -1032,7 +1031,7 @@ TEST_F(CSPDirectiveListTest, OperativeDirectiveGivenType) {
}
TEST_F(CSPDirectiveListTest, GetSourceVector) {
const std::vector<const char*> policies = {
const Vector<const char*> policies = {
// Policy 1
"default-src https://default-src.com",
// Policy 2
......
......@@ -6,6 +6,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
......@@ -26,12 +27,12 @@ TEST_F(MediaListDirectiveTest, GetIntersect) {
struct TestCase {
const char* policy_b;
const std::vector<const char*> expected;
const Vector<const char*> expected;
} cases[] = {
{"", std::vector<const char*>()},
{"text/", std::vector<const char*>()},
{"text/*", std::vector<const char*>()},
{"*/plain", std::vector<const char*>()},
{"", Vector<const char*>()},
{"text/", Vector<const char*>()},
{"text/*", Vector<const char*>()},
{"*/plain", Vector<const char*>()},
{"text/plain */plain", {"text/plain"}},
{"text/plain application/*", {"text/plain"}},
{"text/plain", {"text/plain"}},
......@@ -73,7 +74,7 @@ TEST_F(MediaListDirectiveTest, Subsumes) {
csp.Get());
struct TestCase {
const std::vector<const char*> policies_b;
const Vector<const char*> policies_b;
bool subsumed;
bool subsumed_by_empty_a;
} cases[] = {
......@@ -119,7 +120,7 @@ TEST_F(MediaListDirectiveTest, Subsumes) {
true,
true},
// `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-shockwave-flash text/plain "
"application/x-blink-test-plugin"},
......
......@@ -353,7 +353,7 @@ TEST_F(SourceListDirectiveTest, Subsumes) {
SourceListDirective required("script-src", required_sources, csp.Get());
struct TestCase {
std::vector<String> sources_vector;
Vector<String> sources_vector;
bool expected;
} cases[] = {
// Non-intersecting source lists give an effective policy of 'none', which
......@@ -436,7 +436,7 @@ TEST_F(SourceListDirectiveTest, SubsumesWithSelf) {
csp.Get());
struct TestCase {
std::vector<const char*> sources_b;
Vector<const char*> sources_b;
const char* origin_b;
bool expected;
} cases[] = {
......@@ -607,7 +607,7 @@ TEST_F(SourceListDirectiveTest, SubsumesAllowAllInline) {
struct TestCase {
bool is_script_src;
String sources_a;
std::vector<String> sources_b;
Vector<String> sources_b;
bool expected;
} cases[] = {
// `sourcesA` allows all inline behavior.
......@@ -716,7 +716,7 @@ TEST_F(SourceListDirectiveTest, SubsumesUnsafeAttributes) {
struct TestCase {
bool is_script_src;
String sources_a;
std::vector<String> sources_b;
Vector<String> sources_b;
bool expected;
} cases[] = {
// A or policiesB contain `unsafe-eval`.
......@@ -920,7 +920,7 @@ TEST_F(SourceListDirectiveTest, SubsumesNoncesAndHashes) {
struct TestCase {
bool is_script_src;
String sources_a;
std::vector<String> sources_b;
Vector<String> sources_b;
bool expected;
} cases[] = {
// Check nonces.
......@@ -1068,7 +1068,7 @@ TEST_F(SourceListDirectiveTest, SubsumesStrictDynamic) {
struct TestCase {
bool is_script_src;
String sources_a;
std::vector<String> sources_b;
Vector<String> sources_b;
bool expected;
} cases[] = {
// Neither A nor effective policy of list B has `strict-dynamic`.
......@@ -1243,7 +1243,7 @@ TEST_F(SourceListDirectiveTest, SubsumesStrictDynamic) {
TEST_F(SourceListDirectiveTest, SubsumesListWildcard) {
struct TestCase {
const char* sources_a;
std::vector<const char*> sources_b;
Vector<const char*> sources_b;
bool expected;
} cases[] = {
// `A` subsumes `policiesB`..
......@@ -1274,7 +1274,7 @@ TEST_F(SourceListDirectiveTest, SubsumesListWildcard) {
{"*", "http://a.com ws://b.com ftp://c.com"},
true},
// `A` does not subsume `policiesB`..
{"*", std::vector<const char*>(), false},
{"*", Vector<const char*>(), false},
{"", {"*"}, false},
{"'none'", {"*"}, 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