aboutsummaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets/simplebrowser/webpage.py
blob: 2f2800a172cf8e1880eecb2f79b459b3d03dc2e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

from functools import partial

from PySide6.QtWebEngineCore import QWebEnginePage, QWebEngineCertificateError
from PySide6.QtCore import QTimer, Signal


class WebPage(QWebEnginePage):

    create_certificate_error_dialog = Signal(QWebEngineCertificateError)

    def __init__(self, profile, parent):
        super().__init__(profile, parent)

        self.selectClientCertificate.connect(self.handle_select_client_certificate)
        self.certificateError.connect(self.handle_certificate_error)

    def _emit_create_certificate_error_dialog(self, error):
        self.create_certificate_error_dialog.emit(error)

    def handle_certificate_error(self, error):
        error.defer()
        QTimer.singleShot(0, partial(self._emit_create_certificate_error_dialog, error))

    def handle_select_client_certificate(self, selection):
        # Just select one.
        selection.select(selection.certificates()[0])