2004-03-08 09:56:16 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgIRequest.h"
|
2014-03-04 16:56:44 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2004-03-08 09:56:16 +00:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
|
|
|
#include "nsIImageLoadingContent.h"
|
|
|
|
#include "nsIPrefService.h"
|
2004-11-30 08:23:02 +00:00
|
|
|
#include "nsIPrefLocalizedString.h"
|
2004-03-08 09:56:16 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2004-03-08 09:56:16 +00:00
|
|
|
#include "nsShellService.h"
|
|
|
|
#include "nsWindowsShellService.h"
|
2006-06-27 22:38:55 +00:00
|
|
|
#include "nsIProcess.h"
|
2004-11-30 08:23:02 +00:00
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsBrowserCompsCID.h"
|
2005-07-24 22:56:48 +00:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2007-09-29 09:48:32 +00:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2006-12-20 22:34:51 +00:00
|
|
|
#include "nsIWindowsRegKey.h"
|
2007-07-24 02:27:30 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2010-05-15 00:24:50 +00:00
|
|
|
#include "nsIWinTaskbar.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2015-06-18 23:16:52 +00:00
|
|
|
#include "nsIURLFormatter.h"
|
2012-05-28 02:40:48 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2012-12-14 07:32:54 +00:00
|
|
|
#include "nsXULAppAPI.h"
|
2013-11-22 03:35:39 +00:00
|
|
|
#include "mozilla/WindowsVersion.h"
|
2004-07-22 22:12:13 +00:00
|
|
|
|
2007-01-30 05:14:50 +00:00
|
|
|
#include "windows.h"
|
|
|
|
#include "shellapi.h"
|
2008-04-25 16:44:16 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32_WINNT
|
|
|
|
#undef _WIN32_WINNT
|
|
|
|
#endif
|
|
|
|
#define _WIN32_WINNT 0x0600
|
|
|
|
#define INITGUID
|
2015-06-03 15:40:40 +00:00
|
|
|
#undef NTDDI_VERSION
|
|
|
|
#define NTDDI_VERSION NTDDI_WIN8
|
|
|
|
// Needed for access to IApplicationActivationManager
|
2008-04-25 16:44:16 +00:00
|
|
|
#include <shlobj.h>
|
2007-01-30 05:14:50 +00:00
|
|
|
|
2004-07-22 22:12:13 +00:00
|
|
|
#include <mbstring.h>
|
2012-03-26 19:45:29 +00:00
|
|
|
#include <shlwapi.h>
|
2004-07-22 22:12:13 +00:00
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
#ifndef MAX_BUF
|
|
|
|
#define MAX_BUF 4096
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define REG_SUCCEEDED(val) \
|
|
|
|
(val == ERROR_SUCCESS)
|
|
|
|
|
|
|
|
#define REG_FAILED(val) \
|
|
|
|
(val != ERROR_SUCCESS)
|
|
|
|
|
2010-05-15 00:24:50 +00:00
|
|
|
#define NS_TASKBAR_CONTRACTID "@mozilla.org/windows-taskbar;1"
|
|
|
|
|
2013-11-22 03:35:39 +00:00
|
|
|
using mozilla::IsWin8OrLater;
|
2014-03-04 16:56:44 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2013-11-22 03:35:39 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsWindowsShellService, nsIWindowsShellService, nsIShellService)
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2004-06-30 20:27:30 +00:00
|
|
|
static nsresult
|
2007-09-29 09:48:32 +00:00
|
|
|
OpenKeyForReading(HKEY aKeyRoot, const nsAString& aKeyName, HKEY* aKey)
|
2004-06-30 20:27:30 +00:00
|
|
|
{
|
2007-07-24 02:27:30 +00:00
|
|
|
const nsString &flatName = PromiseFlatString(aKeyName);
|
2004-06-30 20:27:30 +00:00
|
|
|
|
2007-09-29 09:48:32 +00:00
|
|
|
DWORD res = ::RegOpenKeyExW(aKeyRoot, flatName.get(), 0, KEY_READ, aKey);
|
2007-07-24 02:27:30 +00:00
|
|
|
switch (res) {
|
2004-06-30 20:27:30 +00:00
|
|
|
case ERROR_SUCCESS:
|
|
|
|
break;
|
|
|
|
case ERROR_ACCESS_DENIED:
|
|
|
|
return NS_ERROR_FILE_ACCESS_DENIED;
|
|
|
|
case ERROR_FILE_NOT_FOUND:
|
2007-09-29 09:48:32 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2004-06-30 20:27:30 +00:00
|
|
|
}
|
2007-01-30 05:14:50 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2004-06-30 20:27:30 +00:00
|
|
|
}
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Default Browser Registry Settings
|
|
|
|
//
|
2007-09-29 09:48:32 +00:00
|
|
|
// The setting of these values are made by an external binary since writing
|
|
|
|
// these values may require elevation.
|
|
|
|
//
|
2004-03-08 09:56:16 +00:00
|
|
|
// - File Extension Mappings
|
|
|
|
// -----------------------
|
|
|
|
// The following file extensions:
|
|
|
|
// .htm .html .shtml .xht .xhtml
|
|
|
|
// are mapped like so:
|
|
|
|
//
|
2007-01-30 05:14:50 +00:00
|
|
|
// HKCU\SOFTWARE\Classes\.<ext>\ (default) REG_SZ FirefoxHTML
|
2004-03-08 09:56:16 +00:00
|
|
|
//
|
|
|
|
// as aliases to the class:
|
|
|
|
//
|
2004-06-30 20:27:30 +00:00
|
|
|
// HKCU\SOFTWARE\Classes\FirefoxHTML\
|
2007-01-30 05:14:50 +00:00
|
|
|
// DefaultIcon (default) REG_SZ <apppath>,1
|
2012-03-26 19:45:29 +00:00
|
|
|
// shell\open\command (default) REG_SZ <apppath> -osint -url "%1"
|
|
|
|
// shell\open\ddeexec (default) REG_SZ <empty string>
|
2007-01-30 05:14:50 +00:00
|
|
|
//
|
2012-03-26 19:45:29 +00:00
|
|
|
// - Windows Vista and above Protocol Handler
|
2007-01-30 05:14:50 +00:00
|
|
|
//
|
|
|
|
// HKCU\SOFTWARE\Classes\FirefoxURL\ (default) REG_SZ <appname> URL
|
|
|
|
// EditFlags REG_DWORD 2
|
|
|
|
// FriendlyTypeName REG_SZ <appname> URL
|
2007-04-24 21:33:13 +00:00
|
|
|
// DefaultIcon (default) REG_SZ <apppath>,1
|
2012-03-26 19:45:29 +00:00
|
|
|
// shell\open\command (default) REG_SZ <apppath> -osint -url "%1"
|
|
|
|
// shell\open\ddeexec (default) REG_SZ <empty string>
|
2004-03-08 09:56:16 +00:00
|
|
|
//
|
|
|
|
// - Protocol Mappings
|
|
|
|
// -----------------
|
|
|
|
// The following protocols:
|
2007-07-17 18:23:26 +00:00
|
|
|
// HTTP, HTTPS, FTP
|
2004-03-08 09:56:16 +00:00
|
|
|
// are mapped like so:
|
|
|
|
//
|
2007-01-30 05:14:50 +00:00
|
|
|
// HKCU\SOFTWARE\Classes\<protocol>\
|
2007-04-24 21:33:13 +00:00
|
|
|
// DefaultIcon (default) REG_SZ <apppath>,1
|
2012-03-26 19:45:29 +00:00
|
|
|
// shell\open\command (default) REG_SZ <apppath> -osint -url "%1"
|
|
|
|
// shell\open\ddeexec (default) REG_SZ <empty string>
|
2004-03-08 09:56:16 +00:00
|
|
|
//
|
2012-03-26 19:45:29 +00:00
|
|
|
// - Windows Start Menu (XP SP1 and newer)
|
2007-01-30 05:14:50 +00:00
|
|
|
// -------------------------------------------------
|
|
|
|
// The following keys are set to make Firefox appear in the Start Menu as the
|
|
|
|
// browser:
|
2004-03-08 09:56:16 +00:00
|
|
|
//
|
2007-01-30 05:14:50 +00:00
|
|
|
// HKCU\SOFTWARE\Clients\StartMenuInternet\FIREFOX.EXE\
|
|
|
|
// (default) REG_SZ <appname>
|
|
|
|
// DefaultIcon (default) REG_SZ <apppath>,0
|
|
|
|
// InstallInfo HideIconsCommand REG_SZ <uninstpath> /HideShortcuts
|
|
|
|
// InstallInfo IconsVisible REG_DWORD 1
|
|
|
|
// InstallInfo ReinstallCommand REG_SZ <uninstpath> /SetAsDefaultAppGlobal
|
|
|
|
// InstallInfo ShowIconsCommand REG_SZ <uninstpath> /ShowShortcuts
|
|
|
|
// shell\open\command (default) REG_SZ <apppath>
|
|
|
|
// shell\properties (default) REG_SZ <appname> &Options
|
|
|
|
// shell\properties\command (default) REG_SZ <apppath> -preferences
|
|
|
|
// shell\safemode (default) REG_SZ <appname> &Safe Mode
|
|
|
|
// shell\safemode\command (default) REG_SZ <apppath> -safe-mode
|
2004-03-08 09:56:16 +00:00
|
|
|
//
|
|
|
|
|
2012-03-26 19:45:29 +00:00
|
|
|
// The values checked are all default values so the value name is not needed.
|
2004-03-08 09:56:16 +00:00
|
|
|
typedef struct {
|
2013-01-10 12:34:58 +00:00
|
|
|
const char* keyName;
|
|
|
|
const char* valueData;
|
|
|
|
const char* oldValueData;
|
2004-03-08 09:56:16 +00:00
|
|
|
} SETTING;
|
|
|
|
|
2007-01-30 05:14:50 +00:00
|
|
|
#define APP_REG_NAME L"Firefox"
|
2009-07-08 20:51:21 +00:00
|
|
|
#define VAL_FILE_ICON "%APPPATH%,1"
|
2012-03-26 19:45:29 +00:00
|
|
|
#define VAL_OPEN "\"%APPPATH%\" -osint -url \"%1\""
|
|
|
|
#define OLD_VAL_OPEN "\"%APPPATH%\" -requestPending -osint -url \"%1\""
|
2009-07-08 20:51:21 +00:00
|
|
|
#define DI "\\DefaultIcon"
|
2012-03-26 19:45:29 +00:00
|
|
|
#define SOC "\\shell\\open\\command"
|
|
|
|
#define SOD "\\shell\\open\\ddeexec"
|
|
|
|
// Used for updating the FTP protocol handler's shell open command under HKCU.
|
|
|
|
#define FTP_SOC L"Software\\Classes\\ftp\\shell\\open\\command"
|
2009-07-08 20:51:21 +00:00
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
#define MAKE_KEY_NAME1(PREFIX, MID) \
|
|
|
|
PREFIX MID
|
|
|
|
|
2007-09-29 09:48:32 +00:00
|
|
|
// The DefaultIcon registry key value should never be used when checking if
|
2009-07-08 20:51:21 +00:00
|
|
|
// Firefox is the default browser for file handlers since other applications
|
|
|
|
// (e.g. MS Office) may modify the DefaultIcon registry key value to add Icon
|
|
|
|
// Handlers. see http://msdn2.microsoft.com/en-us/library/aa969357.aspx for
|
2012-03-26 19:45:29 +00:00
|
|
|
// more info. The FTP protocol is not checked so advanced users can set the FTP
|
|
|
|
// handler to another application and still have Firefox check if it is the
|
|
|
|
// default HTTP and HTTPS handler.
|
2013-09-13 18:30:20 +00:00
|
|
|
// *** Do not add additional checks here unless you skip them when aForAllTypes
|
|
|
|
// is false below***.
|
2004-03-08 09:56:16 +00:00
|
|
|
static SETTING gSettings[] = {
|
2009-07-08 20:51:21 +00:00
|
|
|
// File Handler Class
|
2013-09-13 18:30:20 +00:00
|
|
|
// ***keep this as the first entry because when aForAllTypes is not set below
|
|
|
|
// it will skip over this check.***
|
2012-03-26 19:45:29 +00:00
|
|
|
{ MAKE_KEY_NAME1("FirefoxHTML", SOC), VAL_OPEN, OLD_VAL_OPEN },
|
|
|
|
|
|
|
|
// Protocol Handler Class - for Vista and above
|
|
|
|
{ MAKE_KEY_NAME1("FirefoxURL", SOC), VAL_OPEN, OLD_VAL_OPEN },
|
|
|
|
|
|
|
|
// Protocol Handlers
|
|
|
|
{ MAKE_KEY_NAME1("HTTP", DI), VAL_FILE_ICON },
|
|
|
|
{ MAKE_KEY_NAME1("HTTP", SOC), VAL_OPEN, OLD_VAL_OPEN },
|
|
|
|
{ MAKE_KEY_NAME1("HTTPS", DI), VAL_FILE_ICON },
|
|
|
|
{ MAKE_KEY_NAME1("HTTPS", SOC), VAL_OPEN, OLD_VAL_OPEN }
|
|
|
|
};
|
|
|
|
|
|
|
|
// The settings to disable DDE are separate from the default browser settings
|
|
|
|
// since they are only checked when Firefox is the default browser and if they
|
|
|
|
// are incorrect they are fixed without notifying the user.
|
|
|
|
static SETTING gDDESettings[] = {
|
|
|
|
// File Handler Class
|
|
|
|
{ MAKE_KEY_NAME1("Software\\Classes\\FirefoxHTML", SOD) },
|
2007-01-30 05:14:50 +00:00
|
|
|
|
|
|
|
// Protocol Handler Class - for Vista and above
|
2012-03-26 19:45:29 +00:00
|
|
|
{ MAKE_KEY_NAME1("Software\\Classes\\FirefoxURL", SOD) },
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
// Protocol Handlers
|
2012-03-26 19:45:29 +00:00
|
|
|
{ MAKE_KEY_NAME1("Software\\Classes\\FTP", SOD) },
|
|
|
|
{ MAKE_KEY_NAME1("Software\\Classes\\HTTP", SOD) },
|
|
|
|
{ MAKE_KEY_NAME1("Software\\Classes\\HTTPS", SOD) }
|
2004-03-08 09:56:16 +00:00
|
|
|
};
|
|
|
|
|
2010-05-15 00:24:50 +00:00
|
|
|
nsresult
|
|
|
|
GetHelperPath(nsAutoString& aPath)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIProperties> directoryService =
|
|
|
|
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> appHelper;
|
2012-12-14 07:32:54 +00:00
|
|
|
rv = directoryService->Get(XRE_EXECUTABLE_FILE,
|
2012-06-06 02:08:30 +00:00
|
|
|
NS_GET_IID(nsIFile),
|
2010-05-15 00:24:50 +00:00
|
|
|
getter_AddRefs(appHelper));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-12-14 07:32:54 +00:00
|
|
|
rv = appHelper->SetNativeLeafName(NS_LITERAL_CSTRING("uninstall"));
|
2010-05-15 00:24:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = appHelper->AppendNative(NS_LITERAL_CSTRING("helper.exe"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-07-12 01:48:20 +00:00
|
|
|
rv = appHelper->GetPath(aPath);
|
|
|
|
|
|
|
|
aPath.Insert(L'"', 0);
|
|
|
|
aPath.Append(L'"');
|
|
|
|
return rv;
|
2010-05-15 00:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
LaunchHelper(nsAutoString& aPath)
|
|
|
|
{
|
|
|
|
STARTUPINFOW si = {sizeof(si), 0};
|
|
|
|
PROCESS_INFORMATION pi = {0};
|
|
|
|
|
2013-08-21 16:13:50 +00:00
|
|
|
if (!CreateProcessW(nullptr, (LPWSTR)aPath.get(), nullptr, nullptr, FALSE,
|
|
|
|
0, nullptr, nullptr, &si, &pi)) {
|
2010-05-15 00:24:50 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-03-26 19:45:29 +00:00
|
|
|
}
|
2010-05-15 00:24:50 +00:00
|
|
|
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowsShellService::ShortcutMaintenance()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-11-03 14:39:51 +00:00
|
|
|
// XXX App ids were updated to a constant install path hash,
|
|
|
|
// XXX this code can be removed after a few upgrade cycles.
|
|
|
|
|
2010-05-15 00:24:50 +00:00
|
|
|
// Launch helper.exe so it can update the application user model ids on
|
|
|
|
// shortcuts in the user's taskbar and start menu. This keeps older pinned
|
|
|
|
// shortcuts grouped correctly after major updates. Note, we also do this
|
|
|
|
// through the upgrade installer script, however, this is the only place we
|
|
|
|
// have a chance to trap links created by users who do control the install/
|
|
|
|
// update process of the browser.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWinTaskbar> taskbarInfo =
|
|
|
|
do_GetService(NS_TASKBAR_CONTRACTID);
|
|
|
|
if (!taskbarInfo) // If we haven't built with win7 sdk features, this fails.
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Avoid if this isn't Win7+
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isSupported = false;
|
2010-05-15 00:24:50 +00:00
|
|
|
taskbarInfo->GetAvailable(&isSupported);
|
|
|
|
if (!isSupported)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsAutoString appId;
|
|
|
|
if (NS_FAILED(taskbarInfo->GetDefaultGroupId(appId)))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(prefName, "browser.taskbar.lastgroupid");
|
2014-10-14 04:10:47 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefs =
|
2010-05-15 00:24:50 +00:00
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (!prefs)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsString> prefString;
|
2014-10-14 04:10:47 +00:00
|
|
|
rv = prefs->GetComplexValue(prefName.get(),
|
|
|
|
NS_GET_IID(nsISupportsString),
|
|
|
|
getter_AddRefs(prefString));
|
2010-05-15 00:24:50 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsAutoString version;
|
|
|
|
prefString->GetData(version);
|
|
|
|
if (!version.IsEmpty() && version.Equals(appId)) {
|
|
|
|
// We're all good, get out of here.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Update the version in prefs
|
|
|
|
prefString =
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
prefString->SetData(appId);
|
2014-10-14 04:10:47 +00:00
|
|
|
rv = prefs->SetComplexValue(prefName.get(),
|
|
|
|
NS_GET_IID(nsISupportsString),
|
|
|
|
prefString);
|
2010-05-15 00:24:50 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Couldn't set last user model id!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString appHelperPath;
|
|
|
|
if (NS_FAILED(GetHelperPath(appHelperPath)))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
appHelperPath.AppendLiteral(" /UpdateShortcutAppUserModelIds");
|
|
|
|
|
|
|
|
return LaunchHelper(appHelperPath);
|
|
|
|
}
|
|
|
|
|
2012-10-05 14:17:30 +00:00
|
|
|
static bool
|
|
|
|
IsAARDefaultHTTP(IApplicationAssociationRegistration* pAAR,
|
|
|
|
bool* aIsDefaultBrowser)
|
|
|
|
{
|
|
|
|
// Make sure the Prog ID matches what we have
|
|
|
|
LPWSTR registeredApp;
|
|
|
|
HRESULT hr = pAAR->QueryCurrentDefault(L"http", AT_URLPROTOCOL, AL_EFFECTIVE,
|
|
|
|
®isteredApp);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
LPCWSTR firefoxHTTPProgID = L"FirefoxURL";
|
|
|
|
*aIsDefaultBrowser = !wcsicmp(registeredApp, firefoxHTTPProgID);
|
|
|
|
CoTaskMemFree(registeredApp);
|
|
|
|
} else {
|
|
|
|
*aIsDefaultBrowser = false;
|
|
|
|
}
|
|
|
|
return SUCCEEDED(hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsAARDefaultHTML(IApplicationAssociationRegistration* pAAR,
|
|
|
|
bool* aIsDefaultBrowser)
|
|
|
|
{
|
|
|
|
LPWSTR registeredApp;
|
|
|
|
HRESULT hr = pAAR->QueryCurrentDefault(L".html", AT_FILEEXTENSION, AL_EFFECTIVE,
|
|
|
|
®isteredApp);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
LPCWSTR firefoxHTMLProgID = L"FirefoxHTML";
|
|
|
|
*aIsDefaultBrowser = !wcsicmp(registeredApp, firefoxHTMLProgID);
|
|
|
|
CoTaskMemFree(registeredApp);
|
|
|
|
} else {
|
|
|
|
*aIsDefaultBrowser = false;
|
|
|
|
}
|
|
|
|
return SUCCEEDED(hr);
|
|
|
|
}
|
|
|
|
|
2013-09-13 18:30:20 +00:00
|
|
|
/*
|
|
|
|
* Query's the AAR for the default status.
|
|
|
|
* This only checks for FirefoxURL and if aCheckAllTypes is set, then
|
|
|
|
* it also checks for FirefoxHTML. Note that those ProgIDs are shared
|
|
|
|
* by all Firefox browsers.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-09-21 14:05:24 +00:00
|
|
|
nsWindowsShellService::IsDefaultBrowserVista(bool aCheckAllTypes,
|
|
|
|
bool* aIsDefaultBrowser)
|
2006-09-22 14:45:57 +00:00
|
|
|
{
|
|
|
|
IApplicationAssociationRegistration* pAAR;
|
2008-04-25 16:44:16 +00:00
|
|
|
HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
|
2013-08-21 16:13:50 +00:00
|
|
|
nullptr,
|
2007-07-24 02:27:30 +00:00
|
|
|
CLSCTX_INPROC,
|
2008-04-25 16:44:16 +00:00
|
|
|
IID_IApplicationAssociationRegistration,
|
2007-07-24 02:27:30 +00:00
|
|
|
(void**)&pAAR);
|
2008-08-05 06:13:44 +00:00
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
if (SUCCEEDED(hr)) {
|
2012-10-05 14:17:30 +00:00
|
|
|
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);
|
2012-09-21 14:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-05 14:17:30 +00:00
|
|
|
} else {
|
|
|
|
IsAARDefaultHTTP(pAAR, aIsDefaultBrowser);
|
2012-06-08 13:19:01 +00:00
|
|
|
}
|
|
|
|
|
2006-09-22 14:45:57 +00:00
|
|
|
pAAR->Release();
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2006-09-22 14:45:57 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2006-09-22 14:45:57 +00:00
|
|
|
}
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsWindowsShellService::IsDefaultBrowser(bool aStartupCheck,
|
2012-09-21 14:05:24 +00:00
|
|
|
bool aForAllTypes,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aIsDefaultBrowser)
|
2004-03-08 09:56:16 +00:00
|
|
|
{
|
2007-09-29 09:48:32 +00:00
|
|
|
// If this is the first browser window, maintain internal state that we've
|
2012-09-21 14:05:24 +00:00
|
|
|
// checked this session (so that subsequent window opens don't show the
|
2007-09-29 09:48:32 +00:00
|
|
|
// default browser dialog).
|
|
|
|
if (aStartupCheck)
|
2011-10-17 14:59:28 +00:00
|
|
|
mCheckedThisSession = true;
|
2006-09-22 14:45:57 +00:00
|
|
|
|
2012-09-21 14:05:24 +00:00
|
|
|
// Assume we're the default unless one of the several checks below tell us
|
|
|
|
// otherwise.
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsDefaultBrowser = true;
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2013-12-03 15:09:50 +00:00
|
|
|
wchar_t exePath[MAX_BUF];
|
2007-07-24 02:27:30 +00:00
|
|
|
if (!::GetModuleFileNameW(0, exePath, MAX_BUF))
|
2006-10-10 19:56:08 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-02-15 23:03:59 +00:00
|
|
|
// Convert the path to a long path since GetModuleFileNameW returns the path
|
|
|
|
// that was used to launch Firefox which is not necessarily a long path.
|
|
|
|
if (!::GetLongPathNameW(exePath, exePath, MAX_BUF))
|
2006-10-10 19:56:08 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-02-15 23:03:59 +00:00
|
|
|
nsAutoString appLongPath(exePath);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2012-03-26 19:45:29 +00:00
|
|
|
HKEY theKey;
|
|
|
|
DWORD res;
|
2009-02-15 23:03:59 +00:00
|
|
|
nsresult rv;
|
2013-12-03 15:09:50 +00:00
|
|
|
wchar_t currValue[MAX_BUF];
|
2012-03-26 19:45:29 +00:00
|
|
|
|
2013-09-13 18:30:20 +00:00
|
|
|
SETTING* settings = gSettings;
|
|
|
|
if (!aForAllTypes && IsWin8OrLater()) {
|
|
|
|
// Skip over the file handler check
|
|
|
|
settings++;
|
|
|
|
}
|
|
|
|
|
2012-03-26 19:45:29 +00:00
|
|
|
SETTING* end = gSettings + sizeof(gSettings) / sizeof(SETTING);
|
|
|
|
|
2013-09-13 18:30:20 +00:00
|
|
|
for (; settings < end; ++settings) {
|
2012-03-26 19:45:29 +00:00
|
|
|
NS_ConvertUTF8toUTF16 keyName(settings->keyName);
|
|
|
|
NS_ConvertUTF8toUTF16 valueData(settings->valueData);
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t offset = valueData.Find("%APPPATH%");
|
2012-03-26 19:45:29 +00:00
|
|
|
valueData.Replace(offset, 9, appLongPath);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2012-03-26 19:45:29 +00:00
|
|
|
rv = OpenKeyForReading(HKEY_CLASSES_ROOT, keyName, &theKey);
|
2008-08-05 06:13:44 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsDefaultBrowser = false;
|
2008-08-05 06:48:06 +00:00
|
|
|
return NS_OK;
|
2008-08-05 06:13:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 19:45:29 +00:00
|
|
|
::ZeroMemory(currValue, sizeof(currValue));
|
2008-08-05 06:13:44 +00:00
|
|
|
DWORD len = sizeof currValue;
|
2013-08-21 16:13:50 +00:00
|
|
|
res = ::RegQueryValueExW(theKey, L"", nullptr, nullptr,
|
|
|
|
(LPBYTE)currValue, &len);
|
2012-03-26 19:45:29 +00:00
|
|
|
// Close the key that was opened.
|
2008-08-05 06:13:44 +00:00
|
|
|
::RegCloseKey(theKey);
|
|
|
|
if (REG_FAILED(res) ||
|
2013-11-19 12:24:07 +00:00
|
|
|
_wcsicmp(valueData.get(), currValue)) {
|
2012-03-26 19:45:29 +00:00
|
|
|
// Key wasn't set or was set to something other than our registry entry.
|
|
|
|
NS_ConvertUTF8toUTF16 oldValueData(settings->oldValueData);
|
|
|
|
offset = oldValueData.Find("%APPPATH%");
|
|
|
|
oldValueData.Replace(offset, 9, appLongPath);
|
|
|
|
// The current registry value doesn't match the current or the old format.
|
2013-11-19 12:24:07 +00:00
|
|
|
if (_wcsicmp(oldValueData.get(), currValue)) {
|
2012-03-26 19:45:29 +00:00
|
|
|
*aIsDefaultBrowser = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ::RegOpenKeyExW(HKEY_CLASSES_ROOT, PromiseFlatString(keyName).get(),
|
|
|
|
0, KEY_SET_VALUE, &theKey);
|
|
|
|
if (REG_FAILED(res)) {
|
|
|
|
// If updating the open command fails try to update it using the helper
|
|
|
|
// application when setting Firefox as the default browser.
|
|
|
|
*aIsDefaultBrowser = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsString &flatValue = PromiseFlatString(valueData);
|
|
|
|
res = ::RegSetValueExW(theKey, L"", 0, REG_SZ,
|
|
|
|
(const BYTE *) flatValue.get(),
|
2014-01-04 15:02:17 +00:00
|
|
|
(flatValue.Length() + 1) * sizeof(char16_t));
|
2012-03-26 19:45:29 +00:00
|
|
|
// Close the key that was created.
|
|
|
|
::RegCloseKey(theKey);
|
|
|
|
if (REG_FAILED(res)) {
|
|
|
|
// If updating the open command fails try to update it using the helper
|
|
|
|
// application when setting Firefox as the default browser.
|
|
|
|
*aIsDefaultBrowser = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-26 19:45:29 +00:00
|
|
|
// Only check if Firefox is the default browser on Vista and above if the
|
|
|
|
// previous checks show that Firefox is the default browser.
|
|
|
|
if (*aIsDefaultBrowser) {
|
2013-09-13 18:30:20 +00:00
|
|
|
IsDefaultBrowserVista(aForAllTypes, aIsDefaultBrowser);
|
2012-03-26 19:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// To handle the case where DDE isn't disabled due for a user because there
|
|
|
|
// account didn't perform a Firefox update this will check if Firefox is the
|
|
|
|
// default browser and if dde is disabled for each handler
|
|
|
|
// and if it isn't disable it. When Firefox is not the default browser the
|
|
|
|
// helper application will disable dde for each handler.
|
2013-09-13 18:30:20 +00:00
|
|
|
if (*aIsDefaultBrowser && aForAllTypes) {
|
2012-03-26 19:45:29 +00:00
|
|
|
// Check ftp settings
|
|
|
|
|
|
|
|
end = gDDESettings + sizeof(gDDESettings) / sizeof(SETTING);
|
|
|
|
|
|
|
|
for (settings = gDDESettings; settings < end; ++settings) {
|
|
|
|
NS_ConvertUTF8toUTF16 keyName(settings->keyName);
|
|
|
|
|
|
|
|
rv = OpenKeyForReading(HKEY_CURRENT_USER, keyName, &theKey);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
::RegCloseKey(theKey);
|
|
|
|
// If disabling DDE fails try to disable it using the helper
|
|
|
|
// application when setting Firefox as the default browser.
|
|
|
|
*aIsDefaultBrowser = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
::ZeroMemory(currValue, sizeof(currValue));
|
|
|
|
DWORD len = sizeof currValue;
|
2013-08-21 16:13:50 +00:00
|
|
|
res = ::RegQueryValueExW(theKey, L"", nullptr, nullptr,
|
|
|
|
(LPBYTE)currValue, &len);
|
2012-03-26 19:45:29 +00:00
|
|
|
// Close the key that was opened.
|
|
|
|
::RegCloseKey(theKey);
|
2014-01-04 15:02:17 +00:00
|
|
|
if (REG_FAILED(res) || char16_t('\0') != *currValue) {
|
2012-03-26 19:45:29 +00:00
|
|
|
// Key wasn't set or was set to something other than our registry entry.
|
|
|
|
// Delete the key along with all of its childrean and then recreate it.
|
|
|
|
const nsString &flatName = PromiseFlatString(keyName);
|
|
|
|
::SHDeleteKeyW(HKEY_CURRENT_USER, flatName.get());
|
2013-08-21 16:13:50 +00:00
|
|
|
res = ::RegCreateKeyExW(HKEY_CURRENT_USER, flatName.get(), 0, nullptr,
|
|
|
|
REG_OPTION_NON_VOLATILE, KEY_SET_VALUE,
|
|
|
|
nullptr, &theKey, nullptr);
|
2012-03-26 19:45:29 +00:00
|
|
|
if (REG_FAILED(res)) {
|
|
|
|
// If disabling DDE fails try to disable it using the helper
|
|
|
|
// application when setting Firefox as the default browser.
|
|
|
|
*aIsDefaultBrowser = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ::RegSetValueExW(theKey, L"", 0, REG_SZ, (const BYTE *) L"",
|
2014-01-04 15:02:17 +00:00
|
|
|
sizeof(char16_t));
|
2012-03-26 19:45:29 +00:00
|
|
|
// Close the key that was created.
|
|
|
|
::RegCloseKey(theKey);
|
|
|
|
if (REG_FAILED(res)) {
|
|
|
|
// If disabling DDE fails try to disable it using the helper
|
|
|
|
// application when setting Firefox as the default browser.
|
|
|
|
*aIsDefaultBrowser = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the FTP protocol handler's shell open command if it is the old
|
|
|
|
// format.
|
|
|
|
res = ::RegOpenKeyExW(HKEY_CURRENT_USER, FTP_SOC, 0, KEY_ALL_ACCESS,
|
|
|
|
&theKey);
|
|
|
|
// Don't update the FTP protocol handler's shell open command when opening
|
|
|
|
// its registry key fails under HKCU since it most likely doesn't exist.
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF8toUTF16 oldValueOpen(OLD_VAL_OPEN);
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t offset = oldValueOpen.Find("%APPPATH%");
|
2012-03-26 19:45:29 +00:00
|
|
|
oldValueOpen.Replace(offset, 9, appLongPath);
|
|
|
|
|
|
|
|
::ZeroMemory(currValue, sizeof(currValue));
|
|
|
|
DWORD len = sizeof currValue;
|
2013-08-21 16:13:50 +00:00
|
|
|
res = ::RegQueryValueExW(theKey, L"", nullptr, nullptr, (LPBYTE)currValue,
|
2012-03-26 19:45:29 +00:00
|
|
|
&len);
|
|
|
|
|
|
|
|
// Don't update the FTP protocol handler's shell open command when the
|
|
|
|
// current registry value doesn't exist or matches the old format.
|
|
|
|
if (REG_FAILED(res) ||
|
2013-11-19 12:24:07 +00:00
|
|
|
_wcsicmp(oldValueOpen.get(), currValue)) {
|
2012-03-26 19:45:29 +00:00
|
|
|
::RegCloseKey(theKey);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF8toUTF16 valueData(VAL_OPEN);
|
|
|
|
valueData.Replace(offset, 9, appLongPath);
|
|
|
|
const nsString &flatValue = PromiseFlatString(valueData);
|
|
|
|
res = ::RegSetValueExW(theKey, L"", 0, REG_SZ,
|
|
|
|
(const BYTE *) flatValue.get(),
|
2014-01-04 15:02:17 +00:00
|
|
|
(flatValue.Length() + 1) * sizeof(char16_t));
|
2012-03-26 19:45:29 +00:00
|
|
|
// Close the key that was created.
|
|
|
|
::RegCloseKey(theKey);
|
|
|
|
// If updating the FTP protocol handlers shell open command fails try to
|
|
|
|
// update it using the helper application when setting Firefox as the
|
|
|
|
// default browser.
|
|
|
|
if (REG_FAILED(res)) {
|
|
|
|
*aIsDefaultBrowser = false;
|
|
|
|
}
|
|
|
|
}
|
2005-12-04 21:02:38 +00:00
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-02 20:43:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowsShellService::GetCanSetDesktopBackground(bool* aResult)
|
|
|
|
{
|
|
|
|
*aResult = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:19:01 +00:00
|
|
|
static nsresult
|
|
|
|
DynSHOpenWithDialog(HWND hwndParent, const OPENASINFO *poainfo)
|
|
|
|
{
|
2013-09-13 18:30:20 +00:00
|
|
|
// shell32.dll is in the knownDLLs list so will always be loaded from the
|
|
|
|
// system32 directory.
|
2013-12-03 15:09:50 +00:00
|
|
|
static const wchar_t kSehllLibraryName[] = L"shell32.dll";
|
2013-09-13 18:30:20 +00:00
|
|
|
HMODULE shellDLL = ::LoadLibraryW(kSehllLibraryName);
|
|
|
|
if (!shellDLL) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-06-08 13:19:01 +00:00
|
|
|
|
2014-02-17 22:32:52 +00:00
|
|
|
decltype(SHOpenWithDialog)* SHOpenWithDialogFn =
|
|
|
|
(decltype(SHOpenWithDialog)*) GetProcAddress(shellDLL, "SHOpenWithDialog");
|
2012-06-08 13:19:01 +00:00
|
|
|
|
2013-09-13 18:30:20 +00:00
|
|
|
if (!SHOpenWithDialogFn) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-06-08 13:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 04:55:50 +00:00
|
|
|
nsresult rv;
|
|
|
|
HRESULT hr = SHOpenWithDialogFn(hwndParent, poainfo);
|
|
|
|
if (SUCCEEDED(hr) || (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))) {
|
|
|
|
rv = NS_OK;
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
2013-09-13 18:30:20 +00:00
|
|
|
FreeLibrary(shellDLL);
|
|
|
|
return rv;
|
2012-06-08 13:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-09-21 14:05:24 +00:00
|
|
|
nsresult
|
2015-06-27 03:27:26 +00:00
|
|
|
nsWindowsShellService::LaunchControlPanelDefaultsSelectionUI()
|
2012-09-21 14:05:24 +00:00
|
|
|
{
|
2015-06-27 03:27:26 +00:00
|
|
|
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();
|
2012-09-21 14:05:24 +00:00
|
|
|
}
|
2015-06-27 03:27:26 +00:00
|
|
|
return SUCCEEDED(hr) ? NS_OK : NS_ERROR_FAILURE;
|
2012-09-21 14:05:24 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 15:40:40 +00:00
|
|
|
nsresult
|
|
|
|
nsWindowsShellService::LaunchModernSettingsDialogDefaultApps()
|
|
|
|
{
|
|
|
|
IApplicationActivationManager* pActivator;
|
|
|
|
HRESULT hr = CoCreateInstance(CLSID_ApplicationActivationManager,
|
|
|
|
nullptr,
|
|
|
|
CLSCTX_INPROC,
|
|
|
|
IID_IApplicationActivationManager,
|
|
|
|
(void**)&pActivator);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
DWORD pid;
|
|
|
|
hr = pActivator->ActivateApplication(
|
|
|
|
L"windows.immersivecontrolpanel_cw5n1h2txyewy"
|
|
|
|
L"!microsoft.windows.immersivecontrolpanel",
|
|
|
|
L"page=SettingsPageAppsDefaults", AO_NONE, &pid);
|
|
|
|
pActivator->Release();
|
|
|
|
return SUCCEEDED(hr) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-18 23:16:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-21 14:05:24 +00:00
|
|
|
nsresult
|
|
|
|
nsWindowsShellService::LaunchHTTPHandlerPane()
|
|
|
|
{
|
|
|
|
OPENASINFO info;
|
|
|
|
info.pcszFile = L"http";
|
2013-08-21 16:13:50 +00:00
|
|
|
info.pcszClass = nullptr;
|
2012-09-21 14:05:24 +00:00
|
|
|
info.oaifInFlags = OAIF_FORCE_REGISTRATION |
|
|
|
|
OAIF_URL_PROTOCOL |
|
|
|
|
OAIF_REGISTER_EXT;
|
2013-08-21 16:13:50 +00:00
|
|
|
return DynSHOpenWithDialog(nullptr, &info);
|
2012-09-21 14:05:24 +00:00
|
|
|
}
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsWindowsShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers)
|
2004-03-08 09:56:16 +00:00
|
|
|
{
|
2008-08-05 06:13:44 +00:00
|
|
|
nsAutoString appHelperPath;
|
2010-05-15 00:24:50 +00:00
|
|
|
if (NS_FAILED(GetHelperPath(appHelperPath)))
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2007-09-29 09:48:32 +00:00
|
|
|
if (aForAllUsers) {
|
|
|
|
appHelperPath.AppendLiteral(" /SetAsDefaultAppGlobal");
|
|
|
|
} else {
|
|
|
|
appHelperPath.AppendLiteral(" /SetAsDefaultAppUser");
|
2007-07-24 02:27:30 +00:00
|
|
|
}
|
2007-02-08 20:18:17 +00:00
|
|
|
|
2012-06-15 02:19:39 +00:00
|
|
|
nsresult rv = LaunchHelper(appHelperPath);
|
2015-06-20 05:16:05 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
2012-06-15 02:19:39 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && IsWin8OrLater()) {
|
2012-09-21 14:05:24 +00:00
|
|
|
if (aClaimAllTypes) {
|
2015-06-18 23:16:52 +00:00
|
|
|
if (IsWin10OrLater()) {
|
|
|
|
rv = LaunchModernSettingsDialogDefaultApps();
|
|
|
|
} else {
|
2015-06-27 03:27:26 +00:00
|
|
|
rv = LaunchControlPanelDefaultsSelectionUI();
|
2015-06-18 23:16:52 +00:00
|
|
|
}
|
2012-09-21 14:05:24 +00:00
|
|
|
// The above call should never really fail, but just in case
|
|
|
|
// fall back to showing the HTTP association screen only.
|
|
|
|
if (NS_FAILED(rv)) {
|
2015-06-18 23:16:52 +00:00
|
|
|
if (IsWin10OrLater()) {
|
|
|
|
rv = InvokeHTTPOpenAsVerb();
|
|
|
|
} else {
|
|
|
|
rv = LaunchHTTPHandlerPane();
|
|
|
|
}
|
2012-09-21 14:05:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-06-20 05:16:05 +00:00
|
|
|
// Windows 10 blocks attempts to load the
|
|
|
|
// HTTP Handler association dialog.
|
2015-06-03 15:40:40 +00:00
|
|
|
if (IsWin10OrLater()) {
|
2015-06-20 05:16:05 +00:00
|
|
|
if (prefs) {
|
|
|
|
int32_t abTest;
|
|
|
|
rv = prefs->GetIntPref("browser.shell.windows10DefaultBrowserABTest", &abTest);
|
|
|
|
if (NS_SUCCEEDED(rv) && abTest == 0) {
|
|
|
|
rv = InvokeHTTPOpenAsVerb();
|
|
|
|
} else {
|
|
|
|
rv = LaunchModernSettingsDialogDefaultApps();
|
|
|
|
}
|
|
|
|
}
|
2015-06-03 15:40:40 +00:00
|
|
|
} else {
|
|
|
|
rv = LaunchHTTPHandlerPane();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The above call should never really fail, but just in case
|
|
|
|
// fall back to showing control panel for all defaults
|
2012-09-21 14:05:24 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2015-06-18 23:16:52 +00:00
|
|
|
if (IsWin10OrLater()) {
|
|
|
|
rv = LaunchModernSettingsDialogDefaultApps();
|
|
|
|
} else {
|
2015-06-27 03:27:26 +00:00
|
|
|
rv = LaunchControlPanelDefaultsSelectionUI();
|
2015-06-18 23:16:52 +00:00
|
|
|
}
|
2012-09-21 14:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-15 02:19:39 +00:00
|
|
|
}
|
2012-09-21 14:05:24 +00:00
|
|
|
|
2014-10-14 04:15:43 +00:00
|
|
|
if (prefs) {
|
|
|
|
(void) prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, true);
|
|
|
|
}
|
|
|
|
|
2012-06-15 02:19:39 +00:00
|
|
|
return rv;
|
2009-07-08 20:51:21 +00:00
|
|
|
}
|
|
|
|
|
2005-12-04 21:02:38 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsWindowsShellService::GetShouldCheckDefaultBrowser(bool* aResult)
|
2005-12-04 21:02:38 +00:00
|
|
|
{
|
2011-10-13 17:16:45 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
2005-12-04 21:02:38 +00:00
|
|
|
// If we've already checked, the browser has been started and this is a
|
|
|
|
// new window open, and we don't want to check again.
|
|
|
|
if (mCheckedThisSession) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aResult = false;
|
2005-12-04 21:02:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-13 17:16:45 +00:00
|
|
|
nsresult rv;
|
2014-10-14 04:10:47 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2005-12-04 21:02:38 +00:00
|
|
|
|
2011-10-13 17:16:45 +00:00
|
|
|
return prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult);
|
2005-12-04 21:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsWindowsShellService::SetShouldCheckDefaultBrowser(bool aShouldCheck)
|
2005-12-04 21:02:38 +00:00
|
|
|
{
|
2011-10-13 17:16:45 +00:00
|
|
|
nsresult rv;
|
2014-10-14 04:10:47 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2005-12-04 21:02:38 +00:00
|
|
|
|
2011-10-13 17:16:45 +00:00
|
|
|
return prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck);
|
2005-12-04 21:02:38 +00:00
|
|
|
}
|
|
|
|
|
2005-06-23 02:25:06 +00:00
|
|
|
static nsresult
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
WriteBitmap(nsIFile* aFile, imgIContainer* aImage)
|
2004-03-08 09:56:16 +00:00
|
|
|
{
|
2013-03-05 23:39:48 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2014-04-15 18:02:23 +00:00
|
|
|
RefPtr<SourceSurface> surface =
|
2013-12-13 08:34:24 +00:00
|
|
|
aImage->GetFrame(imgIContainer::FRAME_FIRST,
|
|
|
|
imgIContainer::FLAG_SYNC_DECODE);
|
2014-04-15 18:02:23 +00:00
|
|
|
NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE);
|
2013-03-05 23:39:48 +00:00
|
|
|
|
2014-04-15 18:02:23 +00:00
|
|
|
// For either of the following formats we want to set the biBitCount member
|
|
|
|
// of the BITMAPINFOHEADER struct to 32, below. For that value the bitmap
|
|
|
|
// format defines that the A8/X8 WORDs in the bitmap byte stream be ignored
|
|
|
|
// for the BI_RGB value we use for the biCompression member.
|
|
|
|
MOZ_ASSERT(surface->GetFormat() == SurfaceFormat::B8G8R8A8 ||
|
|
|
|
surface->GetFormat() == SurfaceFormat::B8G8R8X8);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
|
2014-04-15 18:02:23 +00:00
|
|
|
RefPtr<DataSourceSurface> dataSurface = surface->GetDataSurface();
|
2014-03-04 16:56:44 +00:00
|
|
|
NS_ENSURE_TRUE(dataSurface, NS_ERROR_FAILURE);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2014-03-04 16:56:44 +00:00
|
|
|
int32_t width = dataSurface->GetSize().width;
|
|
|
|
int32_t height = dataSurface->GetSize().height;
|
|
|
|
int32_t bytesPerPixel = 4 * sizeof(uint8_t);
|
|
|
|
uint32_t bytesPerRow = bytesPerPixel * width;
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
// initialize these bitmap structs which we will later
|
|
|
|
// serialize directly to the head of the bitmap file
|
2006-06-26 23:53:01 +00:00
|
|
|
BITMAPINFOHEADER bmi;
|
|
|
|
bmi.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
bmi.biWidth = width;
|
|
|
|
bmi.biHeight = height;
|
|
|
|
bmi.biPlanes = 1;
|
2014-03-04 16:56:44 +00:00
|
|
|
bmi.biBitCount = (WORD)bytesPerPixel*8;
|
2006-06-26 23:53:01 +00:00
|
|
|
bmi.biCompression = BI_RGB;
|
2014-03-04 16:56:44 +00:00
|
|
|
bmi.biSizeImage = bytesPerRow * height;
|
2006-06-26 23:53:01 +00:00
|
|
|
bmi.biXPelsPerMeter = 0;
|
|
|
|
bmi.biYPelsPerMeter = 0;
|
|
|
|
bmi.biClrUsed = 0;
|
|
|
|
bmi.biClrImportant = 0;
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
BITMAPFILEHEADER bf;
|
|
|
|
bf.bfType = 0x4D42; // 'BM'
|
|
|
|
bf.bfReserved1 = 0;
|
|
|
|
bf.bfReserved2 = 0;
|
|
|
|
bf.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
|
2006-06-26 23:53:01 +00:00
|
|
|
bf.bfSize = bf.bfOffBits + bmi.biSizeImage;
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
// get a file output stream
|
|
|
|
nsCOMPtr<nsIOutputStream> stream;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
rv = NS_NewLocalFileOutputStream(getter_AddRefs(stream), aFile);
|
2005-07-24 22:56:48 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2014-03-07 13:21:38 +00:00
|
|
|
DataSourceSurface::MappedSurface map;
|
|
|
|
if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
// write the bitmap headers and rgb pixel data to the file
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
if (stream) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t written;
|
2004-03-08 09:56:16 +00:00
|
|
|
stream->Write((const char*)&bf, sizeof(BITMAPFILEHEADER), &written);
|
|
|
|
if (written == sizeof(BITMAPFILEHEADER)) {
|
2006-06-26 23:53:01 +00:00
|
|
|
stream->Write((const char*)&bmi, sizeof(BITMAPINFOHEADER), &written);
|
2004-03-08 09:56:16 +00:00
|
|
|
if (written == sizeof(BITMAPINFOHEADER)) {
|
2006-06-26 23:53:01 +00:00
|
|
|
// write out the image data backwards because the desktop won't
|
|
|
|
// show bitmaps with negative heights for top-to-bottom
|
2014-03-07 13:21:38 +00:00
|
|
|
uint32_t i = map.mStride * height;
|
2006-06-26 23:53:01 +00:00
|
|
|
do {
|
2014-03-04 16:56:44 +00:00
|
|
|
i -= map.mStride;
|
|
|
|
stream->Write(((const char*)map.mData) + i, bytesPerRow, &written);
|
|
|
|
if (written == bytesPerRow) {
|
2006-06-26 23:53:01 +00:00
|
|
|
rv = NS_OK;
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (i != 0);
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->Close();
|
|
|
|
}
|
|
|
|
|
2014-03-07 13:21:38 +00:00
|
|
|
dataSurface->Unmap();
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowsShellService::SetDesktopBackground(nsIDOMElement* aElement,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aPosition)
|
2004-03-08 09:56:16 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
nsCOMPtr<imgIContainer> container;
|
2004-03-08 09:56:16 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(aElement));
|
|
|
|
if (!imgElement) {
|
|
|
|
// XXX write background loading stuff!
|
2009-12-13 17:11:39 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-07-24 02:27:30 +00:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageContent =
|
|
|
|
do_QueryInterface(aElement, &rv);
|
|
|
|
if (!imageContent)
|
|
|
|
return rv;
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
// get the image container
|
|
|
|
nsCOMPtr<imgIRequest> request;
|
|
|
|
rv = imageContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(request));
|
2007-07-24 02:27:30 +00:00
|
|
|
if (!request)
|
|
|
|
return rv;
|
2004-03-08 09:56:16 +00:00
|
|
|
rv = request->GetImage(getter_AddRefs(container));
|
2004-08-16 23:49:43 +00:00
|
|
|
if (!container)
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
|
2005-07-24 22:56:48 +00:00
|
|
|
// get the file name from localized strings
|
|
|
|
nsCOMPtr<nsIStringBundleService>
|
|
|
|
bundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2005-07-24 22:56:48 +00:00
|
|
|
nsCOMPtr<nsIStringBundle> shellBundle;
|
|
|
|
rv = bundleService->CreateBundle(SHELLSERVICE_PROPERTIES,
|
|
|
|
getter_AddRefs(shellBundle));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// e.g. "Desktop Background.bmp"
|
2006-11-13 17:53:01 +00:00
|
|
|
nsString fileLeafName;
|
2005-07-24 22:56:48 +00:00
|
|
|
rv = shellBundle->GetStringFromName
|
2013-12-13 01:50:01 +00:00
|
|
|
(MOZ_UTF16("desktopBackgroundLeafNameWin"),
|
2005-07-24 22:56:48 +00:00
|
|
|
getter_Copies(fileLeafName));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-06-23 02:25:06 +00:00
|
|
|
|
2005-07-24 22:56:48 +00:00
|
|
|
// get the profile root directory
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
rv = NS_GetSpecialDirectory(NS_APP_APPLICATION_REGISTRY_DIR,
|
|
|
|
getter_AddRefs(file));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2005-07-24 22:56:48 +00:00
|
|
|
// eventually, the path is "%APPDATA%\Mozilla\Firefox\Desktop Background.bmp"
|
|
|
|
rv = file->Append(fileLeafName);
|
2005-06-23 02:25:06 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-07-24 22:56:48 +00:00
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
nsAutoString path;
|
|
|
|
rv = file->GetPath(path);
|
2005-06-23 02:25:06 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2005-07-24 22:56:48 +00:00
|
|
|
// write the bitmap to a file in the profile directory
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
rv = WriteBitmap(file, container);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
// if the file was written successfully, set it as the system wallpaper
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-01-19 19:44:27 +00:00
|
|
|
nsCOMPtr<nsIWindowsRegKey> regKey =
|
|
|
|
do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_LITERAL_STRING("Control Panel\\Desktop"),
|
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString tile;
|
|
|
|
nsAutoString style;
|
|
|
|
switch (aPosition) {
|
|
|
|
case BACKGROUND_TILE:
|
2014-05-26 18:55:08 +00:00
|
|
|
style.Assign('0');
|
|
|
|
tile.Assign('1');
|
2012-01-19 19:44:27 +00:00
|
|
|
break;
|
|
|
|
case BACKGROUND_CENTER:
|
2014-05-26 18:55:08 +00:00
|
|
|
style.Assign('0');
|
|
|
|
tile.Assign('0');
|
2012-01-19 19:44:27 +00:00
|
|
|
break;
|
|
|
|
case BACKGROUND_STRETCH:
|
2014-05-26 18:55:08 +00:00
|
|
|
style.Assign('2');
|
|
|
|
tile.Assign('0');
|
2012-01-19 19:44:27 +00:00
|
|
|
break;
|
2012-02-01 10:37:55 +00:00
|
|
|
case BACKGROUND_FILL:
|
|
|
|
style.AssignLiteral("10");
|
2014-05-26 18:55:08 +00:00
|
|
|
tile.Assign('0');
|
2012-02-01 10:37:55 +00:00
|
|
|
break;
|
|
|
|
case BACKGROUND_FIT:
|
2014-05-26 18:55:08 +00:00
|
|
|
style.Assign('6');
|
|
|
|
tile.Assign('0');
|
2012-02-01 10:37:55 +00:00
|
|
|
break;
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
2012-01-19 19:44:27 +00:00
|
|
|
|
|
|
|
rv = regKey->WriteStringValue(NS_LITERAL_STRING("TileWallpaper"), tile);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = regKey->WriteStringValue(NS_LITERAL_STRING("WallpaperStyle"), style);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = regKey->Close();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
::SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (PVOID)path.get(),
|
|
|
|
SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsWindowsShellService::OpenApplication(int32_t aApplication)
|
2004-03-08 09:56:16 +00:00
|
|
|
{
|
2007-07-24 02:27:30 +00:00
|
|
|
nsAutoString application;
|
2004-03-08 09:56:16 +00:00
|
|
|
switch (aApplication) {
|
|
|
|
case nsIShellService::APPLICATION_MAIL:
|
2007-07-24 02:27:30 +00:00
|
|
|
application.AssignLiteral("Mail");
|
2004-03-08 09:56:16 +00:00
|
|
|
break;
|
|
|
|
case nsIShellService::APPLICATION_NEWS:
|
2007-07-24 02:27:30 +00:00
|
|
|
application.AssignLiteral("News");
|
2004-03-08 09:56:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The Default Client section of the Windows Registry looks like this:
|
|
|
|
//
|
|
|
|
// Clients\aClient\
|
|
|
|
// e.g. aClient = "Mail"...
|
|
|
|
// \Mail\(default) = Client Subkey Name
|
|
|
|
// \Client Subkey Name
|
|
|
|
// \Client Subkey Name\shell\open\command\
|
|
|
|
// \Client Subkey Name\shell\open\command\(default) = path to exe
|
|
|
|
//
|
|
|
|
|
|
|
|
// Find the default application for this class.
|
|
|
|
HKEY theKey;
|
2007-09-29 09:48:32 +00:00
|
|
|
nsresult rv = OpenKeyForReading(HKEY_CLASSES_ROOT, application, &theKey);
|
2007-07-24 02:27:30 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2013-12-03 15:09:50 +00:00
|
|
|
wchar_t buf[MAX_BUF];
|
2004-03-08 09:56:16 +00:00
|
|
|
DWORD type, len = sizeof buf;
|
2007-07-24 02:27:30 +00:00
|
|
|
DWORD res = ::RegQueryValueExW(theKey, EmptyString().get(), 0,
|
|
|
|
&type, (LPBYTE)&buf, &len);
|
|
|
|
|
|
|
|
if (REG_FAILED(res) || !*buf)
|
2004-03-08 09:56:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2005-01-16 21:02:13 +00:00
|
|
|
// Close the key we opened.
|
|
|
|
::RegCloseKey(theKey);
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
// Find the "open" command
|
2014-05-26 18:54:58 +00:00
|
|
|
application.Append('\\');
|
2007-09-29 09:48:32 +00:00
|
|
|
application.Append(buf);
|
|
|
|
application.AppendLiteral("\\shell\\open\\command");
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2007-09-29 09:48:32 +00:00
|
|
|
rv = OpenKeyForReading(HKEY_CLASSES_ROOT, application, &theKey);
|
2007-07-24 02:27:30 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
::ZeroMemory(buf, sizeof(buf));
|
|
|
|
len = sizeof buf;
|
2007-07-24 02:27:30 +00:00
|
|
|
res = ::RegQueryValueExW(theKey, EmptyString().get(), 0,
|
|
|
|
&type, (LPBYTE)&buf, &len);
|
|
|
|
if (REG_FAILED(res) || !*buf)
|
2004-06-30 20:27:30 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2005-01-16 21:02:13 +00:00
|
|
|
// Close the key we opened.
|
|
|
|
::RegCloseKey(theKey);
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
// Look for any embedded environment variables and substitute their
|
2007-07-24 02:27:30 +00:00
|
|
|
// values, as |::CreateProcessW| is unable to do this.
|
|
|
|
nsAutoString path(buf);
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t end = path.Length();
|
|
|
|
int32_t cursor = 0, temp = 0;
|
2004-03-08 09:56:16 +00:00
|
|
|
::ZeroMemory(buf, sizeof(buf));
|
|
|
|
do {
|
|
|
|
cursor = path.FindChar('%', cursor);
|
|
|
|
if (cursor < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
temp = path.FindChar('%', cursor + 1);
|
|
|
|
++cursor;
|
|
|
|
|
|
|
|
::ZeroMemory(&buf, sizeof(buf));
|
2007-07-24 02:27:30 +00:00
|
|
|
|
|
|
|
::GetEnvironmentVariableW(nsAutoString(Substring(path, cursor, temp - cursor)).get(),
|
|
|
|
buf, sizeof(buf));
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
// "+ 2" is to subtract the extra characters used to delimit the environment
|
|
|
|
// variable ('%').
|
2007-07-24 02:27:30 +00:00
|
|
|
path.Replace((cursor - 1), temp - cursor + 2, nsDependentString(buf));
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
++cursor;
|
|
|
|
}
|
|
|
|
while (cursor < end);
|
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
STARTUPINFOW si;
|
2004-03-08 09:56:16 +00:00
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
::ZeroMemory(&si, sizeof(STARTUPINFOW));
|
2004-03-08 09:56:16 +00:00
|
|
|
::ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
|
|
|
|
|
2013-08-21 16:13:50 +00:00
|
|
|
BOOL success = ::CreateProcessW(nullptr, (LPWSTR)path.get(), nullptr,
|
|
|
|
nullptr, FALSE, 0, nullptr, nullptr,
|
2007-07-24 02:27:30 +00:00
|
|
|
&si, &pi);
|
2004-03-08 09:56:16 +00:00
|
|
|
if (!success)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsWindowsShellService::GetDesktopBackgroundColor(uint32_t* aColor)
|
2004-03-08 09:56:16 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t color = ::GetSysColor(COLOR_DESKTOP);
|
2004-03-08 09:56:16 +00:00
|
|
|
*aColor = (GetRValue(color) << 16) | (GetGValue(color) << 8) | GetBValue(color);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsWindowsShellService::SetDesktopBackgroundColor(uint32_t aColor)
|
2004-03-08 09:56:16 +00:00
|
|
|
{
|
|
|
|
int aParameters[2] = { COLOR_BACKGROUND, COLOR_DESKTOP };
|
|
|
|
BYTE r = (aColor >> 16);
|
|
|
|
BYTE g = (aColor << 16) >> 24;
|
|
|
|
BYTE b = (aColor << 24) >> 24;
|
|
|
|
COLORREF colors[2] = { RGB(r,g,b), RGB(r,g,b) };
|
|
|
|
|
|
|
|
::SetSysColors(sizeof(aParameters) / sizeof(int), aParameters, colors);
|
|
|
|
|
2012-01-19 19:44:27 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWindowsRegKey> regKey =
|
|
|
|
do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = regKey->Create(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_LITERAL_STRING("Control Panel\\Colors"),
|
|
|
|
nsIWindowsRegKey::ACCESS_SET_VALUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-12-03 15:09:50 +00:00
|
|
|
wchar_t rgb[12];
|
2012-01-19 19:44:27 +00:00
|
|
|
_snwprintf(rgb, 12, L"%u %u %u", r, g, b);
|
|
|
|
|
|
|
|
rv = regKey->WriteStringValue(NS_LITERAL_STRING("Background"),
|
|
|
|
nsDependentString(rgb));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return regKey->Close();
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
|
2012-05-28 02:40:48 +00:00
|
|
|
nsWindowsShellService::nsWindowsShellService() :
|
|
|
|
mCheckedThisSession(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindowsShellService::~nsWindowsShellService()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-06-27 22:38:55 +00:00
|
|
|
NS_IMETHODIMP
|
2012-06-06 02:08:30 +00:00
|
|
|
nsWindowsShellService::OpenApplicationWithURI(nsIFile* aApplication,
|
2007-07-24 02:27:30 +00:00
|
|
|
const nsACString& aURI)
|
2006-06-27 22:38:55 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIProcess> process =
|
|
|
|
do_CreateInstance("@mozilla.org/process/util;1", &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
rv = process->Init(aApplication);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2006-11-13 17:53:01 +00:00
|
|
|
const nsCString spec(aURI);
|
2006-06-27 22:38:55 +00:00
|
|
|
const char* specStr = spec.get();
|
2011-10-17 14:59:28 +00:00
|
|
|
return process->Run(false, &specStr, 1);
|
2006-06-27 22:38:55 +00:00
|
|
|
}
|
|
|
|
|
2006-12-20 22:34:51 +00:00
|
|
|
NS_IMETHODIMP
|
2012-06-06 02:08:30 +00:00
|
|
|
nsWindowsShellService::GetDefaultFeedReader(nsIFile** _retval)
|
2006-12-20 22:34:51 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2006-12-20 22:34:51 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWindowsRegKey> regKey =
|
|
|
|
do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
|
|
|
|
NS_LITERAL_STRING("feed\\shell\\open\\command"),
|
|
|
|
nsIWindowsRegKey::ACCESS_READ);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString path;
|
|
|
|
rv = regKey->ReadStringValue(EmptyString(), path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (path.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (path.First() == '"') {
|
|
|
|
// Everything inside the quotes
|
|
|
|
path = Substring(path, 1, path.FindChar('"', 1) - 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Everything up to the first space
|
|
|
|
path = Substring(path, 0, path.FindChar(' '));
|
|
|
|
}
|
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> defaultReader =
|
2006-12-20 22:34:51 +00:00
|
|
|
do_CreateInstance("@mozilla.org/file/local;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = defaultReader->InitWithPath(path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool exists;
|
2006-12-20 22:34:51 +00:00
|
|
|
rv = defaultReader->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!exists)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ADDREF(*_retval = defaultReader);
|
|
|
|
return NS_OK;
|
|
|
|
}
|