2004-03-08 09:56:16 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Shell Service.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is mozilla.org.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2005-06-23 02:25:06 +00:00
|
|
|
* Ben Goodger <ben@mozilla.org> (Clients, Mail, New Default Browser)
|
|
|
|
* Joe Hewitt <hewitt@netscape.com> (Set Background)
|
2007-07-24 02:27:30 +00:00
|
|
|
* Blake Ross <blake@cs.stanford.edu> (Desktop Color, DDE support)
|
2005-06-23 02:25:06 +00:00
|
|
|
* Jungshik Shin <jshin@mailaps.org> (I18N)
|
2007-09-29 09:48:32 +00:00
|
|
|
* Robert Strong <robert.bugzilla@gmail.com>
|
2006-12-20 22:34:51 +00:00
|
|
|
* Asaf Romano <mano@mozilla.com>
|
2007-07-24 02:27:30 +00:00
|
|
|
* Ryan Jones <sciguyryan@gmail.com>
|
2004-03-08 09:56:16 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "gfxIImageFrame.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#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"
|
|
|
|
#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"
|
2004-07-22 22:12:13 +00:00
|
|
|
|
2007-01-30 05:14:50 +00:00
|
|
|
#include "windows.h"
|
|
|
|
#include "shellapi.h"
|
2007-07-24 02:27:30 +00:00
|
|
|
#include "shlobj.h"
|
2007-01-30 05:14:50 +00:00
|
|
|
|
2004-07-22 22:12:13 +00:00
|
|
|
#include <mbstring.h>
|
|
|
|
|
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)
|
|
|
|
|
2006-09-22 14:40:55 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(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
|
2007-07-11 05:59:56 +00:00
|
|
|
// shell\open\command (default) REG_SZ <apppath> -requestPending -osint -url "%1"
|
2007-01-30 05:14:50 +00:00
|
|
|
// shell\open\ddeexec (default) REG_SZ "%1",,0,0,,,,
|
|
|
|
// shell\open\ddeexec NoActivateHandler REG_SZ
|
|
|
|
// \Application (default) REG_SZ Firefox
|
|
|
|
// \Topic (default) REG_SZ WWW_OpenURL
|
|
|
|
//
|
|
|
|
// - Windows Vista Protocol Handler
|
|
|
|
//
|
|
|
|
// 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
|
2007-07-11 05:59:56 +00:00
|
|
|
// shell\open\command (default) REG_SZ <apppath> -requestPending -osint -url "%1"
|
2007-01-30 05:14:50 +00:00
|
|
|
// shell\open\ddeexec (default) REG_SZ "%1",,0,0,,,,
|
|
|
|
// shell\open\ddeexec NoActivateHandler REG_SZ
|
|
|
|
// \Application (default) REG_SZ Firefox
|
|
|
|
// \Topic (default) REG_SZ WWW_OpenURL
|
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
|
2007-07-11 05:59:56 +00:00
|
|
|
// shell\open\command (default) REG_SZ <apppath> -requestPending -osint -url "%1"
|
2007-01-30 05:14:50 +00:00
|
|
|
// shell\open\ddeexec (default) REG_SZ "%1",,0,0,,,,
|
|
|
|
// shell\open\ddeexec NoActivateHandler REG_SZ
|
|
|
|
// \Application (default) REG_SZ Firefox
|
|
|
|
// \Topic (default) REG_SZ WWW_OpenURL
|
2004-03-08 09:56:16 +00:00
|
|
|
//
|
2007-01-30 05:14:50 +00:00
|
|
|
// - Windows Start Menu (Win2K SP2, XP SP1, and newer)
|
|
|
|
// -------------------------------------------------
|
|
|
|
// 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
|
|
|
//
|
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
typedef enum {
|
|
|
|
NO_SUBSTITUTION = 0x00,
|
|
|
|
APP_PATH_SUBSTITUTION = 0x01,
|
2007-11-26 19:56:52 +00:00
|
|
|
EXE_NAME_SUBSTITUTION = 0x02
|
2007-07-24 02:27:30 +00:00
|
|
|
} SettingFlags;
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
typedef struct {
|
|
|
|
char* keyName;
|
|
|
|
char* valueName;
|
|
|
|
char* valueData;
|
|
|
|
|
|
|
|
PRInt32 flags;
|
|
|
|
} SETTING;
|
|
|
|
|
2007-01-30 05:14:50 +00:00
|
|
|
#define APP_REG_NAME L"Firefox"
|
2004-03-08 09:56:16 +00:00
|
|
|
#define DI "\\DefaultIcon"
|
|
|
|
#define SOP "\\shell\\open\\command"
|
|
|
|
|
|
|
|
#define CLS_HTML "FirefoxHTML"
|
2007-01-30 05:14:50 +00:00
|
|
|
#define CLS_URL "FirefoxURL"
|
2006-09-19 18:09:58 +00:00
|
|
|
#define VAL_FILE_ICON "%APPPATH%,1"
|
2007-07-11 05:59:56 +00:00
|
|
|
#define VAL_OPEN "\"%APPPATH%\" -requestPending -osint -url \"%1\""
|
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
|
|
|
|
// Firefox is the default browser since other applications (e.g. MS Office) may
|
|
|
|
// modify the DefaultIcon registry key value to add Icon Handlers.
|
2007-03-23 21:32:30 +00:00
|
|
|
// see http://msdn2.microsoft.com/en-us/library/aa969357.aspx for more info.
|
2004-03-08 09:56:16 +00:00
|
|
|
static SETTING gSettings[] = {
|
2007-03-23 21:32:30 +00:00
|
|
|
// File Extension Class - as of 1.8.1.2 the value for VAL_OPEN is also checked
|
|
|
|
// for CLS_HTML since Firefox should also own opeing local files when set as
|
|
|
|
// the default browser.
|
2007-09-29 09:48:32 +00:00
|
|
|
{ MAKE_KEY_NAME1(CLS_HTML, SOP), "", VAL_OPEN, APP_PATH_SUBSTITUTION },
|
2007-01-30 05:14:50 +00:00
|
|
|
|
|
|
|
// Protocol Handler Class - for Vista and above
|
2007-09-29 09:48:32 +00:00
|
|
|
{ MAKE_KEY_NAME1(CLS_URL, SOP), "", VAL_OPEN, APP_PATH_SUBSTITUTION },
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
// Protocol Handlers
|
2007-09-29 09:48:32 +00:00
|
|
|
{ MAKE_KEY_NAME1("HTTP", DI), "", VAL_FILE_ICON, APP_PATH_SUBSTITUTION },
|
|
|
|
{ MAKE_KEY_NAME1("HTTP", SOP), "", VAL_OPEN, APP_PATH_SUBSTITUTION },
|
|
|
|
{ MAKE_KEY_NAME1("HTTPS", DI), "", VAL_FILE_ICON, APP_PATH_SUBSTITUTION },
|
|
|
|
{ MAKE_KEY_NAME1("HTTPS", SOP), "", VAL_OPEN, APP_PATH_SUBSTITUTION }
|
2004-03-08 09:56:16 +00:00
|
|
|
};
|
|
|
|
|
2006-09-22 14:45:57 +00:00
|
|
|
|
2006-09-27 17:58:26 +00:00
|
|
|
// Support for versions of shlobj.h that don't include the Vista API's
|
|
|
|
#if !defined(IApplicationAssociationRegistration)
|
2006-09-22 14:45:57 +00:00
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
typedef enum tagASSOCIATIONLEVEL {
|
2006-09-22 14:45:57 +00:00
|
|
|
AL_MACHINE,
|
|
|
|
AL_EFFECTIVE,
|
|
|
|
AL_USER
|
|
|
|
} ASSOCIATIONLEVEL;
|
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
typedef enum tagASSOCIATIONTYPE {
|
2006-09-22 14:45:57 +00:00
|
|
|
AT_FILEEXTENSION,
|
|
|
|
AT_URLPROTOCOL,
|
|
|
|
AT_STARTMENUCLIENT,
|
|
|
|
AT_MIMETYPE
|
|
|
|
} ASSOCIATIONTYPE;
|
|
|
|
|
|
|
|
MIDL_INTERFACE("4e530b0a-e611-4c77-a3ac-9031d022281b")
|
|
|
|
IApplicationAssociationRegistration : public IUnknown
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE QueryCurrentDefault(LPCWSTR pszQuery,
|
|
|
|
ASSOCIATIONTYPE atQueryType,
|
|
|
|
ASSOCIATIONLEVEL alQueryLevel,
|
|
|
|
LPWSTR *ppszAssociation) = 0;
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE QueryAppIsDefault(LPCWSTR pszQuery,
|
|
|
|
ASSOCIATIONTYPE atQueryType,
|
|
|
|
ASSOCIATIONLEVEL alQueryLevel,
|
|
|
|
LPCWSTR pszAppRegistryName,
|
|
|
|
BOOL *pfDefault) = 0;
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE QueryAppIsDefaultAll(ASSOCIATIONLEVEL alQueryLevel,
|
|
|
|
LPCWSTR pszAppRegistryName,
|
|
|
|
BOOL *pfDefault) = 0;
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE SetAppAsDefault(LPCWSTR pszAppRegistryName,
|
|
|
|
LPCWSTR pszSet,
|
|
|
|
ASSOCIATIONTYPE atSetType) = 0;
|
|
|
|
virtual HRESULT STDMETHODCALLTYPE SetAppAsDefaultAll(LPCWSTR pszAppRegistryName) = 0;
|
2007-07-24 02:27:30 +00:00
|
|
|
virtual HRESULT STDMETHODCALLTYPE ClearUserAssociations(void) = 0;
|
2006-09-22 14:45:57 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const CLSID CLSID_ApplicationAssociationReg = {0x591209C7,0x767B,0x42B2,{0x9F,0xBA,0x44,0xEE,0x46,0x15,0xF2,0xC7}};
|
|
|
|
static const IID IID_IApplicationAssociationReg = {0x4e530b0a,0xe611,0x4c77,{0xa3,0xac,0x90,0x31,0xd0,0x22,0x28,0x1b}};
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsWindowsShellService::IsDefaultBrowserVista(PRBool aStartupCheck, PRBool* aIsDefaultBrowser)
|
|
|
|
{
|
|
|
|
IApplicationAssociationRegistration* pAAR;
|
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationReg,
|
|
|
|
NULL,
|
|
|
|
CLSCTX_INPROC,
|
|
|
|
IID_IApplicationAssociationReg,
|
|
|
|
(void**)&pAAR);
|
2006-09-22 14:45:57 +00:00
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
if (SUCCEEDED(hr)) {
|
2006-09-22 14:45:57 +00:00
|
|
|
hr = pAAR->QueryAppIsDefaultAll(AL_EFFECTIVE,
|
|
|
|
APP_REG_NAME,
|
|
|
|
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 = PR_TRUE;
|
|
|
|
|
|
|
|
pAAR->Release();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
NS_IMETHODIMP
|
2007-07-24 02:27:30 +00:00
|
|
|
nsWindowsShellService::IsDefaultBrowser(PRBool aStartupCheck,
|
|
|
|
PRBool* 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
|
|
|
|
// checked this session (so that subsequent window opens don't show the
|
|
|
|
// default browser dialog).
|
|
|
|
if (aStartupCheck)
|
|
|
|
mCheckedThisSession = PR_TRUE;
|
2006-09-22 14:45:57 +00:00
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
SETTING* settings;
|
|
|
|
SETTING* end = gSettings + sizeof(gSettings)/sizeof(SETTING);
|
|
|
|
|
|
|
|
*aIsDefaultBrowser = PR_TRUE;
|
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
PRUnichar exePath[MAX_BUF];
|
|
|
|
if (!::GetModuleFileNameW(0, exePath, MAX_BUF))
|
2006-10-10 19:56:08 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
nsAutoString appLongPath(exePath);
|
2006-10-10 19:56:08 +00:00
|
|
|
|
|
|
|
// Support short path to the exe so if it is already set the user is not
|
|
|
|
// prompted to set the default browser again.
|
2007-07-24 02:27:30 +00:00
|
|
|
if (!::GetShortPathNameW(exePath, exePath, sizeof(exePath)))
|
2006-10-10 19:56:08 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
nsAutoString appShortPath(exePath);
|
|
|
|
ToUpperCase(appShortPath);
|
2006-10-10 19:56:08 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> lf;
|
2007-07-24 02:27:30 +00:00
|
|
|
nsresult rv = NS_NewLocalFile(appShortPath, PR_TRUE,
|
|
|
|
getter_AddRefs(lf));
|
2006-10-10 19:56:08 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
nsAutoString exeName;
|
|
|
|
rv = lf->GetLeafName(exeName);
|
2006-10-10 19:56:08 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
ToUpperCase(exeName);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
PRUnichar currValue[MAX_BUF];
|
2004-03-08 09:56:16 +00:00
|
|
|
for (settings = gSettings; settings < end; ++settings) {
|
2007-07-24 02:27:30 +00:00
|
|
|
NS_ConvertUTF8toUTF16 dataLongPath(settings->valueData);
|
|
|
|
NS_ConvertUTF8toUTF16 dataShortPath(settings->valueData);
|
|
|
|
NS_ConvertUTF8toUTF16 key(settings->keyName);
|
|
|
|
NS_ConvertUTF8toUTF16 value(settings->valueName);
|
2007-01-30 05:14:50 +00:00
|
|
|
if (settings->flags & APP_PATH_SUBSTITUTION) {
|
2006-10-10 19:56:08 +00:00
|
|
|
PRInt32 offset = dataLongPath.Find("%APPPATH%");
|
|
|
|
dataLongPath.Replace(offset, 9, appLongPath);
|
|
|
|
// Remove the quotes around %APPPATH% in VAL_OPEN for short paths
|
|
|
|
PRInt32 offsetQuoted = dataShortPath.Find("\"%APPPATH%\"");
|
|
|
|
if (offsetQuoted != -1)
|
|
|
|
dataShortPath.Replace(offsetQuoted, 11, appShortPath);
|
|
|
|
else
|
|
|
|
dataShortPath.Replace(offset, 9, appShortPath);
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
2007-01-30 05:14:50 +00:00
|
|
|
if (settings->flags & EXE_NAME_SUBSTITUTION) {
|
2004-03-08 09:56:16 +00:00
|
|
|
PRInt32 offset = key.Find("%APPEXE%");
|
|
|
|
key.Replace(offset, 8, exeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
::ZeroMemory(currValue, sizeof(currValue));
|
|
|
|
HKEY theKey;
|
2007-09-29 09:48:32 +00:00
|
|
|
rv = OpenKeyForReading(HKEY_CLASSES_ROOT, key, &theKey);
|
2004-06-30 20:27:30 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-03-08 09:56:16 +00:00
|
|
|
DWORD len = sizeof currValue;
|
2007-07-24 02:27:30 +00:00
|
|
|
DWORD res = ::RegQueryValueExW(theKey, PromiseFlatString(value).get(),
|
|
|
|
NULL, NULL, (LPBYTE)currValue, &len);
|
2005-01-16 21:02:13 +00:00
|
|
|
// Close the key we opened.
|
|
|
|
::RegCloseKey(theKey);
|
2007-07-24 02:27:30 +00:00
|
|
|
if (REG_FAILED(res) ||
|
2006-11-13 17:53:01 +00:00
|
|
|
!dataLongPath.Equals(currValue, CaseInsensitiveCompare) &&
|
|
|
|
!dataShortPath.Equals(currValue, CaseInsensitiveCompare)) {
|
2004-03-08 09:56:16 +00:00
|
|
|
// Key wasn't set, or was set to something else (something else became the default browser)
|
|
|
|
*aIsDefaultBrowser = PR_FALSE;
|
2007-09-29 09:48:32 +00:00
|
|
|
return NS_OK;
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-29 09:48:32 +00:00
|
|
|
// Only check if Firefox is the default browser on Vista if the previous
|
|
|
|
// checks show that Firefox is the default browser.
|
|
|
|
if (aIsDefaultBrowser)
|
|
|
|
IsDefaultBrowserVista(aStartupCheck, aIsDefaultBrowser);
|
2005-12-04 21:02:38 +00:00
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-06-30 20:27:30 +00:00
|
|
|
nsWindowsShellService::SetDefaultBrowser(PRBool aClaimAllTypes, PRBool aForAllUsers)
|
2004-03-08 09:56:16 +00:00
|
|
|
{
|
2007-09-29 09:48:32 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIProperties> directoryService =
|
|
|
|
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2007-09-29 09:48:32 +00:00
|
|
|
nsCOMPtr<nsILocalFile> appHelper;
|
|
|
|
rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(appHelper));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-06-23 02:25:06 +00:00
|
|
|
|
2007-09-29 09:48:32 +00:00
|
|
|
rv = appHelper->AppendNative(NS_LITERAL_CSTRING("uninstall"));
|
2005-06-23 02:25:06 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-09-29 09:48:32 +00:00
|
|
|
|
|
|
|
rv = appHelper->AppendNative(NS_LITERAL_CSTRING("helper.exe"));
|
2005-06-23 02:25:06 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2008-03-11 22:46:26 +00:00
|
|
|
nsCAutoString appHelperPath;
|
|
|
|
rv = appHelper->GetNativePath(appHelperPath);
|
2007-09-29 09:48:32 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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
|
|
|
|
2008-03-11 22:46:26 +00:00
|
|
|
STARTUPINFO si = {sizeof(si), 0};
|
2007-09-29 09:48:32 +00:00
|
|
|
PROCESS_INFORMATION pi = {0};
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2008-03-11 22:46:26 +00:00
|
|
|
BOOL ok = CreateProcess(NULL, (LPSTR)appHelperPath.get(), NULL, NULL,
|
2007-09-29 09:48:32 +00:00
|
|
|
FALSE, 0, NULL, NULL, &si, &pi);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
2007-09-29 09:48:32 +00:00
|
|
|
if (!ok)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-07-24 02:27:30 +00:00
|
|
|
|
2007-09-29 09:48:32 +00:00
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
2007-07-24 02:27:30 +00:00
|
|
|
|
2007-09-29 09:48:32 +00:00
|
|
|
return NS_OK;
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
|
2005-12-04 21:02:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowsShellService::GetShouldCheckDefaultBrowser(PRBool* 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 = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs;
|
|
|
|
nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
|
|
if (pserve)
|
|
|
|
pserve->GetBranch("", getter_AddRefs(prefs));
|
|
|
|
|
|
|
|
prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowsShellService::SetShouldCheckDefaultBrowser(PRBool 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;
|
|
|
|
}
|
|
|
|
|
2005-06-23 02:25:06 +00:00
|
|
|
static nsresult
|
2005-07-24 22:56:48 +00:00
|
|
|
WriteBitmap(nsIFile* aFile, gfxIImageFrame* aImage)
|
2004-03-08 09:56:16 +00:00
|
|
|
{
|
|
|
|
PRInt32 width, height;
|
|
|
|
aImage->GetWidth(&width);
|
|
|
|
aImage->GetHeight(&height);
|
|
|
|
|
|
|
|
PRUint8* bits;
|
|
|
|
PRUint32 length;
|
2006-06-26 23:53:01 +00:00
|
|
|
aImage->LockImageData();
|
2004-03-08 09:56:16 +00:00
|
|
|
aImage->GetImageData(&bits, &length);
|
2006-06-26 23:53:01 +00:00
|
|
|
if (!bits) {
|
|
|
|
aImage->UnlockImageData();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
PRUint32 bpr;
|
|
|
|
aImage->GetImageBytesPerRow(&bpr);
|
|
|
|
PRInt32 bitCount = bpr/width;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
bmi.biBitCount = (WORD)bitCount*8;
|
|
|
|
bmi.biCompression = BI_RGB;
|
|
|
|
bmi.biSizeImage = length;
|
|
|
|
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;
|
2007-07-24 02:27:30 +00:00
|
|
|
nsresult 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
|
|
|
|
|
|
|
// write the bitmap headers and rgb pixel data to the file
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
if (stream) {
|
|
|
|
PRUint32 written;
|
|
|
|
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
|
|
|
|
PRUint32 i = length;
|
|
|
|
do {
|
|
|
|
i -= bpr;
|
|
|
|
stream->Write(((const char*)bits) + i, bpr, &written);
|
|
|
|
if (written == bpr) {
|
|
|
|
rv = NS_OK;
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (i != 0);
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->Close();
|
|
|
|
}
|
|
|
|
|
2006-06-26 23:53:01 +00:00
|
|
|
aImage->UnlockImageData();
|
2004-03-08 09:56:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowsShellService::SetDesktopBackground(nsIDOMElement* aElement,
|
|
|
|
PRInt32 aPosition)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<gfxIImageFrame> gfxFrame;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(aElement));
|
|
|
|
if (!imgElement) {
|
|
|
|
// XXX write background loading stuff!
|
|
|
|
}
|
|
|
|
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
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
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
|
|
|
|
|
|
|
// get the current frame, which holds the image data
|
|
|
|
container->GetCurrentFrame(getter_AddRefs(gfxFrame));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gfxFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
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
|
|
|
|
(NS_LITERAL_STRING("desktopBackgroundLeafNameWin").get(),
|
|
|
|
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
|
|
|
|
rv = WriteBitmap(file, gfxFrame);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
// if the file was written successfully, set it as the system wallpaper
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
DWORD dwDisp = 0;
|
|
|
|
HKEY key;
|
|
|
|
// Try to create/open a subkey under HKLM.
|
2007-07-24 02:27:30 +00:00
|
|
|
DWORD res = ::RegCreateKeyExW(HKEY_CURRENT_USER,
|
|
|
|
L"Control Panel\\Desktop",
|
|
|
|
0, NULL, REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_WRITE, NULL, &key, &dwDisp);
|
|
|
|
if (REG_SUCCEEDED(res)) {
|
|
|
|
PRUnichar tile[2], style[2];
|
|
|
|
switch (aPosition) {
|
|
|
|
case BACKGROUND_TILE:
|
|
|
|
tile[0] = '1';
|
|
|
|
style[0] = '1';
|
|
|
|
break;
|
|
|
|
case BACKGROUND_CENTER:
|
|
|
|
tile[0] = '0';
|
|
|
|
style[0] = '0';
|
|
|
|
break;
|
|
|
|
case BACKGROUND_STRETCH:
|
|
|
|
tile[0] = '0';
|
|
|
|
style[0] = '2';
|
|
|
|
break;
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
tile[1] = '\0';
|
|
|
|
style[1] = '\0';
|
2007-07-24 02:27:30 +00:00
|
|
|
|
|
|
|
// The size is always 3 unicode characters.
|
|
|
|
PRInt32 size = 3 * sizeof(PRUnichar);
|
|
|
|
::RegSetValueExW(key, L"TileWallpaper",
|
|
|
|
0, REG_SZ, (const BYTE *)tile, size);
|
|
|
|
::RegSetValueExW(key, L"WallpaperStyle",
|
|
|
|
0, REG_SZ, (const BYTE *)style, size);
|
|
|
|
::SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (PVOID)path.get(),
|
|
|
|
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
|
2005-01-16 21:02:13 +00:00
|
|
|
// Close the key we opened.
|
|
|
|
::RegCloseKey(key);
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-06-23 02:25:06 +00:00
|
|
|
nsWindowsShellService::OpenApplication(PRInt32 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
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
PRUnichar 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
|
2007-09-29 09:48:32 +00:00
|
|
|
application.AppendLiteral("\\");
|
|
|
|
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);
|
2004-03-08 09:56:16 +00:00
|
|
|
PRInt32 end = path.Length();
|
|
|
|
PRInt32 cursor = 0, temp = 0;
|
|
|
|
::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));
|
|
|
|
|
2007-07-24 02:27:30 +00:00
|
|
|
BOOL success = ::CreateProcessW(NULL, (LPWSTR)path.get(), NULL,
|
|
|
|
NULL, FALSE, 0, NULL, NULL,
|
|
|
|
&si, &pi);
|
2004-03-08 09:56:16 +00:00
|
|
|
if (!success)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowsShellService::GetDesktopBackgroundColor(PRUint32* aColor)
|
|
|
|
{
|
|
|
|
PRUint32 color = ::GetSysColor(COLOR_DESKTOP);
|
|
|
|
*aColor = (GetRValue(color) << 16) | (GetGValue(color) << 8) | GetBValue(color);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowsShellService::SetDesktopBackgroundColor(PRUint32 aColor)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
DWORD dwDisp = 0;
|
|
|
|
HKEY key;
|
|
|
|
// Try to create/open a subkey under HKLM.
|
2007-07-24 02:27:30 +00:00
|
|
|
DWORD rv = ::RegCreateKeyExW(HKEY_CURRENT_USER,
|
|
|
|
L"Control Panel\\Colors", 0, NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
|
|
|
|
&key, &dwDisp);
|
|
|
|
|
|
|
|
if (REG_SUCCEEDED(rv)) {
|
|
|
|
char rgb[12];
|
2004-03-08 09:56:16 +00:00
|
|
|
sprintf((char*)rgb, "%u %u %u\0", r, g, b);
|
2007-07-24 02:27:30 +00:00
|
|
|
NS_ConvertUTF8toUTF16 backColor(rgb);
|
|
|
|
|
|
|
|
::RegSetValueExW(key, L"Background",
|
|
|
|
0, REG_SZ, (const BYTE *)backColor.get(),
|
|
|
|
(backColor.Length() + 1) * sizeof(PRUnichar));
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
2005-01-16 21:02:13 +00:00
|
|
|
|
|
|
|
// Close the key we opened.
|
|
|
|
::RegCloseKey(key);
|
2004-03-08 09:56:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowsShellService::GetUnreadMailCount(PRUint32* aCount)
|
|
|
|
{
|
|
|
|
*aCount = 0;
|
|
|
|
|
|
|
|
HKEY accountKey;
|
|
|
|
if (GetMailAccountKey(&accountKey)) {
|
|
|
|
DWORD type, unreadCount;
|
|
|
|
DWORD len = sizeof unreadCount;
|
2007-07-24 02:27:30 +00:00
|
|
|
DWORD res = ::RegQueryValueExW(accountKey, L"MessageCount", 0,
|
|
|
|
&type, (LPBYTE)&unreadCount, &len);
|
|
|
|
if (REG_SUCCEEDED(res))
|
2004-03-08 09:56:16 +00:00
|
|
|
*aCount = unreadCount;
|
2005-01-16 21:02:13 +00:00
|
|
|
|
|
|
|
// Close the key we opened.
|
|
|
|
::RegCloseKey(accountKey);
|
2004-03-08 09:56:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsWindowsShellService::GetMailAccountKey(HKEY* aResult)
|
|
|
|
{
|
2007-07-24 02:27:30 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(unread,
|
|
|
|
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\UnreadMail\\");
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
HKEY mailKey;
|
2007-07-24 02:27:30 +00:00
|
|
|
DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, unread.get(), 0,
|
|
|
|
KEY_ENUMERATE_SUB_KEYS, &mailKey);
|
2004-03-08 09:56:16 +00:00
|
|
|
|
|
|
|
PRInt32 i = 0;
|
|
|
|
do {
|
2007-07-24 02:27:30 +00:00
|
|
|
PRUnichar subkeyName[MAX_BUF];
|
2004-03-08 09:56:16 +00:00
|
|
|
DWORD len = sizeof subkeyName;
|
2007-07-24 02:27:30 +00:00
|
|
|
res = ::RegEnumKeyExW(mailKey, i++, subkeyName, &len, NULL, NULL,
|
|
|
|
NULL, NULL);
|
|
|
|
if (REG_SUCCEEDED(res)) {
|
2004-03-08 09:56:16 +00:00
|
|
|
HKEY accountKey;
|
2007-07-24 02:27:30 +00:00
|
|
|
res = ::RegOpenKeyExW(mailKey, PromiseFlatString(subkeyName).get(),
|
|
|
|
0, KEY_READ, &accountKey);
|
|
|
|
if (REG_SUCCEEDED(res)) {
|
2004-03-08 09:56:16 +00:00
|
|
|
*aResult = accountKey;
|
2006-09-22 14:45:57 +00:00
|
|
|
|
|
|
|
// Close the key we opened.
|
2005-01-16 21:02:13 +00:00
|
|
|
::RegCloseKey(mailKey);
|
|
|
|
|
2004-03-08 09:56:16 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (1);
|
|
|
|
|
2005-01-16 21:02:13 +00:00
|
|
|
// Close the key we opened.
|
|
|
|
::RegCloseKey(mailKey);
|
2004-03-08 09:56:16 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-06-27 22:38:55 +00:00
|
|
|
NS_IMETHODIMP
|
2007-07-24 02:27:30 +00:00
|
|
|
nsWindowsShellService::OpenApplicationWithURI(nsILocalFile* aApplication,
|
|
|
|
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();
|
|
|
|
PRUint32 pid;
|
|
|
|
return process->Run(PR_FALSE, &specStr, 1, &pid);
|
|
|
|
}
|
|
|
|
|
2006-12-20 22:34:51 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindowsShellService::GetDefaultFeedReader(nsILocalFile** _retval)
|
|
|
|
{
|
|
|
|
*_retval = nsnull;
|
|
|
|
|
|
|
|
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(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> defaultReader =
|
|
|
|
do_CreateInstance("@mozilla.org/file/local;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = defaultReader->InitWithPath(path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool exists;
|
|
|
|
rv = defaultReader->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!exists)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ADDREF(*_retval = defaultReader);
|
|
|
|
return NS_OK;
|
|
|
|
}
|