Add KVO-compliant _webProcessIsResponsive property to WKWebView and _WKObservablePage...
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Nov 2015 00:32:25 +0000 (00:32 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Nov 2015 00:32:25 +0000 (00:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150818
rdar://problem/22372131

Reviewed by Tim Horton.

* UIProcess/API/C/mac/WKPagePrivateMac.h:
* UIProcess/API/C/mac/WKPagePrivateMac.mm:
(-[WKObservablePageState _webProcessIsResponsive]):
* UIProcess/API/Cocoa/PageLoadStateObserver.h:
* UIProcess/API/Cocoa/WKBrowsingContextController.mm:
(-[WKBrowsingContextController _webProcessIsResponsive]):
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _webProcessIsResponsive]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/Cocoa/NavigationState.h:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::willChangeWebProcessIsResponsive):
(WebKit::NavigationState::didChangeWebProcessIsResponsive):
* UIProcess/PageLoadState.cpp:
(WebKit::PageLoadState::willChangeProcessIsResponsive):
(WebKit::PageLoadState::didChangeProcessIsResponsive):
* UIProcess/PageLoadState.h:
* UIProcess/ResponsivenessTimer.cpp:
(WebKit::ResponsivenessTimer::ResponsivenessTimer):
(WebKit::ResponsivenessTimer::timerFired):
(WebKit::ResponsivenessTimer::stop):
* UIProcess/ResponsivenessTimer.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::willChangeProcessIsResponsive):
(WebKit::WebPageProxy::didChangeProcessIsResponsive):
* UIProcess/WebPageProxy.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::WebProcessProxy):
(WebKit::WebProcessProxy::didBecomeUnresponsive):
(WebKit::WebProcessProxy::didBecomeResponsive):
(WebKit::WebProcessProxy::willChangeIsResponsive):
(WebKit::WebProcessProxy::didChangeIsResponsive):
* UIProcess/WebProcessProxy.h:

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

17 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/mac/WKPagePrivateMac.h
Source/WebKit2/UIProcess/API/C/mac/WKPagePrivateMac.mm
Source/WebKit2/UIProcess/API/Cocoa/PageLoadStateObserver.h
Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/UIProcess/Cocoa/NavigationState.h
Source/WebKit2/UIProcess/Cocoa/NavigationState.mm
Source/WebKit2/UIProcess/PageLoadState.cpp
Source/WebKit2/UIProcess/PageLoadState.h
Source/WebKit2/UIProcess/ResponsivenessTimer.cpp
Source/WebKit2/UIProcess/ResponsivenessTimer.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebProcessProxy.cpp
Source/WebKit2/UIProcess/WebProcessProxy.h

index 77124ba..8046237 100644 (file)
@@ -1,3 +1,45 @@
+2015-11-02  Anders Carlsson  <andersca@apple.com>
+
+        Add KVO-compliant _webProcessIsResponsive property to WKWebView and _WKObservablePageState
+        https://bugs.webkit.org/show_bug.cgi?id=150818
+        rdar://problem/22372131
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/C/mac/WKPagePrivateMac.h:
+        * UIProcess/API/C/mac/WKPagePrivateMac.mm:
+        (-[WKObservablePageState _webProcessIsResponsive]):
+        * UIProcess/API/Cocoa/PageLoadStateObserver.h:
+        * UIProcess/API/Cocoa/WKBrowsingContextController.mm:
+        (-[WKBrowsingContextController _webProcessIsResponsive]):
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _webProcessIsResponsive]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/Cocoa/NavigationState.h:
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::willChangeWebProcessIsResponsive):
+        (WebKit::NavigationState::didChangeWebProcessIsResponsive):
+        * UIProcess/PageLoadState.cpp:
+        (WebKit::PageLoadState::willChangeProcessIsResponsive):
+        (WebKit::PageLoadState::didChangeProcessIsResponsive):
+        * UIProcess/PageLoadState.h:
+        * UIProcess/ResponsivenessTimer.cpp:
+        (WebKit::ResponsivenessTimer::ResponsivenessTimer):
+        (WebKit::ResponsivenessTimer::timerFired):
+        (WebKit::ResponsivenessTimer::stop):
+        * UIProcess/ResponsivenessTimer.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::willChangeProcessIsResponsive):
+        (WebKit::WebPageProxy::didChangeProcessIsResponsive):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::WebProcessProxy):
+        (WebKit::WebProcessProxy::didBecomeUnresponsive):
+        (WebKit::WebProcessProxy::didBecomeResponsive):
+        (WebKit::WebProcessProxy::willChangeIsResponsive):
+        (WebKit::WebProcessProxy::didChangeIsResponsive):
+        * UIProcess/WebProcessProxy.h:
+
 2015-11-02  Tim Horton  <timothy_horton@apple.com>
 
         PDFPlugin should take advantage of threaded scrolling
index 43cb454..ef68dd3 100644 (file)
@@ -44,6 +44,7 @@ extern "C" {
 @property (nonatomic, readonly, getter=isLoading) BOOL loading;
 @property (nonatomic, readonly) double estimatedProgress;
 @property (nonatomic, readonly) BOOL hasOnlySecureContent;
+@property (nonatomic, readonly) BOOL _webProcessIsResponsive;
 
 // Not KVO compliant.
 @property (nonatomic, readonly) NSURL *unreachableURL;
index d97e95d..30aad19 100644 (file)
@@ -85,6 +85,11 @@ using namespace WebKit;
     return _page->pageLoadState().hasOnlySecureContent();
 }
 
+- (BOOL)_webProcessIsResponsive
+{
+    return _page->process().responsivenessTimer()->isResponsive();
+}
+
 - (double)estimatedProgress
 {
     return _page->estimatedProgress();
index 0b3bf43..c01f903 100644 (file)
@@ -98,6 +98,16 @@ private:
     virtual void willChangeCertificateInfo() override { }
     virtual void didChangeCertificateInfo() override { }
 
+    virtual void willChangeWebProcessIsResponsive() override
+    {
+        [m_object willChangeValueForKey:@"_webProcessIsResponsive"];
+    }
+
+    virtual void didChangeWebProcessIsResponsive() override
+    {
+        [m_object didChangeValueForKey:@"_webProcessIsResponsive"];
+    }
+
     id m_object;
     RetainPtr<NSString> m_activeURLKey;
 };
index 008aa2f..c988c16 100644 (file)
@@ -767,6 +767,11 @@ static void setUpPagePolicyClient(WKBrowsingContextController *browsingContext,
     return _page->processIdentifier();
 }
 
+- (BOOL)_webProcessIsResponsive
+{
+    return _page->process().responsivenessTimer()->isResponsive();
+}
+
 @end
 
 #endif // WK_API_ENABLED
index 6da4e32..1b8fde9 100644 (file)
@@ -4002,6 +4002,11 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
 
 #endif
 
+- (BOOL)_webProcessIsResponsive
+{
+    return _page->process().responsivenessTimer()->isResponsive();
+}
+
 @end
 
 
index 7bd8baa..6601497 100644 (file)
@@ -228,6 +228,8 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
 
 @property (nonatomic, getter=_allowsMediaDocumentInlinePlayback, setter=_setAllowsMediaDocumentInlinePlayback:) BOOL _allowsMediaDocumentInlinePlayback;
 
+@property (nonatomic, readonly) BOOL _webProcessIsResponsive WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+
 @end
 
 
index cb08b2f..dae3543 100644 (file)
@@ -150,6 +150,8 @@ private:
     virtual void didChangeNetworkRequestsInProgress() override;
     virtual void willChangeCertificateInfo() override;
     virtual void didChangeCertificateInfo() override;
+    virtual void willChangeWebProcessIsResponsive() override;
+    virtual void didChangeWebProcessIsResponsive() override;
 
     WKWebView *m_webView;
     WeakObjCPtr<id <WKNavigationDelegate> > m_navigationDelegate;
index af8c7fb..0bdf09e 100644 (file)
@@ -907,6 +907,16 @@ void NavigationState::didChangeCertificateInfo()
     [m_webView didChangeValueForKey:@"certificateChain"];
 }
 
+void NavigationState::willChangeWebProcessIsResponsive()
+{
+    [m_webView willChangeValueForKey:@"_webProcessIsResponsive"];
+}
+
+void NavigationState::didChangeWebProcessIsResponsive()
+{
+    [m_webView didChangeValueForKey:@"_webProcessIsResponsive"];
+}
+
 } // namespace WebKit
 
 #endif
index 431e806..80444d6 100644 (file)
@@ -402,6 +402,14 @@ bool PageLoadState::isLoading(const Data& data)
     return false;
 }
 
+void PageLoadState::willChangeProcessIsResponsive()
+{
+}
+
+void PageLoadState::didChangeProcessIsResponsive()
+{
+}
+
 void PageLoadState::callObserverCallback(void (Observer::*callback)())
 {
     for (auto* observer : m_observers)
index c723f54..402c97f 100644 (file)
@@ -75,6 +75,9 @@ public:
 
         virtual void willChangeCertificateInfo() = 0;
         virtual void didChangeCertificateInfo() = 0;
+
+        virtual void willChangeWebProcessIsResponsive() = 0;
+        virtual void didChangeWebProcessIsResponsive() = 0;
     };
 
     class Transaction {
@@ -162,6 +165,11 @@ public:
     void didFinishProgress(const Transaction::Token&);
     void setNetworkRequestsInProgress(const Transaction::Token&, bool);
 
+    // FIXME: We piggy-back off PageLoadState::Observer so that both WKWebView and WKObservablePageState
+    // can listen for changes. Once we get rid of WKObservablePageState these could just be part of API::NavigationClient.
+    void willChangeProcessIsResponsive();
+    void didChangeProcessIsResponsive();
+
 private:
     void beginTransaction() { ++m_outstandingTransactionCount; }
     void endTransaction();
index 69aed9a..651ba5b 100644 (file)
@@ -30,7 +30,7 @@ namespace WebKit {
 
 static const double responsivenessTimeout = 3;
 
-ResponsivenessTimer::ResponsivenessTimer(ResponsivenessTimer::Client* client)
+ResponsivenessTimer::ResponsivenessTimer(ResponsivenessTimer::Client& client)
     : m_client(client)
     , m_isResponsive(true)
     , m_timer(RunLoop::main(), this, &ResponsivenessTimer::timerFired)
@@ -52,8 +52,11 @@ void ResponsivenessTimer::timerFired()
     if (!m_isResponsive)
         return;
 
+    m_client.willChangeIsResponsive();
     m_isResponsive = false;
-    m_client->didBecomeUnresponsive(this);
+    m_client.didChangeIsResponsive();
+
+    m_client.didBecomeUnresponsive();
 }
     
 void ResponsivenessTimer::start()
@@ -67,9 +70,12 @@ void ResponsivenessTimer::start()
 void ResponsivenessTimer::stop()
 {
     if (!m_isResponsive) {
-        // We got a life sign from the web process!
-        m_client->didBecomeResponsive(this);
+        // We got a life sign from the web process.
+        m_client.willChangeIsResponsive();
         m_isResponsive = true;
+        m_client.didChangeIsResponsive();
+
+        m_client.didBecomeResponsive();
     }
 
     m_timer.stop();
index 574131b..0955372 100644 (file)
@@ -35,11 +35,14 @@ public:
     class Client {
     public:
         virtual ~Client() { }
-        virtual void didBecomeUnresponsive(ResponsivenessTimer*) = 0;
-        virtual void didBecomeResponsive(ResponsivenessTimer*) = 0;
+        virtual void didBecomeUnresponsive() = 0;
+        virtual void didBecomeResponsive() = 0;
+
+        virtual void willChangeIsResponsive() = 0;
+        virtual void didChangeIsResponsive() = 0;
     };
 
-    explicit ResponsivenessTimer(ResponsivenessTimer::Client*);
+    explicit ResponsivenessTimer(ResponsivenessTimer::Client&);
     ~ResponsivenessTimer();
     
     void start();
@@ -52,7 +55,7 @@ public:
 private:
     void timerFired();
 
-    ResponsivenessTimer::Client* m_client;
+    ResponsivenessTimer::Client& m_client;
     bool m_isResponsive;
 
     RunLoop::Timer<ResponsivenessTimer> m_timer;
index f31d4c2..098a784 100644 (file)
@@ -4880,6 +4880,16 @@ void WebPageProxy::processDidBecomeResponsive()
         m_loaderClient->processDidBecomeResponsive(*this);
 }
 
+void WebPageProxy::willChangeProcessIsResponsive()
+{
+    m_pageLoadState.willChangeProcessIsResponsive();
+}
+
+void WebPageProxy::didChangeProcessIsResponsive()
+{
+    m_pageLoadState.didChangeProcessIsResponsive();
+}
+
 void WebPageProxy::processDidCrash()
 {
     ASSERT(m_isValid);
index b84950f..64f2dc6 100644 (file)
@@ -811,6 +811,9 @@ public:
     void processDidBecomeUnresponsive();
     void processDidBecomeResponsive();
     void processDidCrash();
+    void willChangeProcessIsResponsive();
+    void didChangeProcessIsResponsive();
+
 #if PLATFORM(IOS)
     void processWillBecomeSuspended();
     void processWillBecomeForeground();
index e53dad5..1912cda 100644 (file)
@@ -100,7 +100,7 @@ Ref<WebProcessProxy> WebProcessProxy::create(WebProcessPool& processPool)
 }
 
 WebProcessProxy::WebProcessProxy(WebProcessPool& processPool)
-    : m_responsivenessTimer(this)
+    : m_responsivenessTimer(*this)
     , m_processPool(processPool)
     , m_mayHaveUniversalFileReadSandboxExtension(false)
     , m_customProtocolManagerProxy(this, processPool)
@@ -552,20 +552,36 @@ void WebProcessProxy::didReceiveInvalidMessage(IPC::Connection& connection, IPC:
     didClose(connection);
 }
 
-void WebProcessProxy::didBecomeUnresponsive(ResponsivenessTimer*)
+void WebProcessProxy::didBecomeUnresponsive()
 {
     Vector<RefPtr<WebPageProxy>> pages;
     copyValuesToVector(m_pageMap, pages);
-    for (size_t i = 0, size = pages.size(); i < size; ++i)
-        pages[i]->processDidBecomeUnresponsive();
+    for (auto& page : pages)
+        page->processDidBecomeUnresponsive();
 }
 
-void WebProcessProxy::didBecomeResponsive(ResponsivenessTimer*)
+void WebProcessProxy::didBecomeResponsive()
 {
     Vector<RefPtr<WebPageProxy>> pages;
     copyValuesToVector(m_pageMap, pages);
-    for (size_t i = 0, size = pages.size(); i < size; ++i)
-        pages[i]->processDidBecomeResponsive();
+    for (auto& page : pages)
+        page->processDidBecomeResponsive();
+}
+
+void WebProcessProxy::willChangeIsResponsive()
+{
+    Vector<RefPtr<WebPageProxy>> pages;
+    copyValuesToVector(m_pageMap, pages);
+    for (auto& page : pages)
+        page->willChangeProcessIsResponsive();
+}
+
+void WebProcessProxy::didChangeIsResponsive()
+{
+    Vector<RefPtr<WebPageProxy>> pages;
+    copyValuesToVector(m_pageMap, pages);
+    for (auto& page : pages)
+        page->didChangeProcessIsResponsive();
 }
 
 void WebProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Connection::Identifier connectionIdentifier)
index 4f10ab2..690df3c 100644 (file)
@@ -206,8 +206,10 @@ private:
     virtual IPC::ProcessType remoteProcessType() override { return IPC::ProcessType::Web; }
 
     // ResponsivenessTimer::Client
-    void didBecomeUnresponsive(ResponsivenessTimer*) override;
-    void didBecomeResponsive(ResponsivenessTimer*) override;
+    void didBecomeUnresponsive() override;
+    void didBecomeResponsive() override;
+    virtual void willChangeIsResponsive() override;
+    virtual void didChangeIsResponsive() override;
 
     // ProcessThrottlerClient
     void sendProcessWillSuspendImminently() override;