Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing a path to --userscripts #5430

Merged
merged 2 commits into from Apr 1, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Allow passing a path to --userscripts

  • Loading branch information
Manishearth committed Mar 28, 2015
commit 4d2ca2d8e2781787dd1fd0b34888dd5a7e3ebad3
@@ -19,6 +19,7 @@ use util::opts;
use util::resource_files::resources_dir_path;
use std::borrow::ToOwned;
use std::fs::read_dir;
use std::path::PathBuf;

#[dom_struct]
pub struct HTMLHeadElement {
@@ -51,34 +52,38 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLHeadElement> {
Some(htmlelement as &VirtualMethods)
}
fn bind_to_tree(&self, _tree_in_doc: bool) {
if !opts::get().userscripts {
return;
}
if let Some(ref path_str) = opts::get().userscripts {
let node: &JSRef<Node> = NodeCast::from_borrowed_ref(self);
let first_child = node.GetFirstChild().root();
let doc = node.owner_doc().root();
let doc = doc.r();

let node: &JSRef<Node> = NodeCast::from_borrowed_ref(self);
let first_child = node.GetFirstChild().root();
let doc = node.owner_doc().root();
let doc = doc.r();
let path = if &**path_str == "" {
let mut p = resources_dir_path();
p.push("user-agent-js");
p
} else {
PathBuf::new(path_str)
};

let mut path = resources_dir_path();
path.push("user-agent-js");
let mut files = match read_dir(&path) {
Ok(d) => d.filter_map(|e| e.ok()).map(|e| e.path()).collect::<Vec<_>>(),
Err(_) => return
};
let mut files = match read_dir(&path) {
Ok(d) => d.filter_map(|e| e.ok()).map(|e| e.path()).collect::<Vec<_>>(),
Err(_) => return
};

files.sort();
files.sort();

for file in files {
let name = match file.into_os_string().into_string() {
Ok(ref s) if s.ends_with(".js") => "file://".to_owned() + &s[..],
_ => continue
};
let new_script = doc.CreateElement("script".to_owned()).unwrap().root();
let new_script = new_script.r();
new_script.set_string_attribute(&atom!("src"), name);
let new_script_node: &JSRef<Node> = NodeCast::from_borrowed_ref(&new_script);
node.InsertBefore(*new_script_node, first_child.r()).unwrap();
for file in files {
let name = match file.into_os_string().into_string() {
Ok(ref s) if s.ends_with(".js") => "file://".to_owned() + &s[..],
_ => continue
};
let new_script = doc.CreateElement("script".to_owned()).unwrap().root();
let new_script = new_script.r();
new_script.set_string_attribute(&atom!("src"), name);
let new_script_node: &JSRef<Node> = NodeCast::from_borrowed_ref(&new_script);
node.InsertBefore(*new_script_node, first_child.r()).unwrap();
}
}
}
}
@@ -59,7 +59,11 @@ pub struct Opts {
pub nonincremental_layout: bool,

pub nossl: bool,
pub userscripts: bool,

/// Where to load userscripts from, if any. An empty string will load from
/// the resources/user-agent-js directory, and if the option isn't passed userscripts
/// won't be loaded
pub userscripts: Option<String>,

pub output_file: Option<String>,
pub headless: bool,
@@ -181,7 +185,7 @@ pub fn default_opts() -> Opts {
layout_threads: 1,
nonincremental_layout: false,
nossl: false,
userscripts: false,
userscripts: None,
output_file: None,
headless: true,
hard_fail: true,
@@ -222,7 +226,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
getopts::optopt("y", "layout-threads", "Number of threads to use for layout", "1"),
getopts::optflag("i", "nonincremental-layout", "Enable to turn off incremental layout."),
getopts::optflag("", "no-ssl", "Disables ssl certificate verification."),
getopts::optflag("", "userscripts", "Uses userscripts in resources/user-agent-js"),
getopts::optflagopt("", "userscripts", "Uses userscripts in resources/user-agent-js, or a specified full path",""),
getopts::optflag("z", "headless", "Headless mode"),
getopts::optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure"),
getopts::optflagopt("", "devtools", "Start remote devtools server on port", "6000"),
@@ -299,7 +303,6 @@ pub fn from_cmdline_args(args: &[String]) -> bool {

let nonincremental_layout = opt_match.opt_present("i");
let nossl = opt_match.opt_present("no-ssl");
let userscripts = opt_match.opt_present("userscripts");

let mut bubble_inline_sizes_separately = debug_options.contains(&"bubble-widths");
let trace_layout = debug_options.contains(&"trace-layout");
@@ -335,7 +338,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
layout_threads: layout_threads,
nonincremental_layout: nonincremental_layout,
nossl: nossl,
userscripts: userscripts,
userscripts: opt_match.opt_default("userscripts", ""),
output_file: opt_match.opt_str("o"),
headless: opt_match.opt_present("z"),
hard_fail: opt_match.opt_present("f"),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.