2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsGNOMEShellService.h"
|
|
|
|
#include "nsShellService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIProperties.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "prenv.h"
|
|
|
|
#include "nsStringAPI.h"
|
|
|
|
#include "nsIGConfService.h"
|
2009-08-25 11:58:11 -07:00
|
|
|
#include "nsIGIOService.h"
|
2011-05-12 01:15:16 -07:00
|
|
|
#include "nsIGSettingsService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsIOutputStream.h"
|
|
|
|
#include "nsIProcess.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
|
|
|
#include "nsIImageLoadingContent.h"
|
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "prprf.h"
|
2013-06-11 10:40:28 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIImageToPixbuf.h"
|
|
|
|
#endif
|
2012-12-13 23:32:54 -08:00
|
|
|
#include "nsXULAppAPI.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib-object.h>
|
2009-01-21 07:24:46 -08:00
|
|
|
#include <gtk/gtk.h>
|
2008-09-08 03:06:32 -07:00
|
|
|
#include <gdk/gdk.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct ProtocolAssociation
|
|
|
|
{
|
|
|
|
const char *name;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool essential;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MimeTypeAssociation
|
|
|
|
{
|
|
|
|
const char *mimeType;
|
|
|
|
const char *extensions;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const ProtocolAssociation appProtocols[] = {
|
2011-10-17 07:59:28 -07:00
|
|
|
{ "http", true },
|
|
|
|
{ "https", true },
|
|
|
|
{ "ftp", false },
|
|
|
|
{ "chrome", false }
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const MimeTypeAssociation appTypes[] = {
|
|
|
|
{ "text/html", "htm html shtml" },
|
|
|
|
{ "application/xhtml+xml", "xhtml xht" }
|
|
|
|
};
|
|
|
|
|
|
|
|
// GConf registry key constants
|
|
|
|
#define DG_BACKGROUND "/desktop/gnome/background"
|
|
|
|
|
|
|
|
static const char kDesktopImageKey[] = DG_BACKGROUND "/picture_filename";
|
|
|
|
static const char kDesktopOptionsKey[] = DG_BACKGROUND "/picture_options";
|
|
|
|
static const char kDesktopDrawBGKey[] = DG_BACKGROUND "/draw_background";
|
|
|
|
static const char kDesktopColorKey[] = DG_BACKGROUND "/primary_color";
|
|
|
|
|
2011-05-12 01:15:16 -07:00
|
|
|
static const char kDesktopBGSchema[] = "org.gnome.desktop.background";
|
|
|
|
static const char kDesktopImageGSKey[] = "picture-uri";
|
|
|
|
static const char kDesktopOptionGSKey[] = "picture-options";
|
|
|
|
static const char kDesktopDrawBGGSKey[] = "draw-background";
|
|
|
|
static const char kDesktopColorGSKey[] = "primary-color";
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsGNOMEShellService::Init()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-05-12 01:15:16 -07:00
|
|
|
// GConf, GSettings or GIO _must_ be available, or we do not allow
|
2007-03-22 10:30:00 -07:00
|
|
|
// CreateInstance to succeed.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
2009-08-25 11:58:11 -07:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs =
|
|
|
|
do_GetService(NS_GIOSERVICE_CONTRACTID);
|
2011-05-12 01:15:16 -07:00
|
|
|
nsCOMPtr<nsIGSettingsService> gsettings =
|
|
|
|
do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-12 01:15:16 -07:00
|
|
|
if (!gconf && !giovfs && !gsettings)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
// 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.
|
2012-07-30 07:20:58 -07:00
|
|
|
mUseLocaleFilenames = PR_GetEnv("G_BROKEN_FILENAMES") != nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-12 13:10:09 -07:00
|
|
|
if (GetAppPathFromLauncher())
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIProperties> dirSvc
|
|
|
|
(do_GetService("@mozilla.org/file/directory_service;1"));
|
|
|
|
NS_ENSURE_TRUE(dirSvc, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> appPath;
|
2012-12-13 23:32:54 -08:00
|
|
|
rv = dirSvc->Get(XRE_EXECUTABLE_FILE, NS_GET_IID(nsIFile),
|
2007-03-22 10:30:00 -07:00
|
|
|
getter_AddRefs(appPath));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return appPath->GetNativePath(mAppPath);
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsGNOMEShellService, nsIShellService)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-04-12 13:10:09 -07:00
|
|
|
nsGNOMEShellService::GetAppPathFromLauncher()
|
|
|
|
{
|
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
const char *launcher = PR_GetEnv("MOZ_APP_LAUNCHER");
|
|
|
|
if (!launcher)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-04-12 13:10:09 -07:00
|
|
|
|
|
|
|
if (g_path_is_absolute(launcher)) {
|
|
|
|
mAppPath = launcher;
|
|
|
|
tmp = g_path_get_basename(launcher);
|
|
|
|
gchar *fullpath = g_find_program_in_path(tmp);
|
|
|
|
if (fullpath && mAppPath.Equals(fullpath))
|
2011-10-17 07:59:28 -07:00
|
|
|
mAppIsInPath = true;
|
2011-04-12 13:10:09 -07:00
|
|
|
g_free(fullpath);
|
|
|
|
} else {
|
|
|
|
tmp = g_find_program_in_path(launcher);
|
|
|
|
if (!tmp)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-04-12 13:10:09 -07:00
|
|
|
mAppPath = tmp;
|
2011-10-17 07:59:28 -07:00
|
|
|
mAppIsInPath = true;
|
2011-04-12 13:10:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free(tmp);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2011-04-12 13:10:09 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGNOMEShellService::KeyMatchesAppName(const char *aKeyValue) const
|
|
|
|
{
|
|
|
|
|
|
|
|
gchar *commandPath;
|
|
|
|
if (mUseLocaleFilenames) {
|
2013-08-21 09:13:50 -07:00
|
|
|
gchar *nativePath = g_filename_from_utf8(aKeyValue, -1,
|
|
|
|
nullptr, nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!nativePath) {
|
|
|
|
NS_ERROR("Error converting path to filesystem encoding");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
commandPath = g_find_program_in_path(nativePath);
|
|
|
|
g_free(nativePath);
|
|
|
|
} else {
|
|
|
|
commandPath = g_find_program_in_path(aKeyValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!commandPath)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool matches = mAppPath.Equals(commandPath);
|
2007-03-22 10:30:00 -07:00
|
|
|
g_free(commandPath);
|
|
|
|
return matches;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-04-12 13:11:20 -07:00
|
|
|
nsGNOMEShellService::CheckHandlerMatchesAppName(const nsACString &handler) const
|
|
|
|
{
|
|
|
|
gint argc;
|
|
|
|
gchar **argv;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString command(handler);
|
2011-04-12 13:11:20 -07:00
|
|
|
|
|
|
|
// The string will be something of the form: [/path/to/]browser "%s"
|
|
|
|
// We want to remove all of the parameters and get just the binary name.
|
|
|
|
|
2013-08-21 09:13:50 -07:00
|
|
|
if (g_shell_parse_argv(command.get(), &argc, &argv, nullptr) && argc > 0) {
|
2011-04-12 13:11:20 -07:00
|
|
|
command.Assign(argv[0]);
|
|
|
|
g_strfreev(argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!KeyMatchesAppName(command.get()))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false; // the handler is set to another app
|
2011-04-12 13:11:20 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2011-04-12 13:11:20 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsGNOMEShellService::IsDefaultBrowser(bool aStartupCheck,
|
2012-09-21 07:05:24 -07:00
|
|
|
bool aForAllTypes,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aIsDefaultBrowser)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsDefaultBrowser = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aStartupCheck)
|
2011-10-17 07:59:28 -07:00
|
|
|
mCheckedThisSession = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
2011-04-12 13:11:20 -07:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool enabled;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString handler;
|
2011-04-12 13:11:20 -07:00
|
|
|
nsCOMPtr<nsIGIOMimeApp> gioApp;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!appProtocols[i].essential)
|
|
|
|
continue;
|
|
|
|
|
2011-04-12 13:11:20 -07:00
|
|
|
if (gconf) {
|
|
|
|
handler.Truncate();
|
|
|
|
gconf->GetAppForProtocol(nsDependentCString(appProtocols[i].name),
|
|
|
|
&enabled, handler);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-12 13:11:20 -07:00
|
|
|
if (!CheckHandlerMatchesAppName(handler) || !enabled)
|
|
|
|
return NS_OK; // the handler is disabled or set to another app
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-12 13:11:20 -07:00
|
|
|
if (giovfs) {
|
|
|
|
handler.Truncate();
|
|
|
|
giovfs->GetAppForURIScheme(nsDependentCString(appProtocols[i].name),
|
|
|
|
getter_AddRefs(gioApp));
|
|
|
|
if (!gioApp)
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-12 13:11:20 -07:00
|
|
|
gioApp->GetCommand(handler);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-12 13:11:20 -07:00
|
|
|
if (!CheckHandlerMatchesAppName(handler))
|
|
|
|
return NS_OK; // the handler is set to another app
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsDefaultBrowser = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsGNOMEShellService::SetDefaultBrowser(bool aClaimAllTypes,
|
|
|
|
bool aForAllUsers)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (aForAllUsers)
|
|
|
|
NS_WARNING("Setting the default browser for all users is not yet supported");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
2011-04-12 13:11:20 -07:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
2011-01-11 00:35:18 -08:00
|
|
|
if (gconf) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString appKeyValue;
|
2011-04-12 13:11:20 -07:00
|
|
|
if (mAppIsInPath) {
|
2011-04-12 13:10:09 -07:00
|
|
|
// 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");
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
|
2011-01-11 00:35:18 -08:00
|
|
|
if (appProtocols[i].essential || aClaimAllTypes) {
|
|
|
|
gconf->SetAppForProtocol(nsDependentCString(appProtocols[i].name),
|
|
|
|
appKeyValue);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-12 13:11:20 -07:00
|
|
|
if (giovfs) {
|
2011-01-11 00:35:18 -08:00
|
|
|
nsresult rv;
|
2011-02-14 08:24:20 -08:00
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
|
|
|
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundle> brandBundle;
|
|
|
|
rv = bundleService->CreateBundle(BRAND_PROPERTIES, getter_AddRefs(brandBundle));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-12-29 03:33:39 -08:00
|
|
|
nsString brandShortName;
|
2013-12-12 17:50:01 -08:00
|
|
|
brandBundle->GetStringFromName(MOZ_UTF16("brandShortName"),
|
2011-02-14 08:24:20 -08:00
|
|
|
getter_Copies(brandShortName));
|
|
|
|
|
|
|
|
// use brandShortName as the application id.
|
|
|
|
NS_ConvertUTF16toUTF8 id(brandShortName);
|
|
|
|
nsCOMPtr<nsIGIOMimeApp> appInfo;
|
|
|
|
rv = giovfs->CreateAppFromCommand(mAppPath,
|
|
|
|
id,
|
|
|
|
getter_AddRefs(appInfo));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-04-12 13:11:20 -07:00
|
|
|
// set handler for the protocols
|
2011-10-10 22:50:08 -07:00
|
|
|
for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
|
2011-04-12 13:11:20 -07:00
|
|
|
if (appProtocols[i].essential || aClaimAllTypes) {
|
|
|
|
appInfo->SetAsDefaultForURIScheme(nsDependentCString(appProtocols[i].name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set handler for .html and xhtml files and MIME types:
|
|
|
|
if (aClaimAllTypes) {
|
|
|
|
// Add mime types for html, xhtml extension and set app to just created appinfo.
|
2011-10-10 22:50:08 -07:00
|
|
|
for (unsigned int i = 0; i < ArrayLength(appTypes); ++i) {
|
2011-04-12 13:11:20 -07:00
|
|
|
appInfo->SetAsDefaultForMimeType(nsDependentCString(appTypes[i].mimeType));
|
|
|
|
appInfo->SetAsDefaultForFileExtensions(nsDependentCString(appTypes[i].extensions));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 21:15:43 -07:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
|
|
if (prefs) {
|
|
|
|
(void) prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, true);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsGNOMEShellService::GetShouldCheckDefaultBrowser(bool* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// If we've already checked, the browser has been started and this is a
|
|
|
|
// new window open, and we don't want to check again.
|
|
|
|
if (mCheckedThisSession) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aResult = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-13 21:10:47 -07:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-10-13 21:10:47 -07:00
|
|
|
return prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsGNOMEShellService::SetShouldCheckDefaultBrowser(bool aShouldCheck)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-10-13 21:10:47 -07:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-10-13 21:10:47 -07:00
|
|
|
return prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-04-02 13:43:12 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGNOMEShellService::GetCanSetDesktopBackground(bool* aResult)
|
|
|
|
{
|
|
|
|
// setting desktop background is currently only supported
|
|
|
|
// for Gnome or desktops using the same GSettings and GConf keys
|
|
|
|
const char* gnomeSession = getenv("GNOME_DESKTOP_SESSION_ID");
|
|
|
|
if (gnomeSession) {
|
|
|
|
*aResult = true;
|
|
|
|
} else {
|
|
|
|
*aResult = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
WriteImage(const nsCString& aPath, imgIContainer* aImage)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-11 10:40:28 -07:00
|
|
|
#if !defined(MOZ_WIDGET_GTK)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
#else
|
|
|
|
nsCOMPtr<nsIImageToPixbuf> imgToPixbuf =
|
|
|
|
do_GetService("@mozilla.org/widget/image-to-gdk-pixbuf;1");
|
|
|
|
if (!imgToPixbuf)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
GdkPixbuf* pixbuf = imgToPixbuf->ConvertImageToPixbuf(aImage);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!pixbuf)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2013-08-21 09:13:50 -07:00
|
|
|
gboolean res = gdk_pixbuf_save(pixbuf, aPath.get(), "png", nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
g_object_unref(pixbuf);
|
|
|
|
return res ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aPosition)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageContent = do_QueryInterface(aElement, &rv);
|
|
|
|
if (!imageContent) return rv;
|
|
|
|
|
|
|
|
// get the image container
|
|
|
|
nsCOMPtr<imgIRequest> request;
|
|
|
|
rv = imageContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(request));
|
|
|
|
if (!request) return rv;
|
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
rv = request->GetImage(getter_AddRefs(container));
|
|
|
|
if (!container) return rv;
|
|
|
|
|
2011-05-12 01:15:16 -07:00
|
|
|
// Set desktop wallpaper filling style
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString options;
|
2011-05-12 01:15:16 -07:00
|
|
|
if (aPosition == BACKGROUND_TILE)
|
2014-05-21 20:48:51 -07:00
|
|
|
options.AssignLiteral("wallpaper");
|
2011-05-12 01:15:16 -07:00
|
|
|
else if (aPosition == BACKGROUND_STRETCH)
|
2014-05-21 20:48:51 -07:00
|
|
|
options.AssignLiteral("stretched");
|
2012-02-01 02:37:55 -08:00
|
|
|
else if (aPosition == BACKGROUND_FILL)
|
2014-05-21 20:48:51 -07:00
|
|
|
options.AssignLiteral("zoom");
|
2012-02-01 02:37:55 -08:00
|
|
|
else if (aPosition == BACKGROUND_FIT)
|
2014-05-21 20:48:51 -07:00
|
|
|
options.AssignLiteral("scaled");
|
2011-05-12 01:15:16 -07:00
|
|
|
else
|
2014-05-21 20:48:51 -07:00
|
|
|
options.AssignLiteral("centered");
|
2011-05-12 01:15:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Write the background file to the home directory.
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString filePath(PR_GetEnv("HOME"));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// get the product brand name from localized strings
|
|
|
|
nsString brandName;
|
|
|
|
nsCID bundleCID = NS_STRINGBUNDLESERVICE_CID;
|
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(bundleCID));
|
|
|
|
if (bundleService) {
|
|
|
|
nsCOMPtr<nsIStringBundle> brandBundle;
|
|
|
|
rv = bundleService->CreateBundle(BRAND_PROPERTIES,
|
|
|
|
getter_AddRefs(brandBundle));
|
|
|
|
if (NS_SUCCEEDED(rv) && brandBundle) {
|
2013-12-12 17:50:01 -08:00
|
|
|
rv = brandBundle->GetStringFromName(MOZ_UTF16("brandShortName"),
|
2007-03-22 10:30:00 -07:00
|
|
|
getter_Copies(brandName));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// build the file name
|
|
|
|
filePath.Append('/');
|
|
|
|
filePath.Append(NS_ConvertUTF16toUTF8(brandName));
|
2014-05-21 20:48:51 -07:00
|
|
|
filePath.AppendLiteral("_wallpaper.png");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// write the image to a file in the home dir
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
rv = WriteImage(filePath, container);
|
2011-05-12 01:15:16 -07:00
|
|
|
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 =
|
|
|
|
do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
|
|
|
|
if (gsettings) {
|
|
|
|
nsCOMPtr<nsIGSettingsCollection> background_settings;
|
|
|
|
gsettings->GetCollectionForSchema(
|
|
|
|
NS_LITERAL_CSTRING(kDesktopBGSchema), getter_AddRefs(background_settings));
|
|
|
|
if (background_settings) {
|
2013-08-21 09:13:50 -07:00
|
|
|
gchar *file_uri = g_filename_to_uri(filePath.get(), nullptr, nullptr);
|
2011-05-12 01:15:16 -07:00
|
|
|
if (!file_uri)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
background_settings->SetString(NS_LITERAL_CSTRING(kDesktopOptionGSKey),
|
|
|
|
options);
|
|
|
|
|
|
|
|
background_settings->SetString(NS_LITERAL_CSTRING(kDesktopImageGSKey),
|
|
|
|
nsDependentCString(file_uri));
|
|
|
|
g_free(file_uri);
|
|
|
|
background_settings->SetBoolean(NS_LITERAL_CSTRING(kDesktopDrawBGGSKey),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2011-05-12 01:15:16 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if the file was written successfully, set it as the system wallpaper
|
|
|
|
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
|
|
|
|
2011-04-12 13:11:20 -07:00
|
|
|
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);
|
2011-10-17 07:59:28 -07:00
|
|
|
gconf->SetBool(NS_LITERAL_CSTRING(kDesktopDrawBGKey), true);
|
2011-04-12 13:11:20 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-09-08 03:06:32 -07:00
|
|
|
#define COLOR_16_TO_8_BIT(_c) ((_c) >> 8)
|
2009-04-17 01:17:29 -07:00
|
|
|
#define COLOR_8_TO_16_BIT(_c) ((_c) << 8 | (_c))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsGNOMEShellService::GetDesktopBackgroundColor(uint32_t *aColor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-05-12 01:15:16 -07:00
|
|
|
nsCOMPtr<nsIGSettingsService> gsettings =
|
|
|
|
do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIGSettingsCollection> background_settings;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString background;
|
2011-05-12 01:15:16 -07:00
|
|
|
|
|
|
|
if (gsettings) {
|
|
|
|
gsettings->GetCollectionForSchema(
|
|
|
|
NS_LITERAL_CSTRING(kDesktopBGSchema), getter_AddRefs(background_settings));
|
|
|
|
if (background_settings) {
|
|
|
|
background_settings->GetString(NS_LITERAL_CSTRING(kDesktopColorGSKey),
|
|
|
|
background);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!background_settings) {
|
|
|
|
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
|
|
|
if (gconf)
|
|
|
|
gconf->GetString(NS_LITERAL_CSTRING(kDesktopColorKey), background);
|
2011-04-12 13:11:20 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (background.IsEmpty()) {
|
|
|
|
*aColor = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-08 03:06:32 -07:00
|
|
|
GdkColor color;
|
|
|
|
gboolean success = gdk_color_parse(background.get(), &color);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-08 03:06:32 -07:00
|
|
|
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-08 03:06:32 -07:00
|
|
|
*aColor = COLOR_16_TO_8_BIT(color.red) << 16 |
|
|
|
|
COLOR_16_TO_8_BIT(color.green) << 8 |
|
|
|
|
COLOR_16_TO_8_BIT(color.blue);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-22 08:56:38 -07:00
|
|
|
ColorToCString(uint32_t aColor, nsCString& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-08 03:06:32 -07:00
|
|
|
// The #rrrrggggbbbb format is used to match gdk_color_to_string()
|
|
|
|
char *buf = aResult.BeginWriting(13);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!buf)
|
|
|
|
return;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t red = COLOR_8_TO_16_BIT((aColor >> 16) & 0xff);
|
|
|
|
uint16_t green = COLOR_8_TO_16_BIT((aColor >> 8) & 0xff);
|
|
|
|
uint16_t blue = COLOR_8_TO_16_BIT(aColor & 0xff);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-17 01:17:29 -07:00
|
|
|
PR_snprintf(buf, 14, "#%04x%04x%04x", red, green, blue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsGNOMEShellService::SetDesktopBackgroundColor(uint32_t aColor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-17 01:17:29 -07:00
|
|
|
NS_ASSERTION(aColor <= 0xffffff, "aColor has extra bits");
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString colorString;
|
2011-05-12 01:15:16 -07:00
|
|
|
ColorToCString(aColor, colorString);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIGSettingsService> gsettings =
|
|
|
|
do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
|
|
|
|
if (gsettings) {
|
|
|
|
nsCOMPtr<nsIGSettingsCollection> background_settings;
|
|
|
|
gsettings->GetCollectionForSchema(
|
|
|
|
NS_LITERAL_CSTRING(kDesktopBGSchema), getter_AddRefs(background_settings));
|
|
|
|
if (background_settings) {
|
|
|
|
background_settings->SetString(NS_LITERAL_CSTRING(kDesktopColorGSKey),
|
|
|
|
colorString);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
|
|
|
|
2011-04-12 13:11:20 -07:00
|
|
|
if (gconf) {
|
|
|
|
gconf->SetString(NS_LITERAL_CSTRING(kDesktopColorKey), colorString);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsGNOMEShellService::OpenApplication(int32_t aApplication)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString scheme;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aApplication == APPLICATION_MAIL)
|
2014-05-21 20:48:51 -07:00
|
|
|
scheme.AssignLiteral("mailto");
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (aApplication == APPLICATION_NEWS)
|
2014-05-21 20:48:51 -07:00
|
|
|
scheme.AssignLiteral("news");
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2011-04-12 13:11:20 -07:00
|
|
|
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
|
|
|
|
if (giovfs) {
|
|
|
|
nsCOMPtr<nsIGIOMimeApp> gioApp;
|
|
|
|
giovfs->GetAppForURIScheme(scheme, getter_AddRefs(gioApp));
|
|
|
|
if (gioApp)
|
|
|
|
return gioApp->Launch(EmptyCString());
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
|
2011-04-12 13:11:20 -07:00
|
|
|
if (!gconf)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool enabled;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString appCommand;
|
2007-03-22 10:30:00 -07:00
|
|
|
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.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool requiresTerminal;
|
2007-03-22 10:30:00 -07:00
|
|
|
gconf->HandlerRequiresTerminal(scheme, &requiresTerminal);
|
|
|
|
if (requiresTerminal)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Perform shell argument expansion
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
2013-08-21 09:13:50 -07:00
|
|
|
if (!g_shell_parse_argv(appCommand.get(), &argc, &argv, nullptr))
|
2007-03-22 10:30:00 -07:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
newArgv[newArgc] = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-21 09:13:50 -07:00
|
|
|
gboolean err = g_spawn_async(nullptr, newArgv, nullptr, G_SPAWN_SEARCH_PATH,
|
|
|
|
nullptr, nullptr, nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
g_strfreev(argv);
|
|
|
|
delete[] newArgv;
|
|
|
|
|
|
|
|
return err ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-05 19:08:30 -07:00
|
|
|
nsGNOMEShellService::OpenApplicationWithURI(nsIFile* aApplication, const nsACString& aURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIProcess> process =
|
|
|
|
do_CreateInstance("@mozilla.org/process/util;1", &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = process->Init(aApplication);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
const nsCString spec(aURI);
|
|
|
|
const char* specStr = spec.get();
|
2011-10-17 07:59:28 -07:00
|
|
|
return process->Run(false, &specStr, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-05 19:08:30 -07:00
|
|
|
nsGNOMEShellService::GetDefaultFeedReader(nsIFile** _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|