from django.utils.deprecation import MiddlewareMixin


class ContentSecurityPolicyMiddleware(MiddlewareMixin):
    def process_response(self, request, response):
        directives = [
            "default-src 'self'",
            "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://translate.google.com https://translate.googleapis.com https://translate.googleusercontent.com https://www.gstatic.com https://www.google.com https://cdn.jsdelivr.net",
            "style-src 'self' 'unsafe-inline' https://translate.googleapis.com https://fonts.googleapis.com https://www.gstatic.com",
            "img-src 'self' data: https:",
            "font-src 'self' data: https://translate.googleapis.com https://fonts.gstatic.com",
            "frame-src 'self' https://translate.google.com https://translate.googleapis.com",
            "connect-src 'self' https://translate.googleapis.com https://translate.google.com https://www.gstatic.com",
            "object-src 'none'",
            "base-uri 'self'",
        ]
        response['Content-Security-Policy'] = '; '.join(directives)
        return response
