mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
Allow window elements as well as iframes to the the target of mozbrowser events.
This commit is contained in:
parent
fa432a5a34
commit
72aa4f2f62
8 changed files with 162 additions and 152 deletions
|
@ -1043,14 +1043,14 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
|
||||
debug!("Panic handler for pipeline {:?}: {}.", pipeline_id, reason);
|
||||
|
||||
// Notify the browser chrome that the pipeline has failed
|
||||
self.trigger_mozbrowsererror(pipeline_id, reason, backtrace);
|
||||
|
||||
if let Some(pipeline_id) = pipeline_id {
|
||||
let pipeline_url = self.pipelines.get(&pipeline_id).map(|pipeline| pipeline.url.clone());
|
||||
let parent_info = self.pipelines.get(&pipeline_id).and_then(|pipeline| pipeline.parent_info);
|
||||
let window_size = self.pipelines.get(&pipeline_id).and_then(|pipeline| pipeline.size);
|
||||
|
||||
// Notify the browser chrome that the pipeline has failed
|
||||
self.trigger_mozbrowsererror(pipeline_id, reason, backtrace);
|
||||
|
||||
self.close_pipeline(pipeline_id, ExitPipelineMode::Force);
|
||||
self.pipelines.remove(&pipeline_id);
|
||||
|
||||
|
@ -1082,12 +1082,10 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
self.handled_panic = true;
|
||||
}
|
||||
|
||||
// TODO: trigger a mozbrowsererror even if there's no pipeline id
|
||||
fn handle_log_entry(&mut self, pipeline_id: Option<PipelineId>, thread_name: Option<String>, entry: LogEntry) {
|
||||
match (pipeline_id, entry) {
|
||||
(Some(pipeline_id), LogEntry::Panic(reason, backtrace)) =>
|
||||
self.trigger_mozbrowsererror(pipeline_id, reason, backtrace),
|
||||
(None, LogEntry::Panic(reason, _)) | (_, LogEntry::Error(reason)) | (_, LogEntry::Warn(reason)) => {
|
||||
match entry {
|
||||
LogEntry::Panic(reason, backtrace) => self.trigger_mozbrowsererror(pipeline_id, reason, backtrace),
|
||||
LogEntry::Error(reason) | LogEntry::Warn(reason) => {
|
||||
// VecDeque::truncate is unstable
|
||||
if WARNINGS_BUFFER_SIZE <= self.handled_warnings.len() {
|
||||
self.handled_warnings.pop_front();
|
||||
|
@ -1284,7 +1282,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsershowmodalprompt
|
||||
let event = MozBrowserEvent::ShowModalPrompt("alert".to_owned(), "Alert".to_owned(),
|
||||
String::from(message), "".to_owned());
|
||||
root_pipeline.trigger_mozbrowser_event(subpage_id, event);
|
||||
root_pipeline.trigger_mozbrowser_event(Some(subpage_id), event);
|
||||
}
|
||||
None => return warn!("Alert sent to Pipeline {:?} after closure.", root_pipeline_id),
|
||||
}
|
||||
|
@ -1578,7 +1576,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
|
||||
fn handle_mozbrowser_event_msg(&mut self,
|
||||
containing_pipeline_id: PipelineId,
|
||||
subpage_id: SubpageId,
|
||||
subpage_id: Option<SubpageId>,
|
||||
event: MozBrowserEvent) {
|
||||
assert!(PREFS.is_mozbrowser_enabled());
|
||||
|
||||
|
@ -2271,7 +2269,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
let can_go_backward = !frame.prev.is_empty();
|
||||
let can_go_forward = !frame.next.is_empty();
|
||||
let event = MozBrowserEvent::LocationChange(url, can_go_backward, can_go_forward);
|
||||
parent_pipeline.trigger_mozbrowser_event(subpage_id, event);
|
||||
parent_pipeline.trigger_mozbrowser_event(Some(subpage_id), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2280,35 +2278,43 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsererror
|
||||
// Note that this does not require the pipeline to be an immediate child of the root
|
||||
// TODO: allow the pipeline id to be optional, triggering the error on the root if it's not provided.
|
||||
fn trigger_mozbrowsererror(&mut self, pipeline_id: PipelineId, reason: String, backtrace: String) {
|
||||
fn trigger_mozbrowsererror(&mut self, pipeline_id: Option<PipelineId>, reason: String, backtrace: String) {
|
||||
if !PREFS.is_mozbrowser_enabled() { return; }
|
||||
|
||||
let ancestor_info = self.get_mozbrowser_ancestor_info(pipeline_id);
|
||||
let mut report = String::new();
|
||||
for (thread_name, warning) in self.handled_warnings.drain(..) {
|
||||
report.push_str("\nWARNING: ");
|
||||
if let Some(thread_name) = thread_name {
|
||||
report.push_str("<");
|
||||
report.push_str(&*thread_name);
|
||||
report.push_str(">: ");
|
||||
}
|
||||
report.push_str(&*warning);
|
||||
}
|
||||
report.push_str("\nERROR: ");
|
||||
report.push_str(&*reason);
|
||||
report.push_str("\n\n");
|
||||
report.push_str(&*backtrace);
|
||||
|
||||
if let Some(ancestor_info) = ancestor_info {
|
||||
match self.pipelines.get(&ancestor_info.0) {
|
||||
Some(ancestor) => {
|
||||
let mut report = String::new();
|
||||
for (thread_name, warning) in self.handled_warnings.drain(..) {
|
||||
report.push_str("\nWARNING: ");
|
||||
if let Some(thread_name) = thread_name {
|
||||
report.push_str("<");
|
||||
report.push_str(&*thread_name);
|
||||
report.push_str(">: ");
|
||||
}
|
||||
report.push_str(&*warning);
|
||||
}
|
||||
report.push_str("\nERROR: ");
|
||||
report.push_str(&*reason);
|
||||
report.push_str("\n\n");
|
||||
report.push_str(&*backtrace);
|
||||
let event = MozBrowserEvent::Error(MozBrowserErrorType::Fatal, Some(reason), Some(report));
|
||||
ancestor.trigger_mozbrowser_event(ancestor_info.1, event);
|
||||
},
|
||||
None => return warn!("Mozbrowsererror via closed pipeline {:?}.", ancestor_info.0),
|
||||
let event = MozBrowserEvent::Error(MozBrowserErrorType::Fatal, Some(reason), Some(report));
|
||||
|
||||
if let Some(pipeline_id) = pipeline_id {
|
||||
if let Some((ancestor_id, subpage_id)) = self.get_mozbrowser_ancestor_info(pipeline_id) {
|
||||
if let Some(ancestor) = self.pipelines.get(&ancestor_id) {
|
||||
return ancestor.trigger_mozbrowser_event(Some(subpage_id), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(root_frame_id) = self.root_frame_id {
|
||||
if let Some(root_frame) = self.frames.get(&root_frame_id) {
|
||||
if let Some(root_pipeline) = self.pipelines.get(&root_frame.current) {
|
||||
return root_pipeline.trigger_mozbrowser_event(None, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
warn!("Mozbrowser error after root pipeline closed.");
|
||||
}
|
||||
|
||||
fn focused_pipeline_in_tree(&self, frame_id: FrameId) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue