script/
clipboard_provider.rsuse base::id::WebViewId;
use constellation_traits::{ScriptToConstellationChan, ScriptToConstellationMessage};
use embedder_traits::EmbedderMsg;
use ipc_channel::ipc::channel;
pub trait ClipboardProvider {
fn get_text(&mut self) -> Result<String, String>;
fn set_text(&mut self, _: String);
}
pub(crate) struct EmbedderClipboardProvider {
pub constellation_sender: ScriptToConstellationChan,
pub webview_id: WebViewId,
}
impl ClipboardProvider for EmbedderClipboardProvider {
fn get_text(&mut self) -> Result<String, String> {
let (tx, rx) = channel().unwrap();
self.constellation_sender
.send(ScriptToConstellationMessage::ForwardToEmbedder(
EmbedderMsg::GetClipboardText(self.webview_id, tx),
))
.unwrap();
rx.recv().unwrap()
}
fn set_text(&mut self, s: String) {
self.constellation_sender
.send(ScriptToConstellationMessage::ForwardToEmbedder(
EmbedderMsg::SetClipboardText(self.webview_id, s),
))
.unwrap();
}
}