Closed Bug 1182095 Opened 9 years ago Closed 2 years ago

Test downloads through Download Manager

Categories

(Core :: DOM: Service Workers, defect, P5)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1187300
Tracking Status
firefox42 --- affected

People

(Reporter: noemi, Assigned: jaoo)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

      No description provided.
Target Milestone: --- → FxOS-S3 (24Jul)
I've been poking around and this is what I saw. No call at https://mxr.mozilla.org/mozilla-central/source/toolkit/components/downloads/nsDownloadManager.cpp#3558 when starting a download. At https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm#Conversion_from_nsIDownloadManager you can see ""Starting in Firefox for Desktop version 26, the nsIDownloadManager and nsIDownload interfaces are not available anymore"" so the sensitive calls might be at:

https://mxr.mozilla.org/mozilla-central/source/toolkit/components/jsdownloads/src/DownloadCore.jsm#1910
https://mxr.mozilla.org/mozilla-central/source/toolkit/components/jsdownloads/src/DownloadCore.jsm#1954

Anyway I gave it a try manually (downloading an image from a page controlled by a service worker) and it seems there is no service worker interception when downloading anything. Ehsan, does it make sense? Thanks!
Flags: needinfo?(ehsan)
(In reply to José Antonio Olivera Ortega [:jaoo] from comment #1)
> I've been poking around and this is what I saw. No call at
> https://mxr.mozilla.org/mozilla-central/source/toolkit/components/downloads/
> nsDownloadManager.cpp#3558 when starting a download.

That code is in nsDownload::Resume.  I guess that means it runs when you resume a download.

> At
> https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/
> Downloads.jsm#Conversion_from_nsIDownloadManager you can see ""Starting in
> Firefox for Desktop version 26, the nsIDownloadManager and nsIDownload
> interfaces are not available anymore"" so the sensitive calls might be at:
> 
> https://mxr.mozilla.org/mozilla-central/source/toolkit/components/
> jsdownloads/src/DownloadCore.jsm#1910
> https://mxr.mozilla.org/mozilla-central/source/toolkit/components/
> jsdownloads/src/DownloadCore.jsm#1954

I don't know what we use for the download manager.  You want to talk to either mak or paolo.

> Anyway I gave it a try manually (downloading an image from a page controlled
> by a service worker) and it seems there is no service worker interception
> when downloading anything. Ehsan, does it make sense? Thanks!

That sounds like a bug which we should fix.
Flags: needinfo?(paolo.mozmail)
Flags: needinfo?(mak77)
Flags: needinfo?(ehsan)
I'm leaving this to paolo that has far more knowledge about it, btw, the old cpp download manager code must be considered deprecated.
Off-hand looks like you're looking at the right place in jsdownloads...

Could you please just give more details about what's your goal and how you are moving to reach it? Cause it's not totally clear from comment 1, at least for me.
Flags: needinfo?(mak77)
(In reply to Marco Bonardo [::mak] from comment #3)
> Could you please just give more details about what's your goal and how you
> are moving to reach it? Cause it's not totally clear from comment 1, at
> least for me.

Indeed, some context would be useful :-)
For downloads on Firefox OS we use Downloads.jsm, feel free to flag me again if you have any question.
Flags: needinfo?(paolo.mozmail)
José, the JS code you found is the right place to be investigating this.

Paolo, we're systematically investigating places in the browser that create channels and looking for requests that should be able to be intercepted by a ServiceWorker but aren't. What this means is that for some a.com, if the user requests a.com/file.zip and a.com has a registered ServiceWorker that can intercept the request, the worker is allowed to synthesize a response directly without the request ever reaching the network. This is implemented in the network code by checking each HTTP channel's notificationCallbacks and loadgroup's notificationCallbacks for the nsINetworkInterceptionController interface - if the callbacks/loadgroup are associated with the originating document, everything works as expected. The code at https://mxr.mozilla.org/mozilla-central/source/toolkit/components/jsdownloads/src/DownloadCore.jsm#1910 creates a channel that doesn't chain to any docshell or document and therefore this interception never occurs.

When is this code called? Is there always a document we can trace the download request to? What happens when we want to restart a download which was originally intercepted, but the user has closed the relevant tab? Can we do something like the special-casing for the ping listener in the docshell code: http://mxr.mozilla.org/mozilla-central/source/docshell/base/nsDocShell.cpp#724 ?
Flags: needinfo?(paolo.mozmail)
I'm not able to provide a detailed answer right now, but one of the conceptual differences between downloads and generic loads is exactly that the former can be set aside and executed later. They're the first step for a file to "exit" from the browser environment and reach the operating system level. In general, we can apply any logic we want when starting the download, but it may be more difficult later. Some downloads may be unable to be restarted without the original document or Service Worker code loaded.
The other thing to note about ServiceWorkers is that their lifetime is not tied to a particular document, so they have much more in common with SharedWorkers. Additionally, we have the ability to start a service worker at will if it isn't running, so maybe we could spin it up on download resumption.
Hmm, if the originating document is unavailable when we restart/resume a download, then fixing this would be difficult, since nsINetworkInterceptController::SetInterceptController can only work if we have access to the docshell...  Perhaps we should mark such as downloads as non-resumable, even though that seems sub-optimal?
Target Milestone: FxOS-S3 (24Jul) → FxOS-S4 (07Aug)
Depends on: 1187300
Thank you guys for your comments about this bug. Big stuff here. I filed a new bug for the fix we need first, the channels created by Downloads.jsm should be intercepted. That's bug 1187300. Once that bug is fixed I'll continue working this one.
Clearing target milestone until we have a fix for bug 1187300.
Target Milestone: FxOS-S4 (07Aug) → ---
(In reply to Ehsan Akhgari (not reviewing patches, not reading bugmail, needinfo? me!) from comment #9)
> Hmm, if the originating document is unavailable when we restart/resume a
> download, then fixing this would be difficult, since
> nsINetworkInterceptController::SetInterceptController can only work if we
> have access to the docshell...  Perhaps we should mark such as downloads as
> non-resumable, even though that seems sub-optimal?

It seems to me that marking these downloads as non-resumable, and disallowing restart when we lose some context we need, would be the way to go. One existing example are attempts to save a complete page to disk, which we incorrectly restart as HTML-only downloads. If interrupted, we should restart them as complete downloads, but disallow that as soon as the document is not available anymore.
Flags: needinfo?(paolo.mozmail)
Let's aim to fix this post-v1
Blocks: ServiceWorkers-postv1
No longer blocks: ServiceWorkers-v1
Priority: -- → P5

Let's track any remaining work here in bug 1187300.

Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.