[epiphany] Allow launching apps and URIs from Flatpak



commit 22b43886e77b12a9d1a6c6c6763c4c9fbc63bb9d
Author: Phaedrus Leeds <mwleeds protonmail com>
Date:   Fri Dec 17 14:03:13 2021 -0800

    Allow launching apps and URIs from Flatpak
    
    It is possible to launch a web app (initiated by the user clicking on
    the install completed notification) from within Flatpak, and it's
    possible to open a URI from within Flatpak, so let these code paths
    execute from Flatpaks. Follow-up commits will enable the rest of the web
    app functionality under Flatpak.

 lib/ephy-file-helpers.c | 53 +++++++++++++++++--------------------------------
 lib/ephy-file-helpers.h | 31 +++++++++--------------------
 src/ephy-shell.c        |  8 ++------
 src/ephy-window.c       | 12 ++---------
 src/window-commands.c   |  6 ++----
 5 files changed, 33 insertions(+), 77 deletions(-)
---
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 469e35200..42fff8a79 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -585,11 +585,6 @@ launch_application (GAppInfo *app,
   GdkScreen *screen;
   gboolean res;
 
-  /* This is impossible to implement inside sandbox. Higher layers must
-   * ensure we don't get here.
-   */
-  g_assert (!ephy_is_running_inside_sandbox ());
-
   display = gdk_display_get_default ();
   screen = gdk_screen_get_default ();
 
@@ -606,28 +601,20 @@ launch_application (GAppInfo *app,
 }
 
 /**
- * ephy_file_launch_desktop_file:
- * @filename: the path to the .desktop file
- * @tag: used to guard against improper usage
+ * ephy_file_launch_webapp_desktop_file:
+ * @filename: the path to the .desktop file of a web app
  *
  * Launches the application described by the desktop file @filename.
  *
  * Returns: %TRUE if the application launch was successful
  **/
 gboolean
-ephy_file_launch_desktop_file (const char                   *filename,
-                               guint32                       user_time,
-                               EphyFileHelpersNotFlatpakTag  tag)
+ephy_file_launch_webapp_desktop_file (const char *filename,
+                                      guint32     user_time)
 {
   g_autoptr (GDesktopAppInfo) app = NULL;
 
-  /* This is impossible to implement inside sandbox. Higher layers must
-   * ensure we don't get here.
-   */
-  g_assert (tag == EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
-  g_assert (!ephy_is_running_inside_sandbox ());
-
-  app = g_desktop_app_info_new (filename);
+  app = g_desktop_app_info_new_from_filename (filename);
 
   return launch_application (G_APP_INFO (app), NULL, user_time);
 }
@@ -696,23 +683,16 @@ ephy_file_launch_handler (GFile   *file,
 }
 
 static gboolean
-open_in_default_handler (const char                   *uri,
-                         const char                   *mime_type,
-                         guint32                       timestamp,
-                         GdkScreen                    *screen,
-                         EphyFileHelpersNotFlatpakTag  tag)
+open_in_default_handler (const char *uri,
+                         const char *mime_type,
+                         guint32     timestamp,
+                         GdkScreen  *screen)
 {
   g_autoptr (GdkAppLaunchContext) context = NULL;
   g_autoptr (GAppInfo) appinfo = NULL;
   g_autoptr (GError) error = NULL;
   GList uris;
 
-  /* This is impossible to implement inside sandbox. Higher layers must
-   * ensure we don't get here.
-   */
-  g_assert (tag == EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
-  g_assert (!ephy_is_running_inside_sandbox ());
-
   context = gdk_display_get_app_launch_context (screen ? gdk_screen_get_display (screen) : 
gdk_display_get_default ());
   gdk_app_launch_context_set_screen (context, screen);
   gdk_app_launch_context_set_timestamp (context, timestamp);
@@ -735,12 +715,15 @@ open_in_default_handler (const char                   *uri,
 }
 
 gboolean
-ephy_file_open_uri_in_default_browser (const char                   *uri,
-                                       guint32                       user_time,
-                                       GdkScreen                    *screen,
-                                       EphyFileHelpersNotFlatpakTag  tag)
+ephy_file_open_uri_in_default_browser (const char *uri,
+                                       guint32     user_time,
+                                       GdkScreen  *screen)
 {
-  return open_in_default_handler (uri, "x-scheme-handler/http", user_time, screen, tag);
+  if (ephy_is_running_inside_sandbox ()) {
+    ephy_open_uri_via_flatpak_portal (uri);
+    return TRUE;
+  }
+  return open_in_default_handler (uri, "x-scheme-handler/http", user_time, screen);
 }
 
 /**
@@ -765,7 +748,7 @@ ephy_file_browse_to (GFile   *file,
     return TRUE;
   }
 
-  return open_in_default_handler (uri, "inode/directory", user_time, NULL, 
EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
+  return open_in_default_handler (uri, "inode/directory", user_time, NULL);
 }
 
 /**
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index e7a881e42..6c74acf38 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -41,11 +41,6 @@ typedef enum
   EPHY_FILE_HELPERS_TESTING_MODE     = 1 << 5
 } EphyFileHelpersFlags;
 
-typedef enum
-{
-  EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK
-} EphyFileHelpersNotFlatpakTag;
-
 gboolean           ephy_file_helpers_init                   (const char            *profile_dir,
                                                              EphyFileHelpersFlags   flags,
                                                              GError               **error);
@@ -73,22 +68,14 @@ gboolean           ephy_file_delete_dir_recursively         (const char
 char       *       ephy_sanitize_filename                   (char                  *filename);
 void               ephy_open_default_instance_window        (void);
 void               ephy_open_incognito_window               (const char            *uri);
-
-/* These functions attempt to launch a particular application chosen by
- * Epiphany, which is not possible to do when running inside flatpak. Be
- * careful!
- */
-gboolean           ephy_file_launch_desktop_file            (const char                   *filename,
-                                                             guint32                       user_time,
-                                                             EphyFileHelpersNotFlatpakTag  tag);
-gboolean           ephy_file_open_uri_in_default_browser    (const char                   *uri,
-                                                             guint32                       user_time,
-                                                             GdkScreen                    *screen,
-                                                             EphyFileHelpersNotFlatpakTag  tag);
-gboolean           ephy_file_browse_to                      (GFile                        *file,
-                                                             guint32                       user_time);
-
-void               ephy_copy_directory                      (const char                   *source,
-                                                             const char                   *target);
+gboolean           ephy_file_launch_webapp_desktop_file     (const char            *filepath,
+                                                             guint32                user_time);
+gboolean           ephy_file_open_uri_in_default_browser    (const char            *uri,
+                                                             guint32                user_time,
+                                                             GdkScreen             *screen);
+gboolean           ephy_file_browse_to                      (GFile                 *file,
+                                                             guint32                user_time);
+void               ephy_copy_directory                      (const char            *source,
+                                                             const char            *target);
 
 G_END_DECLS
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 0ace095aa..d356ee168 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -335,12 +335,8 @@ launch_app (GSimpleAction *action,
 {
   const gchar *desktop_file = g_variant_get_string (parameter, NULL);
 
-  /* We can't get here under flatpak because all web app functionality
-   * is disabled when running under flatpak.
-   */
-  ephy_file_launch_desktop_file (desktop_file,
-                                 gtk_get_current_event_time (),
-                                 EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
+  ephy_file_launch_webapp_desktop_file (desktop_file,
+                                        gtk_get_current_event_time ());
 }
 
 static void
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 06cb1ab13..6dbf337e2 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2119,12 +2119,8 @@ decide_navigation_policy (WebKitWebView            *web_view,
       if (ephy_web_application_is_uri_allowed (uri)) {
         gtk_widget_show (GTK_WIDGET (window));
       } else {
-        /* We can't get here under sandbox because this code only
-         * executes in web app mode.
-         */
         ephy_file_open_uri_in_default_browser (uri, GDK_CURRENT_TIME,
-                                               gtk_window_get_screen (GTK_WINDOW (window)),
-                                               
EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
+                                               gtk_window_get_screen (GTK_WINDOW (window)));
         webkit_policy_decision_ignore (decision);
 
         gtk_widget_destroy (GTK_WIDGET (window));
@@ -2138,12 +2134,8 @@ decide_navigation_policy (WebKitWebView            *web_view,
       if (ephy_web_application_is_uri_allowed (uri))
         return accept_navigation_policy_decision (window, decision, uri);
 
-      /* We can't get here under sandbox because this code only
-       * executes in web app mode.
-       */
       ephy_file_open_uri_in_default_browser (uri, GDK_CURRENT_TIME,
-                                             gtk_window_get_screen (GTK_WINDOW (window)),
-                                             
EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
+                                             gtk_window_get_screen (GTK_WINDOW (window)));
       webkit_policy_decision_ignore (decision);
 
       return TRUE;
diff --git a/src/window-commands.c b/src/window-commands.c
index 32f10091d..2456fef39 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1812,11 +1812,9 @@ save_as_application_proceed (EphyApplicationDialogData *data)
   }
 
   if (desktop_file) {
-    g_autofree char *basename = g_path_get_basename (desktop_file);
-
     /* Translators: Desktop notification when a new web app is created. */
-    g_notification_add_button_with_target (notification, _("Launch"), "app.launch-app", "s", basename);
-    g_notification_set_default_action_and_target (notification, "app.launch-app", "s", basename);
+    g_notification_add_button_with_target (notification, _("Launch"), "app.launch-app", "s", desktop_file);
+    g_notification_set_default_action_and_target (notification, "app.launch-app", "s", desktop_file);
 
     ephy_focus_desktop_app (desktop_file);
   }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]