Changeset 145518 in webkit
- Timestamp:
- Mar 12, 2013 4:17:19 AM (11 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r145517 r145518 1 2013-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 1 57 2013-03-11 Jocelyn Turcotte <jocelyn.turcotte@digia.com> 2 58 -
trunk/Source/WebKit2/Target.pri
r145517 r145518 195 195 UIProcess/API/C/WebKit2_C.h \ 196 196 UIProcess/API/C/qt/WKNativeEvent.h \ 197 UIProcess/API/C/qt/WKIconDatabaseQt.h \ 197 198 UIProcess/API/cpp/WKRetainPtr.h \ 198 199 UIProcess/API/cpp/qt/WKStringQt.h \ … … 545 546 UIProcess/API/C/WKTextChecker.cpp \ 546 547 UIProcess/API/C/WKVibration.cpp \ 548 UIProcess/API/C/qt/WKIconDatabaseQt.cpp \ 547 549 UIProcess/API/cpp/qt/WKStringQt.cpp \ 548 550 UIProcess/API/cpp/qt/WKURLQt.cpp \ -
trunk/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.cpp
r95901 r145518 29 29 using namespace WebKit; 30 30 31 WKURLRef WKURLCreateWithQ Url(const QUrl& qURL)31 WKURLRef WKURLCreateWithQString(const QString& url) 32 32 { 33 WTF::String urlString(qURL.toString()); 34 return toCopiedURLAPI(urlString); 33 return toCopiedURLAPI(url); 34 } 35 36 QString WKURLCopyQString(WKURLRef urlRef) 37 { 38 if (!urlRef) 39 return QString(); 40 return toImpl(urlRef)->string(); 41 } 42 43 WKURLRef WKURLCreateWithQUrl(const QUrl& url) 44 { 45 return WKURLCreateWithQString(url.toString(QUrl::FullyEncoded)); 35 46 } 36 47 … … 39 50 if (!urlRef) 40 51 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)); 43 53 } -
trunk/Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.h
r95901 r145518 26 26 #include <WebKit2/WKURL.h> 27 27 28 WK_EXPORT WKURLRef WKURLCreateWithQString(const QString& url); 29 WK_EXPORT QString WKURLCopyQString(WKURLRef url); 30 28 31 WK_EXPORT WKURLRef WKURLCreateWithQUrl(const QUrl& url); 29 QUrl WKURLCopyQUrl(WKURLRef url);32 WK_EXPORT QUrl WKURLCopyQUrl(WKURLRef url); 30 33 31 34 #endif /* WKURLCF_h */ -
trunk/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider.cpp
r145513 r145518 25 25 #include <QtCore/QUrl> 26 26 #include <QtGui/QImage> 27 #include <wtf/text/StringHash.h>28 #include <wtf/text/WTFString.h>29 27 30 28 using namespace WebKit; … … 42 40 { 43 41 QtWebIconDatabaseClient* iconDatabase = context->iconDatabase(); 44 QUrl iconURL = iconDatabase->iconForPageURL(pageURL);45 42 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()) 47 46 return QUrl(); 48 47 … … 50 49 url.setScheme(QStringLiteral("image")); 51 50 url.setHost(QWebIconImageProvider::identifier()); 52 // Make sure that QML doesn't show cached versions of the previous icon if the icon locationchanged.53 url.setPath(Q Latin1Char('/') + 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())); 54 53 55 54 // FIXME: Use QUrl::DecodedMode when landed in Qt … … 69 68 70 69 QtWebIconDatabaseClient* iconDatabase = QtWebContext::defaultContext()->iconDatabase(); 71 if (!iconDatabase) 72 return QImage(); 70 Q_ASSERT(iconDatabase); 73 71 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()); 76 74 77 75 if (size) 78 76 *size = icon.size(); 79 77 78 if (requestedSize.isValid()) 79 return icon.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); 80 80 81 return icon; 81 82 } -
trunk/Source/WebKit2/UIProcess/API/qt/qwebiconimageprovider_p.h
r145512 r145518 24 24 #include <QString> 25 25 #include <QtQuick/QQuickImageProvider> 26 #include <wtf/text/WTFString.h>27 26 28 27 namespace WebKit { -
trunk/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_favIconLoad.qml
r125291 r145518 15 15 Image { 16 16 id: favicon 17 asynchronous: true 17 18 source: webView.icon 18 19 } … … 27 28 // If this is not the first test, then load a blank page without favicon, restoring the initial state. 28 29 webView.url = 'about:blank' 30 verify(webView.waitForLoadSucceeded()) 29 31 spy.wait() 30 verify(webView.waitForLoadSucceeded())31 32 } 32 33 spy.clear() … … 37 38 var url = Qt.resolvedUrl("../common/favicon.html") 38 39 webView.url = url 40 verify(webView.waitForLoadSucceeded()) 39 41 spy.wait() 40 42 compare(spy.count, 1) … … 47 49 var url = Qt.resolvedUrl("../common/favicon2.html?favicon=load should work with#whitespace!") 48 50 webView.url = url 51 verify(webView.waitForLoadSucceeded()) 49 52 spy.wait() 50 53 compare(spy.count, 1) -
trunk/Source/WebKit2/UIProcess/qt/QtWebContext.cpp
r145517 r145518 119 119 : m_context(context) 120 120 , m_downloadManager(new QtDownloadManager(toImpl(context))) 121 , m_iconDatabase(new QtWebIconDatabaseClient( toImpl(context)))121 , m_iconDatabase(new QtWebIconDatabaseClient(context)) 122 122 { 123 123 } -
trunk/Source/WebKit2/UIProcess/qt/QtWebIconDatabaseClient.cpp
r145517 r145518 21 21 #include "QtWebIconDatabaseClient.h" 22 22 23 #include "Image.h"24 #include "KURL.h"25 23 #include "QtWebContext.h" 26 #include "SharedBuffer.h"27 #include "WKURLQt.h"28 #include "WebContext.h"29 #include "WebIconDatabase.h"30 24 #include <QtCore/QHash> 31 25 #include <QtCore/QObject> 32 26 #include <QtCore/QUrl> 33 27 #include <QtGui/QImage> 28 #include <WKContext.h> 34 29 #include <WKContextPrivate.h> 30 #include <WKIconDatabaseQt.h> 35 31 #include <WKRetainPtr.h> 36 32 #include <WKStringQt.h> 33 #include <WKURLQt.h> 37 34 38 35 namespace WebKit { 36 37 static unsigned s_updateId = 0; 39 38 40 39 static inline QtWebIconDatabaseClient* toQtWebIconDatabaseClient(const void* clientInfo) … … 44 43 } 45 44 46 QtWebIconDatabaseClient::QtWebIconDatabaseClient(W ebContext *context)45 QtWebIconDatabaseClient::QtWebIconDatabaseClient(WKContextRef context) 47 46 { 48 m_iconDatabase = context->iconDatabase();47 m_iconDatabase = WKContextGetIconDatabase(context); 49 48 50 49 WKIconDatabaseClient iconDatabaseClient; … … 53 52 iconDatabaseClient.clientInfo = this; 54 53 iconDatabaseClient.didChangeIconForPageURL = didChangeIconForPageURL; 55 WKIconDatabaseSetIconDatabaseClient( toAPI(m_iconDatabase.get()), &iconDatabaseClient);54 WKIconDatabaseSetIconDatabaseClient(m_iconDatabase, &iconDatabaseClient); 56 55 // Triggers the startup of the icon database. 57 56 WKRetainPtr<WKStringRef> path = adoptWK(WKStringCreateWithQString(QtWebContext::preparedStoragePath(QtWebContext::IconDatabaseStorage))); 58 WKContextSetIconDatabasePath( toAPI(context), path.get());57 WKContextSetIconDatabasePath(context, path.get()); 59 58 } 60 59 61 60 QtWebIconDatabaseClient::~QtWebIconDatabaseClient() 62 61 { 63 m_iconDatabase->close(); 64 WKIconDatabaseSetIconDatabaseClient(toAPI(m_iconDatabase.get()), 0); 62 WKIconDatabaseClose(m_iconDatabase); 63 WKIconDatabaseSetIconDatabaseClient(m_iconDatabase, 0); 64 } 65 66 unsigned QtWebIconDatabaseClient::updateID() 67 { 68 return s_updateId; 65 69 } 66 70 67 71 void QtWebIconDatabaseClient::didChangeIconForPageURL(WKIconDatabaseRef, WKURLRef pageURL, const void* clientInfo) 68 72 { 69 emit toQtWebIconDatabaseClient(clientInfo)->iconChangedForPageURL(toImpl(pageURL)->string()); 73 ++s_updateId; 74 emit toQtWebIconDatabaseClient(clientInfo)->iconChangedForPageURL(WKURLCopyQString(pageURL)); 70 75 } 71 76 72 Q Url QtWebIconDatabaseClient::iconForPageURL(const QString& pageURL)77 QImage QtWebIconDatabaseClient::iconImageForPageURL(const QString& pageURL) 73 78 { 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()); 100 80 } 101 81 102 82 void QtWebIconDatabaseClient::retainIconForPageURL(const QString& pageURL) 103 83 { 104 m_iconDatabase->retainIconForPageURL(pageURL);84 WKIconDatabaseRetainIconForURL(m_iconDatabase, adoptWK(WKURLCreateWithQString(pageURL)).get()); 105 85 } 106 86 107 87 void QtWebIconDatabaseClient::releaseIconForPageURL(const QString& pageURL) 108 88 { 109 m_iconDatabase->releaseIconForPageURL(pageURL);89 WKIconDatabaseReleaseIconForURL(m_iconDatabase, adoptWK(WKURLCreateWithQString(pageURL)).get()); 110 90 } 111 91 -
trunk/Source/WebKit2/UIProcess/qt/QtWebIconDatabaseClient.h
r145512 r145518 22 22 #define QtWebIconDatabaseClient_h 23 23 24 #include "WKIconDatabase.h"25 24 #include "qwebkitglobal.h" 26 25 #include <QtCore/QObject> 27 #include <QtCore/QSize> 28 #include <wtf/RefPtr.h> 29 #include <wtf/Threading.h> 26 #include <WKIconDatabase.h> 30 27 31 28 QT_BEGIN_NAMESPACE … … 36 33 namespace WebKit { 37 34 38 class WebContext;39 class WebIconDatabase;40 41 35 class QtWebIconDatabaseClient : public QObject { 42 36 Q_OBJECT 43 37 44 38 public: 45 QtWebIconDatabaseClient(W ebContext*);39 QtWebIconDatabaseClient(WKContextRef); 46 40 ~QtWebIconDatabaseClient(); 47 41 48 QUrl iconForPageURL(const QString& pageURL); 49 QImage iconImageForPageURL(const QString& pageURL, const QSize& iconSize = QSize(32, 32)); 42 QImage iconImageForPageURL(const QString&); 50 43 51 44 void retainIconForPageURL(const QString&); 52 45 void releaseIconForPageURL(const QString&); 46 47 static unsigned updateID(); 53 48 54 49 public: … … 57 52 private: 58 53 static void didChangeIconForPageURL(WKIconDatabaseRef, WKURLRef pageURL, const void* clientInfo); 59 RefPtr<WebKit::WebIconDatabase> m_iconDatabase; 60 Mutex m_imageLock; 54 WKIconDatabaseRef m_iconDatabase; 61 55 }; 62 56 -
trunk/Source/WebKit2/WebKit2.pri
r141068 r145518 29 29 $$SOURCE_DIR/UIProcess \ 30 30 $$SOURCE_DIR/UIProcess/API/C \ 31 $$SOURCE_DIR/UIProcess/API/C/qt \ 31 32 $$SOURCE_DIR/UIProcess/API/cpp \ 32 33 $$SOURCE_DIR/UIProcess/API/cpp/qt \
Note: See TracChangeset
for help on using the changeset viewer.