Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef nsOSHelperAppService_h__ |
michael@0 | 8 | #define nsOSHelperAppService_h__ |
michael@0 | 9 | |
michael@0 | 10 | // The OS helper app service is a subclass of nsExternalHelperAppService and is implemented on each |
michael@0 | 11 | // platform. It contains platform specific code for finding helper applications for a given mime type |
michael@0 | 12 | // in addition to launching those applications. |
michael@0 | 13 | |
michael@0 | 14 | #include "nsExternalHelperAppService.h" |
michael@0 | 15 | #include "nsCExternalHandlerService.h" |
michael@0 | 16 | #include "nsMIMEInfoImpl.h" |
michael@0 | 17 | #include "nsCOMPtr.h" |
michael@0 | 18 | |
michael@0 | 19 | class nsILineInputStream; |
michael@0 | 20 | |
michael@0 | 21 | class nsOSHelperAppService : public nsExternalHelperAppService |
michael@0 | 22 | { |
michael@0 | 23 | public: |
michael@0 | 24 | nsOSHelperAppService(); |
michael@0 | 25 | virtual ~nsOSHelperAppService(); |
michael@0 | 26 | |
michael@0 | 27 | // method overrides for mime.types and mime.info look up steps |
michael@0 | 28 | already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMimeType, |
michael@0 | 29 | const nsACString& aFileExt, |
michael@0 | 30 | bool *aFound); |
michael@0 | 31 | NS_IMETHOD GetProtocolHandlerInfoFromOS(const nsACString &aScheme, |
michael@0 | 32 | bool *found, |
michael@0 | 33 | nsIHandlerInfo **_retval); |
michael@0 | 34 | |
michael@0 | 35 | // override nsIExternalProtocolService methods |
michael@0 | 36 | nsresult OSProtocolHandlerExists(const char * aProtocolScheme, bool * aHandlerExists); |
michael@0 | 37 | NS_IMETHOD GetApplicationDescription(const nsACString& aScheme, nsAString& _retval); |
michael@0 | 38 | |
michael@0 | 39 | // GetFileTokenForPath must be implemented by each platform. |
michael@0 | 40 | // platformAppPath --> a platform specific path to an application that we got out of the |
michael@0 | 41 | // rdf data source. This can be a mac file spec, a unix path or a windows path depending on the platform |
michael@0 | 42 | // aFile --> an nsIFile representation of that platform application path. |
michael@0 | 43 | virtual nsresult GetFileTokenForPath(const char16_t * platformAppPath, nsIFile ** aFile); |
michael@0 | 44 | |
michael@0 | 45 | protected: |
michael@0 | 46 | already_AddRefed<nsMIMEInfoBase> GetFromType(const nsCString& aMimeType); |
michael@0 | 47 | already_AddRefed<nsMIMEInfoBase> GetFromExtension(const nsCString& aFileExt); |
michael@0 | 48 | |
michael@0 | 49 | private: |
michael@0 | 50 | uint32_t mPermissions; |
michael@0 | 51 | |
michael@0 | 52 | // Helper methods which have to access static members |
michael@0 | 53 | static nsresult UnescapeCommand(const nsAString& aEscapedCommand, |
michael@0 | 54 | const nsAString& aMajorType, |
michael@0 | 55 | const nsAString& aMinorType, |
michael@0 | 56 | nsACString& aUnEscapedCommand); |
michael@0 | 57 | static nsresult GetFileLocation(const char* aPrefName, |
michael@0 | 58 | const char* aEnvVarName, |
michael@0 | 59 | nsAString& aFileLocation); |
michael@0 | 60 | static nsresult LookUpTypeAndDescription(const nsAString& aFileExtension, |
michael@0 | 61 | nsAString& aMajorType, |
michael@0 | 62 | nsAString& aMinorType, |
michael@0 | 63 | nsAString& aDescription, |
michael@0 | 64 | bool aUserData); |
michael@0 | 65 | static nsresult CreateInputStream(const nsAString& aFilename, |
michael@0 | 66 | nsIFileInputStream ** aFileInputStream, |
michael@0 | 67 | nsILineInputStream ** aLineInputStream, |
michael@0 | 68 | nsACString& aBuffer, |
michael@0 | 69 | bool * aNetscapeFormat, |
michael@0 | 70 | bool * aMore); |
michael@0 | 71 | |
michael@0 | 72 | static nsresult GetTypeAndDescriptionFromMimetypesFile(const nsAString& aFilename, |
michael@0 | 73 | const nsAString& aFileExtension, |
michael@0 | 74 | nsAString& aMajorType, |
michael@0 | 75 | nsAString& aMinorType, |
michael@0 | 76 | nsAString& aDescription); |
michael@0 | 77 | |
michael@0 | 78 | static nsresult LookUpExtensionsAndDescription(const nsAString& aMajorType, |
michael@0 | 79 | const nsAString& aMinorType, |
michael@0 | 80 | nsAString& aFileExtensions, |
michael@0 | 81 | nsAString& aDescription); |
michael@0 | 82 | |
michael@0 | 83 | static nsresult GetExtensionsAndDescriptionFromMimetypesFile(const nsAString& aFilename, |
michael@0 | 84 | const nsAString& aMajorType, |
michael@0 | 85 | const nsAString& aMinorType, |
michael@0 | 86 | nsAString& aFileExtensions, |
michael@0 | 87 | nsAString& aDescription); |
michael@0 | 88 | |
michael@0 | 89 | static nsresult ParseNetscapeMIMETypesEntry(const nsAString& aEntry, |
michael@0 | 90 | nsAString::const_iterator& aMajorTypeStart, |
michael@0 | 91 | nsAString::const_iterator& aMajorTypeEnd, |
michael@0 | 92 | nsAString::const_iterator& aMinorTypeStart, |
michael@0 | 93 | nsAString::const_iterator& aMinorTypeEnd, |
michael@0 | 94 | nsAString& aExtensions, |
michael@0 | 95 | nsAString::const_iterator& aDescriptionStart, |
michael@0 | 96 | nsAString::const_iterator& aDescriptionEnd); |
michael@0 | 97 | |
michael@0 | 98 | static nsresult ParseNormalMIMETypesEntry(const nsAString& aEntry, |
michael@0 | 99 | nsAString::const_iterator& aMajorTypeStart, |
michael@0 | 100 | nsAString::const_iterator& aMajorTypeEnd, |
michael@0 | 101 | nsAString::const_iterator& aMinorTypeStart, |
michael@0 | 102 | nsAString::const_iterator& aMinorTypeEnd, |
michael@0 | 103 | nsAString& aExtensions, |
michael@0 | 104 | nsAString::const_iterator& aDescriptionStart, |
michael@0 | 105 | nsAString::const_iterator& aDescriptionEnd); |
michael@0 | 106 | |
michael@0 | 107 | static nsresult LookUpHandlerAndDescription(const nsAString& aMajorType, |
michael@0 | 108 | const nsAString& aMinorType, |
michael@0 | 109 | nsAString& aHandler, |
michael@0 | 110 | nsAString& aDescription, |
michael@0 | 111 | nsAString& aMozillaFlags); |
michael@0 | 112 | |
michael@0 | 113 | static nsresult DoLookUpHandlerAndDescription(const nsAString& aMajorType, |
michael@0 | 114 | const nsAString& aMinorType, |
michael@0 | 115 | nsAString& aHandler, |
michael@0 | 116 | nsAString& aDescription, |
michael@0 | 117 | nsAString& aMozillaFlags, |
michael@0 | 118 | bool aUserData); |
michael@0 | 119 | |
michael@0 | 120 | static nsresult GetHandlerAndDescriptionFromMailcapFile(const nsAString& aFilename, |
michael@0 | 121 | const nsAString& aMajorType, |
michael@0 | 122 | const nsAString& aMinorType, |
michael@0 | 123 | nsAString& aHandler, |
michael@0 | 124 | nsAString& aDescription, |
michael@0 | 125 | nsAString& aMozillaFlags); |
michael@0 | 126 | }; |
michael@0 | 127 | |
michael@0 | 128 | #endif // nsOSHelperAppService_h__ |