Skip to content

Commit 278c355

Browse files
authored
Remove SecurityCriticalData/Class (#9882)
* Remove SecurityCriticalData/Class These are CAS holdovers from .NET Framework that add unnecessary complexity. Uses more modern / safer syntax where I've modified code. I've also removed a few asserts where they then fall over on the next line anyway. Similar to and should follow #7161 and #6561 * Address feedback
1 parent 8fd0b1b commit 278c355

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+614
-1102
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Classification.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,10 @@ static Classification()
213213
RawClassificationTables ct = new RawClassificationTables();
214214
MILGetClassificationTables(out ct);
215215

216-
_unicodeClassTable = new SecurityCriticalData<IntPtr>(ct.UnicodeClasses);
217-
_charAttributeTable = new SecurityCriticalData<IntPtr>(ct.CharacterAttributes);
218-
_mirroredCharTable = new SecurityCriticalData<IntPtr>(ct.Mirroring);
219-
220-
_combiningMarksClassification = new SecurityCriticalData<CombiningMarksClassificationData>(ct.CombiningMarksClassification);
216+
_unicodeClassTable = ct.UnicodeClasses;
217+
_charAttributeTable = ct.CharacterAttributes;
218+
_mirroredCharTable = ct.Mirroring;
219+
_combiningMarksClassification = ct.CombiningMarksClassification;
221220
}
222221
}
223222

@@ -404,27 +403,22 @@ out sizeofChar
404403
return i;
405404
}
406405

407-
private static unsafe short*** UnicodeClassTable
408-
{
409-
get { return (short***)_unicodeClassTable.Value; }
410-
}
411-
private static unsafe CharacterAttribute* CharAttributeTable
412-
{
413-
get { return (CharacterAttribute*)_charAttributeTable.Value; }
414-
}
406+
private static unsafe short*** UnicodeClassTable => (short***)_unicodeClassTable;
407+
408+
private static unsafe CharacterAttribute* CharAttributeTable => (CharacterAttribute*)_charAttributeTable;
415409

416410
internal static CharacterAttribute CharAttributeOf(int charClass)
417-
{
418-
unsafe
419-
{
411+
{
412+
unsafe
413+
{
420414
Invariant.Assert(charClass >= 0 && charClass < (int) UnicodeClass.Max);
421415
return CharAttributeTable[charClass];
422416
}
423417
}
424418

425-
static private readonly SecurityCriticalData<IntPtr> _unicodeClassTable;
426-
static private readonly SecurityCriticalData<IntPtr> _charAttributeTable;
427-
static private readonly SecurityCriticalData<IntPtr> _mirroredCharTable;
428-
static private readonly SecurityCriticalData<CombiningMarksClassificationData> _combiningMarksClassification;
419+
static private readonly IntPtr _unicodeClassTable;
420+
static private readonly IntPtr _charAttributeTable;
421+
static private readonly IntPtr _mirroredCharTable;
422+
static private readonly CombiningMarksClassificationData _combiningMarksClassification;
429423
}
430424
}

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandDevice.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ internal sealed class CommandDevice : InputDevice
2424
{
2525
internal CommandDevice( InputManager inputManager )
2626
{
27-
_inputManager = new SecurityCriticalData<InputManager>(inputManager);
28-
_inputManager.Value.PreProcessInput += new PreProcessInputEventHandler(PreProcessInput);
29-
_inputManager.Value.PostProcessInput += new ProcessInputEventHandler(PostProcessInput);
27+
_inputManager = inputManager;
28+
_inputManager.PreProcessInput += new PreProcessInputEventHandler(PreProcessInput);
29+
_inputManager.PostProcessInput += new ProcessInputEventHandler(PostProcessInput);
3030
}
3131

3232
/// <summary>
@@ -290,7 +290,7 @@ private IInputElement GetSourceFromDevice(InputType device)
290290
}
291291
}
292292

293-
private SecurityCriticalData<InputManager> _inputManager;
293+
private readonly InputManager _inputManager;
294294
}
295295

296296
/// <summary>

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/DefaultTextStore.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ internal static DefaultTextStore Current
245245

246246
// Pointer to ITfDocumentMgr interface.
247247
internal UnsafeNativeMethods.ITfDocumentMgr DocumentManager
248-
{
249-
get { return _doc.Value;}
250-
251-
set { _doc = new SecurityCriticalData<UnsafeNativeMethods.ITfDocumentMgr>(value); }
248+
{
249+
get => _doc;
250+
251+
set => _doc = value;
252252
}
253253

254254
// EditCookie for ITfContext.
@@ -346,7 +346,7 @@ private void Register()
346346
private TextComposition _composition;
347347

348348
// The TSF document object. This is a native resource.
349-
private SecurityCriticalData<UnsafeNativeMethods.ITfDocumentMgr> _doc;
349+
private UnsafeNativeMethods.ITfDocumentMgr _doc;
350350

351351
// The edit cookie TSF returns from CreateContext.
352352
private int _editCookie;

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputMethod.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ internal void EnableOrDisableInputMethod(bool bEnabled)
13471347
//
13481348
if (DefaultImc != IntPtr.Zero)
13491349
{
1350-
UnsafeNativeMethods.ImmAssociateContext(new HandleRef(this, hwnd), new HandleRef(this, _defaultImc.Value));
1350+
UnsafeNativeMethods.ImmAssociateContext(new HandleRef(this, hwnd), new HandleRef(this, _defaultImc));
13511351
}
13521352
}
13531353
else
@@ -1748,7 +1748,7 @@ private IntPtr DefaultImc
17481748
{
17491749
get
17501750
{
1751-
if (_defaultImc==null)
1751+
if (_defaultImc == 0)
17521752
{
17531753
//
17541754
// Get the default HIMC from default IME window.
@@ -1757,11 +1757,12 @@ private IntPtr DefaultImc
17571757
IntPtr himc = UnsafeNativeMethods.ImmGetContext(new HandleRef(this, hwnd));
17581758

17591759
// Store the default imc to _defaultImc.
1760-
_defaultImc = new SecurityCriticalDataClass<IntPtr>(himc);
1760+
_defaultImc = himc;
17611761

17621762
UnsafeNativeMethods.ImmReleaseContext(new HandleRef(this, hwnd), new HandleRef(this, himc));
17631763
}
1764-
return _defaultImc.Value;
1764+
1765+
return _defaultImc;
17651766
}
17661767
}
17671768

@@ -1795,7 +1796,7 @@ private IntPtr DefaultImc
17951796

17961797
// the default imc. The default imc is per thread and we cache it in ThreadStatic.
17971798
[ThreadStatic]
1798-
private static SecurityCriticalDataClass<IntPtr> _defaultImc;
1799+
private static IntPtr _defaultImc;
17991800

18001801
#endregion Private Fields
18011802
}

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputProviderSite.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ internal class InputProviderSite : IDisposable
2121
{
2222
internal InputProviderSite(InputManager inputManager, IInputProvider inputProvider)
2323
{
24-
_inputManager = new SecurityCriticalDataClass<InputManager>(inputManager);
25-
_inputProvider = new SecurityCriticalDataClass<IInputProvider>(inputProvider);
24+
_inputManager = inputManager;
25+
_inputProvider = inputProvider;
2626
}
2727

2828
/// <summary>
@@ -39,13 +39,7 @@ public InputManager InputManager
3939
/// <summary>
4040
/// Returns the input manager that this site is attached to.
4141
/// </summary>
42-
internal InputManager CriticalInputManager
43-
{
44-
get
45-
{
46-
return _inputManager.Value;
47-
}
48-
}
42+
internal InputManager CriticalInputManager => _inputManager;
4943

5044
/// <summary>
5145
/// Unregisters this input provider.
@@ -57,10 +51,11 @@ public void Dispose()
5751
{
5852
_isDisposed = true;
5953

60-
if (_inputManager != null && _inputProvider != null)
54+
if (_inputManager is not null && _inputProvider is not null)
6155
{
62-
_inputManager.Value.UnregisterInputProvider(_inputProvider.Value);
56+
_inputManager.UnregisterInputProvider(_inputProvider);
6357
}
58+
6459
_inputManager = null;
6560
_inputProvider = null;
6661
}
@@ -100,17 +95,17 @@ public bool ReportInput(InputReport inputReport)
10095
InputReportEventArgs input = new InputReportEventArgs(null, inputReport);
10196
input.RoutedEvent=InputManager.PreviewInputReportEvent;
10297

103-
if(_inputManager != null)
98+
if(_inputManager is not null)
10499
{
105-
handled = _inputManager.Value.ProcessInput(input);
100+
handled = _inputManager.ProcessInput(input);
106101
}
107102

108103
return handled;
109104
}
110105

111106
private bool _isDisposed;
112-
private SecurityCriticalDataClass<InputManager> _inputManager;
113-
private SecurityCriticalDataClass<IInputProvider> _inputProvider;
107+
private InputManager _inputManager;
108+
private IInputProvider _inputProvider;
114109
}
115110
}
116111

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputReport.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected InputReport(PresentationSource inputSource, InputType type, InputMode
4343

4444
Validate_InputType( type );
4545
Validate_InputMode( mode );
46-
_inputSource= new SecurityCriticalData<PresentationSource>(inputSource);
46+
_inputSource= inputSource;
4747
_type = type;
4848
_mode = mode;
4949
_timestamp = timestamp;
@@ -52,13 +52,7 @@ protected InputReport(PresentationSource inputSource, InputType type, InputMode
5252
/// <summary>
5353
/// Read-only access to the type of input source that reported input.
5454
/// </summary>
55-
public PresentationSource InputSource
56-
{
57-
get
58-
{
59-
return _inputSource.Value;
60-
}
61-
}
55+
public PresentationSource InputSource => _inputSource;
6256

6357
/// <summary>
6458
/// Read-only access to the type of input that was reported.
@@ -111,7 +105,7 @@ private void Validate_InputType( InputType type )
111105
}
112106
}
113107

114-
private SecurityCriticalData<PresentationSource> _inputSource;
108+
private readonly PresentationSource _inputSource;
115109
private InputType _type;
116110
private InputMode _mode;
117111
private int _timestamp;

0 commit comments

Comments
 (0)