OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/content_security_policy/csp_directive.h" |
| 6 |
| 7 namespace content { |
| 8 |
| 9 CSPDirective::CSPDirective() = default; |
| 10 |
| 11 CSPDirective::CSPDirective(Name name, const CSPSourceList& source_list) |
| 12 : name(name), source_list(source_list) {} |
| 13 |
| 14 CSPDirective::CSPDirective(const CSPDirective&) = default; |
| 15 |
| 16 std::string CSPDirective::ToString() const { |
| 17 return NameToString(name) + " " + source_list.ToString(); |
| 18 } |
| 19 |
| 20 // static |
| 21 std::string CSPDirective::NameToString(CSPDirective::Name name) { |
| 22 switch (name) { |
| 23 case DefaultSrc: |
| 24 return "default-src"; |
| 25 case ChildSrc: |
| 26 return "child-src"; |
| 27 case FrameSrc: |
| 28 return "frame-src"; |
| 29 case FormAction: |
| 30 return "form-action"; |
| 31 case Unknown: |
| 32 return ""; |
| 33 } |
| 34 NOTREACHED(); |
| 35 return ""; |
| 36 } |
| 37 |
| 38 // static |
| 39 CSPDirective::Name CSPDirective::StringToName(const std::string& name) { |
| 40 if (name == "default-src") |
| 41 return CSPDirective::DefaultSrc; |
| 42 if (name == "child-src") |
| 43 return CSPDirective::ChildSrc; |
| 44 if (name == "frame-src") |
| 45 return CSPDirective::FrameSrc; |
| 46 if (name == "form-action") |
| 47 return CSPDirective::FormAction; |
| 48 return CSPDirective::Unknown; |
| 49 } |
| 50 |
| 51 } // namespace content |
OLD | NEW |