public void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { if (navigationResponse.Response != null && (navigationResponse.Response as Foundation.NSHttpUrlResponse) != null) { var httpResponse = navigationResponse.Response as Foundation.NSHttpUrlResponse; if (httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300) { decisionHandler(WKNavigationResponsePolicy.Allow); } else { decisionHandler(WKNavigationResponsePolicy.Cancel); Fail(() => { var error = new NSError(Enums.ErrorCode.HttpFailure, (int)httpResponse.StatusCode); _delegate?.RequestDidFail(this, error); }); } } else { decisionHandler(WKNavigationResponsePolicy.Cancel); Fail(() => { var error = new NSError(Enums.ErrorCode.NetworkFailure, "An unknown error ocurred"); _delegate?.RequestDidFail(this, error); }); } }
public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { if (_reference == null || !_reference.TryGetTarget(out var renderer)) { return; } if (renderer.Element == null) { return; } if (navigationResponse.Response is NSHttpUrlResponse) { var code = ((NSHttpUrlResponse)navigationResponse.Response).StatusCode; if (code >= 400) { renderer.Element.Navigating = false; renderer.Element.HandleNavigationError((int)code); decisionHandler(WKNavigationResponsePolicy.Cancel); return; } } decisionHandler(WKNavigationResponsePolicy.Allow); }
public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { this.Log().Debug($"WKNavigationDelegate.DecidePolicy {navigationResponse.Response?.Url?.ToUri()}"); } decisionHandler(WKNavigationResponsePolicy.Allow); }
public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { if (navigationResponse.Response is NSHttpUrlResponse) { var sta = ((NSHttpUrlResponse)navigationResponse.Response).StatusCode; if (sta >= 400) { Element.InvokeEvent(WebViewEventType.NavigationError, new NavigationErrorDelegate(Element, (int)sta)); } } }
public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { NSHttpUrlResponse response = navigationResponse.Response as NSHttpUrlResponse; NSHttpCookie[] cookies = NSHttpCookie.CookiesWithResponseHeaderFields(response.AllHeaderFields, response.Url); foreach (NSHttpCookie cookie in cookies) { NSHttpCookieStorage.SharedStorage.SetCookie(cookie); } decisionHandler(WKNavigationResponsePolicy.Allow); }
public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { var urlToCheck = $"{navigationResponse.Response.Url.Scheme}:{navigationResponse.Response.Url.AbsoluteString}"; if (!_urls.Contains(urlToCheck)) { decisionHandler(WKNavigationResponsePolicy.Allow); return; //base.ShouldInterceptRequest(view, request); } decisionHandler(WKNavigationResponsePolicy.Cancel); // TODO: how to handle response? }
public virtual void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { //NSHttpUrlResponse response; //NSHttpCookie[] cookies_holder; //response = (NSHttpUrlResponse)navigationResponse.Response; //cookies_holder = NSHttpCookie.CookiesWithResponseHeaderFields(response.AllHeaderFields, response.Url); //foreach (var cookie in cookies_holder) //{ // NSHttpCookieStorage.SharedStorage.SetCookie(cookie); //} decisionHandler(WKNavigationResponsePolicy.Allow); }
public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { if (navigationResponse.Response is NSHttpUrlResponse rsp) { var cookie = NSHttpCookie.CookiesWithResponseHeaderFields(rsp.AllHeaderFields, rsp.Url); foreach (var c in cookie) { webView.Configuration.WebsiteDataStore.HttpCookieStore.SetCookieAsync(c); } var target = owner.eventsHandler.CurrentAction; if (target?.Type == WebViewActionType.Download) { bool startDownload = false; if (!string.IsNullOrEmpty(target.MimeType)) { startDownload = rsp.AllHeaderFields.TryGetValue(new NSString("Content-Type"), out var contentType) && (NSString)contentType == target.MimeType; } else if (rsp.AllHeaderFields.TryGetValue(new NSString("X-Download-Options"), out var downloadOptions) && (NSString)downloadOptions == "noopen") { startDownload = true; } else if (rsp.AllHeaderFields.TryGetValue(new NSString("Content-Disposition"), out var contentDisposition) && contentDisposition.ToString().StartsWith("attachment;", StringComparison.Ordinal)) { startDownload = true; } else if ((Uri)rsp.Url == target.Uri) { startDownload = true; } if (startDownload) { decisionHandler(WKNavigationResponsePolicy.Cancel); StartDownload(rsp.Url, target); return; } } } decisionHandler(WKNavigationResponsePolicy.Allow); }
public void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { var response = navigationResponse.Response as NSHttpUrlResponse; if (response.StatusCode >= 400 && response.StatusCode <= 599) { decisionHandler(WKNavigationResponsePolicy.Cancel); if (response.StatusCode == 410) { messagePage.OnRendererLoadFailed(messageId, false, MessageFailureStatus.Unavailable); } else { messagePage.OnRendererLoadFailed(messageId, true, MessageFailureStatus.LoadFailed); } } else { decisionHandler(WKNavigationResponsePolicy.Allow); } }
public void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { if (navigationResponse.Response.GetType() == typeof(NSHttpUrlResponse)) { NSHttpUrlResponse response = (NSHttpUrlResponse)navigationResponse.Response; if (response.StatusCode >= 400) { // The navigation request resulted in an error. SetTaskResult(null, new HealthServiceException(ClientResources.LoginErrorWithCode.FormatResource(response.StatusCode))); return; } string url = response.Url.AbsoluteString; if (url.Contains(_endUrlString)) { SetTaskResult(new Uri(url), null); } } decisionHandler(WKNavigationResponsePolicy.Allow); }
public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action <WKNavigationResponsePolicy> decisionHandler) { decisionHandler.Invoke(WKNavigationResponsePolicy.Allow); }