Closed Bug 923926 Opened 6 years ago Closed 6 years ago

Allow content authors to cancel a directory scan initiated when the user picks a directory

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla27

People

(Reporter: jwatt, Assigned: jwatt)

References

Details

Attachments

(1 file, 1 obsolete file)

We should allow script to cancel a directory scan initiated when the user picks a directory. Rather than adding special API to HTMLInputElement for this specific use case of a specific input type, I think we should support this by cancelling the scan if preventDefault() is called on any of the scan progress events.
Attached patch patch (obsolete) — Splinter Review
Attachment #813957 - Flags: review?(bugs)
Blocks: 846931
Comment on attachment 813957 [details] [diff] [review]
patch

Forgot I filed bug 912492 for this. I'll move the patch there.
Attachment #813957 - Flags: review?(bugs)
Assignee: jwatt → nobody
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 912492
Closed the wrong bug.
Status: RESOLVED → REOPENED
Resolution: DUPLICATE → ---
Attachment #813957 - Flags: review?(bugs)
Assignee: nobody → jwatt
Attached patch patchSplinter Review
Attachment #813957 - Attachment is obsolete: true
Attachment #813957 - Flags: review?(bugs)
Attachment #814112 - Flags: review?(bugs)
Attachment #814112 - Attachment is patch: true
Attachment #814112 - Flags: review?(bugs) → review+
The code flow for authors with this API is a bit weird. Basically you end up with code looking something like:


var cancelPendingScan = false;
$("cancelScanButton").onclick = function() {
  cancelPendingScan = true;
}
$("fileInput").onprogress = function(e) {
  if (cancelPendingScan) {
    e.preventDefault();
    cancelPendingScan = false;
  }
}

It seems much better if you can cancel the scan directly. Both from a code-flow point of view, and from a resource-use point of view.


I think a better solution is to provide some sort of object representing the directory scan whenever we start a scan. We could fire progress notifications as well as expose an abort() function on this object. The object would be exposed through a "directorypicked" event or some such.

In fact, the object could likely simply be a AbortableProgressPromise.
Not sure about using Promise for anything this, but indeed, a method to cancel the scan
could be handy.
https://hg.mozilla.org/integration/mozilla-inbound/rev/435b379ab3b8

For now I've pushed this to allow experimenters to play with cancelling while my focus is on <input type=number>, and I've opened bug 926303 regarding comment 6 and marked that blocking bug 846931 to make sure we address your issues before openDirectoryPicker() is pref'ed on, Jonas.
https://hg.mozilla.org/mozilla-central/rev/435b379ab3b8
Status: REOPENED → RESOLVED
Closed: 6 years ago6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla27
You need to log in before you can comment on or make changes to this bug.