diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/BrowserInteropHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/BrowserInteropHelper.cs
index 69c2e3af5fd..f83d79196c6 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/BrowserInteropHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/BrowserInteropHelper.cs
@@ -4,24 +4,12 @@
//
// Description: Implements Avalon BrowserInteropHelper class, which helps
-// interop with the browser
+// interop with the browser. Deprecated as XBAP is not supported.
//
-using System;
-using System.Runtime.InteropServices;
-using System.Windows;
-using System.Windows.Interop;
-using System.Windows.Threading;
-using System.Security;
-using System.Diagnostics;
-using MS.Internal;
using MS.Win32;
-using System.Windows.Input;
+using MS.Internal;
using MS.Internal.AppModel;
-using MS.Internal.Interop;
-using System.Threading;
-
-using SafeSecurityHelper=MS.Internal.PresentationFramework.SafeSecurityHelper;
namespace System.Windows.Interop
{
@@ -38,20 +26,7 @@ static BrowserInteropHelper()
///
/// Returns the IOleClientSite interface
///
- ///
- /// Callers must have UnmanagedCode permission to call this API.
- ///
- public static object ClientSite
- {
- get
- {
-
- object oleClientSite = null;
-
-
- return oleClientSite;
- }
- }
+ public static object ClientSite => null;
///
/// Gets a script object that provides access to the HTML window object,
@@ -71,12 +46,6 @@ public static object ClientSite
/// That's why they are still separate. Also, this one is public.
///
public static bool IsBrowserHosted => false;
-
- internal static HostingFlags HostingFlags
- {
- get { return _hostingFlags; }
- set { _hostingFlags = value; }
- }
///
/// Returns the Uri used to launch the application.
@@ -97,21 +66,7 @@ internal static bool IsViewer
{
get
{
- Application app = Application.Current;
- return app != null && app.MimeType == MimeType.Markup;
- }
- }
-
-
- ///
- /// Returns true if the host browser is IE or the WebOC hosted in a standalone application.
- /// Also returns false if not browser-hosted.
- ///
- internal static bool IsHostedInIEorWebOC
- {
- get
- {
- return (HostingFlags & HostingFlags.hfHostedInIEorWebOC) != 0;
+ return Application.Current?.MimeType == MimeType.Markup;
}
}
@@ -132,115 +87,7 @@ internal static bool IsInitialViewerNavigation
}
}
- ///
- /// Retrieves the IServiceProvider object for the browser we're hosted in.
- /// This is used for IDispatchEx operations in the script interop feature.
- /// Critical: Returns critical type UnsafeNativeMethods.IServiceProvider
- ///
- internal static UnsafeNativeMethods.IServiceProvider HostHtmlDocumentServiceProvider
- {
- get
- {
- // HostHtmlDocumentServiceProvider is used by DynamicScriptObject for IDispatchEx
- // operations in case of IE. During initialization we get the document node from
- // the DOM to obtain the required service provider. During this short timeframe
- // it's valid to have a null-value returned here. In all other cases, we make sure
- // not to run with a null service provider for sake of security.
- // See InitializeHostHtmlDocumentServiceProvider as well.
- /* TODO: straighten this with browser flags to check only when hosted in IE */
- Invariant.Assert(!(_initializedHostScript && _hostHtmlDocumentServiceProvider == null));
-
- return _hostHtmlDocumentServiceProvider;
- }
- }
-
- private static void InitializeHostHtmlDocumentServiceProvider(DynamicScriptObject scriptObject)
- {
- // The service provider is used for Internet Explorer IDispatchEx use.
- if ( IsHostedInIEorWebOC
- && scriptObject.ScriptObject is UnsafeNativeMethods.IHTMLWindow4
- && _hostHtmlDocumentServiceProvider == null)
- {
- // We use the IDispatch infrastructure to gain access to the document DOM node where
- // the IServiceProvider lives that was recommended to us by IE people. Notice during
- // this call the HostHtmlDocumentServiceProvider property here is still null, so this
- // first request is made (and succeeds properly) without the service provider in place.
- object document;
- bool foundDoc = scriptObject.TryFindMemberAndInvokeNonWrapped("document",
- NativeMethods.DISPATCH_PROPERTYGET,
- true /* cache DISPID, why not? */,
- null, /* arguments */
- out document);
-
- // The fact the host script is required to be a IHTMLWindow4 here ensures there is
- // document property and because we're dealing with IE, we know it has a service
- // provider on it.
- Invariant.Assert(foundDoc);
- _hostHtmlDocumentServiceProvider = (UnsafeNativeMethods.IServiceProvider)document;
-
- // See HostHtmlDocumentServiceProvider property get accessor for more information on the use of
- // this field to ensure we got a valid service provider.
- _initializedHostScript = true;
- }
- }
-
- private static void HostFilterInput(ref MSG msg, ref bool handled)
- {
- WindowMessage message = (WindowMessage)msg.message;
- // The host gets to see input, keyboard and mouse messages.
- if (message == WindowMessage.WM_INPUT ||
- (message >= WindowMessage.WM_KEYFIRST && message <= WindowMessage.WM_IME_KEYLAST) ||
- (message >= WindowMessage.WM_MOUSEFIRST && message <= WindowMessage.WM_MOUSELAST))
- {
- if (MS.Win32.NativeMethods.S_OK == ForwardTranslateAccelerator(ref msg, false))
- {
- handled = true;
- }
- }
- }
-
- /// This hook gets a "last chance" to handle a key. Such applicaton-unhandled
- /// keys are forwarded to the browser frame.
- ///
- internal static IntPtr PostFilterInput(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
- {
- if (!handled)
- {
- if ((WindowMessage)msg >= WindowMessage.WM_KEYFIRST && (WindowMessage)msg <= WindowMessage.WM_IME_KEYLAST)
- {
- MSG m = new MSG(hwnd, msg, wParam, lParam, SafeNativeMethods.GetMessageTime(), 0, 0);
- if (MS.Win32.NativeMethods.S_OK == ForwardTranslateAccelerator(ref m, true))
- {
- handled = true;
- }
- }
- }
- return IntPtr.Zero;
- }
-
- internal static void InitializeHostFilterInput()
- {
- ComponentDispatcher.ThreadFilterMessage +=
- new ThreadMessageEventHandler(HostFilterInput);
- }
-
- private static void EnsureScriptInteropAllowed()
- {
- if (_isScriptInteropDisabled == null)
- {
- _isScriptInteropDisabled = SafeSecurityHelper.IsFeatureDisabled(SafeSecurityHelper.KeyToRead.ScriptInteropDisable);
- }
- }
-
- private static HostingFlags _hostingFlags;
private static bool _isInitialViewerNavigation;
- private static bool? _isScriptInteropDisabled;
-
- private static UnsafeNativeMethods.IServiceProvider _hostHtmlDocumentServiceProvider;
- private static bool _initializedHostScript;
-
- [DllImport(ExternDll.PresentationHostDll, EntryPoint="ForwardTranslateAccelerator")]
- private static extern int ForwardTranslateAccelerator(ref MSG pMsg, bool appUnhandled);
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/DynamicScriptObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/DynamicScriptObject.cs
index e97f853a82b..6b4ef01edb3 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/DynamicScriptObject.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/DynamicScriptObject.cs
@@ -6,19 +6,10 @@
// Description:
// Enables scripting support against the HTML DOM for XBAPs using the DLR
// dynamic feature, as available through the dynamic keyword in C# 4.0 and
-// also supported in Visual Basic.
+// also supported in Visual Basic. Deprecated as XBAP is not supported.
//
-using System;
-using System.Collections.Generic;
using System.Dynamic;
-using System.Reflection;
-using System.Runtime.InteropServices;
-using System.Security;
-using System.Threading;
-using System.Windows;
-using MS.Internal.Interop;
-using MS.Win32;
namespace System.Windows.Interop
{
@@ -27,38 +18,10 @@ namespace System.Windows.Interop
///
public sealed class DynamicScriptObject : DynamicObject
{
- //----------------------------------------------
- //
- // Constructors
- //
- //----------------------------------------------
-
- #region Constructor
-
///
- /// Wraps the given object in a script object for "dynamic" access.
+ /// Internal constructor, kept for ApiCompat reasons.
///
- /// Object to be wrapped.
- internal DynamicScriptObject(UnsafeNativeMethods.IDispatch scriptObject)
- {
- ArgumentNullException.ThrowIfNull(scriptObject);
-
- _scriptObject = scriptObject;
-
- // In the case of IE, we use IDispatchEx for enhanced security (see InvokeOnScriptObject).
- _scriptObjectEx = _scriptObject as UnsafeNativeMethods.IDispatchEx;
- }
-
- #endregion Constructor
-
-
- //----------------------------------------------
- //
- // Public Methods
- //
- //----------------------------------------------
-
- #region Public Methods
+ internal DynamicScriptObject() { }
///
/// Calls a script method. Corresponds to methods calls in the front-end language.
@@ -69,10 +32,9 @@ internal DynamicScriptObject(UnsafeNativeMethods.IDispatch scriptObject)
/// true - We never defer behavior to the call site, and throw if invalid access is attempted.
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
- ArgumentNullException.ThrowIfNull(binder);
+ result = null;
- result = InvokeAndReturn(binder.Name, NativeMethods.DISPATCH_METHOD, args);
- return true;
+ return false;
}
///
@@ -83,10 +45,9 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
/// true - We never defer behavior to the call site, and throw if invalid access is attempted.
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
- ArgumentNullException.ThrowIfNull(binder);
+ result = null;
- result = InvokeAndReturn(binder.Name, NativeMethods.DISPATCH_PROPERTYGET, null);
- return true;
+ return false;
}
///
@@ -95,14 +56,7 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
/// The binder provided by the call site.
/// The value to set.
/// true - We never defer behavior to the call site, and throw if invalid access is attempted.
- public override bool TrySetMember(SetMemberBinder binder, object value)
- {
- ArgumentNullException.ThrowIfNull(binder);
-
- int flags = GetPropertyPutMethod(value);
- object result = InvokeAndReturn(binder.Name, flags, new object[] { value });
- return true;
- }
+ public override bool TrySetMember(SetMemberBinder binder, object value) => false;
///
/// Gets an indexed value from script. Corresponds to indexer getter syntax in the front-end language.
@@ -113,35 +67,9 @@ public override bool TrySetMember(SetMemberBinder binder, object value)
/// true - We never defer behavior to the call site, and throw if invalid access is attempted.
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
- ArgumentNullException.ThrowIfNull(binder);
-
- ArgumentNullException.ThrowIfNull(indexes);
-
- // IE supports a default member for indexers. Try that first. This accommodates for indexing
- // in collection types, using a default method called "item".
- if (BrowserInteropHelper.IsHostedInIEorWebOC)
- {
- if (TryFindMemberAndInvoke(null, NativeMethods.DISPATCH_METHOD, false /* no DISPID caching */, indexes, out result))
- {
- return true;
- }
- }
-
- // We fall back to property lookup given the first argument of the indices. This accommodates
- // for arrays (e.g. d.x[0]) and square-bracket-style property lookup (e.g. d.document["title"]).
- if (indexes.Length != 1)
- {
- throw new ArgumentException("indexes", HRESULT.DISP_E_BADPARAMCOUNT.GetException());
- }
-
- object index = indexes[0];
- if (index == null)
- {
- throw new ArgumentOutOfRangeException("indexes");
- }
+ result = null;
- result = InvokeAndReturn(index.ToString(), NativeMethods.DISPATCH_PROPERTYGET, false /* no DISPID caching */, null);
- return true;
+ return false;
}
///
@@ -151,31 +79,7 @@ public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out ob
/// The indexes to be used.
/// The value to set.
/// true - We never defer behavior to the call site, and throw if invalid access is attempted.
- public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
- {
- ArgumentNullException.ThrowIfNull(binder);
-
- ArgumentNullException.ThrowIfNull(indexes);
-
- if (indexes.Length != 1)
- {
- throw new ArgumentException("indexes", HRESULT.DISP_E_BADPARAMCOUNT.GetException());
- }
-
- object index = indexes[0];
- if (index == null)
- {
- throw new ArgumentOutOfRangeException("indexes");
- }
-
- // We don't cache resolved DISPIDs for indexers as they have the potential to be used for dynamic resolution
- // of a bunch of members, e.g. when indexing into arrays. This would flood the cache, likely for just a one-
- // time access. So we just don't cache in this case.
- object result = InvokeAndReturn(index.ToString(), NativeMethods.DISPATCH_PROPERTYPUT, false /* no DISPID caching */,
- new object[] { value });
-
- return true;
- }
+ public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value) => false;
///
/// Calls the default script method. Corresponds to delegate calling syntax in the front-end language.
@@ -186,475 +90,16 @@ public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object
/// true - We never defer behavior to the call site, and throw if invalid access is attempted.
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
{
- ArgumentNullException.ThrowIfNull(binder);
+ result = null;
- result = InvokeAndReturn(null, NativeMethods.DISPATCH_METHOD, args);
- return true;
+ return false;
}
///
/// Provides a string representation of the wrapped script object.
///
/// String representation of the wrapped script object, using the toString method or default member on the script object.
- public override string ToString()
- {
- // Note we shouldn't throw in this method (rule CA1065), so we try with best attempt.
-
- HRESULT hr;
-
- Guid guid = Guid.Empty;
- object result = null;
- var dp = new NativeMethods.DISPPARAMS();
-
- // Try to find a toString method.
- int dispid;
- if (TryGetDispIdForMember("toString", true /* DISPID caching */, out dispid))
- {
- hr = InvokeOnScriptObject(dispid, NativeMethods.DISPATCH_METHOD, dp, null /* EXCEPINFO */, out result);
- }
- else
- {
- // If no toString method is found, we try the default member first as a property, then as a method.
-
- dispid = NativeMethods.DISPID_VALUE;
-
- hr = InvokeOnScriptObject(dispid, NativeMethods.DISPATCH_PROPERTYGET, dp, null /* EXCEPINFO */, out result);
-
- if (hr.Failed)
- {
- hr = InvokeOnScriptObject(dispid, NativeMethods.DISPATCH_METHOD, dp, null /* EXCEPINFO */, out result);
- }
- }
-
- if (hr.Succeeded && result != null)
- {
- return result.ToString();
- }
-
- return base.ToString();
- }
-
- #endregion Public Methods
-
-
- //----------------------------------------------
- //
- // Internal Properties
- //
- //----------------------------------------------
-
- #region Internal Properties
-
- ///
- /// Gets the IDispatch script object wrapped by the DynamicScriptObject.
- ///
- internal UnsafeNativeMethods.IDispatch ScriptObject
- {
- get
- {
- return _scriptObject;
- }
- }
-
- #endregion Internal Properties
-
-
- //----------------------------------------------
- //
- // Internal Methods
- //
- //----------------------------------------------
-
- #region Internal Methods
-
- ///
- /// Helper method to attempt invoking a script member with the given name, flags and arguments.
- ///
- /// The name of the member to invoke.
- /// One of the DISPATCH_ flags for IDispatch calls.
- /// true to enable caching of DISPIDs; false otherwise.
- /// Arguments passed to the call.
- /// The raw (not wrapped in DynamicScriptObject) result of the invocation.
- /// true if the member was found; false otherwise.
- internal unsafe bool TryFindMemberAndInvokeNonWrapped(string memberName, int flags, bool cacheDispId, object[] args, out object result)
- {
- result = null;
-
- // In true DLR style we'd return false here, deferring further attempts for resolution to the
- // call site. For better debuggability though, and as we're talking to a specialized object
- // model, we rather throw instead. This Try-method allows internal lookups without directly
- // throwing on non-fatal "member not found" situations, as we might want to have more complex
- // fallback logic (as in ToString).
- if (!TryGetDispIdForMember(memberName, cacheDispId, out int dispId))
- {
- return false;
- }
-
- NativeMethods.DISPPARAMS dp = new NativeMethods.DISPPARAMS();
-
- // Required additional DISPPARAMS arguments for PROPERTYPUT cases. See IDispatch::Invoke
- // documentation for more info.
- int propertyPutDispId = NativeMethods.DISPID_PROPERTYPUT;
- if (flags == NativeMethods.DISPATCH_PROPERTYPUT || flags == NativeMethods.DISPATCH_PROPERTYPUTREF)
- {
- dp.cNamedArgs = 1;
-
- // Stack allocated variables are fixed (unmoveable), so no need to use a fixed
- // statement. The local variable should not get repurposed by the compiler in an
- // unsafe block as we're handing out a pointer to it. For comparison, see the DLR
- // code, CorRuntimeHelpers.cs, where the ConvertInt32ByrefToPtr function relies
- // on the same behavior as they take an IntPtr to a stack-allocated variable that
- // gets used by a DISPPARAMS in a similar way. They have a separate method likely
- // because expression trees can't deal with unsafe code, and they need to fix as
- // they use a by-ref argument which is considered movable (see C# spec, 18.3):
- //
- // public static unsafe IntPtr ConvertInt32ByrefToPtr(ref Int32 value) {
- // fixed (Int32 *x = &value) {
- // AssertByrefPointsToStack(new IntPtr(x));
- // return new IntPtr(x);
- // }
- // }
- dp.rgdispidNamedArgs = new IntPtr(&propertyPutDispId);
- }
-
- try
- {
- if (args != null)
- {
- // Callers of this method might want to implement fallbacks that require the original
- // arguments in the original order, maybe to feed it in to this method again. If we
- // wouldn't clone the arguments array into a local copy, we'd be reversing again.
- args = (object[])args.Clone();
-
- // Reverse the argument order so that parameters read naturally after IDispatch.
- // This code was initially ported from WinForms, see WinForms bug 187662.
- Array.Reverse(args);
-
- // Unwrap arguments that were already promoted to DynamicScriptObject. This can happen
- // if the output of a script accessing method is fed in to the input of another one.
- for (int i = 0; i < args.Length; i++)
- {
- var wrappedArg = args[i] as DynamicScriptObject;
- if (wrappedArg != null)
- {
- args[i] = wrappedArg._scriptObject;
- }
-
- if (args[i] != null)
- {
- // Arrays of COM visible objects (in our definition of the word, see further) are
- // not considered COM visible by themselves, so we take care of this case as well.
- // Jagged arrays are not supported somehow, causing a SafeArrayTypeMismatchException
- // in the call to GetNativeVariantForObject on ArrayToVARIANTVector called below.
- // Multi-dimensional arrays turn out to work fine, so we don't opt out from those.
- Type argType = args[i].GetType();
- if (argType.IsArray)
- {
- argType = argType.GetElementType();
- }
-
- // Caveat: IsTypeVisibleFromCom evaluates false for COM object wrappers provided
- // by the CLR. Therefore we also check for the IsCOMObject property. It also seems
- // COM interop special-cases DateTime as it's not revealed to be visible by any
- // of the first two checks below.
- if (!Marshal.IsTypeVisibleFromCom(argType) &&
- !argType.IsCOMObject && argType != typeof(DateTime))
- {
- throw new ArgumentException(SR.NeedToBeComVisible);
- }
- }
- }
-
- dp.rgvarg = UnsafeNativeMethods.ArrayToVARIANTHelper.ArrayToVARIANTVector(args);
- dp.cArgs = (uint)args.Length;
- }
-
- NativeMethods.EXCEPINFO exInfo = new NativeMethods.EXCEPINFO();
- HRESULT hr = InvokeOnScriptObject(dispId, flags, dp, exInfo, out result);
-
- if (hr.Failed)
- {
- if (hr == HRESULT.DISP_E_MEMBERNOTFOUND)
- {
- return false;
- }
-
- // See KB article 247784, INFO: '80020101' Returned From Some ActiveX Scripting Methods.
- // Internet Explorer returns this error when it has already reported a script error to the user
- // through a dialog or by putting a message in the status bar (Page contains script error). We
- // want consistency between browsers, so route this through the DISP_E_EXCEPTION case.
- if (hr == HRESULT.SCRIPT_E_REPORTED)
- {
- exInfo.scode = hr.Code;
- hr = HRESULT.DISP_E_EXCEPTION;
- }
-
- // We prefix exception messagages with "[memberName]" so that the target of the invocation can
- // be found easily. This is useful beyond just seeing the call site in the debugger as dynamic
- // calls lead to complicated call stacks with the DLR sliced in between the source and target.
- // Also, for good or for bad, dynamic has the potential to encourage endless "dotting into", so
- // it's preferrable to have our runtime resolution failure eloquating the target of the dynamic
- // call. Unfortunately stock CLR exception types often don't offer a convenient spot to put
- // this info in, so we resort to the Message property. Anyway, those exceptions are primarily
- // meant to provide debugging convenience and should not be reported to the end-user in a well-
- // tested application. Essentially all of this is to be conceived as "deferred compilation".
- string member = $"[{(memberName ?? "(default)")}]";
- Exception comException = hr.GetException();
-
- if (hr == HRESULT.DISP_E_EXCEPTION)
- {
- // We wrap script execution failures in TargetInvocationException to keep the API surface
- // free of COMExceptions that reflect a mere implementation detail.
- int errorCode = exInfo.scode != 0 ? exInfo.scode : exInfo.wCode;
- hr = HRESULT.Make(true /* severity */, Facility.Dispatch, errorCode);
- string message = $"{member} {(exInfo.bstrDescription ?? string.Empty)}";
- throw new TargetInvocationException(message, comException)
- {
- HelpLink = exInfo.bstrHelpFile,
- Source = exInfo.bstrSource
- };
- }
- else if (hr == HRESULT.DISP_E_BADPARAMCOUNT || hr == HRESULT.DISP_E_PARAMNOTOPTIONAL)
- {
- throw new TargetParameterCountException(member, comException);
- }
- else if (hr == HRESULT.DISP_E_OVERFLOW || hr == HRESULT.DISP_E_TYPEMISMATCH)
- {
- throw new ArgumentException(member, new InvalidCastException(comException.Message, hr.Code));
- }
- else
- {
- // Something really bad has happened; keeping the exception as-is.
- throw comException;
- }
- }
- }
- finally
- {
- if (dp.rgvarg != IntPtr.Zero)
- {
- UnsafeNativeMethods.ArrayToVARIANTHelper.FreeVARIANTVector(dp.rgvarg, args.Length);
- }
- }
-
- return true;
- }
-
- #endregion Internal Methods
-
-
- //----------------------------------------------
- //
- // Private Methods
- //
- //----------------------------------------------
-
- #region Private Methods
-
- ///
- /// Helper method to invoke a script member with the given name, flags and arguments.
- /// This overload always caches resolved DISPIDs.
- ///
- /// The name of the member to invoke.
- /// One of the DISPATCH_ flags for IDispatch calls.
- /// Arguments passed to the call.
- /// The result of the invocation.
- private object InvokeAndReturn(string memberName, int flags, object[] args)
- {
- return InvokeAndReturn(memberName, flags, true /* DISPID caching */, args);
- }
-
- ///
- /// Helper method to invoke a script member with the given name, flags and arguments.
- /// This overload allows control over the resolved DISPIDs caching behavior.
- ///
- /// The name of the member to invoke.
- /// One of the DISPATCH_ flags for IDispatch calls.
- /// true to enable caching of DISPIDs; false otherwise.
- /// Arguments passed to the call.
- /// The result of the invocation.
- private object InvokeAndReturn(string memberName, int flags, bool cacheDispId, object[] args)
- {
- object result;
- if (!TryFindMemberAndInvoke(memberName, flags, cacheDispId, args, out result))
- {
- if (flags == NativeMethods.DISPATCH_METHOD)
- throw new MissingMethodException(this.ToString(), memberName);
- else
- throw new MissingMemberException(this.ToString(), memberName);
- }
-
- return result;
- }
-
- ///
- /// Helper method to attempt invoking a script member with the given name, flags and arguments.
- /// Wraps the result value in a DynamicScriptObject if required.
- ///
- /// The name of the member to invoke.
- /// One of the DISPATCH_ flags for IDispatch calls.
- /// true to enable caching of DISPIDs; false otherwise.
- /// Arguments passed to the call.
- /// The result of the invocation, wrapped in DynamicScriptObject if required.
- /// true if the member was found; false otherwise.
- private bool TryFindMemberAndInvoke(string memberName, int flags, bool cacheDispId, object[] args, out object result)
- {
- if (!TryFindMemberAndInvokeNonWrapped(memberName, flags, cacheDispId, args, out result))
- {
- return false;
- }
-
- // Only wrap returned COM objects; if the object returns as a CLR object, we just return it.
- if (result != null && Marshal.IsComObject(result))
- {
- // Script objects implement IDispatch.
- result = new DynamicScriptObject((UnsafeNativeMethods.IDispatch)result);
- }
-
- return true;
- }
-
- ///
- /// Helper method to map a script member with the given name onto a DISPID.
- ///
- /// The name of the member to look up.
- /// true to enable caching of DISPIDs; false otherwise.
- /// If the member was found, its DISPID; otherwise, default DISPID_VALUE.
- /// true if the member was found; false if it wasn't (DISP_E_UNKNOWNNAME).
- private bool TryGetDispIdForMember(string memberName, bool cacheDispId, out int dispid)
- {
- dispid = NativeMethods.DISPID_VALUE;
- if (!string.IsNullOrEmpty(memberName))
- {
- if ( !cacheDispId /* short-circuit lookup; will never get cached */
- || !_dispIdCache.TryGetValue(memberName, out dispid))
- {
- Guid guid = Guid.Empty;
-
- string[] names = new string[] { memberName };
- int[] dispids = new int[] { NativeMethods.DISPID_UNKNOWN };
-
- // Only the "member not found" case deserves special treatment. We leave it up to the
- // caller to decide on the right treatment.
- HRESULT hr = _scriptObject.GetIDsOfNames(ref guid, names, dispids.Length, Thread.CurrentThread.CurrentCulture.LCID, dispids);
- if (hr == HRESULT.DISP_E_UNKNOWNNAME)
- {
- return false;
- }
-
- // Fatal unexpected exception here; it's fine to leak a COMException to the surface.
- hr.ThrowIfFailed();
-
- dispid = dispids[0];
-
- if (cacheDispId)
- {
- _dispIdCache[memberName] = dispid;
- }
- }
- }
-
- return true;
- }
-
- private HRESULT InvokeOnScriptObject(int dispid, int flags, NativeMethods.DISPPARAMS dp, NativeMethods.EXCEPINFO exInfo, out object result)
- {
- // If we use reflection to call script code, we need to Assert for the UnmanagedCode permission.
- // But it will be a security issue when the WPF app makes a framework object available to the
- // hosted script via ObjectForScripting or as parameter of InvokeScript, and calls the framework
- // API that demands the UnmanagedCode permission. We do not want the demand to succeed. However,
- // the stack walk will ignore the native frames and keeps going until it reaches the Assert.
- //
- // As an example, if a call to a script object causes an immediate callback before the initial
- // call returns, reentrancy occurs via COM's blocking message loop on outgoing calls:
- //
- // [managed ComVisible object]
- // [CLR COM interop]
- // [COM runtime]
- // ole32.dll!CCliModalLoop::BlockFn()
- // ole32.dll!ModalLoop()
- // [COM runtime]
- // PresentationFramework!DynamicScriptObject::InvokeScript(...)
- //
- // That is why we switch to invoking the script via IDispatch with SUCS on the methods.
-
- if (_scriptObjectEx != null)
- {
- // This case takes care of IE hosting where the use of IDispatchEx is recommended by IE people
- // since the service provider object we can pass here is used by the browser to enforce cross-
- // zone scripting mitigations.
- return _scriptObjectEx.InvokeEx(dispid, Thread.CurrentThread.CurrentCulture.LCID, flags, dp, out result, exInfo, BrowserInteropHelper.HostHtmlDocumentServiceProvider);
- }
- else
- {
- Guid guid = Guid.Empty;
- return _scriptObject.Invoke(dispid, ref guid, Thread.CurrentThread.CurrentCulture.LCID, flags, dp, out result, exInfo, null);
- }
- }
-
- ///
- /// Helper function to get the IDispatch::Invoke invocation method for setting a property.
- ///
- /// Object to be assigned to the property.
- /// DISPATCH_PROPERTYPUTREF or DISPATCH_PROPERTYPUT
- private static int GetPropertyPutMethod(object value)
- {
- // On the top-level script scope, setting a variable of a reference
- // type without using the DISPATCH_PROPERTYPUTREF flag doesn't work since it causes the
- // default member to be invoked as part of the conversion of the reference to a "value".
- // It seems this didn't affect DOM property setters where the IDispatch implementation is
- // more relaxed about the use of PUTREF versus PUT. This code is pretty much analog to
- // the DLR's COM binder's; see ndp\fx\src\Dynamic\System\Dynamic\ComBinderHelpers.cs for
- // further information.
-
- if (value == null)
- {
- return NativeMethods.DISPATCH_PROPERTYPUTREF;
- }
-
- Type type = value.GetType();
- if ( type.IsValueType
- || type.IsArray
- || type == typeof(string)
- || type == typeof(CurrencyWrapper)
- || type == typeof(DBNull)
- || type == typeof(Missing))
- {
- return NativeMethods.DISPATCH_PROPERTYPUT;
- }
- else
- {
- return NativeMethods.DISPATCH_PROPERTYPUTREF;
- }
- }
-
- #endregion Private Methods
-
-
- //----------------------------------------------
- //
- // Private Fields
- //
- //----------------------------------------------
-
- #region Private Fields
-
- ///
- /// Script object to invoke operations on through the "dynamic" feature.
- ///
- private UnsafeNativeMethods.IDispatch _scriptObject;
-
- ///
- /// Script object to invoke operations on through the "dynamic" feature.
- /// Used in the case of IE, where IDispatchEx is used to tighten security (see InvokeOnScriptObject).
- ///
- private UnsafeNativeMethods.IDispatchEx _scriptObjectEx;
-
- ///
- /// Cache of DISPID values for members. Allows to speed up repeated calls.
- ///
- private Dictionary _dispIdCache = new Dictionary();
+ public override string ToString() => null;
- #endregion Private Fields
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Registry.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Registry.cs
index 2e3d71ce760..f921da066b3 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Registry.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Registry.cs
@@ -18,17 +18,8 @@ internal const string
WPF = @"Software\Microsoft\.NETFramework\Windows Presentation Foundation",
WPF_Features = WPF+"\\Features",
- value_MediaImageDisallow = "MediaImageDisallow",
- value_MediaVideoDisallow = "MediaVideoDisallow",
- value_MediaAudioDisallow = "MediaAudioDisallow",
- value_WebBrowserDisallow = "WebBrowserDisallow",
- value_ScriptInteropDisallow = "ScriptInteropDisallow",
value_AutomationWeakReferenceDisallow = "AutomationWeakReferenceDisallow",
- WPF_Hosting = WPF+"\\Hosting",
- value_DisableXbapErrorPage = "DisableXbapErrorPage",
- value_UnblockWebBrowserControl = "UnblockWebBrowserControl",
-
HKCU_XpsViewer = @"HKEY_CURRENT_USER\Software\Microsoft\XPSViewer",
value_IsolatedStorageUserQuota = "IsolatedStorageUserQuota",
HKLM_XpsViewerLocalServer32 = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\CLSID\\{7DDA204B-2097-47C9-8323-C40BB840AE44}\\LocalServer32",
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SafeSecurityHelper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SafeSecurityHelper.cs
index 1cd20692b38..7aefb101cde 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SafeSecurityHelper.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/SafeSecurityHelper.cs
@@ -282,85 +282,6 @@ static bool IsSameKeyToken(byte[] reqKeyToken, byte[] curKeyToken)
}
#endif //!REACHFRAMEWORK
-#if PRESENTATION_CORE || PRESENTATIONFRAMEWORK
- // enum to choose between the various keys
- internal enum KeyToRead
- {
- WebBrowserDisable = 0x01 ,
- MediaAudioDisable = 0x02 ,
- MediaVideoDisable = 0x04 ,
- MediaImageDisable = 0x08 ,
- MediaAudioOrVideoDisable = KeyToRead.MediaVideoDisable | KeyToRead.MediaAudioDisable ,
- ScriptInteropDisable = 0x10 ,
- }
-
- internal static bool IsFeatureDisabled(KeyToRead key)
- {
- string regValue = null;
- bool fResult = false;
-
- switch (key)
- {
- case KeyToRead.WebBrowserDisable:
- regValue = RegistryKeys.value_WebBrowserDisallow;
- break;
- case KeyToRead.MediaAudioDisable:
- regValue = RegistryKeys.value_MediaAudioDisallow;
- break;
- case KeyToRead.MediaVideoDisable:
- regValue = RegistryKeys.value_MediaVideoDisallow;
- break;
- case KeyToRead.MediaImageDisable:
- regValue = RegistryKeys.value_MediaImageDisallow;
- break;
- case KeyToRead.MediaAudioOrVideoDisable:
- regValue = RegistryKeys.value_MediaAudioDisallow;
- break;
- case KeyToRead.ScriptInteropDisable:
- regValue = RegistryKeys.value_ScriptInteropDisallow;
- break;
- default:// throw exception for invalid key
- throw(new System.ArgumentException(key.ToString()));
-
- }
-
- RegistryKey featureKey;
- object obj = null;
- bool keyValue = false;
- // open the key and read the value
- featureKey = Registry.LocalMachine.OpenSubKey(RegistryKeys.WPF_Features);
- if (featureKey != null)
- {
- // If key exists and value is 1 return true else false
- obj = featureKey.GetValue(regValue);
- keyValue = obj is int && ((int)obj == 1);
- if (keyValue)
- {
- fResult = true;
- }
-
- // special case for audio and video since they can be orred
- // this is in the condition that audio is enabled since that is
- // the path that MediaAudioVideoDisable defaults to
- // This is purely to optimize perf on the number of calls to assert
- // in the media or audio scenario.
-
- if ((fResult == false) && (key == KeyToRead.MediaAudioOrVideoDisable))
- {
- regValue = RegistryKeys.value_MediaVideoDisallow;
- // If key exists and value is 1 return true else false
- obj = featureKey.GetValue(regValue);
- keyValue = obj is int && ((int)obj == 1);
- if (keyValue)
- {
- fResult = true;
- }
- }
- }
- return fResult;
- }
-#endif //PRESENTATIONCORE||PRESENTATIONFRAMEWORK
-
#if PRESENTATION_CORE
///
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsCLR.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsCLR.cs
index 3f7a7a66582..b0cdf47eb62 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsCLR.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsCLR.cs
@@ -2873,13 +2873,6 @@ internal interface IHTMLLocation
void Assign(string bstr);
};
- [ComImport, Guid("3050f6cf-98b5-11cf-bb82-00aa00bdce0b"), InterfaceType(ComInterfaceType.InterfaceIsDual)]
- internal interface IHTMLWindow4
- {
- [return: MarshalAs(UnmanagedType.IDispatch)] object CreatePopup([In] ref object reserved);
- [return: MarshalAs(UnmanagedType.Interface)] object frameElement();
- }
-
internal static class ArrayToVARIANTHelper
{
static ArrayToVARIANTHelper()