Cookies settings refactor

See ticket #21051 (https://code.djangoproject.com/ticket/21051#ticket)