Skip to content

Commit 7dc0ba0

Browse files
committed
Add WK2 SPI to prevent the previous back/forward item from remaining in the list
<rdar://problem/16248710> and https://bugs.webkit.org/show_bug.cgi?id=132636 Reviewed by Sam Weinig. Source/WebKit2: Add new PageLoaderClient SPI to keep the current back/forward item from remaining in the list: * UIProcess/API/APILoaderClient.h: (API::LoaderClient::shouldKeepCurrentBackForwardListItemInList): * UIProcess/API/C/WKPage.cpp: (WKPageSetPageLoaderClient): * UIProcess/API/C/WKPageLoaderClient.h: * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::shouldKeepCurrentBackForwardListItemInList): * UIProcess/WebPageProxy.h: * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::addItem): Use that SPI to determine whether we should insert the new item after the previous item, or simply replace the previous item. (WebKit::WebBackForwardList::goToItem): Use that SPI to determine whether the previous item stays or goes. Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebKit2/ShouldKeepCurrentBackForwardListItemInList.cpp: Added. (TestWebKitAPI::itemURLLastComponentIsString): (TestWebKitAPI::didFinishLoadForFrame): (TestWebKitAPI::willGoToBackForwardListItem): (TestWebKitAPI::shouldKeepCurrentBackForwardListItemInList): (TestWebKitAPI::setPageLoaderClient): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebKit2/simple2.html: Added. * TestWebKitAPI/Tests/WebKit2/simple3.html: Added. * WebKitTestRunner/TestController.cpp: (WTR::TestController::createWebViewWithOptions): Update for new client layout. Canonical link: https://commits.webkit.org/150678@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@168407 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 8ed7282 commit 7dc0ba0

13 files changed

Lines changed: 292 additions & 18 deletions

File tree

Source/WebKit2/ChangeLog

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2014-05-06 Brady Eidson <beidson@apple.com>
2+
3+
Add WK2 SPI to prevent the previous back/forward item from remaining in the list
4+
<rdar://problem/16248710> and https://bugs.webkit.org/show_bug.cgi?id=132636
5+
6+
Reviewed by Sam Weinig.
7+
8+
Add new PageLoaderClient SPI to keep the current back/forward item from remaining in the list:
9+
* UIProcess/API/APILoaderClient.h:
10+
(API::LoaderClient::shouldKeepCurrentBackForwardListItemInList):
11+
* UIProcess/API/C/WKPage.cpp:
12+
(WKPageSetPageLoaderClient):
13+
* UIProcess/API/C/WKPageLoaderClient.h:
14+
* UIProcess/WebPageProxy.cpp:
15+
(WebKit::WebPageProxy::shouldKeepCurrentBackForwardListItemInList):
16+
* UIProcess/WebPageProxy.h:
17+
18+
* UIProcess/WebBackForwardList.cpp:
19+
(WebKit::WebBackForwardList::addItem): Use that SPI to determine whether we should insert the new item after
20+
the previous item, or simply replace the previous item.
21+
(WebKit::WebBackForwardList::goToItem): Use that SPI to determine whether the previous item stays or goes.
22+
123
2014-05-06 Dan Bernstein <mitz@apple.com>
224

325
-[WKWebView isLoading] is NO immediately after -loadRequest: until the provisional load starts

Source/WebKit2/UIProcess/API/APILoaderClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class LoaderClient {
9090
virtual void processDidCrash(WebKit::WebPageProxy*) { }
9191

9292
virtual void didChangeBackForwardList(WebKit::WebPageProxy*, WebKit::WebBackForwardListItem*, Vector<RefPtr<WebKit::WebBackForwardListItem>>) { }
93+
virtual bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy*, WebKit::WebBackForwardListItem*) { return true; }
9394
virtual void willGoToBackForwardListItem(WebKit::WebPageProxy*, WebKit::WebBackForwardListItem*, API::Object*) { }
9495

9596
virtual PassRefPtr<Data> webCryptoMasterKey(WebKit::WebPageProxy&) { return nullptr; }

Source/WebKit2/UIProcess/API/C/WKPage.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,14 @@ void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase*
968968
m_client.didChangeBackForwardList(toAPI(page), toAPI(addedItem), toAPI(removedItemsArray.get()), m_client.base.clientInfo);
969969
}
970970

971+
virtual bool shouldKeepCurrentBackForwardListItemInList(WebKit::WebPageProxy* page, WebKit::WebBackForwardListItem* item) override
972+
{
973+
if (!m_client.shouldKeepCurrentBackForwardListItemInList)
974+
return false;
975+
976+
return m_client.shouldKeepCurrentBackForwardListItemInList(toAPI(page), toAPI(item));
977+
}
978+
971979
virtual void willGoToBackForwardListItem(WebPageProxy* page, WebBackForwardListItem* item, API::Object* userData) override
972980
{
973981
if (m_client.willGoToBackForwardListItem)

Source/WebKit2/UIProcess/API/C/WKPageLoaderClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ typedef bool (*WKPageCanAuthenticateAgainstProtectionSpaceInFrameCallback)(WKPag
6969
typedef void (*WKPageDidReceiveAuthenticationChallengeInFrameCallback)(WKPageRef page, WKFrameRef frame, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo);
7070
typedef void (*WKPageDidChangeBackForwardListCallback)(WKPageRef page, WKBackForwardListItemRef addedItem, WKArrayRef removedItems, const void *clientInfo);
7171
typedef bool (*WKPageShouldGoToBackForwardListItemCallback)(WKPageRef page, WKBackForwardListItemRef item, const void *clientInfo);
72+
typedef bool (*WKPageShouldKeepCurrentBackForwardListItemInListCallback)(WKPageRef page, WKBackForwardListItemRef item);
7273
typedef void (*WKPageWillGoToBackForwardListItemCallback)(WKPageRef page, WKBackForwardListItemRef item, WKTypeRef userData, const void *clientInfo);
7374
typedef void (*WKPageDidLayoutCallback)(WKPageRef page, WKLayoutMilestones milestones, WKTypeRef userData, const void *clientInfo);
7475
typedef WKPluginLoadPolicy (*WKPagePluginLoadPolicyCallback)(WKPageRef page, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInfoDictionary, WKStringRef* unavailabilityDescription, const void* clientInfo);
@@ -332,6 +333,7 @@ typedef struct WKPageLoaderClientV4 {
332333
// Version 4
333334
WKPageWebGLLoadPolicyCallback webGLLoadPolicy;
334335
WKPageWebGLLoadPolicyCallback resolveWebGLLoadPolicy;
336+
WKPageShouldKeepCurrentBackForwardListItemInListCallback shouldKeepCurrentBackForwardListItemInList;
335337
} WKPageLoaderClientV4;
336338

337339
// FIXME: These should be deprecated.

Source/WebKit2/UIProcess/WebBackForwardList.cpp

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,34 @@ void WebBackForwardList::addItem(WebBackForwardListItem* newItem)
113113
}
114114
m_entries.clear();
115115
}
116-
116+
117+
bool shouldKeepCurrentItem = true;
118+
117119
if (!m_hasCurrentIndex) {
118120
ASSERT(m_entries.isEmpty());
119121
m_currentIndex = 0;
120122
m_hasCurrentIndex = true;
121-
} else
122-
m_currentIndex++;
123+
} else {
124+
shouldKeepCurrentItem = m_page->shouldKeepCurrentBackForwardListItemInList(m_entries[m_currentIndex].get());
125+
if (shouldKeepCurrentItem)
126+
m_currentIndex++;
127+
}
123128

124-
// m_current never be pointing more than 1 past the end of the entries Vector.
125-
// If it is, something has gone wrong and we should not try to insert the new item.
126-
ASSERT(m_currentIndex <= m_entries.size());
127-
if (m_currentIndex <= m_entries.size())
128-
m_entries.insert(m_currentIndex, newItem);
129+
if (!shouldKeepCurrentItem) {
130+
// m_current never be pointing past the end of the entries Vector.
131+
// If it is, something has gone wrong and we should not try to swap in the new item.
132+
ASSERT(m_currentIndex < m_entries.size());
133+
134+
removedItems.append(m_entries[m_currentIndex]);
135+
m_entries[m_currentIndex] = newItem;
136+
} else {
137+
// m_current never be pointing more than 1 past the end of the entries Vector.
138+
// If it is, something has gone wrong and we should not try to insert the new item.
139+
ASSERT(m_currentIndex <= m_entries.size());
140+
141+
if (m_currentIndex <= m_entries.size())
142+
m_entries.insert(m_currentIndex, newItem);
143+
}
129144

130145
m_page->didChangeBackForwardList(newItem, std::move(removedItems));
131146
}
@@ -136,16 +151,32 @@ void WebBackForwardList::goToItem(WebBackForwardListItem* item)
136151

137152
if (!m_entries.size() || !item || !m_page || !m_hasCurrentIndex)
138153
return;
139-
140-
unsigned index = 0;
141-
for (; index < m_entries.size(); ++index) {
142-
if (m_entries[index] == item)
143-
break;
144-
}
145-
if (index < m_entries.size()) {
146-
m_currentIndex = index;
147-
m_page->didChangeBackForwardList(nullptr, { });
154+
155+
size_t targetIndex = m_entries.find(item);
156+
157+
// If the target item wasn't even in the list, there's nothing else to do.
158+
if (targetIndex == notFound)
159+
return;
160+
161+
// If we're going to an item different from the current item, ask the client if the current
162+
// item should remain in the list.
163+
WebBackForwardListItem* currentItem = m_entries[m_currentIndex].get();
164+
bool shouldKeepCurrentItem = true;
165+
if (currentItem != item)
166+
shouldKeepCurrentItem = m_page->shouldKeepCurrentBackForwardListItemInList(m_entries[m_currentIndex].get());
167+
168+
// If the client said to remove the current item, remove it and then update the target index.
169+
Vector<RefPtr<WebBackForwardListItem>> removedItems;
170+
if (!shouldKeepCurrentItem) {
171+
removedItems.append(currentItem);
172+
m_entries.remove(m_currentIndex);
173+
targetIndex = m_entries.find(item);
174+
175+
ASSERT(targetIndex != notFound);
148176
}
177+
178+
m_currentIndex = targetIndex;
179+
m_page->didChangeBackForwardList(nullptr, removedItems);
149180
}
150181

151182
WebBackForwardListItem* WebBackForwardList::currentItem() const

Source/WebKit2/UIProcess/WebPageProxy.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,11 @@ void WebPageProxy::willGoToBackForwardListItem(uint64_t itemID, IPC::MessageDeco
908908
m_loaderClient->willGoToBackForwardListItem(this, item, userData.get());
909909
}
910910

911+
bool WebPageProxy::shouldKeepCurrentBackForwardListItemInList(WebBackForwardListItem* item)
912+
{
913+
return m_loaderClient->shouldKeepCurrentBackForwardListItemInList(this, item);
914+
}
915+
911916
bool WebPageProxy::canShowMIMEType(const String& mimeType)
912917
{
913918
if (MIMETypeRegistry::canShowMIMEType(mimeType))

Source/WebKit2/UIProcess/WebPageProxy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ class WebPageProxy : public API::ObjectImpl<API::Object::Type::Page>
524524
void didChangeBackForwardList(WebBackForwardListItem* addedItem, Vector<RefPtr<WebBackForwardListItem>> removed);
525525
void willGoToBackForwardListItem(uint64_t itemID, IPC::MessageDecoder&);
526526

527+
bool shouldKeepCurrentBackForwardListItemInList(WebBackForwardListItem*);
528+
527529
bool willHandleHorizontalScrollEvents() const;
528530

529531
bool canShowMIMEType(const String& mimeType);

Tools/ChangeLog

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2014-05-06 Brady Eidson <beidson@apple.com>
2+
3+
Add WK2 SPI to prevent the previous back/forward item from remaining in the list
4+
<rdar://problem/16248710> and https://bugs.webkit.org/show_bug.cgi?id=132636
5+
6+
Reviewed by Sam Weinig.
7+
8+
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
9+
10+
* TestWebKitAPI/Tests/WebKit2/ShouldKeepCurrentBackForwardListItemInList.cpp: Added.
11+
(TestWebKitAPI::itemURLLastComponentIsString):
12+
(TestWebKitAPI::didFinishLoadForFrame):
13+
(TestWebKitAPI::willGoToBackForwardListItem):
14+
(TestWebKitAPI::shouldKeepCurrentBackForwardListItemInList):
15+
(TestWebKitAPI::setPageLoaderClient):
16+
(TestWebKitAPI::TEST):
17+
* TestWebKitAPI/Tests/WebKit2/simple2.html: Added.
18+
* TestWebKitAPI/Tests/WebKit2/simple3.html: Added.
19+
20+
* WebKitTestRunner/TestController.cpp:
21+
(WTR::TestController::createWebViewWithOptions): Update for new client layout.
22+
123
2014-05-06 Darin Adler <darin@apple.com>
224

325
Try to fix iOS build.

Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
5142B2731517C8C800C32B19 /* ContextMenuCanCopyURL.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5142B2721517C89100C32B19 /* ContextMenuCanCopyURL.html */; };
9797
517E7DFC15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */; };
9898
517E7E04151119C100D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */; };
99+
51E5C7021919C3B200D8B3E1 /* simple2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51E780361919AFF8001829A2 /* simple2.html */; };
100+
51E5C7031919C3B200D8B3E1 /* simple3.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51E780371919AFF8001829A2 /* simple3.html */; };
101+
51E5C7051919EA5F00D8B3E1 /* ShouldKeepCurrentBackForwardListItemInList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E5C7041919EA5F00D8B3E1 /* ShouldKeepCurrentBackForwardListItemInList.cpp */; };
99102
51E93017156B13E1004C99DF /* WKPageGetScaleFactorNotZero.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51E93016156B13E1004C99DF /* WKPageGetScaleFactorNotZero.cpp */; };
100103
51FBBB4D1513D4E900822738 /* WebViewCanPasteURL.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51FBBB4C1513D4E900822738 /* WebViewCanPasteURL.mm */; };
101104
51FCF79A1534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51FCF7981534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp */; };
@@ -279,6 +282,8 @@
279282
dstPath = TestWebKitAPI.resources;
280283
dstSubfolderSpec = 7;
281284
files = (
285+
51E5C7021919C3B200D8B3E1 /* simple2.html in Copy Resources */,
286+
51E5C7031919C3B200D8B3E1 /* simple3.html in Copy Resources */,
282287
290A9BB91735F63800D71BBC /* OpenNewWindow.html in Copy Resources */,
283288
290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */,
284289
C2CF975B16CEC71B0054E99D /* JSContextBackForwardCache1.html in Copy Resources */,
@@ -426,6 +431,9 @@
426431
5142B2721517C89100C32B19 /* ContextMenuCanCopyURL.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = ContextMenuCanCopyURL.html; sourceTree = "<group>"; };
427432
517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCachePruneWithinResourceLoadDelegate.mm; sourceTree = "<group>"; };
428433
517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = MemoryCachePruneWithinResourceLoadDelegate.html; sourceTree = "<group>"; };
434+
51E5C7041919EA5F00D8B3E1 /* ShouldKeepCurrentBackForwardListItemInList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShouldKeepCurrentBackForwardListItemInList.cpp; sourceTree = "<group>"; };
435+
51E780361919AFF8001829A2 /* simple2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = simple2.html; sourceTree = "<group>"; };
436+
51E780371919AFF8001829A2 /* simple3.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = simple3.html; sourceTree = "<group>"; };
429437
51E93016156B13E1004C99DF /* WKPageGetScaleFactorNotZero.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKPageGetScaleFactorNotZero.cpp; sourceTree = "<group>"; };
430438
51FBBB4C1513D4E900822738 /* WebViewCanPasteURL.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewCanPasteURL.mm; sourceTree = "<group>"; };
431439
51FCF7971534AC6D00104491 /* ShouldGoToBackForwardListItem_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShouldGoToBackForwardListItem_Bundle.cpp; sourceTree = "<group>"; };
@@ -541,7 +549,7 @@
541549
BCC8B95A12611F4700DE46A4 /* FailedLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FailedLoad.cpp; sourceTree = "<group>"; };
542550
C01363C713C3997300EF3964 /* StringOperators.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringOperators.cpp; sourceTree = "<group>"; };
543551
C02B77F1126612140026BF0F /* SpacebarScrolling.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpacebarScrolling.cpp; sourceTree = "<group>"; };
544-
C02B7853126613AE0026BF0F /* Carbon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Carbon.framework; sourceTree = SDKROOT; };
552+
C02B7853126613AE0026BF0F /* Carbon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Carbon.framework; sourceTree = SDKROOT; };
545553
C02B7882126615410026BF0F /* spacebar-scrolling.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "spacebar-scrolling.html"; sourceTree = "<group>"; };
546554
C045F9441385C2E900C0F3CD /* DownloadDecideDestinationCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DownloadDecideDestinationCrash.cpp; sourceTree = "<group>"; };
547555
C045F9461385C2F800C0F3CD /* 18-characters.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "18-characters.html"; sourceTree = "<group>"; };
@@ -826,6 +834,7 @@
826834
2D640B5417875DFF00BFAF99 /* ScrollPinningBehaviors.cpp */,
827835
51FCF7981534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp */,
828836
51FCF7971534AC6D00104491 /* ShouldGoToBackForwardListItem_Bundle.cpp */,
837+
51E5C7041919EA5F00D8B3E1 /* ShouldKeepCurrentBackForwardListItemInList.cpp */,
829838
C02B77F1126612140026BF0F /* SpacebarScrolling.cpp */,
830839
1AE72F47173EB214006362F0 /* TerminateTwice.cpp */,
831840
BC22D31314DC689800FFB1DD /* UserMessage.cpp */,
@@ -911,6 +920,8 @@
911920
33DC890E1419539300747EF7 /* simple-iframe.html */,
912921
BCAA485514A021640088FAC4 /* simple-tall.html */,
913922
BC909778125571AB00083756 /* simple.html */,
923+
51E780361919AFF8001829A2 /* simple2.html */,
924+
51E780371919AFF8001829A2 /* simple3.html */,
914925
C02B7882126615410026BF0F /* spacebar-scrolling.html */,
915926
);
916927
name = Resources;
@@ -1249,6 +1260,7 @@
12491260
52E5CE4614D21E9D003B2BD8 /* ParentFrame.cpp in Sources */,
12501261
C54237F016B8955800E638FC /* PasteboardNotifications.mm in Sources */,
12511262
BC575BC0126F5752006F0F12 /* PlatformUtilities.cpp in Sources */,
1263+
51E5C7051919EA5F00D8B3E1 /* ShouldKeepCurrentBackForwardListItemInList.cpp in Sources */,
12521264
BC131885117114B600B69727 /* PlatformUtilitiesMac.mm in Sources */,
12531265
BC90955D125548AA00083756 /* PlatformWebViewMac.mm in Sources */,
12541266
333B9CE21277F23100FEFCE3 /* PreventEmptyUserAgent.cpp in Sources */,

0 commit comments

Comments
 (0)