[Qt] [WK2] Move PageLoadClient related code to QtWebPageLoadClient
authorcaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Nov 2011 13:38:40 +0000 (13:38 +0000)
committercaio.oliveira@openbossa.org <caio.oliveira@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Nov 2011 13:38:40 +0000 (13:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72928

Reviewed by Andreas Kling.

Split PageLoadClient related code from QtWebPageProxy/ClientImpl. The new
QtWebPageLoadClient registers itself with WKPageRef and it's owned by the
QQuickWebViewPrivate. This is a move to clean up QtWebPageProxy object.

* Target.pri:
* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::QQuickWebViewPrivate):
(QQuickWebView::loadProgress):
* UIProcess/API/qt/qquickwebview_p.h:
* UIProcess/API/qt/qquickwebview_p_p.h:
* UIProcess/qt/ClientImpl.cpp:
* UIProcess/qt/ClientImpl.h:
* UIProcess/qt/QtWebPageLoadClient.cpp: Added.
(QtWebPageLoadClient::QtWebPageLoadClient):
(QtWebPageLoadClient::didStartProvisionalLoadForFrame):
(QtWebPageLoadClient::didCommitLoadForFrame):
(QtWebPageLoadClient::didSameDocumentNavigationForFrame):
(QtWebPageLoadClient::didReceiveTitleForFrame):
(QtWebPageLoadClient::didFirstVisuallyNonEmptyLayoutForFrame):
(QtWebPageLoadClient::dispatchLoadSucceeded):
(QtWebPageLoadClient::dispatchLoadFailed):
(QtWebPageLoadClient::setLoadProgress):
(toQtWebPageLoadClient):
(QtWebPageLoadClient::didFailProvisionalLoadWithErrorForFrame):
(QtWebPageLoadClient::didFinishLoadForFrame):
(QtWebPageLoadClient::didFailLoadWithErrorForFrame):
(QtWebPageLoadClient::didStartProgress):
(QtWebPageLoadClient::didChangeProgress):
(QtWebPageLoadClient::didFinishProgress):
* UIProcess/qt/QtWebPageLoadClient.h: Added.
(QtWebPageLoadClient::loadProgress):
* UIProcess/qt/QtWebPageProxy.cpp:
(QtWebPageProxy::QtWebPageProxy):
(QtWebPageProxy::init):
(QtWebPageProxy::updateNavigationState):
* UIProcess/qt/QtWebPageProxy.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/Target.pri
Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
Source/WebKit2/UIProcess/qt/ClientImpl.cpp
Source/WebKit2/UIProcess/qt/ClientImpl.h
Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.h [new file with mode: 0644]
Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp
Source/WebKit2/UIProcess/qt/QtWebPageProxy.h

index 6d0d064..9d3ca51 100644 (file)
@@ -1,5 +1,49 @@
 2011-11-22  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
 
+        [Qt] [WK2] Move PageLoadClient related code to QtWebPageLoadClient
+        https://bugs.webkit.org/show_bug.cgi?id=72928
+
+        Reviewed by Andreas Kling.
+
+        Split PageLoadClient related code from QtWebPageProxy/ClientImpl. The new
+        QtWebPageLoadClient registers itself with WKPageRef and it's owned by the
+        QQuickWebViewPrivate. This is a move to clean up QtWebPageProxy object.
+
+        * Target.pri:
+        * UIProcess/API/qt/qquickwebview.cpp:
+        (QQuickWebViewPrivate::QQuickWebViewPrivate):
+        (QQuickWebView::loadProgress):
+        * UIProcess/API/qt/qquickwebview_p.h:
+        * UIProcess/API/qt/qquickwebview_p_p.h:
+        * UIProcess/qt/ClientImpl.cpp:
+        * UIProcess/qt/ClientImpl.h:
+        * UIProcess/qt/QtWebPageLoadClient.cpp: Added.
+        (QtWebPageLoadClient::QtWebPageLoadClient):
+        (QtWebPageLoadClient::didStartProvisionalLoadForFrame):
+        (QtWebPageLoadClient::didCommitLoadForFrame):
+        (QtWebPageLoadClient::didSameDocumentNavigationForFrame):
+        (QtWebPageLoadClient::didReceiveTitleForFrame):
+        (QtWebPageLoadClient::didFirstVisuallyNonEmptyLayoutForFrame):
+        (QtWebPageLoadClient::dispatchLoadSucceeded):
+        (QtWebPageLoadClient::dispatchLoadFailed):
+        (QtWebPageLoadClient::setLoadProgress):
+        (toQtWebPageLoadClient):
+        (QtWebPageLoadClient::didFailProvisionalLoadWithErrorForFrame):
+        (QtWebPageLoadClient::didFinishLoadForFrame):
+        (QtWebPageLoadClient::didFailLoadWithErrorForFrame):
+        (QtWebPageLoadClient::didStartProgress):
+        (QtWebPageLoadClient::didChangeProgress):
+        (QtWebPageLoadClient::didFinishProgress):
+        * UIProcess/qt/QtWebPageLoadClient.h: Added.
+        (QtWebPageLoadClient::loadProgress):
+        * UIProcess/qt/QtWebPageProxy.cpp:
+        (QtWebPageProxy::QtWebPageProxy):
+        (QtWebPageProxy::init):
+        (QtWebPageProxy::updateNavigationState):
+        * UIProcess/qt/QtWebPageProxy.h:
+
+2011-11-22  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
+
         [Qt] [WK2] Move PageUIClient related code to QtWebPageUIClient
         https://bugs.webkit.org/show_bug.cgi?id=72910
 
index 935d9c5..a552d55 100644 (file)
@@ -322,6 +322,7 @@ HEADERS += \
     UIProcess/qt/QtWebError.h \
     UIProcess/qt/QtDialogRunner.h \
     UIProcess/qt/QtDownloadManager.h \
+    UIProcess/qt/QtWebPageLoadClient.h \
     UIProcess/qt/QtWebPageProxy.h \
     UIProcess/qt/QtWebPageUIClient.h \
     UIProcess/qt/qwkhistory.h \
@@ -628,6 +629,7 @@ SOURCES += \
     UIProcess/qt/QtWebError.cpp \
     UIProcess/qt/QtDialogRunner.cpp \
     UIProcess/qt/QtDownloadManager.cpp \
+    UIProcess/qt/QtWebPageLoadClient.cpp \
     UIProcess/qt/QtWebPageProxy.cpp \
     UIProcess/qt/QtWebPageUIClient.cpp \
     UIProcess/qt/qwkhistory.cpp \
index a6f4fb7..4b2f2f3 100644 (file)
@@ -57,9 +57,8 @@ QQuickWebViewPrivate::QQuickWebViewPrivate(QQuickWebView* viewport, WKContextRef
     QWebPreferencesPrivate::get(pageProxy->preferences())->setAttribute(QWebPreferencesPrivate::AcceleratedCompositingEnabled, true);
     pageProxy->init();
 
-    QObject::connect(pageProxy.data(), SIGNAL(updateNavigationState()), q_ptr, SIGNAL(navigationStateChanged()));
-
     pageUIClient.reset(new QtWebPageUIClient(pageProxy->pageRef(), q_ptr));
+    pageLoadClient.reset(new QtWebPageLoadClient(pageProxy->pageRef(), q_ptr));
 }
 
 void QQuickWebViewPrivate::enableMouseEvents()
@@ -543,7 +542,7 @@ QUrl QQuickWebView::url() const
 int QQuickWebView::loadProgress() const
 {
     Q_D(const QQuickWebView);
-    return d->pageProxy->loadProgress();
+    return d->pageLoadClient->loadProgress();
 }
 
 bool QQuickWebView::canGoBack() const
index 7c8841a..2d107f6 100644 (file)
@@ -134,6 +134,7 @@ private:
     QScopedPointer<QQuickWebViewPrivate> d_ptr;
     QQuickWebViewExperimental* m_experimental;
 
+    friend class QtWebPageLoadClient;
     friend class QtWebPageProxy;
     friend class QtWebPageUIClient;
     friend class WTR::PlatformWebView;
index 529e253..1e1ecbb 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "QtPolicyInterface.h"
 #include "QtViewportInteractionEngine.h"
+#include "QtWebPageLoadClient.h"
 #include "QtWebPageProxy.h"
 #include "QtWebPageUIClient.h"
 
@@ -112,6 +113,7 @@ private:
     void setViewInAttachedProperties(QObject*);
 
     QScopedPointer<QtWebPageUIClient> pageUIClient;
+    QScopedPointer<QtWebPageLoadClient> pageLoadClient;
 
     QScopedPointer<QQuickWebPage> pageView;
     QScopedPointer<QtViewportInteractionEngine> interactionEngine;
index 0863ec7..5c75d89 100644 (file)
 #include "config.h"
 #include "ClientImpl.h"
 
-#include "QtWebError.h"
-#include "WebFrameProxy.h"
+#include "WebPageProxy.h"
 #include "WKAPICast.h"
-#include "WKStringQt.h"
 #include "WKURLQt.h"
 #include <QtPolicyInterface.h>
-#include <QtWebPageProxy.h>
 #include <WKArray.h>
 #include <WKFrame.h>
 #include <WKFramePolicyListener.h>
-#include <WKHitTestResult.h>
 #include <WKPage.h>
 #include <WKString.h>
 #include <WKType.h>
 
 using namespace WebKit;
 
-static QtWebPageProxy* toQtWebPageProxy(const void* clientInfo)
-{
-    if (clientInfo)
-        return reinterpret_cast<QtWebPageProxy*>(const_cast<void*>(clientInfo));
-    return 0;
-}
-
 static inline QtPolicyInterface* toQtPolicyInterface(const void* clientInfo)
 {
     ASSERT(clientInfo);
     return reinterpret_cast<QtPolicyInterface*>(const_cast<void*>(clientInfo));
 }
 
-static void dispatchLoadSucceeded(WKFrameRef frame, const void* clientInfo)
-{
-    if (!WKFrameIsMainFrame(frame))
-        return;
-
-    toQtWebPageProxy(clientInfo)->updateNavigationState();
-    toQtWebPageProxy(clientInfo)->loadDidSucceed();
-}
-
-static void dispatchLoadFailed(WKFrameRef frame, const void* clientInfo, WKErrorRef error)
-{
-    if (!WKFrameIsMainFrame(frame))
-        return;
-
-    toQtWebPageProxy(clientInfo)->updateNavigationState();
-
-    int errorCode = WKErrorGetErrorCode(error);
-    if (toImpl(error)->platformError().isCancellation() || errorCode == kWKErrorCodeFrameLoadInterruptedByPolicyChange || errorCode == kWKErrorCodePlugInWillHandleLoad)
-        return;
-
-    toQtWebPageProxy(clientInfo)->loadDidFail(QtWebError(error));
-}
-
-static void qt_wk_didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
-{
-    if (!WKFrameIsMainFrame(frame))
-        return;
-
-    toQtWebPageProxy(clientInfo)->updateNavigationState();
-    toQtWebPageProxy(clientInfo)->loadDidBegin();
-}
-
-static void qt_wk_didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo)
-{
-    dispatchLoadFailed(frame, clientInfo, error);
-}
-
-static void qt_wk_didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
-{
-    if (!WKFrameIsMainFrame(frame))
-        return;
-    WebFrameProxy* wkframe = toImpl(frame);
-    QString urlStr(wkframe->url());
-    QUrl qUrl = urlStr;
-    toQtWebPageProxy(clientInfo)->updateNavigationState();
-    toQtWebPageProxy(clientInfo)->didChangeUrl(qUrl);
-    toQtWebPageProxy(clientInfo)->loadDidCommit();
-}
-
-static void qt_wk_didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
-{
-    dispatchLoadSucceeded(frame, clientInfo);
-}
-
-static void qt_wk_didFailLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo)
-{
-    dispatchLoadFailed(frame, clientInfo, error);
-}
-
-static void qt_wk_didSameDocumentNavigationForFrame(WKPageRef page, WKFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef userData, const void* clientInfo)
-{
-    WebFrameProxy* wkframe = toImpl(frame);
-    QString urlStr(wkframe->url());
-    QUrl qUrl = urlStr;
-    toQtWebPageProxy(clientInfo)->updateNavigationState();
-    toQtWebPageProxy(clientInfo)->didChangeUrl(qUrl);
-}
-
-static void qt_wk_didReceiveTitleForFrame(WKPageRef page, WKStringRef title, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
-{
-    if (!WKFrameIsMainFrame(frame))
-        return;
-    QString qTitle = WKStringCopyQString(title);
-    toQtWebPageProxy(clientInfo)->didChangeTitle(qTitle);
-}
-
-static void qt_wk_didStartProgress(WKPageRef page, const void* clientInfo)
-{
-    toQtWebPageProxy(clientInfo)->didChangeLoadProgress(0);
-}
-
-static void qt_wk_didChangeProgress(WKPageRef page, const void* clientInfo)
-{
-    toQtWebPageProxy(clientInfo)->didChangeLoadProgress(WKPageGetEstimatedProgress(page) * 100);
-}
-
-static void qt_wk_didFinishProgress(WKPageRef page, const void* clientInfo)
-{
-    toQtWebPageProxy(clientInfo)->didChangeLoadProgress(100);
-}
-
-static void qt_wk_didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo)
-{
-    if (!WKFrameIsMainFrame(frame))
-        return;
-
-    toQtWebPageProxy(clientInfo)->didFinishFirstNonEmptyLayout();
-}
-
 static Qt::MouseButton toQtMouseButton(WKEventMouseButton button)
 {
     switch (button) {
@@ -244,26 +134,6 @@ void qt_wk_didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef message
     toImpl(page)->didReceiveMessageFromNavigatorQtObject(toImpl(str)->string());
 }
 
-void setupPageLoaderClient(QtWebPageProxy* qtWebPageProxy, WebPageProxy* webPageProxy)
-{
-    WKPageLoaderClient loadClient;
-    memset(&loadClient, 0, sizeof(WKPageLoaderClient));
-    loadClient.version = kWKPageLoaderClientCurrentVersion;
-    loadClient.clientInfo = qtWebPageProxy;
-    loadClient.didStartProvisionalLoadForFrame = qt_wk_didStartProvisionalLoadForFrame;
-    loadClient.didFailProvisionalLoadWithErrorForFrame = qt_wk_didFailProvisionalLoadWithErrorForFrame;
-    loadClient.didCommitLoadForFrame = qt_wk_didCommitLoadForFrame;
-    loadClient.didFinishLoadForFrame = qt_wk_didFinishLoadForFrame;
-    loadClient.didFailLoadWithErrorForFrame = qt_wk_didFailLoadWithErrorForFrame;
-    loadClient.didSameDocumentNavigationForFrame = qt_wk_didSameDocumentNavigationForFrame;
-    loadClient.didReceiveTitleForFrame = qt_wk_didReceiveTitleForFrame;
-    loadClient.didStartProgress = qt_wk_didStartProgress;
-    loadClient.didChangeProgress = qt_wk_didChangeProgress;
-    loadClient.didFinishProgress = qt_wk_didFinishProgress;
-    loadClient.didFirstVisuallyNonEmptyLayoutForFrame = qt_wk_didFirstVisuallyNonEmptyLayoutForFrame;
-    WKPageSetPageLoaderClient(qtWebPageProxy->pageRef(), &loadClient);
-}
-
 void setupPagePolicyClient(QtPolicyInterface* policyInterface, WebPageProxy* webPageProxy)
 {
     WKPagePolicyClient policyClient;
index 875935e..d77aaba 100644 (file)
 
 #include <WebKit2/WKContext.h>
 
-class QtWebPageProxy;
 namespace WebKit {
 class QtPolicyInterface;
 class WebPageProxy;
 }
 
-void setupPageLoaderClient(QtWebPageProxy*, WebKit::WebPageProxy*);
 void setupPagePolicyClient(WebKit::QtPolicyInterface*, WebKit::WebPageProxy*);
 
 void setupContextInjectedBundleClient(WKContextRef);
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.cpp b/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.cpp
new file mode 100644 (file)
index 0000000..a2480e3
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "QtWebPageLoadClient.h"
+
+#include "WKStringQt.h"
+#include "qquickwebview_p.h"
+#include "qquickwebview_p_p.h"
+#include <WKFrame.h>
+
+QtWebPageLoadClient::QtWebPageLoadClient(WKPageRef pageRef, QQuickWebView* webView)
+    : m_webView(webView)
+    , m_loadProgress(0)
+{
+    WKPageLoaderClient loadClient;
+    memset(&loadClient, 0, sizeof(WKPageLoaderClient));
+    loadClient.version = kWKPageLoaderClientCurrentVersion;
+    loadClient.clientInfo = this;
+    loadClient.didStartProvisionalLoadForFrame = didStartProvisionalLoadForFrame;
+    loadClient.didFailProvisionalLoadWithErrorForFrame = didFailProvisionalLoadWithErrorForFrame;
+    loadClient.didCommitLoadForFrame = didCommitLoadForFrame;
+    loadClient.didFinishLoadForFrame = didFinishLoadForFrame;
+    loadClient.didFailLoadWithErrorForFrame = didFailLoadWithErrorForFrame;
+    loadClient.didSameDocumentNavigationForFrame = didSameDocumentNavigationForFrame;
+    loadClient.didReceiveTitleForFrame = didReceiveTitleForFrame;
+    loadClient.didStartProgress = didStartProgress;
+    loadClient.didChangeProgress = didChangeProgress;
+    loadClient.didFinishProgress = didFinishProgress;
+    loadClient.didFirstVisuallyNonEmptyLayoutForFrame = didFirstVisuallyNonEmptyLayoutForFrame;
+    WKPageSetPageLoaderClient(pageRef, &loadClient);
+}
+
+void QtWebPageLoadClient::didStartProvisionalLoadForFrame()
+{
+    emit m_webView->navigationStateChanged();
+    emit m_webView->loadStarted();
+}
+
+void QtWebPageLoadClient::didCommitLoadForFrame(const QUrl& url)
+{
+    emit m_webView->navigationStateChanged();
+    emit m_webView->urlChanged(url);
+    m_webView->d_func()->loadDidCommit();
+}
+
+void QtWebPageLoadClient::didSameDocumentNavigationForFrame(const QUrl& url)
+{
+    emit m_webView->navigationStateChanged();
+    emit m_webView->urlChanged(url);
+}
+
+void QtWebPageLoadClient::didReceiveTitleForFrame(const QString& title)
+{
+    emit m_webView->titleChanged(title);
+}
+
+void QtWebPageLoadClient::didFirstVisuallyNonEmptyLayoutForFrame()
+{
+    m_webView->d_func()->didFinishFirstNonEmptyLayout();
+}
+
+void QtWebPageLoadClient::dispatchLoadSucceeded()
+{
+    emit m_webView->navigationStateChanged();
+    emit m_webView->loadSucceeded();
+}
+
+void QtWebPageLoadClient::dispatchLoadFailed(WKErrorRef error)
+{
+    emit m_webView->navigationStateChanged();
+
+    int errorCode = WKErrorGetErrorCode(error);
+    if (toImpl(error)->platformError().isCancellation() || errorCode == kWKErrorCodeFrameLoadInterruptedByPolicyChange || errorCode == kWKErrorCodePlugInWillHandleLoad)
+        return;
+
+    QtWebError qtError(error);
+    emit m_webView->loadFailed(static_cast<QQuickWebView::ErrorType>(qtError.type()), qtError.errorCode(), qtError.url());
+}
+
+void QtWebPageLoadClient::setLoadProgress(int loadProgress)
+{
+    m_loadProgress = loadProgress;
+    emit m_webView->loadProgressChanged(m_loadProgress);
+}
+
+static QtWebPageLoadClient* toQtWebPageLoadClient(const void* clientInfo)
+{
+    ASSERT(clientInfo);
+    return reinterpret_cast<QtWebPageLoadClient*>(const_cast<void*>(clientInfo));
+}
+
+void QtWebPageLoadClient::didStartProvisionalLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef, const void* clientInfo)
+{
+    if (!WKFrameIsMainFrame(frame))
+        return;
+    toQtWebPageLoadClient(clientInfo)->didStartProvisionalLoadForFrame();
+}
+
+void QtWebPageLoadClient::didFailProvisionalLoadWithErrorForFrame(WKPageRef, WKFrameRef frame, WKErrorRef error, WKTypeRef, const void* clientInfo)
+{
+    if (!WKFrameIsMainFrame(frame))
+        return;
+    toQtWebPageLoadClient(clientInfo)->dispatchLoadFailed(error);
+}
+
+void QtWebPageLoadClient::didCommitLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef, const void* clientInfo)
+{
+    if (!WKFrameIsMainFrame(frame))
+        return;
+    WebFrameProxy* wkframe = toImpl(frame);
+    QString urlStr(wkframe->url());
+    QUrl qUrl = urlStr;
+    toQtWebPageLoadClient(clientInfo)->didCommitLoadForFrame(qUrl);
+}
+
+void QtWebPageLoadClient::didFinishLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef, const void* clientInfo)
+{
+    if (!WKFrameIsMainFrame(frame))
+        return;
+    toQtWebPageLoadClient(clientInfo)->dispatchLoadSucceeded();
+}
+
+void QtWebPageLoadClient::didFailLoadWithErrorForFrame(WKPageRef, WKFrameRef frame, WKErrorRef error, WKTypeRef, const void* clientInfo)
+{
+    if (!WKFrameIsMainFrame(frame))
+        return;
+    toQtWebPageLoadClient(clientInfo)->dispatchLoadFailed(error);
+}
+
+void QtWebPageLoadClient::didSameDocumentNavigationForFrame(WKPageRef page, WKFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef userData, const void* clientInfo)
+{
+    WebFrameProxy* wkframe = toImpl(frame);
+    QString urlStr(wkframe->url());
+    QUrl qUrl = urlStr;
+    toQtWebPageLoadClient(clientInfo)->didSameDocumentNavigationForFrame(qUrl);
+}
+
+void QtWebPageLoadClient::didReceiveTitleForFrame(WKPageRef, WKStringRef title, WKFrameRef frame, WKTypeRef, const void* clientInfo)
+{
+    if (!WKFrameIsMainFrame(frame))
+        return;
+    QString qTitle = WKStringCopyQString(title);
+    toQtWebPageLoadClient(clientInfo)->didReceiveTitleForFrame(qTitle);
+}
+
+void QtWebPageLoadClient::didStartProgress(WKPageRef, const void* clientInfo)
+{
+    toQtWebPageLoadClient(clientInfo)->setLoadProgress(0);
+}
+
+void QtWebPageLoadClient::didChangeProgress(WKPageRef page, const void* clientInfo)
+{
+    toQtWebPageLoadClient(clientInfo)->setLoadProgress(WKPageGetEstimatedProgress(page) * 100);
+}
+
+void QtWebPageLoadClient::didFinishProgress(WKPageRef, const void* clientInfo)
+{
+    toQtWebPageLoadClient(clientInfo)->setLoadProgress(100);
+}
+
+void QtWebPageLoadClient::didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef, WKFrameRef frame, WKTypeRef, const void *clientInfo)
+{
+    if (!WKFrameIsMainFrame(frame))
+        return;
+    toQtWebPageLoadClient(clientInfo)->didFirstVisuallyNonEmptyLayoutForFrame();
+}
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.h b/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.h
new file mode 100644 (file)
index 0000000..03f2f0e
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef QtWebPageLoadClient_h
+#define QtWebPageLoadClient_h
+
+#include "QtWebError.h"
+#include <QtCore/QString>
+#include <QtCore/QUrl>
+#include <WKPage.h>
+
+class QQuickWebView;
+
+class QtWebPageLoadClient {
+public:
+    QtWebPageLoadClient(WKPageRef, QQuickWebView*);
+
+    int loadProgress() const { return m_loadProgress; }
+
+private:
+    void didStartProvisionalLoadForFrame();
+    void didCommitLoadForFrame(const QUrl&);
+    void didSameDocumentNavigationForFrame(const QUrl&);
+    void didReceiveTitleForFrame(const QString&);
+    void didFirstVisuallyNonEmptyLayoutForFrame();
+
+    void dispatchLoadSucceeded();
+    void dispatchLoadFailed(WKErrorRef);
+    void setLoadProgress(int);
+
+    // WKPageLoadClient callbacks.
+    static void didStartProvisionalLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void* clientInfo);
+    static void didFailProvisionalLoadWithErrorForFrame(WKPageRef, WKFrameRef, WKErrorRef, WKTypeRef userData, const void* clientInfo);
+    static void didCommitLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void* clientInfo);
+    static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void* clientInfo);
+    static void didFailLoadWithErrorForFrame(WKPageRef, WKFrameRef, WKErrorRef, WKTypeRef userData, const void* clientInfo);
+    static void didSameDocumentNavigationForFrame(WKPageRef, WKFrameRef, WKSameDocumentNavigationType, WKTypeRef userData, const void* clientInfo);
+    static void didReceiveTitleForFrame(WKPageRef, WKStringRef, WKFrameRef, WKTypeRef userData, const void* clientInfo);
+    static void didStartProgress(WKPageRef, const void* clientInfo);
+    static void didChangeProgress(WKPageRef, const void* clientInfo);
+    static void didFinishProgress(WKPageRef, const void* clientInfo);
+    static void didFirstVisuallyNonEmptyLayoutForFrame(WKPageRef, WKFrameRef, WKTypeRef userData, const void* clientInfo);
+
+    QQuickWebView* m_webView;
+    int m_loadProgress;
+};
+
+#endif // QtWebPageLoadClient_h
index f8d9bc6..c10773b 100644 (file)
@@ -143,7 +143,6 @@ QtWebPageProxy::QtWebPageProxy(QQuickWebPage* qmlWebPage, QQuickWebView* qmlWebV
     , m_policyInterface(policyInterface)
     , m_context(contextRef ? toImpl(contextRef) : defaultWKContext())
     , m_undoStack(adoptPtr(new QUndoStack(this)))
-    , m_loadProgress(0)
     , m_navigatorQtObjectEnabled(false)
 {
     m_webPageProxy = m_context->createWebPage(this, toImpl(pageGroupRef));
@@ -155,9 +154,6 @@ QtWebPageProxy::QtWebPageProxy(QQuickWebPage* qmlWebPage, QQuickWebView* qmlWebV
 void QtWebPageProxy::init()
 {
     m_webPageProxy->initializeWebPage();
-
-    setupPageLoaderClient(this, m_webPageProxy.get());
-
     if (m_policyInterface)
         setupPagePolicyClient(m_policyInterface, m_webPageProxy.get());
 }
@@ -487,11 +483,6 @@ void QtWebPageProxy::pageDidRequestScroll(const IntPoint& pos)
     m_qmlWebView->d_func()->scrollPositionRequested(pos);
 }
 
-void QtWebPageProxy::didFinishFirstNonEmptyLayout()
-{
-    m_qmlWebView->d_func()->didFinishFirstNonEmptyLayout();
-}
-
 void QtWebPageProxy::didChangeContentsSize(const IntSize& newSize)
 {
     m_qmlWebView->d_func()->didChangeContentsSize(newSize);
@@ -615,42 +606,6 @@ void QtWebPageProxy::didReceiveMessageFromNavigatorQtObject(const String& messag
     emit receivedMessageFromNavigatorQtObject(variantMap);
 }
 
-void QtWebPageProxy::didChangeUrl(const QUrl& url)
-{
-    emit m_qmlWebView->urlChanged(url);
-}
-
-void QtWebPageProxy::didChangeTitle(const QString& newTitle)
-{
-    emit m_qmlWebView->titleChanged(newTitle);
-}
-
-void QtWebPageProxy::loadDidBegin()
-{
-    emit m_qmlWebView->loadStarted();
-}
-
-void QtWebPageProxy::loadDidCommit()
-{
-    m_qmlWebView->d_func()->loadDidCommit();
-}
-
-void QtWebPageProxy::loadDidSucceed()
-{
-    emit m_qmlWebView->loadSucceeded();
-}
-
-void QtWebPageProxy::loadDidFail(const QtWebError& error)
-{
-    emit m_qmlWebView->loadFailed(static_cast<QQuickWebView::ErrorType>(error.type()), error.errorCode(), error.url());
-}
-
-void QtWebPageProxy::didChangeLoadProgress(int percentageLoaded)
-{
-    m_loadProgress = percentageLoaded;
-    emit m_qmlWebView->loadProgressChanged(percentageLoaded);
-}
-
 bool QtWebPageProxy::canGoBack() const
 {
     return m_webPageProxy->canGoBack();
@@ -695,9 +650,9 @@ void QtWebPageProxy::reload()
     m_webPageProxy->reload(/* reloadFromOrigin */ true);
 }
 
-void QtWebPageProxy::navigationStateChanged()
+void QtWebPageProxy::updateNavigationState()
 {
-    emit updateNavigationState();
+    emit m_qmlWebView->navigationStateChanged();
 }
 
 void QtWebPageProxy::didRelaunchProcess()
index c1812e9..ca36820 100644 (file)
@@ -101,7 +101,6 @@ public:
     virtual void pageClosed() { }
     virtual void didRelaunchProcess();
 
-    virtual void didFinishFirstNonEmptyLayout();
     virtual void didChangeContentsSize(const WebCore::IntSize&);
     virtual void didChangeViewportProperties(const WebCore::ViewportArguments&);
 
@@ -138,16 +137,6 @@ public:
     virtual void didFindZoomableArea(const WebCore::IntPoint&, const WebCore::IntRect&);
     virtual void didReceiveMessageFromNavigatorQtObject(const String&);
 
-    void didChangeUrl(const QUrl&);
-    void didChangeTitle(const QString&);
-
-    void loadDidBegin();
-    void loadDidCommit();
-    void loadDidSucceed();
-    void loadDidFail(const QtWebError&);
-    void didChangeLoadProgress(int);
-    int loadProgress() const { return m_loadProgress; }
-
     bool canGoBack() const;
     void goBack();
     bool canGoForward() const;
@@ -157,6 +146,7 @@ public:
     bool canReload() const;
     void reload();
 
+    void updateNavigationState();
     void updateEditorActions();
 
     WKPageRef pageRef() const;
@@ -209,12 +199,10 @@ public:
     void hideContextMenu();
 
 public Q_SLOTS:
-    void navigationStateChanged();
     void didReceiveDownloadResponse(QWebDownloadItem* downloadItem);
 
 public:
     Q_SIGNAL void zoomableAreaFound(const QRect&);
-    Q_SIGNAL void updateNavigationState();
     Q_SIGNAL void receivedMessageFromNavigatorQtObject(const QVariantMap&);
 
 protected:
@@ -263,7 +251,6 @@ private:
     mutable OwnPtr<QWebPreferences> m_preferences;
 
     OwnPtr<QUndoStack> m_undoStack;
-    int m_loadProgress;
 
     bool m_navigatorQtObjectEnabled;
     QPoint m_tripleClick;