diff --git a/uriloader/exthandler/mac/nsInternetConfig.cpp b/uriloader/exthandler/mac/nsInternetConfig.cpp new file mode 100644 index 00000000000..480f6dca34d --- /dev/null +++ b/uriloader/exthandler/mac/nsInternetConfig.cpp @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsInternetConfig.h" +#include "nsString.h" +#include "nsDebug.h" +#include +#include +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 ) + { + ICError err; + if ((long)ICStart == kUnresolvedCFragSymbolAddress ) + return sInstance; + + + OSType creator = GetAppCreatorCode(); + err = ::ICStart( &sInstance, creator ); + if ( err != noErr ) + { + ::ICStop( sInstance ); + } + else + { + ::ICFindConfigFile( sInstance, 0 , nil ); + ::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; + } +} + + +nsresult nsInternetConfig::GetString( unsigned char* inKey, char** outString ) +{ + nsresult result = NS_ERROR_FAILURE; + ICInstance instance = nsInternetConfig::GetInstance(); + if ( instance ) + { + ICError err; + char buffer[256]; + ICAttr junk; + long size = 256; + err = ::ICGetPref( instance, inKey, &junk, buffer, &size ); + if ( err == noErr ) + { + // Buffer is a Pascal string + nsCString temp( &buffer[1], buffer[0] ); + *outString = temp.ToNewCString(); + result = NS_OK; + } + } + return result; +} \ No newline at end of file diff --git a/uriloader/exthandler/mac/nsInternetConfig.h b/uriloader/exthandler/mac/nsInternetConfig.h new file mode 100644 index 00000000000..462f1fd08f6 --- /dev/null +++ b/uriloader/exthandler/mac/nsInternetConfig.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ +#include "InternetConfig.h" +#include "PRTypes.h" +#include "nsError.h" + +class nsInternetConfig +{ +public: + nsInternetConfig(); + ~nsInternetConfig(); + nsresult GetString( unsigned char* inKey, char** outString ); + + static ICInstance GetInstance(); + static PRBool HasSeedChanged(); +private: + static ICInstance sInstance; + static long sSeed; + static PRInt32 sRefCount; +}; \ No newline at end of file diff --git a/uriloader/exthandler/mac/nsMacMIMEDataSource.cpp b/uriloader/exthandler/mac/nsMacMIMEDataSource.cpp new file mode 100644 index 00000000000..17deb9c8fe1 --- /dev/null +++ b/uriloader/exthandler/mac/nsMacMIMEDataSource.cpp @@ -0,0 +1,152 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsMacMIMEDataSource.h" +#include "nsString.h" +#include "MacTypes.h" +#include "InternetConfig.h" + +// Yumm +static void ConvertCharStringToStr255( char* inString, Str255& outString ) +{ + if ( inString == NULL ) + return; + PRInt32 len = nsCRT::strlen(inString); + NS_ASSERTION( len<= 255 , " String is too big"); + if ( len> 255 ) + { + len = 255; + + } + memcpy(&outString[1], inString, len); + outString[0] = len; +} + +static nsresult MakeMIMEInfo( ICMapEntry &entry, nsIMIMEInfo*& info ) +{ + // Create nsIMIMEInfo + nsresult rv = nsComponentManager::CreateInstance(NS_MIMEINFO_PROGID, nsnull, nsIMIMEInfo::GetIID(), &info ); + if ( NS_FAILED( rv ) ) + return rv; + // Stuff in the data; + info->SetMacCreator( entry.file_type ); + info->SetMacType( entry.file_creator); + + nsCString description( (char*)&entry.entry_name[1], entry.entry_name[0]); + nsString unicodeDescription; + unicodeDescription.AssignWithConversion ( description ); + info->SetDescription( unicodeDescription.GetUnicode() ); + + + nsCString mimetype((char*) &entry.MIME_type[1], entry.MIME_type[0] ); + info->SetMIMEType( mimetype.GetBuffer() ); + + // remove the . + nsCString extension((char*) &entry.extension[2], entry.extension[0]-1 ); + info->AppendExtension( extension.GetBuffer() ); + + return NS_OK; +} + +nsMacMIMEDataSource::nsMacMIMEDataSource() +{ + NS_INIT_REFCNT(); +} + +nsMacMIMEDataSource::~nsMacMIMEDataSource() +{ + +} + +NS_IMPL_ISUPPORTS1(nsMacMIMEDataSource,nsIMIMEDataSource); + +NS_IMETHODIMP nsMacMIMEDataSource::GetFromMIMEType(const char *aType, nsIMIMEInfo **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsMacMIMEDataSource::GetFromExtension(const char *aFileExt, nsIMIMEInfo **_retval) +{ + nsresult rv = NS_ERROR_FAILURE; + ICInstance instance = mIC.GetInstance(); + if ( instance ) + { + nsCString filename("foobar."); + filename+=aFileExt; + Str255 pFileName; + ConvertCharStringToStr255( filename, pFileName ); + ICMapEntry entry; + ICError err = ::ICMapFilename( instance, pFileName, &entry ); + if( err == noErr ) + { + rv = MakeMIMEInfo( entry, *_retval ); + } + } + + return rv; +} + +NS_IMETHODIMP nsMacMIMEDataSource::GetFromTypeCreator(PRUint32 aType, PRUint32 aCreator, const char *aFileExt, nsIMIMEInfo **_retval) +{ + nsresult rv = NS_ERROR_FAILURE; + ICInstance instance = mIC.GetInstance(); + if ( instance ) + { + nsCString filename("foobar."); + filename+=aFileExt; + Str255 pFileName; + ConvertCharStringToStr255( filename, pFileName ); + ICMapEntry entry; + ICError err = ::ICMapTypeCreator( instance, aType, aCreator, pFileName, &entry ); + if( err == noErr ) + { + rv = MakeMIMEInfo( entry, *_retval ); + } + } + return rv; +} + + +NS_IMETHODIMP nsMacMIMEDataSource::Add(nsIMIMEInfo *aInfo) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsMacMIMEDataSource::Remove(const char *aType) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsMacMIMEDataSource::GetEnumerator(nsISimpleEnumerator **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsMacMIMEDataSource::Serialize(void) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsMacMIMEDataSource::InitFromFile( nsIFile*) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} \ No newline at end of file diff --git a/uriloader/exthandler/mac/nsMacMIMEDataSource.h b/uriloader/exthandler/mac/nsMacMIMEDataSource.h new file mode 100644 index 00000000000..e381862e50d --- /dev/null +++ b/uriloader/exthandler/mac/nsMacMIMEDataSource.h @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ +#include "nsIMIMEDataSource.h" +#include "nsInternetConfig.h" + +#define NS_NATIVEMIMEDATASOURCE_CID \ +{ /* 95df6581-0001-11d4-a12b-a66ef662f0bc */ \ + 0x95df6581, \ + 0x0001, \ + 0x11d4, \ + {0xa1, 0x2b, 0xa6, 0x6e, 0xf6, 0x62, 0xf0, 0xbc} \ +} + +class nsMacMIMEDataSource: public nsIMIMEDataSource +{ +public: + nsMacMIMEDataSource(); + virtual ~nsMacMIMEDataSource(); + NS_DECL_ISUPPORTS + NS_DECL_NSIMIMEDATASOURCE + +private: + nsInternetConfig mIC; +}; \ No newline at end of file diff --git a/xpfe/appshell/src/nsInternetConfig.cpp b/xpfe/appshell/src/nsInternetConfig.cpp new file mode 100644 index 00000000000..480f6dca34d --- /dev/null +++ b/xpfe/appshell/src/nsInternetConfig.cpp @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsInternetConfig.h" +#include "nsString.h" +#include "nsDebug.h" +#include +#include +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 ) + { + ICError err; + if ((long)ICStart == kUnresolvedCFragSymbolAddress ) + return sInstance; + + + OSType creator = GetAppCreatorCode(); + err = ::ICStart( &sInstance, creator ); + if ( err != noErr ) + { + ::ICStop( sInstance ); + } + else + { + ::ICFindConfigFile( sInstance, 0 , nil ); + ::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; + } +} + + +nsresult nsInternetConfig::GetString( unsigned char* inKey, char** outString ) +{ + nsresult result = NS_ERROR_FAILURE; + ICInstance instance = nsInternetConfig::GetInstance(); + if ( instance ) + { + ICError err; + char buffer[256]; + ICAttr junk; + long size = 256; + err = ::ICGetPref( instance, inKey, &junk, buffer, &size ); + if ( err == noErr ) + { + // Buffer is a Pascal string + nsCString temp( &buffer[1], buffer[0] ); + *outString = temp.ToNewCString(); + result = NS_OK; + } + } + return result; +} \ No newline at end of file diff --git a/xpfe/appshell/src/nsInternetConfig.h b/xpfe/appshell/src/nsInternetConfig.h new file mode 100644 index 00000000000..462f1fd08f6 --- /dev/null +++ b/xpfe/appshell/src/nsInternetConfig.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ +#include "InternetConfig.h" +#include "PRTypes.h" +#include "nsError.h" + +class nsInternetConfig +{ +public: + nsInternetConfig(); + ~nsInternetConfig(); + nsresult GetString( unsigned char* inKey, char** outString ); + + static ICInstance GetInstance(); + static PRBool HasSeedChanged(); +private: + static ICInstance sInstance; + static long sSeed; + static PRInt32 sRefCount; +}; \ No newline at end of file diff --git a/xpfe/appshell/src/nsMacMIMEDataSource.cpp b/xpfe/appshell/src/nsMacMIMEDataSource.cpp new file mode 100644 index 00000000000..17deb9c8fe1 --- /dev/null +++ b/xpfe/appshell/src/nsMacMIMEDataSource.cpp @@ -0,0 +1,152 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsMacMIMEDataSource.h" +#include "nsString.h" +#include "MacTypes.h" +#include "InternetConfig.h" + +// Yumm +static void ConvertCharStringToStr255( char* inString, Str255& outString ) +{ + if ( inString == NULL ) + return; + PRInt32 len = nsCRT::strlen(inString); + NS_ASSERTION( len<= 255 , " String is too big"); + if ( len> 255 ) + { + len = 255; + + } + memcpy(&outString[1], inString, len); + outString[0] = len; +} + +static nsresult MakeMIMEInfo( ICMapEntry &entry, nsIMIMEInfo*& info ) +{ + // Create nsIMIMEInfo + nsresult rv = nsComponentManager::CreateInstance(NS_MIMEINFO_PROGID, nsnull, nsIMIMEInfo::GetIID(), &info ); + if ( NS_FAILED( rv ) ) + return rv; + // Stuff in the data; + info->SetMacCreator( entry.file_type ); + info->SetMacType( entry.file_creator); + + nsCString description( (char*)&entry.entry_name[1], entry.entry_name[0]); + nsString unicodeDescription; + unicodeDescription.AssignWithConversion ( description ); + info->SetDescription( unicodeDescription.GetUnicode() ); + + + nsCString mimetype((char*) &entry.MIME_type[1], entry.MIME_type[0] ); + info->SetMIMEType( mimetype.GetBuffer() ); + + // remove the . + nsCString extension((char*) &entry.extension[2], entry.extension[0]-1 ); + info->AppendExtension( extension.GetBuffer() ); + + return NS_OK; +} + +nsMacMIMEDataSource::nsMacMIMEDataSource() +{ + NS_INIT_REFCNT(); +} + +nsMacMIMEDataSource::~nsMacMIMEDataSource() +{ + +} + +NS_IMPL_ISUPPORTS1(nsMacMIMEDataSource,nsIMIMEDataSource); + +NS_IMETHODIMP nsMacMIMEDataSource::GetFromMIMEType(const char *aType, nsIMIMEInfo **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsMacMIMEDataSource::GetFromExtension(const char *aFileExt, nsIMIMEInfo **_retval) +{ + nsresult rv = NS_ERROR_FAILURE; + ICInstance instance = mIC.GetInstance(); + if ( instance ) + { + nsCString filename("foobar."); + filename+=aFileExt; + Str255 pFileName; + ConvertCharStringToStr255( filename, pFileName ); + ICMapEntry entry; + ICError err = ::ICMapFilename( instance, pFileName, &entry ); + if( err == noErr ) + { + rv = MakeMIMEInfo( entry, *_retval ); + } + } + + return rv; +} + +NS_IMETHODIMP nsMacMIMEDataSource::GetFromTypeCreator(PRUint32 aType, PRUint32 aCreator, const char *aFileExt, nsIMIMEInfo **_retval) +{ + nsresult rv = NS_ERROR_FAILURE; + ICInstance instance = mIC.GetInstance(); + if ( instance ) + { + nsCString filename("foobar."); + filename+=aFileExt; + Str255 pFileName; + ConvertCharStringToStr255( filename, pFileName ); + ICMapEntry entry; + ICError err = ::ICMapTypeCreator( instance, aType, aCreator, pFileName, &entry ); + if( err == noErr ) + { + rv = MakeMIMEInfo( entry, *_retval ); + } + } + return rv; +} + + +NS_IMETHODIMP nsMacMIMEDataSource::Add(nsIMIMEInfo *aInfo) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsMacMIMEDataSource::Remove(const char *aType) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsMacMIMEDataSource::GetEnumerator(nsISimpleEnumerator **_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsMacMIMEDataSource::Serialize(void) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsMacMIMEDataSource::InitFromFile( nsIFile*) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} \ No newline at end of file diff --git a/xpfe/appshell/src/nsMacMIMEDataSource.h b/xpfe/appshell/src/nsMacMIMEDataSource.h new file mode 100644 index 00000000000..e381862e50d --- /dev/null +++ b/xpfe/appshell/src/nsMacMIMEDataSource.h @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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 Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ +#include "nsIMIMEDataSource.h" +#include "nsInternetConfig.h" + +#define NS_NATIVEMIMEDATASOURCE_CID \ +{ /* 95df6581-0001-11d4-a12b-a66ef662f0bc */ \ + 0x95df6581, \ + 0x0001, \ + 0x11d4, \ + {0xa1, 0x2b, 0xa6, 0x6e, 0xf6, 0x62, 0xf0, 0xbc} \ +} + +class nsMacMIMEDataSource: public nsIMIMEDataSource +{ +public: + nsMacMIMEDataSource(); + virtual ~nsMacMIMEDataSource(); + NS_DECL_ISUPPORTS + NS_DECL_NSIMIMEDATASOURCE + +private: + nsInternetConfig mIC; +}; \ No newline at end of file