!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 //@line 38 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/toolkit/mozapps/downloads/content/helperApps.js"
2
3 var Cc = Components.classes;
4 var Ci = Components.interfaces;
5
6 var gRDF;
7
8 const CLASS_MIMEINFO = "mimetype";
9 const CLASS_PROTOCOLINFO = "scheme";
10
11 // namespace prefix
12 const NC_NS = "http://home.netscape.com/NC-rdf#";
13
14 // type list properties
15
16 const NC_MIME_TYPES = NC_NS + "MIME-types";
17 const NC_PROTOCOL_SCHEMES = NC_NS + "Protocol-Schemes";
18
19 ///////////////////////////////////////////////////////////////////////////////
20 // MIME Types DataSource Wrapper
21
NC_URI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
22 function NC_URI(aProperty)
23 {
24 return "http://home.netscape.com/NC-rdf#" + aProperty;
25 }
26
MIME_URI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
27 function MIME_URI(aType)
28 {
29 return "urn:mimetype:" + aType;
30 }
31
HANDLER_URI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
32 function HANDLER_URI(aHandler)
33 {
34 return "urn:mimetype:handler:" + aHandler;
35 }
36
APP_URI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
37 function APP_URI(aType)
38 {
39 return "urn:mimetype:externalApplication:" + aType;
40 }
41
ArrayEnumerator
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
42 function ArrayEnumerator(aItems) {
43 if (aItems) {
44 for (var i = 0; i < aItems.length; ++i) {
45 if (!aItems[i])
46 aItems.splice(i--, 1);
47 }
48 this._contents = aItems;
49 } else {
50 this._contents = [];
51 }
52 }
53
54 ArrayEnumerator.prototype = {
55 _index: 0,
56
hasMoreElements
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
57 hasMoreElements: function () {
58 return this._index < this._contents.length;
59 },
60
getNext
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
61 getNext: function () {
62 return this._contents[this._index++];
63 },
64
push
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
65 push: function (aElement) {
66 if (aElement)
67 this._contents.push(aElement);
68 }
69 };
70
HelperApps
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
71 function HelperApps()
72 {
73 if (!gRDF)
74 gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
75
76 const mimeTypes = "UMimTyp";
77 var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
78
79 var file = fileLocator.get(mimeTypes, Components.interfaces.nsIFile);
80
81 var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
82 var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
83 this._inner = gRDF.GetDataSourceBlocking(fileHandler.getURLSpecFromFile(file));
84 this._inner.AddObserver(this);
85
86 this._fileTypeArc = gRDF.GetResource(NC_URI("FileType"));
87 this._fileHandlerArc = gRDF.GetResource(NC_URI("FileHandler"));
88 this._fileIconArc = gRDF.GetResource(NC_URI("FileIcon"));
89 this._fileExtensionArc = gRDF.GetResource(NC_URI("FileExtension"));
90 this._fileExtensionsArc = gRDF.GetResource(NC_URI("FileExtensions"));
91 this._handleAutoArc = gRDF.GetResource(NC_URI("FileHandleAuto"));
92 this._valueArc = gRDF.GetResource(NC_URI("value"));
93 this._handlerPropArc = gRDF.GetResource(NC_URI("handlerProp"));
94 this._externalAppArc = gRDF.GetResource(NC_URI("externalApplication"));
95 }
96
97 HelperApps.prototype = {
mimeHandlerExists
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
98 mimeHandlerExists: function (aMIMEType)
99 {
100 var valueProperty = gRDF.GetUnicodeResource(NC_URI("value"));
101 var mimeSource = gRDF.GetUnicodeResource(MIME_URI(aMIMEType));
102 var mimeLiteral = gRDF.GetLiteral(aMIMEType);
103 return this._inner.HasAssertion(mimeSource, valueProperty, mimeLiteral, true);
104 },
105
updateTypeInfo
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
106 updateTypeInfo: function (aMIMEInfo)
107 {
108 var mimeType = aMIMEInfo.MIMEType;
109 var isNewMIMEType = this.mimeHandlerExists(mimeType);
110 var entry = new HandlerOverride(MIME_URI(mimeType), this._inner);
111 entry.mimeType = mimeType;
112 entry.isEditable = true;
113 entry.alwaysAsk = aMIMEInfo.alwaysAskBeforeHandling;
114
115 // If not updating (i.e., a newly encountered mime type),
116 // then update extension list and description.
117 if (!isNewMIMEType) {
118 var extEnumerator = aMIMEInfo.getFileExtensions();
119 while (extEnumerator.hasMore()) {
120 entry.addExtension(extEnumerator.getNext());
121 }
122 entry.description = aMIMEInfo.description;
123 entry.appDisplayName = "";
124 }
125
126 const nsIMIMEInfo = Components.interfaces.nsIMIMEInfo;
127 if (aMIMEInfo.preferredAction == nsIMIMEInfo.saveToDisk) {
128 entry.saveToDisk = true;
129 if (!isNewMIMEType) {
130 // Creating a new entry, set path.
131 entry.appPath = "";
132 }
133 }
134 else if (aMIMEInfo.preferredAction == nsIMIMEInfo.useSystemDefault ||
135 aMIMEInfo.preferredApplicationHandler == null) {
136 entry.useSystemDefault = true;
137 if (!isNewMIMEType) {
138 // Creating a new entry, set path.
139 entry.appPath = "";
140 }
141 }
142 else if (aMIMEInfo.preferredApplicationHandler instanceof Components.interfaces.nsILocalHandlerApp) {
143 entry.saveToDisk = false;
144 entry.useSystemDefault = false;
145 entry.handleInternal = false;
146 entry.appPath = aMIMEInfo.preferredApplicationHandler.executable.path;
147 entry.appDisplayName = aMIMEInfo.preferredApplicationHandler.name;
148 }
149
150 // Do RDF magic.
151 entry.buildLinks();
152 this.flush();
153 },
154
getLiteralValue
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
155 getLiteralValue: function (aResource, aProperty)
156 {
157 var res = gRDF.GetResource(aResource);
158 var prop = gRDF.GetResource(NC_URI(aProperty));
159 var val = this.GetTarget(res, prop, true);
160 if (val) {
161 val = val.QueryInterface(Components.interfaces.nsIRDFLiteral);
162 return val.Value;
163 }
164 return "";
165 },
166
167 /* nsIRDFDataSource */
get_URI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
168 get URI() {
169 return this._inner.URI;
170 },
171
GetSource
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
172 GetSource: function (aProperty, aTarget, aTruthValue) {
173 return this._inner.GetSource(aProperty, aTarget, aTruthValue);
174 },
GetSources
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
175 GetSources: function (aProperty, aTarget, aTruthValue) {
176 return this._inner.GetSources(aProperty, aTarget, aTruthValue);
177 },
178
_isRootTypeResource
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
179 _isRootTypeResource: function (aResource) {
180 aResource = aResource.QueryInterface(Components.interfaces.nsIRDFResource);
181 const kRootTypePrefix = "urn:mimetype:";
182 return (aResource.Value.substr(0, kRootTypePrefix.length) == kRootTypePrefix);
183 },
184
getMIMEInfo
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
185 getMIMEInfo: function (aResource) {
186 var types = this._inner.GetTarget(aResource, this._valueArc, true);
187 if (types) {
188 types = types.QueryInterface(Components.interfaces.nsIRDFLiteral);
189 types = types.Value.split(", ");
190
191 mimeSvc = Components.classes["@mozilla.org/mime;1"].getService(Components.interfaces.nsIMIMEService);
192 return mimeSvc.getFromTypeAndExtension(types[0], null);
193 }
194
195 return null;
196 },
197
GetTarget
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
198 GetTarget: function (aSource, aProperty, aTruthValue) {
199 if (this._isRootTypeResource(aSource)) {
200 var typeInfo = this.getMIMEInfo(aSource);
201 if (typeInfo) {
202 var bundle = document.getElementById("strings");
203 if (aProperty.EqualsNode(this._handleAutoArc)) {
204 var handler = this.GetTarget(aSource, this._handlerPropArc, true);
205 if (handler) {
206 handler = handler.QueryInterface(Components.interfaces.nsIRDFResource);
207 return gRDF.GetLiteral(!(this.getLiteralValue(handler.Value, "alwaysAsk") == "true"));
208 }
209 }
210 else if (aProperty.EqualsNode(this._fileTypeArc)) {
211 if (typeInfo.description == "") {
212 try {
213 var literal = bundle.getFormattedString("fileEnding", [typeInfo.primaryExtension.toUpperCase()]);
214 return gRDF.GetLiteral(literal);
215 }
216 catch (e) {
217 // Wow, this sucks, just show the MIME type as a last ditch effort to display
218 // the type of file that this is.
219 return gRDF.GetLiteral(typeInfo.MIMEType);
220 }
221 }
222 return gRDF.GetLiteral(typeInfo.description);
223 }
224 else if (aProperty.EqualsNode(this._fileHandlerArc)) {
225 var handler = this.GetTarget(aSource, this._handlerPropArc, true);
226 if (handler) {
227 handler = handler.QueryInterface(Components.interfaces.nsIRDFResource);
228 if (this.getLiteralValue(handler.Value, "saveToDisk") == "true") {
229 var saveToDisk = bundle.getString("saveToDisk");
230 return gRDF.GetLiteral(saveToDisk);
231 }
232 else if (this.getLiteralValue(handler.Value, "useSystemDefault") == "false") {
233 var extApp = this.GetTarget(handler, this._externalAppArc, true);
234 if (extApp) {
235 extApp = extApp.QueryInterface(Components.interfaces.nsIRDFResource);
236 var openWith = bundle.getFormattedString("openWith", [this.getLiteralValue(extApp.Value, "prettyName")]);
237 return gRDF.GetLiteral(openWith);
238 }
239 }
240 }
241
242 var openWith2 = bundle.getFormattedString("openWith", [typeInfo.defaultDescription]);
243 return gRDF.GetLiteral(openWith2);
244 }
245 else if (aProperty.EqualsNode(this._fileIconArc)) {
246 try {
247 return gRDF.GetLiteral("moz-icon://goat." + typeInfo.primaryExtension + "?size=16");
248 }
249 catch (e) {
250 return gRDF.GetLiteral("moz-icon://goat?size=16&contentType=" + typeInfo.MIMEType);
251 }
252 }
253 else if (aProperty.EqualsNode(this._fileExtensionArc)) {
254 try {
255 return gRDF.GetLiteral(typeInfo.primaryExtension.toUpperCase());
256 }
257 catch (e) { }
258 return gRDF.GetLiteral("");
259 }
260 else if (aProperty.EqualsNode(this._fileExtensionsArc)) {
261 var extns = typeInfo.getFileExtensions();
262
263 // Prevent duplicates.
264 var hash = { };
265 while (extns.hasMore())
266 hash[extns.getNext().toUpperCase()] = 0;
267
268 var str = "";
269 for (var extn in hash)
270 str += extn + ",";
271 str = str.substring(0, str.length - 1);
272
273 return gRDF.GetLiteral(str);
274 }
275 }
276 }
277
278 return this._inner.GetTarget(aSource, aProperty, aTruthValue);
279 },
280
GetTargets
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
281 GetTargets: function (aSource, aProperty, aTruthValue) {
282 if (this._isRootTypeResource(aSource)) {
283 return new ArrayEnumerator([this.GetTarget(aSource, aProperty, aTruthValue)]);
284 }
285
286 return this._inner.GetTargets(aSource, aProperty, aTruthValue);
287 },
Assert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
288 Assert: function (aSource, aProperty, aTarget, aTruthValue) {
289 return this._inner.Assert(aSource, aProperty, aTarget, aTruthValue);
290 },
Unassert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
291 Unassert: function (aSource, aProperty, aTarget) {
292 return this._inner.Unassert(aSource, aProperty, aTarget);
293 },
Change
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
294 Change: function (aSource, aProperty, aOldTarget, aNewTarget) {
295 if (aOldTarget)
296 var ot = aOldTarget.QueryInterface(Components.interfaces.nsIRDFLiteral);
297 if (aNewTarget)
298 var nt = aNewTarget.QueryInterface(Components.interfaces.nsIRDFLiteral);
299
300 return this._inner.Change(aSource, aProperty, aOldTarget, aNewTarget);
301 },
Move
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
302 Move: function (aOldSource, aNewSource, aProperty, aTarget) {
303 return this._inner.Assert(aOldSource, aNewSource, aProperty, aTarget);
304 },
HasAssertion
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
305 HasAssertion: function (aSource, aProperty, aTarget, aTruthValue) {
306 if (this._isRootTypeResource(aSource)) {
307 // Don't show entries in the list for types that we DO NOT handle
308 // automatically. i.e. this list is a means of editing and removing
309 // automatic overrides only.
310 if (aProperty.EqualsNode(this._handleAutoArc)) {
311 var handler = this.GetTarget(aSource, this._handlerPropArc, true);
312 if (handler) {
313 handler = handler.QueryInterface(Components.interfaces.nsIRDFResource);
314 return !(this.getLiteralValue(handler.Value, "alwaysAsk") == "true");
315 }
316 }
317 }
318 return this._inner.HasAssertion(aSource, aProperty, aTarget, aTruthValue);
319 },
ArcLabelsIn
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
320 ArcLabelsIn: function (aNode) {
321 return this._inner.ArcLabelsIn(aNode);
322 },
ArcLabelsOut
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
323 ArcLabelsOut: function (aNode) {
324 return this._inner.ArcLabelsOut(aNode);
325 },
GetAllResources
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
326 GetAllResources: function () {
327 return this._inner.GetAllResources();
328 },
hasArcIn
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
329 hasArcIn: function (aNode, aArc) {
330 return this._inner.hasArcIn(aNode, aArc);
331 },
hasArcOut
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
332 hasArcOut: function (aNode, aArc) {
333 return this._inner.hasArcOut(aNode, aArc);
334 },
335
336 _observers: [],
AddObserver
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
337 AddObserver: function (aObserver) {
338 this._observers.push(aObserver);
339 },
340
RemoveObserver
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
341 RemoveObserver: function (aObserver) {
342 for (var i = 0; i < this._observers.length; ++i) {
343 if (this._observers[i] == aObserver) {
344 this._observers.splice(i, 1);
345 break;
346 }
347 }
348 },
349
onAssert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
350 onAssert: function (aDataSource, aSource, aProperty, aTarget) {
351 for (var i = 0; i < this._observers.length; ++i) {
352 this._observers[i].onAssert(aDataSource, aSource, aProperty, aTarget);
353 }
354 },
355
onUnassert
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
356 onUnassert: function (aDataSource, aSource, aProperty, aTarget) {
357 for (var i = 0; i < this._observers.length; ++i) {
358 this._observers[i].onUnassert(aDataSource, aSource, aProperty, aTarget);
359 }
360 },
361
onChange
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
362 onChange: function (aDataSource, aSource, aProperty, aOldTarget, aNewTarget) {
363 for (var i = 0; i < this._observers.length; ++i) {
364 this._observers[i].onChange(aDataSource, aSource, aProperty, aOldTarget, aNewTarget);
365 }
366 },
367
onMove
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
368 onMove: function (aDataSource, aOldSource, aNewSource, aProperty, aTarget) {
369 for (var i = 0; i < this._observers.length; ++i) {
370 this._observers[i].onMove(aDataSource, aOldSource, aNewSource, aProperty, aTarget);
371 }
372 },
373
onBeginUpdateBatch
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
374 onBeginUpdateBatch: function (aDataSource) {
375 for (var i = 0; i < this._observers.length; ++i) {
376 this._observers[i].onBeginUpdateBatch(aDataSource);
377 }
378 },
379
onEndUpdateBatch
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
380 onEndUpdateBatch: function (aDataSource) {
381 for (var i = 0; i < this._observers.length; ++i) {
382 this._observers[i].onEndUpdateBatch(aDataSource);
383 }
384 },
385
beginUpdateBatch
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
386 beginUpdateBatch: function (aDataSource) {
387 for (var i = 0; i < this._observers.length; ++i) {
388 this._observers[i].beginUpdateBatch(aDataSource);
389 }
390 },
391
endUpdateBatch
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
392 endUpdateBatch: function (aDataSource) {
393 for (var i = 0; i < this._observers.length; ++i) {
394 this._observers[i].endUpdateBatch(aDataSource);
395 }
396 },
397
flush
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
398 flush: function () {
399 var rds = this._inner.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
400 if (rds)
401 rds.Flush();
402 },
403
destroy
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
404 destroy: function () {
405 this._inner.RemoveObserver(this);
406 }
407 };
408
409 /**
410 * Handler Override class
411 **/
HandlerOverride
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
412 function HandlerOverride(aURI, aDatasource)
413 {
414 this.URI = aURI;
415 this._DS = aDatasource;
416 }
417
418 HandlerOverride.prototype = {
419 // general information
get_mimeType
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
420 get mimeType()
421 {
422 return this.getLiteralForContentType(this.URI, "value");
423 },
424
set_mimeType
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
425 set mimeType(aMIMETypeString)
426 {
427 this.changeMIMEStuff(MIME_URI(aMIMETypeString), "value", aMIMETypeString.toLowerCase());
428 return aMIMETypeString;
429 },
430
get_description
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
431 get description()
432 {
433 return this.getLiteralForContentType(this.URI, "description");
434 },
435
set_description
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
436 set description(aDescriptionString)
437 {
438 this.changeMIMEStuff(MIME_URI(this.mimeType), "description", aDescriptionString);
439 return aDescriptionString;
440 },
441
get_isEditable
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
442 get isEditable()
443 {
444 return this.getLiteralForContentType(this.URI, "editable");
445 },
446
set_isEditable
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
447 set isEditable(aIsEditableString)
448 {
449 this.changeMIMEStuff(MIME_URI(this.mimeType), "editable", aIsEditableString);
450 return aIsEditableString;
451 },
452
get_extensions
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
453 get extensions()
454 {
455 var extensionResource = gRDF.GetUnicodeResource(NC_URI("fileExtensions"));
456 var contentTypeResource = gRDF.GetUnicodeResource(MIME_URI(this.mimeType));
457 var extensionTargets = this._DS.GetTargets(contentTypeResource, extensionResource, true);
458 var extString = "";
459 if (extensionTargets) {
460 while (extensionTargets.hasMoreElements()) {
461 var currentExtension = extensionTargets.getNext();
462 if (currentExtension) {
463 currentExtension = currentExtension.QueryInterface(Components.interfaces.nsIRDFLiteral);
464 if (extString != "") {
465 extString += " ";
466 }
467 extString += currentExtension.Value.toLowerCase();
468 }
469 }
470 }
471 return extString;
472 },
473
addExtension
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
474 addExtension: function (aExtensionString)
475 {
476 this.assertMIMEStuff(MIME_URI(this.mimeType), "fileExtensions", aExtensionString.toLowerCase());
477 },
478
removeExtension
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
479 removeExtension: function (aExtensionString)
480 {
481 this.unassertMIMEStuff(MIME_URI(this.mimeType), "fileExtensions", aExtensionString.toLowerCase());
482 },
483
clearExtensions
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
484 clearExtensions: function ()
485 {
486 var extArray = this.extensions.split(" ");
487 for (i = extArray.length - 1; i >= 0; --i) {
488 this.removeExtension(extArray[i]);
489 }
490 },
491
492 // content handling
get_saveToDisk
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
493 get saveToDisk()
494 {
495 return this.getHandlerInfoForType(this.URI, "saveToDisk");
496 },
497
set_saveToDisk
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
498 set saveToDisk(aSavedToDisk)
499 {
500 this.changeMIMEStuff(HANDLER_URI(this.mimeType), "saveToDisk", aSavedToDisk);
501 this.setHandlerProcedure("handleInternal", "false");
502 this.setHandlerProcedure("useSystemDefault", "false");
503 return aSavedToDisk;
504 },
505
get_useSystemDefault
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
506 get useSystemDefault()
507 {
508 return this.getHandlerInfoForType(this.URI, "useSystemDefault");
509 },
510
set_useSystemDefault
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
511 set useSystemDefault(aUseSystemDefault)
512 {
513 this.changeMIMEStuff(HANDLER_URI(this.mimeType), "useSystemDefault", aUseSystemDefault);
514 this.setHandlerProcedure("handleInternal", "false");
515 this.setHandlerProcedure("saveToDisk", "false");
516 return aUseSystemDefault;
517 },
518
get_handleInternal
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
519 get handleInternal()
520 {
521 return this.getHandlerInfoForType(this.URI, "handleInternal");
522 },
523
set_handleInternal
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
524 set handleInternal(aHandledInternally)
525 {
526 this.changeMIMEStuff(HANDLER_URI(this.mimeType), "handleInternal", aHandledInternally);
527 this.setHandlerProcedure("saveToDisk", "false");
528 this.setHandlerProcedure("useSystemDefault", "false");
529 return aHandledInternally;
530 },
531
setHandlerProcedure
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
532 setHandlerProcedure: function (aHandlerProcedure, aValue)
533 {
534 var handlerSource = gRDF.GetUnicodeResource(HANDLER_URI(this.mimeType));
535 var handlerProperty = gRDF.GetUnicodeResource(NC_URI(aHandlerProcedure));
536 var oppositeValue = aValue == "false" ? "true" : "false";
537 var trueLiteral = gRDF.GetLiteral(oppositeValue);
538 var hasCounterpart = this._DS.HasAssertion(handlerSource, handlerProperty, trueLiteral, true);
539 if (hasCounterpart) {
540 var falseLiteral = gRDF.GetLiteral(aValue);
541 this._DS.Change(handlerSource, handlerProperty, trueLiteral, falseLiteral);
542 }
543 },
544
get_alwaysAsk
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
545 get alwaysAsk()
546 {
547 return this.getHandlerInfoForType(this.URI, "alwaysAsk");
548 },
549
set_alwaysAsk
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
550 set alwaysAsk(aAlwaysAsk)
551 {
552 this.changeMIMEStuff(HANDLER_URI(this.mimeType), "alwaysAsk", aAlwaysAsk);
553 return aAlwaysAsk;
554 },
555
556 // helper application
get_appDisplayName
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
557 get appDisplayName()
558 {
559 return getHelperAppInfoForType(this.URI, "prettyName");
560 },
561
set_appDisplayName
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
562 set appDisplayName(aDisplayName)
563 {
564 this.changeMIMEStuff(APP_URI(this.mimeType), "prettyName", aDisplayName);
565 return aDisplayName;
566 },
567
get_appPath
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
568 get appPath()
569 {
570 return this.getHelperAppInfoForType(this.URI, "path");
571 },
572
set_appPath
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
573 set appPath(aAppPath)
574 {
575 this.changeMIMEStuff(APP_URI(this.mimeType), "path", aAppPath);
576 return aAppPath;
577 },
578
579 /**
580 * After setting the various properties on this override, we need to
581 * build the links between the mime type resource, the handler for that
582 * resource, and the helper app (if any) associated with the resource.
583 * We also need to add this mime type to the RDF seq (list) of types.
584 **/
buildLinks
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
585 buildLinks: function()
586 {
587 // assert the handler resource
588 var mimeSource = gRDF.GetUnicodeResource(MIME_URI(this.mimeType));
589 var handlerProperty = gRDF.GetUnicodeResource(NC_URI("handlerProp"));
590 var handlerResource = gRDF.GetUnicodeResource(HANDLER_URI(this.mimeType));
591 this._DS.Assert(mimeSource, handlerProperty, handlerResource, true);
592 // assert the helper app resource
593 var helperAppProperty = gRDF.GetUnicodeResource(NC_URI("externalApplication"));
594 var helperAppResource = gRDF.GetUnicodeResource(APP_URI(this.mimeType));
595 this._DS.Assert(handlerResource, helperAppProperty, helperAppResource, true);
596 // add the mime type to the MIME types seq
597 var container = this.ensureAndGetTypeList("mimetype");
598 var element = gRDF.GetUnicodeResource(MIME_URI(this.mimeType));
599 if (container.IndexOf(element) == -1)
600 container.AppendElement(element);
601 },
602
603 // Implementation helper methods
604
getLiteralForContentType
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
605 getLiteralForContentType: function (aURI, aProperty)
606 {
607 var contentTypeResource = gRDF.GetUnicodeResource(aURI);
608 var propertyResource = gRDF.GetUnicodeResource(NC_URI(aProperty));
609 return this.getLiteral(contentTypeResource, propertyResource);
610 },
611
getLiteral
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
612 getLiteral: function (aSource, aProperty)
613 {
614 var node = this._DS.GetTarget(aSource, aProperty, true);
615 if (node) {
616 node = node.QueryInterface(Components.interfaces.nsIRDFLiteral);
617 return node.Value;
618 }
619 return "";
620 },
621
getHandlerInfoForType
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
622 getHandlerInfoForType: function (aURI, aPropertyString)
623 {
624 // get current selected type
625 var handler = HANDLER_URI(this.getLiteralForContentType(aURI, "value"));
626 var source = gRDF.GetUnicodeResource(handler);
627 var property = gRDF.GetUnicodeResource(NC_URI(aPropertyString));
628 var target = this._DS.GetTarget(source, property, true);
629 if (target) {
630 target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
631 return target.Value;
632 }
633 return "";
634 },
635
getHelperAppInfoForType
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
636 getHelperAppInfoForType: function (aURI, aPropertyString)
637 {
638 var appURI = APP_URI(this.getLiteralForContentType(aURI, "value"));
639 var appRes = gRDF.GetUnicodeResource(appURI);
640 var appProperty = gRDF.GetUnicodeResource(NC_URI(aPropertyString));
641 return getLiteral(appRes, appProperty);
642 },
643
644 // write to the ds
assertMIMEStuff
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
645 assertMIMEStuff: function (aMIMEString, aPropertyString, aValueString)
646 {
647 var mimeSource = gRDF.GetUnicodeResource(aMIMEString);
648 var valueProperty = gRDF.GetUnicodeResource(NC_URI(aPropertyString));
649 var mimeLiteral = gRDF.GetLiteral(aValueString);
650 this._DS.Assert(mimeSource, valueProperty, mimeLiteral, true);
651 },
652
changeMIMEStuff
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
653 changeMIMEStuff: function(aMIMEString, aPropertyString, aValueString)
654 {
655 var mimeSource = gRDF.GetUnicodeResource(aMIMEString);
656 var valueProperty = gRDF.GetUnicodeResource(NC_URI(aPropertyString));
657 var mimeLiteral = gRDF.GetLiteral(aValueString);
658 var currentValue = this._DS.GetTarget(mimeSource, valueProperty, true);
659 if (currentValue) {
660 this._DS.Change(mimeSource, valueProperty, currentValue, mimeLiteral);
661 } else {
662 this._DS.Assert(mimeSource, valueProperty, mimeLiteral, true);
663 }
664 },
665
unassertMIMEStuff
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
666 unassertMIMEStuff: function(aMIMEString, aPropertyString, aValueString)
667 {
668 var mimeSource = gRDF.GetUnicodeResource(aMIMEString);
669 var valueProperty = gRDF.GetUnicodeResource(NC_URI(aPropertyString));
670 var mimeLiteral = gRDF.GetLiteral(aValueString);
671 this._DS.Unassert(mimeSource, valueProperty, mimeLiteral, true);
672 },
673
674 /**
675 * Get the list of types for the given class, creating the list if it doesn't
676 * already exist. The class can be either CLASS_MIMEINFO or CLASS_PROTOCOLINFO
677 * (i.e. the result of a call to _getClass).
678 *
679 * |urn:<class>s|
680 * |urn:<class>s:root|
681 *
682 * @param aClass {string} the class for which to retrieve a list of types
683 *
684 * @returns {nsIRDFContainer} the list of types
685 */
ensureAndGetTypeList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
686 ensureAndGetTypeList: function (aClass) {
687 var source = gRDF.GetResource("urn:" + aClass + "s");
688 var property =
689 gRDF.GetResource(aClass == CLASS_MIMEINFO ? NC_MIME_TYPES
690 : NC_PROTOCOL_SCHEMES);
691 var target = gRDF.GetResource("urn:" + aClass + "s:root");
692
693 // Make sure we have an arc from the source to the target.
694 if (!this._DS.HasAssertion(source, property, target, true))
695 this._DS.Assert(source, property, target, true);
696
697 // Make sure the target is a container.
698 var containerUtils = Cc["@mozilla.org/rdf/container-utils;1"]
699 .getService(Ci.nsIRDFContainerUtils);
700 if (!containerUtils.IsContainer(this._DS, target))
701 containerUtils.MakeSeq(this._DS, target);
702
703 // Get the type list as an RDF container.
704 var typeList =
705 Cc["@mozilla.org/rdf/container;1"].createInstance(Ci.nsIRDFContainer);
706 typeList.Init(this._DS, target);
707
708 return typeList;
709 }
710 };