public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            Console.WriteLine(webView.Url);

            /* example script handler
             * webView.EvaluateJavaScript("callCsharp()", (result, error) =>
             * {
             *  if (error != null) Console.WriteLine(error);
             * });*/

            if (webView.Url == null)
            {
                return;
            }

            if (webView.Url.ToString().ToLower().Contains("success"))
            {
                NavigationController.PushViewController(new CreditCardSuccessViewController(), true);
                NavigationController.ViewControllers[1].RemoveFromParentViewController();
            }
            else
            {
                if (!webView.Url.ToString().ToLower().Contains("declined"))
                {
                    return;
                }
                NavigationController.PushViewController(new CreditCardDeclinedViewController(), true);
                NavigationController.ViewControllers[1].RemoveFromParentViewController();
            }
        }
Beispiel #2
0
 public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     if (FinishedLoadingUrl != null)
     {
         FinishedLoadingUrl(webView.Url.AbsoluteString);
     }
 }
Beispiel #3
0
 public override void DidStartProvisionalNavigation(WKWebView webView, WKNavigation navigation)
 {
     if (StartLoadingUrl != null)
     {
         StartLoadingUrl(webView.Url.AbsoluteString);
     }
 }
        public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            if (_handler == null)
            {
                return;
            }

            if (_handler != null)
            {
                _handler.PlatformView.UpdateCanGoBackForward(_handler.VirtualView);
            }

            if (webView.IsLoading)
            {
                return;
            }

            var url = GetCurrentUrl();

            if (url == $"file://{NSBundle.MainBundle.BundlePath}/")
            {
                return;
            }

            var virtualView = _handler?.VirtualView;

            if (virtualView == null)
            {
                return;
            }

            virtualView.Navigated(_lastEvent, url, WebNavigationResult.Success);

            _handler?.PlatformView.UpdateCanGoBackForward(virtualView);
        }
Beispiel #5
0
        public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            var content = ContextBridgeHelper.GetInjectableJavascript();
            var handler = _renderer.GetJavascriptEvaluationResultHandler();

            _renderer.Control.EvaluateJavaScript((NSString)content, handler);
        }
Beispiel #6
0
        private void OnError(WKWebView webView, WKNavigation navigation, NSError error)
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error))
            {
                this.Log().ErrorFormat("Could not navigate to web page: {0}", error.LocalizedDescription);
            }

            WebErrorStatus status = WebErrorStatus.OperationCanceled;

            _errorMap.TryGetValue((NSUrlError)(int)error.Code, out status);

            if (status != WebErrorStatus.OperationCanceled)
            {
                Uri uri;
                //If the url which failed to load is available in the user info, use it because with the WKWebView the
                //field webView.Url is equal to last successfully loaded URL and not to the failed URL
                var failedUrl = error.UserInfo.UnoGetValueOrDefault(new NSString("NSErrorFailingURLStringKey")) as NSString;
                if (failedUrl != null)
                {
                    uri = new Uri(failedUrl);
                }
                else
                {
                    uri = webView.Url?.ToUri() ?? _parentWebView.Source;
                }

                _parentWebView.OnNavigationFailed(new WebViewNavigationFailedEventArgs()
                {
                    Uri            = uri,
                    WebErrorStatus = status
                });

                _parentWebView.OnComplete(uri, false, status);
            }
        }
        public void OpenUrl(string uri)
        {
            var url     = new NSUrl(uri);
            var request = new NSUrlRequest(url);

            InitialNavigation = LoadRequest(request);
        }
 public override void DidFailProvisionalNavigation(
     WKWebView webView,
     WKNavigation navigation,
     NSError error)
 {
     // HACK YP: handling when auth was canceled
     _cts = new CancellationTokenSource();
     Task.Run(async() =>
     {
         try
         {
             await Task.Delay(1000, _cts.Token);
             _cts.Token.ThrowIfCancellationRequested();
             webView.BeginInvokeOnMainThread(() =>
             {
                 if (_closeRef.TryGetTarget(out var close))
                 {
                     close.Invoke();
                 }
             });
         }
         catch (OperationCanceledException)
         {
             // ignored
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
         }
     });
 }
Beispiel #9
0
        public override void DidStartProvisionalNavigation(WKWebView webView, WKNavigation navigation)
        {
            Debug.WriteLine($"CustomWkWebViewNavigationDelegate - DidStartProvisionalNavigation");

            element.InvokeStarted();
            //base.DidStartProvisionalNavigation(webView, navigation);
        }
Beispiel #10
0
            public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
            {
                if (webView.IsLoading)
                {
                    return;
                }

                var url = GetCurrentUrl();

                if (url == $"file://{NSBundle.MainBundle.BundlePath}/")
                {
                    return;
                }

                _renderer._ignoreSourceChanges = true;
                WebView.SetValueFromRenderer(WebView.SourceProperty, new UrlWebViewSource {
                    Url = url
                });
                _renderer._ignoreSourceChanges = false;

                var args = new WebNavigatedEventArgs(_lastEvent, WebView.Source, url, WebNavigationResult.Success);

                WebView.SendNavigated(args);

                _renderer.UpdateCanGoBackForward();
            }
Beispiel #11
0
 public override void DidCommitNavigation(WKWebView webView, WKNavigation navigation)
 {
     if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
     {
         this.Log().Debug($"WKNavigationDelegate.DidCommitNavigation: Request:{webView.Url?.ToUri()}");
     }
 }
Beispiel #12
0
        public override async void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            try
            {
                var _webView = webViewRenderer.Element as HybridWebView;
                if (_webView != null)
                {
                    await System.Threading.Tasks.Task.Delay(100);

                    var resultWidth  = (double)webView.ScrollView.ContentSize.Width;
                    var resultHeight = (double)webView.ScrollView.ContentSize.Height;
                    System.Console.WriteLine("----" + resultWidth + "-----" + resultHeight + "----" + _webView.Width);

                    double result = MeasureTextHeightSize(_webView.messageContent, _webView.Width, UIFont.LabelFontSize, null);

                    _webView.HeightRequest = result;

                    MessagingCenter.Send <Object, PassModel>(this, "LoadFinished", new PassModel(_webView.Id, Convert.ToDouble(result)));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error at HybridWebViewRenderer LoadingFinished: " + ex.Message);
            }
        }
        public async override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            if (Reference == null || !Reference.TryGetTarget(out FormsWebViewRenderer renderer))
            {
                return;
            }
            if (renderer.Element == null)
            {
                return;
            }

            renderer.Element.HandleNavigationCompleted(webView.Url.ToString());
            await renderer.OnJavascriptInjectionRequest(FormsWebView.InjectedFunction);

            if (renderer.Element.EnableGlobalCallbacks)
            {
                foreach (var function in FormsWebView.GlobalRegisteredCallbacks)
                {
                    await renderer.OnJavascriptInjectionRequest(FormsWebView.GenerateFunctionScript(function.Key));
                }
            }

            foreach (var function in renderer.Element.LocalRegisteredCallbacks)
            {
                await renderer.OnJavascriptInjectionRequest(FormsWebView.GenerateFunctionScript(function.Key));
            }

            renderer.Element.CanGoBack    = webView.CanGoBack;
            renderer.Element.CanGoForward = webView.CanGoForward;
            renderer.Element.Navigating   = false;
            renderer.Element.HandleContentLoaded();
        }
Beispiel #14
0
 public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     webView.EvaluateJavaScript("callCsharp()", (result, error) =>
     {
         if (error != null) Console.WriteLine(error);
     });
 }
Beispiel #15
0
        public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            Console.WriteLine("DidFinishNavigation");
            NSUrl token = webView.Url;

            token.LoadData.
        }
Beispiel #16
0
        public override void DidFailProvisionalNavigation(WKWebView webView, WKNavigation navigation, NSError error)
        {
            Debug.WriteLine($"CustomWkWebViewNavigationDelegate - DidFailProvisionalNavigation - error : {error}");

            var errorKind = ServiceErrorKind.None;

            switch (error.Code)
            {
            case -1009:     // no internet access
            {
                errorKind = ServiceErrorKind.NoInternetAccess;
                break;
            }

            case -1001:     // timeout
            {
                errorKind = ServiceErrorKind.Timeout;
                break;
            }

            case -1003:     // server cannot be found
            case -1100:     // url not found on server
            default:
            {
                errorKind = ServiceErrorKind.ServiceIssue;
                break;
            }
            }
            element.InvokeFailed(errorKind);
            //base.DidFailProvisionalNavigation(webView, navigation, error);
        }
Beispiel #17
0
        public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            var element = Element as WeavyWebView;

            if (element == null)
            {
                return;
            }

            // due to inconsistency when setting the cookies in the wk web view, a reload is performed when the cookies has been set. Until better solution is in place, this is the work-around.
            if (shouldReload)
            {
                shouldReload = false;
                Control.Reload();
            }

            // inject scripts
            Inject(NativeFunction);
            Inject(GetFuncScript());

            // call load finished on the web view
            element.OnLoadFinished(this, EventArgs.Empty);

            // set if we can navigate back/forward
            element.CanGoBack    = Control.CanGoBack;
            element.CanGoForward = Control.CanGoForward;
        }
Beispiel #18
0
 public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     if (_navigation == navigation)
     {
         FinishRequest();
     }
 }
 public override void DidCommitNavigation(WKWebView webView, WKNavigation navigation)
 {
     if (_currentUri != null && _currentNavigation == navigation)
     {
         _webView.HandleNavigationStarting(_currentUri);
     }
 }
Beispiel #20
0
 public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     if (Element != null)
     {
         (Element as ShellWebView).OnNavigationCompleted(webView, webView.Url.AbsoluteString);
     }
 }
Beispiel #21
0
        public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            try
            {
                int          padding     = 10;
                UIEdgeInsets pageMargins = new UIEdgeInsets(padding, padding, padding, padding);
                webView.ViewPrintFormatter.ContentInsets = pageMargins;
                UIPrintPageRenderer renderer = new UIPrintPageRenderer();
                renderer.AddPrintFormatter(webView.ViewPrintFormatter, 0);
                CGSize pageSize      = new CGSize(PDFToHtml.PageWidth, PDFToHtml.PageHeight);
                CGRect printableRect = new CGRect(padding, padding, pageSize.Width - (padding * 2), pageSize.Height - (padding * 2));
                CGRect paperRect     = new CGRect(0, 0, PDFToHtml.PageWidth, PDFToHtml.PageHeight);

                var nSString            = new NSString("PaperRect");
                var printableRectstring = new NSString("PrintableRect");

                renderer.SetValueForKey(NSValue.FromObject(paperRect), nSString);
                renderer.SetValueForKey(NSValue.FromObject(printableRect), printableRectstring);

                NSData file = PrintToPDFWithRenderer(renderer, paperRect);
                File.WriteAllBytes(PDFToHtml.FilePath + ".pdf", file.ToArray());
                PDFToHtml.Status = PDFEnum.Completed;
            }
            catch
            {
                PDFToHtml.Status = PDFEnum.Failed;
            }
        }
            public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
            {
                double height, width;
                int    header, sidespace;

                width     = 595.2;
                height    = 841.8;
                header    = 10;
                sidespace = 10;


                UIEdgeInsets pageMargins = new UIEdgeInsets(header, sidespace, header, sidespace);

                webView.ViewPrintFormatter.ContentInsets = pageMargins;

                UIPrintPageRenderer renderer = new UIPrintPageRenderer();

                renderer.AddPrintFormatter(webView.ViewPrintFormatter, 0);

                CGSize pageSize      = new CGSize(width, height);
                CGRect printableRect = new CGRect(sidespace,
                                                  header,
                                                  pageSize.Width - (sidespace * 2),
                                                  pageSize.Height - (header * 2));
                CGRect paperRect = new CGRect(0, 0, width, height);

                renderer.SetValueForKey(NSValue.FromObject(paperRect), (NSString)"paperRect");
                renderer.SetValueForKey(NSValue.FromObject(printableRect), (NSString)"printableRect");
                NSData file = PrintToPDFWithRenderer(renderer, paperRect);

                File.WriteAllBytes(filename, file.ToArray());
            }
Beispiel #23
0
        /*
         * public override void DecidePolicy (WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
         * {
         *      Console.WriteLine ("**** DecidePolicy****: " + navigationAction.Request);
         *
         *      webView.LoadRequest (navigationAction.Request);  // testing, it blocks the request load
         *
         * }
         */

        public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
                        #if DEBUG
            SystemLogger.Log(SystemLogger.Module.GUI, "AppverseWKNavigationDelegate ************** WEBVIEW LOAD FINISHED");
                        #endif
            if (_appDelegate != null && _application != null)
            {
                UIApplicationState applicationState = _application.ApplicationState;

                // inform other weak delegates (if exist) about the web view finished event
                IPhoneServiceLocator.WebViewLoadingFinished(applicationState, _launchOptions);

                // The NSDictionary options variable would contain any notification data if the user clicked the 'view' button on the notification
                // to launch the application.
                // This method processes these options from the FinishedLaunching.
                _appDelegate.processLaunchOptions(_launchOptions, true, applicationState);

                // Processing extra data received when launched externally (using custom scheme url)
                _appDelegate.processLaunchData();
            }
            else
            {
                                #if DEBUG
                SystemLogger.Log(SystemLogger.Module.GUI, "AppverseWKNavigationDelegate  ************** Application Delegate is not accessible. Stop processing notifications and/or launch data");
                                #endif
            }
        }
Beispiel #24
0
 public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     if (Overlay != null)
     {
         Overlay.RemoveFromSuperview();
         Overlay = null;
     }
 }
            public override void DidStartProvisionalNavigation(WKWebView webView, WKNavigation navigation)
            {
                _webView.WebViewIsBusy = true;
                //string _url = webView.Url.ToString();
                string u = "tel";

                UIApplication.SharedApplication.OpenUrl(new NSUrl(u));
            }
Beispiel #26
0
 public override void DidCommitNavigation(WKWebView webView, WKNavigation navigation)
 {
     if (_currentUri != null && _currentNavigation == navigation)
     {
         // TODO: Determine whether this is needed
         //_webView.HandleNavigationStarting(_currentUri);
     }
 }
Beispiel #27
0
 public override void DidFailNavigation(WKWebView webView, WKNavigation navigation, NSError error)
 {
     if (inner.TryGetTarget(out var target))
     {
         target.NotifyLoadComplete();
         Core.Log("Error: " + error.Description);
     }
 }
Beispiel #28
0
    public async void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
    {
        var content = await webView.EvaluateJavaScriptAsync("(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();");

        var html = FromObject(content);

        Console.WriteLine((html.ToString()).Substring(0, 40));
    }
Beispiel #29
0
 public override void DidFinishNavigation(WebKit.WKWebView webView, WKNavigation navigation)
 {
     if (canDoOnContentLoaded)
     {
         wvp.OnContentLoaded();
         canDoOnContentLoaded = false;
     }
 }
 public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     if (_currentUri != null && _currentNavigation == navigation)
     {
         _webView.HandleNavigationFinished(_currentUri);
         _currentUri        = null;
         _currentNavigation = null;
     }
 }
Beispiel #31
0
        protected override void OnLoadFinished(WKWebView webView, WKNavigation navigation)
        {
            base.OnLoadFinished(webView, navigation);

            if (webView.Url?.AbsoluteString?.StartsWith("https://bitbucket") ?? false)
            {
                var script = new StringBuilder();

                //Apple is full of clowns. The GitHub login page has links that can ultimiately end you at a place where you can purchase something
                //so we need to inject javascript that will remove these links. What a bunch of idiots...
                script.Append("$('#header').hide();");
                script.Append("$('#footer').hide();");

                Web.EvaluateJavaScript("(function(){setTimeout(function(){" + script + "}, 100); })();", null);
            }
        }
 public override void DidFailNavigation(WKWebView webView, WKNavigation navigation, NSError error)
 {
     _webView.Get()?.OnLoadError(error);
 }
 public override void DidStartProvisionalNavigation(WKWebView webView, WKNavigation navigation)
 {
     _webView.Get()?.OnLoadStarted(null, EventArgs.Empty);
 }
 public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     _webView.Get()?.OnLoadFinished(webView, navigation);
 }
        protected virtual void OnLoadFinished(WKWebView webView, WKNavigation navigation)
        {
            _loadingIndicator.Down();

            if (BackButton != null)
            {
                BackButton.Enabled = Web.CanGoBack;
                ForwardButton.Enabled = Web.CanGoForward;
                RefreshButton.Enabled = true;
            }

            if (_showPageAsTitle)
            {
                Web.EvaluateJavaScript("document.title", (o, _) => {
                    Title = o as NSString;
                });
            }
        }
 public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     _webView.Get()?.OnLoadFinished(null, EventArgs.Empty);
 }
        /*
        public override void DecidePolicy (WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
        {
            Console.WriteLine ("**** DecidePolicy****: " + navigationAction.Request);

            webView.LoadRequest (navigationAction.Request);  // testing, it blocks the request load

        }
        */
        public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
            #if DEBUG
            SystemLogger.Log (SystemLogger.Module.GUI, "AppverseWKNavigationDelegate ************** WEBVIEW LOAD FINISHED");
            #endif
            if (_appDelegate != null && _application != null) {

                UIApplicationState applicationState = _application.ApplicationState;

                // inform other weak delegates (if exist) about the web view finished event
                IPhoneServiceLocator.WebViewLoadingFinished(applicationState, _launchOptions);

                // The NSDictionary options variable would contain any notification data if the user clicked the 'view' button on the notification
                // to launch the application.
                // This method processes these options from the FinishedLaunching.
                _appDelegate.processLaunchOptions (_launchOptions, true, applicationState);

                // Processing extra data received when launched externally (using custom scheme url)
                _appDelegate.processLaunchData ();

            } else {
                #if DEBUG
                SystemLogger.Log (SystemLogger.Module.GUI, "AppverseWKNavigationDelegate  ************** Application Delegate is not accessible. Stop processing notifications and/or launch data");
                #endif
            }
        }