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)
}
}
}
}
}
@@ -42,4 +42,16 @@ class GeckoBrowserService {
Future<void> onTrimMemory(int level) {
return _api.onTrimMemory(level);
}
Future<void> openInCustomTab({
required Uri url,
required bool private,
String? contextId,
}) {
return _api.openInCustomTab(
url: url.toString(),
private: private,
contextId: contextId,
);
}
}
@@ -5160,6 +5160,28 @@ class GeckoBrowserApi {
return;
}
}
Future<void> openInCustomTab({required String url, required bool private, required String? contextId, }) async {
final pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoBrowserApi.openInCustomTab$pigeonVar_messageChannelSuffix';
final pigeonVar_channel = BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[url, private, contextId]);
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else {
return;
}
}
}
class GeckoSyncApi {
@@ -1003,6 +1003,11 @@ abstract class GeckoBrowserApi {
);
bool showNativeFragment();
void onTrimMemory(int level);
void openInCustomTab({
required String url,
required bool private,
required String? contextId,
});
}
enum SyncEngineValue { history, bookmarks, tabs }