mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Expose javascript:window.alert() to libsimpleservo
This commit is contained in:
parent
b6cc0f60a9
commit
3a374b3455
7 changed files with 42 additions and 0 deletions
|
@ -347,6 +347,7 @@ impl HostTrait for HostCallbacks {
|
|||
MakeCurrent(self.disp, self.surf, self.surf, self.ctxt);
|
||||
}
|
||||
|
||||
fn on_alert(&self, _message: String) {}
|
||||
fn on_load_started(&self) {}
|
||||
fn on_load_ended(&self) {}
|
||||
fn on_title_changed(&self, _title: String) {}
|
||||
|
|
|
@ -89,6 +89,8 @@ pub trait HostTrait {
|
|||
/// Will be called before drawing.
|
||||
/// Time to make the targetted GL context current.
|
||||
fn make_current(&self);
|
||||
/// javascript window.alert()
|
||||
fn on_alert(&self, msg: String);
|
||||
/// Page starts loading.
|
||||
/// "Reload button" should be disabled.
|
||||
/// "Stop button" should be enabled.
|
||||
|
@ -521,6 +523,7 @@ impl ServoGlue {
|
|||
},
|
||||
EmbedderMsg::Alert(message, sender) => {
|
||||
info!("Alert: {}", message);
|
||||
self.callbacks.host_callbacks.on_alert(message);
|
||||
let _ = sender.send(());
|
||||
},
|
||||
EmbedderMsg::AllowOpeningBrowser(response_chan) => {
|
||||
|
|
|
@ -38,6 +38,7 @@ where
|
|||
pub struct CHostCallbacks {
|
||||
pub flush: extern "C" fn(),
|
||||
pub make_current: extern "C" fn(),
|
||||
pub on_alert: extern "C" fn(message: *const c_char),
|
||||
pub on_load_started: extern "C" fn(),
|
||||
pub on_load_ended: extern "C" fn(),
|
||||
pub on_title_changed: extern "C" fn(title: *const c_char),
|
||||
|
@ -346,6 +347,14 @@ impl HostTrait for HostCallbacks {
|
|||
(self.0.make_current)();
|
||||
}
|
||||
|
||||
fn on_alert(&self, message: String) {
|
||||
debug!("on_alert");
|
||||
let message = CString::new(message).expect("Can't create string");
|
||||
let msg_ptr = message.as_ptr();
|
||||
mem::forget(message);
|
||||
(self.0.on_alert)(msg_ptr);
|
||||
}
|
||||
|
||||
fn on_load_started(&self) {
|
||||
debug!("on_load_ended");
|
||||
(self.0.on_load_started)();
|
||||
|
|
|
@ -375,6 +375,23 @@ impl HostTrait for HostCallbacks {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_alert(&self, message: String) {
|
||||
debug!("on_alert");
|
||||
let env = self.jvm.get_env().unwrap();
|
||||
let s = match new_string(&env, &message) {
|
||||
Ok(s) => s,
|
||||
Err(_) => return,
|
||||
};
|
||||
let s = JValue::from(JObject::from(s));
|
||||
env.call_method(
|
||||
self.callbacks.as_obj(),
|
||||
"onAlert",
|
||||
"(Ljava/lang/String;)V",
|
||||
&[s],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_load_started(&self) {
|
||||
debug!("on_load_started");
|
||||
let env = self.jvm.get_env().unwrap();
|
||||
|
|
|
@ -129,6 +129,10 @@ public class MainActivity extends Activity implements Servo.Client {
|
|||
mServoView.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAlert(String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadStarted() {
|
||||
mReloadButton.setEnabled(false);
|
||||
|
|
|
@ -93,6 +93,8 @@ public class JNIServo {
|
|||
|
||||
void makeCurrent();
|
||||
|
||||
void onAlert(String message);
|
||||
|
||||
void onAnimatingChanged(boolean animating);
|
||||
|
||||
void onLoadStarted();
|
||||
|
|
|
@ -169,6 +169,8 @@ public class Servo {
|
|||
}
|
||||
|
||||
public interface Client {
|
||||
void onAlert(String message);
|
||||
|
||||
boolean onAllowNavigation(String url);
|
||||
|
||||
void onLoadStarted();
|
||||
|
@ -228,6 +230,10 @@ public class Servo {
|
|||
mGfxCb.makeCurrent();
|
||||
}
|
||||
|
||||
public void onAlert(String message) {
|
||||
mRunCallback.inUIThread(() -> mClient.onAlert(message));
|
||||
}
|
||||
|
||||
public void onShutdownComplete() {
|
||||
mShutdownComplete = true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue