| Index: content/common/content_security_policy/csp_directive.cc
|
| diff --git a/content/common/content_security_policy/csp_directive.cc b/content/common/content_security_policy/csp_directive.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c0e487400c4cbec5051af532a7f25a6d9417884e
|
| --- /dev/null
|
| +++ b/content/common/content_security_policy/csp_directive.cc
|
| @@ -0,0 +1,57 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <sstream>
|
| +
|
| +#include "content/common/content_security_policy/csp_directive.h"
|
| +
|
| +namespace content {
|
| +
|
| +CSPDirective::CSPDirective() = default;
|
| +CSPDirective::CSPDirective(Name name, const CSPSourceList& source_list)
|
| + : name(name), source_list(source_list) {}
|
| +CSPDirective::CSPDirective(const CSPDirective&) = default;
|
| +
|
| +std::string CSPDirective::ToString() const {
|
| + return NameToString(name) + " " + source_list.ToString();
|
| +}
|
| +
|
| +// static
|
| +std::string CSPDirective::NameToString(CSPDirective::Name name) {
|
| + switch (name) {
|
| + case DefaultSrc:
|
| + return "default-src";
|
| + case FrameAncestors:
|
| + return "frame-ancestors";
|
| + case ChildSrc:
|
| + return "child-src";
|
| + case FrameSrc:
|
| + return "frame-src";
|
| + case FormAction:
|
| + return "form-action";
|
| + case ReportURI:
|
| + return "report-uri";
|
| + case Unknown:
|
| + return "";
|
| + }
|
| +}
|
| +
|
| +// static
|
| +CSPDirective::Name CSPDirective::StringToName(const std::string& name) {
|
| + if (name == "default-src")
|
| + return CSPDirective::DefaultSrc;
|
| + if (name == "frame-ancestors")
|
| + return CSPDirective::FrameAncestors;
|
| + if (name == "child-src")
|
| + return CSPDirective::ChildSrc;
|
| + if (name == "frame-src")
|
| + return CSPDirective::FrameSrc;
|
| + if (name == "form-action")
|
| + return CSPDirective::FormAction;
|
| + if (name == "report-uri")
|
| + return CSPDirective::ReportURI;
|
| + return CSPDirective::Unknown;
|
| +}
|
| +
|
| +} // namespace content
|
|
|