Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 7a61308

Browse files
committed
Bug 1669731 - P3. Add Allow API to ChannelClassifierService. r=timhuang,nhnt11
UI needs to distinguish the cases when a channel is shimmed and is unshimmed. When a channel is unshimmed, we unblock the channel and simply treat the channel as a non-tracking channel. When a channel is shimmed, although the channel is unblocked by URLCLassifier, we still want to show it in the UI. For this case, URLClassifier will notify a content blocking event when a channel is unblocked. This patch adds a new allow API, so the caller can use unblock() or allow() depending upon the case it requires. Differential Revision: https://phabricator.services.mozilla.com/D93271
1 parent db4a017 commit 7a61308

7 files changed

Lines changed: 54 additions & 23 deletions

netwerk/url-classifier/ChannelClassifierService.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ UrlClassifierBlockedChannel::GetIsPrivateBrowsing(bool* aIsPrivateBrowsing) {
136136
return NS_OK;
137137
}
138138

139+
NS_IMETHODIMP
140+
UrlClassifierBlockedChannel::Allow() {
141+
UC_LOG(("ChannelClassifierService: allow loading the channel %p",
142+
mChannel.get()));
143+
144+
mDecision = ChannelBlockDecision::Allowed;
145+
return NS_OK;
146+
}
147+
139148
NS_IMETHODIMP
140149
UrlClassifierBlockedChannel::Unblock() {
141150
UC_LOG(("ChannelClassifierService: unblock channel %p", mChannel.get()));
@@ -249,9 +258,7 @@ nsresult ChannelClassifierService::OnBeforeBlockChannel(
249258
NS_ISUPPORTS_CAST(nsIUrlClassifierBlockedChannel*, channel),
250259
"urlclassifier-before-block-channel", nullptr);
251260

252-
if (channel->IsUnblocked()) {
253-
aDecision = ChannelBlockDecision::Unblocked;
254-
}
261+
aDecision = channel->GetDecision();
255262
}
256263

257264
return NS_OK;

netwerk/url-classifier/ChannelClassifierService.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace net {
1616
enum class ChannelBlockDecision {
1717
Blocked,
1818
Unblocked,
19+
Allowed,
1920
};
2021

2122
class UrlClassifierBlockedChannel final
@@ -30,6 +31,8 @@ class UrlClassifierBlockedChannel final
3031
return mDecision != ChannelBlockDecision::Blocked;
3132
}
3233

34+
ChannelBlockDecision GetDecision() { return mDecision; };
35+
3336
void SetReason(const nsACString& aFeatureName, const nsACString& aTableName);
3437

3538
protected:

netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,14 @@ UrlClassifierFeatureCryptominingProtection::ProcessChannel(
143143
nsAutoCString list;
144144
UrlClassifierCommon::TablesToString(aList, list);
145145

146-
if (ChannelClassifierService::OnBeforeBlockChannel(aChannel, mName, list) ==
147-
ChannelBlockDecision::Unblocked) {
148-
ContentBlockingNotifier::OnEvent(
149-
aChannel, nsIWebProgressListener::STATE_UNBLOCKED_TRACKING_CONTENT,
150-
false);
146+
ChannelBlockDecision decision =
147+
ChannelClassifierService::OnBeforeBlockChannel(aChannel, mName, list);
148+
if (decision != ChannelBlockDecision::Blocked) {
149+
if (decision == ChannelBlockDecision::Unblocked) {
150+
ContentBlockingNotifier::OnEvent(
151+
aChannel, nsIWebProgressListener::STATE_UNBLOCKED_TRACKING_CONTENT,
152+
false);
153+
}
151154
*aShouldContinue = true;
152155
return NS_OK;
153156
}

netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ UrlClassifierFeatureFingerprintingProtection::ProcessChannel(
150150
nsAutoCString list;
151151
UrlClassifierCommon::TablesToString(aList, list);
152152

153-
if (ChannelClassifierService::OnBeforeBlockChannel(aChannel, mName, list) ==
154-
ChannelBlockDecision::Unblocked) {
155-
ContentBlockingNotifier::OnEvent(
156-
aChannel, nsIWebProgressListener::STATE_UNBLOCKED_TRACKING_CONTENT,
157-
false);
153+
ChannelBlockDecision decision =
154+
ChannelClassifierService::OnBeforeBlockChannel(aChannel, mName, list);
155+
if (decision != ChannelBlockDecision::Blocked) {
156+
if (decision == ChannelBlockDecision::Unblocked) {
157+
ContentBlockingNotifier::OnEvent(
158+
aChannel, nsIWebProgressListener::STATE_UNBLOCKED_TRACKING_CONTENT,
159+
false);
160+
}
158161
*aShouldContinue = true;
159162
return NS_OK;
160163
}

netwerk/url-classifier/UrlClassifierFeatureSocialTrackingProtection.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,14 @@ UrlClassifierFeatureSocialTrackingProtection::ProcessChannel(
146146
nsAutoCString list;
147147
UrlClassifierCommon::TablesToString(aList, list);
148148

149-
if (ChannelClassifierService::OnBeforeBlockChannel(aChannel, mName, list) ==
150-
ChannelBlockDecision::Unblocked) {
151-
ContentBlockingNotifier::OnEvent(
152-
aChannel, nsIWebProgressListener::STATE_UNBLOCKED_TRACKING_CONTENT,
153-
false);
149+
ChannelBlockDecision decision =
150+
ChannelClassifierService::OnBeforeBlockChannel(aChannel, mName, list);
151+
if (decision != ChannelBlockDecision::Blocked) {
152+
if (decision == ChannelBlockDecision::Unblocked) {
153+
ContentBlockingNotifier::OnEvent(
154+
aChannel, nsIWebProgressListener::STATE_UNBLOCKED_TRACKING_CONTENT,
155+
false);
156+
}
154157
*aShouldContinue = true;
155158
return NS_OK;
156159
}

netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ UrlClassifierFeatureTrackingProtection::ProcessChannel(
150150
nsAutoCString list;
151151
UrlClassifierCommon::TablesToString(aList, list);
152152

153-
if (ChannelClassifierService::OnBeforeBlockChannel(aChannel, mName, list) ==
154-
ChannelBlockDecision::Unblocked) {
155-
ContentBlockingNotifier::OnEvent(
156-
aChannel, nsIWebProgressListener::STATE_UNBLOCKED_TRACKING_CONTENT,
157-
false);
153+
ChannelBlockDecision decision =
154+
ChannelClassifierService::OnBeforeBlockChannel(aChannel, mName, list);
155+
if (decision != ChannelBlockDecision::Blocked) {
156+
if (decision == ChannelBlockDecision::Unblocked) {
157+
ContentBlockingNotifier::OnEvent(
158+
aChannel, nsIWebProgressListener::STATE_UNBLOCKED_TRACKING_CONTENT,
159+
false);
160+
}
158161
*aShouldContinue = true;
159162
return NS_OK;
160163
}

netwerk/url-classifier/nsIChannelClassifierService.idl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ interface nsIUrlClassifierBlockedChannel: nsISupports
3535
readonly attribute AString topLevelUrl;
3636

3737
// Ask UrlClassifier to unblock the load.
38+
// This is similar to allow(), the only difference is that the unblocked channel
39+
// is still considered as a tracking channel, so classifier will notify UI
40+
// content blocking event for the channel.
3841
void unblock();
42+
43+
// Ask UrlClassifier to allow the load.
44+
// This is similar to unblock(), the only difference is that the allowed channel
45+
// is not considered as a tracking channel anymore. UI will not receive content
46+
// blocking event for the channel.
47+
void allow();
3948
};
4049

4150
[scriptable, uuid(9411409c-5dac-40b9-ba36-2738a7237a4c)]

0 commit comments

Comments
 (0)