Example #1
0
 async void OnWebMessageReceived(WWebView sender, Web.WebView2.Core.CoreWebView2WebMessageReceivedEventArgs e)
 {
     if (Element.OnThisPlatform().IsJavaScriptAlertEnabled())
     {
         await new global::Windows.UI.Popups.MessageDialog(e.TryGetWebMessageAsString()).ShowAsync();
     }
 }
Example #2
0
        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;
                }
            }
        }
Example #3
0
        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);
            }
        }
Example #4
0
 void OnNavigationCompleted(WWebView sender, Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
 {
     if (e.IsSuccess)
     {
         NavigationSucceeded(sender, e);
     }
     else
     {
         NavigationFailed(sender, e);
     }
 }
Example #5
0
 void TearDown(WWebView webView)
 {
     if (webView == null)
     {
         return;
     }
     webView.NavigationStarting  -= OnNavigationStarted;
     webView.NavigationCompleted -= OnNavigationCompleted;
     webView.CoreProcessFailed   -= OnCoreProcessFailed;
     webView.WebMessageReceived  -= OnWebMessageReceived;
 }
Example #6
0
        void Connect(WWebView webView)
        {
            if (webView == null)
            {
                return;
            }

            webView.CoreProcessFailed   += OnCoreProcessFailed;
            webView.WebMessageReceived  += OnWebMessageReceived;
            webView.NavigationStarting  += OnNavigationStarted;
            webView.NavigationCompleted += OnNavigationCompleted;
        }
Example #7
0
        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;
        }
Example #8
0
        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;
        }
Example #9
0
        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); };");
            }
        }
Example #10
0
 void OnCoreProcessFailed(WWebView sender, Web.WebView2.Core.CoreWebView2ProcessFailedEventArgs args)
 {
     UpdateExecutionMode();
 }