OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #ifndef FeaturePolicy_h |
| 6 #define FeaturePolicy_h |
| 7 |
| 8 #include "platform/PlatformExport.h" |
| 9 #include "platform/heap/Handle.h" |
| 10 #include "platform/weborigin/SecurityOrigin.h" |
| 11 #include "wtf/RefPtr.h" |
| 12 #include "wtf/text/WTFString.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 struct FeaturePolicyFeature { |
| 17 const char* featureName; |
| 18 bool enabledByDefault; |
| 19 bool enabledInNestedContext; |
| 20 }; |
| 21 |
| 22 extern const PLATFORM_EXPORT FeaturePolicyFeature kDocumentCookie; |
| 23 extern const PLATFORM_EXPORT FeaturePolicyFeature kDocumentDomain; |
| 24 extern const PLATFORM_EXPORT FeaturePolicyFeature kDocumentWrite; |
| 25 extern const PLATFORM_EXPORT FeaturePolicyFeature kVibrate; |
| 26 extern const PLATFORM_EXPORT FeaturePolicyFeature kWebRTC; |
| 27 extern const PLATFORM_EXPORT FeaturePolicyFeature kNoSuchFeature; |
| 28 |
| 29 class PLATFORM_EXPORT FeaturePolicy final : public GarbageCollectedFinalized<Fea
turePolicy> { |
| 30 public: |
| 31 static FeaturePolicy* createFromParentPolicy(const FeaturePolicy* parent, Re
fPtr<SecurityOrigin>); |
| 32 |
| 33 // Adds a policy to a frame, taking into account any existing or default |
| 34 // policy which applies. |
| 35 void addPolicyFromString(const String& policy); |
| 36 |
| 37 // Returns whether or not the given feature is enabled by this policy. |
| 38 bool isFeatureEnabledForOrigin(const FeaturePolicyFeature*, const SecurityOr
igin*); |
| 39 |
| 40 // Returns whether or not the given feature is enabled for the policy's |
| 41 // origin. |
| 42 bool isFeatureEnabled(const FeaturePolicyFeature*); |
| 43 |
| 44 // Returns whether or not the named feature is enabled by default. |
| 45 static bool isFeatureEnabledByDefault(const FeaturePolicyFeature*, bool isTo
pLevel); |
| 46 |
| 47 // Track whether the feature policy-controlled V8 bindings have been |
| 48 // installed already. |
| 49 void setFeaturePolicyBindingsInstalled(); |
| 50 bool featurePolicyBindingsInstalled(); |
| 51 |
| 52 DECLARE_VIRTUAL_TRACE(); |
| 53 |
| 54 private: |
| 55 class Whitelist final { |
| 56 public: |
| 57 Whitelist(); |
| 58 |
| 59 // Adds a single origin to the whitelist. |
| 60 void add(RefPtr<SecurityOrigin>); |
| 61 |
| 62 // Adds all origins to the whitelist. |
| 63 void addAll(); |
| 64 |
| 65 // Returns true if the given origin has been added to the whitelist. |
| 66 bool targets(const SecurityOrigin*) const; |
| 67 |
| 68 private: |
| 69 bool m_matchesAllOrigins; |
| 70 Vector<RefPtr<SecurityOrigin>> origins; |
| 71 }; |
| 72 |
| 73 FeaturePolicy(PassRefPtr<SecurityOrigin>, bool isTopLevel); |
| 74 |
| 75 HashMap<const FeaturePolicyFeature*, Whitelist> parse(const String&); |
| 76 |
| 77 RefPtr<SecurityOrigin> m_origin; |
| 78 |
| 79 // True if this policy is attached to a top-level frame (and the top-level |
| 80 // defaults should be used when necessary) |
| 81 bool m_isTopLevel; |
| 82 |
| 83 // Map of feature names to whitelists. Any feature which is missing from |
| 84 // this map should use the defaults. |
| 85 HashMap<const FeaturePolicyFeature*, Whitelist> m_whitelists; |
| 86 |
| 87 // Records whether the V8 bindings have been installed into the document's |
| 88 // V8 context. |
| 89 bool m_bindingsInstalled; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(FeaturePolicy); |
| 92 }; |
| 93 |
| 94 } // namespace blink |
| 95 |
| 96 #endif // FeaturePolicy_h |
OLD | NEW |