Skip to main content

cbf_chrome/bridge/
event.rs

1use cursor_icon::CursorIcon;
2
3use cbf::data::dialog::DialogType;
4use cbf::data::drag::DragOperation;
5
6use crate::data::{
7    choice_menu::ChromeChoiceMenu,
8    context_menu::ChromeContextMenu,
9    custom_scheme::ChromeCustomSchemeRequest,
10    download::{ChromeDownloadCompletion, ChromeDownloadProgress, ChromeDownloadSnapshot},
11    drag::ChromeDragStartRequest,
12    extension::ChromeExtensionInfo,
13    find::ChromeFindRect,
14    ids::{PopupId, TabId},
15    ime::ChromeImeBoundsUpdate,
16    ipc::{TabIpcErrorCode, TabIpcMessageType, TabIpcPayload},
17    lifecycle::ChromeBeforeUnloadReason,
18    navigation::{ChromeNavigationEntryId, ChromeNavigationHistorySnapshot, ChromeNavigationKind},
19    prompt_ui::{PromptUiCloseReason, PromptUiId, PromptUiKind, PromptUiResolution},
20    surface::SurfaceHandle,
21    tab_open::{TabOpenHint, TabOpenResult},
22};
23
24/// Low-level IPC events emitted by the Chromium bridge.
25#[derive(Debug, Clone, PartialEq)]
26pub enum IpcEvent {
27    /// The rendering surface handle for a page was updated.
28    ///
29    /// **Note**: This event does not map to `BrowserEvent` because surface handles
30    /// are a Chrome-specific rendering implementation detail. Applications needing
31    /// this information should subscribe to the raw `ChromeEvent` stream.
32    SurfaceHandleUpdated {
33        profile_id: String,
34        browsing_context_id: TabId,
35        handle: SurfaceHandle,
36    },
37    /// An extension action popup lifecycle started.
38    ExtensionPopupOpened {
39        profile_id: String,
40        browsing_context_id: TabId,
41        popup_id: u64,
42        extension_id: String,
43        title: String,
44    },
45    /// The rendering surface handle for an extension popup was updated.
46    ExtensionPopupSurfaceHandleUpdated {
47        profile_id: String,
48        browsing_context_id: TabId,
49        popup_id: u64,
50        handle: SurfaceHandle,
51    },
52    /// The effective popup size changed after Chromium-side clamping.
53    ExtensionPopupPreferredSizeChanged {
54        profile_id: String,
55        browsing_context_id: TabId,
56        popup_id: u64,
57        width: u32,
58        height: u32,
59    },
60    /// A context menu was requested for an extension popup.
61    ExtensionPopupContextMenuRequested {
62        profile_id: String,
63        browsing_context_id: TabId,
64        popup_id: PopupId,
65        menu: ChromeContextMenu,
66    },
67    /// A host-owned choice menu was requested for an extension popup.
68    ExtensionPopupChoiceMenuRequested {
69        profile_id: String,
70        browsing_context_id: TabId,
71        popup_id: PopupId,
72        request_id: u64,
73        menu: ChromeChoiceMenu,
74    },
75    /// The cursor appearance changed for an extension popup.
76    ExtensionPopupCursorChanged {
77        profile_id: String,
78        browsing_context_id: TabId,
79        popup_id: PopupId,
80        cursor_type: CursorIcon,
81    },
82    /// The title changed for an extension popup.
83    ExtensionPopupTitleUpdated {
84        profile_id: String,
85        browsing_context_id: TabId,
86        popup_id: PopupId,
87        title: String,
88    },
89    /// A JavaScript dialog was requested for an extension popup.
90    ExtensionPopupJavaScriptDialogRequested {
91        profile_id: String,
92        browsing_context_id: TabId,
93        popup_id: PopupId,
94        request_id: u64,
95        r#type: DialogType,
96        message: String,
97        default_prompt_text: Option<String>,
98        reason: ChromeBeforeUnloadReason,
99    },
100    /// The extension popup requested to close.
101    ExtensionPopupCloseRequested {
102        profile_id: String,
103        browsing_context_id: TabId,
104        popup_id: PopupId,
105    },
106    /// The extension popup renderer exited or crashed.
107    ExtensionPopupRenderProcessGone {
108        profile_id: String,
109        browsing_context_id: TabId,
110        popup_id: PopupId,
111        crashed: bool,
112    },
113    /// An extension action popup closed.
114    ExtensionPopupClosed {
115        profile_id: String,
116        browsing_context_id: TabId,
117        popup_id: u64,
118    },
119    /// A new tab was created by the backend.
120    ///
121    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::Created`.
122    TabCreated {
123        profile_id: String,
124        browsing_context_id: TabId,
125        request_id: u64,
126    },
127    /// DevTools was opened for a page.
128    ///
129    /// **Note**: This event does not map to `BrowserEvent` because DevTools is
130    /// currently exposed via the Chrome-specific raw event stream only.
131    DevToolsOpened {
132        profile_id: String,
133        browsing_context_id: TabId,
134        inspected_browsing_context_id: TabId,
135    },
136    /// IME bounds information changed.
137    ///
138    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::ImeBoundsUpdated`.
139    ImeBoundsUpdated {
140        profile_id: String,
141        browsing_context_id: TabId,
142        update: ChromeImeBoundsUpdate,
143    },
144    /// IME bounds information changed for an extension popup.
145    ///
146    /// Maps to `BrowserEvent::TransientBrowsingContext` with
147    /// `TransientBrowsingContextEvent::ImeBoundsUpdated`.
148    ExtensionPopupImeBoundsUpdated {
149        profile_id: String,
150        browsing_context_id: TabId,
151        popup_id: PopupId,
152        update: ChromeImeBoundsUpdate,
153    },
154    /// The backend requested a context menu.
155    ///
156    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::ContextMenuRequested`.
157    ContextMenuRequested {
158        profile_id: String,
159        browsing_context_id: TabId,
160        menu: ChromeContextMenu,
161    },
162    /// The backend requested a host-owned choice menu.
163    ChoiceMenuRequested {
164        profile_id: String,
165        browsing_context_id: TabId,
166        request_id: u64,
167        menu: ChromeChoiceMenu,
168    },
169    /// Host-mediated open request for tab.
170    ///
171    /// Maps to `BrowserEvent::BrowsingContextOpenRequested`.
172    TabOpenRequested {
173        profile_id: String,
174        request_id: u64,
175        source_tab_id: Option<TabId>,
176        target_url: String,
177        open_hint: TabOpenHint,
178        user_gesture: bool,
179    },
180    /// Result for host-mediated open request.
181    ///
182    /// Maps to `BrowserEvent::BrowsingContextOpenResolved`.
183    TabOpenResolved {
184        profile_id: String,
185        request_id: u64,
186        result: TabOpenResult,
187    },
188    /// Navigation state changed for a page.
189    ///
190    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::NavigationStateChanged`.
191    NavigationStateChanged {
192        profile_id: String,
193        browsing_context_id: TabId,
194        url: String,
195        can_go_back: bool,
196        can_go_forward: bool,
197        is_loading: bool,
198        current_entry_id: ChromeNavigationEntryId,
199        current_index: usize,
200        navigation_kind: ChromeNavigationKind,
201    },
202    /// Navigation history snapshot for a page.
203    ///
204    /// Maps to `BrowserEvent::BrowsingContext` with
205    /// `BrowsingContextEvent::NavigationHistorySnapshot`.
206    NavigationHistorySnapshot {
207        profile_id: String,
208        browsing_context_id: TabId,
209        snapshot: ChromeNavigationHistorySnapshot,
210    },
211    /// Cursor appearance changed for a page.
212    ///
213    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::CursorChanged`.
214    CursorChanged {
215        profile_id: String,
216        browsing_context_id: TabId,
217        cursor_type: CursorIcon,
218    },
219    /// The page title changed for a page.
220    ///
221    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::TitleUpdated`.
222    TitleUpdated {
223        profile_id: String,
224        browsing_context_id: TabId,
225        title: String,
226    },
227    /// The page favicon URL changed for a page.
228    ///
229    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::FaviconUrlUpdated`.
230    FaviconUrlUpdated {
231        profile_id: String,
232        browsing_context_id: TabId,
233        url: String,
234    },
235    /// A beforeunload dialog was requested.
236    ///
237    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::JavaScriptDialogRequested`
238    /// with `DialogType::BeforeUnload`.
239    BeforeUnloadDialogRequested {
240        profile_id: String,
241        browsing_context_id: TabId,
242        request_id: u64,
243        reason: ChromeBeforeUnloadReason,
244    },
245    /// A JavaScript dialog was requested for a tab.
246    JavaScriptDialogRequested {
247        profile_id: String,
248        browsing_context_id: TabId,
249        request_id: u64,
250        r#type: DialogType,
251        message: String,
252        default_prompt_text: Option<String>,
253        reason: ChromeBeforeUnloadReason,
254    },
255    /// A tab closed event was observed.
256    ///
257    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::Closed`.
258    TabClosed {
259        profile_id: String,
260        browsing_context_id: TabId,
261    },
262    /// A resize acknowledgement was received for a page.
263    ///
264    /// **Note**: This event does not map to `BrowserEvent` because it is an internal
265    /// acknowledgement with no semantic value for browser-generic consumers.
266    TabResizeAcknowledged {
267        profile_id: String,
268        browsing_context_id: TabId,
269    },
270    /// The DOM HTML was read for a page.
271    ///
272    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::DomHtmlRead`.
273    TabDomHtmlRead {
274        profile_id: String,
275        browsing_context_id: TabId,
276        request_id: u64,
277        html: String,
278    },
279    /// Find-in-page result for a tab.
280    ///
281    /// **Note**: This event does not map to `BrowserEvent` because it carries
282    /// Chromium-specific selection geometry and partial-update semantics.
283    FindReply {
284        profile_id: String,
285        browsing_context_id: TabId,
286        request_id: u64,
287        number_of_matches: u32,
288        active_match_ordinal: i32,
289        selection_rect: ChromeFindRect,
290        final_update: bool,
291    },
292    /// Browsing context IPC message from page to host.
293    TabIpcMessageReceived {
294        profile_id: String,
295        browsing_context_id: TabId,
296        channel: String,
297        message_type: TabIpcMessageType,
298        request_id: u64,
299        payload: TabIpcPayload,
300        content_type: Option<String>,
301        error_code: Option<TabIpcErrorCode>,
302    },
303    /// Host-owned drag start request from renderer.
304    ///
305    /// Maps to `BrowserEvent::BrowsingContext` with `BrowsingContextEvent::DragStartRequested`.
306    DragStartRequested {
307        profile_id: String,
308        browsing_context_id: TabId,
309        request: ChromeDragStartRequest,
310    },
311    /// Negotiated operation for the active external drag changed.
312    ExternalDragOperationChanged {
313        profile_id: String,
314        browsing_context_id: TabId,
315        operation: DragOperation,
316    },
317    /// Shutdown is blocked by a browsing context that requested confirmation.
318    ///
319    /// Maps to `BrowserEvent::ShutdownBlocked`.
320    ShutdownBlocked {
321        request_id: u64,
322        dirty_browsing_context_id: TabId,
323    },
324    /// Shutdown has started.
325    ///
326    /// Maps to `BrowserEvent::ShutdownProceeding`.
327    ShutdownProceeding { request_id: u64 },
328    /// Shutdown was cancelled.
329    ///
330    /// Maps to `BrowserEvent::ShutdownCancelled`.
331    ShutdownCancelled { request_id: u64 },
332    /// A close transaction is blocked by a browsing context that requested confirmation.
333    CloseBrowsingContextsTransactionBlocked {
334        profile_id: String,
335        request_id: u64,
336        dirty_browsing_context_id: TabId,
337    },
338    /// A close transaction completed non-destructive checks.
339    CloseBrowsingContextsTransactionReady { profile_id: String, request_id: u64 },
340    /// A close transaction started closing prepared tabs.
341    CloseBrowsingContextsTransactionProceeding { profile_id: String, request_id: u64 },
342    /// A close transaction was cancelled before commit.
343    CloseBrowsingContextsTransactionCancelled { profile_id: String, request_id: u64 },
344    /// A close transaction finished closing all prepared tabs.
345    CloseBrowsingContextsTransactionCompleted { profile_id: String, request_id: u64 },
346    /// Installed extensions were listed for a profile.
347    ///
348    /// Maps to `BrowserEvent::ExtensionsListed`.
349    ExtensionsListed {
350        profile_id: String,
351        extensions: Vec<ChromeExtensionInfo>,
352    },
353    /// Prompt UI open was requested and host must choose flow.
354    PromptUiOpenRequested {
355        profile_id: String,
356        source_tab_id: Option<TabId>,
357        request_id: u64,
358        kind: PromptUiKind,
359    },
360    /// Prompt UI request was resolved.
361    PromptUiResolved {
362        profile_id: String,
363        source_tab_id: Option<TabId>,
364        request_id: u64,
365        resolution: PromptUiResolution,
366    },
367    /// A registered custom scheme request requires a host response.
368    CustomSchemeRequestReceived { request: ChromeCustomSchemeRequest },
369    /// Non-fatal extension runtime warning.
370    ///
371    /// Maps to `BrowsingContextEvent::ExtensionRuntimeWarning`.
372    ExtensionRuntimeWarning {
373        profile_id: String,
374        browsing_context_id: TabId,
375        detail: String,
376    },
377    /// Backend-managed prompt UI surface was opened.
378    PromptUiOpened {
379        profile_id: String,
380        source_tab_id: Option<TabId>,
381        prompt_ui_id: PromptUiId,
382        kind: PromptUiKind,
383        title: Option<String>,
384        modal: bool,
385    },
386    /// Backend-managed prompt UI surface was closed.
387    PromptUiClosed {
388        profile_id: String,
389        source_tab_id: Option<TabId>,
390        prompt_ui_id: PromptUiId,
391        kind: PromptUiKind,
392        reason: PromptUiCloseReason,
393    },
394    /// Download lifecycle became visible to the host.
395    DownloadCreated {
396        profile_id: String,
397        download: ChromeDownloadSnapshot,
398    },
399    /// Download state changed.
400    DownloadUpdated {
401        profile_id: String,
402        download: ChromeDownloadProgress,
403    },
404    /// Download reached a terminal state.
405    DownloadCompleted {
406        profile_id: String,
407        download: ChromeDownloadCompletion,
408    },
409}