Closed Bug 310071 Opened 19 years ago Closed 18 years ago

Use system calls to add files to the recent documents folder

Categories

(Toolkit :: Downloads API, enhancement)

1.8 Branch
x86
Windows XP
enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.8.1beta2

People

(Reporter: mconnor, Assigned: Gavin)

References

()

Details

(Keywords: fixed1.8.1)

Attachments

(1 file, 4 obsolete files)

We want to consider using the SHAddToRecentDocs call via the shell service to
add downloaded files to the recent documents folder on Windows.  There will be a
hidden boolean pref to disable this behaviour if desired.

This is a 2.0 enhancement, and is a matter of playing nice with the system. 
Users concerned with privacy already have this disabled/hidden on their systems,
since most Windows apps support this well.
*** Bug 309798 has been marked as a duplicate of this bug. ***
*** Bug 310072 has been marked as a duplicate of this bug. ***
Status: NEW → ASSIGNED
Flags: blocking-aviary2.0+
Priority: -- → P5
Target Milestone: --- → Firefox 2 alpha2
Assignee: mconnor → gavin.sharp
Status: ASSIGNED → NEW
Target Milestone: Firefox 2 alpha2 → Firefox 2 beta1
Status: NEW → ASSIGNED
Whiteboard: [swag: 1d]
Assignee: gavin.sharp → nobody
Status: ASSIGNED → NEW
Priority: P5 → --
Version: Trunk → 2.0 Branch
Attached patch patch (obsolete) — Splinter Review
This works. I don't know if the error handling should be better, and I've noticed that sometimes the downloadCompleted handler isn't called when files are downloaded quickly. Maybe this would be better called from nsDownloadManager, but I don't see a better place offhand.
Attached patch smaller patch (obsolete) — Splinter Review
Asaf pointed out that I can't depend on browser from toolkit, so I just put this in nsDownloadManager directly.
Assignee: nobody → gavin.sharp
Attachment #221884 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #221914 - Flags: superreview?(benjamin)
Attachment #221914 - Flags: review?(mconnor)
Comment on attachment 221914 [details] [diff] [review]
smaller patch

Hrm, actually, I see the document added to the "recent docs" list without this patch. Seems windows is doing this itself without our help...
Attachment #221914 - Attachment is obsolete: true
Attachment #221914 - Flags: superreview?(benjamin)
Attachment #221914 - Flags: review?(mconnor)
Ok, the reason I was seeing this work without the patch is because I had "Ask me where to save every file" turned on, which opened the system "Save As" dialog, which apparently has hooks to add any saved items to the most recent documents list.
Attached patch patch v2 (obsolete) — Splinter Review
Attachment #222539 - Flags: superreview?(benjamin)
Attachment #222539 - Flags: review?(mconnor)
Attachment #222539 - Attachment is obsolete: true
Attachment #222539 - Flags: superreview?(benjamin)
Attachment #222539 - Flags: review?(mconnor)
The last patch only worked because SHAddToRecentDocs takes a path in the platform native encoding (Windows-1252, as I understand it), so converting to UTF-8 isn't correct, and would not work for filenames that cannot be expressed using Windows-1252. There is no SHAddToRecentDocsW, so it looks like we need pass a PIDL that represents the path to the file to SHAddToRecentDocs instead of a path, and I'm not sure how to get one of those. I need help from someone who knows the windows shell APIs more than I do.
Keywords: helpwanted
Whiteboard: [swag: 1d] → [swag: ?d]
Attached patch slightly better patch (obsolete) — Splinter Review
There are still a lot of things wrong with this patch, but it works.
- Putting win32 API calls in nsDownloadManager doesn't feel right
- SHParseDisplayName only works in >= WinXP
- String usage is probably wrong
Attached patch better patchSplinter Review
This uses a different method that will work in anything greater than 95, and makes sure not to leak the pidl.
Attachment #224294 - Attachment is obsolete: true
Attachment #224365 - Flags: superreview?(benjamin)
Attachment #224365 - Flags: review?(mconnor)
Keywords: helpwanted
Whiteboard: [swag: ?d] → [patch-r?]
Comment on attachment 224365 [details] [diff] [review]
better patch

>Index: toolkit/components/downloads/src/nsDownloadManager.cpp

> #define PREF_BDM_FLASHCOUNT "browser.download.manager.flashCount"
>+#define PREF_BDM_ADDTORECENTDOCS "browser.download.manager.addtorecentdocs"

other prefs here use mixedCase, you should too.

>+    if (addToRecentDocs) {
>+      LPSHELLFOLDER lpShellFolder = NULL;
>+
>+      if (SUCCEEDED(::SHGetDesktopFolder(&lpShellFolder))) {
>+        PRUnichar *filePath = ToNewUnicode(path);
>+        LPITEMIDLIST lpItemIDList = NULL;
>+        if (SUCCEEDED(lpShellFolder->ParseDisplayName(NULL, NULL, filePath, NULL, &lpItemIDList, NULL))) {

Does this work even if the file is not saved to the desktop?
Attachment #224365 - Flags: superreview?(benjamin) → superreview+
(In reply to comment #11)
> other prefs here use mixedCase, you should too.

will do.

> Does this work even if the file is not saved to the desktop?

Yes, the Desktop folder is special in that its implementation of ParseDisplayName accepts absolute paths to any file on disk.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/ifaces/ishellfolder/parsedisplayname.asp 
pushing out non-critical-path bugs to b2
Target Milestone: Firefox 2 beta1 → Firefox 2 beta2
Attachment #224365 - Flags: review?(mconnor) → review+
Comment on attachment 224365 [details] [diff] [review]
better patch


>+      if (SUCCEEDED(::SHGetDesktopFolder(&lpShellFolder))) {
>+        PRUnichar *filePath = ToNewUnicode(path);
>+        LPITEMIDLIST lpItemIDList = NULL;
>+        if (SUCCEEDED(lpShellFolder->ParseDisplayName(NULL, NULL, filePath, NULL, &lpItemIDList, NULL))) {

Hrm, i'm pretty sure you need W2COLE here to be on the safe side.
Whiteboard: [patch-r?] → [checkin needed]
(In reply to comment #14)
> Hrm, i'm pretty sure you need W2COLE here to be on the safe side.

I discussed this with Asaf, and determined it wouldn't be necessary.

Checked in on the trunk.

mozilla/toolkit/components/build/Makefile.in 	1.37
mozilla/toolkit/components/downloads/src/nsDownloadManager.cpp 	1.67
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Whiteboard: [checkin needed]
Whiteboard: [need-a]
Comment on attachment 224365 [details] [diff] [review]
better patch

This has been on the trunk for nearly two weeks, with no known regressions.
Attachment #224365 - Flags: approval1.8.1?
Attachment #224365 - Flags: approval1.8.1? → approval1.8.1+
Whiteboard: [need-a] → [checkin needed (1.8 branch)]
mozilla/toolkit/components/downloads/src/nsDownloadManager.cpp 	1.53.2.10
mozilla/toolkit/components/build/Makefile.in 	1.24.2.10
Keywords: fixed1.8.1
Whiteboard: [checkin needed (1.8 branch)]
Had someone actually report this as a bug in our XULRunner app.  "browser.download.manager.addtorecentdocs" should be renamed as this applies to the toolkit not just "browser".
All the download manager prefs are prefixed with browser, so I'm not so sure I agree...
maybe we should take the opportunity pre3.0 to realign preferences from browser to toolkit for portability.
Product: Firefox → Toolkit
(In reply to comment #8)
> (...) There is no SHAddToRecentDocsW, so it looks like we need
> pass a PIDL that represents the path to the file to SHAddToRecentDocs instead
> of a path, and I'm not sure how to get one of those. I need help from someone
> who knows the windows shell APIs more than I do.

Gavin, sorry about the very belated comment but here goes: In this case Microsoft didn't implement ANSI/Unicode as two functions but instead they split the flag in two: if UNICODE is defined SHARD_PATH is set to SHARD_PATHW otherwise it's SHARD_PATHA. 

So, I believe lines 2209-2222 in nsDownloadManager.cpp could be replaced with

if (addToRecentDocs)
  ::SHAddToRecentDocs(SHARD_PATHW, path.get());
Aiko, could you file a new bug about that? Seems reasonable to me.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: