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 class nsMIMEInfoOS2;
00054 
00055 class nsOSHelperAppService : public nsExternalHelperAppService
00056 {
00057 public:
00058   nsOSHelperAppService();
00059   virtual ~nsOSHelperAppService();
00060 
00061   // method overrides for mime.types and mime.info look up steps
00062   already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMimeType,
00063                                                   const nsACString& aFileExt,
00064                                                   PRBool     *aFound);
00065 
00066   // override nsIExternalProtocolService methods
00067   NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
00068   nsresult LoadUriInternal(nsIURI * aURL);
00069   NS_IMETHODIMP GetApplicationDescription(const nsACString& aScheme, nsAString& _retval);
00070 
00071 protected:
00072   already_AddRefed<nsMIMEInfoOS2> GetFromType(const nsCString& aMimeType);
00073   already_AddRefed<nsMIMEInfoOS2> GetFromExtension(const nsCString& aFileExt);
00074 
00075 private:
00076   nsresult GetApplicationAndParametersFromINI(const nsACString& aProtocol,
00077                                               char * app, ULONG appLength,
00078                                               char * param, ULONG paramLength);
00079   // Helper methods which have to access static members
00080   static nsresult UnescapeCommand(const nsAString& aEscapedCommand,
00081                                   const nsAString& aMajorType,
00082                                   const nsAString& aMinorType,
00083                                   nsHashtable& aTypeOptions,
00084                                   nsACString& aUnEscapedCommand);
00085   static nsresult GetFileLocation(const char* aPrefName,
00086                                   const char* aEnvVarName,
00087                                   PRUnichar** aFileLocation);
00088   static nsresult LookUpTypeAndDescription(const nsAString& aFileExtension,
00089                                            nsAString& aMajorType,
00090                                            nsAString& aMinorType,
00091                                            nsAString& aDescription);
00092   static nsresult CreateInputStream(const nsAString& aFilename,
00093                                     nsIFileInputStream ** aFileInputStream,
00094                                     nsILineInputStream ** aLineInputStream,
00095                                     nsACString& aBuffer,
00096                                     PRBool * aNetscapeFormat,
00097                                     PRBool * aMore);
00098 
00099   static nsresult GetTypeAndDescriptionFromMimetypesFile(const nsAString& aFilename,
00100                                                          const nsAString& aFileExtension,
00101                                                          nsAString& aMajorType,
00102                                                          nsAString& aMinorType,
00103                                                          nsAString& aDescription);
00104 
00105   static nsresult LookUpExtensionsAndDescription(const nsAString& aMajorType,
00106                                                  const nsAString& aMinorType,
00107                                                  nsAString& aFileExtensions,
00108                                                  nsAString& aDescription);
00109 
00110   static nsresult GetExtensionsAndDescriptionFromMimetypesFile(const nsAString& aFilename,
00111                                                                const nsAString& aMajorType,
00112                                                                const nsAString& aMinorType,
00113                                                                nsAString& aFileExtensions,
00114                                                                nsAString& aDescription);
00115 
00116   static nsresult ParseNetscapeMIMETypesEntry(const nsAString& aEntry,
00117                                               nsAString::const_iterator& aMajorTypeStart,
00118                                               nsAString::const_iterator& aMajorTypeEnd,
00119                                               nsAString::const_iterator& aMinorTypeStart,
00120                                               nsAString::const_iterator& aMinorTypeEnd,
00121                                               nsAString& aExtensions,
00122                                               nsAString::const_iterator& aDescriptionStart,
00123                                               nsAString::const_iterator& aDescriptionEnd);
00124 
00125   static nsresult ParseNormalMIMETypesEntry(const nsAString& aEntry,
00126                                             nsAString::const_iterator& aMajorTypeStart,
00127                                             nsAString::const_iterator& aMajorTypeEnd,
00128                                             nsAString::const_iterator& aMinorTypeStart,
00129                                             nsAString::const_iterator& aMinorTypeEnd,
00130                                             nsAString& aExtensions,
00131                                             nsAString::const_iterator& aDescriptionStart,
00132                                             nsAString::const_iterator& aDescriptionEnd);
00133 
00134   static nsresult LookUpHandlerAndDescription(const nsAString& aMajorType,
00135                                               const nsAString& aMinorType,
00136                                               nsHashtable& aTypeOptions,
00137                                               nsAString& aHandler,
00138                                               nsAString& aDescription,
00139                                               nsAString& aMozillaFlags);
00140   static nsresult GetHandlerAndDescriptionFromMailcapFile(const nsAString& aFilename,
00141                                                           const nsAString& aMajorType,
00142                                                           const nsAString& aMinorType,
00143                                                           nsHashtable& aTypeOptions,
00144                                                           nsAString& aHandler,
00145                                                           nsAString& aDescription,
00146                                                           nsAString& aMozillaFlags);
00147 };
00148 
00149 #endif // nsOSHelperAppService_h__