servo/
servo_delegate.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4use base::generic_channel;
5use embedder_traits::Notification;
6
7use crate::Servo;
8use crate::webview_delegate::{AllowOrDenyRequest, WebResourceLoad};
9
10#[derive(Debug)]
11pub enum ServoError {
12    /// The channel to the off-the-main-thread web engine has been lost. No further
13    /// attempts to communicate will happen. This is an unrecoverable error in Servo.
14    LostConnectionWithBackend,
15    /// The devtools server, used to expose pages to remote web inspectors has failed
16    /// to start.
17    DevtoolsFailedToStart,
18    /// Failed to send response to delegate request.
19    ResponseFailedToSend(generic_channel::SendError),
20}
21
22pub trait ServoDelegate {
23    /// Notification that Servo has received a major error.
24    fn notify_error(&self, _servo: &Servo, _error: ServoError) {}
25    /// Report that the DevTools server has started on the given `port`. The `token` that
26    /// be used to bypass the permission prompt from the DevTools client.
27    fn notify_devtools_server_started(&self, _servo: &Servo, _port: u16, _token: String) {}
28    /// Request a DevTools connection from a DevTools client. Typically an embedder application
29    /// will show a permissions prompt when this happens to confirm a connection is allowed.
30    fn request_devtools_connection(&self, _servo: &Servo, _request: AllowOrDenyRequest) {}
31    /// Any [`WebView`] in this Servo instance has either started to animate or WebXR is
32    /// running. When a [`WebView`] is animating, it is up to the embedding application
33    /// ensure that `Servo::spin_event_loop` is called at regular intervals in order to
34    /// update the painted contents of the [`WebView`].
35    fn notify_animating_changed(&self, _animating: bool) {}
36    /// Triggered when Servo will load a web (HTTP/HTTPS) resource. The load may be
37    /// intercepted and alternate contents can be loaded by the client by calling
38    /// [`WebResourceLoad::intercept`]. If not handled, the load will continue as normal.
39    ///
40    /// Note: This delegate method is called for all resource loads not associated with a
41    /// [`WebView`].  For loads associated with a [`WebView`], Servo  will call
42    /// [`crate::WebViewDelegate::load_web_resource`].
43    fn load_web_resource(&self, _load: WebResourceLoad) {}
44
45    /// Request to display a notification.
46    fn show_notification(&self, _notification: Notification) {}
47}
48
49pub(crate) struct DefaultServoDelegate;
50impl ServoDelegate for DefaultServoDelegate {}