Bug 1522210 - Fingerprinting and cryptomining classifiers must have separate nsIWebProgressListener blocking state codes - part 7 - cryptomining, r=Ehsan,johannh

Differential Revision: https://phabricator.services.mozilla.com/D17641

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-01-30 18:26:15 +00:00
Родитель 13c4d3abd6
Коммит 5f16a34f58
10 изменённых файлов: 85 добавлений и 11 удалений

Просмотреть файл

@ -85,16 +85,20 @@ var TrackingProtection = {
this.categoryLabel.textContent = label ? gNavigatorBundle.getString(label) : "";
},
// FIXME This must change! Fingerprinting must have its own section. See bug 1522566.
// FIXME This must change! Fingerprinting and cryptomining must have theirs
// own sections. See bug 1522566.
isBlocking(state) {
return (state & Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT) != 0 ||
(state & Ci.nsIWebProgressListener.STATE_BLOCKED_FINGERPRINTING_CONTENT) != 0;
(state & Ci.nsIWebProgressListener.STATE_BLOCKED_FINGERPRINTING_CONTENT) != 0 ||
(state & Ci.nsIWebProgressListener.STATE_BLOCKED_CRYPTOMINING_CONTENT) != 0;
},
// FIXME This must change! Fingerprinting must have its own section. See bug 1522566.
// FIXME This must change! Fingerprinting and cryptomining must have theirs
// own sections. See bug 1522566.
isAllowing(state) {
return (state & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT) != 0 ||
(state & Ci.nsIWebProgressListener.STATE_LOADED_FINGERPRINTING_CONTENT) != 0;
(state & Ci.nsIWebProgressListener.STATE_LOADED_FINGERPRINTING_CONTENT) != 0 ||
(state & Ci.nsIWebProgressListener.STATE_LOADED_CRYPTOMINING_CONTENT) != 0;
},
isDetected(state) {

Просмотреть файл

@ -1010,6 +1010,14 @@ class Document : public nsINode,
nsIWebProgressListener::STATE_BLOCKED_FINGERPRINTING_CONTENT);
}
/**
* Get cryptomining content blocked flag for this document.
*/
bool GetHasCryptominingContentBlocked() {
return mContentBlockingLog.HasBlockedAnyOfType(
nsIWebProgressListener::STATE_BLOCKED_CRYPTOMINING_CONTENT);
}
/**
* Get all cookies blocked flag for this document.
*/
@ -1063,6 +1071,17 @@ class Document : public nsINode,
aHasFingerprintingContentBlocked);
}
/**
* Set the cryptomining content blocked flag for this document.
*/
void SetHasCryptominingContentBlocked(bool aHasCryptominingContentBlocked,
const nsACString& aOriginBlocked) {
RecordContentBlockingLog(
aOriginBlocked,
nsIWebProgressListener::STATE_BLOCKED_CRYPTOMINING_CONTENT,
aHasCryptominingContentBlocked);
}
/**
* Set the all cookies blocked flag for this document.
*/
@ -1159,6 +1178,25 @@ class Document : public nsINode,
aHasFingerprintingContentLoaded);
}
/**
* Get cryptomining content loaded flag for this document.
*/
bool GetHasCryptominingContentLoaded() {
return mContentBlockingLog.HasBlockedAnyOfType(
nsIWebProgressListener::STATE_LOADED_CRYPTOMINING_CONTENT);
}
/**
* Set the cryptomining content loaded flag for this document.
*/
void SetHasCryptominingContentLoaded(bool aHasCryptominingContentLoaded,
const nsACString& aOriginBlocked) {
RecordContentBlockingLog(
aOriginBlocked,
nsIWebProgressListener::STATE_LOADED_CRYPTOMINING_CONTENT,
aHasCryptominingContentLoaded);
}
/**
* Get the sandbox flags for this document.
* @see nsSandboxFlags.h for the possible flags

Просмотреть файл

@ -5419,6 +5419,18 @@ void nsGlobalWindowOuter::NotifyContentBlockingEvent(unsigned aEvent,
if (!aBlocked) {
unblocked = !doc->GetHasFingerprintingContentLoaded();
}
} else if (aEvent ==
nsIWebProgressListener::STATE_BLOCKED_CRYPTOMINING_CONTENT) {
doc->SetHasCryptominingContentBlocked(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasCryptominingContentBlocked();
}
} else if (aEvent ==
nsIWebProgressListener::STATE_LOADED_CRYPTOMINING_CONTENT) {
doc->SetHasCryptominingContentLoaded(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasCryptominingContentLoaded();
}
} else if (aEvent == nsIWebProgressListener::
STATE_COOKIES_BLOCKED_BY_PERMISSION) {
doc->SetHasCookiesBlockedByPermission(aBlocked, origin);

Просмотреть файл

@ -239,3 +239,4 @@ XPC_MSG_DEF(NS_ERROR_UNWANTED_URI , "The URI is unwanted")
XPC_MSG_DEF(NS_ERROR_BLOCKED_URI , "The URI is blocked")
XPC_MSG_DEF(NS_ERROR_HARMFUL_URI , "The URI is harmful")
XPC_MSG_DEF(NS_ERROR_FINGERPRINTING_URI , "The URI is fingerprinting")
XPC_MSG_DEF(NS_ERROR_CRYPTOMINING_URI , "The URI is cryptomining")

Просмотреть файл

@ -171,7 +171,7 @@ UrlClassifierCommon::NotifyChannelClassifierProtectionDisabled(
break;
case AntiTrackingCommon::eCryptomining:
// TODO: next patches...
event = nsIWebProgressListener::STATE_LOADED_CRYPTOMINING_CONTENT;
break;
default:

Просмотреть файл

@ -136,8 +136,8 @@ UrlClassifierFeatureCryptomining::ProcessChannel(nsIChannel* aChannel,
// This is a blocking feature.
*aShouldContinue = false;
UrlClassifierCommon::SetBlockedContent(aChannel, NS_ERROR_TRACKING_URI, aList,
EmptyCString(), EmptyCString());
UrlClassifierCommon::SetBlockedContent(aChannel, NS_ERROR_CRYPTOMINING_URI,
aList, EmptyCString(), EmptyCString());
UC_LOG(
("UrlClassifierFeatureCryptomining::ProcessChannel, cancelling "
@ -145,12 +145,10 @@ UrlClassifierFeatureCryptomining::ProcessChannel(nsIChannel* aChannel,
aChannel));
nsCOMPtr<nsIHttpChannelInternal> httpChannel = do_QueryInterface(aChannel);
// FIXME: the way we cancel the channel depends on what the UI wants to show.
// This needs to change, at some point.
if (httpChannel) {
Unused << httpChannel->CancelByChannelClassifier(NS_ERROR_TRACKING_URI);
Unused << httpChannel->CancelByChannelClassifier(NS_ERROR_CRYPTOMINING_URI);
} else {
Unused << aChannel->Cancel(NS_ERROR_TRACKING_URI);
Unused << aChannel->Cancel(NS_ERROR_CRYPTOMINING_URI);
}
return NS_OK;

Просмотреть файл

@ -221,6 +221,9 @@ static const BlockingErrorCode sBlockingErrorCodes[] = {
{NS_ERROR_FINGERPRINTING_URI,
nsIWebProgressListener::STATE_BLOCKED_FINGERPRINTING_CONTENT,
"TrackerUriBlocked", NS_LITERAL_CSTRING("Tracking Protection")},
{NS_ERROR_CRYPTOMINING_URI,
nsIWebProgressListener::STATE_BLOCKED_CRYPTOMINING_CONTENT,
"TrackerUriBlocked", NS_LITERAL_CSTRING("Tracking Protection")},
};
} // namespace

Просмотреть файл

@ -187,6 +187,15 @@ void nsSecureBrowserUIImpl::CheckForContentBlockingEvents() {
mEvent |= STATE_LOADED_FINGERPRINTING_CONTENT;
}
// Has cryptomining content been blocked or loaded?
if (doc->GetHasCryptominingContentBlocked()) {
mEvent |= STATE_BLOCKED_CRYPTOMINING_CONTENT;
}
if (doc->GetHasCryptominingContentLoaded()) {
mEvent |= STATE_LOADED_CRYPTOMINING_CONTENT;
}
// Other block types.
if (doc->GetHasCookiesBlockedByPermission()) {
mEvent |= STATE_COOKIES_BLOCKED_BY_PERMISSION;

Просмотреть файл

@ -276,6 +276,12 @@ interface nsIWebProgressListener : nsISupports
* STATE_LOADED_FINGERPRINTING_CONTENT
* Fingerprinting content has been loaded.
*
* STATE_BLOCKED_CRYPTOMINING_CONTENT
* Cryptomining content has been blocked from loading.
*
* STATE_LOADED_CRYPTOMINING_CONTENT
* Cryptomining content has been loaded.
*
* STATE_BLOCKED_UNSAFE_CONTENT
* Content which againts SafeBrowsing list has been blocked from loading.
*
@ -296,6 +302,8 @@ interface nsIWebProgressListener : nsISupports
const unsigned long STATE_LOADED_TRACKING_CONTENT = 0x00002000;
const unsigned long STATE_BLOCKED_FINGERPRINTING_CONTENT = 0x00000040;
const unsigned long STATE_LOADED_FINGERPRINTING_CONTENT = 0x00000400;
const unsigned long STATE_BLOCKED_CRYPTOMINING_CONTENT = 0x00000800;
const unsigned long STATE_LOADED_CRYPTOMINING_CONTENT = 0x00200000;
const unsigned long STATE_BLOCKED_UNSAFE_CONTENT = 0x00004000;
const unsigned long STATE_COOKIES_LOADED = 0x00008000;
const unsigned long STATE_COOKIES_BLOCKED_BY_PERMISSION = 0x10000000;

Просмотреть файл

@ -808,6 +808,7 @@ with modules["URILOADER"]:
errors["NS_ERROR_MAYBE_TRACKING_URI"] = FAILURE(39)
errors["NS_ERROR_TRACKING_ANNOTATION_URI"] = FAILURE(40)
errors["NS_ERROR_FINGERPRINTING_URI"] = FAILURE(41)
errors["NS_ERROR_CRYPTOMINING_URI"] = FAILURE(42)
# Used when "Save Link As..." doesn't see the headers quickly enough to
# choose a filename. See nsContextMenu.js.
errors["NS_ERROR_SAVE_LINK_AS_TIMEOUT"] = FAILURE(32)