Browse Source

[Navigator] Add the replacement shell service and make it build

master
Matt A. Tobin 2 years ago committed by Roy Tam
parent
commit
7c9f727e06
  1. 20
      navigator/components/build/moz.build
  2. 54
      navigator/components/build/nsModule.cpp
  3. 2
      navigator/components/moz.build
  4. 217
      navigator/components/shell/content/setDesktopBackground.js
  5. 84
      navigator/components/shell/content/setDesktopBackground.xul
  6. 11
      navigator/components/shell/jar.mn
  7. 15
      navigator/components/shell/locale/setDesktopBackground.dtd
  8. 13
      navigator/components/shell/locale/shellservice.properties
  9. 12
      navigator/components/shell/moz.build
  10. 16
      navigator/components/shell/public/moz.build
  11. 19
      navigator/components/shell/public/nsIGNOMEShellService.idl
  12. 15
      navigator/components/shell/public/nsIMacShellService.idl
  13. 95
      navigator/components/shell/public/nsIShellService.idl
  14. 17
      navigator/components/shell/public/nsIWindowsShellService.idl
  15. 110
      navigator/components/shell/src/ShellService.jsm
  16. 27
      navigator/components/shell/src/moz.build
  17. 636
      navigator/components/shell/src/nsGNOMEShellService.cpp
  18. 37
      navigator/components/shell/src/nsGNOMEShellService.h
  19. 433
      navigator/components/shell/src/nsMacShellService.cpp
  20. 33
      navigator/components/shell/src/nsMacShellService.h
  21. 30
      navigator/components/shell/src/nsSetDefaultBrowser.js
  22. 3
      navigator/components/shell/src/nsSetDefaultBrowser.manifest
  23. 18
      navigator/components/shell/src/nsShellService.h
  24. 1275
      navigator/components/shell/src/nsWindowsShellService.cpp
  25. 38
      navigator/components/shell/src/nsWindowsShellService.h
  26. 3
      navigator/themes/classic/jar.mn
  27. BIN
      navigator/themes/classic/navigator/monitor.png
  28. BIN
      navigator/themes/classic/navigator/monitor_16-10.png
  29. 18
      navigator/themes/classic/navigator/setDesktopBackground.css
  30. 3
      navigator/themes/modern/jar.mn
  31. BIN
      navigator/themes/modern/navigator/monitor.png
  32. BIN
      navigator/themes/modern/navigator/monitor_16-10.png
  33. 18
      navigator/themes/modern/navigator/setDesktopBackground.css

20
navigator/components/build/moz.build

@ -12,18 +12,24 @@ XPCOMBinaryComponent('navigatorcomps')
LOCAL_INCLUDES += [
'../dirprovider/src',
'../feeds/src',
# '../shell/src',
]
USE_LIBS += [
'xpcomglue_s',
'xul',
'../shell/src',
]
if CONFIG['OS_ARCH'] == 'WINNT':
OS_LIBS += [
'esent',
'netapi32',
'ole32',
'shell32',
'shlwapi',
'version',
]
DELAYLOAD_DLLS += [
'esent.dll',
'netapi32.dll',
]
OS_LIBS += CONFIG['TK_LIBS']
# Mac: Need to link with CoreFoundation for Mac Migrators (PList reading code)
# GTK2: Need to link with glib for GNOME shell service
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('cocoa', 'gtk2', 'gtk3'):
OS_LIBS += CONFIG['TK_LIBS']

54
navigator/components/build/nsModule.cpp

@ -9,39 +9,67 @@
#include "nsRDFCID.h"
#include "nsFeedSniffer.h"
#if defined(XP_WIN)
#include "nsWindowsShellService.h"
#elif defined(XP_MACOSX)
#include "nsMacShellService.h"
#elif defined(MOZ_WIDGET_GTK)
#include "nsGNOMEShellService.h"
#endif
/////////////////////////////////////////////////////////////////////////////
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSuiteDirectoryProvider)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFeedSniffer)
#if defined(XP_WIN)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindowsShellService)
#elif defined(XP_MACOSX)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacShellService)
#elif defined(MOZ_WIDGET_GTK)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGNOMEShellService, Init)
#endif
NS_DEFINE_NAMED_CID(NS_SUITEDIRECTORYPROVIDER_CID);
NS_DEFINE_NAMED_CID(NS_FEEDSNIFFER_CID);
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(MOZ_WIDGET_GTK)
NS_DEFINE_NAMED_CID(NS_SHELLSERVICE_CID);
#endif
/////////////////////////////////////////////////////////////////////////////
static const mozilla::Module::CIDEntry kSuiteCIDs[] = {
{ &kNS_SUITEDIRECTORYPROVIDER_CID, false, NULL, nsSuiteDirectoryProviderConstructor },
{ &kNS_FEEDSNIFFER_CID, false, NULL, nsFeedSnifferConstructor },
{ NULL }
static const mozilla::Module::CIDEntry kNavigatorCIDs[] = {
{ &kNS_SUITEDIRECTORYPROVIDER_CID, false, nullptr, nsSuiteDirectoryProviderConstructor },
{ &kNS_FEEDSNIFFER_CID, false, nullptr, nsFeedSnifferConstructor },
#if defined(XP_WIN)
{ &kNS_SHELLSERVICE_CID, false, nullptr, nsWindowsShellServiceConstructor },
#elif defined(XP_MACOSX)
{ &kNS_SHELLSERVICE_CID, false, nullptr, nsGNOMEShellServiceConstructor },
#elif defined(MOZ_WIDGET_GTK)
{ &kNS_SHELLSERVICE_CID, false, nullptr, nsMacShellServiceConstructor },
#endif
{ nullptr }
};
static const mozilla::Module::ContractIDEntry kSuiteContracts[] = {
static const mozilla::Module::ContractIDEntry kNavigatorContracts[] = {
{ NS_SUITEDIRECTORYPROVIDER_CONTRACTID, &kNS_SUITEDIRECTORYPROVIDER_CID },
{ NS_FEEDSNIFFER_CONTRACTID, &kNS_FEEDSNIFFER_CID },
{ NULL }
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(MOZ_WIDGET_GTK)
{ NS_SHELLSERVICE_CONTRACTID, &kNS_SHELLSERVICE_CID },
#endif
{ nullptr }
};
static const mozilla::Module::CategoryEntry kSuiteCategories[] = {
static const mozilla::Module::CategoryEntry kNavigatorCategories[] = {
{ XPCOM_DIRECTORY_PROVIDER_CATEGORY, "suite-directory-provider", NS_SUITEDIRECTORYPROVIDER_CONTRACTID },
{ NS_CONTENT_SNIFFER_CATEGORY, "Feed Sniffer", NS_FEEDSNIFFER_CONTRACTID },
{ NULL }
{ nullptr }
};
static const mozilla::Module kSuiteModule = {
static const mozilla::Module kNavigatorModule = {
mozilla::Module::kVersion,
kSuiteCIDs,
kSuiteContracts,
kSuiteCategories
kNavigatorCIDs,
kNavigatorContracts,
kNavigatorCategories
};
NSMODULE_DEFN(SuiteModule) = &kSuiteModule;
NSMODULE_DEFN(nsNavigatorCompsModule) = &kNavigatorModule;

2
navigator/components/moz.build

@ -16,7 +16,7 @@ DIRS += [
'preferences',
'search',
'sessionstore',
# 'shell',
'shell',
'sidebar',
'smile',
]

217
navigator/components/shell/content/setDesktopBackground.js

@ -0,0 +1,217 @@
/* 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/. */
var Ci = Components.interfaces;
var gSetBackground = {
#ifdef XP_MACOSX
_position : "STRETCH",
_backgroundColor : undefined,
#else
_position : "",
_backgroundColor : 0,
#endif
_screenWidth : 0,
_screenHeight : 0,
_image : null,
_canvas : null,
get _shell()
{
return Components.classes["@binaryoutcast.com/navigator/shell-service;1"]
.getService(Ci.nsIShellService);
},
load: function ()
{
this._canvas = document.getElementById("screen");
this._screenWidth = screen.width;
this._screenHeight = screen.height;
#ifdef XP_MACOSX
document.documentElement.getButton("accept").hidden = true;
#endif
if (this._screenWidth / this._screenHeight >= 1.6)
document.getElementById("monitor").setAttribute("aspectratio", "16:10");
#ifdef XP_WIN
// Hide fill + fit options if < Win7 since they don't work.
var version = Components.classes["@mozilla.org/system-info;1"]
.getService(Ci.nsIPropertyBag2)
.getProperty("version");
var isWindows7OrHigher = (parseFloat(version) >= 6.1);
if (!isWindows7OrHigher) {
document.getElementById("fillPosition").hidden = true;
document.getElementById("fitPosition").hidden = true;
}
#endif
// make sure that the correct dimensions will be used
setTimeout(function(self) {
self.init(window.arguments[0]);
}, 0, this);
},
init: function (aImage)
{
this._image = aImage;
// set the size of the coordinate space
this._canvas.width = this._canvas.clientWidth;
this._canvas.height = this._canvas.clientHeight;
var ctx = this._canvas.getContext("2d");
ctx.scale(this._canvas.clientWidth / this._screenWidth, this._canvas.clientHeight / this._screenHeight);
#ifdef XP_MACOSX
// Make sure to reset the button state in case the user has already
// set an image as their desktop background.
var setDesktopBackground = document.getElementById("setDesktopBackground");
setDesktopBackground.hidden = false;
var bundle = document.getElementById("backgroundBundle");
setDesktopBackground.label = bundle.getString("DesktopBackgroundSet");
setDesktopBackground.disabled = false;
document.getElementById("showDesktopPreferences").hidden = true;
#else
this._initColor();
#endif
this.updatePosition();
},
setDesktopBackground: function ()
{
#ifdef XP_MACOSX
Components.classes["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService)
.addObserver(this, "shell:desktop-background-changed", false);
var bundle = document.getElementById("backgroundBundle");
var setDesktopBackground = document.getElementById("setDesktopBackground");
setDesktopBackground.disabled = true;
setDesktopBackground.label = bundle.getString("DesktopBackgroundDownloading");
#else
document.persist("menuPosition", "value");
this._shell.desktopBackgroundColor = this._hexStringToLong(this._backgroundColor);
#endif
this._shell.setDesktopBackground(this._image,
Ci.nsIShellService["BACKGROUND_" + this._position]);
},
updatePosition: function ()
{
var ctx = this._canvas.getContext("2d");
ctx.clearRect(0, 0, this._screenWidth, this._screenHeight);
#ifndef XP_MACOSX
this._position = document.getElementById("menuPosition").value;
#endif
switch (this._position) {
case "TILE":
ctx.save();
ctx.fillStyle = ctx.createPattern(this._image, "repeat");
ctx.fillRect(0, 0, this._screenWidth, this._screenHeight);
ctx.restore();
break;
case "STRETCH":
ctx.drawImage(this._image, 0, 0, this._screenWidth, this._screenHeight);
break;
case "CENTER": {
let x = (this._screenWidth - this._image.naturalWidth) / 2;
let y = (this._screenHeight - this._image.naturalHeight) / 2;
ctx.drawImage(this._image, x, y);
break;
}
case "FILL": {
// Try maxing width first, overflow height.
let widthRatio = this._screenWidth / this._image.naturalWidth;
let width = this._image.naturalWidth * widthRatio;
let height = this._image.naturalHeight * widthRatio;
if (height < this._screenHeight) {
// Height less than screen, max height and overflow width.
let heightRatio = this._screenHeight / this._image.naturalHeight;
width = this._image.naturalWidth * heightRatio;
height = this._image.naturalHeight * heightRatio;
}
let x = (this._screenWidth - width) / 2;
let y = (this._screenHeight - height) / 2;
ctx.drawImage(this._image, x, y, width, height);
break;
}
case "FIT": {
// Try maxing width first, top and bottom borders.
let widthRatio = this._screenWidth / this._image.naturalWidth;
let width = this._image.naturalWidth * widthRatio;
let height = this._image.naturalHeight * widthRatio;
let x = 0;
let y = (this._screenHeight - height) / 2;
if (height > this._screenHeight) {
// Height overflow, maximise height, side borders.
let heightRatio = this._screenHeight / this._image.naturalHeight;
width = this._image.naturalWidth * heightRatio;
height = this._image.naturalHeight * heightRatio;
x = (this._screenWidth - width) / 2;
y = 0;
}
ctx.drawImage(this._image, x, y, width, height);
break;
}
}
}
};
#ifdef XP_MACOSX
gSetBackground["observe"] = function (aSubject, aTopic, aData)
{
if (aTopic == "shell:desktop-background-changed") {
document.getElementById("setDesktopBackground").hidden = true;
document.getElementById("showDesktopPreferences").hidden = false;
Components.classes["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService)
.removeObserver(this, "shell:desktop-background-changed");
}
};
gSetBackground["showDesktopPrefs"] = function()
{
this._shell.openApplication(Ci.nsIMacShellService.APPLICATION_DESKTOP);
};
#else
gSetBackground["_initColor"] = function ()
{
var color = this._shell.desktopBackgroundColor;
const rMask = 4294901760;
const gMask = 65280;
const bMask = 255;
var r = (color & rMask) >> 16;
var g = (color & gMask) >> 8;
var b = (color & bMask);
this.updateColor(this._rgbToHex(r, g, b));
var colorpicker = document.getElementById("desktopColor");
colorpicker.color = this._backgroundColor;
};
gSetBackground["updateColor"] = function (aColor)
{
this._backgroundColor = aColor;
this._canvas.style.backgroundColor = aColor;
};
// Converts a color string in the format "#RRGGBB" to an integer.
gSetBackground["_hexStringToLong"] = function (aString)
{
return parseInt(aString.substring(1, 3), 16) << 16 |
parseInt(aString.substring(3, 5), 16) << 8 |
parseInt(aString.substring(5, 7), 16);
};
gSetBackground["_rgbToHex"] = function (aR, aG, aB)
{
return "#" + [aR, aG, aB].map(aInt => aInt.toString(16).replace(/^(.)$/, "0$1"))
.join("").toUpperCase();
};
#endif

84
navigator/components/shell/content/setDesktopBackground.xul

@ -0,0 +1,84 @@
<?xml version="1.0"?> <!-- -*- Mode: HTML -*- -->
# 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/.
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://navigator/skin/setDesktopBackground.css" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://navigator/locale/setDesktopBackground.dtd">
#ifdef XP_MACOSX
<?xul-overlay href="chrome://browser/content/macBrowserOverlay.xul"?>
#endif
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
windowtype="Shell:SetDesktopBackground"
#ifndef XP_MACOSX
buttons="accept,cancel"
#else
buttons="accept"
#endif
buttonlabelaccept="&setDesktopBackground.title;"
onload="gSetBackground.load();"
ondialogaccept="gSetBackground.setDesktopBackground();"
title="&setDesktopBackground.title;"
style="width: 30em;">
<stringbundle id="backgroundBundle"
src="chrome://navigator/locale/shellservice.properties"/>
<script type="application/javascript" src="chrome://communicator/content/utilityOverlay.js"/>
<script type="application/javascript" src="chrome://navigator/content/setDesktopBackground.js"/>
<script type="application/javascript" src="chrome://global/content/contentAreaUtils.js"/>
#ifndef XP_MACOSX
<hbox align="center">
<label value="&position.label;"/>
<menulist id="menuPosition"
label="&position.label;"
oncommand="gSetBackground.updatePosition();">
<menupopup>
<menuitem label="&center.label;" value="CENTER"/>
<menuitem label="&tile.label;" value="TILE"/>
<menuitem label="&stretch.label;" value="STRETCH"/>
<menuitem label="&fill.label;" value="FILL" id="fillPosition"/>
<menuitem label="&fit.label;" value="FIT" id="fitPosition"/>
</menupopup>
</menulist>
<spacer flex="1"/>
<label value="&color.label;"/>
<colorpicker id="desktopColor"
type="button"
onchange="gSetBackground.updateColor(this.color);"/>
</hbox>
#endif
<groupbox align="center">
<caption label="&preview.label;"/>
<stack>
<!-- if width and height are not present, they default to 300x150 and stretch the stack -->
<html:canvas id="screen" width="1" height="1"/>
<image id="monitor"/>
</stack>
</groupbox>
#ifdef XP_MACOSX
<separator/>
<hbox align="right">
<button id="setDesktopBackground"
label="&setDesktopBackground.title;"
oncommand="gSetBackground.setDesktopBackground();"/>
<button id="showDesktopPreferences"
label="&openDesktopPrefs.label;"
oncommand="gSetBackground.showDesktopPrefs();"
hidden="true"/>
</hbox>
#endif
#ifdef XP_MACOSX
#include ../../../base/content/browserMountPoints.inc
#endif
</dialog>

11
navigator/components/shell/jar.mn

@ -0,0 +1,11 @@
# 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/.
navigator.jar:
* content/navigator/setDesktopBackground.xul (content/setDesktopBackground.xul)
* content/navigator/setDesktopBackground.js (content/setDesktopBackground.js)
en-US.jar:
locale/en-US/navigator/setDesktopBackground.dtd (locale/setDesktopBackground.dtd)
locale/en-US/navigator/shellservice.properties (locale/shellservice.properties)

15
navigator/components/shell/locale/setDesktopBackground.dtd

@ -0,0 +1,15 @@
<!-- 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/. -->
<!ENTITY position.label "Position:">
<!ENTITY tile.label "Tile">
<!ENTITY center.label "Center">
<!ENTITY stretch.label "Stretch">
<!ENTITY fill.label "Fill">
<!ENTITY fit.label "Fit">
<!ENTITY preview.label "Preview">
<!ENTITY color.label "Color:">
<!ENTITY setDesktopBackground.title "Set Desktop Wallpaper">
<!ENTITY openDesktopPrefs.label "Open Desktop Preferences">
<!ENTITY closeWindow.key "w">

13
navigator/components/shell/locale/shellservice.properties

@ -0,0 +1,13 @@
# 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/.
optionsLabel=%S &Preferences
safeModeLabel=%S &Safe Mode
setDefaultBrowserTitle=Default Web Client
setDefaultBrowserMessage=%S is not currently set as your default web client. Would you like to make it the default?
setDefaultBrowserDontAsk=Always check on startup.
alreadyDefaultBrowser=%S is already set as your default web client.
desktopBackgroundLeafNameWin=Desktop Background.bmp
DesktopBackgroundDownloading=Saving Picture…
DesktopBackgroundSet=Set Desktop Wallpaper

12
navigator/components/shell/moz.build

@ -0,0 +1,12 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
DIRS += [
'public',
'src',
]
JAR_MANIFESTS += ['jar.mn']

16
navigator/components/shell/public/moz.build

@ -0,0 +1,16 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
XPIDL_SOURCES += ['nsIShellService.idl']
if CONFIG['OS_ARCH'] == 'WINNT':
XPIDL_SOURCES += ['nsIWindowsShellService.idl']
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
XPIDL_SOURCES += ['nsIMacShellService.idl']
elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
XPIDL_SOURCES += ['nsIGNOMEShellService.idl']
XPIDL_MODULE = 'shellservice'

19
navigator/components/shell/public/nsIGNOMEShellService.idl

@ -0,0 +1,19 @@
/* 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/. */
#include "nsIShellService.idl"
[scriptable, uuid(2ce5c803-edcd-443d-98eb-ceba86d02d13)]
interface nsIGNOMEShellService : nsIShellService
{
/**
* Used to determine whether or not to offer "Set as desktop background"
* functionality. Even if shell service is available it is not
* guaranteed that it is able to set the background for every desktop
* which is especially true for Linux with its many different desktop
* environments.
*/
readonly attribute boolean canSetDesktopBackground;
};

15
navigator/components/shell/public/nsIMacShellService.idl

@ -0,0 +1,15 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsIShellService.idl"
[scriptable, uuid(387fdc80-0077-4b60-a0d9-d9e80a83ba64)]
interface nsIMacShellService : nsIShellService
{
const long APPLICATION_KEYCHAIN_ACCESS = 2;
const long APPLICATION_NETWORK = 3;
const long APPLICATION_DESKTOP = 4;
};

95
navigator/components/shell/public/nsIShellService.idl

@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsISupports.idl"
interface nsIDOMElement;
interface nsIFile;
[scriptable, uuid(2d1a95e4-5bd8-4eeb-b0a8-c1455fd2a357)]
interface nsIShellService : nsISupports
{
/**
* Determines whether or not Firefox is the "Default Browser."
* This is simply whether or not Firefox is registered to handle
* http links.
*
* @param aStartupCheck true if this is the check being performed
* by the first browser window at startup,
* false otherwise.
* @param aForAllTypes true if the check should be made for HTTP and HTML.
* false if the check should be made for HTTP only.
* This parameter may be ignored on some platforms.
*/
boolean isDefaultBrowser(in boolean aStartupCheck,
[optional] in boolean aForAllTypes);
/**
* Registers Firefox as the "Default Browser."
*
* @param aClaimAllTypes Register Firefox as the handler for
* additional protocols (ftp, chrome etc)
* and web documents (.html, .xhtml etc).
* @param aForAllUsers Whether or not Firefox should attempt
* to become the default browser for all
* users on a multi-user system.
*/
void setDefaultBrowser(in boolean aClaimAllTypes, in boolean aForAllUsers);
/**
* Flags for positioning/sizing of the Desktop Background image.
*/
const long BACKGROUND_TILE = 1;
const long BACKGROUND_STRETCH = 2;
const long BACKGROUND_CENTER = 3;
const long BACKGROUND_FILL = 4;
const long BACKGROUND_FIT = 5;
/**
* Sets the desktop background image using either the HTML <IMG>
* element supplied or the background image of the element supplied.
*
* @param aImageElement Either a HTML <IMG> element or an element with
* a background image from which to source the
* background image.
* @param aPosition How to place the image on the desktop
*/
void setDesktopBackground(in nsIDOMElement aElement, in long aPosition);
/**
* Constants identifying applications that can be opened with
* openApplication.
*/
const long APPLICATION_MAIL = 0;
const long APPLICATION_NEWS = 1;
/**
* Opens the application specified. If more than one application of the
* given type is available on the system, the default or "preferred"
* application is used.
*/
void openApplication(in long aApplication);
/**
* The desktop background color, visible when no background image is
* used, or if the background image is centered and does not fill the
* entire screen. A rgb value, where (r << 16 | g << 8 | b)
*/
attribute unsigned long desktopBackgroundColor;
/**
* Opens an application with a specific URI to load.
* @param application
* The application file (or bundle directory, on OS X)
* @param uri
* The uri to be loaded by the application
*/
void openApplicationWithURI(in nsIFile aApplication, in ACString aURI);
/**
* The default system handler for web feeds
*/
readonly attribute nsIFile defaultFeedReader;
};

17
navigator/components/shell/public/nsIWindowsShellService.idl

@ -0,0 +1,17 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsIShellService.idl"
[scriptable, uuid(f8a26b94-49e5-4441-8fbc-315e0b4f22ef)]
interface nsIWindowsShellService : nsIShellService
{
/**
* Provides the shell service an opportunity to do some Win7+ shortcut
* maintenance needed on initial startup of the browser.
*/
void shortcutMaintenance();
};

110
navigator/components/shell/src/ShellService.jsm

@ -0,0 +1,110 @@
/* 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/. */
"use strict";
this.EXPORTED_SYMBOLS = ["ShellService"];
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "WindowsRegistry",
"resource://gre/modules/WindowsRegistry.jsm");
/**
* Internal functionality to save and restore the docShell.allow* properties.
*/
var ShellServiceInternal = {
/**
* Used to determine whether or not to offer "Set as desktop background"
* functionality. Even if shell service is available it is not
* guaranteed that it is able to set the background for every desktop
* which is especially true for Linux with its many different desktop
* environments.
*/
get canSetDesktopBackground() {
#ifdef XP_LINUX
if (this.shellService) {
let linuxShellService = this.shellService
.QueryInterface(Ci.nsIGNOMEShellService);
return linuxShellService.canSetDesktopBackground;
}
#elif defined(XP_WIN) || defined(XP_MACOSX)
return true;
#else
return false;
#endif
},
/**
* Used to determine whether or not to show a "Set Default Browser"
* query dialog. This attribute is true if the application is starting
* up and "browser.shell.checkDefaultBrowser" is true, otherwise it
* is false.
*/
_checkedThisSession: false,
get shouldCheckDefaultBrowser() {
// 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 (this._checkedThisSession) {
return false;
}
if (!Services.prefs.getBoolPref("browser.shell.checkDefaultBrowser")) {
return false;
}
#ifdef XP_WIN
let optOutValue = WindowsRegistry.readRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
"Software\\Mozilla\\Borealis",
"DefaultBrowserOptOut");
WindowsRegistry.removeRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
"Software\\Mozilla\\Borealis",
"DefaultBrowserOptOut");
if (optOutValue == "True") {
Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", false);
return false;
}
#endif
return true;
},
set shouldCheckDefaultBrowser(shouldCheck) {
Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", !!shouldCheck);
},
isDefaultBrowser(startupCheck, forAllTypes) {
// If this is the first browser window, maintain internal state that we've
// checked this session (so that subsequent window opens don't show the
// default browser dialog).
if (startupCheck) {
this._checkedThisSession = true;
}
if (this.shellService) {
return this.shellService.isDefaultBrowser(startupCheck, forAllTypes);
}
return false;
}
};
XPCOMUtils.defineLazyServiceGetter(ShellServiceInternal, "shellService",
"@mozilla.org/browser/shell-service;1", Ci.nsIShellService);
/**
* The external API exported by this module.
*/
this.ShellService = new Proxy(ShellServiceInternal, {
get(target, name) {
if (name in target) {
return target[name];
}
if (target.shellService) {
return target.shellService[name];
}
Services.console.logStringMessage(`${name} not found in ShellService: ${target.shellService}`);
return undefined;
}
});

27
navigator/components/shell/src/moz.build

@ -0,0 +1,27 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
if CONFIG['OS_ARCH'] == 'WINNT':
SOURCES += ['nsWindowsShellService.cpp']
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
SOURCES += ['nsMacShellService.cpp']
elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
SOURCES += ['nsGNOMEShellService.cpp']
if SOURCES:
FINAL_LIBRARY = 'navigatorcomps'
EXTRA_COMPONENTS += [
'nsSetDefaultBrowser.js',
'nsSetDefaultBrowser.manifest',
]
EXTRA_PP_JS_MODULES += ['ShellService.jsm']
for var in ('MOZ_APP_NAME', 'MOZ_APP_VERSION'):
DEFINES[var] = '"%s"' % CONFIG[var]
CXXFLAGS += CONFIG['TK_CFLAGS']

636
navigator/components/shell/src/nsGNOMEShellService.cpp

@ -0,0 +1,636 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "mozilla/ArrayUtils.h"
#include "nsCOMPtr.h"
#include "nsGNOMEShellService.h"
#include "nsIServiceManager.h"
#include "nsIFile.h"
#include "nsIProperties.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIPrefService.h"
#include "prenv.h"
#include "nsStringAPI.h"
#include "nsIGConfService.h"
#include "nsIGIOService.h"
#include "nsIGSettingsService.h"
#include "nsIStringBundle.h"
#include "nsIOutputStream.h"
#include "nsIProcess.h"
#include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIImageLoadingContent.h"
#include "imgIRequest.h"
#include "imgIContainer.h"
#include "mozilla/Sprintf.h"
#if defined(MOZ_WIDGET_GTK)
#include "nsIImageToPixbuf.h"
#endif
#include "nsXULAppAPI.h"
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <limits.h>
#include <stdlib.h>
using namespace mozilla;
struct ProtocolAssociation
{
const char *name;
bool essential;
};
struct MimeTypeAssociation
{
const char *mimeType;
const char *extensions;
};
static const ProtocolAssociation appProtocols[] = {
{ "http", true },
{ "https", true },
{ "ftp", false },
{ "chrome", false }
};
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";
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";
nsresult
nsGNOMEShellService::Init()
{
nsresult rv;
// GConf, GSettings or GIO _must_ be available, or we do not allow
// CreateInstance to succeed.
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
nsCOMPtr<nsIGIOService> giovfs =
do_GetService(NS_GIOSERVICE_CONTRACTID);
nsCOMPtr<nsIGSettingsService> gsettings =
do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
if (!gconf && !giovfs && !gsettings)
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.
mUseLocaleFilenames = PR_GetEnv("G_BROKEN_FILENAMES") != nullptr;
if (GetAppPathFromLauncher())
return NS_OK;
nsCOMPtr<nsIProperties> dirSvc
(do_GetService("@mozilla.org/file/directory_service;1"));
NS_ENSURE_TRUE(dirSvc, NS_ERROR_NOT_AVAILABLE);
nsCOMPtr<nsIFile> appPath;
rv = dirSvc->Get(XRE_EXECUTABLE_FILE, NS_GET_IID(nsIFile),
getter_AddRefs(appPath));
NS_ENSURE_SUCCESS(rv, rv);
return appPath->GetNativePath(mAppPath);
}
NS_IMPL_ISUPPORTS(nsGNOMEShellService, nsIGNOMEShellService, nsIShellService)
bool
nsGNOMEShellService::GetAppPathFromLauncher()
{
gchar *tmp;
const char *launcher = PR_GetEnv("MOZ_APP_LAUNCHER");
if (!launcher)
return false;
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))
mAppIsInPath = true;
g_free(fullpath);
} else {
tmp = g_find_program_in_path(launcher);
if (!tmp)
return false;
mAppPath = tmp;
mAppIsInPath = true;
}
g_free(tmp);
return true;
}
bool
nsGNOMEShellService::KeyMatchesAppName(const char *aKeyValue) const
{
gchar *commandPath;
if (mUseLocaleFilenames) {
gchar *nativePath = g_filename_from_utf8(aKeyValue, -1,
nullptr, nullptr, nullptr);
if (!nativePath) {
NS_ERROR("Error converting path to filesystem encoding");
return false;
}
commandPath = g_find_program_in_path(nativePath);
g_free(nativePath);
} else {
commandPath = g_find_program_in_path(aKeyValue);
}
if (!commandPath)
return false;
bool matches = mAppPath.Equals(commandPath);
g_free(commandPath);
return matches;
}
bool
nsGNOMEShellService::CheckHandlerMatchesAppName(const nsACString &handler) const
{
gint argc;
gchar **argv;
nsAutoCString command(handler);
// 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.
if (g_shell_parse_argv(command.get(), &argc, &argv, nullptr) && argc > 0) {
command.Assign(argv[0]);
g_strfreev(argv);
}
if (!KeyMatchesAppName(command.get()))
return false; // the handler is set to another app
return true;
}
NS_IMETHODIMP
nsGNOMEShellService::IsDefaultBrowser(bool aStartupCheck,
bool aForAllTypes,
bool* aIsDefaultBrowser)
{
*aIsDefaultBrowser = false;
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
bool enabled;
nsAutoCString handler;
nsCOMPtr<nsIGIOMimeApp> gioApp;
for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
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) {
handler.Truncate();
giovfs->GetAppForURIScheme(nsDependentCString(appProtocols[i].name),
getter_AddRefs(gioApp));
if (!gioApp)
return NS_OK;
gioApp->GetCommand(handler);
if (!CheckHandlerMatchesAppName(handler))
return NS_OK; // the handler is set to another app
}
}
*aIsDefaultBrowser = true;
return NS_OK;
}
NS_IMETHODIMP
nsGNOMEShellService::SetDefaultBrowser(bool aClaimAllTypes,
bool aForAllUsers)
{
#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);
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) {
nsresult rv;
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);
nsString brandShortName;
brandBundle->GetStringFromName(u"brandShortName",
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);
// set handler for the protocols
for (unsigned int i = 0; i < ArrayLength(appProtocols); ++i) {
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.
for (unsigned int i = 0; i < ArrayLength(appTypes); ++i) {
appInfo->SetAsDefaultForMimeType(nsDependentCString(appTypes[i].mimeType));
appInfo->SetAsDefaultForFileExtensions(nsDependentCString(appTypes[i].extensions));
}
}
}
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefs) {
(void) prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, true);
// Reset the number of times the dialog should be shown
// before it is silenced.
(void) prefs->SetIntPref(PREF_DEFAULTBROWSERCHECKCOUNT, 0);
}
return NS_OK;
}
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;
}
static nsresult
WriteImage(const nsCString& aPath, imgIContainer* aImage)
{
#if !defined(MOZ_WIDGET_GTK)
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;
GdkPixbuf* pixbuf = imgToPixbuf->ConvertImageToPixbuf(aImage);
if (!pixbuf)
return NS_ERROR_NOT_AVAILABLE;
gboolean res = gdk_pixbuf_save(pixbuf, aPath.get(), "png", nullptr, nullptr);
g_object_unref(pixbuf);
return res ? NS_OK : NS_ERROR_FAILURE;
#endif
}
NS_IMETHODIMP
nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement,
int32_t aPosition)
{
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;
// Set desktop wallpaper filling style
nsAutoCString options;
if (aPosition == BACKGROUND_TILE)
options.AssignLiteral("wallpaper");
else if (aPosition == BACKGROUND_STRETCH)
options.AssignLiteral("stretched");
else if (aPosition == BACKGROUND_FILL)
options.AssignLiteral("zoom");
else if (aPosition == BACKGROUND_FIT)
options.AssignLiteral("scaled");
else
options.AssignLiteral("centered");
// Write the background file to the home directory.
nsAutoCString filePath(PR_GetEnv("HOME"));
// 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) {
rv = brandBundle->GetStringFromName(u"brandShortName",
getter_Copies(brandName));
NS_ENSURE_SUCCESS(rv, rv);
}
}
// build the file name
filePath.Append('/');
filePath.Append(NS_ConvertUTF16toUTF8(brandName));
filePath.AppendLiteral("_wallpaper.png");
// write the image to a file in the home dir
rv = WriteImage(filePath, container);
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) {
gchar *file_uri = g_filename_to_uri(filePath.get(), nullptr, nullptr);
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),
true);
return rv;
}
}
// if the file was written successfully, set it as the system wallpaper
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
// Borealis_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_8_TO_16_BIT(_c) ((_c) << 8 | (_c))
NS_IMETHODIMP
nsGNOMEShellService::GetDesktopBackgroundColor(uint32_t *aColor)
{
nsCOMPtr<nsIGSettingsService> gsettings =
do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
nsCOMPtr<nsIGSettingsCollection> background_settings;
nsAutoCString background;
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);
}
if (background.IsEmpty()) {
*aColor = 0;
return NS_OK;
}
GdkColor color;
gboolean success = gdk_color_parse(background.get(), &color);
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
*aColor = COLOR_16_TO_8_BIT(color.red) << 16 |
COLOR_16_TO_8_BIT(color.green) << 8 |
COLOR_16_TO_8_BIT(color.blue);
return NS_OK;
}
static void
ColorToCString(uint32_t aColor, nsCString& aResult)
{
// The #rrrrggggbbbb format is used to match gdk_color_to_string()
char *buf = aResult.BeginWriting(13);
if (!buf)
return;
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);
snprintf(buf, 14, "#%04x%04x%04x", red, green, blue);
}
NS_IMETHODIMP
nsGNOMEShellService::SetDesktopBackgroundColor(uint32_t aColor)
{
NS_ASSERTION(aColor <= 0xffffff, "aColor has extra bits");
nsAutoCString colorString;
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;
}
}
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
if (gconf) {
gconf->SetString(NS_LITERAL_CSTRING(kDesktopColorKey), colorString);
}
return NS_OK;
}
NS_IMETHODIMP
nsGNOMEShellService::OpenApplication(int32_t aApplication)
{
nsAutoCString scheme;
if (aApplication == APPLICATION_MAIL)
scheme.AssignLiteral("mailto");
else if (aApplication == APPLICATION_NEWS)
scheme.AssignLiteral("news");
else
return NS_ERROR_NOT_AVAILABLE;
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());
}
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
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
nsGNOMEShellService::OpenApplicationWithURI(nsIFile* aApplication, const nsACString& aURI)
{
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();
return process->Run(false, &specStr, 1);
}
NS_IMETHODIMP
nsGNOMEShellService::GetDefaultFeedReader(nsIFile** _retval)
{