Loading mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AlwaysDeniedSchemes.kt 0 → 100644 +22 −0 Original line number Diff line number Diff line /* 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.feature.app.links import java.util.Locale /** * Utility class whether scheme is allowed or denied. */ class AlwaysDeniedSchemes(private val schemes: Set<String>) { /** * Whether or not we should deny given URI scheme by dangerous etc. * * @param scheme A scheme of URI * @return `true` If scheme should be denied */ fun shouldDeny(scheme: String?): Boolean { return schemes.contains(scheme?.lowercase(Locale.ROOT)) } } mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksInterceptor.kt +2 −2 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ private val ALLOWED_SCHEMES_IN_SUBFRAME: List<String> = listOf( class AppLinksInterceptor( private val context: Context, private val engineSupportedSchemes: Set<String> = ENGINE_SUPPORTED_SCHEMES, private val alwaysDeniedSchemes: Set<String> = ALWAYS_DENY_SCHEMES, private val alwaysDeniedSchemes: AlwaysDeniedSchemes = AlwaysDeniedSchemes(ALWAYS_DENY_SCHEMES), private var launchInApp: () -> Boolean = { false }, private val useCases: AppLinksUseCases = AppLinksUseCases( context, Loading Loading @@ -102,7 +102,7 @@ class AppLinksInterceptor( // If scheme not in supported list then follow user preference !launchInApp() && !isPossibleAuthentication(tabSessionState) && engineSupportsScheme -> true // Never go to an external app when scheme is in blocklist alwaysDeniedSchemes.contains(uriScheme) -> true alwaysDeniedSchemes.shouldDeny(uriScheme) -> true else -> false } Loading mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksUseCases.kt +3 −3 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ private const val ANDROID_RESOLVER_PACKAGE_NAME = "android" class AppLinksUseCases( private val context: Context, private var launchInApp: () -> Boolean = { false }, private val alwaysDeniedSchemes: Set<String> = ALWAYS_DENY_SCHEMES, private val alwaysDeniedSchemes: AlwaysDeniedSchemes = AlwaysDeniedSchemes(ALWAYS_DENY_SCHEMES), private val installedBrowsers: Browsers = BrowsersCache.all(context), ) { @Suppress( Loading Loading @@ -163,7 +163,7 @@ class AppLinksUseCases( val appIntent = when { intent?.data == null -> null alwaysDeniedSchemes.contains(intent.data?.scheme) -> null alwaysDeniedSchemes.shouldDeny(intent.data?.scheme) -> null else -> intent } Loading Loading @@ -237,7 +237,7 @@ class AppLinksUseCases( appIntent?.let { try { val scheme = appIntent.data?.scheme if (scheme != null && alwaysDeniedSchemes.contains(scheme)) { if (alwaysDeniedSchemes.shouldDeny(scheme)) { return } Loading mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksInterceptorTest.kt +8 −8 Original line number Diff line number Diff line Loading @@ -202,7 +202,7 @@ class AppLinksInterceptorTest { val blocklistedScheme = "blocklisted" val feature = AppLinksInterceptor( context = mockContext, alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { true }, useCases = mockUseCases, ) Loading Loading @@ -259,7 +259,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { false }, useCases = mockUseCases, ) Loading @@ -279,7 +279,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(notSupportedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(notSupportedScheme)), launchInApp = { false }, useCases = mockUseCases, ) Loading @@ -300,7 +300,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { true }, useCases = mockUseCases, ) Loading @@ -321,7 +321,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { false }, useCases = mockUseCases, ) Loading @@ -343,7 +343,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { false }, useCases = mockUseCases, ) Loading Loading @@ -594,7 +594,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { true }, useCases = mockUseCases, ) Loading @@ -616,7 +616,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { false }, useCases = mockUseCases, ) Loading mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksUseCasesTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -355,7 +355,7 @@ class AppLinksUseCasesTest { fun `A intent scheme denied should return no app intent`() { val uri = "intent://details/#Intent" val context = createContext(Triple(uri, appPackage, "")) val subject = AppLinksUseCases(context, { true }, alwaysDeniedSchemes = setOf("intent")) val subject = AppLinksUseCases(context, { true }, alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf("intent"))) val redirect = subject.interceptedAppLinkRedirect.invoke(uri) Loading Loading
mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AlwaysDeniedSchemes.kt 0 → 100644 +22 −0 Original line number Diff line number Diff line /* 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.feature.app.links import java.util.Locale /** * Utility class whether scheme is allowed or denied. */ class AlwaysDeniedSchemes(private val schemes: Set<String>) { /** * Whether or not we should deny given URI scheme by dangerous etc. * * @param scheme A scheme of URI * @return `true` If scheme should be denied */ fun shouldDeny(scheme: String?): Boolean { return schemes.contains(scheme?.lowercase(Locale.ROOT)) } }
mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksInterceptor.kt +2 −2 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ private val ALLOWED_SCHEMES_IN_SUBFRAME: List<String> = listOf( class AppLinksInterceptor( private val context: Context, private val engineSupportedSchemes: Set<String> = ENGINE_SUPPORTED_SCHEMES, private val alwaysDeniedSchemes: Set<String> = ALWAYS_DENY_SCHEMES, private val alwaysDeniedSchemes: AlwaysDeniedSchemes = AlwaysDeniedSchemes(ALWAYS_DENY_SCHEMES), private var launchInApp: () -> Boolean = { false }, private val useCases: AppLinksUseCases = AppLinksUseCases( context, Loading Loading @@ -102,7 +102,7 @@ class AppLinksInterceptor( // If scheme not in supported list then follow user preference !launchInApp() && !isPossibleAuthentication(tabSessionState) && engineSupportsScheme -> true // Never go to an external app when scheme is in blocklist alwaysDeniedSchemes.contains(uriScheme) -> true alwaysDeniedSchemes.shouldDeny(uriScheme) -> true else -> false } Loading
mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksUseCases.kt +3 −3 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ private const val ANDROID_RESOLVER_PACKAGE_NAME = "android" class AppLinksUseCases( private val context: Context, private var launchInApp: () -> Boolean = { false }, private val alwaysDeniedSchemes: Set<String> = ALWAYS_DENY_SCHEMES, private val alwaysDeniedSchemes: AlwaysDeniedSchemes = AlwaysDeniedSchemes(ALWAYS_DENY_SCHEMES), private val installedBrowsers: Browsers = BrowsersCache.all(context), ) { @Suppress( Loading Loading @@ -163,7 +163,7 @@ class AppLinksUseCases( val appIntent = when { intent?.data == null -> null alwaysDeniedSchemes.contains(intent.data?.scheme) -> null alwaysDeniedSchemes.shouldDeny(intent.data?.scheme) -> null else -> intent } Loading Loading @@ -237,7 +237,7 @@ class AppLinksUseCases( appIntent?.let { try { val scheme = appIntent.data?.scheme if (scheme != null && alwaysDeniedSchemes.contains(scheme)) { if (alwaysDeniedSchemes.shouldDeny(scheme)) { return } Loading
mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksInterceptorTest.kt +8 −8 Original line number Diff line number Diff line Loading @@ -202,7 +202,7 @@ class AppLinksInterceptorTest { val blocklistedScheme = "blocklisted" val feature = AppLinksInterceptor( context = mockContext, alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { true }, useCases = mockUseCases, ) Loading Loading @@ -259,7 +259,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { false }, useCases = mockUseCases, ) Loading @@ -279,7 +279,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(notSupportedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(notSupportedScheme)), launchInApp = { false }, useCases = mockUseCases, ) Loading @@ -300,7 +300,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { true }, useCases = mockUseCases, ) Loading @@ -321,7 +321,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { false }, useCases = mockUseCases, ) Loading @@ -343,7 +343,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { false }, useCases = mockUseCases, ) Loading Loading @@ -594,7 +594,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { true }, useCases = mockUseCases, ) Loading @@ -616,7 +616,7 @@ class AppLinksInterceptorTest { val feature = AppLinksInterceptor( context = mockContext, engineSupportedSchemes = setOf(supportedScheme), alwaysDeniedSchemes = setOf(blocklistedScheme), alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf(blocklistedScheme)), launchInApp = { false }, useCases = mockUseCases, ) Loading
mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksUseCasesTest.kt +1 −1 Original line number Diff line number Diff line Loading @@ -355,7 +355,7 @@ class AppLinksUseCasesTest { fun `A intent scheme denied should return no app intent`() { val uri = "intent://details/#Intent" val context = createContext(Triple(uri, appPackage, "")) val subject = AppLinksUseCases(context, { true }, alwaysDeniedSchemes = setOf("intent")) val subject = AppLinksUseCases(context, { true }, alwaysDeniedSchemes = AlwaysDeniedSchemes(setOf("intent"))) val redirect = subject.interceptedAppLinkRedirect.invoke(uri) Loading