Skip to content

Commit

Permalink
Remove System.Xaml.XamlObjectWriterSettings.AccessLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsan-madhavan committed Jun 25, 2019
1 parent e065272 commit 30cbe44
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 1,256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ CannotRemoveBaseTypeOrInterface : Type 'System.Xaml.XamlException' does not impl
CannotRemoveBaseTypeOrInterface : Type 'System.Xaml.XamlInternalException' does not implement interface 'System.Runtime.InteropServices._Exception' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Xaml.XamlObjectReaderException' does not implement interface 'System.Runtime.InteropServices._Exception' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Xaml.XamlObjectWriterException' does not implement interface 'System.Runtime.InteropServices._Exception' in the implementation but it does in the contract.
MembersMustExist : Member 'System.Xaml.XamlObjectWriterSettings.AccessLevel.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Xaml.XamlObjectWriterSettings.AccessLevel.set(System.Xaml.Permissions.XamlAccessLevel)' does not exist in the implementation but it does exist in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Xaml.XamlParseException' does not implement interface 'System.Runtime.InteropServices._Exception' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Xaml.XamlSchemaException' does not implement interface 'System.Runtime.InteropServices._Exception' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Xaml.XamlXmlWriterException' does not implement interface 'System.Runtime.InteropServices._Exception' in the implementation but it does in the contract.
CannotChangeAttribute : Attribute 'System.Diagnostics.DebuggerDisplayAttribute' on 'System.Xaml.Schema.XamlTypeName' changed from '[DebuggerDisplayAttribute("{{{Namespace}}}{Name}{TypeArgStringForDebugger}")]' in the contract to '[DebuggerDisplayAttribute("{ToString()}")]' in the implementation.
Total Issues: 34
Total Issues: 36
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ namespace System.Windows
[TypeConverter(typeof(DeferrableContentConverter))]
public class DeferrableContent
{
internal XamlLoadPermission LoadPermission
{
get;
private set;
}

internal Stream Stream
{
get;
Expand All @@ -43,13 +37,7 @@ internal DeferrableContent(Stream stream, Baml2006SchemaContext schemaContext,
object rootObject)
{
ObjectWriterParentSettings = objectWriterFactory.GetParentSettings();
if (ObjectWriterParentSettings.AccessLevel != null)
{
XamlLoadPermission loadPermission =
new XamlLoadPermission(ObjectWriterParentSettings.AccessLevel);
loadPermission.Demand();
this.LoadPermission = loadPermission;
}

bool assemblyTargetsFramework2 = false;
// The local assembly can be null if it is not specified in the XamlReaderSettings.
if (schemaContext.LocalAssembly != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,22 +967,7 @@ private void LoadTemplateXaml(XamlObjectWriter objectWriter)
{
System.Xaml.XamlReader templateReader = _templateHolder.PlayXaml();
Debug.Assert(templateReader != null, "PlayXaml returned null");
if (_templateHolder.LoadPermission != null)
{
_templateHolder.LoadPermission.Assert();
try
{
LoadTemplateXaml(templateReader, objectWriter);
}
finally
{
CodeAccessPermission.RevertAssert();
}
}
else
{
LoadTemplateXaml(templateReader, objectWriter);
}
LoadTemplateXaml(templateReader, objectWriter);
}

private void LoadTemplateXaml(System.Xaml.XamlReader templateReader, XamlObjectWriter currentWriter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ public static object LoadDeferredContent(System.Xaml.XamlReader xamlReader, IXam
}

public static object LoadBaml(System.Xaml.XamlReader xamlReader, bool skipJournaledProperties,
Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
Object rootObject, Uri baseUri)
{
XamlObjectWriterSettings settings = XamlReader.CreateObjectWriterSettingsForBaml();
settings.RootObjectInstance = rootObject;
settings.AccessLevel = accessLevel;
object result = Load(xamlReader, null, skipJournaledProperties, rootObject, settings, baseUri);
EnsureXmlNamespaceMaps(result, xamlReader.SchemaContext);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ internal static XamlObjectWriterSettings CreateObjectWriterSettings(XamlObjectWr
if (parentSettings != null)
{
owSettings.SkipDuplicatePropertyCheck = parentSettings.SkipDuplicatePropertyCheck;
owSettings.AccessLevel = parentSettings.AccessLevel;
owSettings.SkipProvideValueOnRoot = parentSettings.SkipProvideValueOnRoot;
owSettings.SourceBamlUri = parentSettings.SourceBamlUri;
}
Expand Down Expand Up @@ -1002,21 +1001,11 @@ internal static object LoadBaml(

if (internalTypeHelper != null)
{
XamlAccessLevel accessLevel = XamlAccessLevel.AssemblyAccessTo(streamInfo.Assembly);
XamlLoadPermission loadPermission = new XamlLoadPermission(accessLevel);
loadPermission.Assert();
try
{
root = WpfXamlLoader.LoadBaml(reader, parserContext.SkipJournaledProperties, parent, accessLevel, parserContext.BaseUri);
}
finally
{
CodeAccessPermission.RevertAssert();
}
root = WpfXamlLoader.LoadBaml(reader, parserContext.SkipJournaledProperties, parent, parserContext.BaseUri);
}
else
{
root = WpfXamlLoader.LoadBaml(reader, parserContext.SkipJournaledProperties, parent, null, parserContext.BaseUri);
root = WpfXamlLoader.LoadBaml(reader, parserContext.SkipJournaledProperties, parent, parserContext.BaseUri);
}

DependencyObject dObject = root as DependencyObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@ private void SetDeferrableContent(DeferrableContent deferrableContent)
if (_reader == null)
{
_reader = reader;
_xamlLoadPermission = deferrableContent.LoadPermission;
SetKeys(keys, deferrableContent.ServiceProvider);
}
else
Expand Down Expand Up @@ -1383,26 +1382,9 @@ private object CreateObject(KeyRecord key)
return null;

Uri baseUri = (_rootElement is IUriContext) ? ((IUriContext)_rootElement).BaseUri : _baseUri;
if (_xamlLoadPermission != null)
{
_xamlLoadPermission.Assert();
try
{
return WpfXamlLoader.LoadDeferredContent(
xamlReader, _objectWriterFactory, false /*skipJournaledProperites*/,
_rootElement, _objectWriterSettings, baseUri);
}
finally
{
CodeAccessPermission.RevertAssert();
}
}
else
{
return WpfXamlLoader.LoadDeferredContent(
xamlReader, _objectWriterFactory, false /*skipJournaledProperites*/,
_rootElement, _objectWriterSettings, baseUri);
}
return WpfXamlLoader.LoadDeferredContent(
xamlReader, _objectWriterFactory, false /*skipJournaledProperites*/,
_rootElement, _objectWriterSettings, baseUri);
}

// Moved "Lookup()" from 3.5 BamlRecordReader to 4.0 ResourceDictionary
Expand Down Expand Up @@ -2471,7 +2453,6 @@ private void CloseReader()
{
_reader.Close();
_reader = null;
_xamlLoadPermission = null;
}

private void CopyDeferredContentFrom(ResourceDictionary loadedRD)
Expand All @@ -2484,7 +2465,6 @@ private void CopyDeferredContentFrom(ResourceDictionary loadedRD)
_objectWriterSettings = loadedRD._objectWriterSettings;
_rootElement = loadedRD._rootElement;
_reader = loadedRD._reader;
_xamlLoadPermission = loadedRD._xamlLoadPermission;
_numDefer = loadedRD._numDefer;
_deferredLocationList = loadedRD._deferredLocationList;
}
Expand Down Expand Up @@ -2609,7 +2589,6 @@ private enum FallbackState
private IXamlObjectWriterFactory _objectWriterFactory;
private XamlObjectWriterSettings _objectWriterSettings;

private XamlLoadPermission _xamlLoadPermission;

/// <summary>
/// Critical: _xamlLoadPermission needs to be updated whenever this field is updated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,6 @@ private ResourceDictionary LoadDictionary(Assembly assembly, string assemblyName
System.Xaml.XamlObjectWriterSettings owSettings = XamlReader.CreateObjectWriterSettingsForBaml();
if (assembly != null)
{
owSettings.AccessLevel = XamlAccessLevel.AssemblyAccessTo(assembly);

AssemblyName asemblyName = new AssemblyName(assembly.FullName);
Uri streamUri = null;
string packUri = string.Format("pack://application:,,,/{0};v{1};component/{2}", asemblyName.Name, asemblyName.Version.ToString(), resourceName);
Expand All @@ -970,24 +968,7 @@ private ResourceDictionary LoadDictionary(Assembly assembly, string assemblyName
}

System.Xaml.XamlObjectWriter writer = new System.Xaml.XamlObjectWriter(bamlReader.SchemaContext, owSettings);

if (owSettings.AccessLevel != null)
{
XamlLoadPermission loadPermission = new XamlLoadPermission(owSettings.AccessLevel);
loadPermission.Assert();
try
{
System.Xaml.XamlServices.Transform(bamlReader, writer);
}
finally
{
CodeAccessPermission.RevertAssert();
}
}
else
{
System.Xaml.XamlServices.Transform(bamlReader, writer);
}
System.Xaml.XamlServices.Transform(bamlReader, writer);

dictionary = (ResourceDictionary)writer.Result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,6 @@ internal TemplateContent(System.Xaml.XamlReader xamlReader, IXamlObjectWriterFac
ObjectWriterFactory = factory;
SchemaContext = xamlReader.SchemaContext;
ObjectWriterParentSettings = factory.GetParentSettings();

XamlAccessLevel accessLevel = ObjectWriterParentSettings.AccessLevel;
if (accessLevel != null)
{
XamlLoadPermission loadPermission = new XamlLoadPermission(accessLevel);
loadPermission.Demand();
LoadPermission = loadPermission;
}
TemplateLoadData.Reader = xamlReader;

Initialize(context);
Expand Down Expand Up @@ -299,12 +291,6 @@ internal System.Xaml.XamlReader PlayXaml()
return _xamlNodeList.GetReader();
}

internal XamlLoadPermission LoadPermission
{
get;
set;
}

//Called by FrameworkTemplate.Seal() to let go of the data used for Template Load.
internal void ResetTemplateLoadData()
{
Expand Down Expand Up @@ -360,22 +346,7 @@ private void ParseTree(
List<PropertyValue> sharedProperties,
ref int nameNumber)
{
if (LoadPermission != null)
{
LoadPermission.Assert();
try
{
ParseNodes(stack, sharedProperties, ref nameNumber);
}
finally
{
CodeAccessPermission.RevertAssert();
}
}
else
{
ParseNodes(stack, sharedProperties, ref nameNumber);
}
ParseNodes(stack, sharedProperties, ref nameNumber);
}

private void ParseNodes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@

#region Microsoft.Security Suppressions
[module: SuppressMessage("Microsoft.Security", "CA2103:ReviewImperativeSecurity", Scope = "member", Target = "System.Xaml.Permissions.XamlLoadPermission.#Copy()", Justification = "Reviewed by senior CLR security developer.")]
[module: SuppressMessage("Microsoft.Security", "CA2103:ReviewImperativeSecurity", Scope = "member", Target = "MS.Internal.Xaml.Runtime.DynamicMethodRuntime.#.ctor(MS.Internal.Xaml.Runtime.XamlRuntimeSettings,System.Xaml.XamlSchemaContext,System.Xaml.Permissions.XamlAccessLevel)", Justification = "Reviewed by Microsoft.")]
[module: SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Scope = "member", Target = "System.Xaml.XamlObjectReader+ObjectMarkupInfo.#GetInstanceDescriptorInfo(System.ComponentModel.Design.Serialization.InstanceDescriptor,System.Reflection.MemberInfo&,System.Collections.ICollection&,System.Boolean&)", Justification = "Non-issue since C# 2.0. LinkDemand is FullDemand by default without a SecurityCritical attribute.")]
[module: SuppressMessage("Microsoft.Security", "CA2106:SecureAsserts", Scope = "member", Target = "MS.Internal.Utility.PerfServiceProxy.#InitializeGetId()", Justification = "Doesn't make sense with security transparency system. Reviewed by Microsoft")]
#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ public ObjectWriterContext(XamlSavedContext savedContext,
XAML3.INameScopeDictionary rootNameScopeDictionary = null;
if (rootNameScope == null)
{
#if TARGETTING35SP1
rootNameScopeDictionary = new NameScopeDictionary(new NameScope());
#else
rootNameScopeDictionary = new NameScope();
#endif
}
else
{
Expand Down Expand Up @@ -88,11 +84,7 @@ public ObjectWriterContext(XamlSchemaContext schemaContext,
XAML3.INameScopeDictionary rootNameScopeDictionary = null;
if (rootNameScope == null)
{
#if TARGETTING35SP1
rootNameScopeDictionary = new NameScopeDictionary(new NameScope());
#else
rootNameScopeDictionary = new NameScope();
#endif
}
else
{
Expand All @@ -115,16 +107,7 @@ public ObjectWriterContext(XamlSchemaContext schemaContext,

public override Assembly LocalAssembly
{
get
{
Assembly result = base.LocalAssembly;
if (result == null && _settings != null && _settings.AccessLevel != null)
{
result = Assembly.Load(_settings.AccessLevel.AssemblyAccessToAssemblyName);
base.LocalAssembly = result;
}
return result;
}
get => base.LocalAssembly;
protected set { base.LocalAssembly = value; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,9 @@ private XamlRuntime CreateRuntime(XamlObjectWriterSettings settings, XamlSchemaC
if (settings != null)
{
runtimeSettings = new XamlRuntimeSettings { IgnoreCanConvert = settings.IgnoreCanConvert };
#if !TARGETTING35SP1
if (settings.AccessLevel != null)
{
result = new PartialTrustTolerantRuntime(runtimeSettings, settings.AccessLevel, schemaContext);
}
}
if (result == null)
{
#endif
result = new ClrObjectRuntime(runtimeSettings, true /*isWriter*/);
}

result = new ClrObjectRuntime(runtimeSettings, true /*isWriter*/);
result.LineInfo = this;
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ public XamlObjectWriterSettings(XamlObjectWriterSettings settings)
BeforePropertiesHandler = settings.BeforePropertiesHandler;
AfterPropertiesHandler = settings.AfterPropertiesHandler;
AfterEndInitHandler = settings.AfterEndInitHandler;
#if !TARGETTING35SP1
XamlSetValueHandler = settings.XamlSetValueHandler;
#endif
RootObjectInstance = settings.RootObjectInstance;
IgnoreCanConvert = settings.IgnoreCanConvert;
ExternalNameScope = settings.ExternalNameScope;
SkipDuplicatePropertyCheck = settings.SkipDuplicatePropertyCheck;
RegisterNamesOnExternalNamescope = settings.RegisterNamesOnExternalNamescope;
AccessLevel = settings.AccessLevel;
SkipProvideValueOnRoot = settings.SkipProvideValueOnRoot;
PreferUnconvertedDictionaryKeys = settings.PreferUnconvertedDictionaryKeys;
SourceBamlUri = settings.SourceBamlUri;
Expand All @@ -41,9 +38,7 @@ public XamlObjectWriterSettings(XamlObjectWriterSettings settings)
public EventHandler<XamlObjectEventArgs> BeforePropertiesHandler { get; set; }
public EventHandler<XamlObjectEventArgs> AfterPropertiesHandler { get; set; }
public EventHandler<XamlObjectEventArgs> AfterEndInitHandler { get; set; }
#if !TARGETTING35SP1
public EventHandler<XamlSetValueEventArgs> XamlSetValueHandler { get; set; }
#endif

public Object RootObjectInstance { get; set; }
public bool IgnoreCanConvert { get; set; }
Expand All @@ -59,11 +54,6 @@ public XamlObjectWriterSettings(XamlObjectWriterSettings settings)
/// </summary>
public Uri SourceBamlUri { get; set; }

// Not critical: This property indicates the expected access level for non-public members
// in partial trust. We don't actually make any security decisions based on
// this value without demanding XamlLoadPermission.
public XamlAccessLevel AccessLevel { get; set; }

internal XamlObjectWriterSettings StripDelegates()
{
XamlObjectWriterSettings result = new XamlObjectWriterSettings(this);
Expand All @@ -72,9 +62,8 @@ internal XamlObjectWriterSettings StripDelegates()
result.AfterEndInitHandler = null;
result.AfterPropertiesHandler = null;
result.BeforePropertiesHandler = null;
#if !TARGETTING35SP1
result.XamlSetValueHandler = null;
#endif

return result;
}
}
Expand Down
Loading

0 comments on commit 30cbe44

Please sign in to comment.