mirror of
https://github.com/servo/servo.git
synced 2025-09-05 20:48:22 +01:00
libservo: Clean up interfaces for alert()/confirm()/prompt() (#35579)
Signed-off-by: Delan Azabani <dazabani@igalia.com>
This commit is contained in:
parent
03e953e22c
commit
276f6a3ba7
16 changed files with 278 additions and 222 deletions
|
@ -21,7 +21,10 @@ use napi_ohos::{Env, JsObject, JsString, NapiRaw};
|
|||
use ohos_ime::{AttachOptions, Ime, ImeProxy, RawTextEditorProxy};
|
||||
use ohos_ime_sys::types::InputMethod_EnterKeyType;
|
||||
use servo::style::Zero;
|
||||
use servo::{InputMethodType, LoadStatus, MediaSessionPlaybackState, PromptResult};
|
||||
use servo::{
|
||||
AlertResponse, InputMethodType, LoadStatus, MediaSessionPlaybackState, PermissionRequest,
|
||||
SimpleDialog, WebView,
|
||||
};
|
||||
use simpleservo::EventLoopWaker;
|
||||
use xcomponent_sys::{
|
||||
OH_NativeXComponent, OH_NativeXComponent_Callback, OH_NativeXComponent_GetKeyEvent,
|
||||
|
@ -671,6 +674,19 @@ impl HostCallbacks {
|
|||
ime_proxy: RefCell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_alert(&self, message: String) {
|
||||
match PROMPT_TOAST.get() {
|
||||
Some(prompt_fn) => {
|
||||
let status = prompt_fn.call(message, ThreadsafeFunctionCallMode::NonBlocking);
|
||||
if status != napi_ohos::Status::Ok {
|
||||
// Queue could be full.
|
||||
error!("show_alert failed with {status}");
|
||||
}
|
||||
},
|
||||
None => error!("PROMPT_TOAST not set. Dropping message {message}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ServoIme {
|
||||
|
@ -698,33 +714,38 @@ impl Ime for ServoIme {
|
|||
|
||||
#[allow(unused)]
|
||||
impl HostTrait for HostCallbacks {
|
||||
fn prompt_alert(&self, msg: String, _trusted: bool) {
|
||||
debug!("prompt_alert: {msg}");
|
||||
match PROMPT_TOAST.get() {
|
||||
Some(prompt_fn) => {
|
||||
let status = prompt_fn.call(msg, ThreadsafeFunctionCallMode::NonBlocking);
|
||||
if status != napi_ohos::Status::Ok {
|
||||
// Queue could be full.
|
||||
error!("prompt_alert failed with {status}");
|
||||
}
|
||||
fn request_permission(&self, _webview: WebView, request: PermissionRequest) {
|
||||
warn!("Permissions prompt not implemented. Denied.");
|
||||
request.deny();
|
||||
}
|
||||
|
||||
fn show_simple_dialog(&self, _webview: WebView, dialog: SimpleDialog) {
|
||||
let _ = match dialog {
|
||||
SimpleDialog::Alert {
|
||||
message,
|
||||
response_sender,
|
||||
} => {
|
||||
debug!("SimpleDialog::Alert");
|
||||
// TODO: Indicate that this message is untrusted, and what origin it came from.
|
||||
self.show_alert(message);
|
||||
response_sender.send(AlertResponse::Ok)
|
||||
},
|
||||
None => error!("PROMPT_TOAST not set. Dropping msg {msg}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_yes_no(&self, msg: String, trusted: bool) -> PromptResult {
|
||||
warn!("Prompt not implemented. Cancelled. {}", msg);
|
||||
PromptResult::Secondary
|
||||
}
|
||||
|
||||
fn prompt_ok_cancel(&self, msg: String, trusted: bool) -> PromptResult {
|
||||
warn!("Prompt not implemented. Cancelled. {}", msg);
|
||||
PromptResult::Secondary
|
||||
}
|
||||
|
||||
fn prompt_input(&self, msg: String, default: String, trusted: bool) -> Option<String> {
|
||||
warn!("Input prompt not implemented. Cancelled. {}", msg);
|
||||
Some(default)
|
||||
SimpleDialog::Confirm {
|
||||
message,
|
||||
response_sender,
|
||||
} => {
|
||||
warn!("Confirm dialog not implemented. Cancelled. {}", message);
|
||||
response_sender.send(Default::default())
|
||||
},
|
||||
SimpleDialog::Prompt {
|
||||
message,
|
||||
response_sender,
|
||||
..
|
||||
} => {
|
||||
warn!("Prompt dialog not implemented. Cancelled. {}", message);
|
||||
response_sender.send(Default::default())
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
fn show_context_menu(&self, title: Option<String>, items: Vec<String>) {
|
||||
|
@ -740,7 +761,7 @@ impl HostTrait for HostCallbacks {
|
|||
if load_status == LoadStatus::Complete {
|
||||
#[cfg(feature = "tracing-hitrace")]
|
||||
let _scope = hitrace::ScopedTrace::start_trace(&c"PageLoadEndedPrompt");
|
||||
self.prompt_alert("Page finished loading!".to_string(), true);
|
||||
self.show_alert("Page finished loading!".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -838,7 +859,7 @@ impl HostTrait for HostCallbacks {
|
|||
if let Some(bt) = backtrace {
|
||||
error!("Backtrace: {bt:?}")
|
||||
}
|
||||
self.prompt_alert("Servo crashed!".to_string(), true);
|
||||
self.prompt_alert(reason, true);
|
||||
self.show_alert("Servo crashed!".to_string());
|
||||
self.show_alert(reason);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue