mirror of
https://github.com/servo/servo.git
synced 2025-10-11 22:10:18 +01:00
Rework the `WebViewDelegate::intercept_web_resource_load` into `WebViewDelegate::load_web_resource` and clean up internal messaging. The main thing here is adding objects which manage the response to these delegate methods. Now we have `WebResourceLoad` and `InterceptedWebResourceLoad` which make it much harder to misuse the API. In addition, the internal messaging for this is cleaned up. Canceling and finishing the load are unrelated to the HTTP body so they are no longer subtypes of an HttpBodyData message. Processing of messages is made a bit more efficient by collecting all body chunks in a vector and only flattening the chunks at the end. Finally, "interceptor" is a much more common spelling than "intercepter" so I've gone ahead and made this change everywhere. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
38 lines
2 KiB
Rust
38 lines
2 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use crate::webview_delegate::{AllowOrDenyRequest, WebResourceLoad};
|
|
use crate::Servo;
|
|
|
|
#[derive(Clone, Copy, Debug, Hash, PartialEq)]
|
|
pub enum ServoError {
|
|
/// The channel to the off-the-main-thread web engine has been lost. No further
|
|
/// attempts to communicate will happen. This is an unrecoverable error in Servo.
|
|
LostConnectionWithBackend,
|
|
/// The devtools server, used to expose pages to remote web inspectors has failed
|
|
/// to start.
|
|
DevtoolsFailedToStart,
|
|
}
|
|
|
|
pub trait ServoDelegate {
|
|
/// Notification that Servo has received a major error.
|
|
fn notify_error(&self, _servo: &Servo, _error: ServoError) {}
|
|
/// Report that the DevTools server has started on the given `port`. The `token` that
|
|
/// be used to bypass the permission prompt from the DevTools client.
|
|
fn notify_devtools_server_started(&self, _servo: &Servo, _port: u16, _token: String) {}
|
|
/// Request a DevTools connection from a DevTools client. Typically an embedder application
|
|
/// will show a permissions prompt when this happens to confirm a connection is allowed.
|
|
fn request_devtools_connection(&self, _servo: &Servo, _request: AllowOrDenyRequest) {}
|
|
/// Triggered when Servo will load a web (HTTP/HTTPS) resource. The load may be
|
|
/// intercepted and alternate contents can be loaded by the client by calling
|
|
/// [`WebResourceLoad::intercept`]. If not handled, the load will continue as normal.
|
|
///
|
|
/// Note: This delegate method is called for all resource loads not associated with a
|
|
/// [`WebView`]. For loads associated with a [`WebView`], Servo will call
|
|
/// [`crate::WebViewDelegate::load_web_resource`].
|
|
fn load_web_resource(&self, _load: WebResourceLoad) {}
|
|
}
|
|
|
|
pub(crate) struct DefaultServoDelegate;
|
|
impl ServoDelegate for DefaultServoDelegate {}
|