1999-07-28 08:02:07 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
1999-07-03 00:08:27 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03: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/
|
1999-07-03 00:08:27 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03: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.
|
1999-07-03 00:08:27 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-07-03 00:08:27 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2000-01-24 18:41:03 +03:00
|
|
|
* Contributor(s): Judson Valeski
|
1999-07-03 00:08:27 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsMIMEInfoImpl.h"
|
2000-01-24 18:41:03 +03:00
|
|
|
#include "nsXPIDLString.h"
|
1999-07-03 00:08:27 +04:00
|
|
|
|
|
|
|
// nsISupports methods
|
2000-03-06 00:26:01 +03:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMIMEInfoImpl, nsIMIMEInfo);
|
1999-07-03 00:08:27 +04:00
|
|
|
|
|
|
|
// nsMIMEInfoImpl methods
|
2000-04-05 07:03:50 +04:00
|
|
|
nsMIMEInfoImpl::nsMIMEInfoImpl() {
|
|
|
|
NS_INIT_REFCNT();
|
2000-07-12 03:11:59 +04:00
|
|
|
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
|
|
|
mAlwaysAskBeforeHandling = PR_TRUE;
|
2000-04-05 07:03:50 +04:00
|
|
|
}
|
|
|
|
|
2000-04-19 08:45:30 +04:00
|
|
|
nsMIMEInfoImpl::nsMIMEInfoImpl(const char *aMIMEType) :mMIMEType( aMIMEType ){
|
1999-07-28 08:02:07 +04:00
|
|
|
NS_INIT_REFCNT();
|
2000-07-12 03:11:59 +04:00
|
|
|
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
|
|
|
mAlwaysAskBeforeHandling = PR_TRUE;
|
1999-07-03 00:08:27 +04:00
|
|
|
}
|
|
|
|
|
2000-01-25 05:40:16 +03:00
|
|
|
PRUint32
|
|
|
|
nsMIMEInfoImpl::GetExtCount() {
|
|
|
|
return mExtensions.Count();
|
|
|
|
}
|
|
|
|
|
2000-01-24 18:41:03 +03:00
|
|
|
NS_IMETHODIMP
|
2000-04-28 14:51:52 +04:00
|
|
|
nsMIMEInfoImpl::GetFileExtensions(PRUint32 *elementCount, char ***extensions) {
|
2000-09-27 23:50:59 +04:00
|
|
|
PRUint32 count = mExtensions.Count();
|
|
|
|
if (count < 1) return NS_OK;
|
1999-07-03 00:08:27 +04:00
|
|
|
|
2000-09-27 23:50:59 +04:00
|
|
|
char **_retExts = (char**)nsMemory::Alloc((count)*sizeof(char*));
|
2000-01-24 18:41:03 +03:00
|
|
|
if (!_retExts) return NS_ERROR_OUT_OF_MEMORY;
|
1999-07-03 00:08:27 +04:00
|
|
|
|
2000-09-27 23:50:59 +04:00
|
|
|
for (PRUint8 i=0; i < count; i++) {
|
2000-04-19 08:45:30 +04:00
|
|
|
nsCString* ext = mExtensions.CStringAt(i);
|
2000-01-24 18:41:03 +03:00
|
|
|
_retExts[i] = ext->ToNewCString();
|
2000-09-27 23:50:59 +04:00
|
|
|
if (!_retExts[i]) {
|
|
|
|
// clean up all the strings we've allocated
|
|
|
|
while (i-- != 0) nsMemory::Free(_retExts[i]);
|
|
|
|
nsMemory::Free(_retExts);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2000-01-24 18:41:03 +03:00
|
|
|
}
|
|
|
|
|
2000-09-27 23:50:59 +04:00
|
|
|
*elementCount = count;
|
2000-01-24 18:41:03 +03:00
|
|
|
*extensions = _retExts;
|
1999-07-03 00:08:27 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-24 18:41:03 +03:00
|
|
|
nsMIMEInfoImpl::ExtensionExists(const char *aExtension, PRBool *_retval) {
|
|
|
|
NS_ASSERTION(aExtension, "no extension");
|
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
PRUint32 extCount = mExtensions.Count();
|
|
|
|
if (extCount < 1) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
if (!aExtension) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
for (PRUint8 i=0; i < extCount; i++) {
|
2000-04-05 07:03:50 +04:00
|
|
|
nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
|
2000-01-24 18:41:03 +03:00
|
|
|
if (ext->Equals(aExtension)) {
|
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*_retval = found;
|
1999-07-03 00:08:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-24 18:41:03 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoImpl::FirstExtension(char **_retval) {
|
|
|
|
PRUint32 extCount = mExtensions.Count();
|
|
|
|
if (extCount < 1) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2000-01-25 05:40:16 +03:00
|
|
|
*_retval = (mExtensions.CStringAt(0))->ToNewCString();
|
2000-01-24 18:41:03 +03:00
|
|
|
if (!*_retval) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-05 07:03:50 +04:00
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::AppendExtension(const char *aExtension)
|
|
|
|
{
|
2000-08-20 10:59:07 +04:00
|
|
|
mExtensions.AppendCString( nsCAutoString(aExtension) );
|
2000-04-05 07:03:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-03 00:08:27 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoImpl::GetMIMEType(char * *aMIMEType) {
|
|
|
|
if (!aMIMEType) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-07-22 03:52:36 +04:00
|
|
|
if (mMIMEType.Length() < 1)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2000-04-05 07:03:50 +04:00
|
|
|
*aMIMEType = mMIMEType.ToNewCString();
|
1999-07-03 00:08:27 +04:00
|
|
|
if (!*aMIMEType) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-05 07:03:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoImpl::SetMIMEType(const char* aMIMEType) {
|
|
|
|
if (!aMIMEType) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-04-19 08:45:30 +04:00
|
|
|
mMIMEType=aMIMEType;
|
2000-04-05 07:03:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-03 00:08:27 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoImpl::GetDescription(PRUnichar * *aDescription) {
|
|
|
|
if (!aDescription) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aDescription = mDescription.ToNewUnicode();
|
|
|
|
if (!*aDescription) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-05 07:03:50 +04:00
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::SetDescription(const PRUnichar * aDescription)
|
|
|
|
{
|
|
|
|
mDescription = aDescription;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-03 00:08:27 +04:00
|
|
|
NS_IMETHODIMP
|
2000-01-24 18:41:03 +03:00
|
|
|
nsMIMEInfoImpl::GetDataURI(nsIURI * *aDataURI) {
|
|
|
|
return mURI->Clone(aDataURI);
|
1999-07-03 00:08:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoImpl::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval) {
|
2000-01-24 18:41:03 +03:00
|
|
|
if (!aMIMEInfo) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsXPIDLCString type;
|
|
|
|
nsresult rv = aMIMEInfo->GetMIMEType(getter_Copies(type));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-04-05 07:03:50 +04:00
|
|
|
*_retval = mMIMEType.EqualsWithConversion(type);
|
|
|
|
|
2000-01-24 18:41:03 +03:00
|
|
|
return NS_OK;
|
1999-07-03 00:08:27 +04:00
|
|
|
}
|
2000-04-05 07:03:50 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::GetMacType(PRUint32 *aMacType)
|
|
|
|
{
|
|
|
|
*aMacType = mMacType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::SetMacType(PRUint32 aMacType)
|
|
|
|
{
|
|
|
|
mMacType = aMacType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::GetMacCreator(PRUint32 *aMacCreator)
|
|
|
|
{
|
|
|
|
*aMacCreator = mMacCreator;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::SetMacCreator(PRUint32 aMacCreator)
|
|
|
|
{
|
|
|
|
mMacCreator = aMacCreator;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-19 08:45:30 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::SetFileExtensions( const char* aExtensions )
|
|
|
|
{
|
|
|
|
mExtensions.Clear();
|
|
|
|
nsCString extList( aExtensions );
|
|
|
|
|
|
|
|
PRInt32 breakLocation = -1;
|
|
|
|
while ( (breakLocation= extList.FindCharInSet( ",",0 ) )!= -1)
|
|
|
|
{
|
|
|
|
nsCString ext( extList, breakLocation );
|
|
|
|
mExtensions.AppendCString( ext );
|
|
|
|
extList.Cut(0, breakLocation+1 );
|
|
|
|
}
|
|
|
|
if ( extList.Length() )
|
|
|
|
mExtensions.AppendCString( extList );
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-06-21 10:34:43 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::GetApplicationDescription(PRUnichar ** aApplicationDescription)
|
|
|
|
{
|
|
|
|
*aApplicationDescription = mPreferredAppDescription.ToNewUnicode();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::SetApplicationDescription(const PRUnichar * aApplicationDescription)
|
|
|
|
{
|
|
|
|
mPreferredAppDescription = aApplicationDescription;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::GetPreferredApplicationHandler(nsIFile ** aPreferredAppHandler)
|
|
|
|
{
|
|
|
|
*aPreferredAppHandler = mPreferredApplication;
|
2000-06-22 00:38:52 +04:00
|
|
|
NS_IF_ADDREF(*aPreferredAppHandler);
|
2000-06-21 10:34:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::SetPreferredApplicationHandler(nsIFile * aPreferredAppHandler)
|
|
|
|
{
|
|
|
|
mPreferredApplication = aPreferredAppHandler;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::GetPreferredAction(nsMIMEInfoHandleAction * aPreferredAction)
|
|
|
|
{
|
|
|
|
*aPreferredAction = mPreferredAction;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::SetPreferredAction(nsMIMEInfoHandleAction aPreferredAction)
|
|
|
|
{
|
|
|
|
mPreferredAction = aPreferredAction;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-07-12 03:11:59 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::GetAlwaysAskBeforeHandling(PRBool * aAlwaysAsk)
|
|
|
|
{
|
|
|
|
*aAlwaysAsk = mAlwaysAskBeforeHandling;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::SetAlwaysAskBeforeHandling(PRBool aAlwaysAsk)
|
|
|
|
{
|
|
|
|
mAlwaysAskBeforeHandling = aAlwaysAsk;
|
|
|
|
return NS_OK;
|
|
|
|
}
|