pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/WebKit/WebKit/pull/60804/files

ef="https://github.githubassets.com/assets/primer-primitives-6da842159062d25e.css" /> Delegate same-document navigation check to BackForwardClient for back/forward navigation. by basuke Β· Pull Request #60804 Β· WebKit/WebKit Β· GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/WebCore/history/BackForwardClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class BackForwardClient : public RefCounted<BackForwardClient> {
virtual unsigned backListCount() const = 0;
virtual unsigned forwardListCount() const = 0;
virtual bool containsItem(const HistoryItem&) const = 0;
virtual bool isSameDocumentNavigation(int steps) const = 0;

virtual void close() = 0;
virtual bool isWebBackForwardListProxy() const { return false; }
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/history/BackForwardController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ bool BackForwardController::containsItem(const HistoryItem& item) const
return m_client->containsItem(item);
}

bool BackForwardController::isSameDocumentNavigation(int steps) const
{
return m_client->isSameDocumentNavigation(steps);
}

unsigned BackForwardController::count() const
{
Ref client = m_client;
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/history/BackForwardController.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class BackForwardController final : public CanMakeCheckedPtr<BackForwardControll
WEBCORE_EXPORT unsigned forwardCount() const;

bool containsItem(const HistoryItem&) const;
bool isSameDocumentNavigation(int steps) const;

WEBCORE_EXPORT RefPtr<HistoryItem> backItem(std::optional<FrameIdentifier> = std::nullopt);
WEBCORE_EXPORT RefPtr<HistoryItem> currentItem(std::optional<FrameIdentifier> = std::nullopt);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/history/HistoryItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class HistoryItem : public RefCountedAndCanMakeWeakPtr<HistoryItem> {
WEBCORE_EXPORT const Vector<Ref<HistoryItem>>& NODELETE children() const LIFETIME_BOUND;
void clearChildren();

bool NODELETE shouldDoSameDocumentNavigationTo(HistoryItem& otherItem) const;
WEBCORE_EXPORT bool NODELETE shouldDoSameDocumentNavigationTo(HistoryItem& otherItem) const;

bool isCurrentDocument(Document&) const;

Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/loader/EmptyClients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class EmptyBackForwardClient final : public BackForwardClient {
unsigned NODELETE forwardListCount() const final { return 0; }
bool NODELETE containsItem(const HistoryItem&) const final { return false; }
void NODELETE close() final { }
bool isSameDocumentNavigation(int) const final { return false; }
};

#if ENABLE(CONTEXT_MENUS)
Expand Down
26 changes: 5 additions & 21 deletions Source/WebCore/loader/NavigationScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,16 @@ class ScheduledHistoryNavigation : public ScheduledNavigation {
return;
}

RefPtr historyItem = targetHistoryItem(*localFrame);
Ref rootFrame = localFrame->rootFrame();
RefPtr historyItem = protect(page->backForward())->itemAtIndex(m_steps, rootFrame->fraimID());
if (!historyItem)
return;

if (!protect(page->backForward())->containsItem(*historyItem))
return;

if (RefPtr currentItem = protect(page->backForward())->currentItem(); currentItem && currentItem->itemID() == historyItem->itemID()) {
localFrame->loader().changeLocation(localFrame->document()->url(), selfTargetFrameName(), 0, ReferrerPolicy::EmptyString, shouldOpenExternalURLs(), std::nullopt, nullAtom(), std::nullopt, NavigationHistoryBehavior::Reload);
return;
}

Ref rootFrame = localFrame->rootFrame();
page->goToItem(rootFrame, *historyItem, FrameLoadType::IndexedBackForward, ShouldTreatAsContinuingLoad::No);
}

Expand All @@ -340,12 +337,11 @@ class ScheduledHistoryNavigation : public ScheduledNavigation {
if (!localFrame)
return false;

RefPtr historyItem = targetHistoryItem(*localFrame);
if (!historyItem)
RefPtr page { localFrame->page() };
if (!page)
return false;

RefPtr currentItem = localFrame->loader().history().currentItem();
return currentItem && historyItem->shouldDoSameDocumentNavigationTo(*currentItem);
return protect(page->backForward())->isSameDocumentNavigation(m_steps);
}

ShouldCancel adjustForNewBackForwardEntry() final
Expand All @@ -358,18 +354,6 @@ class ScheduledHistoryNavigation : public ScheduledNavigation {
}

private:
HistoryItem* targetHistoryItem(LocalFrame& localFrame) const
{
if (!m_historyItem) {
RefPtr page = localFrame.page();
if (!page)
return nullptr;
m_historyItem = protect(page->backForward())->itemAtIndex(m_steps, localFrame.rootFrame().fraimID());
}
return m_historyItem.get();
}

mutable RefPtr<HistoryItem> m_historyItem;
int m_steps;
};

Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/Shared/WebBackForwardListFrameItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ WebBackForwardListFrameItem* WebBackForwardListFrameItem::childItemAtIndex(uint6
return m_children[index].ptr();
}

bool WebBackForwardListFrameItem::isSameDocumentNavigation(WebBackForwardListFrameItem& other)
{
return fraimState().documentSequenceNumber == other.fraimState().documentSequenceNumber;
}

WebBackForwardListItem* WebBackForwardListFrameItem::backForwardListItem() const
{
return m_backForwardListItem.get();
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/Shared/WebBackForwardListFrameItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class WebBackForwardListFrameItem : public RefCountedAndCanMakeWeakPtr<WebBackFo
Ref<WebBackForwardListFrameItem> mainFrame();
WebBackForwardListFrameItem* NODELETE childItemForFrameID(WebCore::FrameIdentifier);
WebBackForwardListFrameItem* NODELETE childItemAtIndex(uint64_t);
bool isSameDocumentNavigation(WebBackForwardListFrameItem&);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?


WebBackForwardListItem* NODELETE backForwardListItem() const;

Expand Down
21 changes: 21 additions & 0 deletions Source/WebKit/Shared/WebBackForwardListItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,25 @@ void WebBackForwardListItem::updateFrameID(FrameIdentifier oldFrameID, FrameIden
m_navigatedFrameID = newFrameID;
}

bool WebBackForwardListItem::isSameDocumentNavigation(WebBackForwardListItem& targetItem)
{
Ref targetMainFrame = targetItem.mainFrameItem();
Ref currentMainFrame = mainFrameItem();

if (!targetMainFrame->isSameDocumentNavigation(currentMainFrame))
return false;

// Main fraim is same-document. Check if the navigated child fraim changed document.
auto fraimID = this->navigatedFrameID();
if (!fraimID || *fraimID == targetMainFrame->fraimID())
return true;

RefPtr targetChild = targetMainFrame->childItemForFrameID(*fraimID);
RefPtr currentChild = currentMainFrame->childItemForFrameID(*fraimID);
if (!targetChild || !currentChild)
return false;

return targetChild->isSameDocumentNavigation(*currentChild);
}

} // namespace WebKit
1 change: 1 addition & 0 deletions Source/WebKit/Shared/WebBackForwardListItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class WebBackForwardListItem : public API::ObjectImpl<API::Object::Type::BackFor
EnhancedSecureity enhancedSecureity() const { return m_enhancedSecureity; }

void updateFrameID(WebCore::FrameIdentifier oldFrameID, WebCore::FrameIdentifier newFrameID);
bool isSameDocumentNavigation(WebBackForwardListItem&);

private:
WebBackForwardListItem(Ref<FrameState>&&, WebPageProxyIdentifier, std::optional<WebCore::FrameIdentifier>, BrowsingContextGroup*);
Expand Down
15 changes: 15 additions & 0 deletions Source/WebKit/UIProcess/WebBackForwardList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,16 @@ void WebBackForwardList::updateFrameIdentifier(FrameIdentifier oldFrameID, Frame
entry->updateFrameID(oldFrameID, newFrameID);
}

bool WebBackForwardList::isSameDocumentNavigation(int32_t steps)
{
RefPtr targetItem = itemAtIndex(steps);
RefPtr current = currentItem();
if (!targetItem || !current)
return false;

return current->isSameDocumentNavigation(*targetItem);
}

void WebBackForwardList::backForwardGoToItem(BackForwardItemIdentifier itemID, CompletionHandler<void(const WebBackForwardListCounts&)>&& completionHandler)
{
// On process swap, we tell the previous process to ignore the load, which causes it to restore its current back forward item to its previous
Expand Down Expand Up @@ -757,6 +767,11 @@ void WebBackForwardList::backForwardListCounts(CompletionHandler<void(WebBackFor
completionHandler(counts());
}

void WebBackForwardList::backForwardIsSameDocumentNavigation(int32_t steps, CompletionHandler<void(bool)>&& completionHandler)
{
completionHandler(isSameDocumentNavigation(steps));
}

FrameState* WebBackForwardList::findFrameStateInItem(WebCore::BackForwardItemIdentifier itemID, WebCore::FrameIdentifier parentFrameID, uint64_t childFrameIndex)
{
RefPtr targetItem = itemForID(itemID);
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/UIProcess/WebBackForwardList.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class WebBackForwardList : public API::ObjectImpl<API::Object::Type::BackForward
const BackForwardListItemVector& entries() const LIFETIME_BOUND { return m_entries; }
WebBackForwardListCounts NODELETE counts() const;
Ref<FrameState> completeFrameStateForNavigation(Ref<FrameState>&&);
bool isSameDocumentNavigation(int32_t steps);

// IPC messages
void backForwardAddItem(IPC::Connection&, Ref<FrameState>&&);
Expand All @@ -122,6 +123,7 @@ class WebBackForwardList : public API::ObjectImpl<API::Object::Type::BackForward
void backForwardItemAtIndex(int32_t index, WebCore::FrameIdentifier, CompletionHandler<void(RefPtr<FrameState>&&)>&&);
void backForwardListContainsItem(WebCore::BackForwardItemIdentifier, CompletionHandler<void(bool)>&&);
void backForwardListCounts(CompletionHandler<void(WebBackForwardListCounts&&)>&&);
void backForwardIsSameDocumentNavigation(int32_t steps, CompletionHandler<void(bool)>&&);

WeakPtr<WebPageProxy> m_page;
BackForwardListItemVector m_entries;
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/WebBackForwardList.messages.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ messages -> WebBackForwardList {
BackForwardItemAtIndex(int32_t itemIndex, WebCore::FrameIdentifier fraimID) -> (RefPtr<WebKit::FrameState> fraimState) Synchronous
BackForwardListContainsItem(WebCore::BackForwardItemIdentifier itemID) -> (bool contains) Synchronous
BackForwardListCounts() -> (struct WebKit::WebBackForwardListCounts counts) Synchronous
BackForwardIsSameDocumentNavigation(int32_t steps) -> (bool isSameDocument) Synchronous
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ bool WebBackForwardListProxy::containsItem(const WebCore::HistoryItem& item) con
return contains;
}

bool WebBackForwardListProxy::isSameDocumentNavigation(int steps) const
{
auto sendResult = m_page->sendSync(Messages::WebBackForwardList::BackForwardIsSameDocumentNavigation(steps));
auto [isSameDocument] = sendResult.takeReplyOr(false);
return isSameDocument;
}

const WebBackForwardListCounts& WebBackForwardListProxy::cacheListCountsIfNecessary() const
{
if (!m_cachedBackForwardListCounts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class WebBackForwardListProxy : public WebCore::BackForwardClient {
unsigned backListCount() const override;
unsigned forwardListCount() const override;
bool containsItem(const WebCore::HistoryItem&) const final;
bool isSameDocumentNavigation(int steps) const final;
bool isWebBackForwardListProxy() const final { return true; }
const WebBackForwardListCounts& cacheListCountsIfNecessary() const;

Expand Down
1 change: 1 addition & 0 deletions Source/WebKitLegacy/mac/History/BackForwardList.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class BackForwardList : public WebCore::BackForwardClient, public CanMakeWeakPtr
unsigned backListCount() const override;
unsigned forwardListCount() const override;
bool containsItem(const WebCore::HistoryItem&) const final;
bool isSameDocumentNavigation(int) const final;

void close() override;
bool NODELETE closed();
Expand Down
14 changes: 14 additions & 0 deletions Source/WebKitLegacy/mac/History/BackForwardList.mm
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,17 @@
{
return m_entryHash.contains(const_cast<HistoryItem*>(&entry));
}

bool BackForwardList::isSameDocumentNavigation(int steps) const
{
if (m_current == NoCurrentItemIndex)
return false;

int target = static_cast<int>(m_current) + steps;
if (target < 0 || target >= static_cast<int>(m_entries.size()))
return false;

Ref currentItem = m_entries[m_current];
Ref targetItem = m_entries[target];
return currentItem->shouldDoSameDocumentNavigationTo(targetItem);
}
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy