nhtrace /trunk/NHTraceVSPackage/WebBrowserEx.cs

Language C# Lines 147
MD5 Hash 03299462349ce5251df6c6a45145a171 Estimated Cost $3,069 (why?)
Repository https://nhtrace.svn.codeplex.com/svn View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace NHTrace
{
	public class WebBrowserEx : System.Windows.Forms.WebBrowser
	{
		#region WebBrowserSiteEx Class
		protected class WebBrowserSiteEx : System.Windows.Forms.WebBrowser.WebBrowserSite, IServiceProvider, IInternetSecurityManager
		{
			private static Guid IID_IInternetSecurityManager = 
				Marshal.GenerateGuidForType(typeof(IInternetSecurityManager));

			private WebBrowserEx _webBrowser;

			public WebBrowserSiteEx(WebBrowserEx webBrowser) : base(webBrowser)
			{
				_webBrowser = webBrowser;
			}

			#region IServiceProvider Members
			public int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObject)
			{
				if(guidService == IID_IInternetSecurityManager &&
					riid == IID_IInternetSecurityManager)
				{
					ppvObject = Marshal.GetComInterfaceForObject(this,
						typeof(IInternetSecurityManager));
					return Constants.S_OK;
				}
				ppvObject = IntPtr.Zero;
				return Constants.E_NOINTERFACE;
			}
			#endregion IServiceProvider Members

			#region IInternetSecurityManager Members
			public unsafe int SetSecuritySite(void* pSite)
			{
			    return Constants.INET_E_DEFAULT_ACTION;
			}

			public unsafe int GetSecuritySite(void** ppSite)
			{
			    return Constants.INET_E_DEFAULT_ACTION;
			}

			public unsafe int MapUrlToZone(string url, int* pdwZone, int dwFlags)
			{
        *pdwZone = 0;//local -> "Local", "Intranet", "Trusted", "Internet", "Restricted"
        return Constants.S_OK;
			}

			public unsafe int GetSecurityId(string url, byte* pbSecurityId, int* pcbSecurityId, int dwReserved)
			{
        return Constants.INET_E_DEFAULT_ACTION;
			}

			public unsafe int ProcessUrlAction(string url, int dwAction, byte* pPolicy, int cbPolicy,
				byte* pContext, int cbContext, int dwFlags, int dwReserved)
			{
        *((int*)pPolicy) = (int)Constants.UrlPolicy.URLPOLICY_ALLOW;
        return Constants.S_OK;
			}

			public unsafe int QueryCustomPolicy(string pwszUrl, void* guidKey, byte** ppPolicy, int* pcbPolicy, byte* pContext, int cbContext, int dwReserved)
			{
			    return Constants.INET_E_DEFAULT_ACTION;
			}

			public int SetZoneMapping(int dwZone, string lpszPattern, int dwFlags)
			{
			    return Constants.INET_E_DEFAULT_ACTION;
			}

			public unsafe int GetZoneMappings(int dwZone, void** ppenumString, int dwFlags)
			{
			    return Constants.INET_E_DEFAULT_ACTION;
			}
			#endregion

		}
		#endregion WebBrowserSiteEx Class

		private WebBrowserSiteEx _site;

		public WebBrowserEx()
		{
		}

		protected override WebBrowserSiteBase CreateWebBrowserSiteBase()
		{
			if(_site == null)
				_site = new WebBrowserSiteEx(this);
			return _site;
		}

	}

  [ComImport]
  [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  [Guid("6d5140c1-7436-11ce-8034-00aa006009fa")]
  public interface IServiceProvider
  {
    [PreserveSig]
    int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObject);
  }

  [ComImport]
  [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  [Guid("79eac9ee-baf9-11ce-8c82-00aa004ba90b")]
  public interface IInternetSecurityManager
  {
    [PreserveSig]
    unsafe int SetSecuritySite(void* pSite);
    [PreserveSig]
    unsafe int GetSecuritySite(void** ppSite);
    [PreserveSig]
    unsafe int MapUrlToZone([In, MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, int* pdwZone, [In] int dwFlags);
    [PreserveSig]
    unsafe int GetSecurityId([In, MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, byte* pbSecurityId, int* pcbSecurityId, int dwReserved);
    [PreserveSig]
    unsafe int ProcessUrlAction([In, MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, int dwAction, byte* pPolicy, int cbPolicy, byte* pContext, int cbContext, int dwFlags, int dwReserved);
    [PreserveSig]
    unsafe int QueryCustomPolicy([In, MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, void* guidKey, byte** ppPolicy, int* pcbPolicy, byte* pContext, int cbContext, int dwReserved);
    [PreserveSig]
    int SetZoneMapping(int dwZone, [In, MarshalAs(UnmanagedType.LPWStr)] string lpszPattern, int dwFlags);
    [PreserveSig]
    unsafe int GetZoneMappings(int dwZone, void** ppenumString, int dwFlags);
  }

  public static class Constants
  {
    public const int S_OK = 0;
    public const int E_NOINTERFACE = unchecked((int)0x80004002);
    public const int INET_E_DEFAULT_ACTION = unchecked((int)0x800C0011);
    public enum UrlPolicy
    {
      URLPOLICY_ALLOW = 0,
      URLPOLICY_QUERY = 1,
      URLPOLICY_DISALLOW = 3,
    }
  }
}
Back to Top