use http::{is_valid_url, resolve_url, retrieve_asset}; use std::default::Default; use std::io; use utils::data_to_dataurl; use html5ever::parse_document; use html5ever::rcdom::{Handle, NodeData, RcDom}; use html5ever::serialize::{serialize, SerializeOpts}; use html5ever::tendril::TendrilSink; enum NodeMatch { Icon, Image, StyleSheet, Anchor, Script, Form, IFrame, Other, } const PNG_PIXEL: &str = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; const 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, opt_user_agent: &str, ) { 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, opt_user_agent, ); } } NodeData::Doctype { .. } => {} NodeData::Text { .. } => {} NodeData::Comment { .. } => { // 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.