Offlin33er commited on
Commit
786ab09
·
verified ·
1 Parent(s): 65d7ed7

M5: AMO install flow, prompt model, uninstall; M6: nothing here

Browse files
app/src/main/java/dev/nova/browser/TabManager.kt CHANGED
@@ -21,10 +21,12 @@ import java.io.File
21
  * Navigation/loading state arrives via delegates (no polling getters exist).
22
  * Session restore is URL-level. History powers the URL bar autocomplete.
23
  *
24
- * M3 extension registry: WebExtensionController.list() refreshes a local
25
- * registry of installed add-ons; enable/disable go through the controller
26
- * with EnableSource.USER. Enabled state is tracked locally (the current
27
- * WebExtension javadoc does not expose a stable isEnabled accessor).
 
 
28
  */
29
  class TabManager(private val runtime: GeckoRuntime, private val context: Context) {
30
 
@@ -36,6 +38,15 @@ class TabManager(private val runtime: GeckoRuntime, private val context: Context
36
  val name: String,
37
  val version: String,
38
  val description: String,
 
 
 
 
 
 
 
 
 
39
  )
40
 
41
  /** Observable tab list for Compose. */
@@ -60,10 +71,13 @@ class TabManager(private val runtime: GeckoRuntime, private val context: Context
60
  /** Console lines forwarded from the dev-console extension. */
61
  val consoleLines = mutableStateListOf<String>()
62
 
63
- /** M3: extension id → enabled, tracked by Nova (see class comment). */
64
  val extensionStates = mutableStateMapOf<String, Boolean>()
65
  private val extensionsById = mutableMapOf<String, WebExtension>()
66
 
 
 
 
67
  private var nextId = 1
68
  private var restoring = false
69
 
@@ -137,7 +151,12 @@ class TabManager(private val runtime: GeckoRuntime, private val context: Context
137
  }
138
  }
139
 
140
- session.open(runtime)
 
 
 
 
 
141
 
142
  // Content scripts of the dev-console extension can sendNativeMessage to us.
143
  devExtension?.let { ext ->
@@ -186,7 +205,7 @@ class TabManager(private val runtime: GeckoRuntime, private val context: Context
186
  activeTabId.value?.let { canGoForwardStates[it] == true } ?: false
187
 
188
  // ------------------------------------------------------------------
189
- // Extension registry (M3)
190
  // ------------------------------------------------------------------
191
 
192
  /**
@@ -200,12 +219,12 @@ class TabManager(private val runtime: GeckoRuntime, private val context: Context
200
  val infos = list?.map { ext ->
201
  extensionsById[ext.id] = ext
202
  if (!extensionStates.containsKey(ext.id)) extensionStates[ext.id] = true
203
- val name = ext.metaData?.name
204
  TabManager.ExtInfo(
205
  id = ext.id,
206
- name = name?.ifBlank { ext.id } ?: ext.id,
207
  version = ext.metaData?.version ?: "",
208
  description = ext.metaData?.description ?: "",
 
209
  )
210
  } ?: emptyList()
211
  callback(infos)
@@ -248,6 +267,65 @@ class TabManager(private val runtime: GeckoRuntime, private val context: Context
248
  )
249
  }
250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  // ------------------------------------------------------------------
252
  // History (M2)
253
  // ------------------------------------------------------------------
 
21
  * Navigation/loading state arrives via delegates (no polling getters exist).
22
  * Session restore is URL-level. History powers the URL bar autocomplete.
23
  *
24
+ * M3/M5 extension registry: WebExtensionController.list() refreshes a local
25
+ * registry; enable/disable/uninstall/install go through the controller.
26
+ * Enabled state is tracked locally (no stable isEnabled accessor in the
27
+ * current WebExtension javadoc). Install permission prompts are surfaced to
28
+ * the UI through pendingInstall — GV refuses installs without a
29
+ * PromptDelegate that returns a GeckoResult.
30
  */
31
  class TabManager(private val runtime: GeckoRuntime, private val context: Context) {
32
 
 
38
  val name: String,
39
  val version: String,
40
  val description: String,
41
+ val isBuiltIn: Boolean,
42
+ )
43
+
44
+ /** M5: an install-permission prompt awaiting the user's decision. */
45
+ data class InstallPrompt(
46
+ val name: String,
47
+ val permissions: List<String>,
48
+ val origins: List<String>,
49
+ val respond: (allow: Boolean) -> Unit,
50
  )
51
 
52
  /** Observable tab list for Compose. */
 
71
  /** Console lines forwarded from the dev-console extension. */
72
  val consoleLines = mutableStateListOf<String>()
73
 
74
+ /** Extension id → enabled, tracked by Nova (see class comment). */
75
  val extensionStates = mutableStateMapOf<String, Boolean>()
76
  private val extensionsById = mutableMapOf<String, WebExtension>()
77
 
78
+ /** M5: install-permission prompt currently awaiting user decision. */
79
+ val pendingInstall = mutableStateOf<InstallPrompt?>(null)
80
+
81
  private var nextId = 1
82
  private var restoring = false
83
 
 
151
  }
152
  }
153
 
154
+ // M6: per-session tracking protection on top of the runtime policy.
155
+ val settings = GeckoSessionSettings.Builder()
156
+ .useTrackingProtection(true)
157
+ .build()
158
+
159
+ session.open(runtime, settings)
160
 
161
  // Content scripts of the dev-console extension can sendNativeMessage to us.
162
  devExtension?.let { ext ->
 
205
  activeTabId.value?.let { canGoForwardStates[it] == true } ?: false
206
 
207
  // ------------------------------------------------------------------
208
+ // Extension registry (M3/M5)
209
  // ------------------------------------------------------------------
210
 
211
  /**
 
219
  val infos = list?.map { ext ->
220
  extensionsById[ext.id] = ext
221
  if (!extensionStates.containsKey(ext.id)) extensionStates[ext.id] = true
 
222
  TabManager.ExtInfo(
223
  id = ext.id,
224
+ name = ext.metaData?.name?.ifBlank { ext.id } ?: ext.id,
225
  version = ext.metaData?.version ?: "",
226
  description = ext.metaData?.description ?: "",
227
+ isBuiltIn = ext.isBuiltIn,
228
  )
229
  } ?: emptyList()
230
  callback(infos)
 
267
  )
268
  }
269
 
270
+ /** M5: uninstalls a non-builtin extension. */
271
+ fun uninstallExtension(id: String, onDone: () -> Unit) {
272
+ val ext = extensionsById[id]
273
+ if (ext == null) {
274
+ Log.w("Nova", "uninstallExtension: unknown extension $id")
275
+ onDone()
276
+ return
277
+ }
278
+ runtime.webExtensionController.uninstall(ext).accept(
279
+ {
280
+ extensionsById.remove(id)
281
+ extensionStates.remove(id)
282
+ Log.i("Nova", "Extension $id uninstalled")
283
+ onDone()
284
+ },
285
+ { error ->
286
+ Log.e("Nova", "uninstall failed for $id", error)
287
+ onDone()
288
+ }
289
+ )
290
+ }
291
+
292
+ /**
293
+ * M5: installs an AMO add-on from its .xpi URL or add-on page URL.
294
+ * install(uri) accepts a remote https: .xpi; GV downloads, validates the
295
+ * Mozilla signature, then raises onInstallPromptRequest via the prompt
296
+ * delegate (see BrowserActivity) — the user decision flows through
297
+ * pendingInstall.
298
+ */
299
+ fun installFromAmo(input: String, onResult: (ok: Boolean, message: String) -> Unit) {
300
+ val trimmed = input.trim()
301
+ val xpiUrl = when {
302
+ trimmed.endsWith(".xpi") -> trimmed
303
+ trimmed.contains("addons.mozilla.org") && trimmed.contains("/addon/") -> {
304
+ val slug = trimmed.substringAfter("/addon/").substringBefore("/").trim('/')
305
+ if (slug.isBlank()) null else "https://addons.mozilla.org/firefox/downloads/latest/$slug/addon.xpi"
306
+ }
307
+ else -> null
308
+ }
309
+ if (xpiUrl == null) {
310
+ onResult(false, "Paste an AMO add-on URL (addons.mozilla.org/…/addon/…) or a direct .xpi link.")
311
+ return
312
+ }
313
+ Log.i("Nova", "Installing extension from $xpiUrl")
314
+ runtime.webExtensionController.install(xpiUrl, WebExtensionController.INSTALLATION_METHOD_MANAGER).accept(
315
+ { ext ->
316
+ if (ext != null) {
317
+ extensionsById[ext.id] = ext
318
+ extensionStates[ext.id] = true
319
+ }
320
+ onResult(true, "Installed ${ext?.id ?: "add-on"}")
321
+ },
322
+ { error ->
323
+ Log.e("Nova", "install failed", error)
324
+ onResult(false, "Install failed: ${error.message}")
325
+ }
326
+ )
327
+ }
328
+
329
  // ------------------------------------------------------------------
330
  // History (M2)
331
  // ------------------------------------------------------------------