diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-06-01 10:36:58 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-06-01 10:36:58 +0200 |
commit | b1e9e47fa11f608ae16bc07f97a2acf95bf80272 (patch) | |
tree | c88c45e80c9c44506e7cdf9a3bb39ebf82a8cd5b /Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp | |
parent | be01689f43cf6882cf670d33df49ead1f570c53a (diff) | |
download | qtwebkit-b1e9e47fa11f608ae16bc07f97a2acf95bf80272.tar.gz |
Imported WebKit commit 499c84c99aa98e9870fa7eaa57db476c6d160d46 (http://svn.webkit.org/repository/webkit/trunk@119200)
Weekly update :). Particularly relevant changes for Qt are the use of the WebCore image decoders and direct usage
of libpng/libjpeg if available in the system.
Diffstat (limited to 'Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp b/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp index 71342a1e3..63dce28d0 100644 --- a/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp @@ -24,6 +24,7 @@ #include "QtWebIconDatabaseClient.h" #include <QtCore/QUrl> #include <QtGui/QImage> +#include <wtf/text/StringHash.h> #include <wtf/text/WTFString.h> using namespace WebKit; @@ -37,24 +38,52 @@ QWebIconImageProvider::~QWebIconImageProvider() { } -QImage QWebIconImageProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize) +WTF::String QWebIconImageProvider::iconURLForPageURLInContext(const WTF::String &pageURL, QtWebContext* context) { - QString decodedIconUrl = id; - decodedIconUrl.remove(0, decodedIconUrl.indexOf('#') + 1); - String pageURL = QString::fromUtf8(QUrl(decodedIconUrl).toEncoded()); + QtWebIconDatabaseClient* iconDatabase = context->iconDatabase(); + WTF::String iconURL = iconDatabase->iconForPageURL(pageURL); + + if (iconURL.isEmpty()) + return String(); + + QUrl url; + url.setScheme(QStringLiteral("image")); + url.setHost(QWebIconImageProvider::identifier()); + + QString path; + path.append(QLatin1Char('/')); + path.append(QString::number(context->contextID())); + path.append(QLatin1Char('/')); + path.append(QString::number(WTF::StringHash::hash(iconURL))); + url.setPath(path); + + // FIXME: Use QUrl::DecodedMode when landed in Qt + url.setFragment(QString::fromLatin1(QByteArray(QString(pageURL).toUtf8()).toBase64())); + + // FIXME: We can't know when the icon url is no longer in use, + // so we never release these icons. At some point we might want + // to introduce expiry of icons to elevate this issue. + iconDatabase->retainIconForPageURL(pageURL); + return url.toString(QUrl::FullyEncoded); +} + +QImage QWebIconImageProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize) +{ // The string identifier has the leading image://webicon/ already stripped, so we just // need to truncate from the first slash to get the context id. - QString contextIDAsString = id; - contextIDAsString.truncate(contextIDAsString.indexOf(QLatin1Char('/'))); + QString contextIDString = id.left(id.indexOf(QLatin1Char('/'))); bool ok = false; - uint64_t contextId = contextIDAsString.toUInt(&ok); + uint64_t contextId = contextIDString.toUInt(&ok); if (!ok) return QImage(); + QtWebContext* context = QtWebContext::contextByID(contextId); if (!context) return QImage(); + QString pageURL = QString::fromUtf8(QByteArray::fromBase64(id.midRef(id.indexOf('#') + 1).toLatin1())); + QtWebIconDatabaseClient* iconDatabase = context->iconDatabase(); QImage icon = requestedSize.isValid() ? iconDatabase->iconImageForPageURL(pageURL, requestedSize) : iconDatabase->iconImageForPageURL(pageURL); ASSERT(!icon.isNull()); |