예제 #1
0
        private static bool ExecuteCommandBinding(object sender, ExecutedRoutedEventArgs e, CommandBinding commandBinding)
        {
            // Asserting a permission in the case that the command was user initiated
            // and the command is a secure command. We can do this safely because at
            // the time the binding was setup, we demanded the permission.
            ISecureCommand secureCommand = e.Command as ISecureCommand;
            bool           elevate       = e.UserInitiated && (secureCommand != null) && (secureCommand.UserInitiatedPermission != null);

            if (elevate)
            {
                secureCommand.UserInitiatedPermission.Assert(); //BlessedAssert
            }
            try
            {
                commandBinding.OnExecuted(sender, e);
            }
            finally
            {
                if (elevate)
                {
                    CodeAccessPermission.RevertAssert();
                }
            }

            return(e.Handled);
        }
예제 #2
0
        void CheckSecureCommand(ICommand command, InputGesture gesture)
        {
            // In v3.5, only ApplicationCommands.Paste was treated as ISecureCommand,
            // causing the below demand to fail if a binding for it was created. As
            // there's no provable security vulnerability and for backwards compat
            // reasons, we special-case Cut and Copy not to be subject to this check
            // even though they have been promoted to ISecureCommand in v4.0.
            ISecureCommand secure = command as ISecureCommand;

            if (secure != null &&
                command != ApplicationCommands.Cut &&
                command != ApplicationCommands.Copy)
            {
                secure.UserInitiatedPermission.Demand();
            }
        }
예제 #3
0
        void CheckSecureCommand(ICommand command, InputGesture gesture)
        {
            // In v3.5, only ApplicationCommands.Paste was treated as ISecureCommand,
            // causing the below demand to fail if a binding for it was created. As
            // there's no provable security vulnerability and for backwards compat
            // reasons, we special-case Cut and Copy not to be subject to this check
            // even though they have been promoted to ISecureCommand in v4.0.
            //
            // See Dev10 bug 815844 on reevaluating the threat model around protection
            // of key bindings. The following demand may be unnecessary or misguided.
            ISecureCommand secure = command as ISecureCommand;

            if (secure != null &&
                command != ApplicationCommands.Cut &&
                command != ApplicationCommands.Copy)
            {
                secure.UserInitiatedPermission.Demand();
            }
        }