Exemple #1
0
    def _on_feature_permission_requested(self, frame, feature):
        """Ask the user for approval for geolocation/notifications."""
        if not isinstance(frame, QWebFrame):  # pragma: no cover
            # This makes no sense whatsoever, but someone reported this being
            # called with a QBuffer...
            log.misc.error("on_feature_permission_requested got called with "
                           "{!r}!".format(frame))
            return

        options = {
            QWebPage.Notifications: 'content.notifications',
            QWebPage.Geolocation: 'content.geolocation',
        }
        messages = {
            QWebPage.Notifications: 'show notifications',
            QWebPage.Geolocation: 'access your location',
        }
        yes_action = functools.partial(
            self.setFeaturePermission, frame, feature,
            QWebPage.PermissionGrantedByUser)
        no_action = functools.partial(
            self.setFeaturePermission, frame, feature,
            QWebPage.PermissionDeniedByUser)

        question = shared.feature_permission(
            url=frame.url(),
            option=options[feature], msg=messages[feature],
            yes_action=yes_action, no_action=no_action,
            abort_on=[self.shutting_down, self.loadStarted])

        if question is not None:
            self.featurePermissionRequestCanceled.connect(
                functools.partial(self._on_feature_permission_cancelled,
                                  question, frame, feature))
    def _on_feature_permission_requested(self, url, feature):
        """Ask the user for approval for geolocation/media/etc.."""
        options = {
            QWebEnginePage.Geolocation: ('content', 'geolocation'),
            QWebEnginePage.MediaAudioCapture: ('content', 'media-capture'),
            QWebEnginePage.MediaVideoCapture: ('content', 'media-capture'),
            QWebEnginePage.MediaAudioVideoCapture:
                ('content', 'media-capture'),
        }
        messages = {
            QWebEnginePage.Geolocation: 'access your location',
            QWebEnginePage.MediaAudioCapture: 'record audio',
            QWebEnginePage.MediaVideoCapture: 'record video',
            QWebEnginePage.MediaAudioVideoCapture: 'record audio/video',
        }
        assert options.keys() == messages.keys()

        if feature not in options:
            log.webview.error("Unhandled feature permission {}".format(
                debug.qenum_key(QWebEnginePage, feature)))
            self.setFeaturePermission(url, feature,
                                      QWebEnginePage.PermissionDeniedByUser)
            return

        yes_action = functools.partial(
            self.setFeaturePermission, url, feature,
            QWebEnginePage.PermissionGrantedByUser)
        no_action = functools.partial(
            self.setFeaturePermission, url, feature,
            QWebEnginePage.PermissionDeniedByUser)

        question = shared.feature_permission(
            url=url, option=options[feature], msg=messages[feature],
            yes_action=yes_action, no_action=no_action,
            abort_on=[self.shutting_down, self.loadStarted])

        if question is not None:
            self.featurePermissionRequestCanceled.connect(
                functools.partial(self._on_feature_permission_cancelled,
                                  question, url, feature))
Exemple #3
0
    def _on_feature_permission_requested(self, frame, feature):
        """Ask the user for approval for geolocation/notifications."""
        if not isinstance(frame, QWebFrame):  # pragma: no cover
            # This makes no sense whatsoever, but someone reported this being
            # called with a QBuffer...
            log.misc.error("on_feature_permission_requested got called with "
                           "{!r}!".format(frame))
            return

        options = {
            QWebPage.Notifications: 'content.notifications',
            QWebPage.Geolocation: 'content.geolocation',
        }
        messages = {
            QWebPage.Notifications: 'show notifications',
            QWebPage.Geolocation: 'access your location',
        }
        yes_action = functools.partial(self.setFeaturePermission, frame,
                                       feature,
                                       QWebPage.PermissionGrantedByUser)
        no_action = functools.partial(self.setFeaturePermission, frame,
                                      feature, QWebPage.PermissionDeniedByUser)

        url = frame.url().adjusted(QUrl.RemoveUserInfo | QUrl.RemovePath
                                   | QUrl.RemoveQuery |  # type: ignore
                                   QUrl.RemoveFragment)

        question = shared.feature_permission(
            url=url,
            option=options[feature],
            msg=messages[feature],
            yes_action=yes_action,
            no_action=no_action,
            abort_on=[self.shutting_down, self.loadStarted])

        if question is not None:
            self.featurePermissionRequestCanceled.connect(  # type: ignore
                functools.partial(self._on_feature_permission_cancelled,
                                  question, frame, feature))