ShibbolethWebView::ShibbolethWebView(Account* account, QWidget* parent) : QWebView(parent) , _account(account) , _accepted(false) , _cursorOverriden(false) { // no minimize setWindowFlags(Qt::Dialog); setAttribute(Qt::WA_DeleteOnClose); QWebPage* page = new QWebPage(this); page->setNetworkAccessManager(account->networkAccessManager()); connect(page, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); connect(page, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool))); connect(page->networkAccessManager()->cookieJar(), SIGNAL(newCookiesForUrl (QList<QNetworkCookie>, QUrl)), this, SLOT(onNewCookiesForUrl (QList<QNetworkCookie>, QUrl))); page->mainFrame()->load(account->url()); this->setPage(page); setWindowTitle(tr("%1 - Authenticate").arg(Theme::instance()->appNameGUI())); // If we have a valid cookie, it's most likely expired. We can use this as // as a criteria to tell the user why the browser window pops up QNetworkCookie shibCookie = ShibbolethCredentials::findShibCookie(_account, ShibbolethCredentials::accountCookies(_account)); if (shibCookie != QNetworkCookie()) { Logger::instance()->postOptionalGuiLog(tr("Reauthentication required"), tr("Your session has expired. You need to re-login to continue to use the client.")); } }
QNetworkAccessManager* QWebPageProto::networkAccessManager() const { QWebPage *item = qscriptvalue_cast<QWebPage*>(thisObject()); if (item) return item->networkAccessManager(); return 0; }
ShibbolethWebView::ShibbolethWebView(AccountPtr account, QWidget* parent) : QWebView(parent) , _account(account) , _accepted(false) , _cursorOverriden(false) { // no minimize setWindowFlags(Qt::Dialog); setAttribute(Qt::WA_DeleteOnClose); QWebPage* page = new QWebPage(this); connect(page, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); connect(page, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool))); // Make sure to accept the same SSL certificate issues as the regular QNAM we use for syncing QObject::connect(page->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), _account.data(), SLOT(slotHandleSslErrors(QNetworkReply*,QList<QSslError>))); // The Account keeps ownership of the cookie jar, it must outlive this webview. account->lendCookieJarTo(page->networkAccessManager()); connect(page->networkAccessManager()->cookieJar(), SIGNAL(newCookiesForUrl (QList<QNetworkCookie>, QUrl)), this, SLOT(onNewCookiesForUrl (QList<QNetworkCookie>, QUrl))); page->mainFrame()->load(account->url()); this->setPage(page); setWindowTitle(tr("%1 - Authenticate").arg(Theme::instance()->appNameGUI())); // If we have a valid cookie, it's most likely expired. We can use this as // as a criteria to tell the user why the browser window pops up QNetworkCookie shibCookie = ShibbolethCredentials::findShibCookie(_account.data(), ShibbolethCredentials::accountCookies(_account.data())); if (shibCookie != QNetworkCookie()) { Logger::instance()->postOptionalGuiLog(tr("Reauthentication required"), tr("Your session has expired. You need to re-login to continue to use the client.")); } ConfigFile config; QSettings settings(config.configFile()); resize(900, 700); // only effective the first time, later overridden by restoreGeometry restoreGeometry(settings.value(ShibbolethWebViewGeometryC).toByteArray()); }
void MainWindow::initWebViewAttributes() { QWebPage* page = webView->page(); // 使用系统代理 QNetworkProxyFactory::setUseSystemConfiguration(true); // 设置本地缓存 QNetworkDiskCache *diskCache = new QNetworkDiskCache(webView); QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); diskCache->setCacheDirectory(location); page->networkAccessManager()->setCache(diskCache); page->settings()->setMaximumPagesInCache(100); }
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; }