Skip to content

Commit

Permalink
Removed some sources of panic from script thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed Jun 24, 2016
1 parent eeed5b6 commit 9da00e2
Showing 1 changed file with 58 additions and 30 deletions.
88 changes: 58 additions & 30 deletions components/script/script_thread.rs
Expand Up @@ -1008,7 +1008,10 @@ impl ScriptThread {
let context = self.root_browsing_context();
match msg {
DevtoolScriptControlMsg::EvaluateJS(id, s, reply) => {
let window = get_browsing_context(&context, id).active_window();
let window = match context.find(id) {
Some(browsing_context) => browsing_context.active_window(),
None => return warn!("Message sent to closed pipeline {}.", id),
};
let global_ref = GlobalRef::Window(window.r());
devtools::handle_evaluate_js(&global_ref, s, reply)
},
Expand All @@ -1025,7 +1028,10 @@ impl ScriptThread {
DevtoolScriptControlMsg::ModifyAttribute(id, node_id, modifications) =>
devtools::handle_modify_attribute(&context, id, node_id, modifications),
DevtoolScriptControlMsg::WantsLiveNotifications(id, to_send) => {
let window = get_browsing_context(&context, id).active_window();
let window = match context.find(id) {
Some(browsing_context) => browsing_context.active_window(),
None => return warn!("Message sent to closed pipeline {}.", id),
};
let global_ref = GlobalRef::Window(window.r());
devtools::handle_wants_live_notifications(&global_ref, to_send)
},
Expand Down Expand Up @@ -1108,8 +1114,7 @@ impl ScriptThread {
if let Some(inner_context) = context.find(id) {
let window = inner_context.active_window();
if window.set_page_clip_rect_with_new_viewport(rect) {
let context = get_browsing_context(&context, id);
self.rebuild_and_force_reflow(&context, ReflowReason::Viewport);
self.rebuild_and_force_reflow(&inner_context, ReflowReason::Viewport);
}
return;
}
Expand All @@ -1119,7 +1124,7 @@ impl ScriptThread {
load.clip_rect = Some(rect);
return;
}
panic!("Page rect message sent to nonexistent pipeline");
warn!("Page rect message sent to nonexistent pipeline");
}

fn handle_set_scroll_state(&self,
Expand All @@ -1134,7 +1139,7 @@ impl ScriptThread {
}
}
}
None => panic!("Set scroll state message sent to nonexistent pipeline: {:?}", id),
None => return warn!("Set scroll state message sent to nonexistent pipeline: {:?}", id),
};

let mut scroll_offsets = HashMap::new();
Expand Down Expand Up @@ -1199,8 +1204,10 @@ impl ScriptThread {
}

fn handle_loads_complete(&self, pipeline: PipelineId) {
let context = get_browsing_context(&self.root_browsing_context(), pipeline);
let doc = context.active_document();
let doc = match self.root_browsing_context().find(pipeline) {
Some(browsing_context) => browsing_context.active_document(),
None => return warn!("Message sent to closed pipeline {}.", pipeline),
};
let doc = doc.r();
if doc.loader().is_blocked() {
return;
Expand Down Expand Up @@ -1306,7 +1313,7 @@ impl ScriptThread {
load.is_frozen = true;
return;
}
panic!("freeze sent to nonexistent pipeline");
warn!("freeze sent to nonexistent pipeline");
}

/// Handles thaw message
Expand All @@ -1325,7 +1332,7 @@ impl ScriptThread {
load.is_frozen = false;
return;
}
panic!("thaw sent to nonexistent pipeline");
warn!("thaw sent to nonexistent pipeline");
}

fn handle_focus_iframe_msg(&self,
Expand Down Expand Up @@ -1444,8 +1451,10 @@ impl ScriptThread {

/// Handles a request for the window title.
fn handle_get_title_msg(&self, pipeline_id: PipelineId) {
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let document = context.active_document();
let document = match self.root_browsing_context().find(pipeline_id) {
Some(browsing_context) => browsing_context.active_document(),
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
};
document.send_title_to_compositor();
}

Expand Down Expand Up @@ -1499,8 +1508,10 @@ impl ScriptThread {

/// Handles when layout thread finishes all animation in one tick
fn handle_tick_all_animations(&self, id: PipelineId) {
let context = get_browsing_context(&self.root_browsing_context(), id);
let document = context.active_document();
let document = match self.root_browsing_context().find(id) {
Some(browsing_context) => browsing_context.active_document(),
None => return warn!("Message sent to closed pipeline {}.", id),
};
document.run_the_animation_frame_callbacks();
}

Expand All @@ -1513,8 +1524,10 @@ impl ScriptThread {

/// Notify the containing document of a child frame that has completed loading.
fn handle_frame_load_event(&self, containing_pipeline: PipelineId, id: PipelineId) {
let context = get_browsing_context(&self.root_browsing_context(), containing_pipeline);
let document = context.active_document();
let document = match self.root_browsing_context().find(containing_pipeline) {
Some(browsing_context) => browsing_context.active_document(),
None => return warn!("Message sent to closed pipeline {}.", containing_pipeline),
};
if let Some(iframe) = document.find_iframe_by_pipeline(id) {
iframe.iframe_load_event_steps(id);
}
Expand Down Expand Up @@ -1839,8 +1852,10 @@ impl ScriptThread {
}

MouseMoveEvent(point) => {
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let document = context.active_document();
let document = match self.root_browsing_context().find(pipeline_id) {
Some(browsing_context) => browsing_context.active_document(),
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
};

// Get the previous target temporarily
let prev_mouse_over_target = self.topmost_mouse_over_target.get();
Expand Down Expand Up @@ -1909,14 +1924,18 @@ impl ScriptThread {
}

TouchpadPressureEvent(point, pressure, phase) => {
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let document = context.active_document();
let document = match self.root_browsing_context().find(pipeline_id) {
Some(browsing_context) => browsing_context.active_document(),
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
};
document.r().handle_touchpad_pressure_event(self.js_runtime.rt(), point, pressure, phase);
}

KeyEvent(key, state, modifiers) => {
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let document = context.active_document();
let document = match self.root_browsing_context().find(pipeline_id) {
Some(browsing_context) => browsing_context.active_document(),
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
};
document.dispatch_key_event(key, state, modifiers, &self.constellation_chan);
}
}
Expand All @@ -1927,8 +1946,10 @@ impl ScriptThread {
mouse_event_type: MouseEventType,
button: MouseButton,
point: Point2D<f32>) {
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let document = context.active_document();
let document = match self.root_browsing_context().find(pipeline_id) {
Some(browsing_context) => browsing_context.active_document(),
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
};
document.handle_mouse_event(self.js_runtime.rt(), button, point, mouse_event_type);
}

Expand All @@ -1938,8 +1959,10 @@ impl ScriptThread {
identifier: TouchId,
point: Point2D<f32>)
-> bool {
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let document = context.active_document();
let document = match self.root_browsing_context().find(pipeline_id) {
Some(browsing_context) => browsing_context.active_document(),
None => { warn!("Message sent to closed pipeline {}.", pipeline_id); return true },
};
document.handle_touch_event(self.js_runtime.rt(), event_type, identifier, point)
}

Expand All @@ -1951,9 +1974,10 @@ impl ScriptThread {
{
let nurl = &load_data.url;
if let Some(fragment) = nurl.fragment() {
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let document = context.active_document();
let document = document.r();
let document = match self.root_browsing_context().find(pipeline_id) {
Some(browsing_context) => browsing_context.active_document(),
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
};
let url = document.url();
if &url[..Position::AfterQuery] == &nurl[..Position::AfterQuery] &&
load_data.method == Method::Get {
Expand Down Expand Up @@ -1988,7 +2012,10 @@ impl ScriptThread {
}

fn handle_resize_event(&self, pipeline_id: PipelineId, new_size: WindowSizeData, size_type: WindowSizeType) {
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let context = match self.root_browsing_context().find(pipeline_id) {
Some(browsing_context) => browsing_context,
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
};
let window = context.active_window();
window.set_window_size(new_size);
window.force_reflow(ReflowGoal::ForDisplay,
Expand Down Expand Up @@ -2159,6 +2186,7 @@ fn shut_down_layout(context_tree: &BrowsingContext) {
}
}

// TODO: remove this function, as it's a source of panic.
pub fn get_browsing_context(context: &BrowsingContext,
pipeline_id: PipelineId)
-> Root<BrowsingContext> {
Expand Down

0 comments on commit 9da00e2

Please sign in to comment.