2007-07-25 21:24:25 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
2007-03-22 10:30:00 -07:00
|
|
|
/* ***** 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.org 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 "nsMIMEInfoImpl.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsStringEnumerator.h"
|
2007-07-17 15:59:58 -07:00
|
|
|
#include "nsILocalFile.h"
|
|
|
|
#include "nsIFileURL.h"
|
2007-09-02 21:44:25 -07:00
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIURILoader.h"
|
|
|
|
#include "nsCURILoader.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsISupports methods
|
2007-07-25 13:40:41 -07: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
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsMIMEInfoImpl methods
|
2007-07-25 13:40:41 -07:00
|
|
|
|
|
|
|
// Constructors for a MIME handler.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMIMEInfoBase::nsMIMEInfoBase(const char *aMIMEType) :
|
2010-05-06 00:22:01 -07:00
|
|
|
mSchemeOrType(aMIMEType),
|
2007-07-25 13:40:41 -07:00
|
|
|
mClass(eMIMEInfo),
|
2007-03-22 10:30:00 -07:00
|
|
|
mPreferredAction(nsIMIMEInfo::saveToDisk),
|
2007-04-15 13:43:49 -07:00
|
|
|
mAlwaysAskBeforeHandling(PR_TRUE)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMIMEInfoBase::nsMIMEInfoBase(const nsACString& aMIMEType) :
|
2010-05-06 00:22:01 -07:00
|
|
|
mSchemeOrType(aMIMEType),
|
2007-07-25 13:40:41 -07:00
|
|
|
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) :
|
2010-05-06 00:22:01 -07:00
|
|
|
mSchemeOrType(aType),
|
2007-07-25 13:40:41 -07:00
|
|
|
mClass(aClass),
|
2007-03-22 10:30:00 -07:00
|
|
|
mPreferredAction(nsIMIMEInfo::saveToDisk),
|
2007-04-15 13:43:49 -07:00
|
|
|
mAlwaysAskBeforeHandling(PR_TRUE)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMIMEInfoBase::~nsMIMEInfoBase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetFileExtensions(nsIUTF8StringEnumerator** aResult)
|
|
|
|
{
|
|
|
|
return NS_NewUTF8StringEnumerator(aResult, &mExtensions, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::ExtensionExists(const nsACString& aExtension, PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
|
|
|
|
PRBool found = PR_FALSE;
|
2009-01-21 20:15:34 -08:00
|
|
|
PRUint32 extCount = mExtensions.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (extCount < 1) return NS_OK;
|
|
|
|
|
|
|
|
for (PRUint8 i=0; i < extCount; i++) {
|
2009-01-21 20:15:34 -08:00
|
|
|
const nsCString& ext = mExtensions[i];
|
|
|
|
if (ext.Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*_retval = found;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetPrimaryExtension(nsACString& _retval)
|
|
|
|
{
|
2009-01-21 20:15:34 -08:00
|
|
|
if (!mExtensions.Length())
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-21 20:15:34 -08:00
|
|
|
_retval = mExtensions[0];
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::SetPrimaryExtension(const nsACString& aExtension)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
|
2009-01-21 20:15:34 -08:00
|
|
|
PRUint32 extCount = mExtensions.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint8 i;
|
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
for (i=0; i < extCount; i++) {
|
2009-01-21 20:15:34 -08:00
|
|
|
const nsCString& ext = mExtensions[i];
|
|
|
|
if (ext.Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
2009-01-21 20:15:34 -08:00
|
|
|
mExtensions.RemoveElementAt(i);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-21 20:15:34 -08:00
|
|
|
mExtensions.InsertElementAt(0, aExtension);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::AppendExtension(const nsACString& aExtension)
|
|
|
|
{
|
2009-01-21 20:15:34 -08:00
|
|
|
mExtensions.AppendElement(aExtension);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-25 13:40:41 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetType(nsACString& aType)
|
|
|
|
{
|
2010-05-06 00:22:01 -07:00
|
|
|
if (mSchemeOrType.IsEmpty())
|
2007-07-25 13:40:41 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2010-05-06 00:22:01 -07:00
|
|
|
aType = mSchemeOrType;
|
2007-07-25 13:40:41 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetMIMEType(nsACString& aMIMEType)
|
|
|
|
{
|
2010-05-06 00:22:01 -07:00
|
|
|
if (mSchemeOrType.IsEmpty())
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2010-05-06 00:22:01 -07:00
|
|
|
aMIMEType = mSchemeOrType;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetDescription(nsAString& aDescription)
|
|
|
|
{
|
|
|
|
aDescription = mDescription;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::SetDescription(const nsAString& aDescription)
|
|
|
|
{
|
|
|
|
mDescription = aDescription;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval)
|
|
|
|
{
|
|
|
|
if (!aMIMEInfo) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCAutoString type;
|
|
|
|
nsresult rv = aMIMEInfo->GetMIMEType(type);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2010-05-06 00:22:01 -07:00
|
|
|
*_retval = mSchemeOrType.Equals(type);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::SetFileExtensions(const nsACString& aExtensions)
|
|
|
|
{
|
|
|
|
mExtensions.Clear();
|
|
|
|
nsCString extList( aExtensions );
|
|
|
|
|
|
|
|
PRInt32 breakLocation = -1;
|
|
|
|
while ( (breakLocation= extList.FindChar(',') )!= -1)
|
|
|
|
{
|
2009-01-21 20:15:34 -08:00
|
|
|
mExtensions.AppendElement(Substring(extList.get(), extList.get() + breakLocation));
|
2007-03-22 10:30:00 -07:00
|
|
|
extList.Cut(0, breakLocation+1 );
|
|
|
|
}
|
|
|
|
if ( !extList.IsEmpty() )
|
2009-01-21 20:15:34 -08:00
|
|
|
mExtensions.AppendElement( extList );
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetDefaultDescription(nsAString& aDefaultDescription)
|
|
|
|
{
|
|
|
|
aDefaultDescription = mDefaultAppDescription;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-07-05 12:31:44 -07:00
|
|
|
nsMIMEInfoBase::GetPreferredApplicationHandler(nsIHandlerApp ** aPreferredAppHandler)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aPreferredAppHandler = mPreferredApplication;
|
|
|
|
NS_IF_ADDREF(*aPreferredAppHandler);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-07-05 12:31:44 -07:00
|
|
|
nsMIMEInfoBase::SetPreferredApplicationHandler(nsIHandlerApp * aPreferredAppHandler)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mPreferredApplication = aPreferredAppHandler;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-13 13:41:34 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetPossibleApplicationHandlers(nsIMutableArray ** aPossibleAppHandlers)
|
|
|
|
{
|
|
|
|
if (!mPossibleApplications)
|
|
|
|
mPossibleApplications = do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
|
|
|
|
if (!mPossibleApplications)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aPossibleAppHandlers = mPossibleApplications;
|
|
|
|
NS_IF_ADDREF(*aPossibleAppHandlers);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2007-07-05 12:31:44 -07:00
|
|
|
nsMIMEInfoBase::GetPreferredAction(nsHandlerInfoAction * aPreferredAction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aPreferredAction = mPreferredAction;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-07-05 12:31:44 -07:00
|
|
|
nsMIMEInfoBase::SetPreferredAction(nsHandlerInfoAction aPreferredAction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mPreferredAction = aPreferredAction;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetAlwaysAskBeforeHandling(PRBool * aAlwaysAsk)
|
|
|
|
{
|
|
|
|
*aAlwaysAsk = mAlwaysAskBeforeHandling;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::SetAlwaysAskBeforeHandling(PRBool aAlwaysAsk)
|
|
|
|
{
|
|
|
|
mAlwaysAskBeforeHandling = aAlwaysAsk;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-17 15:59:58 -07: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);
|
|
|
|
}
|
|
|
|
|
2007-08-20 17:47:47 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::LaunchWithFile(nsIFile* aFile)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// it doesn't make any sense to call this on protocol handlers
|
|
|
|
NS_ASSERTION(mClass == eMIMEInfo,
|
|
|
|
"nsMIMEInfoBase should have mClass == eMIMEInfo");
|
|
|
|
|
|
|
|
if (mPreferredAction == useSystemDefault) {
|
|
|
|
return LaunchDefaultWithFile(aFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPreferredAction == useHelperApp) {
|
|
|
|
if (!mPreferredApplication)
|
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
// at the moment, we only know how to hand files off to local handlers
|
|
|
|
nsCOMPtr<nsILocalHandlerApp> localHandler =
|
|
|
|
do_QueryInterface(mPreferredApplication, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> executable;
|
|
|
|
rv = localHandler->GetExecutable(getter_AddRefs(executable));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCAutoString path;
|
|
|
|
aFile->GetNativePath(path);
|
|
|
|
return LaunchWithIProcess(executable, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2007-07-17 15:59:58 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2007-09-02 21:44:25 -07:00
|
|
|
nsMIMEInfoBase::LaunchWithURI(nsIURI* aURI,
|
|
|
|
nsIInterfaceRequestor* aWindowContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-20 17:47:47 -07:00
|
|
|
// for now, this is only being called with protocol handlers; that
|
|
|
|
// will change once we get to more general registerContentHandler
|
|
|
|
// support
|
|
|
|
NS_ASSERTION(mClass == eProtocolInfo,
|
|
|
|
"nsMIMEInfoBase should be a protocol handler");
|
|
|
|
|
|
|
|
if (mPreferredAction == useSystemDefault) {
|
|
|
|
return LoadUriInternal(aURI);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mPreferredAction == useHelperApp) {
|
|
|
|
if (!mPreferredApplication)
|
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
|
2007-10-03 23:10:47 -07:00
|
|
|
return mPreferredApplication->LaunchWithURI(aURI, aWindowContext);
|
2007-08-20 17:47:47 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMIMEInfoBase::CopyBasicDataTo(nsMIMEInfoBase* aOther)
|
|
|
|
{
|
2010-05-06 00:22:01 -07:00
|
|
|
aOther->mSchemeOrType = mSchemeOrType;
|
2007-03-22 10:30:00 -07:00
|
|
|
aOther->mDefaultAppDescription = mDefaultAppDescription;
|
|
|
|
aOther->mExtensions = mExtensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2010-03-18 01:37:12 -07:00
|
|
|
already_AddRefed<nsIProcess>
|
|
|
|
nsMIMEInfoBase::InitProcess(nsIFile* aApp, nsresult* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-28 20:38:52 -07:00
|
|
|
NS_ASSERTION(aApp, "Unexpected null pointer, fix caller");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-18 01:37:12 -07:00
|
|
|
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID,
|
|
|
|
aResult);
|
|
|
|
if (NS_FAILED(*aResult))
|
|
|
|
return nsnull;
|
|
|
|
|
2010-07-02 13:56:09 -07:00
|
|
|
*aResult = process->Init(aApp);
|
|
|
|
if (NS_FAILED(*aResult))
|
2010-03-18 01:37:12 -07:00
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return process.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
nsMIMEInfoBase::LaunchWithIProcess(nsIFile* aApp, const nsCString& aArg)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv;
|
2010-03-18 01:37:12 -07:00
|
|
|
nsCOMPtr<nsIProcess> process = InitProcess(aApp, &rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2007-07-28 20:38:52 -07:00
|
|
|
const char *string = aArg.get();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-09 09:47:39 -07:00
|
|
|
return process->Run(PR_FALSE, &string, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-18 01:37:12 -07:00
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
nsMIMEInfoBase::LaunchWithIProcess(nsIFile* aApp, const nsString& aArg)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIProcess> process = InitProcess(aApp, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
const PRUnichar *string = aArg.get();
|
|
|
|
|
|
|
|
return process->Runw(PR_FALSE, &string, 1);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsMIMEInfoImpl implementation
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoImpl::GetDefaultDescription(nsAString& aDefaultDescription)
|
|
|
|
{
|
|
|
|
if (mDefaultAppDescription.IsEmpty() && mDefaultApplication) {
|
|
|
|
// Don't want to cache this, just in case someone resets the app
|
|
|
|
// without changing the description....
|
|
|
|
mDefaultApplication->GetLeafName(aDefaultDescription);
|
|
|
|
} else {
|
|
|
|
aDefaultDescription = mDefaultAppDescription;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoImpl::GetHasDefaultHandler(PRBool * _retval)
|
|
|
|
{
|
2007-07-30 16:33:16 -07:00
|
|
|
*_retval = !mDefaultAppDescription.IsEmpty();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mDefaultApplication) {
|
|
|
|
PRBool exists;
|
|
|
|
*_retval = NS_SUCCEEDED(mDefaultApplication->Exists(&exists)) && exists;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMIMEInfoImpl::LaunchDefaultWithFile(nsIFile* aFile)
|
|
|
|
{
|
|
|
|
if (!mDefaultApplication)
|
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
|
2007-07-28 20:38:52 -07:00
|
|
|
nsCAutoString nativePath;
|
|
|
|
aFile->GetNativePath(nativePath);
|
|
|
|
|
|
|
|
return LaunchWithIProcess(mDefaultApplication, nativePath);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-10-18 21:15:41 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMIMEInfoBase::GetPossibleLocalHandlers(nsIArray **_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|