зеркало из https://github.com/mozilla/pjs.git
bug 78919, last part. r=bzbarsky sr=darin.
This adds a new method launchWithFile on nsIMIMEInfo which takes care of opening the selected (preferred or default) application on the mime info with a specified document. defaultDescription is now readonly, and defaultApplication no longer available. This also removes the clone method which was unused in the entire tree.
This commit is contained in:
Родитель
0d599f1613
Коммит
8e085c81b9
|
@ -41,6 +41,9 @@
|
|||
* and file extensions. This means that a MIMEInfo object
|
||||
* may have multiple file extensions associated with it.
|
||||
* However, the reverse is not true.
|
||||
*
|
||||
* MIMEInfo objects are generally retrieved from the MIME Service
|
||||
* @see nsIMIMEService
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
@ -51,7 +54,7 @@ interface nsIUTF8StringEnumerator;
|
|||
|
||||
typedef long nsMIMEInfoHandleAction;
|
||||
|
||||
[scriptable, uuid(ca87c4cb-5d1c-49a9-8776-0099df1a7aa8)]
|
||||
[scriptable, uuid(4174ca8f-5a33-44fd-8735-ffb95baca30a)]
|
||||
interface nsIMIMEInfo : nsISupports {
|
||||
/**
|
||||
* Gives you an array of file types associated with this type.
|
||||
|
@ -64,7 +67,7 @@ interface nsIMIMEInfo : nsISupports {
|
|||
/**
|
||||
* Set File Extensions. Input is a comma delimited list of extensions.
|
||||
*/
|
||||
void SetFileExtensions( in string aExtensions );
|
||||
void SetFileExtensions(in string aExtensions);
|
||||
|
||||
/**
|
||||
* Returns whether or not the given extension is
|
||||
|
@ -79,13 +82,6 @@ interface nsIMIMEInfo : nsISupports {
|
|||
*/
|
||||
void AppendExtension(in string aExtension);
|
||||
|
||||
/**
|
||||
* Returns a clone of this MIMEInfo.
|
||||
*
|
||||
* @return A clone of the MIMEInfo
|
||||
*/
|
||||
nsIMIMEInfo clone();
|
||||
|
||||
/**
|
||||
* Returns the first extension association in
|
||||
* the internal set of extensions.
|
||||
|
@ -131,28 +127,34 @@ interface nsIMIMEInfo : nsISupports {
|
|||
attribute nsIFile preferredApplicationHandler;
|
||||
|
||||
/**
|
||||
* a pretty name description of the associated application
|
||||
* A pretty name description of the preferred application.
|
||||
*/
|
||||
attribute wstring applicationDescription;
|
||||
|
||||
/**
|
||||
* Indicates whether a default application handler exists,
|
||||
* i.e. whether the defaultApplicationHandler attribute is valid
|
||||
* i.e. whether launchWithFile with action = useSystemDefault is possible
|
||||
* and applicationDescription will contain usable information.
|
||||
*/
|
||||
readonly attribute boolean hasDefaultHandler;
|
||||
|
||||
/**
|
||||
* Returns a nsIFile that points to the application that is associated
|
||||
* by default with this content type. This will usually be specified in
|
||||
* the platform settings somehow. This is only guaranteed to be set if
|
||||
* hasDefaultHandler is true!
|
||||
* A pretty name description of the associated default application. Only
|
||||
* usable if hasDefaultHandler is true.
|
||||
*/
|
||||
attribute nsIFile defaultApplicationHandler;
|
||||
readonly attribute wstring defaultDescription;
|
||||
|
||||
/**
|
||||
* a pretty name description of the default application
|
||||
* Launches the application with the specified file, in a way that
|
||||
* depends on the value of preferredAction. preferredAction must be
|
||||
* useHelperApp or useSystemDefault.
|
||||
*
|
||||
* @param aFile The file to launch this application with.
|
||||
*
|
||||
* @throw NS_ERROR_INVALID_ARG if action is not valid for this function.
|
||||
* Other exceptions may be thrown.
|
||||
*/
|
||||
attribute wstring defaultDescription;
|
||||
void launchWithFile(in nsIFile aFile);
|
||||
|
||||
const long saveToDisk = 0;
|
||||
const long alwaysAsk = 1;
|
||||
|
|
|
@ -79,14 +79,28 @@ OSHELPER = nsOSHelperAppService.cpp
|
|||
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
|
||||
OSHELPER += nsInternetConfig.cpp \
|
||||
nsInternetConfigService.cpp \
|
||||
nsMIMEInfoMac.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDES = -I$(srcdir)
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
|
||||
OSHELPER += nsGNOMERegistry.cpp
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDES = -I$(srcdir)
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
|
||||
OSHELPER += nsMIMEInfoBeOS.cpp
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
OSHELPER += nsMIMEInfoWin.cpp
|
||||
LOCAL_INCLUDES += -I$(srcdir)/win
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
OSHELPER += nsMIMEInfoOS2.cpp
|
||||
endif
|
||||
|
||||
EXPORTS = \
|
||||
$(OSDIR)/nsOSHelperAppService.h \
|
||||
|
@ -111,7 +125,8 @@ CPPSRCS = \
|
|||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
OS_LIBS += shell32.lib
|
||||
GARBAGE += nsOSHelperAppService.cpp $(srcdir)/nsOSHelperAppService.cpp
|
||||
GARBAGE += nsOSHelperAppService.cpp $(srcdir)/nsOSHelperAppService.cpp \
|
||||
nsMIMEInfoWin.cpp $(srcdir)/nsMIMEInfoWin.cpp
|
||||
endif
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
|
@ -125,6 +140,6 @@ endif
|
|||
|
||||
# the use of multiple VPATH dirs is broken in cygwin make
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
export:: $(OSDIR)/nsOSHelperAppService.cpp
|
||||
export:: $(OSDIR)/nsOSHelperAppService.cpp $(OSDIR)/nsMIMEInfoWin.cpp
|
||||
$(INSTALL) $^ .
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/* ***** 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 nsOSHelperAppService.cpp.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Paul Ashford.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Christian Biesinger <cbiesinger@web.de>
|
||||
*
|
||||
* 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 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 "nsMIMEInfoBeOS.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
nsMIMEInfoBeOS::nsMIMEInfoBeOS() : nsMIMEInfoImpl()
|
||||
{
|
||||
}
|
||||
|
||||
nsMIMEInfoBeOS::nsMIMEInfoBeOS(const char* aType) : nsMIMEInfoImpl(aType)
|
||||
{
|
||||
}
|
||||
|
||||
nsMIMEInfoBeOS::~nsMIMEInfoBeOS()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMIMEInfoBeOS::LaunchDefaultWithFile(nsIFile* aFile)
|
||||
{
|
||||
// Launch the file, unless it is an executable.
|
||||
nsCOMPtr<nsILocalFile> local(do_QueryInterface(aFile));
|
||||
if (!local)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRBool executable = PR_TRUE;
|
||||
local->IsExecutable(&executable);
|
||||
if (executable)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return local->Launch();
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/* ***** 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 the BeOS MIME Info Implementation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christian Biesinger <cbiesinger@web.de>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* 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 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 ***** */
|
||||
|
||||
#ifndef nsMIMEInfoBeOS_h_
|
||||
#define nsMIMEInfoBeOS_h_
|
||||
|
||||
#include "nsMIMEInfoImpl.h"
|
||||
|
||||
class nsMIMEInfoBeOS : public nsMIMEInfoImpl {
|
||||
public:
|
||||
nsMIMEInfoBeOS();
|
||||
nsMIMEInfoBeOS(const char* aType);
|
||||
virtual ~nsMIMEInfoBeOS();
|
||||
|
||||
protected:
|
||||
virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -35,6 +35,7 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsOSHelperAppService.h"
|
||||
#include "nsMIMEInfoBeOS.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
@ -61,55 +62,6 @@ nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
|
|||
nsOSHelperAppService::~nsOSHelperAppService()
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInfo, nsIFile * aTempFile)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
LOG(("nsOSHelperAppService::LaunchAppWithTempFile\n"));
|
||||
|
||||
if (aMIMEInfo)
|
||||
{
|
||||
nsCOMPtr<nsIFile> application;
|
||||
nsCAutoString path;
|
||||
aTempFile->GetNativePath(path);
|
||||
|
||||
nsMIMEInfoHandleAction action = nsIMIMEInfo::useSystemDefault;
|
||||
aMIMEInfo->GetPreferredAction(&action);
|
||||
|
||||
aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application));
|
||||
if (application && action == nsIMIMEInfo::useHelperApp)
|
||||
{
|
||||
// if we were given an application to use then use it....otherwise
|
||||
// make the registry call to launch the app
|
||||
const char * strPath = path.get();
|
||||
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID);
|
||||
nsresult rv;
|
||||
if (NS_FAILED(rv = process->Init(application)))
|
||||
return rv;
|
||||
PRUint32 pid;
|
||||
if (NS_FAILED(rv = process->Run(PR_FALSE, &strPath, 1, &pid)))
|
||||
return rv;
|
||||
}
|
||||
else // use the system default
|
||||
{
|
||||
// Launch the temp file, unless it is an executable.
|
||||
nsCOMPtr<nsILocalFile> local(do_QueryInterface(aTempFile));
|
||||
if (!local)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRBool executable = PR_TRUE;
|
||||
local->IsExecutable(&executable);
|
||||
if (executable)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
rv = local->Launch();
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists)
|
||||
{
|
||||
LOG(("-- nsOSHelperAppService::ExternalProtocolHandlerExists for '%s'\n",
|
||||
|
@ -160,8 +112,9 @@ nsresult nsOSHelperAppService::SetMIMEInfoForType(const char *aMIMEType, nsIMIME
|
|||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIMIMEInfo> mimeInfo = new nsMIMEInfoImpl();
|
||||
nsMIMEInfoBeOS* mimeInfo = new nsMIMEInfoBeOS();
|
||||
if (mimeInfo) {
|
||||
NS_ADDREF(mimeInfo);
|
||||
BMimeType mimeType(aMIMEType);
|
||||
BMessage data;
|
||||
mimeInfo->SetMIMEType(aMIMEType);
|
||||
|
@ -211,7 +164,7 @@ nsresult nsOSHelperAppService::SetMIMEInfoForType(const char *aMIMEType, nsIMIME
|
|||
rv = GetFileTokenForPath(NS_ConvertUTF8toUCS2(path.Path()).get(), getter_AddRefs(handlerFile));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mimeInfo->SetDefaultApplicationHandler(handlerFile);
|
||||
mimeInfo->SetDefaultApplication(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUCS2(path.Leaf()).get());
|
||||
LOG((" Preferred App: %s\n",path.Leaf()));
|
||||
|
@ -225,7 +178,6 @@ nsresult nsOSHelperAppService::SetMIMEInfoForType(const char *aMIMEType, nsIMIME
|
|||
}
|
||||
|
||||
*_retval = mimeInfo;
|
||||
NS_ADDREF(*_retval);
|
||||
rv = NS_OK;
|
||||
}
|
||||
else
|
||||
|
@ -327,7 +279,7 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char *aMIMEType, const char *aFile
|
|||
return mi;
|
||||
|
||||
*aFound = PR_FALSE;
|
||||
mi = new nsMIMEInfoImpl();
|
||||
mi = new nsMIMEInfoBeOS();
|
||||
if (!mi)
|
||||
return nsnull;
|
||||
NS_ADDREF(mi);
|
||||
|
|
|
@ -51,9 +51,6 @@ public:
|
|||
nsOSHelperAppService();
|
||||
virtual ~nsOSHelperAppService();
|
||||
|
||||
// override nsIExternalHelperAppService methods....
|
||||
NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile);
|
||||
|
||||
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const char *aMIMEType, const char * aFileExt, PRBool *aFound);
|
||||
|
||||
// override nsIExternalProtocolService methods
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
#include "nsInternetConfigService.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIMIMEInfo.h"
|
||||
#include "nsMIMEInfoImpl.h"
|
||||
#include "nsMIMEInfoMac.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIURL.h"
|
||||
|
@ -357,7 +358,7 @@ nsresult nsInternetConfigService::FillMIMEInfoForICEntry(ICMapEntry& entry, nsIM
|
|||
{
|
||||
// create a mime info object and we'll fill it in based on the values from IC mapping entry
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIMIMEInfo> info (new nsMIMEInfoImpl());
|
||||
nsRefPtr<nsMIMEInfoMac> info (new nsMIMEInfoMac());
|
||||
if (info)
|
||||
{
|
||||
nsCAutoString mimetype ((char *)&entry.MIMEType[1], entry.MIMEType[0]);
|
||||
|
@ -399,7 +400,7 @@ nsresult nsInternetConfigService::FillMIMEInfoForICEntry(ICMapEntry& entry, nsIM
|
|||
{
|
||||
nsCOMPtr<nsIFile> nsfile = do_QueryInterface(file, &rv);
|
||||
if (rv == NS_OK)
|
||||
info->SetDefaultApplicationHandler(nsfile);
|
||||
info->SetDefaultApplication(nsfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Scott MacGregor <mscott@netscape.com>
|
||||
* Christian Biesinger <cbiesinger@web.de>
|
||||
*/
|
||||
|
||||
|
||||
#include "nsMIMEInfoMac.h"
|
||||
#include "nsILocalFileMac.h"
|
||||
|
||||
nsMIMEInfoMac::nsMIMEInfoMac() : nsMIMEInfoImpl()
|
||||
{
|
||||
}
|
||||
|
||||
nsMIMEInfoMac::nsMIMEInfoMac(const char* aType) : nsMIMEInfoImpl(aType)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoMac::LaunchWithFile(nsIFile* aFile)
|
||||
{
|
||||
nsIFile* application;
|
||||
|
||||
if (mPreferredAction == useHelperApp)
|
||||
application = mPreferredApplication;
|
||||
else if (mPreferredAction == useSystemDefault)
|
||||
application = mDefaultApplication;
|
||||
else
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (application) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILocalFileMac> app = do_QueryInterface(application, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> docToLoad = do_QueryInterface(aFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return app->LaunchWithDoc(docToLoad, PR_FALSE);
|
||||
}
|
||||
#ifdef XP_MACOSX
|
||||
// We didn't get an application to handle the file from aMIMEInfo, ask LaunchServices directly
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsILocalFileMac> tempFile = do_QueryInterface(aTempFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
FSRef tempFileRef;
|
||||
tempFile->GetFSRef(&tempFileRef);
|
||||
|
||||
FSRef appFSRef;
|
||||
if (::LSGetApplicationForItem(&tempFileRef, kLSRolesAll, &appFSRef, nsnull) == noErr)
|
||||
{
|
||||
nsCOMPtr<nsILocalFileMac> app(do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
if (!app) return NS_ERROR_FAILURE;
|
||||
app->InitWithFSRef(&appFSRef);
|
||||
|
||||
nsCOMPtr <nsILocalFile> docToLoad = do_QueryInterface(aTempFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = app->LaunchWithDoc(docToLoad, PR_FALSE);
|
||||
}
|
||||
return rv;
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/* ***** 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 the MacOS MIMEInfo Implementation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christian Biesinger <cbiesinger@web.de>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* 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 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 ***** */
|
||||
|
||||
#ifndef nsMIMEInfoMac_h_
|
||||
#define nsMIMEInfoMac_h_
|
||||
|
||||
#include "nsMIMEInfoImpl.h"
|
||||
|
||||
class nsMIMEInfoMac : public nsMIMEInfoImpl {
|
||||
public:
|
||||
nsMIMEInfoMac();
|
||||
nsMIMEInfoMac(const char* aMIMEType);
|
||||
|
||||
NS_IMETHOD LaunchWithFile(nsIFile* aFile);
|
||||
|
||||
#ifdef DEBUG
|
||||
protected:
|
||||
virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile) {
|
||||
NS_NOTREACHED("do not call this method, use LaunchWithFile");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -32,6 +32,7 @@
|
|||
#include "nsIPromptService.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsMIMEInfoMac.h"
|
||||
|
||||
#include "nsIInternetConfigService.h"
|
||||
|
||||
|
@ -50,57 +51,6 @@ nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
|
|||
nsOSHelperAppService::~nsOSHelperAppService()
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInfo, nsIFile * aTempFile)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (aMIMEInfo)
|
||||
{
|
||||
nsCOMPtr<nsIFile> application;
|
||||
|
||||
nsMIMEInfoHandleAction action = nsIMIMEInfo::useSystemDefault;
|
||||
aMIMEInfo->GetPreferredAction(&action);
|
||||
|
||||
if (action==nsIMIMEInfo::useHelperApp)
|
||||
aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application));
|
||||
else
|
||||
aMIMEInfo->GetDefaultApplicationHandler(getter_AddRefs(application));
|
||||
|
||||
if (application) {
|
||||
nsCOMPtr<nsILocalFileMac> app = do_QueryInterface(application, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> docToLoad = do_QueryInterface(aTempFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = app->LaunchWithDoc(docToLoad, PR_FALSE);
|
||||
}
|
||||
#ifdef XP_MACOSX
|
||||
else
|
||||
{ // We didn't get an application to handle the file from aMIMEInfo, ask LaunchServices directly
|
||||
nsCOMPtr <nsILocalFileMac> tempFile = do_QueryInterface(aTempFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
FSRef tempFileRef;
|
||||
tempFile->GetFSRef(&tempFileRef);
|
||||
|
||||
FSRef appFSRef;
|
||||
if (::LSGetApplicationForItem(&tempFileRef, kLSRolesAll, &appFSRef, nsnull) == noErr)
|
||||
{
|
||||
nsCOMPtr<nsILocalFileMac> app(do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
if (!app) return NS_ERROR_FAILURE;
|
||||
app->InitWithFSRef(&appFSRef);
|
||||
|
||||
nsCOMPtr <nsILocalFile> docToLoad = do_QueryInterface(aTempFile, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = app->LaunchWithDoc(docToLoad, PR_FALSE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists)
|
||||
{
|
||||
// look up the protocol scheme in Internet Config....if we find a match then we have a handler for it...
|
||||
|
@ -269,13 +219,19 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char * aMIMEType,
|
|||
|
||||
// If we got two matches, and the type has no default app, copy default app
|
||||
if (!hasDefault && miByType && miByExt) {
|
||||
nsCOMPtr<nsIFile> defaultApp;
|
||||
nsXPIDLString desc;
|
||||
miByExt->GetDefaultDescription(getter_Copies(desc));
|
||||
miByExt->GetDefaultApplicationHandler(getter_AddRefs(defaultApp));
|
||||
|
||||
miByType->SetDefaultDescription(desc.get());
|
||||
miByType->SetDefaultApplicationHandler(defaultApp);
|
||||
// IC currently always uses nsMIMEInfoBase-derived classes.
|
||||
// When it stops doing that, this code will need changing.
|
||||
// Using dynamic_cast here so we can fail sorta gracefully if this is no
|
||||
// nsMIMEInfoBase.
|
||||
nsMIMEInfoBase* byType = dynamic_cast<nsMIMEInfoBase*>(miByType.get());
|
||||
nsMIMEInfoBase* byExt = dynamic_cast<nsMIMEInfoBase*>(miByExt.get());
|
||||
if (!byType || !byExt) {
|
||||
NS_ERROR("IC gave us an nsIMIMEInfo that's no nsMIMEInfoBase! Fix nsOSHelperAppService.");
|
||||
return nsnull;
|
||||
}
|
||||
// Copy the attributes of miByType onto miByExt
|
||||
byType->CopyBasicDataTo(byExt);
|
||||
miByType = miByExt;
|
||||
}
|
||||
if (miByType)
|
||||
miByType.swap(mimeInfo);
|
||||
|
@ -286,7 +242,7 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char * aMIMEType,
|
|||
if (!mimeInfo) {
|
||||
*aFound = PR_FALSE;
|
||||
PR_LOG(mLog, PR_LOG_DEBUG, ("Creating new mimeinfo\n"));
|
||||
mimeInfo = new nsMIMEInfoImpl();
|
||||
mimeInfo = new nsMIMEInfoMac();
|
||||
if (!mimeInfo)
|
||||
return nsnull;
|
||||
NS_ADDREF(mimeInfo);
|
||||
|
|
|
@ -37,9 +37,6 @@ public:
|
|||
nsOSHelperAppService();
|
||||
virtual ~nsOSHelperAppService();
|
||||
|
||||
// override nsIExternalHelperAppService methods....
|
||||
NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile);
|
||||
|
||||
// override nsIExternalProtocolService methods
|
||||
NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
|
||||
NS_IMETHOD LoadUrl(nsIURI * aURL);
|
||||
|
|
|
@ -607,12 +607,6 @@ NS_IMETHODIMP nsExternalHelperAppService::ApplyDecodingForExtension(const char *
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsExternalHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMimeInfo, nsIFile * aTempFile)
|
||||
{
|
||||
// this method should only be implemented by each OS specific implementation of this service.
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsExternalAppHandler * nsExternalHelperAppService::CreateNewExternalHandler(nsIMIMEInfo * aMIMEInfo,
|
||||
const char * aTempFileExtension,
|
||||
const nsAString& aFileName,
|
||||
|
@ -1060,10 +1054,10 @@ nsExternalAppHandler::~nsExternalAppHandler()
|
|||
|
||||
NS_IMETHODIMP nsExternalAppHandler::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData )
|
||||
{
|
||||
if (PL_strcmp(aTopic, "oncancel") == 0)
|
||||
if (strcmp(aTopic, "oncancel") == 0)
|
||||
{
|
||||
// User pressed cancel button on dialog.
|
||||
return this->Cancel();
|
||||
return Cancel();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1703,7 +1697,7 @@ nsresult nsExternalAppHandler::ExecuteDesiredAction()
|
|||
// Source and dest dirs should be == so this should just do a rename
|
||||
rv = MoveFile(mFinalFileDestination);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = OpenWithApplication(nsnull);
|
||||
rv = OpenWithApplication();
|
||||
}
|
||||
}
|
||||
else // Various unknown actions go here too
|
||||
|
@ -1986,7 +1980,7 @@ NS_IMETHODIMP nsExternalAppHandler::SaveToDisk(nsIFile * aNewFileLocation, PRBoo
|
|||
}
|
||||
|
||||
|
||||
nsresult nsExternalAppHandler::OpenWithApplication(nsIFile * aApplication)
|
||||
nsresult nsExternalAppHandler::OpenWithApplication()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mCanceled)
|
||||
|
@ -1998,8 +1992,7 @@ nsresult nsExternalAppHandler::OpenWithApplication(nsIFile * aApplication)
|
|||
// if a stop request was already issued then proceed with launching the application.
|
||||
if (mStopRequestIssued)
|
||||
{
|
||||
NS_ASSERTION(mHelperAppService, "Not initialized");
|
||||
rv = mHelperAppService->LaunchAppWithTempFile(mMimeInfo, mFinalFileDestination);
|
||||
rv = mMimeInfo->LaunchWithFile(mFinalFileDestination);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
// Send error notification.
|
||||
|
@ -2011,6 +2004,7 @@ nsresult nsExternalAppHandler::OpenWithApplication(nsIFile * aApplication)
|
|||
else
|
||||
{
|
||||
#if !defined(XP_MAC) && !defined (XP_MACOSX)
|
||||
NS_ASSERTION(mHelperAppService, "Not initialized");
|
||||
// Mac users have been very verbal about temp files being deleted on app exit - they
|
||||
// don't like it - but we'll continue to do this on other platforms for now
|
||||
mHelperAppService->DeleteTemporaryFileOnExit(mFinalFileDestination);
|
||||
|
@ -2050,8 +2044,7 @@ NS_IMETHODIMP nsExternalAppHandler::LaunchWithApplication(nsIFile * aApplication
|
|||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
NS_ASSERTION(mHelperAppService, "Not initialized");
|
||||
rv = mHelperAppService->LaunchAppWithTempFile(mMimeInfo, file);
|
||||
rv = mMimeInfo->LaunchWithFile(file);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -234,7 +234,6 @@ protected:
|
|||
nsresult GetMIMEInfoForExtensionFromExtras(const char * aExtension,
|
||||
nsIMIMEInfo * aMIMEInfo);
|
||||
|
||||
protected:
|
||||
#ifdef PR_LOGGING
|
||||
/**
|
||||
* NSPR Logging Module. Usage: set NSPR_LOG_MODULES=HelperAppService:level,
|
||||
|
@ -246,6 +245,7 @@ protected:
|
|||
// friend, so that it can access the nspr log module
|
||||
friend class nsExternalAppHandler;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Functions related to the tempory file cleanup service provided by
|
||||
* nsExternalHelperAppService
|
||||
|
@ -370,8 +370,9 @@ protected:
|
|||
/**
|
||||
* An internal method used to actually launch a helper app given the temp file
|
||||
* once we are done receiving data AND have showed the progress dialog.
|
||||
* Uses the application specified in the mime info.
|
||||
*/
|
||||
nsresult OpenWithApplication(nsIFile * aApplication);
|
||||
nsresult OpenWithApplication();
|
||||
|
||||
/**
|
||||
* Helper routine which peaks at the mime action specified by mMimeInfo
|
||||
|
|
|
@ -65,16 +65,9 @@ interface nsIExternalHelperAppService : nsISupports
|
|||
* This is a private interface shared between external app handlers and the platform specific
|
||||
* external helper app service
|
||||
*/
|
||||
[scriptable, uuid(491D04D5-449C-11d4-98D0-001083010E9B)]
|
||||
[scriptable, uuid(d0b5d7d3-9565-403d-9fb5-e5089c4567c6)]
|
||||
interface nsPIExternalAppLauncher : nsISupports
|
||||
{
|
||||
/**
|
||||
* Used by the handler to actually launch the helper application.
|
||||
* @param aTempFile The file which contains the data we want the helper app
|
||||
* to use when it is launched
|
||||
*/
|
||||
void launchAppWithTempFile(in nsIMIMEInfo aMIMEInfo, in nsIFile aTempFile);
|
||||
|
||||
/**
|
||||
* mscott --> eventually I should move this into a new service so other
|
||||
* consumers can add temporary files they want deleted on exit.
|
||||
|
|
|
@ -39,34 +39,38 @@
|
|||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsStringEnumerator.h"
|
||||
#include "nsIProcess.h"
|
||||
|
||||
// nsISupports methods
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMIMEInfoImpl, nsIMIMEInfo)
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMIMEInfoBase, nsIMIMEInfo)
|
||||
|
||||
// nsMIMEInfoImpl methods
|
||||
nsMIMEInfoImpl::nsMIMEInfoImpl() {
|
||||
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
||||
mAlwaysAskBeforeHandling = PR_TRUE;
|
||||
nsMIMEInfoBase::nsMIMEInfoBase() :
|
||||
mPreferredAction(nsIMIMEInfo::saveToDisk),
|
||||
mAlwaysAskBeforeHandling(PR_TRUE)
|
||||
{
|
||||
}
|
||||
|
||||
nsMIMEInfoImpl::nsMIMEInfoImpl(const char *aMIMEType) :mMIMEType( aMIMEType ){
|
||||
mPreferredAction = nsIMIMEInfo::saveToDisk;
|
||||
mAlwaysAskBeforeHandling = PR_TRUE;
|
||||
nsMIMEInfoBase::nsMIMEInfoBase(const char *aMIMEType) :
|
||||
mMIMEType(aMIMEType),
|
||||
mPreferredAction(nsIMIMEInfo::saveToDisk),
|
||||
mAlwaysAskBeforeHandling(PR_TRUE)
|
||||
{
|
||||
}
|
||||
|
||||
PRUint32
|
||||
nsMIMEInfoImpl::GetExtCount() {
|
||||
return mExtensions.Count();
|
||||
nsMIMEInfoBase::~nsMIMEInfoBase()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::GetFileExtensions(nsIUTF8StringEnumerator** aResult)
|
||||
nsMIMEInfoBase::GetFileExtensions(nsIUTF8StringEnumerator** aResult)
|
||||
{
|
||||
return NS_NewUTF8StringEnumerator(aResult, &mExtensions, this);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::ExtensionExists(const char *aExtension, PRBool *_retval) {
|
||||
nsMIMEInfoBase::ExtensionExists(const char *aExtension, PRBool *_retval)
|
||||
{
|
||||
NS_ASSERTION(aExtension, "no extension");
|
||||
PRBool found = PR_FALSE;
|
||||
PRUint32 extCount = mExtensions.Count();
|
||||
|
@ -88,7 +92,8 @@ nsMIMEInfoImpl::ExtensionExists(const char *aExtension, PRBool *_retval) {
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::GetPrimaryExtension(char **_retval) {
|
||||
nsMIMEInfoBase::GetPrimaryExtension(char **_retval)
|
||||
{
|
||||
PRUint32 extCount = mExtensions.Count();
|
||||
if (extCount < 1) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
|
@ -98,7 +103,8 @@ nsMIMEInfoImpl::GetPrimaryExtension(char **_retval) {
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::SetPrimaryExtension(const char *aExtension) {
|
||||
nsMIMEInfoBase::SetPrimaryExtension(const char *aExtension)
|
||||
{
|
||||
NS_ASSERTION(aExtension, "no extension");
|
||||
PRUint32 extCount = mExtensions.Count();
|
||||
nsCString extension(aExtension);
|
||||
|
@ -120,40 +126,16 @@ nsMIMEInfoImpl::SetPrimaryExtension(const char *aExtension) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::AppendExtension(const char *aExtension)
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::AppendExtension(const char *aExtension)
|
||||
{
|
||||
mExtensions.AppendCString( nsCAutoString(aExtension) );
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::GetMIMEType(char * *aMIMEType) {
|
||||
nsMIMEInfoBase::GetMIMEType(char * *aMIMEType)
|
||||
{
|
||||
if (!aMIMEType) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (mMIMEType.IsEmpty())
|
||||
|
@ -165,7 +147,8 @@ nsMIMEInfoImpl::GetMIMEType(char * *aMIMEType) {
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::SetMIMEType(const char* aMIMEType) {
|
||||
nsMIMEInfoBase::SetMIMEType(const char* aMIMEType)
|
||||
{
|
||||
if (!aMIMEType) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
mMIMEType=aMIMEType;
|
||||
|
@ -173,7 +156,8 @@ nsMIMEInfoImpl::SetMIMEType(const char* aMIMEType) {
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::GetDescription(PRUnichar * *aDescription) {
|
||||
nsMIMEInfoBase::GetDescription(PRUnichar * *aDescription)
|
||||
{
|
||||
if (!aDescription) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aDescription = ToNewUnicode(mDescription);
|
||||
|
@ -181,14 +165,16 @@ nsMIMEInfoImpl::GetDescription(PRUnichar * *aDescription) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetDescription(const PRUnichar * aDescription)
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::SetDescription(const PRUnichar * aDescription)
|
||||
{
|
||||
mDescription = aDescription;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval) {
|
||||
nsMIMEInfoBase::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval)
|
||||
{
|
||||
if (!aMIMEInfo) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsXPIDLCString type;
|
||||
|
@ -200,31 +186,36 @@ nsMIMEInfoImpl::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetMacType(PRUint32 *aMacType)
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::GetMacType(PRUint32 *aMacType)
|
||||
{
|
||||
*aMacType = mMacType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetMacType(PRUint32 aMacType)
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::SetMacType(PRUint32 aMacType)
|
||||
{
|
||||
mMacType = aMacType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetMacCreator(PRUint32 *aMacCreator)
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::GetMacCreator(PRUint32 *aMacCreator)
|
||||
{
|
||||
*aMacCreator = mMacCreator;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetMacCreator(PRUint32 aMacCreator)
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::SetMacCreator(PRUint32 aMacCreator)
|
||||
{
|
||||
mMacCreator = aMacCreator;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetFileExtensions( const char* aExtensions )
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::SetFileExtensions(const char* aExtensions)
|
||||
{
|
||||
mExtensions.Clear();
|
||||
nsCString extList( aExtensions );
|
||||
|
@ -241,7 +232,8 @@ NS_IMETHODIMP nsMIMEInfoImpl::SetFileExtensions( const char* aExtensions )
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetApplicationDescription(PRUnichar ** aApplicationDescription)
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::GetApplicationDescription(PRUnichar ** aApplicationDescription)
|
||||
{
|
||||
if (mPreferredAppDescription.IsEmpty() && mPreferredApplication) {
|
||||
// Don't want to cache this, just in case someone resets the app
|
||||
|
@ -256,13 +248,117 @@ NS_IMETHODIMP nsMIMEInfoImpl::GetApplicationDescription(PRUnichar ** aApplicatio
|
|||
return *aApplicationDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetApplicationDescription(const PRUnichar * aApplicationDescription)
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::SetApplicationDescription(const PRUnichar * aApplicationDescription)
|
||||
{
|
||||
mPreferredAppDescription = aApplicationDescription;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetDefaultDescription(PRUnichar ** aDefaultDescription)
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::GetDefaultDescription(PRUnichar ** aDefaultDescription)
|
||||
{
|
||||
*aDefaultDescription = ToNewUnicode(mDefaultAppDescription);
|
||||
return *aDefaultDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::GetPreferredApplicationHandler(nsIFile ** aPreferredAppHandler)
|
||||
{
|
||||
*aPreferredAppHandler = mPreferredApplication;
|
||||
NS_IF_ADDREF(*aPreferredAppHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::SetPreferredApplicationHandler(nsIFile * aPreferredAppHandler)
|
||||
{
|
||||
mPreferredApplication = aPreferredAppHandler;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::GetPreferredAction(nsMIMEInfoHandleAction * aPreferredAction)
|
||||
{
|
||||
*aPreferredAction = mPreferredAction;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::SetPreferredAction(nsMIMEInfoHandleAction aPreferredAction)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::LaunchWithFile(nsIFile* aFile)
|
||||
{
|
||||
if (mPreferredAction == useHelperApp) {
|
||||
if (!mPreferredApplication)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
return LaunchWithIProcess(mPreferredApplication, aFile);
|
||||
}
|
||||
else if (mPreferredAction == useSystemDefault) {
|
||||
return LaunchDefaultWithFile(aFile);
|
||||
}
|
||||
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
void
|
||||
nsMIMEInfoBase::CopyBasicDataTo(nsMIMEInfoBase* aOther)
|
||||
{
|
||||
aOther->mMIMEType = mMIMEType;
|
||||
aOther->mDefaultAppDescription = mDefaultAppDescription;
|
||||
aOther->mExtensions = mExtensions;
|
||||
|
||||
aOther->mMacType = mMacType;
|
||||
aOther->mMacCreator = mMacCreator;
|
||||
}
|
||||
|
||||
/* static */
|
||||
nsresult
|
||||
nsMIMEInfoBase::LaunchWithIProcess(nsIFile* aApp, nsIFile* aFile)
|
||||
{
|
||||
NS_ASSERTION(aApp && aFile, "Unexpected null pointer, fix caller");
|
||||
|
||||
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;
|
||||
|
||||
nsCAutoString path;
|
||||
aFile->GetNativePath(path);
|
||||
|
||||
const char * strPath = path.get();
|
||||
|
||||
PRUint32 pid;
|
||||
return process->Run(PR_FALSE, &strPath, 1, &pid);
|
||||
}
|
||||
|
||||
// nsMIMEInfoImpl implementation
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::GetDefaultDescription(PRUnichar ** aDefaultDescription)
|
||||
{
|
||||
if (mDefaultAppDescription.IsEmpty() && mDefaultApplication) {
|
||||
// Don't want to cache this, just in case someone resets the app
|
||||
|
@ -277,73 +373,24 @@ NS_IMETHODIMP nsMIMEInfoImpl::GetDefaultDescription(PRUnichar ** aDefaultDescrip
|
|||
return *aDefaultDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetDefaultDescription(const PRUnichar * aDefaultDescription)
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::GetHasDefaultHandler(PRBool * _retval)
|
||||
{
|
||||
mDefaultAppDescription = aDefaultDescription;
|
||||
*_retval = PR_FALSE;
|
||||
if (mDefaultApplication) {
|
||||
PRBool exists;
|
||||
*_retval = NS_SUCCEEDED(mDefaultApplication->Exists(&exists)) && exists;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetPreferredApplicationHandler(nsIFile ** aPreferredAppHandler)
|
||||
nsresult
|
||||
nsMIMEInfoImpl::LaunchDefaultWithFile(nsIFile* aFile)
|
||||
{
|
||||
*aPreferredAppHandler = mPreferredApplication;
|
||||
NS_IF_ADDREF(*aPreferredAppHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetPreferredApplicationHandler(nsIFile * aPreferredAppHandler)
|
||||
{
|
||||
mPreferredApplication = aPreferredAppHandler;
|
||||
return NS_OK;
|
||||
}
|
||||
if (!mDefaultApplication)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetHasDefaultHandler(PRBool * _retval)
|
||||
{
|
||||
#ifdef XP_WIN
|
||||
// On Windows, we ShellExecute any kind of file
|
||||
// (defaultApplication is always null on windows, too)
|
||||
// Most useful is probably presence/lack of default description
|
||||
*_retval = !mDefaultAppDescription.IsEmpty();
|
||||
#else
|
||||
*_retval = mDefaultApplication != nsnull;
|
||||
#endif
|
||||
return NS_OK;
|
||||
return LaunchWithIProcess(mDefaultApplication, aFile);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetDefaultApplicationHandler(nsIFile ** aDefaultAppHandler)
|
||||
{
|
||||
*aDefaultAppHandler = mDefaultApplication;
|
||||
NS_IF_ADDREF(*aDefaultAppHandler);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetDefaultApplicationHandler(nsIFile * aDefaultAppHandler)
|
||||
{
|
||||
mDefaultApplication = aDefaultAppHandler;
|
||||
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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetAlwaysAskBeforeHandling(PRBool * aAlwaysAsk)
|
||||
{
|
||||
*aAlwaysAsk = mAlwaysAskBeforeHandling;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetAlwaysAskBeforeHandling(PRBool aAlwaysAsk)
|
||||
{
|
||||
mAlwaysAskBeforeHandling = aAlwaysAsk;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -45,29 +45,123 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
class nsMIMEInfoImpl : public nsIMIMEInfo {
|
||||
public:
|
||||
/**
|
||||
* Basic implementation of nsIMIMEInfo. Incomplete - it is meant to be
|
||||
* subclassed, and GetHasDefaultHandler as well as LaunchDefaultWithFile need to
|
||||
* be implemented.
|
||||
*/
|
||||
class nsMIMEInfoBase : public nsIMIMEInfo {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMIMEINFO
|
||||
|
||||
// nsMIMEInfoImpl methods
|
||||
nsMIMEInfoImpl();
|
||||
nsMIMEInfoImpl(const char *aMIMEType);
|
||||
virtual ~nsMIMEInfoImpl() {};
|
||||
PRUint32 GetExtCount(); // returns the number of extensions associated.
|
||||
// I'd use NS_DECL_NSIMIMEINFO, but I don't want GetHasDefaultHandler
|
||||
NS_IMETHOD GetFileExtensions(nsIUTF8StringEnumerator **_retval);
|
||||
NS_IMETHOD SetFileExtensions(const char *aExtensions);
|
||||
NS_IMETHOD ExtensionExists(const char *aExtension, PRBool *_retval);
|
||||
NS_IMETHOD AppendExtension(const char *aExtension);
|
||||
NS_IMETHOD GetPrimaryExtension(char * *aPrimaryExtension);
|
||||
NS_IMETHOD SetPrimaryExtension(const char * aPrimaryExtension);
|
||||
NS_IMETHOD GetMIMEType(char * *aMIMEType);
|
||||
NS_IMETHOD SetMIMEType(const char * aMIMEType);
|
||||
NS_IMETHOD GetDescription(PRUnichar * *aDescription);
|
||||
NS_IMETHOD SetDescription(const PRUnichar * aDescription);
|
||||
NS_IMETHOD GetMacType(PRUint32 *aMacType);
|
||||
NS_IMETHOD SetMacType(PRUint32 aMacType);
|
||||
NS_IMETHOD GetMacCreator(PRUint32 *aMacCreator);
|
||||
NS_IMETHOD SetMacCreator(PRUint32 aMacCreator);
|
||||
NS_IMETHOD Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval);
|
||||
NS_IMETHOD GetPreferredApplicationHandler(nsIFile * *aPreferredApplicationHandler);
|
||||
NS_IMETHOD SetPreferredApplicationHandler(nsIFile * aPreferredApplicationHandler);
|
||||
NS_IMETHOD GetApplicationDescription(PRUnichar * *aApplicationDescription);
|
||||
NS_IMETHOD SetApplicationDescription(const PRUnichar * aApplicationDescription);
|
||||
NS_IMETHOD GetDefaultDescription(PRUnichar * *aDefaultDescription);
|
||||
NS_IMETHOD LaunchWithFile(nsIFile *aFile);
|
||||
NS_IMETHOD GetPreferredAction(nsMIMEInfoHandleAction *aPreferredAction);
|
||||
NS_IMETHOD SetPreferredAction(nsMIMEInfoHandleAction aPreferredAction);
|
||||
NS_IMETHOD GetAlwaysAskBeforeHandling(PRBool *aAlwaysAskBeforeHandling);
|
||||
NS_IMETHOD SetAlwaysAskBeforeHandling(PRBool aAlwaysAskBeforeHandling);
|
||||
|
||||
// nsMIMEInfoBase methods
|
||||
nsMIMEInfoBase();
|
||||
nsMIMEInfoBase(const char *aMIMEType);
|
||||
virtual ~nsMIMEInfoBase(); // must be virtual, as the the base class's Release should call the subclass's destructor
|
||||
|
||||
void SetDefaultDescription(const PRUnichar* aDesc) { mDefaultAppDescription = aDesc; }
|
||||
|
||||
/**
|
||||
* Copies basic data of this MIME Info Implementation to the given other
|
||||
* MIME Info. The data consists of the MIME Type, the (default) description,
|
||||
* the MacOS type and creator, and the extension list (this object's
|
||||
* extension list will replace aOther's list, not append to it). This
|
||||
* function also ensures that aOther's primary extension will be the same as
|
||||
* the one of this object.
|
||||
*/
|
||||
void CopyBasicDataTo(nsMIMEInfoBase* aOther);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Launch the default application for the given file.
|
||||
* For even more control over the launching, override launchWithFile.
|
||||
* Also see the comment about nsIMIMEInfo in general, above.
|
||||
*
|
||||
* @param aFile The file that should be opened
|
||||
*/
|
||||
virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile) = 0;
|
||||
|
||||
/**
|
||||
* This method can be used to launch the file using nsIProcess, with the
|
||||
* path of the file being the first parameter to the executable. This is
|
||||
* meant as a helper method for implementations of
|
||||
* LaunchWithFile/LaunchDefaultWithFile.
|
||||
* Neither aApp nor aFile may be null.
|
||||
*
|
||||
* @param aApp The application to launch
|
||||
* @param aFile The file to open in the application
|
||||
*/
|
||||
static NS_HIDDEN_(nsresult) LaunchWithIProcess(nsIFile* aApp, nsIFile* aFile);
|
||||
|
||||
// member variables
|
||||
nsCStringArray mExtensions; // array of file extensions associated w/ this MIME obj
|
||||
nsAutoString mDescription; // human readable description
|
||||
PRUint32 mMacType, mMacCreator; // Mac file type and creator
|
||||
protected:
|
||||
nsCString mMIMEType;
|
||||
nsCStringArray mExtensions; // array of file extensions associated w/ this MIME obj
|
||||
nsString mDescription; // human readable description
|
||||
PRUint32 mMacType, mMacCreator; // Mac file type and creator
|
||||
nsCString mMIMEType;
|
||||
nsCOMPtr<nsIFile> mPreferredApplication; // preferred application associated with this type.
|
||||
nsCOMPtr<nsIFile> mDefaultApplication; // default application associated with this type.
|
||||
nsMIMEInfoHandleAction mPreferredAction; // preferred action to associate with this type
|
||||
nsString mPreferredAppDescription;
|
||||
nsString mDefaultAppDescription;
|
||||
PRBool mAlwaysAskBeforeHandling;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This is a complete implementation of nsIMIMEInfo, and contains all necessary
|
||||
* methods. However, depending on your platform you may want to use a different
|
||||
* way of launching applications. This class stores the default application in a
|
||||
* member variable and provides a function for setting it. Launching is done
|
||||
* using nsIProcess, native path of the file to open as first argument.
|
||||
*/
|
||||
class nsMIMEInfoImpl : public nsMIMEInfoBase {
|
||||
public:
|
||||
nsMIMEInfoImpl() : nsMIMEInfoBase() {}
|
||||
nsMIMEInfoImpl(const char *aMIMEType) : nsMIMEInfoBase(aMIMEType) {}
|
||||
virtual ~nsMIMEInfoImpl() {}
|
||||
|
||||
// nsIMIMEInfo methods
|
||||
NS_IMETHOD GetHasDefaultHandler(PRBool *_retval);
|
||||
NS_IMETHOD GetDefaultDescription(PRUnichar ** aDefaultDescription);
|
||||
|
||||
// additional methods
|
||||
void SetDefaultApplication(nsIFile* aApp) { mDefaultApplication = aApp; }
|
||||
protected:
|
||||
// nsMIMEInfoBase methods
|
||||
/**
|
||||
* The base class implementation is to use LaunchWithIProcess in combination
|
||||
* with mDefaultApplication. Subclasses can override that behaviour.
|
||||
*/
|
||||
virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile);
|
||||
|
||||
|
||||
nsCOMPtr<nsIFile> mDefaultApplication; // default application associated with this type.
|
||||
};
|
||||
|
||||
#endif //__nsmimeinfoimpl_h___
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Scott MacGregor <mscott@netscape.com>
|
||||
* Boris Zbarsky <bzbarsky@mit.edu> (Added mailcap and mime.types support)
|
||||
* Christian Biesinger <cbiesinger@web.de>
|
||||
*/
|
||||
|
||||
|
||||
#define INCL_DOS
|
||||
#include <os2.h>
|
||||
|
||||
#include "nsMIMEInfoOS2.h"
|
||||
#include "nsExternalHelperAppService.h"
|
||||
#include "nsCExternalHandlerService.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIProcess.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SALT_SIZE 8
|
||||
#define TABLE_SIZE 36
|
||||
static const PRUnichar table[] =
|
||||
{ 'a','b','c','d','e','f','g','h','i','j',
|
||||
'k','l','m','n','o','p','q','r','s','t',
|
||||
'u','v','w','x','y','z','0','1','2','3',
|
||||
'4','5','6','7','8','9'};
|
||||
|
||||
|
||||
nsMIMEInfoOS2::nsMIMEInfoOS2() : nsMIMEInfoImpl()
|
||||
{
|
||||
}
|
||||
|
||||
nsMIMEInfoOS2::nsMIMEInfoOS2(const char* aType) : nsMIMEInfoImpl(aType)
|
||||
{
|
||||
}
|
||||
|
||||
nsMIMEInfoOS2::~nsMIMEInfoOS2()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoOS2::LaunchWithFile(nsIFile* aFile)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCAutoString path;
|
||||
aFile->GetNativePath(path);
|
||||
|
||||
nsIFile* application;
|
||||
if (mPreferredAction == useHelperApp) {
|
||||
application = mPreferredApplication;
|
||||
} else if (mPreferredAction == useSystemDefault) {
|
||||
application = mDefaultApplication;
|
||||
} else {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// The nsIMIMEInfo should have either the default or preferred
|
||||
// application handler attribute set to match the preferredAction!
|
||||
if (!application) {
|
||||
HOBJECT hobject = WinQueryObject(path.get());
|
||||
if (WinSetObjectData( hobject, "OPEN=DEFAULT" ))
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ULONG ulAppType;
|
||||
nsCAutoString apppath;
|
||||
application->GetNativePath(apppath);
|
||||
DosQueryAppType(apppath.get(), &ulAppType);
|
||||
if (ulAppType & (FAPPTYP_DOS |
|
||||
FAPPTYP_WINDOWSPROT31 |
|
||||
FAPPTYP_WINDOWSPROT |
|
||||
FAPPTYP_WINDOWSREAL)) {
|
||||
// if the helper application is a DOS app, create an 8.3 filename
|
||||
// we do this even if the filename is valid because it's 8.3, who cares
|
||||
nsCOMPtr<nsPIExternalAppLauncher> helperAppService (do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID));
|
||||
if (helperAppService)
|
||||
{
|
||||
nsCAutoString leafName;
|
||||
aFile->GetNativeLeafName(leafName);
|
||||
const char* lastDot = strrchr(leafName.get(), '.');
|
||||
char suffix[CCHMAXPATH + 1] = "";
|
||||
if (lastDot)
|
||||
{
|
||||
strcpy(suffix, lastDot);
|
||||
}
|
||||
suffix[4] = '\0';
|
||||
|
||||
nsAutoString saltedTempLeafName;
|
||||
do {
|
||||
saltedTempLeafName.Truncate();
|
||||
// this salting code was ripped directly from the profile manager.
|
||||
// turn PR_Now() into milliseconds since epoch 1058 // and salt rand with that.
|
||||
double fpTime;
|
||||
LL_L2D(fpTime, PR_Now());
|
||||
srand((uint)(fpTime * 1e-6 + 0.5));
|
||||
PRInt32 i;
|
||||
for (i=0;i<SALT_SIZE;i++) {
|
||||
saltedTempLeafName.Append(table[(rand()%TABLE_SIZE)]);
|
||||
}
|
||||
AppendASCIItoUTF16(suffix, saltedTempLeafName);
|
||||
nsresult rv = aFile->MoveTo(nsnull, saltedTempLeafName);
|
||||
} while (NS_FAILED(rv));
|
||||
helperAppService->DeleteTemporaryFileOnExit(aFile);
|
||||
aFile->GetNativePath(path);
|
||||
}
|
||||
} else {
|
||||
path.Insert('\"', 0);
|
||||
path.Append('\"');
|
||||
}
|
||||
|
||||
const char * strPath = path.get();
|
||||
// if we were given an application to use then use it....otherwise
|
||||
// make the registry call to launch the app
|
||||
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID);
|
||||
if (NS_FAILED(rv = process->Init(application)))
|
||||
return rv;
|
||||
PRUint32 pid;
|
||||
return process->Run(PR_FALSE, &strPath, 1, &pid);
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/* ***** 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 the OS/2 MIME Info Implementation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christian Biesinger <cbiesinger@web.de>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* 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 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 ***** */
|
||||
|
||||
#ifndef nsMIMEInfoOS2_h_
|
||||
#define nsMIMEInfoOS2_h_
|
||||
|
||||
#include "nsMIMEInfoImpl.h"
|
||||
|
||||
class nsMIMEInfoOS2 : public nsMIMEInfoImpl
|
||||
{
|
||||
public:
|
||||
nsMIMEInfoOS2();
|
||||
nsMIMEInfoOS2(const char* aType);
|
||||
virtual ~nsMIMEInfoOS2();
|
||||
|
||||
NS_IMETHOD LaunchWithFile(nsIFile* aFile);
|
||||
|
||||
#ifdef DEBUG
|
||||
protected:
|
||||
virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile) {
|
||||
NS_NOTREACHED("Do not call this, use LaunchWithFile");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
|
@ -41,14 +41,13 @@
|
|||
#include "nsHashtable.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prenv.h" // for PR_GetEnv()
|
||||
#include "nsMIMEInfoOS2.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include <stdlib.h> // for system()
|
||||
|
||||
#include "nsIPref.h" // XX Need to convert Handler code to new pref stuff
|
||||
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); // XXX need to convert to contract id
|
||||
|
||||
#define INCL_DOS
|
||||
#include <os2.h>
|
||||
|
||||
#define LOG(args) PR_LOG(mLog, PR_LOG_DEBUG, args)
|
||||
#define LOG_ENABLED() PR_LOG_TEST(mLog, PR_LOG_DEBUG)
|
||||
|
||||
|
@ -73,115 +72,6 @@ nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
|
|||
nsOSHelperAppService::~nsOSHelperAppService()
|
||||
{}
|
||||
|
||||
#define SALT_SIZE 8
|
||||
#define TABLE_SIZE 36
|
||||
const PRUnichar table[] =
|
||||
{ 'a','b','c','d','e','f','g','h','i','j',
|
||||
'k','l','m','n','o','p','q','r','s','t',
|
||||
'u','v','w','x','y','z','0','1','2','3',
|
||||
'4','5','6','7','8','9'};
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInfo, nsIFile * aTempFile)
|
||||
{
|
||||
LOG(("-- nsOSHelperAppService::LaunchAppWithTempFile"));
|
||||
nsresult rv = NS_OK;
|
||||
if (aMIMEInfo)
|
||||
{
|
||||
nsCOMPtr<nsIFile> application;
|
||||
|
||||
nsCAutoString path;
|
||||
aTempFile->GetNativePath(path);
|
||||
LOG(("Launching helper on '%s'\n", path.get()));
|
||||
|
||||
nsMIMEInfoHandleAction action = nsIMIMEInfo::useSystemDefault;
|
||||
aMIMEInfo->GetPreferredAction(&action);
|
||||
|
||||
if (action == nsIMIMEInfo::useHelperApp)
|
||||
{
|
||||
aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application));
|
||||
}
|
||||
else
|
||||
{
|
||||
aMIMEInfo->GetDefaultApplicationHandler(getter_AddRefs(application));
|
||||
}
|
||||
|
||||
// The nsIMIMEInfo should have either the default or preferred
|
||||
// application handler attribute set to match the preferredAction!
|
||||
if (!application) {
|
||||
HOBJECT hobject = WinQueryObject(path.get());
|
||||
if (WinSetObjectData( hobject, "OPEN=DEFAULT" ))
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (LOG_ENABLED()) {
|
||||
nsCAutoString appPath;
|
||||
application->GetNativePath(appPath);
|
||||
LOG(("The helper is '%s'\n", appPath.get()));
|
||||
}
|
||||
|
||||
ULONG ulAppType;
|
||||
nsCAutoString apppath;
|
||||
application->GetNativePath(apppath);
|
||||
DosQueryAppType(apppath.get(), &ulAppType);
|
||||
if (ulAppType & (FAPPTYP_DOS |
|
||||
FAPPTYP_WINDOWSPROT31 |
|
||||
FAPPTYP_WINDOWSPROT |
|
||||
FAPPTYP_WINDOWSREAL)) {
|
||||
// if the helper application is a DOS app, create an 8.3 filename
|
||||
// we do this even if the filename is valid because it's 8.3, who cares
|
||||
nsCOMPtr<nsPIExternalAppLauncher> helperAppService (do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID));
|
||||
if (helperAppService)
|
||||
{
|
||||
nsCAutoString leafName;
|
||||
aTempFile->GetNativeLeafName(leafName);
|
||||
const char* lastDot = strrchr(leafName.get(), '.');
|
||||
char suffix[CCHMAXPATH + 1] = "";
|
||||
if (lastDot)
|
||||
{
|
||||
strcpy(suffix, lastDot);
|
||||
}
|
||||
suffix[4] = '\0';
|
||||
|
||||
nsAutoString saltedTempLeafName;
|
||||
do {
|
||||
saltedTempLeafName.Truncate();
|
||||
// this salting code was ripped directly from the profile manager.
|
||||
// turn PR_Now() into milliseconds since epoch 1058 // and salt rand with that.
|
||||
double fpTime;
|
||||
LL_L2D(fpTime, PR_Now());
|
||||
srand((uint)(fpTime * 1e-6 + 0.5));
|
||||
PRInt32 i;
|
||||
for (i=0;i<SALT_SIZE;i++)
|
||||
{
|
||||
saltedTempLeafName.Append(table[(rand()%TABLE_SIZE)]);
|
||||
}
|
||||
AppendASCIItoUTF16(suffix, saltedTempLeafName);
|
||||
nsresult rv = aTempFile->MoveTo(nsnull, saltedTempLeafName);
|
||||
} while (NS_FAILED(rv));
|
||||
helperAppService->DeleteTemporaryFileOnExit(aTempFile);
|
||||
aTempFile->GetNativePath(path);
|
||||
}
|
||||
} else {
|
||||
path.Insert('\"', 0);
|
||||
path.Append('\"');
|
||||
}
|
||||
|
||||
const char * strPath = path.get();
|
||||
// if we were given an application to use then use it....otherwise
|
||||
// make the registry call to launch the app
|
||||
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID);
|
||||
if (NS_FAILED(rv = process->Init(application)))
|
||||
return rv;
|
||||
PRUint32 pid;
|
||||
if (NS_FAILED(rv = process->Run(PR_FALSE, &strPath, 1, &pid)))
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Take a command with all the mailcap escapes in it and unescape it
|
||||
* Ideally this needs the mime type, mime type options, and location of the
|
||||
|
@ -360,9 +250,9 @@ nsOSHelperAppService::GetFileLocation(const char* aPrefName,
|
|||
// static
|
||||
nsresult
|
||||
nsOSHelperAppService::LookUpTypeAndDescription(const nsAString& aFileExtension,
|
||||
nsAString& aMajorType,
|
||||
nsAString& aMinorType,
|
||||
nsAString& aDescription) {
|
||||
nsAString& aMajorType,
|
||||
nsAString& aMinorType,
|
||||
nsAString& aDescription) {
|
||||
LOG(("-- LookUpTypeAndDescription for extension '%s'\n",
|
||||
NS_LossyConvertUCS2toASCII(aFileExtension).get()));
|
||||
nsresult rv = NS_OK;
|
||||
|
@ -1458,9 +1348,7 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp
|
|||
while (colon_iter != end_iter && *colon_iter != ':') {
|
||||
++colon_iter;
|
||||
}
|
||||
// XXX provided the string code has all it's bugs fixed, we should be able to
|
||||
// remove this PromiseFlatCString call.
|
||||
localFile->InitWithNativePath(PromiseFlatCString(Substring(start_iter, colon_iter)));
|
||||
localFile->InitWithNativePath(Substring(start_iter, colon_iter));
|
||||
rv = localFile->AppendRelativePath(nsDependentString(platformAppPath));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
localFile->Exists(&exists);
|
||||
|
@ -1488,7 +1376,7 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp
|
|||
#endif
|
||||
}
|
||||
|
||||
already_AddRefed<nsIMIMEInfo>
|
||||
already_AddRefed<nsMIMEInfoOS2>
|
||||
nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
||||
// if the extension is null, return immediately
|
||||
if (!aFileExt || !*aFileExt)
|
||||
|
@ -1498,7 +1386,7 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
|
||||
nsresult rv;
|
||||
|
||||
nsAutoString mimeType, majorType, minorType,
|
||||
nsAutoString majorType, minorType,
|
||||
mime_types_description, mailcap_description,
|
||||
handler, mozillaFlags;
|
||||
|
||||
|
@ -1509,9 +1397,12 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
|
||||
NS_LossyConvertUTF16toASCII asciiMajorType(majorType);
|
||||
NS_LossyConvertUTF16toASCII asciiMinorType(minorType);
|
||||
|
||||
LOG(("Type/Description results: majorType='%s', minorType='%s', description='%s'\n",
|
||||
NS_LossyConvertUCS2toASCII(majorType).get(),
|
||||
NS_LossyConvertUCS2toASCII(minorType).get(),
|
||||
asciiMajorType.get(),
|
||||
asciiMinorType.get(),
|
||||
NS_LossyConvertUCS2toASCII(mime_types_description).get()));
|
||||
|
||||
if (majorType.IsEmpty() && minorType.IsEmpty()) {
|
||||
|
@ -1519,13 +1410,12 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
nsIMIMEInfo* mimeInfo = new nsMIMEInfoImpl();
|
||||
nsCAutoString mimeType(asciiMajorType + NS_LITERAL_CSTRING("/") + asciiMinorType);
|
||||
nsMIMEInfoOS2* mimeInfo = new nsMIMEInfoOS2(mimeType.get());
|
||||
if (!mimeInfo)
|
||||
return nsnull;
|
||||
NS_ADDREF(mimeInfo);
|
||||
|
||||
mimeType = majorType + NS_LITERAL_STRING("/") + minorType;
|
||||
mimeInfo->SetMIMEType(NS_ConvertUCS2toUTF8(mimeType).get());
|
||||
mimeInfo->AppendExtension(aFileExt);
|
||||
nsHashtable typeOptions; // empty hash table
|
||||
// The mailcap lookup is two-pass to handle the case of mailcap files
|
||||
|
@ -1560,7 +1450,7 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
rv = GetFileTokenForPath(handler.get(), getter_AddRefs(handlerFile));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mimeInfo->SetDefaultApplicationHandler(handlerFile);
|
||||
mimeInfo->SetDefaultApplication(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
mimeInfo->SetDefaultDescription(handler.get());
|
||||
}
|
||||
|
@ -1569,16 +1459,12 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
}
|
||||
|
||||
return mimeInfo;
|
||||
|
||||
// XXX Once cache can be invalidated, add the mime info to it. See bug 121644
|
||||
// AddMimeInfoToCache(*_retval);
|
||||
|
||||
}
|
||||
|
||||
already_AddRefed<nsIMIMEInfo>
|
||||
already_AddRefed<nsMIMEInfoOS2>
|
||||
nsOSHelperAppService::GetFromType(const char *aMIMEType) {
|
||||
// if the extension is null, return immediately
|
||||
if (!aMIMEType)
|
||||
if (!aMIMEType || !*aMIMEType)
|
||||
return nsnull;
|
||||
|
||||
LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType));
|
||||
|
@ -1648,25 +1534,23 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
|
|||
extensions,
|
||||
mime_types_description);
|
||||
|
||||
nsIMIMEInfo* mimeInfo = new nsMIMEInfoImpl();
|
||||
nsMIMEInfoOS2* mimeInfo = new nsMIMEInfoOS2(aMIMEType);
|
||||
if (!mimeInfo)
|
||||
return nsnull;
|
||||
NS_ADDREF(mimeInfo);
|
||||
|
||||
mimeInfo->SetFileExtensions(PromiseFlatCString(NS_ConvertUCS2toUTF8(extensions)).get());
|
||||
mimeInfo->SetMIMEType(aMIMEType);
|
||||
mimeInfo->SetFileExtensions(NS_ConvertUCS2toUTF8(extensions).get());
|
||||
if (! mime_types_description.IsEmpty()) {
|
||||
mimeInfo->SetDescription(mime_types_description.get());
|
||||
} else {
|
||||
mimeInfo->SetDescription(mailcap_description.get());
|
||||
}
|
||||
|
||||
rv = NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIFile> handlerFile;
|
||||
rv = GetFileTokenForPath(handler.get(), getter_AddRefs(handlerFile));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mimeInfo->SetDefaultApplicationHandler(handlerFile);
|
||||
mimeInfo->SetDefaultApplication(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
mimeInfo->SetDefaultDescription(handler.get());
|
||||
} else {
|
||||
|
@ -1682,12 +1566,12 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
|
|||
const char *aFileExt,
|
||||
PRBool *aFound) {
|
||||
*aFound = PR_TRUE;
|
||||
nsIMIMEInfo* retval = GetFromType(aType).get();
|
||||
nsMIMEInfoOS2* retval = GetFromType(aType).get();
|
||||
PRBool hasDefault = PR_FALSE;
|
||||
if (retval)
|
||||
retval->GetHasDefaultHandler(&hasDefault);
|
||||
if (!retval || !hasDefault) {
|
||||
nsCOMPtr<nsIMIMEInfo> miByExt = GetFromExtension(aFileExt);
|
||||
nsRefPtr<nsMIMEInfoOS2> miByExt = GetFromExtension(aFileExt);
|
||||
// If we had no extension match, but a type match, use that
|
||||
if (!miByExt && retval)
|
||||
return retval;
|
||||
|
@ -1703,7 +1587,7 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
|
|||
// If we got nothing, make a new mimeinfo
|
||||
if (!retval) {
|
||||
*aFound = PR_FALSE;
|
||||
retval = new nsMIMEInfoImpl();
|
||||
retval = new nsMIMEInfoOS2();
|
||||
if (retval) {
|
||||
NS_ADDREF(retval);
|
||||
if (aType && *aType)
|
||||
|
@ -1715,14 +1599,10 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
|
|||
return retval;
|
||||
}
|
||||
|
||||
// Copy default handler
|
||||
nsCOMPtr<nsIFile> defaultHandler;
|
||||
nsXPIDLString desc;
|
||||
miByExt->GetDefaultApplicationHandler(getter_AddRefs(defaultHandler));
|
||||
miByExt->GetDefaultDescription(getter_Copies(desc));
|
||||
// Copy the attributes of retval onto miByExt, to return it
|
||||
retval->CopyBasicDataTo(miByExt);
|
||||
|
||||
retval->SetDefaultApplicationHandler(defaultHandler);
|
||||
retval->SetDefaultDescription(desc.get());
|
||||
miByExt.swap(retval);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
class nsHashtable;
|
||||
class nsILineInputStream;
|
||||
class nsMIMEInfoOS2;
|
||||
|
||||
class nsOSHelperAppService : public nsExternalHelperAppService
|
||||
{
|
||||
|
@ -40,9 +41,6 @@ public:
|
|||
nsOSHelperAppService();
|
||||
virtual ~nsOSHelperAppService();
|
||||
|
||||
// override nsIExternalHelperAppService methods....
|
||||
NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile);
|
||||
|
||||
// method overrides for mime.types and mime.info look up steps
|
||||
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const char *aMimeType,
|
||||
const char *aFileExt,
|
||||
|
@ -59,8 +57,8 @@ public:
|
|||
virtual nsresult GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile);
|
||||
|
||||
protected:
|
||||
already_AddRefed<nsIMIMEInfo> GetFromType(const char *aMimeType);
|
||||
already_AddRefed<nsIMIMEInfo> GetFromExtension(const char *aFileExt);
|
||||
already_AddRefed<nsMIMEInfoOS2> GetFromType(const char *aMimeType);
|
||||
already_AddRefed<nsMIMEInfoOS2> GetFromExtension(const char *aFileExt);
|
||||
|
||||
private:
|
||||
// Helper methods which have to access static members
|
||||
|
@ -73,9 +71,9 @@ private:
|
|||
const char* aEnvVarName,
|
||||
PRUnichar** aFileLocation);
|
||||
static nsresult LookUpTypeAndDescription(const nsAString& aFileExtension,
|
||||
nsAString& aMajorType,
|
||||
nsAString& aMinorType,
|
||||
nsAString& aDescription);
|
||||
nsAString& aMajorType,
|
||||
nsAString& aMinorType,
|
||||
nsAString& aDescription);
|
||||
static nsresult CreateInputStream(const nsAString& aFilename,
|
||||
nsIFileInputStream ** aFileInputStream,
|
||||
nsILineInputStream ** aLineInputStream,
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsMIMEInfoImpl.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
@ -230,7 +231,7 @@ nsGNOMERegistry::LoadURL(nsIURI *aURL)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsIMIMEInfo>
|
||||
/* static */ already_AddRefed<nsMIMEInfoBase>
|
||||
nsGNOMERegistry::GetFromExtension(const char *aFileExt)
|
||||
{
|
||||
if (!gconfLib)
|
||||
|
@ -252,19 +253,17 @@ nsGNOMERegistry::GetFromExtension(const char *aFileExt)
|
|||
return GetFromType(mimeType);
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsIMIMEInfo>
|
||||
/* static */ already_AddRefed<nsMIMEInfoBase>
|
||||
nsGNOMERegistry::GetFromType(const char *aMIMEType)
|
||||
{
|
||||
if (!gconfLib)
|
||||
return nsnull;
|
||||
|
||||
nsCOMPtr<nsIMIMEInfo> mimeInfo;
|
||||
|
||||
GnomeVFSMimeApplication *handlerApp = _gnome_vfs_mime_get_default_application(aMIMEType);
|
||||
if (!handlerApp)
|
||||
return nsnull;
|
||||
|
||||
mimeInfo = new nsMIMEInfoImpl();
|
||||
nsRefPtr<nsMIMEInfoImpl> mimeInfo = new nsMIMEInfoImpl();
|
||||
NS_ENSURE_TRUE(mimeInfo, nsnull);
|
||||
|
||||
mimeInfo->SetMIMEType(aMIMEType);
|
||||
|
@ -297,7 +296,7 @@ nsGNOMERegistry::GetFromType(const char *aMIMEType)
|
|||
NS_NewNativeLocalFile(nsDependentCString(commandPath), PR_TRUE,
|
||||
getter_AddRefs(appFile));
|
||||
if (appFile) {
|
||||
mimeInfo->SetDefaultApplicationHandler(appFile);
|
||||
mimeInfo->SetDefaultApplication(appFile);
|
||||
mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUCS2(handlerApp->name).get());
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
}
|
||||
|
@ -306,7 +305,7 @@ nsGNOMERegistry::GetFromType(const char *aMIMEType)
|
|||
|
||||
_gnome_vfs_mime_application_free(handlerApp);
|
||||
|
||||
nsIMIMEInfo* retval;
|
||||
nsMIMEInfoBase* retval;
|
||||
NS_ADDREF((retval = mimeInfo));
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -36,9 +36,10 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIURI.h"
|
||||
#include "nsIMIMEInfo.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsMIMEInfoBase;
|
||||
|
||||
class nsGNOMERegistry
|
||||
{
|
||||
public:
|
||||
|
@ -48,7 +49,7 @@ class nsGNOMERegistry
|
|||
|
||||
static nsresult LoadURL(nsIURI *aURL);
|
||||
|
||||
static already_AddRefed<nsIMIMEInfo> GetFromExtension(const char *aFileExt);
|
||||
static already_AddRefed<nsMIMEInfoBase> GetFromExtension(const char *aFileExt);
|
||||
|
||||
static already_AddRefed<nsIMIMEInfo> GetFromType(const char *aMIMEType);
|
||||
static already_AddRefed<nsMIMEInfoBase> GetFromType(const char *aMIMEType);
|
||||
};
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "prenv.h" // for PR_GetEnv()
|
||||
#include "nsAutoPtr.h"
|
||||
#include <stdlib.h> // for system()
|
||||
|
||||
#define LOG(args) PR_LOG(mLog, PR_LOG_DEBUG, args)
|
||||
|
@ -74,55 +75,6 @@ nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
|
|||
nsOSHelperAppService::~nsOSHelperAppService()
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInfo, nsIFile * aTempFile)
|
||||
{
|
||||
LOG(("-- nsOSHelperAppService::LaunchAppWithTempFile"));
|
||||
nsresult rv = NS_OK;
|
||||
if (aMIMEInfo)
|
||||
{
|
||||
nsCOMPtr<nsIFile> application;
|
||||
|
||||
nsCAutoString path;
|
||||
aTempFile->GetNativePath(path);
|
||||
LOG(("Launching helper on '%s'\n", path.get()));
|
||||
|
||||
nsMIMEInfoHandleAction action = nsIMIMEInfo::useSystemDefault;
|
||||
aMIMEInfo->GetPreferredAction(&action);
|
||||
|
||||
if (action == nsIMIMEInfo::useHelperApp)
|
||||
{
|
||||
aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application));
|
||||
}
|
||||
else
|
||||
{
|
||||
aMIMEInfo->GetDefaultApplicationHandler(getter_AddRefs(application));
|
||||
}
|
||||
|
||||
// The nsIMIMEInfo should have either the default or preferred
|
||||
// application handler attribute set to match the preferredAction!
|
||||
if (!application)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
|
||||
if (LOG_ENABLED()) {
|
||||
nsCAutoString appPath;
|
||||
application->GetNativePath(appPath);
|
||||
LOG(("The helper is '%s'\n", appPath.get()));
|
||||
}
|
||||
|
||||
// if we were given an application to use then use it....otherwise
|
||||
// make the registry call to launch the app
|
||||
const char * strPath = path.get();
|
||||
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID);
|
||||
if (NS_FAILED(rv = process->Init(application)))
|
||||
return rv;
|
||||
PRUint32 pid;
|
||||
if (NS_FAILED(rv = process->Run(PR_FALSE, &strPath, 1, &pid)))
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Take a command with all the mailcap escapes in it and unescape it
|
||||
* Ideally this needs the mime type, mime type options, and location of the
|
||||
|
@ -336,7 +288,7 @@ IsNetscapeFormat(const nsAString& aBuffer) {
|
|||
NS_NAMED_LITERAL_STRING(MCOMHeader, "#--MCOM MIME Information");
|
||||
|
||||
return StringBeginsWith(aBuffer, netscapeHeader) ||
|
||||
StringBeginsWith(aBuffer, MCOMHeader);
|
||||
StringBeginsWith(aBuffer, MCOMHeader);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1353,9 +1305,7 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp
|
|||
while (colon_iter != end_iter && *colon_iter != ':') {
|
||||
++colon_iter;
|
||||
}
|
||||
// XXX provided the string code has all it's bugs fixed, we should be able to
|
||||
// remove this PromiseFlatCString call.
|
||||
localFile->InitWithNativePath(PromiseFlatCString(Substring(start_iter, colon_iter)));
|
||||
localFile->InitWithNativePath(Substring(start_iter, colon_iter));
|
||||
rv = localFile->AppendRelativePath(nsDependentString(platformAppPath));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
localFile->Exists(&exists);
|
||||
|
@ -1382,7 +1332,7 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp
|
|||
return rv;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIMIMEInfo>
|
||||
already_AddRefed<nsMIMEInfoBase>
|
||||
nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
||||
// if the extension is null, return immediately
|
||||
if (!aFileExt || !*aFileExt)
|
||||
|
@ -1390,7 +1340,7 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
|
||||
LOG(("Here we do an extension lookup for '%s'\n", aFileExt));
|
||||
|
||||
nsAutoString mimeType, majorType, minorType,
|
||||
nsAutoString majorType, minorType,
|
||||
mime_types_description, mailcap_description,
|
||||
handler, mozillaFlags;
|
||||
|
||||
|
@ -1404,7 +1354,7 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
LOG(("Looking in GNOME registry\n"));
|
||||
nsIMIMEInfo *gnomeInfo = nsGNOMERegistry::GetFromExtension(aFileExt).get();
|
||||
nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromExtension(aFileExt).get();
|
||||
if (gnomeInfo) {
|
||||
LOG(("Got MIMEInfo from GNOME registry\n"));
|
||||
return gnomeInfo;
|
||||
|
@ -1421,9 +1371,12 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
|
||||
NS_LossyConvertUTF16toASCII asciiMajorType(majorType);
|
||||
NS_LossyConvertUTF16toASCII asciiMinorType(minorType);
|
||||
|
||||
LOG(("Type/Description results: majorType='%s', minorType='%s', description='%s'\n",
|
||||
NS_LossyConvertUCS2toASCII(majorType).get(),
|
||||
NS_LossyConvertUCS2toASCII(minorType).get(),
|
||||
asciiMajorType.get(),
|
||||
asciiMinorType.get(),
|
||||
NS_LossyConvertUCS2toASCII(mime_types_description).get()));
|
||||
|
||||
if (majorType.IsEmpty() && minorType.IsEmpty()) {
|
||||
|
@ -1431,13 +1384,12 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
nsIMIMEInfo* mimeInfo = new nsMIMEInfoImpl();
|
||||
nsCAutoString mimeType(asciiMajorType + NS_LITERAL_CSTRING("/") + asciiMinorType);
|
||||
nsMIMEInfoImpl* mimeInfo = new nsMIMEInfoImpl(mimeType.get());
|
||||
if (!mimeInfo)
|
||||
return nsnull;
|
||||
NS_ADDREF(mimeInfo);
|
||||
|
||||
mimeType = majorType + NS_LITERAL_STRING("/") + minorType;
|
||||
mimeInfo->SetMIMEType(NS_ConvertUCS2toUTF8(mimeType).get());
|
||||
mimeInfo->AppendExtension(aFileExt);
|
||||
nsHashtable typeOptions; // empty hash table
|
||||
rv = LookUpHandlerAndDescription(majorType, minorType, typeOptions,
|
||||
|
@ -1464,7 +1416,7 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
rv = GetFileTokenForPath(handler.get(), getter_AddRefs(handlerFile));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mimeInfo->SetDefaultApplicationHandler(handlerFile);
|
||||
mimeInfo->SetDefaultApplication(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
mimeInfo->SetDefaultDescription(handler.get());
|
||||
}
|
||||
|
@ -1477,7 +1429,7 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
|||
return mimeInfo;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIMIMEInfo>
|
||||
already_AddRefed<nsMIMEInfoBase>
|
||||
nsOSHelperAppService::GetFromType(const char *aMIMEType) {
|
||||
// if the type is null, return immediately
|
||||
if (!aMIMEType || !*aMIMEType)
|
||||
|
@ -1528,7 +1480,7 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
|
|||
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
LOG(("Looking in GNOME registry\n"));
|
||||
nsIMIMEInfo *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType).get();
|
||||
nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType).get();
|
||||
if (gnomeInfo) {
|
||||
LOG(("Got MIMEInfo from GNOME registry\n"));
|
||||
return gnomeInfo;
|
||||
|
@ -1580,13 +1532,12 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
nsIMIMEInfo* mimeInfo = new nsMIMEInfoImpl();
|
||||
nsMIMEInfoImpl* mimeInfo = new nsMIMEInfoImpl(aMIMEType);
|
||||
if (!mimeInfo)
|
||||
return nsnull;
|
||||
NS_ADDREF(mimeInfo);
|
||||
|
||||
mimeInfo->SetFileExtensions(NS_ConvertUCS2toUTF8(extensions).get());
|
||||
mimeInfo->SetMIMEType(aMIMEType);
|
||||
if (! mime_types_description.IsEmpty()) {
|
||||
mimeInfo->SetDescription(mime_types_description.get());
|
||||
} else {
|
||||
|
@ -1600,7 +1551,7 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
|
|||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mimeInfo->SetDefaultApplicationHandler(handlerFile);
|
||||
mimeInfo->SetDefaultApplication(handlerFile);
|
||||
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
|
||||
mimeInfo->SetDefaultDescription(handler.get());
|
||||
} else {
|
||||
|
@ -1616,12 +1567,12 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
|
|||
const char *aFileExt,
|
||||
PRBool *aFound) {
|
||||
*aFound = PR_TRUE;
|
||||
nsIMIMEInfo* retval = GetFromType(aType).get();
|
||||
nsMIMEInfoBase* retval = GetFromType(aType).get();
|
||||
PRBool hasDefault = PR_FALSE;
|
||||
if (retval)
|
||||
retval->GetHasDefaultHandler(&hasDefault);
|
||||
if (!retval || !hasDefault) {
|
||||
nsCOMPtr<nsIMIMEInfo> miByExt = GetFromExtension(aFileExt);
|
||||
nsRefPtr<nsMIMEInfoBase> miByExt = GetFromExtension(aFileExt);
|
||||
// If we had no extension match, but a type match, use that
|
||||
if (!miByExt && retval)
|
||||
return retval;
|
||||
|
@ -1649,14 +1600,9 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
|
|||
return retval;
|
||||
}
|
||||
|
||||
// Copy default handler
|
||||
nsCOMPtr<nsIFile> defaultHandler;
|
||||
nsXPIDLString desc;
|
||||
miByExt->GetDefaultApplicationHandler(getter_AddRefs(defaultHandler));
|
||||
miByExt->GetDefaultDescription(getter_Copies(desc));
|
||||
|
||||
retval->SetDefaultApplicationHandler(defaultHandler);
|
||||
retval->SetDefaultDescription(desc.get());
|
||||
// Copy the attributes of retval onto miByExt, to return it
|
||||
retval->CopyBasicDataTo(miByExt);
|
||||
miByExt.swap(retval);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -40,9 +40,6 @@ public:
|
|||
nsOSHelperAppService();
|
||||
virtual ~nsOSHelperAppService();
|
||||
|
||||
// override nsIExternalHelperAppService methods....
|
||||
NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile);
|
||||
|
||||
// method overrides for mime.types and mime.info look up steps
|
||||
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const char *aMimeType,
|
||||
const char *aFileExt,
|
||||
|
@ -59,8 +56,8 @@ public:
|
|||
virtual nsresult GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile);
|
||||
|
||||
protected:
|
||||
already_AddRefed<nsIMIMEInfo> GetFromType(const char *aMimeType);
|
||||
already_AddRefed<nsIMIMEInfo> GetFromExtension(const char *aFileExt);
|
||||
already_AddRefed<nsMIMEInfoBase> GetFromType(const char *aMimeType);
|
||||
already_AddRefed<nsMIMEInfoBase> GetFromExtension(const char *aFileExt);
|
||||
|
||||
private:
|
||||
// Helper methods which have to access static members
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Scott MacGregor <mscott@netscape.com>
|
||||
* Christian Biesinger <cbiesinger@web.de>
|
||||
*/
|
||||
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsMIMEInfoWin.h"
|
||||
|
||||
nsMIMEInfoWin::nsMIMEInfoWin() : nsMIMEInfoBase()
|
||||
{
|
||||
}
|
||||
|
||||
nsMIMEInfoWin::nsMIMEInfoWin(const char* aType) : nsMIMEInfoBase(aType)
|
||||
{
|
||||
}
|
||||
|
||||
nsMIMEInfoWin::~nsMIMEInfoWin()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMIMEInfoWin::LaunchDefaultWithFile(nsIFile* aFile)
|
||||
{
|
||||
// Launch the file, unless it is an executable.
|
||||
nsCOMPtr<nsILocalFile> local(do_QueryInterface(aFile));
|
||||
if (!local)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRBool executable = PR_TRUE;
|
||||
local->IsExecutable(&executable);
|
||||
if (executable)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return local->Launch();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoWin::GetHasDefaultHandler(PRBool * _retval)
|
||||
{
|
||||
// We have a default application if we have a description
|
||||
// We can ShellExecute anything; however, callers are probably interested if
|
||||
// there is really an application associated with this type of file
|
||||
*_retval = !mDefaultAppDescription.IsEmpty();
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/* ***** 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 the Windows MIME Info Implementation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christian Biesinger <cbiesinger@web.de>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* 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 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 ***** */
|
||||
|
||||
#ifndef nsMIMEInfoWin_h_
|
||||
#define nsMIMEInfoWin_h_
|
||||
|
||||
#include "nsMIMEInfoImpl.h"
|
||||
|
||||
class nsMIMEInfoWin : public nsMIMEInfoBase {
|
||||
public:
|
||||
nsMIMEInfoWin();
|
||||
nsMIMEInfoWin(const char* aType);
|
||||
virtual ~nsMIMEInfoWin();
|
||||
|
||||
NS_IMETHOD GetHasDefaultHandler(PRBool * _retval);
|
||||
protected:
|
||||
virtual nsresult LaunchDefaultWithFile(nsIFile* aFile);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -26,6 +26,7 @@
|
|||
#include "nsXPIDLString.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIMIMEInfo.h"
|
||||
#include "nsMIMEInfoWin.h"
|
||||
#include "nsMimeTypes.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIProcess.h"
|
||||
|
@ -67,52 +68,6 @@ nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
|
|||
nsOSHelperAppService::~nsOSHelperAppService()
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInfo, nsIFile * aTempFile)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (aMIMEInfo)
|
||||
{
|
||||
nsCOMPtr<nsIFile> application;
|
||||
nsCAutoString path;
|
||||
aTempFile->GetNativePath(path);
|
||||
|
||||
nsMIMEInfoHandleAction action = nsIMIMEInfo::useSystemDefault;
|
||||
aMIMEInfo->GetPreferredAction(&action);
|
||||
|
||||
aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application));
|
||||
if (application && action == nsIMIMEInfo::useHelperApp)
|
||||
{
|
||||
// if we were given an application to use then use it....otherwise
|
||||
// make the registry call to launch the app
|
||||
const char * strPath = path.get();
|
||||
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID);
|
||||
nsresult rv;
|
||||
if (NS_FAILED(rv = process->Init(application)))
|
||||
return rv;
|
||||
PRUint32 pid;
|
||||
if (NS_FAILED(rv = process->Run(PR_FALSE, &strPath, 1, &pid)))
|
||||
return rv;
|
||||
}
|
||||
else // use the system default
|
||||
{
|
||||
// Launch the temp file, unless it is an executable.
|
||||
nsCOMPtr<nsILocalFile> local(do_QueryInterface(aTempFile));
|
||||
if (!local)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRBool executable = PR_TRUE;
|
||||
local->IsExecutable(&executable);
|
||||
if (executable)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
rv = local->Launch();
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// The windows registry provides a mime database key which lists a set of mime types and corresponding "Extension" values.
|
||||
// we can use this to look up our mime type to see if there is a preferred extension for the mime type.
|
||||
static nsresult GetExtensionFromWindowsMimeDatabase(const char * aMimeType, nsCString& aFileExtension)
|
||||
|
@ -377,7 +332,7 @@ static PRBool typeFromExtEquals(const char *aExt, const char *aType)
|
|||
return eq;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetByExtension(const char *aFileExt, const char *aTypeHint)
|
||||
already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const char *aFileExt, const char *aTypeHint)
|
||||
{
|
||||
if (!aFileExt || !*aFileExt)
|
||||
return nsnull;
|
||||
|
@ -408,7 +363,7 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetByExtension(const char *a
|
|||
nsAutoString description;
|
||||
PRBool found = GetValueString(hKey, NULL, description);
|
||||
|
||||
nsIMIMEInfo* mimeInfo = new nsMIMEInfoImpl();
|
||||
nsMIMEInfoWin* mimeInfo = new nsMIMEInfoWin();
|
||||
if (mimeInfo)
|
||||
{
|
||||
NS_ADDREF(mimeInfo);
|
||||
|
@ -471,7 +426,7 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const char
|
|||
}
|
||||
}
|
||||
// If we found an extension for the type, do the lookup
|
||||
nsIMIMEInfo* mi = nsnull;
|
||||
nsMIMEInfoWin* mi = nsnull;
|
||||
if (!fileExtension.IsEmpty())
|
||||
mi = GetByExtension(fileExtension.get(), aMIMEType).get();
|
||||
LOG(("Extension lookup on '%s' found: 0x%p\n", fileExtension.get(), mi));
|
||||
|
@ -494,7 +449,7 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const char
|
|||
}
|
||||
}
|
||||
if (!mi || !hasDefault) {
|
||||
nsCOMPtr<nsIMIMEInfo> miByExt = GetByExtension(aFileExt, aMIMEType);
|
||||
nsRefPtr<nsMIMEInfoWin> miByExt = GetByExtension(aFileExt, aMIMEType);
|
||||
LOG(("Ext. lookup for '%s' found 0x%p\n", aFileExt, miByExt.get()));
|
||||
if (!miByExt && mi)
|
||||
return mi;
|
||||
|
@ -504,7 +459,7 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const char
|
|||
}
|
||||
if (!miByExt && !mi) {
|
||||
*aFound = PR_FALSE;
|
||||
mi = new nsMIMEInfoImpl();
|
||||
mi = new nsMIMEInfoWin();
|
||||
if (mi) {
|
||||
NS_ADDREF(mi);
|
||||
if (aMIMEType && *aMIMEType)
|
||||
|
@ -519,10 +474,8 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const char
|
|||
// if we get here, mi has no default app. copy from extension lookup.
|
||||
nsCOMPtr<nsIFile> defaultApp;
|
||||
nsXPIDLString desc;
|
||||
miByExt->GetDefaultApplicationHandler(getter_AddRefs(defaultApp));
|
||||
miByExt->GetDefaultDescription(getter_Copies(desc));
|
||||
|
||||
mi->SetDefaultApplicationHandler(defaultApp);
|
||||
mi->SetDefaultDescription(desc.get());
|
||||
}
|
||||
return mi;
|
||||
|
|
|
@ -32,15 +32,14 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include <windows.h>
|
||||
|
||||
class nsMIMEInfoWin;
|
||||
|
||||
class nsOSHelperAppService : public nsExternalHelperAppService
|
||||
{
|
||||
public:
|
||||
nsOSHelperAppService();
|
||||
virtual ~nsOSHelperAppService();
|
||||
|
||||
// override nsIExternalHelperAppService methods....
|
||||
NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile);
|
||||
|
||||
// override nsIExternalProtocolService methods
|
||||
NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
|
||||
NS_IMETHOD LoadUrl(nsIURI * aURL);
|
||||
|
@ -56,7 +55,7 @@ public:
|
|||
|
||||
protected:
|
||||
// Lookup a mime info by extension, using an optional type hint
|
||||
already_AddRefed<nsIMIMEInfo> GetByExtension(const char *aFileExt, const char *aTypeHint = nsnull);
|
||||
already_AddRefed<nsMIMEInfoWin> GetByExtension(const char *aFileExt, const char *aTypeHint = nsnull);
|
||||
nsresult FindOSMimeInfoForType(const char * aMimeContentType, nsIURI * aURI, char ** aFileExtension, nsIMIMEInfo ** aMIMEInfo);
|
||||
|
||||
/** Whether we're running on an OS that supports the *W registry functions */
|
||||
|
|
Загрузка…
Ссылка в новой задаче