private bool OnWebViewKeyEvent(object source, View.KeyEventArgs args) { bool result = false; Log.Info("WebView", $"----web view key is {args.Key.KeyPressedName}, state is {args.Key.State}-------"); if (args.Key.State == Key.StateType.Up) { if (args.Key.KeyPressedName == "XF86RaiseChannel") { Log.Info("WebView", $"old url is {simpleWebView.Url}."); if (index != 0) { simpleWebView.Url = websites[--index].ToLowerInvariant(); } else { simpleWebView.Url = websites[WEBSITES_COUNT - 1].ToLowerInvariant(); } result = true; Log.Info("WebView", $"new url is {simpleWebView.Url}."); } else if (args.Key.KeyPressedName == "XF86LowerChannel") { Log.Info("WebView", $"old url is {simpleWebView.Url}."); if (index != WEBSITES_COUNT - 1) { simpleWebView.Url = websites[++index].ToLowerInvariant(); } else { simpleWebView.Url = websites[0].ToLowerInvariant(); } result = true; Log.Info("WebView", $"new url is {simpleWebView.Url}."); } else if (args.Key.KeyPressedName == "XF86Back") { Log.Info("WebView", $"whether webview can go back or not: {simpleWebView.CanGoBack()}."); if (simpleWebView.CanGoBack()) { simpleWebView.GoBack(); } result = true; } else if (args.Key.KeyPressedName == "XF86Red") { FocusManager.Instance.SetCurrentFocusView(addressBar); result = true; } else if (args.Key.KeyPressedName == "XF86Blue") { blueKeyPressedCount++; if (blueKeyPressedCount % 6 == 0) { simpleWebView.Position = new Position(0, ADDRESSBAR_HEIGHT); simpleWebView.Orientation = new Rotation(new Radian(new Degree(60 * blueKeyPressedCount)), Vector3.ZAxis); blueKeyPressedCount = 0; } else { simpleWebView.Orientation = new Rotation(new Radian(new Degree(60 * blueKeyPressedCount)), Vector3.ZAxis); } result = true; } else if (args.Key.KeyPressedName == "XF86Yellow") { yellowKeyPressedCount++; int wdistance = (SCREEN_WIDTH - MIN_WEBVIEW_WIDTH) / 5; int hdistance = (SCREEN_HEIGHT - MIN_WEBVIEW_HEIGHT - ADDRESSBAR_HEIGHT) / 5; simpleWebView.Position = new Position((SCREEN_WIDTH - MIN_WEBVIEW_WIDTH - yellowKeyPressedCount * wdistance) / 2, ADDRESSBAR_HEIGHT); simpleWebView.Size = new Size(MIN_WEBVIEW_WIDTH + yellowKeyPressedCount * wdistance, MIN_WEBVIEW_HEIGHT + hdistance * yellowKeyPressedCount); if (yellowKeyPressedCount % 5 == 0) { yellowKeyPressedCount = 0; } result = true; } else if (args.Key.KeyPressedName == "XF86Green") { Log.Info("WebView", $"key XF86Green is pressed."); //greenKeyPressedCount++; if (greenKeyPressedCount % 2 == 0) { // webview apis Log.Info("WebView", $"web page title is {simpleWebView.Title}"); //faviconView = simpleWebView.Favicon; //if (faviconView != null) //{ // faviconView.Position = new Position(500, 100); // GetDefaultWindow().Add(faviconView); // messageTimer.Start(); //} simpleWebView.ContentBackgroundColor = new Color(1.0f, 0.0f, 0.0f, 1.0f); Log.Info("WebView", $"web page ContentBackgroundColor is {simpleWebView.ContentBackgroundColor}"); simpleWebView.TilesClearedWhenHidden = true; Log.Info("WebView", $"web page TilesClearedWhenHidden is {simpleWebView.TilesClearedWhenHidden}"); simpleWebView.TileCoverAreaMultiplier = 2.0f; Log.Info("WebView", $"web page TileCoverAreaMultiplier is {simpleWebView.TileCoverAreaMultiplier}"); simpleWebView.CursorEnabledByClient = true; Log.Info("WebView", $"web page CursorEnabledByClient is {simpleWebView.CursorEnabledByClient}"); Log.Info("WebView", $"web page SelectedText is {simpleWebView.SelectedText}"); simpleWebView.PageZoomFactor = 2.0f; Log.Info("WebView", $"web page PageZoomFactor is {simpleWebView.PageZoomFactor}"); simpleWebView.TextZoomFactor = 2.0f; Log.Info("WebView", $"web page TextZoomFactor is {simpleWebView.TextZoomFactor}"); Log.Info("WebView", $"web page LoadProgressPercentage is {simpleWebView.LoadProgressPercentage}"); simpleWebView.VideoHoleEnabled = true; Log.Info("WebView", $"web page VideoHoleEnabled is {simpleWebView.VideoHoleEnabled}"); simpleWebView.ActivateAccessibility(true); simpleWebView.AddCustomHeader("test", "value"); simpleWebView.AddDynamicCertificatePath("", ""); simpleWebView.AddJavaScriptMessageHandler("", OnJavaScriptMessageReceived); simpleWebView.CanGoBack(); simpleWebView.CanGoForward(); simpleWebView.CheckVideoPlayingAsynchronously(OnVideoPlaying); simpleWebView.ClearAllTilesResources(); simpleWebView.ClearHistory(); simpleWebView.EvaluateJavaScript("document.body.style.backgroundColor='yellow';"); Log.Info("WebView", $"web view, ScaleFactor is {simpleWebView.GetScaleFactor()}"); Rectangle viewArea = new Rectangle(0, 0, 20, 20); //ImageView shotView = simpleWebView.GetScreenshot(viewArea, 1.0f); //if (shotView != null) //{ // shotView.Position = new Position(500, 200); // GetDefaultWindow().Add(shotView); //} bool succeeded = simpleWebView.GetScreenshotAsynchronously(viewArea, 1.0f, OnScreenshotAcquired); Log.Info("WebView", $"GetScreenshotAsynchronously, {succeeded}"); simpleWebView.GoBack(); Log.Info("WebView", $"web view, here"); simpleWebView.GoForward(); Log.Info("WebView", $"web view, here"); simpleWebView.HighlightText("test", WebView.FindOption.CaseInsensitive, 2); Log.Info("WebView", $"web view, here"); WebHitTestResult test = null;//simpleWebView.HitTest(100, 100, WebView.HitTestMode.Default); if (test != null) { Log.Info("WebView", $"WebHitTestResult, TestResultContext: {test.TestResultContext}"); Log.Info("WebView", $"WebHitTestResult, LinkUrl: {test.LinkUrl}"); Log.Info("WebView", $"WebHitTestResult, LinkTitle: {test.LinkTitle}"); Log.Info("WebView", $"WebHitTestResult, LinkLabel: {test.LinkLabel}"); Log.Info("WebView", $"WebHitTestResult, ImageUrl: {test.ImageUrl}"); Log.Info("WebView", $"WebHitTestResult, MediaUrl: {test.MediaUrl}"); Log.Info("WebView", $"WebHitTestResult, TagName: {test.TagName}"); Log.Info("WebView", $"WebHitTestResult, NodeValue: {test.NodeValue}"); if (test.Attributes != null) { Log.Info("WebView", $"WebHitTestResult, Attributes: {test.Attributes}"); } Log.Info("WebView", $"WebHitTestResult, NodeValue: {test.ImageFileNameExtension}"); ImageView imageView = test.Image; if (imageView != null) { imageView.Position = new Position(500, 500); GetDefaultWindow().Add(imageView); } } succeeded = simpleWebView.HitTestAsynchronously(100, 100, WebView.HitTestMode.Default, OnHitTestFinished); Log.Info("WebView", $"HitTestAsynchronously, {succeeded}"); simpleWebView.RegisterGeolocationPermissionCallback(OnGeolocationPermission); Log.Info("WebView", $"web view, here"); simpleWebView.RegisterJavaScriptAlertCallback(OnJavaScriptAlert); simpleWebView.RegisterJavaScriptConfirmCallback(OnJavaScriptConfirm); simpleWebView.RegisterJavaScriptPromptCallback(OnJavaScriptPrompt); Log.Info("WebView", $"web view, here"); simpleWebView.Reload(); Log.Info("WebView", $"web view, here"); simpleWebView.ReloadWithoutCache(); Log.Info("WebView", $"web view, here"); simpleWebView.RemoveCustomHeader("test"); Log.Info("WebView", $"web view, here"); simpleWebView.Suspend(); simpleWebView.SuspendNetworkLoading(); Log.Info("WebView", $"web view, here"); simpleWebView.Resume(); simpleWebView.ResumeNetworkLoading(); Log.Info("WebView", $"web view, here"); //simpleWebView.LoadContents(); //simpleWebView.LoadHtmlStringOverrideCurrentEntry(); simpleWebView.LoadHtmlString("<Html><Head><title>Example</title></Head><Body><b>[This text is Bold......]</b></Body></Html>"); simpleWebView.ScrollPosition = new Position(0, 200); simpleWebView.ScrollBy(0, 50); simpleWebView.ScrollEdgeBy(0, 50); Log.Info("WebView", $"scroll position is ({simpleWebView.ScrollPosition.X}, {simpleWebView.ScrollPosition.Y})."); Log.Info("WebView", $"scroll size is ({simpleWebView.ScrollSize.Width}, {simpleWebView.ScrollSize.Height})."); Log.Info("WebView", $"content size is ({simpleWebView.ContentSize.Width}, {simpleWebView.ContentSize.Height})."); //simpleWebView.StartInspectorServer(8080); //simpleWebView.StopInspectorServer(); //simpleWebView.StopLoading(); // websettings apis simpleWebView.Settings.LinkMagnifierEnabled = true; Log.Info("WebView", $"web settings LinkMagnifierEnabled is {simpleWebView.Settings.LinkMagnifierEnabled}"); simpleWebView.Settings.ViewportMetaTag = true; Log.Info("WebView", $"web settings ViewportMetaTag is {simpleWebView.Settings.ViewportMetaTag}"); simpleWebView.Settings.DefaultTextEncodingName = "utf-8"; Log.Info("WebView", $"web settings DefaultTextEncodingName is {simpleWebView.Settings.DefaultTextEncodingName}"); simpleWebView.Settings.AutomaticImageLoadingAllowed = true; Log.Info("WebView", $"web settings AutomaticImageLoadingAllowed is {simpleWebView.Settings.AutomaticImageLoadingAllowed}"); simpleWebView.Settings.ScriptsOpenWindowsAllowed = true; Log.Info("WebView", $"web settings ScriptsOpenWindowsAllowed is {simpleWebView.Settings.ScriptsOpenWindowsAllowed}"); simpleWebView.Settings.ImePanelEnabled = true; Log.Info("WebView", $"web settings ImePanelEnabled is {simpleWebView.Settings.ImePanelEnabled}"); simpleWebView.Settings.ClipboardEnabled = true; Log.Info("WebView", $"web settings ClipboardEnabled is {simpleWebView.Settings.ClipboardEnabled}"); simpleWebView.Settings.ArrowScrollEnabled = true; Log.Info("WebView", $"web settings ArrowScrollEnabled is {simpleWebView.Settings.ArrowScrollEnabled}"); simpleWebView.Settings.TextAutosizingEnabled = true; Log.Info("WebView", $"web settings TextAutosizingEnabled is {simpleWebView.Settings.TextAutosizingEnabled}"); simpleWebView.Settings.TextSelectionEnabled = true; Log.Info("WebView", $"web settings TextSelectionEnabled is {simpleWebView.Settings.TextSelectionEnabled}"); simpleWebView.Settings.FormCandidateDataEnabled = true; Log.Info("WebView", $"web settings FormCandidateDataEnabled is {simpleWebView.Settings.FormCandidateDataEnabled}"); simpleWebView.Settings.AutofillPasswordFormEnabled = true; Log.Info("WebView", $"web settings AutofillPasswordFormEnabled is {simpleWebView.Settings.AutofillPasswordFormEnabled}"); simpleWebView.Settings.KeypadWithoutUserActionUsed = true; Log.Info("WebView", $"web settings KeypadWithoutUserActionUsed is {simpleWebView.Settings.KeypadWithoutUserActionUsed}"); simpleWebView.Settings.ZoomForced = true; Log.Info("WebView", $"web settings ZoomForced is {simpleWebView.Settings.ZoomForced}"); simpleWebView.Settings.TextZoomEnabled = true; Log.Info("WebView", $"web settings TextZoomEnabled is {simpleWebView.Settings.TextZoomEnabled}"); simpleWebView.Settings.PluginsEnabled = true; Log.Info("WebView", $"web settings PluginsEnabled is {simpleWebView.Settings.PluginsEnabled}"); simpleWebView.Settings.AutoFittingEnabled = true; Log.Info("WebView", $"web settings AutoFittingEnabled is {simpleWebView.Settings.AutoFittingEnabled}"); simpleWebView.Settings.JavaScriptEnabled = true; Log.Info("WebView", $"web settings JavaScriptEnabled is {simpleWebView.Settings.JavaScriptEnabled}"); simpleWebView.Settings.FileAccessFromExternalUrlAllowed = true; Log.Info("WebView", $"web settings FileAccessFromExternalUrlAllowed is {simpleWebView.Settings.FileAccessFromExternalUrlAllowed}"); simpleWebView.Settings.ScrollbarThumbFocusNotificationsUsed = true; Log.Info("WebView", $"web settings ScrollbarThumbFocusNotificationsUsed is {simpleWebView.Settings.ScrollbarThumbFocusNotificationsUsed}"); simpleWebView.Settings.DoNotTrackEnabled = true; Log.Info("WebView", $"web settings DoNotTrackEnabled is {simpleWebView.Settings.DoNotTrackEnabled}"); simpleWebView.Settings.CacheBuilderEnabled = true; Log.Info("WebView", $"web settings CacheBuilderEnabled is {simpleWebView.Settings.CacheBuilderEnabled}"); simpleWebView.Settings.WebSecurityEnabled = true; Log.Info("WebView", $"web settings WebSecurityEnabled is {simpleWebView.Settings.WebSecurityEnabled}"); simpleWebView.Settings.DefaultFontSize = 20; Log.Info("WebView", $"web settings DefaultFontSize is {simpleWebView.Settings.DefaultFontSize}"); simpleWebView.Settings.SpatialNavigationEnabled = true; Log.Info("WebView", $"web settings SpatialNavigationEnabled is {simpleWebView.Settings.SpatialNavigationEnabled}"); simpleWebView.Settings.MixedContentsAllowed = true; Log.Info("WebView", $"web settings MixedContentsAllowed is {simpleWebView.Settings.MixedContentsAllowed}"); simpleWebView.Settings.PrivateBrowsingEnabled = true; Log.Info("WebView", $"web settings PrivateBrowsingEnabled is {simpleWebView.Settings.PrivateBrowsingEnabled}"); simpleWebView.Settings.EnableExtraFeature("feature", true); Log.Info("WebView", $"web settings EnableExtraFeature is {simpleWebView.Settings.IsExtraFeatureEnabled("feature")}"); // webcontext apis simpleWebView.Context.AppType = WebContext.ApplicationType.WebBrowser; Log.Info("WebView", $"web context, AppType: {simpleWebView.Context.AppType}"); simpleWebView.Context.AppVersion = "6.5"; Log.Info("WebView", $"web context, AppVersion: {simpleWebView.Context.AppVersion}"); simpleWebView.Context.AppId = "1.0id"; Log.Info("WebView", $"web context, AppId: {simpleWebView.Context.AppId}"); simpleWebView.Context.CacheEnabled = false; Log.Info("WebView", $"web context, CacheEnabled: {simpleWebView.Context.CacheEnabled}"); simpleWebView.Context.CertificateFilePath = "/root/share"; Log.Info("WebView", $"web context, CertificateFilePath: {simpleWebView.Context.CertificateFilePath}"); simpleWebView.Context.ProxyUrl = "https://127.0.0.1"; Log.Info("WebView", $"web context, ProxyUrl: {simpleWebView.Context.ProxyUrl}"); simpleWebView.Context.CacheModel = WebContext.CacheModelType.DocumentBrowser; Log.Info("WebView", $"web context, cache model is {simpleWebView.Context.CacheModel}"); Log.Info("WebView", $"web context, ProxyBypassRule: {simpleWebView.Context.ProxyBypassRule}"); simpleWebView.Context.DefaultZoomFactor = 2.0f; Log.Info("WebView", $"web context, DefaultZoomFactor: {simpleWebView.Context.DefaultZoomFactor}"); simpleWebView.Context.ClearCache(); simpleWebView.Context.DeleteAllApplicationCache(); simpleWebView.Context.DeleteAllFormCandidateData(); simpleWebView.Context.DeleteAllFormPasswordData(); simpleWebView.Context.DeleteAllWebDatabase(); simpleWebView.Context.DeleteAllWebIndexedDatabase(); simpleWebView.Context.DeleteAllWebStorage(); simpleWebView.Context.DeleteLocalFileSystem(); simpleWebView.Context.FreeUnusedMemory(); Log.Info("WebView", $"web view, here"); simpleWebView.Context.GetFormPasswordList(OnPasswordDataListAcquired); Log.Info("WebView", $"web view, here"); simpleWebView.Context.GetWebDatabaseOrigins(OnSecurityOriginListAcquired); Log.Info("WebView", $"web view, here"); simpleWebView.Context.GetWebStorageOrigins(OnSecurityOriginListAcquired); Log.Info("WebView", $"web view, here"); simpleWebView.Context.RegisterDownloadStartedCallback(OnDownloadStarted); Log.Info("WebView", $"web view, here"); string[] mimes = { "txt" }; simpleWebView.Context.RegisterJsPluginMimeTypes(mimes); Log.Info("WebView", $"web view, here"); simpleWebView.Context.RegisterMimeOverriddenCallback(OnMimeOverridden); Log.Info("WebView", $"web view, here"); string[] schemes = { "test" }; simpleWebView.Context.RegisterUrlSchemesAsCorsEnabled(schemes); Log.Info("WebView", $"web view, here"); simpleWebView.Context.SetProxyBypassRule("test", ""); Log.Info("WebView", $"web context, ContextProxy: {simpleWebView.Context.ProxyUrl}"); simpleWebView.Context.TimeOffset = 8.0f; Log.Info("WebView", $"web context, TimeOffset: {simpleWebView.Context.TimeOffset}"); simpleWebView.Context.SetTimeZoneOffset(2.0f, 3.0f); simpleWebView.Context.SetDefaultProxyAuth("user", "password"); // webcookiemanager apis simpleWebView.CookieManager.CookieAcceptPolicy = WebCookieManager.CookieAcceptPolicyType.Never; Log.Info("WebView", $"web cookie manager accept policy is {simpleWebView.CookieManager.CookieAcceptPolicy}"); simpleWebView.CookieManager.ClearCookies(); simpleWebView.CookieManager.SetPersistentStorage("/root/share", WebCookieManager.CookiePersistentStorageType.SqlLite); simpleWebView.CookieManager.CookieChanged += OnCookieChanged; // webbackforwardlist apis Log.Info("WebView", $"web back forward list item count is {simpleWebView.BackForwardList.ItemCount}"); WebBackForwardListItem item = simpleWebView.BackForwardList.GetCurrentItem(); Log.Info("WebView", $"web back forward list, current item url is {item.Url}"); Log.Info("WebView", $"web back forward list, current item title is {item.Title}"); Log.Info("WebView", $"web back forward list, current item original url is {item.OriginalUrl}"); if (simpleWebView.BackForwardList.ItemCount > 0) { item = simpleWebView.BackForwardList.GetItemAtIndex(0); Log.Info("WebView", $"web back forward list, item0 url is {item.Url}"); Log.Info("WebView", $"web back forward list, item0 title is {item.Title}"); Log.Info("WebView", $"web back forward list, item0 original url is {item.OriginalUrl}"); WebBackForwardSubList subList = simpleWebView.BackForwardList.GetForwardItems(0); Log.Info("WebView", $"web back forward list, forward sub list ItemCount is {subList.ItemCount}"); subList = simpleWebView.BackForwardList.GetBackwardItems(0); Log.Info("WebView", $"web back forward list, backward sub list ItemCount is {subList.ItemCount}"); } } result = true; } } return(result); }