M5: install permission prompt UI; M6: runtime tracking-protection policy
Browse files
app/src/main/java/dev/nova/browser/BrowserActivity.kt
CHANGED
|
@@ -19,8 +19,10 @@ import androidx.compose.ui.unit.dp
|
|
| 19 |
import androidx.compose.ui.viewinterop.AndroidView
|
| 20 |
import org.mozilla.geckoview.GeckoResult
|
| 21 |
import org.mozilla.geckoview.GeckoRuntime
|
|
|
|
| 22 |
import org.mozilla.geckoview.GeckoView
|
| 23 |
import org.mozilla.geckoview.WebExtension
|
|
|
|
| 24 |
|
| 25 |
class BrowserActivity : ComponentActivity() {
|
| 26 |
|
|
@@ -35,11 +37,46 @@ class BrowserActivity : ComponentActivity() {
|
|
| 35 |
super.onCreate(savedInstanceState)
|
| 36 |
|
| 37 |
if (runtime == null) {
|
| 38 |
-
runtime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
// Layer 2 of the dev console: desktop Firefox DevTools can attach
|
| 40 |
// via about:debugging over USB / Wi-Fi. GV 147 API:
|
| 41 |
// GeckoRuntimeSettings.setRemoteDebuggingEnabled(boolean).
|
| 42 |
runtime!!.settings.setRemoteDebuggingEnabled(true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
tabManager = TabManager(runtime!!, this)
|
| 45 |
|
|
@@ -129,10 +166,40 @@ class BrowserActivity : ComponentActivity() {
|
|
| 129 |
// M3 add-ons manager state
|
| 130 |
var extensions by remember { mutableStateOf<List<TabManager.ExtInfo>>(emptyList()) }
|
| 131 |
var addonsLoading by remember { mutableStateOf(false) }
|
|
|
|
| 132 |
|
| 133 |
val loading = activeId != null && tabManager.loadingStates[activeId!!] == true
|
| 134 |
val progress = activeId?.let { tabManager.progressStates[it] } ?: 0
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
// Re-attach the active session whenever we come back from any overlay.
|
| 137 |
LaunchedEffect(activeId, trayOpen, addonsOpen, consoleOpen) {
|
| 138 |
val id = activeId ?: return@LaunchedEffect
|
|
@@ -175,7 +242,13 @@ class BrowserActivity : ComponentActivity() {
|
|
| 175 |
extensions = extensions,
|
| 176 |
enabledStates = tabManager.extensionStates,
|
| 177 |
loading = addonsLoading,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
onToggle = { id, enabled -> tabManager.setExtensionEnabled(id, enabled) {} },
|
|
|
|
| 179 |
onDismiss = { addonsOpen = false },
|
| 180 |
)
|
| 181 |
return
|
|
|
|
| 19 |
import androidx.compose.ui.viewinterop.AndroidView
|
| 20 |
import org.mozilla.geckoview.GeckoResult
|
| 21 |
import org.mozilla.geckoview.GeckoRuntime
|
| 22 |
+
import org.mozilla.geckoview.GeckoRuntimeSettings
|
| 23 |
import org.mozilla.geckoview.GeckoView
|
| 24 |
import org.mozilla.geckoview.WebExtension
|
| 25 |
+
import org.mozilla.geckoview.WebExtensionController
|
| 26 |
|
| 27 |
class BrowserActivity : ComponentActivity() {
|
| 28 |
|
|
|
|
| 37 |
super.onCreate(savedInstanceState)
|
| 38 |
|
| 39 |
if (runtime == null) {
|
| 40 |
+
// M6: strict-ish tracking protection at the runtime level; sessions
|
| 41 |
+
// additionally opt in via GeckoSessionSettings.useTrackingProtection.
|
| 42 |
+
runtime = GeckoRuntime.create(
|
| 43 |
+
this,
|
| 44 |
+
GeckoRuntimeSettings.Builder()
|
| 45 |
+
.trackingProtectionPolicy(GeckoSession.TrackingProtectionPolicy.RECOMMENDED)
|
| 46 |
+
.build()
|
| 47 |
+
)
|
| 48 |
// Layer 2 of the dev console: desktop Firefox DevTools can attach
|
| 49 |
// via about:debugging over USB / Wi-Fi. GV 147 API:
|
| 50 |
// GeckoRuntimeSettings.setRemoteDebuggingEnabled(boolean).
|
| 51 |
runtime!!.settings.setRemoteDebuggingEnabled(true)
|
| 52 |
+
|
| 53 |
+
// M5: installs REQUIRE a prompt delegate (GV refuses otherwise).
|
| 54 |
+
// The user decision is surfaced as a Compose dialog through
|
| 55 |
+
// TabManager.pendingInstall.
|
| 56 |
+
runtime!!.webExtensionController.setPromptDelegate(
|
| 57 |
+
object : WebExtensionController.PromptDelegate {
|
| 58 |
+
override fun onInstallPromptRequest(
|
| 59 |
+
extension: WebExtension,
|
| 60 |
+
permissions: Array<out String>,
|
| 61 |
+
origins: Array<out String>,
|
| 62 |
+
dataCollectionPermissions: Array<out String>,
|
| 63 |
+
): GeckoResult<WebExtension.PermissionPromptResponse> {
|
| 64 |
+
val result = GeckoResult<WebExtension.PermissionPromptResponse>()
|
| 65 |
+
val name = extension.metaData?.name ?: extension.id
|
| 66 |
+
tabManager.pendingInstall.value = TabManager.InstallPrompt(
|
| 67 |
+
name = name,
|
| 68 |
+
permissions = permissions.toList(),
|
| 69 |
+
origins = origins.toList(),
|
| 70 |
+
) { allow ->
|
| 71 |
+
tabManager.pendingInstall.value = null
|
| 72 |
+
result.complete(
|
| 73 |
+
WebExtension.PermissionPromptResponse(allow, false, false)
|
| 74 |
+
)
|
| 75 |
+
}
|
| 76 |
+
return result
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
)
|
| 80 |
}
|
| 81 |
tabManager = TabManager(runtime!!, this)
|
| 82 |
|
|
|
|
| 166 |
// M3 add-ons manager state
|
| 167 |
var extensions by remember { mutableStateOf<List<TabManager.ExtInfo>>(emptyList()) }
|
| 168 |
var addonsLoading by remember { mutableStateOf(false) }
|
| 169 |
+
var installMessage by remember { mutableStateOf("") }
|
| 170 |
|
| 171 |
val loading = activeId != null && tabManager.loadingStates[activeId!!] == true
|
| 172 |
val progress = activeId?.let { tabManager.progressStates[it] } ?: 0
|
| 173 |
|
| 174 |
+
// M5: install permission prompt — visible over every screen.
|
| 175 |
+
val pendingInstall by tabManager.pendingInstall
|
| 176 |
+
pendingInstall?.let { prompt ->
|
| 177 |
+
AlertDialog(
|
| 178 |
+
onDismissRequest = { prompt.respond(false) },
|
| 179 |
+
title = { Text("Install \"${prompt.name}\"?") },
|
| 180 |
+
text = {
|
| 181 |
+
Column {
|
| 182 |
+
if (prompt.permissions.isEmpty()) {
|
| 183 |
+
Text("This add-on requests no special permissions.")
|
| 184 |
+
} else {
|
| 185 |
+
Text("It requests access to:")
|
| 186 |
+
prompt.permissions.forEach { Text("• $it") }
|
| 187 |
+
}
|
| 188 |
+
if (prompt.origins.isNotEmpty()) {
|
| 189 |
+
Text("Site access:")
|
| 190 |
+
prompt.origins.forEach { Text("• $it") }
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
},
|
| 194 |
+
confirmButton = {
|
| 195 |
+
TextButton(onClick = { prompt.respond(true) }) { Text("Install") }
|
| 196 |
+
},
|
| 197 |
+
dismissButton = {
|
| 198 |
+
TextButton(onClick = { prompt.respond(false) }) { Text("Cancel") }
|
| 199 |
+
},
|
| 200 |
+
)
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
// Re-attach the active session whenever we come back from any overlay.
|
| 204 |
LaunchedEffect(activeId, trayOpen, addonsOpen, consoleOpen) {
|
| 205 |
val id = activeId ?: return@LaunchedEffect
|
|
|
|
| 242 |
extensions = extensions,
|
| 243 |
enabledStates = tabManager.extensionStates,
|
| 244 |
loading = addonsLoading,
|
| 245 |
+
installMessage = installMessage,
|
| 246 |
+
onInstall = { input ->
|
| 247 |
+
installMessage = "Installing…"
|
| 248 |
+
tabManager.installFromAmo(input) { ok, msg -> installMessage = msg }
|
| 249 |
+
},
|
| 250 |
onToggle = { id, enabled -> tabManager.setExtensionEnabled(id, enabled) {} },
|
| 251 |
+
onUninstall = { id -> tabManager.uninstallExtension(id) {} },
|
| 252 |
onDismiss = { addonsOpen = false },
|
| 253 |
)
|
| 254 |
return
|