mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-09 21:00:42 +02:00
Bug 1765313, part 1 - Remove dead code from ContentBlocking.h, r=anti-tracking-reviewers,timhuang
Differential Revision: https://phabricator.services.mozilla.com/D148284
This commit is contained in:
parent
488f74b8a4
commit
1290825926
2 changed files with 0 additions and 127 deletions
|
|
@ -1583,104 +1583,3 @@ bool ContentBlocking::ApproximateAllowAccessForWithoutChannel(
|
||||||
parentPrincipal, type,
|
parentPrincipal, type,
|
||||||
nsContentUtils::IsInPrivateBrowsing(parentDocument), nullptr, 0);
|
nsContentUtils::IsInPrivateBrowsing(parentDocument), nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(ContentBlocking::TrackerClassifierFeatureCallback,
|
|
||||||
nsIUrlClassifierFeatureCallback)
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
ContentBlocking::TrackerClassifierFeatureCallback::OnClassifyComplete(
|
|
||||||
const nsTArray<RefPtr<nsIUrlClassifierFeatureResult>>& aResults) {
|
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
|
||||||
|
|
||||||
if (aResults.IsEmpty()) {
|
|
||||||
// Reject if we can not find url in tracker list.
|
|
||||||
mHolder.RejectIfExists(NS_OK, __func__);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSocialTracker = false;
|
|
||||||
|
|
||||||
// Check if the principal is listed in the social tracking list to report
|
|
||||||
// different tracker type.
|
|
||||||
for (const auto& result : aResults) {
|
|
||||||
nsCOMPtr<nsIUrlClassifierFeature> feature;
|
|
||||||
result->GetFeature(getter_AddRefs(feature));
|
|
||||||
|
|
||||||
if (!feature) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAutoCString name;
|
|
||||||
feature->GetName(name);
|
|
||||||
|
|
||||||
if (name.EqualsLiteral("socialtracking-annotation")) {
|
|
||||||
isSocialTracker = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mHolder.ResolveIfExists(
|
|
||||||
isSocialTracker
|
|
||||||
? nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER
|
|
||||||
: nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER,
|
|
||||||
__func__);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* static */
|
|
||||||
RefPtr<ContentBlocking::CheckTrackerForPrincipalPromise>
|
|
||||||
ContentBlocking::CheckTrackerForPrincipal(nsIPrincipal* aPrincipal) {
|
|
||||||
MOZ_ASSERT(aPrincipal);
|
|
||||||
MOZ_ASSERT(XRE_IsParentProcess());
|
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
|
||||||
auto* basePrincipal = BasePrincipal::Cast(aPrincipal);
|
|
||||||
basePrincipal->GetURI(getter_AddRefs(uri));
|
|
||||||
|
|
||||||
if (!uri) {
|
|
||||||
LOG(("Cannot get uri from the principal."));
|
|
||||||
return CheckTrackerForPrincipalPromise::CreateAndReject(NS_ERROR_FAILURE,
|
|
||||||
__func__);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv;
|
|
||||||
nsCOMPtr<nsIURIClassifier> uriClassifier =
|
|
||||||
mozilla::components::UrlClassifierDB::Service(&rv);
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
LOG(("Cannot get the uri classifier."));
|
|
||||||
return CheckTrackerForPrincipalPromise::CreateAndReject(rv, __func__);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check the uri of the principal with the tracking annotation features
|
|
||||||
// including the social tracker.
|
|
||||||
nsTArray<nsCString> featureNames = {"tracking-annotation"_ns,
|
|
||||||
"socialtracking-annotation"_ns};
|
|
||||||
nsTArray<RefPtr<nsIUrlClassifierFeature>> features;
|
|
||||||
|
|
||||||
for (auto& name : featureNames) {
|
|
||||||
nsCOMPtr<nsIUrlClassifierFeature> feature;
|
|
||||||
uriClassifier->GetFeatureByName(name, getter_AddRefs(feature));
|
|
||||||
MOZ_ASSERT(feature);
|
|
||||||
|
|
||||||
if (!feature) {
|
|
||||||
LOG(("Cannot get feature for feature name(%s)", name.get()));
|
|
||||||
return CheckTrackerForPrincipalPromise::CreateAndReject(NS_ERROR_FAILURE,
|
|
||||||
__func__);
|
|
||||||
}
|
|
||||||
features.AppendElement(feature);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto callback = MakeRefPtr<TrackerClassifierFeatureCallback>();
|
|
||||||
|
|
||||||
RefPtr<CheckTrackerForPrincipalPromise> promise = callback->Promise();
|
|
||||||
|
|
||||||
rv = uriClassifier->AsyncClassifyLocalWithFeatures(
|
|
||||||
uri, features, nsIUrlClassifierFeature::blocklist, callback);
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
LOG(("Fail on classifying the url."));
|
|
||||||
callback->Reject(rv);
|
|
||||||
}
|
|
||||||
|
|
||||||
return promise;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -211,32 +211,6 @@ class ContentBlocking final {
|
||||||
|
|
||||||
static void UpdateAllowAccessOnParentProcess(
|
static void UpdateAllowAccessOnParentProcess(
|
||||||
dom::BrowsingContext* aParentContext, const nsACString& aTrackingOrigin);
|
dom::BrowsingContext* aParentContext, const nsACString& aTrackingOrigin);
|
||||||
|
|
||||||
typedef MozPromise<uint32_t, nsresult, true> CheckTrackerForPrincipalPromise;
|
|
||||||
class TrackerClassifierFeatureCallback final
|
|
||||||
: public nsIUrlClassifierFeatureCallback {
|
|
||||||
public:
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
NS_DECL_NSIURLCLASSIFIERFEATURECALLBACK
|
|
||||||
|
|
||||||
RefPtr<CheckTrackerForPrincipalPromise> Promise() {
|
|
||||||
return mHolder.Ensure(__func__);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Reject(nsresult rv) { mHolder.Reject(rv, __func__); }
|
|
||||||
|
|
||||||
TrackerClassifierFeatureCallback() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
~TrackerClassifierFeatureCallback() = default;
|
|
||||||
|
|
||||||
MozPromiseHolder<CheckTrackerForPrincipalPromise> mHolder;
|
|
||||||
};
|
|
||||||
|
|
||||||
// This method checks if the given princpal belongs to a tracker or a social
|
|
||||||
// tracker.
|
|
||||||
[[nodiscard]] static RefPtr<CheckTrackerForPrincipalPromise>
|
|
||||||
CheckTrackerForPrincipal(nsIPrincipal* aPrincipal);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue