summaryrefslogtreecommitdiff
path: root/qutebrowser/browser/downloads.py
diff options
context:
space:
mode:
Diffstat (limited to 'qutebrowser/browser/downloads.py')
-rw-r--r--qutebrowser/browser/downloads.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py
index fa4ac9da2..4f7897c9d 100644
--- a/qutebrowser/browser/downloads.py
+++ b/qutebrowser/browser/downloads.py
@@ -611,7 +611,11 @@ class AbstractDownloadItem(QObject):
message.error(str(e))
def url(self) -> QUrl:
- """Get the download's origin URL."""
+ """Get the download's URL (i.e. where the file is downloaded from)."""
+ raise NotImplementedError
+
+ def origin(self) -> QUrl:
+ """Get the download's origin URL (i.e. the page starting the download)."""
raise NotImplementedError
def _get_open_filename(self):
@@ -819,6 +823,34 @@ class AbstractDownloadItem(QObject):
self.pdfjs_requested.emit(os.path.basename(filename),
self.url())
+ def cancel_for_origin(self) -> bool:
+ """Cancel the download based on URL/origin.
+
+ For some special cases, we want to cancel downloads immediately, before
+ downloading:
+
+ - file:// downloads from file:// URLs (open the file instead)
+ - http:// downloads from https:// URLs (mixed content)
+ """
+ origin = self.origin()
+ url = self.url()
+ if not origin.isValid():
+ return False
+
+ if url.scheme() == "file" and origin.scheme() == "file":
+ utils.open_file(url.toLocalFile())
+ self.cancel()
+ return True
+
+ if (url.scheme() == "http" and
+ origin.isValid() and origin.scheme() == "https" and
+ config.instance.get("downloads.prevent_mixed_content", url=origin)):
+ self._die("Aborting insecure download from secure page "
+ "(see downloads.prevent_mixed_content).")
+ return True
+
+ return False
+
def set_target(self, target):
"""Set the target for a given download.