nsChannelClassifier.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef nsChannelClassifier_h__
  5. #define nsChannelClassifier_h__
  6. #include "nsIURIClassifier.h"
  7. #include "nsCOMPtr.h"
  8. #include "mozilla/Attributes.h"
  9. class nsIChannel;
  10. class nsIHttpChannelInternal;
  11. class nsIDocument;
  12. namespace mozilla {
  13. namespace net {
  14. class nsChannelClassifier final : public nsIURIClassifierCallback
  15. {
  16. public:
  17. nsChannelClassifier();
  18. NS_DECL_ISUPPORTS
  19. NS_DECL_NSIURICLASSIFIERCALLBACK
  20. // Calls nsIURIClassifier.Classify with the principal of the given channel,
  21. // and cancels the channel on a bad verdict.
  22. void Start(nsIChannel *aChannel);
  23. // Whether or not tracking protection should be enabled on this channel.
  24. nsresult ShouldEnableTrackingProtection(nsIChannel *aChannel, bool *result);
  25. private:
  26. // True if the channel is on the allow list.
  27. bool mIsAllowListed;
  28. // True if the channel has been suspended.
  29. bool mSuspendedChannel;
  30. nsCOMPtr<nsIChannel> mChannel;
  31. ~nsChannelClassifier() {}
  32. // Caches good classifications for the channel principal.
  33. void MarkEntryClassified(nsresult status);
  34. bool HasBeenClassified(nsIChannel *aChannel);
  35. // Helper function so that we ensure we call ContinueBeginConnect once
  36. // Start is called. Returns NS_OK if and only if we will get a callback
  37. // from the classifier service.
  38. nsresult StartInternal();
  39. // Helper function to check a tracking URI against the whitelist
  40. nsresult IsTrackerWhitelisted();
  41. // Helper function to check a URI against the hostname whitelist
  42. bool IsHostnameWhitelisted(nsIURI *aUri, const nsACString &aWhitelisted);
  43. // Checks that the channel was loaded by the URI currently loaded in aDoc
  44. static bool SameLoadingURI(nsIDocument *aDoc, nsIChannel *aChannel);
  45. public:
  46. // If we are blocking tracking content, update the corresponding flag in
  47. // the respective docshell and call nsISecurityEventSink::onSecurityChange.
  48. static nsresult SetBlockedTrackingContent(nsIChannel *channel);
  49. static nsresult NotifyTrackingProtectionDisabled(nsIChannel *aChannel);
  50. };
  51. } // namespace net
  52. } // namespace mozilla
  53. #endif