12 try: |
12 try: |
13 str = unicode # __IGNORE_EXCEPTION__ |
13 str = unicode # __IGNORE_EXCEPTION__ |
14 except NameError: |
14 except NameError: |
15 pass |
15 pass |
16 |
16 |
17 from PyQt5.QtCore import pyqtSlot, QUrl, QTimer, QEventLoop, QPoint, QPointF |
17 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QUrl, QTimer, QEventLoop, \ |
|
18 QPoint, QPointF |
18 from PyQt5.QtGui import QDesktopServices |
19 from PyQt5.QtGui import QDesktopServices |
19 from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineSettings, \ |
20 from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineSettings, \ |
20 QWebEngineScript |
21 QWebEngineScript |
21 from PyQt5.QtWebChannel import QWebChannel |
22 from PyQt5.QtWebChannel import QWebChannel |
22 |
23 |
|
24 from E5Gui import E5MessageBox |
|
25 |
23 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
26 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
24 |
27 |
25 from .JavaScript.ExternalJsObject import ExternalJsObject |
28 from .JavaScript.ExternalJsObject import ExternalJsObject |
26 |
29 |
27 from .Tools.WebHitTestResult import WebHitTestResult |
30 from .Tools.WebHitTestResult import WebHitTestResult |
31 |
34 |
32 |
35 |
33 class WebBrowserPage(QWebEnginePage): |
36 class WebBrowserPage(QWebEnginePage): |
34 """ |
37 """ |
35 Class implementing an enhanced web page. |
38 Class implementing an enhanced web page. |
|
39 |
|
40 @signal safeBrowsingAbort() emitted to indicate an abort due to a safe |
|
41 browsing event |
|
42 @signal safeBrowsingBad(threatType, threatMessages) emitted to indicate a |
|
43 malicious web site as determined by safe browsing |
36 """ |
44 """ |
37 if qVersionTuple() >= (5, 7, 0): |
45 if qVersionTuple() >= (5, 7, 0): |
38 # SafeJsWorld = QWebEngineScript.ApplicationWorld |
46 # SafeJsWorld = QWebEngineScript.ApplicationWorld |
39 SafeJsWorld = QWebEngineScript.MainWorld |
47 SafeJsWorld = QWebEngineScript.MainWorld |
40 else: |
48 else: |
41 SafeJsWorld = QWebEngineScript.MainWorld |
49 SafeJsWorld = QWebEngineScript.MainWorld |
42 |
50 |
|
51 safeBrowsingAbort = pyqtSignal() |
|
52 safeBrowsingBad = pyqtSignal(str, str) |
|
53 |
43 def __init__(self, parent=None): |
54 def __init__(self, parent=None): |
44 """ |
55 """ |
45 Constructor |
56 Constructor |
46 |
57 |
47 @param parent parent widget of this window (QWidget) |
58 @param parent parent widget of this window (QWidget) |
63 self.fullScreenRequested.connect(self.__fullScreenRequested) |
74 self.fullScreenRequested.connect(self.__fullScreenRequested) |
64 |
75 |
65 self.urlChanged.connect(self.__urlChanged) |
76 self.urlChanged.connect(self.__urlChanged) |
66 |
77 |
67 self.__printer = None |
78 self.__printer = None |
|
79 self.__badSite = False |
68 |
80 |
69 def acceptNavigationRequest(self, url, type_, isMainFrame): |
81 def acceptNavigationRequest(self, url, type_, isMainFrame): |
70 """ |
82 """ |
71 Public method to determine, if a request may be accepted. |
83 Public method to determine, if a request may be accepted. |
72 |
84 |
93 # GreaseMonkey |
105 # GreaseMonkey |
94 if type_ == QWebEnginePage.NavigationTypeLinkClicked and \ |
106 if type_ == QWebEnginePage.NavigationTypeLinkClicked and \ |
95 url.toString().endswith(".user.js"): |
107 url.toString().endswith(".user.js"): |
96 WebBrowserWindow.greaseMonkeyManager().downloadScript(url) |
108 WebBrowserWindow.greaseMonkeyManager().downloadScript(url) |
97 return False |
109 return False |
|
110 |
|
111 # Safe Browsing |
|
112 self.__badSite = False |
|
113 if url.scheme() not in \ |
|
114 WebBrowserWindow.safeBrowsingManager().getIgnoreSchemes(): |
|
115 threatLists = WebBrowserWindow.safeBrowsingManager().lookupUrl(url) |
|
116 if threatLists: |
|
117 threatMessages = WebBrowserWindow.safeBrowsingManager()\ |
|
118 .getThreatMessages(threatLists) |
|
119 res = E5MessageBox.warning( |
|
120 WebBrowserWindow.getWindow(), |
|
121 self.tr("Suspicuous URL detected"), |
|
122 self.tr("<p>The URL <b>{0}</b> was found in the Safe" |
|
123 " Browsing database.</p>{1}").format( |
|
124 url.toString(), "".join(threatMessages)), |
|
125 E5MessageBox.StandardButtons( |
|
126 E5MessageBox.Abort | |
|
127 E5MessageBox.Ignore), |
|
128 E5MessageBox.Abort) |
|
129 if res == E5MessageBox.Abort: |
|
130 self.safeBrowsingAbort.emit() |
|
131 return False |
|
132 |
|
133 self.__badSite = True |
|
134 threatType = WebBrowserWindow.safeBrowsingManager()\ |
|
135 .getThreatType(threatLists[0]) |
|
136 self.safeBrowsingBad.emit(threatType, "".join(threatMessages)) |
98 |
137 |
99 return QWebEnginePage.acceptNavigationRequest(self, url, type_, |
138 return QWebEnginePage.acceptNavigationRequest(self, url, type_, |
100 isMainFrame) |
139 isMainFrame) |
101 |
140 |
102 @pyqtSlot(QUrl) |
141 @pyqtSlot(QUrl) |
371 @param sourceId source URL causing the error |
410 @param sourceId source URL causing the error |
372 @type str |
411 @type str |
373 """ |
412 """ |
374 self.view().mainWindow().javascriptConsole().javaScriptConsoleMessage( |
413 self.view().mainWindow().javascriptConsole().javaScriptConsoleMessage( |
375 level, message, lineNumber, sourceId) |
414 level, message, lineNumber, sourceId) |
|
415 |
|
416 ########################################################################### |
|
417 ## Methods below implement safe browsing related functions |
|
418 ########################################################################### |
|
419 |
|
420 def getSafeBrowsingStatus(self): |
|
421 """ |
|
422 Public method to get the safe browsing status of the current page. |
|
423 |
|
424 @return flag indicating a safe site |
|
425 @rtype bool |
|
426 """ |
|
427 return not self.__badSite |
376 |
428 |
377 ################################################## |
429 ################################################## |
378 ## Methods below implement compatibility functions |
430 ## Methods below implement compatibility functions |
379 ################################################## |
431 ################################################## |
380 |
432 |