[Cocoa] Notify the client when a navigation snapshot is taken
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Jul 2014 05:51:20 +0000 (05:51 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Jul 2014 05:51:20 +0000 (05:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134865

Reviewed by Sam Weinig.

* UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h: Declared new delegate method.

* UIProcess/Cocoa/NavigationState.h:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::setNavigationDelegate): Initialize new flag in
m_navigationDelegateMethods.
(WebKit::NavigationState::willRecordNavigationSnapshot): Added. Calls the new
WKNavigationDelegate method.

* UIProcess/PageClient.h: Declared new client function.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::willRecordNavigationSnapshot): Added. Calls the new client function.
* UIProcess/WebPageProxy.h:

* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::willRecordNavigationSnapshot): Override that calls
NavigationState::willRecordNavigationSnapshot.

* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::willRecordNavigationSnapshot): Ditto.

* UIProcess/mac/ViewSnapshotStore.mm:
(WebKit::ViewSnapshotStore::recordSnapshot): Added a call to
WebPageProxy::willRecordNavigationSnapshot.

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

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h
Source/WebKit2/UIProcess/Cocoa/NavigationState.h
Source/WebKit2/UIProcess/Cocoa/NavigationState.mm
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/ios/PageClientImplIOS.h
Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit2/UIProcess/mac/PageClientImpl.h
Source/WebKit2/UIProcess/mac/PageClientImpl.mm
Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm

index 0a60523..2bb0869 100644 (file)
@@ -1,3 +1,38 @@
+2014-07-12  Dan Bernstein  <mitz@apple.com>
+
+        [Cocoa] Notify the client when a navigation snapshot is taken
+        https://bugs.webkit.org/show_bug.cgi?id=134865
+
+        Reviewed by Sam Weinig.
+
+        * UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h: Declared new delegate method.
+
+        * UIProcess/Cocoa/NavigationState.h:
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::setNavigationDelegate): Initialize new flag in
+        m_navigationDelegateMethods.
+        (WebKit::NavigationState::willRecordNavigationSnapshot): Added. Calls the new
+        WKNavigationDelegate method.
+
+        * UIProcess/PageClient.h: Declared new client function.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::willRecordNavigationSnapshot): Added. Calls the new client function.
+        * UIProcess/WebPageProxy.h:
+
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::willRecordNavigationSnapshot): Override that calls
+        NavigationState::willRecordNavigationSnapshot.
+
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::willRecordNavigationSnapshot): Ditto.
+
+        * UIProcess/mac/ViewSnapshotStore.mm:
+        (WebKit::ViewSnapshotStore::recordSnapshot): Added a call to
+        WebPageProxy::willRecordNavigationSnapshot.
+
 2014-07-12  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Unreviewed, fix EFL build break since r171034.
index 641ce83..5fedca2 100644 (file)
@@ -64,7 +64,7 @@ typedef NS_ENUM(NSInteger, _WKSameDocumentNavigationType) {
 - (void)_webViewDidEndNavigationGesture:(WKWebView *)webView withNavigationToBackForwardListItem:(WKBackForwardListItem *)item;
 // Only called if how the gesture will end (with or without navigation) is known before it ends.
 - (void)_webViewWillEndNavigationGesture:(WKWebView *)webView withNavigationToBackForwardListItem:(WKBackForwardListItem *)item;
-
+- (void)_webView:(WKWebView *)webView willSnapshotBackForwardListItem:(WKBackForwardListItem *)item;
 
 #if TARGET_OS_IPHONE
 - (void)_webView:(WKWebView *)webView didStartLoadForQuickLookDocumentInMainFrameWithFileName:(NSString *)fileName uti:(NSString *)uti;
index 9fe2ba8..10179d2 100644 (file)
@@ -78,6 +78,7 @@ public:
     void navigationGestureDidBegin();
     void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&);
     void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&);
+    void willRecordNavigationSnapshot(WebBackForwardListItem&);
 
 private:
     class PolicyClient : public API::PolicyClient {
@@ -166,6 +167,7 @@ private:
         bool webViewDidBeginNavigationGesture : 1;
         bool webViewWillEndNavigationGestureWithNavigationToBackForwardListItem : 1;
         bool webViewDidEndNavigationGestureWithNavigationToBackForwardListItem : 1;
+        bool webViewWillSnapshotBackForwardListItem : 1;
 #if USE(QUICK_LOOK)
         bool webViewDidStartLoadForQuickLookDocumentInMainFrame : 1;
         bool webViewDidFinishLoadForQuickLookDocumentInMainFrame : 1;
index 44fc16b..72e0502 100644 (file)
@@ -140,6 +140,7 @@ void NavigationState::setNavigationDelegate(id <WKNavigationDelegate> delegate)
     m_navigationDelegateMethods.webViewDidBeginNavigationGesture = [delegate respondsToSelector:@selector(_webViewDidBeginNavigationGesture:)];
     m_navigationDelegateMethods.webViewWillEndNavigationGestureWithNavigationToBackForwardListItem = [delegate respondsToSelector:@selector(_webViewWillEndNavigationGesture:withNavigationToBackForwardListItem:)];
     m_navigationDelegateMethods.webViewDidEndNavigationGestureWithNavigationToBackForwardListItem = [delegate respondsToSelector:@selector(_webViewDidEndNavigationGesture:withNavigationToBackForwardListItem:)];
+    m_navigationDelegateMethods.webViewWillSnapshotBackForwardListItem = [delegate respondsToSelector:@selector(_webView:willSnapshotBackForwardListItem:)];
 #if USE(QUICK_LOOK)
     m_navigationDelegateMethods.webViewDidStartLoadForQuickLookDocumentInMainFrame = [delegate respondsToSelector:@selector(_webView:didStartLoadForQuickLookDocumentInMainFrameWithFileName:uti:)];
     m_navigationDelegateMethods.webViewDidFinishLoadForQuickLookDocumentInMainFrame = [delegate respondsToSelector:@selector(_webView:didFinishLoadForQuickLookDocumentInMainFrame:)];
@@ -290,6 +291,18 @@ void NavigationState::navigationGestureDidEnd(bool willNavigate, WebBackForwardL
     [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate) _webViewDidEndNavigationGesture:m_webView withNavigationToBackForwardListItem:willNavigate ? wrapper(item) : nil];
 }
 
+void NavigationState::willRecordNavigationSnapshot(WebBackForwardListItem& item)
+{
+    if (!m_navigationDelegateMethods.webViewWillSnapshotBackForwardListItem)
+        return;
+
+    auto navigationDelegate = m_navigationDelegate.get();
+    if (!navigationDelegate)
+        return;
+
+    [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate) _webView:m_webView willSnapshotBackForwardListItem:wrapper(item)];
+}
+
 NavigationState::PolicyClient::PolicyClient(NavigationState& navigationState)
     : m_navigationState(navigationState)
 {
index 9cfa5fa..cf16c9f 100644 (file)
@@ -298,6 +298,7 @@ public:
     virtual void navigationGestureDidBegin() = 0;
     virtual void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&) = 0;
     virtual void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&) = 0;
+    virtual void willRecordNavigationSnapshot(WebBackForwardListItem&) = 0;
 };
 
 } // namespace WebKit
index a69be6e..54c3e95 100644 (file)
@@ -5143,6 +5143,11 @@ void WebPageProxy::navigationGestureDidEnd(bool willNavigate, WebBackForwardList
     m_pageClient.navigationGestureDidEnd(willNavigate, item);
 }
 
+void WebPageProxy::willRecordNavigationSnapshot(WebBackForwardListItem& item)
+{
+    m_pageClient.willRecordNavigationSnapshot(item);
+}
+
 void WebPageProxy::navigationGestureSnapshotWasRemoved()
 {
     m_isShowingNavigationGestureSnapshot = false;
index c005688..d8b7bd6 100644 (file)
@@ -901,6 +901,7 @@ public:
     void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&);
     void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&);
     void navigationGestureSnapshotWasRemoved();
+    void willRecordNavigationSnapshot(WebBackForwardListItem&);
 
     bool isShowingNavigationGestureSnapshot() const { return m_isShowingNavigationGestureSnapshot; }
 
index f79eea6..d04bac5 100644 (file)
@@ -170,6 +170,7 @@ private:
     virtual void navigationGestureDidBegin() override;
     virtual void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&) override;
     virtual void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&) override;
+    virtual void willRecordNavigationSnapshot(WebBackForwardListItem&) override;
 
     WKContentView *m_contentView;
     WKWebView *m_webView;
index 5ba4deb..ba95af8 100644 (file)
@@ -667,6 +667,11 @@ void PageClientImpl::navigationGestureDidEnd(bool willNavigate, WebBackForwardLi
     NavigationState::fromWebPage(*m_webView->_page).navigationGestureDidEnd(willNavigate, item);
 }
 
+void PageClientImpl::willRecordNavigationSnapshot(WebBackForwardListItem& item)
+{
+    NavigationState::fromWebPage(*m_webView->_page).willRecordNavigationSnapshot(item);
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS)
index 5e220ed..cd7648a 100644 (file)
@@ -176,6 +176,7 @@ private:
     virtual void navigationGestureDidBegin() override;
     virtual void navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem&) override;
     virtual void navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem&) override;
+    virtual void willRecordNavigationSnapshot(WebBackForwardListItem&) override;
 
     NSView *activeView() const;
 
index 30ea39f..38c43cb 100644 (file)
@@ -714,6 +714,15 @@ void PageClientImpl::navigationGestureDidEnd(bool willNavigate, WebBackForwardLi
 #endif
 }
 
+void PageClientImpl::willRecordNavigationSnapshot(WebBackForwardListItem& item)
+{
+#if WK_API_ENABLED
+    NavigationState::fromWebPage(*m_webView->_page).willRecordNavigationSnapshot(item);
+#else
+    UNUSED_PARAM(item);
+#endif
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
index 55c174a..8c87032 100644 (file)
@@ -119,6 +119,8 @@ void ViewSnapshotStore::recordSnapshot(WebPageProxy& webPageProxy)
 
     pruneSnapshots(webPageProxy);
 
+    webPageProxy.willRecordNavigationSnapshot(*item);
+
     RefPtr<ViewSnapshot> snapshot = webPageProxy.takeViewSnapshot();
     if (!snapshot || !snapshot->hasImage())
         return;