aboutsummaryrefslogtreecommitdiffstats
path: root/ports
diff options
context:
space:
mode:
authorPaul Rouget <me@paulrouget.com>2018-10-26 09:38:10 +0200
committerPaul Rouget <me@paulrouget.com>2018-10-26 12:15:52 +0200
commit549c8c565a12aad0c8d4a17dfbb664d5ae2b0691 (patch)
tree0bba0f32d227815e314f25e97694b545064050fd /ports
parentb19f9d9c5b6360d1d05ac3b2b7b3b5d78b0bdfa9 (diff)
downloadservo-549c8c565a12aad0c8d4a17dfbb664d5ae2b0691.tar.gz
servo-549c8c565a12aad0c8d4a17dfbb664d5ae2b0691.zip
Android: proper shutdown mechanism
Diffstat (limited to 'ports')
-rw-r--r--ports/libsimpleservo/src/api.rs23
-rw-r--r--ports/libsimpleservo/src/capi.rs18
-rw-r--r--ports/libsimpleservo/src/jniapi.rs21
3 files changed, 61 insertions, 1 deletions
diff --git a/ports/libsimpleservo/src/api.rs b/ports/libsimpleservo/src/api.rs
index f946b0681cc..8b63aca4169 100644
--- a/ports/libsimpleservo/src/api.rs
+++ b/ports/libsimpleservo/src/api.rs
@@ -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(..) => {},
}
}
diff --git a/ports/libsimpleservo/src/capi.rs b/ports/libsimpleservo/src/capi.rs
index 28c036cff56..7b6e401311d 100644
--- a/ports/libsimpleservo/src/capi.rs
+++ b/ports/libsimpleservo/src/capi.rs
@@ -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
@@ -109,6 +110,18 @@ pub extern "C" fn init_with_gl(
}
#[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");
call(|s| s.set_batch_mode(batch));
@@ -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)();
+ }
}
diff --git a/ports/libsimpleservo/src/jniapi.rs b/ports/libsimpleservo/src/jniapi.rs
index ad027ec946a..bb499cedf48 100644
--- a/ports/libsimpleservo/src/jniapi.rs
+++ b/ports/libsimpleservo/src/jniapi.rs
@@ -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 {
@@ -118,6 +120,18 @@ pub fn Java_org_mozilla_servoview_JNIServo_setBatchMode(
}
#[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,
_: JClass,
@@ -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();