From 283005e217d3735ebf30e7ee6cbbf904c9f97fb1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20St=C3=B6sel?= Date: Fri, 12 Mar 2010 23:25:09 +0100 Subject: [PATCH] Implement and use sokoke_recursive_fork_protection As Midori may call external tools to open URIs it cannot handle, and at the same time Midori is commonly the default browser, this can end in recursion when the external tool also calls Midori. See the description of sokoke_recursive_fork_protection(). --- midori/midori-app.c | 15 +++++++++------ midori/sokoke.c | 33 +++++++++++++++++++++++++++++++++ midori/sokoke.h | 4 ++++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/midori/midori-app.c b/midori/midori-app.c index d8cb2d9f..52716ee7 100644 --- a/midori/midori-app.c +++ b/midori/midori-app.c @@ -470,14 +470,17 @@ midori_app_command_received (MidoriApp* app, gchar* fixed_uri = sokoke_magic_uri (*uris); if (!fixed_uri) fixed_uri = g_strdup (*uris); - if (first) + if (sokoke_recursive_fork_protection (fixed_uri, FALSE)) { - midori_browser_set_current_uri (browser, fixed_uri); - first = FALSE; + if (first) + { + midori_browser_set_current_uri (browser, fixed_uri); + first = FALSE; + } + else + midori_browser_set_current_page (browser, + midori_browser_add_uri (browser, fixed_uri)); } - else - midori_browser_set_current_page (browser, - midori_browser_add_uri (browser, fixed_uri)); g_free (fixed_uri); uris++; } diff --git a/midori/sokoke.c b/midori/sokoke.c index 657ba9a3..a26078a6 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -273,6 +273,7 @@ sokoke_show_uri (GdkScreen* screen, guint32 timestamp, GError** error) { + #if HAVE_HILDON HildonURIAction* action = hildon_uri_get_default_action_by_uri (uri, NULL); return hildon_uri_open (uri, action, error); @@ -352,6 +353,8 @@ sokoke_show_uri (GdkScreen* screen, g_return_val_if_fail (uri != NULL, FALSE); g_return_val_if_fail (!error || !*error, FALSE); + sokoke_recursive_fork_protection (uri, TRUE); + #if GTK_CHECK_VERSION (2, 14, 0) if (gtk_show_uri (screen, uri, timestamp, error)) return TRUE; @@ -1740,6 +1743,36 @@ sokoke_prefetch_uri (const char* uri) return TRUE; } +/** + * sokoke_recursive_fork_protection + * @uri: the URI to check + * @set_uri: if TRUE the URI will be saved + * + * Protects against recursive invokations of the Midori executable + * with the same URI. + * + * As an example, consider having an URI starting with 'tel://'. You + * could attempt to open it with sokoke_show_uri. In turn, 'exo-open' + * might be called. Now quite possibly 'exo-open' is unable to handle + * 'tel://' and might well fall back to 'midori' as default browser. + * + * To protect against this scenario, call this function with the + * URI and %TRUE before calling any external tool. + * #MidoriApp calls sokoke_recursive_fork_protection() with %FALSE + * and bails out if %FALSE is returned. + * + * Return value: %TRUE if @uri is new, %FALSE on recursion + **/ +gboolean +sokoke_recursive_fork_protection (const gchar* uri, + gboolean set_uri) +{ + static gchar* fork_uri = NULL; + if (set_uri) + katze_assign (fork_uri, g_strdup (uri)); + return g_strcmp0 (fork_uri, uri) == 0 ? FALSE : TRUE; +} + /* Provide a new way for SoupSession to assume an 'Accept-Language' string automatically from the return value of g_get_language_names(), properly formatted according to RFC2616. diff --git a/midori/sokoke.h b/midori/sokoke.h index 7d46de24..927cfee9 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -226,4 +226,8 @@ sokoke_prefetch_uri (const char* uri); gchar * sokoke_accept_languages (const gchar* const * lang_names); +gboolean +sokoke_recursive_fork_protection (const gchar* uri, + gboolean set_uri); + #endif /* !__SOKOKE_H__ */ -- 2.39.5