diff options
Diffstat (limited to 'embed')
-rw-r--r-- | embed/ephy-download.c | 3 | ||||
-rw-r--r-- | embed/ephy-embed-shell.c | 44 | ||||
-rw-r--r-- | embed/ephy-embed-shell.h | 4 |
3 files changed, 50 insertions, 1 deletions
diff --git a/embed/ephy-download.c b/embed/ephy-download.c index 792f5c1c7..2713b75ff 100644 --- a/embed/ephy-download.c +++ b/embed/ephy-download.c @@ -670,7 +670,8 @@ ephy_download_do_download_action (EphyDownload *download, break; case EPHY_DOWNLOAD_ACTION_OPEN: LOG ("ephy_download_do_download_action: open"); - ret = ephy_file_launch_handler (NULL, destination, priv->start_time); + ret = ephy_embed_shell_launch_handler (ephy_embed_shell_get_default (), + destination, NULL, priv->start_time); break; case EPHY_DOWNLOAD_ACTION_NONE: LOG ("ephy_download_do_download_action: none"); diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c index c050d9764..9821d4f11 100644 --- a/embed/ephy-embed-shell.c +++ b/embed/ephy-embed-shell.c @@ -608,3 +608,47 @@ ephy_embed_shell_get_mode (EphyEmbedShell *shell) return shell->priv->mode; } + +/** + * ephy_embed_shell_launch_application: + * @shell: an #EphyEmbedShell + * @file: a #GFile to open + * @mime_type: the mime type of @file or %NULL + * @user_time: user time to prevent focus stealing + * + * Tries to open @file with the right application, making sure we will + * not call ourselves in the process. This is needed to avoid + * potential infinite loops when opening unknown file types. + * + * Returns: %TRUE on success + **/ +gboolean +ephy_embed_shell_launch_handler (EphyEmbedShell *shell, + GFile *file, + const char *mime_type, + guint32 user_time) +{ + GAppInfo *app; + GList *list = NULL; + gboolean ret = FALSE; + + g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), FALSE); + g_return_val_if_fail (file || mime_type, FALSE); + + app = ephy_file_launcher_get_app_info_for_file (file, mime_type); + + /* Do not allow recursive calls into the browser, they can lead to + * infinite loops and they should never happen anyway. */ + + /* FIXME: eventually there should be a nice and safe way of getting + * the app ID from the GApplication itself, but for now let's + * hardcode the .desktop file name and use it here. */ + if (!app || g_strcmp0 (g_app_info_get_id (app), "epiphany.desktop") == 0) + return ret; + + list = g_list_append (list, file); + ret = ephy_file_launch_application (app, list, user_time, NULL); + g_list_free (list); + + return ret; +} diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h index 7432e1133..08558f7f2 100644 --- a/embed/ephy-embed-shell.h +++ b/embed/ephy-embed-shell.h @@ -91,6 +91,10 @@ void ephy_embed_shell_add_download (EphyEmbedShell void ephy_embed_shell_remove_download (EphyEmbedShell *shell, EphyDownload *download); EphyEmbedShellMode ephy_embed_shell_get_mode (EphyEmbedShell *shell); +gboolean ephy_embed_shell_launch_handler (EphyEmbedShell *shell, + GFile *file, + const char *mime_type, + guint32 user_time); G_END_DECLS |