WebBrowser/WebBrowserPage.py

changeset 6140
c20e2d414d0d
parent 6139
d24997c47244
child 6142
304a469455c8
equal deleted inserted replaced
6139:d24997c47244 6140:c20e2d414d0d
41 browsing event 41 browsing event
42 @signal safeBrowsingBad(threatType, threatMessages) emitted to indicate a 42 @signal safeBrowsingBad(threatType, threatMessages) emitted to indicate a
43 malicious web site as determined by safe browsing 43 malicious web site as determined by safe browsing
44 """ 44 """
45 if qVersionTuple() >= (5, 7, 0): 45 if qVersionTuple() >= (5, 7, 0):
46 # SafeJsWorld = QWebEngineScript.ApplicationWorld 46 SafeJsWorld = QWebEngineScript.ApplicationWorld
47 SafeJsWorld = QWebEngineScript.MainWorld 47 # SafeJsWorld = QWebEngineScript.MainWorld
48 else: 48 else:
49 SafeJsWorld = QWebEngineScript.MainWorld 49 SafeJsWorld = QWebEngineScript.MainWorld
50 UnsafeJsWorld = QWebEngineScript.MainWorld
50 51
51 safeBrowsingAbort = pyqtSignal() 52 safeBrowsingAbort = pyqtSignal()
52 safeBrowsingBad = pyqtSignal(str, str) 53 safeBrowsingBad = pyqtSignal(str, str)
53 54
54 def __init__(self, parent=None): 55 def __init__(self, parent=None):
57 58
58 @param parent parent widget of this window (QWidget) 59 @param parent parent widget of this window (QWidget)
59 """ 60 """
60 super(WebBrowserPage, self).__init__( 61 super(WebBrowserPage, self).__init__(
61 WebBrowserWindow.webProfile(), parent) 62 WebBrowserWindow.webProfile(), parent)
62
63 self.__setupWebChannel()
64 63
65 self.featurePermissionRequested.connect( 64 self.featurePermissionRequested.connect(
66 self.__featurePermissionRequested) 65 self.__featurePermissionRequested)
67 66
68 self.authenticationRequired.connect( 67 self.authenticationRequired.connect(
79 self.__printer = None 78 self.__printer = None
80 self.__badSite = False 79 self.__badSite = False
81 80
82 if qVersionTuple == (5, 10, 0): 81 if qVersionTuple == (5, 10, 0):
83 self.loadProgress.connect(self.__loadProgressSlot) 82 self.loadProgress.connect(self.__loadProgressSlot)
83
84 # Workaround for changing webchannel world inside
85 # acceptNavigationRequest not working
86 self.__channelUrl = QUrl()
87 self.__channelWorldId = -1
88 self.__setupChannelTimer = QTimer(self)
89 self.__setupChannelTimer.setSingleShot(True)
90 self.__setupChannelTimer.setInterval(100)
91 self.__setupChannelTimer.timeout.connect(self.__setupChannelTimeout)
92
93 @pyqtSlot()
94 def __setupChannelTimeout(self):
95 """
96 Private slot to initiate the setup of the web channel.
97 """
98 self.__setupWebChannelForUrl(self.__channelUrl)
84 99
85 @pyqtSlot(int) 100 @pyqtSlot(int)
86 def __loadProgressSlot(self, progress): 101 def __loadProgressSlot(self, progress):
87 """ 102 """
88 Private slot to implement a workaround for the loadFinished signal 103 Private slot to implement a workaround for the loadFinished signal
165 enable = globalJsEnabled 180 enable = globalJsEnabled
166 else: 181 else:
167 enable = True 182 enable = True
168 self.settings().setAttribute( 183 self.settings().setAttribute(
169 QWebEngineSettings.JavascriptEnabled, enable) 184 QWebEngineSettings.JavascriptEnabled, enable)
185
186 self.__channelUrl = url
187 self.__setupChannelTimer.start()
170 188
171 return result 189 return result
172 190
173 @pyqtSlot(QUrl) 191 @pyqtSlot(QUrl)
174 def __urlChanged(self, url): 192 def __urlChanged(self, url):
345 @return test result object 363 @return test result object
346 @rtype WebHitTestResult 364 @rtype WebHitTestResult
347 """ 365 """
348 return WebHitTestResult(self, pos) 366 return WebHitTestResult(self, pos)
349 367
350 def __setupWebChannel(self): 368 def __setupWebChannelForUrl(self, url):
351 """ 369 """
352 Private method to setup a web channel to our external object. 370 Private method to setup a web channel to our external object.
353 """ 371
354 oldChannel = self.webChannel() 372 @param url URL for which to setup the web channel
355 newChannel = QWebChannel(self) 373 @type QUrl
356 ExternalJsObject.setupWebChannel(newChannel, self) 374 """
357 self.setWebChannel(newChannel) 375 channel = self.webChannel()
358 376 if channel is None:
359 if oldChannel: 377 channel = QWebChannel(self)
360 del oldChannel.registeredObjects["eric_object"] 378 ExternalJsObject.setupWebChannel(channel, self)
361 del oldChannel 379
380 worldId = -1
381 if url.scheme() in ("eric", "qthelp"):
382 worldId = self.UnsafeJsWorld
383 else:
384 worldId = self.SafeJsWorld
385 if worldId != self.__channelWorldId:
386 self.__channelWorldId = worldId
387 try:
388 self.setWebChannel(channel, self.__channelWorldId)
389 except TypeError:
390 # pre Qt 5.7.0
391 self.setWebChannel(channel)
362 392
363 def certificateError(self, error): 393 def certificateError(self, error):
364 """ 394 """
365 Public method to handle SSL certificate errors. 395 Public method to handle SSL certificate errors.
366 396

eric ide

mercurial