From 8e314d11d33f83e045e2084fa201098a7b359530 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Wed, 26 May 2021 15:54:56 -0700 Subject: [PATCH 01/17] WIP --- .editorconfig | 3 + .../WebView2/src/ICoreWebView2Wrapper.cs | 86 +++++++ .../WebView2/src/IWebView2Wrapper.cs | 240 ++++++++++++++++-- .../WebView2/src/WebView2WebViewManager.cs | 19 +- .../WindowsForms/src/BlazorWebView.cs | 5 +- .../WindowsForms/src/RootComponent.cs | 4 +- .../src/WindowsFormsWebView2Wrapper.cs | 108 +++++++- 7 files changed, 425 insertions(+), 40 deletions(-) create mode 100644 src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs diff --git a/.editorconfig b/.editorconfig index caf209beba4a..65036f0cc71e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -49,6 +49,9 @@ csharp_new_line_before_finally = true csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_members_in_anonymous_types = true +# RS0016: Add public types and members to the declared API +dotnet_diagnostic.RS0016.severity = none + [*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}] indent_size = 2 diff --git a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs new file mode 100644 index 000000000000..4b1a1e92e13e --- /dev/null +++ b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs @@ -0,0 +1,86 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.AspNetCore.Components.WebView.WebView2 +{ + public interface ICoreWebView2Wrapper + { + void PostWebMessageAsString(string message); + void AddWebResourceRequestedFilter(string uri, CoreWebView2WebResourceContextWrapper ResourceContext); + Action AddWebResourceRequestedHandler(EventHandler eventHandler); + } + + public enum CoreWebView2WebResourceContextWrapper + { + /// + /// Specifies all resources. + /// + All, + /// + /// Specifies a document resources. + /// + Document, + /// + /// Specifies a CSS resources. + /// + Stylesheet, + /// + /// Specifies an image resources. + /// + Image, + /// + /// Specifies another media resource such as a video. + /// + Media, + /// + /// Specifies a font resource. + /// + Font, + /// + /// Specifies a script resource. + /// + Script, + /// + /// Specifies an XML HTTP request. + /// + XmlHttpRequest, + /// + /// Specifies a Fetch API communication. + /// + Fetch, + /// + /// Specifies a TextTrack resource. + /// + TextTrack, + /// + /// Specifies an EventSource API communication. + /// + EventSource, + /// + /// Specifies a WebSocket API communication. + /// + Websocket, + /// + /// Specifies a Web App Manifest. + /// + Manifest, + /// + /// Specifies a Signed HTTP Exchange. + /// + SignedExchange, + /// + /// Specifies a Ping request. + /// + Ping, + /// + /// Specifies a CSP Violation Report. + /// + CspViolationReport, + /// + /// Specifies an other resource. + /// + Other + } +} diff --git a/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs b/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs index e406af0b9c8b..0617f5a9c7db 100644 --- a/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs +++ b/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs @@ -2,40 +2,248 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; -using Microsoft.Web.WebView2.Core; namespace Microsoft.AspNetCore.Components.WebView.WebView2 { /// /// Provides an abstraction for different UI frameworks to provide access to APIs from - /// and related controls. + /// Microsoft.Web.WebView2.Core.CoreWebView2 and related controls. /// - public interface IWebView2Wrapper + public interface IWebView2Wrapper { - /// - /// Gets the instance on the control. This is only available - /// once the returned by - /// has completed. - /// - CoreWebView2 CoreWebView2 { get; } + TWebView2 WebView2 { get; } + + Task> CreateEnvironmentAsync(); + + + ICoreWebView2Wrapper CoreWebView2 { get; } /// /// Gets or sets the source URI of the control. Setting the source URI causes page navigation. /// Uri Source { get; set; } + Task EnsureCoreWebView2Async(ICoreWebView2EnvironmentWrapper environment = null); + /// - /// Initializes the instance on the control. This should only be called once - /// per control. + /// Event that occurs when an accelerator key is pressed. /// - /// A that can be used to customize the control's behavior. - /// A that will complete once the is initialized and attached to the control. - Task EnsureCoreWebView2Async(CoreWebView2Environment environment = null); + Action AddAcceleratorKeyPressedHandler(EventHandler eventHandler); + } + public interface ICoreWebView2WebResourceRequestedEventArgsWrapper + { /// - /// Event that occurs when an accelerator key is pressed. + /// Gets the web resource request. + /// + /// + /// The request object may be missing some headers that are added by network stack at a later time. + /// + public ICoreWebView2WebResourceRequestWrapper Request { get; } + + /// + /// Gets or sets the object. + /// + /// + /// If this object is set, the event will be completed with this Response. + /// An empty object can be created with and then modified to construct the Response. + /// + public ICoreWebView2WebResourceResponseWrapper Response { get; set; } + + /// + /// Gets the web resource request context. + /// + public CoreWebView2WebResourceContextWrapper ResourceContext { get; } + } + + + /// + /// An HTTP request used with the event. + /// + public interface ICoreWebView2WebResourceRequestWrapper + { + /// + /// Gets or sets the request URI. + /// + string Uri { get; set; } + + /// + /// Gets or sets the HTTP request method. + /// + string Method { get; set; } + + /// + /// Gets or sets the HTTP request message body as stream. + /// + /// + /// POST data should be here. If a stream is set, which overrides the message body, the stream must have all the content data available by the time the event deferral of this request is completed. Stream should be agile or be created from a background STA to prevent performance impact to the UI thread. null means no content data. + /// + /// + Stream Content { get; set; } + + ///// + ///// Gets the mutable HTTP request headers. + ///// + //ICoreWebView2HttpRequestHeadersWrapper Headers { get; } + } + + + /// + /// An HTTP response used with the event. + /// + public interface ICoreWebView2WebResourceResponseWrapper + { + /// + /// Gets HTTP response content as stream. + /// + /// + /// Stream must have all the content data available by the time the event deferral of this response is completed. Stream should be agile or be created from a background thread to prevent performance impact to the UI thread. null means no content data. + /// + /// + Stream Content { get; set; } + + /// + /// Gets the overridden HTTP response headers. /// - event EventHandler AcceleratorKeyPressed; + ICoreWebView2HttpResponseHeadersWrapper Headers { get; } + + /// + /// Gets or sets the HTTP response status code. + /// + int StatusCode { get; set; } + + /// + /// Gets or sets the HTTP response reason phrase. + /// + string ReasonPhrase { get; set; } + } + + + + + + + //public interface ICoreWebView2HttpRequestHeadersWrapper : IEnumerable>, IEnumerable + //{ + // /// + // IEnumerator IEnumerable.GetEnumerator() + // { + // return GetEnumerator(); + // } + + // /// + // IEnumerator> IEnumerable>.GetEnumerator() + // { + // return GetEnumerator(); + // } + + // /// + // /// Returns an enumerator that iterates through the or collection. + // /// + // CoreWebView2HttpHeadersCollectionIterator GetEnumerator() + // { + // return GetIterator(); + // } + + // internal CoreWebView2HttpRequestHeaders(object rawCoreWebView2HttpRequestHeaders) + // { + // _rawNative = rawCoreWebView2HttpRequestHeaders; + // } + + // /// + // /// Gets the header value matching the name. + // /// + // /// The header value matching the name. + // string GetHeader(string name) + // { + // return _nativeICoreWebView2HttpRequestHeaders.GetHeader(name); + // } + + // /// + // /// Gets the header value matching the name using a . + // /// + // /// The header value matching the name. + // CoreWebView2HttpHeadersCollectionIterator GetHeaders(string name) + // { + // return new CoreWebView2HttpHeadersCollectionIterator(_nativeICoreWebView2HttpRequestHeaders.GetHeaders(name)); + // } + + // /// + // /// Checks whether the headers contain an entry that matches the header name. + // /// + // /// Whether the headers contain an entry that matches the header name. + // bool Contains(string name) + // { + // return _nativeICoreWebView2HttpRequestHeaders.Contains(name) != 0; + // } + + // /// + // /// Adds or updates header that matches the name. + // /// + // void SetHeader(string name, string value) + // { + // _nativeICoreWebView2HttpRequestHeaders.SetHeader(name, value); + // } + + // /// + // /// Removes header that matches the name. + // /// + // void RemoveHeader(string name) + // { + // _nativeICoreWebView2HttpRequestHeaders.RemoveHeader(name); + // } + + // /// + // /// Gets a over the collection of request headers. + // /// + // CoreWebView2HttpHeadersCollectionIterator GetIterator() + // { + // return new CoreWebView2HttpHeadersCollectionIterator(_nativeICoreWebView2HttpRequestHeaders.GetIterator()); + // } + //} + + public interface ICoreWebView2HttpResponseHeadersWrapper : IEnumerable>, IEnumerable + { + /// + /// Appends header line with name and value. + /// + /// The header name to be appended. + /// The header value to be appended. + void AppendHeader(string name, string value); + + /// + /// Checks whether this CoreWebView2HttpResponseHeaders contain entries matching the header name. + /// + /// The name of the header to seek. + bool Contains(string name); + + /// + /// Gets the first header value in the collection matching the name. + /// + /// The header name. + /// The first header value in the collection matching the name. + string GetHeader(string name); + + /// + /// Gets the header values matching the name. + /// + /// The header name. + CoreWebView2HttpHeadersCollectionIterator GetHeaders(string name); + + } + + public interface ICoreWebView2AcceleratorKeyPressedEventArgsWrapper + { + uint VirtualKey { get; } + int KeyEventLParam { get; } + bool Handled { get; set; } + } + + public interface ICoreWebView2EnvironmentWrapper + { + TCoreWebView2Environment CoreWebView2Environment { get; } } } diff --git a/src/Components/WebView/Platforms/WebView2/src/WebView2WebViewManager.cs b/src/Components/WebView/Platforms/WebView2/src/WebView2WebViewManager.cs index 3180af07cdaf..afc2e95d5f57 100644 --- a/src/Components/WebView/Platforms/WebView2/src/WebView2WebViewManager.cs +++ b/src/Components/WebView/Platforms/WebView2/src/WebView2WebViewManager.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.FileProviders; -using Microsoft.Web.WebView2.Core; namespace Microsoft.AspNetCore.Components.WebView.WebView2 { @@ -14,25 +13,25 @@ namespace Microsoft.AspNetCore.Components.WebView.WebView2 /// An implementation of that uses the Edge WebView2 browser control /// to render web content. /// - public class WebView2WebViewManager : WebViewManager + public class WebView2WebViewManager : WebViewManager { // Using an IP address means that WebView2 doesn't wait for any DNS resolution, // making it substantially faster. Note that this isn't real HTTP traffic, since // we intercept all the requests within this origin. private const string AppOrigin = "https://0.0.0.0/"; - private readonly IWebView2Wrapper _webview; + private readonly IWebView2Wrapper _webview; private readonly Task _webviewReadyTask; /// - /// Constructs an instance of . + /// Constructs an instance of . /// /// A wrapper to access platform-specific WebView2 APIs. /// A service provider containing services to be used by this class and also by application code. /// A instance that can marshal calls to the required thread or sync context. /// Provides static content to the webview. /// Path to the host page within the . - public WebView2WebViewManager(IWebView2Wrapper webview, IServiceProvider services, Dispatcher dispatcher, IFileProvider fileProvider, string hostPageRelativePath) + public WebView2WebViewManager(IWebView2Wrapper webview, IServiceProvider services, Dispatcher dispatcher, IFileProvider fileProvider, string hostPageRelativePath) : base(services, dispatcher, new Uri(AppOrigin), fileProvider, hostPageRelativePath) { _webview = webview ?? throw new ArgumentNullException(nameof(webview)); @@ -59,12 +58,12 @@ protected override void SendMessage(string message) private async Task InitializeWebView2() { - var environment = await CoreWebView2Environment.CreateAsync().ConfigureAwait(true); + var environment = await _webview.CreateEnvironmentAsync().ConfigureAwait(true); await _webview.EnsureCoreWebView2Async(environment); ApplyDefaultWebViewSettings(); - _webview.CoreWebView2.AddWebResourceRequestedFilter($"{AppOrigin}*", CoreWebView2WebResourceContext.All); - _webview.CoreWebView2.WebResourceRequested += (sender, eventArgs) => + _webview.CoreWebView2.AddWebResourceRequestedFilter($"{AppOrigin}*", CoreWebView2WebResourceContextWrapper.All); + _webview.CoreWebView2.AddWebResourceRequestedHandler(eventArgs => { // Unlike server-side code, we get told exactly why the browser is making the request, // so we can be smarter about fallback. We can ensure that 'fetch' requests never result @@ -111,7 +110,7 @@ private void ApplyDefaultWebViewSettings() // Desktop applications don't normally want to enable things like "alt-left to go back" // or "ctrl+f to find". Developers should explicitly opt into allowing these. // Issues #30511 and #30624 track making an option to control this. - _webview.AcceleratorKeyPressed += (sender, eventArgs) => + var removeCallback = _webview.AddAcceleratorKeyPressedHandler((sender, eventArgs) => { if (eventArgs.VirtualKey != 0x49) // Allow ctrl+shift+i to open dev tools, at least for now { @@ -120,7 +119,7 @@ private void ApplyDefaultWebViewSettings() // WinForms. Leaving the code here because it's supposedly fixed in a newer version. eventArgs.Handled = true; } - }; + }); } } } diff --git a/src/Components/WebView/Platforms/WindowsForms/src/BlazorWebView.cs b/src/Components/WebView/Platforms/WindowsForms/src/BlazorWebView.cs index 78a3df51baa3..76f05ce7b66a 100644 --- a/src/Components/WebView/Platforms/WindowsForms/src/BlazorWebView.cs +++ b/src/Components/WebView/Platforms/WindowsForms/src/BlazorWebView.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using Microsoft.AspNetCore.Components.WebView.WebView2; using Microsoft.Extensions.FileProviders; +using Microsoft.Web.WebView2.Core; using WebView2Control = Microsoft.Web.WebView2.WinForms.WebView2; namespace Microsoft.AspNetCore.Components.WebView.WindowsForms @@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Components.WebView.WindowsForms public sealed class BlazorWebView : ContainerControl, IDisposable { private readonly WebView2Control _webview; - private WebView2WebViewManager _webviewManager; + private WebView2WebViewManager _webviewManager; private string _hostPage; private IServiceProvider _services; @@ -139,7 +140,7 @@ private void StartWebViewCoreIfPossible() var hostPageRelativePath = Path.GetRelativePath(contentRootDir, HostPage); var fileProvider = new PhysicalFileProvider(contentRootDir); - _webviewManager = new WebView2WebViewManager(new WindowsFormsWebView2Wrapper(_webview), Services, Dispatcher, fileProvider, hostPageRelativePath); + _webviewManager = new WebView2WebViewManager(new WindowsFormsWebView2Wrapper(_webview), Services, Dispatcher, fileProvider, hostPageRelativePath); foreach (var rootComponent in RootComponents) { // Since the page isn't loaded yet, this will always complete synchronously diff --git a/src/Components/WebView/Platforms/WindowsForms/src/RootComponent.cs b/src/Components/WebView/Platforms/WindowsForms/src/RootComponent.cs index 037ada5ce24f..fa6b148cf3bc 100644 --- a/src/Components/WebView/Platforms/WindowsForms/src/RootComponent.cs +++ b/src/Components/WebView/Platforms/WindowsForms/src/RootComponent.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Components.WebView.WebView2; +using Microsoft.Web.WebView2.Core; +using WebView2Control = Microsoft.Web.WebView2.WinForms.WebView2; namespace Microsoft.AspNetCore.Components.WebView.WindowsForms { @@ -53,7 +55,7 @@ internal Task AddToWebViewManagerAsync(WebViewManager webViewManager) return webViewManager.AddRootComponentAsync(ComponentType, Selector, parameterView); } - internal Task RemoveFromWebViewManagerAsync(WebView2WebViewManager webviewManager) + internal Task RemoveFromWebViewManagerAsync(WebView2WebViewManager webviewManager) { return webviewManager.RemoveRootComponentAsync(Selector); } diff --git a/src/Components/WebView/Platforms/WindowsForms/src/WindowsFormsWebView2Wrapper.cs b/src/Components/WebView/Platforms/WindowsForms/src/WindowsFormsWebView2Wrapper.cs index 6459ea4cedd7..f0d2815a858c 100644 --- a/src/Components/WebView/Platforms/WindowsForms/src/WindowsFormsWebView2Wrapper.cs +++ b/src/Components/WebView/Platforms/WindowsForms/src/WindowsFormsWebView2Wrapper.cs @@ -9,9 +9,9 @@ namespace Microsoft.AspNetCore.Components.WebView.WindowsForms { - internal class WindowsFormsWebView2Wrapper : IWebView2Wrapper + internal class WindowsFormsWebView2Wrapper : IWebView2Wrapper { - private readonly WebView2Control _webView2; + private readonly WindowsFormsCoreWebView2Wrapper _coreWebView2Wrapper; public WindowsFormsWebView2Wrapper(WebView2Control webView2) { @@ -20,26 +20,112 @@ public WindowsFormsWebView2Wrapper(WebView2Control webView2) throw new ArgumentNullException(nameof(webView2)); } - _webView2 = webView2; + WebView2 = webView2; + _coreWebView2Wrapper = new WindowsFormsCoreWebView2Wrapper(WebView2); + } + + public ICoreWebView2Wrapper CoreWebView2 => _coreWebView2Wrapper; + + public async Task> CreateEnvironmentAsync() + { + return new WindowsFormsCoreWebView2EnvironmentWrapper(await CoreWebView2Environment.CreateAsync()); } - public CoreWebView2 CoreWebView2 => _webView2.CoreWebView2; public Uri Source { - get => _webView2.Source; - set => _webView2.Source = value; + get => WebView2.Source; + set => WebView2.Source = value; + } + + public WebView2Control WebView2 { get; } + + public Action AddAcceleratorKeyPressedHandler(EventHandler eventHandler) + { + EventHandler realHandler = (object sender, CoreWebView2AcceleratorKeyPressedEventArgs e) => + { + eventHandler(WebView2, new WindowsFormsCoreWebView2AcceleratorKeyPressedEventArgsWrapper(e)); + }; + WebView2.AcceleratorKeyPressed += realHandler; + + // Return removal callback + return () => { WebView2.AcceleratorKeyPressed -= realHandler; }; + } + + public Task EnsureCoreWebView2Async(ICoreWebView2EnvironmentWrapper environment = null) + { + return WebView2.EnsureCoreWebView2Async(environment.CoreWebView2Environment); + } + } + + internal class WindowsFormsCoreWebView2AcceleratorKeyPressedEventArgsWrapper : ICoreWebView2AcceleratorKeyPressedEventArgsWrapper + { + private readonly CoreWebView2AcceleratorKeyPressedEventArgs _eventArgs; + + public WindowsFormsCoreWebView2AcceleratorKeyPressedEventArgsWrapper(CoreWebView2AcceleratorKeyPressedEventArgs eventArgs) + { + _eventArgs = eventArgs; + } + public uint VirtualKey => _eventArgs.VirtualKey; + + public int KeyEventLParam => _eventArgs.KeyEventLParam; + + public bool Handled + { + get => _eventArgs.Handled; + set => _eventArgs.Handled = value; + } + } + + internal class WindowsFormsCoreWebView2EnvironmentWrapper : ICoreWebView2EnvironmentWrapper + { + public WindowsFormsCoreWebView2EnvironmentWrapper(CoreWebView2Environment coreWebView2Environment) + { + if (coreWebView2Environment is null) + { + throw new ArgumentNullException(nameof(coreWebView2Environment)); + } + + CoreWebView2Environment = coreWebView2Environment; + } + + public CoreWebView2Environment CoreWebView2Environment { get; } + } + + internal class WindowsFormsCoreWebView2Wrapper : ICoreWebView2Wrapper + { + private readonly WebView2Control _webView2; + + public WindowsFormsCoreWebView2Wrapper(WebView2Control webView2) + { + if (webView2 is null) + { + throw new ArgumentNullException(nameof(webView2)); + } + + _webView2 = webView2; + } + + public void AddWebResourceRequestedFilter(string uri, CoreWebView2WebResourceContextWrapper ResourceContext) + { + _webView2.CoreWebView2.AddWebResourceRequestedFilter(uri, (CoreWebView2WebResourceContext)ResourceContext); } - public event EventHandler AcceleratorKeyPressed + public Action AddWebResourceRequestedHandler(EventHandler eventHandler) { - add => _webView2.AcceleratorKeyPressed += value; - remove => _webView2.AcceleratorKeyPressed -= value; + EventHandler realHandler = (object sender, CoreWebView2WebResourceRequestedEventArgs e) => + { + eventHandler(_webView2, new WindowsFormsCoreWebView2AcceleratorKeyPressedEventArgsWrapper(e)); + }; + _webView2.CoreWebView2.WebResourceRequested += realHandler; + + // Return removal callback + return () => { _webView2.CoreWebView2.WebResourceRequested -= realHandler; }; } - public Task EnsureCoreWebView2Async(CoreWebView2Environment environment = null) + public void PostWebMessageAsString(string message) { - return _webView2.EnsureCoreWebView2Async(environment); + _webView2.CoreWebView2.PostWebMessageAsString(message); } } } From 9ae5ce579c03a7a8370b76f19c26a9faa53ba981 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Thu, 27 May 2021 15:56:46 -0700 Subject: [PATCH 02/17] Wrapper works in WinForms! --- .../WebView2/src/ICoreWebView2Wrapper.cs | 17 +++- .../WebView2/src/IWebView2Wrapper.cs | 28 +++--- ...NetCore.Components.WebView.WebView2.csproj | 3 +- .../WebView2/src/WebView2WebViewManager.cs | 30 +++--- ...ore.Components.WebView.WindowsForms.csproj | 1 + .../src/WindowsFormsWebView2Wrapper.cs | 91 ++++++++++++++++--- 6 files changed, 127 insertions(+), 43 deletions(-) diff --git a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs index 4b1a1e92e13e..bfde511a04a1 100644 --- a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs +++ b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs @@ -2,14 +2,29 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; namespace Microsoft.AspNetCore.Components.WebView.WebView2 { - public interface ICoreWebView2Wrapper + public interface ICoreWebView2Wrapper { void PostWebMessageAsString(string message); void AddWebResourceRequestedFilter(string uri, CoreWebView2WebResourceContextWrapper ResourceContext); Action AddWebResourceRequestedHandler(EventHandler eventHandler); + Task AddScriptToExecuteOnDocumentCreatedAsync(string javaScript); + void AddWebMessageReceivedHandler(Action messageReceived); + } + + public class WebMessageReceivedEventArgs : EventArgs + { + public WebMessageReceivedEventArgs(string source, string webMessageAsString) + { + Source = source; + WebMessageAsString = webMessageAsString; + } + + public string Source { get; } + public string WebMessageAsString { get; } } public enum CoreWebView2WebResourceContextWrapper diff --git a/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs b/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs index 0617f5a9c7db..8863a00a749c 100644 --- a/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs +++ b/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; @@ -19,14 +20,16 @@ public interface IWebView2Wrapper Task> CreateEnvironmentAsync(); - ICoreWebView2Wrapper CoreWebView2 { get; } + ICoreWebView2Wrapper CoreWebView2 { get; } + + TCoreWebView2Environment Environment { get; } /// /// Gets or sets the source URI of the control. Setting the source URI causes page navigation. /// Uri Source { get; set; } - Task EnsureCoreWebView2Async(ICoreWebView2EnvironmentWrapper environment = null); + Task EnsureCoreWebView2Async(ICoreWebView2EnvironmentWrapper environment); /// /// Event that occurs when an accelerator key is pressed. @@ -44,19 +47,12 @@ public interface ICoreWebView2WebResourceRequestedEventArgsWrapper /// public ICoreWebView2WebResourceRequestWrapper Request { get; } - /// - /// Gets or sets the object. - /// - /// - /// If this object is set, the event will be completed with this Response. - /// An empty object can be created with and then modified to construct the Response. - /// - public ICoreWebView2WebResourceResponseWrapper Response { get; set; } - /// /// Gets the web resource request context. /// public CoreWebView2WebResourceContextWrapper ResourceContext { get; } + + void SetResponse(Stream content, int statusCode, string statusMessage, string headerString); } @@ -227,11 +223,11 @@ public interface ICoreWebView2HttpResponseHeadersWrapper : IEnumerableThe first header value in the collection matching the name. string GetHeader(string name); - /// - /// Gets the header values matching the name. - /// - /// The header name. - CoreWebView2HttpHeadersCollectionIterator GetHeaders(string name); + ///// + ///// Gets the header values matching the name. + ///// + ///// The header name. + //CoreWebView2HttpHeadersCollectionIterator GetHeaders(string name); } diff --git a/src/Components/WebView/Platforms/WebView2/src/Microsoft.AspNetCore.Components.WebView.WebView2.csproj b/src/Components/WebView/Platforms/WebView2/src/Microsoft.AspNetCore.Components.WebView.WebView2.csproj index 3744779f7e91..eeaa39e3eda1 100644 --- a/src/Components/WebView/Platforms/WebView2/src/Microsoft.AspNetCore.Components.WebView.WebView2.csproj +++ b/src/Components/WebView/Platforms/WebView2/src/Microsoft.AspNetCore.Components.WebView.WebView2.csproj @@ -1,4 +1,4 @@ - + - $(DefaultNetCoreTargetFramework)-windows + $(DefaultNetCoreTargetFramework)-windows WebView2 wrappers for BlazorWebView components on Windows. true disable diff --git a/src/Components/WebView/Platforms/WindowsForms/src/Microsoft.AspNetCore.Components.WebView.WindowsForms.csproj b/src/Components/WebView/Platforms/WindowsForms/src/Microsoft.AspNetCore.Components.WebView.WindowsForms.csproj index ba31e738976f..c0267e983273 100644 --- a/src/Components/WebView/Platforms/WindowsForms/src/Microsoft.AspNetCore.Components.WebView.WindowsForms.csproj +++ b/src/Components/WebView/Platforms/WindowsForms/src/Microsoft.AspNetCore.Components.WebView.WindowsForms.csproj @@ -1,7 +1,10 @@ - $(DefaultNetCoreTargetFramework)-windows + + $(DefaultNetCoreTargetFramework)-windows Build Windows Forms applications with Blazor and WebView2. true true diff --git a/src/Components/WebView/Platforms/Wpf/src/Microsoft.AspNetCore.Components.WebView.Wpf.csproj b/src/Components/WebView/Platforms/Wpf/src/Microsoft.AspNetCore.Components.WebView.Wpf.csproj index 24750b660a1c..87f347764d0e 100644 --- a/src/Components/WebView/Platforms/Wpf/src/Microsoft.AspNetCore.Components.WebView.Wpf.csproj +++ b/src/Components/WebView/Platforms/Wpf/src/Microsoft.AspNetCore.Components.WebView.Wpf.csproj @@ -1,7 +1,10 @@ - $(DefaultNetCoreTargetFramework)-windows + + $(DefaultNetCoreTargetFramework)-windows Build WPF applications with Blazor and WebView2. true true From 41e3aba49f8cfbb156f5418d948af6fe5e7d33bf Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Thu, 3 Jun 2021 15:42:53 -0700 Subject: [PATCH 17/17] Add doc comments stating not to use these types --- .../WebView2/src/CoreWebView2WebResourceContextWrapper.cs | 3 +++ .../ICoreWebView2AcceleratorKeyPressedEventArgsWrapper.cs | 3 +++ .../Platforms/WebView2/src/ICoreWebView2SettingsWrapper.cs | 5 ++++- .../WebView2/src/ICoreWebView2WebResourceRequestWrapper.cs | 5 ++++- .../src/ICoreWebView2WebResourceRequestedEventArgsWrapper.cs | 3 +++ .../WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs | 3 +++ .../WebView/Platforms/WebView2/src/IWebView2Wrapper.cs | 3 +++ .../Platforms/WebView2/src/WebMessageReceivedEventArgs.cs | 3 +++ 8 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Components/WebView/Platforms/WebView2/src/CoreWebView2WebResourceContextWrapper.cs b/src/Components/WebView/Platforms/WebView2/src/CoreWebView2WebResourceContextWrapper.cs index 7c242c41eddf..9ebde6a2a2df 100644 --- a/src/Components/WebView/Platforms/WebView2/src/CoreWebView2WebResourceContextWrapper.cs +++ b/src/Components/WebView/Platforms/WebView2/src/CoreWebView2WebResourceContextWrapper.cs @@ -4,6 +4,9 @@ namespace Microsoft.AspNetCore.Components.WebView.WebView2 { /// + /// Types in the Microsoft.AspNetCore.Components.WebView.WebView2 are not recommended for use outside + /// of the Blazor framework. These types will change in a future release. + /// /// Specifies the web resource request contexts. /// public enum CoreWebView2WebResourceContextWrapper diff --git a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2AcceleratorKeyPressedEventArgsWrapper.cs b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2AcceleratorKeyPressedEventArgsWrapper.cs index ee209c47b987..9674d539fa83 100644 --- a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2AcceleratorKeyPressedEventArgsWrapper.cs +++ b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2AcceleratorKeyPressedEventArgsWrapper.cs @@ -4,6 +4,9 @@ namespace Microsoft.AspNetCore.Components.WebView.WebView2 { /// + /// Types in the Microsoft.AspNetCore.Components.WebView.WebView2 are not recommended for use outside + /// of the Blazor framework. These types will change in a future release. + /// /// Event args for the AcceleratorKeyPressed event. /// public interface ICoreWebView2AcceleratorKeyPressedEventArgsWrapper diff --git a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2SettingsWrapper.cs b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2SettingsWrapper.cs index f878ce6b561b..2211fbd044d8 100644 --- a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2SettingsWrapper.cs +++ b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2SettingsWrapper.cs @@ -1,9 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.AspNetCore.Components.WebView.WebView2 { /// + /// Types in the Microsoft.AspNetCore.Components.WebView.WebView2 are not recommended for use outside + /// of the Blazor framework. These types will change in a future release. + /// /// Defines properties that enable, disable, or modify WebView features. /// /// diff --git a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2WebResourceRequestWrapper.cs b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2WebResourceRequestWrapper.cs index 8b23b516c77d..e8cf3e483389 100644 --- a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2WebResourceRequestWrapper.cs +++ b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2WebResourceRequestWrapper.cs @@ -1,9 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.AspNetCore.Components.WebView.WebView2 { /// + /// Types in the Microsoft.AspNetCore.Components.WebView.WebView2 are not recommended for use outside + /// of the Blazor framework. These types will change in a future release. + /// /// An HTTP request used with the event. /// public interface ICoreWebView2WebResourceRequestWrapper diff --git a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2WebResourceRequestedEventArgsWrapper.cs b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2WebResourceRequestedEventArgsWrapper.cs index 962e0dfe86f1..9260ee10475b 100644 --- a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2WebResourceRequestedEventArgsWrapper.cs +++ b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2WebResourceRequestedEventArgsWrapper.cs @@ -6,6 +6,9 @@ namespace Microsoft.AspNetCore.Components.WebView.WebView2 { /// + /// Types in the Microsoft.AspNetCore.Components.WebView.WebView2 are not recommended for use outside + /// of the Blazor framework. These types will change in a future release. + /// /// Event args for the WebResourceRequested event. /// public interface ICoreWebView2WebResourceRequestedEventArgsWrapper diff --git a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs index f3ad1b554e4f..284f160db5b3 100644 --- a/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs +++ b/src/Components/WebView/Platforms/WebView2/src/ICoreWebView2Wrapper.cs @@ -7,6 +7,9 @@ namespace Microsoft.AspNetCore.Components.WebView.WebView2 { /// + /// Types in the Microsoft.AspNetCore.Components.WebView.WebView2 are not recommended for use outside + /// of the Blazor framework. These types will change in a future release. + /// /// Defines an abstraction for different WebView2 implementations on different platforms. /// public interface ICoreWebView2Wrapper diff --git a/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs b/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs index b66e9fa56670..f5dcd61d3f70 100644 --- a/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs +++ b/src/Components/WebView/Platforms/WebView2/src/IWebView2Wrapper.cs @@ -7,6 +7,9 @@ namespace Microsoft.AspNetCore.Components.WebView.WebView2 { /// + /// Types in the Microsoft.AspNetCore.Components.WebView.WebView2 are not recommended for use outside + /// of the Blazor framework. These types will change in a future release. + /// /// Provides an abstraction for different UI frameworks to provide access to APIs from /// Microsoft.Web.WebView2.Core.CoreWebView2 and related controls. /// diff --git a/src/Components/WebView/Platforms/WebView2/src/WebMessageReceivedEventArgs.cs b/src/Components/WebView/Platforms/WebView2/src/WebMessageReceivedEventArgs.cs index e1d68f7db0cc..a5817424aab0 100644 --- a/src/Components/WebView/Platforms/WebView2/src/WebMessageReceivedEventArgs.cs +++ b/src/Components/WebView/Platforms/WebView2/src/WebMessageReceivedEventArgs.cs @@ -6,6 +6,9 @@ namespace Microsoft.AspNetCore.Components.WebView.WebView2 { /// + /// Types in the Microsoft.AspNetCore.Components.WebView.WebView2 are not recommended for use outside + /// of the Blazor framework. These types will change in a future release. + /// /// Event arguments for the WebMessageReceived event. /// public class WebMessageReceivedEventArgs : EventArgs