eric6/WebBrowser/UrlBar/UrlBar.py

changeset 7766
0af772bc14c4
parent 7759
51aa6c6b66f7
child 7781
607a6098cb44
--- a/eric6/WebBrowser/UrlBar/UrlBar.py	Wed Oct 07 17:58:51 2020 +0200
+++ b/eric6/WebBrowser/UrlBar/UrlBar.py	Wed Oct 07 19:14:36 2020 +0200
@@ -12,6 +12,10 @@
 from PyQt5.QtGui import QColor, QPalette, QLinearGradient, QIcon
 from PyQt5.QtWidgets import QDialog, QApplication
 from PyQt5.QtWebEngineWidgets import QWebEnginePage
+try:
+    from PyQt5.QtNetwork import QSslCertificate     # __IGNORE_EXCEPTION__
+except ImportError:
+    QSslCertificate = None      # __IGNORE_WARNING__
 
 from E5Gui.E5LineEdit import E5LineEdit
 from E5Gui.E5LineEditButton import E5LineEditButton
@@ -21,9 +25,11 @@
 from WebBrowser.SafeBrowsing.SafeBrowsingLabel import SafeBrowsingLabel
 
 from .FavIconLabel import FavIconLabel
+from .SslLabel import SslLabel
 
 import UI.PixmapCache
 import Preferences
+import Utilities
 
 
 class UrlBar(E5LineEdit):
@@ -56,6 +62,10 @@
         self.__favicon = FavIconLabel(self)
         self.addWidget(self.__favicon, E5LineEdit.LeftSide)
         
+        self.__sslLabel = SslLabel(self)
+        self.addWidget(self.__sslLabel, E5LineEdit.LeftSide)
+        self.__sslLabel.setVisible(False)
+        
         self.__rssButton = E5LineEditButton(self)
         self.__rssButton.setIcon(UI.PixmapCache.getIcon("rss16"))
         self.addWidget(self.__rssButton, E5LineEdit.RightSide)
@@ -101,6 +111,10 @@
         
         self.__browser.safeBrowsingBad.connect(
             self.__safeBrowsingLabel.setThreatInfo)
+        
+        self.__sslLabel.clicked.connect(self.__browser.page().showSslInfo)
+        self.__browser.page().sslConfigurationChanged.connect(
+            self.__sslConfigurationChanged)
     
     def browser(self):
         """
@@ -131,6 +145,7 @@
         """
         self.__bookmarkButton.setVisible(False)
         self.__rssButton.setVisible(False)
+        self.__sslLabel.setVisible(False)
     
     def __checkBookmark(self):
         """
@@ -417,3 +432,36 @@
             )
             widget = SafeBrowsingInfoWidget(threatInfo, self.__browser)
             widget.showAt(pos)
+    
+    @pyqtSlot()
+    def __sslConfigurationChanged(self):
+        """
+        Private slot to handle a change of the associated web page SSL
+        configuration.
+        """
+        sslConfiguration = self.__browser.page().getSslConfiguration()
+        if sslConfiguration is not None and QSslCertificate is not None:
+            sslCertificate = self.__browser.page().getSslCertificate()
+            if sslCertificate is not None:
+                org = Utilities.decodeString(", ".join(
+                    sslCertificate.subjectInfo(QSslCertificate.Organization)))
+                if org == "":
+                    cn = Utilities.decodeString(", ".join(
+                        sslCertificate.subjectInfo(
+                            QSslCertificate.CommonName)))
+                    if cn != "":
+                        org = cn.split(".", 1)[1]
+                    if org == "":
+                        org = self.tr("Unknown")
+                self.__sslLabel.setText(" {0} ".format(org))
+                self.__sslLabel.setVisible(True)
+                valid = not sslCertificate.isBlacklisted()
+                if valid:
+                    config = self.__browser.page().getSslConfiguration()
+                    if config is None or config.sessionCipher().isNull():
+                        valid = False
+                self.__sslLabel.setValidity(valid)
+            else:
+                self.__sslLabel.setVisible(False)
+        else:
+            self.__sslLabel.setVisible(False)

eric ide

mercurial