1. A method for use at a computer system, the computer system including a processor and system memory, the method for enforcing a policy for an application, the method comprising: receiving user input selecting an amended application for execution, the amended application including an embedded target application, the embedded target application embedded within the amended application; accessing a policy file specified for the embedded target application, the policy file including one or more policy elements, the one or more policy elements defining one or more management conditions that are to apply to the embedded target application; configuring the amended application to monitor the embedded target application's use of one or more Application Program Interfaces (APIs) relevant to the defined one or more management conditions; executing the embedded target application subsequent to configuring the amended application to monitor the one or more APIs; during execution of the embedded target application, detecting an API request from the embedded target application to an API from among the one or more APIs, the API for performing an activity related to a management condition from among the defined one or more management conditions; gathering additional context associated with performing the activity; tracking visual state of the embedded target application by storing visual state data for the embedded target application; and adjusting behavior of the embedded target application so that the activity complies with the management condition based on the gathered additional context, including: determining that the amended application is to present a custom user interface; switching visual context to the amended application; the amended application injecting the custom user interface into the embedded target application; receiving user input at the custom user interface; switching visual context to the embedded target application subsequent to receiving the user input; and restoring the visual state data for the embedded target application based on the stored visual state data.