зеркало из https://github.com/mozilla/pjs.git
rename files to .mm. b=419390,419392 r/sr=roc
This commit is contained in:
Родитель
e667436870
Коммит
0e73d615b2
|
@ -54,7 +54,7 @@ else
|
|||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
OSDIR = win
|
||||
else
|
||||
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
OSDIR = mac
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
|
||||
|
@ -92,19 +92,18 @@ ifdef MOZ_PHOENIX
|
|||
REQUIRES += toolkitcomps
|
||||
endif
|
||||
|
||||
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
REQUIRES += windowwatcher \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
OSHELPER = nsOSHelperAppService.cpp
|
||||
|
||||
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
OSHELPER += nsInternetConfig.cpp \
|
||||
nsInternetConfigService.cpp \
|
||||
nsMIMEInfoMac.cpp \
|
||||
nsLocalHandlerAppMac.cpp \
|
||||
CMMSRCS = nsOSHelperAppService.mm \
|
||||
nsInternetConfig.mm \
|
||||
nsInternetConfigService.mm \
|
||||
nsMIMEInfoMac.mm \
|
||||
nsLocalHandlerAppMac.mm \
|
||||
$(NULL)
|
||||
else
|
||||
OSHELPER = nsOSHelperAppService.cpp
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDES = -I$(srcdir)
|
||||
|
@ -141,7 +140,7 @@ XPIDLSRCS = \
|
|||
nsIHandlerService.idl \
|
||||
$(NULL)
|
||||
|
||||
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
XPIDLSRCS += nsIInternetConfigService.idl
|
||||
endif
|
||||
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
/* -*- 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 Mozilla Communicator client code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 "nsInternetConfig.h"
|
||||
#include "nsString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
#include <Processes.h>
|
||||
ICInstance nsInternetConfig::sInstance = NULL;
|
||||
long nsInternetConfig::sSeed = 0;
|
||||
PRInt32 nsInternetConfig::sRefCount = 0;
|
||||
|
||||
|
||||
|
||||
static OSType GetAppCreatorCode()
|
||||
{
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess } ;
|
||||
ProcessInfoRec procInfo;
|
||||
|
||||
procInfo.processInfoLength = sizeof(ProcessInfoRec);
|
||||
procInfo.processName = nsnull;
|
||||
procInfo.processAppSpec = nsnull;
|
||||
|
||||
GetProcessInformation(&psn, &procInfo);
|
||||
return procInfo.processSignature;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ICInstance nsInternetConfig::GetInstance()
|
||||
{
|
||||
if ( !sInstance )
|
||||
{
|
||||
OSStatus err;
|
||||
if ((long)ICStart == kUnresolvedCFragSymbolAddress )
|
||||
return sInstance;
|
||||
|
||||
|
||||
OSType creator = GetAppCreatorCode();
|
||||
err = ::ICStart( &sInstance, creator );
|
||||
if ( err != noErr )
|
||||
{
|
||||
::ICStop( sInstance );
|
||||
}
|
||||
else
|
||||
{
|
||||
::ICGetSeed( sInstance, &sSeed );
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
PRBool nsInternetConfig::HasSeedChanged()
|
||||
{
|
||||
ICInstance instance = nsInternetConfig::GetInstance();
|
||||
if ( instance )
|
||||
{
|
||||
long newSeed = 0;
|
||||
::ICGetSeed( sInstance, &newSeed );
|
||||
if ( newSeed != sSeed )
|
||||
{
|
||||
sSeed = newSeed;
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsInternetConfig::nsInternetConfig()
|
||||
{
|
||||
sRefCount++;
|
||||
}
|
||||
|
||||
nsInternetConfig::~nsInternetConfig()
|
||||
{
|
||||
sRefCount--;
|
||||
if ( sRefCount == 0 && sInstance)
|
||||
{
|
||||
::ICStop( sInstance );
|
||||
sInstance = NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,652 @@
|
|||
/* -*- 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 Mozilla Communicator client code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Steve Dagley <sdagley@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 "nsInternetConfigService.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIMIMEInfo.h"
|
||||
#include "nsMIMEInfoMac.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsString.h"
|
||||
#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>
|
||||
|
||||
|
||||
// helper converter function.....
|
||||
static void ConvertCharStringToStr255(const char* inString, Str255& outString)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/* Define Class IDs */
|
||||
|
||||
nsInternetConfigService::nsInternetConfigService()
|
||||
{
|
||||
}
|
||||
|
||||
nsInternetConfigService::~nsInternetConfigService()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Implement the nsISupports methods...
|
||||
*/
|
||||
NS_IMPL_ISUPPORTS1(nsInternetConfigService, nsIInternetConfigService)
|
||||
|
||||
// void LaunchURL (in string url);
|
||||
// Given a url string, call ICLaunchURL using url
|
||||
// Under OS X use LaunchServices instead of IC
|
||||
NS_IMETHODIMP nsInternetConfigService::LaunchURL(const char *url)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
CFURLRef myURLRef = ::CFURLCreateWithBytes(
|
||||
kCFAllocatorDefault,
|
||||
(const UInt8*)url,
|
||||
strlen(url),
|
||||
kCFStringEncodingUTF8, NULL);
|
||||
if (myURLRef)
|
||||
{
|
||||
rv = ::LSOpenCFURLRef(myURLRef, NULL);
|
||||
::CFRelease(myURLRef);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// 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 hasProtocolHandler (in string protocol); */
|
||||
// returns NS_ERROR_NOT_AVAILABLE if the current application is registered
|
||||
// as the protocol handler for the given protocol
|
||||
NS_IMETHODIMP nsInternetConfigService::HasProtocolHandler(const char *protocol, PRBool *_retval)
|
||||
{
|
||||
*_retval = PR_FALSE; // presume the OS doesn't have a handler
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// 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)
|
||||
nsCAutoString scheme(protocol);
|
||||
scheme += ":";
|
||||
CFURLRef myURLRef = ::CFURLCreateWithBytes(
|
||||
kCFAllocatorDefault,
|
||||
(const UInt8 *)scheme.get(),
|
||||
scheme.Length(),
|
||||
kCFStringEncodingUTF8, NULL);
|
||||
if (myURLRef)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
::CFRelease(myURLRef);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
ICInstance inst = nsInternetConfig::GetInstance();
|
||||
OSStatus err = noErr;
|
||||
ICAttr attr;
|
||||
Handle prefH;
|
||||
PRBool domimecheck = PR_TRUE;
|
||||
PRBool gotmatch = PR_FALSE;
|
||||
ICMapEntry ent;
|
||||
|
||||
// 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)
|
||||
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;
|
||||
for (long i = 1; i <= count; ++i)
|
||||
{
|
||||
err = ::ICGetIndMapEntry(inst, prefH, i, &pos, &ent);
|
||||
if (err == noErr)
|
||||
{
|
||||
// first, do mime type check
|
||||
if (domimecheck)
|
||||
{
|
||||
nsCAutoString temp((char *)&ent.MIMEType[1], (int)ent.MIMEType[0]);
|
||||
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
|
||||
if (ent.extension[0]) // check for non-empty pascal string
|
||||
{
|
||||
nsCAutoString temp((char *)&ent.extension[1], (int)ent.extension[0]);
|
||||
if (temp.EqualsIgnoreCase(fileextension))
|
||||
{
|
||||
// mime type and file extension match, we're outta here
|
||||
gotmatch = PR_TRUE;
|
||||
// copy over ICMapEntry
|
||||
*entry = ent;
|
||||
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?
|
||||
gotmatch = PR_TRUE;
|
||||
// copy over ICMapEntry
|
||||
*entry = ent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
::DisposeHandle(prefH);
|
||||
}
|
||||
else
|
||||
{
|
||||
err = memFullErr;
|
||||
}
|
||||
err = ::ICEnd(inst);
|
||||
if (err == noErr && gotmatch == PR_FALSE)
|
||||
{
|
||||
err = fnfErr; // return SOME kind of error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (err != noErr)
|
||||
return NS_ERROR_FAILURE;
|
||||
else
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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
|
||||
nsresult rv = NS_OK;
|
||||
nsRefPtr<nsMIMEInfoMac> info (new nsMIMEInfoMac());
|
||||
if (info)
|
||||
{
|
||||
nsCAutoString mimetype ((char *)&entry.MIMEType[1], entry.MIMEType[0]);
|
||||
// check if entry.MIMEType is empty, if so, set mime type to APPLICATION_OCTET_STREAM
|
||||
if (entry.MIMEType[0])
|
||||
info->SetMIMEType(mimetype);
|
||||
else
|
||||
{ // 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(NS_LITERAL_CSTRING(TEXT_PLAIN));
|
||||
else
|
||||
info->SetMIMEType(NS_LITERAL_CSTRING(APPLICATION_OCTET_STREAM));
|
||||
}
|
||||
|
||||
// convert entry.extension which is a Str255
|
||||
// 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);
|
||||
info->AppendExtension(temp);
|
||||
info->SetMacType(entry.fileType);
|
||||
info->SetMacCreator(entry.fileCreator);
|
||||
temp.Assign((char *) &entry.entryName[1], entry.entryName[0]);
|
||||
info->SetDescription(NS_ConvertASCIItoUTF16(temp));
|
||||
|
||||
temp.Assign((char *) &entry.postAppName[1], entry.postAppName[0]);
|
||||
info->SetDefaultDescription(NS_ConvertASCIItoUTF16(temp));
|
||||
|
||||
if (entry.flags & kICMapPostMask)
|
||||
{
|
||||
// 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)
|
||||
info->SetDefaultApplication(nsfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
else // we failed to allocate the info object...
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* void FillInMIMEInfo (in string mimetype, in string fileExtension, out nsIMIMEInfo mimeinfo); */
|
||||
NS_IMETHODIMP nsInternetConfigService::FillInMIMEInfo(const char *mimetype, const char * aFileExtension, nsIMIMEInfo **mimeinfo)
|
||||
{
|
||||
nsresult rv;
|
||||
ICMapEntry entry;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(mimeinfo);
|
||||
*mimeinfo = nsnull;
|
||||
|
||||
if (aFileExtension && *aFileExtension)
|
||||
{
|
||||
nsCAutoString fileExtension;
|
||||
fileExtension.Assign(".");
|
||||
fileExtension.Append(aFileExtension);
|
||||
rv = GetMappingForMIMEType(mimetype, fileExtension.get(), &entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = GetMappingForMIMEType(mimetype, nsnull, &entry);
|
||||
}
|
||||
|
||||
if (rv == NS_OK)
|
||||
rv = FillMIMEInfoForICEntry(entry, mimeinfo);
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromExtension(const char *aFileExt, nsIMIMEInfo **_retval)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
ICInstance instance = nsInternetConfig::GetInstance();
|
||||
if (instance)
|
||||
{
|
||||
nsCAutoString filename("foobar.");
|
||||
filename += aFileExt;
|
||||
Str255 pFileName;
|
||||
ConvertCharStringToStr255(filename.get(), pFileName);
|
||||
ICMapEntry entry;
|
||||
OSStatus err = ::ICMapFilename(instance, pFileName, &entry);
|
||||
if (err == noErr)
|
||||
{
|
||||
rv = FillMIMEInfoForICEntry(entry, _retval);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsInternetConfigService::GetMIMEInfoFromTypeCreator(PRUint32 aType, PRUint32 aCreator, const char *aFileExt, nsIMIMEInfo **_retval)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
ICInstance instance = nsInternetConfig::GetInstance();
|
||||
if (instance)
|
||||
{
|
||||
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);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsInternetConfigService::GetFileMappingFlags(FSSpec* fsspec, PRBool lookupByExtensionFirst, PRInt32 *_retval)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
OSStatus err = noErr;
|
||||
|
||||
NS_ENSURE_ARG(_retval);
|
||||
*_retval = -1;
|
||||
|
||||
ICInstance instance = nsInternetConfig::GetInstance();
|
||||
if (instance)
|
||||
{
|
||||
ICMapEntry entry;
|
||||
|
||||
if (lookupByExtensionFirst)
|
||||
err = ::ICMapFilename(instance, fsspec->name, &entry);
|
||||
|
||||
if (!lookupByExtensionFirst || err != noErr)
|
||||
{
|
||||
FInfo info;
|
||||
err = FSpGetFInfo(fsspec, &info);
|
||||
if (err == noErr)
|
||||
err = ::ICMapTypeCreator(instance, info.fdType, info.fdCreator, fsspec->name, &entry);
|
||||
}
|
||||
|
||||
if (err == noErr)
|
||||
*_retval = entry.flags;
|
||||
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/* void GetDownloadFolder (out FSSpec fsspec); */
|
||||
NS_IMETHODIMP nsInternetConfigService::GetDownloadFolder(FSSpec *fsspec)
|
||||
{
|
||||
ICInstance inst = nsInternetConfig::GetInstance();
|
||||
OSStatus err;
|
||||
Handle prefH;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
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)
|
||||
{
|
||||
ICAttr attr;
|
||||
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;
|
||||
}
|
||||
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
|
||||
FSSpec tempSpec = (*(ICFileSpecHandle)prefH)->fss;
|
||||
err = ::FSMakeFSSpec(tempSpec.vRefNum, tempSpec.parID, tempSpec.name, fsspec);
|
||||
if (err == noErr)
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Best not to leave that handle laying around
|
||||
DisposeHandle(prefH);
|
||||
}
|
||||
err = ::ICEnd(inst);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsInternetConfigService::GetICKeyPascalString(PRUint32 inIndex, const unsigned char*& outICKey)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
switch (inIndex)
|
||||
{
|
||||
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;
|
||||
case eICString_FTPProxyPassword: outICKey = kICFTPProxyPassword; break;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
default:
|
||||
rv = NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsInternetConfigService::GetICPreference(PRUint32 inKey,
|
||||
void *outData, long *ioSize)
|
||||
{
|
||||
const unsigned char *icKey;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsInternetConfigService::GetString(PRUint32 inKey, nsACString& value)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsInternetConfigService::GetColor(PRUint32 inKey, PRUint32 *outColor)
|
||||
{
|
||||
// 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)))
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsInternetConfigService::GetBoolean(PRUint32 inKey, PRBool *outFlag)
|
||||
{
|
||||
Boolean buffer;
|
||||
long size = sizeof(Boolean);
|
||||
nsresult rv = GetICPreference(inKey, (void *)&buffer, &size);
|
||||
if (rv == NS_OK)
|
||||
{
|
||||
if ((size_t)size < sizeof(Boolean))
|
||||
*outFlag = PR_FALSE; // default to false if we didn't get the right amount of data
|
||||
else
|
||||
*outFlag = buffer;
|
||||
}
|
||||
return rv;
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/* ***** 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 Mozilla code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* the Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Dan Mosedale <dmose@mozilla.org>
|
||||
*
|
||||
* 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 <LaunchServices.h>
|
||||
|
||||
#include "nsLocalHandlerAppMac.h"
|
||||
#include "nsILocalFileMac.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
/**
|
||||
* mostly copy/pasted from nsMacShellService.cpp (which is in browser/,
|
||||
* so we can't depend on it here). This code probably really wants to live
|
||||
* somewhere more central (see bug 389922).
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsLocalHandlerAppMac::LaunchWithURI(nsIURI *aURI,
|
||||
nsIInterfaceRequestor *aWindowContext)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(mExecutable, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
CFURLRef appURL;
|
||||
rv = lfm->GetCFURL(&appURL);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCAutoString uriSpec;
|
||||
aURI->GetSpec(uriSpec);
|
||||
|
||||
const UInt8* uriString = reinterpret_cast<const UInt8*>(uriSpec.get());
|
||||
CFURLRef uri = ::CFURLCreateWithBytes(NULL, uriString, uriSpec.Length(),
|
||||
kCFStringEncodingUTF8, NULL);
|
||||
if (!uri) {
|
||||
::CFRelease(appURL);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
CFArrayRef uris = ::CFArrayCreate(NULL, reinterpret_cast<const void**>(&uri),
|
||||
1, NULL);
|
||||
if (!uris) {
|
||||
::CFRelease(uri);
|
||||
::CFRelease(appURL);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
LSLaunchURLSpec launchSpec;
|
||||
launchSpec.appURL = appURL;
|
||||
launchSpec.itemURLs = uris;
|
||||
launchSpec.passThruParams = NULL;
|
||||
launchSpec.launchFlags = kLSLaunchDefaults;
|
||||
launchSpec.asyncRefCon = NULL;
|
||||
|
||||
OSErr err = ::LSOpenFromURLSpec(&launchSpec, NULL);
|
||||
|
||||
::CFRelease(uris);
|
||||
::CFRelease(uri);
|
||||
::CFRelease(appURL);
|
||||
|
||||
return err != noErr ? NS_ERROR_FAILURE : NS_OK;
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/* -*- Mode: C++; tab-width: 3; 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 the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications, Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1999
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Scott MacGregor <mscott@netscape.com>
|
||||
* Christian Biesinger <cbiesinger@web.de>
|
||||
* Dan Mosedale <dmose@mozilla.org>
|
||||
* Stan Shebs <stanshebs@earthlink.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 <LaunchServices.h>
|
||||
|
||||
#include "nsMIMEInfoMac.h"
|
||||
#include "nsILocalFileMac.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsIInternetConfigService.h"
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoMac::LaunchWithFile(nsIFile *aFile)
|
||||
{
|
||||
nsCOMPtr<nsIFile> application;
|
||||
nsresult rv;
|
||||
|
||||
NS_ASSERTION(mClass == eMIMEInfo, "only MIME infos are currently allowed"
|
||||
"to pass content by value");
|
||||
|
||||
if (mPreferredAction == useHelperApp) {
|
||||
|
||||
// we don't yet support passing content by value (rather than reference)
|
||||
// to web apps. at some point, we will probably want to.
|
||||
nsCOMPtr<nsILocalHandlerApp> localHandlerApp =
|
||||
do_QueryInterface(mPreferredApplication, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = localHandlerApp->GetExecutable(getter_AddRefs(application));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
} else if (mPreferredAction == useSystemDefault) {
|
||||
application = mDefaultApplication;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// if we've already got an app, just QI so we have the launchWithDoc method
|
||||
nsCOMPtr<nsILocalFileMac> app;
|
||||
if (application) {
|
||||
app = do_QueryInterface(application, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
} else {
|
||||
// otherwise ask LaunchServices for an app directly
|
||||
nsCOMPtr<nsILocalFileMac> tempFile = do_QueryInterface(aFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
FSRef tempFileRef;
|
||||
tempFile->GetFSRef(&tempFileRef);
|
||||
|
||||
FSRef appFSRef;
|
||||
if (::LSGetApplicationForItem(&tempFileRef, kLSRolesAll, &appFSRef, nsnull) == noErr)
|
||||
{
|
||||
app = (do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
if (!app) return NS_ERROR_FAILURE;
|
||||
app->InitWithFSRef(&appFSRef);
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aFile);
|
||||
return app->LaunchWithDoc(localFile, PR_FALSE);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMIMEInfoMac::LoadUriInternal(nsIURI *aURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCAutoString uri;
|
||||
aURI->GetSpec(uri);
|
||||
if (!uri.IsEmpty()) {
|
||||
nsCOMPtr<nsIInternetConfigService> icService =
|
||||
do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID);
|
||||
if (icService)
|
||||
rv = icService->LaunchURL(uri.get());
|
||||
}
|
||||
return rv;
|
||||
}
|
|
@ -0,0 +1,379 @@
|
|||
/* -*- Mode: C++; tab-width: 3; 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 the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications, Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1999
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Scott MacGregor <mscott@netscape.com>
|
||||
* Dan Mosedale <dmose@mozilla.org>
|
||||
* Stan Shebs <stanshebs@earthlink.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 "nsOSHelperAppService.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsILocalFileMac.h"
|
||||
#include "nsMimeTypes.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIPromptService.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsMIMEInfoMac.h"
|
||||
|
||||
#include "nsIInternetConfigService.h"
|
||||
#include "nsEmbedCID.h"
|
||||
#include <LaunchServices.h>
|
||||
|
||||
// chrome URL's
|
||||
#define HELPERAPPLAUNCHER_BUNDLE_URL "chrome://global/locale/helperAppLauncher.properties"
|
||||
#define BRAND_BUNDLE_URL "chrome://branding/locale/brand.properties"
|
||||
|
||||
extern "C" {
|
||||
// Returns the CFURL for application currently set as the default opener for
|
||||
// the given URL scheme. appURL must be released by the caller.
|
||||
extern OSStatus _LSCopyDefaultSchemeHandlerURL(CFStringRef scheme,
|
||||
CFURLRef *appURL);
|
||||
}
|
||||
|
||||
nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
|
||||
{
|
||||
}
|
||||
|
||||
nsOSHelperAppService::~nsOSHelperAppService()
|
||||
{}
|
||||
|
||||
nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists)
|
||||
{
|
||||
// look up the protocol scheme in Internet Config....if we find a match then we have a handler for it...
|
||||
*aHandlerExists = PR_FALSE;
|
||||
// ask the internet config service to look it up for us...
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
|
||||
if (icService)
|
||||
{
|
||||
rv = icService->HasProtocolHandler(aProtocolScheme, aHandlerExists);
|
||||
if (rv == NS_ERROR_NOT_AVAILABLE)
|
||||
{
|
||||
// There is a protocol handler, but it's the current app! We can't let
|
||||
// the current app handle the protocol, as that'll get us into an infinite
|
||||
// loop, so we just pretend there's no protocol handler available.
|
||||
*aHandlerExists = PR_FALSE;
|
||||
rv = NS_OK;
|
||||
|
||||
// FIXME: instead of pretending there's no protocol handler available,
|
||||
// let the caller know about the loop so it can deal with the problem
|
||||
// (i.e. either fix it automatically, if there's some way to do that,
|
||||
// or just provide the user with options for fixing it manually).
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
CFStringRef schemeCFString =
|
||||
::CFStringCreateWithBytes(kCFAllocatorDefault,
|
||||
(const UInt8 *)PromiseFlatCString(aScheme).get(),
|
||||
aScheme.Length(),
|
||||
kCFStringEncodingUTF8,
|
||||
false);
|
||||
if (schemeCFString) {
|
||||
// Since the public API (LSGetApplicationForURL) fails every now and then,
|
||||
// we're using undocumented _LSCopyDefaultSchemeHandlerURL
|
||||
CFURLRef handlerBundleURL;
|
||||
OSStatus err = ::_LSCopyDefaultSchemeHandlerURL(schemeCFString,
|
||||
&handlerBundleURL);
|
||||
if (err == noErr) {
|
||||
CFBundleRef handlerBundle = ::CFBundleCreate(NULL, handlerBundleURL);
|
||||
if (handlerBundle) {
|
||||
// Get the human-readable name of the default handler bundle
|
||||
CFStringRef bundleName =
|
||||
(CFStringRef)::CFBundleGetValueForInfoDictionaryKey(handlerBundle,
|
||||
kCFBundleNameKey);
|
||||
if (bundleName) {
|
||||
nsAutoTArray<UniChar, 255> buffer;
|
||||
CFIndex bundleNameLength = ::CFStringGetLength(bundleName);
|
||||
buffer.SetLength(bundleNameLength);
|
||||
::CFStringGetCharacters(bundleName, CFRangeMake(0, bundleNameLength),
|
||||
buffer.Elements());
|
||||
_retval.Assign(buffer.Elements(), bundleNameLength);
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
::CFRelease(handlerBundle);
|
||||
}
|
||||
|
||||
::CFRelease(handlerBundleURL);
|
||||
}
|
||||
|
||||
::CFRelease(schemeCFString);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * aPlatformAppPath, nsIFile ** aFile)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILocalFileMac> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
CFURLRef pathAsCFURL;
|
||||
CFStringRef pathAsCFString = ::CFStringCreateWithCharacters(NULL,
|
||||
aPlatformAppPath,
|
||||
nsCRT::strlen(aPlatformAppPath));
|
||||
if (!pathAsCFString)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (::CFStringGetCharacterAtIndex(pathAsCFString, 0) == '/') {
|
||||
// we have a Posix path
|
||||
pathAsCFURL = ::CFURLCreateWithFileSystemPath(nsnull, pathAsCFString,
|
||||
kCFURLPOSIXPathStyle, PR_FALSE);
|
||||
if (!pathAsCFURL) {
|
||||
::CFRelease(pathAsCFString);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if it doesn't start with a / it's not an absolute Posix path
|
||||
// let's check if it's a HFS path left over from old preferences
|
||||
|
||||
// If it starts with a ':' char, it's not an absolute HFS path
|
||||
// so bail for that, and also if it's empty
|
||||
if (::CFStringGetLength(pathAsCFString) == 0 ||
|
||||
::CFStringGetCharacterAtIndex(pathAsCFString, 0) == ':')
|
||||
{
|
||||
::CFRelease(pathAsCFString);
|
||||
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
|
||||
}
|
||||
|
||||
pathAsCFURL = ::CFURLCreateWithFileSystemPath(nsnull, pathAsCFString,
|
||||
kCFURLHFSPathStyle, PR_FALSE);
|
||||
if (!pathAsCFURL) {
|
||||
::CFRelease(pathAsCFString);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
rv = localFile->InitWithCFURL(pathAsCFURL);
|
||||
::CFRelease(pathAsCFString);
|
||||
::CFRelease(pathAsCFURL);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
*aFile = localFile;
|
||||
NS_IF_ADDREF(*aFile);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
///////////////////////////
|
||||
// method overrides --> use internet config information for mime type lookup.
|
||||
///////////////////////////
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::GetFromTypeAndExtension(const nsACString& aType, const nsACString& aFileExt, nsIMIMEInfo ** aMIMEInfo)
|
||||
{
|
||||
// first, ask our base class....
|
||||
nsresult rv = nsExternalHelperAppService::GetFromTypeAndExtension(aType, aFileExt, aMIMEInfo);
|
||||
if (NS_SUCCEEDED(rv) && *aMIMEInfo)
|
||||
{
|
||||
UpdateCreatorInfo(*aMIMEInfo);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIMIMEInfo>
|
||||
nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
|
||||
const nsACString& aFileExt,
|
||||
PRBool * aFound)
|
||||
{
|
||||
nsIMIMEInfo* mimeInfo = nsnull;
|
||||
*aFound = PR_TRUE;
|
||||
|
||||
const nsCString& flatType = PromiseFlatCString(aMIMEType);
|
||||
const nsCString& flatExt = PromiseFlatCString(aFileExt);
|
||||
|
||||
// ask the internet config service to look it up for us...
|
||||
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
|
||||
PR_LOG(mLog, PR_LOG_DEBUG, ("Mac: HelperAppService lookup for type '%s' ext '%s' (IC: 0x%p)\n",
|
||||
flatType.get(), flatExt.get(), icService.get()));
|
||||
if (icService)
|
||||
{
|
||||
nsCOMPtr<nsIMIMEInfo> miByType, miByExt;
|
||||
if (!aMIMEType.IsEmpty())
|
||||
icService->FillInMIMEInfo(flatType.get(), flatExt.get(), getter_AddRefs(miByType));
|
||||
|
||||
PRBool hasDefault = PR_FALSE;
|
||||
if (miByType)
|
||||
miByType->GetHasDefaultHandler(&hasDefault);
|
||||
|
||||
if (!aFileExt.IsEmpty() && (!hasDefault || !miByType)) {
|
||||
icService->GetMIMEInfoFromExtension(flatExt.get(), getter_AddRefs(miByExt));
|
||||
if (miByExt && !aMIMEType.IsEmpty()) {
|
||||
// XXX see XXX comment below
|
||||
nsIMIMEInfo* pByExt = miByExt.get();
|
||||
nsMIMEInfoBase* byExt = static_cast<nsMIMEInfoBase*>(pByExt);
|
||||
byExt->SetMIMEType(aMIMEType);
|
||||
}
|
||||
}
|
||||
PR_LOG(mLog, PR_LOG_DEBUG, ("OS gave us: By Type: 0x%p By Ext: 0x%p type has default: %s\n",
|
||||
miByType.get(), miByExt.get(), hasDefault ? "true" : "false"));
|
||||
|
||||
// If we got two matches, and the type has no default app, copy default app
|
||||
if (!hasDefault && miByType && miByExt) {
|
||||
// IC currently always uses nsMIMEInfoBase-derived classes.
|
||||
// When it stops doing that, this code will need changing.
|
||||
// XXX This assumes that IC will give os an nsMIMEInfoBase. I'd use
|
||||
// dynamic_cast but that crashes.
|
||||
// XXX these pBy* variables are needed because .get() returns an
|
||||
// nsDerivedSafe thingy that can't be cast to nsMIMEInfoBase*
|
||||
nsIMIMEInfo* pByType = miByType.get();
|
||||
nsIMIMEInfo* pByExt = miByExt.get();
|
||||
nsMIMEInfoBase* byType = static_cast<nsMIMEInfoBase*>(pByType);
|
||||
nsMIMEInfoBase* byExt = static_cast<nsMIMEInfoBase*>(pByExt);
|
||||
if (!byType || !byExt) {
|
||||
NS_ERROR("IC gave us an nsIMIMEInfo that's no nsMIMEInfoBase! Fix nsOSHelperAppService.");
|
||||
return nsnull;
|
||||
}
|
||||
// Copy the attributes of miByType onto miByExt
|
||||
byType->CopyBasicDataTo(byExt);
|
||||
miByType = miByExt;
|
||||
}
|
||||
if (miByType)
|
||||
miByType.swap(mimeInfo);
|
||||
else if (miByExt)
|
||||
miByExt.swap(mimeInfo);
|
||||
}
|
||||
|
||||
if (!mimeInfo) {
|
||||
*aFound = PR_FALSE;
|
||||
PR_LOG(mLog, PR_LOG_DEBUG, ("Creating new mimeinfo\n"));
|
||||
// Create a Mac-specific MIME info so we can use Mac-specific members.
|
||||
nsMIMEInfoMac* mimeInfoMac = new nsMIMEInfoMac(aMIMEType);
|
||||
if (!mimeInfoMac)
|
||||
return nsnull;
|
||||
NS_ADDREF(mimeInfoMac);
|
||||
|
||||
if (!aFileExt.IsEmpty())
|
||||
mimeInfoMac->AppendExtension(aFileExt);
|
||||
|
||||
// Now see if Launch Services knows of an application that should be run for this type.
|
||||
OSStatus err;
|
||||
FSRef appFSRef;
|
||||
CFStringRef CFExt = ::CFStringCreateWithCString(NULL, flatExt.get(), kCFStringEncodingUTF8);
|
||||
err = ::LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator, CFExt,
|
||||
kLSRolesAll, &appFSRef, nsnull);
|
||||
if (err == noErr) {
|
||||
nsCOMPtr<nsILocalFileMac> app(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
if (!app) {
|
||||
::CFRelease(CFExt);
|
||||
NS_RELEASE(mimeInfoMac);
|
||||
return nsnull;
|
||||
}
|
||||
app->InitWithFSRef(&appFSRef);
|
||||
mimeInfoMac->SetDefaultApplication(app);
|
||||
PR_LOG(mLog, PR_LOG_DEBUG, ("LSGetApplicationForInfo found a default application\n"));
|
||||
} else {
|
||||
// Just leave the default application unset.
|
||||
PR_LOG(mLog, PR_LOG_DEBUG, ("LSGetApplicationForInfo returned error code %d; default application was not set\n", err));
|
||||
}
|
||||
mimeInfo = mimeInfoMac;
|
||||
::CFRelease(CFExt);
|
||||
}
|
||||
|
||||
return mimeInfo;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString &aScheme,
|
||||
PRBool *found,
|
||||
nsIHandlerInfo **_retval)
|
||||
{
|
||||
NS_ASSERTION(!aScheme.IsEmpty(), "No scheme was specified!");
|
||||
|
||||
nsresult rv = OSProtocolHandlerExists(nsPromiseFlatCString(aScheme).get(),
|
||||
found);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsMIMEInfoMac *handlerInfo =
|
||||
new nsMIMEInfoMac(aScheme, nsMIMEInfoBase::eProtocolInfo);
|
||||
NS_ENSURE_TRUE(handlerInfo, NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ADDREF(*_retval = handlerInfo);
|
||||
|
||||
if (!*found) {
|
||||
// Code that calls this requires an object regardless if the OS has
|
||||
// something for us, so we return the empty object.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoString desc;
|
||||
GetApplicationDescription(aScheme, desc);
|
||||
handlerInfo->SetDefaultDescription(desc);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// we never want to use a hard coded value for the creator and file type for the mac. always look these values up
|
||||
// from internet config.
|
||||
void nsOSHelperAppService::UpdateCreatorInfo(nsIMIMEInfo * aMIMEInfo)
|
||||
{
|
||||
PRUint32 macCreatorType;
|
||||
PRUint32 macFileType;
|
||||
aMIMEInfo->GetMacType(&macFileType);
|
||||
aMIMEInfo->GetMacCreator(&macCreatorType);
|
||||
|
||||
if (macFileType == 0 || macCreatorType == 0)
|
||||
{
|
||||
// okay these values haven't been initialized yet so fetch a mime object from internet config.
|
||||
nsCAutoString mimeType;
|
||||
aMIMEInfo->GetMIMEType(mimeType);
|
||||
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
|
||||
if (icService)
|
||||
{
|
||||
nsCOMPtr<nsIMIMEInfo> osMimeObject;
|
||||
icService->FillInMIMEInfo(mimeType.get(), nsnull, getter_AddRefs(osMimeObject));
|
||||
if (osMimeObject)
|
||||
{
|
||||
osMimeObject->GetMacType(&macFileType);
|
||||
osMimeObject->GetMacCreator(&macCreatorType);
|
||||
aMIMEInfo->SetMacCreator(macCreatorType);
|
||||
aMIMEInfo->SetMacType(macFileType);
|
||||
} // if we got an os object
|
||||
} // if we got the ic service
|
||||
} // if the creator or file type hasn't been initialized yet
|
||||
}
|
|
@ -57,7 +57,7 @@ MODULE_OPTIMIZE_FLAGS = -Os -fno-strict-aliasing
|
|||
endif
|
||||
endif
|
||||
|
||||
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
REQUIRES += macmorefiles
|
||||
endif
|
||||
|
||||
|
@ -91,8 +91,8 @@ endif
|
|||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
CPPSRCS += nsLocalFileOS2.cpp
|
||||
else
|
||||
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
CPPSRCS += nsLocalFileOSX.cpp
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
CMMSRCS = nsLocalFileOSX.mm
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
CPPSRCS += nsLocalFileWin.cpp
|
||||
|
@ -120,7 +120,7 @@ EXPORTS = \
|
|||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
EXPORTS += nsLocalFileOS2.h
|
||||
else
|
||||
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
EXPORTS += nsLocalFileOSX.h
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
|
@ -128,7 +128,7 @@ EXPORTS += nsLocalFileWin.h
|
|||
else
|
||||
EXPORTS += nsLocalFileUnix.h
|
||||
endif # windows
|
||||
endif # mac
|
||||
endif # cocoa
|
||||
endif # os2
|
||||
|
||||
XPIDLSRCS = \
|
||||
|
@ -161,9 +161,9 @@ XPIDLSRCS = \
|
|||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
XPIDLSRCS += nsILocalFileOS2.idl
|
||||
else
|
||||
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
XPIDLSRCS += nsILocalFileMac.idl
|
||||
endif # mac
|
||||
endif # cocoa
|
||||
endif # os2
|
||||
|
||||
SDK_XPIDLSRCS = \
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче