Esempio n. 1
0
        private async Task <bool> ValidateRequestElectronWASM()
        {
            string uri      = this.Request.QueryString.Get("uri");
            string referrer = this.Request.QueryString.Get("referrer");

            IWebResponse response = new EmbedIOWebResponse(this.Request, this.Response);

            response.SetEncoding("UTF-8");
            response.AddResponseHeader("Cache-Control", "no-cache");
            response.SetReasonPhrase("OK");
            response.SetMimeType("text/plain");

            if (!string.IsNullOrEmpty(uri) && !string.IsNullOrEmpty(referrer))
            {
                var args = new WebNavigatingEventArgs(
                    WebNavigationEvent.NewPage,
                    new UrlWebViewSource()
                {
                    Url = referrer
                },
                    uri);

                //This is not entirely true as we would only compare the current BlazorWebview
                //but it must be only one executed btw
                foreach (var webIdentity in WebViewHelper.GetAllWebViewIdentities())
                {
                    var webview = webIdentity as IBlazorWebView;
                    webview.SendNavigating(args);

                    if (args.Cancel)
                    {
                        break;
                    }
                }

                if (args.Cancel)
                {
                    response.SetStatutCode(401);
                }
                else
                {
                    response.SetStatutCode(200);
                }
            }
            else
            {
                response.SetStatutCode(200);
            }

            await response.SetDataAsync(new MemoryStream(Encoding.UTF8.GetBytes("OK")));

            return(true);
        }
Esempio n. 2
0
        private async Task <bool> ValidateRequestAndroid(string webextensionId)
        {
            string cancel = "false";

            if (int.TryParse(webextensionId, out int runtimeId))
            {
                var webview = WebViewHelper.GetWebViewByRuntimeIdentity(runtimeId);
                if (webview != null)
                {
                    string uri      = this.Request.QueryString.Get("uri");
                    string referrer = this.Request.QueryString.Get("referrer");

                    if (ShouldExcludeFromNavigatingEvent(uri, out bool shouldCancel))
                    {
                        if (shouldCancel)
                        {
                            cancel = "true";
                        }
                    }
                    else
                    {
                        var args = new WebNavigatingEventArgs(
                            WebNavigationEvent.NewPage,
                            new UrlWebViewSource()
                        {
                            Url = referrer
                        },
                            uri);

                        webview.SendNavigating(args);

                        if (args.Cancel)
                        {
                            cancel = "true";
                        }
                    }
                }
            }

            IWebResponse response = new EmbedIOWebResponse(this.Request, this.Response);

            response.SetEncoding("UTF-8");
            response.AddResponseHeader("Cache-Control", "no-cache");
            response.SetStatutCode(200);
            response.SetReasonPhrase("OK");
            response.SetMimeType("text/plain");
            await response.SetDataAsync(new MemoryStream(Encoding.UTF8.GetBytes(cancel)));

            return(true);
        }