summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/app.vala26
-rw-r--r--core/tab.vala50
2 files changed, 76 insertions, 0 deletions
diff --git a/core/app.vala b/core/app.vala
index 188a6f55..a23ced7e 100644
--- a/core/app.vala
+++ b/core/app.vala
@@ -40,6 +40,32 @@ namespace Midori {
Gtk.Window.set_default_icon_name (Config.PROJECT_NAME);
var context = WebKit.WebContext.get_default ();
+ context.register_uri_scheme ("stock", (request) => {
+ string icon_name = request.get_path ().substring (1, -1);
+ int icon_size = 48;
+ Gtk.icon_size_lookup ((Gtk.IconSize)Gtk.IconSize.DIALOG, out icon_size, null);
+ try {
+ var icon = Gtk.IconTheme.get_default ().load_icon (icon_name, icon_size, Gtk.IconLookupFlags.FORCE_SYMBOLIC);
+ var output = new MemoryOutputStream (null, realloc, free);
+ icon.save_to_stream (output, "png");
+ output.close ();
+ uint8[] data = output.steal_data ();
+ data.length = (int)output.get_data_size ();
+ var stream = new MemoryInputStream.from_data (data, free);
+ request.finish (stream, -1, null);
+ } catch (Error error) {
+ critical ("Failed to load icon %s: %s", icon_name, error.message);
+ }
+ });
+ context.register_uri_scheme ("res", (request) => {
+ try {
+ var stream = resources_open_stream (request.get_path (),
+ ResourceLookupFlags.NONE);
+ request.finish (stream, -1, null);
+ } catch (Error error) {
+ critical ("Failed to load resource %s: %s", request.get_uri (), error.message);
+ }
+ });
string config = Path.build_path (Path.DIR_SEPARATOR_S,
Environment.get_user_config_dir (), Environment.get_prgname ());
DirUtils.create_with_parents (config, 0700);
diff --git a/core/tab.vala b/core/tab.vala
index 7d19655e..3a177711 100644
--- a/core/tab.vala
+++ b/core/tab.vala
@@ -114,6 +114,56 @@ namespace Midori {
}
}
+ public override bool web_process_crashed () {
+ return display_error ("face-sad", _("Oops - %s").printf (uri), _("Something went wrong with '%s'.").printf (uri));
+ }
+
+ public override bool load_failed (WebKit.LoadEvent load_event, string uri, Error load_error) {
+ var monitor = NetworkMonitor.get_default ();
+ string hostname = new Soup.URI (uri).host;
+ string? title = null;
+ string? message = null;
+ if (!monitor.network_available) {
+ title = _("You are not connected to a network");
+ message = _("Your computer must be connected to a network to reach “%s”. " +
+ "Connect to a wireless access point or attach a network cable and try again.").printf (hostname);
+ } else {
+ try {
+ monitor.can_reach (NetworkAddress.parse_uri (Config.PROJECT_WEBSITE, 80));
+ title = _("Midori can't find the page you're looking for");
+ message = _("The page located at “%s” cannot be found. " +
+ "Check the web address for misspelled words and try again.").printf (hostname);
+ } catch (Error error) {
+ title = _("You are not connected to the Internet");
+ message = _("Your computer appears to be connected to a network, but can't reach “%s”. " +
+ "Check your network settings and try again.").printf (hostname);
+ }
+ }
+ display_uri = uri;
+ return display_error ("network-error", title, message, load_error.message);
+ }
+
+ bool display_error (string icon_name, string title, string message, string? description=null) {
+ try {
+ string stylesheet = (string)resources_lookup_data ("/data/about.css",
+ ResourceLookupFlags.NONE).get_data ();
+ string html = ((string)resources_lookup_data ("/data/error.html",
+ ResourceLookupFlags.NONE).get_data ())
+ .replace ("{stylesheet}", stylesheet)
+ .replace ("{icon}", icon_name)
+ .replace ("{title}", title)
+ .replace ("{message}", message)
+ .replace ("{description}", description ?? "")
+ .replace ("{tryagain}", _("Try Again"))
+ .replace ("{uri}", display_uri);
+ load_alternate_html (html, display_uri, display_uri);
+ return true;
+ } catch (Error error) {
+ critical ("Failed to display error: %s", error.message);
+ }
+ return false;
+ }
+
public override void mouse_target_changed (WebKit.HitTestResult result, uint modifiers) {
link_uri = result.link_uri;
}