Example #1
0
 def acceptNavigationRequest(self, url, type_, bool_):
     if self.delegate_links and \
             type_ == self.NavigationTypeLinkClicked and \
             url.url().startswith("om://"):
         LOGGER.debug("acceptNavigationRequest %s", url)
         self.parent().linkClicked.emit(url)
         return False
     return QWebEnginePage.acceptNavigationRequest(
         self, url, type_, bool_)
Example #2
0
 def acceptNavigationRequest(self, url, _type, isMainFrame):
     #print("acceptNavigationRequest")
     # print(url)
     return QWebEnginePage.acceptNavigationRequest(self, url, _type,
                                                   isMainFrame)
Example #3
0
 def acceptNavigationRequest(self, url, type_, bool_):
     if self.delegate_links and type_ == self.NavigationTypeLinkClicked and url.url().startswith("om://"):
         LOGGER.debug("acceptNavigationRequest %s", url)
         self.parent().linkClicked.emit(url)
         return False
     return QWebEnginePage.acceptNavigationRequest(self, url, type_, bool_)
Example #4
0
 def acceptNavigationRequest(self, url, _type, isMainFrame):
     print([url, url.scheme(), url.path(), url.query()])
     return QWebEnginePage.acceptNavigationRequest(self, url, _type, isMainFrame)
Example #5
0
    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