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
--- 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"
%}