Forward to embedder message for setting/getting clipboard contents from clipboard provider.

Create clipboard context in browser.rs and handle new messages.
This commit is contained in:
Michal Mieczkowski 2019-06-13 20:17:49 +02:00
parent 1e5103e675
commit f4d972adb2
5 changed files with 47 additions and 2 deletions

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use embedder_traits::EmbedderMsg;
use ipc_channel::ipc::channel;
use script_traits::{ScriptMsg, ScriptToConstellationChan};
use std::borrow::ToOwned;
@ -16,11 +17,17 @@ pub trait ClipboardProvider {
impl ClipboardProvider for ScriptToConstellationChan {
fn clipboard_contents(&mut self) -> String {
let (tx, rx) = channel().unwrap();
self.send(ScriptMsg::GetClipboardContents(tx)).unwrap();
self.send(ScriptMsg::ForwardToEmbedder(
EmbedderMsg::GetClipboardContents(tx),
))
.unwrap();
rx.recv().unwrap()
}
fn set_clipboard_contents(&mut self, s: String) {
self.send(ScriptMsg::SetClipboardContents(s)).unwrap();
self.send(ScriptMsg::ForwardToEmbedder(
EmbedderMsg::SetClipboardContents(s),
))
.unwrap();
}
}