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
|
|
|
|
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
|
|
|
|
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.
|
2016-12-01 07:13:00 +03:00
|
|
|
nsresult ShouldEnableTrackingProtection(bool *result);
|
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;
|
2010-05-22 01:03:02 +04: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();
|
2015-08-07 23:08:22 +03:00
|
|
|
// Helper function to check a tracking URI against the whitelist
|
|
|
|
nsresult IsTrackerWhitelisted();
|
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);
|
2014-11-12 02:05:55 +03:00
|
|
|
|
2016-12-01 07:13:00 +03:00
|
|
|
nsresult ShouldEnableTrackingProtectionInternal(nsIChannel *aChannel,
|
|
|
|
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();
|
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,
|
|
|
|
const nsACString& aPrefix);
|
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
|