Bug 1756083 - Cleanup snap name handling and enable portal when running under either flatpak or snap. r=stransky
Differential Revision: https://phabricator.services.mozilla.com/D139474
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include "imgIContainer.h"
|
#include "imgIContainer.h"
|
||||||
#include "mozilla/Sprintf.h"
|
#include "mozilla/Sprintf.h"
|
||||||
#include "mozilla/WidgetUtils.h"
|
#include "mozilla/WidgetUtils.h"
|
||||||
|
#include "mozilla/WidgetUtilsGtk.h"
|
||||||
#include "mozilla/dom/Element.h"
|
#include "mozilla/dom/Element.h"
|
||||||
#if defined(MOZ_WIDGET_GTK)
|
#if defined(MOZ_WIDGET_GTK)
|
||||||
# include "nsImageToPixbuf.h"
|
# include "nsImageToPixbuf.h"
|
||||||
@@ -72,18 +73,6 @@ static const MimeTypeAssociation appTypes[] = {
|
|||||||
#define kDesktopDrawBGGSKey "draw-background"
|
#define kDesktopDrawBGGSKey "draw-background"
|
||||||
#define kDesktopColorGSKey "primary-color"
|
#define kDesktopColorGSKey "primary-color"
|
||||||
|
|
||||||
static bool IsRunningAsASnap() {
|
|
||||||
const char* snapName = mozilla::widget::WidgetUtils::GetSnapInstanceName();
|
|
||||||
|
|
||||||
// return early if not set.
|
|
||||||
if (snapName == nullptr) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// snapName as defined on https://snapcraft.io/firefox
|
|
||||||
return (strcmp(snapName, "firefox") == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult nsGNOMEShellService::Init() {
|
nsresult nsGNOMEShellService::Init() {
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
||||||
@@ -200,9 +189,9 @@ nsGNOMEShellService::IsDefaultBrowser(bool aForAllTypes,
|
|||||||
bool* aIsDefaultBrowser) {
|
bool* aIsDefaultBrowser) {
|
||||||
*aIsDefaultBrowser = false;
|
*aIsDefaultBrowser = false;
|
||||||
|
|
||||||
if (IsRunningAsASnap()) {
|
if (widget::IsRunningUnderSnap()) {
|
||||||
const gchar* argv[] = {"xdg-settings", "check", "default-web-browser",
|
const gchar* argv[] = {"xdg-settings", "check", "default-web-browser",
|
||||||
"firefox.desktop", nullptr};
|
(SNAP_INSTANCE_NAME ".desktop"), nullptr};
|
||||||
GSpawnFlags flags = static_cast<GSpawnFlags>(G_SPAWN_SEARCH_PATH |
|
GSpawnFlags flags = static_cast<GSpawnFlags>(G_SPAWN_SEARCH_PATH |
|
||||||
G_SPAWN_STDERR_TO_DEV_NULL);
|
G_SPAWN_STDERR_TO_DEV_NULL);
|
||||||
gchar* output = nullptr;
|
gchar* output = nullptr;
|
||||||
@@ -280,9 +269,9 @@ nsGNOMEShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers) {
|
|||||||
"Setting the default browser for all users is not yet supported");
|
"Setting the default browser for all users is not yet supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (IsRunningAsASnap()) {
|
if (widget::IsRunningUnderSnap()) {
|
||||||
const gchar* argv[] = {"xdg-settings", "set", "default-web-browser",
|
const gchar* argv[] = {"xdg-settings", "set", "default-web-browser",
|
||||||
"firefox.desktop", nullptr};
|
(SNAP_INSTANCE_NAME ".desktop"), nullptr};
|
||||||
GSpawnFlags flags = static_cast<GSpawnFlags>(G_SPAWN_SEARCH_PATH |
|
GSpawnFlags flags = static_cast<GSpawnFlags>(G_SPAWN_SEARCH_PATH |
|
||||||
G_SPAWN_STDOUT_TO_DEV_NULL |
|
G_SPAWN_STDOUT_TO_DEV_NULL |
|
||||||
G_SPAWN_STDERR_TO_DEV_NULL);
|
G_SPAWN_STDERR_TO_DEV_NULL);
|
||||||
|
|||||||
@@ -33,6 +33,10 @@
|
|||||||
# include "nsILocalFileMac.h"
|
# include "nsILocalFileMac.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MOZ_WIDGET_GTK
|
||||||
|
#include "mozilla/WidgetUtilsGtk.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "nsAppDirectoryServiceDefs.h"
|
#include "nsAppDirectoryServiceDefs.h"
|
||||||
#include "nsDirectoryServiceDefs.h"
|
#include "nsDirectoryServiceDefs.h"
|
||||||
#include "nsNetCID.h"
|
#include "nsNetCID.h"
|
||||||
@@ -1906,16 +1910,11 @@ nsToolkitProfileService::CreateProfile(nsIFile* aRootDir,
|
|||||||
* get essentially the same benefits as dedicated profiles provides.
|
* get essentially the same benefits as dedicated profiles provides.
|
||||||
*/
|
*/
|
||||||
bool nsToolkitProfileService::IsSnapEnvironment() {
|
bool nsToolkitProfileService::IsSnapEnvironment() {
|
||||||
const char* snapName = mozilla::widget::WidgetUtils::GetSnapInstanceName();
|
#ifdef MOZ_WIDGET_GTK
|
||||||
|
return widget::IsRunningUnderSnap();
|
||||||
// return early if not set.
|
#else
|
||||||
if (snapName == nullptr) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
#endif
|
||||||
|
|
||||||
// snapName as defined on e.g.
|
|
||||||
// https://snapcraft.io/firefox or https://snapcraft.io/thunderbird
|
|
||||||
return (strcmp(snapName, MOZ_APP_NAME) == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -130,14 +130,5 @@ void WidgetUtils::GetBrandShortName(nsAString& aBrandName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* WidgetUtils::GetSnapInstanceName() {
|
|
||||||
char* instanceName = PR_GetEnv("SNAP_INSTANCE_NAME");
|
|
||||||
if (instanceName != nullptr) {
|
|
||||||
return instanceName;
|
|
||||||
}
|
|
||||||
// Compatibility for snapd <= 2.35:
|
|
||||||
return PR_GetEnv("SNAP_NAME");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace widget
|
} // namespace widget
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|||||||
@@ -88,11 +88,6 @@ class WidgetUtils {
|
|||||||
* Get branchShortName from string bundle
|
* Get branchShortName from string bundle
|
||||||
*/
|
*/
|
||||||
static void GetBrandShortName(nsAString& aBrandName);
|
static void GetBrandShortName(nsAString& aBrandName);
|
||||||
|
|
||||||
/* When packaged as a snap, strict confinement needs to be accounted for.
|
|
||||||
See https://snapcraft.io/docs for details.
|
|
||||||
Return the snap's instance name, or null when not running as a snap. */
|
|
||||||
static const char* GetSnapInstanceName();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace widget
|
} // namespace widget
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "gfx2DGlue.h"
|
#include "gfx2DGlue.h"
|
||||||
#include "gfxPlatform.h"
|
#include "gfxPlatform.h"
|
||||||
#include "mozilla/WidgetUtils.h" // For WidgetUtils
|
#include "mozilla/WidgetUtilsGtk.h"
|
||||||
#include "mozilla/gfx/Tools.h"
|
#include "mozilla/gfx/Tools.h"
|
||||||
#include "nsPrintfCString.h"
|
#include "nsPrintfCString.h"
|
||||||
#include "prenv.h" // For PR_GetEnv
|
#include "prenv.h" // For PR_GetEnv
|
||||||
@@ -44,9 +44,8 @@ char* WaylandBufferSHM::mDumpDir = PR_GetEnv("MOZ_WAYLAND_DUMP_DIR");
|
|||||||
static int WaylandAllocateShmMemory(int aSize) {
|
static int WaylandAllocateShmMemory(int aSize) {
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
|
|
||||||
nsCString shmPrefix("/");
|
nsAutoCString shmPrefix("/");
|
||||||
const char* snapName = mozilla::widget::WidgetUtils::GetSnapInstanceName();
|
if (const char* snapName = GetSnapInstanceName()) {
|
||||||
if (snapName != nullptr) {
|
|
||||||
shmPrefix.AppendPrintf("snap.%s.", snapName);
|
shmPrefix.AppendPrintf("snap.%s.", snapName);
|
||||||
}
|
}
|
||||||
shmPrefix.Append("wayland.mozilla.ipc");
|
shmPrefix.Append("wayland.mozilla.ipc");
|
||||||
|
|||||||
@@ -98,23 +98,41 @@ bool IsRunningUnderFlatpak() {
|
|||||||
return sRunning;
|
return sRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsRunningUnderSnap() {
|
||||||
|
static bool sRunning = [] {
|
||||||
|
const char* instanceName = [] {
|
||||||
|
if (const char* instanceName = g_getenv("SNAP_INSTANCE_NAME")) {
|
||||||
|
return instanceName;
|
||||||
|
}
|
||||||
|
// Compatibility for snapd <= 2.35:
|
||||||
|
return g_getenv("SNAP_NAME");
|
||||||
|
}();
|
||||||
|
return instanceName && !strcmp(instanceName, SNAP_INSTANCE_NAME);
|
||||||
|
};
|
||||||
|
return sRunning;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* GetSnapInstanceName() {
|
||||||
|
return IsRunningUnderSnap() ? SNAP_INSTANCE_NAME : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool ShouldUsePortal(PortalKind aPortalKind) {
|
bool ShouldUsePortal(PortalKind aPortalKind) {
|
||||||
static bool sFlatpakPortalEnv = [] {
|
static bool sPortalEnv = [] {
|
||||||
if (IsRunningUnderFlatpak()) {
|
if (IsRunningUnderFlatpakOrSnap()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const char* portalEnvString = g_getenv("GTK_USE_PORTAL");
|
const char* portalEnvString = g_getenv("GTK_USE_PORTAL");
|
||||||
return portalEnvString && atoi(portalEnvString) != 0;
|
return portalEnvString && atoi(portalEnvString) != 0;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
bool autoBehavior = sFlatpakPortalEnv;
|
bool autoBehavior = sPortalEnv;
|
||||||
const int32_t pref = [&] {
|
const int32_t pref = [&] {
|
||||||
switch (aPortalKind) {
|
switch (aPortalKind) {
|
||||||
case PortalKind::FilePicker:
|
case PortalKind::FilePicker:
|
||||||
return StaticPrefs::widget_use_xdg_desktop_portal_file_picker();
|
return StaticPrefs::widget_use_xdg_desktop_portal_file_picker();
|
||||||
case PortalKind::MimeHandler:
|
case PortalKind::MimeHandler:
|
||||||
// Mime portal breaks default browser handling, see bug 1516290.
|
// Mime portal breaks default browser handling, see bug 1516290.
|
||||||
autoBehavior = IsRunningUnderFlatpak();
|
autoBehavior = IsRunningUnderFlatpakOrSnap();
|
||||||
return StaticPrefs::widget_use_xdg_desktop_portal_mime_handler();
|
return StaticPrefs::widget_use_xdg_desktop_portal_mime_handler();
|
||||||
case PortalKind::Print:
|
case PortalKind::Print:
|
||||||
// Print portal still needs more work, so auto behavior is just when
|
// Print portal still needs more work, so auto behavior is just when
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
#include "nsTArray.h"
|
#include "nsTArray.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <gdk/gdk.h>
|
|
||||||
|
typedef struct _GdkDisplay GdkDisplay;
|
||||||
|
typedef struct _GdkDevice GdkDevice;
|
||||||
|
|
||||||
namespace mozilla::widget {
|
namespace mozilla::widget {
|
||||||
|
|
||||||
@@ -31,6 +33,23 @@ bool GdkIsX11Display();
|
|||||||
GdkDevice* GdkGetPointer();
|
GdkDevice* GdkGetPointer();
|
||||||
|
|
||||||
bool IsRunningUnderFlatpak();
|
bool IsRunningUnderFlatpak();
|
||||||
|
|
||||||
|
// When packaged as a snap, strict confinement needs to be accounted for.
|
||||||
|
// See https://snapcraft.io/docs for details.
|
||||||
|
// Name as defined on e.g.
|
||||||
|
// https://snapcraft.io/firefox or https://snapcraft.io/thunderbird
|
||||||
|
#ifdef MOZ_APP_NAME
|
||||||
|
# define SNAP_INSTANCE_NAME MOZ_APP_NAME
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool IsRunningUnderSnap();
|
||||||
|
inline bool IsRunningUnderFlatpakOrSnap() {
|
||||||
|
return IsRunningUnderFlatpak() || IsRunningUnderSnap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the snap's instance name, or null when not running as a snap.
|
||||||
|
const char* GetSnapInstanceName();
|
||||||
|
|
||||||
enum class PortalKind {
|
enum class PortalKind {
|
||||||
FilePicker,
|
FilePicker,
|
||||||
MimeHandler,
|
MimeHandler,
|
||||||
|
|||||||
Reference in New Issue
Block a user