diff --git a/core/src/avm1/globals.rs b/core/src/avm1/globals.rs index 7e65d2847..9c9880235 100644 --- a/core/src/avm1/globals.rs +++ b/core/src/avm1/globals.rs @@ -28,11 +28,11 @@ mod rectangle; mod sound; mod stage; pub(crate) mod string; -pub(crate) mod system_capabilities; pub(crate) mod system; -pub(crate) mod text_field; +pub(crate) mod system_capabilities; pub(crate) mod system_ime; pub(crate) mod system_security; +pub(crate) mod text_field; mod text_format; mod xml; @@ -317,11 +317,24 @@ pub fn create_globals<'gc>( globals.define_value(gc_context, "Number", number.into(), EnumSet::empty()); globals.define_value(gc_context, "Boolean", boolean.into(), EnumSet::empty()); - let system_security = system_security::create(gc_context, Some(object_proto), Some(function_proto)); + let system_security = + system_security::create(gc_context, Some(object_proto), Some(function_proto)); let system_capabilities = system_capabilities::create(gc_context, Some(object_proto)); - let system_ime = system_ime::create(gc_context, Some(object_proto), Some(function_proto), &listeners.ime); + let system_ime = system_ime::create( + gc_context, + Some(object_proto), + Some(function_proto), + &listeners.ime, + ); - let system = system::create(gc_context, Some(object_proto), Some(function_proto), system_security, system_capabilities, system_ime); + let system = system::create( + gc_context, + Some(object_proto), + Some(function_proto), + system_security, + system_capabilities, + system_ime, + ); globals.define_value(gc_context, "System", system.into(), EnumSet::empty()); globals.define_value( diff --git a/core/src/avm1/globals/system.rs b/core/src/avm1/globals/system.rs index 5378c8740..c27248493 100644 --- a/core/src/avm1/globals/system.rs +++ b/core/src/avm1/globals/system.rs @@ -1,20 +1,20 @@ +use crate::avm1::function::Executable; use crate::avm1::object::Object; use crate::avm1::property::Attribute::{DontDelete, DontEnum, ReadOnly}; use crate::avm1::return_value::ReturnValue; use crate::avm1::{Avm1, Error, ScriptObject, TObject, Value}; use crate::context::UpdateContext; +use enumset::{EnumSet, EnumSetType}; use gc_arena::MutationContext; use num_enum::TryFromPrimitive; use std::convert::TryFrom; -use crate::avm1::function::Executable; -use enumset::{EnumSet, EnumSetType}; /// Available type of sandbox for a given SWF pub enum SandboxType { Remote, LocalWithFile, LocalWithNetwork, - LocalTrusted + LocalTrusted, } impl SandboxType { @@ -37,7 +37,7 @@ pub enum OperatingSystem { Windows95, WindowsCE, Linux, - MacOS + MacOS, } impl OperatingSystem { @@ -84,7 +84,7 @@ impl Manufacturer { Manufacturer::Windows => "WIN", Manufacturer::Macintosh => "MAC", Manufacturer::Linux => "LNX", - _ => "" + _ => "", } } } @@ -111,12 +111,12 @@ pub enum Language { Spanish, Swedish, TraditionalChinese, - Turkish + Turkish, } impl Language { pub fn get_language_code(&self, player_version: u8) -> &str { - return match self { + match self { Language::Czech => "cs", Language::Danish => "da", Language::Dutch => "nl", @@ -143,7 +143,7 @@ impl Language { Language::Spanish => "es", Language::Swedish => "sv", Language::TraditionalChinese => "zh-TW", - Language::Turkish => "tr" + Language::Turkish => "tr", } } } @@ -157,7 +157,7 @@ pub enum ScreenColor { impl ScreenColor { pub fn get_color_code(&self) -> &str { - return match self { + match self { ScreenColor::Color => "color", ScreenColor::Gray => "gray", ScreenColor::BlackWhite => "bw", @@ -175,7 +175,7 @@ pub enum PlayerType { impl PlayerType { pub fn get_player_name(&self) -> &str { - return match self { + match self { PlayerType::StandAlone => "StandAlone", PlayerType::External => "External", PlayerType::PlugIn => "PlugIn", @@ -244,7 +244,11 @@ pub struct SystemProperties { impl SystemProperties { pub fn get_version_string(&self, avm: &Avm1) -> String { - format!("{} {},0,0,0", self.manufacturer.get_platform_name(), avm.player_version) + format!( + "{} {},0,0,0", + self.manufacturer.get_platform_name(), + avm.player_version + ) } pub fn has_capability(&self, cap: SystemCapabilities) -> bool { @@ -258,14 +262,14 @@ impl SystemProperties { fn encode_capability(&self, cap: SystemCapabilities) -> &str { match self.has_capability(cap) { true => "t", - false => "f" + false => "f", } } fn encode_not_capability(&self, cap: SystemCapabilities) -> &str { match self.has_capability(cap) { true => "t", - false => "f" + false => "f", } } @@ -274,30 +278,69 @@ impl SystemProperties { } pub fn get_server_string(&self, avm: &Avm1) -> String { - url::form_urlencoded::Serializer::new(String::new()) .append_pair("A", self.encode_capability(SystemCapabilities::Audio)) - .append_pair("SA", self.encode_capability(SystemCapabilities::StreamingAudio)) - .append_pair("SV", self.encode_capability(SystemCapabilities::StreamingVideo)) - .append_pair("EV", self.encode_capability(SystemCapabilities::EmbeddedVideo)) + .append_pair( + "SA", + self.encode_capability(SystemCapabilities::StreamingAudio), + ) + .append_pair( + "SV", + self.encode_capability(SystemCapabilities::StreamingVideo), + ) + .append_pair( + "EV", + self.encode_capability(SystemCapabilities::EmbeddedVideo), + ) .append_pair("MP3", self.encode_capability(SystemCapabilities::MP3)) - .append_pair("AE", self.encode_capability(SystemCapabilities::AudioEncoder)) - .append_pair("VE", self.encode_capability(SystemCapabilities::VideoEncoder)) - .append_pair("ACC", self.encode_not_capability(SystemCapabilities::Accessibility)) + .append_pair( + "AE", + self.encode_capability(SystemCapabilities::AudioEncoder), + ) + .append_pair( + "VE", + self.encode_capability(SystemCapabilities::VideoEncoder), + ) + .append_pair( + "ACC", + self.encode_not_capability(SystemCapabilities::Accessibility), + ) .append_pair("PR", self.encode_capability(SystemCapabilities::Printing)) - .append_pair("SP", self.encode_capability(SystemCapabilities::ScreenPlayback)) - .append_pair("SB", self.encode_capability(SystemCapabilities::ScreenBroadcast)) + .append_pair( + "SP", + self.encode_capability(SystemCapabilities::ScreenPlayback), + ) + .append_pair( + "SB", + self.encode_capability(SystemCapabilities::ScreenBroadcast), + ) .append_pair("DEB", self.encode_capability(SystemCapabilities::Debugger)) - .append_pair("M", &self.encode_string(self.manufacturer.get_manufacturer_string(avm.player_version).as_str())) - .append_pair("R", &format!("{}x{}", self.screen_resolution.0, self.screen_resolution.1)) + .append_pair( + "M", + &self.encode_string( + self.manufacturer + .get_manufacturer_string(avm.player_version) + .as_str(), + ), + ) + .append_pair( + "R", + &format!("{}x{}", self.screen_resolution.0, self.screen_resolution.1), + ) .append_pair("COL", self.screen_color.get_color_code()) .append_pair("AR", &self.aspect_ratio.to_string()) .append_pair("OS", &self.encode_string(self.os.get_os_name())) .append_pair("L", self.language.get_language_code(avm.player_version)) .append_pair("IME", self.encode_capability(SystemCapabilities::IME)) .append_pair("PT", self.player_type.get_player_name()) - .append_pair("AVD", self.encode_not_capability(SystemCapabilities::AvHardware)) - .append_pair("LFD", self.encode_not_capability(SystemCapabilities::LocalFileRead)) + .append_pair( + "AVD", + self.encode_not_capability(SystemCapabilities::AvHardware), + ) + .append_pair( + "LFD", + self.encode_not_capability(SystemCapabilities::LocalFileRead), + ) .append_pair("DP", &self.dpi.to_string()) .finish() } @@ -316,8 +359,8 @@ impl Default for SystemProperties { // TODO: note for fp <7 this should be the locale and the ui lang for >= 7, on windows language: Language::English, screen_resolution: (0, 0), - aspect_ratio: 1 as f32, - dpi: 1 as f32, + aspect_ratio: 1_f32, + dpi: 1_f32, manufacturer: Manufacturer::Linux, os: OperatingSystem::Linux, sandbox_type: SandboxType::LocalTrusted, @@ -431,7 +474,7 @@ pub fn create<'gc>( fn_proto: Option>, security: Object<'gc>, capabilities: Object<'gc>, - ime: Object<'gc> + ime: Object<'gc>, ) -> Object<'gc> { let mut system = ScriptObject::object(gc_context, proto); @@ -443,7 +486,6 @@ pub fn create<'gc>( DontDelete | DontEnum, ); - system.add_property( gc_context, "useCodepage", diff --git a/core/src/avm1/globals/system_capabilities.rs b/core/src/avm1/globals/system_capabilities.rs index aa01f9ce1..e4d00e6e5 100644 --- a/core/src/avm1/globals/system_capabilities.rs +++ b/core/src/avm1/globals/system_capabilities.rs @@ -1,11 +1,11 @@ +use crate::avm1::function::Executable; +use crate::avm1::globals::system::SystemCapabilities; use crate::avm1::object::Object; use crate::avm1::property::Attribute::{DontDelete, DontEnum, ReadOnly}; -use crate::avm1::{ScriptObject, TObject, Avm1, Value, Error}; -use gc_arena::MutationContext; -use crate::context::UpdateContext; use crate::avm1::return_value::ReturnValue; -use crate::avm1::globals::system::SystemCapabilities; -use crate::avm1::function::Executable; +use crate::avm1::{Avm1, Error, ScriptObject, TObject, Value}; +use crate::context::UpdateContext; +use gc_arena::MutationContext; macro_rules! capabilities_func { ($func_name: ident, $capability: expr) => { @@ -55,16 +55,21 @@ capabilities_func!(get_has_embedded_video, SystemCapabilities::EmbeddedVideo); capabilities_func!(get_has_ime, SystemCapabilities::IME); capabilities_func!(get_has_mp3, SystemCapabilities::MP3); capabilities_func!(get_has_printing, SystemCapabilities::Printing); -capabilities_func!(get_has_screen_broadcast, SystemCapabilities::ScreenBroadcast); +capabilities_func!( + get_has_screen_broadcast, + SystemCapabilities::ScreenBroadcast +); capabilities_func!(get_has_screen_playback, SystemCapabilities::ScreenPlayback); capabilities_func!(get_has_streaming_audio, SystemCapabilities::StreamingAudio); capabilities_func!(get_has_streaming_video, SystemCapabilities::StreamingVideo); capabilities_func!(get_has_video_encoder, SystemCapabilities::VideoEncoder); capabilities_func!(get_is_debugger, SystemCapabilities::Debugger); -inverse_capabilities_func!(get_is_local_file_read_disabled, SystemCapabilities::LocalFileRead); +inverse_capabilities_func!( + get_is_local_file_read_disabled, + SystemCapabilities::LocalFileRead +); inverse_capabilities_func!(get_is_av_hardware_disabled, SystemCapabilities::AvHardware); - pub fn get_player_type<'gc>( _avm: &mut Avm1<'gc>, context: &mut UpdateContext<'_, 'gc, '_>, @@ -89,7 +94,11 @@ pub fn get_language<'gc>( _this: Object<'gc>, _args: &[Value<'gc>], ) -> Result, Error> { - Ok(context.system.language.get_language_code(avm.player_version).into()) + Ok(context + .system + .language + .get_language_code(avm.player_version) + .into()) } pub fn get_screen_resolution_x<'gc>( @@ -134,7 +143,11 @@ pub fn get_manufacturer<'gc>( _this: Object<'gc>, _args: &[Value<'gc>], ) -> Result, Error> { - Ok(context.system.manufacturer.get_manufacturer_string(avm.player_version).into()) + Ok(context + .system + .manufacturer + .get_manufacturer_string(avm.player_version) + .into()) } pub fn get_os_name<'gc>( @@ -164,7 +177,6 @@ pub fn get_server_string<'gc>( Ok(context.system.get_server_string(avm).into()) } - pub fn create<'gc>( gc_context: MutationContext<'gc, '_>, proto: Option>, diff --git a/core/src/avm1/globals/system_ime.rs b/core/src/avm1/globals/system_ime.rs index 456dc5ca7..2914d353c 100644 --- a/core/src/avm1/globals/system_ime.rs +++ b/core/src/avm1/globals/system_ime.rs @@ -1,12 +1,12 @@ +use crate::avm1::listeners::Listeners; use crate::avm1::object::Object; +use crate::avm1::property::Attribute; use crate::avm1::property::Attribute::{DontDelete, DontEnum, ReadOnly}; -use crate::avm1::{ScriptObject, TObject, Avm1, Value, Error}; +use crate::avm1::return_value::ReturnValue; +use crate::avm1::{Avm1, Error, ScriptObject, TObject, Value}; +use crate::context::UpdateContext; use gc_arena::MutationContext; use std::convert::Into; -use crate::context::UpdateContext; -use crate::avm1::return_value::ReturnValue; -use crate::avm1::property::Attribute; -use crate::avm1::listeners::Listeners; fn on_ime_composition<'gc>( _avm: &mut Avm1<'gc>, @@ -135,7 +135,7 @@ pub fn create<'gc>( on_ime_composition, gc_context, DontDelete | DontEnum, - fn_proto + fn_proto, ); ime.force_set_function( @@ -143,16 +143,15 @@ pub fn create<'gc>( do_conversion, gc_context, DontDelete | DontEnum, - fn_proto + fn_proto, ); - ime.force_set_function( "getConversionMode", get_conversion_mode, gc_context, DontDelete | DontEnum, - fn_proto + fn_proto, ); ime.force_set_function( @@ -160,7 +159,7 @@ pub fn create<'gc>( get_enabled, gc_context, DontDelete | DontEnum, - fn_proto + fn_proto, ); ime.force_set_function( @@ -168,7 +167,7 @@ pub fn create<'gc>( set_composition_string, gc_context, DontDelete | DontEnum, - fn_proto + fn_proto, ); ime.force_set_function( @@ -176,7 +175,7 @@ pub fn create<'gc>( set_conversion_mode, gc_context, DontDelete | DontEnum, - fn_proto + fn_proto, ); ime.force_set_function( @@ -184,7 +183,7 @@ pub fn create<'gc>( set_enabled, gc_context, DontDelete | DontEnum, - fn_proto + fn_proto, ); ime.into() diff --git a/core/src/avm1/globals/system_security.rs b/core/src/avm1/globals/system_security.rs index 5c7f8d91a..497b1929a 100644 --- a/core/src/avm1/globals/system_security.rs +++ b/core/src/avm1/globals/system_security.rs @@ -1,11 +1,11 @@ +use crate::avm1::function::Executable; use crate::avm1::object::Object; use crate::avm1::property::Attribute::{DontDelete, DontEnum, ReadOnly}; -use crate::avm1::{ScriptObject, TObject, Avm1, Value, Error}; +use crate::avm1::return_value::ReturnValue; +use crate::avm1::{Avm1, Error, ScriptObject, TObject, Value}; +use crate::context::UpdateContext; use gc_arena::MutationContext; use std::convert::Into; -use crate::context::UpdateContext; -use crate::avm1::return_value::ReturnValue; -use crate::avm1::function::Executable; fn allow_domain<'gc>( _avm: &mut Avm1<'gc>, @@ -46,7 +46,6 @@ fn get_sandbox_type<'gc>( Ok(context.system.sandbox_type.get_sandbox_name().into()) } - pub fn create<'gc>( gc_context: MutationContext<'gc, '_>, proto: Option>, @@ -59,7 +58,7 @@ pub fn create<'gc>( allow_domain, gc_context, DontDelete | ReadOnly | DontEnum, - fn_proto + fn_proto, ); security.force_set_function( @@ -67,7 +66,7 @@ pub fn create<'gc>( allow_insecure_domain, gc_context, DontDelete | ReadOnly | DontEnum, - fn_proto + fn_proto, ); security.force_set_function( @@ -75,7 +74,7 @@ pub fn create<'gc>( load_policy_file, gc_context, DontDelete | ReadOnly | DontEnum, - fn_proto + fn_proto, ); security.add_property( diff --git a/core/src/avm1/listeners.rs b/core/src/avm1/listeners.rs index f3872cecc..6d50965b5 100644 --- a/core/src/avm1/listeners.rs +++ b/core/src/avm1/listeners.rs @@ -136,7 +136,7 @@ impl<'gc> Listeners<'gc> { #[derive(Clone, Debug, PartialEq, Eq)] pub enum SystemListener { Mouse, - Ime + Ime, } #[derive(Clone, Collect, Debug, Copy)] diff --git a/core/src/avm1/script_object.rs b/core/src/avm1/script_object.rs index c631f5280..999414566 100644 --- a/core/src/avm1/script_object.rs +++ b/core/src/avm1/script_object.rs @@ -718,6 +718,7 @@ mod tests { use rand::{rngs::SmallRng, SeedableRng}; use std::collections::BTreeMap; use std::sync::Arc; + use crate::avm1::globals::system::SystemProperties; fn with_object(swf_version: u8, test: F) -> R where @@ -758,6 +759,7 @@ mod tests { stage_size: (Twips::from_pixels(550.0), Twips::from_pixels(400.0)), player: None, load_manager: &mut LoadManager::new(), + system: &mut SystemProperties::default(), }; root.post_instantiation(&mut avm, &mut context, root, None); diff --git a/core/src/avm1/test_utils.rs b/core/src/avm1/test_utils.rs index 2b56aeae1..af0bc75e7 100644 --- a/core/src/avm1/test_utils.rs +++ b/core/src/avm1/test_utils.rs @@ -14,6 +14,7 @@ use gc_arena::{rootless_arena, GcCell, MutationContext}; use rand::{rngs::SmallRng, SeedableRng}; use std::collections::BTreeMap; use std::sync::Arc; +use crate::avm1::globals::system::SystemProperties; pub fn with_avm(swf_version: u8, test: F) -> R where @@ -57,6 +58,7 @@ where stage_size: (Twips::from_pixels(550.0), Twips::from_pixels(400.0)), player: None, load_manager: &mut LoadManager::new(), + system: &mut SystemProperties::default(), }; root.post_instantiation(&mut avm, &mut context, root, None); diff --git a/core/src/backend/input.rs b/core/src/backend/input.rs index 15e9255de..dade32d55 100644 --- a/core/src/backend/input.rs +++ b/core/src/backend/input.rs @@ -17,9 +17,6 @@ pub trait InputBackend: Downcast { /// Set the clipboard to the given content fn set_clipboard_content(&mut self, content: String); - - /// Empty the clipboard - fn clear_clipboard(&mut self); } impl_downcast!(InputBackend); @@ -52,8 +49,6 @@ impl InputBackend for NullInputBackend { fn set_mouse_cursor(&mut self, _cursor: MouseCursor) {} fn set_clipboard_content(&mut self, _content: String) {} - - fn clear_clipboard(&mut self) {} } impl Default for NullInputBackend { diff --git a/core/src/context.rs b/core/src/context.rs index b5e3fd0f5..2893c93cc 100644 --- a/core/src/context.rs +++ b/core/src/context.rs @@ -1,6 +1,7 @@ //! Contexts and helper types passed between functions. use crate::avm1; +use crate::avm1::globals::system::SystemProperties; use crate::avm1::listeners::SystemListener; use crate::avm1::{Object, Value}; use crate::backend::input::InputBackend; @@ -17,7 +18,6 @@ use rand::rngs::SmallRng; use std::collections::BTreeMap; use std::collections::VecDeque; use std::sync::{Arc, Mutex, Weak}; -use crate::avm1::globals::system::SystemProperties; /// `UpdateContext` holds shared data that is used by the various subsystems of Ruffle. /// `Player` crates this when it begins a tick and passes it through the call stack to diff --git a/core/src/player.rs b/core/src/player.rs index a7c1d1b05..5aac2f65a 100644 --- a/core/src/player.rs +++ b/core/src/player.rs @@ -1,4 +1,5 @@ use crate::avm1::debug::VariableDumper; +use crate::avm1::globals::system::SystemProperties; use crate::avm1::listeners::SystemListener; use crate::avm1::{Activation, Avm1, TObject, Value}; use crate::backend::input::{InputBackend, MouseCursor}; @@ -20,8 +21,6 @@ use std::collections::BTreeMap; use std::convert::TryFrom; use std::ops::DerefMut; use std::sync::{Arc, Mutex, Weak}; -use crate::avm1::globals::system::SystemProperties; - static DEVICE_FONT_TAG: &[u8] = include_bytes!("../assets/noto-sans-definefont3.bin"); @@ -237,7 +236,7 @@ impl Player { navigator, input, self_reference: None, - system: SystemProperties::default() + system: SystemProperties::default(), }; player.mutate_with_update_context(|avm, context| { @@ -881,7 +880,7 @@ impl Player { system_prototypes: avm.prototypes().clone(), player, load_manager, - system: system_properties + system: system_properties, }; let ret = f(avm, &mut update_context);