diff --git a/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/SystemEngineView.kt b/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/SystemEngineView.kt index 4c137434b8d..4f48eee5fab 100644 --- a/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/SystemEngineView.kt +++ b/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/SystemEngineView.kt @@ -828,8 +828,8 @@ class SystemEngineView @JvmOverloads constructor( URL_MATCHER?.setCategoriesEnabled(categories) ?: run { URL_MATCHER = UrlMatcher.createMatcher( resources, - R.raw.domain_blacklist, - R.raw.domain_whitelist, + R.raw.domain_blocklist, + R.raw.domain_safelist, categories) } diff --git a/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/matcher/WhiteList.kt b/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/matcher/Safelist.kt similarity index 66% rename from components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/matcher/WhiteList.kt rename to components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/matcher/Safelist.kt index f7295fa5df7..8051dc53452 100644 --- a/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/matcher/WhiteList.kt +++ b/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/matcher/Safelist.kt @@ -10,23 +10,23 @@ import android.util.JsonReader import java.util.ArrayList /** - * Stores white-listed URIs for individual hosts. + * Stores safe-listed URIs for individual hosts. */ -internal class WhiteList { - private val rootNode: WhiteListTrie = WhiteListTrie.createRootNode() +internal class Safelist { + private val rootNode: SafelistTrie = SafelistTrie.createRootNode() /** - * Adds the provided whitelist for the provided host. + * Adds the provided safelist for the provided host. * * @param host the reversed host URI ("foo.com".reverse()) - * @param whitelist a [Trie] representing the white-listed URIs + * @param safelist a [Trie] representing the safe-listed URIs */ - fun put(host: ReversibleString, whitelist: Trie) { - rootNode.putWhiteList(host, whitelist) + fun put(host: ReversibleString, safelist: Trie) { + rootNode.putSafelist(host, safelist) } /** - * Checks if the given resource is white-listed for the given host. + * Checks if the given resource is safe-listed for the given host. * * @param host the host URI as string ("foo.com") * @param host the resources URI as string ("bar.com") @@ -36,7 +36,7 @@ internal class WhiteList { } /** - * Checks if the given resource is white-listed for the given host. + * Checks if the given resource is safe-listed for the given host. * * @param hostUri the host URI * @param resource the resources URI @@ -53,9 +53,9 @@ internal class WhiteList { } private fun contains(site: ReversibleString, resource: ReversibleString, revHostTrie: Trie): Boolean { - val next = revHostTrie.children.get(site.charAt(0).toInt()) as? WhiteListTrie ?: return false + val next = revHostTrie.children.get(site.charAt(0).toInt()) as? SafelistTrie ?: return false - if (next.whitelist?.findNode(resource) != null) { + if (next.safelist?.findNode(resource) != null) { return true } @@ -83,21 +83,21 @@ internal class WhiteList { companion object { /** - * Parses json for white-listed URIs. + * Parses json for safe-listed URIs. * * @param reader a JsonReader - * @return the white list. + * @return the safe list. */ @Suppress("NestedBlockDepth") - fun fromJson(reader: JsonReader): WhiteList { - val whiteList = WhiteList() + fun fromJson(reader: JsonReader): Safelist { + val safelist = Safelist() reader.beginObject() while (reader.hasNext()) { reader.skipValue() reader.beginObject() - val whitelistTrie = Trie.createRootNode() + val safelistTrie = Trie.createRootNode() val propertyList = ArrayList() while (reader.hasNext()) { val itemName = reader.nextName() @@ -110,66 +110,66 @@ internal class WhiteList { } else if (itemName == "resources") { reader.beginArray() while (reader.hasNext()) { - whitelistTrie.put(reader.nextString().reverse()) + safelistTrie.put(reader.nextString().reverse()) } reader.endArray() } } - propertyList.forEach { whiteList.put(it.reverse(), whitelistTrie) } + propertyList.forEach { safelist.put(it.reverse(), safelistTrie) } reader.endObject() } reader.endObject() - return whiteList + return safelist } } } /** - * A [Trie] implementation which stores a white list (another [Trie]). + * A [Trie] implementation which stores a safe list (another [Trie]). */ -internal class WhiteListTrie private constructor(character: Char, parent: WhiteListTrie?) : Trie(character, parent) { - var whitelist: Trie? = null +internal class SafelistTrie private constructor(character: Char, parent: SafelistTrie?) : Trie(character, parent) { + var safelist: Trie? = null override fun createNode(character: Char, parent: Trie): Trie { - return WhiteListTrie(character, parent as WhiteListTrie) + return SafelistTrie(character, parent as SafelistTrie) } /** * Adds new nodes (recursively) for all chars in the provided string and stores - * the provide whitelist Trie. + * the provide safelist Trie. * * @param string the string for which a node should be added. - * @param whitelist the whitelist to store. + * @param safelist the safelist to store. * @return the newly created node or the existing one. */ - fun putWhiteList(string: String, whitelist: Trie) { - this.putWhiteList(string.reversible(), whitelist) + fun putSafelist(string: String, safelist: Trie) { + this.putSafelist(string.reversible(), safelist) } /** * Adds new nodes (recursively) for all chars in the provided string and stores - * the provide whitelist Trie. + * the provide safelist Trie. * * @param string the string for which a node should be added. - * @param whitelist the whitelist to store. + * @param safelist the safelist to store. * @return the newly created node or the existing one. */ - fun putWhiteList(string: ReversibleString, whitelist: Trie) { - val node = super.put(string) as WhiteListTrie + fun putSafelist(string: ReversibleString, safelist: Trie) { + val node = super.put(string) as SafelistTrie - if (node.whitelist != null) { - throw IllegalStateException("Whitelist already set for node $string") + if (node.safelist != null) { + throw IllegalStateException("Safelist already set for node $string") } - node.whitelist = whitelist + node.safelist = safelist } companion object { /** * Creates a new root node. */ - fun createRootNode(): WhiteListTrie { - return WhiteListTrie(Character.MIN_VALUE, null) + fun createRootNode(): SafelistTrie { + return SafelistTrie(Character.MIN_VALUE, null) } } } diff --git a/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/matcher/UrlMatcher.kt b/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/matcher/UrlMatcher.kt index 4095ac2c54c..b8042c9ff9a 100644 --- a/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/matcher/UrlMatcher.kt +++ b/components/browser/engine-system/src/main/java/mozilla/components/browser/engine/system/matcher/UrlMatcher.kt @@ -15,20 +15,20 @@ import java.nio.charset.StandardCharsets.UTF_8 import java.util.LinkedList /** - * Provides functionality to process categorized URL black/white lists and match + * Provides functionality to process categorized URL block/safe lists and match * URLs against these lists. */ class UrlMatcher { private val categories: MutableMap internal val enabledCategories = HashSet() - private val whiteList: WhiteList? + private val safelist: Safelist? private val previouslyMatched = HashSet() private val previouslyUnmatched = HashSet() constructor(patterns: Array) { categories = HashMap() - whiteList = null + safelist = null val defaultCategory = Trie.createRootNode() patterns.forEach { defaultCategory.put(it.reverse()) } @@ -40,9 +40,9 @@ class UrlMatcher { enabledCategories: Set, supportedCategories: Set, categoryMap: MutableMap, - whiteList: WhiteList? = null + safelist: Safelist? = null ) { - this.whiteList = whiteList + this.safelist = safelist this.categories = categoryMap for ((key) in categoryMap) { @@ -85,7 +85,7 @@ class UrlMatcher { } /** - * Checks if the given page URI is blacklisted for the given resource URI. + * Checks if the given page URI is blocklisted for the given resource URI. * Returns true if the site (page URI) is allowed to access * the resource URI, otherwise false. * @@ -99,7 +99,7 @@ class UrlMatcher { } /** - * Checks if the given page URI is blacklisted for the given resource URI. + * Checks if the given page URI is blocklisted for the given resource URI. * Returns true if the site (page URI) is allowed to access * the resource URI, otherwise false. * @@ -119,7 +119,7 @@ class UrlMatcher { return notMatchesFound } - if (whiteList?.contains(pageURI, resourceURI) == true) { + if (safelist?.contains(pageURI, resourceURI) == true) { return notMatchesFound } @@ -170,54 +170,54 @@ class UrlMatcher { * Creates a new matcher instance for the provided URL lists. * * @deprecated Pass resources directly - * @param blackListFile resource ID to a JSON file containing the black list - * @param whiteListFile resource ID to a JSON file containing the white list + * @param blocklistFile resource ID to a JSON file containing the block list + * @param safelistFile resource ID to a JSON file containing the safe list */ fun createMatcher( context: Context, - @RawRes blackListFile: Int, - @RawRes whiteListFile: Int, + @RawRes blocklistFile: Int, + @RawRes safelistFile: Int, enabledCategories: Set = supportedCategories ): UrlMatcher = - createMatcher(context.resources, blackListFile, whiteListFile, enabledCategories) + createMatcher(context.resources, blocklistFile, safelistFile, enabledCategories) /** * Creates a new matcher instance for the provided URL lists. * - * @param blackListFile resource ID to a JSON file containing the black list - * @param whiteListFile resource ID to a JSON file containing the white list + * @param blocklistFile resource ID to a JSON file containing the block list + * @param safelistFile resource ID to a JSON file containing the safe list */ fun createMatcher( resources: Resources, - @RawRes blackListFile: Int, - @RawRes whiteListFile: Int, + @RawRes blocklistFile: Int, + @RawRes safelistFile: Int, enabledCategories: Set = supportedCategories ): UrlMatcher { - val blackListReader = InputStreamReader(resources.openRawResource(blackListFile), UTF_8) - val whiteListReader = InputStreamReader(resources.openRawResource(whiteListFile), UTF_8) - return createMatcher(blackListReader, whiteListReader, enabledCategories) + val blocklistReader = InputStreamReader(resources.openRawResource(blocklistFile), UTF_8) + val safelistReader = InputStreamReader(resources.openRawResource(safelistFile), UTF_8) + return createMatcher(blocklistReader, safelistReader, enabledCategories) } /** * Creates a new matcher instance for the provided URL lists. * - * @param black reader containing the black list - * @param white resource ID to a JSON file containing the white list + * @param block reader containing the block list + * @param safe resource ID to a JSON file containing the safe list */ fun createMatcher( - black: Reader, - white: Reader, + block: Reader, + safe: Reader, enabledCategories: Set = supportedCategories ): UrlMatcher { val categoryMap = HashMap() - JsonReader(black).use { + JsonReader(block).use { jsonReader -> loadCategories(jsonReader, categoryMap) } - var whiteList: WhiteList? - JsonReader(white).use { jsonReader -> whiteList = WhiteList.fromJson(jsonReader) } - return UrlMatcher(enabledCategories, supportedCategories, categoryMap, whiteList) + var safelist: Safelist? + JsonReader(safe).use { jsonReader -> safelist = Safelist.fromJson(jsonReader) } + return UrlMatcher(enabledCategories, supportedCategories, categoryMap, safelist) } /** diff --git a/components/browser/engine-system/src/main/res/raw/domain_blacklist.json b/components/browser/engine-system/src/main/res/raw/domain_blocklist.json similarity index 100% rename from components/browser/engine-system/src/main/res/raw/domain_blacklist.json rename to components/browser/engine-system/src/main/res/raw/domain_blocklist.json diff --git a/components/browser/engine-system/src/main/res/raw/domain_whitelist.json b/components/browser/engine-system/src/main/res/raw/domain_safelist.json similarity index 100% rename from components/browser/engine-system/src/main/res/raw/domain_whitelist.json rename to components/browser/engine-system/src/main/res/raw/domain_safelist.json diff --git a/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/matcher/SafelistTest.kt b/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/matcher/SafelistTest.kt new file mode 100644 index 00000000000..3b793938e1d --- /dev/null +++ b/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/matcher/SafelistTest.kt @@ -0,0 +1,126 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package mozilla.components.browser.engine.system.matcher + +import android.util.JsonReader +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Assert +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Assert.fail +import org.junit.Test +import org.junit.runner.RunWith +import java.io.StringReader + +@RunWith(AndroidJUnit4::class) +class SafelistTest { + + /** + * Test setup: + * mozilla.org: allow foo.com + * foo.mozilla.org: additionally allow bar.com + * + * Test: + * mozilla.org can only use foo.com, but foo.mozilla.org can use both foo.com and bar.com + */ + @Test + fun safelist() { + val mozillaOrg = "mozilla.org" + val fooMozillaOrg = "foo.mozilla.org" + val fooCom = "foo.com" + val barCom = "bar.com" + + val fooComTrie = Trie.createRootNode() + fooComTrie.put(fooCom.reverse()) + + val barComTrie = Trie.createRootNode() + barComTrie.put(barCom.reverse()) + + val safelist = Safelist() + safelist.put(mozillaOrg.reverse(), fooComTrie) + safelist.put(fooMozillaOrg.reverse(), barComTrie) + + assertTrue(safelist.contains("http://$mozillaOrg", "http://$fooCom")) + assertFalse(safelist.contains("http://$mozillaOrg", "http://$barCom")) + assertTrue(safelist.contains("http://hello.$mozillaOrg", "http://$fooCom")) + assertFalse(safelist.contains("http://hello.$mozillaOrg", "http://$barCom")) + assertTrue(safelist.contains("http://$mozillaOrg/somewhere", "http://$fooCom/somewhereElse/bla/bla")) + assertFalse(safelist.contains("http://$mozillaOrg/another/page.html?u=a", "http://$barCom/hello")) + + assertTrue(safelist.contains("http://$fooMozillaOrg", "http://$fooCom")) + assertTrue(safelist.contains("http://$fooMozillaOrg", "http://$barCom")) + assertTrue(safelist.contains("http://hello.$fooMozillaOrg", "http://$fooCom")) + assertTrue(safelist.contains("http://hello.$fooMozillaOrg", "http://$barCom")) + assertTrue(safelist.contains("http://$fooMozillaOrg/somewhere", "http://$fooCom/somewhereElse/bla/bla")) + assertTrue(safelist.contains("http://$fooMozillaOrg/another/page.html?u=a", "http://$barCom/hello")) + + // Test some invalid inputs + assertFalse(safelist.contains("http://$barCom", "http://$barCom")) + assertFalse(safelist.contains("http://$barCom", "http://$mozillaOrg")) + + // Check we don't safelist resources for data: + assertFalse(safelist.contains("data:text/html;stuff", "http://$fooCom/somewhereElse/bla/bla")) + } + + @Test + fun safelistTrie() { + val safelist = Trie.createRootNode() + safelist.put("abc") + + val trie = SafelistTrie.createRootNode() + trie.putSafelist("def", safelist) + Assert.assertNull(trie.findNode("abc")) + + val foundSafelist = trie.findNode("def") as SafelistTrie + Assert.assertNotNull(foundSafelist) + Assert.assertNotNull(foundSafelist.safelist?.findNode("abc")) + + try { + trie.putSafelist("def", safelist) + fail("Expected IllegalStateException") + } catch (e: IllegalStateException) { } + } + + val SAFE_LIST_JSON = """{ + "Host1": { + "properties": [ + "host1.com", + "host1.de" + ], + "resources": [ + "host1ads.com", + "host1ads.de" + ] + }, + "Host2": { + "properties": [ + "host2.com", + "host2.de" + ], + "resources": [ + "host2ads.com", + "host2ads.de" + ] + } + }""" + + @Test + fun fromJson() { + val safelist = Safelist.fromJson(JsonReader(StringReader(SAFE_LIST_JSON))) + + assertTrue(safelist.contains("http://host1.com", "http://host1ads.com")) + assertTrue(safelist.contains("https://host1.com", "https://host1ads.de")) + assertTrue(safelist.contains("javascript://host1.de", "javascript://host1ads.com")) + assertTrue(safelist.contains("file://host1.de", "file://host1ads.de")) + + assertTrue(safelist.contains("http://host2.com", "http://host2ads.com")) + assertTrue(safelist.contains("about://host2.com", "about://host2ads.de")) + assertTrue(safelist.contains("http://host2.de", "http://host2ads.com")) + assertTrue(safelist.contains("http://host2.de", "http://host2ads.de")) + + assertFalse(safelist.contains("data://host2.de", "data://host2ads.de")) + assertFalse(safelist.contains("foo://host2.de", "foo://host2ads.de")) + } +} \ No newline at end of file diff --git a/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/matcher/UrlMatcherTest.kt b/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/matcher/UrlMatcherTest.kt index 07ebd548e88..29e314f7f58 100644 --- a/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/matcher/UrlMatcherTest.kt +++ b/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/matcher/UrlMatcherTest.kt @@ -184,7 +184,7 @@ class UrlMatcherTest { } """ - val WHITE_LIST = """{ + val SAFE_LIST = """{ "SocialTest1": { "properties": [ "www.socialtest1.com" @@ -198,7 +198,7 @@ class UrlMatcherTest { fun createMatcher() { val matcher = UrlMatcher.createMatcher( StringReader(BLOCK_LIST), - StringReader(WHITE_LIST)) + StringReader(SAFE_LIST)) // Check returns correct category val (matchesAds, categoryAds) = matcher.matches("http://adtest1.com", "http://www.adtest1.com") @@ -235,7 +235,7 @@ class UrlMatcherTest { assertTrue(matchesAnalytics) assertEquals(categoryAnalytics, ANALYTICS) - // Check that white list worked + // Check that safe list worked assertTrue(matcher.matches("http://socialtest1.com", "http://www.socialtest1.com").first) assertFalse(matcher.matches("http://socialtest1.de", "http://www.socialtest1.com").first) @@ -259,7 +259,7 @@ class UrlMatcherTest { fun setCategoriesEnabled() { val matcher = spy(UrlMatcher.createMatcher( StringReader(BLOCK_LIST), - StringReader(WHITE_LIST), + StringReader(SAFE_LIST), setOf("Advertising", "Analytics")) ) @@ -276,7 +276,7 @@ class UrlMatcherTest { fun webFontsNotBlockedByDefault() { val matcher = UrlMatcher.createMatcher( StringReader(BLOCK_LIST), - StringReader(WHITE_LIST), + StringReader(SAFE_LIST), setOf(UrlMatcher.ADVERTISING, UrlMatcher.ANALYTICS, UrlMatcher.SOCIAL, UrlMatcher.CONTENT)) assertFalse( diff --git a/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/matcher/WhiteListTest.kt b/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/matcher/WhiteListTest.kt deleted file mode 100644 index d7d614f4d05..00000000000 --- a/components/browser/engine-system/src/test/java/mozilla/components/browser/engine/system/matcher/WhiteListTest.kt +++ /dev/null @@ -1,126 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package mozilla.components.browser.engine.system.matcher - -import android.util.JsonReader -import androidx.test.ext.junit.runners.AndroidJUnit4 -import org.junit.Assert -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue -import org.junit.Assert.fail -import org.junit.Test -import org.junit.runner.RunWith -import java.io.StringReader - -@RunWith(AndroidJUnit4::class) -class WhiteListTest { - - /** - * Test setup: - * mozilla.org: allow foo.com - * foo.mozilla.org: additionally allow bar.com - * - * Test: - * mozilla.org can only use foo.com, but foo.mozilla.org can use both foo.com and bar.com - */ - @Test - fun whiteList() { - val mozillaOrg = "mozilla.org" - val fooMozillaOrg = "foo.mozilla.org" - val fooCom = "foo.com" - val barCom = "bar.com" - - val fooComTrie = Trie.createRootNode() - fooComTrie.put(fooCom.reverse()) - - val barComTrie = Trie.createRootNode() - barComTrie.put(barCom.reverse()) - - val whiteList = WhiteList() - whiteList.put(mozillaOrg.reverse(), fooComTrie) - whiteList.put(fooMozillaOrg.reverse(), barComTrie) - - assertTrue(whiteList.contains("http://$mozillaOrg", "http://$fooCom")) - assertFalse(whiteList.contains("http://$mozillaOrg", "http://$barCom")) - assertTrue(whiteList.contains("http://hello.$mozillaOrg", "http://$fooCom")) - assertFalse(whiteList.contains("http://hello.$mozillaOrg", "http://$barCom")) - assertTrue(whiteList.contains("http://$mozillaOrg/somewhere", "http://$fooCom/somewhereElse/bla/bla")) - assertFalse(whiteList.contains("http://$mozillaOrg/another/page.html?u=a", "http://$barCom/hello")) - - assertTrue(whiteList.contains("http://$fooMozillaOrg", "http://$fooCom")) - assertTrue(whiteList.contains("http://$fooMozillaOrg", "http://$barCom")) - assertTrue(whiteList.contains("http://hello.$fooMozillaOrg", "http://$fooCom")) - assertTrue(whiteList.contains("http://hello.$fooMozillaOrg", "http://$barCom")) - assertTrue(whiteList.contains("http://$fooMozillaOrg/somewhere", "http://$fooCom/somewhereElse/bla/bla")) - assertTrue(whiteList.contains("http://$fooMozillaOrg/another/page.html?u=a", "http://$barCom/hello")) - - // Test some invalid inputs - assertFalse(whiteList.contains("http://$barCom", "http://$barCom")) - assertFalse(whiteList.contains("http://$barCom", "http://$mozillaOrg")) - - // Check we don't whitelist resources for data: - assertFalse(whiteList.contains("data:text/html;stuff", "http://$fooCom/somewhereElse/bla/bla")) - } - - @Test - fun whiteListTrie() { - val whitelist = Trie.createRootNode() - whitelist.put("abc") - - val trie = WhiteListTrie.createRootNode() - trie.putWhiteList("def", whitelist) - Assert.assertNull(trie.findNode("abc")) - - val foundWhitelist = trie.findNode("def") as WhiteListTrie - Assert.assertNotNull(foundWhitelist) - Assert.assertNotNull(foundWhitelist.whitelist?.findNode("abc")) - - try { - trie.putWhiteList("def", whitelist) - fail("Expected IllegalStateException") - } catch (e: IllegalStateException) { } - } - - val WHITE_LIST_JSON = """{ - "Host1": { - "properties": [ - "host1.com", - "host1.de" - ], - "resources": [ - "host1ads.com", - "host1ads.de" - ] - }, - "Host2": { - "properties": [ - "host2.com", - "host2.de" - ], - "resources": [ - "host2ads.com", - "host2ads.de" - ] - } - }""" - - @Test - fun fromJson() { - val whiteList = WhiteList.fromJson(JsonReader(StringReader(WHITE_LIST_JSON))) - - assertTrue(whiteList.contains("http://host1.com", "http://host1ads.com")) - assertTrue(whiteList.contains("https://host1.com", "https://host1ads.de")) - assertTrue(whiteList.contains("javascript://host1.de", "javascript://host1ads.com")) - assertTrue(whiteList.contains("file://host1.de", "file://host1ads.de")) - - assertTrue(whiteList.contains("http://host2.com", "http://host2ads.com")) - assertTrue(whiteList.contains("about://host2.com", "about://host2ads.de")) - assertTrue(whiteList.contains("http://host2.de", "http://host2ads.com")) - assertTrue(whiteList.contains("http://host2.de", "http://host2ads.de")) - - assertFalse(whiteList.contains("data://host2.de", "data://host2ads.de")) - assertFalse(whiteList.contains("foo://host2.de", "foo://host2ads.de")) - } -} \ No newline at end of file diff --git a/components/feature/addons/src/test/resources/collection.json b/components/feature/addons/src/test/resources/collection.json index 0e16d43397d..78e5e99734e 100644 --- a/components/feature/addons/src/test/resources/collection.json +++ b/components/feature/addons/src/test/resources/collection.json @@ -89,7 +89,7 @@ "url": "http://www.gnu.org/licenses/gpl-3.0.html" }, "release_notes": { - "en-US": "See release notes.\n\nNew:\n\nStatic filter option elemhide as per ABP semantic\n\nThe elemhide option is now fully supported, rather than being an alias of generichide. The elemhide option will be internally converted into two filters, generichide and specifichide. There have been cases raised by filter list maintainers where specifichide would be useful. Additionally, the filter options elemhide, generichide and specifichide can be aliased with ehide, ghide and shide respectively. (generichide appears over 1,300 times just in \"uBlock filters\".)\n\nClosed as fixed:\n\n\nCommits with no entry in issue tracker:\n\n\nCommits history since 1.22.4." + "en-US": "See release notes.\n\nNew:\n\nStatic filter option elemhide as per ABP semantic\n\nThe elemhide option is now fully supported, rather than being an alias of generichide. The elemhide option will be internally converted into two filters, generichide and specifichide. There have been cases raised by filter list maintainers where specifichide would be useful. Additionally, the filter options elemhide, generichide and specifichide can be aliased with ehide, ghide and shide respectively. (generichide appears over 1,300 times just in \"uBlock filters\".)\n\nClosed as fixed:\n\n\nCommits with no entry in issue tracker:\n\n\nCommits history since 1.22.4." }, "reviewed": null, "version": "1.23.0" diff --git a/components/feature/addons/src/test/resources/collection_with_empty_values.json b/components/feature/addons/src/test/resources/collection_with_empty_values.json index e54031cbdb0..d8fb4ab6a6c 100644 --- a/components/feature/addons/src/test/resources/collection_with_empty_values.json +++ b/components/feature/addons/src/test/resources/collection_with_empty_values.json @@ -72,7 +72,7 @@ "url": "http://www.gnu.org/licenses/gpl-3.0.html" }, "release_notes": { - "en-US": "See release notes.\n\nNew:\n\nStatic filter option elemhide as per ABP semantic\n\nThe elemhide option is now fully supported, rather than being an alias of generichide. The elemhide option will be internally converted into two filters, generichide and specifichide. There have been cases raised by filter list maintainers where specifichide would be useful. Additionally, the filter options elemhide, generichide and specifichide can be aliased with ehide, ghide and shide respectively. (generichide appears over 1,300 times just in \"uBlock filters\".)\n\nClosed as fixed:\n\n\nCommits with no entry in issue tracker:\n\n\nCommits history since 1.22.4." + "en-US": "See release notes.\n\nNew:\n\nStatic filter option elemhide as per ABP semantic\n\nThe elemhide option is now fully supported, rather than being an alias of generichide. The elemhide option will be internally converted into two filters, generichide and specifichide. There have been cases raised by filter list maintainers where specifichide would be useful. Additionally, the filter options elemhide, generichide and specifichide can be aliased with ehide, ghide and shide respectively. (generichide appears over 1,300 times just in \"uBlock filters\".)\n\nClosed as fixed:\n\n\nCommits with no entry in issue tracker:\n\n\nCommits history since 1.22.4." }, "reviewed": null, "version": null diff --git a/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksInterceptor.kt b/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksInterceptor.kt index b501be316a5..98af7c02604 100644 --- a/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksInterceptor.kt +++ b/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksInterceptor.kt @@ -79,9 +79,9 @@ class AppLinksInterceptor( // or if we're already on the site then let's not go to an external app. ((!hasUserGesture && !isAllowedRedirect && !isDirectNavigation) || isSameDomain(lastUri, uri)) && engineSupportsScheme -> true - // If scheme not in whitelist then follow user preference + // If scheme not in safelist then follow user preference (!interceptLinkClicks || !launchInApp()) && engineSupportsScheme -> true - // Never go to an external app when scheme is in blacklist + // Never go to an external app when scheme is in blocklist alwaysDeniedSchemes.contains(uriScheme) -> true else -> false } diff --git a/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksInterceptorTest.kt b/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksInterceptorTest.kt index 1a0d97d4d48..f003174ef34 100644 --- a/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksInterceptorTest.kt +++ b/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksInterceptorTest.kt @@ -161,21 +161,21 @@ class AppLinksInterceptorTest { } @Test - fun `black listed schemes request not intercepted when triggered by user clicking on a link`() { + fun `block listed schemes request not intercepted when triggered by user clicking on a link`() { val engineSession: EngineSession = mock() - val blacklistedScheme = "blacklisted" + val blocklistedScheme = "blocklisted" val feature = AppLinksInterceptor( context = mockContext, interceptLinkClicks = true, - alwaysDeniedSchemes = setOf(blacklistedScheme), + alwaysDeniedSchemes = setOf(blocklistedScheme), launchInApp = { true }, useCases = mockUseCases ) - val blackListedUrl = "$blacklistedScheme://example.com" - val blacklistedRedirect = AppLinkRedirect(Intent.parseUri(blackListedUrl, 0), blackListedUrl, null) - whenever(mockGetRedirect.invoke(blackListedUrl)).thenReturn(blacklistedRedirect) - var response = feature.onLoadRequest(engineSession, blackListedUrl, null, true, false, false, false, false) + val blocklistedUrl = "$blocklistedScheme://example.com" + val blocklistedRedirect = AppLinkRedirect(Intent.parseUri(blocklistedUrl, 0), blocklistedUrl, null) + whenever(mockGetRedirect.invoke(blocklistedUrl)).thenReturn(blocklistedRedirect) + var response = feature.onLoadRequest(engineSession, blocklistedUrl, null, true, false, false, false, false) assertEquals(null, response) } @@ -241,12 +241,12 @@ class AppLinksInterceptorTest { val engineSession: EngineSession = mock() val supportedScheme = "supported" val notSupportedScheme = "not_supported" - val blacklistedScheme = "blacklisted" + val blocklistedScheme = "blocklisted" val feature = AppLinksInterceptor( context = mockContext, interceptLinkClicks = false, engineSupportedSchemes = setOf(supportedScheme), - alwaysDeniedSchemes = setOf(blacklistedScheme), + alwaysDeniedSchemes = setOf(blocklistedScheme), launchInApp = { false }, useCases = mockUseCases ) @@ -259,7 +259,7 @@ class AppLinksInterceptorTest { } @Test - fun `blacklisted schemes request always ignored even if the engine does not support it`() { + fun `blocklisted schemes request always ignored even if the engine does not support it`() { val engineSession: EngineSession = mock() val supportedScheme = "supported" val notSupportedScheme = "not_supported" @@ -284,12 +284,12 @@ class AppLinksInterceptorTest { val engineSession: EngineSession = mock() val supportedScheme = "supported" val notSupportedScheme = "not_supported" - val blacklistedScheme = "blacklisted" + val blocklistedScheme = "blocklisted" val feature = AppLinksInterceptor( context = mockContext, interceptLinkClicks = false, engineSupportedSchemes = setOf(supportedScheme), - alwaysDeniedSchemes = setOf(blacklistedScheme), + alwaysDeniedSchemes = setOf(blocklistedScheme), launchInApp = { true }, useCases = mockUseCases ) @@ -306,12 +306,12 @@ class AppLinksInterceptorTest { val engineSession: EngineSession = mock() val supportedScheme = "supported" val notSupportedScheme = "not_supported" - val blacklistedScheme = "blacklisted" + val blocklistedScheme = "blocklisted" val feature = AppLinksInterceptor( context = mockContext, interceptLinkClicks = true, engineSupportedSchemes = setOf(supportedScheme), - alwaysDeniedSchemes = setOf(blacklistedScheme), + alwaysDeniedSchemes = setOf(blocklistedScheme), launchInApp = { false }, useCases = mockUseCases ) @@ -329,12 +329,12 @@ class AppLinksInterceptorTest { val engineSession: EngineSession = mock() val supportedScheme = "supported" val notSupportedScheme = "not_supported" - val blacklistedScheme = "blacklisted" + val blocklistedScheme = "blocklisted" val feature = AppLinksInterceptor( context = mockContext, interceptLinkClicks = true, engineSupportedSchemes = setOf(supportedScheme), - alwaysDeniedSchemes = setOf(blacklistedScheme), + alwaysDeniedSchemes = setOf(blocklistedScheme), launchInApp = { false }, useCases = mockUseCases ) diff --git a/components/feature/webcompat-reporter/README.md b/components/feature/webcompat-reporter/README.md index 311eaeaefc7..88ad600f91e 100644 --- a/components/feature/webcompat-reporter/README.md +++ b/components/feature/webcompat-reporter/README.md @@ -30,7 +30,7 @@ The `install` function has an optional second parameter, `productName`. This all WebCompatReporterFeature.install(engine, "fenix") ``` -would add the `browser-fenix` label to the report. Note that simply inventing new values here does not work, as each product name has to be whitelisted by the WebCompat team on webcompat.com, so [please get in touch](https://wiki.mozilla.org/Compatibility#Core_Team) when you need to add a new product name. +would add the `browser-fenix` label to the report. Note that simply inventing new values here does not work, as each product name has to be safelisted by the WebCompat team on webcompat.com, so [please get in touch](https://wiki.mozilla.org/Compatibility#Core_Team) when you need to add a new product name. ## License diff --git a/components/feature/webcompat/src/main/assets/extensions/webcompat/experiment-apis/matchPatterns.json b/components/feature/webcompat/src/main/assets/extensions/webcompat/experiment-apis/matchPatterns.json index 4df6ada1ef9..a42ee02b940 100644 --- a/components/feature/webcompat/src/main/assets/extensions/webcompat/experiment-apis/matchPatterns.json +++ b/components/feature/webcompat/src/main/assets/extensions/webcompat/experiment-apis/matchPatterns.json @@ -10,7 +10,7 @@ "parameters": [ { "name": "patterns", - "description": "Array of string URL patterns to whitelist", + "description": "Array of string URL patterns to safelist", "type": "array", "items": { "type": "string" diff --git a/components/lib/crash/README.md b/components/lib/crash/README.md index 81c88ad94f1..bd45f838eb8 100644 --- a/components/lib/crash/README.md +++ b/components/lib/crash/README.md @@ -87,7 +87,7 @@ SentryService( [Socorro](https://wiki.mozilla.org/Socorro) is the name for the [Mozilla Crash Stats](https://crash-stats.mozilla.org/) project. -⚠️ Note: Socorro filters crashes by "app name". New app names need to be whitelisted for the server to accept the crash. [File a bug](https://bugzilla.mozilla.org/enter_bug.cgi?product=Socorro) if you would like to get your app added to the whitelist. +⚠️ Note: Socorro filters crashes by "app name". New app names need to be safelisted for the server to accept the crash. [File a bug](https://bugzilla.mozilla.org/enter_bug.cgi?product=Socorro) if you would like to get your app added to the safelist. Add a `MozillaSocorroService` instance to your `CrashReporter` in order to upload crashes to Socorro: diff --git a/components/lib/crash/src/main/java/mozilla/components/lib/crash/service/MozillaSocorroService.kt b/components/lib/crash/src/main/java/mozilla/components/lib/crash/service/MozillaSocorroService.kt index 7035819e9f7..b1cd0323e1d 100644 --- a/components/lib/crash/src/main/java/mozilla/components/lib/crash/service/MozillaSocorroService.kt +++ b/components/lib/crash/src/main/java/mozilla/components/lib/crash/service/MozillaSocorroService.kt @@ -62,9 +62,9 @@ private const val FILE_REGEX = "([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4} * * @param applicationContext The application [Context]. * @param appName A human-readable app name. This name is used on crash-stats.mozilla.com to filter crashes by app. - * The name needs to be whitelisted for the server to accept the crash. + * The name needs to be safelisted for the server to accept the crash. * [File a bug](https://bugzilla.mozilla.org/enter_bug.cgi?product=Socorro) if you would like to get your - * app added to the whitelist. + * app added to the safelist. * @param appId The application ID assigned by Socorro server. * @param version The engine version. * @param buildId The engine build ID. diff --git a/docs/changelog.md b/docs/changelog.md index c483138da81..3c0a6a895e9 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -14,6 +14,10 @@ permalink: /changelog/ * **browser-engine-gecko**, **browser-engine-gecko-beta**, **browser-engine-gecko-nightly** * Exposes GeckoView `CompositorController#ClearColor` as Setting +* **browser-engine-system** + * ⚠️ **This is a breaking change**: Renames `blackListFile` to `blocklistFile`. + * ⚠️ **This is a breaking change**: Renames `whiteListFile` to `safelistFile`. + * **concept-engine** * ⚠️ Removed `TrackingCategory`.`SHIMMED`, for user usability reasons, we are going to mark SHIMMED categories as blocked, to follow the same pattern as Firefox desktop for more information see [#8769](https://github.com/mozilla-mobile/android-components/issues/8769) @@ -2913,7 +2917,7 @@ permalink: /changelog/ * Added custom notification icon for `FetchDownloadManager`. * **feature-app-links** - * Added whitelist for schemes of URLs to open with an external app. This defaults to `mailto`, `market`, `sms` and `tel`. + * Added safelist for schemes of URLs to open with an external app. This defaults to `mailto`, `market`, `sms` and `tel`. * **feature-accounts** * ⚠️ **This is a breaking change**: Public API for interacting with `FxaAccountManager` and sync changes diff --git a/docs/changelog_archive.md b/docs/changelog_archive.md index 6dc8f165f3f..dbe57a67300 100644 --- a/docs/changelog_archive.md +++ b/docs/changelog_archive.md @@ -509,7 +509,7 @@ permalink: /changelog/archive * `VisitType` is now part of `HistoryTrackingDelegate`'s `onVisited` method signature * **feature-session** - * `HistoryDelegate` now implements a blacklist of URI schemas. + * `HistoryDelegate` now implements a blocklist of URI schemas. * **browser-engine-gecko-nightly** * Implement `allowAutoplayMedia` in terms of `autoplayDefault`. diff --git a/docs/contribute/updating_tracking_protection_lists.md b/docs/contribute/updating_tracking_protection_lists.md index 422cea515c0..1c700219e85 100644 --- a/docs/contribute/updating_tracking_protection_lists.md +++ b/docs/contribute/updating_tracking_protection_lists.md @@ -16,8 +16,8 @@ The following lists are kept outside of the Android Components repository in the | AC | Shavar | Purpose | |-----------------------|----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [domain_blacklist.json][1] | [disconnect-blacklist.json][2] | This blocklist is the core of tracking protection in Firefox. [For more information][3]. | -| [domain_whitelist.json][4] | [disconnect-entitylist.json][5] | It is used to allow third-party subresources that are wholly owned by the same company that owns the top-level website that the user is visiting for more details. [For more information][6]. | +| [domain_blocklist.json][1] | [disconnect-blocklist.json][2] | This blocklist is the core of tracking protection in Firefox. [For more information][3]. | +| [domain_safelist.json][4] | [disconnect-entitylist.json][5] | It is used to allow third-party subresources that are wholly owned by the same company that owns the top-level website that the user is visiting for more details. [For more information][6].| @@ -25,15 +25,15 @@ The following lists are kept outside of the Android Components repository in the For every FireFox release, a new branch gets created following the same pattern as [merge-day](https://mozac.org/contributing/merge-day), where `master` contains `nightly`'s lists, the higher branch number contains `Beta` and the higher branch number before contains `Stable`. -That means that every [merge-day](https://mozac.org/contributing/merge-day), we need to update the [domain_blacklist.json][1] and [domain_whitelist.json][4] files with their counterpart on [shavar-prod-lists](https://github.com/mozilla-services/shavar-prod-lists). +That means that every [merge-day](https://mozac.org/contributing/merge-day), we need to update the [domain_blocklist.json][1] and [domain_safelist.json][4] files with their counterpart on [shavar-prod-lists](https://github.com/mozilla-services/shavar-prod-lists). ### Preparation 1. Go to the [shavar-prod-lists](https://github.com/mozilla-services/shavar-prod-lists) repository 2. Switch to the higher branch number (Beta). -3. Copy the content of [disconnect-blacklist.json][2] -> [domain_blacklist.json][1] +3. Copy the content of [disconnect-blocklist.json][2] -> [domain_blocklist.json][1] 4. Run all the tests on `browser-engine-system` 🤞 5. 🔴 `If` something fails proceed to verify what's causing the issue and address it. -6. ✅ `Else` proceed to copy the content of [disconnect-entitylist.json][5] -> [domain_whitelist.json][4] +6. ✅ `Else` proceed to copy the content of [disconnect-entitylist.json][5] -> [domain_safelist.json][4] 7. Run all the tests on `browser-engine-system` 🤞 8. 🔴 `If` something fails proceed to verify what's causing the issue and address it. 9. ✅ `Else` proceed to commit your changes using the guideline below. @@ -44,18 +44,18 @@ This way we can know which version of the lists we have on AC. ``` Closes #6163: Update tracking protection lists -domain_blacklist.json maps to disconnect-blacklist.json +domain_blocklist.json maps to disconnect-blocklist.json commit(shavar-prod-lists) d5755856f4eeab4ce5e8fb7896600ed7768368e5 -domain_whitelist.json maps to disconnect-entitylist.json +domain_safelist.json maps to disconnect-entitylist.json commit(shavar-prod-lists) 01dcca911aa7787fd835a1a19cef1012296f4eb7 ``` THE END! -[1]: https://github.com/mozilla-mobile/android-components/blob/master/components/browser/engine-system/src/main/res/raw/domain_blacklist.json -[2]: https://github.com/mozilla-services/shavar-prod-lists/blob/master/disconnect-blacklist.json -[3]: https://github.com/mozilla-services/shavar-prod-lists/blob/master/README.md#disconnect-blacklistjson -[4]: https://github.com/mozilla-mobile/android-components/blob/master/components/browser/engine-system/src/main/res/raw/domain_whitelist.json +[1]: https://github.com/mozilla-mobile/android-components/blob/master/components/browser/engine-system/src/main/res/raw/domain_blocklist.json +[2]: https://github.com/mozilla-services/shavar-prod-lists/blob/master/disconnect-blocklist.json +[3]: https://github.com/mozilla-services/shavar-prod-lists/blob/master/README.md#disconnect-blocklist.json +[4]: https://github.com/mozilla-mobile/android-components/blob/master/components/browser/engine-system/src/main/res/raw/domain_safelist.json [5]: https://github.com/mozilla-services/shavar-prod-lists/blob/master/disconnect-entitylist.json [6]: https://github.com/mozilla-services/shavar-prod-lists/blob/master/README.md#disconnect-entitylistjson