diff options
author | SendilKumar N <sendilkumarn@live.com> | 2017-03-09 01:03:00 +0800 |
---|---|---|
committer | SendilKumar N <sendilkumarn@live.com> | 2017-03-13 21:57:50 +0800 |
commit | 5b25cb33450e13acd6160af81cd462d3b7778538 (patch) | |
tree | 885e9d3641ab8d228641f67409dd6544dc5fe8dd /components/script/dom/userscripts.rs | |
parent | c11d398010f1c26622c64e076786a00776096b94 (diff) | |
download | servo-5b25cb33450e13acd6160af81cd462d3b7778538.tar.gz servo-5b25cb33450e13acd6160af81cd462d3b7778538.zip |
apply user scripts correctly
replace to utf8_lossy
Diffstat (limited to 'components/script/dom/userscripts.rs')
-rw-r--r-- | components/script/dom/userscripts.rs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/components/script/dom/userscripts.rs b/components/script/dom/userscripts.rs index 66758afaa98..fd5ae5f023e 100644 --- a/components/script/dom/userscripts.rs +++ b/components/script/dom/userscripts.rs @@ -2,25 +2,25 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; -use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::inheritance::Castable; -use dom::bindings::js::RootedReference; -use dom::bindings::str::DOMString; +use dom::globalscope::GlobalScope; use dom::htmlheadelement::HTMLHeadElement; use dom::node::Node; +use js::jsval::UndefinedValue; use servo_config::opts; use servo_config::resource_files::resources_dir_path; -use std::borrow::ToOwned; -use std::fs::read_dir; +use std::fs::{File, read_dir}; +use std::io::Read; use std::path::PathBuf; pub fn load_script(head: &HTMLHeadElement) { if let Some(ref path_str) = opts::get().userscripts { let node = head.upcast::<Node>(); - let first_child = node.GetFirstChild(); let doc = node.owner_doc(); + let win = doc.window(); + let cx = win.get_cx(); + rooted!(in(cx) let mut rval = UndefinedValue()); let path = if &**path_str == "" { if let Ok(mut p) = resources_dir_path() { @@ -40,13 +40,11 @@ pub fn load_script(head: &HTMLHeadElement) { 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(DOMString::from("script")).unwrap(); - new_script.set_string_attribute(&local_name!("src"), DOMString::from(name)); - node.InsertBefore(new_script.upcast(), first_child.r()).unwrap(); + let mut f = File::open(&file).unwrap(); + let mut contents = vec![]; + f.read_to_end(&mut contents).unwrap(); + let script_text = String::from_utf8_lossy(&contents); + win.upcast::<GlobalScope>().evaluate_js_on_global_with_result(&script_text, rval.handle_mut()); } } } |