mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
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>
This commit is contained in:
parent
7256590599
commit
a1326a7cf6
13 changed files with 364 additions and 9 deletions
|
@ -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 => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue