Changeset 145518 in webkit


Ignore:
Timestamp:
Mar 12, 2013 4:17:19 AM (11 years ago)
Author:
jocelyn.turcotte@digia.com
Message:

[Qt][WK2] Layer QtWebIconDatabaseClient on the C API
https://bugs.webkit.org/show_bug.cgi?id=109564

Reviewed by Simon Hausmann.
Signed off for WebKit2 by Benjamin Poulain.

  • Target.pri:
  • UIProcess/API/C/qt/WKIconDatabaseQt.cpp: Added.

(WKIconDatabaseTryGetQImageForURL):

  • New API added to get a QImage from the IconDatabase. Based on WKIconDatabaseCG.h/cpp
  • UIProcess/API/C/qt/WKIconDatabaseQt.h: Added.
  • UIProcess/API/cpp/qt/WKURLQt.cpp:

(WKURLCreateWithQString):
(WKURLCopyQString):
(WKURLCreateWithQUrl):
(WKURLCopyQUrl):

  • The WKUrlRef behind the scene is a WTF::String and encoding it back and forth to a QUrl can slightly change its string representation. Allow converting a WKUrlRef to and from a QString to ensure this.
  • UIProcess/API/cpp/qt/WKURLQt.h:
  • UIProcess/API/qt/qwebiconimageprovider.cpp:

(QWebIconImageProvider::iconURLForPageURLInContext):

  • The icon URL isn't accessible form the C API and shouldn't need to be. Use an ID incremented on each update to trigger an update of the QML Image component.

(QWebIconImageProvider::requestImage):

  • The IconDatabase was previously assumed to resize the image to the requested size, but this parameter is ignored, as stated in a comment in WebIconDatabase::imageForPageURL. Explicitely do the resize after fetching the original icon to also be able to report the original size properly to QtQuick.
  • UIProcess/API/qt/qwebiconimageprovider_p.h:
  • UIProcess/API/qt/tests/qmltests/WebView/tst_favIconLoad.qml:
    • Set the image to load asynchronously to further test the possibility of threading issues in QtWebIconDatabaseClient::iconImageForPageURL
    • Add a few barriers to fix some issues where the load succeeded signal would be wrongly catched by init() before the next test.
  • UIProcess/qt/QtWebContext.cpp:

(WebKit::QtWebContext::QtWebContext):

  • UIProcess/qt/QtWebIconDatabaseClient.cpp:

(WebKit):
(WebKit::QtWebIconDatabaseClient::QtWebIconDatabaseClient):
(WebKit::QtWebIconDatabaseClient::~QtWebIconDatabaseClient):
(WebKit::QtWebIconDatabaseClient::updateID):
(WebKit::QtWebIconDatabaseClient::didChangeIconForPageURL):
(WebKit::QtWebIconDatabaseClient::iconImageForPageURL):

  • Remove the Mutex. This mutex was useless given that it would only be locked from a single thread. Since the IconDatabase runs in its own thread, it already is thread-safe to access.

(WebKit::QtWebIconDatabaseClient::retainIconForPageURL):
(WebKit::QtWebIconDatabaseClient::releaseIconForPageURL):

  • UIProcess/qt/QtWebIconDatabaseClient.h:

(QtWebIconDatabaseClient):

  • WebKit2.pri:
Location:
trunk/Source/WebKit2
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r145517 r145518  
     12013-03-11  Jocelyn Turcotte  <jocelyn.turcotte@digia.com>
     2
     3        [Qt][WK2] Layer QtWebIconDatabaseClient on the C API
     4        https://bugs.webkit.org/show_bug.cgi?id=109564
     5
     6        Reviewed by Simon Hausmann.
     7        Signed off for WebKit2 by Benjamin Poulain.
     8
     9        * Target.pri:
     10        * UIProcess/API/C/qt/WKIconDatabaseQt.cpp: Added.
     11        (WKIconDatabaseTryGetQImageForURL):
     12          - New API added to get a QImage from the IconDatabase.
     13            Based on WKIconDatabaseCG.h/cpp
     14        * UIProcess/API/C/qt/WKIconDatabaseQt.h: Added.
     15        * UIProcess/API/cpp/qt/WKURLQt.cpp:
     16        (WKURLCreateWithQString):
     17        (WKURLCopyQString):
     18        (WKURLCreateWithQUrl):
     19        (WKURLCopyQUrl):
     20          - The WKUrlRef behind the scene is a WTF::String and encoding it back and forth to
     21            a QUrl can slightly change its string representation. Allow converting a WKUrlRef
     22            to and from a QString to ensure this.
     23        * UIProcess/API/cpp/qt/WKURLQt.h:
     24        * UIProcess/API/qt/qwebiconimageprovider.cpp:
     25        (QWebIconImageProvider::iconURLForPageURLInContext):
     26          - The icon URL isn't accessible form the C API and shouldn't need to be.
     27            Use an ID incremented on each update to trigger an update of the QML Image component.
     28        (QWebIconImageProvider::requestImage):
     29          - The IconDatabase was previously assumed to resize the image to the requested size,
     30            but this parameter is ignored, as stated in a comment in WebIconDatabase::imageForPageURL.
     31            Explicitely do the resize after fetching the original icon to also be able to report
     32            the original size properly to QtQuick.
     33        * UIProcess/API/qt/qwebiconimageprovider_p.h:
     34        * UIProcess/API/qt/tests/qmltests/WebView/tst_favIconLoad.qml:
     35          - Set the image to load asynchronously to further test the possibility of threading issues
     36            in QtWebIconDatabaseClient::iconImageForPageURL
     37          - Add a few barriers to fix some issues where the load succeeded signal would be wrongly
     38            catched by init() before the next test.
     39        * UIProcess/qt/QtWebContext.cpp:
     40        (WebKit::QtWebContext::QtWebContext):
     41        * UIProcess/qt/QtWebIconDatabaseClient.cpp:
     42        (WebKit):
     43        (WebKit::QtWebIconDatabaseClient::QtWebIconDatabaseClient):
     44        (WebKit::QtWebIconDatabaseClient::~QtWebIconDatabaseClient):
     45        (WebKit::QtWebIconDatabaseClient::updateID):
     46        (WebKit::QtWebIconDatabaseClient::didChangeIconForPageURL):
     47        (WebKit::QtWebIconDatabaseClient::iconImageForPageURL):
     48          - Remove the Mutex. This mutex was useless given that it would only
     49            be locked from a single thread. Since the IconDatabase runs in its own thread,
     50            it already is thread-safe to access.
     51        (WebKit::QtWebIconDatabaseClient::retainIconForPageURL):
     52        (WebKit::QtWebIconDatabaseClient::releaseIconForPageURL):
     53        * UIProcess/qt/QtWebIconDatabaseClient.h:
     54        (QtWebIconDatabaseClient):
     55        * WebKit2.pri:
     56
    1572013-03-11  Jocelyn Turcotte  <jocelyn.turcotte@digia.com>
    258
  • trunk/Source/WebKit2/Target.pri

    r145517 r145518  
    195195    UIProcess/API/C/WebKit2_C.h \
    196196    UIProcess/API/C/qt/WKNativeEvent.h \
     197    UIProcess/API/C/qt/WKIconDatabaseQt.h \
    197198    UIProcess/API/cpp/WKRetainPtr.h \
    198199    UIProcess/API/cpp/qt/WKStringQt.h \
     
    545546    UIProcess/API/C/WKTextChecker.cpp \
    546547    UIProcess/API/C/WKVibration.cpp \
     548    UIProcess/API/C/qt/WKIconDatabaseQt.cpp \
    547549    UIProcess/API/cpp/qt/WKStringQt.cpp \
    548550    UIProcess/API/cpp/qt/WKURLQt.cpp \
  • trunk/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.cpp

    r95901 r145518  
    2929using namespace WebKit;
    3030
    31 WKURLRef WKURLCreateWithQUrl(const QUrl& qURL)
     31WKURLRef WKURLCreateWithQString(const QString& url)
    3232{
    33     WTF::String urlString(qURL.toString());
    34     return toCopiedURLAPI(urlString);
     33    return toCopiedURLAPI(url);
     34}
     35
     36QString WKURLCopyQString(WKURLRef urlRef)
     37{
     38    if (!urlRef)
     39        return QString();
     40    return toImpl(urlRef)->string();
     41}
     42
     43WKURLRef WKURLCreateWithQUrl(const QUrl& url)
     44{
     45    return WKURLCreateWithQString(url.toString(QUrl::FullyEncoded));
    3546}
    3647
     
    3950    if (!urlRef)
    4051        return QUrl();
    41     const WTF::String& string = toImpl(urlRef)->string();
    42     return QUrl(QString(reinterpret_cast<const QChar*>(string.characters()), string.length()));
     52    return QUrl(WKURLCopyQString(urlRef));
    4353}
  • trunk/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.h

    r95901 r145518  
    2626#include <WebKit2/WKURL.h>
    2727
     28WK_EXPORT WKURLRef WKURLCreateWithQString(const QString& url);
     29WK_EXPORT QString WKURLCopyQString(WKURLRef url);
     30
    2831WK_EXPORT WKURLRef WKURLCreateWithQUrl(const QUrl& url);
    29 QUrl WKURLCopyQUrl(WKURLRef url);
     32WK_EXPORT QUrl WKURLCopyQUrl(WKURLRef url);
    3033
    3134#endif /* WKURLCF_h */
  • trunk/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp

    r145513 r145518  
    2525#include <QtCore/QUrl>
    2626#include <QtGui/QImage>
    27 #include <wtf/text/StringHash.h>
    28 #include <wtf/text/WTFString.h>
    2927
    3028using namespace WebKit;
     
    4240{
    4341    QtWebIconDatabaseClient* iconDatabase = context->iconDatabase();
    44     QUrl iconURL = iconDatabase->iconForPageURL(pageURL);
    4542
    46     if (iconURL.isEmpty())
     43    // Verify that the image data is actually available before reporting back
     44    // a url, since clients assume that the url can be used directly.
     45    if (iconDatabase->iconImageForPageURL(pageURL).isNull())
    4746        return QUrl();
    4847
     
    5049    url.setScheme(QStringLiteral("image"));
    5150    url.setHost(QWebIconImageProvider::identifier());
    52     // Make sure that QML doesn't show cached versions of the previous icon if the icon location changed.
    53     url.setPath(QLatin1Char('/') + QString::number(WTF::StringHash::hash(iconURL.toString())));
     51    // Make sure that QML doesn't show a cached previous version of the icon after it changed.
     52    url.setPath(QStringLiteral("/%1").arg(QtWebIconDatabaseClient::updateID()));
    5453
    5554    // FIXME: Use QUrl::DecodedMode when landed in Qt
     
    6968
    7069    QtWebIconDatabaseClient* iconDatabase = QtWebContext::defaultContext()->iconDatabase();
    71     if (!iconDatabase)
    72         return QImage();
     70    Q_ASSERT(iconDatabase);
    7371
    74     QImage icon = requestedSize.isValid() ? iconDatabase->iconImageForPageURL(pageURL, requestedSize) : iconDatabase->iconImageForPageURL(pageURL);
    75     ASSERT(!icon.isNull());
     72    QImage icon = iconDatabase->iconImageForPageURL(pageURL);
     73    Q_ASSERT(!icon.isNull());
    7674
    7775    if (size)
    7876        *size = icon.size();
    7977
     78    if (requestedSize.isValid())
     79        return icon.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
     80
    8081    return icon;
    8182}
  • trunk/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider_p.h

    r145512 r145518  
    2424#include <QString>
    2525#include <QtQuick/QQuickImageProvider>
    26 #include <wtf/text/WTFString.h>
    2726
    2827namespace WebKit {
  • trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_favIconLoad.qml

    r125291 r145518  
    1515    Image {
    1616        id: favicon
     17        asynchronous: true
    1718        source: webView.icon
    1819    }
     
    2728                // If this is not the first test, then load a blank page without favicon, restoring the initial state.
    2829                webView.url = 'about:blank'
     30                verify(webView.waitForLoadSucceeded())
    2931                spy.wait()
    30                 verify(webView.waitForLoadSucceeded())
    3132            }
    3233            spy.clear()
     
    3738            var url = Qt.resolvedUrl("../common/favicon.html")
    3839            webView.url = url
     40            verify(webView.waitForLoadSucceeded())
    3941            spy.wait()
    4042            compare(spy.count, 1)
     
    4749            var url = Qt.resolvedUrl("../common/favicon2.html?favicon=load should work with#whitespace!")
    4850            webView.url = url
     51            verify(webView.waitForLoadSucceeded())
    4952            spy.wait()
    5053            compare(spy.count, 1)
  • trunk/Source/WebKit2/UIProcess/qt/QtWebContext.cpp

    r145517 r145518  
    119119    : m_context(context)
    120120    , m_downloadManager(new QtDownloadManager(toImpl(context)))
    121     , m_iconDatabase(new QtWebIconDatabaseClient(toImpl(context)))
     121    , m_iconDatabase(new QtWebIconDatabaseClient(context))
    122122{
    123123}
  • trunk/Source/WebKit2/UIProcess/qt/QtWebIconDatabaseClient.cpp

    r145517 r145518  
    2121#include "QtWebIconDatabaseClient.h"
    2222
    23 #include "Image.h"
    24 #include "KURL.h"
    2523#include "QtWebContext.h"
    26 #include "SharedBuffer.h"
    27 #include "WKURLQt.h"
    28 #include "WebContext.h"
    29 #include "WebIconDatabase.h"
    3024#include <QtCore/QHash>
    3125#include <QtCore/QObject>
    3226#include <QtCore/QUrl>
    3327#include <QtGui/QImage>
     28#include <WKContext.h>
    3429#include <WKContextPrivate.h>
     30#include <WKIconDatabaseQt.h>
    3531#include <WKRetainPtr.h>
    3632#include <WKStringQt.h>
     33#include <WKURLQt.h>
    3734
    3835namespace WebKit {
     36
     37static unsigned s_updateId = 0;
    3938
    4039static inline QtWebIconDatabaseClient* toQtWebIconDatabaseClient(const void* clientInfo)
     
    4443}
    4544
    46 QtWebIconDatabaseClient::QtWebIconDatabaseClient(WebContext *context)
     45QtWebIconDatabaseClient::QtWebIconDatabaseClient(WKContextRef context)
    4746{
    48     m_iconDatabase = context->iconDatabase();
     47    m_iconDatabase = WKContextGetIconDatabase(context);
    4948
    5049    WKIconDatabaseClient iconDatabaseClient;
     
    5352    iconDatabaseClient.clientInfo = this;
    5453    iconDatabaseClient.didChangeIconForPageURL = didChangeIconForPageURL;
    55     WKIconDatabaseSetIconDatabaseClient(toAPI(m_iconDatabase.get()), &iconDatabaseClient);
     54    WKIconDatabaseSetIconDatabaseClient(m_iconDatabase, &iconDatabaseClient);
    5655    // Triggers the startup of the icon database.
    5756    WKRetainPtr<WKStringRef> path = adoptWK(WKStringCreateWithQString(QtWebContext::preparedStoragePath(QtWebContext::IconDatabaseStorage)));
    58     WKContextSetIconDatabasePath(toAPI(context), path.get());
     57    WKContextSetIconDatabasePath(context, path.get());
    5958}
    6059
    6160QtWebIconDatabaseClient::~QtWebIconDatabaseClient()
    6261{
    63     m_iconDatabase->close();
    64     WKIconDatabaseSetIconDatabaseClient(toAPI(m_iconDatabase.get()), 0);
     62    WKIconDatabaseClose(m_iconDatabase);
     63    WKIconDatabaseSetIconDatabaseClient(m_iconDatabase, 0);
     64}
     65
     66unsigned QtWebIconDatabaseClient::updateID()
     67{
     68    return s_updateId;
    6569}
    6670
    6771void QtWebIconDatabaseClient::didChangeIconForPageURL(WKIconDatabaseRef, WKURLRef pageURL, const void* clientInfo)
    6872{
    69     emit toQtWebIconDatabaseClient(clientInfo)->iconChangedForPageURL(toImpl(pageURL)->string());
     73    ++s_updateId;
     74    emit toQtWebIconDatabaseClient(clientInfo)->iconChangedForPageURL(WKURLCopyQString(pageURL));
    7075}
    7176
    72 QUrl QtWebIconDatabaseClient::iconForPageURL(const QString& pageURL)
     77QImage QtWebIconDatabaseClient::iconImageForPageURL(const QString& pageURL)
    7378{
    74     String iconURL;
    75     m_iconDatabase->synchronousIconURLForPageURL(pageURL, iconURL);
    76 
    77     if (iconURL.isEmpty())
    78         return QUrl();
    79 
    80     // Verify that the image data is actually available before reporting back
    81     // a url, since clients assume that the url can be used directly.
    82     WebCore::Image* iconImage = m_iconDatabase->imageForPageURL(pageURL);
    83     if (!iconImage || iconImage->isNull())
    84         return QUrl();
    85 
    86     return QUrl(iconURL);
    87 }
    88 
    89 QImage QtWebIconDatabaseClient::iconImageForPageURL(const QString& pageURL, const QSize& iconSize)
    90 {
    91     MutexLocker locker(m_imageLock);
    92 
    93     WebCore::IntSize size(iconSize.width(), iconSize.height());
    94 
    95     QPixmap* nativeImage = m_iconDatabase->nativeImageForPageURL(pageURL, size);
    96     if (!nativeImage)
    97         return QImage();
    98 
    99     return nativeImage->toImage();
     79    return WKIconDatabaseTryGetQImageForURL(m_iconDatabase, adoptWK(WKURLCreateWithQString(pageURL)).get());
    10080}
    10181
    10282void QtWebIconDatabaseClient::retainIconForPageURL(const QString& pageURL)
    10383{
    104     m_iconDatabase->retainIconForPageURL(pageURL);
     84    WKIconDatabaseRetainIconForURL(m_iconDatabase, adoptWK(WKURLCreateWithQString(pageURL)).get());
    10585}
    10686
    10787void QtWebIconDatabaseClient::releaseIconForPageURL(const QString& pageURL)
    10888{
    109     m_iconDatabase->releaseIconForPageURL(pageURL);
     89    WKIconDatabaseReleaseIconForURL(m_iconDatabase, adoptWK(WKURLCreateWithQString(pageURL)).get());
    11090}
    11191
  • trunk/Source/WebKit2/UIProcess/qt/QtWebIconDatabaseClient.h

    r145512 r145518  
    2222#define QtWebIconDatabaseClient_h
    2323
    24 #include "WKIconDatabase.h"
    2524#include "qwebkitglobal.h"
    2625#include <QtCore/QObject>
    27 #include <QtCore/QSize>
    28 #include <wtf/RefPtr.h>
    29 #include <wtf/Threading.h>
     26#include <WKIconDatabase.h>
    3027
    3128QT_BEGIN_NAMESPACE
     
    3633namespace WebKit {
    3734
    38 class WebContext;
    39 class WebIconDatabase;
    40 
    4135class QtWebIconDatabaseClient : public QObject {
    4236    Q_OBJECT
    4337
    4438public:
    45     QtWebIconDatabaseClient(WebContext*);
     39    QtWebIconDatabaseClient(WKContextRef);
    4640    ~QtWebIconDatabaseClient();
    4741
    48     QUrl iconForPageURL(const QString& pageURL);
    49     QImage iconImageForPageURL(const QString& pageURL, const QSize& iconSize = QSize(32, 32));
     42    QImage iconImageForPageURL(const QString&);
    5043
    5144    void retainIconForPageURL(const QString&);
    5245    void releaseIconForPageURL(const QString&);
     46
     47    static unsigned updateID();
    5348
    5449public:
     
    5752private:
    5853    static void didChangeIconForPageURL(WKIconDatabaseRef, WKURLRef pageURL, const void* clientInfo);
    59     RefPtr<WebKit::WebIconDatabase> m_iconDatabase;
    60     Mutex m_imageLock;
     54    WKIconDatabaseRef m_iconDatabase;
    6155};
    6256
  • trunk/Source/WebKit2/WebKit2.pri

    r141068 r145518  
    2929    $$SOURCE_DIR/UIProcess \
    3030    $$SOURCE_DIR/UIProcess/API/C \
     31    $$SOURCE_DIR/UIProcess/API/C/qt \
    3132    $$SOURCE_DIR/UIProcess/API/cpp \
    3233    $$SOURCE_DIR/UIProcess/API/cpp/qt \
Note: See TracChangeset for help on using the changeset viewer.