Example #1
0
        private void HandleDecisionHandlerDelegateResponse(Android.Webkit.WebView view, string url, Abstractions.Delegates.DecisionHandlerDelegate response)
        {
            if (!response.Cancel && !response.OffloadOntoDevice)
            {
                return;
            }

            var finishedManualResetEvent = new ManualResetEvent(false);

            void CancelOrOffloadOntoDevice()
            {
                if (response.OffloadOntoDevice && !AttemptToHandleCustomUrlScheme(view, url))
                {
                    Device.OpenUri(new Uri(url));
                }

                view.StopLoading();

                finishedManualResetEvent.Set();
            }

            if (Device.IsInvokeRequired)
            {
                Device.BeginInvokeOnMainThread(CancelOrOffloadOntoDevice);
            }
            else
            {
                CancelOrOffloadOntoDevice();
            }

            finishedManualResetEvent.WaitOne();
        }
Example #2
0
        void CheckResponseValidity(Android.Webkit.WebView view, string url)
        {
            if (Reference == null || !Reference.TryGetTarget(out FormsWebViewRenderer renderer))
            {
                return;
            }
            if (renderer.Element == null)
            {
                return;
            }

            var response = renderer.Element.HandleNavigationStartRequest(url);

            if (response.Cancel || response.OffloadOntoDevice)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    if (response.OffloadOntoDevice)
                    {
                        AttemptToHandleCustomUrlScheme(view, url);
                    }

                    view.StopLoading();
                });
            }
        }
Example #3
0
        public override WebResourceResponse ShouldInterceptRequest(Android.Webkit.WebView view, string url)
        {
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                goto EndShouldInterceptRequest;
            }

            if (Reference == null || !Reference.TryGetTarget(out FormsWebViewRenderer renderer))
            {
                goto EndShouldInterceptRequest;
            }
            if (renderer.Element == null)
            {
                goto EndShouldInterceptRequest;
            }

            var response = renderer.Element.HandleNavigationStartRequest(url);

            if (response.Cancel || response.OffloadOntoDevice)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    if (response.OffloadOntoDevice)
                    {
                        AttemptToHandleCustomUrlScheme(view, url);
                    }

                    view.StopLoading();
                });
            }

EndShouldInterceptRequest:
            return(base.ShouldInterceptRequest(view, url));
        }
        public override void OnPageStarted(AWebView view, string url, Bitmap favicon)
        {
            if (view is null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            if (_renderer?.Element == null || _webView == null || string.IsNullOrWhiteSpace(url) || url == WebViewRenderer.AssetBaseUrl)
            {
                return;
            }

            _renderer.SyncNativeCookiesToElement(url);
            var cancel = false;

            if (!url.Equals(_renderer.UrlCanceled, StringComparison.OrdinalIgnoreCase))
            {
                cancel = SendNavigatingCanceled(url);
            }

            _renderer.UrlCanceled = null;

            if (cancel)
            {
                _navigationResult = WebNavigationResult.Cancel;
                view.StopLoading();
            }
            else
            {
                _navigationResult = WebNavigationResult.Success;
                base.OnPageStarted(view, url, favicon);
                _webView.HandleNavigationStarting(new Uri(url));
            }
        }
Example #5
0
        public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
        {
            if (Reference == null || !Reference.TryGetTarget(out FormsWebViewRenderer renderer))
            {
                goto EndShouldInterceptRequest;
            }
            if (renderer.Element == null)
            {
                goto EndShouldInterceptRequest;
            }

            string url      = request.Url.ToString();
            var    response = renderer.Element.HandleNavigationStartRequest(url);

            if (response.Cancel || response.OffloadOntoDevice)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    if (response.OffloadOntoDevice)
                    {
                        AttemptToHandleCustomUrlScheme(view, url);
                    }

                    view.StopLoading();
                });
                return(true);
            }

EndShouldInterceptRequest:
            return(base.ShouldOverrideUrlLoading(view, request));
        }
        public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, string url)
        {
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.N)
            {
                return(base.ShouldOverrideUrlLoading(view, url));
            }

            if (Reference == null || !Reference.TryGetTarget(out FormsWebViewRenderer renderer))
            {
                return(base.ShouldOverrideUrlLoading(view, url));
            }
            if (renderer.Element == null)
            {
                return(base.ShouldOverrideUrlLoading(view, url));
            }

            var response = renderer.Element.HandleNavigationStartRequest(url);

            if (response.Cancel || response.OffloadOntoDevice)
            {
                if (response.OffloadOntoDevice)
                {
                    AttemptToHandleCustomUrlScheme(view, url);
                }
                view.StopLoading();
                return(true);
            }

            return(base.ShouldOverrideUrlLoading(view, url));
        }
        public override void OnPageStarted(WView view, string url, Bitmap favicon)
        {
            if (_renderer == null || string.IsNullOrWhiteSpace(url) || url == WebViewRenderer.AssetBaseUrl)
            {
                return;
            }

            var cancel = false;

            if (!url.Equals(_renderer.UrlCanceled, StringComparison.OrdinalIgnoreCase))
            {
                cancel = SendNavigatingCanceled(url);
            }
            _renderer.UrlCanceled = null;

            if (cancel)
            {
                _navigationResult = WebNavigationResult.Cancel;
                view.StopLoading();
            }
            else
            {
                _navigationResult = WebNavigationResult.Success;
                base.OnPageStarted(view, url, favicon);
            }
        }
Example #8
0
        public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
        {
            if (Reference == null || !Reference.TryGetTarget(out FormsWebViewRenderer renderer))
            {
                return(true);
            }
            if (renderer.Element == null)
            {
                return(true);
            }

            string url      = request.Url.ToString();
            var    response = renderer.Element.HandleNavigationStartRequest(url);

            if (response.Cancel || response.OffloadOntoDevice)
            {
                if (response.OffloadOntoDevice)
                {
                    AttemptToHandleCustomUrlScheme(view, url);
                }

                view.StopLoading();
                return(true);
            }

            return(false);
        }
Example #9
0
 public override void OnPageStarted(Android.Webkit.WebView view, string url, Bitmap favicon)
 {
     if (((NavigationRequestedDelegate)Element.InvokeEvent(WebViewEventType.NavigationRequested, new NavigationRequestedDelegate(Element, url))).Cancel)
     {
         view.StopLoading();
     }
     else
     {
         Element.SetValue(FormsWebView.SourceProperty, url);
     }
 }
        public override void OnPageStarted(WView view, string url, Bitmap favicon)
        {
            if (_renderer == null || string.IsNullOrWhiteSpace(url) || url == WebViewRenderer.AssetBaseUrl)
            {
                return;
            }

            if (_renderer?.Element?.ShouldManageCookies == true)
            {
                var cookieManager = CookieManager.Instance;
                cookieManager.SetAcceptCookie(true);
                cookieManager.RemoveAllCookie();
                var cookies = _renderer.Element.Cookies?.GetCookies(new System.Uri(url));
                for (var i = 0; i < (cookies?.Count ?? -1); i++)
                {
                    string cookieValue  = cookies[i].Value;
                    string cookieDomain = cookies[i].Domain;
                    string cookieName   = cookies[i].Name;
                    cookieManager.SetCookie(cookieDomain, cookieName + "=" + cookieValue);
                }
            }

            var cancel = false;

            if (!url.Equals(_renderer.UrlCanceled, StringComparison.OrdinalIgnoreCase))
            {
                cancel = SendNavigatingCanceled(url);
            }
            _renderer.UrlCanceled = null;

            if (cancel)
            {
                _navigationResult = WebNavigationResult.Cancel;
                view.StopLoading();
            }
            else
            {
                _navigationResult = WebNavigationResult.Success;
                base.OnPageStarted(view, url, favicon);
            }
        }
Example #11
0
        private bool DoesComponentWantToOverrideUrlLoading(Android.Webkit.WebView view, string url)
        {
            if (_reference != null && _reference.TryGetTarget(out var renderer) && renderer.Element != null)
            {
                var response = renderer.Element.HandleNavigationStartRequest(url);

                if (response.Cancel || response.OffloadOntoDevice)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (response.OffloadOntoDevice)
                        {
                            AttemptToHandleCustomUrlScheme(view, url);
                        }

                        view.StopLoading();
                    });
                    return(true);
                }
            }
            return(false);
        }
Example #12
0
 partial void StopPartial()
 {
     _webView.StopLoading();
 }