Repository: qutebrowser/qutebrowser
Pull request: Local files will no longer be downloaded but instead opened with a command like xdg-open for Linux, open for Mac, and start for Windows
<!-- Thanks for submitting a pull request! Please pick a descriptive title (not just "issue 12345"). If there is an open issue associated to your PR, please add a line like "Closes #12345" somewhere in the PR description (outside of this comment) -->
Closes #6549

Problem statement:
FR: don't download local files, open them with their default program.
After clicking on a file that cannot be opened by qutebrowser on a local directory page (`file://` URLs), `qutebrowser` should not start a download for that local file, but instead try to open it with the default handler.

IRC conversation:
```
17:29 <emanuele6> if i'm viewing a local directory in qutebrowser
17:29 <emanuele6> and i click on a file that qutebrowser can't open, qutebrowser tries to download it
17:29 <emanuele6> e.g. mkv files
17:29 <emanuele6> is there a way to tell qutebrowser to open it in mpv?
17:32 <The-Compiler> emanuele6: nope, that behavior is coming from the underlying Chromium
17:33 <The-Compiler> emanuele6: might make sense for qutebrowser to not accept the download and open the file:/// URL with the default handler though - mind opening an issue?
```

Hints from issue discussion:
Note that we should double-check that the download request is really coming from a `file:` URL before doing this.

Commit message: Added back question code which was accidentally removed

Patch to review:
diff --git a/qutebrowser/browser/webengine/webenginedownloads.py b/qutebrowser/browser/webengine/webenginedownloads.py
index 0ec9d551c3f..942e5332a9b 100644
--- a/qutebrowser/browser/webengine/webenginedownloads.py
+++ b/qutebrowser/browser/webengine/webenginedownloads.py
@@ -293,12 +293,15 @@ def handle_download(self, qt_item):
             return
 
         # Ask the user for a filename - needs to be blocking!
-        question = downloads.get_filename_question(
-            suggested_filename=suggested_filename, url=qt_item.url(),
-            parent=self)
-        self._init_filename_question(question, download)
-
-        message.global_bridge.ask(question, blocking=True)
+        if url.toDisplayString()[:7] == "file://":
+            utils.open_file(url.toDisplayString()[7:])
+            qt_item.cancel() 
+        else:
+            question = downloads.get_filename_question(
+                suggested_filename=suggested_filename, url=qt_item.url(),
+                parent=self)
+            self._init_filename_question(question, download)
+            message.global_bridge.ask(question, blocking=True)
         # The filename is set via the question.answered signal, connected in
         # _init_filename_question.
 


Code review comments:
diff_hunk: @@ -293,12 +293,15 @@ def handle_download(self, qt_item):
             return
 
         # Ask the user for a filename - needs to be blocking!
-        question = downloads.get_filename_question(
-            suggested_filename=suggested_filename, url=qt_item.url(),
-            parent=self)
-        self._init_filename_question(question, download)
-
-        message.global_bridge.ask(question, blocking=True)
+        if url.toDisplayString()[:7] == "file://":
+            utils.open_file(url.toDisplayString()[7:])
path: qutebrowser/browser/webengine/webenginedownloads.py
text: @user1:
```suggestion
            utils.open_file(url.toLocalFile())
```

diff_hunk: @@ -293,12 +293,15 @@ def handle_download(self, qt_item):
             return
 
         # Ask the user for a filename - needs to be blocking!
-        question = downloads.get_filename_question(
-            suggested_filename=suggested_filename, url=qt_item.url(),
-            parent=self)
-        self._init_filename_question(question, download)
-
-        message.global_bridge.ask(question, blocking=True)
+        if url.toDisplayString()[:7] == "file://":
path: qutebrowser/browser/webengine/webenginedownloads.py
text: @user1:
```suggestion
        if url.scheme() == "file":
```

diff_hunk: @@ -293,12 +293,15 @@ def handle_download(self, qt_item):
             return
 
         # Ask the user for a filename - needs to be blocking!
-        question = downloads.get_filename_question(
-            suggested_filename=suggested_filename, url=qt_item.url(),
-            parent=self)
-        self._init_filename_question(question, download)
-
-        message.global_bridge.ask(question, blocking=True)
+        if url.toDisplayString()[:7] == "file://":
+            utils.open_file(url.toDisplayString()[7:])
+            qt_item.cancel() 
path: qutebrowser/browser/webengine/webenginedownloads.py
text: @user1:
If you do

```suggestion
            qt_item.cancel() 
            return
```

here you can [Eschew the Extraneous Else](https://youtu.be/JVVMMULwR4s?t=289) below :wink:

(And it'll also make the structure a bit more consistent with the existing checks above for `self._mhtml_target`, `use_pdfjs` and `downloads.immediate_download_path()`.)