Exemple #1
0
def dictionary_dir(old=False):
    """Return the path (str) to the QtWebEngine's dictionaries directory."""
    if qtutils.version_check('5.10', compiled=False) and not old:
        datapath = standarddir.data()
    else:
        datapath = QLibraryInfo.location(QLibraryInfo.DataPath)
    return os.path.join(datapath, 'qtwebengine_dictionaries')
    def _check_initiator(self, job):
        """Check whether the initiator of the job should be allowed.

        Only the browser itself or luminos:// pages should access any of those
        URLs. The request interceptor further locks down luminos://settings/set.

        Args:
            job: QWebEngineUrlRequestJob

        Return:
            True if the initiator is allowed, False if it was blocked.
        """
        try:
            initiator = job.initiator()
            request_url = job.requestUrl()
        except AttributeError:
            # Added in Qt 5.11
            return True

        # https://codereview.qt-project.org/#/c/234849/
        is_opaque = initiator == QUrl("null")
        target = request_url.scheme(), request_url.host()

        if is_opaque and not qtutils.version_check("5.12"):
            # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-70421
            # When we don't register the luminos:// scheme, all requests are
            # flagged as opaque.
            return True

        if (target == ("luminos", "testdata") and is_opaque
                and qtutils.version_check("5.12")):
            # Allow requests to qute://testdata, as this is needed in Qt 5.12
            # for all tests to work properly. No qute://testdata handler is
            # installed outside of tests.
            return True

        if initiator.isValid() and initiator.scheme(
        ) != "luminos" and initiator.scheme() not in self.schemes.keys():
            log.webview.warning(
                "Blocking malicious request from {} to {}".format(
                    initiator.toDisplayString(),
                    request_url.toDisplayString()))
            job.fail(QWebEngineUrlRequestJob.RequestDenied)
            return False

        return True
    def install(self, profile, schemes):
        self.schemes = schemes
        """Install the handler for luminos:// URLs on the given profile."""
        if QWebEngineUrlScheme is not None:
            assert QWebEngineUrlScheme.schemeByName(b"luminos").name()

        profile.installUrlSchemeHandler(b"luminos", self)

        for scheme in schemes.keys():
            if QWebEngineUrlScheme.schemeByName(scheme.encode("ascii")).name():
                profile.installUrlSchemeHandler(scheme.encode("ascii"), self)

        if qtutils.version_check("5.11",
                                 compiled=False) and not qtutils.version_check(
                                     "5.12", compiled=False):
            # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-63378
            profile.installUrlSchemeHandler(b"chrome-error", self)
            profile.installUrlSchemeHandler(b"chrome-extension", self)
Exemple #4
0
def init():
    """Initialize the dictionary path if supported."""
    if qtutils.version_check('5.10', compiled=False):
        new_dir = dictionary_dir()
        old_dir = dictionary_dir(old=True)
        os.environ['QTWEBENGINE_DICTIONARIES_PATH'] = new_dir
        try:
            if os.path.exists(old_dir) and not os.path.exists(new_dir):
                shutil.copytree(old_dir, new_dir)
        except OSError:
            log.misc.exception("Failed to copy old dictionaries")
 def javaScriptPrompt(self, url, js_msg, defaultValue):
     """Override javaScriptPrompt to use luminos prompts."""
     escape_msg = qtutils.version_check('5.11', compiled=False)
     if self._isShuttingDown:
         return (False, "")
     try:
         return Shared.javascript_prompt(url, js_msg, defaultValue,
                                         abort_on=[self.loadStarted,
                                                   self.shuttingDown],
                                         escape_msg=escape_msg)
     except Shared.CallSuper:
         return super().javaScriptPrompt(url, js_msg, defaultValue)
 def javaScriptAlert(self, securityOrigin, js_msg):
     """Override javaScriptAlert to use luminos prompts."""
     if self._isShuttingDown:
         return
     escape_msg = qtutils.version_check('5.11', compiled=False)
     try:
         Shared.javascript_alert(securityOrigin, js_msg,
                                 abort_on=[self.loadStarted,
                                           self.shuttingDown],
                                 escape_msg=escape_msg)
     except Shared.CallSuper:
         super().javaScriptAlert(securityOrigin, js_msg)
Exemple #7
0
    def _updateSettings(self, option, value):
        """Update global settings when qwebsettings changed."""
        self.settings.updateSetting(option)

        if option in ['content.headers.user_agent',
                      'content.headers.accept_language']:
            self.profile.setter.set_http_headers()
        elif option == 'content.cache.size':
            self.profile.setter.set_http_cache_size()
        elif (option == 'content.cookies.store' and qtutils.version_check('5.9', compiled=False)):  # https://bugreports.qt.io/browse/QTBUG-58650
            self.setter.set_persistent_cookie_policy()
        elif option == 'spellcheck.languages':
            self.profile.setter.set_dictionary_language()
    def init_profile(self):
        """Initialize settings on the given profile."""
        self.set_http_headers()
        self.set_http_cache_size()

        settings = self._profile.settings()
        settings.setAttribute(QWebEngineSettings.FullScreenSupportEnabled,
                              True)
        try:
            settings.setAttribute(QWebEngineSettings.FocusOnNavigationEnabled,
                                  False)
        except AttributeError:
            # Added in Qt 5.8
            pass

        if qtutils.version_check('5.8'):
            self.set_dictionary_language()