From e838ae8db3d9e5c92ea8093c6db50bd62b0e8e3a Mon Sep 17 00:00:00 2001 From: Arturo Mejia Date: Tue, 6 Oct 2020 16:30:36 -0400 Subject: [PATCH] Closes issue #8367: Add SHIMMED TrackingCategory --- .../mozilla/components/browser/engine/gecko/GeckoEngine.kt | 6 ++++++ .../components/browser/engine/gecko/GeckoEngineTest.kt | 5 ++++- .../mozilla/components/concept/engine/EngineSession.kt | 7 +++++++ docs/changelog.md | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt index 1774ccce2a4..c8078fe2fb5 100644 --- a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt +++ b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngine.kt @@ -4,6 +4,7 @@ package mozilla.components.browser.engine.gecko +import android.annotation.SuppressLint import android.content.Context import android.util.AttributeSet import androidx.annotation.VisibleForTesting @@ -684,12 +685,17 @@ internal fun ContentBlockingController.LogEntry.BlockingData.hasBlockedCookies() category == Event.COOKIES_BLOCKED_SOCIALTRACKER } +// There is going to be a patch from GV for adding [REPLACED_UNSAFE_CONTENT] as +// a valid option for [BlockingData.category] +// https://bugzilla.mozilla.org/show_bug.cgi?id=1669577 +@SuppressLint("SwitchIntDef") internal fun ContentBlockingController.LogEntry.BlockingData.getBlockedCategory(): TrackingCategory { return when (category) { Event.BLOCKED_FINGERPRINTING_CONTENT -> TrackingCategory.FINGERPRINTING Event.BLOCKED_CRYPTOMINING_CONTENT -> TrackingCategory.CRYPTOMINING Event.BLOCKED_SOCIALTRACKING_CONTENT, Event.COOKIES_BLOCKED_SOCIALTRACKER -> TrackingCategory.MOZILLA_SOCIAL Event.BLOCKED_TRACKING_CONTENT -> TrackingCategory.SCRIPTS_AND_SUB_RESOURCES + Event.REPLACED_UNSAFE_CONTENT -> TrackingCategory.SHIMMED else -> TrackingCategory.NONE } } diff --git a/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt b/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt index d42c29dbf19..de1d6f94d2f 100644 --- a/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt +++ b/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineTest.kt @@ -1686,6 +1686,7 @@ class GeckoEngineTest { assertTrue(trackerLog.blockedCategories.contains(TrackingCategory.FINGERPRINTING)) assertTrue(trackerLog.blockedCategories.contains(TrackingCategory.CRYPTOMINING)) assertTrue(trackerLog.blockedCategories.contains(TrackingCategory.MOZILLA_SOCIAL)) + assertTrue(trackerLog.blockedCategories.contains(TrackingCategory.SHIMMED)) assertTrue(trackerLog.loadedCategories.contains(TrackingCategory.SCRIPTS_AND_SUB_RESOURCES)) assertTrue(trackerLog.loadedCategories.contains(TrackingCategory.FINGERPRINTING)) @@ -1863,6 +1864,7 @@ class GeckoEngineTest { val blockedFingerprintingContent = createBlockingData(Event.BLOCKED_FINGERPRINTING_CONTENT) val blockedCyptominingContent = createBlockingData(Event.BLOCKED_CRYPTOMINING_CONTENT) val blockedSocialContent = createBlockingData(Event.BLOCKED_SOCIALTRACKING_CONTENT) + val shimmedContent = createBlockingData(Event.REPLACED_UNSAFE_CONTENT) val loadedTrackingLevel1Content = createBlockingData(Event.LOADED_LEVEL_1_TRACKING_CONTENT) val loadedTrackingLevel2Content = createBlockingData(Event.LOADED_LEVEL_2_TRACKING_CONTENT) @@ -1882,7 +1884,8 @@ class GeckoEngineTest { blockedSocialContent, loadedSocialContent, loadedCookieSocialTracker, - blockedCookieSocialTracker + blockedCookieSocialTracker, + shimmedContent ) val addLogSecondEntry = object : ContentBlockingController.LogEntry() {} diff --git a/components/concept/engine/src/main/java/mozilla/components/concept/engine/EngineSession.kt b/components/concept/engine/src/main/java/mozilla/components/concept/engine/EngineSession.kt index 9419443cfbc..34bfc8cc185 100644 --- a/components/concept/engine/src/main/java/mozilla/components/concept/engine/EngineSession.kt +++ b/components/concept/engine/src/main/java/mozilla/components/concept/engine/EngineSession.kt @@ -359,6 +359,13 @@ abstract class EngineSession( */ SCRIPTS_AND_SUB_RESOURCES(1 shl 31), + /** + * Indicates that content that would have been blocked has instead been replaced with a shim. + * This category is only used for categorization purposes ie. for checking the state of blocked content. + * It can not be used to actively configure a tracking protection policy. + */ + SHIMMED(NONE.id), + RECOMMENDED(AD.id + ANALYTICS.id + SOCIAL.id + TEST.id + MOZILLA_SOCIAL.id + CRYPTOMINING.id + FINGERPRINTING.id), diff --git a/docs/changelog.md b/docs/changelog.md index 25e456af91d..89876d3a421 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -13,6 +13,7 @@ permalink: /changelog/ * **concept-engine** * Added `MediaSession` for the media session API. + * 🌟 Added a new `TrackingCategory`.`SHIMMED` to indicate that content that would have been blocked has instead been replaced with a shimmed file. See more on [Fenix #14071](https://github.com/mozilla-mobile/fenix/issues/14071) * **browser-engine-gecko(-nightly)** * Added `GeckoMediaSessionController` and `GeckoMediaSessionDelegate` for the media session API.