Offlin33er commited on
Commit
2fa22c6
·
verified ·
1 Parent(s): fb018f6

Pivot v0.6.0: chrome-less shell + ⌘ palette + unrestricted defaults

Browse files
app/src/main/java/dev/nova/browser/BrowserActivity.kt CHANGED
@@ -7,17 +7,12 @@ import androidx.activity.ComponentActivity
7
  import androidx.activity.OnBackPressedCallback
8
  import androidx.activity.compose.setContent
9
  import androidx.compose.foundation.layout.*
10
- import androidx.compose.foundation.lazy.LazyRow
11
- import androidx.compose.foundation.lazy.items
12
  import androidx.compose.material3.*
13
  import androidx.compose.runtime.*
 
14
  import androidx.compose.ui.Modifier
15
- import androidx.compose.ui.focus.onFocusChanged
16
- import androidx.compose.ui.platform.LocalFocusManager
17
- import androidx.compose.ui.text.style.TextOverflow
18
  import androidx.compose.ui.unit.dp
19
  import androidx.compose.ui.viewinterop.AndroidView
20
- import org.mozilla.geckoview.ContentBlocking
21
  import org.mozilla.geckoview.GeckoResult
22
  import org.mozilla.geckoview.GeckoRuntime
23
  import org.mozilla.geckoview.GeckoRuntimeSettings
@@ -26,6 +21,19 @@ import org.mozilla.geckoview.GeckoView
26
  import org.mozilla.geckoview.WebExtension
27
  import org.mozilla.geckoview.WebExtensionController
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  class BrowserActivity : ComponentActivity() {
30
 
31
  companion object {
@@ -39,58 +47,49 @@ class BrowserActivity : ComponentActivity() {
39
  super.onCreate(savedInstanceState)
40
 
41
  if (runtime == null) {
42
- // M6: content blocking (tracking protection) at the runtime level.
43
- // NB: the old GeckoSession.TrackingProtectionPolicy API is gone in
44
- // current GV; the modern API is ContentBlocking settings.
45
  runtime = GeckoRuntime.create(
46
  this,
47
  GeckoRuntimeSettings.Builder()
48
- .contentBlocking(
49
- ContentBlocking.Settings.Builder()
50
- .antiTracking(ContentBlocking.AntiTracking.RECOMMENDED)
51
- .cookieBehavior(ContentBlocking.CookieBehavior.ACCEPT_NON_TRACKERS)
52
- .build()
53
- )
54
  .build()
55
  )
56
- // Layer 2 of the dev console: desktop Firefox DevTools can attach
57
- // via about:debugging over USB / Wi-Fi. GV 147 API:
58
- // GeckoRuntimeSettings.setRemoteDebuggingEnabled(boolean).
59
  runtime!!.settings.setRemoteDebuggingEnabled(true)
60
 
61
- // M5: installs REQUIRE a prompt delegate (GV refuses otherwise).
62
- // The user decision is surfaced as a Compose dialog through
63
- // TabManager.pendingInstall.
64
- runtime!!.webExtensionController.setPromptDelegate(
65
- object : WebExtensionController.PromptDelegate {
66
- override fun onInstallPromptRequest(
67
- extension: WebExtension,
68
- permissions: Array<out String>,
69
- origins: Array<out String>,
70
- dataCollectionPermissions: Array<out String>,
71
- ): GeckoResult<WebExtension.PermissionPromptResponse> {
72
- val result = GeckoResult<WebExtension.PermissionPromptResponse>()
73
- val name = extension.metaData?.name ?: extension.id
74
- tabManager.pendingInstall.value = TabManager.InstallPrompt(
75
- name = name,
76
- permissions = permissions.toList(),
77
- origins = origins.toList(),
78
- ) { allow ->
79
- tabManager.pendingInstall.value = null
80
- result.complete(
81
- WebExtension.PermissionPromptResponse(allow, false, false)
82
  )
83
  }
84
- return result
85
  }
86
- }
87
- )
88
  }
89
  tabManager = TabManager(runtime!!, this)
90
 
91
  installDevConsoleExtension()
92
 
93
- // Hardware back button: navigate the page back before leaving the app.
 
94
  onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
95
  override fun handleOnBackPressed() {
96
  if (tabManager.canGoBack()) {
@@ -123,10 +122,6 @@ class BrowserActivity : ComponentActivity() {
123
  tabManager.persistSession()
124
  }
125
 
126
- /**
127
- * Installs the bundled dev-console extension (idempotent) and wires the
128
- * background-script native messaging channel.
129
- */
130
  private fun installDevConsoleExtension() {
131
  val controller = runtime!!.webExtensionController
132
  controller.ensureBuiltIn("resource://android/assets/devconsole/", "devconsole@nova")
@@ -142,7 +137,6 @@ class BrowserActivity : ComponentActivity() {
142
  )
143
  }
144
 
145
- /** Receives messages from the extension's background script. */
146
  private inner class NovaBackgroundMessageDelegate : WebExtension.MessageDelegate {
147
  override fun onMessage(
148
  nativeApp: String,
@@ -155,76 +149,55 @@ class BrowserActivity : ComponentActivity() {
155
  }
156
 
157
  // ------------------------------------------------------------------
158
- // UI
159
  // ------------------------------------------------------------------
160
  @Composable
161
  private fun NovaUI() {
162
- var urlInput by remember { mutableStateOf("https://example.com") }
163
- var urlFocused by remember { mutableStateOf(false) }
164
  var trayOpen by remember { mutableStateOf(false) }
165
  var addonsOpen by remember { mutableStateOf(false) }
166
  var consoleOpen by remember { mutableStateOf(false) }
167
  val geckoView = remember { GeckoView(this) }
168
- val focusManager = LocalFocusManager.current
169
  val activeId by tabManager.activeTabId
170
 
171
- val canGoBack by remember { derivedStateOf { tabManager.canGoBack() } }
172
- val canGoForward by remember { derivedStateOf { tabManager.canGoForward() } }
173
-
174
- // M3 add-ons manager state
175
- var extensions by remember { mutableStateOf<List<TabManager.ExtInfo>>(emptyList()) }
176
- var addonsLoading by remember { mutableStateOf(false) }
177
- var installMessage by remember { mutableStateOf("") }
178
-
179
  val loading = activeId != null && tabManager.loadingStates[activeId!!] == true
180
  val progress = activeId?.let { tabManager.progressStates[it] } ?: 0
181
 
182
- // M5: install permission prompt — visible over every screen.
183
- val pendingInstall by tabManager.pendingInstall
184
- pendingInstall?.let { prompt ->
185
- AlertDialog(
186
- onDismissRequest = { prompt.respond(false) },
187
- title = { Text("Install \"${prompt.name}\"?") },
188
- text = {
189
- Column {
190
- if (prompt.permissions.isEmpty()) {
191
- Text("This add-on requests no special permissions.")
192
- } else {
193
- Text("It requests access to:")
194
- prompt.permissions.forEach { Text("• $it") }
195
- }
196
- if (prompt.origins.isNotEmpty()) {
197
- Text("Site access:")
198
- prompt.origins.forEach { Text("• $it") }
199
- }
200
- }
201
- },
202
- confirmButton = {
203
- TextButton(onClick = { prompt.respond(true) }) { Text("Install") }
204
- },
205
- dismissButton = {
206
- TextButton(onClick = { prompt.respond(false) }) { Text("Cancel") }
207
- },
208
- )
209
- }
210
-
211
  // Re-attach the active session whenever we come back from any overlay.
212
- LaunchedEffect(activeId, trayOpen, addonsOpen, consoleOpen) {
213
  val id = activeId ?: return@LaunchedEffect
214
  val tab = tabManager.tabs.firstOrNull { t -> t.id == id } ?: return@LaunchedEffect
215
  geckoView.setSession(tab.session)
216
  }
217
 
218
- // M2: live URL sync — follow the active tab's navigation while the
219
- // user is not editing the address bar.
220
- val activeUrl = activeId?.let { tabManager.lastUrls[it] }
221
- LaunchedEffect(activeUrl) {
222
- if (!urlFocused && activeUrl != null) urlInput = activeUrl
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  }
224
 
225
- // M2: autocomplete suggestions from history while typing
226
- val suggestions = if (urlFocused) tabManager.suggestionsFor(urlInput) else emptyList()
227
-
228
  if (trayOpen) {
229
  TabTray(
230
  tabs = tabManager.tabs.toList(),
@@ -239,6 +212,10 @@ class BrowserActivity : ComponentActivity() {
239
  }
240
 
241
  if (addonsOpen) {
 
 
 
 
242
  LaunchedEffect(Unit) {
243
  addonsLoading = true
244
  tabManager.refreshExtensions { list ->
@@ -253,7 +230,7 @@ class BrowserActivity : ComponentActivity() {
253
  installMessage = installMessage,
254
  onInstall = { input ->
255
  installMessage = "Installing…"
256
- tabManager.installFromAmo(input) { ok, msg -> installMessage = msg }
257
  },
258
  onToggle = { id, enabled -> tabManager.setExtensionEnabled(id, enabled) {} },
259
  onUninstall = { id -> tabManager.uninstallExtension(id) {} },
@@ -271,67 +248,14 @@ class BrowserActivity : ComponentActivity() {
271
  return
272
  }
273
 
274
- Column(Modifier.fillMaxSize()) {
275
- OutlinedTextField(
276
- value = urlInput,
277
- onValueChange = { urlInput = it },
278
- modifier = Modifier
279
- .fillMaxWidth()
280
- .padding(horizontal = 8.dp, vertical = 4.dp)
281
- .onFocusChanged { urlFocused = it.isFocused },
282
- label = { Text("Search or enter address") },
283
- singleLine = true,
284
  )
285
 
286
- // Autocomplete dropdown (history matches, most recent first)
287
- if (urlFocused && suggestions.isNotEmpty()) {
288
- Surface(
289
- tonalElevation = 4.dp,
290
- modifier = Modifier
291
- .fillMaxWidth()
292
- .padding(horizontal = 8.dp),
293
- ) {
294
- Column {
295
- suggestions.forEach { suggestion ->
296
- TextButton(
297
- onClick = {
298
- urlInput = suggestion
299
- urlFocused = false
300
- focusManager.clearFocus()
301
- tabManager.activeSession()?.loadUri(suggestion)
302
- },
303
- modifier = Modifier.fillMaxWidth(),
304
- ) {
305
- Text(suggestion, maxLines = 1, overflow = TextOverflow.Ellipsis)
306
- }
307
- }
308
- }
309
- }
310
- }
311
-
312
- Row(Modifier.padding(horizontal = 8.dp)) {
313
- TextButton(
314
- onClick = { tabManager.activeSession()?.goBack() },
315
- enabled = canGoBack,
316
- ) { Text("◀") }
317
- TextButton(
318
- onClick = { tabManager.activeSession()?.goForward() },
319
- enabled = canGoForward,
320
- ) { Text("▶") }
321
- TextButton(onClick = { tabManager.activeSession()?.reload() }) { Text("⟳") }
322
- TextButton(onClick = {
323
- focusManager.clearFocus()
324
- tabManager.activeSession()?.loadUri(normalize(urlInput))
325
- }) { Text("Go") }
326
- TextButton(onClick = { tabManager.open("about:blank") }) { Text("+") }
327
- TextButton(onClick = { trayOpen = true }) { Text("Tabs ${tabManager.tabs.size}") }
328
- TextButton(onClick = { addonsOpen = true }) { Text("Add-ons") }
329
- TextButton(onClick = { consoleOpen = true }) {
330
- Text("Console ${tabManager.consoleLines.size}")
331
- }
332
- }
333
-
334
- // M2: loading bar for the active tab
335
  if (loading) {
336
  LinearProgressIndicator(
337
  progress = { progress / 100f },
@@ -339,43 +263,14 @@ class BrowserActivity : ComponentActivity() {
339
  )
340
  }
341
 
342
- // Tab strip
343
- LazyRow(Modifier.padding(horizontal = 8.dp)) {
344
- items(tabManager.tabs, key = { it.id }) { tab ->
345
- AssistChip(
346
- onClick = { tabManager.activate(tab.id) },
347
- label = {
348
- Text(
349
- "Tab ${tab.id}" + (if (tab.id == activeId) " ●" else ""),
350
- maxLines = 1,
351
- )
352
- },
353
- trailingIcon = {
354
- TextButton(onClick = { tabManager.close(tab.id) }) { Text("✕") }
355
- },
356
- modifier = Modifier.padding(end = 4.dp),
357
- )
358
- }
359
- }
360
-
361
- // Console preview (full screen lives behind the Console button)
362
- val lines = tabManager.consoleLines.takeLast(3)
363
- if (lines.isNotEmpty()) {
364
- Surface(
365
- tonalElevation = 2.dp,
366
- modifier = Modifier
367
- .fillMaxWidth()
368
- .heightIn(max = 72.dp),
369
- ) {
370
- Column(Modifier.padding(6.dp)) {
371
- lines.forEach { line -> Text(line, style = MaterialTheme.typography.labelSmall, maxLines = 1) }
372
- }
373
- }
374
- }
375
-
376
- AndroidView(
377
- factory = { geckoView },
378
- modifier = Modifier.fillMaxWidth().weight(1f),
379
  )
380
  }
381
  }
 
7
  import androidx.activity.OnBackPressedCallback
8
  import androidx.activity.compose.setContent
9
  import androidx.compose.foundation.layout.*
 
 
10
  import androidx.compose.material3.*
11
  import androidx.compose.runtime.*
12
+ import androidx.compose.ui.Alignment
13
  import androidx.compose.ui.Modifier
 
 
 
14
  import androidx.compose.ui.unit.dp
15
  import androidx.compose.ui.viewinterop.AndroidView
 
16
  import org.mozilla.geckoview.GeckoResult
17
  import org.mozilla.geckoview.GeckoRuntime
18
  import org.mozilla.geckoview.GeckoRuntimeSettings
 
21
  import org.mozilla.geckoview.WebExtension
22
  import org.mozilla.geckoview.WebExtensionController
23
 
24
+ /**
25
+ * Nova after the pivot: a chrome-less, unrestricted browser.
26
+ *
27
+ * Unrestricted defaults:
28
+ * - NO tracking protection / content blocking (conventional browsers ship it on).
29
+ * - Extension install permissions AUTO-GRANTED (no prompts).
30
+ * - about:config enabled (full engine configuration surface).
31
+ * - Remote debugging always on (desktop Firefox DevTools via about:debugging).
32
+ *
33
+ * New UI paradigm: no URL bar, no toolbar, no tab strip. Content is
34
+ * edge-to-edge; a floating ⌘ button summons the command palette which routes
35
+ * everything (navigate, search, tabs, add-ons, console).
36
+ */
37
  class BrowserActivity : ComponentActivity() {
38
 
39
  companion object {
 
47
  super.onCreate(savedInstanceState)
48
 
49
  if (runtime == null) {
50
+ // Unrestricted: no ContentBlocking settings passed — Gecko's default
51
+ // is no anti-tracking policy. about:config gives full engine access.
 
52
  runtime = GeckoRuntime.create(
53
  this,
54
  GeckoRuntimeSettings.Builder()
55
+ .aboutConfigEnabled(true)
 
 
 
 
 
56
  .build()
57
  )
58
+ // Desktop Firefox DevTools attach via about:debugging (USB / Wi-Fi).
 
 
59
  runtime!!.settings.setRemoteDebuggingEnabled(true)
60
 
61
+ // Unrestricted: install permission requests are auto-granted, no
62
+ // dialog. (GV refuses installs without a registered PromptDelegate
63
+ // that returns a GeckoResult, so we register one that always
64
+ // allows. Flip AUTO_GRANT to false to restore the prompt UI.)
65
+ if (AUTO_GRANT_PERMISSIONS) {
66
+ runtime!!.webExtensionController.setPromptDelegate(
67
+ object : WebExtensionController.PromptDelegate {
68
+ override fun onInstallPromptRequest(
69
+ extension: WebExtension,
70
+ permissions: Array<out String>,
71
+ origins: Array<out String>,
72
+ dataCollectionPermissions: Array<out String>,
73
+ ): GeckoResult<WebExtension.PermissionPromptResponse> {
74
+ Log.i(
75
+ "Nova",
76
+ "Auto-granting install permissions for ${extension.id}: " +
77
+ "permissions=${permissions.toList()} origins=${origins.toList()}"
78
+ )
79
+ return GeckoResult.fromValue(
80
+ WebExtension.PermissionPromptResponse(true, false, false)
 
81
  )
82
  }
 
83
  }
84
+ )
85
+ }
86
  }
87
  tabManager = TabManager(runtime!!, this)
88
 
89
  installDevConsoleExtension()
90
 
91
+ // Hardware back: navigate the page back before leaving the app; if a
92
+ // palette/screen is open it consumes back instead.
93
  onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
94
  override fun handleOnBackPressed() {
95
  if (tabManager.canGoBack()) {
 
122
  tabManager.persistSession()
123
  }
124
 
 
 
 
 
125
  private fun installDevConsoleExtension() {
126
  val controller = runtime!!.webExtensionController
127
  controller.ensureBuiltIn("resource://android/assets/devconsole/", "devconsole@nova")
 
137
  )
138
  }
139
 
 
140
  private inner class NovaBackgroundMessageDelegate : WebExtension.MessageDelegate {
141
  override fun onMessage(
142
  nativeApp: String,
 
149
  }
150
 
151
  // ------------------------------------------------------------------
152
+ // UI: edge-to-edge content + floating ⌘ + overlays
153
  // ------------------------------------------------------------------
154
  @Composable
155
  private fun NovaUI() {
156
+ var paletteOpen by remember { mutableStateOf(false) }
 
157
  var trayOpen by remember { mutableStateOf(false) }
158
  var addonsOpen by remember { mutableStateOf(false) }
159
  var consoleOpen by remember { mutableStateOf(false) }
160
  val geckoView = remember { GeckoView(this) }
 
161
  val activeId by tabManager.activeTabId
162
 
 
 
 
 
 
 
 
 
163
  val loading = activeId != null && tabManager.loadingStates[activeId!!] == true
164
  val progress = activeId?.let { tabManager.progressStates[it] } ?: 0
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  // Re-attach the active session whenever we come back from any overlay.
167
+ LaunchedEffect(activeId, paletteOpen, trayOpen, addonsOpen, consoleOpen) {
168
  val id = activeId ?: return@LaunchedEffect
169
  val tab = tabManager.tabs.firstOrNull { t -> t.id == id } ?: return@LaunchedEffect
170
  geckoView.setSession(tab.session)
171
  }
172
 
173
+ if (paletteOpen) {
174
+ CommandPalette(
175
+ tabCount = tabManager.tabs.size,
176
+ activeTabId = activeId,
177
+ onSubmit = { input ->
178
+ paletteOpen = false
179
+ tabManager.activeSession()?.loadUri(normalize(input))
180
+ },
181
+ onCommand = { cmd ->
182
+ paletteOpen = false
183
+ when (cmd) {
184
+ "new_tab" -> tabManager.open("about:blank")
185
+ "close_tab" -> {
186
+ val id = activeId
187
+ if (id != null) tabManager.close(id)
188
+ }
189
+ "reload" -> tabManager.activeSession()?.reload()
190
+ "tray" -> trayOpen = true
191
+ "addons" -> addonsOpen = true
192
+ "console" -> consoleOpen = true
193
+ "clear_console" -> tabManager.consoleLines.clear()
194
+ }
195
+ },
196
+ onDismiss = { paletteOpen = false },
197
+ )
198
+ return
199
  }
200
 
 
 
 
201
  if (trayOpen) {
202
  TabTray(
203
  tabs = tabManager.tabs.toList(),
 
212
  }
213
 
214
  if (addonsOpen) {
215
+ var extensions by remember { mutableStateOf<List<TabManager.ExtInfo>>(emptyList()) }
216
+ var addonsLoading by remember { mutableStateOf(false) }
217
+ var installMessage by remember { mutableStateOf("") }
218
+
219
  LaunchedEffect(Unit) {
220
  addonsLoading = true
221
  tabManager.refreshExtensions { list ->
 
230
  installMessage = installMessage,
231
  onInstall = { input ->
232
  installMessage = "Installing…"
233
+ tabManager.installFromAmo(input) { _, msg -> installMessage = msg }
234
  },
235
  onToggle = { id, enabled -> tabManager.setExtensionEnabled(id, enabled) {} },
236
  onUninstall = { id -> tabManager.uninstallExtension(id) {} },
 
248
  return
249
  }
250
 
251
+ // Chrome-less browsing surface
252
+ Box(Modifier.fillMaxSize()) {
253
+ AndroidView(
254
+ factory = { geckoView },
255
+ modifier = Modifier.fillMaxSize(),
 
 
 
 
 
256
  )
257
 
258
+ // Minimal status: loading bar hugging the top edge
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  if (loading) {
260
  LinearProgressIndicator(
261
  progress = { progress / 100f },
 
263
  )
264
  }
265
 
266
+ // The single piece of chrome: ⌘ summons the palette
267
+ ExtendedFloatingActionButton(
268
+ text = { Text("⌘") },
269
+ icon = {},
270
+ onClick = { paletteOpen = true },
271
+ modifier = Modifier
272
+ .align(Alignment.BottomEnd)
273
+ .padding(20.dp),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  )
275
  }
276
  }