Adding reference source for System.Net
[mono.git] / mcs / class / referencesource / System / net / System / Net / _ComImports.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="_ComImports.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6
7 #define AUTOPROXY_MANAGED_JSCRIPT
8 #if !AUTOPROXY_MANAGED_JSCRIPT
9
10 namespace System.Net.ComImports
11 {
12     using System.Runtime.InteropServices;
13     using EXCEPINFO = System.Runtime.InteropServices.ComTypes.EXCEPINFO;
14
15     //
16     // HRESULTs
17     //
18
19     internal enum HRESULT
20     {
21         TYPE_E_ELEMENTNOTFOUND  = unchecked((int) 0x8002802B),
22         SCRIPT_E_REPORTED       = unchecked((int) 0x80020101),
23         E_NOTIMPL               = unchecked((int)0x80004001),
24         E_NOINTERFACE           = unchecked((int)0x80004002),
25         S_OK                    = 0x00000000,
26         S_FALSE                 = 0x00000001
27     }
28
29
30     //
31     // Scripting Interfaces
32     //
33
34     internal enum ScriptState : uint
35     {
36         Uninitialized   = 0,
37         Started         = 1,
38         Connected       = 2,
39         Disconnected    = 3,
40         Closed          = 4,
41         Initialized     = 5,
42     }
43
44     internal enum ScriptThreadState : uint
45     {
46         NotInScript = 0,
47         Running     = 1,
48     }
49
50     [Flags]
51     internal enum ScriptText : uint
52     {
53         None                = 0x0000,
54
55         DelayExecution      = 0x0001,
56         IsVisible           = 0x0002,
57         IsExpression        = 0x0020,
58         IsPersistent        = 0x0040,
59         HostManageSource    = 0x0080,
60     }
61
62     [Flags]
63     internal enum ScriptItem : uint
64     {
65         None                = 0x0000,
66
67         IsVisible           = 0x0002,
68         IsSource            = 0x0004,
69         GlobalMembers       = 0x0008,
70         IsPersistent        = 0x0040,
71         CodeOnly            = 0x0200,
72         NoCode              = 0x0400,
73     }
74
75     [Flags]
76     internal enum ScriptInfo : uint
77     {
78         None        = 0x0000,
79
80         IUnknown    = 0x0001,
81         ITypeInfo   = 0x0002,
82     }
83
84     //
85     // A "fake" interface to use to interact with the script itself through IDispatch.
86     // It uses the IDispatch guid.  New methods can be added as needed in any order.
87     //
88     [ComImport]
89     [Guid("00020400-0000-0000-C000-000000000046")]
90     [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
91     internal interface IScript
92     {
93         object FindProxyForURL(string url, string host);
94     }
95
96     [ComImport]
97     [Guid("BB1A2AE1-A4F9-11cf-8F20-00805F2CD064")]
98     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
99     internal interface IActiveScript
100     {
101         void SetScriptSite(IActiveScriptSite pass);
102         void GetScriptSite(Guid riid, out IntPtr site);
103         void SetScriptState(ScriptState state);
104         void GetScriptState(out ScriptState scriptState);
105         void Close();
106         void AddNamedItem(string name, ScriptItem flags);
107         void AddTypeLib(Guid typeLib, uint major, uint minor, uint flags);
108         void GetScriptDispatch(string itemName, out IScript dispatch);
109         void GetCurrentScriptThreadID(out uint thread);
110         void GetScriptThreadID(uint win32ThreadId, out uint thread);
111         void GetScriptThreadState(uint thread, out ScriptThreadState state);
112         void InterruptScriptThread(uint thread, out EXCEPINFO exceptionInfo, uint flags);
113         void Clone(out IActiveScript script);
114     }
115
116     [ComImport]
117     [Guid("DB01A1E3-A42B-11cf-8F20-00805F2CD064")]
118     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
119     internal interface IActiveScriptSite
120     {
121         void GetLCID(out int lcid);
122         void GetItemInfo(
123             string name,
124             ScriptInfo returnMask,
125             [Out] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.IUnknown)] object[] item,
126             [Out] [MarshalAs(UnmanagedType.LPArray)] IntPtr[] typeInfo);
127         void GetDocVersionString(out string version);
128         void OnScriptTerminate(object result, EXCEPINFO exceptionInfo);
129         void OnStateChange(ScriptState scriptState);
130         void OnScriptError(IActiveScriptError scriptError);
131         void OnEnterScript();
132         void OnLeaveScript();
133     }
134
135     internal enum UrlPolicy {
136         DisAllow = 0x03
137     }
138
139     [ComImport(), Guid("6D5140C1-7436-11CE-8034-00AA006009FA"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
140     internal interface IOleServiceProvider {
141         [PreserveSig]
142         int QueryService([In] ref Guid guidService, [In] ref Guid riid, [Out] out IntPtr ppvObject);
143     }
144
145     internal static class ComConstants {
146         public const int INTERFACE_USES_SECURITY_MANAGER = 0x00000008; // Object knows to use IInternetHostSecurityManager
147     }
148
149     [ComImport]
150     [Guid("CB5BDC81-93C1-11cf-8F20-00805F2CD064")]
151     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
152     internal interface IObjectSafety
153     {
154         [return: MarshalAs(UnmanagedType.I4)]
155         [PreserveSig]
156         int GetInterfaceSafetyOptions(ref Guid riid, [Out] out int pdwSupportedOptions, [Out] out int pdwEnabledOptions);
157
158         [return: MarshalAs(UnmanagedType.I4)]
159         [PreserveSig]
160         int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions);
161     }
162
163     [ComImport]
164     [Guid("3af280b6-cb3f-11d0-891e-00c04fb6bfc4")]
165     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
166     internal interface IInternetHostSecurityManager
167     {
168         [return: MarshalAs(UnmanagedType.I4)]
169         [PreserveSig]
170         int GetSecurityId([Out] byte[] pbSecurityId, [In, Out]ref IntPtr pcbSecurityId, IntPtr dwReserved);
171         
172         [return: MarshalAs(UnmanagedType.I4)]
173         [PreserveSig]
174         int ProcessUrlAction(int dwAction, [Out] int[] pPolicy, int cbPolicy, [Out] byte[] pContext, int cbContext, int dwFlags, int dwReserved);
175         
176         [return: MarshalAs(UnmanagedType.I4)]
177         [PreserveSig]
178         int QueryCustomPolicy(Guid guidKey, [Out] out byte[] ppPolicy, [Out] out int pcbPolicy, byte[] pContext, int cbContext, int dwReserved);
179     }
180
181     [ComImport]
182     [Guid("EAE1BA61-A4ED-11cf-8F20-00805F2CD064")]
183     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
184     internal interface IActiveScriptError
185     {
186         void GetExceptionInfo(out EXCEPINFO exceptionInfo);
187         void GetSourcePosition(out uint sourceContext, out uint lineNumber, out int characterPosition);
188         void GetSourceLineText(out string sourceLine);
189     }
190
191     [ComImport]
192     [Guid("BB1A2AE2-A4F9-11cf-8F20-00805F2CD064")]
193     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
194     internal interface IActiveScriptParse32
195     {
196         void InitNew();
197
198         void AddScriptlet(
199             string defaultName,
200             string code,
201             string itemName,
202             string subItemName,
203             string eventName,
204             string delimiter,
205             IntPtr sourceContextCookie,
206             uint startingLineNumber,
207             ScriptText flags,
208             out string name,
209             out EXCEPINFO exceptionInfo);
210
211         void ParseScriptText(
212             string code,
213             string itemName,
214             [MarshalAs(UnmanagedType.IUnknown)] object context,
215             string delimiter,
216             IntPtr sourceContextCookie,
217             uint startingLineNumber,
218             ScriptText flags,
219             [MarshalAs(UnmanagedType.Struct)] out object result,
220             out EXCEPINFO exceptionInfo);
221     }
222
223     [ComImport]
224     [Guid("C7EF7658-E1EE-480E-97EA-D52CB4D76D17")]
225     [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
226     internal interface IActiveScriptParse64
227     {
228         void InitNew();
229
230         void AddScriptlet(
231             string defaultName,
232             string code,
233             string itemName,
234             string subItemName,
235             string eventName,
236             string delimiter,
237             IntPtr sourceContextCookie,
238             uint startingLineNumber,
239             ScriptText flags,
240             out string name,
241             out EXCEPINFO exceptionInfo);
242
243         void ParseScriptText(
244             string code,
245             string itemName,
246             [MarshalAs(UnmanagedType.IUnknown)] object context,
247             string delimiter,
248             IntPtr sourceContextCookie,
249             uint startingLineNumber,
250             ScriptText flags,
251             [MarshalAs(UnmanagedType.Struct)] out object result,
252             out EXCEPINFO exceptionInfo);
253     }
254
255     // Use this helper to deal with the fact that two interfaces with different Guids are required on 32 vs. 64 bit.
256     internal class ActiveScriptParseWrapper
257     {
258         private readonly IActiveScriptParse32 asp32;
259         private readonly IActiveScriptParse64 asp64;
260
261         internal ActiveScriptParseWrapper(object comObject)
262         {
263             if (IntPtr.Size == 4)
264             {
265                 asp32 = (IActiveScriptParse32) comObject;
266             }
267             else
268             {
269                 asp64 = (IActiveScriptParse64) comObject;
270             }
271         }
272
273         internal void InitNew()
274         {
275             if (asp32 != null)
276             {
277                 asp32.InitNew();
278             }
279             else
280             {
281                 asp64.InitNew();
282             }
283         }
284
285         internal void AddScriptlet(
286             string defaultName,
287             string code,
288             string itemName,
289             string subItemName,
290             string eventName,
291             string delimiter,
292             IntPtr sourceContextCookie,
293             uint startingLineNumber,
294             ScriptText flags,
295             out string name,
296             out EXCEPINFO exceptionInfo)
297         {
298             if (asp32 != null)
299             {
300                 asp32.AddScriptlet(defaultName, code, itemName, subItemName, eventName,
301                     delimiter, sourceContextCookie, startingLineNumber, flags, out name, out exceptionInfo);
302             }
303             else
304             {
305                 asp64.AddScriptlet(defaultName, code, itemName, subItemName, eventName,
306                     delimiter, sourceContextCookie, startingLineNumber, flags, out name, out exceptionInfo);
307             }
308         }
309
310         internal void ParseScriptText(
311             string code,
312             string itemName,
313             [MarshalAs(UnmanagedType.IUnknown)] object context,
314             string delimiter,
315             IntPtr sourceContextCookie,
316             uint startingLineNumber,
317             ScriptText flags,
318             [MarshalAs(UnmanagedType.Struct)] out object result,
319             out EXCEPINFO exceptionInfo)
320         {
321             if (asp32 != null)
322             {
323                 asp32.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie,
324                     startingLineNumber, flags, out result, out exceptionInfo);
325             }
326             else
327             {
328                 asp64.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie,
329                     startingLineNumber, flags, out result, out exceptionInfo);
330             }
331         }
332     }
333
334
335     //
336     // COM Classes
337     //
338
339     [ComImport]
340     [Guid("f414c260-6ac0-11cf-b6d1-00aa00bbbb58")]
341     internal class JScriptEngine { }
342 }
343
344 #endif