Skip to content

P1: ad blocker, site permissions, Safe Browsing, state restore - #14

Merged
GothwadTech merged 2 commits into
mainfrom
feat/p1-features
Nov 24, 2026
Merged

GothwadTech merged 2 commits into
mainfrom
feat/p1-features

Conversation

@GothwadTech

@GothwadTech GothwadTech commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Every P1 gap from the audit, each with the UI the user needs to control it.

1. Ad and tracker blocker (with on/off)

  • browser/AdBlocker.kt — host matching from a bundled list (res/raw/adblock_hosts.txt, ~120 curated ad/analytics/tracker hosts). Matches the host or any parent domain, never blocks main-frame requests, never touches CDNs that serve page assets (gstatic, fbcdn, cloudfront, jsdelivr…).
  • WebViewPool.shouldInterceptRequest returns an empty 200 for blocked hosts, so the page keeps rendering.
  • UI: Settings → Ad blocking and permissions → switch + live "N requests blocked since launch" + Reset. Off means every request loads.

2. Site permissions (camera / microphone / location) with UI

  • onPermissionRequest (video/audio capture) and onGeolocationPermissionsShowPrompt now forward to a browser-owned dialog: "example.com wants to use your camera" → Allow / Block, remembered per origin.
  • Before granting the page, the app requests the real Android permission, so camera and mic actually work instead of silently failing.
  • SitePermissionStore (DataStore) keeps the decisions; Settings lists every allowed site with Remove and Clear all; a switch can deny every request outright.
  • Manifest gains CAMERA, RECORD_AUDIO, ACCESS_FINE/COARSE_LOCATION, and setGeolocationEnabled(true).

3. Safe Browsing

  • onSafeBrowsingHit raises a dialog with the threat label (phishing / harmful software …), Back to safety as the default action and an explicit Continue anyway. Nothing proceeds silently.

4. WebView state restore

  • MainActivity.onSaveInstanceState writes every live WebView's state into the bundle; the pool restores it when the tab is recreated. Rotation and process death keep scroll position, form input and back/forward history.

5. Manifest

  • <queries> for https, http, market, mailto so external links can be resolved on Android 11+.

Honest limits

  • The blocklist is a curated starter set, not EasyList; it stops the common networks, not every first-party ad. A user-editable list is the next step.
  • Incognito still shares the process cookie jar (WebView limitation); permissions behave the same in both modes.
  • Download management (progress, pause/resume, share via FileProvider) is not in this PR — it is the remaining P1 item and a UI-heavy change on its own.

Checks

The PR's own Quality Gate & Tests run compiles the app, runs unit tests and lint.

Summary by CodeRabbit

  • New Features
    • Added ad and tracker blocking, with a setting to enable or disable it and a blocked-request count in Settings.
    • Added site permission prompts for camera, microphone, and location, with options to remember decisions and manage saved permissions.
    • Added Safe Browsing warnings with an option to return to safety or continue.
    • Browser tabs now restore their navigation state after the app is recreated.

Ad blocker
- AdBlocker: host-based blocking from a bundled, curated list (res/raw/adblock_hosts.txt),
  matched on the host name only, main-frame requests never blocked
- WebViewPool.shouldInterceptRequest returns an empty 200 for blocked hosts
- Settings > Ad blocking and permissions: on/off switch, live blocked count, reset

Site permissions
- WebViewPool.onPermissionRequest (camera/mic) and onGeolocationPermissionsShowPrompt
  forward to a browser-owned dialog: Allow / Block, remembered per origin
- the app asks Android for the real permission before granting the page, so camera and
  microphone actually work
- SitePermissionStore keeps decisions in DataStore; Settings lists allowed sites with
  Remove and Clear all; prompts can be switched off entirely

Safe Browsing
- onSafeBrowsingHit raises a dialog with the threat label, Back to safety (default) and
  an explicit Continue anyway

State restore
- MainActivity saves every WebView state on onSaveInstanceState and the pool restores it
  on the next create, so rotation and process death keep scroll, form input and history

Also: <queries> for web/app links, camera/mic/location permissions, geolocation enabled.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

Changes: Browser Request Controls

Layer / File(s) Summary
Settings and permission decision storage
app/src/main/java/com/bansify/browser/data/BrowserModels.kt, app/src/main/java/com/bansify/browser/data/BrowserPreferences.kt, app/src/main/java/com/bansify/browser/data/SitePermissions.kt
Browser settings add ad-blocking and site-permission prompt preferences. Site-permission decisions are stored by origin and permission, with lookup, update, and removal operations.
Ad-block request filtering
app/src/main/java/com/bansify/browser/browser/AdBlocker.kt, app/src/main/java/com/bansify/browser/browser/WebViewPool.kt, app/src/main/res/raw/adblock_hosts.txt
AdBlocker loads host entries, matches hosts and subdomains, excludes main-frame requests, and counts blocked requests. WebViewPool returns an empty response for matching requests when blocking is enabled.
Site permissions and Safe Browsing
app/src/main/AndroidManifest.xml, app/src/main/java/com/bansify/browser/browser/WebViewPool.kt, app/src/main/java/com/bansify/browser/viewmodel/BrowserViewModel.kt
The manifest declares runtime permissions and package visibility queries. WebViewPool forwards site-permission requests and Safe Browsing hits. BrowserViewModel applies remembered decisions, publishes pending requests and warnings, and resolves Safe Browsing responses.
Permission dialogs and settings controls
app/src/main/java/com/bansify/browser/ui/BrowserApp.kt, app/src/main/java/com/bansify/browser/ui/components/SitePermissionDialogs.kt, app/src/main/java/com/bansify/browser/ui/screens/SettingsScreen.kt, app/src/main/java/com/bansify/browser/ui/screens/SettingsSubScreens.kt
BrowserApp displays permission and Safe Browsing dialogs and requests Android permissions when required. Settings expose blocking and prompt switches, the blocked-request count, and controls to remove saved permission decisions.

WebView State Restoration

Layer / File(s) Summary
Save and restore WebView navigation state
app/src/main/java/com/bansify/browser/MainActivity.kt, app/src/main/java/com/bansify/browser/browser/WebViewPool.kt
MainActivity saves active pool state and supplies it during creation. WebViewPool saves live WebView state by tab ID and attempts to restore state when creating a WebView.

Change: Feature

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

The class already had a companion object holding DESKTOP_USER_AGENT; adding a
second one for active/pendingState broke the build. The two state properties now
live in the existing companion.
@GothwadTech
GothwadTech merged commit 5b04e54 into main Nov 24, 2026
4 of 5 checks passed
@GothwadTech
GothwadTech deleted the feat/p1-features branch November 24, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant