提交 65a7cf3c 编写于 作者: M Martin Zikmund

chore: Adjusting iOS/macOS buildability

上级 27973ca4
......@@ -25,7 +25,7 @@ namespace SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests
var uriString = e.NewValue?.ToString();
if (!string.IsNullOrEmpty(uriString))
{
(d as WebView2Uno).Navigate(new Uri(uriString, UriKind.Absolute));
((WebView2Uno)d).Source = new Uri(uriString, UriKind.Absolute);
}
}
}
......
......@@ -12,9 +12,10 @@ namespace SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests
InitializeComponent();
#if HAS_UNO
webView.Navigate(new Uri("https://nv-assets.azurewebsites.net/tests/docs/WebView2_NavigateToAnchor.html"));
webView.NavigationStarting += WebView2_NavigationStarting;
webView.NavigationCompleted += WebView2_NavigationCompleted;
//TODO:MZ:
//webView.Navigate(new Uri("https://nv-assets.azurewebsites.net/tests/docs/WebView2_NavigateToAnchor.html"));
//webView.NavigationStarting += WebView2_NavigationStarting;
//webView.NavigationCompleted += WebView2_NavigationCompleted;
#endif
}
......
using Uno.UI.Samples.Controls;
using System;
using Windows.UI.Xaml;
using Windows.UI.Core;
using System;
using System.Threading;
using Windows.UI.Xaml.Controls;
using System.Threading.Tasks;
using SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests;
using Uno.UI.Samples.Controls;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests
{
......@@ -16,28 +16,30 @@ namespace SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests
public WebView2_JavascriptInvoke()
{
this.InitializeComponent();
MyButton.Click += MyButton_OnClick;
}
//TODO:MZ:
// MyButton.Click += MyButton_OnClick;
//}
private void MyButton_OnClick(object sender, RoutedEventArgs e)
{
var t = Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
async () => await InvokeScriptAsync(MyWebView2, CancellationToken.None, GetReloadJavascript(), new string[] { "" })
);
}
public static async Task<string> InvokeScriptAsync(Microsoft.UI.Xaml.Controls.WebView2 webView, CancellationToken ct, string script, string[] arguments)
{
return await webView.InvokeScriptAsync(script, arguments).AsTask(ct);
//private void MyButton_OnClick(object sender, RoutedEventArgs e)
//{
// var t = Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
// async () => await InvokeScriptAsync(MyWebView2, CancellationToken.None, GetReloadJavascript(), new string[] { "" })
// );
//}
//public static async Task<string> InvokeScriptAsync(Microsoft.UI.Xaml.Controls.WebView2 webView, CancellationToken ct, string script, string[] arguments)
//{
//
// //return await webView.CoreWebView2.ExecuteScriptAsync(script, arguments).AsTask(ct);
}
private static string GetReloadJavascript()
{
#if XAMARIN_IOS
return "location.reload(true);";
#else
return "window.location.reload()";
#endif
}
// private static string GetReloadJavascript()
// {
//#if XAMARIN_IOS
// return "location.reload(true);";
//#else
// return "window.location.reload()";
//#endif
// }
#endif
}
}
......@@ -28,7 +28,7 @@ namespace SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests
};
request.Headers.Add("HELLO", "TESTTEST, TEST2");
request.Headers.Add("HELLO2", "TEST111");
MyWebView2.NavigateWithHttpRequestMessage(request);
MyWebView2.CoreWebView2.NavigateWithHttpRequestMessage(request);
}
#endif
}
......
//#if __WASM__ || __MACOS__
//#pragma warning disable CS0067, CS0414
//#endif
//#if XAMARIN || __WASM__ || __SKIA__
//using Windows.Foundation;
//using Windows.UI.Xaml.Controls;
//using System;
//using System.Collections.Generic;
//using System.Diagnostics.CodeAnalysis;
//using System.Linq;
//using System.Net.Http;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using Uno.Extensions;
//using Uno;
//namespace Windows.UI.Xaml.Controls
//{
//#if __WASM__ || __SKIA__
// [NotImplemented]
//#endif
// internal partial class WebView : Control
// {
// private object _internalSource;
// private string _invokeScriptResponse = string.Empty;
// internal void Navigate(Uri uri)
// {
// _owner.SetInternalSource(uri ?? BlankUri);
// }
// //
// // Summary:
// // Loads the specified HTML content as a new document.
// //
// // Parameters:
// // text:
// // The HTML content to display in t he WebView control.
// internal void NavigateToString(string text)
// {
// _owner.SetInternalSource(text ?? "");
// }
// private void SetInternalSource(object source)
// {
// _internalSource = source;
// _owner.UpdateFromInternalSource();
// }
// internal void OnUnsupportedUriSchemeIdentified(WebViewUnsupportedUriSchemeIdentifiedEventArgs args)
// {
// UnsupportedUriSchemeIdentified?.Invoke(_owner, args);
// }
// }
//}
//#endif
......@@ -3,7 +3,7 @@ using System.Net.Http;
namespace Uno.UI.Xaml.Controls;
internal interface INativeWebView
internal partial interface INativeWebView
{
void GoBack();
void GoForward();
......
......@@ -5,7 +5,6 @@ using WebKit;
using System.Threading;
using System.Threading.Tasks;
using Uno.Extensions;
using Uno.UI.Extensions;
using Uno.Foundation.Logging;
using Windows.Web;
using System.IO;
......@@ -84,7 +83,7 @@ public partial class UnoWKWebView : WKWebView, INativeWebView
public void ProcessNavigation(string html) => throw new NotImplementedException();
public void ProcessNavigation(HttpRequestMessage httpRequestMessage) => throw new NotImplementedException();
public void RegisterNavigationEvents(CoreWebView2 coreWebView)
void INativeWebView.SetOwner(CoreWebView2 coreWebView)
{
_coreWebView = coreWebView;
......@@ -174,7 +173,9 @@ public partial class UnoWKWebView : WKWebView, INativeWebView
if (UIKit.UIApplication.SharedApplication.CanOpenUrl(target))
{
UIKit.UIApplication.SharedApplication.OpenUrl(target);
_coreWebView.OnComplete(target, isSuccessful: true, status: WebErrorStatus.Unknown);
// TODO:MZ:
_coreWebView.RaiseNavigationCompleted();
//_coreWebView.OnComplete(target, isSuccessful: true, status: WebErrorStatus.Unknown);
}
#else
if (target != null && NSWorkspace.SharedWorkspace.UrlForApplication(new NSUrl(target.AbsoluteUri)) != null)
......@@ -185,11 +186,13 @@ public partial class UnoWKWebView : WKWebView, INativeWebView
#endif
else
{
_coreWebView.OnNavigationFailed(new WebViewNavigationFailedEventArgs()
{
Uri = target,
WebErrorStatus = WebErrorStatus.Unknown
});
// TODO:MZ:
_coreWebView.RaiseNavigationCompleted();
//_coreWebView.OnNavigationFailed(new WebViewNavigationFailedEventArgs()
//{
// Uri = target,
// WebErrorStatus = WebErrorStatus.Unknown
//});
}
}
}
......@@ -373,16 +376,18 @@ public partial class UnoWKWebView : WKWebView, INativeWebView
}
else
{
uri = webView.Url?.ToUri() ?? _coreWebView.Source;
uri = webView.Url?.ToUri() ?? new Uri(_coreWebView.Source); // TODO:MZ: What if Source is invalid URI?
}
_coreWebView.OnNavigationFailed(new WebViewNavigationFailedEventArgs()
{
Uri = uri,
WebErrorStatus = status
});
//TODO:MZ:
_coreWebView.RaiseNavigationCompleted();
//_coreWebView.OnNavigationFailed(new WebViewNavigationFailedEventArgs()
//{
// Uri = uri,
// WebErrorStatus = status
//});
_coreWebView.OnComplete(uri, false, status);
//_coreWebView.OnComplete(uri, false, status);
}
_isCancelling = false;
......@@ -472,11 +477,13 @@ public partial class UnoWKWebView : WKWebView, INativeWebView
this.Log().Error($"The uri [{uri}] is invalid.");
}
_coreWebView.RaiseNavigationFailed(new WebViewNavigationFailedEventArgs()
{
Uri = uri,
WebErrorStatus = WebErrorStatus.UnexpectedClientError
});
// TODO:MZ:
_coreWebView.RaiseNavigationCompleted();
//_coreWebView.RaiseNavigationFailed(new WebViewNavigationFailedEventArgs()
//{
// Uri = uri,
// WebErrorStatus = WebErrorStatus.UnexpectedClientError
//});
}
}
......
using System;
using System.Collections.Generic;
using CoreGraphics;
using Foundation;
using System;
using WebKit;
using System.Threading;
using System.Threading.Tasks;
using Uno.Extensions;
using Uno.Foundation.Logging;
using Windows.Web;
using System.IO;
using System.Linq;
using Windows.ApplicationModel.Resources;
using Uno.UI.Xaml.Controls;
using System.Net.Http;
using Microsoft.Web.WebView2.Core;
using Uno.UI.Extensions;
#if __IOS__
using UIKit;
#else
using AppKit;
#endif
namespace Windows.UI.Xaml.Controls;
......@@ -299,20 +317,21 @@ internal class WebViewNavigationDelegate : WKNavigationDelegate
#endif
}
internal void OnComplete(Uri uri, bool isSuccessful, WebErrorStatus status)
{
var args = new WebViewNavigationCompletedEventArgs()
{
IsSuccess = isSuccessful,
Uri = uri ?? Source,
WebErrorStatus = status
};
CanGoBack = _nativeWebView.CanGoBack;
CanGoForward = _nativeWebView.CanGoForward;
NavigationCompleted?.Invoke(_owner, args);
}
//internal void OnComplete(Uri uri, bool isSuccessful, WebErrorStatus status)
//{
// // TODO:MZ:
// //var args = new WebViewNavigationCompletedEventArgs()
// //{
// // IsSuccess = isSuccessful,
// // Uri = uri ?? Source,
// // WebErrorStatus = status
// //};
// //CanGoBack = _nativeWebView.CanGoBack;
// //CanGoForward = _nativeWebView.CanGoForward;
// //NavigationCompleted?.Invoke(_owner, args);
//}
internal void OnNavigationStarting(WebViewNavigationStartingEventArgs args)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册