Docs
GeckoView architecture
How Petal combines Mozilla GeckoView with a Jetpack Compose interface.
1. Unified Engine Architecture: Single Engine View & BrowserStore
Petal Browser employs a consolidated, production-grade browser engine architecture modeled after Firefox / Fenix. All tabs, browser surfaces, and WebExtensions run on a single unified engine stack:
- Engine Core:
org.mozilla.geckoview:geckoview159.0.20261102144711 - Component Stack: Mozilla Android Components 159.0.1 (
concept-engine,browser-engine-gecko,browser-state,browser-store,feature-downloads,service-firefox-accounts) - Runtime Singleton:
com.petal.browser.engine.gecko.PetalGeckoRuntimeconfigures Firefox Enhanced Tracking Protection (ETP), Total Cookie Protection, cookie banner blocker, safe browsing, and WebExtensions. - Authoritative Cookie Bridge:
PetalGeckoCookieBridgeinterfaces with GeckoView'sStorageControllerwith strict isolation between standard and private tab contexts. - Built-in Network Blocker:
petal_network_blockerWebExtension intercepts all subresource network requests atwebRequest.onBeforeRequestand runs early cosmetic CSS injection atdocument_start. - Unified Tab Surface:
PetalTabSurfacedefines the tab contract across activePetalTabViewControllerand backgroundPlaceholderTabControllerinstances.
Single-Engine View Architecture (Fenix Model)
Instead of allocating a separate GeckoView / SurfaceView texture per open tab (which caused GPU memory exhaustion and render-thread stall ANRs), Petal uses a single active tab viewport:
- Single View Controller (
PetalTabViewController):BrowserActivitymaintains one retainedsingleTabViewControllerinstance mounted incontentFrame.- When switching tabs (
showAlbum()), the outgoing tab is demoted to a lightweightPlaceholderAlbumController(preserving its title, URL, favicon, and thumbnail) while its engine session remains managed inBrowserStore. - The newly selected tab session is bound and rendered in
singleTabViewController.render(session).
- Background Tabs:
- Background tabs do NOT allocate native Android views or SurfaceViews.
- Background tab sessions are tracked inside
BrowserStore. Inactive tabs can be suspended to session state envelopes byPetalTabSuspenderunder memory pressure.
- Consolidated Engine Bridge (
PetalEngineBridge):- Centralizes static engine utilities, download dispatching, intent routing, profile resolution, and user agent generation.
- Replaced legacy static helpers from deprecated
PetalGeckoView.
graph TD
A[BrowserActivity.java] --> B[PetalTabViewController.kt (Single Active View)]
A --> C[PetalEngineStore / BrowserStore]
C --> D[GeckoEngine / EngineSession Pool]
D --> E[GeckoRuntime Singleton / GeckoSession]
B --> E
A --> F[BrowserContainer (Tab Manager)]
F --> G[PlaceholderAlbumController (Background Tabs)]
A --> H[ComposeView Bridging Container]
H --> I[Jetpack Compose M3 UI Screens]
2. Delegate Ownership & Activity Recreation Rebinding
Petal browser delegates implement the PetalOwnedDelegate contract to survive Android Activity recreations without leaking stale closures or tearing down live Gecko sessions:
PetalPromptDelegateWrapper: Expressive Material 3 prompts (alerts, auth, file pickers, choices, credit card prompts) with fallback forwarding.PetalPermissionDelegateWrapper: Runtime permissions (camera, microphone, geolocation) with automatic Android permission requests.PetalContentDelegateWrapper: Dynamic title, URL, crash recovery, and security changes.- Dynamic Rebinding: When an Activity is recreated,
PetalTabViewController.bindTab()callsrebind()on all owned delegates, updating the volatile activity supplier without re-instantiating delegates on active Gecko sessions.
3. Store-Driven State & APZ Touch Filtering
State synchronization is strictly unidirectional and reactive:
- BrowserStore Observation:
BrowserActivitysubscribes toPetalEngineStore.observeManually()inonCreate().- Loading completion, refresh resets, omnibox updates, and back stack states are driven directly from store actions.
- APZ (Async Pan Zoom) Overscroll Arbitration:
- Pull-to-refresh checks
PanZoomController.onTouchEventForDetailResult(canOverscrollTop()) inPetalTabViewController. - Distinguishes document-level overscroll top from inner scroll containers (overflow divs, carousels), preventing false refresh triggers.
- Pull-to-refresh checks
4. ComposeView Bridging Pattern & ViewTree Requirements
Petal embeds Jetpack Compose modular screens into BrowserActivity using dynamic ComposeView bridging:
- Primary container is a plain
FrameLayout contentFrameinactivity_main.xml; pull-to-refresh is Mozilla'sSwipeRefreshFeatureon eachPetalTabViewController. - Sub-screens (Settings, Tab Switcher, Downloads, History, Bookmarks, Omnibox, Credits, Reader, Incognito Home) are generated via companion bridge objects.
- ViewTree lifecycle, ViewModel store, and saved state registry owners are explicitly wired:
composeView.apply {
setViewTreeLifecycleOwner(activity)
setViewTreeViewModelStoreOwner(activity)
setViewTreeSavedStateRegistryOwner(activity)
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
}
5. Subpackage Directory Structure
com.petal.browser.activity: Core activities (BrowserActivity,SettingsActivity,PetalPwaActivity).com.petal.browser.browser: Core browser tab contracts (PetalTabViewController,PlaceholderAlbumController,AlbumController,BrowserContainer).com.petal.browser.engine.gecko: Engine integrations (PetalEngineStore,PetalEngineBridge,PetalGeckoRuntime,PetalTabSuspender).com.petal.browser.compose: Jetpack Compose UI surfaces (settings, tabs, omnibox, context menus, video player).com.petal.browser.predictive: Predictive back gesture coordination, blur snapshots, and transition curves.com.petal.browser.media: Video overlays, PiP coordination, andPetalMediaBridge.com.petal.browser.download: Download UI and state, backed by Mozilla'sAbstractFetchDownloadService.com.petal.browser.pwa: Progressive Web App (PWA) manifest installation and notification manager.com.petal.browser.passwords: Hardware-backed credential vault and autofill.com.petal.browser.ui.glass: Liquid glass material rendering and background blurs.com.petal.browser.ui.theme: Material 3 Expressive theme tokens and anti-slop design system.