eric6/WebBrowser/WebBrowserView.py

changeset 7945
76daafe10009
parent 7937
181d1160f617
child 7960
e8fc383322f7
equal deleted inserted replaced
7941:cf988a30ba47 7945:76daafe10009
36 from .Tools.WebBrowserTools import getHtmlPage, pixmapToDataUrl 36 from .Tools.WebBrowserTools import getHtmlPage, pixmapToDataUrl
37 37
38 import Preferences 38 import Preferences
39 import UI.PixmapCache 39 import UI.PixmapCache
40 import Utilities 40 import Utilities
41 from Globals import qVersionTuple
42 41
43 42
44 class WebBrowserView(QWebEngineView): 43 class WebBrowserView(QWebEngineView):
45 """ 44 """
46 Class implementing the web browser view widget. 45 Class implementing the web browser view widget.
135 134
136 self.__restoreData = None 135 self.__restoreData = None
137 136
138 if self.parentWidget() is not None: 137 if self.parentWidget() is not None:
139 self.parentWidget().installEventFilter(self) 138 self.parentWidget().installEventFilter(self)
140
141 if qVersionTuple() < (5, 11, 0):
142 lay = self.layout()
143 lay.currentChanged.connect(
144 lambda: QTimer.singleShot(0, self.__setRwhvqt))
145 self.__setRwhvqt()
146 139
147 self.grabGesture(Qt.PinchGesture) 140 self.grabGesture(Qt.PinchGesture)
148 141
149 def __createNewPage(self): 142 def __createNewPage(self):
150 """ 143 """
581 574
582 if not hitTest.isContentEditable() and not hitTest.isContentSelected(): 575 if not hitTest.isContentEditable() and not hitTest.isContentSelected():
583 self.__menu.addSeparator() 576 self.__menu.addSeparator()
584 self.__menu.addAction(self.__mw.adBlockIcon().menuAction()) 577 self.__menu.addAction(self.__mw.adBlockIcon().menuAction())
585 578
586 if ( 579 self.__menu.addSeparator()
587 qVersionTuple() >= (5, 11, 0) or 580 self.__menu.addAction(
588 Preferences.getWebBrowser("WebInspectorEnabled") 581 UI.PixmapCache.getIcon("webInspector"),
589 ): 582 self.tr("Inspect Element..."), self.__webInspector)
590 self.__menu.addSeparator()
591 self.__menu.addAction(
592 UI.PixmapCache.getIcon("webInspector"),
593 self.tr("Inspect Element..."), self.__webInspector)
594 583
595 if not self.__menu.isEmpty(): 584 if not self.__menu.isEmpty():
596 pos = evt.globalPos() 585 pos = evt.globalPos()
597 self.__menu.popup(QPoint(pos.x(), pos.y() + 1)) 586 self.__menu.popup(QPoint(pos.x(), pos.y() + 1))
598 587
1569 ): 1558 ):
1570 self.parentWidget().installEventFilter(self) 1559 self.parentWidget().installEventFilter(self)
1571 1560
1572 # find the render widget receiving events for the web page 1561 # find the render widget receiving events for the web page
1573 if obj is self and evt.type() == QEvent.ChildAdded: 1562 if obj is self and evt.type() == QEvent.ChildAdded:
1574 if qVersionTuple() >= (5, 11, 0): 1563 QTimer.singleShot(0, self.__setRwhvqt)
1575 QTimer.singleShot(0, self.__setRwhvqt)
1576 1564
1577 # forward events to WebBrowserView 1565 # forward events to WebBrowserView
1578 if ( 1566 if (
1579 obj is self.__rwhvqt and 1567 obj is self.__rwhvqt and
1580 evt.type() in [QEvent.KeyPress, QEvent.KeyRelease, 1568 evt.type() in [QEvent.KeyPress, QEvent.KeyRelease,
2275 2263
2276 ########################################################################### 2264 ###########################################################################
2277 ## Methods below implement slots for Qt 5.11+ 2265 ## Methods below implement slots for Qt 5.11+
2278 ########################################################################### 2266 ###########################################################################
2279 2267
2280 if qVersionTuple() >= (5, 11, 0): 2268 @pyqtSlot("QWebEngineQuotaRequest")
2281 @pyqtSlot("QWebEngineQuotaRequest") 2269 def __quotaRequested(self, quotaRequest):
2282 def __quotaRequested(self, quotaRequest): 2270 """
2283 """ 2271 Private slot to handle quota requests of the web page.
2284 Private slot to handle quota requests of the web page. 2272
2273 @param quotaRequest reference to the quota request object
2274 @type QWebEngineQuotaRequest
2275 """
2276 acceptRequest = Preferences.getWebBrowser("AcceptQuotaRequest")
2277 # map yes/no/ask from (0, 1, 2)
2278 if acceptRequest == 0:
2279 # always yes
2280 ok = True
2281 elif acceptRequest == 1:
2282 # always no
2283 ok = False
2284 else:
2285 # ask user
2286 from .Download.DownloadUtilities import dataString
2287 sizeStr = dataString(quotaRequest.requestedSize())
2285 2288
2286 @param quotaRequest reference to the quota request object 2289 ok = E5MessageBox.yesNo(
2287 @type QWebEngineQuotaRequest 2290 self,
2288 """ 2291 self.tr("Quota Request"),
2289 acceptRequest = Preferences.getWebBrowser("AcceptQuotaRequest") 2292 self.tr("""<p> Allow the website at <b>{0}</b> to use"""
2290 # map yes/no/ask from (0, 1, 2) 2293 """ <b>{1}</b> of persistent storage?</p>""")
2291 if acceptRequest == 0: 2294 .format(quotaRequest.origin().host(), sizeStr)
2292 # always yes 2295 )
2293 ok = True 2296
2294 elif acceptRequest == 1: 2297 if ok:
2295 # always no 2298 quotaRequest.accept()
2296 ok = False 2299 else:
2297 else: 2300 quotaRequest.reject()
2298 # ask user
2299 from .Download.DownloadUtilities import dataString
2300 sizeStr = dataString(quotaRequest.requestedSize())
2301
2302 ok = E5MessageBox.yesNo(
2303 self,
2304 self.tr("Quota Request"),
2305 self.tr("""<p> Allow the website at <b>{0}</b> to use"""
2306 """ <b>{1}</b> of persistent storage?</p>""")
2307 .format(quotaRequest.origin().host(), sizeStr)
2308 )
2309
2310 if ok:
2311 quotaRequest.accept()
2312 else:
2313 quotaRequest.reject()
2314 2301
2315 ########################################################################### 2302 ###########################################################################
2316 ## Methods below implement slots for Qt 5.12+ 2303 ## Methods below implement slots for Qt 5.12+
2317 ########################################################################### 2304 ###########################################################################
2318 2305
2319 if qVersionTuple() >= (5, 12, 0): 2306 @pyqtSlot("QWebEngineClientCertificateSelection")
2320 @pyqtSlot("QWebEngineClientCertificateSelection") 2307 def __selectClientCertificate(self, clientCertificateSelection):
2321 def __selectClientCertificate(self, clientCertificateSelection): 2308 """
2322 """ 2309 Private slot to handle the client certificate selection request.
2323 Private slot to handle the client certificate selection request. 2310
2311 @param clientCertificateSelection list of client SSL certificates
2312 found in system's client certificate store
2313 @type QWebEngineClientCertificateSelection
2314 """
2315 certificates = clientCertificateSelection.certificates()
2316 if len(certificates) == 0:
2317 clientCertificateSelection.selectNone()
2318 elif len(certificates) == 1:
2319 clientCertificateSelection.select(certificates[0])
2320 else:
2321 certificate = None
2322 from E5Network.E5SslCertificateSelectionDialog import (
2323 E5SslCertificateSelectionDialog
2324 )
2325 dlg = E5SslCertificateSelectionDialog(certificates, self)
2326 if dlg.exec() == QDialog.Accepted:
2327 certificate = dlg.getSelectedCertificate()
2324 2328
2325 @param clientCertificateSelection list of client SSL certificates 2329 if certificate is None:
2326 found in system's client certificate store
2327 @type QWebEngineClientCertificateSelection
2328 """
2329 certificates = clientCertificateSelection.certificates()
2330 if len(certificates) == 0:
2331 clientCertificateSelection.selectNone() 2330 clientCertificateSelection.selectNone()
2332 elif len(certificates) == 1:
2333 clientCertificateSelection.select(certificates[0])
2334 else: 2331 else:
2335 certificate = None 2332 clientCertificateSelection.select(certificate)
2336 from E5Network.E5SslCertificateSelectionDialog import (
2337 E5SslCertificateSelectionDialog
2338 )
2339 dlg = E5SslCertificateSelectionDialog(certificates, self)
2340 if dlg.exec() == QDialog.Accepted:
2341 certificate = dlg.getSelectedCertificate()
2342
2343 if certificate is None:
2344 clientCertificateSelection.selectNone()
2345 else:
2346 clientCertificateSelection.select(certificate)

eric ide

mercurial