libservo: Convert intercept_web_resource_load into load_web_resource (#35564)

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>
This commit is contained in:
Martin Robinson 2025-02-21 15:36:42 +01:00 committed by GitHub
parent f6e2e3d418
commit cf2b93f18a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 245 additions and 208 deletions

View file

@ -30,5 +30,6 @@ malloc_size_of_derive = { workspace = true }
num-traits = { workspace = true }
serde = { workspace = true }
servo_url = { path = "../../url" }
url = { workspace = true }
webrender_api = { workspace = true }
webxr-api = { workspace = true, features = ["ipc"], optional = true }

View file

@ -18,6 +18,7 @@ use malloc_size_of_derive::MallocSizeOf;
use num_derive::FromPrimitive;
use serde::{Deserialize, Serialize};
use servo_url::ServoUrl;
use url::Url;
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize};
pub use crate::input_events::*;
@ -452,49 +453,30 @@ pub struct WebResourceRequest {
)]
#[ignore_malloc_size_of = "Defined in hyper"]
pub headers: HeaderMap,
pub url: ServoUrl,
pub url: Url,
pub is_for_main_frame: bool,
pub is_redirect: bool,
}
impl WebResourceRequest {
pub fn new(
method: Method,
headers: HeaderMap,
url: ServoUrl,
is_for_main_frame: bool,
is_redirect: bool,
) -> Self {
WebResourceRequest {
method,
url,
headers,
is_for_main_frame,
is_redirect,
}
}
}
#[derive(Clone, Deserialize, Serialize)]
pub enum WebResourceResponseMsg {
// Response of WebResourceRequest, no body included.
/// Start an interception of this web resource load. It's expected that the client subsequently
/// send either a `CancelLoad` or `FinishLoad` message after optionally sending chunks of body
/// data via `SendBodyData`.
Start(WebResourceResponse),
// send a body chunk. It is expected Response sent before body.
Body(HttpBodyData),
// not to override the response.
None,
}
#[derive(Clone, Deserialize, Serialize)]
pub enum HttpBodyData {
Chunk(Vec<u8>),
Done,
Cancelled,
/// Send a chunk of body data.
SendBodyData(Vec<u8>),
/// Signal that this load has been finished by the interceptor.
FinishLoad,
/// Signal that this load has been cancelled by the interceptor.
CancelLoad,
/// Signal that this load will not be intercepted.
DoNotIntercept,
}
#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct WebResourceResponse {
pub url: ServoUrl,
pub url: Url,
#[serde(
deserialize_with = "::hyper_serde::deserialize",
serialize_with = "::hyper_serde::serialize"
@ -511,7 +493,7 @@ pub struct WebResourceResponse {
}
impl WebResourceResponse {
pub fn new(url: ServoUrl) -> WebResourceResponse {
pub fn new(url: Url) -> WebResourceResponse {
WebResourceResponse {
url,
headers: HeaderMap::new(),