Back to index

lightning-sunbird  0.9+nobinonly
nsOSHelperAppService.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the Mozilla browser.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications, Inc.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Scott MacGregor <mscott@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef nsOSHelperAppService_h__
00041 #define nsOSHelperAppService_h__
00042 
00043 // The OS helper app service is a subclass of nsExternalHelperAppService and is implemented on each
00044 // platform. It contains platform specific code for finding helper applications for a given mime type
00045 // in addition to launching those applications.
00046 
00047 #include "nsExternalHelperAppService.h"
00048 #include "nsCExternalHandlerService.h"
00049 #include "nsCOMPtr.h"
00050 
00051 class nsHashtable;
00052 class nsILineInputStream;
00053 
00054 class nsOSHelperAppService : public nsExternalHelperAppService
00055 {
00056 public:
00057   nsOSHelperAppService();
00058   virtual ~nsOSHelperAppService();
00059 
00060   // method overrides for mime.types and mime.info look up steps
00061   already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMimeType,
00062                                                   const nsACString& aFileExt,
00063                                                   PRBool     *aFound);
00064 
00065   // override nsIExternalProtocolService methods
00066   NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
00067   nsresult LoadUriInternal(nsIURI * aURL);
00068   NS_IMETHOD GetApplicationDescription(const nsACString& aScheme, nsAString& _retval);
00069 
00070   // GetFileTokenForPath must be implemented by each platform. 
00071   // platformAppPath --> a platform specific path to an application that we got out of the 
00072   //                     rdf data source. This can be a mac file spec, a unix path or a windows path depending on the platform
00073   // aFile --> an nsIFile representation of that platform application path.
00074   virtual nsresult GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile);
00075   
00076 protected:
00077   already_AddRefed<nsMIMEInfoBase> GetFromType(const nsCString& aMimeType);
00078   already_AddRefed<nsMIMEInfoBase> GetFromExtension(const nsCString& aFileExt);
00079 
00080   virtual void FixFilePermissions(nsILocalFile* aFile);
00081 private:
00082   PRUint32 mPermissions;
00083 
00084   // Helper methods which have to access static members
00085   static nsresult UnescapeCommand(const nsAString& aEscapedCommand,
00086                                   const nsAString& aMajorType,
00087                                   const nsAString& aMinorType,
00088                                   nsHashtable& aTypeOptions,
00089                                   nsACString& aUnEscapedCommand);
00090   static nsresult GetFileLocation(const char* aPrefName,
00091                                   const char* aEnvVarName,
00092                                   PRUnichar** aFileLocation);
00093   static nsresult LookUpTypeAndDescription(const nsAString& aFileExtension,
00094                                            nsAString& aMajorType,
00095                                            nsAString& aMinorType,
00096                                            nsAString& aDescription,
00097                                            PRBool aUserData);
00098   static nsresult CreateInputStream(const nsAString& aFilename,
00099                                     nsIFileInputStream ** aFileInputStream,
00100                                     nsILineInputStream ** aLineInputStream,
00101                                     nsACString& aBuffer,
00102                                     PRBool * aNetscapeFormat,
00103                                     PRBool * aMore);
00104 
00105   static nsresult GetTypeAndDescriptionFromMimetypesFile(const nsAString& aFilename,
00106                                                          const nsAString& aFileExtension,
00107                                                          nsAString& aMajorType,
00108                                                          nsAString& aMinorType,
00109                                                          nsAString& aDescription);
00110 
00111   static nsresult LookUpExtensionsAndDescription(const nsAString& aMajorType,
00112                                                  const nsAString& aMinorType,
00113                                                  nsAString& aFileExtensions,
00114                                                  nsAString& aDescription);
00115 
00116   static nsresult GetExtensionsAndDescriptionFromMimetypesFile(const nsAString& aFilename,
00117                                                                const nsAString& aMajorType,
00118                                                                const nsAString& aMinorType,
00119                                                                nsAString& aFileExtensions,
00120                                                                nsAString& aDescription);
00121 
00122   static nsresult ParseNetscapeMIMETypesEntry(const nsAString& aEntry,
00123                                               nsAString::const_iterator& aMajorTypeStart,
00124                                               nsAString::const_iterator& aMajorTypeEnd,
00125                                               nsAString::const_iterator& aMinorTypeStart,
00126                                               nsAString::const_iterator& aMinorTypeEnd,
00127                                               nsAString& aExtensions,
00128                                               nsAString::const_iterator& aDescriptionStart,
00129                                               nsAString::const_iterator& aDescriptionEnd);
00130 
00131   static nsresult ParseNormalMIMETypesEntry(const nsAString& aEntry,
00132                                             nsAString::const_iterator& aMajorTypeStart,
00133                                             nsAString::const_iterator& aMajorTypeEnd,
00134                                             nsAString::const_iterator& aMinorTypeStart,
00135                                             nsAString::const_iterator& aMinorTypeEnd,
00136                                             nsAString& aExtensions,
00137                                             nsAString::const_iterator& aDescriptionStart,
00138                                             nsAString::const_iterator& aDescriptionEnd);
00139 
00140   static nsresult LookUpHandlerAndDescription(const nsAString& aMajorType,
00141                                               const nsAString& aMinorType,
00142                                               nsHashtable& aTypeOptions,
00143                                               nsAString& aHandler,
00144                                               nsAString& aDescription,
00145                                               nsAString& aMozillaFlags);
00146   
00147   static nsresult DoLookUpHandlerAndDescription(const nsAString& aMajorType,
00148                                                 const nsAString& aMinorType,
00149                                                 nsHashtable& aTypeOptions,
00150                                                 nsAString& aHandler,
00151                                                 nsAString& aDescription,
00152                                                 nsAString& aMozillaFlags,
00153                                                 PRBool aUserData);
00154   
00155   static nsresult GetHandlerAndDescriptionFromMailcapFile(const nsAString& aFilename,
00156                                                           const nsAString& aMajorType,
00157                                                           const nsAString& aMinorType,
00158                                                           nsHashtable& aTypeOptions,
00159                                                           nsAString& aHandler,
00160                                                           nsAString& aDescription,
00161                                                           nsAString& aMozillaFlags);
00162 
00163   nsresult GetHandlerAppFromPrefs(const char* aScheme, nsIFile** aApp);
00164 };
00165 
00166 #endif // nsOSHelperAppService_h__