Skip to content

Remove Critical/Unsecure property/method proxies and CAS-related code #10701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1419531
Swap Hashtable for a Dictionary<IInputProvider, InputProviderSite>
h3xds1nz Oct 11, 2024
46667df
Remove UnsecureInputProviders and replace with InputProviders
h3xds1nz Oct 11, 2024
c909281
Remove UnsecureCurrent and replace uses with Current property
h3xds1nz Oct 11, 2024
d80e59b
UnsecureInputManager -> InputManager
h3xds1nz Apr 3, 2025
3371ba5
CriticalFromHwnd -> FromHwnd
h3xds1nz Apr 3, 2025
ebda003
CriticalActiveSource -> ActiveSource
h3xds1nz Apr 3, 2025
ee47dfa
Stylus CriticalActiveSource -> ActiveSource
h3xds1nz Apr 3, 2025
f26d886
comments in pen
h3xds1nz Apr 3, 2025
7962dc6
CriticalCreate -> Create
h3xds1nz Apr 3, 2025
584ab3f
HwndSourceKeyboardInputSite removal of CriticalUnregister
h3xds1nz Apr 3, 2025
149ec89
CriticalHandleWMGetobject -> HandleWM_GETOBJECT
h3xds1nz Apr 3, 2025
56373eb
CriticalCreateBitmapSourceFromHBitmap -> CreateBitmapSourceFromHBitmap
h3xds1nz Apr 3, 2025
638ec51
CriticalCopyPixels -> CopyPixelsEx/Impl
h3xds1nz Apr 3, 2025
51a5214
CriticalItemName -> ItemName
h3xds1nz Apr 3, 2025
0b5e2dc
CriticalOpenFile -> remove
h3xds1nz Apr 3, 2025
426ed34
CriticalExecuteCommandSource -> ExecuteCommandSource
h3xds1nz Apr 3, 2025
4a62897
CriticalShutdown -> Shutdown
h3xds1nz Apr 3, 2025
12dc6f4
CriticalSourceWnd -> GetSourceWindowHandle()
h3xds1nz Apr 3, 2025
208f07a
Remove remarks in WinRTSpellerInterop
h3xds1nz Apr 3, 2025
5bfa814
some comments removal
h3xds1nz Apr 3, 2025
97dab12
CriticalAttach -> AttachWndProcHook
h3xds1nz Apr 3, 2025
7cad1d5
DetachCritical -> DetachWndProcHook
h3xds1nz Apr 3, 2025
3c66d0c
Remove DemandIfUntrusted
h3xds1nz Apr 3, 2025
f41302b
No, ProcessInput does not have demand
h3xds1nz Apr 3, 2025
2c3d5ec
ActiveSource also doesn't do security demand
h3xds1nz Apr 3, 2025
317b7b7
CriticalRecognize -> Recognize
h3xds1nz Apr 3, 2025
87d3b03
more comments removals
h3xds1nz Apr 3, 2025
8082318
CriticalInvokeShutdown-> InvokeShutdown
h3xds1nz Apr 3, 2025
e8752b7
CriticalRequestProcessing -> RequestProcessing
h3xds1nz Apr 3, 2025
eaf9bfa
CriticalCreate -> Create
h3xds1nz Apr 3, 2025
c5be8c7
comments removal only
h3xds1nz Apr 3, 2025
998c4d2
CriticalFromVisual -> FromVisual
h3xds1nz Apr 3, 2025
606ad68
last comments
h3xds1nz Apr 3, 2025
de07f76
Remove _inTrustedSubWindow because it is always false
h3xds1nz Apr 3, 2025
bf55d85
Fix casts and bad squash of CriticalFromVisual -> FromVisual
h3xds1nz Apr 3, 2025
fe51e42
Add FromNullableVisual to avoid checks on every call site
h3xds1nz Apr 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ internal static Rect GetScreenRect( IntPtr hwnd, UIElement el )
// Get element at given point (screen coords)
internal static Visual GetElementFromPoint( IntPtr hwnd, Visual root, Point pointScreen )
{
HwndSource hwndSource = HwndSource.CriticalFromHwnd(hwnd);
HwndSource hwndSource = HwndSource.FromHwnd(hwnd);

if(hwndSource == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static bool ShouldShow(DependencyObject focusedObject)
/// <returns>The HwndSource associated with the Visual</returns>
private static HwndSource GetHwndSource(DependencyObject focusedObject)
{
return PresentationSource.CriticalFromVisual(focusedObject) as HwndSource;
return PresentationSource.FromVisual(focusedObject) as HwndSource;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,6 @@ private static void CompileFeatureSet(
}
}

/// <SecurityNotes>
/// Critical - This method reads into unsafe cluster map.
/// </SecurityNotes>
private static void GetNextEnabledGlyphRange(
Feature[] FeatureSet, // In: List of features to apply
int featureCount, // In: Actual nubmer of features in FeatureSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
namespace MS.Internal
{
/// <summary>
/// Helper class for handling all web requests/responses in the framework. Using it ensures consisent handling
/// Helper class for handling all web requests/responses in the framework. Using it ensures consistent handling
/// and support for special features: cookies, NTLM authentication, caching, inferring MIME type from filename.
///
/// Only two methods are mandatory:
/// - CreateRequest. (PackWebRequestFactory.CreateWebRequest is an allowed alternative. It delegates to
/// this CreateRequest for non-pack URIs.)
/// - HandleWebResponse.
/// The remaining methods just automate the entire request process, up to the point of getting the response
/// stream. Using the SecurityTreatAsSafe ones helps avoid making other code SecurityCritical.
/// The remaining methods just automate the entire request process, up to the point of getting the response stream.
///
/// Related types:
/// - BaseUriHelper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ static PackageStore()
/// </summary>
/// <param name="uri">key uri</param>
/// <returns>Package</returns>
/// <permission cref="EnvironmentPermission"></permission>
/// <remarks>
/// </remarks>
public static Package GetPackage(Uri uri)
Expand All @@ -71,7 +70,6 @@ public static Package GetPackage(Uri uri)
/// </summary>
/// <param name="uri">key uri</param>
/// <param name="package">package</param>
/// <permission cref="EnvironmentPermission"></permission>
/// <remarks>
/// If a package with the uri is already in the store,it throws an exception.
/// The package will not be automatically replaced within the store.
Expand Down Expand Up @@ -117,7 +115,6 @@ public static void AddPackage(Uri uri, Package package)
/// Removes a uri, package pair from the package store.
/// </summary>
/// <param name="uri">key uri</param>
/// <permission cref="EnvironmentPermission"></permission>
/// <remarks>
/// </remarks>
public static void RemovePackage(Uri uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,7 @@ internal AutomationPeer ValidateConnected(AutomationPeer connectedPeer)
}

/// <summary>
/// This is responsible for adding parent info like the parent window handle
/// and the parent itself to it's child. This is by definition is a securitycritical operation
/// for two reasons
/// 1. it's doing an action which is securitycritical
/// 2. it can not be treated as safe as it doesn't know whether
/// the peer is actually this objects's parent or not and must be used by methods which has
/// This is responsible for adding parent info like the parent window handle and the parent itself to it's child.
/// </summary>
/// <param name="peer"></param>
internal bool TrySetParentInfo(AutomationPeer peer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private bool ComputeBoundingRectangle(out Rect rect)
{
rect = Rect.Empty;

PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner);
PresentationSource presentationSource = PresentationSource.FromVisual(_owner);

// If there's no source, the element is not visible, return empty rect
if(presentationSource == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected override string GetHelpTextCore()
///
protected override Rect GetBoundingRectangleCore()
{
PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner);
PresentationSource presentationSource = PresentationSource.FromVisual(_owner);

// If there's no source, the element is not visible, return empty rect
if(presentationSource == null)
Expand All @@ -197,7 +197,7 @@ protected override Rect GetBoundingRectangleCore()
///
internal override Rect GetVisibleBoundingRectCore()
{
PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner);
PresentationSource presentationSource = PresentationSource.FromVisual(_owner);

// If there's no source, the element is not visible, return empty rect
if (presentationSource == null)
Expand Down Expand Up @@ -491,7 +491,7 @@ protected override Point GetClickablePointCore()
{
Point pt = new Point(double.NaN, double.NaN);

PresentationSource presentationSource = PresentationSource.CriticalFromVisual(_owner);
PresentationSource presentationSource = PresentationSource.FromVisual(_owner);

// If there's no source, the element is not visible, return (double.NaN, double.NaN) point
if(presentationSource == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ public static void RemoveDropHandler(DependencyObject element, DragEventHandler
/// <param name="allowedEffects">
/// The allowed effects that is one of the DragDropEffects values.
/// </param>
/// <remarks>
/// Requires UnmanagedCode permission.
/// If caller does not have this permission, the dragdrop will not occur.
/// </remarks>
public static DragDropEffects DoDragDrop(DependencyObject dragSource, object data, DragDropEffects allowedEffects)
{
DataObject dataObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,55 +123,27 @@ public ReadOnlyCollection<ApplicationGesture> GetEnabledGestures()

/// <summary>
/// Performs gesture recognition on the StrokeCollection if a gesture recognizer
/// is present and installed on the system. If not, this method throws an InvalidOperationException.
/// is present and installed on the system. If not, this method throws an InvalidOperationException.
/// To determine if this method will throw an exception, only call this method if
/// the RecognizerAvailable property returns true.
///
/// </summary>
/// <param name="strokes">The StrokeCollection to perform gesture recognition on</param>
/// <returns></returns>
/// <remarks>Callers must have UnmanagedCode permission to call this API.</remarks>
public ReadOnlyCollection<GestureRecognitionResult> Recognize(StrokeCollection strokes)
{
return RecognizeImpl(strokes);
}

/// <summary>
/// Performs gesture recognition on the StrokeCollection if a gesture recognizer
/// is present and installed on the system. If not, this method throws an InvalidOperationException.
/// To determine if this method will throw an exception, only call this method if
/// the RecognizerAvailable property returns true.
/// </summary>
/// <param name="strokes">The StrokeCollection to perform gesture recognition on</param>
/// <returns></returns>
// Built into Core, also used by Framework.
internal ReadOnlyCollection<GestureRecognitionResult> CriticalRecognize(StrokeCollection strokes)
{
return RecognizeImpl(strokes);
}

/// <summary>
/// Performs gesture recognition on the StrokeCollection if a gesture recognizer
/// is present and installed on the system.
/// </summary>
/// <param name="strokes">The StrokeCollection to perform gesture recognition on</param>
/// <returns></returns>
private ReadOnlyCollection<GestureRecognitionResult> RecognizeImpl(StrokeCollection strokes)
{
ArgumentNullException.ThrowIfNull(strokes);

if (strokes.Count > 2)
{
throw new ArgumentException(SR.StrokeCollectionCountTooBig, nameof(strokes));
}

VerifyAccess();
VerifyDisposed();
VerifyRecognizerAvailable();

return new ReadOnlyCollection<GestureRecognitionResult>(_nativeRecognizer.Recognize(strokes));
}



#endregion Public Methods

//-------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
Expand Down Expand Up @@ -450,7 +450,7 @@ private PresentationSource GetSourceForElement(IInputElement element)

if (containingVisual != null)
{
source = PresentationSource.CriticalFromVisual(containingVisual);
source = PresentationSource.FromVisual(containingVisual);
}
}

Expand All @@ -472,7 +472,7 @@ private PresentationSource CriticalGetActiveSource()
{
IntPtr hwnd = MS.Win32.UnsafeNativeMethods.GetActiveWindow();
if (hwnd != IntPtr.Zero)
return HwndSource.CriticalFromHwnd(hwnd);
return HwndSource.FromHwnd(hwnd);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,13 @@ private bool CanExecuteImpl(object parameter, IInputElement target, bool trusted
{
RoutedEvent = CommandManager.PreviewCanExecuteEvent
};
CriticalCanExecuteWrapper(parameter, target, trusted, args);

CanExecuteWrapper(target, trusted, args);

if (!args.Handled)
{
args.RoutedEvent = CommandManager.CanExecuteEvent;
CriticalCanExecuteWrapper(parameter, target, trusted, args);
CanExecuteWrapper(target, trusted, args);
}

continueRouting = args.ContinueRouting;
Expand All @@ -339,7 +341,7 @@ private bool CanExecuteImpl(object parameter, IInputElement target, bool trusted
}
}

private void CriticalCanExecuteWrapper(object parameter, IInputElement target, bool trusted, CanExecuteRoutedEventArgs args)
private static void CanExecuteWrapper(IInputElement target, bool trusted, CanExecuteRoutedEventArgs args)
{
// This cast is ok since we are already testing for UIElement, ContentElement, or UIElement3D
// both of which derive from DO
Expand All @@ -356,8 +358,9 @@ private void CriticalCanExecuteWrapper(object parameter, IInputElement target, b
else if (targetAsDO is UIElement3D uie3D)
{
uie3D.RaiseEvent(args, trusted);
}
}
}

internal bool ExecuteCore(object parameter, IInputElement target, bool userInitiated)
{
if (target == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
Expand Down Expand Up @@ -207,10 +207,6 @@ private void LegacyLoadFromStream(Stream cursorStream)
{
//Generate a temporal file based on the memory stream.

// GetTempFileName requires unrestricted Environment permission
// FileIOPermission.Write permission. However, since we don't
// know the path of the file to be created we have to give
// unrestricted permission here.
// GetTempFileName documentation does not mention that it throws
// any exception. However, if it does, CLR reverts the assert.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ internal static IInputElement GetFocusedElement(DependencyObject element, bool v
{
DependencyObject focusScope = element;

if (PresentationSource.CriticalFromVisual(focusScope) != PresentationSource.CriticalFromVisual(focusedElement))
if (PresentationSource.FromVisual(focusScope) != PresentationSource.FromVisual(focusedElement))
{
SetFocusedElement(focusScope, null);
focusedElement = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Windows.Media;
Expand Down Expand Up @@ -267,9 +267,8 @@ internal static Point TranslatePoint(Point pt, DependencyObject from, Dependency
// we only know how to do that if both roots are sourced in HwndSources.
if(rootFrom != rootTo)
{
HwndSource sourceFrom = PresentationSource.CriticalFromVisual(rootFrom) as HwndSource;
HwndSource sourceTo = PresentationSource.CriticalFromVisual(rootTo) as HwndSource;

HwndSource sourceFrom = PresentationSource.FromVisual(rootFrom) as HwndSource;
HwndSource sourceTo = PresentationSource.FromVisual(rootTo) as HwndSource;

if(sourceFrom != null && sourceFrom.Handle != IntPtr.Zero && sourceFrom.CompositionTarget != null &&
sourceTo != null && sourceTo.Handle != IntPtr.Zero && sourceTo.CompositionTarget != null)
Expand Down
Loading