2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-07-03 00:08:27 +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/
|
1999-07-03 00:08:27 +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.
|
1999-07-03 00:08:27 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org 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.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
1999-07-03 00:08:27 +04:00
|
|
|
|
|
|
|
#include "nsMIMEInfoImpl.h"
|
2000-01-24 18:41:03 +03:00
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2001-06-28 06:18:13 +04:00
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsEscape.h"
|
|
|
|
|
|
|
|
#define NEVER_ASK_FOR_SAVE_TO_DISK_PREF "browser.helperApps.neverAsk.saveToDisk"
|
|
|
|
#define NEVER_ASK_FOR_OPEN_FILE_PREF "browser.helperApps.neverAsk.openFile"
|
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;
|
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;
|
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();
|
2002-02-12 05:22:39 +03:00
|
|
|
*elementCount = count;
|
|
|
|
*extensions = nsnull;
|
|
|
|
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-28 00:25:15 +04:00
|
|
|
for (PRUint32 i=0; i < count; i++) {
|
2000-04-19 08:45:30 +04:00
|
|
|
nsCString* ext = mExtensions.CStringAt(i);
|
2001-09-29 12:28:41 +04:00
|
|
|
_retExts[i] = ToNewCString(*ext);
|
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;
|
|
|
|
|
2002-01-16 07:28:06 +03:00
|
|
|
nsDependentCString extension(aExtension);
|
2000-01-24 18:41:03 +03:00
|
|
|
for (PRUint8 i=0; i < extCount; i++) {
|
2000-04-05 07:03:50 +04:00
|
|
|
nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
|
2002-01-16 07:28:06 +03:00
|
|
|
if (ext->Equals(extension, nsCaseInsensitiveCStringComparator())) {
|
2000-01-24 18:41:03 +03:00
|
|
|
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
|
2002-01-16 07:28:06 +03:00
|
|
|
nsMIMEInfoImpl::GetPrimaryExtension(char **_retval) {
|
2000-01-24 18:41:03 +03:00
|
|
|
PRUint32 extCount = mExtensions.Count();
|
|
|
|
if (extCount < 1) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2001-09-29 12:28:41 +04:00
|
|
|
*_retval = ToNewCString(*(mExtensions.CStringAt(0)));
|
2000-01-24 18:41:03 +03:00
|
|
|
if (!*_retval) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-16 07:28:06 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoImpl::SetPrimaryExtension(const char *aExtension) {
|
|
|
|
NS_ASSERTION(aExtension, "no extension");
|
|
|
|
PRUint32 extCount = mExtensions.Count();
|
|
|
|
nsCString extension(aExtension);
|
|
|
|
PRUint8 i;
|
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
for (i=0; i < extCount; i++) {
|
|
|
|
nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
|
|
|
|
if (ext->Equals(extension, nsCaseInsensitiveCStringComparator())) {
|
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
mExtensions.RemoveCStringAt(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
mExtensions.InsertCStringAt(extension, 0);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-12-12 04:02:26 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoImpl::Clone(nsIMIMEInfo** aClone) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aClone);
|
|
|
|
|
|
|
|
nsMIMEInfoImpl* clone = new nsMIMEInfoImpl(mMIMEType.get());
|
|
|
|
if (!clone) {
|
|
|
|
*aClone = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
clone->mExtensions = mExtensions;
|
|
|
|
clone->mDescription = mDescription;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (mURI) {
|
|
|
|
result = mURI->Clone(getter_AddRefs(clone->mURI));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Failed to clone URI");
|
|
|
|
}
|
|
|
|
clone->mMacType = mMacType;
|
|
|
|
clone->mMacCreator = mMacCreator;
|
|
|
|
if (mPreferredApplication) {
|
|
|
|
result = mPreferredApplication->Clone(getter_AddRefs(clone->mPreferredApplication));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Failed to clone preferred handler application");
|
|
|
|
}
|
|
|
|
clone->mPreferredAction = mPreferredAction;
|
|
|
|
clone->mPreferredAppDescription = mPreferredAppDescription;
|
|
|
|
|
|
|
|
return CallQueryInterface(clone, aClone);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2001-09-29 12:28:41 +04:00
|
|
|
*aMIMEType = ToNewCString(mMIMEType);
|
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;
|
|
|
|
|
2001-09-29 12:28:41 +04:00
|
|
|
*aDescription = ToNewUnicode(mDescription);
|
1999-07-03 00:08:27 +04:00
|
|
|
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;
|
2002-03-05 02:18:21 +03:00
|
|
|
while ( (breakLocation= extList.FindChar(',') )!= -1)
|
2000-04-19 08:45:30 +04:00
|
|
|
{
|
2001-10-25 03:47:43 +04:00
|
|
|
nsCString ext( extList.get(), breakLocation );
|
2000-04-19 08:45:30 +04:00
|
|
|
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)
|
|
|
|
{
|
2001-09-29 12:28:41 +04:00
|
|
|
*aApplicationDescription = ToNewUnicode(mPreferredAppDescription);
|
2000-06-21 10:34:43 +04:00
|
|
|
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)
|
|
|
|
{
|
2001-06-28 06:18:13 +04:00
|
|
|
// this is a bit complicated. We now store the always ask preference in two preferences:
|
|
|
|
// browser.helperApps.neverAsk.saveToDisk and
|
|
|
|
// browser.helperApps.neverAsk.openFile
|
|
|
|
// Both lists are comma delimited lists containing mime types which the user has specifically
|
|
|
|
// decided to override the helper app dialog for.
|
|
|
|
|
|
|
|
// for get always ask, we just need to search both pref branches for our mime type...
|
|
|
|
PRBool mimeTypeIsPresent = PR_FALSE;
|
|
|
|
CheckPrefForMimeType(NEVER_ASK_FOR_SAVE_TO_DISK_PREF, &mimeTypeIsPresent);
|
|
|
|
|
|
|
|
if (mimeTypeIsPresent)
|
|
|
|
{
|
|
|
|
*aAlwaysAsk = PR_FALSE;
|
|
|
|
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CheckPrefForMimeType(NEVER_ASK_FOR_OPEN_FILE_PREF, &mimeTypeIsPresent);
|
|
|
|
if (mimeTypeIsPresent)
|
|
|
|
{
|
|
|
|
*aAlwaysAsk = PR_FALSE;
|
|
|
|
// do we need to force a preferred action here? I don't think so...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-12 03:11:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-06-28 06:18:13 +04:00
|
|
|
// re-write me to use new string apis to avoid the extra string copy of the pref value in order to call ::Find
|
|
|
|
void nsMIMEInfoImpl::CheckPrefForMimeType(const char * prefName, PRBool * aMimeTypeIsPresent)
|
|
|
|
{
|
|
|
|
*aMimeTypeIsPresent = PR_FALSE;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(prefs, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && prefBranch)
|
|
|
|
{
|
|
|
|
nsXPIDLCString prefCString;
|
|
|
|
nsCAutoString prefValue;
|
|
|
|
rv = prefBranch->GetCharPref(prefName, getter_Copies(prefCString));
|
|
|
|
if (NS_SUCCEEDED(rv) && *prefCString.get())
|
|
|
|
{
|
|
|
|
nsUnescape(NS_CONST_CAST(char*,(const char*)prefCString.get()));
|
|
|
|
|
|
|
|
prefValue = prefCString; // i should be able to avoid this string copy
|
|
|
|
PRInt32 pos = prefValue.Find(mMIMEType, PR_TRUE);
|
|
|
|
if (pos >= 0)
|
|
|
|
*aMimeTypeIsPresent = PR_TRUE;
|
|
|
|
}
|
|
|
|
} // if we got the prefs service
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsMIMEInfoImpl::SetRememberPrefForMimeType(const char * prefName)
|
|
|
|
{
|
|
|
|
// first, make sure it isn't already there...
|
|
|
|
PRBool mimeTypeIsPresent = PR_FALSE;
|
|
|
|
CheckPrefForMimeType(prefName, &mimeTypeIsPresent);
|
|
|
|
if (mimeTypeIsPresent) return; // mime type is already present...
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(prefs, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && prefBranch)
|
|
|
|
{
|
|
|
|
// read out the current pref string and unescape it.
|
|
|
|
nsXPIDLCString prefCString;
|
|
|
|
nsCAutoString prefValue;
|
|
|
|
rv = prefBranch->GetCharPref(prefName, getter_Copies(prefCString));
|
|
|
|
if (NS_SUCCEEDED(rv) && *prefCString.get())
|
|
|
|
{
|
|
|
|
nsUnescape(NS_CONST_CAST(char*,(const char*)prefCString.get()));
|
|
|
|
prefValue = prefCString;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prefValue.IsEmpty()) // if the pref string isn't empty...
|
|
|
|
{
|
|
|
|
prefValue.Append(", ");
|
|
|
|
prefValue.Append(mMIMEType);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prefValue = mMIMEType;
|
|
|
|
|
|
|
|
// always escape the pref b4 storing it in case someone enters some funky characters for a mime type...
|
|
|
|
nsXPIDLCString escapedPrefString;
|
2001-10-25 03:47:43 +04:00
|
|
|
escapedPrefString.Adopt(nsEscape(prefValue.get(), url_XAlphas));
|
2001-06-28 06:18:13 +04:00
|
|
|
prefBranch->SetCharPref(prefName, escapedPrefString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-12 03:11:59 +04:00
|
|
|
NS_IMETHODIMP nsMIMEInfoImpl::SetAlwaysAskBeforeHandling(PRBool aAlwaysAsk)
|
|
|
|
{
|
2001-06-28 06:18:13 +04:00
|
|
|
if (!aAlwaysAsk)
|
|
|
|
{
|
|
|
|
if (mPreferredAction == nsIMIMEInfo::saveToDisk)
|
|
|
|
SetRememberPrefForMimeType(NEVER_ASK_FOR_SAVE_TO_DISK_PREF);
|
|
|
|
else
|
|
|
|
SetRememberPrefForMimeType(NEVER_ASK_FOR_OPEN_FILE_PREF);
|
|
|
|
}
|
2000-07-12 03:11:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|