From: Christian Dywan Date: Thu, 5 May 2011 19:49:51 +0000 (+0200) Subject: Implement support for geo URI RFC 5870 X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=414997b236ada8e363f132e6e276a5f41e4609c5;p=midori Implement support for geo URI RFC 5870 --- diff --git a/data/midori.desktop.in b/data/midori.desktop.in index 403ac3ce..f5e2852d 100644 --- a/data/midori.desktop.in +++ b/data/midori.desktop.in @@ -5,7 +5,7 @@ _Name=Midori _GenericName=Web Browser _Comment=Lightweight web browser Categories=GTK;Network;WebBrowser; -MimeType=text/html;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https; +MimeType=text/html;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/geo; Exec=midori %u Icon=midori Terminal=false diff --git a/midori/midori-view.c b/midori/midori-view.c index 96cd4e29..5777a0a7 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -983,7 +983,14 @@ midori_view_web_view_navigation_decision_cb (WebKitWebView* web_view JSContextRef js_context; gchar* result; const gchar* uri = webkit_network_request_get_uri (request); - if (g_str_has_prefix (uri, "mailto:") || sokoke_external_uri (uri)) + if (g_str_has_prefix (uri, "geo:")) + { + gchar* new_uri = sokoke_magic_uri (uri); + midori_view_set_uri (view, new_uri); + g_free (new_uri); + return TRUE; + } + else if (g_str_has_prefix (uri, "mailto:") || sokoke_external_uri (uri)) { if (sokoke_show_uri (gtk_widget_get_screen (GTK_WIDGET (web_view)), uri, GDK_CURRENT_TIME, NULL)) diff --git a/midori/sokoke.c b/midori/sokoke.c index 39b0a4d9..4df529a0 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -812,6 +812,7 @@ sokoke_external_uri (const gchar* uri) if (!uri || !strncmp (uri, "http", 4) || !strncmp (uri, "file", 4) + || !strncmp (uri, "geo", 3) || !strncmp (uri, "about:", 6)) return FALSE; @@ -850,6 +851,33 @@ sokoke_magic_uri (const gchar* uri) /* Add file:// if we have a local path */ if (g_path_is_absolute (uri)) return g_strconcat ("file://", uri, NULL); + /* Parse geo URI geo:48.202778,16.368472;crs=wgs84;u=40 as a location */ + if (!strncmp (uri, "geo:", 4)) + { + gchar* comma; + gchar* semicolon; + gchar* latitude; + gchar* longitude; + gchar* geo; + + comma = strchr (&uri[4], ','); + /* geo:latitude,longitude[,altitude][;u=u][;crs=crs] */ + if (!(comma && *comma)) + return g_strdup (uri); + semicolon = strchr (comma + 1, ';'); + if (!semicolon) + semicolon = strchr (comma + 1, ','); + latitude = g_strndup (&uri[4], comma - &uri[4]); + if (semicolon) + longitude = g_strndup (comma + 1, semicolon - comma - 1); + else + longitude = g_strdup (comma + 1); + geo = g_strdup_printf ("http://www.openstreetmap.org/?mlat=%s&mlon=%s", + latitude, longitude); + g_free (latitude); + g_free (longitude); + return geo; + } /* Do we have a protocol? */ if (g_strstr_len (uri, 8, "://")) return sokoke_idn_to_punycode (g_strdup (uri));