android-components / mozilla.components.feature.app.links / AppLinksInterceptor

AppLinksInterceptor

class AppLinksInterceptor : RequestInterceptor (source)

This feature implements use cases for detecting and handling redirects to external apps. The user is asked to confirm her intention before leaving the app. These include the Android Intents, custom schemes and support for Intent.CATEGORY_BROWSABLE http(s) URLs.

In the case of Android Intents that are not installed, and with no fallback, the user is prompted to search the installed market place.

It provides use cases to detect and open links openable in third party non-browser apps.

It requires: a Context.

A Boolean flag is provided at construction to allow the feature and use cases to be landed without adjoining UI. The UI will be activated in https://github.com/mozilla-mobile/android-components/issues/2974 and https://github.com/mozilla-mobile/android-components/issues/2975.

Parameters

context - Context the feature is associated with.

interceptLinkClicks - If {true} then intercept link clicks.

alwaysAllowedSchemes - List of schemes that will always be allowed to be opened in a third-party app even if interceptLinkClicks is false.

alwaysDeniedSchemes - List of schemes that will never be opened in a third-party app even if interceptLinkClicks is true.

launchInApp - If {true} then launch app links in third party app(s). Default to false because of security concerns.

useCases - These use cases allow for the detection of, and opening of links that other apps have registered to open.

launchFromInterceptor - If {true} then the interceptor will launch the link in third-party apps if available.

Constructors

Name Summary
<init> AppLinksInterceptor(context: <ERROR CLASS>, interceptLinkClicks: Boolean = false, alwaysAllowedSchemes: Set<String> = setOf("mailto", "market", "sms", "tel"), alwaysDeniedSchemes: Set<String> = setOf("javascript", "about"), launchInApp: () -> Boolean = { false }, useCases: AppLinksUseCases = AppLinksUseCases(context, launchInApp), launchFromInterceptor: Boolean = false)
This feature implements use cases for detecting and handling redirects to external apps. The user is asked to confirm her intention before leaving the app. These include the Android Intents, custom schemes and support for Intent.CATEGORY_BROWSABLE http(s) URLs.

Functions

Name Summary
onLoadRequest fun onLoadRequest(engineSession: EngineSession, uri: String, hasUserGesture: Boolean, isSameDomain: Boolean): InterceptionResponse?
A request to open an URI. This is called before each page load to allow providing custom behavior.

Inherited Functions

Name Summary
onErrorRequest open fun onErrorRequest(session: EngineSession, errorType: ErrorType, uri: String?): ErrorResponse?
A request that the engine wasn’t able to handle that resulted in an error.

Extension Functions

Name Summary
loadResourceAsString fun Any.loadResourceAsString(path: String): String
Loads a file from the resources folder and returns its content as a string object.