async void OnWebMessageReceived(WWebView sender, Web.WebView2.Core.CoreWebView2WebMessageReceivedEventArgs e) { if (Element.OnThisPlatform().IsJavaScriptAlertEnabled()) { await new global::Windows.UI.Popups.MessageDialog(e.TryGetWebMessageAsString()).ShowAsync(); } }
void OnNavigationStarted(WWebView sender, Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e) { // TODO WINUI3 //Uri uri = e.Uri; //if (uri != null) //{ Uri uri; if (Uri.TryCreate(e.Uri, UriKind.Absolute, out uri) && uri != null) { var args = new WebNavigatingEventArgs(_eventState, new UrlWebViewSource { Url = uri.AbsoluteUri }, uri.AbsoluteUri); WebViewController.SendNavigating(args); e.Cancel = args.Cancel; // reset in this case because this is the last event we will get if (args.Cancel) { _eventState = WebNavigationEvent.NewPage; } } }
void NavigationFailed(WWebView sender, Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) { Uri uri = sender.Source; if (uri != null) { SendNavigated(new UrlWebViewSource { Url = uri.AbsoluteUri }, _eventState, WebNavigationResult.Failure); } }
void OnNavigationCompleted(WWebView sender, Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) { if (e.IsSuccess) { NavigationSucceeded(sender, e); } else { NavigationFailed(sender, e); } }
void TearDown(WWebView webView) { if (webView == null) { return; } webView.NavigationStarting -= OnNavigationStarted; webView.NavigationCompleted -= OnNavigationCompleted; webView.CoreProcessFailed -= OnCoreProcessFailed; webView.WebMessageReceived -= OnWebMessageReceived; }
void Connect(WWebView webView) { if (webView == null) { return; } webView.CoreProcessFailed += OnCoreProcessFailed; webView.WebMessageReceived += OnWebMessageReceived; webView.NavigationStarting += OnNavigationStarted; webView.NavigationCompleted += OnNavigationCompleted; }
void Connect(WWebView webView) { if (webView == null) { return; } // TODO WINUI3 //webView.SeparateProcessLost += OnSeparateProcessLost; //webView.NavigationFailed += OnNavigationFailed; //webView.ScriptNotify += OnScriptNotify; webView.NavigationStarting += OnNavigationStarted; webView.NavigationCompleted += OnNavigationCompleted; }
void TearDown(WWebView webView) { if (webView == null) { return; } webView.NavigationStarting -= OnNavigationStarted; webView.NavigationCompleted -= OnNavigationCompleted; // TODO WINUI3 // webView.SeparateProcessLost -= OnSeparateProcessLost; //webView.NavigationFailed -= OnNavigationFailed; //webView.ScriptNotify -= OnScriptNotify; }
async void NavigationSucceeded(WWebView sender, Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) { // TODO WINUI3 //if (e.Uri != null) // SendNavigated(new UrlWebViewSource { Url = e.Uri.AbsoluteUri }, _eventState, WebNavigationResult.Success); Uri uri = sender.Source; if (uri != null) { SendNavigated(new UrlWebViewSource { Url = uri.AbsoluteUri }, _eventState, WebNavigationResult.Success); } UpdateCanGoBackForward(); if (Element.OnThisPlatform().IsJavaScriptAlertEnabled()) { await Control.ExecuteScriptAsync("window.alert = function(message){ window.external.notify(message); };"); } }
void OnCoreProcessFailed(WWebView sender, Web.WebView2.Core.CoreWebView2ProcessFailedEventArgs args) { UpdateExecutionMode(); }