"javascript:" urls: clean up js evaluation code

- move it to its own function
- move the `url = "about:blank" code into the same block
- move the `use` statement to the top of the file
This commit is contained in:
Daniel Johnson 2017-08-27 23:18:19 -07:00
parent fc23cb1a63
commit 5d28dd64d9

View file

@ -119,6 +119,7 @@ use task_source::performance_timeline::{PerformanceTimelineTask, PerformanceTime
use task_source::user_interaction::{UserInteractionTask, UserInteractionTaskSource}; use task_source::user_interaction::{UserInteractionTask, UserInteractionTaskSource};
use time::{get_time, precise_time_ns, Tm}; use time::{get_time, precise_time_ns, Tm};
use url::Position; use url::Position;
use url::percent_encoding::percent_decode;
use webdriver_handlers; use webdriver_handlers;
use webvr_traits::{WebVREvent, WebVRMsg}; use webvr_traits::{WebVREvent, WebVRMsg};
@ -2309,20 +2310,28 @@ impl ScriptThread {
browsing_context_id: Option<BrowsingContextId>, browsing_context_id: Option<BrowsingContextId>,
mut load_data: LoadData, mut load_data: LoadData,
replace: bool) { replace: bool) {
let is_javascript = load_data.url.scheme() == "javascript";
if is_javascript {
self.eval_js_url(parent_pipeline_id, &mut load_data);
}
match browsing_context_id { match browsing_context_id {
Some(browsing_context_id) => { Some(browsing_context_id) => {
let iframe = self.documents.borrow().find_iframe(parent_pipeline_id, browsing_context_id); let iframe = self.documents.borrow().find_iframe(parent_pipeline_id, browsing_context_id);
if let Some(iframe) = iframe { if let Some(iframe) = iframe {
iframe.navigate_or_reload_child_browsing_context(Some(load_data), NavigationType::Regular, replace); iframe.navigate_or_reload_child_browsing_context(Some(load_data), NavigationType::Regular, replace);
} }
// TODO: Test javascript: urls in iframes
} }
None => { None => {
let is_javascript = load_data.url.scheme() == "javascript"; self.script_sender
if is_javascript { .send((parent_pipeline_id, ScriptMsg::LoadUrl(load_data, replace)))
use url::percent_encoding::percent_decode; .unwrap();
}
}
}
fn eval_js_url(&self, pipeline_id: PipelineId, load_data: &mut LoadData) {
{
// Turn javascript: URL into JS code to eval, according to the steps in // Turn javascript: URL into JS code to eval, according to the steps in
// https://html.spec.whatwg.org/multipage/#javascript-protocol // https://html.spec.whatwg.org/multipage/#javascript-protocol
@ -2336,7 +2345,8 @@ impl ScriptThread {
let script_source = percent_decode(encoded.as_bytes()).decode_utf8_lossy(); let script_source = percent_decode(encoded.as_bytes()).decode_utf8_lossy();
// Script source is ready to be evaluated (11.) // Script source is ready to be evaluated (11.)
let window = self.documents.borrow().find_window(parent_pipeline_id); let window = self.documents.borrow().find_window(pipeline_id);
if let Some(window) = window { if let Some(window) = window {
let _ac = JSAutoCompartment::new(self.get_cx(), window.reflector().get_jsobject().get()); let _ac = JSAutoCompartment::new(self.get_cx(), window.reflector().get_jsobject().get());
rooted!(in(self.get_cx()) let mut jsval = UndefinedValue()); rooted!(in(self.get_cx()) let mut jsval = UndefinedValue());
@ -2359,19 +2369,11 @@ impl ScriptThread {
Some(JsEvalResult::NoContent) Some(JsEvalResult::NoContent)
}; };
} }
} };
if is_javascript {
load_data.url = ServoUrl::parse("about:blank").unwrap(); load_data.url = ServoUrl::parse("about:blank").unwrap();
} }
self.script_sender
.send((parent_pipeline_id, ScriptMsg::LoadUrl(load_data, replace)))
.unwrap();
}
}
}
fn handle_resize_event(&self, pipeline_id: PipelineId, new_size: WindowSizeData, size_type: WindowSizeType) { fn handle_resize_event(&self, pipeline_id: PipelineId, new_size: WindowSizeData, size_type: WindowSizeType) {
let document = match { self.documents.borrow().find_document(pipeline_id) } { let document = match { self.documents.borrow().find_document(pipeline_id) } {
Some(document) => document, Some(document) => document,