1 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Dan Mosedale <dmose@mozilla.org>
24 * Myk Melez <myk@mozilla.org>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * 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.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 #include "nsISupports.idl"
41
42 interface nsIURI;
43 interface nsIFile;
44 interface nsIUTF8StringEnumerator;
45 interface nsIHandlerApp;
46 interface nsIArray;
47 interface nsIMutableArray;
48 interface nsIInterfaceRequestor;
49
50 typedef long nsHandlerInfoAction;
51
52 /**
53 * nsIHandlerInfo gives access to the information about how a given protocol
54 * scheme or MIME-type is handled.
55 */
56 [scriptable, uuid(325e56a7-3762-4312-aec7-f1fcf84b4145)]
57 interface nsIHandlerInfo : nsISupports {
58 /**
59 * The type of this handler info. For MIME handlers, this is the MIME type.
60 * For protocol handlers, it's the scheme.
61 *
62 * @return String representing the type.
63 */
64 readonly attribute ACString type;
65
66 /**
67 * A human readable description of the handler type
68 */
69 attribute AString description;
70
71 /**
72 * The application the user has said they want associated with this content
73 * type. This is not always guaranteed to be set!!
74 */
75 attribute nsIHandlerApp preferredApplicationHandler;
76
77 /**
78 * Applications that can handle this content type.
79 *
80 * The list will include the preferred handler, if any. Elements of this
81 * array are nsIHandlerApp objects, and this attribute will always reference
82 * an array, whether or not there are any possible handlers. If there are
83 * no possible handlers, the array will contain no elements, so just check
84 * its length (nsIArray::length) to see if there are any possible handlers.
85 */
86 readonly attribute nsIMutableArray possibleApplicationHandlers;
87
88 /**
89 * Indicates whether a default application handler exists,
90 * i.e. whether launchWithFile with action = useSystemDefault is possible
91 * and defaultDescription will contain usable information.
92 */
93 readonly attribute boolean hasDefaultHandler;
94
95 /**
96 * A pretty name description of the associated default application. Only
97 * usable if hasDefaultHandler is true.
98 */
99 readonly attribute AString defaultDescription;
100
101 /**
102 * Launches the application with the specified URI, in a way that
103 * depends on the value of preferredAction. preferredAction must be
104 * useHelperApp or useSystemDefault.
105 *
106 * @note Only the URI scheme is used to determine how to launch. This is
107 * essentially a pass-by-value operation. This means that in the case of
108 * a file: URI, the handler that is registered for file: will be launched
109 * and our code will not make any decision based on the content-type or
110 * extension, though the invoked file: handler is free to do so.
111 *
112 * @param aURI
113 * The URI to launch this application with
114 *
115 * @param aWindowContext
116 * The window to parent the dialog against, and, if a web handler
117 * is chosen, it is loaded in this window as well. See
118 * nsIHandlerApp.launchWithURI for more details.
119 *
120 * @throw NS_ERROR_INVALID_ARG if preferredAction is not valid for this
121 * call. Other exceptions may be thrown.
122 */
123 void launchWithURI(in nsIURI aURI,
124 [optional] in nsIInterfaceRequestor aWindowContext);
125
126 /**
127 * preferredAction is how the user specified they would like to handle
128 * this content type: save to disk, use specified helper app, use OS
129 * default handler or handle using navigator; possible value constants
130 * listed below
131 */
132 attribute nsHandlerInfoAction preferredAction;
133
134 const long saveToDisk = 0;
135 /**
136 * Used to indicate that we know nothing about what to do with this. You
137 * could consider this to be not initialized.
138 */
139 const long alwaysAsk = 1;
140 const long useHelperApp = 2;
141 const long handleInternally = 3;
142 const long useSystemDefault = 4;
143
144 /**
145 * alwaysAskBeforeHandling: if true, we should always give the user a
146 * dialog asking how to dispose of this content.
147 */
148 attribute boolean alwaysAskBeforeHandling;
149 };
150
151 /**
152 * nsIMIMEInfo extends nsIHandlerInfo with a bunch of information specific to
153 * MIME content-types. There is a one-to-many relationship between MIME types
154 * and file extensions. This means that a MIMEInfo object may have multiple
155 * file extensions associated with it. However, the reverse is not true.
156 *
157 * MIMEInfo objects are generally retrieved from the MIME Service
158 * @see nsIMIMEService
159 */
160 [scriptable, uuid(cd7083f8-5fe9-4248-bb09-0b0e2982fde8)]
161 interface nsIMIMEInfo : nsIHandlerInfo {
162 /**
163 * Gives you an array of file types associated with this type.
164 *
165 * @return Number of elements in the array.
166 * @return Array of extensions.
167 */
168 nsIUTF8StringEnumerator getFileExtensions();
169
170 /**
171 * Set File Extensions. Input is a comma delimited list of extensions.
172 */
173 void setFileExtensions(in AUTF8String aExtensions);
174
175 /**
176 * Returns whether or not the given extension is
177 * associated with this MIME info.
178 *
179 * @return TRUE if the association exists.
180 */
181 boolean extensionExists(in AUTF8String aExtension);
182
183 /**
184 * Append a given extension to the set of extensions
185 */
186 void appendExtension(in AUTF8String aExtension);
187
188 /**
189 * Returns the first extension association in
190 * the internal set of extensions.
191 *
192 * @return The first extension.
193 */
194 attribute AUTF8String primaryExtension;
195
196 /**
197 * The MIME type of this MIMEInfo.
198 *
199 * @return String representing the MIME type.
200 *
201 * @deprecated use nsIHandlerInfo::type instead.
202 */
203 readonly attribute ACString MIMEType;
204
205 /**
206 * Mac Type and creator types
207 */
208 attribute PRUint32 macType;
209 attribute PRUint32 macCreator;
210
211 /**
212 * Returns whether or not these two nsIMIMEInfos are logically
213 * equivalent.
214 *
215 * @returns PR_TRUE if the two are considered equal
216 */
217 boolean equals(in nsIMIMEInfo aMIMEInfo);
218
219 /**
220 * Returns a list of nsILocalHandlerApp objects containing
221 * handlers associated with this mimeinfo. Implemented per
222 * platform using information in this object to generate the
223 * best list. Typically used for an "open with" style user
224 * option.
225 *
226 * @return nsIArray of nsILocalHandlerApp
227 */
228 readonly attribute nsIArray possibleLocalHandlers;
229
230 /**
231 * Launches the application with the specified file, in a way that
232 * depends on the value of preferredAction. preferredAction must be
233 * useHelperApp or useSystemDefault.
234 *
235 * @param aFile The file to launch this application with.
236 *
237 * @throw NS_ERROR_INVALID_ARG if action is not valid for this function.
238 * Other exceptions may be thrown.
239 */
240 void launchWithFile(in nsIFile aFile);
241 };
242
243 /**
244 * nsIHandlerApp represents an external application that can handle content
245 * of some sort (either a MIME type or a protocol).
246 *
247 * FIXME: now that we've made nsIWebHandlerApp inherit from nsIHandlerApp,
248 * we should also try to make nsIWebContentHandlerInfo inherit from or possibly
249 * be replaced by nsIWebHandlerApp (bug 394710).
250 */
251 [scriptable, uuid(8d298761-0963-4c90-99e2-6ea498825e82)]
252 interface nsIHandlerApp : nsISupports {
253
254 /**
255 * Human readable name for the handler
256 */
257 attribute AString name;
258
259 /**
260 * Whether or not the given handler app is logically equivalent to the
261 * invokant (i.e. they represent the same app).
262 *
263 * Two apps are the same if they are both either local or web handlers
264 * and their executables/URI templates are the same in a string comparison.
265 *
266 * @param aHandlerApp the handler app to compare to the invokant
267 *
268 * @returns true if the two are logically equivalent, false otherwise
269 */
270 boolean equals(in nsIHandlerApp aHandlerApp);
271
272 /**
273 * Launches the application with the specified URI.
274 *
275 * @param aURI
276 * The URI to launch this application with
277 *
278 * @param aWindowContext
279 *
280 * Currently only relevant to web-handler apps. If given, this
281 * represents the docshell to load the handler in and is passed
282 * through to nsIURILoader.openURI. If this parameter is null or
283 * not present, the web handler app implementation will attempt to
284 * find/create a place to load the handler and do so. As of this
285 * writing, it tries to load the web handler in a new window using
286 * nsIBrowserDOMWindow.openURI. In the future, it may attempt to
287 * have a more comprehensive strategy which could include handing
288 * off to the system default browser (bug 394479).
289 */
290 void launchWithURI(in nsIURI aURI,
291 [optional] in nsIInterfaceRequestor aWindowContext);
292
293 };
294
295 /**
296 * nsILocalHandlerApp is a local OS-level executable
297 */
298 [scriptable, uuid(9812be73-273c-478c-8170-c3e0db08ae7c)]
299 interface nsILocalHandlerApp : nsIHandlerApp {
300
301 /**
302 * Pointer to the executable file used to handle content
303 */
304 attribute nsIFile executable;
305 };
306
307 /**
308 * nsIWebHandlerApp is a web-based handler, as speced by the WhatWG HTML5
309 * draft. Currently, only GET-based handlers are supported. At some point,
310 * we probably want to work with WhatWG to spec out and implement POST-based
311 * handlers as well.
312 */
313 [scriptable, uuid(7521a093-c498-45ce-b462-df7ba0d882f6)]
314 interface nsIWebHandlerApp : nsIHandlerApp {
315
316 /**
317 * Template used to construct the URI to GET. Template is expected to have
318 * a %s in it, and the escaped URI to be handled is inserted in place of
319 * that %s, as per the HTML5 spec.
320 */
321 attribute AUTF8String uriTemplate;
322 };