move open url into bottom sheet

This commit is contained in:
Fabian Freund
2026-02-22 18:54:59 +01:00
parent 5230d3cb6b
commit ac80632eeb
8 changed files with 193 additions and 42 deletions
@@ -14,6 +14,7 @@ import eu.weblibre.flutter_mozilla_components.BrowserFragment
import eu.weblibre.flutter_mozilla_components.GeckoViewFactory
import eu.weblibre.flutter_mozilla_components.GlobalComponents
import eu.weblibre.flutter_mozilla_components.ProfileContext
import eu.weblibre.flutter_mozilla_components.activities.ExternalAppBrowserActivity
import eu.weblibre.flutter_mozilla_components.activities.NotificationActivity
import eu.weblibre.flutter_mozilla_components.feature.DefaultSelectionActionDelegate
import eu.weblibre.flutter_mozilla_components.pigeons.AddonCollection
@@ -58,7 +59,11 @@ import eu.weblibre.flutter_mozilla_components.pigeons.ReaderViewController
import eu.weblibre.flutter_mozilla_components.pigeons.ReaderViewEvents
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding
import mozilla.components.browser.state.action.CustomTabListAction
import mozilla.components.browser.state.action.SystemAction
import mozilla.components.browser.state.state.CustomTabConfig
import mozilla.components.browser.state.state.SessionState
import mozilla.components.browser.state.state.createCustomTab
import mozilla.components.feature.addons.logger
import mozilla.components.support.base.ext.getStacktraceAsString
import mozilla.components.support.base.log.Log
@@ -386,4 +391,32 @@ class GeckoBrowserApiImpl : GeckoBrowserApi {
}
}
}
override fun openInCustomTab(url: String, `private`: Boolean, contextId: String?) {
val currentActivity = requireNotNull(activity) { "Activity not attached" }
val customTabConfig = CustomTabConfig()
val tab = createCustomTab(
url = url,
contextId = contextId,
config = customTabConfig,
source = SessionState.Source.Internal.CustomTab,
private = `private`,
)
components.core.store.dispatch(
CustomTabListAction.AddCustomTabAction(tab)
)
components.useCases.sessionUseCases.loadUrl(url, tab.id)
val intent = ExternalAppBrowserActivity.createIntent(
context = currentActivity,
customTabSessionId = tab.id,
)
currentActivity.startActivity(intent)
logger.debug("$TAG: Opened custom tab ${tab.id} for $url (private=$`private`)")
}
}
@@ -4394,6 +4394,7 @@ interface GeckoBrowserApi {
fun initialize(profileFolder: String, logLevel: LogLevel, contentBlocking: ContentBlocking, addonCollection: AddonCollection?, fxaServerOverride: String?, syncTokenServerOverride: String?)
fun showNativeFragment(): Boolean
fun onTrimMemory(level: Long)
fun openInCustomTab(url: String, private: Boolean, contextId: String?)
companion object {
/** The codec used by GeckoBrowserApi. */
@@ -4475,6 +4476,26 @@ interface GeckoBrowserApi {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_mozilla_components.GeckoBrowserApi.openInCustomTab$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val urlArg = args[0] as String
val privateArg = args[1] as Boolean
val contextIdArg = args[2] as String?
val wrapped: List<Any?> = try {
api.openInCustomTab(urlArg, privateArg, contextIdArg)
listOf(null)
} catch (exception: Throwable) {
GeckoPigeonUtils.wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
}
}
}