protect against obj-c exceptions in uriloader. b=419390 r/sr=roc

This commit is contained in:
joshmoz@gmail.com 2008-03-04 00:14:47 -08:00
Родитель bec89326a0
Коммит 8d27660432
5 изменённых файлов: 86 добавлений и 14 удалений

Просмотреть файл

@ -34,8 +34,9 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsInternetConfig.h"
#include "nsObjCExceptions.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsDebug.h"
@ -49,6 +50,8 @@ PRInt32 nsInternetConfig::sRefCount = 0;
static OSType GetAppCreatorCode()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
ProcessSerialNumber psn = { 0, kCurrentProcess } ;
ProcessInfoRec procInfo;
@ -57,13 +60,17 @@ static OSType GetAppCreatorCode()
procInfo.processAppSpec = nsnull;
GetProcessInformation(&psn, &procInfo);
return procInfo.processSignature;
return procInfo.processSignature;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0x0);
}
ICInstance nsInternetConfig::GetInstance()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if ( !sInstance )
{
OSStatus err;
@ -83,10 +90,14 @@ ICInstance nsInternetConfig::GetInstance()
}
}
return sInstance;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NULL);
}
PRBool nsInternetConfig::HasSeedChanged()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
ICInstance instance = nsInternetConfig::GetInstance();
if ( instance )
{
@ -99,6 +110,8 @@ PRBool nsInternetConfig::HasSeedChanged()
}
}
return PR_FALSE;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(PR_FALSE);
}
nsInternetConfig::nsInternetConfig()
@ -108,11 +121,15 @@ nsInternetConfig::nsInternetConfig()
nsInternetConfig::~nsInternetConfig()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
sRefCount--;
if ( sRefCount == 0 && sInstance)
{
::ICStop( sInstance );
sInstance = NULL;
}
NS_OBJC_END_TRY_ABORT_BLOCK;
}

Просмотреть файл

@ -37,6 +37,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsInternetConfigService.h"
#include "nsObjCExceptions.h"
#include "nsCOMPtr.h"
#include "nsIMIMEInfo.h"
#include "nsMIMEInfoMac.h"
@ -50,13 +51,8 @@
#include "nsCRT.h"
#include "nsILocalFileMac.h"
#include "nsMimeTypes.h"
#include <TextUtils.h>
#include <CodeFragments.h>
#include <Processes.h>
#include <Gestalt.h>
#include <CFURL.h>
#include <Finder.h>
#include <LaunchServices.h>
#import <Carbon/Carbon.h>
// helper converter function.....
@ -96,6 +92,8 @@ NS_IMPL_ISUPPORTS1(nsInternetConfigService, nsIInternetConfigService)
// Under OS X use LaunchServices instead of IC
NS_IMETHODIMP nsInternetConfigService::LaunchURL(const char *url)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsresult rv = NS_ERROR_FAILURE;
CFURLRef myURLRef = ::CFURLCreateWithBytes(
@ -110,12 +108,16 @@ NS_IMETHODIMP nsInternetConfigService::LaunchURL(const char *url)
}
return rv;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
// boolean HasMappingForMIMEType (in string mimetype);
// given a mime type, search Internet Config database for a mapping for that mime type
NS_IMETHODIMP nsInternetConfigService::HasMappingForMIMEType(const char *mimetype, PRBool *_retval)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
ICMapEntry entry;
nsresult rv = GetMappingForMIMEType(mimetype, nsnull, &entry);
if (rv == noErr)
@ -123,6 +125,8 @@ NS_IMETHODIMP nsInternetConfigService::HasMappingForMIMEType(const char *mimetyp
else
*_retval = PR_FALSE;
return rv;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
/* boolean hasProtocolHandler (in string protocol); */
@ -130,6 +134,8 @@ NS_IMETHODIMP nsInternetConfigService::HasMappingForMIMEType(const char *mimetyp
// as the protocol handler for the given protocol
NS_IMETHODIMP nsInternetConfigService::HasProtocolHandler(const char *protocol, PRBool *_retval)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
*_retval = PR_FALSE; // presume the OS doesn't have a handler
nsresult rv = NS_OK;
@ -171,12 +177,16 @@ NS_IMETHODIMP nsInternetConfigService::HasProtocolHandler(const char *protocol,
}
return rv;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
// This method does the dirty work of traipsing through IC mappings database
// looking for a mapping for mimetype
nsresult nsInternetConfigService::GetMappingForMIMEType(const char *mimetype, const char *fileextension, ICMapEntry *entry)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
ICInstance inst = nsInternetConfig::GetInstance();
OSStatus err = noErr;
ICAttr attr;
@ -273,6 +283,8 @@ nsresult nsInternetConfigService::GetMappingForMIMEType(const char *mimetype, co
return NS_ERROR_FAILURE;
else
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsresult nsInternetConfigService::FillMIMEInfoForICEntry(ICMapEntry& entry, nsIMIMEInfo ** mimeinfo)
@ -371,6 +383,8 @@ NS_IMETHODIMP nsInternetConfigService::FillInMIMEInfo(const char *mimetype, cons
NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromExtension(const char *aFileExt, nsIMIMEInfo **_retval)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsresult rv = NS_ERROR_FAILURE;
ICInstance instance = nsInternetConfig::GetInstance();
if (instance)
@ -387,11 +401,15 @@ NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromExtension(const char *aFil
}
}
return rv;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromTypeCreator(PRUint32 aType, PRUint32 aCreator, const char *aFileExt, nsIMIMEInfo **_retval)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsresult rv = NS_ERROR_FAILURE;
ICInstance instance = nsInternetConfig::GetInstance();
if (instance)
@ -406,11 +424,15 @@ NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromTypeCreator(PRUint32 aType
rv = FillMIMEInfoForICEntry(entry,_retval);
}
return rv;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
NS_IMETHODIMP nsInternetConfigService::GetFileMappingFlags(FSSpec* fsspec, PRBool lookupByExtensionFirst, PRInt32 *_retval)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsresult rv = NS_ERROR_FAILURE;
OSStatus err = noErr;
@ -439,12 +461,16 @@ NS_IMETHODIMP nsInternetConfigService::GetFileMappingFlags(FSSpec* fsspec, PRBoo
rv = NS_OK;
}
return rv;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
/* void GetDownloadFolder (out FSSpec fsspec); */
NS_IMETHODIMP nsInternetConfigService::GetDownloadFolder(FSSpec *fsspec)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
ICInstance inst = nsInternetConfig::GetInstance();
OSStatus err;
Handle prefH;
@ -493,6 +519,8 @@ NS_IMETHODIMP nsInternetConfigService::GetDownloadFolder(FSSpec *fsspec)
}
}
return rv;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsresult nsInternetConfigService::GetICKeyPascalString(PRUint32 inIndex, const unsigned char*& outICKey)
@ -568,6 +596,8 @@ nsresult nsInternetConfigService::GetICKeyPascalString(PRUint32 inIndex, const u
nsresult nsInternetConfigService::GetICPreference(PRUint32 inKey,
void *outData, long *ioSize)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
const unsigned char *icKey;
nsresult rv = GetICKeyPascalString(inKey, icKey);
if (rv == NS_OK)
@ -585,6 +615,8 @@ nsresult nsInternetConfigService::GetICPreference(PRUint32 inKey,
rv = NS_ERROR_FAILURE;
}
return rv;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}

Просмотреть файл

@ -35,8 +35,9 @@
*
* ***** END LICENSE BLOCK ***** */
#include <LaunchServices.h>
#import <Carbon/Carbon.h>
#include "nsObjCExceptions.h"
#include "nsLocalHandlerAppMac.h"
#include "nsILocalFileMac.h"
#include "nsIURI.h"
@ -50,6 +51,8 @@ NS_IMETHODIMP
nsLocalHandlerAppMac::LaunchWithURI(nsIURI *aURI,
nsIInterfaceRequestor *aWindowContext)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsresult rv;
nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(mExecutable, &rv));
NS_ENSURE_SUCCESS(rv, rv);
@ -92,4 +95,6 @@ nsLocalHandlerAppMac::LaunchWithURI(nsIURI *aURI,
::CFRelease(appURL);
return err != noErr ? NS_ERROR_FAILURE : NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}

Просмотреть файл

@ -40,8 +40,9 @@
*
* ***** END LICENSE BLOCK ***** */
#include <LaunchServices.h>
#import <Carbon/Carbon.h>
#include "nsObjCExceptions.h"
#include "nsMIMEInfoMac.h"
#include "nsILocalFileMac.h"
#include "nsIFileURL.h"
@ -50,6 +51,8 @@
NS_IMETHODIMP
nsMIMEInfoMac::LaunchWithFile(nsIFile *aFile)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsCOMPtr<nsIFile> application;
nsresult rv;
@ -97,7 +100,9 @@ nsMIMEInfoMac::LaunchWithFile(nsIFile *aFile)
}
}
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aFile);
return app->LaunchWithDoc(localFile, PR_FALSE);
return app->LaunchWithDoc(localFile, PR_FALSE);
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsresult

Просмотреть файл

@ -40,6 +40,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsOSHelperAppService.h"
#include "nsObjCExceptions.h"
#include "nsISupports.h"
#include "nsString.h"
#include "nsTArray.h"
@ -53,10 +54,10 @@
#include "nsMemory.h"
#include "nsCRT.h"
#include "nsMIMEInfoMac.h"
#include "nsIInternetConfigService.h"
#include "nsEmbedCID.h"
#include <LaunchServices.h>
#import <Carbon/Carbon.h>
// chrome URL's
#define HELPERAPPLAUNCHER_BUNDLE_URL "chrome://global/locale/helperAppLauncher.properties"
@ -105,6 +106,8 @@ nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolSch
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsresult rv = NS_ERROR_NOT_AVAILABLE;
CFStringRef schemeCFString =
@ -146,10 +149,14 @@ NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString&
}
return rv;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * aPlatformAppPath, nsIFile ** aFile)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsresult rv;
nsCOMPtr<nsILocalFileMac> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv,rv);
@ -200,6 +207,8 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * aPlatformAp
NS_IF_ADDREF(*aFile);
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
///////////////////////////
// method overrides --> use internet config information for mime type lookup.
@ -221,6 +230,8 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
const nsACString& aFileExt,
PRBool * aFound)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSNULL;
nsIMIMEInfo* mimeInfo = nsnull;
*aFound = PR_TRUE;
@ -316,6 +327,8 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
}
return mimeInfo;
NS_OBJC_END_TRY_ABORT_BLOCK_NSNULL;
}
NS_IMETHODIMP