mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Embedder Prompt API
This commit is contained in:
parent
5f55cd5d71
commit
51f15a055e
17 changed files with 447 additions and 110 deletions
|
@ -106,6 +106,37 @@ impl EmbedderReceiver {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum PromptDefinition {
|
||||
/// Show a message.
|
||||
Alert(String, IpcSender<()>),
|
||||
/// Ask a Ok/Cancel question.
|
||||
OkCancel(String, IpcSender<PromptResult>),
|
||||
/// Ask a Yes/No question.
|
||||
YesNo(String, IpcSender<PromptResult>),
|
||||
/// Ask the user to enter text.
|
||||
Input(String, String, IpcSender<Option<String>>),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, PartialEq, Serialize)]
|
||||
pub enum PromptOrigin {
|
||||
/// Prompt is triggered from content (window.prompt/alert/confirm/…).
|
||||
/// Prompt message is unknown.
|
||||
Untrusted,
|
||||
/// Prompt is triggered from Servo (ask for permission, show error,…).
|
||||
Trusted,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, PartialEq, Serialize)]
|
||||
pub enum PromptResult {
|
||||
/// Prompt was closed by clicking on the primary button (ok/yes)
|
||||
Primary,
|
||||
/// Prompt was closed by clicking on the secondary button (cancel/no)
|
||||
Secondary,
|
||||
/// Prompt was dismissed
|
||||
Dismissed,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum EmbedderMsg {
|
||||
/// A status message to be displayed by the browser chrome.
|
||||
|
@ -116,8 +147,8 @@ pub enum EmbedderMsg {
|
|||
MoveTo(DeviceIntPoint),
|
||||
/// Resize the window to size
|
||||
ResizeTo(DeviceIntSize),
|
||||
// Show an alert message.
|
||||
Alert(String, IpcSender<()>),
|
||||
/// Show dialog to user
|
||||
Prompt(PromptDefinition, PromptOrigin),
|
||||
/// Wether or not to allow a pipeline to load a url.
|
||||
AllowNavigationRequest(PipelineId, ServoUrl),
|
||||
/// Whether or not to allow script to open a new tab/browser
|
||||
|
@ -174,7 +205,7 @@ impl Debug for EmbedderMsg {
|
|||
EmbedderMsg::ChangePageTitle(..) => write!(f, "ChangePageTitle"),
|
||||
EmbedderMsg::MoveTo(..) => write!(f, "MoveTo"),
|
||||
EmbedderMsg::ResizeTo(..) => write!(f, "ResizeTo"),
|
||||
EmbedderMsg::Alert(..) => write!(f, "Alert"),
|
||||
EmbedderMsg::Prompt(..) => write!(f, "Prompt"),
|
||||
EmbedderMsg::AllowUnload(..) => write!(f, "AllowUnload"),
|
||||
EmbedderMsg::AllowNavigationRequest(..) => write!(f, "AllowNavigationRequest"),
|
||||
EmbedderMsg::Keyboard(..) => write!(f, "Keyboard"),
|
||||
|
|
|
@ -55,8 +55,8 @@
|
|||
// user prompts
|
||||
void alert(DOMString message);
|
||||
void alert();
|
||||
//boolean confirm(optional DOMString message = "");
|
||||
//DOMString? prompt(optional DOMString message = "", optional DOMString default = "");
|
||||
boolean confirm(optional DOMString message = "");
|
||||
DOMString? prompt(optional DOMString message = "", optional DOMString default = "");
|
||||
//void print();
|
||||
//any showModalDialog(DOMString url, optional any argument);
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ use crossbeam_channel::{unbounded, Sender, TryRecvError};
|
|||
use cssparser::{Parser, ParserInput, SourceLocation};
|
||||
use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType};
|
||||
use dom_struct::dom_struct;
|
||||
use embedder_traits::{EmbedderMsg, EventLoopWaker};
|
||||
use embedder_traits::{EmbedderMsg, EventLoopWaker, PromptDefinition, PromptOrigin, PromptResult};
|
||||
use euclid::default::{Point2D as UntypedPoint2D, Rect as UntypedRect};
|
||||
use euclid::{Point2D, Rect, Scale, Size2D, Vector2D};
|
||||
use ipc_channel::ipc::{channel, IpcSender};
|
||||
|
@ -620,11 +620,32 @@ impl WindowMethods for Window {
|
|||
}
|
||||
let (sender, receiver) =
|
||||
ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap();
|
||||
let msg = EmbedderMsg::Alert(s.to_string(), sender);
|
||||
let prompt = PromptDefinition::Alert(s.to_string(), sender);
|
||||
let msg = EmbedderMsg::Prompt(prompt, PromptOrigin::Untrusted);
|
||||
self.send_to_embedder(msg);
|
||||
receiver.recv().unwrap();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-confirm
|
||||
fn Confirm(&self, s: DOMString) -> bool {
|
||||
let (sender, receiver) =
|
||||
ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap();
|
||||
let prompt = PromptDefinition::OkCancel(s.to_string(), sender);
|
||||
let msg = EmbedderMsg::Prompt(prompt, PromptOrigin::Untrusted);
|
||||
self.send_to_embedder(msg);
|
||||
receiver.recv().unwrap() == PromptResult::Primary
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-prompt
|
||||
fn Prompt(&self, message: DOMString, default: DOMString) -> Option<DOMString> {
|
||||
let (sender, receiver) =
|
||||
ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap();
|
||||
let prompt = PromptDefinition::Input(message.to_string(), default.to_string(), sender);
|
||||
let msg = EmbedderMsg::Prompt(prompt, PromptOrigin::Untrusted);
|
||||
self.send_to_embedder(msg);
|
||||
receiver.recv().unwrap().map(|s| s.into())
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-window-stop
|
||||
fn Stop(&self) {
|
||||
// TODO: Cancel ongoing navigation.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue