зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1526243 - [Linux] Don't use nsGConfService in nsGNOMEShellService.cpp, r=glandium
Don't use gconf service to get/set default browser as it breaks recent Gnome environment. Also use XDG_CURRENT_DESKTOP to check actual desktop. Differential Revision: https://phabricator.services.mozilla.com/D25395 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
3503b00341
Коммит
69f81abebc
|
@ -15,7 +15,6 @@
|
||||||
#include "nsIPrefService.h"
|
#include "nsIPrefService.h"
|
||||||
#include "prenv.h"
|
#include "prenv.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsIGConfService.h"
|
|
||||||
#include "nsIGIOService.h"
|
#include "nsIGIOService.h"
|
||||||
#include "nsIGSettingsService.h"
|
#include "nsIGSettingsService.h"
|
||||||
#include "nsIStringBundle.h"
|
#include "nsIStringBundle.h"
|
||||||
|
@ -70,14 +69,6 @@ static const MimeTypeAssociation appTypes[] = {
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
// GConf registry key constants
|
|
||||||
#define DG_BACKGROUND "/desktop/gnome/background"
|
|
||||||
|
|
||||||
#define kDesktopImageKey DG_BACKGROUND "/picture_filename"
|
|
||||||
#define kDesktopOptionsKey DG_BACKGROUND "/picture_options"
|
|
||||||
#define kDesktopDrawBGKey DG_BACKGROUND "/draw_background"
|
|
||||||
#define kDesktopColorKey DG_BACKGROUND "/primary_color"
|
|
||||||
|
|
||||||
#define kDesktopBGSchema "org.gnome.desktop.background"
|
#define kDesktopBGSchema "org.gnome.desktop.background"
|
||||||
#define kDesktopImageGSKey "picture-uri"
|
#define kDesktopImageGSKey "picture-uri"
|
||||||
#define kDesktopOptionGSKey "picture-options"
|
#define kDesktopOptionGSKey "picture-options"
|
||||||
|
@ -93,15 +84,14 @@ nsresult nsGNOMEShellService::Init() {
|
||||||
return NS_ERROR_NOT_AVAILABLE;
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GConf, GSettings or GIO _must_ be available, or we do not allow
|
// GSettings or GIO _must_ be available, or we do not allow
|
||||||
// CreateInstance to succeed.
|
// CreateInstance to succeed.
|
||||||
|
|
||||||
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
|
||||||
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
||||||
nsCOMPtr<nsIGSettingsService> gsettings =
|
nsCOMPtr<nsIGSettingsService> gsettings =
|
||||||
do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
|
do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
|
||||||
|
|
||||||
if (!gconf && !giovfs && !gsettings) return NS_ERROR_NOT_AVAILABLE;
|
if (!giovfs && !gsettings) return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
|
||||||
// Check G_BROKEN_FILENAMES. If it's set, then filenames in glib use
|
// Check G_BROKEN_FILENAMES. If it's set, then filenames in glib use
|
||||||
// the locale encoding. If it's not set, they use UTF-8.
|
// the locale encoding. If it's not set, they use UTF-8.
|
||||||
|
@ -217,25 +207,13 @@ nsGNOMEShellService::IsDefaultBrowser(bool aForAllTypes,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
|
||||||
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
||||||
|
|
||||||
bool enabled;
|
|
||||||
nsAutoCString handler;
|
nsAutoCString handler;
|
||||||
nsCOMPtr<nsIGIOMimeApp> gioApp;
|
nsCOMPtr<nsIGIOMimeApp> gioApp;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
|
for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
|
||||||
if (!appProtocols[i].essential) continue;
|
if (!appProtocols[i].essential) continue;
|
||||||
|
|
||||||
if (gconf) {
|
|
||||||
handler.Truncate();
|
|
||||||
gconf->GetAppForProtocol(nsDependentCString(appProtocols[i].name),
|
|
||||||
&enabled, handler);
|
|
||||||
|
|
||||||
if (!CheckHandlerMatchesAppName(handler) || !enabled)
|
|
||||||
return NS_OK; // the handler is disabled or set to another app
|
|
||||||
}
|
|
||||||
|
|
||||||
if (giovfs) {
|
if (giovfs) {
|
||||||
handler.Truncate();
|
handler.Truncate();
|
||||||
nsCOMPtr<nsIHandlerApp> handlerApp;
|
nsCOMPtr<nsIHandlerApp> handlerApp;
|
||||||
|
@ -275,29 +253,7 @@ nsGNOMEShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
|
||||||
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
||||||
if (gconf) {
|
|
||||||
nsAutoCString appKeyValue;
|
|
||||||
if (mAppIsInPath) {
|
|
||||||
// mAppPath is in the users path, so use only the basename as the launcher
|
|
||||||
gchar *tmp = g_path_get_basename(mAppPath.get());
|
|
||||||
appKeyValue = tmp;
|
|
||||||
g_free(tmp);
|
|
||||||
} else {
|
|
||||||
appKeyValue = mAppPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
appKeyValue.AppendLiteral(" %s");
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
|
|
||||||
if (appProtocols[i].essential || aClaimAllTypes) {
|
|
||||||
gconf->SetAppForProtocol(nsDependentCString(appProtocols[i].name),
|
|
||||||
appKeyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (giovfs) {
|
if (giovfs) {
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||||
|
@ -358,7 +314,13 @@ nsGNOMEShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers) {
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsGNOMEShellService::GetCanSetDesktopBackground(bool *aResult) {
|
nsGNOMEShellService::GetCanSetDesktopBackground(bool *aResult) {
|
||||||
// setting desktop background is currently only supported
|
// setting desktop background is currently only supported
|
||||||
// for Gnome or desktops using the same GSettings and GConf keys
|
// for Gnome or desktops using the same GSettings keys
|
||||||
|
const char *currentDesktop = getenv("XDG_CURRENT_DESKTOP");
|
||||||
|
if (currentDesktop && strstr(currentDesktop, "GNOME") != nullptr) {
|
||||||
|
*aResult = true;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
const char *gnomeSession = getenv("GNOME_DESKTOP_SESSION_ID");
|
const char *gnomeSession = getenv("GNOME_DESKTOP_SESSION_ID");
|
||||||
if (gnomeSession) {
|
if (gnomeSession) {
|
||||||
*aResult = true;
|
*aResult = true;
|
||||||
|
@ -446,10 +408,6 @@ nsGNOMEShellService::SetDesktopBackground(dom::Element *aElement,
|
||||||
rv = WriteImage(filePath, container);
|
rv = WriteImage(filePath, container);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// Try GSettings first. If we don't have GSettings or the right schema, fall
|
|
||||||
// back to using GConf instead. Note that if GSettings works ok, the changes
|
|
||||||
// get mirrored to GConf by the gsettings->gconf bridge in
|
|
||||||
// gnome-settings-daemon
|
|
||||||
nsCOMPtr<nsIGSettingsService> gsettings =
|
nsCOMPtr<nsIGSettingsService> gsettings =
|
||||||
do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
|
do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
|
||||||
if (gsettings) {
|
if (gsettings) {
|
||||||
|
@ -472,22 +430,7 @@ nsGNOMEShellService::SetDesktopBackground(dom::Element *aElement,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the file was written successfully, set it as the system wallpaper
|
return NS_ERROR_FAILURE;
|
||||||
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
|
||||||
|
|
||||||
if (gconf) {
|
|
||||||
gconf->SetString(NS_LITERAL_CSTRING(kDesktopOptionsKey), options);
|
|
||||||
|
|
||||||
// Set the image to an empty string first to force a refresh
|
|
||||||
// (since we could be writing a new image on top of an existing
|
|
||||||
// Firefox_wallpaper.png and nautilus doesn't monitor the file for changes)
|
|
||||||
gconf->SetString(NS_LITERAL_CSTRING(kDesktopImageKey), EmptyCString());
|
|
||||||
|
|
||||||
gconf->SetString(NS_LITERAL_CSTRING(kDesktopImageKey), filePath);
|
|
||||||
gconf->SetBool(NS_LITERAL_CSTRING(kDesktopDrawBGKey), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define COLOR_16_TO_8_BIT(_c) ((_c) >> 8)
|
#define COLOR_16_TO_8_BIT(_c) ((_c) >> 8)
|
||||||
|
@ -509,12 +452,6 @@ nsGNOMEShellService::GetDesktopBackgroundColor(uint32_t *aColor) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!background_settings) {
|
|
||||||
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
|
||||||
if (gconf)
|
|
||||||
gconf->GetString(NS_LITERAL_CSTRING(kDesktopColorKey), background);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (background.IsEmpty()) {
|
if (background.IsEmpty()) {
|
||||||
*aColor = 0;
|
*aColor = 0;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -562,13 +499,7 @@ nsGNOMEShellService::SetDesktopBackgroundColor(uint32_t aColor) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
if (gconf) {
|
|
||||||
gconf->SetString(NS_LITERAL_CSTRING(kDesktopColorKey), colorString);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -588,45 +519,7 @@ nsGNOMEShellService::OpenApplication(int32_t aApplication) {
|
||||||
if (handlerApp) return handlerApp->LaunchWithURI(nullptr, nullptr);
|
if (handlerApp) return handlerApp->LaunchWithURI(nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
return NS_ERROR_FAILURE;
|
||||||
if (!gconf) return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
bool enabled;
|
|
||||||
nsAutoCString appCommand;
|
|
||||||
gconf->GetAppForProtocol(scheme, &enabled, appCommand);
|
|
||||||
|
|
||||||
if (!enabled) return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
// XXX we don't currently handle launching a terminal window.
|
|
||||||
// If the handler requires a terminal, bail.
|
|
||||||
bool requiresTerminal;
|
|
||||||
gconf->HandlerRequiresTerminal(scheme, &requiresTerminal);
|
|
||||||
if (requiresTerminal) return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
// Perform shell argument expansion
|
|
||||||
int argc;
|
|
||||||
char **argv;
|
|
||||||
if (!g_shell_parse_argv(appCommand.get(), &argc, &argv, nullptr))
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
char **newArgv = new char *[argc + 1];
|
|
||||||
int newArgc = 0;
|
|
||||||
|
|
||||||
// Run through the list of arguments. Copy all of them to the new
|
|
||||||
// argv except for %s, which we skip.
|
|
||||||
for (int i = 0; i < argc; ++i) {
|
|
||||||
if (strcmp(argv[i], "%s") != 0) newArgv[newArgc++] = argv[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
newArgv[newArgc] = nullptr;
|
|
||||||
|
|
||||||
gboolean err = g_spawn_async(nullptr, newArgv, nullptr, G_SPAWN_SEARCH_PATH,
|
|
||||||
nullptr, nullptr, nullptr, nullptr);
|
|
||||||
|
|
||||||
g_strfreev(argv);
|
|
||||||
delete[] newArgv;
|
|
||||||
|
|
||||||
return err ? NS_OK : NS_ERROR_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
Загрузка…
Ссылка в новой задаче