mirror of https://github.com/roytam1/boc-uxp.git
Browse Source
This will be replaced with more contemporary versions in a future series of commits. tl;dr NOW I HAVE TO DO IT, DAMN IT!custom-2020
37 changed files with 7 additions and 5777 deletions
@ -1,62 +0,0 @@
|
||||
/* -*- Mode: Java; 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/. */
|
||||
|
||||
// this dialog can only be opened if we have a shell service
|
||||
const nsIShellService = Components.interfaces.nsIShellService; |
||||
const nsIPrefBranch = Components.interfaces.nsIPrefBranch; |
||||
|
||||
function onLoad() |
||||
{ |
||||
var shellSvc = Components.classes["@binaryoutcast.com/navigator/shell-service;1"] |
||||
.getService(nsIShellService); |
||||
var defaultList = document.getElementById("defaultList"); |
||||
var appTypes = shellSvc.shouldBeDefaultClientFor; |
||||
/* Iterate through the list of possible default client types and check for |
||||
each list item if we want to be the default for that type using the AND |
||||
conjunction */ |
||||
for (var i = 0; i < defaultList.getRowCount(); i++) { |
||||
var currentItem = defaultList.getItemAtIndex(i); |
||||
try { |
||||
if (shellSvc.isDefaultClient(false, nsIShellService[currentItem.value])) { |
||||
currentItem.checked = true; |
||||
currentItem.disabled = true; |
||||
} |
||||
else if (nsIShellService[currentItem.value] & appTypes) |
||||
currentItem.checked = true; |
||||
} catch (e) { |
||||
currentItem.hidden = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
function onAccept() |
||||
{ |
||||
// for each checked item, if we aren't already the default, make us the default.
|
||||
var shellSvc = Components.classes["@binaryoutcast.com/navigator/shell-service;1"] |
||||
.getService(nsIShellService); |
||||
var appTypes = 0; |
||||
var appTypesCheck = 0; |
||||
var defaultList = document.getElementById("defaultList"); |
||||
|
||||
for (var i = 0; i < defaultList.getRowCount(); i++) { |
||||
var currentItem = defaultList.getItemAtIndex(i); |
||||
var currentAppType = nsIShellService[currentItem.value]; |
||||
|
||||
if (currentItem.checked) { |
||||
appTypesCheck |= currentAppType; |
||||
|
||||
if (!currentItem.disabled) |
||||
appTypes |= currentAppType; |
||||
} |
||||
} |
||||
|
||||
if (appTypes) |
||||
shellSvc.setDefaultClient(false, true, appTypes); |
||||
|
||||
// Update the pref for which app types we should check if we are the default app
|
||||
shellSvc.shouldBeDefaultClientFor = appTypesCheck; |
||||
|
||||
shellSvc.shouldCheckDefaultClient = document.getElementById('checkOnStartup').checked; |
||||
} |
@ -1,37 +0,0 @@
|
||||
<?xml version="1.0"?> |
||||
|
||||
<!-- 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/"?> |
||||
|
||||
<!DOCTYPE window [ |
||||
<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" > |
||||
%brandDTD; |
||||
<!ENTITY % defaultClientDTD SYSTEM "chrome://communicator/locale/defaultClientDialog.dtd" > |
||||
%defaultClientDTD; |
||||
]> |
||||
|
||||
<dialog xmlns:html="http://www.w3.org/1999/xhtml" |
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
||||
id="defaultClientDialog" |
||||
buttons="accept,cancel" |
||||
onload="onLoad();" |
||||
ondialogaccept="return onAccept();" |
||||
title="&defaultClient.title;"> |
||||
|
||||
<script type="application/javascript" src="chrome://communicator/content/defaultClientDialog.js"/> |
||||
|
||||
<description>&defaultClient.intro;</description> |
||||
<listbox rows="4" id="defaultList"> |
||||
<listitem value="BROWSER" type="checkbox" label="&browser.label;"/> |
||||
<listitem value="MAIL" type="checkbox" label="&email.label;" disabled="true"/> |
||||
<listitem value="NEWS" type="checkbox" label="&newsgroups.label;" disabled="true"/> |
||||
<listitem value="RSS" type="checkbox" label="&feeds.label;" disabled="true"/> |
||||
</listbox> |
||||
|
||||
<separator class="thin"/> |
||||
<checkbox id="checkOnStartup" checked="true" label="&checkOnStartup.label;" accesskey="&checkOnStartup.accesskey;"/> |
||||
|
||||
</dialog> |
@ -1,73 +0,0 @@
|
||||
/* -*- 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/. */
|
||||
|
||||
const nsIShellService = Components.interfaces.nsIShellService; |
||||
var gShell = Components.classes["@binaryoutcast.com/navigator/shell-service;1"] |
||||
.getService(nsIShellService); |
||||
|
||||
var gImage, gPosition, gPicker, gDesktop; |
||||
|
||||
function onLoad() |
||||
{ |
||||
document.getElementById("itemsBox").hidden = /Mac/.test(navigator.platform); |
||||
gImage = window.arguments[0]; |
||||
gPosition = document.getElementById("position"); |
||||
gPicker = document.getElementById("picker"); |
||||
gDesktop = document.getElementById("desktop"); |
||||
|
||||
sizeToContent(); |
||||
window.innerWidth += screen.width / 2 - gDesktop.boxObject.width; |
||||
window.innerHeight += screen.height / 2 - gDesktop.boxObject.height; |
||||
|
||||
try { |
||||
var color = gShell.desktopBackgroundColor; |
||||
color = (0xF000000 | color).toString(16).toUpperCase().replace("F", "#"); |
||||
gDesktop.style.backgroundColor = color; |
||||
gPicker.color = color; |
||||
} catch (e) { |
||||
gPicker.parentNode.hidden = true; |
||||
} |
||||
|
||||
gDesktop.style.backgroundImage = 'url("' + gImage.src + '")'; |
||||
|
||||
updatePosition(); |
||||
} |
||||
|
||||
function onApply() |
||||
{ |
||||
if (!gPicker.parentNode.hidden) |
||||
gShell.desktopBackgroundColor = parseInt(gPicker.color.substr(1), 16); |
||||
|
||||
gShell.setDesktopBackground(gImage, nsIShellService[gPosition.value]); |
||||
} |
||||
|
||||
function updatePosition() |
||||
{ |
||||
gDesktop.style.backgroundPosition = "center"; |
||||
gDesktop.style.backgroundRepeat = "no-repeat"; |
||||
switch (gPosition.value) { |
||||
case "BACKGROUND_FIT": |
||||
gDesktop.style.backgroundSize = "contain"; |
||||
return; |
||||
case "BACKGROUND_FILL": |
||||
gDesktop.style.backgroundSize = "cover"; |
||||
return; |
||||
case "BACKGROUND_STRETCH": |
||||
gDesktop.style.backgroundPosition = ""; |
||||
gDesktop.style.backgroundSize = "100% 100%"; |
||||
return; |
||||
case "BACKGROUND_TILE": |
||||
gDesktop.style.backgroundPosition = ""; |
||||
gDesktop.style.backgroundRepeat = "repeat"; |
||||
} |
||||
gDesktop.style.backgroundSize = |
||||
(gImage.naturalWidth / 2) + "px " + (gImage.naturalHeight / 2) + "px"; |
||||
} |
||||
|
||||
function updateColor() |
||||
{ |
||||
gDesktop.style.backgroundColor = gPicker.color; |
||||
} |
@ -1,50 +0,0 @@
|
||||
<?xml version="1.0"?> |
||||
|
||||
<!-- 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://communicator/skin/" type="text/css"?> |
||||
|
||||
<!DOCTYPE dialog SYSTEM "chrome://communicator/locale/setDesktopBackground.dtd"> |
||||
|
||||
<dialog id="setDesktopBackground" |
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
||||
onload="onLoad();" |
||||
buttons="accept,extra2" |
||||
buttoniconaccept="close" |
||||
buttonlabelaccept="&close.label;" |
||||
buttoniconextra2="apply" |
||||
buttonlabelextra2="&apply.label;" |
||||
buttonaccesskeyextra2="&apply.accesskey;" |
||||
ondialogextra2="onApply();" |
||||
title="&setDesktopBackground.title;"> |
||||
|
||||
<script type="text/javascript" |
||||
src="chrome://communicator/content/setDesktopBackground.js"/> |
||||
|
||||
<hbox id="itemsBox" align="center"> |
||||
<label value="&position.label;" accesskey="&position.accesskey;"/> |
||||
<menulist id="position" |
||||
value="BACKGROUND_STRETCH" |
||||
persist="value" |
||||
oncommand="updatePosition();"> |
||||
<menupopup> |
||||
<menuitem value="BACKGROUND_TILE" label="&position.tile.label;"/> |
||||
<menuitem value="BACKGROUND_STRETCH" label="&position.stretch.label;"/> |
||||
<menuitem value="BACKGROUND_CENTER" label="&position.center.label;"/> |
||||
<menuitem value="BACKGROUND_FILL" label="&position.fill.label;"/> |
||||
<menuitem value="BACKGROUND_FIT" label="&position.fit.label;"/> |
||||
</menupopup> |
||||
</menulist> |
||||
<hbox flex="1" pack="end"> |
||||
<label value="&picker.label;" accesskey="&picker.accesskey;"/> |
||||
<colorpicker id="picker" type="button" onchange="updateColor();"/> |
||||
</hbox> |
||||
</hbox> |
||||
|
||||
<groupbox flex="1"> |
||||
<caption label="&preview.caption;"/> |
||||
<spacer id="desktop" flex="1"/> |
||||
</groupbox> |
||||
</dialog> |
@ -1,14 +0,0 @@
|
||||
# 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/. |
||||
|
||||
comm.jar: |
||||
content/communicator/defaultClientDialog.js (content/defaultClientDialog.js) |
||||
content/communicator/defaultClientDialog.xul (content/defaultClientDialog.xul) |
||||
content/communicator/setDesktopBackground.js (content/setDesktopBackground.js) |
||||
content/communicator/setDesktopBackground.xul (content/setDesktopBackground.xul) |
||||
|
||||
en-US.jar: |
||||
locale/en-US/communicator/defaultClientDialog.dtd (locale/defaultClientDialog.dtd) |
||||
locale/en-US/communicator/shellservice.properties (locale/shellservice.properties) |
||||
locale/en-US/communicator/setDesktopBackground.dtd (locale/setDesktopBackground.dtd) |
@ -1,14 +0,0 @@
|
||||
<!-- 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 defaultClient.title "Default Client"> |
||||
<!ENTITY defaultClient.intro "Use &brandShortName; as the default client for:"> |
||||
|
||||
<!ENTITY browser.label "Navigator"> |
||||
<!ENTITY email.label "E-Mail"> |
||||
<!ENTITY newsgroups.label "Newsgroups"> |
||||
<!ENTITY feeds.label "Feeds"> |
||||
|
||||
<!ENTITY checkOnStartup.label "Always perform this check when starting &brandShortName;"> |
||||
<!ENTITY checkOnStartup.accesskey "A"> |
@ -1,19 +0,0 @@
|
||||
<!-- 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 setDesktopBackground.title "Set Desktop Background"> |
||||
|
||||
<!ENTITY position.label "Position:"> |
||||
<!ENTITY position.accesskey "P"> |
||||
<!ENTITY position.tile.label "Tile"> |
||||
<!ENTITY position.stretch.label "Stretch"> |
||||
<!ENTITY position.center.label "Center"> |
||||
<!ENTITY position.fill.label "Fill"> |
||||
<!ENTITY position.fit.label "Fit"> |
||||
<!ENTITY picker.label "Color:"> |
||||
<!ENTITY picker.accesskey "C"> |
||||
<!ENTITY preview.caption "Preview"> |
||||
<!ENTITY apply.label "Apply"> |
||||
<!ENTITY apply.accesskey "A"> |
||||
<!ENTITY close.label "Close"> |
@ -1,7 +0,0 @@
|
||||
# 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/. |
||||
|
||||
preferencesLabel=%S &Preferences |
||||
safeModeLabel=%S &Safe Mode |
||||
desktopBackgroundLeafNameWin=Desktop Background.bmp |
@ -1,40 +0,0 @@
|
||||
# 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 += [ |
||||
'public/nsIShellService.idl', |
||||
] |
||||
|
||||
if CONFIG['OS_ARCH'] == 'WINNT': |
||||
XPIDL_SOURCES += [ |
||||
'public/nsIWindowsShellService.idl', |
||||
] |
||||
|
||||
XPIDL_MODULE = 'shellservice' |
||||
|
||||
if CONFIG['OS_ARCH'] == 'WINNT': |
||||
SOURCES += ['src/nsWindowsShellService.cpp'] |
||||
OS_LIBS += [ |
||||
'ole32', |
||||
'version', |
||||
'uuid', |
||||
'shell32', |
||||
] |
||||
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': |
||||
SOURCES += ['src/nsMacShellService.cpp'] |
||||
elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']: |
||||
SOURCES += ['src/nsGNOMEShellService.cpp'] |
||||
|
||||
if SOURCES: |
||||
EXTRA_COMPONENTS += [ |
||||
'nsSetDefault.manifest', |
||||
'src/nsSetDefault.js', |
||||
] |
||||
|
||||
FINAL_LIBRARY = 'navigatorcomps' |
||||
|
||||
CXXFLAGS += CONFIG['TK_CFLAGS'] |
||||
|
||||
JAR_MANIFESTS += ['jar.mn'] |
@ -1,3 +0,0 @@
|
||||
component {a3d5b950-690a-491f-a881-2c2cdcd241cb} nsSetDefault.js |
||||
contract @binaryoutcast.com/navigator/default-browser-clh;1 {a3d5b950-690a-491f-a881-2c2cdcd241cb} |
||||
category command-line-handler m-setdefault @binaryoutcast.com/navigator/default-browser-clh;1 |
@ -1,113 +0,0 @@
|
||||
/* -*- Mode: IDL; 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(4244d99e-0fbf-4cf3-903a-893634704e84)] |
||||
interface nsIShellService : nsISupports |
||||
{ |
||||
/** |
||||
* app types we can be registered to handle |
||||
*/ |
||||
const unsigned short BROWSER = 0x0001; |
||||
const unsigned short MAIL = 0x0002; |
||||
const unsigned short NEWS = 0x0004; |
||||
const unsigned short RSS = 0x0008; |
||||
|
||||
/** |
||||
* Determines whether or not SeaMonkey is the "Default Client" for the |
||||
* passed in app type. |
||||
* |
||||
* This is simply whether or not SeaMonkey is registered to handle |
||||
* the url schemes associated with the app. |
||||
* |
||||
* @param aStartupCheck true if this is the check being performed |
||||
* by the first window at startup, |
||||
* false otherwise. |
||||
* @param aApps the application types being tested (Browser, Mail, News, RSS) |
||||
*/ |
||||
boolean isDefaultClient(in boolean aStartupCheck, in unsigned short aApps); |
||||
|
||||
/** |
||||
* Registers SeaMonkey as the "Default Client" for the |
||||
* passed in app types. |
||||
* |
||||
* @param aForAllUsers Whether or not SeaMonkey should attempt |
||||
* to become the default client for all |
||||
* users on a multi-user system. |
||||
* @param aClaimAllTypes Register SeaMonkey as the handler for |
||||
* additional protocols (ftp, chrome etc) |
||||
* and web documents (.html, .xhtml etc). |
||||
* @param aApps the application types being tested (Mail, News, Browser, RSS) |
||||
*/ |
||||
void setDefaultClient(in boolean aForAllUsers, in boolean aClaimAllTypes, in unsigned short aApps); |
||||
|
||||
/** |
||||
* Used to determine whether or not to show a "Set Default Client" |
||||
* query dialog. This attribute is true if the application is starting |
||||
* up and "shell.checkDefaultClient" is true, otherwise it |
||||
* is false. |
||||
*/ |
||||
attribute boolean shouldCheckDefaultClient; |
||||
|
||||
|
||||
/** |
||||
* Returns the appTypes constants we should be the default client for. |
||||
* Saves/reads the default apps to/from the pref shell.checkDefaultApps |
||||
*/ |
||||
attribute unsigned short shouldBeDefaultClientFor; |
||||
|
||||
/** |
||||
* Attempt to determine whether it is possible to change the wallpaper. |
||||
*/ |
||||
readonly attribute boolean canSetDesktopBackground; |
||||
|
||||
/** |
||||
* 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); |
||||
|
||||
/** |
||||
* 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; |
||||
|
||||
/** |
||||
* 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. An RGB value (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; |
||||
}; |
||||
|
@ -1,18 +0,0 @@
|
||||
/* -*- 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(16e7e8da-8bef-4f41-be5f-045b2e9918e1)] |
||||
interface nsIWindowsShellService : nsIShellService |
||||
{ |
||||
/** |
||||
* Provides the shell service an opportunity to do some Win7+ shortcut |
||||
* maintenance needed on initial startup of the browser. |
||||
*/ |
||||
void shortcutMaintenance(); |
||||
}; |
||||
|
||||
|
@ -1,498 +0,0 @@
|
||||
/* -*- 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 "nsCOMPtr.h" |
||||
#include "nsComponentManagerUtils.h" |
||||
#include "nsDirectoryServiceDefs.h" |
||||
#include "nsDirectoryServiceUtils.h" |
||||
#include "nsGNOMEShellService.h" |
||||
#include "nsServiceManagerUtils.h" |
||||
#include "nsIGSettingsService.h" |
||||
#include "nsIGConfService.h" |
||||
#include "nsIGIOService.h" |
||||
#include "nsIPrefService.h" |
||||
#include "nsIStringBundle.h" |
||||
#include "nsIImageLoadingContent.h" |
||||
#include "nsIDOMElement.h" |
||||
#include "imgIRequest.h" |
||||
#include "imgIContainer.h" |
||||
#include "nsIImageToPixbuf.h" |
||||
#include "nsIFile.h" |
||||
#include "nsIProcess.h" |
||||
#include "prenv.h" |
||||
#include "mozilla/ArrayUtils.h" |
||||
#include "nsXULAppAPI.h" |
||||
#include <glib.h> |
||||
#include <glib-object.h> |
||||
#include <gtk/gtk.h> |
||||
#include <gdk/gdk.h> |
||||
#include <gdk-pixbuf/gdk-pixbuf.h> |
||||
|
||||
// GConf registry key constants
|
||||
#define DG_BACKGROUND "/desktop/gnome/background" |
||||
|
||||
#define DGB_OPTIONS DG_BACKGROUND "/picture_options" |
||||
#define DGB_IMAGE DG_BACKGROUND "/picture_filename" |
||||
#define DGB_DRAWBG DG_BACKGROUND "/draw_background" |
||||
#define DGB_COLOR DG_BACKGROUND "/primary_color" |
||||
|
||||
#define OGDB_SCHEMA "org.gnome.desktop.background" |
||||
#define OGDB_OPTIONS "picture-options" |
||||
#define OGDB_IMAGE "picture-uri" |
||||
#define OGDB_DRAWBG "draw-background" |
||||
#define OGDB_COLOR "primary-color" |
||||
|
||||
struct ProtocolAssociation { |
||||
uint16_t app; |
||||
const char* protocol; |
||||
}; |
||||
|
||||
struct MimeTypeAssociation { |
||||
uint16_t app; |
||||
const char* mimeType; |
||||
const char* extensions; |
||||
}; |
||||
|
||||
static const ProtocolAssociation gProtocols[] = { |
||||
{ nsIShellService::BROWSER, "http" }, |
||||
{ nsIShellService::BROWSER, "https" }, |
||||
{ nsIShellService::MAIL, "mailto" }, |
||||
{ nsIShellService::NEWS, "news" }, |
||||
{ nsIShellService::NEWS, "snews" }, |
||||
{ nsIShellService::RSS, "feed" } |
||||
}; |
||||
|
||||
static const MimeTypeAssociation gMimeTypes[] = { |
||||
{ nsIShellService::BROWSER, "text/html", "htm html" }, |
||||
{ nsIShellService::BROWSER, "application/xhtml+xml", "xhtml" }, |
||||
{ nsIShellService::MAIL, "message/rfc822", "eml" }, |
||||
{ nsIShellService::RSS, "application/rss+xml", "rss" } |
||||
}; |
||||
|
||||
NS_IMPL_ISUPPORTS(nsGNOMEShellService, nsIShellService) |
||||
|
||||
nsresult |
||||
GetBrandName(nsACString& aBrandName) |
||||
{ |
||||
// get the product brand name from localized strings
|
||||
nsresult rv; |
||||
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService("@mozilla.org/intl/stringbundle;1", &rv)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
|
||||
nsCOMPtr<nsIStringBundle> brandBundle; |
||||
rv = bundleService->CreateBundle(BRAND_PROPERTIES, getter_AddRefs(brandBundle)); |
||||
NS_ENSURE_TRUE(brandBundle, rv); |
||||
|
||||
nsString brandName; |
||||
rv = brandBundle->GetStringFromName(u"brandShortName", |
||||
getter_Copies(brandName)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
|
||||
CopyUTF16toUTF8(brandName, aBrandName); |
||||
return rv; |
||||
} |
||||
|
||||
nsresult |
||||
nsGNOMEShellService::Init() |
||||
{ |
||||
nsresult rv; |
||||
|
||||
// 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; |
||||
|
||||
const char* launcher = PR_GetEnv("MOZ_APP_LAUNCHER"); |
||||
if (launcher) { |
||||
if (g_path_is_absolute(launcher)) { |
||||
mAppPath = launcher; |
||||
gchar* basename = g_path_get_basename(launcher); |
||||
gchar* fullpath = g_find_program_in_path(basename); |
||||
mAppIsInPath = fullpath && mAppPath.Equals(fullpath); |
||||
g_free(fullpath); |
||||
g_free(basename); |
||||
return NS_OK; |
||||
} |
||||
|
||||
gchar* fullpath = g_find_program_in_path(launcher); |
||||
if (fullpath) { |
||||
mAppPath = fullpath; |
||||
mAppIsInPath = true; |
||||
g_free(fullpath); |
||||
return NS_OK; |
||||
} |
||||
} |
||||
|
||||
nsCOMPtr<nsIFile> appPath; |
||||
rv = NS_GetSpecialDirectory(XRE_EXECUTABLE_FILE, getter_AddRefs(appPath)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
|
||||
return appPath->GetNativePath(mAppPath); |
||||
} |
||||
|
||||
bool |
||||
nsGNOMEShellService::HandlerMatchesAppName(const char* aHandler) |
||||
{ |
||||
bool matches = false; |
||||
gint argc; |
||||
gchar** argv; |
||||
if (g_shell_parse_argv(aHandler, &argc, &argv, nullptr) && argc > 0) { |
||||
gchar* command = nullptr; |
||||
if (!mUseLocaleFilenames) |
||||
command = g_find_program_in_path(argv[0]); |
||||
else { |
||||
gchar* nativeFile = g_filename_from_utf8(argv[0], -1, |
||||
nullptr, nullptr, nullptr); |
||||
if (nativeFile) { |
||||
command = g_find_program_in_path(nativeFile); |
||||
g_free(nativeFile); |
||||
} |
||||
} |
||||
matches = command && mAppPath.Equals(command); |
||||
g_free(command); |
||||
g_strfreev(argv); |
||||
} |
||||
|
||||
return matches; |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::IsDefaultClient(bool aStartupCheck, uint16_t aApps, |
||||
bool* aIsDefaultClient) |
||||
{ |
||||
if (aStartupCheck) |
||||
mCheckedThisSessionClient = true; |
||||
|
||||
*aIsDefaultClient = false; |
||||
nsCString handler; |
||||
nsCOMPtr<nsIGIOMimeApp> app; |
||||
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); |
||||
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); |
||||
|
||||
for (unsigned i = 0; i < mozilla::ArrayLength(gProtocols); i++) { |
||||
if (aApps & gProtocols[i].app) { |
||||
nsDependentCString protocol(gProtocols[i].protocol); |
||||
if (giovfs) { |
||||
giovfs->GetAppForURIScheme(protocol, getter_AddRefs(app)); |
||||
if (!app) |
||||
return NS_OK; |
||||
|
||||
if (NS_SUCCEEDED(app->GetCommand(handler)) && |
||||
!HandlerMatchesAppName(handler.get())) |
||||
return NS_OK; |
||||
} |
||||
|
||||
bool enabled; |
||||
if (gconf && |
||||
NS_SUCCEEDED(gconf->GetAppForProtocol(protocol, &enabled, handler)) && |
||||
(!enabled || !HandlerMatchesAppName(handler.get()))) |
||||
return NS_OK; |
||||
} |
||||
} |
||||
|
||||
*aIsDefaultClient = true; |
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::SetDefaultClient(bool aForAllUsers, |
||||
bool aClaimAllTypes, uint16_t aApps) |
||||
{ |
||||
nsresult rv; |
||||
|
||||
nsCOMPtr<nsIGIOMimeApp> app; |
||||
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); |
||||
if (giovfs) { |
||||
nsCString brandName; |
||||
rv = GetBrandName(brandName); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
|
||||
rv = giovfs->CreateAppFromCommand(mAppPath, brandName, getter_AddRefs(app)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
|
||||
for (unsigned i = 0; i < mozilla::ArrayLength(gMimeTypes); i++) { |
||||
if (aApps & gMimeTypes[i].app) { |
||||
rv = app->SetAsDefaultForMimeType(nsDependentCString(gMimeTypes[i].mimeType)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
rv = app->SetAsDefaultForFileExtensions(nsDependentCString(gMimeTypes[i].extensions)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
} |
||||
} |
||||
} |
||||
|
||||
nsCString appKeyValue; |
||||
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); |
||||
if (gconf) { |
||||
if (!mAppIsInPath) |
||||
appKeyValue = mAppPath; |
||||
else { |
||||
gchar* basename = g_path_get_basename(mAppPath.get()); |
||||
appKeyValue = basename; |
||||
g_free(basename); |
||||
} |
||||
appKeyValue.AppendLiteral(" %s"); |
||||
} |
||||
|
||||
for (unsigned i = 0; i < mozilla::ArrayLength(gProtocols); i++) { |
||||
if (aApps & gProtocols[i].app) { |
||||
nsDependentCString protocol(gProtocols[i].protocol); |
||||
if (app) { |
||||
rv = app->SetAsDefaultForURIScheme(protocol); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
} |
||||
if (gconf) { |
||||
rv = gconf->SetAppForProtocol(protocol, appKeyValue); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::GetShouldCheckDefaultClient(bool* aResult) |
||||
{ |
||||
if (mCheckedThisSessionClient) { |
||||
*aResult = false; |
||||
return NS_OK; |
||||
} |
||||
|
||||
nsresult rv; |
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
return prefs->GetBoolPref(PREF_CHECKDEFAULTCLIENT, aResult); |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::SetShouldCheckDefaultClient(bool aShouldCheck) |
||||
{ |
||||
nsresult rv; |
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
return prefs->SetBoolPref(PREF_CHECKDEFAULTCLIENT, aShouldCheck); |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::GetShouldBeDefaultClientFor(uint16_t* aApps) |
||||
{ |
||||
nsresult rv; |
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
int32_t result; |
||||
rv = prefs->GetIntPref("shell.checkDefaultApps", &result); |
||||
*aApps = result; |
||||
return rv; |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::SetShouldBeDefaultClientFor(uint16_t aApps) |
||||
{ |
||||
nsresult rv; |
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
return prefs->SetIntPref("shell.checkDefaultApps", aApps); |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::GetCanSetDesktopBackground(bool* aResult) |
||||
{ |
||||
nsCOMPtr<nsIGConfService> gconf(do_GetService(NS_GCONFSERVICE_CONTRACTID)); |
||||
*aResult = gconf && getenv("GNOME_DESKTOP_SESSION_ID"); |
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement, |
||||
int32_t aPosition) |
||||
{ |
||||
nsCString brandName; |
||||
nsresult rv = GetBrandName(brandName); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
|
||||
// build the file name
|
||||
nsCString filePath(PR_GetEnv("HOME")); |
||||
filePath.Append('/'); |
||||
filePath.Append(brandName); |
||||
filePath.AppendLiteral("_wallpaper.png"); |
||||
|
||||
// get the image container
|
||||
nsCOMPtr<nsIImageLoadingContent> imageContent(do_QueryInterface(aElement, &rv)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
|
||||
nsCOMPtr<imgIRequest> request; |
||||
rv = imageContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, |
||||
getter_AddRefs(request)); |
||||
NS_ENSURE_TRUE(request, rv); |
||||
|
||||
nsCOMPtr<imgIContainer> container; |
||||
rv = request->GetImage(getter_AddRefs(container)); |
||||
NS_ENSURE_TRUE(request, rv); |
||||
|
||||
nsCOMPtr<nsIImageToPixbuf> imgToPixbuf(do_GetService("@mozilla.org/widget/image-to-gdk-pixbuf;1")); |
||||
if (!imgToPixbuf) |
||||
return NS_ERROR_NOT_AVAILABLE; |
||||
|
||||
GdkPixbuf* pixbuf = imgToPixbuf->ConvertImageToPixbuf(container); |
||||
if (!pixbuf) |
||||
return NS_ERROR_NOT_AVAILABLE; |
||||
|
||||
// write the image to a file in the home dir
|
||||
gboolean res = gdk_pixbuf_save(pixbuf, filePath.get(), "png", |
||||
nullptr, nullptr); |
||||
|
||||
g_object_unref(pixbuf); |
||||
if (!res) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
// set desktop wallpaper filling style
|
||||
const char* options; |
||||
switch (aPosition) { |
||||
case BACKGROUND_TILE: |
||||
options = "wallpaper"; |
||||
break; |
||||
case BACKGROUND_STRETCH: |
||||
options = "stretched"; |
||||
break; |
||||
case BACKGROUND_FILL: |
||||
options = "zoom"; |
||||
break; |
||||
case BACKGROUND_FIT: |
||||
options = "scaled"; |
||||
break; |
||||
default: |
||||
options = "centered"; |
||||
break; |
||||
} |
||||
|
||||
// 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(OGDB_SCHEMA), |
||||
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(OGDB_OPTIONS), |
||||
nsDependentCString(options)); |
||||
background_settings->SetString(NS_LITERAL_CSTRING(OGDB_IMAGE), |
||||
nsDependentCString(file_uri)); |
||||
g_free(file_uri); |
||||
background_settings->SetBoolean(NS_LITERAL_CSTRING(OGDB_DRAWBG), true); |
||||
return NS_OK; |
||||
} |
||||
} |
||||
|
||||
// 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(DGB_OPTIONS), nsDependentCString(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 SeaMonkey_wallpaper.png
|
||||
// and nautilus doesn't monitor the file for changes).
|
||||
gconf->SetString(NS_LITERAL_CSTRING(DGB_IMAGE), EmptyCString()); |
||||
gconf->SetString(NS_LITERAL_CSTRING(DGB_IMAGE), filePath); |
||||
gconf->SetBool(NS_LITERAL_CSTRING(DGB_DRAWBG), true); |
||||
} |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
#define COLOR_16_TO_8_BIT(_c) ((_c) >> 8) |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::GetDesktopBackgroundColor(uint32_t *aColor) |
||||
{ |
||||
nsCOMPtr<nsIGSettingsService> gsettings(do_GetService(NS_GSETTINGSSERVICE_CONTRACTID)); |
||||
nsCOMPtr<nsIGSettingsCollection> background_settings; |
||||
|
||||
if (gsettings) |
||||
gsettings->GetCollectionForSchema(NS_LITERAL_CSTRING(OGDB_SCHEMA), |
||||
getter_AddRefs(background_settings)); |
||||
|
||||
nsCString background; |
||||
if (background_settings) |
||||
background_settings->GetString(NS_LITERAL_CSTRING(OGDB_COLOR), |
||||
background); |
||||
else { |
||||
nsCOMPtr<nsIGConfService> gconf(do_GetService(NS_GCONFSERVICE_CONTRACTID)); |
||||
if (gconf) |
||||
gconf->GetString(NS_LITERAL_CSTRING(DGB_COLOR), background); |
||||
} |
||||
|
||||
if (background.IsEmpty()) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
GdkColor color; |
||||
NS_ENSURE_TRUE(gdk_color_parse(background.get(), &color), 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; |
||||
} |
||||
|
||||
#define COLOR_8_TO_16_BIT(_c) ((_c) << 8 | (_c)) |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::SetDesktopBackgroundColor(uint32_t aColor) |
||||
{ |
||||
NS_ENSURE_ARG_MAX(aColor, 0xFFFFFF); |
||||
|
||||
uint8_t red = aColor >> 16; |
||||
uint8_t green = aColor >> 8; |
||||
uint8_t blue = aColor; |
||||
char colorString[14]; |
||||
sprintf(colorString, "#%04x%04x%04x", COLOR_8_TO_16_BIT(red), |
||||
COLOR_8_TO_16_BIT(green), COLOR_8_TO_16_BIT(blue)); |
||||
|
||||
nsCOMPtr<nsIGSettingsService> gsettings(do_GetService(NS_GSETTINGSSERVICE_CONTRACTID)); |
||||
if (gsettings) { |
||||
nsCOMPtr<nsIGSettingsCollection> background_settings; |
||||
gsettings->GetCollectionForSchema(NS_LITERAL_CSTRING(OGDB_SCHEMA), |
||||
getter_AddRefs(background_settings)); |
||||
if (background_settings) { |
||||
background_settings->SetString(NS_LITERAL_CSTRING(OGDB_COLOR), |
||||
nsDependentCString(colorString)); |
||||
return NS_OK; |
||||
} |
||||
} |
||||
|
||||
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); |
||||
if (gconf) |
||||
gconf->SetString(NS_LITERAL_CSTRING(DGB_COLOR), nsDependentCString(colorString)); |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
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 = PromiseFlatCString(aURI); |
||||
const char* specStr = spec.get(); |
||||
return process->Run(false, &specStr, 1); |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsGNOMEShellService::GetDefaultFeedReader(nsIFile** _retval) |
||||
{ |
||||
return NS_ERROR_NOT_IMPLEMENTED; |
||||
} |
@ -1,39 +0,0 @@
|
||||
/* -*- 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 "nsShellService.h" |
||||
#include "nsStringGlue.h" |
||||
#include "mozilla/Attributes.h" |
||||
|
||||
#define NS_SUITEGNOMEINTEGRATION_CID \ |
||||
{0xc16cfa25, 0xa74a, 0x420b, {0xa5, 0x45, 0x4b, 0xc0, 0x6b, 0x08, 0xa8, 0x65}} |
||||
|
||||
struct ProtocolAssociation; |
||||
|
||||
class nsGNOMEShellService final : public nsIShellService |
||||
{ |
||||
public: |
||||
nsGNOMEShellService() : mCheckedThisSessionClient(false) { } |
||||
|
||||
NS_DECL_ISUPPORTS |
||||
NS_DECL_NSISHELLSERVICE |
||||
|
||||
nsresult Init(); |
||||
|
||||
private: |
||||
~nsGNOMEShellService() {} |
||||
bool HandlerMatchesAppName(const char* aHandler); |
||||
|
||||
nsCString mAppPath; |
||||
bool mAppIsInPath; |
||||
bool mUseLocaleFilenames; |
||||
bool mCheckedThisSessionClient; |
||||
}; |
||||
|
||||
#endif // nsgnomeshellservice_h____
|
||||
|
@ -1,457 +0,0 @@
|
||||
/* -*- 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 "nsCOMPtr.h" |
||||
#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 "nsIProperties.h" |
||||
#include "nsServiceManagerUtils.h" |
||||
|
||||
#include <ApplicationServices/ApplicationServices.h> |
||||
|
||||
#define SAFARI_BUNDLE_IDENTIFIER "com.apple.Safari" |
||||
|
||||
NS_IMPL_ISUPPORTS(nsMacShellService, nsIShellService, nsIWebProgressListener) |
||||
|
||||
NS_IMETHODIMP |
||||
nsMacShellService::IsDefaultClient(bool aStartupCheck, uint16_t aApps, bool *aIsDefaultClient) |
||||
{ |
||||
// If this is the first window, maintain internal state that we've
|
||||
// checked this session (so that subsequent window opens don't show the
|
||||
// default client dialog).
|
||||
if (aStartupCheck) |
||||
mCheckedThisSessionClient = true; |
||||
|
||||
*aIsDefaultClient = false; |
||||
|
||||
if (aApps & nsIShellService::BROWSER) |
||||
if(!isDefaultHandlerForProtocol(CFSTR("http"))) |
||||
return NS_OK; |
||||
if (aApps & nsIShellService::MAIL) |
||||
if(!isDefaultHandlerForProtocol(CFSTR("mailto"))) |
||||
return NS_OK; |
||||
if (aApps & nsIShellService::NEWS) |
||||
if(!isDefaultHandlerForProtocol(CFSTR("news"))) |
||||
return NS_OK; |
||||
if (aApps & nsIShellService::RSS) |
||||
if(!isDefaultHandlerForProtocol(CFSTR("feed"))) |
||||
return NS_OK; |
||||
|
||||
*aIsDefaultClient = true; |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsMacShellService::SetDefaultClient(bool aForAllUsers, |
||||
bool aClaimAllTypes, uint16_t aApps) |
||||
{ |
||||
// Note: We don't support aForAllUsers on Mac OS X.
|
||||
|
||||
CFStringRef suiteID = ::CFBundleGetIdentifier(::CFBundleGetMainBundle()); |
||||
if (!suiteID) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
if (aApps & nsIShellService::BROWSER) |
||||
{ |
||||
if (::LSSetDefaultHandlerForURLScheme(CFSTR("http"), suiteID) != noErr) |
||||
return NS_ERROR_FAILURE; |
||||
if (::LSSetDefaultHandlerForURLScheme(CFSTR("https"), suiteID) != noErr) |
||||
return NS_ERROR_FAILURE; |
||||
if (::LSSetDefaultRoleHandlerForContentType(kUTTypeHTML, kLSRolesAll, suiteID) != noErr) |
||||
return NS_ERROR_FAILURE; |
||||
if (::LSSetDefaultRoleHandlerForContentType(CFSTR("public.xhtml"), kLSRolesAll, suiteID) != noErr) |
||||
return NS_ERROR_FAILURE; |
||||
} |
||||
|
||||
if (aApps & nsIShellService::MAIL) |
||||
if (::LSSetDefaultHandlerForURLScheme(CFSTR("mailto"), suiteID) != noErr) |
||||
return NS_ERROR_FAILURE; |
||||
if (aApps & nsIShellService::NEWS) |
||||
if (::LSSetDefaultHandlerForURLScheme(CFSTR("news"), suiteID) != noErr) |
||||
return NS_ERROR_FAILURE; |
||||
if (aApps & nsIShellService::RSS) |
||||
if (::LSSetDefaultHandlerForURLScheme(CFSTR("feed"), suiteID) != noErr) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsMacShellService::GetShouldCheckDefaultClient(bool* aResult) |
||||
{ |
||||
if (mCheckedThisSessionClient) |
||||
{ |
||||
*aResult = false; |
||||
return NS_OK; |
||||
} |
||||
|
||||
nsresult rv; |
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
return prefs->GetBoolPref(PREF_CHECKDEFAULTCLIENT, aResult); |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsMacShellService::SetShouldCheckDefaultClient(bool aShouldCheck) |
||||
{ |
||||
nsresult rv; |
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
return prefs->SetBoolPref(PREF_CHECKDEFAULTCLIENT, aShouldCheck); |
||||
} |
||||
|
||||
bool |
||||
nsMacShellService::isDefaultHandlerForProtocol(CFStringRef aScheme) |
||||
{ |
||||
bool isDefault = false; |
||||
|
||||
CFStringRef suiteID = ::CFBundleGetIdentifier(::CFBundleGetMainBundle()); |
||||
if (!suiteID) |
||||
{ |
||||
// CFBundleGetIdentifier is expected to return nullptr only if the specified
|
||||
// bundle doesn't have a bundle identifier in its dictionary. In this case,
|
||||
// that means a failure, since our bundle does have an identifier.
|
||||
return isDefault; |
||||
} |
||||
|
||||
// Get the default handler's bundle ID for the scheme.
|
||||
CFStringRef defaultHandlerID = ::LSCopyDefaultHandlerForURLScheme(aScheme); |
||||
if (defaultHandlerID) |
||||
{ |
||||
// The handler ID in LaunchServices is in all lower case, but the bundle
|
||||
// identifier could have upper case characters. So we're using
|
||||
// CFStringCompare with the kCFCompareCaseInsensitive option here.
|
||||
isDefault = ::CFStringCompare(suiteID, defaultHandlerID, |
||||
kCFCompareCaseInsensitive) == kCFCompareEqualTo; |
||||
::CFRelease(defaultHandlerID); |
||||
} |
||||
|
||||
return isDefault; |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsMacShellService::GetShouldBeDefaultClientFor(uint16_t* aApps) |
||||
{ |
||||
nsresult rv; |
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
int32_t result; |
||||
rv = prefs->GetIntPref("shell.checkDefaultApps", &result); |
||||
*aApps = result; |
||||
return rv; |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
nsMacShellService::SetShouldBeDefaultClientFor(uint16_t aApps) |
||||
{ |
||||
nsresult rv; |
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); |
||||
NS_ENSURE_SUCCESS(rv, rv); |
||||
return prefs->SetIntPref("shell.checkDefaultApps", aApps); |
||||
} |
||||
|
||||
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 image 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) |
||||
{ |
||||
bool exists = false; |
||||
mBackgroundFile->Exists(&exists); |
||||
|