summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-04-04 08:44:14 -0400
committerMatt A. Tobin <email@mattatobin.com>2018-04-04 08:44:14 -0400
commit20cae79eb3ce238022056d104e2efcb03139f2e1 (patch)
tree6a3d4dba4d7829d5035e00ca809f52d4fc43a5e4
parent99831baf2e2d98caefbf1c7a212613ad5d6360a9 (diff)
downloadUXP-20cae79eb3ce238022056d104e2efcb03139f2e1.tar
UXP-20cae79eb3ce238022056d104e2efcb03139f2e1.tar.gz
UXP-20cae79eb3ce238022056d104e2efcb03139f2e1.tar.lz
UXP-20cae79eb3ce238022056d104e2efcb03139f2e1.tar.xz
UXP-20cae79eb3ce238022056d104e2efcb03139f2e1.zip
[PALEMOON] Wholesale steal Basilisk's shell component
-rw-r--r--application/palemoon/components/shell/Makefile.in11
-rw-r--r--application/palemoon/components/shell/ShellService.jsm114
-rw-r--r--application/palemoon/components/shell/content/setDesktopBackground.js253
-rw-r--r--application/palemoon/components/shell/jar.mn2
-rw-r--r--application/palemoon/components/shell/moz.build12
-rw-r--r--application/palemoon/components/shell/nsGNOMEShellService.cpp77
-rw-r--r--application/palemoon/components/shell/nsGNOMEShellService.h16
-rw-r--r--application/palemoon/components/shell/nsIGNOMEShellService.idl19
-rw-r--r--application/palemoon/components/shell/nsIMacShellService.idl2
-rw-r--r--application/palemoon/components/shell/nsIShellService.idl19
-rw-r--r--application/palemoon/components/shell/nsIWindowsShellService.idl2
-rw-r--r--application/palemoon/components/shell/nsMacShellService.cpp76
-rw-r--r--application/palemoon/components/shell/nsMacShellService.h4
-rw-r--r--application/palemoon/components/shell/nsSetDefaultBrowser.js11
-rw-r--r--application/palemoon/components/shell/nsShellService.h2
-rw-r--r--application/palemoon/components/shell/nsWindowsShellService.cpp349
-rw-r--r--application/palemoon/components/shell/nsWindowsShellService.h8
17 files changed, 553 insertions, 424 deletions
diff --git a/application/palemoon/components/shell/Makefile.in b/application/palemoon/components/shell/Makefile.in
deleted file mode 100644
index df084b709..000000000
--- a/application/palemoon/components/shell/Makefile.in
+++ /dev/null
@@ -1,11 +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/.
-
-include $(topsrcdir)/config/rules.mk
-
-CXXFLAGS += $(TK_CFLAGS)
-
-clobber::
- rm -f $(DIST)/lib/$(LIBRARY_NAME).lib
diff --git a/application/palemoon/components/shell/ShellService.jsm b/application/palemoon/components/shell/ShellService.jsm
new file mode 100644
index 000000000..12e275bdb
--- /dev/null
+++ b/application/palemoon/components/shell/ShellService.jsm
@@ -0,0 +1,114 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this file,
+* You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["ShellService"];
+
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/AppConstants.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "WindowsRegistry",
+ "resource://gre/modules/WindowsRegistry.jsm");
+
+/**
+ * Internal functionality to save and restore the docShell.allow* properties.
+ */
+let ShellServiceInternal = {
+ /**
+ * Used to determine whether or not to offer "Set as desktop background"
+ * functionality. Even if shell service is available it is not
+ * guaranteed that it is able to set the background for every desktop
+ * which is especially true for Linux with its many different desktop
+ * environments.
+ */
+ get canSetDesktopBackground() {
+ if (AppConstants.platform == "win" ||
+ AppConstants.platform == "macosx") {
+ return true;
+ }
+
+ if (AppConstants.platform == "linux") {
+ if (this.shellService) {
+ let linuxShellService = this.shellService
+ .QueryInterface(Ci.nsIGNOMEShellService);
+ return linuxShellService.canSetDesktopBackground;
+ }
+ }
+
+ return false;
+ },
+
+ /**
+ * Used to determine whether or not to show a "Set Default Browser"
+ * query dialog. This attribute is true if the application is starting
+ * up and "browser.shell.checkDefaultBrowser" is true, otherwise it
+ * is false.
+ */
+ _checkedThisSession: false,
+ get shouldCheckDefaultBrowser() {
+ // If we've already checked, the browser has been started and this is a
+ // new window open, and we don't want to check again.
+ if (this._checkedThisSession) {
+ return false;
+ }
+
+ if (!Services.prefs.getBoolPref("browser.shell.checkDefaultBrowser")) {
+ return false;
+ }
+
+ if (AppConstants.platform == "win") {
+ let optOutValue = WindowsRegistry.readRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+ "Software\\Mozilla\\PaleMoon",
+ "DefaultBrowserOptOut");
+ WindowsRegistry.removeRegKey(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
+ "Software\\Mozilla\\PaleMoon",
+ "DefaultBrowserOptOut");
+ if (optOutValue == "True") {
+ Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", false);
+ return false;
+ }
+ }
+
+ return true;
+ },
+
+ set shouldCheckDefaultBrowser(shouldCheck) {
+ Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", !!shouldCheck);
+ },
+
+ isDefaultBrowser(startupCheck, forAllTypes) {
+ // If this is the first browser window, maintain internal state that we've
+ // checked this session (so that subsequent window opens don't show the
+ // default browser dialog).
+ if (startupCheck) {
+ this._checkedThisSession = true;
+ }
+ if (this.shellService) {
+ return this.shellService.isDefaultBrowser(startupCheck, forAllTypes);
+ }
+ return false;
+ }
+};
+
+XPCOMUtils.defineLazyServiceGetter(ShellServiceInternal, "shellService",
+ "@mozilla.org/browser/shell-service;1", Ci.nsIShellService);
+
+/**
+ * The external API exported by this module.
+ */
+this.ShellService = new Proxy(ShellServiceInternal, {
+ get(target, name) {
+ if (name in target) {
+ return target[name];
+ }
+ if (target.shellService) {
+ return target.shellService[name];
+ }
+ Services.console.logStringMessage(`${name} not found in ShellService: ${target.shellService}`);
+ return undefined;
+ }
+});
diff --git a/application/palemoon/components/shell/content/setDesktopBackground.js b/application/palemoon/components/shell/content/setDesktopBackground.js
index e90a32d03..53cc70db0 100644
--- a/application/palemoon/components/shell/content/setDesktopBackground.js
+++ b/application/palemoon/components/shell/content/setDesktopBackground.js
@@ -1,16 +1,14 @@
-# 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 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/. */
+
+Components.utils.import("resource://gre/modules/AppConstants.jsm");
var Ci = Components.interfaces;
var gSetBackground = {
-#ifndef XP_MACOSX
- _position : "",
- _backgroundColor : 0,
-#else
- _position : "STRETCH",
-#endif
+ _position : AppConstants.platform == "macosx" ? "STRETCH" : "",
+ _backgroundColor : AppConstants.platform != "macosx" ? 0 : undefined,
_screenWidth : 0,
_screenHeight : 0,
_image : null,
@@ -27,23 +25,23 @@ var gSetBackground = {
this._canvas = document.getElementById("screen");
this._screenWidth = screen.width;
this._screenHeight = screen.height;
-#ifdef XP_MACOSX
- document.documentElement.getButton("accept").hidden = true;
-#endif
+ if (AppConstants.platform == "macosx") {
+ document.documentElement.getButton("accept").hidden = true;
+ }
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;
+ if (AppConstants.platform == "win") {
+ // Hide fill + fit options if < Win7 since they don't work.
+ var version = Components.classes["@mozilla.org/system-info;1"]
+ .getService(Ci.nsIPropertyBag2)
+ .getProperty("version");
+ var isWindows7OrHigher = (parseFloat(version) >= 6.1);
+ if (!isWindows7OrHigher) {
+ document.getElementById("fillPosition").hidden = true;
+ document.getElementById("fitPosition").hidden = true;
+ }
}
-#endif
// make sure that the correct dimensions will be used
setTimeout(function(self) {
@@ -62,92 +60,37 @@ var gSetBackground = {
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
+ if (AppConstants.platform != "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;
+ }
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)
+ setDesktopBackground: function ()
{
- if (aTopic == "shell:desktop-background-changed") {
- document.getElementById("setDesktopBackground").hidden = true;
- document.getElementById("showDesktopPreferences").hidden = false;
-
+ if (AppConstants.platform != "macosx") {
+ document.persist("menuPosition", "value");
+ this._shell.desktopBackgroundColor = this._hexStringToLong(this._backgroundColor);
+ } else {
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
+ .addObserver(this, "shell:desktop-background-changed", false);
- 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
+ var bundle = document.getElementById("backgroundBundle");
+ var setDesktopBackground = document.getElementById("setDesktopBackground");
+ setDesktopBackground.disabled = true;
+ setDesktopBackground.label = bundle.getString("DesktopBackgroundDownloading");
+ }
this._shell.setDesktopBackground(this._image,
Ci.nsIShellService["BACKGROUND_" + this._position]);
},
@@ -157,9 +100,9 @@ var gSetBackground = {
var ctx = this._canvas.getContext("2d");
ctx.clearRect(0, 0, this._screenWidth, this._screenHeight);
-#ifndef XP_MACOSX
- this._position = document.getElementById("menuPosition").value;
-#endif
+ if (AppConstants.platform != "macosx") {
+ this._position = document.getElementById("menuPosition").value;
+ }
switch (this._position) {
case "TILE":
@@ -171,43 +114,101 @@ var gSetBackground = {
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;
+ case "CENTER": {
+ let x = (this._screenWidth - this._image.naturalWidth) / 2;
+ let y = (this._screenHeight - this._image.naturalHeight) / 2;
ctx.drawImage(this._image, x, y);
break;
- case "FILL":
- //Try maxing width first, overflow height
- var widthRatio = this._screenWidth / this._image.naturalWidth;
- var width = this._image.naturalWidth * widthRatio;
- var height = this._image.naturalHeight * widthRatio;
+ }
+ case "FILL": {
+ // Try maxing width first, overflow height.
+ let widthRatio = this._screenWidth / this._image.naturalWidth;
+ let width = this._image.naturalWidth * widthRatio;
+ let height = this._image.naturalHeight * widthRatio;
if (height < this._screenHeight) {
- //height less than screen, max height and overflow width
- var heightRatio = this._screenHeight / this._image.naturalHeight;
+ // Height less than screen, max height and overflow width.
+ let heightRatio = this._screenHeight / this._image.naturalHeight;
width = this._image.naturalWidth * heightRatio;
height = this._image.naturalHeight * heightRatio;
}
- var x = (this._screenWidth - width) / 2;
- var y = (this._screenHeight - height) / 2;
+ let x = (this._screenWidth - width) / 2;
+ let y = (this._screenHeight - height) / 2;
ctx.drawImage(this._image, x, y, width, height);
break;
- case "FIT":
- //Try maxing width first, top and bottom borders
- 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;
+ }
+ case "FIT": {
+ // Try maxing width first, top and bottom borders.
+ let widthRatio = this._screenWidth / this._image.naturalWidth;
+ let width = this._image.naturalWidth * widthRatio;
+ let height = this._image.naturalHeight * widthRatio;
+ let x = 0;
+ let y = (this._screenHeight - height) / 2;
if (height > this._screenHeight) {
- //height overflow, maximise height, side borders
- var heightRatio = this._screenHeight / this._image.naturalHeight;
+ // Height overflow, maximise height, side borders.
+ let heightRatio = this._screenHeight / this._image.naturalHeight;
width = this._image.naturalWidth * heightRatio;
height = this._image.naturalHeight * heightRatio;
x = (this._screenWidth - width) / 2;
y = 0;
}
ctx.drawImage(this._image, x, y, width, height);
- break;
+ break;
+ }
}
}
};
+
+if (AppConstants.platform != "macosx") {
+ gSetBackground["_initColor"] = function ()
+ {
+ var color = this._shell.desktopBackgroundColor;
+
+ const rMask = 4294901760;
+ const gMask = 65280;
+ const bMask = 255;
+ var r = (color & rMask) >> 16;
+ var g = (color & gMask) >> 8;
+ var b = (color & bMask);
+ this.updateColor(this._rgbToHex(r, g, b));
+
+ var colorpicker = document.getElementById("desktopColor");
+ colorpicker.color = this._backgroundColor;
+ };
+
+ gSetBackground["updateColor"] = function (aColor)
+ {
+ this._backgroundColor = aColor;
+ this._canvas.style.backgroundColor = aColor;
+ };
+
+ // Converts a color string in the format "#RRGGBB" to an integer.
+ gSetBackground["_hexStringToLong"] = function (aString)
+ {
+ return parseInt(aString.substring(1, 3), 16) << 16 |
+ parseInt(aString.substring(3, 5), 16) << 8 |
+ parseInt(aString.substring(5, 7), 16);
+ };
+
+ gSetBackground["_rgbToHex"] = function (aR, aG, aB)
+ {
+ return "#" + [aR, aG, aB].map(aInt => aInt.toString(16).replace(/^(.)$/, "0$1"))
+ .join("").toUpperCase();
+ };
+} else {
+ gSetBackground["observe"] = function (aSubject, aTopic, aData)
+ {
+ if (aTopic == "shell:desktop-background-changed") {
+ document.getElementById("setDesktopBackground").hidden = true;
+ document.getElementById("showDesktopPreferences").hidden = false;
+
+ Components.classes["@mozilla.org/observer-service;1"]
+ .getService(Ci.nsIObserverService)
+ .removeObserver(this, "shell:desktop-background-changed");
+ }
+ };
+
+ gSetBackground["showDesktopPrefs"] = function()
+ {
+ this._shell.openApplication(Ci.nsIMacShellService.APPLICATION_DESKTOP);
+ };
+}
diff --git a/application/palemoon/components/shell/jar.mn b/application/palemoon/components/shell/jar.mn
index eed15c397..1f33b5d56 100644
--- a/application/palemoon/components/shell/jar.mn
+++ b/application/palemoon/components/shell/jar.mn
@@ -4,4 +4,4 @@
browser.jar:
* content/browser/setDesktopBackground.xul (content/setDesktopBackground.xul)
-* content/browser/setDesktopBackground.js (content/setDesktopBackground.js)
+ content/browser/setDesktopBackground.js (content/setDesktopBackground.js)
diff --git a/application/palemoon/components/shell/moz.build b/application/palemoon/components/shell/moz.build
index 38965c5d7..94ec88571 100644
--- a/application/palemoon/components/shell/moz.build
+++ b/application/palemoon/components/shell/moz.build
@@ -1,4 +1,4 @@
-# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -18,6 +18,10 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
XPIDL_SOURCES += [
'nsIMacShellService.idl',
]
+elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
+ XPIDL_SOURCES += [
+ 'nsIGNOMEShellService.idl',
+ ]
XPIDL_MODULE = 'shellservice'
@@ -29,7 +33,7 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
SOURCES += [
'nsMacShellService.cpp',
]
-elif CONFIG['MOZ_WIDGET_GTK']:
+elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
SOURCES += [
'nsGNOMEShellService.cpp',
]
@@ -42,6 +46,10 @@ EXTRA_COMPONENTS += [
'nsSetDefaultBrowser.manifest',
]
+EXTRA_JS_MODULES += [
+ 'ShellService.jsm',
+]
+
for var in ('MOZ_APP_NAME', 'MOZ_APP_VERSION'):
DEFINES[var] = '"%s"' % CONFIG[var]
diff --git a/application/palemoon/components/shell/nsGNOMEShellService.cpp b/application/palemoon/components/shell/nsGNOMEShellService.cpp
index 14510d111..9bc5f5913 100644
--- a/application/palemoon/components/shell/nsGNOMEShellService.cpp
+++ b/application/palemoon/components/shell/nsGNOMEShellService.cpp
@@ -21,12 +21,13 @@
#include "nsIStringBundle.h"
#include "nsIOutputStream.h"
#include "nsIProcess.h"
-#include "nsNetUtil.h"
+#include "nsServiceManagerUtils.h"
+#include "nsComponentManagerUtils.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIImageLoadingContent.h"
#include "imgIRequest.h"
#include "imgIContainer.h"
-#include "prprf.h"
+#include "mozilla/Sprintf.h"
#if defined(MOZ_WIDGET_GTK)
#include "nsIImageToPixbuf.h"
#endif
@@ -116,7 +117,7 @@ nsGNOMEShellService::Init()
return appPath->GetNativePath(mAppPath);
}
-NS_IMPL_ISUPPORTS(nsGNOMEShellService, nsIShellService)
+NS_IMPL_ISUPPORTS(nsGNOMEShellService, nsIGNOMEShellService, nsIShellService)
bool
nsGNOMEShellService::GetAppPathFromLauncher()
@@ -152,7 +153,8 @@ nsGNOMEShellService::KeyMatchesAppName(const char *aKeyValue) const
gchar *commandPath;
if (mUseLocaleFilenames) {
- gchar *nativePath = g_filename_from_utf8(aKeyValue, -1, nullptr, nullptr, nullptr);
+ gchar *nativePath = g_filename_from_utf8(aKeyValue, -1,
+ nullptr, nullptr, nullptr);
if (!nativePath) {
NS_ERROR("Error converting path to filesystem encoding");
return false;
@@ -199,8 +201,6 @@ nsGNOMEShellService::IsDefaultBrowser(bool aStartupCheck,
bool* aIsDefaultBrowser)
{
*aIsDefaultBrowser = false;
- if (aStartupCheck)
- mCheckedThisSession = true;
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
@@ -284,7 +284,7 @@ nsGNOMEShellService::SetDefaultBrowser(bool aClaimAllTypes,
NS_ENSURE_SUCCESS(rv, rv);
nsString brandShortName;
- brandBundle->GetStringFromName(MOZ_UTF16("brandShortName"),
+ brandBundle->GetStringFromName(u"brandShortName",
getter_Copies(brandShortName));
// use brandShortName as the application id.
@@ -312,41 +312,14 @@ nsGNOMEShellService::SetDefaultBrowser(bool aClaimAllTypes,
}
}
- 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(do_GetService(NS_PREFSERVICE_CONTRACTID));
+ if (prefs) {
+ (void) prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, true);
+ // Reset the number of times the dialog should be shown
+ // before it is silenced.
+ (void) prefs->SetIntPref(PREF_DEFAULTBROWSERCHECKCOUNT, 0);
}
- 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;
}
@@ -386,7 +359,7 @@ WriteImage(const nsCString& aPath, imgIContainer* aImage)
return res ? NS_OK : NS_ERROR_FAILURE;
#endif
}
-
+
NS_IMETHODIMP
nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement,
int32_t aPosition)
@@ -407,15 +380,15 @@ nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement,
// Set desktop wallpaper filling style
nsAutoCString options;
if (aPosition == BACKGROUND_TILE)
- options.Assign("wallpaper");
+ options.AssignLiteral("wallpaper");
else if (aPosition == BACKGROUND_STRETCH)
- options.Assign("stretched");
+ options.AssignLiteral("stretched");
else if (aPosition == BACKGROUND_FILL)
- options.Assign("zoom");
+ options.AssignLiteral("zoom");
else if (aPosition == BACKGROUND_FIT)
- options.Assign("scaled");
+ options.AssignLiteral("scaled");
else
- options.Assign("centered");
+ options.AssignLiteral("centered");
// Write the background file to the home directory.
nsAutoCString filePath(PR_GetEnv("HOME"));
@@ -429,7 +402,7 @@ nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement,
rv = bundleService->CreateBundle(BRAND_PROPERTIES,
getter_AddRefs(brandBundle));
if (NS_SUCCEEDED(rv) && brandBundle) {
- rv = brandBundle->GetStringFromName(MOZ_UTF16("brandShortName"),
+ rv = brandBundle->GetStringFromName(u"brandShortName",
getter_Copies(brandName));
NS_ENSURE_SUCCESS(rv, rv);
}
@@ -438,7 +411,7 @@ nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement,
// build the file name
filePath.Append('/');
filePath.Append(NS_ConvertUTF16toUTF8(brandName));
- filePath.Append("_wallpaper.png");
+ filePath.AppendLiteral("_wallpaper.png");
// write the image to a file in the home dir
rv = WriteImage(filePath, container);
@@ -478,7 +451,7 @@ nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement,
// 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)
+ // PaleMoon_wallpaper.png and nautilus doesn't monitor the file for changes)
gconf->SetString(NS_LITERAL_CSTRING(kDesktopImageKey),
EmptyCString());
@@ -543,7 +516,7 @@ ColorToCString(uint32_t aColor, nsCString& aResult)
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);
+ snprintf(buf, 14, "#%04x%04x%04x", red, green, blue);
}
NS_IMETHODIMP
@@ -580,9 +553,9 @@ nsGNOMEShellService::OpenApplication(int32_t aApplication)
{
nsAutoCString scheme;
if (aApplication == APPLICATION_MAIL)
- scheme.Assign("mailto");
+ scheme.AssignLiteral("mailto");
else if (aApplication == APPLICATION_NEWS)
- scheme.Assign("news");
+ scheme.AssignLiteral("news");
else
return NS_ERROR_NOT_AVAILABLE;
diff --git a/application/palemoon/components/shell/nsGNOMEShellService.h b/application/palemoon/components/shell/nsGNOMEShellService.h
index 36a4a0c42..a7b003802 100644
--- a/application/palemoon/components/shell/nsGNOMEShellService.h
+++ b/application/palemoon/components/shell/nsGNOMEShellService.h
@@ -6,28 +6,28 @@
#ifndef nsgnomeshellservice_h____
#define nsgnomeshellservice_h____
-#include "nsIShellService.h"
+#include "nsIGNOMEShellService.h"
#include "nsStringAPI.h"
#include "mozilla/Attributes.h"
-class nsGNOMEShellService final : public nsIShellService
+class nsGNOMEShellService final : public nsIGNOMEShellService
{
public:
- nsGNOMEShellService() : mCheckedThisSession(false), mAppIsInPath(false) { }
+ nsGNOMEShellService() : mAppIsInPath(false) { }
NS_DECL_ISUPPORTS
NS_DECL_NSISHELLSERVICE
+ NS_DECL_NSIGNOMESHELLSERVICE
- nsresult Init() NS_HIDDEN;
+ nsresult Init();
private:
~nsGNOMEShellService() {}
- NS_HIDDEN_(bool) KeyMatchesAppName(const char *aKeyValue) const;
- NS_HIDDEN_(bool) CheckHandlerMatchesAppName(const nsACString& handler) const;
+ bool KeyMatchesAppName(const char *aKeyValue) const;
+ bool CheckHandlerMatchesAppName(const nsACString& handler) const;
- NS_HIDDEN_(bool) GetAppPathFromLauncher();
- bool mCheckedThisSession;
+ bool GetAppPathFromLauncher();
bool mUseLocaleFilenames;
nsCString mAppPath;
bool mAppIsInPath;
diff --git a/application/palemoon/components/shell/nsIGNOMEShellService.idl b/application/palemoon/components/shell/nsIGNOMEShellService.idl
new file mode 100644
index 000000000..842ce5e8a
--- /dev/null
+++ b/application/palemoon/components/shell/nsIGNOMEShellService.idl
@@ -0,0 +1,19 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsIShellService.idl"
+
+[scriptable, uuid(2ce5c803-edcd-443d-98eb-ceba86d02d13)]
+interface nsIGNOMEShellService : nsIShellService
+{
+ /**
+ * Used to determine whether or not to offer "Set as desktop background"
+ * functionality. Even if shell service is available it is not
+ * guaranteed that it is able to set the background for every desktop
+ * which is especially true for Linux with its many different desktop
+ * environments.
+ */
+ readonly attribute boolean canSetDesktopBackground;
+};
+
diff --git a/application/palemoon/components/shell/nsIMacShellService.idl b/application/palemoon/components/shell/nsIMacShellService.idl
index 3c2f42315..6a532bbd0 100644
--- a/application/palemoon/components/shell/nsIMacShellService.idl
+++ b/application/palemoon/components/shell/nsIMacShellService.idl
@@ -5,7 +5,7 @@
#include "nsIShellService.idl"
-[scriptable, uuid(7f8ca08e-1df4-4735-86e9-50dedb48e5e8)]
+[scriptable, uuid(387fdc80-0077-4b60-a0d9-d9e80a83ba64)]
interface nsIMacShellService : nsIShellService
{
const long APPLICATION_KEYCHAIN_ACCESS = 2;
diff --git a/application/palemoon/components/shell/nsIShellService.idl b/application/palemoon/components/shell/nsIShellService.idl
index 4825741b3..3e7e94b00 100644
--- a/application/palemoon/components/shell/nsIShellService.idl
+++ b/application/palemoon/components/shell/nsIShellService.idl
@@ -8,7 +8,7 @@
interface nsIDOMElement;
interface nsIFile;
-[scriptable, uuid(99d2e9f1-3c86-40f7-81fd-3060c18489f0)]
+[scriptable, uuid(2d1a95e4-5bd8-4eeb-b0a8-c1455fd2a357)]
interface nsIShellService : nsISupports
{
/**
@@ -39,23 +39,6 @@ interface nsIShellService : nsISupports
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;
diff --git a/application/palemoon/components/shell/nsIWindowsShellService.idl b/application/palemoon/components/shell/nsIWindowsShellService.idl
index 913eb4292..57ed37055 100644
--- a/application/palemoon/components/shell/nsIWindowsShellService.idl
+++ b/application/palemoon/components/shell/nsIWindowsShellService.idl
@@ -5,7 +5,7 @@
#include "nsIShellService.idl"
-[scriptable, uuid(89b0a761-d9a0-4c39-ab83-d81566459a31)]
+[scriptable, uuid(f8a26b94-49e5-4441-8fbc-315e0b4f22ef)]
interface nsIWindowsShellService : nsIShellService
{
/**
diff --git a/application/palemoon/components/shell/nsMacShellService.cpp b/application/palemoon/components/shell/nsMacShellService.cpp
index 914b9ae65..d8d64039d 100644
--- a/application/palemoon/components/shell/nsMacShellService.cpp
+++ b/application/palemoon/components/shell/nsMacShellService.cpp
@@ -17,13 +17,13 @@
#include "nsIURL.h"
#include "nsIWebBrowserPersist.h"
#include "nsMacShellService.h"
-#include "nsNetUtil.h"
+#include "nsIProperties.h"
+#include "nsServiceManagerUtils.h"
#include "nsShellService.h"
#include "nsStringAPI.h"
#include "nsIDocShell.h"
#include "nsILoadContext.h"
-
#include <CoreFoundation/CoreFoundation.h>
#include <ApplicationServices/ApplicationServices.h>
@@ -49,19 +49,14 @@ nsMacShellService::IsDefaultBrowser(bool aStartupCheck,
return NS_ERROR_FAILURE;
}
- // Get the default http handler's bundle ID (or nullptr if it has not been explicitly set)
+ // 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;
}
@@ -90,47 +85,15 @@ nsMacShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers)
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(do_GetService(NS_PREFSERVICE_CONTRACTID));
+ if (prefs) {
+ (void) prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, true);
+ // Reset the number of times the dialog should be shown
+ // before it is silenced.
+ (void) prefs->SetIntPref(PREF_DEFAULTBROWSERCHECKCOUNT, 0);
}
- 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;
}
@@ -202,8 +165,10 @@ nsMacShellService::SetDesktopBackground(nsIDOMElement* aElement,
loadContext = do_QueryInterface(docShell);
}
- return wbp->SaveURI(imageURI, nullptr, docURI, content->OwnerDoc()->GetReferrerPolicy(),
- nullptr, nullptr, mBackgroundFile, loadContext);
+ return wbp->SaveURI(imageURI, nullptr,
+ docURI, content->OwnerDoc()->GetReferrerPolicy(),
+ nullptr, nullptr,
+ mBackgroundFile, loadContext);
}
NS_IMETHODIMP
@@ -269,7 +234,8 @@ nsMacShellService::OnStateChange(nsIWebProgress* aWebProgress,
OSStatus status;
// Convert the path into a FSRef
- status = ::FSPathMakeRef((const UInt8*)nativePath.get(), &pictureRef, nullptr);
+ status = ::FSPathMakeRef((const UInt8*)nativePath.get(), &pictureRef,
+ nullptr);
if (status == noErr) {
err = ::FSNewAlias(nil, &pictureRef, &aliasHandle);
if (err == noErr && aliasHandle == nil)
@@ -336,8 +302,8 @@ nsMacShellService::OpenApplication(int32_t aApplication)
}
break;
case nsIMacShellService::APPLICATION_KEYCHAIN_ACCESS:
- err = ::LSGetApplicationForInfo('APPL', 'kcmr', nullptr, kLSRolesAll, nullptr,
- &appURL);
+ err = ::LSGetApplicationForInfo('APPL', 'kcmr', nullptr, kLSRolesAll,
+ nullptr, &appURL);
break;
case nsIMacShellService::APPLICATION_NETWORK:
{
@@ -349,8 +315,7 @@ nsMacShellService::OpenApplication(int32_t aApplication)
if (!exists)
return NS_ERROR_FILE_NOT_FOUND;
return lf->Launch();
- }
- break;
+ }
case nsIMacShellService::APPLICATION_DESKTOP:
{
nsCOMPtr<nsIFile> lf;
@@ -361,8 +326,7 @@ nsMacShellService::OpenApplication(int32_t aApplication)
if (!exists)
return NS_ERROR_FILE_NOT_FOUND;
return lf->Launch();
- }
- break;
+ }
}
if (appURL && err == noErr) {
diff --git a/application/palemoon/components/shell/nsMacShellService.h b/application/palemoon/components/shell/nsMacShellService.h
index 7ca1c71ac..db9527809 100644
--- a/application/palemoon/components/shell/nsMacShellService.h
+++ b/application/palemoon/components/shell/nsMacShellService.h
@@ -15,7 +15,7 @@ class nsMacShellService : public nsIMacShellService,
public nsIWebProgressListener
{
public:
- nsMacShellService() : mCheckedThisSession(false) {};
+ nsMacShellService() {};
NS_DECL_ISUPPORTS
NS_DECL_NSISHELLSERVICE
@@ -27,8 +27,6 @@ protected:
private:
nsCOMPtr<nsIFile> mBackgroundFile;
-
- bool mCheckedThisSession;
};
#endif // nsmacshellservice_h____
diff --git a/application/palemoon/components/shell/nsSetDefaultBrowser.js b/application/palemoon/components/shell/nsSetDefaultBrowser.js
index d1d1e72cb..c7a78c538 100644
--- a/application/palemoon/components/shell/nsSetDefaultBrowser.js
+++ b/application/palemoon/components/shell/nsSetDefaultBrowser.js
@@ -2,13 +2,14 @@
* 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
+/*
+ * --setDefaultBrowser commandline handler
* Makes the current executable the "default browser".
*/
const Cc = Components.classes;
const Ci = Components.interfaces;
+Components.utils.import("resource:///modules/ShellService.jsm");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function nsSetDefaultBrowser() {}
@@ -16,13 +17,11 @@ 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);
+ ShellService.setDefaultBrowser(true, true);
}
},
- helpInfo: " -setDefaultBrowser Set this app as the default browser.\n",
+ helpInfo: " --setDefaultBrowser Set this app as the default browser.\n",
classID: Components.ID("{F57899D0-4E2C-4ac6-9E29-50C736103B0C}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
diff --git a/application/palemoon/components/shell/nsShellService.h b/application/palemoon/components/shell/nsShellService.h
index d5fade37b..516a8423a 100644
--- a/application/palemoon/components/shell/nsShellService.h
+++ b/application/palemoon/components/shell/nsShellService.h
@@ -4,6 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#define PREF_CHECKDEFAULTBROWSER "browser.shell.checkDefaultBrowser"
+#define PREF_SKIPDEFAULTBROWSERCHECK "browser.shell.skipDefaultBrowserCheck"
+#define PREF_DEFAULTBROWSERCHECKCOUNT "browser.shell.defaultBrowserCheckCount"
#define SHELLSERVICE_PROPERTIES "chrome://browser/locale/shellservice.properties"
#define BRAND_PROPERTIES "chrome://branding/locale/brand.properties"
diff --git a/application/palemoon/components/shell/nsWindowsShellService.cpp b/application/palemoon/components/shell/nsWindowsShellService.cpp
index 813ec4fe1..c4039b95a 100644
--- a/application/palemoon/components/shell/nsWindowsShellService.cpp
+++ b/application/palemoon/components/shell/nsWindowsShellService.cpp
@@ -3,6 +3,8 @@
* 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 "nsWindowsShellService.h"
+
#include "imgIContainer.h"
#include "imgIRequest.h"
#include "mozilla/gfx/2D.h"
@@ -15,8 +17,8 @@
#include "nsIServiceManager.h"
#include "nsIStringBundle.h"
#include "nsNetUtil.h"
+#include "nsServiceManagerUtils.h"
#include "nsShellService.h"
-#include "nsWindowsShellService.h"
#include "nsIProcess.h"
#include "nsICategoryManager.h"
#include "nsBrowserCompsCID.h"
@@ -27,6 +29,7 @@
#include "nsUnicharUtils.h"
#include "nsIWinTaskbar.h"
#include "nsISupportsPrimitives.h"
+#include "nsIURLFormatter.h"
#include "nsThreadUtils.h"
#include "nsXULAppAPI.h"
#include "mozilla/WindowsVersion.h"
@@ -47,6 +50,9 @@
#include <mbstring.h>
#include <shlwapi.h>
+#include <lm.h>
+#undef ACCESS_READ
+
#ifndef MAX_BUF
#define MAX_BUF 4096
#endif
@@ -129,7 +135,7 @@ OpenKeyForReading(HKEY aKeyRoot, const nsAString& aKeyName, HKEY* aKey)
// The following keys are set to make PaleMoon appear in the Start Menu as the
// browser:
//
-// HKCU\SOFTWARE\Clients\StartMenuInternet\FIREFOX.EXE\
+// HKCU\SOFTWARE\Clients\StartMenuInternet\PaleMoon.EXE\
// (default) REG_SZ <appname>
// DefaultIcon (default) REG_SZ <apppath>,0
// InstallInfo HideIconsCommand REG_SZ <uninstpath> /HideShortcuts
@@ -278,20 +284,15 @@ nsWindowsShellService::ShortcutMaintenance()
return NS_ERROR_UNEXPECTED;
NS_NAMED_LITERAL_CSTRING(prefName, "browser.taskbar.lastgroupid");
- nsCOMPtr<nsIPrefService> prefs =
+ nsCOMPtr<nsIPrefBranch> prefs =
do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs)
return NS_ERROR_UNEXPECTED;
- nsCOMPtr<nsIPrefBranch> prefBranch;
- prefs->GetBranch(nullptr, getter_AddRefs(prefBranch));
- if (!prefBranch)
- return NS_ERROR_UNEXPECTED;
-
nsCOMPtr<nsISupportsString> prefString;
- rv = prefBranch->GetComplexValue(prefName.get(),
- NS_GET_IID(nsISupportsString),
- getter_AddRefs(prefString));
+ rv = prefs->GetComplexValue(prefName.get(),
+ NS_GET_IID(nsISupportsString),
+ getter_AddRefs(prefString));
if (NS_SUCCEEDED(rv)) {
nsAutoString version;
prefString->GetData(version);
@@ -307,9 +308,9 @@ nsWindowsShellService::ShortcutMaintenance()
return rv;
prefString->SetData(appId);
- rv = prefBranch->SetComplexValue(prefName.get(),
- NS_GET_IID(nsISupportsString),
- prefString);
+ rv = prefs->SetComplexValue(prefName.get(),
+ NS_GET_IID(nsISupportsString),
+ prefString);
if (NS_FAILED(rv)) {
NS_WARNING("Couldn't set last user model id!");
return NS_ERROR_UNEXPECTED;
@@ -325,38 +326,47 @@ nsWindowsShellService::ShortcutMaintenance()
}
static bool
-IsAARDefaultHTTP(IApplicationAssociationRegistration* pAAR,
- bool* aIsDefaultBrowser)
+IsAARDefault(const RefPtr<IApplicationAssociationRegistration>& pAAR,
+ LPCWSTR aClassName)
{
// Make sure the Prog ID matches what we have
LPWSTR registeredApp;
- HRESULT hr = pAAR->QueryCurrentDefault(L"http", AT_URLPROTOCOL, AL_EFFECTIVE,
+ bool isProtocol = *aClassName != L'.';
+ ASSOCIATIONTYPE queryType = isProtocol ? AT_URLPROTOCOL : AT_FILEEXTENSION;
+ HRESULT hr = pAAR->QueryCurrentDefault(aClassName, queryType, AL_EFFECTIVE,
&registeredApp);
- if (SUCCEEDED(hr)) {
- LPCWSTR firefoxHTTPProgID = L"PaleMoonURL";
- *aIsDefaultBrowser = !wcsicmp(registeredApp, firefoxHTTPProgID);
- CoTaskMemFree(registeredApp);
- } else {
- *aIsDefaultBrowser = false;
+ if (FAILED(hr)) {
+ return false;
}
- return SUCCEEDED(hr);
+
+ LPCWSTR progID = isProtocol ? L"PaleMoonURL" : L"PaleMoonHTML";
+ bool isDefault = !wcsicmp(registeredApp, progID);
+ CoTaskMemFree(registeredApp);
+
+ return isDefault;
}
-static bool
-IsAARDefaultHTML(IApplicationAssociationRegistration* pAAR,
- bool* aIsDefaultBrowser)
+static void
+IsDefaultBrowserWin8(bool aCheckAllTypes, bool* aIsDefaultBrowser)
{
- LPWSTR registeredApp;
- HRESULT hr = pAAR->QueryCurrentDefault(L".html", AT_FILEEXTENSION, AL_EFFECTIVE,
- &registeredApp);
- if (SUCCEEDED(hr)) {
- LPCWSTR firefoxHTMLProgID = L"PaleMoonHTML";
- *aIsDefaultBrowser = !wcsicmp(registeredApp, firefoxHTMLProgID);
- CoTaskMemFree(registeredApp);
- } else {
- *aIsDefaultBrowser = false;
+ RefPtr<IApplicationAssociationRegistration> pAAR;
+ HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
+ nullptr,
+ CLSCTX_INPROC,
+ IID_IApplicationAssociationRegistration,
+ getter_AddRefs(pAAR));
+ if (FAILED(hr)) {
+ return;
+ }
+
+ bool res = IsAARDefault(pAAR, L"http");
+ if (*aIsDefaultBrowser) {
+ *aIsDefaultBrowser = res;
+ }
+ res = IsAARDefault(pAAR, L".html");
+ if (*aIsDefaultBrowser && aCheckAllTypes) {
+ *aIsDefaultBrowser = res;
}
- return SUCCEEDED(hr);
}
/*
@@ -369,37 +379,27 @@ bool
nsWindowsShellService::IsDefaultBrowserVista(bool aCheckAllTypes,
bool* aIsDefaultBrowser)
{
- IApplicationAssociationRegistration* pAAR;
+ RefPtr<IApplicationAssociationRegistration> pAAR;
HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
nullptr,
CLSCTX_INPROC,
IID_IApplicationAssociationRegistration,
- (void**)&pAAR);
-
- if (SUCCEEDED(hr)) {
- if (aCheckAllTypes) {
- BOOL res;
- hr = pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE,
- APP_REG_NAME,
- &res);
- *aIsDefaultBrowser = res;
-
- // If we have all defaults, let's make sure that our ProgID
- // is explicitly returned as well. Needed only for Windows 8.
- if (*aIsDefaultBrowser && IsWin8OrLater()) {
- IsAARDefaultHTTP(pAAR, aIsDefaultBrowser);
- if (*aIsDefaultBrowser) {
- IsAARDefaultHTML(pAAR, aIsDefaultBrowser);
- }
- }
- } else {
- IsAARDefaultHTTP(pAAR, aIsDefaultBrowser);
- }
+ getter_AddRefs(pAAR));
+ if (FAILED(hr)) {
+ return false;
+ }
- pAAR->Release();
- return true;
+ if (aCheckAllTypes) {
+ BOOL res;
+ hr = pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE,
+ APP_REG_NAME,
+ &res);
+ *aIsDefaultBrowser = res;
+ } else if (!IsWin8OrLater()) {
+ *aIsDefaultBrowser = IsAARDefault(pAAR, L"http");
}
- return false;
+
+ return true;
}
NS_IMETHODIMP
@@ -407,12 +407,6 @@ nsWindowsShellService::IsDefaultBrowser(bool aStartupCheck,
bool aForAllTypes,
bool* aIsDefaultBrowser)
{
- // 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;
-
// Assume we're the default unless one of the several checks below tell us
// otherwise.
*aIsDefaultBrowser = true;
@@ -499,6 +493,9 @@ nsWindowsShellService::IsDefaultBrowser(bool aStartupCheck,
// previous checks show that PaleMoon is the default browser.
if (*aIsDefaultBrowser) {
IsDefaultBrowserVista(aForAllTypes, aIsDefaultBrowser);
+ if (IsWin8OrLater()) {
+ IsDefaultBrowserWin8(aForAllTypes, aIsDefaultBrowser);
+ }
}
// To handle the case where DDE isn't disabled due for a user because there
@@ -603,13 +600,6 @@ nsWindowsShellService::IsDefaultBrowser(bool aStartupCheck,
return NS_OK;
}
-NS_IMETHODIMP
-nsWindowsShellService::GetCanSetDesktopBackground(bool* aResult)
-{
- *aResult = true;
- return NS_OK;
-}
-
static nsresult
DynSHOpenWithDialog(HWND hwndParent, const OPENASINFO *poainfo)
{
@@ -628,14 +618,34 @@ DynSHOpenWithDialog(HWND hwndParent, const OPENASINFO *poainfo)
return NS_ERROR_FAILURE;
}
- nsresult rv =
- SUCCEEDED(SHOpenWithDialogFn(hwndParent, poainfo)) ? NS_OK :
- NS_ERROR_FAILURE;
+ nsresult rv;
+ HRESULT hr = SHOpenWithDialogFn(hwndParent, poainfo);
+ if (SUCCEEDED(hr) || (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))) {
+ rv = NS_OK;
+ } else {
+ rv = NS_ERROR_FAILURE;
+ }
FreeLibrary(shellDLL);
return rv;
}
nsresult
+nsWindowsShellService::LaunchControlPanelDefaultsSelectionUI()
+{
+ IApplicationAssociationRegistrationUI* pAARUI;
+ HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI,
+ NULL,
+ CLSCTX_INPROC,
+ IID_IApplicationAssociationRegistrationUI,
+ (void**)&pAARUI);
+ if (SUCCEEDED(hr)) {
+ hr = pAARUI->LaunchAdvancedAssociationUI(APP_REG_NAME);
+ pAARUI->Release();
+ }
+ return SUCCEEDED(hr) ? NS_OK : NS_ERROR_FAILURE;
+}
+
+nsresult
nsWindowsShellService::LaunchControlPanelDefaultPrograms()
{
// Build the path control.exe path safely
@@ -651,7 +661,8 @@ nsWindowsShellService::LaunchControlPanelDefaultPrograms()
return NS_ERROR_FAILURE;
}
- WCHAR params[] = L"control.exe /name Microsoft.DefaultPrograms /page pageDefaultProgram";
+ WCHAR params[] = L"control.exe /name Microsoft.DefaultPrograms /page "
+ "pageDefaultProgram\\pageAdvancedSettings?pszAppName=" APP_REG_NAME;
STARTUPINFOW si = {sizeof(si), 0};
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWDEFAULT;
@@ -666,9 +677,62 @@ nsWindowsShellService::LaunchControlPanelDefaultPrograms()
return NS_OK;
}
+static bool
+IsWindowsLogonConnected()
+{
+ WCHAR userName[UNLEN + 1];
+ DWORD size = ArrayLength(userName);
+ if (!GetUserNameW(userName, &size)) {
+ return false;
+ }
+
+ LPUSER_INFO_24 info;
+ if (NetUserGetInfo(nullptr, userName, 24, (LPBYTE *)&info)
+ != NERR_Success) {
+ return false;
+ }
+ bool connected = info->usri24_internet_identity;
+ NetApiBufferFree(info);
+
+ return connected;
+}
+
+static bool
+SettingsAppBelievesConnected()
+{
+ nsresult rv;
+ nsCOMPtr<nsIWindowsRegKey> regKey =
+ do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
+ if (NS_FAILED(rv)) {
+ return false;
+ }
+
+ rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
+ NS_LITERAL_STRING("SOFTWARE\\Microsoft\\Windows\\Shell\\Associations"),
+ nsIWindowsRegKey::ACCESS_READ);
+ if (NS_FAILED(rv)) {
+ return false;
+ }
+
+ uint32_t value;
+ rv = regKey->ReadIntValue(NS_LITERAL_STRING("IsConnectedAtLogon"), &value);
+ if (NS_FAILED(rv)) {
+ return false;
+ }
+
+ return !!value;
+}
+
nsresult
nsWindowsShellService::LaunchModernSettingsDialogDefaultApps()
{
+ if (!IsWindowsBuildOrLater(14965) &&
+ !IsWindowsLogonConnected() && SettingsAppBelievesConnected()) {
+ // Use the classic Control Panel to work around a bug of older
+ // builds of Windows 10.
+ return LaunchControlPanelDefaultPrograms();
+ }
+
IApplicationActivationManager* pActivator;
HRESULT hr = CoCreateInstance(CLSID_ApplicationActivationManager,
nullptr,
@@ -682,6 +746,15 @@ nsWindowsShellService::LaunchModernSettingsDialogDefaultApps()
L"windows.immersivecontrolpanel_cw5n1h2txyewy"
L"!microsoft.windows.immersivecontrolpanel",
L"page=SettingsPageAppsDefaults", AO_NONE, &pid);
+ if (SUCCEEDED(hr)) {
+ // Do not check error because we could at least open
+ // the "Default apps" setting.
+ pActivator->ActivateApplication(
+ L"windows.immersivecontrolpanel_cw5n1h2txyewy"
+ L"!microsoft.windows.immersivecontrolpanel",
+ L"page=SettingsPageAppsDefaults"
+ L"&target=SystemSettings_DefaultApps_Browser", AO_NONE, &pid);
+ }
pActivator->Release();
return SUCCEEDED(hr) ? NS_OK : NS_ERROR_FAILURE;
}
@@ -689,6 +762,36 @@ nsWindowsShellService::LaunchModernSettingsDialogDefaultApps()
}
nsresult
+nsWindowsShellService::InvokeHTTPOpenAsVerb()
+{
+ nsCOMPtr<nsIURLFormatter> formatter(
+ do_GetService("@mozilla.org/toolkit/URLFormatterService;1"));
+ if (!formatter) {
+ return NS_ERROR_UNEXPECTED;
+ }
+
+ nsString urlStr;
+ nsresult rv = formatter->FormatURLPref(
+ NS_LITERAL_STRING("app.support.baseURL"), urlStr);
+ if (NS_FAILED(rv)) {
+ return rv;
+ }
+ if (!StringBeginsWith(urlStr, NS_LITERAL_STRING("https://"))) {
+ return NS_ERROR_FAILURE;
+ }
+ urlStr.AppendLiteral("win10-default-browser");
+
+ SHELLEXECUTEINFOW seinfo = { sizeof(SHELLEXECUTEINFOW) };
+ seinfo.lpVerb = L"openas";
+ seinfo.lpFile = urlStr.get();
+ seinfo.nShow = SW_SHOWNORMAL;
+ if (!ShellExecuteExW(&seinfo)) {
+ return NS_ERROR_FAILURE;
+ }
+ return NS_OK;
+}
+
+nsresult
nsWindowsShellService::LaunchHTTPHandlerPane()
{
OPENASINFO info;
@@ -716,16 +819,23 @@ nsWindowsShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers)
nsresult rv = LaunchHelper(appHelperPath);
if (NS_SUCCEEDED(rv) && IsWin8OrLater()) {
if (aClaimAllTypes) {
- rv = LaunchControlPanelDefaultPrograms();
+ if (IsWin10OrLater()) {
+ rv = LaunchModernSettingsDialogDefaultApps();
+ } else {
+ rv = LaunchControlPanelDefaultsSelectionUI();
+ }
// The above call should never really fail, but just in case
// fall back to showing the HTTP association screen only.
if (NS_FAILED(rv)) {
- rv = LaunchHTTPHandlerPane();
+ if (IsWin10OrLater()) {
+ rv = InvokeHTTPOpenAsVerb();
+ } else {
+ rv = LaunchHTTPHandlerPane();
+ }
}
} else {
- // Windows 10 blocks attempts to load the HTTP Handler
- // association dialog, so the modern Settings dialog
- // is opened with the Default Apps view loaded.
+ // Windows 10 blocks attempts to load the
+ // HTTP Handler association dialog.
if (IsWin10OrLater()) {
rv = LaunchModernSettingsDialogDefaultApps();
} else {
@@ -735,50 +845,20 @@ nsWindowsShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers)
// The above call should never really fail, but just in case
// fall back to showing control panel for all defaults
if (NS_FAILED(rv)) {
- rv = LaunchControlPanelDefaultPrograms();
+ rv = LaunchControlPanelDefaultsSelectionUI();
}
}
}
- return rv;
-}
-
-NS_IMETHODIMP
-nsWindowsShellService::GetShouldCheckDefaultBrowser(bool* aResult)
-{
- NS_ENSURE_ARG_POINTER(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(do_GetService(NS_PREFSERVICE_CONTRACTID));
+ if (prefs) {
+ (void) prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, true);
+ // Reset the number of times the dialog should be shown
+ // before it is silenced.
+ (void) prefs->SetIntPref(PREF_DEFAULTBROWSERCHECKCOUNT, 0);
}
- nsCOMPtr<nsIPrefBranch> prefs;
- nsresult rv;
- nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
- NS_ENSURE_SUCCESS(rv, rv);
-
- rv = pserve->GetBranch("", getter_AddRefs(prefs));
- NS_ENSURE_SUCCESS(rv, rv);
-
- return prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult);
-}
-
-NS_IMETHODIMP
-nsWindowsShellService::SetShouldCheckDefaultBrowser(bool aShouldCheck)
-{
- nsCOMPtr<nsIPrefBranch> prefs;
- nsresult rv;
-
- nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
- NS_ENSURE_SUCCESS(rv, rv);
-
- rv = pserve->GetBranch("", getter_AddRefs(prefs));
- NS_ENSURE_SUCCESS(rv, rv);
-
- return prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck);
+ return rv;
}
static nsresult
@@ -912,7 +992,7 @@ nsWindowsShellService::SetDesktopBackground(nsIDOMElement* aElement,
// e.g. "Desktop Background.bmp"
nsString fileLeafName;
rv = shellBundle->GetStringFromName
- (MOZ_UTF16("desktopBackgroundLeafNameWin"),
+ (u"desktopBackgroundLeafNameWin",
getter_Copies(fileLeafName));
NS_ENSURE_SUCCESS(rv, rv);
@@ -948,24 +1028,24 @@ nsWindowsShellService::SetDesktopBackground(nsIDOMElement* aElement,
nsAutoString style;
switch (aPosition) {
case BACKGROUND_TILE:
- style.AssignLiteral("0");
- tile.AssignLiteral("1");
+ style.Assign('0');
+ tile.Assign('1');
break;
case BACKGROUND_CENTER:
- style.AssignLiteral("0");
- tile.AssignLiteral("0");
+ style.Assign('0');
+ tile.Assign('0');
break;
case BACKGROUND_STRETCH:
- style.AssignLiteral("2");
- tile.AssignLiteral("0");
+ style.Assign('2');
+ tile.Assign('0');
break;
case BACKGROUND_FILL:
style.AssignLiteral("10");
- tile.AssignLiteral("0");
+ tile.Assign('0');
break;
case BACKGROUND_FIT:
- style.AssignLiteral("6");
- tile.AssignLiteral("0");
+ style.Assign('6');
+ tile.Assign('0');
break;
}
@@ -1023,7 +1103,7 @@ nsWindowsShellService::OpenApplication(int32_t aApplication)
::RegCloseKey(theKey);
// Find the "open" command
- application.AppendLiteral("\\");
+ application.Append('\\');
application.Append(buf);
application.AppendLiteral("\\shell\\open\\command");
@@ -1122,8 +1202,7 @@ nsWindowsShellService::SetDesktopBackgroundColor(uint32_t aColor)
return regKey->Close();
}
-nsWindowsShellService::nsWindowsShellService() :
- mCheckedThisSession(false)
+nsWindowsShellService::nsWindowsShellService()
{
}
diff --git a/application/palemoon/components/shell/nsWindowsShellService.h b/application/palemoon/components/shell/nsWindowsShellService.h
index f856ffd35..06c6c3c9b 100644
--- a/application/palemoon/components/shell/nsWindowsShellService.h
+++ b/application/palemoon/components/shell/nsWindowsShellService.h
@@ -16,9 +16,10 @@
class nsWindowsShellService : public nsIWindowsShellService
{
+ virtual ~nsWindowsShellService();
+
public:
nsWindowsShellService();
- virtual ~nsWindowsShellService();
NS_DECL_ISUPPORTS
NS_DECL_NSISHELLSERVICE
@@ -26,12 +27,11 @@ public:
protected:
bool IsDefaultBrowserVista(bool aCheckAllTypes, bool* aIsDefaultBrowser);
+ nsresult LaunchControlPanelDefaultsSelectionUI();
nsresult LaunchControlPanelDefaultPrograms();
nsresult LaunchModernSettingsDialogDefaultApps();
+ nsresult InvokeHTTPOpenAsVerb();
nsresult LaunchHTTPHandlerPane();
-
-private:
- bool mCheckedThisSession;
};
#endif // nswindowsshellservice_h____