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/renderer/content_security_policy_util.h" |
| 6 #include "third_party/WebKit/public/platform/WebContentSecurityPolicyStruct.h" |
| 7 |
| 8 namespace content { |
| 9 |
| 10 CSPSource BuildCSPSource( |
| 11 const blink::WebContentSecurityPolicySourceExpression& source) { |
| 12 return CSPSource( |
| 13 source.scheme.utf8(), // scheme |
| 14 source.host.utf8(), // host |
| 15 source.isHostWildcard == blink::WebWildcardDispositionHasWildcard, |
| 16 source.port == 0 ? url::PORT_UNSPECIFIED : source.port, // port |
| 17 source.isPortWildcard == blink::WebWildcardDispositionHasWildcard, |
| 18 source.path.utf8()); // path |
| 19 } |
| 20 |
| 21 CSPSourceList BuildCSPSourceList( |
| 22 const blink::WebContentSecurityPolicySourceList& source_list) { |
| 23 std::vector<CSPSource> sources; |
| 24 for (const auto& source : source_list.sources) { |
| 25 sources.push_back(BuildCSPSource(source)); |
| 26 } |
| 27 |
| 28 return CSPSourceList(source_list.allowSelf, // allow_self |
| 29 source_list.allowStar, // allow_star |
| 30 sources); // source_list |
| 31 } |
| 32 |
| 33 CSPDirective BuildCSPDirective( |
| 34 const blink::WebContentSecurityPolicyDirective& directive) { |
| 35 return CSPDirective( |
| 36 CSPDirective::StringToName(directive.name.utf8()), // name |
| 37 BuildCSPSourceList(directive.sourceList)); // source_list |
| 38 } |
| 39 |
| 40 ContentSecurityPolicy BuildContentSecurityPolicy( |
| 41 const blink::WebContentSecurityPolicyPolicy& policy) { |
| 42 std::vector<CSPDirective> directives; |
| 43 for (const auto& directive : policy.directives) |
| 44 directives.push_back(BuildCSPDirective(directive)); |
| 45 |
| 46 std::vector<std::string> report_endpoints; |
| 47 for (const blink::WebString& endpoint : policy.reportEndpoints) |
| 48 report_endpoints.push_back(endpoint.utf8()); |
| 49 |
| 50 return ContentSecurityPolicy(policy.disposition, // disposition |
| 51 policy.source, // source |
| 52 directives, // directives |
| 53 report_endpoints, // report_endpoints |
| 54 policy.header.utf8()); // header |
| 55 } |
| 56 |
| 57 } // namespace content |
OLD | NEW |