extern crate html5ever;
// extern crate reqwest;
use std::default::Default;
use std::io;
use http::{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,
Other,
}
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) {
match node.data {
NodeData::Document => {
// Dig deeper
for child in node.children.borrow().iter() {
walk_and_embed_assets(&url, child, opt_no_js);
}
},
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.