No issue: Add extension function to TabSessionState for shortening urls safely.

pull/543/head
Arturo Mejia 2 years ago committed by mergify[bot]
parent c09f899da4
commit d16d61c055

@ -4,7 +4,31 @@
package org.mozilla.fenix.tabstray.ext
import androidx.compose.runtime.Composable
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.toolbar.MAX_URI_LENGTH
import org.mozilla.fenix.components.components
import org.mozilla.fenix.compose.inComposePreview
import org.mozilla.fenix.ext.toShortUrl
/**
* Shortens URLs to be more user friendly, by applying [String.toShortUrl]
* and making sure it's equal or below the [MAX_URI_LENGTH].
*/
@Composable
fun TabSessionState.toShortUrl(): String {
// Truncate to MAX_URI_LENGTH to prevent the UI from locking up for
// extremely large URLs such as data URIs or bookmarklets. The same
// is done in the toolbar and awesomebar:
// https://github.com/mozilla-mobile/fenix/issues/1824
// https://github.com/mozilla-mobile/android-components/issues/6985
return if (inComposePreview) {
this.content.url.take(MAX_URI_LENGTH)
} else {
this.content.url.toShortUrl(components.publicSuffixList)
.take(MAX_URI_LENGTH)
}
}
fun TabSessionState.isActive(maxActiveTime: Long): Boolean {
val lastActiveTime = maxOf(lastAccess, createdAt)

Loading…
Cancel
Save