Helpviewer/HelpBrowserWV.py

changeset 1558
754120837dd8
parent 1518
e6e21910210d
child 1561
fe54c9df80e8
equal deleted inserted replaced
1557:4831bab2b94e 1558:754120837dd8
30 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog 30 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog
31 from .JavaScriptResources import fetchLinks_js 31 from .JavaScriptResources import fetchLinks_js
32 from .HTMLResources import notFoundPage_html 32 from .HTMLResources import notFoundPage_html
33 try: 33 try:
34 from .SslInfoDialog import SslInfoDialog 34 from .SslInfoDialog import SslInfoDialog
35 from PyQt4.QtNetwork import QSslCertificate
35 SSL_AVAILABLE = True 36 SSL_AVAILABLE = True
36 except ImportError: 37 except ImportError:
37 SSL_AVAILABLE = False 38 SSL_AVAILABLE = False
38 import Helpviewer.HelpWindow 39 import Helpviewer.HelpWindow
39 40
170 self.__proxy.setWebPage(self) 171 self.__proxy.setWebPage(self)
171 self.__proxy.setPrimaryNetworkAccessManager( 172 self.__proxy.setPrimaryNetworkAccessManager(
172 Helpviewer.HelpWindow.HelpWindow.networkAccessManager()) 173 Helpviewer.HelpWindow.HelpWindow.networkAccessManager())
173 self.setNetworkAccessManager(self.__proxy) 174 self.setNetworkAccessManager(self.__proxy)
174 175
175 self.__sslInfo = None 176 self.__sslConfiguration = None
176 self.__proxy.finished.connect(self.__managerFinished) 177 self.__proxy.finished.connect(self.__managerFinished)
177 178
178 def acceptNavigationRequest(self, frame, request, type_): 179 def acceptNavigationRequest(self, frame, request, type_):
179 """ 180 """
180 Protected method to determine, if a request may be accepted. 181 Protected method to determine, if a request may be accepted.
334 frame = None 335 frame = None
335 336
336 mainFrameRequest = frame == self.mainFrame() 337 mainFrameRequest = frame == self.mainFrame()
337 338
338 if mainFrameRequest and \ 339 if mainFrameRequest and \
339 self.__sslInfo is not None and \ 340 self.__sslConfiguration is not None and \
340 reply.url() == self.mainFrame().url(): 341 reply.url() == self.mainFrame().url():
341 self.__sslInfo = None 342 self.__sslConfiguration = None
342 343
343 if reply.error() == QNetworkReply.NoError and \ 344 if reply.error() == QNetworkReply.NoError and \
344 mainFrameRequest and \ 345 mainFrameRequest and \
345 self.__sslInfo is None and \ 346 self.__sslConfiguration is None and \
346 reply.url().scheme().lower() == "https" and \ 347 reply.url().scheme().lower() == "https" and \
347 reply.url() == self.mainFrame().url(): 348 reply.url() == self.mainFrame().url():
348 self.__sslInfo = reply.sslConfiguration().peerCertificate() 349 self.__sslConfiguration = reply.sslConfiguration()
349 self.__sslInfo.url = QUrl(reply.url()) 350 self.__sslConfiguration.url = QUrl(reply.url())
350 351
351 def getSslInfo(self): 352 def getSslInfo(self):
352 """ 353 """
353 Public method to get a reference to the SSL info object. 354 Public method to get a reference to the SSL info object.
354 355
355 @return reference to the SSL info (QSslCertificate) 356 @return reference to the SSL info (QSslCertificate)
356 """ 357 """
357 return self.__sslInfo 358 sslInfo = self.__sslConfiguration.peerCertificate()
359 sslInfo.url = QUrl(self.__sslConfiguration.url)
360 return sslInfo
358 361
359 def showSslInfo(self): 362 def showSslInfo(self):
360 """ 363 """
361 Public slot to show some SSL information for the loaded page. 364 Public slot to show some SSL information for the loaded page.
362 """ 365 """
363 if SSL_AVAILABLE and self.__sslInfo is not None: 366 if SSL_AVAILABLE and self.__sslConfiguration is not None:
364 dlg = SslInfoDialog(self.__sslInfo, self.view()) 367 dlg = SslInfoDialog(self.getSslInfo(), self.view())
365 dlg.exec_() 368 dlg.exec_()
366 else: 369 else:
367 E5MessageBox.warning(self.view(), 370 E5MessageBox.warning(self.view(),
368 self.trUtf8("SSL Certificate Info"), 371 self.trUtf8("SSL Certificate Info"),
369 self.trUtf8("""There is no SSL Certificate Info available.""")) 372 self.trUtf8("""There is no SSL Certificate Info available."""))
373
374 def hasValidSslInfo(self):
375 """
376 Public method to check, if the page has a valid SSL certificate.
377
378 @return flag indicating a valid SSL certificate (boolean)
379 """
380 if self.__sslConfiguration is None:
381 return False
382
383 certList = self.__sslConfiguration.peerCertificateChain()
384 if not certList:
385 return False
386
387 certificateDict = Preferences.toDict(
388 Preferences.Prefs.settings.value("Help/CaCertificatesDict"))
389 for server in certificateDict:
390 localCAList = QSslCertificate.fromData(certificateDict[server])
391 for cert in certList:
392 if cert in localCAList:
393 return True
394
395 for cert in certList:
396 if not cert.isValid():
397 return False
398
399 return True
370 400
371 ########################################################################################## 401 ##########################################################################################
372 402
373 403
374 class HelpBrowser(QWebView): 404 class HelpBrowser(QWebView):

eric ide

mercurial