Exemple #1
0
        public virtual void ProcessRequest(ResourceRequest request, CoreWebView2Deferral deferral, Action <ResourceResponse, CoreWebView2Deferral> callback)
        {
            Task.Run(async() =>
            {
                try
                {
                    ResourceResponse response = null;
                    response = await RequestInterceptor.ProcessRequest(_appFunc, request);

                    if (IsBadRequest((HttpStatusCode)response.StatusCode) || IsRouteNotFound((HttpStatusCode)response.StatusCode))
                    {
                        string redirectUrl = GetHomeUrl(request.Url);
                        var newRequest     = new Chromium.AspNetCore.Bridge.ResourceRequest(redirectUrl, "GET", request.Headers, null);
                        response           = await RequestInterceptor.ProcessRequest(_appFunc, newRequest);
                    }

                    ((App)Application.Current).Dispatcher.Invoke(
                        DispatcherPriority.Background,
                        new Action(() =>
                    {
                        // Callback
                        callback.Invoke(response, deferral);
                    }));
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    Console.WriteLine(exception.StackTrace);

                    deferral?.Complete();
                    deferral = null;
                }
            });
        }
 public void CompleteNewTabInitialize(CoreWebView2 coreWebView)
 {   //When changing WPF Tab Items everything initializes again.
     if (Def != null)
     {
         Args.NewWindow = coreWebView;
         Args.Handled   = true;
         Def.Complete();
         Def = null;
     }
 }
 public void CompleteNewTabInitialize(CoreWebView2 coreWebView)
 {
     if (Def != null)
     {
         Args.NewWindow = coreWebView;
         Args.Handled   = true;
         Def.Complete();
         Def = null;
     }
 }
Exemple #4
0
        private async void CoreWebView2_NewWindowRequestedAsync(object sender, CoreWebView2NewWindowRequestedEventArgs e)
        {
            CoreWebView2Deferral def = e.GetDeferral();
            Tab nTab = new();

            MainBrowser.HandleNewTabRequestAsync(nTab);
            await nTab.CreateTabFromNewWindowRequested(CoreWebView2.Environment, true, MainBrowser);

            e.NewWindow = nTab.CoreWebView2;
            e.Handled   = true;
            def.Complete();
        }
Exemple #5
0
        private async void WebView2_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
        {
            if (Deferral != null)
            {
                Deferral.Complete();
            }
            else
            {
                Console.WriteLine("Deferral Is NULL...");
            }

            //
            string script_id = await WebView2.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync(Properties.Resources.systemjs);

            WebView2.CoreWebView2.NavigationCompleted += CoreWebView2_NavigationCompleted;

            //
            Console.WriteLine("WebView2Manager-WebView2_CoreWebView2InitializationCompleted");
        }
Exemple #6
0
        private async void WebView21_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
        {
            //
            if (Deferral != null)
            {
                Deferral.Complete();
            }

            //
            Console.WriteLine("NewWindow:CoreWebView2InitializationCompleted");

            webView21.CoreWebView2.NavigationCompleted      += CoreWebView2_NavigationCompleted;
            webView21.CoreWebView2.FrameNavigationCompleted += CoreWebView2_FrameNavigationCompleted;
            webView21.CoreWebView2.NewWindowRequested       += CoreWebView2_NewWindowRequested;

            //
            string script_id = await webView21.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync(Resources.systemjs);

            Console.WriteLine($"NewWindow:AddScriptToExecuteOnDocumentCreatedAsync Completed, ScriptID: {script_id}");
        }
        private void WebView2Control_CoreWebView2Ready(object sender, EventArgs e)
        {
            HandleResize();

            _webView2Control.Source = new Uri("https://www.bing.com/");

            _webView2Control.CoreWebView2.SourceChanged        += CoreWebView2_SourceChanged;
            _webView2Control.CoreWebView2.HistoryChanged       += CoreWebView2_HistoryChanged;
            _webView2Control.CoreWebView2.DocumentTitleChanged += CoreWebView2_DocumentTitleChanged;
            _webView2Control.CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.Image);
            _webView2Control.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
            UpdateTitleWithEvent("CoreWebView2Ready");

            if (_newWindowRequestedEventArgs != null)
            {
                _newWindowRequestedEventArgs.NewWindow = _webView2Control.CoreWebView2;
                _newWindowRequestedEventArgs.Handled   = true;
                _newWindowDeferral.Complete();
                _newWindowRequestedEventArgs = null;
                _newWindowDeferral           = null;
            }
        }