From eb1b4745288402d7be12f5e379f0671f622c0f57 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Mon, 2 Sep 2019 21:49:36 -0400 Subject: [PATCH] Propagate AVM locals to `NavigationBackend`. --- core/src/avm1.rs | 26 +++++++++++++++++++++++--- core/src/backend/navigator.rs | 12 ++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/core/src/avm1.rs b/core/src/avm1.rs index 61457d334..4bc8e1891 100644 --- a/core/src/avm1.rs +++ b/core/src/avm1.rs @@ -1,5 +1,6 @@ use crate::avm1::globals::create_globals; use crate::avm1::object::Object; +use crate::backend::navigator::NavigationMethod; use crate::prelude::*; use gc_arena::{GcCell, MutationContext}; @@ -56,6 +57,20 @@ impl<'gc> Avm1<'gc> { } } + /// Convert the current locals pool into a set of form values. + /// + /// This is necessary to support form submission from Flash via a couple of + /// legacy methods, such as the `ActionGetURL2` opcode or `getURL` function. + pub fn locals_into_form_values(&self) -> HashMap { + let mut form_values = HashMap::new(); + + for (k, v) in self.locals.iter() { + form_values.insert(k.clone(), v.clone().into_string()); + } + + form_values + } + pub fn do_action( &mut self, context: &mut ActionContext<'_, 'gc, '_>, @@ -622,7 +637,7 @@ impl<'gc> Avm1<'gc> { fn action_get_url_2( &mut self, context: &mut ActionContext, - _method: swf::avm1::types::SendVarsMethod, + swf_method: swf::avm1::types::SendVarsMethod, is_target_sprite: bool, is_load_vars: bool, ) -> Result<(), Error> { @@ -637,11 +652,16 @@ impl<'gc> Avm1<'gc> { } if is_load_vars { - log::warn!("Loading AVM locals into forms is not yet implemented"); + log::warn!("Reading AVM locals from forms is not yet implemented"); return Ok(()); //maybe error? } - context.navigator.navigate_to_url(url, Some(target), None); + let vars = match NavigationMethod::from_send_vars_method(swf_method) { + Some(method) => Some((method, self.locals_into_form_values())), + None => None + }; + + context.navigator.navigate_to_url(url, Some(target), vars); Ok(()) } diff --git a/core/src/backend/navigator.rs b/core/src/backend/navigator.rs index 731cb9a2a..035c858d0 100644 --- a/core/src/backend/navigator.rs +++ b/core/src/backend/navigator.rs @@ -1,6 +1,7 @@ //! Browser-related platform functions use std::collections::HashMap; +use swf::avm1::types::SendVarsMethod; /// Enumerates all possible navigation methods. pub enum NavigationMethod { @@ -11,6 +12,17 @@ pub enum NavigationMethod { POST } +impl NavigationMethod { + /// Convert an SWF method enum into a NavigationMethod. + pub fn from_send_vars_method(s: SendVarsMethod) -> Option { + match s { + SendVarsMethod::None => None, + SendVarsMethod::Get => Some(Self::GET), + SendVarsMethod::Post => Some(Self::POST), + } + } +} + /// A backend interacting with a browser environment. pub trait NavigatorBackend { /// Cause a browser navigation to a given URL.