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::webview_delegate::{AllowOrDenyRequest, WebResourceLoad};
8
9#[derive(Debug)]
10pub enum ServoError {
11 /// The channel to the off-the-main-thread web engine has been lost. No further
12 /// attempts to communicate will happen. This is an unrecoverable error in Servo.
13 LostConnectionWithBackend,
14 /// The devtools server, used to expose pages to remote web inspectors has failed
15 /// to start.
16 DevtoolsFailedToStart,
17 /// Failed to send response to delegate request.
18 ResponseFailedToSend(generic_channel::SendError),
19}
20
21pub trait ServoDelegate {
22 /// Notification that Servo has received a major error.
23 fn notify_error(&self, _error: ServoError) {}
24 /// Report that the DevTools server has started on the given `port`. The `token` that
25 /// be used to bypass the permission prompt from the DevTools client.
26 fn notify_devtools_server_started(&self, _port: u16, _token: String) {}
27 /// Request a DevTools connection from a DevTools client. Typically an embedder application
28 /// will show a permissions prompt when this happens to confirm a connection is allowed.
29 fn request_devtools_connection(&self, _request: AllowOrDenyRequest) {}
30 /// Triggered when Servo will load a web (HTTP/HTTPS) resource. The load may be
31 /// intercepted and alternate contents can be loaded by the client by calling
32 /// [`WebResourceLoad::intercept`]. If not handled, the load will continue as normal.
33 ///
34 /// Note: This delegate method is called for all resource loads not associated with a
35 /// [`WebView`]. For loads associated with a [`WebView`], Servo will call
36 /// [`crate::WebViewDelegate::load_web_resource`].
37 fn load_web_resource(&self, _load: WebResourceLoad) {}
38
39 /// Request to display a notification.
40 fn show_notification(&self, _notification: Notification) {}
41}
42
43pub(crate) struct DefaultServoDelegate;
44impl ServoDelegate for DefaultServoDelegate {}