Bug 449522 - Context menu for HTML5 <video> elements. r=gavin, ui-r=boriss
[wine-gecko.git] / uriloader / exthandler / nsMIMEInfoImpl.h
blob77813b5cc7142d0c4b99d32b5e57fc7c10782b87
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:set ts=4 sw=4 sts=4 et: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Dan Mosedale <dmose@mozilla.org>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
39 #ifndef __nsmimeinfoimpl_h___
40 #define __nsmimeinfoimpl_h___
42 #include "nsIMIMEInfo.h"
43 #include "nsIAtom.h"
44 #include "nsString.h"
45 #include "nsVoidArray.h"
46 #include "nsIMutableArray.h"
47 #include "nsIFile.h"
48 #include "nsCOMPtr.h"
49 #include "nsIURI.h"
51 /**
52 * UTF8 moz-icon URI string for the default handler application's icon, if
53 * available.
55 #define PROPERTY_DEFAULT_APP_ICON_URL "defaultApplicationIconURL"
56 /**
57 * UTF8 moz-icon URI string for the user's preferred handler application's
58 * icon, if available.
60 #define PROPERTY_CUSTOM_APP_ICON_URL "customApplicationIconURL"
62 /**
63 * Basic implementation of nsIMIMEInfo. Incomplete - it is meant to be
64 * subclassed, and GetHasDefaultHandler as well as LaunchDefaultWithFile need to
65 * be implemented.
67 class nsMIMEInfoBase : public nsIMIMEInfo {
68 public:
69 NS_DECL_ISUPPORTS
71 // I'd use NS_DECL_NSIMIMEINFO, but I don't want GetHasDefaultHandler
72 NS_IMETHOD GetFileExtensions(nsIUTF8StringEnumerator **_retval);
73 NS_IMETHOD SetFileExtensions(const nsACString & aExtensions);
74 NS_IMETHOD ExtensionExists(const nsACString & aExtension, PRBool *_retval);
75 NS_IMETHOD AppendExtension(const nsACString & aExtension);
76 NS_IMETHOD GetPrimaryExtension(nsACString & aPrimaryExtension);
77 NS_IMETHOD SetPrimaryExtension(const nsACString & aPrimaryExtension);
78 NS_IMETHOD GetType(nsACString & aType);
79 NS_IMETHOD GetMIMEType(nsACString & aMIMEType);
80 NS_IMETHOD GetDescription(nsAString & aDescription);
81 NS_IMETHOD SetDescription(const nsAString & aDescription);
82 NS_IMETHOD GetMacType(PRUint32 *aMacType);
83 NS_IMETHOD SetMacType(PRUint32 aMacType);
84 NS_IMETHOD GetMacCreator(PRUint32 *aMacCreator);
85 NS_IMETHOD SetMacCreator(PRUint32 aMacCreator);
86 NS_IMETHOD Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval);
87 NS_IMETHOD GetPreferredApplicationHandler(nsIHandlerApp * *aPreferredAppHandler);
88 NS_IMETHOD SetPreferredApplicationHandler(nsIHandlerApp * aPreferredAppHandler);
89 NS_IMETHOD GetPossibleApplicationHandlers(nsIMutableArray * *aPossibleAppHandlers);
90 NS_IMETHOD GetDefaultDescription(nsAString & aDefaultDescription);
91 NS_IMETHOD LaunchWithFile(nsIFile *aFile);
92 NS_IMETHOD LaunchWithURI(nsIURI *aURI,
93 nsIInterfaceRequestor *aWindowContext);
94 NS_IMETHOD GetPreferredAction(nsHandlerInfoAction *aPreferredAction);
95 NS_IMETHOD SetPreferredAction(nsHandlerInfoAction aPreferredAction);
96 NS_IMETHOD GetAlwaysAskBeforeHandling(PRBool *aAlwaysAskBeforeHandling);
97 NS_IMETHOD SetAlwaysAskBeforeHandling(PRBool aAlwaysAskBeforeHandling);
98 NS_IMETHOD GetPossibleLocalHandlers(nsIArray **_retval);
100 enum HandlerClass {
101 eMIMEInfo,
102 eProtocolInfo
105 // nsMIMEInfoBase methods
106 nsMIMEInfoBase(const char *aMIMEType = "") NS_HIDDEN;
107 nsMIMEInfoBase(const nsACString& aMIMEType) NS_HIDDEN;
108 nsMIMEInfoBase(const nsACString& aType, HandlerClass aClass) NS_HIDDEN;
109 virtual ~nsMIMEInfoBase(); // must be virtual, as the the base class's Release should call the subclass's destructor
111 void SetMIMEType(const nsACString & aMIMEType) { mType = aMIMEType; }
113 void SetDefaultDescription(const nsString& aDesc) { mDefaultAppDescription = aDesc; }
116 * Copies basic data of this MIME Info Implementation to the given other
117 * MIME Info. The data consists of the MIME Type, the (default) description,
118 * the MacOS type and creator, and the extension list (this object's
119 * extension list will replace aOther's list, not append to it). This
120 * function also ensures that aOther's primary extension will be the same as
121 * the one of this object.
123 void CopyBasicDataTo(nsMIMEInfoBase* aOther);
126 * Return whether this MIMEInfo has any extensions
128 PRBool HasExtensions() const { return mExtensions.Count() != 0; }
130 protected:
132 * Launch the default application for the given file.
133 * For even more control over the launching, override launchWithFile.
134 * Also see the comment about nsIMIMEInfo in general, above.
136 * @param aFile The file that should be opened
138 virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile) = 0;
141 * Loads the URI with the OS default app.
143 * @param aURI The URI to pass off to the OS.
145 virtual NS_HIDDEN_(nsresult) LoadUriInternal(nsIURI *aURI) = 0;
148 * This method can be used to launch the file or URI with a single
149 * argument (typically either a file path or a URI spec). This is
150 * meant as a helper method for implementations of
151 * LaunchWithURI/LaunchDefaultWithFile.
153 * @param aApp The application to launch (may not be null)
154 * @param aArg The argument to pass on the command line
156 static NS_HIDDEN_(nsresult) LaunchWithIProcess(nsIFile* aApp,
157 const nsCString &aArg);
160 * Given a file: nsIURI, return the associated nsILocalFile
162 * @param aURI the file: URI in question
163 * @param aFile the associated nsILocalFile (out param)
165 static NS_HIDDEN_(nsresult) GetLocalFileFromURI(nsIURI *aURI,
166 nsILocalFile **aFile);
168 // member variables
169 nsCStringArray mExtensions; ///< array of file extensions associated w/ this MIME obj
170 nsString mDescription; ///< human readable description
171 PRUint32 mMacType, mMacCreator; ///< Mac file type and creator
172 nsCString mType;
173 HandlerClass mClass;
174 nsCOMPtr<nsIHandlerApp> mPreferredApplication;
175 nsCOMPtr<nsIMutableArray> mPossibleApplications;
176 nsHandlerInfoAction mPreferredAction; ///< preferred action to associate with this type
177 nsString mPreferredAppDescription;
178 nsString mDefaultAppDescription;
179 PRBool mAlwaysAskBeforeHandling;
184 * This is a complete implementation of nsIMIMEInfo, and contains all necessary
185 * methods. However, depending on your platform you may want to use a different
186 * way of launching applications. This class stores the default application in a
187 * member variable and provides a function for setting it. For local
188 * applications, launching is done using nsIProcess, native path of the file to
189 * open as first argument.
191 class nsMIMEInfoImpl : public nsMIMEInfoBase {
192 public:
193 nsMIMEInfoImpl(const char *aMIMEType = "") : nsMIMEInfoBase(aMIMEType) {}
194 nsMIMEInfoImpl(const nsACString& aMIMEType) : nsMIMEInfoBase(aMIMEType) {}
195 nsMIMEInfoImpl(const nsACString& aType, HandlerClass aClass) :
196 nsMIMEInfoBase(aType, aClass) {}
197 virtual ~nsMIMEInfoImpl() {}
199 // nsIMIMEInfo methods
200 NS_IMETHOD GetHasDefaultHandler(PRBool *_retval);
201 NS_IMETHOD GetDefaultDescription(nsAString& aDefaultDescription);
203 // additional methods
205 * Sets the default application. Supposed to be only called by the OS Helper
206 * App Services; the default application is immutable after it is first set.
208 void SetDefaultApplication(nsIFile* aApp) { if (!mDefaultApplication) mDefaultApplication = aApp; }
210 protected:
211 // nsMIMEInfoBase methods
213 * The base class implementation is to use LaunchWithIProcess in combination
214 * with mDefaultApplication. Subclasses can override that behaviour.
216 virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile);
219 * Loads the URI with the OS default app. This should be overridden by each
220 * OS's implementation.
222 virtual NS_HIDDEN_(nsresult) LoadUriInternal(nsIURI *aURI) = 0;
224 nsCOMPtr<nsIFile> mDefaultApplication; ///< default application associated with this type.
227 #endif //__nsmimeinfoimpl_h___