2001-09-29 00:14:13 +04:00
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
2000-09-07 01:14:03 +04:00
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
2000-09-07 01:14:03 +04:00
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
|
* 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.
|
2000-09-07 01:14:03 +04:00
|
|
|
|
*
|
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-09-07 01:14:03 +04:00
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
|
* Contributor(s):
|
2002-10-01 09:27:15 +04:00
|
|
|
|
* Steve Dagley <sdagley@netscape.com>
|
2001-09-29 00:14:13 +04: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 NPL, 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 NPL, the GPL or the LGPL.
|
|
|
|
|
*
|
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-09-07 01:14:03 +04:00
|
|
|
|
|
|
|
|
|
#include "nsInternetConfigService.h"
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
#include "nsIMIMEInfo.h"
|
|
|
|
|
#include "nsIFactory.h"
|
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
|
#include "nsIURL.h"
|
|
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
|
#include "nsReadableUtils.h"
|
2002-10-01 05:00:09 +04:00
|
|
|
|
#include "nsString.h"
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
|
#include "nsILocalFileMac.h"
|
2000-09-07 01:14:03 +04:00
|
|
|
|
#include "nsMimeTypes.h"
|
|
|
|
|
#include <TextUtils.h>
|
2002-10-01 09:27:15 +04:00
|
|
|
|
#include <CodeFragments.h>
|
2001-04-17 00:16:51 +04:00
|
|
|
|
#include <Processes.h>
|
2002-10-01 09:27:15 +04:00
|
|
|
|
#include <Gestalt.h>
|
|
|
|
|
#include <CFURL.h>
|
|
|
|
|
#include <Finder.h>
|
|
|
|
|
#include <LaunchServices.h>
|
|
|
|
|
|
2000-09-07 01:14:03 +04:00
|
|
|
|
|
2000-09-15 10:06:19 +04:00
|
|
|
|
// helper converter function.....
|
2002-10-01 09:27:15 +04:00
|
|
|
|
static void ConvertCharStringToStr255(const char* inString, Str255& outString)
|
2000-09-15 10:06:19 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
if (inString == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
PRInt32 len = strlen(inString);
|
|
|
|
|
NS_ASSERTION(len <= 255 , " String is too big");
|
|
|
|
|
if (len> 255)
|
|
|
|
|
{
|
|
|
|
|
len = 255;
|
|
|
|
|
}
|
|
|
|
|
memcpy(&outString[1], inString, len);
|
|
|
|
|
outString[0] = len;
|
2000-09-15 10:06:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-07 01:14:03 +04:00
|
|
|
|
/* Define Class IDs */
|
|
|
|
|
static NS_DEFINE_CID(kICServiceCID, NS_INTERNETCONFIGSERVICE_CID);
|
|
|
|
|
|
|
|
|
|
nsInternetConfigService::nsInternetConfigService()
|
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
long version;
|
|
|
|
|
OSErr err;
|
|
|
|
|
mRunningOSX = ((err = ::Gestalt(gestaltSystemVersion, &version)) == noErr && version >= 0x00001000);
|
2002-10-02 05:46:37 +04:00
|
|
|
|
mRunningJaguar = (err == noErr && version >= 0x00001020);
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsInternetConfigService::~nsInternetConfigService()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Implement the nsISupports methods...
|
|
|
|
|
*/
|
2002-10-01 09:27:15 +04:00
|
|
|
|
NS_IMPL_ISUPPORTS1(nsInternetConfigService, nsIInternetConfigService)
|
2000-09-07 01:14:03 +04:00
|
|
|
|
|
|
|
|
|
// void LaunchURL (in string url);
|
2002-10-01 09:27:15 +04:00
|
|
|
|
// Given a url string, call ICLaunchURL using url
|
|
|
|
|
// Under OS X use LaunchServices instead of IC
|
2000-09-07 01:14:03 +04:00
|
|
|
|
NS_IMETHODIMP nsInternetConfigService::LaunchURL(const char *url)
|
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
|
2002-10-01 09:27:15 +04:00
|
|
|
|
#if TARGET_CARBON
|
|
|
|
|
if (mRunningOSX && ((UInt32)LSOpenCFURLRef != (UInt32)kUnresolvedCFragSymbolAddress))
|
2000-09-07 01:14:03 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
CFURLRef myURLRef = ::CFURLCreateWithBytes(
|
|
|
|
|
kCFAllocatorDefault,
|
|
|
|
|
(const UInt8*)url,
|
|
|
|
|
strlen(url),
|
|
|
|
|
kCFStringEncodingUTF8, NULL);
|
|
|
|
|
if (myURLRef)
|
|
|
|
|
{
|
|
|
|
|
rv = ::LSOpenCFURLRef(myURLRef, NULL);
|
|
|
|
|
::CFRelease(myURLRef);
|
|
|
|
|
}
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
2002-10-01 09:27:15 +04:00
|
|
|
|
#endif
|
2000-09-07 01:14:03 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|
2002-10-01 09:27:15 +04:00
|
|
|
|
return rv;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
|
|
|
|
ICMapEntry entry;
|
|
|
|
|
nsresult rv = GetMappingForMIMEType(mimetype, nsnull, &entry);
|
|
|
|
|
if (rv == noErr)
|
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
|
else
|
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* boolean hasProtocalHandler (in string protocol); */
|
2001-04-17 00:16:51 +04:00
|
|
|
|
// returns NS_ERROR_NOT_AVAILABLE if the current application is registered for as the
|
|
|
|
|
// protocol handler for protocol
|
|
|
|
|
NS_IMETHODIMP nsInternetConfigService::HasProtocolHandler(const char *protocol, PRBool *_retval)
|
2000-09-07 01:14:03 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
*_retval = PR_FALSE; // Presume failure
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE; // Ditto
|
2002-09-27 03:38:08 +04:00
|
|
|
|
|
2002-10-01 09:27:15 +04:00
|
|
|
|
#if TARGET_CARBON
|
|
|
|
|
// Use LaunchServices directly when we're running under OS X to avoid the problem of some protocols
|
|
|
|
|
// 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
|
|
|
|
|
// so we only use it for 10.2 or later.
|
|
|
|
|
|
|
|
|
|
// Since protocol comes in with _just_ the protocol we have to add a ':' to the end of it or
|
|
|
|
|
// LaunchServices will be very unhappy with the CFURLRef created from it (crashes trying to look
|
|
|
|
|
// up a handler for it with LSGetApplicationForURL, at least under 10.2.1)
|
|
|
|
|
if (mRunningJaguar)
|
2001-04-17 00:16:51 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsCAutoString scheme(protocol);
|
|
|
|
|
scheme += ":";
|
|
|
|
|
CFURLRef myURLRef = ::CFURLCreateWithBytes(
|
|
|
|
|
kCFAllocatorDefault,
|
|
|
|
|
(const UInt8 *)scheme.get(),
|
|
|
|
|
scheme.Length(),
|
|
|
|
|
kCFStringEncodingUTF8, NULL);
|
|
|
|
|
if (myURLRef)
|
2001-04-17 00:16:51 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
FSRef appFSRef;
|
|
|
|
|
|
|
|
|
|
if (::LSGetApplicationForURL(myURLRef, kLSRolesAll, &appFSRef, NULL) == noErr)
|
|
|
|
|
{ // 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);
|
2001-04-17 00:16:51 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2002-10-01 09:27:15 +04:00
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
// look for IC pref "\pHelper<65><protocol>"
|
|
|
|
|
Str255 pref = kICHelper;
|
2001-04-17 00:16:51 +04:00
|
|
|
|
|
2002-10-01 09:27:15 +04:00
|
|
|
|
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;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method does the dirty work of traipsing through IC mappings database
|
|
|
|
|
// looking for a mapping for mimetype
|
2001-01-05 03:44:16 +03:00
|
|
|
|
nsresult nsInternetConfigService::GetMappingForMIMEType(const char *mimetype, const char *fileextension, ICMapEntry *entry)
|
2000-09-07 01:14:03 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
ICInstance inst = nsInternetConfig::GetInstance();
|
|
|
|
|
OSStatus err = noErr;
|
|
|
|
|
ICAttr attr;
|
|
|
|
|
Handle prefH;
|
|
|
|
|
PRBool domimecheck = PR_TRUE;
|
|
|
|
|
PRBool gotmatch = PR_FALSE;
|
|
|
|
|
ICMapEntry ent;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
|
2001-06-14 02:31:08 +04:00
|
|
|
|
// if mime type is "unknown" or "octet stream" *AND* we have a file extension,
|
|
|
|
|
// then disable match on mime type
|
|
|
|
|
if (((nsCRT::strcasecmp(mimetype, UNKNOWN_CONTENT_TYPE) == 0) ||
|
|
|
|
|
(nsCRT::strcasecmp(mimetype, APPLICATION_OCTET_STREAM) == 0)) &&
|
|
|
|
|
fileextension)
|
2000-09-07 01:14:03 +04:00
|
|
|
|
domimecheck = PR_FALSE;
|
|
|
|
|
|
|
|
|
|
entry->totalLength = 0;
|
|
|
|
|
if (inst)
|
|
|
|
|
{
|
|
|
|
|
err = ::ICBegin(inst, icReadOnlyPerm);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
{
|
|
|
|
|
prefH = ::NewHandle(2048); // picked 2048 out of thin air
|
|
|
|
|
if (prefH)
|
|
|
|
|
{
|
|
|
|
|
err = ::ICFindPrefHandle(inst, kICMapping, &attr, prefH);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
{
|
|
|
|
|
long count;
|
|
|
|
|
err = ::ICCountMapEntries(inst, prefH, &count);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
{
|
|
|
|
|
long pos;
|
2002-10-01 09:27:15 +04:00
|
|
|
|
for (long i = 1; i <= count; ++i)
|
2000-09-07 01:14:03 +04:00
|
|
|
|
{
|
2001-01-05 03:44:16 +03:00
|
|
|
|
err = ::ICGetIndMapEntry(inst, prefH, i, &pos, &ent);
|
2000-09-07 01:14:03 +04:00
|
|
|
|
if (err == noErr)
|
|
|
|
|
{
|
|
|
|
|
// first, do mime type check
|
|
|
|
|
if (domimecheck)
|
|
|
|
|
{
|
2001-01-05 03:44:16 +03:00
|
|
|
|
nsCAutoString temp((char *)&ent.MIMEType[1], (int)ent.MIMEType[0]);
|
2000-09-07 01:14:03 +04:00
|
|
|
|
if (!temp.EqualsIgnoreCase(mimetype))
|
|
|
|
|
{
|
|
|
|
|
// we need to do mime check, and check failed
|
|
|
|
|
// nothing here to see, move along
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (fileextension)
|
|
|
|
|
{
|
|
|
|
|
// if fileextension was passed in, compare that also
|
2001-01-05 03:44:16 +03:00
|
|
|
|
if (ent.extension[0]) // check for non-empty pascal string
|
2000-09-07 01:14:03 +04:00
|
|
|
|
{
|
2001-01-05 03:44:16 +03:00
|
|
|
|
nsCAutoString temp((char *)&ent.extension[1], (int)ent.extension[0]);
|
2000-09-07 01:14:03 +04:00
|
|
|
|
if (temp.EqualsIgnoreCase(fileextension))
|
|
|
|
|
{
|
|
|
|
|
// mime type and file extension match, we're outta here
|
2001-01-05 03:44:16 +03:00
|
|
|
|
gotmatch = PR_TRUE;
|
|
|
|
|
// copy over ICMapEntry
|
|
|
|
|
*entry = ent;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(domimecheck)
|
|
|
|
|
{
|
|
|
|
|
// at this point, we've got our match because
|
|
|
|
|
// domimecheck is true, the mime strings match, and fileextension isn't passed in
|
|
|
|
|
// bad thing is we'll stop on first match, but what can you do?
|
2001-01-05 03:44:16 +03:00
|
|
|
|
gotmatch = PR_TRUE;
|
|
|
|
|
// copy over ICMapEntry
|
|
|
|
|
*entry = ent;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
::DisposeHandle(prefH);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
err = memFullErr;
|
|
|
|
|
}
|
|
|
|
|
err = ::ICEnd(inst);
|
2001-01-05 03:44:16 +03:00
|
|
|
|
if (err == noErr && gotmatch == PR_FALSE)
|
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
err = fnfErr; // return SOME kind of error
|
2001-01-05 03:44:16 +03:00
|
|
|
|
}
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-10-01 09:27:15 +04:00
|
|
|
|
|
2001-01-05 03:44:16 +03:00
|
|
|
|
if (err != noErr)
|
2002-10-01 09:27:15 +04:00
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-01-05 03:44:16 +03:00
|
|
|
|
else
|
2002-10-01 09:27:15 +04:00
|
|
|
|
return NS_OK;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-15 10:06:19 +04:00
|
|
|
|
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
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsresult rv = NS_OK;
|
2000-09-15 10:06:19 +04:00
|
|
|
|
nsCOMPtr<nsIMIMEInfo> info (do_CreateInstance(NS_MIMEINFO_CONTRACTID));
|
|
|
|
|
if (info)
|
|
|
|
|
{
|
|
|
|
|
nsCAutoString mimetype ((char *)&entry.MIMEType[1], entry.MIMEType[0]);
|
2001-08-22 04:19:08 +04:00
|
|
|
|
// check if entry.MIMEType is empty, if so, set mime type to APPLICATION_OCTET_STREAM
|
|
|
|
|
if (entry.MIMEType[0])
|
|
|
|
|
info->SetMIMEType(mimetype.get());
|
|
|
|
|
else
|
2002-04-29 11:01:44 +04:00
|
|
|
|
{ // The IC mappings seem to not be very agressive about determining the mime type if
|
|
|
|
|
// all we have is a type or creator code. This is a bandaid approach for when we
|
|
|
|
|
// get a file of type 'TEXT' with no mime type mapping so that we'll display the
|
|
|
|
|
// file rather than trying to download it.
|
|
|
|
|
if (entry.fileType == 'TEXT')
|
|
|
|
|
info->SetMIMEType(TEXT_PLAIN);
|
|
|
|
|
else
|
|
|
|
|
info->SetMIMEType(APPLICATION_OCTET_STREAM);
|
|
|
|
|
}
|
2000-09-15 10:06:19 +04:00
|
|
|
|
|
|
|
|
|
// convert entry.extension which is a Str255
|
|
|
|
|
// don't forget to remove the '.' in front of the file extension....
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsCAutoString temp((char *)&entry.extension[2], entry.extension[0] > 0 ? (int)entry.extension[0]-1 : 0);
|
|
|
|
|
info->AppendExtension(temp.get());
|
2000-09-15 10:06:19 +04:00
|
|
|
|
info->SetMacType(entry.fileType);
|
|
|
|
|
info->SetMacCreator(entry.fileCreator);
|
|
|
|
|
temp.Assign((char *) &entry.entryName[1], entry.entryName[0]);
|
2001-03-02 12:26:57 +03:00
|
|
|
|
info->SetDescription(NS_ConvertASCIItoUCS2(temp.get()).get());
|
2000-09-15 10:06:19 +04:00
|
|
|
|
|
|
|
|
|
temp.Assign((char *) &entry.postAppName[1], entry.postAppName[0]);
|
2003-01-15 01:29:48 +03:00
|
|
|
|
info->SetDefaultDescription(NS_ConvertASCIItoUCS2(temp.get()).get());
|
2000-09-15 10:06:19 +04:00
|
|
|
|
|
|
|
|
|
if (entry.flags & kICMapPostMask)
|
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
// there is a post processor app
|
|
|
|
|
info->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
|
|
|
|
nsCOMPtr<nsILocalFileMac> file (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
|
|
|
|
if (file)
|
|
|
|
|
{
|
|
|
|
|
rv = file->InitToAppWithCreatorCode(entry.postCreator);
|
|
|
|
|
if (rv == NS_OK)
|
|
|
|
|
{
|
|
|
|
|
nsCOMPtr<nsIFile> nsfile = do_QueryInterface(file, &rv);
|
|
|
|
|
if (rv == NS_OK)
|
2003-01-15 01:29:48 +03:00
|
|
|
|
info->SetDefaultApplicationHandler(nsfile);
|
2002-10-01 09:27:15 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-09-15 10:06:19 +04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// there isn't a post processor app so set the preferred action to be save to disk.
|
|
|
|
|
info->SetPreferredAction(nsIMIMEInfo::saveToDisk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*mimeinfo = info;
|
|
|
|
|
NS_IF_ADDREF(*mimeinfo);
|
2002-10-01 09:27:15 +04:00
|
|
|
|
}
|
|
|
|
|
else // we failed to allocate the info object...
|
|
|
|
|
rv = NS_ERROR_FAILURE;
|
2000-09-15 10:06:19 +04:00
|
|
|
|
|
2002-10-01 09:27:15 +04:00
|
|
|
|
return rv;
|
2000-09-15 10:06:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* void FillInMIMEInfo (in string mimetype, in string fileExtension, out nsIMIMEInfo mimeinfo); */
|
|
|
|
|
NS_IMETHODIMP nsInternetConfigService::FillInMIMEInfo(const char *mimetype, const char * aFileExtension, nsIMIMEInfo **mimeinfo)
|
2000-09-07 01:14:03 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsresult rv;
|
|
|
|
|
ICMapEntry entry;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(mimeinfo);
|
|
|
|
|
*mimeinfo = nsnull;
|
|
|
|
|
|
2000-09-15 10:06:19 +04:00
|
|
|
|
if (aFileExtension)
|
2000-09-07 01:14:03 +04:00
|
|
|
|
{
|
2000-09-15 10:06:19 +04:00
|
|
|
|
nsCAutoString fileExtension;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
fileExtension.Assign(".");
|
2000-09-15 10:06:19 +04:00
|
|
|
|
fileExtension.Append(aFileExtension);
|
2001-11-02 09:39:49 +03:00
|
|
|
|
rv = GetMappingForMIMEType(mimetype, fileExtension.get(), &entry);
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rv = GetMappingForMIMEType(mimetype, nsnull, &entry);
|
|
|
|
|
}
|
2002-10-01 09:27:15 +04:00
|
|
|
|
|
2000-09-07 01:14:03 +04:00
|
|
|
|
if (rv == NS_OK)
|
2002-10-01 09:27:15 +04:00
|
|
|
|
rv = FillMIMEInfoForICEntry(entry, mimeinfo);
|
2000-09-07 01:14:03 +04:00
|
|
|
|
else
|
|
|
|
|
rv = NS_ERROR_FAILURE;
|
2002-10-01 09:27:15 +04:00
|
|
|
|
|
2000-09-07 01:14:03 +04:00
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-15 10:06:19 +04:00
|
|
|
|
NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromExtension(const char *aFileExt, nsIMIMEInfo **_retval)
|
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
ICInstance instance = nsInternetConfig::GetInstance();
|
|
|
|
|
if (instance)
|
2000-09-15 10:06:19 +04:00
|
|
|
|
{
|
|
|
|
|
nsCAutoString filename("foobar.");
|
2002-10-01 09:27:15 +04:00
|
|
|
|
filename += aFileExt;
|
|
|
|
|
Str255 pFileName;
|
|
|
|
|
ConvertCharStringToStr255(filename.get(), pFileName);
|
|
|
|
|
ICMapEntry entry;
|
|
|
|
|
OSStatus err = ::ICMapFilename(instance, pFileName, &entry);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
{
|
|
|
|
|
rv = FillMIMEInfoForICEntry(entry, _retval);
|
|
|
|
|
}
|
2000-09-15 10:06:19 +04:00
|
|
|
|
}
|
|
|
|
|
return rv;
|
2002-10-01 09:27:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-15 10:06:19 +04:00
|
|
|
|
NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromTypeCreator(PRUint32 aType, PRUint32 aCreator, const char *aFileExt, nsIMIMEInfo **_retval)
|
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
ICInstance instance = nsInternetConfig::GetInstance();
|
|
|
|
|
if (instance)
|
2000-09-15 10:06:19 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsCAutoString filename("foobar.");
|
|
|
|
|
filename += aFileExt;
|
|
|
|
|
Str255 pFileName;
|
|
|
|
|
ConvertCharStringToStr255(filename.get(), pFileName);
|
|
|
|
|
ICMapEntry entry;
|
|
|
|
|
OSStatus err = ::ICMapTypeCreator(instance, aType, aCreator, pFileName, &entry);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
rv = FillMIMEInfoForICEntry(entry,_retval);
|
2000-09-15 10:06:19 +04:00
|
|
|
|
}
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-04-04 01:08:51 +04:00
|
|
|
|
NS_IMETHODIMP nsInternetConfigService::GetFileMappingFlags(FSSpec* fsspec, PRBool lookupByExtensionFirst, PRInt32 *_retval)
|
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
OSStatus err = noErr;
|
2001-04-04 01:08:51 +04:00
|
|
|
|
|
|
|
|
|
NS_ENSURE_ARG(_retval);
|
|
|
|
|
*_retval = -1;
|
|
|
|
|
|
|
|
|
|
ICInstance instance = nsInternetConfig::GetInstance();
|
2002-10-01 09:27:15 +04:00
|
|
|
|
if (instance)
|
2001-04-04 01:08:51 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
ICMapEntry entry;
|
2001-04-04 01:08:51 +04:00
|
|
|
|
|
|
|
|
|
if (lookupByExtensionFirst)
|
2002-10-01 09:27:15 +04:00
|
|
|
|
err = ::ICMapFilename(instance, fsspec->name, &entry);
|
2001-04-04 01:08:51 +04:00
|
|
|
|
|
|
|
|
|
if (!lookupByExtensionFirst || err != noErr)
|
|
|
|
|
{
|
|
|
|
|
FInfo info;
|
2002-10-01 09:27:15 +04:00
|
|
|
|
err = FSpGetFInfo(fsspec, &info);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
err = ::ICMapTypeCreator(instance, info.fdType, info.fdCreator, fsspec->name, &entry);
|
2001-04-04 01:08:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-01 09:27:15 +04:00
|
|
|
|
if (err == noErr)
|
|
|
|
|
*_retval = entry.flags;
|
|
|
|
|
|
|
|
|
|
rv = NS_OK;
|
2001-04-04 01:08:51 +04:00
|
|
|
|
}
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-07 01:14:03 +04:00
|
|
|
|
/* void GetDownloadFolder (out FSSpec fsspec); */
|
|
|
|
|
NS_IMETHODIMP nsInternetConfigService::GetDownloadFolder(FSSpec *fsspec)
|
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
ICInstance inst = nsInternetConfig::GetInstance();
|
|
|
|
|
OSStatus err;
|
|
|
|
|
Handle prefH;
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(fsspec);
|
|
|
|
|
|
|
|
|
|
if (inst)
|
|
|
|
|
{
|
|
|
|
|
err = ::ICBegin(inst, icReadOnlyPerm);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
{
|
|
|
|
|
prefH = ::NewHandle(256); // ICFileSpec ~= 112 bytes + variable, 256 bytes hopefully is sufficient
|
|
|
|
|
if (prefH)
|
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
ICAttr attr;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
err = ::ICFindPrefHandle(inst, kICDownloadFolder, &attr, prefH);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
{
|
|
|
|
|
err = ::Munger(prefH, 0, NULL, kICFileSpecHeaderSize, (Ptr)-1, 0);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
{
|
|
|
|
|
Boolean wasChanged;
|
|
|
|
|
err = ::ResolveAlias(NULL, (AliasHandle)prefH, fsspec, &wasChanged);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
{
|
|
|
|
|
rv = NS_OK;
|
|
|
|
|
}
|
2001-10-08 08:59:59 +04:00
|
|
|
|
else
|
|
|
|
|
{ // ResolveAlias for the DownloadFolder failed - try grabbing the FSSpec
|
|
|
|
|
err = ::ICFindPrefHandle(inst, kICDownloadFolder, &attr, prefH);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
{ // Use FSMakeFSSpec to verify the saved FSSpec is still valid
|
2002-10-01 09:27:15 +04:00
|
|
|
|
FSSpec tempSpec = (*(ICFileSpecHandle)prefH)->fss;
|
2001-10-09 00:20:57 +04:00
|
|
|
|
err = ::FSMakeFSSpec(tempSpec.vRefNum, tempSpec.parID, tempSpec.name, fsspec);
|
2001-10-08 08:59:59 +04:00
|
|
|
|
if (err == noErr)
|
|
|
|
|
rv = NS_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-10-08 08:59:59 +04:00
|
|
|
|
// Best not to leave that handle laying around
|
|
|
|
|
DisposeHandle(prefH);
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|
|
|
|
|
err = ::ICEnd(inst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-01 05:00:09 +04:00
|
|
|
|
nsresult nsInternetConfigService::GetICKeyPascalString(PRUint32 inIndex, const unsigned char*& outICKey)
|
2000-09-07 01:14:03 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsresult rv = NS_OK;
|
2001-03-28 17:56:19 +04:00
|
|
|
|
|
|
|
|
|
switch (inIndex)
|
|
|
|
|
{
|
2002-10-01 05:00:09 +04:00
|
|
|
|
case eICColor_WebBackgroundColour: outICKey = kICWebBackgroundColour; break;
|
|
|
|
|
case eICColor_WebReadColor: outICKey = kICWebReadColor; break;
|
|
|
|
|
case eICColor_WebTextColor: outICKey = kICWebTextColor; break;
|
|
|
|
|
case eICColor_WebUnreadColor: outICKey = kICWebUnreadColor; break;
|
|
|
|
|
|
|
|
|
|
case eICBoolean_WebUnderlineLinks: outICKey = kICWebUnderlineLinks; break;
|
|
|
|
|
case eICBoolean_UseFTPProxy: outICKey = kICUseFTPProxy; break;
|
|
|
|
|
case eICBoolean_UsePassiveFTP: outICKey = kICUsePassiveFTP; break;
|
|
|
|
|
case eICBoolean_UseHTTPProxy: outICKey = kICUseHTTPProxy; break;
|
|
|
|
|
case eICBoolean_NewMailDialog: outICKey = kICNewMailDialog; break;
|
|
|
|
|
case eICBoolean_NewMailFlashIcon: outICKey = kICNewMailFlashIcon; break;
|
|
|
|
|
case eICBoolean_NewMailPlaySound: outICKey = kICNewMailPlaySound; break;
|
|
|
|
|
case eICBoolean_UseGopherProxy: outICKey = kICUseGopherProxy; break;
|
|
|
|
|
case eICBoolean_UseSocks: outICKey = kICUseSocks; break;
|
|
|
|
|
|
|
|
|
|
case eICString_WWWHomePage: outICKey = kICWWWHomePage; break;
|
|
|
|
|
case eICString_WebSearchPagePrefs: outICKey = kICWebSearchPagePrefs; break;
|
|
|
|
|
case eICString_MacSearchHost: outICKey = kICMacSearchHost; break;
|
|
|
|
|
case eICString_FTPHost: outICKey = kICFTPHost; break;
|
|
|
|
|
case eICString_FTPProxyUser: outICKey = kICFTPProxyUser; break;
|
|
|
|
|
case eICString_FTPProxyAccount: outICKey = kICFTPProxyAccount; break;
|
|
|
|
|
case eICString_FTPProxyHost: outICKey = kICFTPProxyHost; break;
|
2002-12-04 00:00:45 +03:00
|
|
|
|
case eICString_FTPProxyPassword: outICKey = kICFTPProxyPassword; break;
|
2002-10-01 05:00:09 +04:00
|
|
|
|
case eICString_HTTPProxyHost: outICKey = kICHTTPProxyHost; break;
|
|
|
|
|
case eICString_LDAPSearchbase: outICKey = kICLDAPSearchbase; break;
|
|
|
|
|
case eICString_LDAPServer: outICKey = kICLDAPServer; break;
|
|
|
|
|
case eICString_SMTPHost: outICKey = kICSMTPHost; break;
|
|
|
|
|
case eICString_Email: outICKey = kICEmail; break;
|
|
|
|
|
case eICString_MailAccount: outICKey = kICMailAccount; break;
|
|
|
|
|
case eICString_MailPassword: outICKey = kICMailPassword; break;
|
|
|
|
|
case eICString_NewMailSoundName: outICKey = kICNewMailSoundName; break;
|
|
|
|
|
case eICString_NNTPHost: outICKey = kICNNTPHost; break;
|
|
|
|
|
case eICString_NewsAuthUsername: outICKey = kICNewsAuthUsername; break;
|
|
|
|
|
case eICString_NewsAuthPassword: outICKey = kICNewsAuthPassword; break;
|
|
|
|
|
case eICString_InfoMacPreferred: outICKey = kICInfoMacPreferred; break;
|
|
|
|
|
case eICString_Organization: outICKey = kICOrganization; break;
|
|
|
|
|
case eICString_QuotingString: outICKey = kICQuotingString; break;
|
|
|
|
|
case eICString_RealName: outICKey = kICRealName; break;
|
|
|
|
|
case eICString_FingerHost: outICKey = kICFingerHost; break;
|
|
|
|
|
case eICString_GopherHost: outICKey = kICGopherHost; break;
|
|
|
|
|
case eICString_GopherProxy: outICKey = kICGopherProxy; break;
|
|
|
|
|
case eICString_SocksHost: outICKey = kICSocksHost; break;
|
|
|
|
|
case eICString_TelnetHost: outICKey = kICTelnetHost; break;
|
|
|
|
|
case eICString_IRCHost: outICKey = kICIRCHost; break;
|
|
|
|
|
case eICString_UMichPreferred: outICKey = kICUMichPreferred; break;
|
|
|
|
|
case eICString_WAISGateway: outICKey = kICWAISGateway; break;
|
|
|
|
|
case eICString_WhoisHost: outICKey = kICWhoisHost; break;
|
|
|
|
|
case eICString_PhHost: outICKey = kICPhHost; break;
|
|
|
|
|
case eICString_NTPHost: outICKey = kICNTPHost; break;
|
|
|
|
|
case eICString_ArchiePreferred: outICKey = kICArchiePreferred; break;
|
2001-03-28 17:56:19 +04:00
|
|
|
|
|
2002-10-01 05:00:09 +04:00
|
|
|
|
case eICText_MailHeaders: outICKey = kICMailHeaders; break;
|
|
|
|
|
case eICText_Signature: outICKey = kICSignature; break;
|
|
|
|
|
case eICText_NewsHeaders: outICKey = kICNewsHeaders; break;
|
|
|
|
|
case eICText_SnailMailAddress: outICKey = kICSnailMailAddress; break;
|
|
|
|
|
case eICText_Plan: outICKey = kICPlan; break;
|
2001-03-28 17:56:19 +04:00
|
|
|
|
|
|
|
|
|
default:
|
2002-10-01 09:27:15 +04:00
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
2001-03-28 17:56:19 +04:00
|
|
|
|
}
|
2002-10-01 09:27:15 +04:00
|
|
|
|
return rv;
|
2001-03-28 17:56:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult nsInternetConfigService::GetICPreference(PRUint32 inKey,
|
|
|
|
|
void *outData, long *ioSize)
|
|
|
|
|
{
|
2002-10-01 05:00:09 +04:00
|
|
|
|
const unsigned char *icKey;
|
2002-10-01 09:27:15 +04:00
|
|
|
|
nsresult rv = GetICKeyPascalString(inKey, icKey);
|
|
|
|
|
if (rv == NS_OK)
|
|
|
|
|
{
|
|
|
|
|
ICInstance instance = nsInternetConfig::GetInstance();
|
|
|
|
|
if (instance)
|
|
|
|
|
{
|
|
|
|
|
OSStatus err;
|
|
|
|
|
ICAttr junk;
|
|
|
|
|
err = ::ICGetPref(instance, icKey, &junk, outData, ioSize);
|
|
|
|
|
if (err != noErr)
|
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
return rv;
|
2001-03-28 17:56:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-10-01 09:27:15 +04:00
|
|
|
|
NS_IMETHODIMP nsInternetConfigService::GetString(PRUint32 inKey, nsACString& value)
|
2001-03-28 17:56:19 +04:00
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
long size = 256;
|
|
|
|
|
char buffer[256];
|
|
|
|
|
nsresult rv = GetICPreference(inKey, (void *)&buffer, &size);
|
|
|
|
|
if (rv == NS_OK)
|
|
|
|
|
{
|
|
|
|
|
if (size == 0)
|
|
|
|
|
{
|
|
|
|
|
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]);
|
2001-03-28 17:56:19 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-10-01 09:27:15 +04:00
|
|
|
|
return rv;
|
2001-03-28 17:56:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsInternetConfigService::GetColor(PRUint32 inKey, PRUint32 *outColor)
|
|
|
|
|
{
|
2002-10-01 05:00:09 +04:00
|
|
|
|
// We're 'borrowing' this macro from nscolor.h so that uriloader doesn't depend on gfx.
|
|
|
|
|
// Make a color out of r,g,b values. This assumes that the r,g,b values are
|
|
|
|
|
// properly constrained to 0-255. This also assumes that a is 255.
|
|
|
|
|
|
|
|
|
|
#define MAKE_NS_RGB(_r,_g,_b) \
|
|
|
|
|
((PRUint32) ((255 << 24) | ((_b)<<16) | ((_g)<<8) | (_r)))
|
|
|
|
|
|
2002-10-01 09:27:15 +04:00
|
|
|
|
RGBColor buffer;
|
|
|
|
|
long size = sizeof(RGBColor);
|
|
|
|
|
nsresult rv = GetICPreference(inKey, &buffer, &size);
|
|
|
|
|
if (rv == NS_OK)
|
|
|
|
|
{
|
|
|
|
|
if (size != sizeof(RGBColor))
|
|
|
|
|
{ // 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);
|
2002-09-27 03:38:08 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-10-01 09:27:15 +04:00
|
|
|
|
return rv;
|
2001-03-28 17:56:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsInternetConfigService::GetBoolean(PRUint32 inKey, PRBool *outFlag)
|
|
|
|
|
{
|
2002-10-01 09:27:15 +04:00
|
|
|
|
Boolean buffer;
|
|
|
|
|
long size = sizeof(Boolean);
|
|
|
|
|
nsresult rv = GetICPreference(inKey, (void *)&buffer, &size);
|
|
|
|
|
if (rv == NS_OK)
|
|
|
|
|
{
|
|
|
|
|
if ((size_t)size < sizeof(Boolean))
|
2001-03-28 17:56:19 +04:00
|
|
|
|
*outFlag = PR_FALSE; // default to false if we didn't get the right amount of data
|
2002-10-01 09:27:15 +04:00
|
|
|
|
else
|
|
|
|
|
*outFlag = buffer;
|
2001-03-28 17:56:19 +04:00
|
|
|
|
}
|
2002-10-01 09:27:15 +04:00
|
|
|
|
return rv;
|
2000-09-07 01:14:03 +04:00
|
|
|
|
}
|