本文整理汇总了C++中QNetworkAccessManager::cookieJar方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkAccessManager::cookieJar方法的具体用法?C++ QNetworkAccessManager::cookieJar怎么用?C++ QNetworkAccessManager::cookieJar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkAccessManager
的用法示例。
在下文中一共展示了QNetworkAccessManager::cookieJar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cookieJar
static QNetworkCookieJar* cookieJar(QObject* originatingFrame)
{
if (!originatingFrame)
return 0;
QWebFrame* frame = qobject_cast<QWebFrame*>(originatingFrame);
if (!frame)
return 0;
QNetworkAccessManager* manager = frame->page()->networkAccessManager();
QNetworkCookieJar* jar = manager->cookieJar();
return jar;
}
示例2:
static QNetworkCookieJar *cookieJar(const Document *document)
{
Frame *frame = document->frame();
if (!frame)
return 0;
FrameLoader *loader = frame->loader();
if (!loader)
return 0;
QWebFrame* webFrame = static_cast<FrameLoaderClientQt*>(loader->client())->webFrame();
QWebPage* page = webFrame->page();
QNetworkAccessManager* manager = page->networkAccessManager();
QNetworkCookieJar* jar = manager->cookieJar();
return jar;
}
示例3: load
void MediaPlayerPrivate::load(const String& url)
{
// We are now loading
if (m_networkState != MediaPlayer::Loading) {
m_networkState = MediaPlayer::Loading;
m_player->networkStateChanged();
}
// And we don't have any data yet
if (m_readyState != MediaPlayer::HaveNothing) {
m_readyState = MediaPlayer::HaveNothing;
m_player->readyStateChanged();
}
const QUrl rUrl = QUrl(QString(url));
const QString scheme = rUrl.scheme().toLower();
// Grab the client media element
HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
// Construct the media content with a network request if the resource is http[s]
if (scheme == "http" || scheme == "https") {
QNetworkRequest request = QNetworkRequest(rUrl);
// Grab the current document
Document* document = element->document();
if (!document)
document = element->ownerDocument();
// Grab the frame and network manager
Frame* frame = document ? document->frame() : 0;
FrameLoaderClientQt* frameLoader = frame ? static_cast<FrameLoaderClientQt*>(frame->loader()->client()) : 0;
QNetworkAccessManager* manager = frameLoader ? frameLoader->webFrame()->page()->networkAccessManager() : 0;
if (document && manager) {
// Set the cookies
QNetworkCookieJar* jar = manager->cookieJar();
QList<QNetworkCookie> cookies = jar->cookiesForUrl(rUrl);
// Don't set the header if there are no cookies.
// This prevents a warning from being emitted.
if (!cookies.isEmpty())
request.setHeader(QNetworkRequest::CookieHeader, qVariantFromValue(cookies));
// Set the refferer, but not when requesting insecure content from a secure page
QUrl documentUrl = QUrl(QString(document->documentURI()));
if (documentUrl.scheme().toLower() == "http" || scheme == "https")
request.setRawHeader("Referer", documentUrl.toEncoded());
// Set the user agent
request.setRawHeader("User-Agent", frameLoader->userAgent(rUrl).utf8().data());
}
m_mediaPlayer->setMedia(QMediaContent(request));
} else {
// Otherwise, just use the URL
m_mediaPlayer->setMedia(QMediaContent(rUrl));
}
// Set the current volume and mute status
// We get these from the element, rather than the player, in case we have
// transitioned from a media engine which doesn't support muting, to a media
// engine which does.
m_mediaPlayer->setMuted(element->muted());
m_mediaPlayer->setVolume(static_cast<int>(element->volume() * 100.0));
}
示例4: commitLoad
void MediaPlayerPrivateQt::commitLoad(const String& url)
{
// We are now loading
if (m_networkState != MediaPlayer::Loading) {
m_networkState = MediaPlayer::Loading;
m_webCorePlayer->networkStateChanged();
}
// And we don't have any data yet
if (m_readyState != MediaPlayer::HaveNothing) {
m_readyState = MediaPlayer::HaveNothing;
m_webCorePlayer->readyStateChanged();
}
KURL kUrl(ParsedURLString, url);
const QUrl rUrl = kUrl;
const QString scheme = rUrl.scheme().toLower();
// Grab the client media element
HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient());
// Construct the media content with a network request if the resource is http[s]
if (scheme == QString::fromLatin1("http") || scheme == QString::fromLatin1("https")) {
QNetworkRequest request = QNetworkRequest(rUrl);
// Grab the current document
Document* document = element->document();
if (!document)
document = element->ownerDocument();
// Grab the frame and network manager
Frame* frame = document ? document->frame() : 0;
FrameLoader* frameLoader = frame ? frame->loader() : 0;
QNetworkAccessManager* manager = frameLoader ? frameLoader->networkingContext()->networkAccessManager() : 0;
if (manager) {
// Set the cookies
QNetworkCookieJar* jar = manager->cookieJar();
QList<QNetworkCookie> cookies = jar->cookiesForUrl(rUrl);
// Don't set the header if there are no cookies.
// This prevents a warning from being emitted.
if (!cookies.isEmpty())
request.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue(cookies));
// Set the refferer, but not when requesting insecure content from a secure page
QUrl documentUrl = QUrl(QString(document->documentURI()));
if (documentUrl.scheme().toLower() == QString::fromLatin1("http") || scheme == QString::fromLatin1("https"))
request.setRawHeader("Referer", documentUrl.toEncoded());
// Set the user agent
request.setRawHeader("User-Agent", frameLoader->userAgent(rUrl).utf8().data());
}
m_mediaPlayer->setMedia(QMediaContent(request));
} else {
// Otherwise, just use the URL
m_mediaPlayer->setMedia(QMediaContent(rUrl));
}
// Set the current volume and mute status
// We get these from the element, rather than the player, in case we have
// transitioned from a media engine which doesn't support muting, to a media
// engine which does.
m_mediaPlayer->setMuted(element->muted());
m_mediaPlayer->setVolume(static_cast<int>(element->volume() * 100.0));
// Don't send PlaybackChanged notification for pre-roll.
m_suppressNextPlaybackChanged = true;
// Setting a media source will start loading the media, but we need
// to pre-roll as well to get video size-hints and buffer-status
if (element->paused())
m_mediaPlayer->pause();
else
m_mediaPlayer->play();
}