Re-landing #169667 - use LaunchServices APIs instead of InternetConfig APIs when appropriate (fixed mach-o and Mac Classic build issues from 1st landing try). r=ccarlen,sr=sfraser

This commit is contained in:
sdagley%netscape.com 2002-10-01 05:27:15 +00:00
Родитель 9113ce1184
Коммит a50ca5627d
8 изменённых файлов: 316 добавлений и 283 удалений

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

@ -120,30 +120,3 @@ nsInternetConfig::~nsInternetConfig()
} }
} }
nsresult nsInternetConfig::GetString( ConstStr255Param inKey, char** outString )
{
nsresult result = NS_ERROR_FAILURE;
ICInstance instance = nsInternetConfig::GetInstance();
if ( instance )
{
OSStatus err;
char buffer[256];
ICAttr junk;
long size = 256;
err = ::ICGetPref( instance, inKey, &junk, buffer, &size );
if ( err == noErr )
{
if (size == 0) {
*outString = nsnull;
return NS_OK;
}
// Buffer is a Pascal string
nsCString temp( &buffer[1], buffer[0] );
*outString = ToNewCString(temp);
result = NS_OK;
}
}
return result;
}

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

@ -47,7 +47,6 @@ class nsInternetConfig
public: public:
nsInternetConfig(); nsInternetConfig();
~nsInternetConfig(); ~nsInternetConfig();
nsresult GetString( ConstStr255Param inKey, char** outString );
static ICInstance GetInstance(); static ICInstance GetInstance();
static PRBool HasSeedChanged(); static PRBool HasSeedChanged();

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

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Steve Dagley <sdagley@netscape.com>
* *
* Alternatively, the contents of this file may be used under the terms of * 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 * either the GNU General Public License Version 2 or later (the "GPL"), or
@ -48,22 +49,28 @@
#include "nsILocalFileMac.h" #include "nsILocalFileMac.h"
#include "nsMimeTypes.h" #include "nsMimeTypes.h"
#include <TextUtils.h> #include <TextUtils.h>
#include <CodeFragments.h>
#include <Processes.h> #include <Processes.h>
#include <Gestalt.h>
#include <CFURL.h>
#include <Finder.h>
#include <LaunchServices.h>
// helper converter function..... // helper converter function.....
static void ConvertCharStringToStr255( const char* inString, Str255& outString ) static void ConvertCharStringToStr255(const char* inString, Str255& outString)
{ {
if ( inString == NULL ) if (inString == NULL)
return; return;
PRInt32 len = strlen(inString);
NS_ASSERTION( len<= 255 , " String is too big"); PRInt32 len = strlen(inString);
if ( len> 255 ) NS_ASSERTION(len <= 255 , " String is too big");
{ if (len> 255)
len = 255; {
len = 255;
} }
memcpy(&outString[1], inString, len); memcpy(&outString[1], inString, len);
outString[0] = len; outString[0] = len;
} }
/* Define Class IDs */ /* Define Class IDs */
@ -72,6 +79,11 @@ static NS_DEFINE_CID(kICServiceCID, NS_INTERNETCONFIGSERVICE_CID);
nsInternetConfigService::nsInternetConfigService() nsInternetConfigService::nsInternetConfigService()
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
long version;
OSErr err;
mRunningOSX = ((err = ::Gestalt(gestaltSystemVersion, &version)) == noErr && version >= 0x00001000);
mRunningJaguar = (err == noErr && version >= 0x00001200);
} }
nsInternetConfigService::~nsInternetConfigService() nsInternetConfigService::~nsInternetConfigService()
@ -82,35 +94,43 @@ nsInternetConfigService::~nsInternetConfigService()
/* /*
* Implement the nsISupports methods... * Implement the nsISupports methods...
*/ */
NS_IMPL_THREADSAFE_ADDREF(nsInternetConfigService) NS_IMPL_ISUPPORTS1(nsInternetConfigService, nsIInternetConfigService)
NS_IMPL_THREADSAFE_RELEASE(nsInternetConfigService)
NS_INTERFACE_MAP_BEGIN(nsInternetConfigService)
NS_INTERFACE_MAP_ENTRY(nsIInternetConfigService)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIInternetConfigService)
NS_INTERFACE_MAP_END_THREADSAFE
// void LaunchURL (in string url); // void LaunchURL (in string url);
// given a url string, call ICLaunchURL using url // Given a url string, call ICLaunchURL using url
// Under OS X use LaunchServices instead of IC
NS_IMETHODIMP nsInternetConfigService::LaunchURL(const char *url) NS_IMETHODIMP nsInternetConfigService::LaunchURL(const char *url)
{ {
nsresult result; nsresult rv = NS_ERROR_FAILURE;
size_t len = strlen(url);
long selStart = 0, selEnd = len;
ICInstance inst = nsInternetConfig::GetInstance();
if (inst) #if TARGET_CARBON
if (mRunningOSX && ((UInt32)LSOpenCFURLRef != (UInt32)kUnresolvedCFragSymbolAddress))
{ {
result = ::ICLaunchURL(inst, "\p", (Ptr)url, (long)len, &selStart, &selEnd); CFURLRef myURLRef = ::CFURLCreateWithBytes(
if (result == noErr) kCFAllocatorDefault,
return NS_OK; (const UInt8*)url,
else strlen(url),
return NS_ERROR_FAILURE; kCFStringEncodingUTF8, NULL);
if (myURLRef)
{
rv = ::LSOpenCFURLRef(myURLRef, NULL);
::CFRelease(myURLRef);
}
} }
else else
#endif
{ {
return NS_ERROR_FAILURE; size_t len = strlen(url);
long selStart = 0, selEnd = len;
ICInstance inst = nsInternetConfig::GetInstance();
if (inst)
{
if (::ICLaunchURL(inst, "\p", (Ptr)url, (long)len, &selStart, &selEnd) == noErr)
rv = NS_OK;
}
} }
return rv;
} }
// boolean HasMappingForMIMEType (in string mimetype); // boolean HasMappingForMIMEType (in string mimetype);
@ -131,65 +151,119 @@ NS_IMETHODIMP nsInternetConfigService::HasMappingForMIMEType(const char *mimetyp
// protocol handler for protocol // protocol handler for protocol
NS_IMETHODIMP nsInternetConfigService::HasProtocolHandler(const char *protocol, PRBool *_retval) NS_IMETHODIMP nsInternetConfigService::HasProtocolHandler(const char *protocol, PRBool *_retval)
{ {
*_retval = PR_FALSE; *_retval = PR_FALSE; // Presume failure
// look for IC pref "\pHelper¥<protocol>" nsresult rv = NS_ERROR_FAILURE; // Ditto
Str255 pref = kICHelper;
if (strlen(protocol) > 248)
return NS_ERROR_OUT_OF_MEMORY;
memcpy(pref + pref[0] + 1, protocol, strlen(protocol));
pref[0] = pref[0] + strlen(protocol);
ICInstance instance = nsInternetConfig::GetInstance(); #if TARGET_CARBON
if ( !instance ) // Use LaunchServices directly when we're running under OS X to avoid the problem of some protocols
return NS_ERROR_FAILURE; // apparently not being reflected into the IC mappings (webcal for one). Even better it seems
// LaunchServices under 10.1.x will often fail to find an app when using LSGetApplicationForURL
OSStatus err; // so we only use it for 10.2 or later.
ICAttr junk;
ICAppSpec spec; // Since protocol comes in with _just_ the protocol we have to add a ':' to the end of it or
long ioSize = sizeof(ICAppSpec); // LaunchServices will be very unhappy with the CFURLRef created from it (crashes trying to look
err = ::ICGetPref( instance, pref, &junk, (void *)&spec, &ioSize ); // up a handler for it with LSGetApplicationForURL, at least under 10.2.1)
if ( err != noErr ) if (mRunningJaguar)
return NS_ERROR_FAILURE;
// check if registered protocol helper is us
// if so, return PR_FALSE because we'll go into infinite recursion
// continually launching back into ourselves
ProcessSerialNumber psn;
OSErr oserr = ::GetCurrentProcess(&psn);
if (oserr == noErr)
{ {
ProcessInfoRec info; nsCAutoString scheme(protocol);
info.processInfoLength = sizeof(ProcessInfoRec); scheme += ":";
info.processName = nsnull; CFURLRef myURLRef = ::CFURLCreateWithBytes(
info.processAppSpec = nsnull; kCFAllocatorDefault,
err = ::GetProcessInformation(&psn, &info); (const UInt8 *)scheme.get(),
if (err == noErr) scheme.Length(),
kCFStringEncodingUTF8, NULL);
if (myURLRef)
{ {
if (info.processSignature != spec.fCreator) FSRef appFSRef;
*_retval = PR_TRUE;
else if (::LSGetApplicationForURL(myURLRef, kLSRolesAll, &appFSRef, NULL) == noErr)
return NS_ERROR_NOT_AVAILABLE; { // Now see if the FSRef for the found app == the running app
ProcessSerialNumber psn;
if (::GetCurrentProcess(&psn) == noErr)
{
FSRef runningAppFSRef;
if (::GetProcessBundleLocation(&psn, &runningAppFSRef) == noErr)
{
if (::FSCompareFSRefs(&appFSRef, &runningAppFSRef) == noErr)
{ // Oops, the current app is the handler which would cause infinite recursion
rv = NS_ERROR_NOT_AVAILABLE;
}
else
{
*_retval = PR_TRUE;
rv = NS_OK;
}
}
}
}
::CFRelease(myURLRef);
} }
else
return NS_ERROR_FAILURE;
} }
else else
return NS_ERROR_FAILURE; #endif
{
// look for IC pref "\pHelper¥<protocol>"
Str255 pref = kICHelper;
return NS_OK; if (nsCRT::strlen(protocol) > 248)
rv = NS_ERROR_OUT_OF_MEMORY;
else
{
memcpy(pref + pref[0] + 1, protocol, nsCRT::strlen(protocol));
pref[0] = pref[0] + nsCRT::strlen(protocol);
ICInstance instance = nsInternetConfig::GetInstance();
if (instance)
{
OSStatus err;
ICAttr junk;
ICAppSpec spec;
long ioSize = sizeof(ICAppSpec);
err = ::ICGetPref(instance, pref, &junk, (void *)&spec, &ioSize);
if (err == noErr)
{
// check if registered protocol helper is us
// if so, return PR_FALSE because we'll go into infinite recursion
// continually launching back into ourselves
ProcessSerialNumber psn;
OSErr oserr = ::GetCurrentProcess(&psn);
if (oserr == noErr)
{
ProcessInfoRec info;
info.processInfoLength = sizeof(ProcessInfoRec);
info.processName = nsnull;
info.processAppSpec = nsnull;
err = ::GetProcessInformation(&psn, &info);
if (err == noErr)
{
if (info.processSignature != spec.fCreator)
{
*_retval = PR_TRUE;
rv = NS_OK;
}
else
rv = NS_ERROR_NOT_AVAILABLE;
}
}
}
}
}
}
return rv;
} }
// This method does the dirty work of traipsing through IC mappings database // This method does the dirty work of traipsing through IC mappings database
// looking for a mapping for mimetype // looking for a mapping for mimetype
nsresult nsInternetConfigService::GetMappingForMIMEType(const char *mimetype, const char *fileextension, ICMapEntry *entry) nsresult nsInternetConfigService::GetMappingForMIMEType(const char *mimetype, const char *fileextension, ICMapEntry *entry)
{ {
ICInstance inst = nsInternetConfig::GetInstance(); ICInstance inst = nsInternetConfig::GetInstance();
OSStatus err = noErr; OSStatus err = noErr;
ICAttr attr; ICAttr attr;
Handle prefH; Handle prefH;
PRBool domimecheck = PR_TRUE, gotmatch = PR_FALSE; PRBool domimecheck = PR_TRUE;
ICMapEntry ent; PRBool gotmatch = PR_FALSE;
ICMapEntry ent;
// if mime type is "unknown" or "octet stream" *AND* we have a file extension, // if mime type is "unknown" or "octet stream" *AND* we have a file extension,
// then disable match on mime type // then disable match on mime type
@ -215,7 +289,7 @@ nsresult nsInternetConfigService::GetMappingForMIMEType(const char *mimetype, co
if (err == noErr) if (err == noErr)
{ {
long pos; long pos;
for(long i = 1; i <= count; i++) for (long i = 1; i <= count; ++i)
{ {
err = ::ICGetIndMapEntry(inst, prefH, i, &pos, &ent); err = ::ICGetIndMapEntry(inst, prefH, i, &pos, &ent);
if (err == noErr) if (err == noErr)
@ -270,20 +344,21 @@ nsresult nsInternetConfigService::GetMappingForMIMEType(const char *mimetype, co
err = ::ICEnd(inst); err = ::ICEnd(inst);
if (err == noErr && gotmatch == PR_FALSE) if (err == noErr && gotmatch == PR_FALSE)
{ {
err = fnfErr; // return SOME kind of error err = fnfErr; // return SOME kind of error
} }
} }
} }
if (err != noErr) if (err != noErr)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
else else
return NS_OK; return NS_OK;
} }
nsresult nsInternetConfigService::FillMIMEInfoForICEntry(ICMapEntry& entry, nsIMIMEInfo ** mimeinfo) nsresult nsInternetConfigService::FillMIMEInfoForICEntry(ICMapEntry& entry, nsIMIMEInfo ** mimeinfo)
{ {
// create a mime info object and we'll fill it in based on the values from IC mapping entry // create a mime info object and we'll fill it in based on the values from IC mapping entry
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIMIMEInfo> info (do_CreateInstance(NS_MIMEINFO_CONTRACTID)); nsCOMPtr<nsIMIMEInfo> info (do_CreateInstance(NS_MIMEINFO_CONTRACTID));
if (info) if (info)
{ {
@ -304,8 +379,8 @@ nsresult nsInternetConfigService::FillMIMEInfoForICEntry(ICMapEntry& entry, nsIM
// convert entry.extension which is a Str255 // convert entry.extension which is a Str255
// don't forget to remove the '.' in front of the file extension.... // don't forget to remove the '.' in front of the file extension....
nsCAutoString temp((char *)&entry.extension[2], entry.extension[0] > 0 ? (int)entry.extension[0]-1 : 0); nsCAutoString temp((char *)&entry.extension[2], entry.extension[0] > 0 ? (int)entry.extension[0]-1 : 0);
info->AppendExtension(temp.get()); info->AppendExtension(temp.get());
info->SetMacType(entry.fileType); info->SetMacType(entry.fileType);
info->SetMacCreator(entry.fileCreator); info->SetMacCreator(entry.fileCreator);
temp.Assign((char *) &entry.entryName[1], entry.entryName[0]); temp.Assign((char *) &entry.entryName[1], entry.entryName[0]);
@ -316,21 +391,21 @@ nsresult nsInternetConfigService::FillMIMEInfoForICEntry(ICMapEntry& entry, nsIM
if (entry.flags & kICMapPostMask) if (entry.flags & kICMapPostMask)
{ {
// there is a post processor app // there is a post processor app
info->SetPreferredAction(nsIMIMEInfo::useSystemDefault); info->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
nsCOMPtr<nsILocalFileMac> file (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); nsCOMPtr<nsILocalFileMac> file (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
if (file) if (file)
{ {
rv = file->InitToAppWithCreatorCode(entry.postCreator); rv = file->InitToAppWithCreatorCode(entry.postCreator);
if (rv == NS_OK) if (rv == NS_OK)
{ {
//info->SetAlwaysAskBeforeHandling(PR_FALSE); //info->SetAlwaysAskBeforeHandling(PR_FALSE);
nsCOMPtr<nsIFile> nsfile = do_QueryInterface(file, &rv); nsCOMPtr<nsIFile> nsfile = do_QueryInterface(file, &rv);
if (rv == NS_OK) if (rv == NS_OK)
info->SetPreferredApplicationHandler(nsfile); info->SetPreferredApplicationHandler(nsfile);
} }
} }
} }
else else
{ {
// there isn't a post processor app so set the preferred action to be save to disk. // there isn't a post processor app so set the preferred action to be save to disk.
@ -339,18 +414,18 @@ nsresult nsInternetConfigService::FillMIMEInfoForICEntry(ICMapEntry& entry, nsIM
*mimeinfo = info; *mimeinfo = info;
NS_IF_ADDREF(*mimeinfo); NS_IF_ADDREF(*mimeinfo);
} }
else // we failed to allocate the info object... else // we failed to allocate the info object...
rv = NS_ERROR_FAILURE; rv = NS_ERROR_FAILURE;
return rv; return rv;
} }
/* void FillInMIMEInfo (in string mimetype, in string fileExtension, out nsIMIMEInfo mimeinfo); */ /* void FillInMIMEInfo (in string mimetype, in string fileExtension, out nsIMIMEInfo mimeinfo); */
NS_IMETHODIMP nsInternetConfigService::FillInMIMEInfo(const char *mimetype, const char * aFileExtension, nsIMIMEInfo **mimeinfo) NS_IMETHODIMP nsInternetConfigService::FillInMIMEInfo(const char *mimetype, const char * aFileExtension, nsIMIMEInfo **mimeinfo)
{ {
nsresult rv; nsresult rv;
ICMapEntry entry; ICMapEntry entry;
NS_ENSURE_ARG_POINTER(mimeinfo); NS_ENSURE_ARG_POINTER(mimeinfo);
*mimeinfo = nsnull; *mimeinfo = nsnull;
@ -366,90 +441,84 @@ NS_IMETHODIMP nsInternetConfigService::FillInMIMEInfo(const char *mimetype, cons
{ {
rv = GetMappingForMIMEType(mimetype, nsnull, &entry); rv = GetMappingForMIMEType(mimetype, nsnull, &entry);
} }
if (rv == NS_OK) if (rv == NS_OK)
{ rv = FillMIMEInfoForICEntry(entry, mimeinfo);
rv = FillMIMEInfoForICEntry(entry, mimeinfo);
}
else else
{
rv = NS_ERROR_FAILURE; rv = NS_ERROR_FAILURE;
}
return rv; return rv;
} }
NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromExtension(const char *aFileExt, nsIMIMEInfo **_retval) NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromExtension(const char *aFileExt, nsIMIMEInfo **_retval)
{ {
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
ICInstance instance = nsInternetConfig::GetInstance(); ICInstance instance = nsInternetConfig::GetInstance();
if ( instance ) if (instance)
{ {
nsCAutoString filename("foobar."); nsCAutoString filename("foobar.");
filename+=aFileExt; filename += aFileExt;
Str255 pFileName; Str255 pFileName;
ConvertCharStringToStr255( filename.get(), pFileName ); ConvertCharStringToStr255(filename.get(), pFileName);
ICMapEntry entry; ICMapEntry entry;
OSStatus err = ::ICMapFilename( instance, pFileName, &entry ); OSStatus err = ::ICMapFilename(instance, pFileName, &entry);
if( err == noErr ) if (err == noErr)
{ {
rv = FillMIMEInfoForICEntry(entry, _retval); rv = FillMIMEInfoForICEntry(entry, _retval);
} }
} }
return rv; return rv;
} }
NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromTypeCreator(PRUint32 aType, PRUint32 aCreator, const char *aFileExt, nsIMIMEInfo **_retval) NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromTypeCreator(PRUint32 aType, PRUint32 aCreator, const char *aFileExt, nsIMIMEInfo **_retval)
{ {
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
ICInstance instance = nsInternetConfig::GetInstance(); ICInstance instance = nsInternetConfig::GetInstance();
if ( instance ) if (instance)
{ {
nsCAutoString filename("foobar."); nsCAutoString filename("foobar.");
filename+=aFileExt; filename += aFileExt;
Str255 pFileName; Str255 pFileName;
ConvertCharStringToStr255( filename.get(), pFileName ); ConvertCharStringToStr255(filename.get(), pFileName);
ICMapEntry entry; ICMapEntry entry;
OSStatus err = ::ICMapTypeCreator( instance, aType, aCreator, pFileName, &entry ); OSStatus err = ::ICMapTypeCreator(instance, aType, aCreator, pFileName, &entry);
if( err == noErr ) if (err == noErr)
rv = FillMIMEInfoForICEntry(entry,_retval); rv = FillMIMEInfoForICEntry(entry,_retval);
} }
return rv; return rv;
} }
NS_IMETHODIMP nsInternetConfigService::GetFileMappingFlags(FSSpec* fsspec, PRBool lookupByExtensionFirst, PRInt32 *_retval) NS_IMETHODIMP nsInternetConfigService::GetFileMappingFlags(FSSpec* fsspec, PRBool lookupByExtensionFirst, PRInt32 *_retval)
{ {
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
OSStatus err = noErr; OSStatus err = noErr;
NS_ENSURE_ARG(_retval); NS_ENSURE_ARG(_retval);
*_retval = -1; *_retval = -1;
ICInstance instance = nsInternetConfig::GetInstance(); ICInstance instance = nsInternetConfig::GetInstance();
if ( instance ) if (instance)
{ {
ICMapEntry entry; ICMapEntry entry;
if (lookupByExtensionFirst) if (lookupByExtensionFirst)
err = ::ICMapFilename( instance, fsspec->name, &entry ); err = ::ICMapFilename(instance, fsspec->name, &entry);
if (!lookupByExtensionFirst || err != noErr) if (!lookupByExtensionFirst || err != noErr)
{ {
FInfo info; FInfo info;
err = FSpGetFInfo (fsspec, &info); err = FSpGetFInfo(fsspec, &info);
if (err == noErr) if (err == noErr)
err = ::ICMapTypeCreator( instance, info.fdType, info.fdCreator, fsspec->name, &entry ); err = ::ICMapTypeCreator(instance, info.fdType, info.fdCreator, fsspec->name, &entry);
} }
if (err == noErr) if (err == noErr)
*_retval = entry.flags; *_retval = entry.flags;
rv = NS_OK; rv = NS_OK;
} }
return rv; return rv;
} }
@ -457,10 +526,10 @@ NS_IMETHODIMP nsInternetConfigService::GetFileMappingFlags(FSSpec* fsspec, PRBoo
/* void GetDownloadFolder (out FSSpec fsspec); */ /* void GetDownloadFolder (out FSSpec fsspec); */
NS_IMETHODIMP nsInternetConfigService::GetDownloadFolder(FSSpec *fsspec) NS_IMETHODIMP nsInternetConfigService::GetDownloadFolder(FSSpec *fsspec)
{ {
ICInstance inst = nsInternetConfig::GetInstance(); ICInstance inst = nsInternetConfig::GetInstance();
OSStatus err; OSStatus err;
Handle prefH; Handle prefH;
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
NS_ENSURE_ARG_POINTER(fsspec); NS_ENSURE_ARG_POINTER(fsspec);
@ -472,7 +541,7 @@ NS_IMETHODIMP nsInternetConfigService::GetDownloadFolder(FSSpec *fsspec)
prefH = ::NewHandle(256); // ICFileSpec ~= 112 bytes + variable, 256 bytes hopefully is sufficient prefH = ::NewHandle(256); // ICFileSpec ~= 112 bytes + variable, 256 bytes hopefully is sufficient
if (prefH) if (prefH)
{ {
ICAttr attr; ICAttr attr;
err = ::ICFindPrefHandle(inst, kICDownloadFolder, &attr, prefH); err = ::ICFindPrefHandle(inst, kICDownloadFolder, &attr, prefH);
if (err == noErr) if (err == noErr)
{ {
@ -490,7 +559,7 @@ NS_IMETHODIMP nsInternetConfigService::GetDownloadFolder(FSSpec *fsspec)
err = ::ICFindPrefHandle(inst, kICDownloadFolder, &attr, prefH); err = ::ICFindPrefHandle(inst, kICDownloadFolder, &attr, prefH);
if (err == noErr) if (err == noErr)
{ // Use FSMakeFSSpec to verify the saved FSSpec is still valid { // Use FSMakeFSSpec to verify the saved FSSpec is still valid
FSSpec tempSpec = (*(ICFileSpecHandle)prefH)->fss; FSSpec tempSpec = (*(ICFileSpecHandle)prefH)->fss;
err = ::FSMakeFSSpec(tempSpec.vRefNum, tempSpec.parID, tempSpec.name, fsspec); err = ::FSMakeFSSpec(tempSpec.vRefNum, tempSpec.parID, tempSpec.name, fsspec);
if (err == noErr) if (err == noErr)
rv = NS_OK; rv = NS_OK;
@ -509,7 +578,7 @@ NS_IMETHODIMP nsInternetConfigService::GetDownloadFolder(FSSpec *fsspec)
nsresult nsInternetConfigService::GetICKeyPascalString(PRUint32 inIndex, const unsigned char*& outICKey) nsresult nsInternetConfigService::GetICKeyPascalString(PRUint32 inIndex, const unsigned char*& outICKey)
{ {
nsresult result = NS_OK; nsresult rv = NS_OK;
switch (inIndex) switch (inIndex)
{ {
@ -571,10 +640,9 @@ nsresult nsInternetConfigService::GetICKeyPascalString(PRUint32 inIndex, const u
case eICText_Plan: outICKey = kICPlan; break; case eICText_Plan: outICKey = kICPlan; break;
default: default:
result = NS_ERROR_INVALID_ARG; rv = NS_ERROR_INVALID_ARG;
} }
return rv;
return result;
} }
@ -582,41 +650,43 @@ nsresult nsInternetConfigService::GetICPreference(PRUint32 inKey,
void *outData, long *ioSize) void *outData, long *ioSize)
{ {
const unsigned char *icKey; const unsigned char *icKey;
nsresult result = GetICKeyPascalString( inKey, icKey ); nsresult rv = GetICKeyPascalString(inKey, icKey);
if (NS_FAILED(result)) if (rv == NS_OK)
return result; {
ICInstance instance = nsInternetConfig::GetInstance();
ICInstance instance = nsInternetConfig::GetInstance(); if (instance)
if ( !instance ) {
return NS_ERROR_FAILURE; OSStatus err;
ICAttr junk;
OSStatus err; err = ::ICGetPref(instance, icKey, &junk, outData, ioSize);
ICAttr junk; if (err != noErr)
err = ::ICGetPref( instance, icKey, &junk, outData, ioSize ); rv = NS_ERROR_UNEXPECTED;
if ( err ) }
return NS_ERROR_UNEXPECTED; else
rv = NS_ERROR_FAILURE;
return NS_OK; }
return rv;
} }
NS_IMETHODIMP nsInternetConfigService::GetString(PRUint32 inKey, char **value) NS_IMETHODIMP nsInternetConfigService::GetString(PRUint32 inKey, nsACString& value)
{ {
long size = 256; long size = 256;
char buffer[256]; char buffer[256];
nsresult result = GetICPreference( inKey, (void *)&buffer, &size ); nsresult rv = GetICPreference(inKey, (void *)&buffer, &size);
if ( result == NS_OK ) { if (rv == NS_OK)
if ( size == 0 ) { {
*value = nsnull; if (size == 0)
return NS_ERROR_UNEXPECTED; {
value = "";
rv = NS_ERROR_UNEXPECTED;
}
else
{ // Buffer is a Pascal string so adjust for length byte when assigning
value.Assign(&buffer[1], (unsigned char)buffer[0]);
} }
// Buffer is a Pascal string; convert it to a c-string
nsCString temp( &buffer[1], buffer[0] );
*value = ToNewCString(temp);
} }
return rv;
return result;
} }
@ -629,43 +699,35 @@ NS_IMETHODIMP nsInternetConfigService::GetColor(PRUint32 inKey, PRUint32 *outCol
#define MAKE_NS_RGB(_r,_g,_b) \ #define MAKE_NS_RGB(_r,_g,_b) \
((PRUint32) ((255 << 24) | ((_b)<<16) | ((_g)<<8) | (_r))) ((PRUint32) ((255 << 24) | ((_b)<<16) | ((_g)<<8) | (_r)))
RGBColor buffer; RGBColor buffer;
long size = sizeof(RGBColor); long size = sizeof(RGBColor);
nsresult result = GetICPreference( inKey, &buffer, &size ); nsresult rv = GetICPreference(inKey, &buffer, &size);
if ( result == NS_OK ) { if (rv == NS_OK)
if ( size != sizeof(RGBColor) ) { {
*outColor = MAKE_NS_RGB(0xff, 0xff, 0xff); // default to white if we didn't get the right size if (size != sizeof(RGBColor))
return NS_OK; { // default to white if we didn't get the right size
*outColor = MAKE_NS_RGB(0xff, 0xff, 0xff);
}
else
{ // convert to a web color
*outColor = MAKE_NS_RGB(buffer.red >> 8, buffer.green >> 8, buffer.blue >> 8);
} }
// convert to a web color
*outColor = MAKE_NS_RGB( buffer.red>>8, buffer.green>>8, buffer.blue>>8 );
} }
return rv;
return result;
} }
NS_IMETHODIMP nsInternetConfigService::GetBoolean(PRUint32 inKey, PRBool *outFlag) NS_IMETHODIMP nsInternetConfigService::GetBoolean(PRUint32 inKey, PRBool *outFlag)
{ {
Boolean buffer; Boolean buffer;
long size = sizeof(Boolean); long size = sizeof(Boolean);
nsresult result = GetICPreference( inKey, (void *)&buffer, &size ); nsresult rv = GetICPreference(inKey, (void *)&buffer, &size);
if ( result == NS_OK ) { if (rv == NS_OK)
if ( (size_t)size < sizeof(Boolean) ) { {
if ((size_t)size < sizeof(Boolean))
*outFlag = PR_FALSE; // default to false if we didn't get the right amount of data *outFlag = PR_FALSE; // default to false if we didn't get the right amount of data
return NS_OK; else
} *outFlag = buffer;
*outFlag = buffer;
result = NS_OK;
} }
return rv;
return result;
}
NS_IMETHODIMP nsInternetConfigService::GetText(PRUint32 inKey, PRUint32 *ioLength, PRUnichar **outText)
{
return NS_ERROR_NOT_IMPLEMENTED;
} }

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

@ -61,6 +61,9 @@ protected:
nsresult GetICKeyPascalString(PRUint32 inIndex, const unsigned char*& outICKey); nsresult GetICKeyPascalString(PRUint32 inIndex, const unsigned char*& outICKey);
nsresult GetICPreference(PRUint32 inKey, void *outData, long *ioSize); nsresult GetICPreference(PRUint32 inKey, void *outData, long *ioSize);
PRBool mRunningOSX;
PRBool mRunningJaguar;
}; };
#endif #endif

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

@ -123,11 +123,9 @@ interface nsIInternetConfigService : nsISupports
[noscript] void getDownloadFolder(out FSSpec fsspec); [noscript] void getDownloadFolder(out FSSpec fsspec);
string getString(in unsigned long keyenum); ACString getString(in unsigned long keyenum);
unsigned long getColor(in unsigned long keyenum); unsigned long getColor(in unsigned long keyenum);
boolean getBoolean(in unsigned long keyenum); boolean getBoolean(in unsigned long keyenum);
wstring getText(in unsigned long keyenum, out unsigned long length);
}; };

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

@ -65,6 +65,8 @@
#include "nsSound.h" #include "nsSound.h"
#include "nsString.h"
//#define SOUND_DEBUG //#define SOUND_DEBUG
#pragma mark nsSoundRequest #pragma mark nsSoundRequest
@ -432,9 +434,9 @@ nsSound::GetSoundResourceName(const char* inSoundName, StringPtr outResourceName
nsCOMPtr <nsIInternetConfigService> icService = do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID, &rv); nsCOMPtr <nsIInternetConfigService> icService = do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
nsXPIDLCString newMailSound; nsCAutoString newMailSound;
rv = icService->GetString(nsIInternetConfigService::eICString_NewMailSoundName, getter_Copies(newMailSound)); rv = icService->GetString(nsIInternetConfigService::eICString_NewMailSoundName, newMailSound);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;

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

@ -60,14 +60,12 @@ nsUserInfo::GetFullname(PRUnichar **aFullname)
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService) if (icService)
{ {
char* cName; nsCAutoString cName;
result = icService->GetString(nsIInternetConfigService::eICString_RealName, &cName); result = icService->GetString(nsIInternetConfigService::eICString_RealName, cName);
if ( NS_SUCCEEDED ( result ) ) if ( NS_SUCCEEDED ( result ) )
{ {
nsString fullName; nsString fullName;
fullName.AssignWithConversion( cName ); *aFullname = ToNewUnicode(cName);
nsMemory::Free( cName );
*aFullname = ToNewUnicode(fullName);
} }
} }
return result; return result;
@ -81,7 +79,11 @@ nsUserInfo::GetEmailAddress(char * *aEmailAddress)
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService) if (icService)
{ {
result = icService->GetString(nsIInternetConfigService::eICString_Email, aEmailAddress); nsCAutoString tempString;
result = icService->GetString(nsIInternetConfigService::eICString_Email, tempString);
if (NS_SUCCEEDED(result))
*aEmailAddress = ToNewCString(tempString);
} }
return result; return result;
} }
@ -91,16 +93,14 @@ nsUserInfo::GetUsername(char * *aUsername)
{ {
*aUsername = nsnull; *aUsername = nsnull;
char* cString; nsCAutoString tempString;
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService) if (icService)
rv = icService->GetString(nsIInternetConfigService::eICString_Email, &cString); rv = icService->GetString(nsIInternetConfigService::eICString_Email, tempString);
if ( NS_FAILED( rv ) ) return rv; if ( NS_FAILED( rv ) ) return rv;
nsCAutoString tempString(cString);
nsMemory::Free( cString );
const char* atString = "@"; const char* atString = "@";
PRInt32 atOffset = tempString.Find(atString); PRInt32 atOffset = tempString.Find(atString);
if (atOffset != kNotFound) if (atOffset != kNotFound)
@ -114,14 +114,12 @@ NS_IMETHODIMP
nsUserInfo::GetDomain(char * *aDomain) nsUserInfo::GetDomain(char * *aDomain)
{ {
*aDomain = nsnull; *aDomain = nsnull;
char* cString; nsCAutoString tempString;
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService) if (icService)
rv = icService->GetString(nsIInternetConfigService::eICString_Email, &cString); rv = icService->GetString(nsIInternetConfigService::eICString_Email, tempString);
if ( NS_FAILED( rv ) ) return rv; if ( NS_FAILED( rv ) ) return rv;
nsCAutoString tempString( cString);
nsMemory::Free( cString );
const char* atString = "@"; const char* atString = "@";
PRInt32 atOffset = tempString.Find(atString); PRInt32 atOffset = tempString.Find(atString);
if (atOffset != kNotFound) if (atOffset != kNotFound)

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

@ -60,14 +60,12 @@ nsUserInfo::GetFullname(PRUnichar **aFullname)
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService) if (icService)
{ {
char* cName; nsCAutoString cName;
result = icService->GetString(nsIInternetConfigService::eICString_RealName, &cName); result = icService->GetString(nsIInternetConfigService::eICString_RealName, cName);
if ( NS_SUCCEEDED ( result ) ) if ( NS_SUCCEEDED ( result ) )
{ {
nsString fullName; nsString fullName;
fullName.AssignWithConversion( cName ); *aFullname = ToNewUnicode(cName);
nsMemory::Free( cName );
*aFullname = ToNewUnicode(fullName);
} }
} }
return result; return result;
@ -81,7 +79,11 @@ nsUserInfo::GetEmailAddress(char * *aEmailAddress)
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService) if (icService)
{ {
result = icService->GetString(nsIInternetConfigService::eICString_Email, aEmailAddress); nsCAutoString tempString;
result = icService->GetString(nsIInternetConfigService::eICString_Email, tempString);
if (NS_SUCCEEDED(result))
*aEmailAddress = ToNewCString(tempString);
} }
return result; return result;
} }
@ -91,16 +93,14 @@ nsUserInfo::GetUsername(char * *aUsername)
{ {
*aUsername = nsnull; *aUsername = nsnull;
char* cString; nsCAutoString tempString;
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService) if (icService)
rv = icService->GetString(nsIInternetConfigService::eICString_Email, &cString); rv = icService->GetString(nsIInternetConfigService::eICString_Email, tempString);
if ( NS_FAILED( rv ) ) return rv; if ( NS_FAILED( rv ) ) return rv;
nsCAutoString tempString(cString);
nsMemory::Free( cString );
const char* atString = "@"; const char* atString = "@";
PRInt32 atOffset = tempString.Find(atString); PRInt32 atOffset = tempString.Find(atString);
if (atOffset != kNotFound) if (atOffset != kNotFound)
@ -114,14 +114,12 @@ NS_IMETHODIMP
nsUserInfo::GetDomain(char * *aDomain) nsUserInfo::GetDomain(char * *aDomain)
{ {
*aDomain = nsnull; *aDomain = nsnull;
char* cString; nsCAutoString tempString;
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService) if (icService)
rv = icService->GetString(nsIInternetConfigService::eICString_Email, &cString); rv = icService->GetString(nsIInternetConfigService::eICString_Email, tempString);
if ( NS_FAILED( rv ) ) return rv; if ( NS_FAILED( rv ) ) return rv;
nsCAutoString tempString( cString);
nsMemory::Free( cString );
const char* atString = "@"; const char* atString = "@";
PRInt32 atOffset = tempString.Find(atString); PRInt32 atOffset = tempString.Find(atString);
if (atOffset != kNotFound) if (atOffset != kNotFound)