Skip to content

Commit c0b716b

Browse files
authored
Remove XBAP-related dead code from BrowserInteropHelper/SafeSecurityHelper (#9855)
* Remove XBAP-related dead code from BrowserInteropHelper * Remove IHTMLWindow4 interface import * Remove IsHostedInIEorWebOC and related code (as it is always false) * Remove HostHtmlDocumentServiceProvider as it is always NULL * Hollow out DynamicScriptObject as instances were provided via BrowserInteropHelper
1 parent 24105c1 commit c0b716b

File tree

5 files changed

+18
-821
lines changed

5 files changed

+18
-821
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/BrowserInteropHelper.cs

+4-157
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,12 @@
44

55
//
66
// Description: Implements Avalon BrowserInteropHelper class, which helps
7-
// interop with the browser
7+
// interop with the browser. Deprecated as XBAP is not supported.
88
//
99

10-
using System;
11-
using System.Runtime.InteropServices;
12-
using System.Windows;
13-
using System.Windows.Interop;
14-
using System.Windows.Threading;
15-
using System.Security;
16-
using System.Diagnostics;
17-
using MS.Internal;
1810
using MS.Win32;
19-
using System.Windows.Input;
11+
using MS.Internal;
2012
using MS.Internal.AppModel;
21-
using MS.Internal.Interop;
22-
using System.Threading;
23-
24-
using SafeSecurityHelper=MS.Internal.PresentationFramework.SafeSecurityHelper;
2513

2614
namespace System.Windows.Interop
2715
{
@@ -38,20 +26,7 @@ static BrowserInteropHelper()
3826
/// <summary>
3927
/// Returns the IOleClientSite interface
4028
/// </summary>
41-
/// <remarks>
42-
/// Callers must have UnmanagedCode permission to call this API.
43-
/// </remarks>
44-
public static object ClientSite
45-
{
46-
get
47-
{
48-
49-
object oleClientSite = null;
50-
51-
52-
return oleClientSite;
53-
}
54-
}
29+
public static object ClientSite => null;
5530

5631
/// <summary>
5732
/// Gets a script object that provides access to the HTML window object,
@@ -71,12 +46,6 @@ public static object ClientSite
7146
/// That's why they are still separate. Also, this one is public.
7247
/// </remarks>
7348
public static bool IsBrowserHosted => false;
74-
75-
internal static HostingFlags HostingFlags
76-
{
77-
get { return _hostingFlags; }
78-
set { _hostingFlags = value; }
79-
}
8049

8150
/// <summary>
8251
/// Returns the Uri used to launch the application.
@@ -97,21 +66,7 @@ internal static bool IsViewer
9766
{
9867
get
9968
{
100-
Application app = Application.Current;
101-
return app != null && app.MimeType == MimeType.Markup;
102-
}
103-
}
104-
105-
106-
/// <summary>
107-
/// Returns true if the host browser is IE or the WebOC hosted in a standalone application.
108-
/// Also returns false if not browser-hosted.
109-
/// </summary>
110-
internal static bool IsHostedInIEorWebOC
111-
{
112-
get
113-
{
114-
return (HostingFlags & HostingFlags.hfHostedInIEorWebOC) != 0;
69+
return Application.Current?.MimeType == MimeType.Markup;
11570
}
11671
}
11772

@@ -132,115 +87,7 @@ internal static bool IsInitialViewerNavigation
13287
}
13388
}
13489

135-
/// <summary>
136-
/// Retrieves the IServiceProvider object for the browser we're hosted in.
137-
/// This is used for IDispatchEx operations in the script interop feature.
138-
/// Critical: Returns critical type UnsafeNativeMethods.IServiceProvider
139-
/// </summary>
140-
internal static UnsafeNativeMethods.IServiceProvider HostHtmlDocumentServiceProvider
141-
{
142-
get
143-
{
144-
// HostHtmlDocumentServiceProvider is used by DynamicScriptObject for IDispatchEx
145-
// operations in case of IE. During initialization we get the document node from
146-
// the DOM to obtain the required service provider. During this short timeframe
147-
// it's valid to have a null-value returned here. In all other cases, we make sure
148-
// not to run with a null service provider for sake of security.
149-
// See InitializeHostHtmlDocumentServiceProvider as well.
150-
/* TODO: straighten this with browser flags to check only when hosted in IE */
151-
Invariant.Assert(!(_initializedHostScript && _hostHtmlDocumentServiceProvider == null));
152-
153-
return _hostHtmlDocumentServiceProvider;
154-
}
155-
}
156-
157-
private static void InitializeHostHtmlDocumentServiceProvider(DynamicScriptObject scriptObject)
158-
{
159-
// The service provider is used for Internet Explorer IDispatchEx use.
160-
if ( IsHostedInIEorWebOC
161-
&& scriptObject.ScriptObject is UnsafeNativeMethods.IHTMLWindow4
162-
&& _hostHtmlDocumentServiceProvider == null)
163-
{
164-
// We use the IDispatch infrastructure to gain access to the document DOM node where
165-
// the IServiceProvider lives that was recommended to us by IE people. Notice during
166-
// this call the HostHtmlDocumentServiceProvider property here is still null, so this
167-
// first request is made (and succeeds properly) without the service provider in place.
168-
object document;
169-
bool foundDoc = scriptObject.TryFindMemberAndInvokeNonWrapped("document",
170-
NativeMethods.DISPATCH_PROPERTYGET,
171-
true /* cache DISPID, why not? */,
172-
null, /* arguments */
173-
out document);
174-
175-
// The fact the host script is required to be a IHTMLWindow4 here ensures there is
176-
// document property and because we're dealing with IE, we know it has a service
177-
// provider on it.
178-
Invariant.Assert(foundDoc);
179-
_hostHtmlDocumentServiceProvider = (UnsafeNativeMethods.IServiceProvider)document;
180-
181-
// See HostHtmlDocumentServiceProvider property get accessor for more information on the use of
182-
// this field to ensure we got a valid service provider.
183-
_initializedHostScript = true;
184-
}
185-
}
186-
187-
private static void HostFilterInput(ref MSG msg, ref bool handled)
188-
{
189-
WindowMessage message = (WindowMessage)msg.message;
190-
// The host gets to see input, keyboard and mouse messages.
191-
if (message == WindowMessage.WM_INPUT ||
192-
(message >= WindowMessage.WM_KEYFIRST && message <= WindowMessage.WM_IME_KEYLAST) ||
193-
(message >= WindowMessage.WM_MOUSEFIRST && message <= WindowMessage.WM_MOUSELAST))
194-
{
195-
if (MS.Win32.NativeMethods.S_OK == ForwardTranslateAccelerator(ref msg, false))
196-
{
197-
handled = true;
198-
}
199-
}
200-
}
201-
202-
/// <summary> This hook gets a "last chance" to handle a key. Such applicaton-unhandled
203-
/// keys are forwarded to the browser frame.
204-
/// </summary>
205-
internal static IntPtr PostFilterInput(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
206-
{
207-
if (!handled)
208-
{
209-
if ((WindowMessage)msg >= WindowMessage.WM_KEYFIRST && (WindowMessage)msg <= WindowMessage.WM_IME_KEYLAST)
210-
{
211-
MSG m = new MSG(hwnd, msg, wParam, lParam, SafeNativeMethods.GetMessageTime(), 0, 0);
212-
if (MS.Win32.NativeMethods.S_OK == ForwardTranslateAccelerator(ref m, true))
213-
{
214-
handled = true;
215-
}
216-
}
217-
}
218-
return IntPtr.Zero;
219-
}
220-
221-
internal static void InitializeHostFilterInput()
222-
{
223-
ComponentDispatcher.ThreadFilterMessage +=
224-
new ThreadMessageEventHandler(HostFilterInput);
225-
}
226-
227-
private static void EnsureScriptInteropAllowed()
228-
{
229-
if (_isScriptInteropDisabled == null)
230-
{
231-
_isScriptInteropDisabled = SafeSecurityHelper.IsFeatureDisabled(SafeSecurityHelper.KeyToRead.ScriptInteropDisable);
232-
}
233-
}
234-
235-
private static HostingFlags _hostingFlags;
23690
private static bool _isInitialViewerNavigation;
237-
private static bool? _isScriptInteropDisabled;
238-
239-
private static UnsafeNativeMethods.IServiceProvider _hostHtmlDocumentServiceProvider;
240-
private static bool _initializedHostScript;
241-
242-
[DllImport(ExternDll.PresentationHostDll, EntryPoint="ForwardTranslateAccelerator")]
243-
private static extern int ForwardTranslateAccelerator(ref MSG pMsg, bool appUnhandled);
24491
}
24592
}
24693

0 commit comments

Comments
 (0)