[Qt][WK2] Layer QtDownloadManager on the C API
authorjocelyn.turcotte@digia.com <jocelyn.turcotte@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2013 11:18:29 +0000 (11:18 +0000)
committerjocelyn.turcotte@digia.com <jocelyn.turcotte@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2013 11:18:29 +0000 (11:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109562

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

* UIProcess/API/cpp/qt/WKURLQt.cpp:
(WebKit::adoptToQString):
(WebKit):
(WebKit::adoptToQUrl):
* UIProcess/API/cpp/qt/WKURLQt.h:
(WebKit):
* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::handleDownloadRequest):
* UIProcess/qt/QtDownloadManager.cpp:
(WebKit::toQtDownloadManager):
(WebKit):
(WebKit::QtDownloadManager::QtDownloadManager):
(WebKit::QtDownloadManager::addDownload):
(WebKit::QtDownloadManager::didReceiveResponse):
(WebKit::QtDownloadManager::didCreateDestination):
(WebKit::QtDownloadManager::didFinishDownload):
(WebKit::QtDownloadManager::didFailDownload):
(WebKit::QtDownloadManager::didReceiveDataForDownload):
* UIProcess/qt/QtDownloadManager.h:
(WebKit):
(QtDownloadManager):
* UIProcess/qt/QtWebContext.cpp:
(WebKit::QtWebContext::QtWebContext):
* UIProcess/qt/QtWebError.cpp:
(WebKit::QtWebError::url):
(WebKit::QtWebError::description):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@145519 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.cpp
Source/WebKit2/UIProcess/API/cpp/qt/WKURLQt.h
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/qt/QtDownloadManager.cpp
Source/WebKit2/UIProcess/qt/QtDownloadManager.h
Source/WebKit2/UIProcess/qt/QtWebContext.cpp
Source/WebKit2/UIProcess/qt/QtWebError.cpp

index 937665f..028f18c 100644 (file)
@@ -1,5 +1,40 @@
 2013-03-11  Jocelyn Turcotte  <jocelyn.turcotte@digia.com>
 
+        [Qt][WK2] Layer QtDownloadManager on the C API
+        https://bugs.webkit.org/show_bug.cgi?id=109562
+
+        Reviewed by Simon Hausmann.
+        Signed off for WebKit2 by Benjamin Poulain.
+
+        * UIProcess/API/cpp/qt/WKURLQt.cpp:
+        (WebKit::adoptToQString):
+        (WebKit):
+        (WebKit::adoptToQUrl):
+        * UIProcess/API/cpp/qt/WKURLQt.h:
+        (WebKit):
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::handleDownloadRequest):
+        * UIProcess/qt/QtDownloadManager.cpp:
+        (WebKit::toQtDownloadManager):
+        (WebKit):
+        (WebKit::QtDownloadManager::QtDownloadManager):
+        (WebKit::QtDownloadManager::addDownload):
+        (WebKit::QtDownloadManager::didReceiveResponse):
+        (WebKit::QtDownloadManager::didCreateDestination):
+        (WebKit::QtDownloadManager::didFinishDownload):
+        (WebKit::QtDownloadManager::didFailDownload):
+        (WebKit::QtDownloadManager::didReceiveDataForDownload):
+        * UIProcess/qt/QtDownloadManager.h:
+        (WebKit):
+        (QtDownloadManager):
+        * UIProcess/qt/QtWebContext.cpp:
+        (WebKit::QtWebContext::QtWebContext):
+        * UIProcess/qt/QtWebError.cpp:
+        (WebKit::QtWebError::url):
+        (WebKit::QtWebError::description):
+
+2013-03-11  Jocelyn Turcotte  <jocelyn.turcotte@digia.com>
+
         [Qt][WK2] Layer QtWebIconDatabaseClient on the C API
         https://bugs.webkit.org/show_bug.cgi?id=109564
 
index 0bda880..f9177fd 100644 (file)
@@ -22,6 +22,7 @@
 #include "WKURLQt.h"
 
 #include "WKAPICast.h"
+#include "WKRetainPtr.h"
 #include <QString>
 #include <wtf/RefPtr.h>
 #include <wtf/text/WTFString.h>
@@ -51,3 +52,15 @@ QUrl WKURLCopyQUrl(WKURLRef urlRef)
         return QUrl();
     return QUrl(WKURLCopyQString(urlRef));
 }
+
+namespace WebKit {
+QString adoptToQString(WKURLRef urlRef)
+{
+    return WKURLCopyQString(adoptWK(urlRef).get());
+}
+
+QUrl adoptToQUrl(WKURLRef urlRef)
+{
+    return WKURLCopyQUrl(adoptWK(urlRef).get());
+}
+} /* namespace WebKit */
index a861f7d..b12f974 100644 (file)
@@ -31,4 +31,12 @@ WK_EXPORT QString WKURLCopyQString(WKURLRef url);
 WK_EXPORT WKURLRef WKURLCreateWithQUrl(const QUrl& url);
 WK_EXPORT QUrl WKURLCopyQUrl(WKURLRef url);
 
+namespace WebKit {
+QString adoptToQString(WKURLRef);
+QUrl adoptToQUrl(WKURLRef);
+} /* namespace WebKit */
+
+using WebKit::adoptToQString;
+using WebKit::adoptToQUrl;
+
 #endif /* WKURLCF_h */
index d73bb41..7375d54 100644 (file)
@@ -627,7 +627,7 @@ void QQuickWebViewPrivate::handleDownloadRequest(DownloadProxy* download)
     downloadItem->d->downloadProxy = download;
 
     q->connect(downloadItem->d, SIGNAL(receivedResponse(QWebDownloadItem*)), q, SLOT(_q_onReceivedResponseFromDownload(QWebDownloadItem*)));
-    QtWebContext::defaultContext()->downloadManager()->addDownload(download, downloadItem);
+    QtWebContext::defaultContext()->downloadManager()->addDownload(toAPI(download), downloadItem);
 }
 
 void QQuickWebViewPrivate::_q_onVisibleChanged()
index eb76f1a..514a3e5 100644 (file)
 #include "config.h"
 #include "QtDownloadManager.h"
 
-#include "DownloadProxy.h"
 #include "QtWebError.h"
-#include "WKStringQt.h"
-#include "WKURLQt.h"
-#include "WebContext.h"
 #include "qwebdownloaditem_p.h"
 #include "qwebdownloaditem_p_p.h"
+#include <WKDownload.h>
+#include <WKStringQt.h>
+#include <WKURLQt.h>
+#include <WKURLResponse.h>
 
 namespace WebKit {
 
-QtDownloadManager::QtDownloadManager(WebContext* context)
+static inline QtDownloadManager* toQtDownloadManager(const void* clientInfo)
+{
+    ASSERT(clientInfo);
+    return reinterpret_cast<QtDownloadManager*>(const_cast<void*>(clientInfo));
+}
+
+QtDownloadManager::QtDownloadManager(WKContextRef context)
 {
     WKContextDownloadClient downloadClient;
     memset(&downloadClient, 0, sizeof(WKContextDownloadClient));
@@ -42,52 +48,60 @@ QtDownloadManager::QtDownloadManager(WebContext* context)
     downloadClient.didCreateDestination = didCreateDestination;
     downloadClient.didFinish = didFinishDownload;
     downloadClient.didFail = didFailDownload;
-    WKContextSetDownloadClient(toAPI(context), &downloadClient);
+    WKContextSetDownloadClient(context, &downloadClient);
 }
 
 QtDownloadManager::~QtDownloadManager()
 {
 }
 
-void QtDownloadManager::addDownload(DownloadProxy* download, QWebDownloadItem* downloadItem)
+void QtDownloadManager::addDownload(WKDownloadRef download, QWebDownloadItem* downloadItem)
 {
-    m_downloads[download->downloadID()] = downloadItem;
+    m_downloads[WKDownloadGetID(download)] = downloadItem;
 }
 
-void QtDownloadManager::downloadReceivedResponse(DownloadProxy* download, const WebCore::ResourceResponse& response)
+void QtDownloadManager::didReceiveResponse(WKContextRef, WKDownloadRef download, WKURLResponseRef response, const void* clientInfo)
 {
+    QtDownloadManager* q = toQtDownloadManager(clientInfo);
+
     // Will be called when the headers are read by WebProcess.
-    QWebDownloadItem* downloadItem = m_downloads.value(download->downloadID());
+    QWebDownloadItem* downloadItem = q->m_downloads.value(WKDownloadGetID(download));
     ASSERT(downloadItem);
 
-    downloadItem->d->sourceUrl = response.url();
-    downloadItem->d->mimeType = response.mimeType();
-    downloadItem->d->expectedContentLength = response.expectedContentLength();
-    downloadItem->d->suggestedFilename = response.suggestedFilename();
+    downloadItem->d->sourceUrl = adoptToQUrl(WKURLResponseCopyURL(response));
+    downloadItem->d->mimeType = adoptToQString(WKURLResponseCopyMIMEType(response));
+    downloadItem->d->expectedContentLength = WKURLResponseGetExpectedContentLength(response);
+    downloadItem->d->suggestedFilename = WKStringCopyQString(adoptWK(WKURLResponseCopySuggestedFilename(response)).get());
 
     downloadItem->d->didReceiveResponse(downloadItem);
 }
 
-void QtDownloadManager::downloadCreatedDestination(DownloadProxy* download, const QString& path)
+void QtDownloadManager::didCreateDestination(WKContextRef, WKDownloadRef download, WKStringRef path, const void* clientInfo)
 {
-    QWebDownloadItem* downloadItem = m_downloads.value(download->downloadID());
+    QtDownloadManager* q = toQtDownloadManager(clientInfo);
+
+    QWebDownloadItem* downloadItem = q->m_downloads.value(WKDownloadGetID(download));
     ASSERT(downloadItem);
-    downloadItem->d->destinationPath = path;
+    downloadItem->d->destinationPath = WKStringCopyQString(path);
     emit downloadItem->destinationFileCreated(downloadItem->d->destinationPath);
 }
 
-void QtDownloadManager::downloadFinished(DownloadProxy* download)
+void QtDownloadManager::didFinishDownload(WKContextRef, WKDownloadRef download, const void *clientInfo)
 {
+    QtDownloadManager* q = toQtDownloadManager(clientInfo);
+
     // Will be called when download finishes with success.
-    QWebDownloadItem* downloadItem = m_downloads.take(download->downloadID());
+    QWebDownloadItem* downloadItem = q->m_downloads.take(WKDownloadGetID(download));
     ASSERT(downloadItem);
     emit downloadItem->succeeded();
 }
 
-void QtDownloadManager::downloadFailed(DownloadProxy* download, const QtWebError& error)
+void QtDownloadManager::didFailDownload(WKContextRef, WKDownloadRef download, WKErrorRef error, const void* clientInfo)
 {
+    QtDownloadManager* q = toQtDownloadManager(clientInfo);
+
     // Will be called when download fails or is aborted.
-    QWebDownloadItem* downloadItem = m_downloads.take(download->downloadID());
+    QWebDownloadItem* downloadItem = q->m_downloads.take(WKDownloadGetID(download));
     ASSERT(downloadItem);
 
     // If the parent is null at this point, the download failed before it
@@ -99,47 +113,19 @@ void QtDownloadManager::downloadFailed(DownloadProxy* download, const QtWebError
         return;
     }
 
-    emit downloadItem->failed(error.errorCodeAsDownloadError(), error.url(), error.description());
+    QtWebError qtError(error);
+    emit downloadItem->failed(qtError.errorCodeAsDownloadError(), qtError.url(), qtError.description());
 }
 
-void QtDownloadManager::downloadDataReceived(DownloadProxy* download, uint64_t length)
+void QtDownloadManager::didReceiveDataForDownload(WKContextRef, WKDownloadRef download, uint64_t length, const void* clientInfo)
 {
+    QtDownloadManager* q = toQtDownloadManager(clientInfo);
+
     // Will be called everytime bytes were written to destination file by WebProcess.
-    QWebDownloadItem* downloadItem = m_downloads.value(download->downloadID());
+    QWebDownloadItem* downloadItem = q->m_downloads.value(WKDownloadGetID(download));
     ASSERT(downloadItem);
     downloadItem->d->totalBytesReceived += length;
     emit downloadItem->totalBytesReceivedChanged(length);
 }
 
-static inline QtDownloadManager* toQtDownloadManager(const void* clientInfo)
-{
-    ASSERT(clientInfo);
-    return reinterpret_cast<QtDownloadManager*>(const_cast<void*>(clientInfo));
-}
-
-void QtDownloadManager::didReceiveResponse(WKContextRef, WKDownloadRef download, WKURLResponseRef response, const void *clientInfo)
-{
-    toQtDownloadManager(clientInfo)->downloadReceivedResponse(toImpl(download), toImpl(response)->resourceResponse());
-}
-
-void QtDownloadManager::didCreateDestination(WKContextRef, WKDownloadRef download, WKStringRef path, const void *clientInfo)
-{
-    toQtDownloadManager(clientInfo)->downloadCreatedDestination(toImpl(download), WKStringCopyQString(path));
-}
-
-void QtDownloadManager::didFinishDownload(WKContextRef, WKDownloadRef download, const void *clientInfo)
-{
-    toQtDownloadManager(clientInfo)->downloadFinished(toImpl(download));
-}
-
-void QtDownloadManager::didFailDownload(WKContextRef, WKDownloadRef download, WKErrorRef error, const void *clientInfo)
-{
-    toQtDownloadManager(clientInfo)->downloadFailed(toImpl(download), QtWebError(error));
-}
-
-void QtDownloadManager::didReceiveDataForDownload(WKContextRef, WKDownloadRef download, uint64_t length, const void *clientInfo)
-{
-    toQtDownloadManager(clientInfo)->downloadDataReceived(toImpl(download), length);
-}
-
 } // namespace WebKit
index a49f5e2..a52309b 100644 (file)
 
 class QWebDownloadItem;
 
-namespace WebCore {
-class ResourceResponse;
-}
-
 namespace WebKit {
 
 class DownloadProxy;
 class QtWebError;
-class WebContext;
 
 class QtDownloadManager {
 public:
-    QtDownloadManager(WebContext*);
+    QtDownloadManager(WKContextRef);
     ~QtDownloadManager();
 
-    void addDownload(DownloadProxy*, QWebDownloadItem*);
+    void addDownload(WKDownloadRef, QWebDownloadItem*);
 
 private:
-    void downloadReceivedResponse(DownloadProxy*, const WebCore::ResourceResponse&);
-    void downloadCreatedDestination(DownloadProxy*, const QString& path);
-    void downloadFinished(DownloadProxy*);
-    void downloadFailed(DownloadProxy*, const QtWebError&);
-    void downloadDataReceived(DownloadProxy*, uint64_t length);
-
-    // WKContextDownloadClient callbacks.
     static void didReceiveResponse(WKContextRef, WKDownloadRef, WKURLResponseRef, const void* clientInfo);
     static void didCreateDestination(WKContextRef, WKDownloadRef, WKStringRef path, const void* clientInfo);
     static void didFinishDownload(WKContextRef, WKDownloadRef, const void* clientInfo);
index ca562dc..4489d74 100644 (file)
@@ -117,7 +117,7 @@ static void initializeContextInjectedBundleClient(WKContextRef context)
 
 QtWebContext::QtWebContext(WKContextRef context)
     : m_context(context)
-    , m_downloadManager(new QtDownloadManager(toImpl(context)))
+    , m_downloadManager(new QtDownloadManager(context))
     , m_iconDatabase(new QtWebIconDatabaseClient(context))
 {
 }
index b589159..c2f506c 100644 (file)
@@ -57,12 +57,12 @@ int QtWebError::errorCode() const
 
 QString QtWebError::url() const
 {
-    return WKStringCopyQString(WKURLCopyString(WKErrorCopyFailingURL(error.get())));
+    return adoptToQString(WKErrorCopyFailingURL(error.get()));
 }
 
 QString QtWebError::description() const
 {
-    return WKStringCopyQString(WKErrorCopyLocalizedDescription(error.get()));
+    return adoptToQString(WKErrorCopyLocalizedDescription(error.get()));
 }
 
 bool QtWebError::isCancellation() const