22 from PyQt6.QtWebEngineCore import QWebEnginePage, QWebEngineScript, QWebEngineSettings |
25 from PyQt6.QtWebEngineCore import QWebEnginePage, QWebEngineScript, QWebEngineSettings |
23 |
26 |
24 from eric7 import EricUtilities, Preferences |
27 from eric7 import EricUtilities, Preferences |
25 from eric7.EricWidgets import EricMessageBox |
28 from eric7.EricWidgets import EricMessageBox |
26 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
29 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
30 from eric7.SystemUtilities import QtUtilities |
27 |
31 |
28 from .JavaScript.ExternalJsObject import ExternalJsObject |
32 from .JavaScript.ExternalJsObject import ExternalJsObject |
29 from .Tools import Scripts |
33 from .Tools import Scripts |
30 from .Tools.WebHitTestResult import WebHitTestResult |
34 from .Tools.WebHitTestResult import WebHitTestResult |
31 |
35 |
64 printPageRequested = pyqtSignal() |
71 printPageRequested = pyqtSignal() |
65 navigationRequestAccepted = pyqtSignal(QUrl, QWebEnginePage.NavigationType, bool) |
72 navigationRequestAccepted = pyqtSignal(QUrl, QWebEnginePage.NavigationType, bool) |
66 |
73 |
67 sslConfigurationChanged = pyqtSignal() |
74 sslConfigurationChanged = pyqtSignal() |
68 |
75 |
|
76 if QtUtilities.qVersionTuple() >= (6, 8, 0): |
|
77 PermissionTypeQuestions = { |
|
78 QWebEnginePermission.PermissionType.Geolocation: QCoreApplication.translate( |
|
79 "WebBrowserPage", |
|
80 "<p>Allow <b>{0}</b> to access your location information?</p>", |
|
81 ), |
|
82 QWebEnginePermission.PermissionType.MediaAudioCapture: QCoreApplication.translate( |
|
83 "WebBrowserPage", |
|
84 "<p>Allow <b>{0}</b> to access your microphone?</p>", |
|
85 ), |
|
86 QWebEnginePermission.PermissionType.MediaVideoCapture: QCoreApplication.translate( |
|
87 "WebBrowserPage", |
|
88 "<p>Allow <b>{0}</b> to access your webcam?</p>", |
|
89 ), |
|
90 QWebEnginePermission.PermissionType.MediaAudioVideoCapture: QCoreApplication.translate( |
|
91 "WebBrowserPage", |
|
92 "<p>Allow <b>{0}</b> to access your microphone and webcam?</p>", |
|
93 ), |
|
94 QWebEnginePermission.PermissionType.MouseLock: QCoreApplication.translate( |
|
95 "WebBrowserPage", |
|
96 "<p>Allow <b>{0}</b> to lock your mouse cursor?</p>", |
|
97 ), |
|
98 QWebEnginePermission.PermissionType.DesktopVideoCapture: QCoreApplication.translate( |
|
99 "WebBrowserPage", |
|
100 "<p>Allow <b>{0}</b> to capture video of your desktop?</p>", |
|
101 ), |
|
102 QWebEnginePermission.PermissionType.DesktopAudioVideoCapture: QCoreApplication.translate( |
|
103 "WebBrowserPage", |
|
104 "<p>Allow <b>{0}</b> to capture audio and video of your desktop?</p>", |
|
105 ), |
|
106 QWebEnginePermission.PermissionType.Notifications: QCoreApplication.translate( |
|
107 "WebBrowserPage", |
|
108 "<p>Allow <b>{0}</b> to show notifications on your desktop?</p>", |
|
109 ), |
|
110 QWebEnginePermission.PermissionType.ClipboardReadWrite: QCoreApplication.translate( |
|
111 "WebBrowserPage", |
|
112 "<p>Allow <b>{0}</b> to read from and write to the clipboard?</p>", |
|
113 ), |
|
114 QWebEnginePermission.PermissionType.LocalFontsAccess: QCoreApplication.translate( |
|
115 "WebBrowserPage", |
|
116 "<p>Allow <b>{0}</b> to access fonts stored on this machine?</p>", |
|
117 ), |
|
118 } |
|
119 else: |
|
120 PermissionTypeQuestions = {} |
|
121 |
69 def __init__(self, view, parent=None): |
122 def __init__(self, view, parent=None): |
70 """ |
123 """ |
71 Constructor |
124 Constructor |
72 |
125 |
73 @param view reference to the WebBrowserView associated with the page |
126 @param view reference to the WebBrowserView associated with the page |
80 self.__printer = None |
133 self.__printer = None |
81 self.__badSite = False |
134 self.__badSite = False |
82 |
135 |
83 self.__view = view |
136 self.__view = view |
84 |
137 |
85 self.featurePermissionRequested.connect(self.__featurePermissionRequested) |
138 try: |
|
139 # Qt 6.8+ |
|
140 self.permissionRequested.connect(self.__permissionRequested) |
|
141 except AttributeError: |
|
142 # Qt <6.8 |
|
143 self.featurePermissionRequested.connect(self.__featurePermissionRequested) |
86 self.authenticationRequired.connect( |
144 self.authenticationRequired.connect( |
87 lambda url, auth: WebBrowserWindow.networkManager().authentication( |
145 lambda url, auth: WebBrowserWindow.networkManager().authentication( |
88 url, auth, self |
146 url, auth, self |
89 ) |
147 ) |
90 ) |
148 ) |
301 @param url url requesting the feature |
359 @param url url requesting the feature |
302 @type QUrl |
360 @type QUrl |
303 @param feature requested feature |
361 @param feature requested feature |
304 @type QWebEnginePage.Feature |
362 @type QWebEnginePage.Feature |
305 """ |
363 """ |
|
364 # Qt <6.8 |
306 manager = WebBrowserWindow.featurePermissionManager() |
365 manager = WebBrowserWindow.featurePermissionManager() |
307 manager.requestFeaturePermission(self, url, feature) |
366 manager.requestFeaturePermission(self, url, feature) |
|
367 |
|
368 def __permissionRequested(self, permission): |
|
369 """ |
|
370 Private slot handling a permission request. |
|
371 |
|
372 @param permission reference to the permission request object |
|
373 @type QWebEnginePermission |
|
374 """ |
|
375 # Qt 6.8+ |
|
376 question = self.PermissionTypeQuestions.get(permission.permissionType()) |
|
377 if question and EricMessageBox.yesNo( |
|
378 self.view(), |
|
379 self.tr("Permission Request"), |
|
380 question.format(permission.origin().host()), |
|
381 yesDefault=True, |
|
382 ): |
|
383 permission.grant() |
|
384 else: |
|
385 permission.deny() |
|
386 |
308 |
387 |
309 def execJavaScript( |
388 def execJavaScript( |
310 self, script, worldId=QWebEngineScript.ScriptWorldId.MainWorld, timeout=500 |
389 self, script, worldId=QWebEngineScript.ScriptWorldId.MainWorld, timeout=500 |
311 ): |
390 ): |
312 """ |
391 """ |
313 Public method to execute a JavaScript function synchroneously. |
392 Public method to execute a JavaScript function synchronously. |
314 |
393 |
315 @param script JavaScript script source to be executed |
394 @param script JavaScript script source to be executed |
316 @type str |
395 @type str |
317 @param worldId ID to run the script under |
396 @param worldId ID to run the script under |
318 @type QWebEngineScript.ScriptWorldId |
397 @type QWebEngineScript.ScriptWorldId |