Skip to content

Commit 20c9a3d

Browse files
authored
AVM2: Implement System.setClipboard (#8751)
* avm2: Implement System.setClipboard * web: Add comment to set_clipboard_content
1 parent 02360b2 commit 20c9a3d

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

core/src/avm2/globals/flash/system.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
pub mod application_domain;
55
pub mod security;
6+
pub mod system;

core/src/avm2/globals/flash/system/System.as

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ package flash.system {
33
public static function gc(): void {
44

55
}
6+
7+
public static native function setClipboard(string:String): void;
68
}
79
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! `flash.system.System` native methods
2+
3+
use crate::avm2::activation::Activation;
4+
use crate::avm2::object::Object;
5+
use crate::avm2::value::Value;
6+
use crate::avm2::Error;
7+
8+
/// Implements `flash.system.System.setClipboard` method
9+
pub fn set_clipboard<'gc>(
10+
activation: &mut Activation<'_, 'gc, '_>,
11+
_this: Option<Object<'gc>>,
12+
args: &[Value<'gc>],
13+
) -> Result<Value<'gc>, Error<'gc>> {
14+
//TODO: in FP9+ this function only works when called from a button handler in the Plugin due to
15+
// sandbox restrictions
16+
let new_content = args
17+
.get(0)
18+
.unwrap_or(&Value::Undefined)
19+
.coerce_to_string(activation)?
20+
.to_string();
21+
22+
activation.context.ui.set_clipboard_content(new_content);
23+
24+
Ok(Value::Undefined)
25+
}

web/src/ui.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ impl UiBackend for WebUiBackend {
5656
}
5757

5858
fn set_clipboard_content(&mut self, _content: String) {
59+
//TODO: in AVM2 FP9+ this only works when called from a button handler due to sandbox
60+
// restrictions
5961
log::warn!("set clipboard not implemented");
6062
}
6163

0 commit comments

Comments
 (0)