Closed Bug 125324 Opened 23 years ago Closed 21 years ago

Improper use of nsIDirectoryServiceProvider

Categories

(SeaMonkey :: UI Design, defect)

All
Linux
defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: ccarlen, Assigned: timeless)

Details

Attachments

(1 file, 2 obsolete files)

http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/xpfe/components/filepicker/res/content/filepicker.js#133 This code is getting a file location directly from a provider instead of nsIDirectoryService. It happens to work because the object with the conract ID "@mozilla.org/file/directory_service;1" happens to implement nsIDirectoryServiceProvider as well as nsIDirectoryService and that provider happens to provide the "Home" location. The service should not be QI'able to a provider. It breaks the contract that when the service is asked for a file location, registered providers are consulted. BTW, somebody just asked me why their js code using directory service wasn't working. It was because they used this code as an example ;-) The code should do something like this: var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"] .getService( Components.interfaces.nsIProperties ); homeDir = dirSvc.get("Home", Components.interfaces.nsIFile);
Please don't assign bugs to my old email address.
Assignee: bryner → bryner
.
Assignee: bryner → akkana
Attached patch this should work (obsolete) — Splinter Review
Comment on attachment 108513 [details] [diff] [review] this should work i ran the changes through xpcshell on windows, but someone should test the xpfilepicker itself :)
Attachment #108513 - Flags: superreview?(bzbarsky)
Attachment #108513 - Flags: review?(akkana)
+ var dirServiceProvider = Components.classes[nsIDirectoryService_CONTRACTID] + .getService(nsIDirectoryService); You want nsIProperties here, not nsIDirectoryService. The latter has no "get." Also, I'd change the name of "dirServiceProvider" to "dirService." var persistent = new Object(); - homeDir = dirServiceProvider.getFile("Home", persistent); + homeDir = dirServiceProvider.get("Home", Components.interfaces.nsIFile, persistent);
Attached patch better (obsolete) — Splinter Review
per ccarlen
Attachment #108513 - Attachment is obsolete: true
Comment on attachment 108679 [details] [diff] [review] better homeDir is used elsewhere in this file; not initializing it is a bad idea.
Attachment #108679 - Flags: superreview-
Attachment #108513 - Flags: superreview?(bzbarsky)
Attachment #108513 - Flags: review?(akkana)
Attached patch okSplinter Review
Attachment #108679 - Attachment is obsolete: true
Attachment #129315 - Flags: superreview?(jaggernaut)
Attachment #129315 - Flags: review?(ccarlen)
Comment on attachment 129315 [details] [diff] [review] ok >Index: mozilla/xpfe/components/filepicker/res/content/filepicker.js >=================================================================== >+const nsIProperties = Components.interfaces.nsIProperties; >+const nsIDirectoryService_CONTRACTID = "@mozilla.org/file/directory_service;1"; This should really be |NS_DIRECTORYSERVICE_CONTRACTID|, or |nsDirectoryService_CONTRACTID| to keep in this file's style. I think the only accepted exceptions in our js code to "constants should be all uppercase" are the interface consts which are used as shortcuts for Components.interfaces.*.
Attachment #129315 - Flags: superreview?(jaggernaut) → superreview+
Comment on attachment 129315 [details] [diff] [review] ok thanks. r=ccarlen.
Attachment #129315 - Flags: review?(ccarlen) → review+
Assignee: akkzilla → timeless
mozilla/xpfe/components/filepicker/res/content/filepicker.js 1.86
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Verified FIXED
Status: RESOLVED → VERIFIED
Product: Core → Mozilla Application Suite
Component: XP Apps: GUI Features → UI Design
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: