public bool LogIn(Windows.UI.Xaml.Controls.WebView webView, Windows.UI.Xaml.Controls.Frame parentFrame) { var uri = driveLink.GetStartUri(); webView.Navigate(uri); webView.NavigationCompleted += (s, e) => { if (driveLink.CheckRedirectUrl(e.Uri.AbsoluteUri)) { driveLink.ContinueGetTokens(e.Uri); var dialog = new Windows.UI.Popups.MessageDialog("You are authenticated!", "Success!"); dialog.ShowAsync(); parentFrame.GoBack(); } }; webView.NavigationFailed += (s, e) => { driveLink.ContinueGetTokens(null); var dialog = new Windows.UI.Popups.MessageDialog("There problems authenticating you. Please try again :(", "Fail!"); dialog.ShowAsync(); parentFrame.GoBack(); }; return(true); }
private void Control_NavigationStarting(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationStartingEventArgs args) { CookieWebView.OnNavigating(new CookieNavigationEventArgs() { Url = args.Uri.ToString() }); }
public static async Task <SizeI> WebViewContentSizeAsync(this Windows.UI.Xaml.Controls.WebView webView) { int contentWidth = 72 * 8; int contentHeight = 72 * 10; try { var widthString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" }); int.TryParse(widthString, out contentWidth); Debug.WriteLine("elementHeight = " + webView.Height); //var rect = await webView.InvokeScriptAsync("pizzx", new[] { "document.getElementById( 'rasta' ).clientHeight.toString()" }); // ask the content its height //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.scrollHeight.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.getBoundingClientRect().height.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "self.innerHeight.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.offsetHeight.toString()" }); var heightString = await webView.InvokeScriptAsync("eval", new[] { "Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight ).toString()" });//, document.documentElement.offsetHeight ).toString()" }); int.TryParse(heightString, out contentHeight); } catch (Exception e) { await Forms9Patch.Settings.RequestUserHelp(e); } return(new SizeI(contentWidth, contentHeight)); }
private static void WebView_NavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args) { var message = $"NavigationCompleted @ {args.Uri} [{sender.Source}]"; SetMessage(sender, message); sender.Log().DebugIfEnabled(() => message); }
private static void WebView_NavigationStarting(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationStartingEventArgs args) { var message = $"NavigationStarting @ {args.Uri} [{sender.Source}]"; SetMessage(sender, message); sender.Log().Debug(message); }
private void Control_NavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args) { var httpBaseProtocolFilter = new HttpBaseProtocolFilter(); var cookieManager = httpBaseProtocolFilter.CookieManager; var cookieCollection = cookieManager.GetCookies(args.Uri); var cookies = new CookieCollection(); foreach (var cookie in cookieCollection) { cookies.Add(new Cookie() { Domain = cookie.Domain, HttpOnly = cookie.HttpOnly, Name = cookie.Name, Path = cookie.Path, Secure = cookie.Secure, Value = cookie.Value, }); } CookieWebView.OnNavigated(new CookieNavigatedEventArgs() { Url = args.Uri.ToString(), Cookies = cookies }); }
public async Task LoadData(int _userId) { userId = _userId; _webview = new Windows.UI.Xaml.Controls.WebView(); _webview.Settings.IsJavaScriptEnabled = true; _webview.NavigationStarting += WebView_NavigationStarting; _webview.NavigationFailed += Webview_NavigationFailed; _webview.NavigationCompleted += WebView_NavigationCompleted; _webview.ScriptNotify += WebView_ScriptNotify; using (var db = new PrototypingContext()) { User user = db.Users.Single(u => u.UserId == userId); db.Entry(user).Reference(u => u.Prototype).Load(); recordSettings = db.RecordSettings.Last(); WebView.Navigate(new Uri(user.Prototype.Url)); } if (!recordSettings.Touches && !recordSettings.FrontCamera) { StartIconVisibility = false; } if (!recordSettings.FrontCamera) { VideoIconVisibility = false; } else { await MediaCaptureInitialization(); } }
public static async Task <SizeI> WebViewContentSizeAsync(this Windows.UI.Xaml.Controls.WebView webView) { var widthString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" }); if (!int.TryParse(widthString, out int contentWidth)) { throw new Exception(string.Format("failure/width:{0}", widthString)); } Debug.WriteLine("elementHeight = " + webView.Height); //var rect = await webView.InvokeScriptAsync("pizzx", new[] { "document.getElementById( 'rasta' ).clientHeight.toString()" }); // ask the content its height //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.scrollHeight.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.getBoundingClientRect().height.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "self.innerHeight.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.offsetHeight.toString()" }); var heightString = await webView.InvokeScriptAsync("eval", new[] { "Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight ).toString()" });//, document.documentElement.offsetHeight ).toString()" }); if (!int.TryParse(heightString, out int contentHeight)) { throw new Exception(string.Format("failure/height:{0}", heightString)); } return(new SizeI(contentWidth, contentHeight)); }
/// <summary> /// Present the Last.fm authentication UI and attempt to obtain a session key. /// </summary> /// <param name="authView">A WebView to display the Last.fm authentication page.</param> /// <param name="onSuccess">A callback for when the authentication is successful.</param> /// <param name="onFailure">A callback for when the authentication fails.</param> /// <returns>An async Task.</returns> public async Task LastFmLogin(Windows.UI.Xaml.Controls.WebView authView, Func <bool> onSuccess, Func <bool> onFailure) { Contract.Requires(authView != null); Contract.Requires(onSuccess != null); Contract.Requires(onFailure != null); try { HttpResponseMessage getTokenMessage = await __client.GetAsync(LastFmApiSecrets.LASTFMAPI_GET_TOKEN); string tokenResponse = await getTokenMessage.Content.ReadAsStringAsync(); string token = JsonObject .Parse(tokenResponse) .GetNamedString("token"); string authUri = string.Format(LastFmApiSecrets.LASTFMAPI_AUTH_URL_FORMAT, token); authView.LoadCompleted += async(sender, e) => { try { if (e.Uri.LocalPath.ToString().ToLowerInvariant() == LastFmApiSecrets.LASTFMAPI_AUTH_SUCCESS_URL) { string getSessionSignature = string.Format(LastFmApiSecrets.LASTFMAPI_GET_SESSION_SIGN_FORMAT, token); string getSessionSignatureMd5 = getSessionSignature.GetMd5Hash(); string getSession = string.Format(LastFmApiSecrets.LASTFMAPI_GET_SESSION_FORMAT, token, getSessionSignatureMd5); HttpResponseMessage getSessionMessage = await __client.GetAsync(getSession); string sessionResponse = await getSessionMessage.Content.ReadAsStringAsync(); JsonObject session = JsonObject .Parse(sessionResponse) .GetNamedObject("session"); LogIn(session.GetNamedString("name"), session.GetNamedString("key")); onSuccess(); } } catch (Exception) { // Failure after user interaction onFailure(); } }; authView.NavigationFailed += (sender, e) => { // WebView navigation failure onFailure(); }; authView.Navigate(new Uri(authUri)); } catch (Exception) { // Failure before user interaction onFailure(); } }
public static async Task <SizeI> WebViewContentSizeAsync(this Windows.UI.Xaml.Controls.WebView webView, int depth = 0, [System.Runtime.CompilerServices.CallerMemberName] string callerName = null) { if (webView is null) { await Forms9Patch.Debug.RequestUserHelp(null, "webView is null."); } int contentWidth = 72 * 8; int contentHeight = 72 * 10; if (depth > 50) { return(new SizeI(contentWidth, contentHeight)); } if (depth > 0) { await Task.Delay(100); } int line = P42.Utils.ReflectionExtensions.CallerLineNumber(); try { line = P42.Utils.ReflectionExtensions.CallerLineNumber(); var widthString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" }); line = P42.Utils.ReflectionExtensions.CallerLineNumber(); int.TryParse(widthString, out contentWidth); line = P42.Utils.ReflectionExtensions.CallerLineNumber(); System.Diagnostics.Debug.WriteLine("elementHeight = " + webView.Height); //var rect = await webView.InvokeScriptAsync("pizzx", new[] { "document.getElementById( 'rasta' ).clientHeight.toString()" }); // ask the content its height //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.scrollHeight.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.documentElement.getBoundingClientRect().height.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "self.innerHeight.toString()" }); //var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.offsetHeight.toString()" }); line = P42.Utils.ReflectionExtensions.CallerLineNumber(); var heightString = await webView.InvokeScriptAsync("eval", new[] { "Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight ).toString()" });//, document.documentElement.offsetHeight ).toString()" }); line = P42.Utils.ReflectionExtensions.CallerLineNumber(); int.TryParse(heightString, out contentHeight); line = P42.Utils.ReflectionExtensions.CallerLineNumber(); } catch (Exception e) { //await Forms9Patch.Debug.RequestUserHelp(e, "line = " + line + ", callerName=["+callerName+"]"); System.Diagnostics.Debug.WriteLine("UwpWebViewExtensions.WebViewContentSizeAsync FAIL"); return(await WebViewContentSizeAsync(webView, depth + 1, callerName)); } return(new SizeI(contentWidth, contentHeight)); }
private static void OnContentUriChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Windows.UI.Xaml.Controls.WebView wv = d as Windows.UI.Xaml.Controls.WebView; var uri = e.NewValue as Uri; if (uri == null) { return; } wv?.Navigate(uri); }
private async void OnWebNavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args) { while (NotificationIds.Count > 0) { Context.HideProgress(NotificationIds[0]); NotificationIds.RemoveAt(0); } if (!args.Uri.ToString().StartsWith(VkAuthorization.GetRedirectUrl())) { return; } await TryFinishAuthorizationAsync(args.Uri); }
private void Control_NewWindowRequested(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNewWindowRequestedEventArgs args) { var eventArgs = ManageRequestHandling(args.Uri.AbsoluteUri, args.Referrer.AbsoluteUri); if (eventArgs.Cancel) { args.Handled = true; } else { args.Handled = false; } }
private void Control_FrameNavigationStarting(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationStartingEventArgs args) { string referrer = args.Uri.AbsoluteUri; if (Element != null && Element.Source != null && Element.Source is UrlWebViewSource) { referrer = ((UrlWebViewSource)Element.Source).Url; } var eventArgs = ManageRequestHandling(args.Uri.AbsoluteUri, referrer); args.Cancel = eventArgs.Cancel; }
private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Windows.UI.Xaml.Controls.WebView wv = d as Windows.UI.Xaml.Controls.WebView; var content = e.NewValue as string; if (string.IsNullOrEmpty(content)) { return; } wv?.NavigateToString(content); }
/// <summary> /// Called when the UWP WebView event NavigationCompleted has been sent. /// </summary> /// <param name="sender">sender object</param> /// <param name="args">event args</param> private void OnNavigationCompleted( Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args) { if (this.Element.Source is HtmlWebViewSource) { this.Element.SendNavigated( new WebNavigatedEventArgs( WebNavigationEvent.NewPage, this.Element.Source, "about:blank", // no URL available args.IsSuccess ? WebNavigationResult.Success : WebNavigationResult.Failure)); } }
public static void EvalJS(WebBrowser browser, string js) { try { #if MAST_PHONE browser.InvokeScript("eval", new string[] { js }); #elif MAST_STORE await browser.InvokeScriptAsync("eval", new string[] { js }); #endif } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("EvalJS:" + ex.Message); // TODO: Bubble this up. } }
private async void WebView_NavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args) { string docClickScript = @"if (document.addEventListener) {" + "document.addEventListener(\"click\", PageClicked, false);" + "} else {" + "document.attachEvent('onclick', PageClicked);" + "} " + "function PageClicked(event){" + "var pointX = event.clientX;" + "var pointY = event.clientY;" + " window.external.notify('tap:' + pointX + ':' + pointY);" + "}"; await sender.InvokeScriptAsync("eval", new string[] { docClickScript }); //set event 'click' on page RingContentVisibility = false; RingText = screeningText; }
public static async Task <SizeI> WebViewContentSizeAsync(this Windows.UI.Xaml.Controls.WebView webView) { var widthString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" }); if (!int.TryParse(widthString, out int contentWidth)) { throw new Exception(string.Format("failure/width:{0}", widthString)); } // ask the content its height var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" }); if (!int.TryParse(heightString, out int contentHeight)) { throw new Exception(string.Format("failure/height:{0}", heightString)); } return(new SizeI(contentWidth, contentHeight)); }
public WebContentFetcher() { WebViewInstance = new Windows.UI.Xaml.Controls.WebView(); //WebViewInstance.Visibility = Windows.UI.Xaml.Visibility.Collapsed; WebViewInstance.NavigationStarting += async(sender, e) => { Debug.WriteLine("Starting NavigationStarting"); Navigating = true; await Task.Delay(4000); if (Navigating) { Debug.WriteLine("Time exceeds"); e.Cancel = true; Navigating = false; Fetching = false; HtmlContent = ""; } Debug.WriteLine("End NavigationStarting"); }; WebViewInstance.NavigationCompleted += async(sender, e) => { Debug.WriteLine("Starting NavigationCompleted"); Navigating = false; HtmlContent = await WebViewInstance.InvokeScriptAsync("eval", new string[1] { "document.doctype" }); HtmlContent += await WebViewInstance.InvokeScriptAsync("eval", new string[1] { "document.documentElement.outerHTML" }); if (!e.IsSuccess) { await Task.Delay(500); } Fetching = false; Debug.WriteLine("End NavigationCompleted"); }; }
/// <summary> /// Event handler that shows the Print Preview dialog once the DOM content has been loaded for the URI /// </summary> /// <param name="sender">The sender</param> /// <param name="args">The event args related to the DOM content loading completion</param> private async void NativeWebViewDOMContentLoaded( #pragma warning disable IDE0060 // Remove unused parameter Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewDOMContentLoadedEventArgs args) #pragma warning restore IDE0060 // Remove unused parameter { try { await ShowPrintApiAsync(); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { await PrintStatusReporting.ReportExceptionAsync(ex); } #pragma warning restore CA1031 // Do not catch general exception types finally { Unwire(); } }
/// <summary> /// Constructor /// </summary> /// <param name="printJobConfiguration">Configuration information for the print job</param> /// <param name="webViewAdditionalFunctions">Interface that provides access to functionality required by this class. Typically, this interface will be implemented by a subclass of Xamarin.Forms.WebView</param> public WebViewPrintJob( PrintJobConfiguration printJobConfiguration, IWebViewAdditionalFunctions webViewAdditionalFunctions) : base(printJobConfiguration) { if (webViewAdditionalFunctions is null) { throw new PrintJobException( "EXCEPTION:PRN003 Invalid interface to native WebView", new ArgumentNullException(nameof(webViewAdditionalFunctions))); } else if (webViewAdditionalFunctions.NativeControl is null) { throw new PrintJobException( "EXCEPTION:PRN004 Invalid (null) native WebView"); } else if (!(webViewAdditionalFunctions.NativeControl is Windows.UI.Xaml.Controls.WebView)) { throw new PrintJobException( "EXCEPTION:PRN006 Invalid native WebView"); } _nativeWebView = (Windows.UI.Xaml.Controls.WebView)webViewAdditionalFunctions.NativeControl; }
public static void SetIsAttached(Windows.UI.Xaml.Controls.WebView obj, bool value) { obj.SetValue(IsAttachedProperty, value); }
private static async void Browser_NavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args) { await sender.InvokeScriptAsync("eval", new[] { DisableScrollingJs }); }
/// <summary> /// Sets source string /// </summary> /// <param name="obj">Webview</param> /// <param name="value">Source string</param> public static void SetSourceString(_WebView obj, string value) { obj.SetValue(SourceStringProperty, value); }
public static async Task <string> GetHtml(this Windows.UI.Xaml.Controls.WebView webView) { string html = await webView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" }); return(html); }
private void WebView_NavigationStarting(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationStartingEventArgs args) { RingText = loadingPageText; RingContentVisibility = true; }
public static bool GetIsAttached(Windows.UI.Xaml.Controls.WebView obj) { return((bool)obj.GetValue(IsAttachedProperty)); }
public Bridge(BridgeHandler handler, WebBrowser browser) { this.handler = handler; this.browser = browser; }
public static void EvalJS(WebBrowser browser, string js) { try { #if MAST_PHONE browser.InvokeScript("eval", new string[] { js }); #elif MAST_STORE await browser.InvokeScriptAsync("eval", new string[] { js }); #endif } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("EvalJS:" + ex.Message); // TODO: Bubble this up. } }
private static void UnregisterEvents(Windows.UI.Xaml.Controls.WebView webView) { webView.NavigationStarting -= WebView_NavigationStarting; webView.NavigationCompleted -= WebView_NavigationCompleted; webView.NavigationFailed -= WebView_NavigationFailed; }
private void Control_NewWindowRequested(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNewWindowRequestedEventArgs args) { args.Handled = true; sender.Navigate(args.Uri); }