<rdar://problem/11176921> and https://bugs.webkit.org/show_bug.cgi?id=83600 Need...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Apr 2012 17:46:05 +0000 (17:46 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Apr 2012 17:46:05 +0000 (17:46 +0000)
Source/WebKit2:

- Add a new WKBundlePageLoaderClient callback allowing the bundle to be notified
  of back/forward navigations (and deny them if it chooses)
- Add a new API to WKBundleBackForwardListItem to probe if the item is in the page cache.

Reviewed by Darin Adler.

Add the new WKBundleBackForwardListItem API:
* WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.cpp:
(WKBundleBackForwardListItemIsInPageCache):
* WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.h:
* WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.h:
(WebKit::InjectedBundleBackForwardListItem::isInPageCache):

Update the UI page loader client to allow for a user data object to be passed from the bundle:
* UIProcess/API/C/WKPage.h:
* UIProcess/WebLoaderClient.cpp:
(WebKit::WebLoaderClient::shouldGoToBackForwardListItem): Update a comment typo.
(WebKit::WebLoaderClient::willGoToBackForwardListItem): Update for the user data field.
* UIProcess/WebLoaderClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::willGoToBackForwardListItem):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

Add the new callback to the bundle loader client:
* WebProcess/InjectedBundle/API/c/WKBundlePage.h:
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
(WebKit::InjectedBundlePageLoaderClient::shouldGoToBackForwardListItem):
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
(InjectedBundlePageLoaderClient):

Call the bundle client before doing anything else, possibly canceling the navigation:
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::shouldGoToHistoryItem):

* WebProcess/qt/QtBuiltinBundlePage.cpp:
(WebKit::QtBuiltinBundlePage::QtBuiltinBundlePage) Adopt new bundle client interface.

Tools:

Add a test ShouldGoToBackForwardListItem that exercises the new BundlePageLoaderClient
callback as well as the new WKBundleBackForwardListItemIsInPageCache() API.

Reviewed by Darin Adler.

* TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp: Added.
(TestWebKitAPI::didFinishLoadForFrame):
(TestWebKitAPI::willGoToBackForwardListItem):
(TestWebKitAPI::setPageLoaderClient):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp: Added.
(ShouldGoToBackForwardListItemTest):
(TestWebKitAPI::shouldGoToBackForwardListItemCallback):
(TestWebKitAPI::ShouldGoToBackForwardListItemTest::ShouldGoToBackForwardListItemTest):
(TestWebKitAPI::ShouldGoToBackForwardListItemTest::didCreatePage):
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:

* WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
(WTR::InjectedBundlePage::InjectedBundlePage): Update for the new client.

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

20 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.h
Source/WebKit2/UIProcess/WebLoaderClient.cpp
Source/WebKit2/UIProcess/WebLoaderClient.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.h
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.h
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/qt/QtBuiltinBundlePage.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp [new file with mode: 0644]
Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp

index 6165717..9347eb8 100644 (file)
@@ -1,3 +1,46 @@
+2012-04-13  Brady Eidson  <beidson@apple.com>
+
+        <rdar://problem/11176921> and https://bugs.webkit.org/show_bug.cgi?id=83600
+        Need WebKit2 API to notify whether history loads are in the page cache
+
+        - Add a new WKBundlePageLoaderClient callback allowing the bundle to be notified
+          of back/forward navigations (and deny them if it chooses)
+        - Add a new API to WKBundleBackForwardListItem to probe if the item is in the page cache.
+
+        Reviewed by Darin Adler.
+
+        Add the new WKBundleBackForwardListItem API:
+        * WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.cpp:
+        (WKBundleBackForwardListItemIsInPageCache):
+        * WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.h:
+        * WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.h:
+        (WebKit::InjectedBundleBackForwardListItem::isInPageCache):
+
+        Update the UI page loader client to allow for a user data object to be passed from the bundle:
+        * UIProcess/API/C/WKPage.h:
+        * UIProcess/WebLoaderClient.cpp:
+        (WebKit::WebLoaderClient::shouldGoToBackForwardListItem): Update a comment typo.
+        (WebKit::WebLoaderClient::willGoToBackForwardListItem): Update for the user data field.
+        * UIProcess/WebLoaderClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::willGoToBackForwardListItem):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+
+        Add the new callback to the bundle loader client:
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.h: 
+        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
+        (WebKit::InjectedBundlePageLoaderClient::shouldGoToBackForwardListItem):
+        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
+        (InjectedBundlePageLoaderClient):
+
+        Call the bundle client before doing anything else, possibly canceling the navigation:
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::shouldGoToHistoryItem):
+
+        * WebProcess/qt/QtBuiltinBundlePage.cpp:
+        (WebKit::QtBuiltinBundlePage::QtBuiltinBundlePage) Adopt new bundle client interface.
+
 2012-04-13  Dinu Jacob  <dinu.jacob@nokia.com>
 
         [Qt][WK2] Title in MiniBrowser is not updated for a page with no title
index b07b6c0..5634405 100644 (file)
@@ -71,7 +71,7 @@ typedef void (*WKPageDidChangeBackForwardListCallback)(WKPageRef page, WKBackFor
 typedef bool (*WKPageShouldGoToBackForwardListItemCallback)(WKPageRef page, WKBackForwardListItemRef item, const void *clientInfo);
 typedef void (*WKPageDidFailToInitializePluginCallback)(WKPageRef page, WKStringRef mimeType, const void* clientInfo);
 typedef void (*WKPageDidNewFirstVisuallyNonEmptyLayoutCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo);
-typedef void (*WKPageWillGoToBackForwardListItemCallback)(WKPageRef page, WKBackForwardListItemRef item, const void *clientInfo);
+typedef void (*WKPageWillGoToBackForwardListItemCallback)(WKPageRef page, WKBackForwardListItemRef item, WKTypeRef userData, const void *clientInfo);
 
 struct WKPageLoaderClient {
     int                                                                 version;
index 2aae016..ddd92c4 100644 (file)
@@ -243,17 +243,17 @@ bool WebLoaderClient::shouldGoToBackForwardListItem(WebPageProxy* page, WebBackF
 {
     // We should only even considering sending the shouldGoToBackForwardListItem() client callback
     // for version 0 clients. Later versioned clients should get willGoToBackForwardListItem() instead,
-    // but do to XPC race conditions this one might have been called instead.
+    // but due to XPC race conditions this one might have been called instead.
     if (m_client.version > 0 || !m_client.shouldGoToBackForwardListItem)
         return true;
 
     return m_client.shouldGoToBackForwardListItem(toAPI(page), toAPI(item), m_client.clientInfo);
 }
 
-void WebLoaderClient::willGoToBackForwardListItem(WebPageProxy* page, WebBackForwardListItem* item)
+void WebLoaderClient::willGoToBackForwardListItem(WebPageProxy* page, WebBackForwardListItem* item, APIObject* userData)
 {
     if (m_client.willGoToBackForwardListItem)
-        m_client.willGoToBackForwardListItem(toAPI(page), toAPI(item), m_client.clientInfo);
+        m_client.willGoToBackForwardListItem(toAPI(page), toAPI(item), toAPI(userData), m_client.clientInfo);
 }
 
 void WebLoaderClient::didFailToInitializePlugin(WebPageProxy* page, const String& mimeType)
index 55cc6aa..cd0d6be 100644 (file)
@@ -83,7 +83,7 @@ public:
 
     void didChangeBackForwardList(WebPageProxy*, WebBackForwardListItem* addedItem, Vector<RefPtr<APIObject> >* removedItems);
     bool shouldGoToBackForwardListItem(WebPageProxy*, WebBackForwardListItem*);
-    void willGoToBackForwardListItem(WebPageProxy*, WebBackForwardListItem*);
+    void willGoToBackForwardListItem(WebPageProxy*, WebBackForwardListItem*, APIObject*);
 
     void didFailToInitializePlugin(WebPageProxy*, const String& mimeType);
 };
index cdd39e5..2eda08c 100644 (file)
@@ -642,10 +642,15 @@ void WebPageProxy::shouldGoToBackForwardListItem(uint64_t itemID, bool& shouldGo
     shouldGoToBackForwardItem = item && m_loaderClient.shouldGoToBackForwardListItem(this, item);
 }
 
-void WebPageProxy::willGoToBackForwardListItem(uint64_t itemID)
+void WebPageProxy::willGoToBackForwardListItem(uint64_t itemID, CoreIPC::ArgumentDecoder* arguments)
 {
+    RefPtr<APIObject> userData;
+    WebContextUserMessageDecoder messageDecoder(userData, m_process->context());
+    if (!arguments->decode(messageDecoder))
+        return;
+
     if (WebBackForwardListItem* item = process()->webBackForwardItem(itemID))
-        m_loaderClient.willGoToBackForwardListItem(this, item);
+        m_loaderClient.willGoToBackForwardListItem(this, item, userData.get());
 }
 
 String WebPageProxy::activeURL() const
index 17de19f..25e639a 100644 (file)
@@ -272,7 +272,7 @@ public:
     void tryRestoreScrollPosition();
     void didChangeBackForwardList(WebBackForwardListItem* addedItem, Vector<RefPtr<APIObject> >* removedItems);
     void shouldGoToBackForwardListItem(uint64_t itemID, bool& shouldGoToBackForwardListItem);
-    void willGoToBackForwardListItem(uint64_t itemID);
+    void willGoToBackForwardListItem(uint64_t itemID, CoreIPC::ArgumentDecoder* arguments);
 
     String activeURL() const;
     String provisionalURL() const;
index 373d848..c850760 100644 (file)
@@ -166,7 +166,7 @@ messages -> WebPageProxy {
     BackForwardForwardListCount() -> (int32_t count)
     BackForwardClear()
     ShouldGoToBackForwardListItem(uint64_t itemID) -> (bool shouldGoToBackForwardListItem)
-    WillGoToBackForwardListItem(uint64_t itemID)
+    WillGoToBackForwardListItem(uint64_t itemID, WebKit::InjectedBundleUserMessageEncoder userData)
 
     # Undo/Redo messages
     RegisterEditCommandForUndo(uint64_t commandID, uint32_t editAction)
index e9845e3..4b32b34 100644 (file)
@@ -67,6 +67,11 @@ bool WKBundleBackForwardListItemIsTargetItem(WKBundleBackForwardListItemRef item
     return toImpl(itemRef)->isTargetItem();
 }
 
+bool WKBundleBackForwardListItemIsInPageCache(WKBundleBackForwardListItemRef itemRef)
+{
+    return toImpl(itemRef)->isInPageCache();
+}
+
 WKArrayRef WKBundleBackForwardListItemCopyChildren(WKBundleBackForwardListItemRef itemRef)
 {
     return toAPI(toImpl(itemRef)->children().leakRef());
index f256464..e9475ac 100644 (file)
@@ -43,6 +43,8 @@ WK_EXPORT WKStringRef WKBundleBackForwardListItemCopyTitle(WKBundleBackForwardLi
 WK_EXPORT WKStringRef WKBundleBackForwardListItemCopyTarget(WKBundleBackForwardListItemRef item);
 WK_EXPORT bool WKBundleBackForwardListItemIsTargetItem(WKBundleBackForwardListItemRef item);
 
+WK_EXPORT bool WKBundleBackForwardListItemIsInPageCache(WKBundleBackForwardListItemRef item);
+
 WK_EXPORT WKArrayRef WKBundleBackForwardListItemCopyChildren(WKBundleBackForwardListItemRef item);
 
 #ifdef __cplusplus
index e68e558..5a4d0f6 100644 (file)
@@ -101,6 +101,7 @@ typedef void (*WKBundlePageDidClearWindowObjectForFrameCallback)(WKBundlePageRef
 typedef void (*WKBundlePageDidCancelClientRedirectForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo);
 typedef void (*WKBundlePageWillPerformClientRedirectForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKURLRef url, double delay, double date, const void *clientInfo);
 typedef void (*WKBundlePageDidHandleOnloadEventsForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo);
+typedef bool (*WKBundlePageShouldGoToBackForwardListItemCallback)(WKBundlePageRef page, WKBundleBackForwardListItemRef item, WKTypeRef* userData, const void *clientInfo);
 
 struct WKBundlePageLoaderClient {
     int                                                                 version;
@@ -130,6 +131,7 @@ struct WKBundlePageLoaderClient {
     WKBundlePageDidLayoutForFrameCallback                               didLayoutForFrame;
     WKBundlePageDidNewFirstVisuallyNonEmptyLayoutCallback               didNewFirstVisuallyNonEmptyLayout;
     WKBundlePageDidDetectXSSForFrameCallback                            didDetectXSSForFrame;
+    WKBundlePageShouldGoToBackForwardListItemCallback                   shouldGoToBackForwardListItem;
 };
 typedef struct WKBundlePageLoaderClient WKBundlePageLoaderClient;
 
index 6cd9ec6..da08fb7 100644 (file)
@@ -53,6 +53,7 @@ public:
 
     const String& target() const { return m_item->target(); }
     bool isTargetItem() const { return m_item->isTargetItem(); }
+    bool isInPageCache() const { return m_item->isInPageCache(); }
 
     PassRefPtr<ImmutableArray> children() const;
 
index 24a3b81..2084b58 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -36,6 +36,18 @@ using namespace WebCore;
 
 namespace WebKit {
 
+bool InjectedBundlePageLoaderClient::shouldGoToBackForwardListItem(WebPage* page, InjectedBundleBackForwardListItem* item, RefPtr<APIObject>& userData)
+{
+    if (!m_client.shouldGoToBackForwardListItem)
+        return true;
+
+    WKTypeRef userDataToPass = 0;
+    bool result = m_client.shouldGoToBackForwardListItem(toAPI(page), toAPI(item), &userDataToPass, m_client.clientInfo);
+    userData = adoptRef(toImpl(userDataToPass));
+    
+    return result;
+}
+
 void InjectedBundlePageLoaderClient::didStartProvisionalLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData)
 {
     if (!m_client.didStartProvisionalLoadForFrame)
index 1cc41a6..04a2ac2 100644 (file)
@@ -42,11 +42,13 @@ class ResourceResponse;
 namespace WebKit {
 
 class APIObject;
+class InjectedBundleBackForwardListItem;
 class WebPage;
 class WebFrame;
 
 class InjectedBundlePageLoaderClient : public APIClient<WKBundlePageLoaderClient, kWKBundlePageLoaderClientCurrentVersion> {
 public:
+    bool shouldGoToBackForwardListItem(WebPage*, InjectedBundleBackForwardListItem*, RefPtr<APIObject>& userData);
     void didStartProvisionalLoadForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData);
     void didReceiveServerRedirectForProvisionalLoadForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData);
     void didFailProvisionalLoadWithErrorForFrame(WebPage*, WebFrame*, const WebCore::ResourceError&, RefPtr<APIObject>& userData);
index 9a2b2e0..9e7c6be 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "AuthenticationManager.h"
 #include "DataReference.h"
+#include "InjectedBundleBackForwardListItem.h"
 #include "InjectedBundleNavigationAction.h"
 #include "InjectedBundleUserMessageCoders.h"
 #include "PlatformCertificateInfo.h"
@@ -930,13 +931,20 @@ bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem* item) const
         ASSERT_NOT_REACHED();
         return false;
     }
+
+    RefPtr<InjectedBundleBackForwardListItem> bundleItem = InjectedBundleBackForwardListItem::create(item);
+    RefPtr<APIObject> userData;
+
+    // Ask the bundle client first
+    bool shouldGoToBackForwardListItem = webPage->injectedBundleLoaderClient().shouldGoToBackForwardListItem(webPage, bundleItem.get(), userData);
+    if (!shouldGoToBackForwardListItem)
+        return false;
     
     if (webPage->willGoToBackForwardItemCallbackEnabled()) {
-        webPage->send(Messages::WebPageProxy::WillGoToBackForwardListItem(itemID));
+        webPage->send(Messages::WebPageProxy::WillGoToBackForwardListItem(itemID, InjectedBundleUserMessageEncoder(userData.get())));
         return true;
     }
     
-    bool shouldGoToBackForwardListItem;
     if (!webPage->sendSync(Messages::WebPageProxy::ShouldGoToBackForwardListItem(itemID), Messages::WebPageProxy::ShouldGoToBackForwardListItem::Reply(shouldGoToBackForwardListItem)))
         return false;
     
index 4a2d554..930c630 100644 (file)
@@ -69,6 +69,7 @@ QtBuiltinBundlePage::QtBuiltinBundlePage(QtBuiltinBundle* bundle, WKBundlePageRe
         0, // didLayoutForFrame
         0, // didNewFirstVisuallyNonEmptyLayoutForFrame
         0, // didDetectXSSForFrame
+        0, // shouldGoToBackForwardListItem
     };
     WKBundlePageSetPageLoaderClient(m_page, &loaderClient);
 }
index fa4430f..c5d42c1 100644 (file)
@@ -1,3 +1,28 @@
+2012-04-10  Brady Eidson  <beidson@apple.com>
+
+        <rdar://problem/11176921> and https://bugs.webkit.org/show_bug.cgi?id=83600
+        Need WebKit2 API to notify whether history loads are in the page cache
+
+        Add a test ShouldGoToBackForwardListItem that exercises the new BundlePageLoaderClient
+        callback as well as the new WKBundleBackForwardListItemIsInPageCache() API.
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp: Added.
+        (TestWebKitAPI::didFinishLoadForFrame):
+        (TestWebKitAPI::willGoToBackForwardListItem):
+        (TestWebKitAPI::setPageLoaderClient):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp: Added.
+        (ShouldGoToBackForwardListItemTest):
+        (TestWebKitAPI::shouldGoToBackForwardListItemCallback):
+        (TestWebKitAPI::ShouldGoToBackForwardListItemTest::ShouldGoToBackForwardListItemTest):
+        (TestWebKitAPI::ShouldGoToBackForwardListItemTest::didCreatePage):
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
+        (WTR::InjectedBundlePage::InjectedBundlePage): Update for the new client.
+
 2012-04-13  Dominik Röttsches  <dominik.rottsches@linux.intel.com>
 
         Group EFL bots into a category on the buildbot master
index d116c75..b82579f 100644 (file)
@@ -43,6 +43,8 @@
                517E7DFC15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */; };
                517E7E04151119C100D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */; };
                51FBBB4D1513D4E900822738 /* WebViewCanPasteURL.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51FBBB4C1513D4E900822738 /* WebViewCanPasteURL.mm */; };
+               51FCF79A1534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51FCF7981534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp */; };
+               51FCF7A11534B2A000104491 /* ShouldGoToBackForwardListItem_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51FCF7971534AC6D00104491 /* ShouldGoToBackForwardListItem_Bundle.cpp */; };
                520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */; };
                520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4B141EB09E00937EA8 /* WebArchive.cpp */; };
                52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */; };
                517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCachePruneWithinResourceLoadDelegate.mm; sourceTree = "<group>"; };
                517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = MemoryCachePruneWithinResourceLoadDelegate.html; sourceTree = "<group>"; };
                51FBBB4C1513D4E900822738 /* WebViewCanPasteURL.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewCanPasteURL.mm; sourceTree = "<group>"; };
+               51FCF7971534AC6D00104491 /* ShouldGoToBackForwardListItem_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShouldGoToBackForwardListItem_Bundle.cpp; sourceTree = "<group>"; };
+               51FCF7981534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShouldGoToBackForwardListItem.cpp; sourceTree = "<group>"; };
                520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive_Bundle.cpp; sourceTree = "<group>"; };
                520BCF4B141EB09E00937EA8 /* WebArchive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive.cpp; sourceTree = "<group>"; };
                52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadAlternateHTMLStringWithNonDirectoryURL.cpp; sourceTree = "<group>"; };
                                C0BD669C131D3CF700E18F2A /* ResponsivenessTimerDoesntFireEarly.cpp */,
                                C0BD669E131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp */,
                                C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */,
+                               51FCF7981534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp */,
+                               51FCF7971534AC6D00104491 /* ShouldGoToBackForwardListItem_Bundle.cpp */,
                                C02B77F1126612140026BF0F /* SpacebarScrolling.cpp */,
                                BC22D31314DC689800FFB1DD /* UserMessage.cpp */,
                                BC22D31714DC68B800FFB1DD /* UserMessage_Bundle.cpp */,
                                51FBBB4D1513D4E900822738 /* WebViewCanPasteURL.mm in Sources */,
                                5142B2711517C88B00C32B19 /* ContextMenuCanCopyURL.mm in Sources */,
                                C540F776152E4DA000A40C8C /* SimplifyMarkup.mm in Sources */,
+                               51FCF79A1534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                93F7E86F14DC8E5C00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp in Sources */,
                                BC22D31914DC68B900FFB1DD /* UserMessage_Bundle.cpp in Sources */,
                                93AF4ECE1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp in Sources */,
+                               51FCF7A11534B2A000104491 /* ShouldGoToBackForwardListItem_Bundle.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem.cpp
new file mode 100644 (file)
index 0000000..c13a5eb
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+
+#include <WebKit2/WKString.h>
+
+namespace TestWebKitAPI {
+
+static bool finished = false;
+static bool receivedProperBackForwardCallbacks = false;
+
+static void didFinishLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef, const void*)
+{
+    // Only mark finished when the main frame loads
+    if (WKFrameGetParentFrame(frame))
+        return;
+
+    finished = true;
+}
+
+static void willGoToBackForwardListItem(WKPageRef, WKBackForwardListItemRef, WKTypeRef userData, const void*)
+{
+    if (WKGetTypeID(userData) == WKStringGetTypeID()) {
+        if (WKStringIsEqualToUTF8CString((WKStringRef)userData, "shouldGoToBackForwardListItemCallback called as expected"))
+            receivedProperBackForwardCallbacks = true;
+    }
+
+    finished = true;
+}
+
+static void setPageLoaderClient(WKPageRef page)
+{
+    WKPageLoaderClient loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+    loaderClient.version = 1;
+    loaderClient.clientInfo = 0;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+    loaderClient.willGoToBackForwardListItem = willGoToBackForwardListItem;
+
+    WKPageSetPageLoaderClient(page, &loaderClient);
+}
+
+TEST(WebKit2, ShouldGoToBackForwardListItem)
+{
+    WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("ShouldGoToBackForwardListItemTest"));
+    // Enable the page cache so we can test the WKBundleBackForwardListItemIsInPageCache API
+    WKContextSetCacheModel(context.get(), kWKCacheModelDocumentBrowser);
+
+    PlatformWebView webView(context.get());
+    setPageLoaderClient(webView.page());
+
+    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get());
+    Util::run(&finished);
+    
+    finished = false;
+    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple-iframe", "html")).get());
+    Util::run(&finished);
+
+    finished = false;
+    WKPageGoBack(webView.page());
+    Util::run(&finished);
+    
+    EXPECT_EQ(receivedProperBackForwardCallbacks, true);
+}
+
+} // namespace TestWebKitAPI
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp
new file mode 100644 (file)
index 0000000..0f15c47
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "InjectedBundleTest.h"
+
+#include "PlatformUtilities.h"
+#include <WebKit2/WKBundlePage.h>
+#include <WebKit2/WKBundleBackForwardListItem.h>
+
+namespace TestWebKitAPI {
+
+class ShouldGoToBackForwardListItemTest : public InjectedBundleTest {
+public:
+    ShouldGoToBackForwardListItemTest(const std::string& identifier);
+
+    virtual void didCreatePage(WKBundleRef bundle, WKBundlePageRef page);
+};
+
+static InjectedBundleTest::Register<ShouldGoToBackForwardListItemTest> registrar("ShouldGoToBackForwardListItemTest");
+
+static bool shouldGoToBackForwardListItemCallback(WKBundlePageRef, WKBundleBackForwardListItemRef item, WKTypeRef* userData, const void*)
+{
+    // The item should be in the page cache
+    if (WKBundleBackForwardListItemIsInPageCache(item))
+        *userData = WKStringCreateWithUTF8CString("shouldGoToBackForwardListItemCallback called as expected");
+
+    return true;
+}
+
+ShouldGoToBackForwardListItemTest::ShouldGoToBackForwardListItemTest(const std::string& identifier)
+    : InjectedBundleTest(identifier)
+{
+}
+
+void ShouldGoToBackForwardListItemTest::didCreatePage(WKBundleRef bundle, WKBundlePageRef page)
+{    
+    WKBundlePageLoaderClient pageLoaderClient;
+    memset(&pageLoaderClient, 0, sizeof(pageLoaderClient));
+    
+    pageLoaderClient.version = 1;
+    pageLoaderClient.clientInfo = this;
+    pageLoaderClient.shouldGoToBackForwardListItem = shouldGoToBackForwardListItemCallback;
+    
+    WKBundlePageSetPageLoaderClient(page, &pageLoaderClient);
+}
+
+} // namespace TestWebKitAPI
index 37b2064..7dbdc0d 100644 (file)
@@ -235,6 +235,7 @@ InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page)
         0, // didLayoutForFrame
         0, // didNewFirstVisuallyNonEmptyLayoutForFrame
         didDetectXSSForFrame,
+        0, // shouldGoToBackForwardListItem
     };
     WKBundlePageSetPageLoaderClient(m_page, &loaderClient);