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