From 9861941bb7d4438d1d4e7971bce431b89de0584a Mon Sep 17 00:00:00 2001
From: Milian Wolff <milian.wolff@kdab.com>
Date: Tue, 27 Aug 2013 17:23:41 +0200
Subject: [PATCH 4/8] [Qt] Enable QML handling of crashed/unresponsive
 QtWebProcess

https://bugs.webkit.org/show_bug.cgi?id=108474

Forward the processDidCrash, didRelaunchProcess, processDidBecomeUnresponsive
and processDidBecomeResponsive signals to QML's WebView.experimental.

Reviewed by Jocelyn Turcotte.

* UIProcess/API/qt/qquickwebview.cpp:
(QQuickWebViewPrivate::processDidCrash):
(QQuickWebViewPrivate::didRelaunchProcess):
(QQuickWebViewPrivate::processDidBecomeUnresponsive):
(QQuickWebViewPrivate::processDidBecomeResponsive):
* UIProcess/API/qt/qquickwebview_p.h:
* UIProcess/API/qt/qquickwebview_p_p.h:
(QQuickWebViewPrivate):

NOTE: This is the initial iteration of the patch attached to upstream
bug report 108474, i.e.:
https://bug-108474-attachments.webkit.org/attachment.cgi?id=185771
The actually committed version is incompatible with the status of
QtWebKit stable as the architecture changed too much.

Change-Id: I91d28dde2774fd1487a96ac36a14b522ffb7756c
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@153580 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
---
 Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp  | 24 ++++++++++++++++++++++
 Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h  |  5 +++++
 .../WebKit2/UIProcess/API/qt/qquickwebview_p_p.h   |  2 ++
 .../WebKit2/UIProcess/qt/QtWebPageLoadClient.cpp   | 22 ++++++++++++++++++++
 Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.h  |  4 ++++
 5 files changed, 57 insertions(+)

diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
index c5827b2..690be32 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
@@ -485,16 +485,40 @@ void QQuickWebViewPrivate::processDidCrash()
         loadProgressDidChange(100);
         emit q->loadingChanged(&loadRequest);
     }
+
+    emit q->experimental()->processDidCrash();
 }
 
 void QQuickWebViewPrivate::didRelaunchProcess()
 {
+    Q_Q(QQuickWebView);
+
     qWarning("WARNING: The web process has been successfully restarted.");
 
     webPageProxy->drawingArea()->setSize(viewSize(), IntSize());
 
     updateViewportSize();
     updateUserScripts();
+
+    emit q->experimental()->didRelaunchProcess();
+}
+
+void QQuickWebViewPrivate::processDidBecomeUnresponsive()
+{
+    Q_Q(QQuickWebView);
+
+    qWarning("WARNING: The web process has become unresponsive.");
+
+    emit q->experimental()->processDidBecomeUnresponsive();
+}
+
+void QQuickWebViewPrivate::processDidBecomeResponsive()
+{
+    Q_Q(QQuickWebView);
+
+    qWarning("WARNING: The web process has become responsive.");
+
+    emit q->experimental()->processDidBecomeResponsive();
 }
 
 PassOwnPtr<DrawingAreaProxy> QQuickWebViewPrivate::createDrawingAreaProxy()
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
index 8de0bc1..b53171f 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h
@@ -378,6 +378,11 @@ Q_SIGNALS:
     void preferredMinimumContentsWidthChanged();
     void remoteInspectorUrlChanged();
 
+    void processDidCrash();
+    void didRelaunchProcess();
+    void processDidBecomeUnresponsive();
+    void processDidBecomeResponsive();
+
 private:
     QQuickWebViewExperimental(QQuickWebView* webView, QQuickWebViewPrivate* webViewPrivate);
     QQuickWebView* q_ptr;
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
index adedb6a..2a46d5c 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h
@@ -133,6 +133,8 @@ public:
     virtual void pageDidRequestScroll(const QPoint& pos) { }
     void processDidCrash();
     void didRelaunchProcess();
+    void processDidBecomeUnresponsive();
+    void processDidBecomeResponsive();
     PassOwnPtr<WebKit::DrawingAreaProxy> createDrawingAreaProxy();
     void handleDownloadRequest(WebKit::DownloadProxy*);
 
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.cpp b/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.cpp
index b877ca8..9f90212 100644
--- a/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.cpp
+++ b/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.cpp
@@ -47,6 +47,8 @@ QtWebPageLoadClient::QtWebPageLoadClient(WKPageRef pageRef, QQuickWebView* webVi
     loadClient.didChangeProgress = didChangeProgress;
     loadClient.didFinishProgress = didFinishProgress;
     loadClient.didChangeBackForwardList = didChangeBackForwardList;
+    loadClient.processDidBecomeUnresponsive = processDidBecomeUnresponsive;
+    loadClient.processDidBecomeResponsive = processDidBecomeResponsive;
     WKPageSetPageLoaderClient(pageRef, &loadClient);
 }
 
@@ -88,6 +90,16 @@ void QtWebPageLoadClient::didChangeBackForwardList()
     m_webView->d_func()->backForwardListDidChange();
 }
 
+void QtWebPageLoadClient::processDidBecomeUnresponsive()
+{
+    m_webView->d_func()->processDidBecomeUnresponsive();
+}
+
+void QtWebPageLoadClient::processDidBecomeResponsive()
+{
+    m_webView->d_func()->processDidBecomeResponsive();
+}
+
 void QtWebPageLoadClient::dispatchLoadSucceeded()
 {
     m_webView->d_func()->loadDidSucceed();
@@ -213,4 +225,14 @@ void QtWebPageLoadClient::didChangeBackForwardList(WKPageRef, WKBackForwardListI
     toQtWebPageLoadClient(clientInfo)->didChangeBackForwardList();
 }
 
+void QtWebPageLoadClient::processDidBecomeUnresponsive(WKPageRef, const void* clientInfo)
+{
+    toQtWebPageLoadClient(clientInfo)->processDidBecomeUnresponsive();
+}
+
+void QtWebPageLoadClient::processDidBecomeResponsive(WKPageRef, const void* clientInfo)
+{
+    toQtWebPageLoadClient(clientInfo)->processDidBecomeResponsive();
+}
+
 } // namespace Webkit
diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.h b/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.h
index 668bac1..fd49543 100644
--- a/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.h
+++ b/Source/WebKit2/UIProcess/qt/QtWebPageLoadClient.h
@@ -48,6 +48,8 @@ private:
     void didReceiveTitle();
     void didChangeProgress(int);
     void didChangeBackForwardList();
+    void processDidBecomeUnresponsive();
+    void processDidBecomeResponsive();
 
     void dispatchLoadSucceeded();
     void dispatchLoadStopped();
@@ -67,6 +69,8 @@ private:
     static void didChangeProgress(WKPageRef, const void* clientInfo);
     static void didFinishProgress(WKPageRef, const void* clientInfo);
     static void didChangeBackForwardList(WKPageRef, WKBackForwardListItemRef, WKArrayRef, const void *clientInfo);
+    static void processDidBecomeUnresponsive(WKPageRef, const void* clientInfo);
+    static void processDidBecomeResponsive(WKPageRef, const void* clientInfo);
 
     QQuickWebView* m_webView;
 };
-- 
1.9.0

