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"
|
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;
|
|
|
|
|
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 {
|
2010-05-22 01:03:02 +04:00
|
|
|
public:
|
2016-12-01 07:13:00 +03:00
|
|
|
explicit nsChannelClassifier(nsIChannel* aChannel);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-05-22 01:03:02 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2017-06-13 02:16:00 +03:00
|
|
|
NS_DECL_NSIURICLASSIFIERCALLBACK
|
2017-03-01 06:27:51 +03:00
|
|
|
NS_DECL_NSIOBSERVER
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-01 06:27:51 +03:00
|
|
|
// Calls nsIURIClassifier.Classify with the principal of the given channel,
|
|
|
|
// and cancels the channel on a bad verdict.
|
2017-08-04 13:20:13 +03:00
|
|
|
void Start();
|
2018-11-30 13:46:48 +03: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;
|
2018-11-30 13:46:48 +03: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();
|
2017-06-13 02:16:00 +03:00
|
|
|
// Helper function to check a URI against the hostname whitelist
|
|
|
|
bool IsHostnameWhitelisted(nsIURI* aUri, const nsACString& aWhitelisted);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
public:
|
2017-02-21 04:46:36 +03:00
|
|
|
// If we are blocking content, update the corresponding flag in the respective
|
2019-01-28 19:40:21 +03:00
|
|
|
// docshell and call nsDocLoader::OnSecurityChange.
|
2017-02-21 04:46:36 +03:00
|
|
|
static nsresult SetBlockedContent(nsIChannel* channel, nsresult aErrorCode,
|
|
|
|
const nsACString& aList,
|
|
|
|
const nsACString& aProvider,
|
2017-08-04 13:20:13 +03:00
|
|
|
const nsACString& aFullHash);
|
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
|