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:
Josh Matthews 2017-02-28 10:27:10 -05:00
parent 208f97420a
commit 2bd02fe423

View file

@ -117,29 +117,20 @@ impl Runnable for ImageResponseHandlerRunnable {
/// The context required for asynchronously loading an external image.
struct ImageContext {
/// The element that initiated the request.
elem: Trusted<HTMLImageElement>,
/// The initial URL requested.
url: ServoUrl,
/// A handle with which to communicate with the image cache.
image_cache: ImageCacheThread,
/// Indicates whether the request failed, and why
status: Result<(), NetworkError>,
/// The cache ID for this request.
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 {
fn process_request_body(&mut self) {}
fn process_request_eof(&mut self) {}
fn process_response(&mut self, metadata: Result<FetchMetadata, NetworkError>) {
self.image_cache().notify_pending_response(
self.image_cache.notify_pending_response(
self.id,
FetchResponseMsg::ProcessResponse(metadata.clone()));
@ -163,19 +154,16 @@ impl FetchResponseListener for ImageContext {
fn process_response_chunk(&mut self, payload: Vec<u8>) {
if self.status.is_ok() {
self.image_cache().notify_pending_response(
self.image_cache.notify_pending_response(
self.id,
FetchResponseMsg::ProcessResponseChunk(payload));
}
}
fn process_response_eof(&mut self, response: Result<(), NetworkError>) {
let elem = self.elem.root();
let document = document_from_node(&*elem);
let image_cache = self.image_cache();
image_cache.notify_pending_response(self.id,
FetchResponseMsg::ProcessResponseEOF(response));
document.finish_load(LoadType::Image(self.url.clone()));
self.image_cache.notify_pending_response(
self.id,
FetchResponseMsg::ProcessResponseEOF(response));
}
}
@ -251,8 +239,7 @@ impl HTMLImageElement {
let window = window_from_node(self);
let context = Arc::new(Mutex::new(ImageContext {
elem: Trusted::new(self),
url: img_url.clone(),
image_cache: window.image_cache_thread().clone(),
status: Ok(()),
id: id,
}));
@ -275,7 +262,9 @@ impl HTMLImageElement {
.. 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) {
@ -634,6 +623,15 @@ impl VirtualMethods for HTMLImageElement {
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) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {