Closed Bug 1258797 Opened 8 years ago Closed 7 years ago

Save as dialog won't open on known sites after copying profile from linux to windows

Categories

(Firefox :: Downloads Panel, defect)

44 Branch
x86_64
Windows 10
defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 58
Tracking Status
firefox58 --- fixed

People

(Reporter: agnag1+bugzilla, Assigned: Kwan, Mentored)

References

Details

(Whiteboard: [lang=js][good next bug])

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0
Build ID: 20160308181531

Steps to reproduce:

Use Firefox on Linux, save content from various websites to different folders, so the prefered location is saved (and different from the default)

Copy the whole profile folder including profile.ini to the Windows PC.

* Set download preference to ask for target folder on every file
* Go to one of the previous known sites, download something
* The Download dialog appears (open with / save file)
* Save file, click OK.


How I FIXED it: clear recent History
Time range: Everything
Details: Check (only) Site preferences

The culprit most likely is the different Path naming scheme between Windows and Linux

C:/Users/Name/ vs.
/home/name/


Actual results:

* The pre-download Dialog closes as expected, but the "save as" Dialog does not open, nor does the file download. 


Expected results:

Save file Dialog opening with default download location
OS: Unspecified → Windows 10
Hardware: Unspecified → x86_64
Component: Untriaged → Preferences
Paolo, where is this information saved? ISTR looking at a bug like this before, but I don't recall off-hand how I'd find it back again.

(Either way, it's per-site, so this isn't a preferences bug -> back to untriaged)
Component: Preferences → Untriaged
Flags: needinfo?(paolo.mozmail)
It's saved in ContentPrefs, might be simple to fix.
Flags: needinfo?(paolo.mozmail)
ni -> me to figure out at least half of this and make it a mentored bug.
Component: Untriaged → Downloads Panel
Flags: needinfo?(gijskruitbosch+bugs)
Yeah, I can reproduce this on Windows, at least. The following errors show up in the browser console:

NS_ERROR_FILE_UNRECOGNIZED_PATH: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath] DownloadLastDir.jsm:167:0
[Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath]"  nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)"  location: "JS frame :: resource://gre/modules/DownloadLastDir.jsm :: DownloadLastDir.prototype.getFileAsync/<.handleCompletion :: line 167"  data: no] ContentPrefUtils.jsm:50:0


The basic fix here should be to make DownloadLastDir catch exceptions like this and return the default instead.

In order to reproduce if you don't have a profile to copy, follow these steps:

0. clean profile, set downloads to always ask for a directory

1. go to http://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/

2. open the browser (not web) console:

3. Run:

cps2 = Services.contentPrefs.QueryInterface(Ci.nsIContentPrefService2);

cps2.set("archive.mozilla.org", "browser.download.lastDir", "/this/is/bogus", {usePrivateBrowsing: false})

4. Run:

cps2.getByDomainAndName("archive.mozilla.org", "browser.download.lastDir", {usePrivateBrowsing: false}, {handleCompletion() { console.log('done')}, handleResult(cp) { console.log(cp) }})

and verify that the value of the content pref matches the 'this/is/bogus' thing you just assigned.

5. Try to download one of the files that prompt a download, e.g. http://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-48.0a1.en-US.linux-i686.checksums .

6. click 'save' if prompted to open/save

7. You should see a 'save file as' dialog. Instead you see nothing and you get the errors above in the browser console.

Fixing this would involve wrapping both:

https://dxr.mozilla.org/mozilla-central/rev/55d557f4d73ee58664bdf2fa85aaab555224722e/toolkit/mozapps/downloads/DownloadLastDir.jsm#124

and this:

https://dxr.mozilla.org/mozilla-central/rev/55d557f4d73ee58664bdf2fa85aaab555224722e/toolkit/mozapps/downloads/DownloadLastDir.jsm#163-167

in try...catch blocks, and ensuring that "lastDirFile" (in the first case) and "file" in the seocnd case end up being null.
Mentor: gijskruitbosch+bugs
Flags: needinfo?(gijskruitbosch+bugs)
Whiteboard: [lang=js]
Status: UNCONFIRMED → NEW
Ever confirmed: true
Whiteboard: [lang=js] → [lang=js][good next bug]
I confirm this is happening after migrating Windows -> Linux.  Only happens with saving https pages.

NS_ERROR_FILE_UNRECOGNIZED_PATH: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath]DownloadLastDir.jsm:167
[Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath]"  nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)"  location: "JS frame :: resource://gre/modules/DownloadLastDir.jsm :: DownloadLastDir.prototype.getFileAsync/<.handleCompletion :: line 167"  data: no]
DownloadLastDir.prototype.getFileAsync/<.handleCompletion()
DownloadLastDir.jsm:167
safeCallback()
ContentPrefUtils.jsm:47
cbHandleCompletion()
ContentPrefUtils.jsm:36
onDone()
ContentPrefService2.jsm:154
handleCompletion()
ContentPrefService2.jsm:750
(unknown)
(In reply to :Gijs from comment #4)
> cps2 = Services.contentPrefs.QueryInterface(Ci.nsIContentPrefService2);

Just as a note this results in "TypeError: Services.contentPrefs is undefined" on nightly now for some reason.  Still works on 55, but .get... fails with [Exception... "Failure arg 2 [nsIContentPrefService2.getByDomainAndName]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line 1"  data: no]
Fortunately ubuntu comes with a nice SQLite DB browser that lets one edit to reproduce.

> https://dxr.mozilla.org/mozilla-central/rev/
> 55d557f4d73ee58664bdf2fa85aaab555224722e/toolkit/mozapps/downloads/
> DownloadLastDir.jsm#124

Fortunately obsolete now.
 
> https://dxr.mozilla.org/mozilla-central/rev/
> 55d557f4d73ee58664bdf2fa85aaab555224722e/toolkit/mozapps/downloads/
> DownloadLastDir.jsm#163-167

Done.

> ensuring that [...] "file" [...] end up being null.

I went for putting it back to plainPrefFile, so that there was no behaviour difference between having no pref, and finding an invalid one.  Let me know if you'd prefer null though.
Assignee: nobody → moz-ian
Status: NEW → ASSIGNED
(In reply to Ian Moody [:Kwan] from comment #7)
> (In reply to :Gijs from comment #4)
> > cps2 = Services.contentPrefs.QueryInterface(Ci.nsIContentPrefService2);
> 
> Just as a note this results in "TypeError: Services.contentPrefs is
> undefined" on nightly now for some reason.

It's because the Services.contentPrefs alias got rm'd, apparently.

>  Still works on 55, but .get...
> fails with [Exception... "Failure arg 2
> [nsIContentPrefService2.getByDomainAndName]"  nsresult: "0x80004005
> (NS_ERROR_FAILURE)"  location: "JS frame :: debugger eval code ::
> <TOP_LEVEL> :: line 1"  data: no]
> Fortunately ubuntu comes with a nice SQLite DB browser that lets one edit to
> reproduce.

contentPrefs = Components.classes["@mozilla.org/content-pref/service;1"]
                         .getService(Components.interfaces.nsIContentPrefService2);

contentPrefs.getByDomainAndName("archive.mozilla.org", "browser.download.lastDir", null, {handleCompletion: f => console.log('completion', f), handleResult: f => console.log('value', f.value) });

produces something sane.

Anyway, tested with this and it seems to work. :-)
Comment on attachment 8913971 [details]
Bug 1258797 - Catch error when trying to open save as dialog to invalid path.

https://reviewboard.mozilla.org/r/185342/#review190300
Attachment #8913971 - Flags: review?(gijskruitbosch+bugs) → review+
Pushed by gijskruitbosch@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/e900a3d074b8
Catch error when trying to open save as dialog to invalid path. r=Gijs
Backed out for failing eslint at toolkit/mozapps/downloads/DownloadLastDir.jsm:150:

https://hg.mozilla.org/integration/autoland/rev/562b8f9ed39c21bbb30e75fdff6376ff18b3fd9e

Push with failure: https://treeherder.mozilla.org/#/jobs?repo=autoland&revision=e900a3d074b81b7617e6a65bcd18a02450652990&filter-resultStatus=testfailed&filter-resultStatus=busted&filter-resultStatus=exception&filter-resultStatus=usercancel&filter-resultStatus=runnable
Failure log: https://treeherder.mozilla.org/logviewer.html#?job_id=134215744&repo=autoland
> TEST-UNEXPECTED-ERROR | /builds/worker/checkouts/gecko/toolkit/mozapps/downloads/DownloadLastDir.jsm:150:11 | Closing curly brace does not appear on the same line as the subsequent block. (brace-style)
Flags: needinfo?(moz-ian)
Whoops, sorry, forgot about eslint, and after I went to all the trouble of setting it up way back when.

Anyway, fixed:
>$ mach eslint toolkit/mozapps/downloads/DownloadLastDir.jsm
>✖ 0 problems (0 errors, 0 warnings)
Flags: needinfo?(moz-ian)
Keywords: checkin-needed
Pushed by gijskruitbosch@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/972c3948109e
Catch error when trying to open save as dialog to invalid path. r=Gijs
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/972c3948109e
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 58
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: