private async void OnDomContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args) { var model = Model; await AutoFill(model.UserName, "username", "email", "login"); await AutoFill(model.Password, "password", "passwd"); }
private void Browser_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { if (!args.IsSuccess) { Debug.WriteLine("Navigation to this page failed, check your internet connection."); } }
private void WebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { //this.webView.AllowedScriptNotifyUris.Add(new Uri("ms-appx-web:///Resources/HTMLPage1.html")); //gridManager.Move(7, 12, this.webView); gridManager.Move(0, 0, this.webView); }
internal async Task createWebView(Dictionary<string, object> options) { _browserWindow._window = await _browserWindow.createWindow(options); string url; if (options.ContainsKey(NKEBrowserOptions.kPreloadURL)) url = (string)options[NKEBrowserOptions.kPreloadURL]; else url = NKEBrowserDefaults.kPreloadURL; WebView webView = new WebView(WebViewExecutionMode.SeparateThread); this.webView = webView; _browserWindow.webView = webView; _browserWindow._window.controls.Add(webView); webView.Navigate(new Uri(url)); _browserWindow.context = await NKSMSWebViewContext.getScriptContext(_id, webView, options); webView.NavigationStarting += WebView_NavigationStarting; webView.NavigationCompleted += this.WebView_NavigationCompleted; this.init_IPC(); this._type = NKEBrowserType.MSWebView.ToString(); if (options.itemOrDefault<bool>("NKE.InstallElectro", true)) await Renderer.addElectro(_browserWindow.context, options); NKLogging.log(string.Format("+E{0} Renderer Ready", _id)); _browserWindow.events.emit("NKE.DidFinishLoad", _id); }
private void Web_OnNavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args) { // WebView native object must be inserted in the OnNavigationStarting event handler KeyHandler winRTObject = new KeyHandler(); // Expose the native WinRT object on the page's global object Web.AddWebAllowedObject("NotifyApp", winRTObject); }
private async void WebViewer_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { // Check if new location is redirect uri if (args.Uri.AbsoluteUri.IndexOf(App.RedirectUri) == 0) { // Get parameters var encoder = new WwwFormUrlDecoder(args.Uri.AbsoluteUri.Replace('#', '&')); // Replacing # with ? to make GetFirstValueByName() work var accessToken = encoder.GetFirstValueByName("access_token"); var expires = encoder.GetFirstValueByName("expires"); if (!String.IsNullOrEmpty(accessToken)) { // Success App.AccessToken = accessToken; App.Expires = expires; Frame.GoBack(); var successDialog = new MessageDialog("Successfully logged in.", "Success!"); await successDialog.ShowAsync(); return; } // Show error message, if something went wrong var errorDialog = new MessageDialog("Whoops, we could not log you in successfully. Sorry for that!", "Something went wrong..."); await errorDialog.ShowAsync(); Frame.GoBack(); } }
#pragma warning disable CS1998 /// <summary> /// Converts HTML to PNG /// </summary> /// <param name="html">HTML.</param> /// <param name="fileName">File name.</param> /// <param name="onComplete">On complete.</param> public async void ToPng(string html, string fileName, Action <string> onComplete) { var rootPageRenderer = (Xamarin.Forms.Platform.UWP.PageRenderer)Platform.GetRenderer(Forms9Patch.RootPage._instance); var size = new Size(8.5, 11); var webView = new Windows.UI.Xaml.Controls.WebView { DefaultBackgroundColor = Windows.UI.Colors.White, Width = (size.Width - 0.5) * 72 / 2, Height = 10, // (size.Height - 0.5) * 72, }; /* * var transform = new TranslateTransform(); * transform.TransformPoint(new Windows.Foundation.Point(0, 0)); * webView.RenderTransform = transform; */ rootPageRenderer.Children.Add(webView); webView.Visibility = Visibility.Visible; webView.SetValue(PngFileNameProperty, fileName); webView.SetValue(OnCompleteProperty, onComplete); webView.SetValue(HtmlStringProperty, html); webView.NavigationCompleted += NavigationCompleteA; webView.NavigationFailed += WebView_NavigationFailed; webView.NavigateToString(html); }
private void wvMain_UnviewableContentIdentified(Windows.UI.Xaml.Controls.WebView sender, WebViewUnviewableContentIdentifiedEventArgs args) { SendMessage?.Invoke(null, new ContentViewEventArgs() { Type = "UnviewableContentIdentified" }); }
public void Unload() { if (dtMaxLoadTime != null) { dtMaxLoadTime.Stop(); dtMaxLoadTime.Tick -= DtMaxLoadTime_Tick; dtMaxLoadTime = null; } if (_renderElement != null) { _renderElement.ScriptNotify -= wvMain_ScriptNotify; _renderElement.ContentLoading -= wvMain_ContentLoading; _renderElement.NavigationStarting -= wvMain_NavigationStarting; _renderElement.NavigationCompleted -= wvMain_NavigationCompleted; _renderElement.LoadCompleted -= wvMain_LoadCompleted; _renderElement.LongRunningScriptDetected -= wvMain_LongRunningScriptDetected; _renderElement.UnsafeContentWarningDisplaying -= wvMain_UnsafeContentWarningDisplaying; _renderElement.UnviewableContentIdentified -= wvMain_UnviewableContentIdentified; _renderElement.NavigationFailed -= wvMain_NavigationFailed; _renderElement.NewWindowRequested -= wvMain_NewWindowRequested; _renderElement.DOMContentLoaded -= wvMain_DOMContentLoaded; _renderElement = null; } }
public GoogleDownloadController(AccountDB acc, AccountDownloadListener notify) { //browser = webBrowser; browser = new WebView(); Init(acc, notify); SetupWebBrowser(); }
private void Web_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { if (args.IsSuccess) { Value.Text = args.Uri.ToString(); } }
private void wvMain_UnsafeContentWarningDisplaying(Windows.UI.Xaml.Controls.WebView sender, object args) { SendMessage?.Invoke(null, new ContentViewEventArgs() { Type = "UnsafeContentWarningDisplaying" }); }
private void wvMain_LongRunningScriptDetected(Windows.UI.Xaml.Controls.WebView sender, WebViewLongRunningScriptDetectedEventArgs args) { SendMessage?.Invoke(null, new ContentViewEventArgs() { Type = "LongRunningScriptDetected" }); }
public async void CheckingLoginByManualSuccess(WebView webView, bool isLoaded) { if (CheckInternetConnection() || isUserCancel) return; if (isLoaded) { NotifyDownloadStatus(DownloadStatus.LOADING, " ..."); bool success = await IsPageSuccess(webView); if (success) { isReload = false; NotifyCloseWebViewForm(); currentStep = STEP_ACCEPT; NotifyDownloadStatus(DownloadStatus.PROCESSING, "60%"); browser.Navigate(new Uri(YAHOO_OAUTH2_URL)); return; } else { NotifyDownloadStatus(DownloadStatus.CONTINUE_LOGIN, ""); NotifyOpenWebViewForm(); System.Diagnostics.Debug.WriteLine("open form"); return; } } }
/// <summary> /// Called by the host when we should show content. /// </summary> /// <param name="post"></param> public async void OnPrepareContent(Post post) { // So the loading UI m_host.ShowLoading(); m_loadingHidden = false; // Since some of this can be costly, delay the work load until we aren't animating. await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { lock(this) { if(m_isDestroyed) { return; } // Make the webview m_webView = new WebView(WebViewExecutionMode.SeparateThread); // Setup the listeners, we need all of these because some web pages don't trigger // some of them. m_webView.FrameNavigationCompleted += NavigationCompleted; m_webView.NavigationFailed += NavigationFailed; m_webView.DOMContentLoaded += DOMContentLoaded; m_webView.ContentLoading += ContentLoading; // Navigate m_webView.Navigate(new Uri(post.Url, UriKind.Absolute)); ui_contentRoot.Children.Add(m_webView); } }); }
public MainPage() { WebView Navegador = new WebView(); this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; Navegador.Navigate(new Uri("http://www.bing.com", UriKind.Absolute)); }
public void InitializeComponent() { if (_contentLoaded) return; _contentLoaded = true; Application.LoadComponent(this, new System.Uri("ms-appx:///BlankPage.xaml"), Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application); FullScreenLandscape = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenLandscape"); Filled = (Windows.UI.Xaml.VisualState)this.FindName("Filled"); FullScreenPortrait = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenPortrait"); Snapped = (Windows.UI.Xaml.VisualState)this.FindName("Snapped"); FullGrid = (Windows.UI.Xaml.Controls.Grid)this.FindName("FullGrid"); SnapGrid = (Windows.UI.Xaml.Controls.Grid)this.FindName("SnapGrid"); PortaitGrid = (Windows.UI.Xaml.Controls.Grid)this.FindName("PortaitGrid"); textBlock = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("textBlock"); ContentView2 = (Windows.UI.Xaml.Controls.WebView)this.FindName("ContentView2"); ItemListView1 = (Windows.UI.Xaml.Controls.ListView)this.FindName("ItemListView1"); ContentView1 = (Windows.UI.Xaml.Controls.WebView)this.FindName("ContentView1"); TitleText = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("TitleText"); grid = (Windows.UI.Xaml.Controls.Grid)this.FindName("grid"); ItemListView = (Windows.UI.Xaml.Controls.ListView)this.FindName("ItemListView"); PostTitleText = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("PostTitleText"); ContentView = (Windows.UI.Xaml.Controls.WebView)this.FindName("ContentView"); }
private async void NavigationCompleteA(Windows.UI.Xaml.Controls.WebView webView, WebViewNavigationCompletedEventArgs args) { //IsMainPageChild(webView); webView.NavigationCompleted -= NavigationCompleteA; var contentSize = await webView.WebViewContentSizeAsync(); System.Diagnostics.Debug.WriteLine("A contentSize=[" + contentSize + "]"); System.Diagnostics.Debug.WriteLine("A webView.Size=[" + webView.Width + "," + webView.Height + "] IsOnMainThread=[" + P42.Utils.Environment.IsOnMainThread + "]"); //webView.Width = contentSize.Width; var width = (int)webView.GetValue(PngWidthProperty); webView.Width = width; webView.Height = contentSize.Height; //webView.UpdateLayout(); webView.NavigationCompleted += NavigationCompleteB; //if (webView.GetValue(HtmlStringProperty) is string html) // webView.NavigateToString(html); //else //NavigationCompleteB(webView, args); webView.Refresh(); }
/// <summary> /// Initializes a new instance of the <see cref="EngagementPageOverlay" /> class. /// </summary> public EngagementPageOverlay() { // Initialize the webview for notifications. Banner = new WebView(); Banner.Name = BannerWebviewName; Banner.Height = BannerHeight; Banner.HorizontalAlignment = HorizontalAlignment.Stretch; Banner.VerticalAlignment = VerticalAlignment.Top; Banner.Visibility = Visibility.Collapsed; // Initialize the webview for text\Web announcements and Polls. Interstitial = new WebView(); Interstitial.Name = InterstitialWebviewName; Interstitial.HorizontalAlignment = HorizontalAlignment.Stretch; Interstitial.VerticalAlignment = VerticalAlignment.Stretch; Interstitial.Visibility = Visibility.Collapsed; // Initialize the webviews' container. Container = new Grid(); Container.Name = OverlayContainerName; // Add webviews to the container but leave the first index to the page's content. Container.Children.Insert(1, Banner); Container.Children.Insert(2, Interstitial); }
public async Task<string> GetSchedule(string user) { StringBuilder sb = new StringBuilder(); try { UnityDataAccess uda = new UnityDataAccess(); // string sToken = await uda.GetToken(objUnityData.UnitySvcUser, objUnityData.UnitySvcPwd, user); string strDate = DateTime.Now.ToString(@"MM/dd/yyyy"); string sJson = await uda.Magic("GetSchedule", objUnityData.UnityAppUser, objUnityData.UnityAppName, "", objUnityData.Token, strDate, "", "", "", "", "", ""); return sJson; } catch (Exception ex) { WebView wc = new WebView(); wc.NavigateToString(ex.Message); Window.Current.Content = wc; return ""; } }
private void loginWeb_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args) { if (args.Uri.AbsoluteUri.Contains("#")) { if (args.Uri.Fragment.StartsWith("#access_token=")) { loginWeb.Stop(); string token = args.Uri.Fragment.Replace("#access_token=", string.Empty); ApplicationData.Current.LocalSettings.Values[SharedStrings.AccessTokenKeyValue] = token; SharedStrings.CurrentToken = token; if (!fromMain) { if (!Frame.Navigate(typeof(MainPage))) { } } else { if (Frame.CanGoBack) { Frame.GoBack(); } } } } }
public void Back(ref WebView web) { if (web.CanGoBack) { web.GoBack(); } }
void CreateBrowser() { SetDefaultUserAgent(); Result = new controls.WebView(controls.WebViewExecutionMode.SeparateThread); Result.Loaded += async(s, e) => await View.LoadFinished.RaiseOn(Thread.Pool); Result.NavigationStarting += (s, e) => { if (e.Uri != null && View.OnBrowserNavigating(e.Uri.ToString())) { Result.Stop(); } }; Result.NavigationCompleted += async(s, e) => { if (View.BrowserNavigated.IsHandled()) { var html = (await EvaluateJavascript("document.documentElement.outerHTML")).ToStringOrEmpty(); var url = e.Uri.ToStringOrEmpty(); Thread.Pool.RunAction(() => View.OnBrowserNavigated(url, html)); } }; Result.LoadCompleted += Browser_LoadCompleted; Result.NavigationFailed += Browser_NavigationFailed; }
public void InitializeComponent() { if (_contentLoaded) return; _contentLoaded = true; Application.LoadComponent(this, new System.Uri("ms-appx:///SplitPage.xaml"), Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application); pageRoot = (NoelBlogReader.Common.LayoutAwarePage)this.FindName("pageRoot"); itemsViewSource = (Windows.UI.Xaml.Data.CollectionViewSource)this.FindName("itemsViewSource"); primaryColumn = (Windows.UI.Xaml.Controls.ColumnDefinition)this.FindName("primaryColumn"); titlePanel = (Windows.UI.Xaml.Controls.Grid)this.FindName("titlePanel"); itemListScrollViewer = (Windows.UI.Xaml.Controls.ScrollViewer)this.FindName("itemListScrollViewer"); itemDetail = (Windows.UI.Xaml.Controls.ScrollViewer)this.FindName("itemDetail"); itemDetailGrid = (Windows.UI.Xaml.Controls.Grid)this.FindName("itemDetailGrid"); itemTitle = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("itemTitle"); contentViewBorder = (Windows.UI.Xaml.Controls.Border)this.FindName("contentViewBorder"); contentView = (Windows.UI.Xaml.Controls.WebView)this.FindName("contentView"); contentViewRect = (Windows.UI.Xaml.Shapes.Rectangle)this.FindName("contentViewRect"); itemListView = (Windows.UI.Xaml.Controls.ListView)this.FindName("itemListView"); backButton = (Windows.UI.Xaml.Controls.Button)this.FindName("backButton"); pageTitle = (Windows.UI.Xaml.Controls.TextBlock)this.FindName("pageTitle"); FullScreenLandscape = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenLandscape"); Filled = (Windows.UI.Xaml.VisualState)this.FindName("Filled"); FullScreenPortrait = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenPortrait"); FullScreenPortrait_Detail = (Windows.UI.Xaml.VisualState)this.FindName("FullScreenPortrait_Detail"); Snapped = (Windows.UI.Xaml.VisualState)this.FindName("Snapped"); Snapped_Detail = (Windows.UI.Xaml.VisualState)this.FindName("Snapped_Detail"); }
private async void MainWebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args) { try { // is coming from click on page if (_isFromNavigationButton == false && args.Uri != null) { if (ViewModel.ParseLinksPages) { args.Cancel = true; await ViewModel.LoadCurrentPageAsync(args.Uri.ToString()); NavigateToCurrentPage(false); } else { await ViewModel.LoadCurrentPageAsync(args.Uri.ToString()); } } _isFromNavigationButton = false; } catch (Exception ex) { // TODO: handle it properly } }
private void wvMain_NavigationStarting(Windows.UI.Xaml.Controls.WebView sender, WebViewNavigationStartingEventArgs args) { SendMessage?.Invoke(null, new ContentViewEventArgs() { Type = "NavigationStarting", Uri = args.Uri }); }
public void Forward(ref WebView web) { if (web.CanGoForward) { web.GoForward(); } }
private void WebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args) { mProgressBar.Visibility = Visibility.Visible; Log.d(args.Uri); if (args.Uri.ToString().Contains("facebook.com")) { args.Cancel = true; return; } if (!skip && args.Uri.ToString().Contains("/users/auth/osm/callback")) { skip = true; args.Cancel = true; Task.Run(() => { Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() => { HttpRequestMessage request = new HttpRequestMessage(); request.RequestUri = args.Uri; request.Headers.Add("Install-ID", Prefs.InstallId); // use a custom user agent to change the behavior of the website request.Headers.Add("User-Agent", WebViewUtils.CreateAppsUserAgent()); mWebView.NavigateWithHttpRequestMessage(request); }).Forget(); }); } }
private async void NetWeb_DOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args) { await NetWeb.InvokeScriptAsync("eval", new string[] { IPSource.IPHelper.GetDomain() }); NetWeb.DOMContentLoaded -= NetWeb_DOMContentLoaded; await Task.Delay(2000); await NetWeb.InvokeScriptAsync("eval", new string[] { IPSource.IPHelper.Script3 }); }
async void OnWebViewNavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, WebViewNavigationCompletedEventArgs args) { if (args.IsSuccess) { await Control.InvokeScriptAsync("eval", new[] { JavaScriptFunction }); } }
async private void LoadAndRefresh(Mark selectedMark, Windows.UI.Xaml.Controls.WebView WebViewControl) { if (selectedMark.type == "undefined") // just to be sure mark got created { await Task.Delay(TimeSpan.FromSeconds(2)); } while (shouldRefresh) { if (selectedMark.type == "link") { GetRequest(Globals.serverUrl); } else { GetRequest(Globals.serverUrl); var file = selectedMark.type + ".html?id=" + selectedMark.id; WebViewControl.Navigate(new Uri(Globals.serverUrl + "/template/" + file)); } if (shouldRefresh) { await Task.Delay(TimeSpan.FromSeconds(10)); } } }
private async void WebView_DOMContentLoaded(WebView sender) { if (!Settings.HaveHardwareButtons) { await sender.InvokeScriptAsync("eval", new[] {HtmlHelper.MarginScript}); } await sender.InvokeScriptAsync("eval", new[] {HtmlHelper.FontColorScript}); }
private static void OnHTMLTextChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { Windows.UI.Xaml.Controls.WebView wv = obj as Windows.UI.Xaml.Controls.WebView; if (wv != null) { wv.NavigateToString((string)args.NewValue); } }
private void MyWebview_PermissionRequested(WebView sender, WebViewPermissionRequestedEventArgs args) { if (args.PermissionRequest.PermissionType == WebViewPermissionType.Media && args.PermissionRequest.Uri.Host == "web.whatsapp.com") { args.PermissionRequest.Allow(); } }
private Windows.UI.Xaml.Controls.WebView CreateWebView() { var wv = new Windows.UI.Xaml.Controls.WebView(WebViewExecutionMode.SeparateProcess); wv.Settings.IsJavaScriptEnabled = true; WireUpWebViewDiagnostics(wv); return(wv); }
public LiveHotmailDownloadController(AccountD acc, AccountDownloadListener notify) { browser = new WebView(); Init(acc, notify); currentLookup = 1; SetupWebBrowser(); }
private void wvMain_DOMContentLoaded(Windows.UI.Xaml.Controls.WebView sender, WebViewDOMContentLoadedEventArgs args) { dtMaxLoadTime.Stop(); SendMessage?.Invoke(null, new ContentViewEventArgs() { Type = "DOMContentLoaded", Uri = args.Uri }); }
private void wvMain_ContentLoading(Windows.UI.Xaml.Controls.WebView sender, WebViewContentLoadingEventArgs args) { dtMaxLoadTime.Start(); SendMessage?.Invoke(null, new ContentViewEventArgs() { Type = "ContentLoading", Uri = args.Uri }); }
private void wvMain_NewWindowRequested(Windows.UI.Xaml.Controls.WebView sender, WebViewNewWindowRequestedEventArgs args) { SendMessage?.Invoke(null, new ContentViewEventArgs() { Type = "NewWindowRequested", Uri = args.Uri }); args.Handled = true; }
public static void SetHtmlSource(WebView view, string value) { if (null == view) { throw new ArgumentNullException("view"); } view.SetValue(HtmlSourceProperty, value); }
public static string GetHtmlSource(WebView view) { if (null == view) { throw new ArgumentNullException("view"); } return (string)view.GetValue(HtmlSourceProperty); }
/// <summary> /// Set the /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void LoginWebView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args) { if (args.Uri.ToString().StartsWith(String.Format("{0}oauth/authorize/",coinbase["url"]))) //This passes after the user has signed in, and the web view is navigated to JSON for the app to use. { string authCode = args.Uri.ToString().Split('/').Last(); Login(authCode); //Use the Authorization Code to grab an access key, and set up the user's wallet. } }
private async void myWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { string pagecontent = await myWebView.InvokeScriptAsync("eval", new string[] { "document.documentElement.innerHTML;" }); myWebView.Visibility = Visibility.Collapsed; //Debug.WriteLine(pagecontent); refreshUI(pagecontent); await library.writeFile("artist" + artist.sublink, pagecontent); }
private void contentView_ContentLoading(WebView sender, WebViewContentLoadingEventArgs args) { var ds = DataContext as ItemViewModel; if (ds != null) { ds.IsPrintEnable = false; } }
private async void NavigationCompleteB(Windows.UI.Xaml.Controls.WebView webView, WebViewNavigationCompletedEventArgs args) { IsMainPageChild(webView); using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream()) { System.Diagnostics.Debug.WriteLine("B webView.Size=[" + webView.Width + "," + webView.Height + "] IsOnMainThread=[" + P42.Utils.Environment.IsOnMainThread + "]"); try { //await Task.Delay(2000); await webView.CapturePreviewToStreamAsync(ms); var decoder = await BitmapDecoder.CreateAsync(ms); var transform = new BitmapTransform { ScaledHeight = (uint)decoder.PixelHeight, ScaledWidth = (uint)decoder.PixelWidth }; var pixelData = await decoder.GetPixelDataAsync( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.DoNotColorManage); var bytes = pixelData.DetachPixelData(); var piclib = Windows.Storage.ApplicationData.Current.TemporaryFolder; var fileName = (string)webView.GetValue(PngFileNameProperty) + ".png"; var file = await piclib.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName); using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)decoder.PixelWidth, (uint)decoder.PixelHeight, 0, 0, bytes); await encoder.FlushAsync(); } var onComplete = (TaskCompletionSource <ToFileResult>)webView.GetValue(TaskCompletionSourceProperty); System.Diagnostics.Debug.WriteLine(GetType() + "." + P42.Utils.ReflectionExtensions.CallerMemberName() + ": Complete[" + file.Path + "]"); onComplete?.SetResult(new ToFileResult(false, file.Path)); } catch (Exception e) { var onComplete = (TaskCompletionSource <ToFileResult>)webView.GetValue(TaskCompletionSourceProperty); onComplete?.SetResult(new ToFileResult(true, e.InnerException?.Message ?? e.Message)); } } }
private void uiWebBrowser_NavigationCompleted(Windows.UI.Xaml.Controls.WebView sender, Windows.UI.Xaml.Controls.WebViewNavigationCompletedEventArgs args) { count++; //if (e.Uri.ToString().StartsWith("http://") // && e.Uri.ToString().Contains(DropboxManager.DROPBOX_AUTH_URI)) if (count == 3) { this.Popup.IsOpen = false; //await uiWebBrowser.ClearCookiesAsync(); } }
public void Load() { if (_webView == null) { _webView = CreateWebView(); _webView.AddWebAllowedObject(_webApp.GetType().Name, _webApp); _webView.Source = _sourceUri; Content = _webView; } }
bool IsMainPageChild(Windows.UI.Xaml.Controls.WebView webView) { var currentPage = Forms9Patch.PageExtensions.FindCurrentPage(Xamarin.Forms.Application.Current?.MainPage); var rootPageRenderer = (Xamarin.Forms.Platform.UWP.PageRenderer)Platform.GetRenderer(currentPage); var result = rootPageRenderer.Children.Contains(webView); System.Diagnostics.Debug.WriteLine("IsMainPageChild : [" + result + "] WebView.Parent=[" + webView.Parent + "]"); return(result); }
public void Unload() { Content = null; UnwireWebViewDiagnostics(_webView); if (_webView != null) { _webView = null; } GC.Collect(); }
public override async Task Init() { _webView = new WebView { Name = "PrintWebView" + (instanceCount++).ToString("D3"), DefaultBackgroundColor = Windows.UI.Colors.White, Visibility = Visibility.Visible, }; RootPanel.Children.Insert(0, _webView); PrintContent = _webView; _webView.NavigationCompleted += _webView_NavigationCompleted;; if (_sourceWebView != null) { var contentSize = await _sourceWebView.WebViewContentSizeAsync(); _webView.Width = contentSize.Width; _webView.Height = contentSize.Height; Html = await _sourceWebView.GetHtml(); _webView.NavigateToString(Html); } else if (!string.IsNullOrWhiteSpace(Html)) { _webView.Width = 96 * 8; _webView.Height = 96 * 10.5; var baseTag = $"<base href=\"{BaseUrl}\"></base>"; string htmlWithBaseTag; var internalWebView = new Windows.UI.Xaml.Controls.WebView(); internalWebView.NavigationCompleted += async(sender, args) => { var script = BaseInsertionScript.Replace("baseTag", baseTag); await sender.InvokeScriptAsync("eval", new[] { script }); htmlWithBaseTag = await sender.InvokeScriptAsync("eval", new[] { "document.documentElement.outerHTML;" }); _webView.NavigateToString(!string.IsNullOrEmpty(htmlWithBaseTag) ? htmlWithBaseTag : Html); }; internalWebView.NavigateToString(Html); } else if (!string.IsNullOrWhiteSpace(Url)) { _webView.Width = 96 * 8; _webView.Height = 96 * 10.5; Uri uri = new Uri(Url, UriKind.RelativeOrAbsolute); if (!uri.IsAbsoluteUri) { uri = new Uri(LocalScheme + Url, UriKind.RelativeOrAbsolute); } _webView.Source = uri; } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.WebView> e) { base.OnElementChanged(e); if (e.OldElement != null || e.NewElement == null || Control == null) { return; } Windows.UI.Xaml.Controls.WebView newWebView = new Windows.UI.Xaml.Controls.WebView(WebViewExecutionMode.SeparateProcess); newWebView.Source = Control.Source; SetNativeControl(webView); }
async Task <WebViewBrush> GetWebViewBrush(Windows.UI.Xaml.Controls.WebView webView) { // resize width to content var _OriginalWidth = webView.Width; var _WidthString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollWidth.toString()" }); int _ContentWidth; if (!int.TryParse(_WidthString, out _ContentWidth)) { throw new Exception(string.Format("failure/width:{0}", _WidthString)); } webView.Width = _ContentWidth; // resize height to content var _OriginalHeight = webView.Height; var _HeightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" }); int _ContentHeight; if (!int.TryParse(_HeightString, out _ContentHeight)) { throw new Exception(string.Format("failure/height:{0}", _HeightString)); } webView.Height = _ContentHeight; // create brush var _OriginalVisibilty = webView.Visibility; webView.Visibility = Windows.UI.Xaml.Visibility.Visible; var _Brush = new WebViewBrush { Stretch = Stretch.Uniform, SourceName = webView.Name }; _Brush.Redraw(); // webView.Width = _OriginalWidth; //webView.Height = _OriginalHeight; webView.Visibility = _OriginalVisibilty; return(_Brush); }
/// <summary> /// ナビゲーション完了時に発生するイベント /// </summary> /// <param name="sender">WebView</param> /// <param name="e">WebViewナビゲーション完了時イベントのデータ</param> public async void OnNavigationCompletedWebView(Windows.UI.Xaml.Controls.WebView sender, WebViewNavigationCompletedEventArgs e) { textUri.Text = GetCurUri(); if (!e.IsSuccess) { string strErrMsg = e.WebErrorStatus.ToString(); int nErrCode = (int)e.WebErrorStatus; string strMsg = string.Format("{0} ( {1} )", strErrMsg, nErrCode); await new Windows.UI.Popups.MessageDialog(strMsg).ShowAsync(); } return; }
public void InitializeComponent() { if (_contentLoaded) { return; } _contentLoaded = true; Application.LoadComponent(this, new System.Uri("ms-appx:///MainPage.xaml"), Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application); txtRssUrl = (Windows.UI.Xaml.Controls.TextBox) this.FindName("txtRssUrl"); TitleText = (Windows.UI.Xaml.Controls.TextBlock) this.FindName("TitleText"); ItemListView = (Windows.UI.Xaml.Controls.ListView) this.FindName("ItemListView"); PostTitleText = (Windows.UI.Xaml.Controls.TextBlock) this.FindName("PostTitleText"); ContentView = (Windows.UI.Xaml.Controls.WebView) this.FindName("ContentView"); }
private async void NavigationCompleteB(Windows.UI.Xaml.Controls.WebView webView, WebViewNavigationCompletedEventArgs args) { System.Diagnostics.Debug.WriteLine("B webView.Size=[" + webView.Width + "," + webView.Height + "]"); using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream()) { await webView.CapturePreviewToStreamAsync(ms); var decoder = await BitmapDecoder.CreateAsync(ms); var transform = new BitmapTransform { ScaledHeight = (uint)decoder.PixelHeight, ScaledWidth = (uint)decoder.PixelWidth }; var pixelData = await decoder.GetPixelDataAsync( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.DoNotColorManage); var bytes = pixelData.DetachPixelData(); var piclib = Windows.Storage.ApplicationData.Current.TemporaryFolder; var fileName = (string)webView.GetValue(PngFileNameProperty) + ".png"; var file = await piclib.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName); using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)decoder.PixelWidth, (uint)decoder.PixelHeight, 0, 0, bytes); await encoder.FlushAsync(); } var onComplete = (Action <string>)webView.GetValue(OnCompleteProperty); onComplete?.Invoke(file.Path); } }
private void JellyfinWebView_ContainsFullScreenElementChanged(Windows.UI.Xaml.Controls.WebView sender, object args) { ApplicationView appView = ApplicationView.GetForCurrentView(); if (sender.ContainsFullScreenElement) { appView.TryEnterFullScreenMode(); return; } if (!appView.IsFullScreenMode) { return; } appView.ExitFullScreenMode(); }
private async void NavigationCompleteA(Windows.UI.Xaml.Controls.WebView webView, WebViewNavigationCompletedEventArgs args) { var contentSize = await webView.WebViewContentSizeAsync(); webView.NavigationCompleted -= NavigationCompleteA; System.Diagnostics.Debug.WriteLine("A contentSize=[" + contentSize + "]"); System.Diagnostics.Debug.WriteLine("A webView.Size=[" + webView.Width + "," + webView.Height + "]"); webView.Width = contentSize.Width; webView.Height = contentSize.Height; webView.UpdateLayout(); webView.NavigationCompleted += NavigationCompleteB; var html = (string)webView.GetValue(HtmlStringProperty); webView.NavigateToString(html); }
#pragma warning disable CS1998 public void ToPng(TaskCompletionSource <ToFileResult> taskCompletionSource, string html, string fileName, int width) { Device.BeginInvokeOnMainThread(async() => { //var size = new Size(5, 11); //if (Platform.GetRenderer(popup.WebView) is Xamarin.Forms.Platform.UWP.WebViewRenderer renderer) { //var webView = renderer.Control; _webView = new Windows.UI.Xaml.Controls.WebView(WebViewExecutionMode.SameThread) { Name = "PrintWebView" + (instanceCount++).ToString("D3"), DefaultBackgroundColor = Windows.UI.Colors.White, Visibility = Visibility.Visible, }; _webView.Settings.IsJavaScriptEnabled = true; _webView.Settings.IsIndexedDBEnabled = true; PrintHelper.RootPanel.Children.Insert(0, _webView); var webView = _webView; webView.DefaultBackgroundColor = Windows.UI.Colors.White; webView.Width = width; webView.Height = 10; // (size.Height - 0.5) * 72, webView.Visibility = Visibility.Visible; webView.SetValue(PngFileNameProperty, fileName); webView.SetValue(TaskCompletionSourceProperty, taskCompletionSource); webView.SetValue(HtmlStringProperty, html); webView.SetValue(PngWidthProperty, width); webView.Width = width; webView.NavigationCompleted += NavigationCompleteA; webView.NavigationFailed += WebView_NavigationFailed; webView.NavigateToString(html); await taskCompletionSource.Task; PrintHelper.RootPanel.Children.Remove(webView); } }); }
private void NavigationCompleteC(Windows.UI.Xaml.Controls.WebView webView, WebViewNavigationCompletedEventArgs args) { webView.NavigationCompleted -= NavigationCompleteC; if (webView.GetValue(TaskCompletionSourceProperty) is TaskCompletionSource <ToFileResult> onComplete) { if (webView.GetValue(ToFileResultProperty) is ToFileResult result) { System.Diagnostics.Debug.WriteLine(GetType() + "." + P42.Utils.ReflectionExtensions.CallerMemberName() + ": Complete[" + result.Result + "]"); onComplete.SetResult(result); } else { onComplete.SetResult(new ToFileResult(true, "unknown error generating PNG.")); } } else { throw new Exception("Failed to get TaskCompletionSource for UWP WebView.ToPngAsync"); } }
private void WebView_NavigationStarting(Windows.UI.Xaml.Controls.WebView sender, WebViewNavigationStartingEventArgs args) { //Debug.Write("args.Uri => " + args.Uri); sender.AddWebAllowedObject("JWChinese", comm); try { // if loading pages from database, then uri will be null // if pinyin view if (args.Uri == null && view.IsChinese) { busyIndicator = BusyIndicator.Start(" "); } } catch (Exception ex) { Debug.WriteLine("busyIndicator ERROR!! => " + ex.Message); } }