mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 07:48:38 +09:00
Add Pale Moon
This commit is contained in:
parent
dcd9973243
commit
fe8028fa2e
1173 changed files with 143053 additions and 934 deletions
11
application/palemoon/components/shell/Makefile.in
Normal file
11
application/palemoon/components/shell/Makefile.in
Normal file
|
|
@ -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/.
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
CXXFLAGS += $(TK_CFLAGS)
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)/lib/$(LIBRARY_NAME).lib
|
||||
|
|
@ -0,0 +1,213 @@
|
|||
# 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 = {
|
||||
#ifndef XP_MACOSX
|
||||
_position : "",
|
||||
_backgroundColor : 0,
|
||||
#else
|
||||
_position : "STRETCH",
|
||||
#endif
|
||||
_screenWidth : 0,
|
||||
_screenHeight : 0,
|
||||
_image : null,
|
||||
_canvas : null,
|
||||
|
||||
get _shell()
|
||||
{
|
||||
return Components.classes["@mozilla.org/browser/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 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);
|
||||
|
||||
#ifndef XP_MACOSX
|
||||
this._initColor();
|
||||
#else
|
||||
// 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;
|
||||
#endif
|
||||
this.updatePosition();
|
||||
},
|
||||
|
||||
#ifndef XP_MACOSX
|
||||
_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;
|
||||
},
|
||||
|
||||
updateColor: function (aColor)
|
||||
{
|
||||
this._backgroundColor = aColor;
|
||||
this._canvas.style.backgroundColor = aColor;
|
||||
},
|
||||
|
||||
// Converts a color string in the format "#RRGGBB" to an integer.
|
||||
_hexStringToLong: function (aString)
|
||||
{
|
||||
return parseInt(aString.substring(1,3), 16) << 16 |
|
||||
parseInt(aString.substring(3,5), 16) << 8 |
|
||||
parseInt(aString.substring(5,7), 16);
|
||||
},
|
||||
|
||||
_rgbToHex: function (aR, aG, aB)
|
||||
{
|
||||
return "#" + [aR, aG, aB].map(function(aInt) aInt.toString(16).replace(/^(.)$/, "0$1"))
|
||||
.join("").toUpperCase();
|
||||
},
|
||||
#else
|
||||
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");
|
||||
}
|
||||
},
|
||||
|
||||
showDesktopPrefs: function()
|
||||
{
|
||||
this._shell.openApplication(Ci.nsIMacShellService.APPLICATION_DESKTOP);
|
||||
},
|
||||
#endif
|
||||
|
||||
setDesktopBackground: function ()
|
||||
{
|
||||
#ifndef XP_MACOSX
|
||||
document.persist("menuPosition", "value");
|
||||
this._shell.desktopBackgroundColor = this._hexStringToLong(this._backgroundColor);
|
||||
#else
|
||||
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");
|
||||
#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":
|
||||
var x = (this._screenWidth - this._image.naturalWidth) / 2;
|
||||
var y = (this._screenHeight - this._image.naturalHeight) / 2;
|
||||
ctx.drawImage(this._image, x, y);
|
||||
break;
|
||||
case "FILL":
|
||||
//Try maxing width first, overflow height
|
||||
var widthRatio = this._screenWidth / this._image.naturalWidth;
|
||||
var width = this._image.naturalWidth * widthRatio;
|
||||
var height = this._image.naturalHeight * widthRatio;
|
||||
if (height < this._screenHeight) {
|
||||
//height less than screen, max height and overflow width
|
||||
var heightRatio = this._screenHeight / this._image.naturalHeight;
|
||||
width = this._image.naturalWidth * heightRatio;
|
||||
height = this._image.naturalHeight * heightRatio;
|
||||
}
|
||||
var x = (this._screenWidth - width) / 2;
|
||||
var y = (this._screenHeight - height) / 2;
|
||||
ctx.drawImage(this._image, x, y, width, height);
|
||||
break;
|
||||
case "FIT":
|
||||
//Try maxing width first, top and bottom borders
|
||||
var widthRatio = this._screenWidth / this._image.naturalWidth;
|
||||
var width = this._image.naturalWidth * widthRatio;
|
||||
var height = this._image.naturalHeight * widthRatio;
|
||||
var x = 0;
|
||||
var y = (this._screenHeight - height) / 2;
|
||||
if (height > this._screenHeight) {
|
||||
//height overflow, maximise height, side borders
|
||||
var 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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -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://browser/skin/setDesktopBackground.css" type="text/css"?>
|
||||
|
||||
<!DOCTYPE dialog SYSTEM "chrome://browser/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://browser/locale/shellservice.properties"/>
|
||||
<script type="application/javascript" src="chrome://browser/content/utilityOverlay.js"/>
|
||||
<script type="application/javascript" src="chrome://browser/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="¢er.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>
|
||||
7
application/palemoon/components/shell/jar.mn
Normal file
7
application/palemoon/components/shell/jar.mn
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# 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/.
|
||||
|
||||
browser.jar:
|
||||
* content/browser/setDesktopBackground.xul (content/setDesktopBackground.xul)
|
||||
* content/browser/setDesktopBackground.js (content/setDesktopBackground.js)
|
||||
48
application/palemoon/components/shell/moz.build
Normal file
48
application/palemoon/components/shell/moz.build
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# -*- Mode: python; c-basic-offset: 4; 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/.
|
||||
|
||||
JAR_MANIFESTS += ['jar.mn']
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'nsIShellService.idl',
|
||||
]
|
||||
|
||||
if CONFIG['OS_ARCH'] == 'WINNT':
|
||||
XPIDL_SOURCES += [
|
||||
'nsIWindowsShellService.idl',
|
||||
]
|
||||
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
|
||||
XPIDL_SOURCES += [
|
||||
'nsIMacShellService.idl',
|
||||
]
|
||||
|
||||
XPIDL_MODULE = 'shellservice'
|
||||
|
||||
if CONFIG['OS_ARCH'] == 'WINNT':
|
||||
SOURCES += [
|
||||
'nsWindowsShellService.cpp',
|
||||
]
|
||||
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
|
||||
SOURCES += [
|
||||
'nsMacShellService.cpp',
|
||||
]
|
||||
elif CONFIG['MOZ_WIDGET_GTK']:
|
||||
SOURCES += [
|
||||
'nsGNOMEShellService.cpp',
|
||||
]
|
||||
|
||||
if SOURCES:
|
||||
FINAL_LIBRARY = 'browsercomps'
|
||||
|
||||
EXTRA_COMPONENTS += [
|
||||
'nsSetDefaultBrowser.js',
|
||||
'nsSetDefaultBrowser.manifest',
|
||||
]
|
||||
|
||||
for var in ('MOZ_APP_NAME', 'MOZ_APP_VERSION'):
|
||||
DEFINES[var] = '"%s"' % CONFIG[var]
|
||||
|
||||
CXXFLAGS += CONFIG['TK_CFLAGS']
|
||||
664
application/palemoon/components/shell/nsGNOMEShellService.cpp
Normal file
664
application/palemoon/components/shell/nsGNOMEShellService.cpp
Normal file
|
|
@ -0,0 +1,664 @@
|
|||
/* -*- 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 "nsShellService.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 "nsNetUtil.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIImageLoadingContent.h"
|
||||
#include "imgIRequest.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "prprf.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, 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;
|
||||
if (aStartupCheck)
|
||||
mCheckedThisSession = true;
|
||||
|
||||
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(MOZ_UTF16("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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGNOMEShellService::GetShouldCheckDefaultBrowser(bool* aResult)
|
||||
{
|
||||
// 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) {
|
||||
*aResult = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefs;
|
||||
nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (pserve)
|
||||
pserve->GetBranch("", getter_AddRefs(prefs));
|
||||
|
||||
if (prefs)
|
||||
prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGNOMEShellService::SetShouldCheckDefaultBrowser(bool aShouldCheck)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefs;
|
||||
nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (pserve)
|
||||
pserve->GetBranch("", getter_AddRefs(prefs));
|
||||
|
||||
if (prefs)
|
||||
prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck);
|
||||
|
||||
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.Assign("wallpaper");
|
||||
else if (aPosition == BACKGROUND_STRETCH)
|
||||
options.Assign("stretched");
|
||||
else if (aPosition == BACKGROUND_FILL)
|
||||
options.Assign("zoom");
|
||||
else if (aPosition == BACKGROUND_FIT)
|
||||
options.Assign("scaled");
|
||||
else
|
||||
options.Assign("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(MOZ_UTF16("brandShortName"),
|
||||
getter_Copies(brandName));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
|
||||
// build the file name
|
||||
filePath.Append('/');
|
||||
filePath.Append(NS_ConvertUTF16toUTF8(brandName));
|
||||
filePath.Append("_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
|
||||
// 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_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);
|
||||
|
||||
PR_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.Assign("mailto");
|
||||
else if (aApplication == APPLICATION_NEWS)
|
||||
scheme.Assign("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)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
36
application/palemoon/components/shell/nsGNOMEShellService.h
Normal file
36
application/palemoon/components/shell/nsGNOMEShellService.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#ifndef nsgnomeshellservice_h____
|
||||
#define nsgnomeshellservice_h____
|
||||
|
||||
#include "nsIShellService.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
class nsGNOMEShellService final : public nsIShellService
|
||||
{
|
||||
public:
|
||||
nsGNOMEShellService() : mCheckedThisSession(false), mAppIsInPath(false) { }
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISHELLSERVICE
|
||||
|
||||
nsresult Init() NS_HIDDEN;
|
||||
|
||||
private:
|
||||
~nsGNOMEShellService() {}
|
||||
|
||||
NS_HIDDEN_(bool) KeyMatchesAppName(const char *aKeyValue) const;
|
||||
NS_HIDDEN_(bool) CheckHandlerMatchesAppName(const nsACString& handler) const;
|
||||
|
||||
NS_HIDDEN_(bool) GetAppPathFromLauncher();
|
||||
bool mCheckedThisSession;
|
||||
bool mUseLocaleFilenames;
|
||||
nsCString mAppPath;
|
||||
bool mAppIsInPath;
|
||||
};
|
||||
|
||||
#endif // nsgnomeshellservice_h____
|
||||
15
application/palemoon/components/shell/nsIMacShellService.idl
Normal file
15
application/palemoon/components/shell/nsIMacShellService.idl
Normal file
|
|
@ -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(7f8ca08e-1df4-4735-86e9-50dedb48e5e8)]
|
||||
interface nsIMacShellService : nsIShellService
|
||||
{
|
||||
const long APPLICATION_KEYCHAIN_ACCESS = 2;
|
||||
const long APPLICATION_NETWORK = 3;
|
||||
const long APPLICATION_DESKTOP = 4;
|
||||
};
|
||||
|
||||
112
application/palemoon/components/shell/nsIShellService.idl
Normal file
112
application/palemoon/components/shell/nsIShellService.idl
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/* -*- 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(99d2e9f1-3c86-40f7-81fd-3060c18489f0)]
|
||||
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);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
attribute boolean shouldCheckDefaultBrowser;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
|
|
@ -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(89b0a761-d9a0-4c39-ab83-d81566459a31)]
|
||||
interface nsIWindowsShellService : nsIShellService
|
||||
{
|
||||
/**
|
||||
* Provides the shell service an opportunity to do some Win7+ shortcut
|
||||
* maintenance needed on initial startup of the browser.
|
||||
*/
|
||||
void shortcutMaintenance();
|
||||
};
|
||||
|
||||
470
application/palemoon/components/shell/nsMacShellService.cpp
Normal file
470
application/palemoon/components/shell/nsMacShellService.cpp
Normal file
|
|
@ -0,0 +1,470 @@
|
|||
/* -*- 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 "nsDirectoryServiceDefs.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIImageLoadingContent.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsILocalFileMac.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIWebBrowserPersist.h"
|
||||
#include "nsMacShellService.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsShellService.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsILoadContext.h"
|
||||
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
#define NETWORK_PREFPANE NS_LITERAL_CSTRING("/System/Library/PreferencePanes/Network.prefPane")
|
||||
#define DESKTOP_PREFPANE NS_LITERAL_CSTRING("/System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane")
|
||||
|
||||
#define SAFARI_BUNDLE_IDENTIFIER "com.apple.Safari"
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsMacShellService, nsIMacShellService, nsIShellService, nsIWebProgressListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::IsDefaultBrowser(bool aStartupCheck,
|
||||
bool aForAllTypes,
|
||||
bool* aIsDefaultBrowser)
|
||||
{
|
||||
*aIsDefaultBrowser = false;
|
||||
|
||||
CFStringRef firefoxID = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
|
||||
if (!firefoxID) {
|
||||
// CFBundleGetIdentifier is expected to return nullptr only if the specified
|
||||
// bundle doesn't have a bundle identifier in its plist. In this case, that
|
||||
// means a failure, since our bundle does have an identifier.
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Get the default http handler's bundle ID (or nullptr if it has not been explicitly set)
|
||||
CFStringRef defaultBrowserID = ::LSCopyDefaultHandlerForURLScheme(CFSTR("http"));
|
||||
if (defaultBrowserID) {
|
||||
*aIsDefaultBrowser = ::CFStringCompare(firefoxID, defaultBrowserID, 0) == kCFCompareEqualTo;
|
||||
::CFRelease(defaultBrowserID);
|
||||
}
|
||||
|
||||
// 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 (aStartupCheck)
|
||||
mCheckedThisSession = true;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers)
|
||||
{
|
||||
// Note: We don't support aForAllUsers on Mac OS X.
|
||||
|
||||
CFStringRef firefoxID = ::CFBundleGetIdentifier(::CFBundleGetMainBundle());
|
||||
if (!firefoxID) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (::LSSetDefaultHandlerForURLScheme(CFSTR("http"), firefoxID) != noErr) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (::LSSetDefaultHandlerForURLScheme(CFSTR("https"), firefoxID) != noErr) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (aClaimAllTypes) {
|
||||
if (::LSSetDefaultHandlerForURLScheme(CFSTR("ftp"), firefoxID) != noErr) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (::LSSetDefaultRoleHandlerForContentType(kUTTypeHTML, kLSRolesAll, firefoxID) != noErr) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::GetShouldCheckDefaultBrowser(bool* aResult)
|
||||
{
|
||||
// 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) {
|
||||
*aResult = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefs;
|
||||
nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (pserve)
|
||||
pserve->GetBranch("", getter_AddRefs(prefs));
|
||||
|
||||
prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::SetShouldCheckDefaultBrowser(bool aShouldCheck)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefs;
|
||||
nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (pserve)
|
||||
pserve->GetBranch("", getter_AddRefs(prefs));
|
||||
|
||||
prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::GetCanSetDesktopBackground(bool* aResult)
|
||||
{
|
||||
*aResult = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::SetDesktopBackground(nsIDOMElement* aElement,
|
||||
int32_t aPosition)
|
||||
{
|
||||
// Note: We don't support aPosition on OS X.
|
||||
|
||||
// Get the image URI:
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIImageLoadingContent> imageContent = do_QueryInterface(aElement,
|
||||
&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIURI> imageURI;
|
||||
rv = imageContent->GetCurrentURI(getter_AddRefs(imageURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// We need the referer URI for nsIWebBrowserPersist::saveURI
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsIURI *docURI = content->OwnerDoc()->GetDocumentURI();
|
||||
if (!docURI)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get the desired image file name
|
||||
nsCOMPtr<nsIURL> imageURL(do_QueryInterface(imageURI));
|
||||
if (!imageURL) {
|
||||
// XXXmano (bug 300293): Non-URL images (e.g. the data: protocol) are not
|
||||
// yet supported. What filename should we take here?
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsAutoCString fileName;
|
||||
imageURL->GetFileName(fileName);
|
||||
nsCOMPtr<nsIProperties> fileLocator
|
||||
(do_GetService("@mozilla.org/file/directory_service;1", &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Get the current user's "Pictures" folder (That's ~/Pictures):
|
||||
fileLocator->Get(NS_OSX_PICTURE_DOCUMENTS_DIR, NS_GET_IID(nsIFile),
|
||||
getter_AddRefs(mBackgroundFile));
|
||||
if (!mBackgroundFile)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsAutoString fileNameUnicode;
|
||||
CopyUTF8toUTF16(fileName, fileNameUnicode);
|
||||
|
||||
// and add the imgage file name itself:
|
||||
mBackgroundFile->Append(fileNameUnicode);
|
||||
|
||||
// Download the image; the desktop background will be set in OnStateChange()
|
||||
nsCOMPtr<nsIWebBrowserPersist> wbp
|
||||
(do_CreateInstance("@mozilla.org/embedding/browser/nsWebBrowserPersist;1", &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
uint32_t flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION |
|
||||
nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES |
|
||||
nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE;
|
||||
|
||||
wbp->SetPersistFlags(flags);
|
||||
wbp->SetProgressListener(this);
|
||||
|
||||
nsCOMPtr<nsILoadContext> loadContext;
|
||||
nsCOMPtr<nsISupports> container = content->OwnerDoc()->GetContainer();
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container);
|
||||
if (docShell) {
|
||||
loadContext = do_QueryInterface(docShell);
|
||||
}
|
||||
|
||||
return wbp->SaveURI(imageURI, nullptr, docURI, content->OwnerDoc()->GetReferrerPolicy(),
|
||||
nullptr, nullptr, mBackgroundFile, loadContext);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::OnProgressChange(nsIWebProgress* aWebProgress,
|
||||
nsIRequest* aRequest,
|
||||
int32_t aCurSelfProgress,
|
||||
int32_t aMaxSelfProgress,
|
||||
int32_t aCurTotalProgress,
|
||||
int32_t aMaxTotalProgress)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::OnLocationChange(nsIWebProgress* aWebProgress,
|
||||
nsIRequest* aRequest,
|
||||
nsIURI* aLocation,
|
||||
uint32_t aFlags)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::OnStatusChange(nsIWebProgress* aWebProgress,
|
||||
nsIRequest* aRequest,
|
||||
nsresult aStatus,
|
||||
const char16_t* aMessage)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::OnSecurityChange(nsIWebProgress* aWebProgress,
|
||||
nsIRequest* aRequest,
|
||||
uint32_t aState)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::OnStateChange(nsIWebProgress* aWebProgress,
|
||||
nsIRequest* aRequest,
|
||||
uint32_t aStateFlags,
|
||||
nsresult aStatus)
|
||||
{
|
||||
if (aStateFlags & STATE_STOP) {
|
||||
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (os)
|
||||
os->NotifyObservers(nullptr, "shell:desktop-background-changed", nullptr);
|
||||
|
||||
bool exists = false;
|
||||
mBackgroundFile->Exists(&exists);
|
||||
if (!exists)
|
||||
return NS_OK;
|
||||
|
||||
nsAutoCString nativePath;
|
||||
mBackgroundFile->GetNativePath(nativePath);
|
||||
|
||||
AEDesc tAEDesc = { typeNull, nil };
|
||||
OSErr err = noErr;
|
||||
AliasHandle aliasHandle = nil;
|
||||
FSRef pictureRef;
|
||||
OSStatus status;
|
||||
|
||||
// Convert the path into a FSRef
|
||||
status = ::FSPathMakeRef((const UInt8*)nativePath.get(), &pictureRef, nullptr);
|
||||
if (status == noErr) {
|
||||
err = ::FSNewAlias(nil, &pictureRef, &aliasHandle);
|
||||
if (err == noErr && aliasHandle == nil)
|
||||
err = paramErr;
|
||||
|
||||
if (err == noErr) {
|
||||
// We need the descriptor (based on the picture file reference)
|
||||
// for the 'Set Desktop Picture' apple event.
|
||||
char handleState = ::HGetState((Handle)aliasHandle);
|
||||
::HLock((Handle)aliasHandle);
|
||||
err = ::AECreateDesc(typeAlias, *aliasHandle,
|
||||
GetHandleSize((Handle)aliasHandle), &tAEDesc);
|
||||
// unlock the alias handler
|
||||
::HSetState((Handle)aliasHandle, handleState);
|
||||
::DisposeHandle((Handle)aliasHandle);
|
||||
}
|
||||
if (err == noErr) {
|
||||
AppleEvent tAppleEvent;
|
||||
OSType sig = 'MACS';
|
||||
AEBuildError tAEBuildError;
|
||||
// Create a 'Set Desktop Pictue' Apple Event
|
||||
err = ::AEBuildAppleEvent(kAECoreSuite, kAESetData, typeApplSignature,
|
||||
&sig, sizeof(OSType), kAutoGenerateReturnID,
|
||||
kAnyTransactionID, &tAppleEvent, &tAEBuildError,
|
||||
"'----':'obj '{want:type (prop),form:prop" \
|
||||
",seld:type('dpic'),from:'null'()},data:(@)",
|
||||
&tAEDesc);
|
||||
if (err == noErr) {
|
||||
AppleEvent reply = { typeNull, nil };
|
||||
// Sent the event we built, the reply event isn't necessary
|
||||
err = ::AESend(&tAppleEvent, &reply, kAENoReply, kAENormalPriority,
|
||||
kNoTimeOut, nil, nil);
|
||||
::AEDisposeDesc(&tAppleEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::OpenApplication(int32_t aApplication)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
CFURLRef appURL = nil;
|
||||
OSStatus err = noErr;
|
||||
|
||||
switch (aApplication) {
|
||||
case nsIShellService::APPLICATION_MAIL:
|
||||
{
|
||||
CFURLRef tempURL = ::CFURLCreateWithString(kCFAllocatorDefault,
|
||||
CFSTR("mailto:"), nullptr);
|
||||
err = ::LSGetApplicationForURL(tempURL, kLSRolesAll, nullptr, &appURL);
|
||||
::CFRelease(tempURL);
|
||||
}
|
||||
break;
|
||||
case nsIShellService::APPLICATION_NEWS:
|
||||
{
|
||||
CFURLRef tempURL = ::CFURLCreateWithString(kCFAllocatorDefault,
|
||||
CFSTR("news:"), nullptr);
|
||||
err = ::LSGetApplicationForURL(tempURL, kLSRolesAll, nullptr, &appURL);
|
||||
::CFRelease(tempURL);
|
||||
}
|
||||
break;
|
||||
case nsIMacShellService::APPLICATION_KEYCHAIN_ACCESS:
|
||||
err = ::LSGetApplicationForInfo('APPL', 'kcmr', nullptr, kLSRolesAll, nullptr,
|
||||
&appURL);
|
||||
break;
|
||||
case nsIMacShellService::APPLICATION_NETWORK:
|
||||
{
|
||||
nsCOMPtr<nsIFile> lf;
|
||||
rv = NS_NewNativeLocalFile(NETWORK_PREFPANE, true, getter_AddRefs(lf));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
bool exists;
|
||||
lf->Exists(&exists);
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
return lf->Launch();
|
||||
}
|
||||
break;
|
||||
case nsIMacShellService::APPLICATION_DESKTOP:
|
||||
{
|
||||
nsCOMPtr<nsIFile> lf;
|
||||
rv = NS_NewNativeLocalFile(DESKTOP_PREFPANE, true, getter_AddRefs(lf));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
bool exists;
|
||||
lf->Exists(&exists);
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
return lf->Launch();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (appURL && err == noErr) {
|
||||
err = ::LSOpenCFURLRef(appURL, nullptr);
|
||||
rv = err != noErr ? NS_ERROR_FAILURE : NS_OK;
|
||||
|
||||
::CFRelease(appURL);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::GetDesktopBackgroundColor(uint32_t *aColor)
|
||||
{
|
||||
// This method and |SetDesktopBackgroundColor| has no meaning on Mac OS X.
|
||||
// The mac desktop preferences UI uses pictures for the few solid colors it
|
||||
// supports.
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::SetDesktopBackgroundColor(uint32_t aColor)
|
||||
{
|
||||
// This method and |GetDesktopBackgroundColor| has no meaning on Mac OS X.
|
||||
// The mac desktop preferences UI uses pictures for the few solid colors it
|
||||
// supports.
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::OpenApplicationWithURI(nsIFile* aApplication, const nsACString& aURI)
|
||||
{
|
||||
nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(aApplication));
|
||||
CFURLRef appURL;
|
||||
nsresult rv = lfm->GetCFURL(&appURL);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
const nsCString spec(aURI);
|
||||
const UInt8* uriString = (const UInt8*)spec.get();
|
||||
CFURLRef uri = ::CFURLCreateWithBytes(nullptr, uriString, aURI.Length(),
|
||||
kCFStringEncodingUTF8, nullptr);
|
||||
if (!uri)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
CFArrayRef uris = ::CFArrayCreate(nullptr, (const void**)&uri, 1, nullptr);
|
||||
if (!uris) {
|
||||
::CFRelease(uri);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
LSLaunchURLSpec launchSpec;
|
||||
launchSpec.appURL = appURL;
|
||||
launchSpec.itemURLs = uris;
|
||||
launchSpec.passThruParams = nullptr;
|
||||
launchSpec.launchFlags = kLSLaunchDefaults;
|
||||
launchSpec.asyncRefCon = nullptr;
|
||||
|
||||
OSErr err = ::LSOpenFromURLSpec(&launchSpec, nullptr);
|
||||
|
||||
::CFRelease(uris);
|
||||
::CFRelease(uri);
|
||||
|
||||
return err != noErr ? NS_ERROR_FAILURE : NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacShellService::GetDefaultFeedReader(nsIFile** _retval)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
*_retval = nullptr;
|
||||
|
||||
CFStringRef defaultHandlerID = ::LSCopyDefaultHandlerForURLScheme(CFSTR("feed"));
|
||||
if (!defaultHandlerID) {
|
||||
defaultHandlerID = ::CFStringCreateWithCString(kCFAllocatorDefault,
|
||||
SAFARI_BUNDLE_IDENTIFIER,
|
||||
kCFStringEncodingASCII);
|
||||
}
|
||||
|
||||
CFURLRef defaultHandlerURL = nullptr;
|
||||
OSStatus status = ::LSFindApplicationForInfo(kLSUnknownCreator,
|
||||
defaultHandlerID,
|
||||
nullptr, // inName
|
||||
nullptr, // outAppRef
|
||||
&defaultHandlerURL);
|
||||
|
||||
if (status == noErr && defaultHandlerURL) {
|
||||
nsCOMPtr<nsILocalFileMac> defaultReader =
|
||||
do_CreateInstance("@mozilla.org/file/local;1", &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = defaultReader->InitWithCFURL(defaultHandlerURL);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_ADDREF(*_retval = defaultReader);
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
::CFRelease(defaultHandlerURL);
|
||||
}
|
||||
|
||||
::CFRelease(defaultHandlerID);
|
||||
|
||||
return rv;
|
||||
}
|
||||
34
application/palemoon/components/shell/nsMacShellService.h
Normal file
34
application/palemoon/components/shell/nsMacShellService.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#ifndef nsmacshellservice_h____
|
||||
#define nsmacshellservice_h____
|
||||
|
||||
#include "nsIMacShellService.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsMacShellService : public nsIMacShellService,
|
||||
public nsIWebProgressListener
|
||||
{
|
||||
public:
|
||||
nsMacShellService() : mCheckedThisSession(false) {};
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISHELLSERVICE
|
||||
NS_DECL_NSIMACSHELLSERVICE
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
|
||||
protected:
|
||||
virtual ~nsMacShellService() {};
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIFile> mBackgroundFile;
|
||||
|
||||
bool mCheckedThisSession;
|
||||
};
|
||||
|
||||
#endif // nsmacshellservice_h____
|
||||
31
application/palemoon/components/shell/nsSetDefaultBrowser.js
Normal file
31
application/palemoon/components/shell/nsSetDefaultBrowser.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* 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/. */
|
||||
|
||||
/*
|
||||
* -setDefaultBrowser commandline handler
|
||||
* Makes the current executable the "default browser".
|
||||
*/
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
function nsSetDefaultBrowser() {}
|
||||
|
||||
nsSetDefaultBrowser.prototype = {
|
||||
handle: function nsSetDefault_handle(aCmdline) {
|
||||
if (aCmdline.handleFlag("setDefaultBrowser", false)) {
|
||||
var shell = Cc["@mozilla.org/browser/shell-service;1"].
|
||||
getService(Ci.nsIShellService);
|
||||
shell.setDefaultBrowser(true, true);
|
||||
}
|
||||
},
|
||||
|
||||
helpInfo: " -setDefaultBrowser Set this app as the default browser.\n",
|
||||
|
||||
classID: Components.ID("{F57899D0-4E2C-4ac6-9E29-50C736103B0C}"),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsSetDefaultBrowser]);
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
component {F57899D0-4E2C-4ac6-9E29-50C736103B0C} nsSetDefaultBrowser.js
|
||||
contract @mozilla.org/browser/default-browser-clh;1 {F57899D0-4E2C-4ac6-9E29-50C736103B0C}
|
||||
category command-line-handler m-setdefaultbrowser @mozilla.org/browser/default-browser-clh;1
|
||||
10
application/palemoon/components/shell/nsShellService.h
Normal file
10
application/palemoon/components/shell/nsShellService.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#define PREF_CHECKDEFAULTBROWSER "browser.shell.checkDefaultBrowser"
|
||||
|
||||
#define SHELLSERVICE_PROPERTIES "chrome://browser/locale/shellservice.properties"
|
||||
#define BRAND_PROPERTIES "chrome://branding/locale/brand.properties"
|
||||
|
||||
1198
application/palemoon/components/shell/nsWindowsShellService.cpp
Normal file
1198
application/palemoon/components/shell/nsWindowsShellService.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,37 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#ifndef nswindowsshellservice_h____
|
||||
#define nswindowsshellservice_h____
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsIWindowsShellService.h"
|
||||
#include "nsITimer.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <ole2.h>
|
||||
|
||||
class nsWindowsShellService : public nsIWindowsShellService
|
||||
{
|
||||
public:
|
||||
nsWindowsShellService();
|
||||
virtual ~nsWindowsShellService();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISHELLSERVICE
|
||||
NS_DECL_NSIWINDOWSSHELLSERVICE
|
||||
|
||||
protected:
|
||||
bool IsDefaultBrowserVista(bool aCheckAllTypes, bool* aIsDefaultBrowser);
|
||||
nsresult LaunchControlPanelDefaultPrograms();
|
||||
nsresult LaunchModernSettingsDialogDefaultApps();
|
||||
nsresult LaunchHTTPHandlerPane();
|
||||
|
||||
private:
|
||||
bool mCheckedThisSession;
|
||||
};
|
||||
|
||||
#endif // nswindowsshellservice_h____
|
||||
Loading…
Add table
Add a link
Reference in a new issue