예제 #1
0
bool thirdPartyCookiePolicyPermits(QNetworkCookieJar* jar, const QUrl& url, const QUrl& firstPartyUrl)
{
#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
    if (firstPartyUrl.isEmpty())
        return true;

    if (urlsShareSameDomain(url, firstPartyUrl))
        return true;

    switch (QWebSettings::globalSettings()->thirdPartyCookiePolicy()) {
    case QWebSettings::AlwaysAllowThirdPartyCookies:
        return true;
    case QWebSettings::AlwaysBlockThirdPartyCookies:
        return false;
    case QWebSettings::AllowThirdPartyWithExistingCookies: {
        QList<QNetworkCookie> cookies = jar->cookiesForUrl(url);
        return !cookies.isEmpty();
    }
    default:
        return false;
    }
#else
    return true;
#endif
}
예제 #2
0
bool thirdPartyCookiePolicyPermits(NetworkingContext* context, const QUrl& url, const QUrl& firstPartyUrl)
{
#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
    if (!context)
        return true;

    if (!context->networkAccessManager())
        return true;

    QNetworkCookieJar* jar = context->networkAccessManager()->cookieJar();
    if (!jar)
        return true;

    if (firstPartyUrl.isEmpty())
        return true;

    if (urlsShareSameDomain(url, firstPartyUrl))
        return true;

    return context->thirdPartyCookiePolicyPermission(url);
#else
    return true;
#endif
}