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().
This commit is contained in:
André Stösel 2010-03-12 23:25:09 +01:00 committed by Christian Dywan
parent b0162d83f2
commit 283005e217
3 changed files with 46 additions and 6 deletions

View file

@ -470,14 +470,17 @@ midori_app_command_received (MidoriApp* app,
gchar* fixed_uri = sokoke_magic_uri (*uris); gchar* fixed_uri = sokoke_magic_uri (*uris);
if (!fixed_uri) if (!fixed_uri)
fixed_uri = g_strdup (*uris); fixed_uri = g_strdup (*uris);
if (first) if (sokoke_recursive_fork_protection (fixed_uri, FALSE))
{ {
midori_browser_set_current_uri (browser, fixed_uri); if (first)
first = FALSE; {
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); g_free (fixed_uri);
uris++; uris++;
} }

View file

@ -273,6 +273,7 @@ sokoke_show_uri (GdkScreen* screen,
guint32 timestamp, guint32 timestamp,
GError** error) GError** error)
{ {
#if HAVE_HILDON #if HAVE_HILDON
HildonURIAction* action = hildon_uri_get_default_action_by_uri (uri, NULL); HildonURIAction* action = hildon_uri_get_default_action_by_uri (uri, NULL);
return hildon_uri_open (uri, action, error); 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 (uri != NULL, FALSE);
g_return_val_if_fail (!error || !*error, FALSE); g_return_val_if_fail (!error || !*error, FALSE);
sokoke_recursive_fork_protection (uri, TRUE);
#if GTK_CHECK_VERSION (2, 14, 0) #if GTK_CHECK_VERSION (2, 14, 0)
if (gtk_show_uri (screen, uri, timestamp, error)) if (gtk_show_uri (screen, uri, timestamp, error))
return TRUE; return TRUE;
@ -1740,6 +1743,36 @@ sokoke_prefetch_uri (const char* uri)
return TRUE; 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' /* Provide a new way for SoupSession to assume an 'Accept-Language'
string automatically from the return value of g_get_language_names(), string automatically from the return value of g_get_language_names(),
properly formatted according to RFC2616. properly formatted according to RFC2616.

View file

@ -226,4 +226,8 @@ sokoke_prefetch_uri (const char* uri);
gchar * gchar *
sokoke_accept_languages (const gchar* const * lang_names); sokoke_accept_languages (const gchar* const * lang_names);
gboolean
sokoke_recursive_fork_protection (const gchar* uri,
gboolean set_uri);
#endif /* !__SOKOKE_H__ */ #endif /* !__SOKOKE_H__ */