Developing a browser app that uses an alternative browser engine
At a glance
| Item | Summary |
|---|---|
| Purpose | Create a browser app and associated extensions. |
| App architecture | A C/Objective-C header, Objective-C, Swift sample with the source-visible chain BrowserApp → ActivityViewController → BrowserPageViewModel → ServiceProvider → BrowserEngineKit APIs. |
| Main patterns | Model-View-ViewModel, View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, SwiftUI environment injection, Binding-based state propagation |
| Project style | 38 scanned source file(s) across C/Objective-C header, Objective-C, Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, Task, await suspension point, Task closure isolated to MainActor; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper, ObservableObject, @Published. |
| Key frameworks/packages | Foundation, os, XPC, BrowserEngineKit, CustomBrowserEngine; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── BrowserExample/
├── BrowserApp/
│ ├── AlertManager.swift
│ ├── BrowserApp.swift
│ ├── BrowserPageViewModel.swift
│ ├── TabViewModel.swift
│ └── BrowserPage.swift
├── NetworkingExtension/
│ └── NetworkingExtension.swift
├── RenderingExtension/
│ └── RenderingExtension.swift
├── WebContentExtension/
│ └── WebContentExtension.swift
└── CustomBrowserEngine/
├── UIProcess/
│ ├── WebView.swift
│ └── WebContentView.swift
├── XPC/
│ └── XPCCodable.swift
└── NetworkProcess/
└── NetworkSession.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: C/Objective-C header, Objective-C, Swift.
- The verified tree contains 14 project/configuration file(s) and 62 source declaration(s).
Overall architecture
flowchart LR
N1["BrowserApp"]
N2["ActivityViewController"]
N3["BrowserPageViewModel"]
N4["ServiceProvider"]
N5["BrowserEngineKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
BrowserExample/BrowserApp/BrowserApp.swift:11 — architecture anchor
@main
struct BrowserApp: App {
@State var browserPageViewModel = BrowserPageViewModel()
@State var alertManager = AlertManager()
var body: some Scene {
WindowGroup {
NavigationStack {
BrowserPage(model: browserPageViewModel)
.navigationTitle("Browser Example")
.navigationBarTitleDisplayMode(.inline)
}
.presentingAlerts(from: alertManager)
.environmentObject(alertManager)
.onOpenURL { open($0) }
}
}
private func open(_ url: URL) {
Task {
do {
try await browserPageViewModel.createNewTab(destination: .url(url), activate: true)
} catch let error {
await alertManager.present(error: error, title: "Failed to open url")
}
}
}
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into BrowserEngineKit.
Ownership and state
classDiagram
Alert *-- UUID : id
Alert *-- String : title
Alert *-- String : message
Alert *-- Array : buttons
Ownership evidence
BrowserExample/BrowserApp/AlertManager.swift:13 — stored dependency or nearest verified ownership anchor
public struct Alert: Identifiable {
// ...
public var id = UUID()
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
Alert |
UUID (id) |
owns value state | App/module collaborators |
Alert |
String (title) |
owns value state | App/module collaborators |
Alert |
String (message) |
owns value state | App/module collaborators |
Alert |
Array (buttons) |
owns value state | App/module collaborators |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | BrowserExample/BrowserApp/AlertManager.swift:88 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | BrowserExample/BrowserApp/BrowserApp.swift:32 |
| Suspension boundary | await suspension point |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | BrowserExample/BrowserApp/BrowserApp.swift:34 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | BrowserExample/BrowserApp/BrowserPageViewModel.swift:60 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
BrowserExample/BrowserApp/AlertManager.swift:88 — representative execution boundary
@MainActor
public class AlertManager: ObservableObject {
// ...
@Published public var currentAlert: Alert? = nil
// ...
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | BrowserExample/BrowserApp/ActivityViewButton.swift:34 |
| State propagation | ObservableObject |
ObservableObject supplies an observation contract. | BrowserExample/BrowserApp/AlertManager.swift:89 |
| State propagation | @Published |
A published property can emit owner-controlled changes. | BrowserExample/BrowserApp/AlertManager.swift:92 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | BrowserExample/BrowserApp/AlertManager.swift:8 |
| Source import | os |
The cited file imports this module; runtime use and architectural role are not inferred. | BrowserExample/BrowserApp/ActivityViewButton.swift:10 |
| Source import | XPC |
The cited file imports this module; runtime use and architectural role are not inferred. | BrowserExample/CustomBrowserEngine/NetworkProcess/NetworkSession.swift:9 |
| Source import | BrowserEngineKit |
The cited file imports this module; runtime use and architectural role are not inferred. | BrowserExample/CustomBrowserEngine/RenderingProcess/RenderingExtensionProxy.swift:9 |
| Source import | CustomBrowserEngine |
The cited file imports this module; runtime use and architectural role are not inferred. | BrowserExample/BrowserApp/BrowserApp.swift:9 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
BrowserExample/CustomBrowserEngine/UIProcess/WebView.swift:23 — representative type boundary
public protocol WebViewUIDelegate: AnyObject {
func webViewDidStartLoading(_ webView: WebView)
func webViewDidStopLoading(_ webView: WebView)
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
BrowserApp |
Application entry and top-level composition | App |
WebViewUIDelegate |
Defines a capability or collaboration contract | AnyObject |
ServiceProvider |
Defines a capability or collaboration contract | Concrete collaborators/imported frameworks |
AlertManager |
Long-lived feature or framework coordination | ObservableObject |
BrowserPageViewModel |
UI-facing state and feature coordination | ObservableObject |
TabViewModel |
UI-facing state and feature coordination | ObservableObject |
WebView |
User-interface presentation and input forwarding | UIView |
TabContentView |
User-interface presentation and input forwarding | View |
NetworkSession |
Owns a session-scoped interaction | NSObject |
WebContentView |
User-interface presentation and input forwarding | UIView |
The source explicitly defines local protocol relationships: BrowserExtensionTask → XPCCodable, WebContentExtensionTask → XPCCodable, WebContentExtensionBootstrapCommand → XPCCodable, HostingHandleMessage → XPCCodable, IOSurfaceMessage → XPCCodable, NetworkExtensionTask → XPCCodable.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
log (BrowserExample/BrowserApp/ActivityViewButton.swift:12) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
isPresented (BrowserExample/BrowserApp/ActivityViewButton.swift:34) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
id (BrowserExample/BrowserApp/AlertManager.swift:13) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
title (BrowserExample/BrowserApp/AlertManager.swift:14) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
Reference code
BrowserExample/BrowserApp/ActivityViewButton.swift:12 — representative boundary
private let log = Logger(subsystem: Constants.logSubsystem, category: String(describing: ActivityViewController.self))Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | BrowserApp |
The source’s App suffix makes this role explicit. |
| Represents or runs a user/system command | WebContentExtensionBootstrapCommand |
The source’s Command suffix makes this role explicit. |
| View lifecycle, callbacks, and feature coordination | ActivityViewController |
The source’s Controller suffix makes this role explicit. |
| Receives callback-driven events | WebViewUIDelegate |
The source’s Delegate suffix makes this role explicit. |
| Long-lived feature or framework coordination | AlertManager |
The source’s Manager suffix makes this role explicit. |
| Supplies a capability or framework resource | ServiceProvider |
The source’s Provider suffix makes this role explicit. |
| Owns a session-scoped interaction | NetworkSession |
The source’s Session suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Model-View-ViewModel | BrowserExample/BrowserApp/BrowserPageViewModel.swift:15 |
Role-named view models keep UI-facing state or coordination outside view declarations. |
| View-controller organization | BrowserExample/BrowserApp/ActivityViewButton.swift:53 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Protocol-oriented abstraction | BrowserExample/CustomBrowserEngine/Shared/BrowserExtensionProxy.swift:14 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | BrowserExample/BrowserApp/BrowserPageViewModel.swift:93 |
Callback protocols invert event delivery back into the sample’s owner. |
| SwiftUI environment injection | BrowserExample/BrowserApp/BrowserPage.swift:40 |
The environment supplies state or a capability without threading it through every initializer. |
| Binding-based state propagation | BrowserExample/BrowserApp/BrowserPage.swift:339 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
Main application flow
sequenceDiagram
participant BrowserProcessPool
participant renderingProxy
participant networkProxy
participant contentProxy
BrowserProcessPool->>BrowserProcessPool: getOrLaunchContentProcess()
BrowserProcessPool->>BrowserProcessPool: getOrLaunchRenderingProcess()
BrowserProcessPool->>renderingProxy: getEndpoint()
BrowserProcessPool->>BrowserProcessPool: getOrLaunchNetworkProcess()
BrowserProcessPool->>networkProxy: getEndpoint()
BrowserProcessPool->>contentProxy: bootstrap()
Reference code
BrowserExample/CustomBrowserEngine/UIProcess/BrowserProcessPool.swift:60 — launchProcesses()
public func launchProcesses(id: PageID) async throws -> WebContentExtensionProxy {
// 1. Launch a new web content process instance.
let contentProcess = try await getOrLaunchContentProcess(pageID: id)
let contentConnection = try contentProcess.makeLibXPCConnection()
let contentProxy = WebContentExtensionProxy(connection: contentConnection)
try contentProxy.applyRestrictedSandbox(version: lockdownVersion)
// 2. Get the shared rendering process.
let renderingProcess = try await getOrLaunchRenderingProcess()
let renderingConnection = try renderingProcess.makeLibXPCConnection()
let renderingProxy = RenderingExtensionProxy(connection: renderingConnection)
let renderingEndpoint = try await renderingProxy.getEndpoint()
try renderingProxy.applyRestrictedSandbox(version: lockdownVersion)
// 3. Get the shared networking process.
let networkProcess = try await getOrLaunchNetworkProcess()
let networkConnection = try networkProcess.makeLibXPCConnection()
let networkProxy = NetworkingExtensionProxy(connection: networkConnection)
let networkEndpoint = try await networkProxy.getEndpoint()
try networkProxy.applyRestrictedSandbox(version: lockdownVersion)
// 4. Perform the bootstrap process.
try await contentProxy.bootstrap(renderingExtension: renderingEndpoint, networkExtension: networkEndpoint)
webContentProcesses[id] = contentProcess
return contentProxy
}Naming conventions
- Types: App: BrowserApp; Command: WebContentExtensionBootstrapCommand; Controller: ActivityViewController; Delegate: WebViewUIDelegate; Manager: AlertManager; Provider: ServiceProvider; Session: NetworkSession; View: TabContentView, WebContentView, WebView.
- Protocols:
WebViewUIDelegate,ServiceProvider,WebViewNavigationNelegate,XPCCodable,XPCEncodable,XPCDecodable. - Methods:
present,dismissCurrentAlert,body,makeActions,makeMessage,presentingAlerts,open,handle. - Files:
BrowserExample/BrowserApp/AlertManager.swift,BrowserExample/BrowserApp/BrowserApp.swift,BrowserExample/BrowserApp/BrowserPageViewModel.swift,BrowserExample/BrowserApp/TabViewModel.swift,BrowserExample/CustomBrowserEngine/UIProcess/WebView.swift,BrowserExample/BrowserApp/BrowserPage.swift.
Architecture takeaways
BrowserAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches XPC, BrowserEngineKit, CustomBrowserEngine, SwiftUI through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
BrowserExample/BrowserApp/BrowserApp.swift |
Cited implementation, Task, await suspension point, CustomBrowserEngine, BrowserApp |
BrowserExample/BrowserApp/AlertManager.swift |
Cited implementation, @MainActor, ObservableObject, @Published, Foundation, Alert, Button, AlertManager, AlertPresenter |
BrowserExample/CustomBrowserEngine/UIProcess/WebView.swift |
WebViewUIDelegate, WebViewNavigationNelegate, WebView, WebViewNavigationStack |
BrowserExample/BrowserApp/ActivityViewButton.swift |
Cited implementation, ActivityViewController, SwiftUI state property wrapper, os, ActivityViewControllerConfiguration, ActivityViewButton |
BrowserExample/BrowserApp/BrowserPageViewModel.swift |
BrowserPageViewModel, Cited implementation, Task closure isolated to MainActor, NavigationDirection |
BrowserExample/CustomBrowserEngine/Shared/BrowserExtensionProxy.swift |
Cited implementation, BrowserExtensionTask, BrowserExtensionProxy |
BrowserExample/BrowserApp/BrowserPage.swift |
Cited implementation, TabContentView, BrowserPage, WebViewRepresentable, BookmarksList, DismissButton |
BrowserExample/CustomBrowserEngine/NetworkProcess/NetworkSession.swift |
XPC, NetworkSession |
BrowserExample/CustomBrowserEngine/RenderingProcess/RenderingExtensionProxy.swift |
BrowserEngineKit, RenderingExtensionProxy |
BrowserExample/NetworkingExtension/NetworkingExtension.swift |
CustomNetworkingExtension |
BrowserExample/RenderingExtension/RenderingExtension.swift |
CustomRenderingExtension |
BrowserExample/WebContentExtension/WebContentExtension.swift |
CustomWebContentExtension |
BrowserExample/BrowserApp/TabViewModel.swift |
TabViewModel |
BrowserExample/CustomBrowserEngine/XPC/XPCCodable.swift |
XPCCodable, XPCEncodable, XPCDecodable, XPCEncoder, XPCDecoder |
BrowserExample/CustomBrowserEngine/UIProcess/WebContentView.swift |
WebContentView |
BrowserExample/CustomBrowserEngine/BrowserEngine.h |
Feature implementation |
BrowserExample/CustomBrowserEngine/UIProcess/BrowserProcessPool.swift |
launchProcesses |