├── new-microsoft-edge-icon.png ├── Src ├── Interop │ ├── _LARGE_INTEGER.cs │ ├── _ULARGE_INTEGER.cs │ ├── EventRegistrationToken.cs │ ├── _FILETIME.cs │ ├── _RemotableHandle.cs │ ├── tagRECT.cs │ ├── GUID.cs │ ├── IUnknown.cs │ ├── __MIDL_IWinTypes_0009.cs │ ├── __MIDL___MIDL_itf_webview22Elibrary_formatted_0007_0001_0001.cs │ ├── WEBVIEW2_KEY_EVENT_TYPE.cs │ ├── ISequentialStream.cs │ ├── ICoreWebView2CapturePreviewCompletedHandler.cs │ ├── ICoreWebView2ContentLoadingEventHandler.cs │ ├── WEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT.cs │ ├── ICoreWebView2ContainsFullScreenElementChangedEventHandler.cs │ ├── ICoreWebView2ProcessFailedEventArgs.cs │ ├── ICoreWebView2FocusChangedEventHandler.cs │ ├── ICoreWebView2NewWindowRequestedEventHandler.cs │ ├── tagSTATSTG.cs │ ├── ICoreWebView2ExecuteScriptCompletedHandler.cs │ ├── ICoreWebView2MoveFocusRequestedEventHandler.cs │ ├── ICoreWebView2NavigationCompletedEventHandler.cs │ ├── ICoreWebView2ScriptDialogOpeningEventHandler.cs │ ├── ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler.cs │ ├── ICoreWebView2CreateCoreWebView2HostCompletedHandler.cs │ ├── ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler.cs │ ├── ICoreWebView2CallDevToolsProtocolMethodCompletedHandler.cs │ ├── ICoreWebView2DevToolsProtocolEventReceivedEventHandler.cs │ ├── ICoreWebView2DocumentTitleChangedEventHandler.cs │ ├── ICoreWebView2AcceleratorKeyPressedEventHandler.cs │ ├── ICoreWebView2ZoomFactorChangedEventHandler.cs │ ├── ICoreWebView2SourceChangedEventArgs.cs │ ├── ICoreWebView2DevToolsProtocolEventReceiver.cs │ ├── ICoreWebView2HistoryChangedEventHandler.cs │ ├── ICoreWebView2ProcessFailedEventHandler.cs │ ├── ICoreWebView2DevToolsProtocolEventReceivedEventArgs.cs │ ├── ICoreWebView2WindowCloseRequestedEventHandler.cs │ ├── ICoreWebView2NewBrowserVersionAvailableEventHandler.cs │ ├── ICoreWebView2PermissionRequestedEventHandler.cs │ ├── ICoreWebView2SourceChangedEventHandler.cs │ ├── WEBVIEW2_MOVE_FOCUS_REASON.cs │ ├── WEBVIEW2_PERMISSION_STATE.cs │ ├── ICoreWebView2NavigationStartingEventHandler.cs │ ├── ICoreWebView2NewBrowserVersionAvailableEventArgs.cs │ ├── ICoreWebView2WebMessageReceivedEventHandler.cs │ ├── ICoreWebView2ContentLoadingEventArgs.cs │ ├── ICoreWebView2Deferral.cs │ ├── ICoreWebView2HttpHeadersCollectionIterator.cs │ ├── ICoreWebView2WebResourceRequestedEventArgs.cs │ ├── WEBVIEW2_SCRIPT_DIALOG_KIND.cs │ ├── ICoreWebView2WebResourceRequestedEventHandler.cs │ ├── ICoreWebView2AcceleratorKeyPressedEventArgs.cs │ ├── IStream.cs │ ├── WEBVIEW2_PHYSICAL_KEY_STATUS.cs │ ├── ICoreWebView2NavigationCompletedEventArgs.cs │ ├── WEBVIEW2_PERMISSION_TYPE.cs │ ├── WEBVIEW2_PROCESS_FAILED_KIND.cs │ ├── ICoreWebView2MoveFocusRequestedEventArgs.cs │ ├── ICoreWebView2HttpResponseHeaders.cs │ ├── ICoreWebView2HttpRequestHeaders.cs │ ├── ICoreWebView2PermissionRequestedEventArgs.cs │ ├── ICoreWebView2WebResourceResponse.cs │ ├── ICoreWebView2Environment.cs │ ├── ICoreWebView2WebResourceRequest.cs │ ├── ICoreWebView2NavigationStartingEventArgs.cs │ ├── ICoreWebView2WebMessageReceivedEventArgs.cs │ ├── WEBVIEW2_WEB_RESOURCE_CONTEXT.cs │ ├── WEBVIEW2_WEB_ERROR_STATUS.cs │ ├── ICoreWebView2ScriptDialogOpeningEventArgs.cs │ ├── ICoreWebView2NewWindowRequestedEventArgs.cs │ └── Globals.cs ├── Wrapper │ ├── EventArgs │ │ ├── ContainsFullScreenElementChangedEventArgs.cs │ │ ├── CapturePreviewCompletedArgs.cs │ │ ├── NewVersionAvailableEventArgs.cs │ │ ├── AcceleratorKeyPressedEventArgs.cs │ │ ├── HistoryChangedEventArgs.cs │ │ ├── WindowCloseRequestedEventArgs.cs │ │ ├── ZoomFactorCompletedEventArgs.cs │ │ ├── CreateWebViewCompletedEventArgs.cs │ │ ├── DocumentTitleChangedEventArgs.cs │ │ ├── FocusChangedEventEventArgs.cs │ │ ├── ExecuteScriptCompletedEventArgs.cs │ │ ├── ProcessFailedEventArgs.cs │ │ ├── EnvironmentCreatedEventArgs.cs │ │ ├── SourceChangedEventArgs.cs │ │ ├── AddScriptToExecuteOnDocumentCreatedCompletedEventArgs.cs │ │ ├── CallDevToolsProtocolMethodCompletedEventArgs.cs │ │ ├── MoveFocusRequestedEventArgs.cs │ │ ├── DevToolsProtocolEventReceivedEventArgs.cs │ │ ├── NavigationCompletedEventArgs.cs │ │ ├── ContentLoadingEventArgs.cs │ │ ├── PermissionRequestedEventArgs.cs │ │ ├── ScriptDialogOpeningEventArgs .cs │ │ ├── NewWindowRequestedEventArgs.cs │ │ ├── WebResourceRequestedEventArgs.cs │ │ ├── NavigationStartingEventArgs.cs │ │ └── WebMessageReceivedEventArgs.cs │ ├── Handlers │ │ ├── HandlerBase.cs │ │ ├── DevToolProtocol.cs │ │ ├── CapturePreviewCompletedHandler .cs │ │ ├── HistoryChangedEventHandler.cs │ │ ├── ProcessFailedEventHandler.cs │ │ ├── SourceChangedEventHandler.cs │ │ ├── ContentLoadingEventHandler.cs │ │ ├── CreateWebViewCompletedHandler.cs │ │ ├── DocumentTitleChangedEventHandler.cs │ │ ├── NewWindowRequestedEventHandler.cs │ │ ├── ExecuteScriptCompletedHandler.cs │ │ ├── ScriptDialogOpeningEventHandler.cs │ │ ├── MoveFocusRequestedEventHandler.cs │ │ ├── NavigationStartingEventHandler.cs │ │ ├── PermissionRequestedEventHandler.cs │ │ ├── ZoomFactorChangedEventHandler.cs │ │ ├── WebMessageReceivedEventHandler.cs │ │ ├── AcceleratorKeyPressedEventHandler.cs │ │ ├── FocusChangedEventHandler.cs │ │ ├── ContainsFullScreenElementChangedEventHandler.cs │ │ ├── NewVersionAvailableEventHandler.cs │ │ ├── WindowCloseRequestedEventHandler.cs │ │ ├── EnvironmentCompletedHandler.cs │ │ ├── NavigationCompletedEventHandler.cs │ │ ├── AddScriptToExecuteOnDocumentCreatedCompletedHandler.cs │ │ ├── CallDevToolsProtocolMethodCompletedHandler.cs │ │ ├── DevToolsProtocolEventReceivedEventHandler.cs │ │ └── WebResourceRequestedEventHandler.cs │ ├── WebView2Deferral.cs │ ├── WebView2WebResourceResponse.cs │ ├── WebView2HttpResponseHeaderCollection.cs │ ├── WebView2DevToolsProtocolEventReceiver.cs │ ├── WebView2WebResourceRequest.cs │ ├── WebView2HttpRequestHeaderCollection.cs │ └── WebView2Loader.cs ├── Properties │ └── AssemblyInfo.cs ├── WebView2.Interop.nuspec ├── WebView2.Interop.sln └── ExternDll.cs ├── .gitattributes ├── LICENSE └── README.md /new-microsoft-edge-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michael-russin/webview2-interop/HEAD/new-microsoft-edge-icon.png -------------------------------------------------------------------------------- /Src/Interop/_LARGE_INTEGER.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | public struct _LARGE_INTEGER 6 | { 7 | public long QuadPart; 8 | } 9 | } -------------------------------------------------------------------------------- /Src/Interop/_ULARGE_INTEGER.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | public struct _ULARGE_INTEGER 6 | { 7 | public ulong QuadPart; 8 | } 9 | } -------------------------------------------------------------------------------- /Src/Interop/EventRegistrationToken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | public struct EventRegistrationToken 6 | { 7 | public long @value; 8 | } 9 | } -------------------------------------------------------------------------------- /Src/Interop/_FILETIME.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | public struct _FILETIME 6 | { 7 | public uint dwLowDateTime; 8 | 9 | public uint dwHighDateTime; 10 | } 11 | } -------------------------------------------------------------------------------- /Src/Interop/_RemotableHandle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | public struct _RemotableHandle 6 | { 7 | public int fContext; 8 | 9 | public __MIDL_IWinTypes_0009 u; 10 | } 11 | } -------------------------------------------------------------------------------- /Src/Interop/tagRECT.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | public struct tagRECT 6 | { 7 | public int left; 8 | 9 | public int top; 10 | 11 | public int right; 12 | 13 | public int bottom; 14 | } 15 | } -------------------------------------------------------------------------------- /Src/Interop/GUID.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | public struct GUID 6 | { 7 | public uint Data1; 8 | 9 | public ushort Data2; 10 | 11 | public ushort Data3; 12 | 13 | public byte[] Data4; 14 | } 15 | } -------------------------------------------------------------------------------- /Src/Interop/IUnknown.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | [Guid("00000000-0000-0000-C000-000000000046")] 6 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 7 | public interface IUnknown 8 | { 9 | 10 | } 11 | } -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/ContainsFullScreenElementChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Wrapper 4 | { 5 | public class ContainsFullScreenElementChangedEventArgs : EventArgs 6 | { 7 | internal ContainsFullScreenElementChangedEventArgs() 8 | { 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Src/Interop/__MIDL_IWinTypes_0009.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MtrDev.WebView2.Interop 5 | { 6 | [StructLayout(LayoutKind.Explicit)] 7 | public struct __MIDL_IWinTypes_0009 8 | { 9 | [FieldOffset(0)] 10 | public int hInproc; 11 | 12 | [FieldOffset(0)] 13 | public int hRemote; 14 | } 15 | } -------------------------------------------------------------------------------- /Src/Interop/__MIDL___MIDL_itf_webview22Elibrary_formatted_0007_0001_0001.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | public struct __MIDL___MIDL_itf_webview22Elibrary_formatted_0007_0001_0001 6 | { 7 | public uint Data1; 8 | 9 | public ushort Data2; 10 | 11 | public ushort Data3; 12 | 13 | public byte[] Data4; 14 | } 15 | } -------------------------------------------------------------------------------- /Src/Interop/WEBVIEW2_KEY_EVENT_TYPE.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MtrDev.WebView2.Interop 8 | { 9 | public enum WEBVIEW2_KEY_EVENT_TYPE 10 | { 11 | WEBVIEW2_KEY_EVENT_TYPE_KEY_DOWN = 0, 12 | WEBVIEW2_KEY_EVENT_TYPE_KEY_UP = 1, 13 | WEBVIEW2_KEY_EVENT_TYPE_SYSTEM_KEY_DOWN = 2, 14 | WEBVIEW2_KEY_EVENT_TYPE_SYSTEM_KEY_UP = 3 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Src/Interop/ISequentialStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | [Guid("0C733A30-2A1C-11CE-ADE5-00AA0044773D")] 8 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 9 | public interface __ISequentialStream 10 | { 11 | 12 | void RemoteRead(out byte pv, [In] uint cb, out uint pcbRead); 13 | 14 | 15 | void RemoteWrite([In] ref byte pv, [In] uint cb, out uint pcbWritten); 16 | } 17 | } -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/CapturePreviewCompletedArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Wrapper 4 | { 5 | public class CapturePreviewCompletedArgs : EventArgs 6 | { 7 | internal CapturePreviewCompletedArgs(int result) 8 | { 9 | Result = result; 10 | } 11 | 12 | public int Result { get; private set; } 13 | 14 | public override string ToString() 15 | { 16 | return string.Format("Result={0}", Result); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2CapturePreviewCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("A1A2EC1C-B5C3-4EB2-9BCB-9166AFAA0E85")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2CapturePreviewCompletedHandler 15 | { 16 | 17 | void Invoke([In] int result); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyVersion("0.9.430.3")] 5 | [assembly: Guid("A4B17755-18D0-4FE3-B81E-E758DB965F9D")] 6 | //[assembly: ImportedFromTypeLib("WebView2")] 7 | [assembly: TypeLibVersion(1, 0)] 8 | [assembly: AssemblyTitle("WebView2 Interop")] 9 | [assembly: AssemblyDescription("Interop for Microsoft WebView2")] 10 | [assembly: AssemblyCompany("MtrDev")] 11 | [assembly: AssemblyProduct("WebView2 Interop")] 12 | [assembly: AssemblyCopyright("Copyright © Mike Russin 2020")] 13 | 14 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2ContentLoadingEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MtrDev.WebView2.Interop 5 | { 6 | [ComVisible(true)] 7 | [ComImport] 8 | [Guid("70057D5C-0BAA-4219-97B0-FFF1C088ED32")] 9 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 10 | public interface ICoreWebView2ContentLoadingEventHandler 11 | { 12 | void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2 webview, [In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2ContentLoadingEventArgs args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Src/Interop/WEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | /// 6 | /// Image format used by the IWebView2WebView::CapturePreview method. 7 | /// 8 | public enum WEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT 9 | { 10 | /// 11 | /// PNG image format. 12 | /// 13 | WEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_PNG, 14 | /// 15 | /// JPEG image format. 16 | /// 17 | WEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_JPEG 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2ContainsFullScreenElementChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MtrDev.WebView2.Interop 5 | { 6 | [ComVisible(true)] 7 | [ComImport] 8 | [Guid("EC2AF7C6-4579-40AB-8C36-5CCEE58EB7CB")] 9 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 10 | public interface ICoreWebView2ContainsFullScreenElementChangedEventHandler 11 | { 12 | void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2 webview, [In, MarshalAs(UnmanagedType.Interface)] object args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2ProcessFailedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MtrDev.WebView2.Interop 5 | { 6 | /// 7 | /// Checked 8 | /// 9 | [ComVisible(true)] 10 | [ComImport] 11 | [Guid("9E354785-CFA2-480A-84E0-57837ADD8E36")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | public interface ICoreWebView2ProcessFailedEventArgs 14 | { 15 | [DispId(1610678272)] 16 | WEBVIEW2_PROCESS_FAILED_KIND ProcessFailedKind 17 | { 18 | 19 | get; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2FocusChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("19F31771-9BB5-422B-9A0A-6EDDAF4FFE0F")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2FocusChangedEventHandler 15 | { 16 | 17 | void Invoke([In] ICoreWebView2Host webview, [In, MarshalAs(UnmanagedType.IUnknown)] object args); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2NewWindowRequestedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("715E10DD-2323-4F03-B6B3-AB34006B96D5")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2NewWindowRequestedEventHandler 15 | { 16 | 17 | void Invoke([In] ICoreWebView2 webview, [In] ICoreWebView2NewWindowRequestedEventArgs args); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/tagSTATSTG.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MtrDev.WebView2.Interop 5 | { 6 | public struct tagSTATSTG 7 | { 8 | public string pwcsName; 9 | 10 | public uint type; 11 | 12 | public _ULARGE_INTEGER cbSize; 13 | 14 | public _FILETIME mtime; 15 | 16 | public _FILETIME ctime; 17 | 18 | public _FILETIME atime; 19 | 20 | public uint grfMode; 21 | 22 | public uint grfLocksSupported; 23 | 24 | [ComAliasName("MtrDev.WebView2.Interop.GUID")] 25 | public GUID clsid; 26 | 27 | public uint grfStateBits; 28 | 29 | public uint reserved; 30 | } 31 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2ExecuteScriptCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("51457AE2-93FD-404E-A957-3D6034EAD733")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2ExecuteScriptCompletedHandler 15 | { 16 | 17 | void Invoke([In] int errorCode, [In, MarshalAs(UnmanagedType.LPWStr)] string resultObjectAsJson); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2MoveFocusRequestedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("01BA7131-3DBE-4C83-A789-99C467A2C3F5")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2MoveFocusRequestedEventHandler 15 | { 16 | 17 | void Invoke([In] ICoreWebView2Host webview, [In] ICoreWebView2MoveFocusRequestedEventArgs args); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2NavigationCompletedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("17EB2F75-B65B-4E5F-A0E1-933126DDD5BB")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2NavigationCompletedEventHandler 15 | { 16 | 17 | void Invoke([In] ICoreWebView2 webview, [In] ICoreWebView2NavigationCompletedEventArgs args); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2ScriptDialogOpeningEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("E4CDFD7A-AA15-4738-8A8F-4C8C28A9BAC1")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2ScriptDialogOpeningEventHandler 15 | { 16 | 17 | void Invoke([In] ICoreWebView2 webview, [In] ICoreWebView2ScriptDialogOpeningEventArgs args); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("7ED79562-90E1-47CD-A4E0-01D9211D7E3D")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler 15 | { 16 | 17 | void Invoke(int result, ICoreWebView2Environment webViewEnvironment); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2CreateCoreWebView2HostCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("E09F5D38-91E3-49D1-8182-70A616AA06B9")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2CreateCoreWebView2HostCompletedHandler 15 | { 16 | 17 | void Invoke([In] int result, [In] ICoreWebView2Host host); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("8889C588-9DC7-4266-9BB3-369AFDDE2A7F")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler 15 | { 16 | 17 | void Invoke([In] int errorCode, [In, MarshalAs(UnmanagedType.LPWStr)] string id); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2CallDevToolsProtocolMethodCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("B7627F5F-8723-4ED3-AC20-F93104CDEA51")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2CallDevToolsProtocolMethodCompletedHandler 15 | { 16 | 17 | void Invoke([In] int errorCode, [In, MarshalAs(UnmanagedType.LPWStr)] string returnObjectAsJson); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2DevToolsProtocolEventReceivedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("8B0DF849-2D94-47FB-8072-FE7A4D5FBA6A")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2DevToolsProtocolEventReceivedEventHandler 15 | { 16 | 17 | void Invoke([In] ICoreWebView2 webview, [In] ICoreWebView2DevToolsProtocolEventReceivedEventArgs args); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2DocumentTitleChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("CF313728-68BC-4577-9A35-08E660544AD9")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2DocumentTitleChangedEventHandler 15 | { 16 | void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2 webview, [In, MarshalAs(UnmanagedType.Interface)] object args); 17 | } 18 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2AcceleratorKeyPressedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("253D0AA2-6F85-4FB2-9D6B-0DC5FEDBB085")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2AcceleratorKeyPressedEventHandler 15 | { 16 | void Invoke([In] ICoreWebView2Host webview, [In] ICoreWebView2AcceleratorKeyPressedEventArgs args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2ZoomFactorChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("1B03A40F-92B7-443A-87E0-B65714B6CB9D")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2ZoomFactorChangedEventHandler 15 | { 16 | 17 | void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2Host webview, [In, MarshalAs(UnmanagedType.Interface)] object args); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2SourceChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("26D4B817-9496-4F67-AEAB-24EB38482037")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2SourceChangedEventArgs 15 | { 16 | bool IsNewDocument 17 | { 18 | [return: MarshalAs(UnmanagedType.Bool)] 19 | get; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2DevToolsProtocolEventReceiver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MtrDev.WebView2.Interop 5 | { 6 | [ComVisible(true)] 7 | [ComImport] 8 | [Guid("13FC668D-1F6D-4955-A4F4-D1EE7DEB5B74")] 9 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 10 | public interface ICoreWebView2DevToolsProtocolEventReceiver 11 | { 12 | void add_DevToolsProtocolEventReceived([In] ICoreWebView2DevToolsProtocolEventReceivedEventHandler eventHandler, out EventRegistrationToken token); 13 | 14 | void remove_DevToolsProtocolEventReceived([In] EventRegistrationToken token); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2HistoryChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("29211B19-F775-48CC-9757-5DA3CA1F626A")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2HistoryChangedEventHandler 15 | { 16 | void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2 webview, [In, MarshalAs(UnmanagedType.IUnknown)] object args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2ProcessFailedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("A85C66A9-DE47-47F7-AD64-ABB32F1CF14D")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2ProcessFailedEventHandler 15 | { 16 | 17 | void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2 webview, [In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2ProcessFailedEventArgs args); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2DevToolsProtocolEventReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("7EF09904-8B46-4FE1-87FF-5A28EFAF7723")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2DevToolsProtocolEventReceivedEventArgs 15 | { 16 | [DispId(1610678272)] 17 | string ParameterObjectAsJson 18 | { 19 | [return: MarshalAs(UnmanagedType.LPWStr)] 20 | get; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2WindowCloseRequestedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("1AE0297A-9671-4ED6-902A-4544B9B4AECD")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2WindowCloseRequestedEventHandler 15 | { 16 | void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2 webview, [In, MarshalAs(UnmanagedType.Interface)] object args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2NewBrowserVersionAvailableEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("865E16C4-A24D-4AC1-BC23-2E608CA313F9")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2NewBrowserVersionAvailableEventHandler 15 | { 16 | void Invoke([In] ICoreWebView2Environment webViewEnvironment, [In] ICoreWebView2NewBrowserVersionAvailableEventArgs args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2PermissionRequestedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("7079A1F0-CF14-4046-8E26-46BF54163673")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2PermissionRequestedEventHandler 15 | { 16 | 17 | void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2 webview, [In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2PermissionRequestedEventArgs args); 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2SourceChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("E345159A-B573-41AB-A4F7-F94CB238AF45")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2SourceChangedEventHandler 15 | { 16 | void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2 webview, [In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2SourceChangedEventArgs args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Src/Interop/WEBVIEW2_MOVE_FOCUS_REASON.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | /// 6 | /// Reason for moving focus. 7 | /// 8 | public enum WEBVIEW2_MOVE_FOCUS_REASON 9 | { 10 | /// 11 | /// Code setting focus into WebView. 12 | /// 13 | WEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC, 14 | /// 15 | /// Moving focus due to Tab traversal forward. 16 | /// 17 | WEBVIEW2_MOVE_FOCUS_REASON_NEXT, 18 | /// 19 | /// Moving focus due to Tab traversal backward. 20 | /// 21 | WEBVIEW2_MOVE_FOCUS_REASON_PREVIOUS 22 | } 23 | } -------------------------------------------------------------------------------- /Src/Interop/WEBVIEW2_PERMISSION_STATE.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | /// 6 | /// Response to a permission request. 7 | /// 8 | public enum WEBVIEW2_PERMISSION_STATE 9 | { 10 | /// 11 | /// Use default browser behavior, which normally prompt users for decision. 12 | /// 13 | WEBVIEW2_PERMISSION_STATE_DEFAULT, 14 | /// 15 | /// Grant the permission request. 16 | /// 17 | WEBVIEW2_PERMISSION_STATE_ALLOW, 18 | /// 19 | /// Deny the permission request. 20 | /// 21 | WEBVIEW2_PERMISSION_STATE_DENY 22 | } 23 | } -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/NewVersionAvailableEventArgs.cs: -------------------------------------------------------------------------------- 1 | using MtrDev.WebView2.Interop; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Wrapper 9 | { 10 | public class NewVersionAvailableEventArgs : EventArgs, ICoreWebView2NewBrowserVersionAvailableEventArgs 11 | { 12 | private ICoreWebView2NewBrowserVersionAvailableEventArgs _args; 13 | 14 | public NewVersionAvailableEventArgs(ICoreWebView2NewBrowserVersionAvailableEventArgs args) 15 | { 16 | _args = args; 17 | } 18 | 19 | public string NewVersion => _args.NewVersion; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2NavigationStartingEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("CD2F4CAE-BA09-47F3-94EE-A785CEC7C907")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2NavigationStartingEventHandler 15 | { 16 | void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2 webview, [In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2NavigationStartingEventArgs args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2NewBrowserVersionAvailableEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("5A86C3E7-511B-4F99-BC20-8A8ED5449C12")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2NewBrowserVersionAvailableEventArgs 15 | { 16 | [DispId(1610678272)] 17 | string NewVersion 18 | { 19 | [return: MarshalAs(UnmanagedType.LPWStr)] 20 | get; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2WebMessageReceivedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("ABABDC66-DF8D-487D-A737-7B25E8F835AA")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2WebMessageReceivedEventHandler 15 | { 16 | 17 | // void Invoke([In] IWebView2WebView webview, [In] IWebView2WebMessageReceivedEventArgs args); 18 | void Invoke([In] ICoreWebView2 webview, [In] ICoreWebView2WebMessageReceivedEventArgs args); 19 | } 20 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2ContentLoadingEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("696ED8C1-4657-4769-928F-10EF8040ED25")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2ContentLoadingEventArgs 15 | { 16 | bool IsErrorPage 17 | { 18 | [return: MarshalAs(UnmanagedType.Bool)] 19 | get; 20 | } 21 | 22 | long NavigationId 23 | { 24 | [return: MarshalAs(UnmanagedType.I8)] 25 | get; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2Deferral.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// This interface is used to complete deferrals on event args that 9 | /// support getting deferrals via their GetDeferral method. 10 | /// 11 | [ComVisible(true)] 12 | [ComImport] 13 | [Guid("C1000D7C-4817-40EB-A2AE-3B929D5A8EE3")] 14 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 15 | public interface ICoreWebView2Deferral 16 | { 17 | /// 18 | /// Completes the associated deferred event. Complete should only be 19 | /// called once for each deferral taken. 20 | /// 21 | void Complete(); 22 | } 23 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2HttpHeadersCollectionIterator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Checked 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("B0F8A736-CC49-4414-BB9C-FDBC02599622")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2HttpHeadersCollectionIterator 15 | { 16 | 17 | void GetCurrentHeader([MarshalAs(UnmanagedType.LPWStr)] out string name, [MarshalAs(UnmanagedType.LPWStr)] out string value); 18 | 19 | 20 | [DispId(1610678273)] 21 | bool HasCurrentHeader 22 | { 23 | [return: MarshalAs(UnmanagedType.Bool)] 24 | get; 25 | } 26 | 27 | void MoveNext(out int has_next); 28 | } 29 | } -------------------------------------------------------------------------------- /Src/WebView2.Interop.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | MIT 10 | https://github.com/michael-russin/webview2-interop 11 | false 12 | $description$ 13 | Interop based off Microsoft WebView2 release 0.8.270 14 | Copyright 2019 15 | WebView2 Interop Edge Chromium 16 | 17 | 18 | 19 | 20 | 23 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2WebResourceRequestedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("6EF9912F-5A9D-42A9-8C17-9BB53E1D5C63")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2WebResourceRequestedEventArgs 15 | { 16 | [DispId(1610678272)] 17 | ICoreWebView2WebResourceRequest Request 18 | { 19 | get; 20 | } 21 | 22 | [DispId(1610678273)] 23 | ICoreWebView2WebResourceResponse Response 24 | { 25 | get; 26 | set; 27 | } 28 | 29 | ICoreWebView2Deferral GetDeferral(); 30 | 31 | void ResourceContext(ref WEBVIEW2_WEB_RESOURCE_CONTEXT context); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Src/Interop/WEBVIEW2_SCRIPT_DIALOG_KIND.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | /// 6 | /// Kind of JavaScript dialog used in the IWebView2ScriptDialogOpeningEventHandler 7 | /// interface. 8 | /// 9 | public enum WEBVIEW2_SCRIPT_DIALOG_KIND 10 | { 11 | /// 12 | /// A dialog invoked via the window.alert JavaScript function. 13 | /// 14 | WEBVIEW2_SCRIPT_DIALOG_KIND_ALERT, 15 | /// 16 | /// A dialog invoked via the window.confirm JavaScript function. 17 | /// 18 | WEBVIEW2_SCRIPT_DIALOG_KIND_CONFIRM, 19 | /// 20 | /// A dialog invoked via the window.prompt JavaScript function. 21 | /// 22 | WEBVIEW2_SCRIPT_DIALOG_KIND_PROMPT, 23 | /// 24 | /// A dialog invoked via the beforeunload JavaScript event. 25 | WEBVIEW2_SCRIPT_DIALOG_KIND_BEFOREUNLOAD 26 | /// 27 | } 28 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2WebResourceRequestedEventHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Fires when an HTTP request is made in the webview. The host can override 9 | /// request, response headers and response content. 10 | /// 11 | [ComVisible(true)] 12 | [ComImport] 13 | [Guid("A8DC0663-3C2C-4190-8129-5F1F598CA7B8")] 14 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 15 | public interface ICoreWebView2WebResourceRequestedEventHandler 16 | { 17 | /// 18 | /// Called to provide the implementer with the event args for the 19 | /// corresponding event. 20 | /// 21 | /// 22 | /// 23 | void Invoke([In] ICoreWebView2 webview, 24 | [In] ICoreWebView2WebResourceRequestedEventArgs args); 25 | } 26 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2AcceleratorKeyPressedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("AF1587DD-E2FF-4BFF-8C1A-699D6D34C683")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2AcceleratorKeyPressedEventArgs 15 | { 16 | [DispId(1610678272)] 17 | WEBVIEW2_KEY_EVENT_TYPE KeyEventType 18 | { 19 | get; 20 | } 21 | 22 | [DispId(1610678273)] 23 | uint VirtualKey 24 | { 25 | get; 26 | } 27 | 28 | 29 | [DispId(1610678274)] 30 | int KeyEventLParam 31 | { 32 | get; 33 | } 34 | 35 | 36 | [DispId(1610678275)] 37 | WEBVIEW2_PHYSICAL_KEY_STATUS PhysicalKeyStatus 38 | { 39 | get; 40 | } 41 | 42 | 43 | void Handle([In] int handled); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 michael-russin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/AcceleratorKeyPressedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using MtrDev.WebView2.Interop; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Wrapper 6 | { 7 | public class AcceleratorKeyPressedEventArgs: EventArgs, ICoreWebView2AcceleratorKeyPressedEventArgs 8 | { 9 | private ICoreWebView2AcceleratorKeyPressedEventArgs _args; 10 | 11 | internal AcceleratorKeyPressedEventArgs(ICoreWebView2AcceleratorKeyPressedEventArgs args) 12 | { 13 | _args = args; 14 | } 15 | 16 | public WEBVIEW2_KEY_EVENT_TYPE KeyEventType => _args.KeyEventType; 17 | 18 | public uint VirtualKey => _args.VirtualKey; 19 | 20 | public int KeyEventLParam => _args.KeyEventLParam; 21 | 22 | public WEBVIEW2_PHYSICAL_KEY_STATUS PhysicalKeyStatus => _args.PhysicalKeyStatus; 23 | 24 | public void Handle([In] int handled) 25 | { 26 | _args.Handle(handled); 27 | } 28 | 29 | public override string ToString() 30 | { 31 | return string.Format("KeyEventType={0}, VirtualKey={1}, KeyEventLParam={2}, PhysicalKeyStatus={3} ", 32 | KeyEventType, VirtualKey, KeyEventLParam, PhysicalKeyStatus); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Src/Interop/IStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | #pragma warning disable CS0108 8 | 9 | [Guid("0000000C-0000-0000-C000-000000000046")] 10 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 11 | public interface __IStream : __ISequentialStream 12 | { 13 | 14 | void Clone(out __IStream ppstm); 15 | 16 | 17 | void Commit([In] uint grfCommitFlags); 18 | 19 | 20 | void LockRegion([In] _ULARGE_INTEGER libOffset, [In] _ULARGE_INTEGER cb, [In] uint dwLockType); 21 | 22 | 23 | void RemoteCopyTo([In] __IStream pstm, [In] _ULARGE_INTEGER cb, out _ULARGE_INTEGER pcbRead, out _ULARGE_INTEGER pcbWritten); 24 | 25 | 26 | void RemoteRead(out byte pv, [In] uint cb, out uint pcbRead); 27 | 28 | 29 | void RemoteSeek([In] _LARGE_INTEGER dlibMove, [In] uint dwOrigin, out _ULARGE_INTEGER plibNewPosition); 30 | 31 | 32 | void RemoteWrite([In] ref byte pv, [In] uint cb, out uint pcbWritten); 33 | 34 | 35 | void Revert(); 36 | 37 | 38 | void SetSize([In] _ULARGE_INTEGER libNewSize); 39 | 40 | 41 | void Stat(out tagSTATSTG pstatstg, [In] uint grfStatFlag); 42 | 43 | 44 | void UnlockRegion([In] _ULARGE_INTEGER libOffset, [In] _ULARGE_INTEGER cb, [In] uint dwLockType); 45 | } 46 | } -------------------------------------------------------------------------------- /Src/Interop/WEBVIEW2_PHYSICAL_KEY_STATUS.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace MtrDev.WebView2.Interop 5 | { 6 | /// 7 | /// A structure representing the information packed into the LPARAM given 8 | /// to a Win32 key event. See the documentation for WM_KEYDOWN for details 9 | /// at https://docs.microsoft.com/windows/win32/inputdev/wm-keydown 10 | /// 11 | [StructLayout(LayoutKind.Sequential)] 12 | public struct WEBVIEW2_PHYSICAL_KEY_STATUS 13 | { 14 | /// 15 | /// The repeat count for the current message. 16 | /// /// 17 | public uint RepeatCount; 18 | 19 | /// 20 | /// The scan code. 21 | /// 22 | public uint ScanCode; 23 | 24 | /// 25 | /// Indicates whether the key is an extended key. 26 | /// 27 | public int IsExtendedKey; 28 | 29 | /// 30 | /// The context code. 31 | /// 32 | public int IsMenuKeyDown; 33 | 34 | /// 35 | /// The previous key state. 36 | /// 37 | public int WasKeyDown; 38 | 39 | /// 40 | /// The transition state. 41 | /// 42 | public int IsKeyReleased; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2NavigationCompletedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Event args for the NavigationCompleted event. 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("1337EED4-BC5B-48FB-9672-80D18733CFD5")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2NavigationCompletedEventArgs 15 | { 16 | /// 17 | /// True when the navigation is successful. This 18 | /// is false for a navigation that ended up in an error page (failures due to 19 | /// no network, DNS lookup failure, HTTP server responds with 4xx), but could 20 | /// also be false for additional things such as window.stop() called on 21 | /// navigated page. 22 | /// 23 | [DispId(1610678272)] 24 | bool IsSuccess 25 | { 26 | [return: MarshalAs(UnmanagedType.Bool)] 27 | get; 28 | } 29 | 30 | /// 31 | /// The error code if the navigation failed. 32 | /// 33 | [DispId(1610678273)] 34 | WEBVIEW2_WEB_ERROR_STATUS WebErrorStatus 35 | { 36 | get; 37 | } 38 | 39 | long NavigationId 40 | { 41 | get; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Src/Interop/WEBVIEW2_PERMISSION_TYPE.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | /// 6 | /// The type of a permission request. 7 | /// 8 | public enum WEBVIEW2_PERMISSION_TYPE 9 | { 10 | /// 11 | /// Unknown permission. 12 | /// 13 | WEBVIEW2_PERMISSION_TYPE_UNKNOWN_PERMISSION, 14 | /// 15 | /// Permission to capture audio. 16 | /// 17 | WEBVIEW2_PERMISSION_TYPE_MICROPHONE, 18 | /// 19 | /// Permission to capture video. 20 | /// 21 | WEBVIEW2_PERMISSION_TYPE_CAMERA, 22 | /// 23 | /// Permission to access geolocation. 24 | /// 25 | WEBVIEW2_PERMISSION_TYPE_GEOLOCATION, 26 | /// 27 | /// Permission to send web notifications. 28 | /// 29 | WEBVIEW2_PERMISSION_TYPE_NOTIFICATIONS, 30 | /// 31 | /// Permission to access generic sensor. 32 | /// Generic Sensor covering ambient-light-sensor, accelerometer, gyroscope 33 | /// and magnetometer. 34 | /// 35 | WEBVIEW2_PERMISSION_TYPE_OTHER_SENSORS, 36 | /// 37 | /// Permission to read system clipboard without a user gesture. 38 | /// 39 | WEBVIEW2_PERMISSION_TYPE_CLIPBOARD_READ 40 | } 41 | } -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/HistoryChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using System; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class HistoryChangedEventArgs : EventArgs 31 | { 32 | internal HistoryChangedEventArgs() 33 | { 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/WindowCloseRequestedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using System; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class WindowCloseRequestedEventArgs : EventArgs 31 | { 32 | internal WindowCloseRequestedEventArgs() 33 | { 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Src/WebView2.Interop.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 16 3 | VisualStudioVersion = 16.0.29424.173 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebView2.Interop", "WebView2.Interop.csproj", "{411A56C5-8D28-427E-A558-EB88E4751E45}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Any CPU = Debug|Any CPU 10 | Debug|x86 = Debug|x86 11 | Release|Any CPU = Release|Any CPU 12 | Release|x86 = Release|x86 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {411A56C5-8D28-427E-A558-EB88E4751E45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 16 | {411A56C5-8D28-427E-A558-EB88E4751E45}.Debug|Any CPU.Build.0 = Debug|Any CPU 17 | {411A56C5-8D28-427E-A558-EB88E4751E45}.Debug|x86.ActiveCfg = Debug|x86 18 | {411A56C5-8D28-427E-A558-EB88E4751E45}.Debug|x86.Build.0 = Debug|x86 19 | {411A56C5-8D28-427E-A558-EB88E4751E45}.Release|Any CPU.ActiveCfg = Release|Any CPU 20 | {411A56C5-8D28-427E-A558-EB88E4751E45}.Release|Any CPU.Build.0 = Release|Any CPU 21 | {411A56C5-8D28-427E-A558-EB88E4751E45}.Release|x86.ActiveCfg = Release|x86 22 | {411A56C5-8D28-427E-A558-EB88E4751E45}.Release|x86.Build.0 = Release|x86 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | GlobalSection(ExtensibilityGlobals) = postSolution 28 | SolutionGuid = {0E15441A-B3D0-44FA-99B7-389E146EBF17} 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/ZoomFactorCompletedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | 27 | namespace MtrDev.WebView2.Wrapper 28 | { 29 | public class ZoomFactorCompletedEventArgs : EventArgs 30 | { 31 | public ZoomFactorCompletedEventArgs(object args) 32 | { 33 | } 34 | 35 | public double Factor { get; private set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/HandlerBase.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | 27 | namespace MtrDev.WebView2.Wrapper.Handlers 28 | { 29 | public class HandlerBase 30 | { 31 | public HandlerBase(Action callback) 32 | { 33 | Callback = callback; 34 | } 35 | 36 | protected Action Callback { get; private set; } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Src/Interop/WEBVIEW2_PROCESS_FAILED_KIND.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | /// 6 | /// Kind of process failure used in the IWebView2ProcessFailedEventHandler interface. 7 | /// 8 | public enum WEBVIEW2_PROCESS_FAILED_KIND 9 | { 10 | /// 11 | /// Indicates the browser process terminated unexpectedly. 12 | /// The WebView automatically goes into the Closed state. 13 | /// The app has to recreate a new WebView to recover from this failure. 14 | /// 15 | WEBVIEW2_PROCESS_FAILED_KIND_BROWSER_PROCESS_EXITED, 16 | 17 | /// 18 | /// Indicates the render process terminated unexpectedly. 19 | /// A new render process will be created automatically and navigated to an 20 | /// error page. 21 | /// The app can use Reload to try to recover from this failure. 22 | /// 23 | 24 | WEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_EXITED, 25 | 26 | /// 27 | /// Indicates the render process becomes unresponsive. 28 | /// The app can try to navigate away from the page to recover from the 29 | /// failure. 30 | /// Note that this does not seem to work right now. 31 | /// Does not fire for simple long running script case, the only related test 32 | /// SitePerProcessBrowserTest::NoCommitTimeoutForInvisibleWebContents is 33 | /// disabled. 34 | /// 35 | WEBVIEW2_PROCESS_FAILED_KIND_RENDER_PROCESS_UNRESPONSIVE 36 | } 37 | } -------------------------------------------------------------------------------- /Src/ExternDll.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | using System.Linq; 29 | using System.Text; 30 | using System.Threading.Tasks; 31 | 32 | namespace MtrDev.WebView2 33 | { 34 | internal static class ExternDll 35 | { 36 | public const string User32 = "user32.dll"; 37 | public const string WebView2Loader = "WebView2Loader.dll"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2MoveFocusRequestedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Event args for the MoveFocusRequested event. 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("CE31A597-E202-49B9-A9BE-825481ED517E")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2MoveFocusRequestedEventArgs 15 | { 16 | /// 17 | /// The reason for WebView to fire the MoveFocus Requested event. 18 | /// 19 | [DispId(1610678272)] 20 | WEBVIEW2_MOVE_FOCUS_REASON Reason 21 | { 22 | get; 23 | } 24 | 25 | /// 26 | /// Indicate whether the event has been handled by the app. 27 | /// If the app has moved the focus to its desired location, it should set 28 | /// Handled property to TRUE. 29 | /// When Handled property is false after the event handler returns, default 30 | /// action will be taken. The default action is to try to find the next tab 31 | /// stop child window in the app and try to move focus to that window. If 32 | /// there is no other such window to move focus to, focus will be cycled 33 | /// within the WebView's web content. 34 | /// 35 | [DispId(1610678273)] 36 | bool Handled 37 | { 38 | [return: MarshalAs(UnmanagedType.Bool)] 39 | get; 40 | [param: MarshalAs(UnmanagedType.Bool)] 41 | set; 42 | } 43 | 44 | } 45 | } -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/DevToolProtocol.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | 27 | namespace MtrDev.WebView2.Wrapper.Handlers 28 | { 29 | internal class DevToolProtocol 30 | { 31 | public DevToolProtocol(string eventName, Action callback) 32 | { 33 | EventName = eventName; 34 | Callback = callback; 35 | } 36 | 37 | public string EventName { get; private set; } 38 | 39 | public Action Callback { get; private set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/CreateWebViewCompletedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using MtrDev.WebView2.Interop; 26 | using System; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class CreateWebViewCompletedEventArgs : EventArgs 31 | { 32 | internal CreateWebViewCompletedEventArgs(int result, ICoreWebView2Host webView) 33 | { 34 | Result = result; 35 | WebView = new WebView2WebView(webView); 36 | } 37 | 38 | public int Result { get; private set; } 39 | 40 | public WebView2WebView WebView { get; private set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2HttpResponseHeaders.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// HTTP response headers. Used to construct a WebResourceResponse for the 9 | /// WebResourceRequested event. 10 | /// 11 | [ComVisible(true)] 12 | [ComImport] 13 | [Guid("3E81928E-DDAE-4B3C-BCEF-DB2752BCFA1E")] 14 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 15 | public interface ICoreWebView2HttpResponseHeaders 16 | { 17 | /// 18 | /// Appends header line with name and value. 19 | /// 20 | /// 21 | /// 22 | void AppendHeader([In, MarshalAs(UnmanagedType.LPWStr)] string name, [In, MarshalAs(UnmanagedType.LPWStr)] string value); 23 | 24 | /// 25 | /// Checks whether the headers contain entries matching the header name. 26 | /// 27 | /// 28 | /// 29 | int Contains([In, MarshalAs(UnmanagedType.LPWStr)] string name); 30 | 31 | /// 32 | /// Gets the header values matching the name. 33 | /// 34 | /// 35 | /// 36 | void GetHeaders([In, MarshalAs(UnmanagedType.LPWStr)] string name, out ICoreWebView2HttpHeadersCollectionIterator iterator); 37 | 38 | /// 39 | /// Gets an iterator over the collection of entire response headers. 40 | /// 41 | /// 42 | void GetIterator(out ICoreWebView2HttpHeadersCollectionIterator iterator); 43 | } 44 | } -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/DocumentTitleChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class DocumentTitleChangedEventArgs : EventArgs 31 | { 32 | internal DocumentTitleChangedEventArgs(ICoreWebView2 webview) 33 | { 34 | string title; 35 | webview.DocumentTitle(out title); 36 | Title = title; 37 | } 38 | 39 | public string Title { get; private set; } 40 | 41 | public override string ToString() 42 | { 43 | return string.Format("Args={0}", Title); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/FocusChangedEventEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | 27 | namespace MtrDev.WebView2.Wrapper 28 | { 29 | public class FocusChangedEventEventArgs : EventArgs 30 | { 31 | internal FocusChangedEventEventArgs(WebView2WebView webview, object args) 32 | { 33 | WebView2WebView = webview; 34 | Args = args; 35 | } 36 | 37 | public WebView2WebView WebView2WebView { get; private set; } 38 | 39 | public object Args { get; private set; } 40 | 41 | public override string ToString() 42 | { 43 | return string.Format("Args={0}", Args); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/CapturePreviewCompletedHandler .cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class CapturePreviewCompletedHandler : HandlerBase, ICoreWebView2CapturePreviewCompletedHandler 31 | { 32 | public CapturePreviewCompletedHandler(Action callback) : base(callback) 33 | { 34 | } 35 | 36 | public void Invoke(int result) 37 | { 38 | CapturePreviewCompletedArgs eventArgs = new CapturePreviewCompletedArgs(result); 39 | 40 | Callback.Invoke(eventArgs); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/HistoryChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | using System; 28 | 29 | namespace MtrDev.WebView2.Wrapper.Handlers 30 | { 31 | public class HistoryChangedEventHandler : HandlerBase, 32 | ICoreWebView2HistoryChangedEventHandler 33 | { 34 | public HistoryChangedEventHandler(Action callback) : base(callback) 35 | { 36 | } 37 | 38 | public void Invoke(ICoreWebView2 webview, object args) 39 | { 40 | HistoryChangedEventArgs completedArgs = new HistoryChangedEventArgs(); 41 | Callback(completedArgs); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/ProcessFailedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | 29 | namespace MtrDev.WebView2.Wrapper.Handlers 30 | { 31 | public class ProcessFailedEventHandler : HandlerBase, ICoreWebView2ProcessFailedEventHandler 32 | { 33 | public ProcessFailedEventHandler(Action callback) : base(callback) 34 | { 35 | } 36 | 37 | public void Invoke(ICoreWebView2 webview, ICoreWebView2ProcessFailedEventArgs args) 38 | { 39 | ProcessFailedEventArgs eventArgs = new ProcessFailedEventArgs(args); 40 | Callback.Invoke(eventArgs); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/SourceChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | using System; 28 | 29 | namespace MtrDev.WebView2.Wrapper.Handlers 30 | { 31 | public class SourceChangedEventHandler: HandlerBase, 32 | ICoreWebView2SourceChangedEventHandler 33 | { 34 | public SourceChangedEventHandler(Action callback) : base(callback) 35 | { 36 | } 37 | 38 | public void Invoke(ICoreWebView2 webview, ICoreWebView2SourceChangedEventArgs args) 39 | { 40 | SourceChangedEventArgs completedArgs = new SourceChangedEventArgs(args); 41 | Callback(completedArgs); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/ExecuteScriptCompletedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | 27 | namespace MtrDev.WebView2.Wrapper 28 | { 29 | public class ExecuteScriptCompletedEventArgs : EventArgs 30 | { 31 | internal ExecuteScriptCompletedEventArgs(int errorCode, string resultObjectAsJson) 32 | { 33 | ErrorCode = errorCode; 34 | ResultAsJson = resultObjectAsJson; 35 | } 36 | 37 | public int ErrorCode { get; private set; } 38 | 39 | public string ResultAsJson { get; private set; } 40 | 41 | public override string ToString() 42 | { 43 | return string.Format("ErrorCode={0}, ResultObjectAsJson={1}", ErrorCode, ResultAsJson); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/ContentLoadingEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | using System; 28 | 29 | namespace MtrDev.WebView2.Wrapper.Handlers 30 | { 31 | public class ContentLoadingEventHandler : HandlerBase, 32 | ICoreWebView2ContentLoadingEventHandler 33 | { 34 | public ContentLoadingEventHandler(Action callback) : base(callback) 35 | { 36 | } 37 | 38 | public void Invoke(ICoreWebView2 webview, ICoreWebView2ContentLoadingEventArgs args) 39 | { 40 | ContentLoadingEventArgs completedArgs = new ContentLoadingEventArgs(args); 41 | Callback(completedArgs); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/CreateWebViewCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class CreateWebViewCompletedHandler : HandlerBase, ICoreWebView2CreateCoreWebView2HostCompletedHandler 31 | { 32 | public CreateWebViewCompletedHandler(Action callback) : base(callback) 33 | { 34 | } 35 | 36 | public void Invoke(int result, ICoreWebView2Host webView) 37 | { 38 | CreateWebViewCompletedEventArgs eventArgs = new CreateWebViewCompletedEventArgs(result, webView); 39 | Callback.Invoke(eventArgs); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/DocumentTitleChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class DocumentTitleChangedEventHandler : HandlerBase, 31 | ICoreWebView2DocumentTitleChangedEventHandler 32 | { 33 | public DocumentTitleChangedEventHandler(Action callback) : base(callback) 34 | { 35 | } 36 | 37 | public void Invoke(ICoreWebView2 webview, object args) 38 | { 39 | DocumentTitleChangedEventArgs completedArgs = new DocumentTitleChangedEventArgs(webview); 40 | Callback(completedArgs); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/NewWindowRequestedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class NewWindowRequestedEventHandler : HandlerBase, ICoreWebView2NewWindowRequestedEventHandler 31 | { 32 | public NewWindowRequestedEventHandler(Action callback) : base(callback) 33 | { 34 | } 35 | 36 | public void Invoke(ICoreWebView2 webview, ICoreWebView2NewWindowRequestedEventArgs args) 37 | { 38 | NewWindowRequestedEventArgs eventArgs = new NewWindowRequestedEventArgs(args); 39 | Callback.Invoke(eventArgs); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/ExecuteScriptCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class ExecuteScriptCompletedHandler : HandlerBase, ICoreWebView2ExecuteScriptCompletedHandler 31 | { 32 | public ExecuteScriptCompletedHandler(Action callback) : base(callback) 33 | { 34 | } 35 | 36 | public void Invoke(int errorCode, string resultObjectAsJson) 37 | { 38 | ExecuteScriptCompletedEventArgs eventArgs = new ExecuteScriptCompletedEventArgs(errorCode, resultObjectAsJson); 39 | Callback.Invoke(eventArgs); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/ScriptDialogOpeningEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class ScriptDialogOpeningEventHandler : HandlerBase, ICoreWebView2ScriptDialogOpeningEventHandler 31 | { 32 | public ScriptDialogOpeningEventHandler(Action callback) : base(callback) 33 | { 34 | } 35 | 36 | public void Invoke(ICoreWebView2 webview, ICoreWebView2ScriptDialogOpeningEventArgs args) 37 | { 38 | ScriptDialogOpeningEventArgs eventArgs = new ScriptDialogOpeningEventArgs(args); 39 | Callback.Invoke(eventArgs); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/MoveFocusRequestedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class MoveFocusRequestedEventHandler : HandlerBase, 31 | ICoreWebView2MoveFocusRequestedEventHandler 32 | { 33 | public MoveFocusRequestedEventHandler(Action callback) : base(callback) 34 | { 35 | } 36 | 37 | public void Invoke(ICoreWebView2Host webview, ICoreWebView2MoveFocusRequestedEventArgs args) 38 | { 39 | MoveFocusRequestedEventArgs eventArgs = new MoveFocusRequestedEventArgs(args); 40 | Callback.Invoke(eventArgs); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/NavigationStartingEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using System; 27 | using MtrDev.WebView2.Interop; 28 | 29 | namespace MtrDev.WebView2.Wrapper.Handlers 30 | { 31 | public class NavigationStartingEventHandler : HandlerBase, 32 | ICoreWebView2NavigationStartingEventHandler 33 | { 34 | public NavigationStartingEventHandler(Action callback) : base(callback) 35 | { 36 | } 37 | 38 | public void Invoke(ICoreWebView2 webview, ICoreWebView2NavigationStartingEventArgs args) 39 | { 40 | NavigationStartingEventArgs completedArgs = new NavigationStartingEventArgs(args); 41 | Callback(completedArgs); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/PermissionRequestedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class PermissionRequestedEventHandler : HandlerBase, 31 | ICoreWebView2PermissionRequestedEventHandler 32 | { 33 | public PermissionRequestedEventHandler(Action callback) : base(callback) 34 | { 35 | } 36 | 37 | public void Invoke(ICoreWebView2 webview, ICoreWebView2PermissionRequestedEventArgs args) 38 | { 39 | PermissionRequestedEventArgs eventArgs = new PermissionRequestedEventArgs(args); 40 | Callback.Invoke(eventArgs); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/ZoomFactorChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class ZoomFactorChangedEventHandler : ICoreWebView2ZoomFactorChangedEventHandler 31 | { 32 | Action _callback; 33 | 34 | public ZoomFactorChangedEventHandler(Action callback) 35 | { 36 | _callback = callback; 37 | } 38 | 39 | 40 | public void Invoke(ICoreWebView2Host webview, object args) 41 | { 42 | ZoomFactorCompletedEventArgs eventArgs = new ZoomFactorCompletedEventArgs(args); 43 | _callback.Invoke(eventArgs); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/WebMessageReceivedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class WebMessageReceivedEventHandler : ICoreWebView2WebMessageReceivedEventHandler 31 | { 32 | Action _callback; 33 | 34 | public WebMessageReceivedEventHandler(Action callback) 35 | { 36 | _callback = callback; 37 | } 38 | 39 | public void Invoke(ICoreWebView2 webview, ICoreWebView2WebMessageReceivedEventArgs args) 40 | { 41 | WebMessageReceivedEventArgs eventArgs = new WebMessageReceivedEventArgs(args); 42 | _callback.Invoke(eventArgs); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/ProcessFailedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class ProcessFailedEventArgs : EventArgs, ICoreWebView2ProcessFailedEventArgs 31 | { 32 | private ICoreWebView2ProcessFailedEventArgs _args; 33 | 34 | internal ProcessFailedEventArgs(ICoreWebView2ProcessFailedEventArgs args) 35 | { 36 | _args = args; 37 | } 38 | 39 | public WEBVIEW2_PROCESS_FAILED_KIND ProcessFailedKind 40 | { 41 | get { return _args.ProcessFailedKind; } 42 | } 43 | 44 | public override string ToString() 45 | { 46 | return string.Format("ProcessFailedKind = {0}", ProcessFailedKind); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/EnvironmentCreatedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class EnvironmentCreatedEventArgs : EventArgs 31 | { 32 | internal EnvironmentCreatedEventArgs(int result, ICoreWebView2Environment webViewEnvironment) 33 | { 34 | Result = result; 35 | if (webViewEnvironment != null) 36 | { 37 | WebViewEnvironment = new WebView2Environment(webViewEnvironment); 38 | } 39 | } 40 | 41 | public int Result 42 | { 43 | get; private set; 44 | } 45 | 46 | public WebView2Environment WebViewEnvironment 47 | { 48 | get; private set; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/AcceleratorKeyPressedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | using System; 28 | using System.Runtime.InteropServices; 29 | 30 | namespace MtrDev.WebView2.Wrapper.Handlers 31 | { 32 | public class AcceleratorKeyPressedEventHandler : HandlerBase, ICoreWebView2AcceleratorKeyPressedEventHandler 33 | { 34 | public AcceleratorKeyPressedEventHandler(Action callback) : base(callback) 35 | { 36 | } 37 | 38 | public void Invoke([In] ICoreWebView2Host webview, [In] ICoreWebView2AcceleratorKeyPressedEventArgs args) 39 | { 40 | AcceleratorKeyPressedEventArgs eventArgs = new AcceleratorKeyPressedEventArgs(args); 41 | Callback(eventArgs); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/SourceChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | using System; 28 | 29 | namespace MtrDev.WebView2.Wrapper 30 | { 31 | public class SourceChangedEventArgs : EventArgs, ICoreWebView2SourceChangedEventArgs 32 | { 33 | private ICoreWebView2SourceChangedEventArgs _args; 34 | 35 | internal SourceChangedEventArgs(ICoreWebView2SourceChangedEventArgs args) 36 | { 37 | _args = args; 38 | } 39 | 40 | /// 41 | /// True if the page being navigated to is a new document. 42 | /// 43 | public bool IsNewDocument => _args.IsNewDocument; 44 | 45 | public override string ToString() 46 | { 47 | return string.Format("IsNewDocument={0}", IsNewDocument); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/FocusChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class FocusChangedEventHandler : HandlerBase, 31 | ICoreWebView2FocusChangedEventHandler 32 | { 33 | public FocusChangedEventHandler(Action callback) : base(callback) 34 | { 35 | } 36 | 37 | public void Invoke(ICoreWebView2Host webview, object args) 38 | { 39 | // FocusChangedEventEventArgs eventArgs = new FocusChangedEventEventArgs(new WebView2WebView(webview), args); 40 | FocusChangedEventEventArgs eventArgs = new FocusChangedEventEventArgs(null, args); 41 | Callback.Invoke(eventArgs); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/AddScriptToExecuteOnDocumentCreatedCompletedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using System; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | /// 31 | /// The result of the AddScriptToExecuteOnDocumentCreated method. 32 | /// 33 | public class AddScriptToExecuteOnDocumentCreatedCompletedEventArgs : EventArgs 34 | { 35 | internal AddScriptToExecuteOnDocumentCreatedCompletedEventArgs(int errorCode, string id) 36 | { 37 | ErrorCode = errorCode; 38 | Id = id; 39 | } 40 | 41 | public int ErrorCode { get; private set; } 42 | 43 | public string Id { get; private set; } 44 | 45 | public override string ToString() 46 | { 47 | return string.Format("Id={0}, ErrorCode={1}", Id, ErrorCode); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/ContainsFullScreenElementChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | using System; 28 | using System.Runtime.InteropServices; 29 | 30 | namespace MtrDev.WebView2.Wrapper.Handlers 31 | { 32 | public class ContainsFullScreenElementChangedEventHandler : HandlerBase, ICoreWebView2ContainsFullScreenElementChangedEventHandler 33 | { 34 | public ContainsFullScreenElementChangedEventHandler(Action callback) : base(callback) 35 | { 36 | } 37 | 38 | public void Invoke(ICoreWebView2 webview, object args) 39 | { 40 | ContainsFullScreenElementChangedEventArgs eventArgs = new ContainsFullScreenElementChangedEventArgs(); 41 | Callback(eventArgs); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/NewVersionAvailableEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | using System; 28 | using System.Runtime.InteropServices; 29 | 30 | namespace MtrDev.WebView2.Wrapper.Handlers 31 | { 32 | public class NewVersionAvailableEventHandler : HandlerBase, 33 | ICoreWebView2NewBrowserVersionAvailableEventHandler 34 | { 35 | public NewVersionAvailableEventHandler(Action callback) : base(callback) 36 | { 37 | } 38 | 39 | public void Invoke([In] ICoreWebView2Environment webViewEnvironment, [In] ICoreWebView2NewBrowserVersionAvailableEventArgs args) 40 | { 41 | NewVersionAvailableEventArgs eventArgs = new NewVersionAvailableEventArgs(args); 42 | Callback.Invoke(eventArgs); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/WindowCloseRequestedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | using System; 28 | using System.Runtime.InteropServices; 29 | 30 | namespace MtrDev.WebView2.Wrapper.Handlers 31 | { 32 | public class WindowCloseRequestedEventHandler : HandlerBase, 33 | ICoreWebView2WindowCloseRequestedEventHandler 34 | { 35 | public WindowCloseRequestedEventHandler(Action callback) : base(callback) 36 | { 37 | } 38 | 39 | public void Invoke([In, MarshalAs(UnmanagedType.Interface)] ICoreWebView2 webview, [In, MarshalAs(UnmanagedType.Interface)] object args) 40 | { 41 | WindowCloseRequestedEventArgs completedArgs = new WindowCloseRequestedEventArgs(); 42 | Callback(completedArgs); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/EnvironmentCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using System.Threading.Tasks; 30 | using MtrDev.WebView2.Interop; 31 | 32 | namespace MtrDev.WebView2.Wrapper.Handlers 33 | { 34 | public class EnvironmentCompletedHandler : HandlerBase, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler 35 | { 36 | public EnvironmentCompletedHandler(Action callback) : base(callback) 37 | { 38 | } 39 | 40 | public void Invoke(int result, ICoreWebView2Environment webViewEnvironment) 41 | { 42 | EnvironmentCreatedEventArgs eventArgs = new EnvironmentCreatedEventArgs(result, webViewEnvironment); 43 | 44 | Callback.Invoke(eventArgs); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Src/Wrapper/WebView2Deferral.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | /// 31 | /// This class is used to complete deferrals on event args that 32 | /// support getting deferrals via their GetDeferral method. 33 | /// 34 | public class WebView2Deferral : ICoreWebView2Deferral 35 | { 36 | private ICoreWebView2Deferral _deferral; 37 | 38 | internal WebView2Deferral(ICoreWebView2Deferral deferral) 39 | { 40 | _deferral = deferral; 41 | } 42 | 43 | /// 44 | /// Completes the associated deferred event. Complete should only be 45 | /// called once for each deferral taken. 46 | /// 47 | public void Complete() 48 | { 49 | _deferral.Complete(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/CallDevToolsProtocolMethodCompletedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | 27 | namespace MtrDev.WebView2.Wrapper 28 | { 29 | public class CallDevToolsProtocolMethodCompletedEventArgs : EventArgs 30 | { 31 | internal CallDevToolsProtocolMethodCompletedEventArgs(string method, int errorCode, string returnObjectAsJson) 32 | { 33 | ErrorCode = errorCode; 34 | ReturnObjectAsJson = returnObjectAsJson; 35 | Method = method; 36 | } 37 | 38 | public int ErrorCode { get; private set; } 39 | 40 | public string ReturnObjectAsJson { get; private set; } 41 | 42 | public string Method { get; private set; } 43 | 44 | public override string ToString() 45 | { 46 | return string.Format("Method={0}, ErrorCode={1}, ReturnObjectAsJson={2}", Method, ErrorCode, ReturnObjectAsJson); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/NavigationCompletedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using System.Threading.Tasks; 30 | using MtrDev.WebView2.Interop; 31 | 32 | namespace MtrDev.WebView2.Wrapper.Handlers 33 | { 34 | public class NavigationCompletedEventHandler : ICoreWebView2NavigationCompletedEventHandler 35 | { 36 | Action _callback; 37 | 38 | public NavigationCompletedEventHandler(Action callback) 39 | { 40 | _callback = callback; 41 | } 42 | 43 | public void Invoke(ICoreWebView2 webview, ICoreWebView2NavigationCompletedEventArgs args) 44 | { 45 | NavigationCompletedEventArgs completedArgs = new NavigationCompletedEventArgs(args); 46 | _callback(completedArgs); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/AddScriptToExecuteOnDocumentCreatedCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class AddScriptToExecuteOnDocumentCreatedCompletedHandler : HandlerBase, 31 | ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler 32 | { 33 | public AddScriptToExecuteOnDocumentCreatedCompletedHandler(Action callback) : base(callback) 34 | { 35 | } 36 | 37 | public void Invoke(int errorCode, string id) 38 | { 39 | AddScriptToExecuteOnDocumentCreatedCompletedEventArgs eventArgs = 40 | new AddScriptToExecuteOnDocumentCreatedCompletedEventArgs(errorCode, id); 41 | Callback.Invoke(eventArgs); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/CallDevToolsProtocolMethodCompletedHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class CallDevToolsProtocolMethodCompletedHandler : HandlerBase, ICoreWebView2CallDevToolsProtocolMethodCompletedHandler 31 | { 32 | private string _method; 33 | 34 | public CallDevToolsProtocolMethodCompletedHandler(string method, Action callback) : base(callback) 35 | { 36 | _method = method; 37 | } 38 | 39 | public void Invoke(int errorCode, string returnObjectAsJson) 40 | { 41 | CallDevToolsProtocolMethodCompletedEventArgs eventArgs = new CallDevToolsProtocolMethodCompletedEventArgs(_method, errorCode, returnObjectAsJson); 42 | Callback(eventArgs); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/MoveFocusRequestedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class MoveFocusRequestedEventArgs: EventArgs, ICoreWebView2MoveFocusRequestedEventArgs 31 | { 32 | private ICoreWebView2MoveFocusRequestedEventArgs _args; 33 | 34 | public MoveFocusRequestedEventArgs(ICoreWebView2MoveFocusRequestedEventArgs args) 35 | { 36 | _args = args; 37 | } 38 | 39 | public WEBVIEW2_MOVE_FOCUS_REASON Reason 40 | { 41 | get => _args.Reason; 42 | } 43 | 44 | public bool Handled 45 | { 46 | get => _args.Handled; 47 | 48 | set => _args.Handled = value; 49 | } 50 | 51 | public override string ToString() 52 | { 53 | return string.Format("Reason={0}, Handled={1}", Reason, Handled); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/DevToolsProtocolEventReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class DevToolsProtocolEventReceivedEventArgs : EventArgs, ICoreWebView2DevToolsProtocolEventReceivedEventArgs 31 | { 32 | internal DevToolsProtocolEventReceivedEventArgs(string eventName, ICoreWebView2DevToolsProtocolEventReceivedEventArgs args) 33 | { 34 | ParameterObjectAsJson = args.ParameterObjectAsJson; 35 | EventName = eventName; 36 | } 37 | 38 | public string EventName { get; private set; } 39 | 40 | public string ParameterObjectAsJson 41 | { 42 | get; private set; 43 | } 44 | 45 | public override string ToString() 46 | { 47 | return string.Format("EventName={0}, ParameterObjectAsJson={1}", EventName, ParameterObjectAsJson); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/DevToolsProtocolEventReceivedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using MtrDev.WebView2.Interop; 26 | using System; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | public class DevToolsProtocolEventReceivedEventHandler : HandlerBase, 31 | ICoreWebView2DevToolsProtocolEventReceivedEventHandler 32 | { 33 | private string _eventName; 34 | 35 | public DevToolsProtocolEventReceivedEventHandler(string eventName, Action callback) : 36 | base(callback) 37 | { 38 | _eventName = eventName; 39 | } 40 | 41 | public void Invoke(ICoreWebView2 webview, ICoreWebView2DevToolsProtocolEventReceivedEventArgs args) 42 | { 43 | DevToolsProtocolEventReceivedEventArgs eventArgs = new DevToolsProtocolEventReceivedEventArgs(_eventName, args); 44 | Callback.Invoke(eventArgs); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2HttpRequestHeaders.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// HTTP request headers. Used to inspect or modify the HTTP request on 9 | /// WebResourceRequested event and NavigationStarting event. 10 | /// 11 | [ComVisible(true)] 12 | [ComImport] 13 | [Guid("160B895B-D0AF-4A42-A14F-5571CFA68B03")] 14 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 15 | public interface ICoreWebView2HttpRequestHeaders 16 | { 17 | /// 18 | /// Gets the header value matching the name. 19 | /// 20 | /// 21 | /// 22 | void GetHeader([In, MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value); 23 | 24 | void GetHeader([In, MarshalAs(UnmanagedType.LPWStr)] string name, out ICoreWebView2HttpHeadersCollectionIterator iterator); 25 | 26 | /// 27 | /// Checks whether the headers contain an entry matching the header name. 28 | /// 29 | /// 30 | /// 31 | int Contains([In, MarshalAs(UnmanagedType.LPWStr)] string name); 32 | 33 | /// 34 | /// Adds or updates header that matches the name. 35 | /// 36 | /// 37 | /// 38 | void SetHeader([In, MarshalAs(UnmanagedType.LPWStr)] string name, [In, MarshalAs(UnmanagedType.LPWStr)] string value); 39 | 40 | /// 41 | /// Removes header that matches the name. 42 | /// 43 | /// 44 | void RemoveHeader([In, MarshalAs(UnmanagedType.LPWStr)] string name); 45 | 46 | /// 47 | /// Gets an iterator over the collection of request headers. 48 | /// 49 | /// 50 | void GetIterator(out ICoreWebView2HttpHeadersCollectionIterator iterator); 51 | } 52 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2PermissionRequestedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Event args for the PermissionRequested event. 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("DBB6C9C9-FBB5-40FD-8843-5BE65807FD8A")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2PermissionRequestedEventArgs 15 | { 16 | /// 17 | /// The origin of the web content that requests the permission. 18 | /// 19 | [DispId(1610678272)] 20 | string Uri 21 | { 22 | [return: MarshalAs(UnmanagedType.LPWStr)] 23 | get; 24 | } 25 | 26 | /// 27 | /// The type of the permission that is requested. 28 | /// 29 | [DispId(1610678273)] 30 | WEBVIEW2_PERMISSION_TYPE PermissionType 31 | { 32 | 33 | get; 34 | } 35 | 36 | /// 37 | /// True when the permission request was initiated through a user gesture. 38 | /// Note that being initiated through a user gesture doesn't mean that user 39 | /// intended to access the associated resource. 40 | /// 41 | [DispId(1610678274)] 42 | bool IsUserInitiated 43 | { 44 | [return: MarshalAs(UnmanagedType.Bool)] 45 | get; 46 | } 47 | 48 | /// 49 | /// The status of a permission request, i.e. whether the request is granted. 50 | /// Default value is WEBVIEW2_PERMISSION_STATE_DEFAULT. 51 | /// 52 | [DispId(1610678275)] 53 | WEBVIEW2_PERMISSION_STATE State 54 | { 55 | 56 | get; 57 | 58 | set; 59 | } 60 | 61 | /// 62 | /// GetDeferral can be called to return an IWebView2Deferral object. 63 | /// Developer can use the deferral object to make the permission decision 64 | /// at a later time. 65 | /// 66 | /// 67 | ICoreWebView2Deferral GetDeferral(); 68 | } 69 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2WebResourceResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Runtime.InteropServices.ComTypes; 5 | 6 | namespace MtrDev.WebView2.Interop 7 | { 8 | /// 9 | /// An HTTP response used with the WebResourceRequested event. 10 | /// 11 | [ComVisible(true)] 12 | [ComImport] 13 | [Guid("2B842125-E3B4-40A2-8BB8-C31AABF70E0A")] 14 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 15 | public interface ICoreWebView2WebResourceResponse 16 | { 17 | /// 18 | /// HTTP response content as stream. Stream must have all the 19 | /// content data available by the time this response's WebResourceRequested 20 | /// event deferral is completed. Stream should be agile or be created from 21 | /// a background thread to prevent performance impact to the UI thread. 22 | /// Null means no content data. IStream semantics 23 | /// apply (return S_OK to Read calls until all data is exhausted) 24 | /// 25 | [DispId(1610678272)] 26 | IStream Content 27 | { 28 | [return: MarshalAs(UnmanagedType.Interface)] 29 | get; 30 | 31 | [param: MarshalAs(UnmanagedType.Interface)] 32 | set; 33 | } 34 | 35 | /// 36 | /// Overridden HTTP response headers. 37 | /// 38 | [DispId(1610678274)] 39 | ICoreWebView2HttpResponseHeaders Headers 40 | { 41 | [return: MarshalAs(UnmanagedType.Interface)] 42 | get; 43 | } 44 | 45 | /// 46 | /// The HTTP response status code. 47 | /// 48 | [DispId(1610678275)] 49 | int StatusCode 50 | { 51 | 52 | get; 53 | 54 | set; 55 | } 56 | 57 | /// 58 | /// The HTTP response reason phrase 59 | /// 60 | [DispId(1610678277)] 61 | string ReasonPhrase 62 | { 63 | [return: MarshalAs(UnmanagedType.LPWStr)] 64 | get; 65 | [param: MarshalAs(UnmanagedType.LPWStr)] 66 | set; 67 | } 68 | 69 | 70 | } 71 | } -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/NavigationCompletedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class NavigationCompletedEventArgs : EventArgs, ICoreWebView2NavigationCompletedEventArgs 31 | { 32 | private ICoreWebView2NavigationCompletedEventArgs _args; 33 | 34 | public NavigationCompletedEventArgs(ICoreWebView2NavigationCompletedEventArgs args) 35 | { 36 | _args = args; 37 | } 38 | 39 | public bool IsSuccess 40 | { 41 | get => _args.IsSuccess; 42 | } 43 | 44 | public WEBVIEW2_WEB_ERROR_STATUS WebErrorStatus 45 | { 46 | get => _args.WebErrorStatus; 47 | } 48 | 49 | public override string ToString() 50 | { 51 | return string.Format("IsSuccess={0}, WebErrorStatus={1}", IsSuccess, WebErrorStatus); 52 | } 53 | 54 | public long NavigationId => _args.NavigationId; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/ContentLoadingEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | using System; 28 | 29 | namespace MtrDev.WebView2.Wrapper 30 | { 31 | public class ContentLoadingEventArgs : EventArgs, ICoreWebView2ContentLoadingEventArgs 32 | { 33 | private ICoreWebView2ContentLoadingEventArgs _args; 34 | 35 | internal ContentLoadingEventArgs(ICoreWebView2ContentLoadingEventArgs args) 36 | { 37 | _args = args; 38 | } 39 | 40 | /// 41 | /// True if the loaded content is an error page. 42 | /// 43 | public bool IsErrorPage => _args.IsErrorPage; 44 | 45 | /// 46 | /// The ID of the navigation. 47 | /// 48 | public long NavigationId => _args.NavigationId; 49 | 50 | public override string ToString() 51 | { 52 | return string.Format("IsErrorPage={0}, NavigationId ={1}", IsErrorPage, NavigationId); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Src/Wrapper/Handlers/WebResourceRequestedEventHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper.Handlers 29 | { 30 | /// 31 | /// Fires when an HTTP request is made in the webview. The host can override 32 | /// request, response headers and response content. 33 | /// 34 | public class WebResourceRequestedEventHandler : HandlerBase, ICoreWebView2WebResourceRequestedEventHandler 35 | { 36 | public WebResourceRequestedEventHandler(Action callback) : base(callback) 37 | { 38 | } 39 | 40 | //public void Invoke(IWebView2WebView webview, IWebView2WebResourceRequestedEventArgs args) 41 | public void Invoke(ICoreWebView2 webview, ICoreWebView2WebResourceRequestedEventArgs args) 42 | { 43 | WebResourceRequestedEventArgs eventArgs = new WebResourceRequestedEventArgs(args); 44 | Callback.Invoke(eventArgs); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2Environment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Runtime.InteropServices.ComTypes; 5 | 6 | namespace MtrDev.WebView2.Interop 7 | { 8 | #pragma warning disable CS0108 9 | 10 | /// 11 | /// Checked 12 | /// 13 | [ComVisible(true)] 14 | [ComImport] 15 | [Guid("7DC2EC84-56CB-4FCC-B4C6-A9F85C7B2894")] 16 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 17 | public interface ICoreWebView2Environment 18 | { 19 | void CreateCoreWebView2Host([In] IntPtr parentWindow, [In]ICoreWebView2CreateCoreWebView2HostCompletedHandler handler); 20 | 21 | void CreateWebResourceResponse(IStream Content, 22 | int StatusCode, 23 | [In, MarshalAs(UnmanagedType.LPWStr)] string reasonPhrase, 24 | [In, MarshalAs(UnmanagedType.LPWStr)] string headers, 25 | ref ICoreWebView2WebResourceResponse response); 26 | 27 | /// 28 | /// The browser version info of the current IWebView2Environment, 29 | /// including channel name if it is not the stable channel. 30 | /// This matches the format of the GetWebView2BrowserVersionInfo API. 31 | /// Channel names are 'beta', 'dev', and 'canary'. 32 | /// 33 | [DispId(1610678274)] 34 | string BrowserVersionInfo 35 | { 36 | [return: MarshalAs(UnmanagedType.LPWStr)] 37 | get; 38 | } 39 | 40 | /// 41 | /// The NewVersionAvailable event fires when a newer version of the 42 | /// Edge browser is installed and available to use via WebView2. 43 | /// To use the newer version of the browser you must create a new 44 | /// IWebView2Environment and IWebView2WebView. 45 | /// 46 | /// 47 | /// 48 | void add_NewVersionAvailable([In] ICoreWebView2NewBrowserVersionAvailableEventHandler eventHandler, out EventRegistrationToken token); 49 | 50 | 51 | void remove_NewVersionAvailable([In] EventRegistrationToken token); 52 | } 53 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2WebResourceRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Runtime.InteropServices.ComTypes; 5 | 6 | namespace MtrDev.WebView2.Interop 7 | { 8 | /// 9 | /// An HTTP request used with the WebResourceRequested event. 10 | /// 11 | [ComVisible(true)] 12 | [ComImport] 13 | [Guid("7471A125-D5E8-45A8-B119-F9E9230D4D0B")] 14 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 15 | public interface ICoreWebView2WebResourceRequest 16 | { 17 | /// 18 | /// The request URI. 19 | /// 20 | [DispId(1610678272)] 21 | string Uri 22 | { 23 | [return: MarshalAs(UnmanagedType.LPWStr)] 24 | get; 25 | [param: MarshalAs(UnmanagedType.LPWStr)] 26 | set; 27 | } 28 | 29 | /// 30 | /// The HTTP request method. 31 | /// 32 | [DispId(1610678274)] 33 | string Method 34 | { 35 | [return: MarshalAs(UnmanagedType.LPWStr)] 36 | get; 37 | [param: MarshalAs(UnmanagedType.LPWStr)] 38 | set; 39 | } 40 | 41 | /// 42 | /// The HTTP request message body as stream. POST data would be here. 43 | /// If a stream is set, which will override the message body, the stream must 44 | /// have all the content data available by the time this 45 | /// response's WebResourceRequested event deferral is completed. Stream 46 | /// should be agile or be created from a background STA to prevent performance 47 | /// impact to the UI thread. Null means no content data. IStream semantics 48 | /// apply (return S_OK to Read calls until all data is exhausted) 49 | /// 50 | [DispId(1610678276)] 51 | IStream Content 52 | { 53 | [return:MarshalAs(UnmanagedType.Interface)] 54 | get; 55 | 56 | [param: MarshalAs(UnmanagedType.Interface)] 57 | set; 58 | } 59 | 60 | /// 61 | /// The mutable HTTP request headers 62 | /// 63 | [DispId(1610678278)] 64 | ICoreWebView2HttpRequestHeaders Headers 65 | { 66 | [return: MarshalAs(UnmanagedType.Interface)] 67 | get; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2NavigationStartingEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Event args for the NavigationStarting event. 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("1C81A448-575B-44A1-9ABD-1B93A3DE9E03")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2NavigationStartingEventArgs 15 | { 16 | /// 17 | /// The uri of the requested navigation. 18 | /// 19 | [DispId(1610678272)] 20 | string Uri 21 | { 22 | [return: MarshalAs(UnmanagedType.LPWStr)] 23 | get; 24 | } 25 | 26 | /// 27 | /// True when the navigation was initiated through a user gesture as opposed 28 | /// to programmatic navigation. 29 | /// 30 | [DispId(1610678273)] 31 | bool IsUserInitiated 32 | { 33 | [return: MarshalAs(UnmanagedType.Bool)] 34 | get; 35 | } 36 | 37 | /// 38 | /// True when the navigation is redirected. 39 | /// 40 | [DispId(1610678274)] 41 | bool IsRedirected 42 | { 43 | [return: MarshalAs(UnmanagedType.Bool)] 44 | get; 45 | } 46 | 47 | /// 48 | /// The HTTP request headers for the navigation. 49 | /// 50 | [DispId(1610678275)] 51 | ICoreWebView2HttpRequestHeaders RequestHeaders 52 | { 53 | get; 54 | } 55 | 56 | /// 57 | /// The host may set this flag to cancel the navigation. 58 | /// If set, it will be as if the navigation never happened and the current 59 | /// page's content will be intact. For performance reasons, GET HTTP requests 60 | /// may happen, while the host is responding. This means cookies can be set 61 | /// and used part of a request for the navigation. 62 | /// 63 | [DispId(1610678276)] 64 | bool Cancel 65 | { 66 | [return: MarshalAs(UnmanagedType.Bool)] 67 | get; 68 | [param: MarshalAs(UnmanagedType.Bool)] 69 | set; 70 | } 71 | 72 | long NavigationId 73 | { 74 | get; 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2WebMessageReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Event args for the WebMessageReceived event. 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("B21D70E2-942E-44EB-B843-22C156FDE288")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2WebMessageReceivedEventArgs 15 | { 16 | /// 17 | /// The URI of the document that sent this web message. 18 | /// 19 | [DispId(1610678272)] 20 | string Source 21 | { 22 | [return: MarshalAs(UnmanagedType.LPWStr)] 23 | get; 24 | } 25 | 26 | /// 27 | /// The message posted from the webview content to the host converted to a 28 | /// JSON string. Use this to communicate via JavaScript objects. 29 | /// 30 | /// For example the following postMessage calls result in the 31 | /// following WebMessageAsJson values: 32 | /// 33 | /// ``` 34 | /// postMessage({'a': 'b'}) L"{\"a\": \"b\"}" 35 | /// postMessage(1.2) L"1.2" 36 | /// postMessage('example') L"\"example\"" 37 | /// ``` 38 | /// 39 | [DispId(1610678273)] 40 | string WebMessageAsJson 41 | { 42 | [return: MarshalAs(UnmanagedType.LPWStr)] 43 | get; 44 | } 45 | 46 | /// 47 | /// If the message posted from the webview content to the host is a 48 | /// string type, this method will return the value of that string. If the 49 | /// message posted is some other kind of JavaScript type this method will fail 50 | /// with E_INVALIDARG. Use this to communicate via simple strings. 51 | /// 52 | /// For example the following postMessage calls result in the 53 | /// following WebMessageAsString values: 54 | /// 55 | /// ``` 56 | /// postMessage({'a': 'b'}) E_INVALIDARG 57 | /// postMessage(1.2) E_INVALIDARG 58 | /// postMessage('example') L"example" 59 | /// ``` 60 | /// 61 | [DispId(1610678274)] 62 | string WebMessageAsString 63 | { 64 | [return: MarshalAs(UnmanagedType.LPWStr)] 65 | get; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /Src/Wrapper/WebView2WebResourceResponse.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using System; 27 | using System.Runtime.InteropServices.ComTypes; 28 | using MtrDev.WebView2.Interop; 29 | 30 | namespace MtrDev.WebView2.Wrapper 31 | { 32 | public class WebView2WebResourceResponse 33 | { 34 | internal ICoreWebView2WebResourceResponse _response; 35 | 36 | internal WebView2WebResourceResponse(ICoreWebView2WebResourceResponse response) 37 | { 38 | _response = response; 39 | } 40 | 41 | internal ICoreWebView2WebResourceResponse InternalWebView2WebResourceResponse { get { return _response; } } 42 | 43 | public IStream Content 44 | { 45 | get { return _response.Content; } 46 | set { _response.Content = value; } 47 | } 48 | 49 | public WebView2HttpResponseHeaderCollection Headers 50 | { 51 | get { return new WebView2HttpResponseHeaderCollection(_response.Headers); } 52 | } 53 | 54 | public int StatusCode 55 | { 56 | get { return _response.StatusCode; } 57 | set { _response.StatusCode = value; } 58 | } 59 | 60 | public string ReasonPhrase 61 | { 62 | get { return _response.ReasonPhrase; } 63 | set { _response.ReasonPhrase = value; } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/PermissionRequestedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class PermissionRequestedEventArgs : EventArgs, ICoreWebView2PermissionRequestedEventArgs 31 | { 32 | private ICoreWebView2PermissionRequestedEventArgs _args; 33 | 34 | internal PermissionRequestedEventArgs(ICoreWebView2PermissionRequestedEventArgs args) 35 | { 36 | _args = args; 37 | } 38 | 39 | public string Uri 40 | { 41 | get => _args.Uri; 42 | } 43 | 44 | public WEBVIEW2_PERMISSION_TYPE PermissionType 45 | { 46 | get => _args.PermissionType; 47 | } 48 | 49 | public bool IsUserInitiated 50 | { 51 | get => _args.IsUserInitiated; 52 | } 53 | 54 | public WEBVIEW2_PERMISSION_STATE State 55 | { 56 | get => _args.State; 57 | set => _args.State = value; 58 | } 59 | 60 | public ICoreWebView2Deferral GetDeferral() 61 | { 62 | return new WebView2Deferral(_args.GetDeferral()); 63 | } 64 | 65 | public override string ToString() 66 | { 67 | return string.Format("Uri={0}, PermissionType={1}, IsUserInitiated={2}, State={3},", 68 | Uri, PermissionType, IsUserInitiated, State); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/ScriptDialogOpeningEventArgs .cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class ScriptDialogOpeningEventArgs : EventArgs 31 | { 32 | ICoreWebView2ScriptDialogOpeningEventArgs _args; 33 | 34 | internal ScriptDialogOpeningEventArgs(ICoreWebView2ScriptDialogOpeningEventArgs args) 35 | { 36 | _args = args; 37 | } 38 | 39 | public string Uri 40 | { 41 | get => _args.Uri; 42 | } 43 | 44 | public WEBVIEW2_SCRIPT_DIALOG_KIND Kind 45 | { 46 | get => _args.Kind; 47 | } 48 | 49 | public string Message 50 | { 51 | get => _args.Message; 52 | } 53 | 54 | public void Accept() 55 | { 56 | _args.Accept(); 57 | } 58 | 59 | public string DefaultText 60 | { 61 | get => _args.DefaultText; 62 | } 63 | 64 | public string ResultText 65 | { 66 | get => _args.ResultText; 67 | set => _args.ResultText = value; 68 | } 69 | 70 | public WebView2Deferral GetDeferral() 71 | { 72 | return new WebView2Deferral(_args.GetDeferral()); 73 | } 74 | 75 | public override string ToString() 76 | { 77 | return string.Format("Uri={0}, Kind={1}, Message={4}, DefaultText={2}, ResultText={3},", 78 | Uri, Kind, DefaultText, ResultText, Message); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Src/Interop/WEBVIEW2_WEB_RESOURCE_CONTEXT.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | /// 6 | /// Enum for resourceContextFilter of WebResourceRequested event 7 | /// 8 | public enum WEBVIEW2_WEB_RESOURCE_CONTEXT 9 | { 10 | /// 11 | /// Filter all resource types 12 | /// 13 | WEBVIEW2_WEB_RESOURCE_CONTEXT_ALL = 0 , 14 | /// 15 | /// Filter document requests 16 | /// 17 | WEBVIEW2_WEB_RESOURCE_CONTEXT_DOCUMENT = 1, 18 | /// 19 | /// Filter CSS resources 20 | /// 21 | WEBVIEW2_WEB_RESOURCE_CONTEXT_STYLESHEET = 2, 22 | /// 23 | /// Filter image resources 24 | /// 25 | WEBVIEW2_WEB_RESOURCE_CONTEXT_IMAGE = 3, 26 | /// 27 | /// Filter other media types such as videos 28 | /// 29 | WEBVIEW2_WEB_RESOURCE_CONTEXT_MEDIA = 4, 30 | /// 31 | /// Filter fonts 32 | /// 33 | WEBVIEW2_WEB_RESOURCE_CONTEXT_FONT = 5, 34 | /// 35 | /// Filter scripts 36 | /// 37 | WEBVIEW2_WEB_RESOURCE_CONTEXT_SCRIPT = 6, 38 | /// 39 | /// Filter XML HTTP requests 40 | /// 41 | WEBVIEW2_WEB_RESOURCE_CONTEXT_XML_HTTP_REQUEST = 7, 42 | /// 43 | /// Filter fetch requests 44 | /// 45 | WEBVIEW2_WEB_RESOURCE_CONTEXT_FETCH = 8, 46 | 47 | /// 48 | /// TextTrack resources 49 | /// 50 | WEBVIEW2_WEB_RESOURCE_CONTEXT_TEXT_TRACK = 9, 51 | /// 52 | /// EventSource API communication 53 | /// 54 | WEBVIEW2_WEB_RESOURCE_CONTEXT_EVENT_SOURCE = 10, 55 | /// 56 | /// WebSocket API communication 57 | /// 58 | WEBVIEW2_WEB_RESOURCE_CONTEXT_WEBSOCKET = 11, 59 | /// 60 | /// Web App Manifests 61 | /// 62 | WEBVIEW2_WEB_RESOURCE_CONTEXT_MANIFEST = 12, 63 | /// 64 | /// Signed HTTP Exchanges 65 | /// 66 | WEBVIEW2_WEB_RESOURCE_CONTEXT_SIGNED_EXCHANGE = 13, 67 | /// 68 | /// Ping requests 69 | /// 70 | WEBVIEW2_WEB_RESOURCE_CONTEXT_PING = 14, 71 | /// 72 | /// CSP Violation Reports 73 | /// 74 | WEBVIEW2_WEB_RESOURCE_CONTEXT_CSP_VIOLATION_REPORT = 15, 75 | /// 76 | /// Other resources 77 | /// 78 | WEBVIEW2_WEB_RESOURCE_CONTEXT_OTHER = 16 79 | } 80 | } -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/NewWindowRequestedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class NewWindowRequestedEventArgs : EventArgs, ICoreWebView2NewWindowRequestedEventArgs 31 | { 32 | private ICoreWebView2NewWindowRequestedEventArgs _args; 33 | private bool _windowSet; 34 | 35 | internal NewWindowRequestedEventArgs(ICoreWebView2NewWindowRequestedEventArgs args) 36 | { 37 | _args = args; 38 | _windowSet = false; 39 | } 40 | 41 | public bool Handled { get => _args.Handled; set => _args.Handled = value; } 42 | 43 | public bool IsUserInitiated => _args.IsUserInitiated; 44 | 45 | 46 | public ICoreWebView2 NewWindow 47 | { 48 | get 49 | { 50 | // this seems to crash if NewWindow wasn't set already. 51 | if (!_windowSet) 52 | return null; 53 | return _args.NewWindow; 54 | } 55 | set 56 | { 57 | _windowSet = true; 58 | _args.NewWindow = value; 59 | } 60 | } 61 | 62 | public string Uri => _args.Uri; 63 | 64 | public ICoreWebView2Deferral GetDeferral() 65 | { 66 | return new WebView2Deferral(_args.GetDeferral()); 67 | } 68 | 69 | public override string ToString() 70 | { 71 | return string.Format("Handled={0}, IsUserInitiated={1}", Handled, IsUserInitiated); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Src/Interop/WEBVIEW2_WEB_ERROR_STATUS.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MtrDev.WebView2.Interop 4 | { 5 | /// 6 | /// Error status values for web navigations. 7 | /// 8 | public enum WEBVIEW2_WEB_ERROR_STATUS 9 | { 10 | /// 11 | /// An unknown error occurred. 12 | /// 13 | WEBVIEW2_WEB_ERROR_STATUS_UNKNOWN, 14 | /// 15 | /// The SSL certificate common name does not match the web address. 16 | /// 17 | WEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_COMMON_NAME_IS_INCORRECT, 18 | /// 19 | /// The SSL certificate has expired. 20 | /// 21 | WEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_EXPIRED, 22 | /// 23 | /// The SSL client certificate contains errors. 24 | /// 25 | WEBVIEW2_WEB_ERROR_STATUS_CLIENT_CERTIFICATE_CONTAINS_ERRORS, 26 | /// 27 | /// The SSL certificate has been revoked. 28 | /// 29 | WEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_REVOKED, 30 | /// 31 | /// The SSL certificate is invalid. 32 | /// 33 | WEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_IS_INVALID, 34 | /// 35 | /// The host is unreachable. 36 | /// 37 | WEBVIEW2_WEB_ERROR_STATUS_SERVER_UNREACHABLE, 38 | /// 39 | /// The connection has timed out. 40 | /// 41 | WEBVIEW2_WEB_ERROR_STATUS_TIMEOUT, 42 | /// 43 | /// The server returned an invalid or unrecognized response. 44 | /// 45 | WEBVIEW2_WEB_ERROR_STATUS_ERROR_HTTP_INVALID_SERVER_RESPONSE, 46 | /// 47 | /// The connection was aborted. 48 | /// 49 | WEBVIEW2_WEB_ERROR_STATUS_CONNECTION_ABORTED, 50 | /// 51 | /// The connection was reset. 52 | /// 53 | WEBVIEW2_WEB_ERROR_STATUS_CONNECTION_RESET, 54 | /// 55 | /// The Internet connection has been lost. 56 | /// 57 | WEBVIEW2_WEB_ERROR_STATUS_DISCONNECTED, 58 | /// 59 | /// Cannot connect to destination. 60 | /// 61 | WEBVIEW2_WEB_ERROR_STATUS_CANNOT_CONNECT, 62 | /// 63 | /// Could not resolve provided host name. 64 | /// 65 | WEBVIEW2_WEB_ERROR_STATUS_HOST_NAME_NOT_RESOLVED, 66 | /// 67 | /// The operation was canceled. 68 | /// 69 | WEBVIEW2_WEB_ERROR_STATUS_OPERATION_CANCELED, 70 | /// 71 | /// The request redirect failed. 72 | /// 73 | WEBVIEW2_WEB_ERROR_STATUS_REDIRECT_FAILED, 74 | /// 75 | /// An unexpected error occurred. 76 | /// 77 | WEBVIEW2_WEB_ERROR_STATUS_UNEXPECTED_ERROR 78 | } 79 | } -------------------------------------------------------------------------------- /Src/Wrapper/WebView2HttpResponseHeaderCollection.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | using System.Collections.ObjectModel; 29 | using MtrDev.WebView2.Interop; 30 | 31 | namespace MtrDev.WebView2.Wrapper 32 | { 33 | public class WebView2HttpResponseHeaderCollection 34 | { 35 | private ICoreWebView2HttpResponseHeaders _httpHeaders; 36 | private IDictionary _headerNameValues; 37 | 38 | internal WebView2HttpResponseHeaderCollection(ICoreWebView2HttpResponseHeaders httpHeaders) 39 | { 40 | _httpHeaders = httpHeaders; 41 | _headerNameValues = new Dictionary(); 42 | 43 | ICoreWebView2HttpHeadersCollectionIterator iterator; 44 | _httpHeaders.GetIterator(out iterator); 45 | if (iterator != null) 46 | { 47 | int hasNext; 48 | iterator.MoveNext(out hasNext); 49 | while (hasNext != 0) 50 | { 51 | string name; 52 | string value; 53 | 54 | iterator.GetCurrentHeader(out name, out value); 55 | _headerNameValues.Add(name, value); 56 | iterator.MoveNext(out hasNext); 57 | } 58 | } 59 | } 60 | 61 | public void AppendHeader(string name, string value) 62 | { 63 | _httpHeaders.AppendHeader(name, value); 64 | _headerNameValues.Add(name, value); 65 | } 66 | 67 | public IReadOnlyDictionary HeaderDictionary 68 | { 69 | get 70 | { 71 | return new ReadOnlyDictionary(_headerNameValues); 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/WebResourceRequestedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class WebResourceRequestedEventArgs : EventArgs 31 | { 32 | private ICoreWebView2WebResourceRequestedEventArgs _args; 33 | private WebView2WebResourceResponse _webResponse; 34 | 35 | internal WebResourceRequestedEventArgs(ICoreWebView2WebResourceRequestedEventArgs args) 36 | { 37 | _args = args; 38 | _webResponse = new WebView2WebResourceResponse(_args.Response); 39 | } 40 | 41 | public WebView2WebResourceRequest Request 42 | { 43 | get { return new WebView2WebResourceRequest(_args.Request); } 44 | } 45 | 46 | public WebView2WebResourceResponse Response 47 | { 48 | get { return _webResponse; } 49 | } 50 | 51 | public void SetResponse(WebView2WebResourceResponse response) 52 | { 53 | _args.Response = response.InternalWebView2WebResourceResponse; 54 | } 55 | 56 | public WEBVIEW2_WEB_RESOURCE_CONTEXT ResourceContext 57 | { 58 | get 59 | { 60 | WEBVIEW2_WEB_RESOURCE_CONTEXT context = WEBVIEW2_WEB_RESOURCE_CONTEXT.WEBVIEW2_WEB_RESOURCE_CONTEXT_ALL; 61 | _args.ResourceContext(ref context); 62 | return context; 63 | } 64 | } 65 | 66 | public WebView2Deferral GetDeferral() 67 | { 68 | return new WebView2Deferral(_args.GetDeferral()); 69 | } 70 | 71 | public override string ToString() 72 | { 73 | return string.Format("ResourceContext = {0}, Request = {1}, Response= {2}", ResourceContext, Request, Response); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2ScriptDialogOpeningEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Event args for the IWebView2WebView::add_ScriptDialogOpening event. 9 | /// 10 | [ComVisible(true)] 11 | [ComImport] 12 | [Guid("49C08E35-FCE1-4C6A-8DBD-6F58666C0CBE")] 13 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 14 | public interface ICoreWebView2ScriptDialogOpeningEventArgs 15 | { 16 | /// 17 | /// The URI of the page that requested the dialog box. 18 | /// 19 | [DispId(1610678272)] 20 | string Uri 21 | { 22 | [return: MarshalAs(UnmanagedType.LPWStr)] 23 | get; 24 | } 25 | 26 | /// 27 | /// The kind of JavaScript dialog box. 28 | /// 29 | [DispId(1610678273)] 30 | WEBVIEW2_SCRIPT_DIALOG_KIND Kind 31 | { 32 | 33 | get; 34 | } 35 | 36 | /// 37 | /// The message of the dialog box. From JavaScript this is the first parameter 38 | /// passed to alert, confirm, and prompt. 39 | /// 40 | [DispId(1610678274)] 41 | string Message 42 | { 43 | [return: MarshalAs(UnmanagedType.LPWStr)] 44 | get; 45 | } 46 | 47 | /// 48 | /// The host may call this to respond with OK to confirm and prompt 49 | /// dialogs or not call this method to indicate cancel. From JavaScript this 50 | /// means that the confirm function returns true if Accept is called. And 51 | /// for the prompt function it returns the value of ResultText if Accept is 52 | /// called and returns false otherwise. 53 | /// 54 | void Accept(); 55 | 56 | /// 57 | /// The second parameter passed to the JavaScript prompt dialog. This is the 58 | /// the default value to use for the result of the prompt JavaScript function. 59 | /// 60 | [DispId(1610678276)] 61 | string DefaultText 62 | { 63 | [return: MarshalAs(UnmanagedType.LPWStr)] 64 | get; 65 | } 66 | 67 | /// 68 | /// The return value from the JavaScript prompt function if Accept is called. 69 | /// This is ignored for dialog kinds other than prompt. If Accept is not 70 | /// called this value is ignored and false is returned from prompt. 71 | /// 72 | [DispId(1610678277)] 73 | string ResultText 74 | { 75 | [return: MarshalAs(UnmanagedType.LPWStr)] 76 | get; 77 | [param: MarshalAs(UnmanagedType.LPWStr)] 78 | set; 79 | } 80 | 81 | /// 82 | /// GetDeferral can be called to return an IWebView2Deferral object. 83 | /// You can use this to complete the event at a later time. 84 | /// 85 | /// 86 | ICoreWebView2Deferral GetDeferral(); 87 | } 88 | } -------------------------------------------------------------------------------- /Src/Wrapper/WebView2DevToolsProtocolEventReceiver.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using MtrDev.WebView2.Interop; 27 | using MtrDev.WebView2.Wrapper.Handlers; 28 | using System; 29 | 30 | namespace MtrDev.WebView2.Wrapper 31 | { 32 | /// 33 | /// A Receiver is created for a particular DevTools Protocol event and allows 34 | /// you to subscribe and unsubsribe from that event. 35 | /// Obtained from the WebView object via GetDevToolsProtocolEventReceiver. 36 | /// 37 | public class WebView2DevToolsProtocolEventReceiver 38 | { 39 | private ICoreWebView2DevToolsProtocolEventReceiver _reciever; 40 | 41 | internal WebView2DevToolsProtocolEventReceiver(string eventName, ICoreWebView2DevToolsProtocolEventReceiver receiver) 42 | { 43 | EventName = eventName; 44 | _reciever = receiver; 45 | } 46 | 47 | public string EventName 48 | { 49 | get; 50 | private set; 51 | } 52 | 53 | public long RegisterDevToolsProtocolEventReceived(Action callback) 54 | { 55 | DevToolsProtocolEventReceivedEventHandler completedHandler = new DevToolsProtocolEventReceivedEventHandler(EventName, callback); 56 | 57 | EventRegistrationToken token; 58 | _reciever.add_DevToolsProtocolEventReceived(completedHandler, out token); 59 | return token.value; 60 | } 61 | 62 | /// 63 | /// Remove an event handler previously added with RegisterDevToolsProtocolEventReceived 64 | /// 65 | /// 66 | public void UnregisterDevToolsProtocolEventReceived(long token) 67 | { 68 | EventRegistrationToken registrationToken = new EventRegistrationToken() 69 | { 70 | value = token 71 | }; 72 | _reciever.remove_DevToolsProtocolEventReceived(registrationToken); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Src/Wrapper/WebView2WebResourceRequest.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using System; 27 | using System.Runtime.InteropServices.ComTypes; 28 | using MtrDev.WebView2.Interop; 29 | 30 | namespace MtrDev.WebView2.Wrapper 31 | { 32 | public class WebView2WebResourceRequest 33 | { 34 | private ICoreWebView2WebResourceRequest _request; 35 | 36 | internal WebView2WebResourceRequest(ICoreWebView2WebResourceRequest request) 37 | { 38 | _request = request; 39 | } 40 | 41 | /// 42 | /// The request URI. 43 | /// 44 | public string Uri 45 | { 46 | get => _request.Uri; 47 | set => _request.Uri = value; 48 | } 49 | 50 | /// 51 | /// The HTTP request method. 52 | /// 53 | public string Method 54 | { 55 | get { return _request.Method; } 56 | set { _request.Method = value; } 57 | } 58 | 59 | /// 60 | /// The HTTP request message body as stream. POST data would be here. 61 | /// If a stream is set, which will override the message body, the stream must 62 | /// have all the content data available by the time this 63 | /// response's WebResourceRequested event deferral is completed. Stream 64 | /// should be agile or be created from a background STA to prevent performance 65 | /// impact to the UI thread. Null means no content data. IStream semantics 66 | /// apply (return S_OK to Read calls until all data is exhausted) 67 | /// 68 | public IStream Content 69 | { 70 | get { return _request.Content; } 71 | set { _request.Content = value; } 72 | } 73 | 74 | /// 75 | /// The mutable HTTP request headers 76 | /// 77 | public WebView2HttpRequestHeaderCollection Headers 78 | { 79 | get { return new WebView2HttpRequestHeaderCollection(_request.Headers); } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # webview2-interop 4 | Interop and C# wrapper classes for Microsoft WebView2 web browser control 5 | 6 | When Microsoft revealed their plans for a Chrome based Edge browser the first thing I thought was "I wonder if they are going to support an embedded web browser control"? Well sure enough they released [WebView2](https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2) and I've been keeping an eye on the releases. Recently I found a great [sample](https://github.com/MicrosoftEdge/WebView2Browser) written by [David Risney](https://github.com/david-risney) and I was inspired to take a shot at putting together a C# version. 7 | 8 | This project contains interop code for the WebView2. Most of it has been modified from what you get from the standard tlbimp command. Besides the interop classes which match the [WebView2 interface](https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2/reference-webview2) closely there are also some wrapper classes around the interfaces available. The wrappers try to take some of the patterns used in C++ and hopefully make them a little more C# friendly. For example the add/remove methods with interface callbacks have been changed to Register/Unregister that take Actions with event arguments. 9 | 10 | The browser demo project can be downloaded from [webview2-dotnetbrowser](https://github.com/michael-russin/webview2-dotnetbrowser) 11 | 12 | Besides using this project it uses a [WebView2 Windows Forms control](https://github.com/michael-russin/webview2-control) implementation of WebView2 you can use in the Visual Studio designer. 13 | 14 | ## Installing / Getting started 15 | 16 | * Microsoft Edge (Chromium) installed on a supported OS. 17 | * Visual Stdio 2017 or 2019 with C# and desktop development set up 18 | 19 | ### Initial Configuration 20 | 21 | Some projects require initial configuration (e.g. access tokens or keys, `npm i`). 22 | This is the section where you would document those requirements. 23 | 24 | ## Features 25 | 26 | * Interop classes for the WebView2 27 | * Wrapper classes around WebView2 interfaces 28 | 29 | * If you are using 0.9.430 check [here](./implemented0.9.430.md) to see what is implemented and working. 30 | * If you are using 0.8.355 or below check [here](./implemented.md) to see what is implemented and working. 31 | 32 | ## Contributing 33 | 34 | If you'd like to contribute, please fork the repository and use a feature 35 | branch. Please let me know of any issues you run into. 36 | 37 | ## Links 38 | - Nuget download: https://www.nuget.org/packages/MtrDev.WebView2.Interop/ 39 | - Project homepage: https://github.com/michael-russin/webview2-interop 40 | - Repository: https://github.com/michael-russin/webview2-interop 41 | - Issue tracker: https://github.com/michael-russin/webview2-interop/issues 42 | - Related projects: 43 | - WebView2 Windows Forms Control: https://github.com/michael-russin/webview2-control 44 | - David's awsome C++ sample: https://github.com/MicrosoftEdge/WebView2Browser 45 | - WebView2 Documentation: https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2/reference-webview2 46 | 47 | 48 | ## Licensing 49 | 50 | The code in this project is licensed under MIT license. 51 | -------------------------------------------------------------------------------- /Src/Interop/ICoreWebView2NewWindowRequestedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace MtrDev.WebView2.Interop 6 | { 7 | /// 8 | /// Event args for the NewWindowRequested event. The event is fired when content 9 | /// inside webview requested to a open a new window (through window.open() etc.) 10 | /// 11 | [ComVisible(true)] 12 | [ComImport] 13 | [Guid("DDBF77B3-3411-44AB-AA15-FDFC93AFFCF8")] 14 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 15 | public interface ICoreWebView2NewWindowRequestedEventArgs 16 | { 17 | /// 18 | /// The target uri of the NewWindowRequest. 19 | /// 20 | [DispId(1610678272)] 21 | string Uri 22 | { 23 | [return: MarshalAs(UnmanagedType.LPWStr)] 24 | get; 25 | } 26 | 27 | /// 28 | /// Sets a WebView as a result of the NewWindowRequest. The target 29 | /// webview should not be navigated. If the NewWindow is set, its top level 30 | /// window will return as the opened WindowProxy. 31 | /// 32 | [DispId(1610678273)] 33 | ICoreWebView2 NewWindow 34 | { 35 | [param: MarshalAs(UnmanagedType.Interface)] 36 | set; 37 | [return: MarshalAs(UnmanagedType.Interface)] 38 | get; 39 | } 40 | 41 | //void put_NewWindow([In] IWebView2WebView newWindow); 42 | ///// Gets the new window. 43 | //void get_NewWindow([Out]out IWebView2WebView newWindow); 44 | 45 | /// 46 | /// Sets whether the NewWindowRequestedEvent is handled by host. If this is false 47 | /// and no NewWindow is set, the WebView will open a popup 48 | /// window and it will be returned as opened WindowProxy. 49 | /// If set to true and no NewWindow is set for a window.open call, the opened 50 | /// WindowProxy will be for an dummy window object and no window will load. 51 | /// Default is false. 52 | /// 53 | [DispId(1610678275)] 54 | bool Handled 55 | { 56 | [param: MarshalAs(UnmanagedType.Bool)] 57 | set; 58 | [return: MarshalAs(UnmanagedType.Bool)] 59 | get; 60 | } 61 | 62 | /// 63 | /// IsUserInitiated is true when the new window request was initiated through a user gesture 64 | /// such as clicking an anchor tag with target. 65 | /// 66 | [DispId(1610678277)] 67 | bool IsUserInitiated 68 | { 69 | [return: MarshalAs(UnmanagedType.Bool)] 70 | get; 71 | } 72 | 73 | /// 74 | /// Obtain an IWebView2Deferral object and put the event into a deferred state. 75 | /// You can use the IWebView2Deferral object to complete the window open 76 | /// request at a later time. 77 | /// While this event is deferred the opener window will be returned a WindowProxy 78 | /// to an unnavigated window, which will navigate when the deferral is complete. 79 | /// 80 | /// 81 | ICoreWebView2Deferral GetDeferral(); 82 | } 83 | } -------------------------------------------------------------------------------- /Src/Wrapper/WebView2HttpRequestHeaderCollection.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using MtrDev.WebView2.Interop; 26 | using System; 27 | using System.Collections.Generic; 28 | using System.Collections.ObjectModel; 29 | 30 | namespace MtrDev.WebView2.Wrapper 31 | { 32 | public class WebView2HttpRequestHeaderCollection 33 | { 34 | private ICoreWebView2HttpRequestHeaders _httpHeaders; 35 | private IDictionary _headerNameValues; 36 | 37 | internal WebView2HttpRequestHeaderCollection(ICoreWebView2HttpRequestHeaders httpHeaders) 38 | { 39 | _httpHeaders = httpHeaders; 40 | _headerNameValues = new Dictionary(); 41 | 42 | ICoreWebView2HttpHeadersCollectionIterator iterator; 43 | _httpHeaders.GetIterator(out iterator); 44 | if (iterator != null) 45 | { 46 | int hasNext; 47 | iterator.MoveNext(out hasNext); 48 | while (hasNext != 0) 49 | { 50 | string name; 51 | string value; 52 | 53 | iterator.GetCurrentHeader(out name, out value); 54 | _headerNameValues.Add(name, value); 55 | iterator.MoveNext(out hasNext); 56 | } 57 | 58 | } 59 | } 60 | 61 | public void SetHeader(string name, string value) 62 | { 63 | _httpHeaders.SetHeader(name, value); 64 | if (_headerNameValues.ContainsKey(name)) 65 | { 66 | _headerNameValues[name] = value; 67 | } 68 | else 69 | { 70 | _headerNameValues.Add(name, value); 71 | } 72 | } 73 | 74 | public void Remove(string name) 75 | { 76 | _httpHeaders.RemoveHeader(name); 77 | _headerNameValues.Remove(name); 78 | } 79 | 80 | public IReadOnlyDictionary HeaderDictionary 81 | { 82 | get 83 | { 84 | return new ReadOnlyDictionary(_headerNameValues); 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Src/Interop/Globals.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MtrDev.WebView2.Interop 9 | { 10 | public class Globals 11 | { 12 | private Globals() 13 | { 14 | } 15 | 16 | /// 17 | /// DLL export to create a WebView2 environment with a custom version of Edge, 18 | /// user data directory and/or additional browser switches. 19 | /// 20 | /// the relative path to the folder that contains the embedded Edge 21 | /// specified to change the default user data folder location for 22 | /// WebView2. The path can be an absolute file path or a relative file path 23 | /// that is interpreted as relative to the current process's executable 24 | /// 25 | /// 26 | /// 27 | [DllImport(ExternDll.WebView2Loader, SetLastError = true)] 28 | public static extern int CreateCoreWebView2EnvironmentWithDetails( 29 | [In, MarshalAs(UnmanagedType.LPWStr)] 30 | string browserExecutableFolder, 31 | [In, MarshalAs(UnmanagedType.LPWStr)] 32 | string userDataFolder, 33 | [In, MarshalAs(UnmanagedType.LPWStr)] 34 | string additionalBrowserArguments, 35 | [In] ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler environment_created_handler); 36 | 37 | /// 38 | /// Creates an evergreen WebView2 Environment using the installed Edge version. 39 | /// This is equivalent to calling CreateWebView2EnvironmentWithDetails with 40 | /// nullptr for browserExecutableFolder, userDataFolder, additionalBrowserArguments. 41 | /// See CreateWebView2EnvironmentWithDetails for more details 42 | /// 43 | /// 44 | /// 45 | [DllImport(ExternDll.WebView2Loader, SetLastError = true)] 46 | public static extern int CreateCoreWebView2Environment( 47 | [In] ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler environment_created_handler); 48 | 49 | /// 50 | /// Get the browser version info including channel name if it is not the stable channel 51 | /// or the Embedded Edge. 52 | /// Channel names are beta, dev, and canary. 53 | /// If an override exists for the browserExecutableFolder or the channel preference, 54 | /// the override will be used. 55 | /// If there isn't an override, then the parameter passed to GetWebView2BrowserVersionInfo is used. 56 | /// 57 | /// 58 | /// 59 | /// 60 | [DllImport(ExternDll.WebView2Loader, SetLastError = true)] 61 | public static extern int GetCoreWebView2BrowserVersionInfo( 62 | [In, MarshalAs(UnmanagedType.LPWStr)] 63 | string browserExecutableFolder, 64 | [MarshalAs(UnmanagedType.LPWStr)] 65 | out string versionInfo); 66 | 67 | [DllImport(ExternDll.WebView2Loader, SetLastError = true)] 68 | public static extern int CompareBrowserVersions( 69 | [In, MarshalAs(UnmanagedType.LPWStr)] 70 | string version1, 71 | [In, MarshalAs(UnmanagedType.LPWStr)] 72 | string version2, 73 | out int result); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/NavigationStartingEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | 26 | using System; 27 | using MtrDev.WebView2.Interop; 28 | 29 | namespace MtrDev.WebView2.Wrapper 30 | { 31 | public class NavigationStartingEventArgs : EventArgs, ICoreWebView2NavigationStartingEventArgs 32 | { 33 | private ICoreWebView2NavigationStartingEventArgs _args; 34 | 35 | internal NavigationStartingEventArgs(ICoreWebView2NavigationStartingEventArgs args) 36 | { 37 | _args = args; 38 | } 39 | 40 | /// 41 | /// The uri of the requested navigation. 42 | /// 43 | public string Uri 44 | { 45 | get => _args.Uri; 46 | } 47 | 48 | /// 49 | /// True when the navigation was initiated through a user gesture as opposed 50 | /// to programmatic navigation. 51 | /// 52 | public bool IsUserInitiated 53 | { 54 | get => _args.IsUserInitiated; 55 | } 56 | 57 | /// 58 | /// True when the navigation is redirected. 59 | /// 60 | /// 61 | public bool IsRedirected 62 | { 63 | get => _args.IsRedirected; 64 | } 65 | 66 | private WebView2HttpRequestHeaderCollection _httpHeaderCollection; 67 | public WebView2HttpRequestHeaderCollection HttpHeaderCollection 68 | { 69 | get 70 | { 71 | if (_httpHeaderCollection == null) 72 | { 73 | _httpHeaderCollection = new WebView2HttpRequestHeaderCollection(_args.RequestHeaders); 74 | } 75 | return _httpHeaderCollection; 76 | } 77 | } 78 | 79 | /// 80 | /// The host may set this flag to cancel the navigation. 81 | /// If set, it will be as if the navigation never happened and the current 82 | /// page's content will be intact. For performance reasons, GET HTTP requests 83 | /// may happen, while the host is responding. This means cookies can be set 84 | /// and used part of a request for the navigation. 85 | /// 86 | /// 87 | public bool Cancel 88 | { 89 | get => _args.Cancel; 90 | set => _args.Cancel = value; 91 | } 92 | 93 | ICoreWebView2HttpRequestHeaders ICoreWebView2NavigationStartingEventArgs.RequestHeaders 94 | { 95 | get => throw new NotImplementedException(); 96 | } 97 | 98 | public long NavigationId => _args.NavigationId; 99 | 100 | public override string ToString() 101 | { 102 | return string.Format("Uri={0}, IsUserInitiated={1}, IsRedirected={2}, Cancel={3}, NavigationId={4}", Uri, IsUserInitiated, IsRedirected, Cancel, NavigationId); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Src/Wrapper/EventArgs/WebMessageReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using System; 26 | using MtrDev.WebView2.Interop; 27 | 28 | namespace MtrDev.WebView2.Wrapper 29 | { 30 | public class WebMessageReceivedEventArgs : EventArgs, ICoreWebView2WebMessageReceivedEventArgs 31 | { 32 | private ICoreWebView2WebMessageReceivedEventArgs _args; 33 | 34 | internal WebMessageReceivedEventArgs(ICoreWebView2WebMessageReceivedEventArgs args) 35 | { 36 | _args = args; 37 | } 38 | 39 | /// 40 | /// The URI of the document that sent this web message. 41 | /// 42 | public string Source 43 | { 44 | get 45 | { 46 | return _args.Source; 47 | } 48 | } 49 | 50 | /// 51 | /// The message posted from the webview content to the host converted to a 52 | /// JSON string. Use this to communicate via JavaScript objects. 53 | /// 54 | /// For example the following postMessage calls result in the 55 | /// following WebMessageAsJson values: 56 | /// 57 | /// ``` 58 | /// postMessage({'a': 'b'}) L"{\"a\": \"b\"}" 59 | /// postMessage(1.2) L"1.2" 60 | /// postMessage('example') L"\"example\"" 61 | /// ``` 62 | /// 63 | public string WebMessageAsJson 64 | { 65 | get 66 | { 67 | return _args.WebMessageAsJson; 68 | } 69 | } 70 | 71 | /// 72 | /// If the message posted from the webview content to the host is a 73 | /// string type, this method will return the value of that string. If the 74 | /// message posted is some other kind of JavaScript type this method will fail 75 | /// with E_INVALIDARG. Use this to communicate via simple strings. 76 | /// 77 | /// For example the following postMessage calls result in the 78 | /// following WebMessageAsString values: 79 | /// 80 | /// ``` 81 | /// postMessage({'a': 'b'}) E_INVALIDARG 82 | /// postMessage(1.2) E_INVALIDARG 83 | /// postMessage('example') L"example" 84 | /// ``` 85 | /// 86 | public string WebMessageAsString 87 | { 88 | get 89 | { 90 | try 91 | { 92 | return _args.WebMessageAsString; 93 | } 94 | catch(Exception) 95 | { 96 | } 97 | return null; 98 | } 99 | } 100 | public override string ToString() 101 | { 102 | return string.Format("Source={0}, WebMessageAsJson={1}, WebMessageAsString={2}", Source, WebMessageAsJson, WebMessageAsString); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Src/Wrapper/WebView2Loader.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright (c) 2019 Michael T. Russin 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | #endregion 25 | using MtrDev.WebView2.Interop; 26 | using MtrDev.WebView2.Wrapper.Handlers; 27 | using System; 28 | 29 | namespace MtrDev.WebView2.Wrapper 30 | { 31 | /// 32 | /// Exposes global methods from WebView2Loader.dll 33 | /// 34 | public class WebView2Loader 35 | { 36 | private WebView2Loader() { } 37 | 38 | /// 39 | /// Create a WebView2 environment with a custom version of Edge, user data directory and/or additional browser switches. 40 | /// 41 | /// relative path to the folder that contains the embedded Edge 42 | /// specified to change the default user data folder location for WebView2 43 | /// Specified to change the behavior of the WebView. These will be passed to the browser process as part of the command line. 44 | /// Callback when complete 45 | /// 46 | public static int CreateEnvironmentWithDetails( 47 | string browserExecutableFolder, 48 | string userDataFolder, 49 | string additionalBrowserArguments, 50 | Action callback) 51 | { 52 | EnvironmentCompletedHandler handler = new EnvironmentCompletedHandler(callback); 53 | int hr = Globals.CreateCoreWebView2EnvironmentWithDetails(browserExecutableFolder, 54 | userDataFolder, 55 | additionalBrowserArguments, 56 | handler); 57 | 58 | if(hr != 0 && callback !=null) 59 | { 60 | EnvironmentCreatedEventArgs args = new EnvironmentCreatedEventArgs(hr, null); 61 | callback.Invoke(args); 62 | } 63 | return hr; 64 | } 65 | 66 | /// 67 | /// Creates an evergreen WebView2 Environment using the installed Edge version. 68 | /// 69 | /// 70 | /// 71 | public static int CreateEnvironment(Action callback) 72 | { 73 | EnvironmentCompletedHandler handler = new EnvironmentCompletedHandler(callback); 74 | int hr = Globals.CreateCoreWebView2Environment(handler); 75 | if (hr != 0 && callback != null) 76 | { 77 | EnvironmentCreatedEventArgs args = new EnvironmentCreatedEventArgs(hr, null); 78 | callback.Invoke(args); 79 | } 80 | return hr; 81 | } 82 | 83 | /// 84 | /// Get the browser version info including channel name if it is not the stable channel or the Embedded Edge. 85 | /// 86 | /// 87 | /// 88 | /// 89 | public static int GetWebView2BrowserVersionInfo(string browserExecutableFolder, out string versionInfo) 90 | { 91 | int hr = Globals.GetCoreWebView2BrowserVersionInfo(browserExecutableFolder, out versionInfo); 92 | return hr; 93 | } 94 | 95 | public static int CompareBrowserVersions(string version1, string version2) 96 | { 97 | int result = 0; 98 | int hr = Globals.CompareBrowserVersions(version1, version2, out result); 99 | return result; 100 | } 101 | } 102 | } 103 | --------------------------------------------------------------------------------