mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Initiate a new image request when an image element's adopting steps are run.
Remove the redundant tracked loads for the underlying image request; the load blockers present in the ImageRequest structure perform the same duty with better accuracy.
This commit is contained in:
parent
208f97420a
commit
2bd02fe423
1 changed files with 20 additions and 22 deletions
|
@ -117,29 +117,20 @@ impl Runnable for ImageResponseHandlerRunnable {
|
||||||
|
|
||||||
/// The context required for asynchronously loading an external image.
|
/// The context required for asynchronously loading an external image.
|
||||||
struct ImageContext {
|
struct ImageContext {
|
||||||
/// The element that initiated the request.
|
/// A handle with which to communicate with the image cache.
|
||||||
elem: Trusted<HTMLImageElement>,
|
image_cache: ImageCacheThread,
|
||||||
/// The initial URL requested.
|
|
||||||
url: ServoUrl,
|
|
||||||
/// Indicates whether the request failed, and why
|
/// Indicates whether the request failed, and why
|
||||||
status: Result<(), NetworkError>,
|
status: Result<(), NetworkError>,
|
||||||
/// The cache ID for this request.
|
/// The cache ID for this request.
|
||||||
id: PendingImageId,
|
id: PendingImageId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageContext {
|
|
||||||
fn image_cache(&self) -> ImageCacheThread {
|
|
||||||
let elem = self.elem.root();
|
|
||||||
window_from_node(&*elem).image_cache_thread().clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FetchResponseListener for ImageContext {
|
impl FetchResponseListener for ImageContext {
|
||||||
fn process_request_body(&mut self) {}
|
fn process_request_body(&mut self) {}
|
||||||
fn process_request_eof(&mut self) {}
|
fn process_request_eof(&mut self) {}
|
||||||
|
|
||||||
fn process_response(&mut self, metadata: Result<FetchMetadata, NetworkError>) {
|
fn process_response(&mut self, metadata: Result<FetchMetadata, NetworkError>) {
|
||||||
self.image_cache().notify_pending_response(
|
self.image_cache.notify_pending_response(
|
||||||
self.id,
|
self.id,
|
||||||
FetchResponseMsg::ProcessResponse(metadata.clone()));
|
FetchResponseMsg::ProcessResponse(metadata.clone()));
|
||||||
|
|
||||||
|
@ -163,19 +154,16 @@ impl FetchResponseListener for ImageContext {
|
||||||
|
|
||||||
fn process_response_chunk(&mut self, payload: Vec<u8>) {
|
fn process_response_chunk(&mut self, payload: Vec<u8>) {
|
||||||
if self.status.is_ok() {
|
if self.status.is_ok() {
|
||||||
self.image_cache().notify_pending_response(
|
self.image_cache.notify_pending_response(
|
||||||
self.id,
|
self.id,
|
||||||
FetchResponseMsg::ProcessResponseChunk(payload));
|
FetchResponseMsg::ProcessResponseChunk(payload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_response_eof(&mut self, response: Result<(), NetworkError>) {
|
fn process_response_eof(&mut self, response: Result<(), NetworkError>) {
|
||||||
let elem = self.elem.root();
|
self.image_cache.notify_pending_response(
|
||||||
let document = document_from_node(&*elem);
|
self.id,
|
||||||
let image_cache = self.image_cache();
|
|
||||||
image_cache.notify_pending_response(self.id,
|
|
||||||
FetchResponseMsg::ProcessResponseEOF(response));
|
FetchResponseMsg::ProcessResponseEOF(response));
|
||||||
document.finish_load(LoadType::Image(self.url.clone()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,8 +239,7 @@ impl HTMLImageElement {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
|
|
||||||
let context = Arc::new(Mutex::new(ImageContext {
|
let context = Arc::new(Mutex::new(ImageContext {
|
||||||
elem: Trusted::new(self),
|
image_cache: window.image_cache_thread().clone(),
|
||||||
url: img_url.clone(),
|
|
||||||
status: Ok(()),
|
status: Ok(()),
|
||||||
id: id,
|
id: id,
|
||||||
}));
|
}));
|
||||||
|
@ -275,7 +262,9 @@ impl HTMLImageElement {
|
||||||
.. RequestInit::default()
|
.. RequestInit::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
document.fetch_async(LoadType::Image(img_url), request, action_sender);
|
// This is a background load because the load blocker already fulfills the
|
||||||
|
// purpose of delaying the document's load event.
|
||||||
|
document.loader().fetch_async_background(request, action_sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_image_response(&self, image: ImageResponse) {
|
fn process_image_response(&self, image: ImageResponse) {
|
||||||
|
@ -634,6 +623,15 @@ impl VirtualMethods for HTMLImageElement {
|
||||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn adopting_steps(&self, old_doc: &Document) {
|
||||||
|
self.super_type().unwrap().adopting_steps(old_doc);
|
||||||
|
|
||||||
|
let elem = self.upcast::<Element>();
|
||||||
|
let document = document_from_node(self);
|
||||||
|
self.update_image(Some((elem.get_string_attribute(&local_name!("src")),
|
||||||
|
document.base_url())));
|
||||||
|
}
|
||||||
|
|
||||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||||
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
||||||
match attr.local_name() {
|
match attr.local_name() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue