From cf76a629023c99557239464a278daec280d1f448 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Thu, 18 Jul 2024 10:13:45 -0700 Subject: [PATCH] HybridWebView control for integrating JS/HTML/CSS easily into a .NET MAUI app (#22880) * Initial HybridWebView control to send messages between C# and .NET Fixes #22302 --- eng/devices/windows.cake | 2 +- .../Pages/Controls/HybridWebViewPage.xaml | 32 ++ .../Pages/Controls/HybridWebViewPage.xaml.cs | 23 + .../Raw/HybridSamplePage/docs/sample.pdf | Bin 0 -> 18144 bytes .../Resources/Raw/HybridSamplePage/index.html | 32 ++ .../HybridSamplePage/scripts/HybridWebView.js | 48 ++ .../Raw/HybridSamplePage/styles/app.css | 10 + .../ViewModels/ControlsViewModel.cs | 3 + .../src/Core/HybridWebView/HybridWebView.cs | 54 ++ ...ybridWebViewRawMessageReceivedEventArgs.cs | 14 + .../net-android/PublicAPI.Unshipped.txt | 13 + .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 13 + .../net-maccatalyst/PublicAPI.Unshipped.txt | 13 + .../net-tizen/PublicAPI.Unshipped.txt | 13 + .../net-windows/PublicAPI.Unshipped.txt | 13 + .../PublicAPI/net/PublicAPI.Unshipped.txt | 13 + .../netstandard/PublicAPI.Unshipped.txt | 13 + .../Xaml/Hosting/AppHostBuilderExtensions.cs | 1 + .../DeviceTests/Controls.DeviceTests.csproj | 4 + .../HybridWebView/HybridWebViewTests.cs | 83 ++++ .../tests/DeviceTests/Memory/MemoryTests.cs | 12 + .../Resources/Raw/HybridTestRoot/index.html | 23 + .../HybridTestRoot/scripts/HybridWebView.js | 48 ++ .../tests/DeviceTests/TestCategory.cs | 1 + src/Core/src/Core/IHybridWebView.cs | 18 + .../FileExtensionContentTypeProvider.cs | 469 ++++++++++++++++++ .../HybridWebViewHandler.Android.cs | 103 ++++ .../HybridWebViewHandler.Standard.cs | 11 + .../HybridWebViewHandler.Tizen.cs | 11 + .../HybridWebViewHandler.Windows.cs | 221 +++++++++ .../HybridWebView/HybridWebViewHandler.cs | 110 ++++ .../HybridWebView/HybridWebViewHandler.iOS.cs | 212 ++++++++ .../HybridWebViewQueryStringHelper.cs | 50 ++ .../HybridWebView/IHybridPlatformWebView.cs | 7 + .../HybridWebView/IHybridWebViewHandler.cs | 23 + .../src/Platform/Android/MauiHybridWebView.cs | 27 + .../Android/MauiHybridWebViewClient.cs | 124 +++++ .../src/Platform/Windows/MauiHybridWebView.cs | 22 + .../src/Platform/iOS/MauiHybridWebView.cs | 38 ++ .../net-android/PublicAPI.Unshipped.txt | 36 ++ .../PublicAPI/net-ios/PublicAPI.Unshipped.txt | 32 ++ .../net-maccatalyst/PublicAPI.Unshipped.txt | 33 ++ .../net-tizen/PublicAPI.Unshipped.txt | 27 + .../net-windows/PublicAPI.Unshipped.txt | 32 ++ .../src/PublicAPI/net/PublicAPI.Unshipped.txt | 27 + .../netstandard/PublicAPI.Unshipped.txt | 27 + .../netstandard2.0/PublicAPI.Unshipped.txt | 27 + 47 files changed, 2167 insertions(+), 1 deletion(-) create mode 100644 src/Controls/samples/Controls.Sample/Pages/Controls/HybridWebViewPage.xaml create mode 100644 src/Controls/samples/Controls.Sample/Pages/Controls/HybridWebViewPage.xaml.cs create mode 100644 src/Controls/samples/Controls.Sample/Resources/Raw/HybridSamplePage/docs/sample.pdf create mode 100644 src/Controls/samples/Controls.Sample/Resources/Raw/HybridSamplePage/index.html create mode 100644 src/Controls/samples/Controls.Sample/Resources/Raw/HybridSamplePage/scripts/HybridWebView.js create mode 100644 src/Controls/samples/Controls.Sample/Resources/Raw/HybridSamplePage/styles/app.css create mode 100644 src/Controls/src/Core/HybridWebView/HybridWebView.cs create mode 100644 src/Controls/src/Core/HybridWebView/HybridWebViewRawMessageReceivedEventArgs.cs create mode 100644 src/Controls/tests/DeviceTests/Elements/HybridWebView/HybridWebViewTests.cs create mode 100644 src/Controls/tests/DeviceTests/Resources/Raw/HybridTestRoot/index.html create mode 100644 src/Controls/tests/DeviceTests/Resources/Raw/HybridTestRoot/scripts/HybridWebView.js create mode 100644 src/Core/src/Core/IHybridWebView.cs create mode 100644 src/Core/src/Handlers/HybridWebView/FileExtensionContentTypeProvider.cs create mode 100644 src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.Android.cs create mode 100644 src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.Standard.cs create mode 100644 src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.Tizen.cs create mode 100644 src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.Windows.cs create mode 100644 src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.cs create mode 100644 src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.iOS.cs create mode 100644 src/Core/src/Handlers/HybridWebView/HybridWebViewQueryStringHelper.cs create mode 100644 src/Core/src/Handlers/HybridWebView/IHybridPlatformWebView.cs create mode 100644 src/Core/src/Handlers/HybridWebView/IHybridWebViewHandler.cs create mode 100644 src/Core/src/Platform/Android/MauiHybridWebView.cs create mode 100644 src/Core/src/Platform/Android/MauiHybridWebViewClient.cs create mode 100644 src/Core/src/Platform/Windows/MauiHybridWebView.cs create mode 100644 src/Core/src/Platform/iOS/MauiHybridWebView.cs diff --git a/eng/devices/windows.cake b/eng/devices/windows.cake index 76741497c1e8..a64592128e97 100644 --- a/eng/devices/windows.cake +++ b/eng/devices/windows.cake @@ -205,7 +205,7 @@ Task("Test") .IsDependentOn("SetupTestPaths") .Does(() => { - var waitForResultTimeoutInSeconds = 120; + var waitForResultTimeoutInSeconds = 240; CleanDirectories(TEST_RESULTS); diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/HybridWebViewPage.xaml b/src/Controls/samples/Controls.Sample/Pages/Controls/HybridWebViewPage.xaml new file mode 100644 index 000000000000..78779691808a --- /dev/null +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/HybridWebViewPage.xaml @@ -0,0 +1,32 @@ + + + + + +