LCOV - code coverage report
Current view: top level - netwerk/base - nsChannelClassifier.h (source / functions) Hit Total Coverage
Test: output.info Lines: 1 1 100.0 %
Date: 2017-07-14 16:53:18 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 nsChannelClassifier_h__
       6             : #define nsChannelClassifier_h__
       7             : 
       8             : #include "nsIObserver.h"
       9             : #include "nsIURIClassifier.h"
      10             : #include "nsCOMPtr.h"
      11             : #include "mozilla/Attributes.h"
      12             : #include "mozilla/Maybe.h"
      13             : 
      14             : class nsIChannel;
      15             : class nsIHttpChannelInternal;
      16             : class nsIDocument;
      17             : 
      18             : namespace mozilla {
      19             : namespace net {
      20             : 
      21             : class nsChannelClassifier final : public nsIURIClassifierCallback,
      22             :                                   public nsIObserver
      23             : {
      24             : public:
      25             :     explicit nsChannelClassifier(nsIChannel* aChannel);
      26             : 
      27             :     NS_DECL_ISUPPORTS
      28             :     NS_DECL_NSIURICLASSIFIERCALLBACK
      29             :     NS_DECL_NSIOBSERVER
      30             : 
      31             :     // Calls nsIURIClassifier.Classify with the principal of the given channel,
      32             :     // and cancels the channel on a bad verdict.
      33             :     void Start();
      34             :     // Whether or not tracking protection should be enabled on this channel.
      35             :     bool ShouldEnableTrackingProtection();
      36             :     // Whether or not to annotate the channel with tracking protection list.
      37             :     bool ShouldEnableTrackingAnnotation();
      38             : 
      39             :     // Helper function to check a tracking URI against the whitelist
      40             :     nsresult IsTrackerWhitelisted(nsIURI* aWhiteListURI,
      41             :                                   nsIURIClassifierCallback* aCallback);
      42             : 
      43             :     // Called once we actually classified an URI. (An additional whitelist
      44             :     // check will be done if the classifier reports the URI is a tracker.)
      45             :     nsresult OnClassifyCompleteInternal(nsresult aErrorCode,
      46             :                                         const nsACString& aList,
      47             :                                         const nsACString& aProvider,
      48             :                                         const nsACString& aPrefix);
      49             : 
      50             :     // Check a tracking URI against the local blacklist and whitelist.
      51             :     // Returning NS_OK means the check will be processed
      52             :     // and the caller should wait for the result.
      53             :     nsresult CheckIsTrackerWithLocalTable(nsIURIClassifierCallback* aCallback);
      54             : 
      55             :     // Helper function to create a whitelist URL.
      56             :     already_AddRefed<nsIURI> CreateWhiteListURI() const;
      57             : 
      58             :     already_AddRefed<nsIChannel> GetChannel();
      59             : 
      60             : private:
      61             :     // True if the channel is on the allow list.
      62             :     bool mIsAllowListed;
      63             :     // True if the channel has been suspended.
      64             :     bool mSuspendedChannel;
      65             :     nsCOMPtr<nsIChannel> mChannel;
      66             :     Maybe<bool> mTrackingProtectionEnabled;
      67             :     Maybe<bool> mTrackingAnnotationEnabled;
      68             : 
      69          67 :     ~nsChannelClassifier() {}
      70             :     // Caches good classifications for the channel principal.
      71             :     void MarkEntryClassified(nsresult status);
      72             :     bool HasBeenClassified(nsIChannel *aChannel);
      73             :     // Helper function so that we ensure we call ContinueBeginConnect once
      74             :     // Start is called. Returns NS_OK if and only if we will get a callback
      75             :     // from the classifier service.
      76             :     nsresult StartInternal();
      77             :     // Helper function to check a URI against the hostname whitelist
      78             :     bool IsHostnameWhitelisted(nsIURI *aUri, const nsACString &aWhitelisted);
      79             :     // Checks that the channel was loaded by the URI currently loaded in aDoc
      80             :     static bool SameLoadingURI(nsIDocument *aDoc, nsIChannel *aChannel);
      81             :     // Note this function will be also used to decide whether or not to enable
      82             :     // channel annotation. When |aAnnotationsOnly| is true, this function
      83             :     // is called by ShouldEnableTrackingAnnotation(). Otherwise, this is called
      84             :     // by ShouldEnableTrackingProtection().
      85             :     nsresult ShouldEnableTrackingProtectionInternal(nsIChannel *aChannel,
      86             :                                                     bool aAnnotationsOnly,
      87             :                                                     bool *result);
      88             : 
      89             :     bool AddonMayLoad(nsIChannel *aChannel, nsIURI *aUri);
      90             :     void AddShutdownObserver();
      91             :     void RemoveShutdownObserver();
      92             : public:
      93             :     // If we are blocking content, update the corresponding flag in the respective
      94             :     // docshell and call nsISecurityEventSink::onSecurityChange.
      95             :     static nsresult SetBlockedContent(nsIChannel *channel,
      96             :                                       nsresult aErrorCode,
      97             :                                       const nsACString& aList,
      98             :                                       const nsACString& aProvider,
      99             :                                       const nsACString& aPrefix);
     100             :     static nsresult NotifyTrackingProtectionDisabled(nsIChannel *aChannel);
     101             : };
     102             : 
     103             : } // namespace net
     104             : } // namespace mozilla
     105             : 
     106             : #endif

Generated by: LCOV version 1.13