diff options
author | pylbrecht <palbrecht@mailbox.org> | 2020-02-02 19:24:39 +0100 |
---|---|---|
committer | pylbrecht <palbrecht@mailbox.org> | 2020-02-03 20:46:03 +0100 |
commit | ed0973fb1c87e344c6660a0e9fa282866c0ecf00 (patch) | |
tree | 7222140aeb3725e28281e8a5250f79f9f5c3aaec /components/script/dom/htmlimageelement.rs | |
parent | 5f55cd5d71df9c555fbc24777168396ddd539f28 (diff) | |
download | servo-ed0973fb1c87e344c6660a0e9fa282866c0ecf00.tar.gz servo-ed0973fb1c87e344c6660a0e9fa282866c0ecf00.zip |
Add image usability checks to drawImage()
Diffstat (limited to 'components/script/dom/htmlimageelement.rs')
-rw-r--r-- | components/script/dom/htmlimageelement.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 59238ca6545..1cfecef1728 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -13,7 +13,7 @@ use crate::dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageE use crate::dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods; use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeBinding::NodeMethods; use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; -use crate::dom::bindings::error::Fallible; +use crate::dom::bindings::error::{Error, Fallible}; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::refcounted::Trusted; use crate::dom::bindings::reflector::DomObject; @@ -164,6 +164,26 @@ impl HTMLImageElement { pub fn get_url(&self) -> Option<ServoUrl> { self.current_request.borrow().parsed_url.clone() } + // https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument + pub fn is_usable(&self) -> Fallible<bool> { + // If image has an intrinsic width or intrinsic height (or both) equal to zero, then return bad. + match &self.current_request.borrow().image { + Some(image) => { + if image.width == 0 || image.height == 0 { + return Ok(false); + } + }, + None => return Ok(false), + } + + match self.current_request.borrow().state { + // If image's current request's state is broken, then throw an "InvalidStateError" DOMException. + State::Broken => Err(Error::InvalidState), + State::CompletelyAvailable => Ok(true), + // If image is not fully decodable, then return bad. + State::PartiallyAvailable | State::Unavailable => Ok(false), + } + } } /// The context required for asynchronously loading an external image. |