/// <summary> /// Executes when loading error is occured. /// /// Basically, show an html page for each error. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WebBrowser_LoadError(object sender, CefSharp.LoadErrorEventArgs e) { // Save the original url string originalUrl = null; this.NavigationBar.Dispatcher.Invoke(() => originalUrl = this.NavigationBar.urlTextBox.Text); // In case error aborted by CEF, do nothing if (e.ErrorCode == CefSharp.CefErrorCode.Aborted) { return; } // Handle loading errors string errorPagePath = string.Empty; if (OrganicUtility.IsConnected() == false) { // In case of no internet errorPagePath = "organic://error/no_internet"; } else if (e.ErrorCode == CefSharp.CefErrorCode.NameNotResolved) { // In case of domain could not be resolved errorPagePath = "organic://error/could_not_resolve"; } else { // Default loading error page System.Console.WriteLine(e.ErrorText); errorPagePath = "organic://error/general"; } // Handle more loading errors here // Load the error page this.WebBrowser.Dispatcher.Invoke(() => this.WebBrowser.Address = OrganicUtility.GetLocalPageActualUrl(errorPagePath)); // Restore the url this.NavigationBar.Dispatcher.Invoke(() => this.NavigationBar.urlTextBox.Text = originalUrl); }
/// <summary> /// Executes when a key in the keyboard is up in the URL text box /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void UrlTextBox_KeyUp(object sender, KeyEventArgs eventArgs) { if (eventArgs.Key == Key.Enter) { // In case the given url is a valid address if (OrganicUtility.IsValidUrl(this.NavigationBar.Url)) { this.WebBrowser.Address = this.NavigationBar.Url; } // In case the given url is an organic url (such as organic://history) else if (OrganicUtility.IsOrganicUrl(this.NavigationBar.Url)) { this.WebBrowser.Address = OrganicUtility.GetLocalPageActualUrl(this.NavigationBar.Url); } // In case the given url is NOT actually a url else { this.WebBrowser.Address = "https://www.google.com/search?q=" + HttpUtility.UrlEncode(this.NavigationBar.Url); } } }