mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #23801 - paulrouget:alert, r=jdm
Expose javascript:window.alert() to libsimpleservo <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23801) <!-- Reviewable:end -->
This commit is contained in:
commit
60f1ffc5a7
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);
|
MakeCurrent(self.disp, self.surf, self.surf, self.ctxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_alert(&self, _message: String) {}
|
||||||
fn on_load_started(&self) {}
|
fn on_load_started(&self) {}
|
||||||
fn on_load_ended(&self) {}
|
fn on_load_ended(&self) {}
|
||||||
fn on_title_changed(&self, _title: String) {}
|
fn on_title_changed(&self, _title: String) {}
|
||||||
|
|
|
@ -89,6 +89,8 @@ pub trait HostTrait {
|
||||||
/// Will be called before drawing.
|
/// Will be called before drawing.
|
||||||
/// Time to make the targetted GL context current.
|
/// Time to make the targetted GL context current.
|
||||||
fn make_current(&self);
|
fn make_current(&self);
|
||||||
|
/// javascript window.alert()
|
||||||
|
fn on_alert(&self, msg: String);
|
||||||
/// Page starts loading.
|
/// Page starts loading.
|
||||||
/// "Reload button" should be disabled.
|
/// "Reload button" should be disabled.
|
||||||
/// "Stop button" should be enabled.
|
/// "Stop button" should be enabled.
|
||||||
|
@ -521,6 +523,7 @@ impl ServoGlue {
|
||||||
},
|
},
|
||||||
EmbedderMsg::Alert(message, sender) => {
|
EmbedderMsg::Alert(message, sender) => {
|
||||||
info!("Alert: {}", message);
|
info!("Alert: {}", message);
|
||||||
|
self.callbacks.host_callbacks.on_alert(message);
|
||||||
let _ = sender.send(());
|
let _ = sender.send(());
|
||||||
},
|
},
|
||||||
EmbedderMsg::AllowOpeningBrowser(response_chan) => {
|
EmbedderMsg::AllowOpeningBrowser(response_chan) => {
|
||||||
|
|
|
@ -38,6 +38,7 @@ where
|
||||||
pub struct CHostCallbacks {
|
pub struct CHostCallbacks {
|
||||||
pub flush: extern "C" fn(),
|
pub flush: extern "C" fn(),
|
||||||
pub make_current: 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_started: extern "C" fn(),
|
||||||
pub on_load_ended: extern "C" fn(),
|
pub on_load_ended: extern "C" fn(),
|
||||||
pub on_title_changed: extern "C" fn(title: *const c_char),
|
pub on_title_changed: extern "C" fn(title: *const c_char),
|
||||||
|
@ -346,6 +347,14 @@ impl HostTrait for HostCallbacks {
|
||||||
(self.0.make_current)();
|
(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) {
|
fn on_load_started(&self) {
|
||||||
debug!("on_load_ended");
|
debug!("on_load_ended");
|
||||||
(self.0.on_load_started)();
|
(self.0.on_load_started)();
|
||||||
|
|
|
@ -375,6 +375,23 @@ impl HostTrait for HostCallbacks {
|
||||||
.unwrap();
|
.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) {
|
fn on_load_started(&self) {
|
||||||
debug!("on_load_started");
|
debug!("on_load_started");
|
||||||
let env = self.jvm.get_env().unwrap();
|
let env = self.jvm.get_env().unwrap();
|
||||||
|
|
|
@ -129,6 +129,10 @@ public class MainActivity extends Activity implements Servo.Client {
|
||||||
mServoView.stop();
|
mServoView.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAlert(String message) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadStarted() {
|
public void onLoadStarted() {
|
||||||
mReloadButton.setEnabled(false);
|
mReloadButton.setEnabled(false);
|
||||||
|
|
|
@ -93,6 +93,8 @@ public class JNIServo {
|
||||||
|
|
||||||
void makeCurrent();
|
void makeCurrent();
|
||||||
|
|
||||||
|
void onAlert(String message);
|
||||||
|
|
||||||
void onAnimatingChanged(boolean animating);
|
void onAnimatingChanged(boolean animating);
|
||||||
|
|
||||||
void onLoadStarted();
|
void onLoadStarted();
|
||||||
|
|
|
@ -169,6 +169,8 @@ public class Servo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Client {
|
public interface Client {
|
||||||
|
void onAlert(String message);
|
||||||
|
|
||||||
boolean onAllowNavigation(String url);
|
boolean onAllowNavigation(String url);
|
||||||
|
|
||||||
void onLoadStarted();
|
void onLoadStarted();
|
||||||
|
@ -228,6 +230,10 @@ public class Servo {
|
||||||
mGfxCb.makeCurrent();
|
mGfxCb.makeCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onAlert(String message) {
|
||||||
|
mRunCallback.inUIThread(() -> mClient.onAlert(message));
|
||||||
|
}
|
||||||
|
|
||||||
public void onShutdownComplete() {
|
public void onShutdownComplete() {
|
||||||
mShutdownComplete = true;
|
mShutdownComplete = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue