qwebiconimageprovider.cpp [plain text]
#include "config.h"
#include "qwebiconimageprovider_p.h"
#include "QtWebContext.h"
#include "QtWebIconDatabaseClient.h"
#include <QtCore/QUrl>
#include <QtGui/QImage>
#include <wtf/text/WTFString.h>
using namespace WebKit;
QWebIconImageProvider::QWebIconImageProvider()
: QDeclarativeImageProvider(QDeclarativeImageProvider::Image)
{
}
QWebIconImageProvider::~QWebIconImageProvider()
{
}
QImage QWebIconImageProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize)
{
QString decodedIconUrl = id;
decodedIconUrl.remove(0, decodedIconUrl.indexOf('#') + 1);
String pageURL = QString::fromUtf8(QUrl(decodedIconUrl).toEncoded());
QString contextIDAsString = id;
contextIDAsString.truncate(contextIDAsString.indexOf(QLatin1Char('/')));
bool ok = false;
uint64_t contextId = contextIDAsString.toUInt(&ok);
if (!ok)
return QImage();
QtWebContext* context = QtWebContext::contextByID(contextId);
if (!context)
return QImage();
QtWebIconDatabaseClient* iconDatabase = context->iconDatabase();
QImage icon = requestedSize.isValid() ? iconDatabase->iconImageForPageURL(pageURL, requestedSize) : iconDatabase->iconImageForPageURL(pageURL);
ASSERT(!icon.isNull());
if (size)
*size = icon.size();
return icon;
}