6 |
6 |
7 """ |
7 """ |
8 Module implementing the helpbrowser using QWebView. |
8 Module implementing the helpbrowser using QWebView. |
9 """ |
9 """ |
10 |
10 |
11 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QUrl, QUrlQuery, QTimer, \ |
11 from PyQt5.QtCore import ( |
12 QEventLoop, QPoint, QPointF |
12 pyqtSlot, pyqtSignal, QUrl, QUrlQuery, QTimer, QEventLoop, QPoint, QPointF |
|
13 ) |
13 from PyQt5.QtGui import QDesktopServices |
14 from PyQt5.QtGui import QDesktopServices |
14 from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineSettings, \ |
15 from PyQt5.QtWebEngineWidgets import ( |
15 QWebEngineScript |
16 QWebEnginePage, QWebEngineSettings, QWebEngineScript |
|
17 ) |
16 from PyQt5.QtWebChannel import QWebChannel |
18 from PyQt5.QtWebChannel import QWebChannel |
17 |
19 |
18 from E5Gui import E5MessageBox |
20 from E5Gui import E5MessageBox |
19 |
21 |
20 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
22 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
120 if url.scheme() == "abp": |
122 if url.scheme() == "abp": |
121 if WebBrowserWindow.adBlockManager().addSubscriptionFromUrl(url): |
123 if WebBrowserWindow.adBlockManager().addSubscriptionFromUrl(url): |
122 return False |
124 return False |
123 |
125 |
124 # GreaseMonkey |
126 # GreaseMonkey |
125 if type_ == QWebEnginePage.NavigationTypeLinkClicked and \ |
127 if ( |
126 url.toString().endswith(".user.js"): |
128 type_ == QWebEnginePage.NavigationTypeLinkClicked and |
|
129 url.toString().endswith(".user.js") |
|
130 ): |
127 WebBrowserWindow.greaseMonkeyManager().downloadScript(url) |
131 WebBrowserWindow.greaseMonkeyManager().downloadScript(url) |
128 return False |
132 return False |
129 |
133 |
130 if url.scheme() == "eric": |
134 if url.scheme() == "eric": |
131 if url.path() == "AddSearchProvider": |
135 if url.path() == "AddSearchProvider": |
137 self.printPageRequested.emit() |
141 self.printPageRequested.emit() |
138 return False |
142 return False |
139 |
143 |
140 # Safe Browsing |
144 # Safe Browsing |
141 self.__badSite = False |
145 self.__badSite = False |
142 from WebBrowser.SafeBrowsing.SafeBrowsingManager import \ |
146 from WebBrowser.SafeBrowsing.SafeBrowsingManager import ( |
143 SafeBrowsingManager |
147 SafeBrowsingManager |
144 if SafeBrowsingManager.isEnabled() and \ |
148 ) |
145 url.scheme() not in \ |
149 if ( |
146 SafeBrowsingManager.getIgnoreSchemes(): |
150 SafeBrowsingManager.isEnabled() and |
147 threatLists = \ |
151 url.scheme() not in SafeBrowsingManager.getIgnoreSchemes() |
|
152 ): |
|
153 threatLists = ( |
148 WebBrowserWindow.safeBrowsingManager().lookupUrl(url)[0] |
154 WebBrowserWindow.safeBrowsingManager().lookupUrl(url)[0] |
|
155 ) |
149 if threatLists: |
156 if threatLists: |
150 threatMessages = WebBrowserWindow.safeBrowsingManager()\ |
157 threatMessages = ( |
|
158 WebBrowserWindow.safeBrowsingManager() |
151 .getThreatMessages(threatLists) |
159 .getThreatMessages(threatLists) |
|
160 ) |
152 res = E5MessageBox.warning( |
161 res = E5MessageBox.warning( |
153 WebBrowserWindow.getWindow(), |
162 WebBrowserWindow.getWindow(), |
154 self.tr("Suspicuous URL detected"), |
163 self.tr("Suspicuous URL detected"), |
155 self.tr("<p>The URL <b>{0}</b> was found in the Safe" |
164 self.tr("<p>The URL <b>{0}</b> was found in the Safe" |
156 " Browsing database.</p>{1}").format( |
165 " Browsing database.</p>{1}").format( |
162 if res == E5MessageBox.Abort: |
171 if res == E5MessageBox.Abort: |
163 self.safeBrowsingAbort.emit() |
172 self.safeBrowsingAbort.emit() |
164 return False |
173 return False |
165 |
174 |
166 self.__badSite = True |
175 self.__badSite = True |
167 threatType = WebBrowserWindow.safeBrowsingManager()\ |
176 threatType = ( |
|
177 WebBrowserWindow.safeBrowsingManager() |
168 .getThreatType(threatLists[0]) |
178 .getThreatType(threatLists[0]) |
|
179 ) |
169 self.safeBrowsingBad.emit(threatType, "".join(threatMessages)) |
180 self.safeBrowsingBad.emit(threatType, "".join(threatMessages)) |
170 |
181 |
171 result = QWebEnginePage.acceptNavigationRequest(self, url, type_, |
182 result = QWebEnginePage.acceptNavigationRequest(self, url, type_, |
172 isMainFrame) |
183 isMainFrame) |
173 |
184 |
196 Private slot to handle changes of the URL. |
207 Private slot to handle changes of the URL. |
197 |
208 |
198 @param url new URL |
209 @param url new URL |
199 @type QUrl |
210 @type QUrl |
200 """ |
211 """ |
201 if not url.isEmpty() and url.scheme() == "eric" and \ |
212 if ( |
202 not self.isJavaScriptEnabled(): |
213 not url.isEmpty() and |
|
214 url.scheme() == "eric" and |
|
215 not self.isJavaScriptEnabled() |
|
216 ): |
203 self.settings().setAttribute(QWebEngineSettings.JavascriptEnabled, |
217 self.settings().setAttribute(QWebEngineSettings.JavascriptEnabled, |
204 True) |
218 True) |
205 self.triggerAction(QWebEnginePage.Reload) |
219 self.triggerAction(QWebEnginePage.Reload) |
206 |
220 |
207 @classmethod |
221 @classmethod |
542 handler. |
556 handler. |
543 |
557 |
544 @param request reference to the registration request |
558 @param request reference to the registration request |
545 @type QWebEngineRegisterProtocolHandlerRequest |
559 @type QWebEngineRegisterProtocolHandlerRequest |
546 """ |
560 """ |
547 from PyQt5.QtWebEngineCore import \ |
561 from PyQt5.QtWebEngineCore import ( |
548 QWebEngineRegisterProtocolHandlerRequest |
562 QWebEngineRegisterProtocolHandlerRequest |
|
563 ) |
549 |
564 |
550 if self.__registerProtocolHandlerRequest: |
565 if self.__registerProtocolHandlerRequest: |
551 del self.__registerProtocolHandlerRequest |
566 del self.__registerProtocolHandlerRequest |
552 self.__registerProtocolHandlerRequest = None |
567 self.__registerProtocolHandlerRequest = None |
553 self.__registerProtocolHandlerRequest = \ |
568 self.__registerProtocolHandlerRequest = ( |
554 QWebEngineRegisterProtocolHandlerRequest(request) |
569 QWebEngineRegisterProtocolHandlerRequest(request) |
|
570 ) |
555 except TypeError: |
571 except TypeError: |
556 # this is supported with Qt 5.12 and later |
572 # this is supported with Qt 5.12 and later |
557 pass |
573 pass |
558 |
574 |
559 def registerProtocolHandlerRequestUrl(self): |
575 def registerProtocolHandlerRequestUrl(self): |
561 Public method to get the registered protocol handler request URL. |
577 Public method to get the registered protocol handler request URL. |
562 |
578 |
563 @return registered protocol handler request URL |
579 @return registered protocol handler request URL |
564 @rtype QUrl |
580 @rtype QUrl |
565 """ |
581 """ |
566 if self.__registerProtocolHandlerRequest and \ |
582 if ( |
|
583 self.__registerProtocolHandlerRequest and |
567 (self.url().host() == |
584 (self.url().host() == |
568 self.__registerProtocolHandlerRequest.origin().host()): |
585 self.__registerProtocolHandlerRequest.origin().host()) |
|
586 ): |
569 return self.__registerProtocolHandlerRequest.origin() |
587 return self.__registerProtocolHandlerRequest.origin() |
570 else: |
588 else: |
571 return QUrl() |
589 return QUrl() |
572 |
590 |
573 def registerProtocolHandlerRequestScheme(self): |
591 def registerProtocolHandlerRequestScheme(self): |
575 Public method to get the registered protocol handler request scheme. |
593 Public method to get the registered protocol handler request scheme. |
576 |
594 |
577 @return registered protocol handler request scheme |
595 @return registered protocol handler request scheme |
578 @rtype str |
596 @rtype str |
579 """ |
597 """ |
580 if self.__registerProtocolHandlerRequest and \ |
598 if ( |
|
599 self.__registerProtocolHandlerRequest and |
581 (self.url().host() == |
600 (self.url().host() == |
582 self.__registerProtocolHandlerRequest.origin().host()): |
601 self.__registerProtocolHandlerRequest.origin().host()) |
|
602 ): |
583 return self.__registerProtocolHandlerRequest.scheme() |
603 return self.__registerProtocolHandlerRequest.scheme() |
584 else: |
604 else: |
585 return "" |
605 return "" |