shouldShowRelay

open override fun shouldShowRelay(host: String, domain: String, isRelayUser: Boolean): Boolean

Determines whether Firefox Relay should be offered for a given site.

This function implements the Relay visibility decision logic based on three factors:

  1. Whether the site is on the denylist

  2. Whether the user is an existing Relay user

  3. Whether the site is on the allowlist

Decision Logic (in order)

  1. If the site is on the denylist, don't show Relay (regardless of user status)

  2. If the site is NOT on the denylist and the user is a Relay user, show Relay

  3. If the site is NOT on the denylist and the user is not a Relay user, check the allowlist:

  • If the site is on the allowlist, show Relay (to promote Relay to new users)

  • Otherwise, don't show Relay

Fail-Safe Behavior

If Remote Settings is unavailable:

  • If denylist fetch fails: don't show Relay (conservative: avoid showing on potentially blocked sites)

  • If allowlist fetch fails for non-Relay users: assume empty (conservative: don't promote without data)

Arguments

  • host - The full hostname (e.g., "mail.google.com", "www.example.com")

  • domain - The registrable domain from PSL (e.g., "google.com", "example.co.uk")

  • is_relay_user - Whether the user already has a Relay account

Public Suffix List (PSL)

Mobile clients should use PSL to extract the domain:

  • Host: Full hostname like "mail.google.com"

  • Domain: Registrable domain (eTLD+1) like "google.com"

  • Swift: Use URL.host and extract domain via PSL library

  • Kotlin: Use URL.host and extract domain via PSL library

Returns

true if Relay should be shown for this site, false otherwise

Determining if User is a Relay User

Mobile clients should check if the user is a Relay user by calling FirefoxAccount.getAttachedClients() and checking if Relay is in the list of attached clients.

Example

val url = URL("https://mail.google.com/inbox")
val host = url.host // "mail.google.com"
val domain = PublicSuffixList.getRegistrableDomain(host) // "google.com"

val rsClient = RelayRemoteSettingsClient(remoteSettingsService)
val attachedClients = fxAccount.getAttachedClients()
val isRelayUser = attachedClients.any { it.clientId == RELAY_CLIENT_ID }

if (rsClient.shouldShowRelay(host, domain, isRelayUser)) {
// Show Relay UI
}