extern crate html5ever;
use std::default::Default;
use std::io;
use http::{is_url, retrieve_asset, resolve_url};
use self::html5ever::parse_document;
use self::html5ever::rcdom::{Handle, NodeData, RcDom};
use self::html5ever::tendril::TendrilSink;
use self::html5ever::serialize::{SerializeOpts, serialize};
enum NodeMatch {
Icon,
Image,
StyleSheet,
Anchor,
Script,
Form,
Other,
}
static PNG_PIXEL: &str = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
static JS_DOM_EVENT_ATTRS: [&str; 21] = [
// Input
"onfocus", "onblur", "onselect", "onchange", "onsubmit", "onreset", "onkeydown", "onkeypress", "onkeyup",
// Mouse
"onmouseover", "onmouseout", "onmousedown", "onmouseup", "onmousemove",
// Click
"onclick", "ondblclick",
// Load
"onload", "onunload", "onabort", "onerror", "onresize",
];
pub fn walk_and_embed_assets(url: &str, node: &Handle, opt_no_js: bool, opt_no_images: bool) {
match node.data {
NodeData::Document => {
// Dig deeper
for child in node.children.borrow().iter() {
walk_and_embed_assets(&url, child, opt_no_js, opt_no_images);
}
},
NodeData::Doctype {
name: _,
public_id: _,
system_id: _,
} => {},
NodeData::Text { contents: _, } => {},
NodeData::Comment { contents: _, } => {
// Note: in case of opt_no_js being set to true, there's no need to worry about
// getting rid of comments that may contain scripts, e.g.