Chromium Code Reviews| 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 | |
|
Mike West
2017/02/24 10:56:28
Nit: Did you consider making this an `enum class`
andypaicu
2017/03/13 10:07:20
I have no strong feelings one way or the other
htt
| |
| 27 enum PortMatchingResult { | |
| 28 PortNotMatching = 0, | |
| 29 PortMatchingWildcard, | |
| 30 PortMatchingUpgrade, | |
| 31 PortMatchingExact | |
| 32 }; | |
|
Mike West
2017/02/24 10:56:28
Tiny nit: Newline after the enum.
andypaicu
2017/03/13 10:07:20
Done.
| |
| 33 enum SchemeMatchingResult { | |
| 34 SchemeNotMatching = 0, | |
| 35 SchemeMatchingUpgrade, | |
| 36 SchemeMatchingExact | |
| 37 }; | |
| 38 | |
| 25 CSPSource(ContentSecurityPolicy*, | 39 CSPSource(ContentSecurityPolicy*, |
| 26 const String& scheme, | 40 const String& scheme, |
| 27 const String& host, | 41 const String& host, |
| 28 int port, | 42 int port, |
| 29 const String& path, | 43 const String& path, |
| 30 WildcardDisposition hostWildcard, | 44 WildcardDisposition hostWildcard, |
| 31 WildcardDisposition portWildcard); | 45 WildcardDisposition portWildcard); |
| 32 bool isSchemeOnly() const; | 46 bool isSchemeOnly() const; |
| 33 const String& getScheme() { return m_scheme; }; | 47 const String& getScheme() { return m_scheme; }; |
| 34 bool matches(const KURL&, | 48 bool matches(const KURL&, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 56 FRIEND_TEST_ALL_PREFIXES(CSPSourceTest, Intersect); | 70 FRIEND_TEST_ALL_PREFIXES(CSPSourceTest, Intersect); |
| 57 FRIEND_TEST_ALL_PREFIXES(CSPSourceTest, IntersectSchemesOnly); | 71 FRIEND_TEST_ALL_PREFIXES(CSPSourceTest, IntersectSchemesOnly); |
| 58 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, GetIntersectCSPSources); | 72 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, GetIntersectCSPSources); |
| 59 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, | 73 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, |
| 60 GetIntersectCSPSourcesSchemes); | 74 GetIntersectCSPSourcesSchemes); |
| 61 FRIEND_TEST_ALL_PREFIXES(CSPDirectiveListTest, GetSourceVector); | 75 FRIEND_TEST_ALL_PREFIXES(CSPDirectiveListTest, GetSourceVector); |
| 62 FRIEND_TEST_ALL_PREFIXES(CSPDirectiveListTest, OperativeDirectiveGivenType); | 76 FRIEND_TEST_ALL_PREFIXES(CSPDirectiveListTest, OperativeDirectiveGivenType); |
| 63 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, SubsumesWithSelf); | 77 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, SubsumesWithSelf); |
| 64 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, GetSources); | 78 FRIEND_TEST_ALL_PREFIXES(SourceListDirectiveTest, GetSources); |
| 65 | 79 |
| 66 bool schemeMatches(const String&) const; | 80 SchemeMatchingResult schemeMatches(const String&) const; |
| 67 bool hostMatches(const String&) const; | 81 bool hostMatches(const String&) const; |
| 68 bool pathMatches(const String&) const; | 82 bool pathMatches(const String&) const; |
| 69 // Protocol is necessary to determine default port if it is zero. | 83 // Protocol is necessary to determine default port if it is zero. |
| 70 bool portMatches(int port, const String& protocol) const; | 84 PortMatchingResult portMatches(int port, const String& protocol) const; |
| 71 bool isSimilar(CSPSource* other) const; | 85 bool isSimilar(CSPSource* other) const; |
| 72 | 86 |
| 87 // Helper inline functions for Port and Scheme MatchingResult enums | |
| 88 bool inline requiresUpgrade(const PortMatchingResult result) const { | |
| 89 return result == PortMatchingUpgrade; | |
| 90 } | |
| 91 bool inline requiresUpgrade(const SchemeMatchingResult result) const { | |
| 92 return result == SchemeMatchingUpgrade; | |
| 93 } | |
| 94 | |
| 95 bool inline canUpgrade(const PortMatchingResult result) const { | |
| 96 return result == PortMatchingUpgrade || result == PortMatchingWildcard; | |
| 97 } | |
| 98 | |
| 99 bool inline canUpgrade(const SchemeMatchingResult result) const { | |
| 100 return result == SchemeMatchingUpgrade; | |
| 101 } | |
| 102 | |
| 73 Member<ContentSecurityPolicy> m_policy; | 103 Member<ContentSecurityPolicy> m_policy; |
| 74 String m_scheme; | 104 String m_scheme; |
| 75 String m_host; | 105 String m_host; |
| 76 int m_port; | 106 int m_port; |
| 77 String m_path; | 107 String m_path; |
| 78 | 108 |
| 79 WildcardDisposition m_hostWildcard; | 109 WildcardDisposition m_hostWildcard; |
| 80 WildcardDisposition m_portWildcard; | 110 WildcardDisposition m_portWildcard; |
| 81 }; | 111 }; |
| 82 | 112 |
| 83 } // namespace blink | 113 } // namespace blink |
| 84 | 114 |
| 85 #endif | 115 #endif |
| OLD | NEW |