예제 #1
0
        protected override bool ShouldStartLoad(WKWebView webView, WKNavigationAction navigationAction)
        {
            try
            {
                //We're being redirected to our redirect URL so we must have been successful
                if (navigationAction.Request.Url.Host == "dillonbuchanan.com")
                {
                    var code = navigationAction.Request.Url.Query.Split('=')[1];
                    ViewModel.Login(code);
                    return false;
                }
    
                if (navigationAction.Request.Url.AbsoluteString.StartsWith("https://github.com/join"))
                {
                    Mvx.Resolve<IAlertDialogService>().Alert("Error", "Sorry, due to restrictions, creating GitHub accounts cannot be done in CodeHub.");
                    return false;
                }

                return base.ShouldStartLoad(webView, navigationAction);
            }
            catch 
            {
                Mvx.Resolve<IAlertDialogService>().Alert("Error Logging in!", "CodeHub is unable to login you in due to an unexpected error. Please try again.");
                return false;
            }
        }
예제 #2
0
        protected override bool ShouldStartLoad(WKWebView webView, WKNavigationAction navigationAction)
        {
            if (!navigationAction.Request.Url.AbsoluteString.StartsWith("file://", System.StringComparison.Ordinal))
            {
                ViewModel.GoToLinkCommand.Execute(navigationAction.Request.Url.AbsoluteString);
                return false;
            }

            return base.ShouldStartLoad(webView, navigationAction);
        }
        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

            webView = new WKWebView (View.Frame, new WKWebViewConfiguration ());
            View.AddSubview (webView);

            var url = new NSUrl ("https://evolve.xamarin.com");
            var request = new NSUrlRequest (url);
            webView.LoadRequest (request);
        }
예제 #4
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			// Create a new WKWebView, assign the delegate and add it to the view
			webView = new WKWebView(View.Frame, new WKWebViewConfiguration());
			webView.UIDelegate = this;
			View.AddSubview (webView);

			// Find the Alerts.html file and load it into the WKWebView
			string htmlPath = NSBundle.MainBundle.PathForResource ("Alerts", "html");
			string htmlContents = File.ReadAllText (htmlPath);
			webView.LoadHtmlString (htmlContents, null);
		}
예제 #5
0
		public void RunJavaScriptConfirmPanel (WKWebView webView, string message, WKFrameInfo frame, Action<bool> completionHandler)
		{
			// Create a native UIAlertController with the message
			var alertController = UIAlertController.Create (null, message, UIAlertControllerStyle.Alert);

			// Add two actions to the alert. Based on the result we call the completion handles and pass either true or false
			alertController.AddAction (UIAlertAction.Create ("Ok", UIAlertActionStyle.Default, okAction => {
				completionHandler(true);
			}));
			alertController.AddAction (UIAlertAction.Create ("Cancel", UIAlertActionStyle.Default, cancelAction => {
				completionHandler (false);
			}));

			// Present the alert
			PresentViewController (alertController, true, null);
		}
예제 #6
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 ViewController()
		{
			var split = new NSSplitView (new CGRect (0.0f, 0.0f, 400.0f, 400.0f)) { DividerStyle = NSSplitViewDividerStyle.Thin };
			var text = new NSTextField(new CGRect(0.0f, 0.0f, 64.0f, 16.0f));
			split.AddSubview (text);
			var button = new NSButton (new CGRect (0.0f, 0.0f, 64.0f, 16.0f)) {
				Title = "Go",
				StringValue = "https://www.google.com/" // TODO: This doesn't get set for some reason
			};
			button.Activated += (object sender, EventArgs e) => m_webView.LoadRequest (new NSUrlRequest (new NSUrl (text.StringValue)));
			split.AddSubview (button);

			var config = new WKWebViewConfiguration ();
			config.Preferences.SetValueForKey(NSNumber.FromBoolean(true), new NSString("developerExtrasEnabled"));
			m_webView = new WKWebView(new CGRect(0.0f, 0.0f, 400.0f, 400.0f), config);
			split.AddSubview (m_webView);
			View = split;
		}
예제 #8
0
        protected override bool ShouldStartLoad(WKWebView webView, WKNavigationAction navigationAction)
        {
            try 
            {
                if (navigationAction.NavigationType == WKNavigationType.LinkActivated) 
                {
                    if (navigationAction.Request.Url.ToString().Substring(0, 7).Equals("wiki://"))
                    {
                        GoToPage(navigationAction.Request.Url.ToString().Substring(7));
                        return false;
                    }
                }
            }
            catch
            {
            }

            return base.ShouldStartLoad(webView, navigationAction);
        }
예제 #9
0
        protected override bool ShouldStartLoad(WKWebView webView, WKNavigationAction navigationAction)
        {
            // F*****g BitBucket and their horrible user interface.
            if (ForbiddenRoutes.Any(navigationAction.Request.Url.AbsoluteString.StartsWith))
            {
                AlertDialogService.ShowAlert("Invalid Request", "Sorry, due to restrictions you can not sign-up for a new account in CodeBucket.");
                return false;
            }

            //We're being redirected to our redirect URL so we must have been successful
            if (navigationAction.Request.Url.Host == "codebucket")
            {
                ViewModel.Code = navigationAction.Request.Url.Query.Split('=')[1];
                ViewModel.LoginCommand.ExecuteIfCan();
                return false;
            }

            return base.ShouldStartLoad(webView, navigationAction);
        }
예제 #10
0
 public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     _webView.Get()?.OnLoadFinished(webView, navigation);
 }
예제 #11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Web = new WKWebView(View.Bounds, new WKWebViewConfiguration());
            Web.NavigationDelegate = new NavigationDelegate(this);
            Add(Web);
        }
예제 #12
0
        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 DidStartProvisionalNavigation(WKWebView webView, WKNavigation navigation)
 {
 }
예제 #14
0
 public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
 }
예제 #15
0
 public override void DidFailProvisionalNavigation(WKWebView webView, WKNavigation navigation, NSError error)
 {
     // If navigation fails, this gets called
     ConsoleHelper.WriteLine("DidFailProvisionalNavigation" + error.ToString());
 }
예제 #16
0
        public HtmlElement (string cellKey) 
        {
            Key = new NSString(cellKey);
            _height = 0f;

            _webView = new Lazy<WKWebView>(() =>
            {
                var bounds = UIScreen.MainScreen.Bounds;
                var webView = new WKWebView(new CGRect(0, 0, bounds.Width, 44f), new WKWebViewConfiguration());
                webView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
                webView.ScrollView.ScrollEnabled = false;
                webView.ScrollView.Bounces = false;
                webView.NavigationDelegate = new NavigationDelegate(this);
                return webView;
            });
        }
        /*
        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
            }
        }
        void SegmentValueChanged (object sender, EventArgs e)
        {
            if (_viewSegment.SelectedSegment == 0)
            {
                if (_previewView != null)
                {
                    _previewView.RemoveFromSuperview();
                    _previewView.Dispose();
                    _previewView = null;
                }

                Add(TextView);
                TextView.BecomeFirstResponder();
            }
            else
            {
                if (_previewView == null)
                    _previewView = new WKWebView(this.View.Bounds, new WKWebViewConfiguration());

                TextView.RemoveFromSuperview();
                Add(_previewView);

                var markdownService = Mvx.Resolve<IMarkdownService>();
                var markdownText = markdownService.Convert(Text);
                var model = new DescriptionModel(markdownText, (int)UIFont.PreferredSubheadline.PointSize);
                var view = new MarkdownView { Model = model }.GenerateString();
                _previewView.LoadHtmlString(view, NSBundle.MainBundle.BundleUrl);
            }
        }
        public override void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action <WKNavigationActionPolicy> decisionHandler)
        {
            string requestUrlString = navigationAction.Request.Url.ToString();

            // If the URL has the browser:// scheme then this is a request to open an external browser
            if (requestUrlString.StartsWith(iOSBrokerConstants.BrowserExtPrefix, StringComparison.OrdinalIgnoreCase))
            {
                DispatchQueue.MainQueue.DispatchAsync(() => _authenticationAgentUIViewController.CancelAuthentication(null, null));

                // Build the HTTPS URL for launching with an external browser
                var httpsUrlBuilder = new UriBuilder(requestUrlString)
                {
                    Scheme = Uri.UriSchemeHttps
                };
                requestUrlString = httpsUrlBuilder.Uri.AbsoluteUri;

                DispatchQueue.MainQueue.DispatchAsync(
                    () => UIApplication.SharedApplication.OpenUrl(new NSUrl(requestUrlString)));
                _authenticationAgentUIViewController.DismissViewController(true, null);
                decisionHandler(WKNavigationActionPolicy.Cancel);
                return;
            }

            if (requestUrlString.StartsWith(_authenticationAgentUIViewController.Callback, StringComparison.OrdinalIgnoreCase) ||
                requestUrlString.StartsWith(iOSBrokerConstants.BrowserExtInstallPrefix, StringComparison.OrdinalIgnoreCase))
            {
                _authenticationAgentUIViewController.DismissViewController(true, () =>
                                                                           _authenticationAgentUIViewController.CallbackMethod(AuthorizationResult.FromUri(requestUrlString)));
                decisionHandler(WKNavigationActionPolicy.Cancel);
                return;
            }

            if (requestUrlString.StartsWith(iOSBrokerConstants.DeviceAuthChallengeRedirect, StringComparison.OrdinalIgnoreCase))
            {
                Uri    uri   = new Uri(requestUrlString);
                string query = uri.Query;
                if (query.StartsWith("?", StringComparison.OrdinalIgnoreCase))
                {
                    query = query.Substring(1);
                }

                Dictionary <string, string> keyPair = CoreHelpers.ParseKeyValueList(query, '&', true, false, null);
                string responseHeader = DeviceAuthHelper.GetBypassChallengeResponse(keyPair);

                NSMutableUrlRequest newRequest = (NSMutableUrlRequest)navigationAction.Request.MutableCopy();
                newRequest.Url = new NSUrl(keyPair["SubmitUrl"]);
                newRequest[iOSBrokerConstants.ChallengeResponseHeader] = responseHeader;
                webView.LoadRequest(newRequest);
                decisionHandler(WKNavigationActionPolicy.Cancel);
                return;
            }

            if (!navigationAction.Request.Url.AbsoluteString.Equals(AboutBlankUri, StringComparison.OrdinalIgnoreCase) &&
                !navigationAction.Request.Url.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
            {
                AuthorizationResult result = AuthorizationResult.FromStatus(
                    AuthorizationStatus.ErrorHttp,
                    MsalError.NonHttpsRedirectNotSupported,
                    MsalErrorMessage.NonHttpsRedirectNotSupported);

                _authenticationAgentUIViewController.DismissViewController(true, () => _authenticationAgentUIViewController.CallbackMethod(result));
                decisionHandler(WKNavigationActionPolicy.Cancel);
                return;
            }
            decisionHandler(WKNavigationActionPolicy.Allow);
            return;
        }
예제 #20
0
 public override void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
 {
     var ret = _webView.Get()?.ShouldStartLoad(webView, navigationAction) ?? true;
     decisionHandler(ret ? WKNavigationActionPolicy.Allow : WKNavigationActionPolicy.Cancel);
 }
예제 #21
0
        //
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
              Title = "Test";

              View.Add(_scrollView);
              _scrollView.BackgroundColor = UIColor.FromRGB(235,235,235);
              _scrollView.FitToGuides(this, 0);

              for ( var idx = 0; idx < 10; idx++ )
              {
            var container = new Container();

            _scrollView.Add(container);

            if ( _scrollView.Subviews.Length == 1 )
            {
              container.Anchor(NSLayoutAttribute.Top, _scrollView, NSLayoutAttribute.Top, 10);
            }
            else
            {
              var prevView = _scrollView.Subviews[_scrollView.Subviews.Length - 2];
              container.Anchor(NSLayoutAttribute.Top, prevView, NSLayoutAttribute.Bottom, 10);
            }

            container
              .Anchor(NSLayoutAttribute.Left, _scrollView, NSLayoutAttribute.Left, 10)
              .Anchor(NSLayoutAttribute.Width, _scrollView, NSLayoutAttribute.Width, -20);

            container.ExpandedConstraint =
              NSLayoutConstraint.Create(
            container,
            NSLayoutAttribute.Height,
            NSLayoutRelation.Equal,
            _scrollView,
            NSLayoutAttribute.Height,
            1,
            -20);

            container.Header.Text = "hopla";

            //        var image = new UIImageView(UIImage.FromBundle("bloodborne.jpg"));
            //        container.Content.Add(image);
            //        image.FitToParent(0);

            var webView = new WKWebView(new CGRect(), new WKWebViewConfiguration());
            webView.ScrollView.ScrollEnabled = false;
            webView.Layer.BackgroundColor = UIColor.White.CGColor;

            container.Content = webView;

            webView.LoadRequest(new NSUrlRequest(new NSUrl("https://www.google.com")));
              }

              var finalView = _scrollView.Subviews[_scrollView.Subviews.Length - 1];
              finalView.Anchor(NSLayoutAttribute.Bottom, _scrollView, NSLayoutAttribute.Bottom, -10);
        }
예제 #22
0
 public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
 {
     _webView.Get()?.OnLoadFinished(null, EventArgs.Empty);
 }
예제 #23
0
 public override void DidStartProvisionalNavigation(WKWebView webView, WKNavigation navigation)
 {
     _webView.Get()?.OnLoadStarted(null, EventArgs.Empty);
 }
예제 #24
0
        protected override bool ShouldStartLoad(WKWebView webView, WKNavigationAction navigationAction)
        {
            var url = navigationAction.Request.Url;
            if(url.Scheme.Equals("app")) {
                var func = url.Host;

                if (func.Equals("ready"))
                {
                    _domLoaded = true;
                    foreach (var e in _toBeExecuted)
                        Web.EvaluateJavaScript(e, null);
                }
                else if(func.Equals("comment"))
                {
                    var commentModel = _serializationService.Deserialize<JavascriptCommentModel>(UrlDecode(url.Fragment));
                    PromptForComment(commentModel);
                }

                return false;
            }

            return base.ShouldStartLoad(webView, navigationAction);
        }
예제 #25
0
 public override void DidFailNavigation(WKWebView webView, WKNavigation navigation, NSError error)
 {
     _webView.Get()?.OnLoadError(error);
 }
예제 #26
0
파일: WebView.cs 프로젝트: xNUTs/CodeBucket
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Web = new WKWebView(View.Bounds, new WKWebViewConfiguration());
            Web.NavigationDelegate = new NavigationDelegate(this);
            Add(Web);

            var loadableViewModel = ViewModel as LoadableViewModel;
            if (loadableViewModel != null)
            {
                loadableViewModel.Bind(x => x.IsLoading).Subscribe(x =>
                {
                    if (x) NetworkActivity.PushNetworkActive();
                    else NetworkActivity.PopNetworkActive();
                });
            }
        }
예제 #27
0
 protected virtual bool ShouldStartLoad (WKWebView webView, WKNavigationAction navigationAction)
 {
     return true;
 }
        public override void LoadView()
        {
            // Create and configure the views.
            View = new UIView {
                BackgroundColor = UIColor.White
            };

            // Used to switch between the different views.
            _switcher = new UISegmentedControl(new string[] { "About", "Licenses", "Offline data" })
            {
                SelectedSegment = 0
            };

            // Displays the about.md in a web view.
            _aboutView = new WKWebView(new CGRect(), new WKWebViewConfiguration());
            _aboutView.TranslatesAutoresizingMaskIntoConstraints = false;
            _aboutView.NavigationDelegate = new BrowserLinksNavigationDelegate();

            // Displays the licenses.md in a web view.
            _licensesView = new WKWebView(new CGRect(), new WKWebViewConfiguration())
            {
                Hidden = true
            };
            _licensesView.TranslatesAutoresizingMaskIntoConstraints = false;
            _licensesView.NavigationDelegate = new BrowserLinksNavigationDelegate();

            // View for managing offline data for samples.
            _downloadView = new UIStackView {
                BackgroundColor = UIColor.White, Hidden = true
            };
            _downloadView.Axis = UILayoutConstraintAxis.Vertical;
            _downloadView.LayoutMarginsRelativeArrangement = true;
            _downloadView.Alignment = UIStackViewAlignment.Fill;
            _downloadView.TranslatesAutoresizingMaskIntoConstraints = false;

            // Label for download status.
            _statusLabel = new UILabel()
            {
                Text = "Ready", TextAlignment = UITextAlignment.Center
            };

            // Buttons for downloading or deleting all items.
            _buttonToolbar = new UIToolbar()
            {
                TranslatesAutoresizingMaskIntoConstraints = false, Hidden = true
            };

            _downloadAllButton = new UIBarButtonItem()
            {
                Title = "Download all"
            };
            _deleteAllButton = new UIBarButtonItem()
            {
                Title = "Delete all"
            };
            _cancelButton = new UIBarButtonItem()
            {
                Title = "Cancel"
            };

            _buttonToolbar.Items = new[]
            {
                _downloadAllButton,
                new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                _deleteAllButton,
            };

            // Table of samples with downloadable items.
            _downloadTable                 = new UITableView();
            _downloadTable.Source          = new SamplesTableSource(_samples, _statusLabel);
            _downloadTable.RowHeight       = 50;
            _downloadTable.AllowsSelection = false;

            // Add the views to the download view.
            _downloadView.AddArrangedSubview(_statusLabel);
            _downloadView.AddArrangedSubview(_downloadTable);

            // Add sub views to main view.
            View.AddSubviews(_aboutView, _licensesView, _downloadView, _buttonToolbar);

            NSLayoutConstraint.ActivateConstraints(new[]
            {
                _aboutView.TopAnchor.ConstraintEqualTo(View.TopAnchor),
                _aboutView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _aboutView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                _aboutView.BottomAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.BottomAnchor),

                _licensesView.TopAnchor.ConstraintEqualTo(View.TopAnchor),
                _licensesView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _licensesView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                _licensesView.BottomAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.BottomAnchor),

                _downloadView.TopAnchor.ConstraintEqualTo(View.TopAnchor),
                _downloadView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _downloadView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                _downloadView.BottomAnchor.ConstraintEqualTo(_buttonToolbar.TopAnchor),

                _statusLabel.HeightAnchor.ConstraintEqualTo(40),

                _buttonToolbar.TopAnchor.ConstraintEqualTo(_downloadView.BottomAnchor),
                _buttonToolbar.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _buttonToolbar.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                _buttonToolbar.BottomAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.BottomAnchor),
            });
        }