2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-09-01 03:18:46 +04:00
|
|
|
|
2010-05-22 01:03:02 +04:00
|
|
|
#ifndef nsChannelClassifier_h__
|
|
|
|
#define nsChannelClassifier_h__
|
2007-09-01 03:18:46 +04:00
|
|
|
|
2017-05-04 13:14:04 +03:00
|
|
|
#include "nsIObserver.h"
|
2010-05-22 01:03:02 +04:00
|
|
|
#include "nsIURIClassifier.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2012-06-06 07:18:25 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2016-12-01 07:13:00 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2007-09-01 03:18:46 +04:00
|
|
|
|
2017-10-12 06:54:00 +03:00
|
|
|
#include <functional>
|
|
|
|
|
2010-05-22 01:03:02 +04:00
|
|
|
class nsIChannel;
|
2015-01-21 22:33:07 +03:00
|
|
|
class nsIHttpChannelInternal;
|
2015-08-13 12:14:36 +03:00
|
|
|
class nsIDocument;
|
2010-05-22 01:03:02 +04:00
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2017-01-12 13:07:22 +03:00
|
|
|
class nsChannelClassifier final : public nsIURIClassifierCallback,
|
|
|
|
public nsIObserver
|
2007-09-01 03:18:46 +04:00
|
|
|
{
|
2010-05-22 01:03:02 +04:00
|
|
|
public:
|
2016-12-01 07:13:00 +03:00
|
|
|
explicit nsChannelClassifier(nsIChannel* aChannel);
|
2010-05-22 01:03:02 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIURICLASSIFIERCALLBACK
|
2017-01-12 13:07:22 +03:00
|
|
|
NS_DECL_NSIOBSERVER
|
2010-05-22 01:03:02 +04:00
|
|
|
|
2015-01-10 00:25:13 +03:00
|
|
|
// Calls nsIURIClassifier.Classify with the principal of the given channel,
|
2015-06-18 17:57:00 +03:00
|
|
|
// and cancels the channel on a bad verdict.
|
2016-12-01 07:13:00 +03:00
|
|
|
void Start();
|
2015-01-10 00:25:13 +03:00
|
|
|
// Whether or not tracking protection should be enabled on this channel.
|
2017-06-13 02:16:00 +03:00
|
|
|
bool ShouldEnableTrackingProtection();
|
|
|
|
// Whether or not to annotate the channel with tracking protection list.
|
|
|
|
bool ShouldEnableTrackingAnnotation();
|
|
|
|
|
|
|
|
// Helper function to check a tracking URI against the whitelist
|
|
|
|
nsresult IsTrackerWhitelisted(nsIURI* aWhiteListURI,
|
|
|
|
nsIURIClassifierCallback* aCallback);
|
2010-05-22 01:03:02 +04:00
|
|
|
|
2017-03-01 06:27:51 +03:00
|
|
|
// Called once we actually classified an URI. (An additional whitelist
|
|
|
|
// check will be done if the classifier reports the URI is a tracker.)
|
|
|
|
nsresult OnClassifyCompleteInternal(nsresult aErrorCode,
|
|
|
|
const nsACString& aList,
|
|
|
|
const nsACString& aProvider,
|
2017-08-04 13:20:13 +03:00
|
|
|
const nsACString& aFullHash);
|
2017-03-01 06:27:51 +03:00
|
|
|
|
2017-06-13 02:16:00 +03:00
|
|
|
// Check a tracking URI against the local blacklist and whitelist.
|
|
|
|
// Returning NS_OK means the check will be processed
|
|
|
|
// and the caller should wait for the result.
|
2017-10-12 06:54:00 +03:00
|
|
|
nsresult CheckIsTrackerWithLocalTable(std::function<void()>&& aCallback);
|
2017-06-13 02:16:00 +03:00
|
|
|
|
|
|
|
// Helper function to create a whitelist URL.
|
|
|
|
already_AddRefed<nsIURI> CreateWhiteListURI() const;
|
|
|
|
|
|
|
|
already_AddRefed<nsIChannel> GetChannel();
|
|
|
|
|
2010-05-22 01:03:02 +04:00
|
|
|
private:
|
2015-01-10 00:25:13 +03:00
|
|
|
// True if the channel is on the allow list.
|
2014-08-23 02:17:32 +04:00
|
|
|
bool mIsAllowListed;
|
2015-01-10 00:25:13 +03:00
|
|
|
// True if the channel has been suspended.
|
|
|
|
bool mSuspendedChannel;
|
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2016-12-01 07:13:00 +03:00
|
|
|
Maybe<bool> mTrackingProtectionEnabled;
|
2017-06-13 02:16:00 +03:00
|
|
|
Maybe<bool> mTrackingAnnotationEnabled;
|
2010-05-22 01:03:02 +04:00
|
|
|
|
2017-08-17 19:16:00 +03:00
|
|
|
~nsChannelClassifier();
|
2015-01-10 00:25:13 +03:00
|
|
|
// Caches good classifications for the channel principal.
|
2010-05-22 01:03:02 +04:00
|
|
|
void MarkEntryClassified(nsresult status);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasBeenClassified(nsIChannel *aChannel);
|
2015-01-10 00:25:13 +03:00
|
|
|
// Helper function so that we ensure we call ContinueBeginConnect once
|
|
|
|
// Start is called. Returns NS_OK if and only if we will get a callback
|
|
|
|
// from the classifier service.
|
2015-01-21 22:33:07 +03:00
|
|
|
nsresult StartInternal();
|
2016-03-12 00:57:38 +03:00
|
|
|
// Helper function to check a URI against the hostname whitelist
|
|
|
|
bool IsHostnameWhitelisted(nsIURI *aUri, const nsACString &aWhitelisted);
|
2015-08-13 12:14:36 +03:00
|
|
|
// Checks that the channel was loaded by the URI currently loaded in aDoc
|
|
|
|
static bool SameLoadingURI(nsIDocument *aDoc, nsIChannel *aChannel);
|
2017-06-13 02:16:00 +03:00
|
|
|
// Note this function will be also used to decide whether or not to enable
|
|
|
|
// channel annotation. When |aAnnotationsOnly| is true, this function
|
|
|
|
// is called by ShouldEnableTrackingAnnotation(). Otherwise, this is called
|
|
|
|
// by ShouldEnableTrackingProtection().
|
2016-12-01 07:13:00 +03:00
|
|
|
nsresult ShouldEnableTrackingProtectionInternal(nsIChannel *aChannel,
|
2017-06-13 02:16:00 +03:00
|
|
|
bool aAnnotationsOnly,
|
2016-12-01 07:13:00 +03:00
|
|
|
bool *result);
|
|
|
|
|
2017-02-10 08:08:06 +03:00
|
|
|
bool AddonMayLoad(nsIChannel *aChannel, nsIURI *aUri);
|
2017-02-24 05:14:07 +03:00
|
|
|
void AddShutdownObserver();
|
|
|
|
void RemoveShutdownObserver();
|
2017-11-28 23:10:37 +03:00
|
|
|
static nsresult SendThreatHitReport(nsIChannel *aChannel,
|
|
|
|
const nsACString& aProvider,
|
|
|
|
const nsACString& aList,
|
|
|
|
const nsACString& aFullHash);
|
2014-11-12 02:05:55 +03:00
|
|
|
public:
|
2017-02-21 04:46:36 +03:00
|
|
|
// If we are blocking content, update the corresponding flag in the respective
|
|
|
|
// docshell and call nsISecurityEventSink::onSecurityChange.
|
|
|
|
static nsresult SetBlockedContent(nsIChannel *channel,
|
|
|
|
nsresult aErrorCode,
|
|
|
|
const nsACString& aList,
|
|
|
|
const nsACString& aProvider,
|
2017-08-04 13:20:13 +03:00
|
|
|
const nsACString& aFullHash);
|
2014-11-12 02:05:55 +03:00
|
|
|
static nsresult NotifyTrackingProtectionDisabled(nsIChannel *aChannel);
|
2007-09-01 03:18:46 +04:00
|
|
|
};
|
2010-05-22 01:03:02 +04:00
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-05-22 01:03:02 +04:00
|
|
|
#endif
|