Bug 1411589 - Export ShouldUseFlatpakPortal(); r=stransky
authorJan Horak <jhorak@redhat.com>
Thu, 08 Mar 2018 17:39:59 +0100
changeset 414048 e2d6c52a232e4d3a4d80719b97d53c42bfc09d64
parent 414047 ac148c181d2b0471fbe34b2559ad9876790f3796
child 414049 c470cb1ec203f838faabf078fc8c2e16fafecc1d
push id33857
push userncsoregi@mozilla.com
push dateTue, 17 Apr 2018 21:54:38 +0000
treeherdermozilla-central@1a1223d74b7b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstransky
bugs1411589
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1411589 - Export ShouldUseFlatpakPortal(); r=stransky We need to detect the flatpak environment on multiple places. Making the ShouldUseFlatpakPortal() exported to the nsIGIOService allows us to reuse it. MozReview-Commit-ID: 41NJyR3fqZQ
toolkit/system/gnome/nsGIOService.cpp
xpcom/system/nsIGIOService.idl
--- a/toolkit/system/gnome/nsGIOService.cpp
+++ b/toolkit/system/gnome/nsGIOService.cpp
@@ -32,17 +32,17 @@ static bool GetShouldUseFlatpakPortal() 
     shouldUsePortal = true;
   } else {
     shouldUsePortal = (g_getenv("GTK_USE_PORTAL") != nullptr);
   }
   g_free(path);
   return shouldUsePortal;
 }
 
-static bool ShouldUseFlatpakPortal() {
+static bool ShouldUseFlatpakPortalImpl() {
   static bool sShouldUseFlatpakPortal = GetShouldUseFlatpakPortal();
   return sShouldUseFlatpakPortal;
 }
 
 class nsFlatpakHandlerApp : public nsIHandlerApp
 {
 public:
   NS_DECL_ISUPPORTS
@@ -451,17 +451,17 @@ NS_IMETHODIMP
 nsGIOService::GetAppForURIScheme(const nsACString& aURIScheme,
                                  nsIHandlerApp** aApp)
 {
   *aApp = nullptr;
 
   // Application in flatpak sandbox does not have access to the list
   // of installed applications on the system. We use generic
   // nsFlatpakHandlerApp which forwards launch call to the system.
-  if (ShouldUseFlatpakPortal()) {
+  if (ShouldUseFlatpakPortalImpl()) {
     nsFlatpakHandlerApp *mozApp = new nsFlatpakHandlerApp();
     NS_ADDREF(*aApp = mozApp);
     return NS_OK;
   }
 
   GAppInfo *app_info = g_app_info_get_default_for_uri_scheme(
                           PromiseFlatCString(aURIScheme).get());
   if (app_info) {
@@ -510,17 +510,17 @@ nsGIOService::GetAppsForURIScheme(const 
 NS_IMETHODIMP
 nsGIOService::GetAppForMimeType(const nsACString& aMimeType,
                                 nsIHandlerApp**   aApp)
 {
   *aApp = nullptr;
 
   // Flatpak does not reveal installed application to the sandbox,
   // we need to create generic system handler.
-  if (ShouldUseFlatpakPortal()) {
+  if (ShouldUseFlatpakPortalImpl()) {
     nsFlatpakHandlerApp *mozApp = new nsFlatpakHandlerApp();
     NS_ADDREF(*aApp = mozApp);
     return NS_OK;
   }
 
   char *content_type =
     g_content_type_from_mime_type(PromiseFlatCString(aMimeType).get());
   if (!content_type)
@@ -739,8 +739,15 @@ nsGIOService::CreateAppFromCommand(nsACS
   }
   g_free(executableWithFullPath);
 
   nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info);
   NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*appInfo = mozApp);
   return NS_OK;
 }
+
+NS_IMETHODIMP
+nsGIOService::ShouldUseFlatpakPortal(bool* aRes)
+{
+  *aRes = ShouldUseFlatpakPortalImpl();
+  return NS_OK;
+}
--- a/xpcom/system/nsIGIOService.idl
+++ b/xpcom/system/nsIGIOService.idl
@@ -76,13 +76,17 @@ interface nsIGIOService : nsISupports
   /*** Misc. methods ***/
 
   /* Open the given URI in the default application */
   void               showURI(in nsIURI uri);
   [noscript] void    showURIForInput(in ACString uri);
 
   /* Open path in file manager using org.freedesktop.FileManager1 interface */
   [noscript] void    orgFreedesktopFileManager1ShowItems(in ACString path);
+
+  /* Check if we're in flatpak runtime or using GTK portals has been enforced */
+  [noscript] bool    shouldUseFlatpakPortal();
+
 };
 
 %{C++
 #define NS_GIOSERVICE_CONTRACTID "@mozilla.org/gio-service;1"
 %}