Use the origin of the actual image response when determining if a canvas is origin clean.

This commit is contained in:
SendilKumar N 2017-03-09 20:30:01 +08:00 committed by Josh Matthews
parent d855c929ef
commit 5acee23f5d
22 changed files with 79 additions and 92 deletions

View file

@ -32,7 +32,7 @@ use dom::htmlcanvaselement::HTMLCanvasElement;
use dom::htmlcanvaselement::utils as canvas_utils;
use dom::htmlimageelement::HTMLImageElement;
use dom::imagedata::ImageData;
use dom::node::{Node, NodeDamage, window_from_node};
use dom::node::{document_from_node, Node, NodeDamage, window_from_node};
use dom_struct::dom_struct;
use euclid::matrix2d::Matrix2D;
use euclid::point::Point2D;
@ -228,16 +228,11 @@ impl CanvasRenderingContext2D {
}
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::CanvasRenderingContext2D(image) =>
image.origin_is_clean(),
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::HTMLImageElement(image) =>
match image.get_url() {
None => true,
Some(url) => {
// TODO(zbarsky): we should check the origin of the image against
// the entry settings object, but for now check it against the canvas' doc.
let node: &Node = &*self.canvas.upcast();
url.origin() == node.owner_doc().url().origin()
}
}
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::HTMLImageElement(image) => {
let image_origin = image.get_origin().expect("Image's origin is missing");
let document = document_from_node(&*self.canvas);
document.url().clone().origin() == image_origin
}
}
}
@ -429,8 +424,8 @@ impl CanvasRenderingContext2D {
};
let img = match self.request_image_from_cache(url) {
ImageResponse::Loaded(img) => img,
ImageResponse::PlaceholderLoaded(_) |
ImageResponse::Loaded(img, _) => img,
ImageResponse::PlaceholderLoaded(_, _) |
ImageResponse::None |
ImageResponse::MetadataLoaded(_) => {
return None;