UrlClassifierExceptionList.h (2335B)
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_UrlClassifierExceptionList_h 8 #define mozilla_UrlClassifierExceptionList_h 9 10 #include "nsHashKeys.h" 11 #include "nsTHashMap.h" 12 #include "nsIUrlClassifierExceptionList.h" 13 #include "nsISupports.h" 14 #include "nsTArray.h" 15 #include "nsString.h" 16 17 namespace mozilla::net { 18 19 /** 20 * @see nsIUrlClassifierExceptionList 21 */ 22 class UrlClassifierExceptionList final : public nsIUrlClassifierExceptionList { 23 public: 24 NS_DECL_ISUPPORTS 25 NS_DECL_NSIURLCLASSIFIEREXCEPTIONLIST 26 27 UrlClassifierExceptionList() = default; 28 29 private: 30 ~UrlClassifierExceptionList() = default; 31 32 // A list of exception entries 33 using ExceptionEntryArray = 34 nsTArray<RefPtr<nsIUrlClassifierExceptionListEntry>>; 35 36 // A map from (schemeless) site to a list of exception entries. 37 using SiteToEntries = nsTHashMap<nsCStringHashKey, ExceptionEntryArray>; 38 39 // Helper method to check if any exception in the array matches the given 40 // load. 41 static bool ExceptionListMatchesLoad(ExceptionEntryArray* aExceptions, 42 nsIURI* aURI, nsIURI* aTopLevelURI, 43 bool aIsPrivateBrowsing); 44 45 // Helper method to extract the schemeless site from a URL pattern. 46 NS_IMETHODIMP GetSchemelessSiteFromUrlPattern(const nsACString& aUrlPattern, 47 nsACString& aSite); 48 49 // The feature this exception list is for, e.g. "tracking-protection". 50 nsCString mFeature; 51 52 // A two stage hash map to store the (top level) site-specific exception 53 // entries. 54 // The outer hash map key is the top level (schemeless) site. 55 // The inner hash map key is the (schemeless) site of the load to be checked. 56 nsTHashMap<nsCStringHashKey, SiteToEntries> mExceptions; 57 58 // A map of exception list entries which apply across all top level sites. 59 // The hash map key is the (schemeless) site of the load to be checked. 60 nsTHashMap<nsCStringHashKey, ExceptionEntryArray> mGlobalExceptions; 61 }; 62 63 } // namespace mozilla::net 64 65 #endif