ThirdPartyCookieBlockingExceptions.h (2469B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef mozilla_net_ThirdPartyCookieBlockingExceptions_h 6 #define mozilla_net_ThirdPartyCookieBlockingExceptions_h 7 8 #include "mozilla/MozPromise.h" 9 #include "nsEffectiveTLDService.h" 10 #include "nsString.h" 11 #include "nsTArray.h" 12 #include "nsTHashSet.h" 13 #include "nsIThirdPartyCookieBlockingExceptionListService.h" 14 15 class nsIEffectiveTLDService; 16 class nsIURI; 17 class nsIChannel; 18 19 namespace mozilla { 20 namespace net { 21 22 class ThirdPartyCookieBlockingExceptions final { 23 public: 24 // Initializes the foreign cookie blocking exception list. 25 void Initialize(); 26 27 // Check if the given top-level and third-party URIs are in the exception 28 // list. 29 bool CheckExceptionForURIs(nsIURI* aFirstPartyURI, nsIURI* aThirdPartyURI); 30 31 // Check if the given channel is in the exception list. 32 bool CheckExceptionForChannel(nsIChannel* aChannel); 33 34 void Insert(const nsACString& aException); 35 void Remove(const nsACString& aException); 36 37 void GetExceptions(nsTArray<nsCString>& aExceptions); 38 39 void Shutdown(); 40 41 bool IsInitialized() const { return mIsInitialized; } 42 43 private: 44 nsCOMPtr<nsIThirdPartyCookieBlockingExceptionListService> 45 m3PCBExceptionService; 46 47 // A helper function to create a key for the exception list. 48 static void Create3PCBExceptionKey(const nsACString& aFirstPartySite, 49 const nsACString& aThirdPartySite, 50 nsACString& aKey) { 51 aKey.Truncate(); 52 aKey.Append(aFirstPartySite); 53 aKey.AppendLiteral(","); 54 aKey.Append(aThirdPartySite); 55 } 56 57 // Check if the given third-party site is in the wildcard exception list. 58 // The wildcard exception list is used to allow third-party cookies under 59 // every top-level site. 60 bool CheckWildcardException(const nsACString& aThirdPartySite); 61 62 // Check if the given first-party and third-party sites are in the exception 63 // list. 64 bool CheckException(const nsACString& aFirstPartySite, 65 const nsACString& aThirdPartySite); 66 67 // The flag that indicates if the 3PCB exception service is initialized. 68 bool mIsInitialized = false; 69 nsTHashSet<nsCStringHashKey> m3PCBExceptionsSet; 70 }; 71 72 } // namespace net 73 } // namespace mozilla 74 75 #endif // mozilla_net_ThirdPartyCookieBlockingExceptions_h