eric7/WebBrowser/WebBrowserPage.py

branch
eric7
changeset 8556
766e1566cb74
parent 8553
10d31e5ce9e5
child 8561
641304b46f08
equal deleted inserted replaced
8555:844c2713bf44 8556:766e1566cb74
11 from PyQt6.QtCore import ( 11 from PyQt6.QtCore import (
12 pyqtSlot, pyqtSignal, QUrl, QUrlQuery, QTimer, QEventLoop, QPoint, QPointF 12 pyqtSlot, pyqtSignal, QUrl, QUrlQuery, QTimer, QEventLoop, QPoint, QPointF
13 ) 13 )
14 from PyQt6.QtGui import QDesktopServices 14 from PyQt6.QtGui import QDesktopServices
15 from PyQt6.QtWebEngineCore import ( 15 from PyQt6.QtWebEngineCore import (
16 QWebEnginePage, QWebEngineSettings, QWebEngineScript, 16 QWebEnginePage, QWebEngineSettings, QWebEngineScript
17 PYQT_WEBENGINE_VERSION
18 ) 17 )
19 from PyQt6.QtWebChannel import QWebChannel 18 from PyQt6.QtWebChannel import QWebChannel
20 19
21 try: 20 try:
22 from PyQt6.QtNetwork import QSslConfiguration, QSslCertificate 21 from PyQt6.QtNetwork import QSslConfiguration, QSslCertificate
62 navigationRequestAccepted = pyqtSignal(QUrl, QWebEnginePage.NavigationType, 61 navigationRequestAccepted = pyqtSignal(QUrl, QWebEnginePage.NavigationType,
63 bool) 62 bool)
64 63
65 sslConfigurationChanged = pyqtSignal() 64 sslConfigurationChanged = pyqtSignal()
66 65
67 def __init__(self, parent=None): 66 def __init__(self, view, parent=None):
68 """ 67 """
69 Constructor 68 Constructor
70 69
71 @param parent parent widget of this window (QWidget) 70 @param view reference to the WebBrowserView associated with the page
71 @type WebBrowserView
72 @param parent reference to the parent widget (defaults to None)
73 @type QWidget (optional)
74 """
75 """
76 Constructor
77
78 @param parent parent widget of this window (optional)
79 @type QWidget
72 """ 80 """
73 super().__init__( 81 super().__init__(
74 WebBrowserWindow.webProfile(), parent) 82 WebBrowserWindow.webProfile(), parent)
75 83
76 self.__printer = None 84 self.__printer = None
77 self.__badSite = False 85 self.__badSite = False
78 self.__registerProtocolHandlerRequest = None 86 self.__registerProtocolHandlerRequest = None
87
88 self.__view = view
79 89
80 self.featurePermissionRequested.connect( 90 self.featurePermissionRequested.connect(
81 self.__featurePermissionRequested) 91 self.__featurePermissionRequested)
82 self.authenticationRequired.connect( 92 self.authenticationRequired.connect(
83 lambda url, auth: WebBrowserWindow.networkManager().authentication( 93 lambda url, auth: WebBrowserWindow.networkManager().authentication(
151 return False 161 return False
152 162
153 if url.scheme() == "eric": 163 if url.scheme() == "eric":
154 if url.path() == "AddSearchProvider": 164 if url.path() == "AddSearchProvider":
155 query = QUrlQuery(url) 165 query = QUrlQuery(url)
156 self.view().mainWindow().openSearchManager().addEngine( 166 self.__view.mainWindow().openSearchManager().addEngine(
157 QUrl(query.queryItemValue("url"))) 167 QUrl(query.queryItemValue("url")))
158 return False 168 return False
159 elif url.path() == "PrintPage": 169 elif url.path() == "PrintPage":
160 self.printPageRequested.emit() 170 self.printPageRequested.emit()
161 return False 171 return False
433 @type QWebEngineCertificateError 443 @type QWebEngineCertificateError
434 @return flag indicating to ignore this error 444 @return flag indicating to ignore this error
435 @rtype bool 445 @rtype bool
436 """ 446 """
437 return WebBrowserWindow.networkManager().certificateError( 447 return WebBrowserWindow.networkManager().certificateError(
438 error, self.view()) 448 error, self.__view)
439 449
440 def __fullScreenRequested(self, request): 450 def __fullScreenRequested(self, request):
441 """ 451 """
442 Private slot handling a full screen request. 452 Private slot handling a full screen request.
443 453
444 @param request reference to the full screen request 454 @param request reference to the full screen request
445 @type QWebEngineFullScreenRequest 455 @type QWebEngineFullScreenRequest
446 """ 456 """
447 self.view().requestFullScreen(request.toggleOn()) 457 self.__view.requestFullScreen(request.toggleOn())
448 458
449 accepted = request.toggleOn() == self.view().isFullScreen() 459 accepted = request.toggleOn() == self.__view.isFullScreen()
450 460
451 if accepted: 461 if accepted:
452 request.accept() 462 request.accept()
453 else: 463 else:
454 request.reject() 464 request.reject()
504 @param lineNumber line number of an error 514 @param lineNumber line number of an error
505 @type int 515 @type int
506 @param sourceId source URL causing the error 516 @param sourceId source URL causing the error
507 @type str 517 @type str
508 """ 518 """
509 self.view().mainWindow().javascriptConsole().javaScriptConsoleMessage( 519 self.__view.mainWindow().javascriptConsole().javaScriptConsoleMessage(
510 level, message, lineNumber, sourceId) 520 level, message, lineNumber, sourceId)
511 521
512 ########################################################################### 522 ###########################################################################
513 ## Methods below implement safe browsing related functions 523 ## Methods below implement safe browsing related functions
514 ########################################################################### 524 ###########################################################################
532 Public method to get the web site icon. 542 Public method to get the web site icon.
533 543
534 @return web site icon 544 @return web site icon
535 @rtype QIcon 545 @rtype QIcon
536 """ 546 """
537 return self.view().icon() 547 return self.__view.icon()
538 548
539 if not hasattr(QWebEnginePage, "scrollPosition"): 549 if not hasattr(QWebEnginePage, "scrollPosition"):
540 def scrollPosition(self): 550 def scrollPosition(self):
541 """ 551 """
542 Public method to get the scroll position of the web page. 552 Public method to get the scroll position of the web page.
685 @type QPoint 695 @type QPoint
686 """ 696 """
687 if SSL_AVAILABLE and self.__sslConfiguration is not None: 697 if SSL_AVAILABLE and self.__sslConfiguration is not None:
688 from EricNetwork.EricSslInfoWidget import EricSslInfoWidget 698 from EricNetwork.EricSslInfoWidget import EricSslInfoWidget
689 widget = EricSslInfoWidget(self.url(), self.__sslConfiguration, 699 widget = EricSslInfoWidget(self.url(), self.__sslConfiguration,
690 self.view()) 700 self.__view)
691 widget.showAt(pos) 701 widget.showAt(pos)
692 else: 702 else:
693 EricMessageBox.warning( 703 EricMessageBox.warning(
694 self.view(), 704 self.__view,
695 self.tr("SSL Info"), 705 self.tr("SSL Info"),
696 self.tr("""This site does not contain SSL information.""")) 706 self.tr("""This site does not contain SSL information."""))
697 707
698 def hasValidSslInfo(self): 708 def hasValidSslInfo(self):
699 """ 709 """

eric ide

mercurial