| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CSPSource_h | 5 #ifndef CSPSource_h |
| 6 #define CSPSource_h | 6 #define CSPSource_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/frame/csp/ContentSecurityPolicy.h" | 9 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 11 #include "platform/network/ResourceRequest.h" | 11 #include "platform/network/ResourceRequest.h" |
| 12 #include "public/platform/WebContentSecurityPolicyStruct.h" | 12 #include "public/platform/WebContentSecurityPolicyStruct.h" |
| 13 #include "wtf/Allocator.h" | 13 #include "wtf/Allocator.h" |
| 14 #include "wtf/text/WTFString.h" | 14 #include "wtf/text/WTFString.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 class ContentSecurityPolicy; | 18 class ContentSecurityPolicy; |
| 19 class KURL; | 19 class KURL; |
| 20 | 20 |
| 21 class CORE_EXPORT CSPSource : public GarbageCollectedFinalized<CSPSource> { | 21 class CORE_EXPORT CSPSource : public GarbageCollectedFinalized<CSPSource> { |
| 22 public: | 22 public: |
| 23 enum WildcardDisposition { NoWildcard, HasWildcard }; | 23 enum WildcardDisposition { NoWildcard, HasWildcard }; |
| 24 | 24 |
| 25 // NotMatching is the only negative member, the rest are different types of |
| 26 // matches. NotMatching should always be 0 to let if statements work nicely |
| 27 enum class PortMatchingResult { |
| 28 NotMatching, |
| 29 MatchingWildcard, |
| 30 MatchingUpgrade, |
| 31 MatchingExact |
| 32 }; |
| 33 |
| 34 enum class SchemeMatchingResult { |
| 35 NotMatching, |
| 36 MatchingUpgrade, |
| 37 MatchingExact |
| 38 }; |
| 39 |
| 25 CSPSource(ContentSecurityPolicy*, | 40 CSPSource(ContentSecurityPolicy*, |
| 26 const String& scheme, | 41 const String& scheme, |
| 27 const String& host, | 42 const String& host, |
| 28 int port, | 43 int port, |
| 29 const String& path, | 44 const String& path, |
| 30 WildcardDisposition hostWildcard, | 45 WildcardDisposition hostWildcard, |
| 31 WildcardDisposition portWildcard); | 46 WildcardDisposition portWildcard); |
| 32 bool isSchemeOnly() const; | 47 bool isSchemeOnly() const; |
| 33 const String& getScheme() { return m_scheme; }; | 48 const String& getScheme() { return m_scheme; }; |
| 34 bool matches(const KURL&, | 49 bool matches(const KURL&, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 56 FRIEND_TEST_ALL_PREFIXES(CSPSourceTest, Intersect); | 71 FRIEND_TEST_ALL_PREFIXES(CSPSourceTest, Intersect); |
| 57 FRIEND_TEST_ALL_PREFIXES(CSPSourceTest, IntersectSchemesOnly); | 72 FRIEND_TEST_ALL_PREFIXES(CSPSourceTest, IntersectSchemesOnly); |
| 58 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, GetIntersectCSPSources); | 73 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, GetIntersectCSPSources); |
| 59 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, | 74 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, |
| 60 GetIntersectCSPSourcesSchemes); | 75 GetIntersectCSPSourcesSchemes); |
| 61 FRIEND_TEST_ALL_PREFIXES(CSPDirectiveListTest, GetSourceVector); | 76 FRIEND_TEST_ALL_PREFIXES(CSPDirectiveListTest, GetSourceVector); |
| 62 FRIEND_TEST_ALL_PREFIXES(CSPDirectiveListTest, OperativeDirectiveGivenType); | 77 FRIEND_TEST_ALL_PREFIXES(CSPDirectiveListTest, OperativeDirectiveGivenType); |
| 63 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, SubsumesWithSelf); | 78 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, SubsumesWithSelf); |
| 64 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, GetSources); | 79 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, GetSources); |
| 65 | 80 |
| 66 bool schemeMatches(const String&) const; | 81 SchemeMatchingResult schemeMatches(const String&) const; |
| 67 bool hostMatches(const String&) const; | 82 bool hostMatches(const String&) const; |
| 68 bool pathMatches(const String&) const; | 83 bool pathMatches(const String&) const; |
| 69 // Protocol is necessary to determine default port if it is zero. | 84 // Protocol is necessary to determine default port if it is zero. |
| 70 bool portMatches(int port, const String& protocol) const; | 85 PortMatchingResult portMatches(int port, const String& protocol) const; |
| 71 bool isSimilar(CSPSource* other) const; | 86 bool isSimilar(CSPSource* other) const; |
| 72 | 87 |
| 88 // Helper inline functions for Port and Scheme MatchingResult enums |
| 89 bool inline requiresUpgrade(const PortMatchingResult result) const { |
| 90 return result == PortMatchingResult::MatchingUpgrade; |
| 91 } |
| 92 bool inline requiresUpgrade(const SchemeMatchingResult result) const { |
| 93 return result == SchemeMatchingResult::MatchingUpgrade; |
| 94 } |
| 95 |
| 96 bool inline canUpgrade(const PortMatchingResult result) const { |
| 97 return result == PortMatchingResult::MatchingUpgrade || result == PortMatchi
ngResult::MatchingWildcard; |
| 98 } |
| 99 |
| 100 bool inline canUpgrade(const SchemeMatchingResult result) const { |
| 101 return result == SchemeMatchingResult::MatchingUpgrade; |
| 102 } |
| 103 |
| 73 Member<ContentSecurityPolicy> m_policy; | 104 Member<ContentSecurityPolicy> m_policy; |
| 74 String m_scheme; | 105 String m_scheme; |
| 75 String m_host; | 106 String m_host; |
| 76 int m_port; | 107 int m_port; |
| 77 String m_path; | 108 String m_path; |
| 78 | 109 |
| 79 WildcardDisposition m_hostWildcard; | 110 WildcardDisposition m_hostWildcard; |
| 80 WildcardDisposition m_portWildcard; | 111 WildcardDisposition m_portWildcard; |
| 81 }; | 112 }; |
| 82 | 113 |
| 83 } // namespace blink | 114 } // namespace blink |
| 84 | 115 |
| 85 #endif | 116 #endif |
| OLD | NEW |