2007-07-26 08:24:31 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 20:52:41 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-07-03 00:08:27 +04:00
|
|
|
*
|
2004-04-17 20:52:41 +04:00
|
|
|
* 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/
|
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.
|
|
|
|
*
|
2004-04-17 20:52:41 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-17 20:52:41 +04:00
|
|
|
* 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"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-17 20:52:41 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-17 20:52:41 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** 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"
|
2003-06-17 21:00:40 +04:00
|
|
|
#include "nsStringEnumerator.h"
|
2004-02-24 01:49:28 +03:00
|
|
|
#include "nsIProcess.h"
|
2007-07-18 02:59:58 +04:00
|
|
|
#include "nsILocalFile.h"
|
|
|
|
#include "nsIFileURL.h"
|
1999-07-03 00:08:27 +04:00
|
|
|
|
|
|
|
// nsISupports methods
|
2007-07-26 00:40:42 +04:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsMIMEInfoBase)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsMIMEInfoBase)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMIMEInfoBase)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIHandlerInfo)
|
|
|
|
// This is only an nsIMIMEInfo if it's a MIME handler.
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIMIMEInfo, mClass == eMIMEInfo)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIHandlerInfo)
|
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
1999-07-03 00:08:27 +04:00
|
|
|
|
|
|
|
// nsMIMEInfoImpl methods
|
2007-07-26 00:40:42 +04:00
|
|
|
|
|
|
|
// Constructors for a MIME handler.
|
2004-02-24 01:49:28 +03:00
|
|
|
nsMIMEInfoBase::nsMIMEInfoBase(const char *aMIMEType) :
|
2007-04-16 00:43:49 +04:00
|
|
|
mMacType(0),
|
|
|
|
mMacCreator(0),
|
2007-07-26 00:40:42 +04:00
|
|
|
mType(aMIMEType),
|
|
|
|
mClass(eMIMEInfo),
|
2004-02-24 01:49:28 +03:00
|
|
|
mPreferredAction(nsIMIMEInfo::saveToDisk),
|
2007-04-16 00:43:49 +04:00
|
|
|
mAlwaysAskBeforeHandling(PR_TRUE)
|
2004-02-24 01:49:28 +03:00
|
|
|
{
|
1999-07-03 00:08:27 +04:00
|
|
|
}
|
|
|
|
|
2004-06-11 19:47:57 +04:00
|
|
|
nsMIMEInfoBase::nsMIMEInfoBase(const nsACString& aMIMEType) :
|
2007-04-16 00:43:49 +04:00
|
|
|
mMacType(0),
|
|
|
|
mMacCreator(0),
|
2007-07-26 00:40:42 +04:00
|
|
|
mType(aMIMEType),
|
|
|
|
mClass(eMIMEInfo),
|
|
|
|
mPreferredAction(nsIMIMEInfo::saveToDisk),
|
|
|
|
mAlwaysAskBeforeHandling(PR_TRUE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor for a handler that lets the caller specify whether this is a
|
|
|
|
// MIME handler or a protocol handler. In the long run, these will be distinct
|
|
|
|
// classes (f.e. nsMIMEInfo and nsProtocolInfo), but for now we reuse this class
|
|
|
|
// for both and distinguish between the two kinds of handlers via the aClass
|
|
|
|
// argument to this method, which can be either eMIMEInfo or eProtocolInfo.
|
|
|
|
nsMIMEInfoBase::nsMIMEInfoBase(const nsACString& aType, HandlerClass aClass) :
|
|
|
|
mMacType(0),
|
|
|
|
mMacCreator(0),
|
|
|
|
mType(aType),
|
|
|
|
mClass(aClass),
|
2004-06-11 19:47:57 +04:00
|
|
|
mPreferredAction(nsIMIMEInfo::saveToDisk),
|
2007-04-16 00:43:49 +04:00
|
|
|
mAlwaysAskBeforeHandling(PR_TRUE)
|
2004-06-11 19:47:57 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
nsMIMEInfoBase::~nsMIMEInfoBase()
|
|
|
|
{
|
2000-01-25 05:40:16 +03:00
|
|
|
}
|
|
|
|
|
2000-01-24 18:41:03 +03:00
|
|
|
NS_IMETHODIMP
|
2004-02-24 01:49:28 +03:00
|
|
|
nsMIMEInfoBase::GetFileExtensions(nsIUTF8StringEnumerator** aResult)
|
2003-06-17 21:00:40 +04:00
|
|
|
{
|
|
|
|
return NS_NewUTF8StringEnumerator(aResult, &mExtensions, this);
|
1999-07-03 00:08:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-16 00:56:37 +04:00
|
|
|
nsMIMEInfoBase::ExtensionExists(const nsACString& aExtension, PRBool *_retval)
|
2004-02-24 01:49:28 +03:00
|
|
|
{
|
2004-04-16 00:56:37 +04:00
|
|
|
NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
|
2000-01-24 18:41:03 +03:00
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
PRUint32 extCount = mExtensions.Count();
|
2002-03-06 01:35:56 +03:00
|
|
|
if (extCount < 1) return NS_OK;
|
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);
|
2004-04-16 00:56:37 +04:00
|
|
|
if (ext->Equals(aExtension, 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
|
2004-04-16 00:56:37 +04:00
|
|
|
nsMIMEInfoBase::GetPrimaryExtension(nsACString& _retval)
|
2004-02-24 01:49:28 +03:00
|
|
|
{
|
2000-01-24 18:41:03 +03:00
|
|
|
PRUint32 extCount = mExtensions.Count();
|
|
|
|
if (extCount < 1) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2004-04-16 00:56:37 +04:00
|
|
|
_retval = *(mExtensions.CStringAt(0));
|
2000-01-24 18:41:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-16 07:28:06 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-16 00:56:37 +04:00
|
|
|
nsMIMEInfoBase::SetPrimaryExtension(const nsACString& aExtension)
|
2004-02-24 01:49:28 +03:00
|
|
|
{
|
2004-04-16 00:56:37 +04:00
|
|
|
NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
|
2002-01-16 07:28:06 +03:00
|
|
|
PRUint32 extCount = mExtensions.Count();
|
|
|
|
PRUint8 i;
|
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
for (i=0; i < extCount; i++) {
|
|
|
|
nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
|
2004-04-16 00:56:37 +04:00
|
|
|
if (ext->Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
|
2002-01-16 07:28:06 +03:00
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
mExtensions.RemoveCStringAt(i);
|
|
|
|
}
|
|
|
|
|
2004-04-16 00:56:37 +04:00
|
|
|
mExtensions.InsertCStringAt(aExtension, 0);
|
2002-01-16 07:28:06 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-16 00:56:37 +04:00
|
|
|
nsMIMEInfoBase::AppendExtension(const nsACString& aExtension)
|
2000-04-05 07:03:50 +04:00
|
|
|
{
|
2004-04-16 00:56:37 +04:00
|
|
|
mExtensions.AppendCString(aExtension);
|
|
|
|
return NS_OK;
|
2000-04-05 07:03:50 +04:00
|
|
|
}
|
|
|
|
|
2007-07-26 00:40:42 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetType(nsACString& aType)
|
|
|
|
{
|
|
|
|
if (mType.IsEmpty())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
aType = mType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-12 04:02:26 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-16 00:56:37 +04:00
|
|
|
nsMIMEInfoBase::GetMIMEType(nsACString& aMIMEType)
|
2004-02-24 01:49:28 +03:00
|
|
|
{
|
2007-07-26 00:40:42 +04:00
|
|
|
if (mType.IsEmpty())
|
2000-07-22 03:52:36 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2007-07-26 00:40:42 +04:00
|
|
|
aMIMEType = mType;
|
1999-07-03 00:08:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-04-16 00:56:37 +04:00
|
|
|
nsMIMEInfoBase::GetDescription(nsAString& aDescription)
|
2004-02-24 01:49:28 +03:00
|
|
|
{
|
2004-04-16 00:56:37 +04:00
|
|
|
aDescription = mDescription;
|
1999-07-03 00:08:27 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-16 00:56:37 +04:00
|
|
|
nsMIMEInfoBase::SetDescription(const nsAString& aDescription)
|
2000-04-05 07:03:50 +04:00
|
|
|
{
|
2004-04-16 00:56:37 +04:00
|
|
|
mDescription = aDescription;
|
|
|
|
return NS_OK;
|
2000-04-05 07:03:50 +04:00
|
|
|
}
|
|
|
|
|
1999-07-03 00:08:27 +04:00
|
|
|
NS_IMETHODIMP
|
2004-02-24 01:49:28 +03:00
|
|
|
nsMIMEInfoBase::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval)
|
|
|
|
{
|
2000-01-24 18:41:03 +03:00
|
|
|
if (!aMIMEInfo) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2004-04-16 00:56:37 +04:00
|
|
|
nsCAutoString type;
|
|
|
|
nsresult rv = aMIMEInfo->GetMIMEType(type);
|
2000-01-24 18:41:03 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2007-07-26 00:40:42 +04:00
|
|
|
*_retval = mType.Equals(type);
|
2000-04-05 07:03:50 +04:00
|
|
|
|
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
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetMacType(PRUint32 *aMacType)
|
2000-04-05 07:03:50 +04:00
|
|
|
{
|
2004-04-16 00:56:37 +04:00
|
|
|
*aMacType = mMacType;
|
2006-04-28 22:17:11 +04:00
|
|
|
|
|
|
|
if (!mMacType)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2004-04-16 00:56:37 +04:00
|
|
|
return NS_OK;
|
2000-04-05 07:03:50 +04:00
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::SetMacType(PRUint32 aMacType)
|
2000-04-05 07:03:50 +04:00
|
|
|
{
|
2004-04-16 00:56:37 +04:00
|
|
|
mMacType = aMacType;
|
|
|
|
return NS_OK;
|
2000-04-05 07:03:50 +04:00
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetMacCreator(PRUint32 *aMacCreator)
|
2000-04-05 07:03:50 +04:00
|
|
|
{
|
2004-04-16 00:56:37 +04:00
|
|
|
*aMacCreator = mMacCreator;
|
2006-04-28 22:17:11 +04:00
|
|
|
|
|
|
|
if (!mMacCreator)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2004-04-16 00:56:37 +04:00
|
|
|
return NS_OK;
|
2000-04-05 07:03:50 +04:00
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::SetMacCreator(PRUint32 aMacCreator)
|
2000-04-05 07:03:50 +04:00
|
|
|
{
|
2004-04-16 00:56:37 +04:00
|
|
|
mMacCreator = aMacCreator;
|
|
|
|
return NS_OK;
|
2000-04-05 07:03:50 +04:00
|
|
|
}
|
2000-04-19 08:45:30 +04:00
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-16 00:56:37 +04:00
|
|
|
nsMIMEInfoBase::SetFileExtensions(const nsACString& aExtensions)
|
|
|
|
{
|
|
|
|
mExtensions.Clear();
|
|
|
|
nsCString extList( aExtensions );
|
|
|
|
|
|
|
|
PRInt32 breakLocation = -1;
|
|
|
|
while ( (breakLocation= extList.FindChar(',') )!= -1)
|
|
|
|
{
|
|
|
|
mExtensions.AppendCString(Substring(extList.get(), extList.get() + breakLocation));
|
|
|
|
extList.Cut(0, breakLocation+1 );
|
|
|
|
}
|
|
|
|
if ( !extList.IsEmpty() )
|
|
|
|
mExtensions.AppendCString( extList );
|
|
|
|
return NS_OK;
|
2000-04-19 08:45:30 +04:00
|
|
|
}
|
2000-06-21 10:34:43 +04:00
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
2004-04-16 00:56:37 +04:00
|
|
|
nsMIMEInfoBase::GetDefaultDescription(nsAString& aDefaultDescription)
|
2003-01-12 04:14:35 +03:00
|
|
|
{
|
2004-04-16 00:56:37 +04:00
|
|
|
aDefaultDescription = mDefaultAppDescription;
|
|
|
|
return NS_OK;
|
2003-01-12 04:14:35 +03:00
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
2007-07-05 23:31:46 +04:00
|
|
|
nsMIMEInfoBase::GetPreferredApplicationHandler(nsIHandlerApp ** aPreferredAppHandler)
|
2000-06-21 10:34:43 +04:00
|
|
|
{
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
2007-07-05 23:31:46 +04:00
|
|
|
nsMIMEInfoBase::SetPreferredApplicationHandler(nsIHandlerApp * aPreferredAppHandler)
|
2000-06-21 10:34:43 +04:00
|
|
|
{
|
|
|
|
mPreferredApplication = aPreferredAppHandler;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
2007-07-05 23:31:46 +04:00
|
|
|
nsMIMEInfoBase::GetPreferredAction(nsHandlerInfoAction * aPreferredAction)
|
2003-07-08 17:52:46 +04:00
|
|
|
{
|
2004-02-24 01:49:28 +03:00
|
|
|
*aPreferredAction = mPreferredAction;
|
2003-07-08 17:52:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-02-24 01:49:28 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-07-05 23:31:46 +04:00
|
|
|
nsMIMEInfoBase::SetPreferredAction(nsHandlerInfoAction aPreferredAction)
|
2003-01-12 04:14:35 +03:00
|
|
|
{
|
2004-02-24 01:49:28 +03:00
|
|
|
mPreferredAction = aPreferredAction;
|
2003-01-12 04:14:35 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetAlwaysAskBeforeHandling(PRBool * aAlwaysAsk)
|
2003-01-12 04:14:35 +03:00
|
|
|
{
|
2004-02-24 01:49:28 +03:00
|
|
|
*aAlwaysAsk = mAlwaysAskBeforeHandling;
|
|
|
|
|
2003-01-12 04:14:35 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::SetAlwaysAskBeforeHandling(PRBool aAlwaysAsk)
|
2000-06-21 10:34:43 +04:00
|
|
|
{
|
2004-02-24 01:49:28 +03:00
|
|
|
mAlwaysAskBeforeHandling = aAlwaysAsk;
|
2000-06-21 10:34:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-02-24 01:49:28 +03:00
|
|
|
|
2007-07-18 02:59:58 +04:00
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
nsMIMEInfoBase::GetLocalFileFromURI(nsIURI *aURI, nsILocalFile **aFile)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFileURL> fileUrl = do_QueryInterface(aURI, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
rv = fileUrl->GetFile(getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return CallQueryInterface(file, aFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
2007-07-18 02:59:58 +04:00
|
|
|
nsMIMEInfoBase::LaunchWithURI(nsIURI* aURI)
|
2000-06-21 10:34:43 +04:00
|
|
|
{
|
2007-07-18 02:59:58 +04:00
|
|
|
nsCOMPtr<nsILocalFile> docToLoad;
|
|
|
|
nsresult rv;
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
if (mPreferredAction == useHelperApp) {
|
|
|
|
if (!mPreferredApplication)
|
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
|
2007-07-18 02:59:58 +04:00
|
|
|
// check for and possibly launch with web application
|
|
|
|
nsCOMPtr<nsIWebHandlerApp> webHandler =
|
|
|
|
do_QueryInterface(mPreferredApplication, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return LaunchWithWebHandler(webHandler, aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ok, we must have a local handler app
|
|
|
|
nsCOMPtr<nsILocalHandlerApp> localHandler =
|
|
|
|
do_QueryInterface(mPreferredApplication, &rv);
|
2007-07-05 23:31:46 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-18 02:59:58 +04:00
|
|
|
|
2007-07-05 23:31:46 +04:00
|
|
|
nsCOMPtr<nsIFile> executable;
|
|
|
|
rv = localHandler->GetExecutable(getter_AddRefs(executable));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-18 02:59:58 +04:00
|
|
|
|
2007-07-29 07:38:52 +04:00
|
|
|
// get the nsILocalFile version of the doc to launch with
|
2007-07-18 02:59:58 +04:00
|
|
|
rv = GetLocalFileFromURI(aURI, getter_AddRefs(docToLoad));
|
2007-07-29 07:38:52 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
|
|
|
|
// If we don't have a file, we must be a protocol handler
|
|
|
|
NS_ASSERTION(mClass == eProtocolInfo,
|
|
|
|
"nsMIMEInfoBase should be a protocol handler");
|
|
|
|
|
|
|
|
// so pass the entire URI to the handler.
|
|
|
|
nsCAutoString spec;
|
|
|
|
aURI->GetSpec(spec);
|
|
|
|
return LaunchWithIProcess(executable, spec);
|
|
|
|
}
|
2007-07-18 02:59:58 +04:00
|
|
|
|
2007-07-29 07:38:52 +04:00
|
|
|
// note that the file pointed to by docToLoad could possibly have
|
|
|
|
// originated as a file: URI if we're in some non-browser application.
|
|
|
|
|
|
|
|
nsCAutoString path;
|
|
|
|
docToLoad->GetNativePath(path);
|
|
|
|
return LaunchWithIProcess(executable, path);
|
2004-02-24 01:49:28 +03:00
|
|
|
}
|
|
|
|
else if (mPreferredAction == useSystemDefault) {
|
2007-07-26 08:24:31 +04:00
|
|
|
if (mClass == eProtocolInfo)
|
|
|
|
return LoadUriInternal(aURI);
|
|
|
|
|
2007-07-18 02:59:58 +04:00
|
|
|
rv = GetLocalFileFromURI(aURI, getter_AddRefs(docToLoad));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return LaunchDefaultWithFile(docToLoad);
|
2004-02-24 01:49:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2000-06-21 10:34:43 +04:00
|
|
|
}
|
2000-07-12 03:11:59 +04:00
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
void
|
|
|
|
nsMIMEInfoBase::CopyBasicDataTo(nsMIMEInfoBase* aOther)
|
2000-07-12 03:11:59 +04:00
|
|
|
{
|
2007-07-26 00:40:42 +04:00
|
|
|
aOther->mType = mType;
|
2004-02-24 01:49:28 +03:00
|
|
|
aOther->mDefaultAppDescription = mDefaultAppDescription;
|
|
|
|
aOther->mExtensions = mExtensions;
|
2001-06-28 06:18:13 +04:00
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
aOther->mMacType = mMacType;
|
|
|
|
aOther->mMacCreator = mMacCreator;
|
2000-07-12 03:11:59 +04:00
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
/* static */
|
|
|
|
nsresult
|
2007-07-29 07:38:52 +04:00
|
|
|
nsMIMEInfoBase::LaunchWithIProcess(nsIFile* aApp, const nsCString& aArg)
|
2000-07-12 03:11:59 +04:00
|
|
|
{
|
2007-07-29 07:38:52 +04:00
|
|
|
NS_ASSERTION(aApp, "Unexpected null pointer, fix caller");
|
2004-02-24 01:49:28 +03:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = process->Init(aApp)))
|
|
|
|
return rv;
|
|
|
|
|
2007-07-29 07:38:52 +04:00
|
|
|
const char *string = aArg.get();
|
2004-02-24 01:49:28 +03:00
|
|
|
|
|
|
|
PRUint32 pid;
|
2007-07-29 07:38:52 +04:00
|
|
|
return process->Run(PR_FALSE, &string, 1, &pid);
|
2004-02-24 01:49:28 +03:00
|
|
|
}
|
|
|
|
|
2007-07-18 02:59:58 +04:00
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
nsMIMEInfoBase::LaunchWithWebHandler(nsIWebHandlerApp *aApp, nsIURI *aURI)
|
|
|
|
{
|
|
|
|
// we'll be implementing this Real Soon Now!
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
// nsMIMEInfoImpl implementation
|
|
|
|
NS_IMETHODIMP
|
2004-04-16 00:56:37 +04:00
|
|
|
nsMIMEInfoImpl::GetDefaultDescription(nsAString& aDefaultDescription)
|
2004-02-24 01:49:28 +03:00
|
|
|
{
|
|
|
|
if (mDefaultAppDescription.IsEmpty() && mDefaultApplication) {
|
|
|
|
// Don't want to cache this, just in case someone resets the app
|
|
|
|
// without changing the description....
|
2004-04-16 00:56:37 +04:00
|
|
|
mDefaultApplication->GetLeafName(aDefaultDescription);
|
2004-02-24 01:49:28 +03:00
|
|
|
} else {
|
2004-04-16 00:56:37 +04:00
|
|
|
aDefaultDescription = mDefaultAppDescription;
|
2004-02-24 01:49:28 +03:00
|
|
|
}
|
|
|
|
|
2004-04-16 00:56:37 +04:00
|
|
|
return NS_OK;
|
2004-02-24 01:49:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoImpl::GetHasDefaultHandler(PRBool * _retval)
|
|
|
|
{
|
2007-07-31 03:33:17 +04:00
|
|
|
*_retval = !mDefaultAppDescription.IsEmpty();
|
2004-02-24 01:49:28 +03:00
|
|
|
if (mDefaultApplication) {
|
|
|
|
PRBool exists;
|
|
|
|
*_retval = NS_SUCCEEDED(mDefaultApplication->Exists(&exists)) && exists;
|
|
|
|
}
|
2000-07-12 03:11:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-02-24 01:49:28 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMIMEInfoImpl::LaunchDefaultWithFile(nsIFile* aFile)
|
|
|
|
{
|
|
|
|
if (!mDefaultApplication)
|
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
|
2007-07-29 07:38:52 +04:00
|
|
|
nsCAutoString nativePath;
|
|
|
|
aFile->GetNativePath(nativePath);
|
|
|
|
|
|
|
|
return LaunchWithIProcess(mDefaultApplication, nativePath);
|
2004-02-24 01:49:28 +03:00
|
|
|
}
|
|
|
|
|