def __setGlobalLoadingImages(self, enable): """ Private slot to toggle the global images loading setting. @param enable flag indicating the state to set @type bool """ from WebBrowser.WebBrowserWindow import WebBrowserWindow WebBrowserWindow.webSettings().setAttribute( QWebEngineSettings.AutoLoadImages, enable) Preferences.setWebBrowser("AutoLoadImages", enable) Preferences.syncPreferences() self._window.preferencesChanged() self.__updateIcon() if not enable: # reload page upon disabling loading images self._window.currentBrowser().reload()
def isEnabled(cls): """ Class method to check, if the web inspector is enabled. @return flag indicating the enabled state @rtype bool """ if qVersionTuple() < (5, 11, 0): if not os.getenv("QTWEBENGINE_REMOTE_DEBUGGING"): return False from WebBrowser.WebBrowserWindow import WebBrowserWindow if not WebBrowserWindow.webSettings().testAttribute( QWebEngineSettings.JavascriptEnabled): return False if qVersionTuple() < (5, 11, 0): return Preferences.getWebBrowser("WebInspectorEnabled") else: return True
def acceptNavigationRequest(self, url, type_, isMainFrame): """ Public method to determine, if a request may be accepted. @param url URL to navigate to @type QUrl @param type_ type of the navigation request @type QWebEnginePage.NavigationType @param isMainFrame flag indicating, that the request originated from the main frame @type bool @return flag indicating acceptance @rtype bool """ scheme = url.scheme() if scheme == "mailto": QDesktopServices.openUrl(url) return False # AdBlock if url.scheme() == "abp": if WebBrowserWindow.adBlockManager().addSubscriptionFromUrl(url): return False # GreaseMonkey if PYQT_WEBENGINE_VERSION >= 0x50e00: # PyQtWebEngine >= 5.14.0 navigationType = type_ in [ QWebEnginePage.NavigationTypeLinkClicked, QWebEnginePage.NavigationTypeRedirect ] else: navigationType = type_ == QWebEnginePage.NavigationTypeLinkClicked if navigationType and url.toString().endswith(".user.js"): WebBrowserWindow.greaseMonkeyManager().downloadScript(url) return False if url.scheme() == "eric": if url.path() == "AddSearchProvider": query = QUrlQuery(url) self.view().mainWindow().openSearchManager().addEngine( QUrl(query.queryItemValue("url"))) return False elif url.path() == "PrintPage": self.printPageRequested.emit() return False # Safe Browsing self.__badSite = False from WebBrowser.SafeBrowsing.SafeBrowsingManager import ( SafeBrowsingManager) if (SafeBrowsingManager.isEnabled() and url.scheme() not in SafeBrowsingManager.getIgnoreSchemes()): threatLists = ( WebBrowserWindow.safeBrowsingManager().lookupUrl(url)[0]) if threatLists: threatMessages = (WebBrowserWindow.safeBrowsingManager(). getThreatMessages(threatLists)) res = E5MessageBox.warning( WebBrowserWindow.getWindow(), self.tr("Suspicuous URL detected"), self.tr("<p>The URL <b>{0}</b> was found in the Safe" " Browsing database.</p>{1}").format( url.toString(), "".join(threatMessages)), E5MessageBox.StandardButtons(E5MessageBox.Abort | E5MessageBox.Ignore), E5MessageBox.Abort) if res == E5MessageBox.Abort: self.safeBrowsingAbort.emit() return False self.__badSite = True threatType = ( WebBrowserWindow.safeBrowsingManager().getThreatType( threatLists[0])) self.safeBrowsingBad.emit(threatType, "".join(threatMessages)) result = QWebEnginePage.acceptNavigationRequest( self, url, type_, isMainFrame) if result: if isMainFrame: isWeb = url.scheme() in ("http", "https", "ftp", "ftps", "file") globalJsEnabled = WebBrowserWindow.webSettings().testAttribute( QWebEngineSettings.JavascriptEnabled) if isWeb: enable = globalJsEnabled else: enable = True self.settings().setAttribute( QWebEngineSettings.JavascriptEnabled, enable) self.__channelUrl = url self.__setupChannelTimer.start() self.navigationRequestAccepted.emit(url, type_, isMainFrame) return result