Feature.h (1369B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_Feature_h 8 #define mozilla_dom_Feature_h 9 10 #include "nsCOMPtr.h" 11 #include "nsString.h" 12 #include "nsTArray.h" 13 14 class nsIPrincipal; 15 16 namespace mozilla::dom { 17 18 class Feature final { 19 public: 20 explicit Feature(const nsAString& aFeatureName); 21 22 ~Feature(); 23 24 const nsAString& Name() const; 25 26 void SetAllowsNone(); 27 28 bool AllowsNone() const; 29 30 void SetAllowsAll(); 31 32 bool AllowsAll() const; 33 34 void AppendToAllowList(nsIPrincipal* aPrincipal); 35 36 void GetAllowList(nsTArray<nsCOMPtr<nsIPrincipal>>& aList) const; 37 38 bool AllowListContains(nsIPrincipal* aPrincipal) const; 39 40 bool HasAllowList() const; 41 42 bool Allows(nsIPrincipal* aPrincipal) const; 43 44 private: 45 nsString mFeatureName; 46 47 enum Policy { 48 // denotes a policy of "feature 'none'" 49 eNone, 50 51 // denotes a policy of "feature *" 52 eAll, 53 54 // denotes a policy of "feature bar.com foo.com" 55 eAllowList, 56 }; 57 58 Policy mPolicy; 59 60 CopyableTArray<nsCOMPtr<nsIPrincipal>> mAllowList; 61 }; 62 63 } // namespace mozilla::dom 64 65 #endif // mozilla_dom_Feature_h