mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Android: proper shutdown mechanism
This commit is contained in:
parent
b19f9d9c5b
commit
549c8c565a
7 changed files with 145 additions and 17 deletions
|
@ -77,6 +77,8 @@ pub trait HostTrait {
|
|||
/// has events for Servo, or Servo has woken up the embedder event loop via
|
||||
/// EventLoopWaker).
|
||||
fn on_animating_changed(&self, animating: bool);
|
||||
/// Servo finished shutting down.
|
||||
fn on_shutdown_complete(&self);
|
||||
}
|
||||
|
||||
pub struct ServoGlue {
|
||||
|
@ -169,6 +171,12 @@ pub fn init(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn deinit() {
|
||||
SERVO.with(|s| {
|
||||
s.replace(None).unwrap().deinit()
|
||||
});
|
||||
}
|
||||
|
||||
impl ServoGlue {
|
||||
fn get_browser_id(&self) -> Result<BrowserId, &'static str> {
|
||||
let browser_id = match self.browser_id {
|
||||
|
@ -177,6 +185,17 @@ impl ServoGlue {
|
|||
};
|
||||
Ok(browser_id)
|
||||
}
|
||||
|
||||
/// Request shutdown. Will call on_shutdown_complete.
|
||||
pub fn request_shutdown(&mut self) -> Result<(), &'static str> {
|
||||
self.process_event(WindowEvent::Quit)
|
||||
}
|
||||
|
||||
/// Call after on_shutdown_complete
|
||||
pub fn deinit(self) {
|
||||
self.servo.deinit();
|
||||
}
|
||||
|
||||
/// This is the Servo heartbeat. This needs to be called
|
||||
/// everytime wakeup is called or when embedder wants Servo
|
||||
/// to act on its pending events.
|
||||
|
@ -404,6 +423,9 @@ impl ServoGlue {
|
|||
self.events.push(WindowEvent::Quit);
|
||||
}
|
||||
},
|
||||
EmbedderMsg::Shutdown => {
|
||||
self.callbacks.host_callbacks.on_shutdown_complete();
|
||||
},
|
||||
EmbedderMsg::Status(..) |
|
||||
EmbedderMsg::SelectFiles(..) |
|
||||
EmbedderMsg::MoveTo(..) |
|
||||
|
@ -415,7 +437,6 @@ impl ServoGlue {
|
|||
EmbedderMsg::SetFullscreenState(..) |
|
||||
EmbedderMsg::ShowIME(..) |
|
||||
EmbedderMsg::HideIME |
|
||||
EmbedderMsg::Shutdown |
|
||||
EmbedderMsg::Panic(..) => {},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ pub struct CHostCallbacks {
|
|||
pub on_url_changed: extern fn(url: *const c_char),
|
||||
pub on_history_changed: extern fn(can_go_back: bool, can_go_forward: bool),
|
||||
pub on_animating_changed: extern fn(animating: bool),
|
||||
pub on_shutdown_complete: extern fn(),
|
||||
}
|
||||
|
||||
/// Servo options
|
||||
|
@ -108,6 +109,18 @@ pub extern "C" fn init_with_gl(
|
|||
init(opts, gl, wakeup, readfile, callbacks)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn deinit() {
|
||||
debug!("deinit");
|
||||
api::deinit();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn request_shutdown() {
|
||||
debug!("request_shutdown");
|
||||
call(|s| s.request_shutdown());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn set_batch_mode(batch: bool) {
|
||||
debug!("set_batch_mode");
|
||||
|
@ -296,4 +309,9 @@ impl HostTrait for HostCallbacks {
|
|||
debug!("on_animating_changed");
|
||||
(self.0.on_animating_changed)(animating);
|
||||
}
|
||||
|
||||
fn on_shutdown_complete(&self) {
|
||||
debug!("on_shutdown_complete");
|
||||
(self.0.on_shutdown_complete)();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,8 @@ pub fn Java_org_mozilla_servoview_JNIServo_init(
|
|||
"script::dom::bindings::error",
|
||||
// Show GL errors by default.
|
||||
"canvas::webgl_thread",
|
||||
"compositing::compositor",
|
||||
"constellation::constellation",
|
||||
];
|
||||
let mut filter = Filter::default().with_min_level(Level::Debug);
|
||||
for &module in &filters {
|
||||
|
@ -117,6 +119,18 @@ pub fn Java_org_mozilla_servoview_JNIServo_setBatchMode(
|
|||
call(&env, |s| s.set_batch_mode(batch == JNI_TRUE));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_org_mozilla_servoview_JNIServo_requestShutdown(env: JNIEnv, _class: JClass) {
|
||||
debug!("requestShutdown");
|
||||
call(&env, |s| s.request_shutdown());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_org_mozilla_servoview_JNIServo_deinit(_env: JNIEnv, _class: JClass) {
|
||||
debug!("deinit");
|
||||
api::deinit();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn Java_org_mozilla_servoview_JNIServo_resize(
|
||||
env: JNIEnv,
|
||||
|
@ -357,6 +371,13 @@ impl HostTrait for HostCallbacks {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_shutdown_complete(&self) {
|
||||
debug!("on_shutdown_complete");
|
||||
let env = self.jvm.get_env().unwrap();
|
||||
env.call_method(self.callbacks.as_obj(), "onShutdownComplete", "()V", &[])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_title_changed(&self, title: String) {
|
||||
debug!("on_title_changed");
|
||||
let env = self.jvm.get_env().unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue