コード例 #1
0
            protected override CefResourceHandler GetResourceHandler(CefBrowser browser, CefFrame frame, CefRequest request)
            {
                if (request.Url == OwnerWebView.DefaultLocalUrl)
                {
                    return(AsyncResourceHandler.FromText(OwnerWebView.htmlToLoad ?? ""));
                }

                if (UrlHelper.IsChromeInternalUrl(request.Url))
                {
                    return(null);
                }

                var resourceHandler = new ResourceHandler(request, OwnerWebView.GetRequestUrl(request.Url, (ResourceType)request.ResourceType));

                void TriggerBeforeResourceLoadEvent()
                {
                    var beforeResourceLoad = OwnerWebView.BeforeResourceLoad;

                    if (beforeResourceLoad != null)
                    {
                        OwnerWebView.ExecuteWithAsyncErrorHandling(() => beforeResourceLoad(resourceHandler));
                    }
                }

                if (Uri.TryCreate(resourceHandler.Url, UriKind.Absolute, out var url) && url.Scheme == ResourceUrl.EmbeddedScheme)
                {
                    resourceHandler.BeginAsyncResponse(() => {
                        var urlWithoutQuery = new UriBuilder(url);
                        if (!string.IsNullOrEmpty(url.Query))
                        {
                            urlWithoutQuery.Query = string.Empty;
                        }

                        OwnerWebView.ExecuteWithAsyncErrorHandling(() => ResourcesProvider.LoadEmbeddedResource(resourceHandler, urlWithoutQuery.Uri));

                        TriggerBeforeResourceLoadEvent();

                        if (resourceHandler.Handled || OwnerWebView.IgnoreMissingResources)
                        {
                            return;
                        }

                        var resourceLoadFailed = OwnerWebView.ResourceLoadFailed;
                        if (resourceLoadFailed != null)
                        {
                            resourceLoadFailed(url.ToString());
                        }
                        else
                        {
                            OwnerWebView.ForwardUnhandledAsyncException(new InvalidOperationException("Resource not found: " + url));
                        }
                    });
                }
                else
                {
                    TriggerBeforeResourceLoadEvent();
                }

                return(resourceHandler.Handler);
            }
コード例 #2
0
            private void FlushScripts()
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine($"{nameof(FlushScripts)} running ('{Id}')");
#endif
                OwnerWebView.ExecuteWithAsyncErrorHandling(InnerFlushScripts);
            }
コード例 #3
0
 private void FlushScripts() {
     OwnerWebView.ExecuteWithAsyncErrorHandling(() => {
         try {
             isFlushRunning = true;
             while (!FlushTaskCancelationToken.IsCancellationRequested) {
                 InnerFlushScripts();
             }
         } catch (OperationCanceledException) {
             // stop
         } finally {
             isFlushRunning = false;
             StoppedFlushHandle.Set();
         }
     });
 }
コード例 #4
0
            protected override bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
            {
                if (OwnerWebView.FilterUrl(request.Url))
                {
                    return(false);
                }

                if (OwnerWebView.IsHistoryDisabled && (request.TransitionType & TransitionType.ForwardBack) == TransitionType.ForwardBack)
                {
                    return(true);
                }

                bool cancel = false;

                if (OwnerWebView.BeforeNavigate != null)
                {
                    var wrappedRequest = new Request(request, OwnerWebView.GetRequestUrl(request.Url, (ResourceType)request.ResourceType));
                    OwnerWebView.ExecuteWithAsyncErrorHandling(() => OwnerWebView.BeforeNavigate(wrappedRequest));
                    cancel = wrappedRequest.Canceled;
                }

                return(cancel);
            }
コード例 #5
0
            protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool userGesture, bool isRedirect)
            {
                if (UrlHelper.IsInternalUrl(request.Url))
                {
                    return(false);
                }

                if (OwnerWebView.IsHistoryDisabled && request.TransitionType.HasFlag(CefTransitionType.ForwardBackFlag))
                {
                    return(true);
                }

                var cancel         = false;
                var beforeNavigate = OwnerWebView.BeforeNavigate;

                if (beforeNavigate != null)
                {
                    var wrappedRequest = new Request(request, OwnerWebView.GetRequestUrl(request.Url, (ResourceType)request.ResourceType));
                    OwnerWebView.ExecuteWithAsyncErrorHandling(() => beforeNavigate(wrappedRequest));
                    cancel = wrappedRequest.Canceled;
                }

                return(cancel);
            }