diff options
author | zhuhaichao518 <zhuhaichao518@gmail.com> | 2025-01-16 15:44:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-16 07:44:16 +0000 |
commit | a1326a7cf65f0890a926223bce4d687f73c8dd9e (patch) | |
tree | ea3d4f0d7754adddc084ca92d1ea42f7f219ea74 /components/net/fetch | |
parent | 725659059905b993ba8f230f7bcd30e514110ab0 (diff) | |
download | servo-a1326a7cf65f0890a926223bce4d687f73c8dd9e.tar.gz servo-a1326a7cf65f0890a926223bce4d687f73c8dd9e.zip |
Implement WebResourceRequested Event. (#34961)
* Implement WebResourceRequested Event on the Embedder Layer
Signed-off-by: zhuhaichao518 <zhuhaichao518@gmail.com>
* fix and add test
Signed-off-by: zhuhaichao518 <zhuhaichao518@gmail.com>
* resolve comments
Signed-off-by: zhuhaichao518 <zhuhaichao518@gmail.com>
* remove sample code in webview
Signed-off-by: zhuhaichao518 <zhuhaichao518@gmail.com>
* remove typo
Signed-off-by: zhuhaichao518 <zhuhaichao518@gmail.com>
* ./mach format
Signed-off-by: zhuhaichao518 <zhuhaichao518@gmail.com>
* fix test fail caused by interception message
Signed-off-by: zhuhaichao518 <zhuhaichao518@gmail.com>
* update impl for is_for_main_frame
Signed-off-by: zhuhaichao518 <zhuhaichao518@gmail.com>
---------
Signed-off-by: zhuhaichao518 <zhuhaichao518@gmail.com>
Diffstat (limited to 'components/net/fetch')
-rw-r--r-- | components/net/fetch/methods.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index 76b4da0ed31..cfaa22fc455 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -43,6 +43,7 @@ use crate::fetch::headers::determine_nosniff; use crate::filemanager_thread::FileManager; use crate::http_loader::{determine_requests_referrer, http_fetch, set_default_accept, HttpState}; use crate::protocols::ProtocolRegistry; +use crate::request_intercepter::RequestIntercepter; use crate::subresource_integrity::is_response_integrity_valid; pub type Target<'a> = &'a mut (dyn FetchTaskTarget + Send); @@ -60,6 +61,7 @@ pub struct FetchContext { pub devtools_chan: Option<Arc<Mutex<Sender<DevtoolsControlMsg>>>>, pub filemanager: Arc<Mutex<FileManager>>, pub file_token: FileTokenCheck, + pub request_intercepter: Arc<Mutex<RequestIntercepter>>, pub cancellation_listener: Arc<CancellationListener>, pub timing: ServoArc<Mutex<ResourceFetchTiming>>, pub protocols: Arc<ProtocolRegistry>, @@ -193,6 +195,18 @@ pub fn should_request_be_blocked_by_csp( .unwrap_or(csp::CheckResult::Allowed) } +pub fn maybe_intercept_request( + request: &mut Request, + context: &FetchContext, + response: &mut Option<Response>, +) { + context + .request_intercepter + .lock() + .unwrap() + .intercept_request(request, response, context); +} + /// [Main fetch](https://fetch.spec.whatwg.org/#concept-main-fetch) pub async fn main_fetch( fetch_params: &mut FetchParams, @@ -299,6 +313,9 @@ pub async fn main_fetch( let current_url = request.current_url(); let current_scheme = current_url.scheme(); + // Intercept the request and maybe override the response. + maybe_intercept_request(request, context, &mut response); + let mut response = match response { Some(res) => res, None => { |