--- a/browsercore/core/network/webnetworkaccessmanager.cpp Fri May 14 15:40:36 2010 +0300
+++ b/browsercore/core/network/webnetworkaccessmanager.cpp Wed Jun 23 17:59:43 2010 +0300
@@ -1,30 +1,34 @@
/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, version 2.1 of the License.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
*
-* Contributors:
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program. If not,
+* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
*
-* Description:
+* Description:
*
*/
-
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QAuthenticator>
+#include <QNetworkInterface>
#if QT_VERSION >= 0x040500
#include <QNetworkDiskCache>
+// #include "networkdiskcache.h"
#endif
-//#include "wrtsettings.h"
#include "bedrockprovisioning.h"
#include "wrtbrowsercontainer.h"
#include "webcookiejar.h"
@@ -34,7 +38,7 @@
#include "networkerrorreply.h"
#include "SchemeHandlerBr.h"
-#include "qwebframe.h"
+#include <QWebFrame>
namespace WRT {
@@ -44,49 +48,51 @@
m_reply = NULL;
this->setCookieJar(m_cookieJar);
connect(this, SIGNAL(authenticationRequired(QNetworkReply *, QAuthenticator *)), m_browserContainer, SLOT(slotAuthenticationRequired(QNetworkReply *, QAuthenticator *)));
-
connect(this, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy & , QAuthenticator * )), m_browserContainer, SLOT(slotProxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)));
+ connect(this, SIGNAL(finished(QNetworkReply *)), this, SLOT(onfinished(QNetworkReply *)));
setupCache();
setupNetworkProxy();
}
-#ifdef NETWORK_DEBUG
-void WebNetworkAccessManager::error(QNetworkReply::NetworkError)
+int WebNetworkAccessManager::activeNetworkInterfaces()
+{
+ int count = 0;
+ QList<QNetworkInterface> allNIFs = QNetworkInterface::allInterfaces();
+ foreach (QNetworkInterface aNIF, allNIFs) {
+ if (aNIF.isValid() && aNIF.flags() & QNetworkInterface::IsUp && !(aNIF.flags() & QNetworkInterface::IsLoopBack))
+ count++;
+ }
+ return count;
+}
+
+void WebNetworkAccessManager::onfinished(QNetworkReply* reply)
{
-// qDebug() << "Network::error:" << n_reply->error() << " String:" << n_reply->errorString();
-// QString errorNumber = QString::number(n_reply->error() );
- QNetworkReply::NetworkError error = n_reply->error();
-
- if ( error != 5 && error != 0 )
- {
- switch ( error )
- {
- case QNetworkReply::HostNotFoundError:
- WebDialogProvider::showTimedMessage(NULL, "No Connection ", 2000);
- break;
- /*
- // ContentNotFoundError cause many problems. For now, we ignore
- // TODO: We will find more graceful way to handle this error
- case QNetworkReply::ContentNotFoundError:
- WebDialogProvider::showTimedMessage(NULL, "Content Not Found", 2000);
- break;
- */
- case QNetworkReply::ProtocolUnknownError:
- WebDialogProvider::showTimedMessage(NULL, "Protocol Unknown", 2000);
- break;
-
- default:
- break; // Ignore other error msgs
+ QNetworkReply::NetworkError networkError = reply->error();
+ QString replyUrl = reply->url().toString();
+
+ if ( networkError != QNetworkReply::OperationCanceledError &&
+ networkError != QNetworkReply::NoError )
+ {
+ QString errorMsg = reply->errorString();
+ if ( activeNetworkInterfaces() == 0 ) {
+ errorMsg = "Network not available";
+ } else {
+ int httpErrorCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ if ( httpErrorCode ) {
+ QString httpErrorStr = QString ("HTTP %1 ").arg(httpErrorCode);
+ QString httpReasonStr = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
+ errorMsg = httpErrorStr + httpReasonStr;
+ }
+ }
+ emit networkErrorHappened(errorMsg);
+ emit networkErrorUrl(replyUrl);
}
- }
- return;
}
-#endif
WebNetworkAccessManager::~WebNetworkAccessManager()
{
delete m_cookieJar;
- //setCache(NULL);
+ setCache(NULL);
delete m_reply;
}
@@ -95,6 +101,11 @@
QNetworkRequest req = request;
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
+ // improve performance by
+ // load from cache if available, otherwise load from network.
+ // Note that this can return possibly stale (but not expired) items from cache.
+ // QNetworkRequest::PreferNetwork is default value
+ req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
if (m_reply != NULL) {
delete m_reply;
@@ -125,11 +136,7 @@
if (reply == NULL) {
reply = createRequestHelper(op, req, outgoingData);
}
-#ifdef NETWORK_DEBUG
- n_reply = reply;
- connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
- this, SLOT(error(QNetworkReply::NetworkError)));
-#endif
+
return reply;
}
@@ -204,6 +211,7 @@
#if QT_VERSION >= 0x040500
qDiskCache = new QNetworkDiskCache(this);
+// qDiskCache = new NetworkDiskCache(this);
if ( !BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("DiskCacheEnabled").toBool() )
return;