def test_fake_profile(self, stubs):
        store = stubs.FakeCookieStore()
        profile = stubs.FakeWebEngineProfile(cookie_store=store)

        cookies.install_filter(profile)

        assert store.cookie_filter is cookies._accept_cookie
Пример #2
0
def _init_default_profile():
    """Init the default QWebEngineProfile."""
    global default_profile

    default_profile = QWebEngineProfile.defaultProfile()
    init_user_agent()

    default_profile.setter = ProfileSetter(  # type: ignore[attr-defined]
        default_profile)
    default_profile.setCachePath(os.path.join(standarddir.cache(),
                                              'webengine'))
    default_profile.setPersistentStoragePath(
        os.path.join(standarddir.data(), 'webengine'))
    default_profile.setter.init_profile()
    default_profile.setter.set_persistent_cookie_policy()

    _qute_scheme_handler.install(default_profile)
    _req_interceptor.install(default_profile)
    _download_manager.install(default_profile)
    cookies.install_filter(default_profile)

    # Clear visited links on web history clear
    history.web_history.history_cleared.connect(
        default_profile.clearAllVisitedLinks)
    history.web_history.url_cleared.connect(
        lambda url, profile=default_profile: profile.clearVisitedLinks([url]))
Пример #3
0
def _init_profile(profile: QWebEngineProfile) -> None:
    """Initialize a new QWebEngineProfile.

    This currently only contains the steps which are shared between a private and a
    non-private profile (at the moment, only the default profile).
    """
    profile.setter = ProfileSetter(profile)  # type: ignore[attr-defined]
    profile.setter.init_profile()

    _qute_scheme_handler.install(profile)
    _req_interceptor.install(profile)
    _download_manager.install(profile)
    cookies.install_filter(profile)

    # Clear visited links on web history clear
    history.web_history.history_cleared.connect(profile.clearAllVisitedLinks)
    history.web_history.url_cleared.connect(
        lambda url: profile.clearVisitedLinks([url]))

    _global_settings.init_settings()
Пример #4
0
def init():
    """Initialize QtWebEngine-specific modules."""
    # For some reason we need to keep a reference, otherwise the scheme handler
    # won't work...
    # https://www.riverbankcomputing.com/pipermail/pyqt/2016-September/038075.html
    global _qute_scheme_handler

    app = QApplication.instance()
    log.init.debug("Initializing qute://* handler...")
    _qute_scheme_handler = webenginequtescheme.QuteSchemeHandler(parent=app)
    _qute_scheme_handler.install(webenginesettings.default_profile)
    _qute_scheme_handler.install(webenginesettings.private_profile)

    log.init.debug("Initializing request interceptor...")
    host_blocker = objreg.get('host-blocker')
    args = objreg.get('args')
    req_interceptor = interceptor.RequestInterceptor(host_blocker,
                                                     args=args,
                                                     parent=app)
    req_interceptor.install(webenginesettings.default_profile)
    req_interceptor.install(webenginesettings.private_profile)

    log.init.debug("Initializing QtWebEngine downloads...")
    download_manager = webenginedownloads.DownloadManager(parent=app)
    download_manager.install(webenginesettings.default_profile)
    download_manager.install(webenginesettings.private_profile)
    objreg.register('webengine-download-manager', download_manager)

    log.init.debug("Initializing cookie filter...")
    cookies.install_filter(webenginesettings.default_profile)
    cookies.install_filter(webenginesettings.private_profile)

    # Clear visited links on web history clear
    hist = objreg.get('web-history')
    for p in [
            webenginesettings.default_profile,
            webenginesettings.private_profile
    ]:
        hist.history_cleared.connect(p.clearAllVisitedLinks)
        hist.url_cleared.connect(
            lambda url, profile=p: profile.clearVisitedLinks([url]))
Пример #5
0
def init_private_profile():
    """Init the private QWebEngineProfile."""
    global private_profile

    if not qtutils.is_single_process():
        private_profile = QWebEngineProfile()
        private_profile.setter = ProfileSetter(  # type: ignore[attr-defined]
            private_profile)
        assert private_profile.isOffTheRecord()
        private_profile.setter.init_profile()

        _qute_scheme_handler.install(private_profile)
        _req_interceptor.install(private_profile)
        _download_manager.install(private_profile)
        cookies.install_filter(private_profile)

        # Clear visited links on web history clear
        history.web_history.history_cleared.connect(
            private_profile.clearAllVisitedLinks)
        history.web_history.url_cleared.connect(
            lambda url, profile=private_profile: profile.clearVisitedLinks(
                [url]))
 def test_real_profile(self):
     profile = QWebEngineProfile()
     cookies.install_filter(profile)