Web Browser eric7

Sat, 24 Sep 2022 13:38:40 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 24 Sep 2022 13:38:40 +0200
branch
eric7
changeset 9350
8d2b507f8588
parent 9349
df34d520c63b
child 9351
b5f360405f12

Web Browser
- added support for QWebEnginePage.fileSystemAccessRequested signal of Qt 6.4.

src/eric7/Preferences/ConfigurationPages/WebBrowserPage.py file | annotate | diff | comparison | revisions
src/eric7/Preferences/__init__.py file | annotate | diff | comparison | revisions
src/eric7/WebBrowser/WebBrowserView.py file | annotate | diff | comparison | revisions
--- a/src/eric7/Preferences/ConfigurationPages/WebBrowserPage.py	Fri Sep 23 13:43:06 2022 +0200
+++ b/src/eric7/Preferences/ConfigurationPages/WebBrowserPage.py	Sat Sep 24 13:38:40 2022 +0200
@@ -16,6 +16,7 @@
 import Preferences
 
 
+# TODO: add a combo box selection for 'AcceptFileSystemAccessRequest'
 class WebBrowserPage(ConfigurationPageBase, Ui_WebBrowserPage):
     """
     Class implementing the  Web Browser configuration page.
--- a/src/eric7/Preferences/__init__.py	Fri Sep 23 13:43:06 2022 +0200
+++ b/src/eric7/Preferences/__init__.py	Sat Sep 24 13:38:40 2022 +0200
@@ -938,6 +938,7 @@
         "UserAgent": "",
         "AcceptQuotaRequest": 2,  # yes/no/ask (0, 1, 2)
         "AcceptProtocolHandlerRequest": 2,  # yes/no/ask (0, 1, 2)
+        "AcceptFileSystemAccessRequest": 2,  # yes/no/ask (0, 1, 2)
         # Auto Scroller
         "AutoScrollEnabled": True,
         "AutoScrollDivider": 8.0,
@@ -2876,7 +2877,7 @@
             Prefs.settings.value("WebBrowser/" + key, Prefs.webBrowserDefaults[key]),
             encode=False,
         )
-    elif key in [
+    elif key in (
         "StartupBehavior",
         "HistoryLimit",
         "DownloadManagerRemovePolicy",
@@ -2900,7 +2901,8 @@
         "RefererTrimmingPolicy",
         "AcceptQuotaRequest",
         "AcceptProtocolHandlerRequest",
-    ]:
+        "AcceptFileSystemAccessRequest",
+    ):
         return int(
             Prefs.settings.value("WebBrowser/" + key, Prefs.webBrowserDefaults[key])
         )
--- a/src/eric7/WebBrowser/WebBrowserView.py	Fri Sep 23 13:43:06 2022 +0200
+++ b/src/eric7/WebBrowser/WebBrowserView.py	Sat Sep 24 13:38:40 2022 +0200
@@ -185,6 +185,11 @@
         self.__page.safeBrowsingBad.connect(self.safeBrowsingBad)
         self.__page.printPageRequested.connect(self.__printPage)
         self.__page.quotaRequested.connect(self.__quotaRequested)
+        with contextlib.suppress(AttributeError):
+            # Qt 6.4+
+            self.__page.fileSystemAccessRequested.connect(
+                self.__fileSystemAccessRequested
+            )
         # The registerProtocolHandlerRequested signal is handled in
         # WebBrowserPage.
         self.__page.selectClientCertificate.connect(self.__selectClientCertificate)
@@ -2372,3 +2377,63 @@
                 clientCertificateSelection.selectNone()
             else:
                 clientCertificateSelection.select(certificate)
+
+    ###########################################################################
+    ## Methods below implement slots for Qt 6.4+
+    ###########################################################################
+
+    @pyqtSlot("QWebEngineFileSystemAccessRequest")
+    def __fileSystemAccessRequested(self, accessRequest):
+        """
+        Private slot to handle file system access requests of the web page.
+
+        @param accessRequest reference to the file system access request object
+        @type QWebEngineFileSystemAccessRequest
+        """
+        from PyQt6.QtWebEngineCore import QWebEngineFileSystemAccessRequest
+
+        acceptRequest = Preferences.getWebBrowser("AcceptFileSystemAccessRequest")
+        # map yes/no/ask from (0, 1, 2)
+        if acceptRequest == 0:
+            # always yes
+            ok = True
+        elif acceptRequest == 1:
+            # always no
+            ok = False
+        else:
+            # ask user
+            if (
+                accessRequest.accessFlags()
+                == QWebEngineFileSystemAccessRequest.AccessFlag.Read
+            ):
+                msgTemplate = self.tr(
+                    "<p>Grant the web site at <b>{0}</b> <b>Read</b> access"
+                    " to '{0}'?</p>"
+                )
+            elif (
+                accessRequest.accessFlags()
+                == QWebEngineFileSystemAccessRequest.AccessFlag.Write
+            ):
+                msgTemplate = self.tr(
+                    "<p>Grant the web site at <b>{0}</b> <b>Write</b> access"
+                    " to '{0}'?</p>"
+                )
+            else:
+                msgTemplate = self.tr(
+                    "<p>Grant the web site at <b>{0}</b> <b>Read and Write</b> access"
+                    " to '{0}'?</p>"
+                )
+
+            ok = EricMessageBox.yesNo(
+                self,
+                self.tr("File System Access Request"),
+                msgTemplate.format(
+                    accessRequest.origin().host(),
+                    accessRequest.filePath().toLocalFile(),
+                ),
+            )
+
+        if ok:
+            accessRequest.accept()
+        else:
+            accessRequest.reject()

eric ide

mercurial