From e42200263fdecceb0721e646f2f981202c72ed37 Mon Sep 17 00:00:00 2001 From: Jan Horak Date: Thu, 9 Mar 2023 15:14:26 +0000 Subject: [PATCH] Bug 1621913 Don't show the defaultBrowserBox in settings under flatpak; r=settings-reviewers,Gijs Under Flatpak we cannot determine if the application is set as default handler for http/https protocols and also the application cannot set the system defaults. In order to avoid user confusion we hide the defaultBrowserBox which under flatpak shows always: "Firefox is not your default browser" and the "Make Default..." button does not make any change to the system. Differential Revision: https://phabricator.services.mozilla.com/D170590 --- browser/components/preferences/main.js | 11 +++++------ browser/components/preferences/preferences.js | 11 +++++++++++ toolkit/system/gnome/nsGIOService.cpp | 5 +++++ xpcom/system/nsIGIOService.idl | 1 + 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/browser/components/preferences/main.js b/browser/components/preferences/main.js index c8b7bca0953c..064e5ce48956 100644 --- a/browser/components/preferences/main.js +++ b/browser/components/preferences/main.js @@ -1269,7 +1269,9 @@ var gMainPane = { if (AppConstants.HAVE_SHELL_SERVICE) { let shellSvc = getShellService(); let defaultBrowserBox = document.getElementById("defaultBrowserBox"); - if (!shellSvc) { + let isInFlatpak = gGIOService?.isRunningUnderFlatpak; + // Flatpak does not support setting nor detection of default browser + if (!shellSvc || isInFlatpak) { defaultBrowserBox.hidden = true; return; } @@ -2454,11 +2456,8 @@ var gMainPane = { possibleAppMenuItems.push(menuItem); } // Add gio handlers - if (Cc["@mozilla.org/gio-service;1"]) { - let gIOSvc = Cc["@mozilla.org/gio-service;1"].getService( - Ci.nsIGIOService - ); - var gioApps = gIOSvc.getAppsForURIScheme(handlerInfo.type); + if (gGIOService) { + var gioApps = gGIOService.getAppsForURIScheme(handlerInfo.type); let possibleHandlers = handlerInfo.possibleApplicationHandlers; for (let handler of gioApps.enumerate(Ci.nsIHandlerApp)) { // OS handler share the same name, it's most likely the same app, skipping... diff --git a/browser/components/preferences/preferences.js b/browser/components/preferences/preferences.js index d2c99c0f7c26..85da477c0621 100644 --- a/browser/components/preferences/preferences.js +++ b/browser/components/preferences/preferences.js @@ -68,6 +68,17 @@ XPCOMUtils.defineLazyServiceGetters(this, { gMIMEService: ["@mozilla.org/mime;1", "nsIMIMEService"], }); +if (Cc["@mozilla.org/gio-service;1"]) { + XPCOMUtils.defineLazyServiceGetter( + this, + "gGIOService", + "@mozilla.org/gio-service;1", + "nsIGIOService" + ); +} else { + this.gGIOService = null; +} + ChromeUtils.defineESModuleGetters(this, { BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs", ContextualIdentityService: diff --git a/toolkit/system/gnome/nsGIOService.cpp b/toolkit/system/gnome/nsGIOService.cpp index f8c61b5c1503..25e744ee96a9 100644 --- a/toolkit/system/gnome/nsGIOService.cpp +++ b/toolkit/system/gnome/nsGIOService.cpp @@ -702,6 +702,11 @@ nsresult nsGIOService::LaunchFile(const nsACString& aPath) { return LaunchPath(aPath); } +nsresult nsGIOService::GetIsRunningUnderFlatpak(bool* aResult) { + *aResult = mozilla::widget::IsRunningUnderFlatpak(); + return NS_OK; +} + static nsresult RevealDirectory(nsIFile* aFile, bool aForce) { nsAutoCString path; if (bool isDir; NS_SUCCEEDED(aFile->IsDirectory(&isDir)) && isDir) { diff --git a/xpcom/system/nsIGIOService.idl b/xpcom/system/nsIGIOService.idl index f956b0128868..36f19d28e303 100644 --- a/xpcom/system/nsIGIOService.idl +++ b/xpcom/system/nsIGIOService.idl @@ -75,6 +75,7 @@ interface nsIGIOService : nsISupports AUTF8String getDescriptionForMimeType(in AUTF8String mimeType); /*** Misc. methods ***/ + [infallible] readonly attribute boolean isRunningUnderFlatpak; /* Open the given URI in the default application */ [noscript] void showURI(in nsIURI uri);