aboutsummaryrefslogtreecommitdiffstats
path: root/components/net/fetch
diff options
context:
space:
mode:
authorwebbeef <me@webbeef.org>2025-03-06 21:25:08 -0800
committerGitHub <noreply@github.com>2025-03-07 05:25:08 +0000
commit139774e6b55c297bc94f7fcb8c9bf5bb8c6a7474 (patch)
tree70f425d369998013ca8ed559a6719a6c280f7378 /components/net/fetch
parent1864ebfb357cdf4ac6f97d53c5f74f989f08b2ec (diff)
downloadservo-139774e6b55c297bc94f7fcb8c9bf5bb8c6a7474.tar.gz
servo-139774e6b55c297bc94f7fcb8c9bf5bb8c6a7474.zip
Add an about:memory page (#35728)
This patch exposes a servo internal DOM API that is only made available to about: pages on the navigator object to request memory reports. The about:memory page itself is loaded like other html resources (eg. bad cert, net error) and makes use of this new API. On the implementation side, notable changes: - components/script/routed_promise.rs abstracts the setup used to fulfill a promise when the work needs to be routed through the constellation. The goal is to migrate other similar promise APIs in followup (eg. dom/webgpu/gpu.rs, bluetooth.rs). - a new message is added to request a report from the memory reporter, and the memory reporter creates a json representation of the set of memory reports. - the post-processing of memory reports is done in Javascript in the about-memory.html page, providing the same results as the current Rust code that outputs to stdout. We can decide later if we want to remove the current output. Signed-off-by: webbeef <me@webbeef.org>
Diffstat (limited to 'components/net/fetch')
-rw-r--r--components/net/fetch/methods.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs
index 4d40cb78b15..a2c690fb53d 100644
--- a/components/net/fetch/methods.rs
+++ b/components/net/fetch/methods.rs
@@ -12,6 +12,7 @@ use base64::engine::general_purpose;
use content_security_policy as csp;
use crossbeam_channel::Sender;
use devtools_traits::DevtoolsControlMsg;
+use embedder_traits::resources::{self, Resource};
use headers::{AccessControlExposeHeaders, ContentType, HeaderMapExt};
use http::header::{self, HeaderMap, HeaderName};
use http::{HeaderValue, Method, StatusCode};
@@ -680,6 +681,17 @@ fn create_blank_reply(url: ServoUrl, timing_type: ResourceTimingType) -> Respons
response
}
+fn create_about_memory(url: ServoUrl, timing_type: ResourceTimingType) -> Response {
+ let mut response = Response::new(url, ResourceFetchTiming::new(timing_type));
+ response
+ .headers
+ .typed_insert(ContentType::from(mime::TEXT_HTML_UTF_8));
+ *response.body.lock().unwrap() =
+ ResponseBody::Done(resources::read_bytes(Resource::AboutMemoryHTML));
+ response.status = HttpStatus::default();
+ response
+}
+
/// Handle a request from the user interface to ignore validation errors for a certificate.
fn handle_allowcert_request(request: &mut Request, context: &FetchContext) -> io::Result<()> {
let error = |string| Err(io::Error::new(io::ErrorKind::Other, string));
@@ -739,6 +751,7 @@ async fn scheme_fetch(
let scheme = url.scheme();
match scheme {
"about" if url.path() == "blank" => create_blank_reply(url, request.timing_type()),
+ "about" if url.path() == "memory" => create_about_memory(url, request.timing_type()),
"chrome" if url.path() == "allowcert" => {
if let Err(error) = handle_allowcert_request(request, context) {