web: Flush shared objects in unload intead of beforeunload
Fix part of #2092. A panic could occur if content navigated away using getURL, which could trigger the shared object flush while the frame was still executing. Move the flush to "unload" so that it occurs after execution is complete.
This commit is contained in:
parent
9e46757f5f
commit
972e743e34
|
@ -72,7 +72,7 @@ struct RuffleInstance {
|
||||||
mouse_wheel_callback: Option<Closure<dyn FnMut(WheelEvent)>>,
|
mouse_wheel_callback: Option<Closure<dyn FnMut(WheelEvent)>>,
|
||||||
key_down_callback: Option<Closure<dyn FnMut(KeyboardEvent)>>,
|
key_down_callback: Option<Closure<dyn FnMut(KeyboardEvent)>>,
|
||||||
key_up_callback: Option<Closure<dyn FnMut(KeyboardEvent)>>,
|
key_up_callback: Option<Closure<dyn FnMut(KeyboardEvent)>>,
|
||||||
before_unload_callback: Option<Closure<dyn FnMut(Event)>>,
|
unload_callback: Option<Closure<dyn FnMut(Event)>>,
|
||||||
has_focus: bool,
|
has_focus: bool,
|
||||||
trace_observer: Arc<RefCell<JsValue>>,
|
trace_observer: Arc<RefCell<JsValue>>,
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ impl Ruffle {
|
||||||
instance.mouse_up_callback = None;
|
instance.mouse_up_callback = None;
|
||||||
instance.player_mouse_down_callback = None;
|
instance.player_mouse_down_callback = None;
|
||||||
instance.window_mouse_down_callback = None;
|
instance.window_mouse_down_callback = None;
|
||||||
instance.before_unload_callback = None;
|
instance.unload_callback = None;
|
||||||
|
|
||||||
// Cancel the animation handler, if it's still active.
|
// Cancel the animation handler, if it's still active.
|
||||||
if let Some(id) = instance.animation_handler_id {
|
if let Some(id) = instance.animation_handler_id {
|
||||||
|
@ -351,7 +351,7 @@ impl Ruffle {
|
||||||
mouse_wheel_callback: None,
|
mouse_wheel_callback: None,
|
||||||
key_down_callback: None,
|
key_down_callback: None,
|
||||||
key_up_callback: None,
|
key_up_callback: None,
|
||||||
before_unload_callback: None,
|
unload_callback: None,
|
||||||
timestamp: None,
|
timestamp: None,
|
||||||
has_focus: false,
|
has_focus: false,
|
||||||
trace_observer,
|
trace_observer,
|
||||||
|
@ -665,7 +665,7 @@ impl Ruffle {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let before_unload_callback = Closure::wrap(Box::new(move |_| {
|
let unload_callback = Closure::wrap(Box::new(move |_| {
|
||||||
INSTANCES.with(|instances| {
|
INSTANCES.with(|instances| {
|
||||||
if let Some(instance) = instances.borrow().get(index) {
|
if let Some(instance) = instances.borrow().get(index) {
|
||||||
let instance = instance.borrow();
|
let instance = instance.borrow();
|
||||||
|
@ -673,17 +673,16 @@ impl Ruffle {
|
||||||
player.flush_shared_objects();
|
player.flush_shared_objects();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
}) as Box<dyn FnMut(Event)>);
|
||||||
as Box<dyn FnMut(Event)>);
|
|
||||||
|
|
||||||
window
|
window
|
||||||
.add_event_listener_with_callback(
|
.add_event_listener_with_callback(
|
||||||
"beforeunload",
|
"unload",
|
||||||
before_unload_callback.as_ref().unchecked_ref(),
|
unload_callback.as_ref().unchecked_ref(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut instance = instances.get(index).unwrap().borrow_mut();
|
let mut instance = instances.get(index).unwrap().borrow_mut();
|
||||||
instance.before_unload_callback = Some(before_unload_callback);
|
instance.unload_callback = Some(unload_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
ruffle
|
ruffle
|
||||||
|
|
Loading…
Reference in New Issue