Files
servo/components/script/clipboard_provider.rs
Euclid Ye cae0752676 cargo: Rename workspace-local library starting with b to servo_* (#43552)
Follow up of #43526. This addresses Nico's comment:
https://github.com/servo/servo/pull/43526#issuecomment-4104953308

- `bluetooth_traits` -> `servo_bluetooth_traits`
- `base` -> `servo_base`
- `bluetooth` -> `servo_bluetooth`
- `background_hang_monitor` -> `servo_background_hang_monitor`

Testing: This should not change any behaviour.

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2026-03-23 08:26:49 +00:00

39 lines
1.4 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* 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, ScriptToEmbedderChan};
use malloc_size_of_derive::MallocSizeOf;
use servo_base::generic_channel::GenericCallback;
use servo_base::id::WebViewId;
/// A trait which abstracts access to the embedder's clipboard in order to allow unit
/// testing clipboard-dependent parts of `script`.
pub trait ClipboardProvider {
/// Get the text content of the clipboard.
fn get_text(&mut self) -> Result<String, String>;
/// Set the text content of the clipboard.
fn set_text(&mut self, _: String);
}
#[derive(MallocSizeOf)]
pub(crate) struct EmbedderClipboardProvider {
pub embedder_sender: ScriptToEmbedderChan,
pub webview_id: WebViewId,
}
impl ClipboardProvider for EmbedderClipboardProvider {
fn get_text(&mut self) -> Result<String, String> {
let (callback, rx) = GenericCallback::new_blocking().unwrap();
self.embedder_sender
.send(EmbedderMsg::GetClipboardText(self.webview_id, callback))
.unwrap();
rx.recv().unwrap()
}
fn set_text(&mut self, s: String) {
self.embedder_sender
.send(EmbedderMsg::SetClipboardText(self.webview_id, s))
.unwrap();
}
}