|
|
@ -4,8 +4,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.mozilla.fenix.home.blocklist
|
|
|
|
package org.mozilla.fenix.home.blocklist
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
|
|
import androidx.annotation.VisibleForTesting
|
|
|
|
import androidx.annotation.VisibleForTesting
|
|
|
|
import mozilla.components.support.ktx.kotlin.sha1
|
|
|
|
import mozilla.components.support.ktx.kotlin.sha1
|
|
|
|
|
|
|
|
import org.mozilla.fenix.ext.containsQueryParameters
|
|
|
|
import org.mozilla.fenix.home.recentbookmarks.RecentBookmark
|
|
|
|
import org.mozilla.fenix.home.recentbookmarks.RecentBookmark
|
|
|
|
import org.mozilla.fenix.home.recentsyncedtabs.RecentSyncedTabState
|
|
|
|
import org.mozilla.fenix.home.recentsyncedtabs.RecentSyncedTabState
|
|
|
|
import org.mozilla.fenix.home.recenttabs.RecentTab
|
|
|
|
import org.mozilla.fenix.home.recenttabs.RecentTab
|
|
|
@ -16,6 +18,8 @@ import org.mozilla.fenix.utils.Settings
|
|
|
|
* Class for interacting with the a blocklist stored in [settings].
|
|
|
|
* Class for interacting with the a blocklist stored in [settings].
|
|
|
|
* The blocklist is a set of SHA1 hashed URLs, which are stripped
|
|
|
|
* The blocklist is a set of SHA1 hashed URLs, which are stripped
|
|
|
|
* of protocols and common subdomains like "www" or "mobile".
|
|
|
|
* of protocols and common subdomains like "www" or "mobile".
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Also used for filtering the sponsored URLs.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class BlocklistHandler(private val settings: Settings) {
|
|
|
|
class BlocklistHandler(private val settings: Settings) {
|
|
|
|
|
|
|
|
|
|
|
@ -52,6 +56,14 @@ class BlocklistHandler(private val settings: Settings) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Filter a list of recent tabs from sponsored urls.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@JvmName("filterContileRecentTab")
|
|
|
|
|
|
|
|
fun List<RecentTab>.filterContile(): List<RecentTab> = filterNot {
|
|
|
|
|
|
|
|
it is RecentTab.Tab &&
|
|
|
|
|
|
|
|
Uri.parse(it.state.content.url).containsQueryParameters(settings.frecencyFilterQuery)
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* If the state is set to [RecentSyncedTabState.Success], filter the list of recently synced
|
|
|
|
* If the state is set to [RecentSyncedTabState.Success], filter the list of recently synced
|
|
|
|
* tabs by the blocklist. If the filtered list of tabs is empty, change the state to
|
|
|
|
* tabs by the blocklist. If the filtered list of tabs is empty, change the state to
|
|
|
@ -74,6 +86,24 @@ class BlocklistHandler(private val settings: Settings) {
|
|
|
|
this
|
|
|
|
this
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Filter a list of recently synced tabs of sponsored urls if the state is
|
|
|
|
|
|
|
|
* [RecentSyncedTabState.Success].
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@JvmName("filterContileRecentSyncedTab")
|
|
|
|
|
|
|
|
fun RecentSyncedTabState.filterContile() = if (this is RecentSyncedTabState.Success) {
|
|
|
|
|
|
|
|
val filteredTabs = this.tabs.filterNot {
|
|
|
|
|
|
|
|
Uri.parse(it.url).containsQueryParameters(settings.frecencyFilterQuery)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filteredTabs.isEmpty()) {
|
|
|
|
|
|
|
|
RecentSyncedTabState.None
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
RecentSyncedTabState.Success(filteredTabs)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Filter a list of recent history items by the blocklist. Requires this class to be contextually
|
|
|
|
* Filter a list of recent history items by the blocklist. Requires this class to be contextually
|
|
|
|
* in a scope.
|
|
|
|
* in a scope.
|
|
|
@ -87,6 +117,15 @@ class BlocklistHandler(private val settings: Settings) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Filter a list of recently visited history items of sponsored urls.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@JvmName("filterContileRecentlyVisited")
|
|
|
|
|
|
|
|
fun List<RecentlyVisitedItem>.filterContile(): List<RecentlyVisitedItem> = filterNot {
|
|
|
|
|
|
|
|
it is RecentlyVisitedItem.RecentHistoryHighlight &&
|
|
|
|
|
|
|
|
Uri.parse(it.url).containsQueryParameters(settings.frecencyFilterQuery)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun blocklistContainsUrl(blocklist: Set<String>, url: String): Boolean =
|
|
|
|
private fun blocklistContainsUrl(blocklist: Set<String>, url: String): Boolean =
|
|
|
|
blocklist.any { it == url.stripAndHash() }
|
|
|
|
blocklist.any { it == url.stripAndHash() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|