haikuwebkit/Source/WTF/wtf/DebugUtilities.h

71 lines
2.3 KiB
C
Raw Permalink Normal View History

/*
Introduce SuspendedPageProxy to keep old web processes around after their WebPageProxy has been swapped to a new one. https://bugs.webkit.org/show_bug.cgi?id=184559 Reviewed by Alex Christensen. Source/WebCore: Covered by new API test. WebCore changes rework the meaning of a "ForSuspension" policy to simply navigate the page to about:blank. * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::redirectReceived): (WebCore::DocumentLoader::willSendRequest): (WebCore::DocumentLoader::startLoadingMainResource): * loader/DocumentLoader.h: * loader/FrameLoader.cpp: (WebCore::FrameLoader::init): (WebCore::FrameLoader::continueLoadAfterNavigationPolicy): Source/WebKit: Before this patch, when a WebPageProxy navigates and is swapped to a new process, the old process almost always goes away. This is not desirable for a few reasons: 1 - We can't keep the PageCache working for back/forward scenarios 2 - We throw away a "foo.com" web process, meaning the next time we need to host a "foo.com" web page we have to launch and initialize a new web process. This patch adds a SuspendedPageProxy object to keep around the old web process and to manage communication with it. For now, a WebPageProxy keeps exactly one "suspended page" representing the most recently visited page and its process. Additionally, that process is never reused. So no benefit is achieved with this patch, but it enables future benefits. * Platform/Logging.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::setSuspendedPage): * Shared/WebBackForwardListItem.h: New object to represent the state of a WebPageProxy in an old web process that is not currently hosting the view. * UIProcess/SuspendedPageProxy.cpp: Added. (WebKit::SuspendedPageProxy::SuspendedPageProxy): (WebKit::SuspendedPageProxy::~SuspendedPageProxy): (WebKit::SuspendedPageProxy::webProcessDidClose): (WebKit::SuspendedPageProxy::didFinishLoad): (WebKit::SuspendedPageProxy::didReceiveMessage): (WebKit::SuspendedPageProxy::loggingString const): * UIProcess/SuspendedPageProxy.h: Copied from Source/WebKit/Platform/Logging.h. (WebKit::SuspendedPageProxy::create): (WebKit::SuspendedPageProxy::page const): (WebKit::SuspendedPageProxy::process const): (WebKit::SuspendedPageProxy::item const): (WebKit::SuspendedPageProxy::finishedSuspending const): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::reattachToWebProcess): (WebKit::WebPageProxy::attachToProcessForNavigation): (WebKit::WebPageProxy::maybeCreateSuspendedPage): (WebKit::WebPageProxy::suspendedPageProcessClosed): (WebKit::WebPageProxy::receivedPolicyDecision): (WebKit::WebPageProxy::didFinishLoadForFrame): * UIProcess/WebPageProxy.h: * UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::suspendWebPageProxy): (WebKit::WebProcessProxy::suspendedPageWasDestroyed): (WebKit::WebProcessProxy::removeWebPage): (WebKit::WebProcessProxy::didReceiveMessage): Optionally pass WebPageProxy messages along to SuspendedPageProxy objects. (WebKit::WebProcessProxy::didClose): (WebKit::WebProcessProxy::maybeShutDown): (WebKit::WebProcessProxy::canTerminateChildProcess): Don't terminate child processes if they still have suspended pages. * UIProcess/WebProcessProxy.h: * WebKit.xcodeproj/project.pbxproj: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::setIsSuspended): * WebProcess/WebPage/WebPage.h: (WebKit::WebPage::isSuspended const): For now, used only by WebProcess::updateActivePages. Will have more uses soon. * WebProcess/WebPage/WebPage.messages.in: * WebProcess/WebProcess.messages.in: * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateActivePages): Allow the UIProcess to request an update of the web processes user visible name. Source/WTF: * wtf/DebugUtilities.h: (WTF::debugString): Add a debug utility to easily construct a "const char*" that is released after a spin of the run loop. This greatly eases uses our String classes and functions inside of "%s" style environments like printf and LOG. Tools: * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm: Canonical link: https://commits.webkit.org/200140@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230640 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-04-13 18:04:22 +00:00
* Copyright (C) 2017-2018 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. ``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
* 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.
*/
Introduce SuspendedPageProxy to keep old web processes around after their WebPageProxy has been swapped to a new one. https://bugs.webkit.org/show_bug.cgi?id=184559 Reviewed by Alex Christensen. Source/WebCore: Covered by new API test. WebCore changes rework the meaning of a "ForSuspension" policy to simply navigate the page to about:blank. * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::redirectReceived): (WebCore::DocumentLoader::willSendRequest): (WebCore::DocumentLoader::startLoadingMainResource): * loader/DocumentLoader.h: * loader/FrameLoader.cpp: (WebCore::FrameLoader::init): (WebCore::FrameLoader::continueLoadAfterNavigationPolicy): Source/WebKit: Before this patch, when a WebPageProxy navigates and is swapped to a new process, the old process almost always goes away. This is not desirable for a few reasons: 1 - We can't keep the PageCache working for back/forward scenarios 2 - We throw away a "foo.com" web process, meaning the next time we need to host a "foo.com" web page we have to launch and initialize a new web process. This patch adds a SuspendedPageProxy object to keep around the old web process and to manage communication with it. For now, a WebPageProxy keeps exactly one "suspended page" representing the most recently visited page and its process. Additionally, that process is never reused. So no benefit is achieved with this patch, but it enables future benefits. * Platform/Logging.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::setSuspendedPage): * Shared/WebBackForwardListItem.h: New object to represent the state of a WebPageProxy in an old web process that is not currently hosting the view. * UIProcess/SuspendedPageProxy.cpp: Added. (WebKit::SuspendedPageProxy::SuspendedPageProxy): (WebKit::SuspendedPageProxy::~SuspendedPageProxy): (WebKit::SuspendedPageProxy::webProcessDidClose): (WebKit::SuspendedPageProxy::didFinishLoad): (WebKit::SuspendedPageProxy::didReceiveMessage): (WebKit::SuspendedPageProxy::loggingString const): * UIProcess/SuspendedPageProxy.h: Copied from Source/WebKit/Platform/Logging.h. (WebKit::SuspendedPageProxy::create): (WebKit::SuspendedPageProxy::page const): (WebKit::SuspendedPageProxy::process const): (WebKit::SuspendedPageProxy::item const): (WebKit::SuspendedPageProxy::finishedSuspending const): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::reattachToWebProcess): (WebKit::WebPageProxy::attachToProcessForNavigation): (WebKit::WebPageProxy::maybeCreateSuspendedPage): (WebKit::WebPageProxy::suspendedPageProcessClosed): (WebKit::WebPageProxy::receivedPolicyDecision): (WebKit::WebPageProxy::didFinishLoadForFrame): * UIProcess/WebPageProxy.h: * UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::suspendWebPageProxy): (WebKit::WebProcessProxy::suspendedPageWasDestroyed): (WebKit::WebProcessProxy::removeWebPage): (WebKit::WebProcessProxy::didReceiveMessage): Optionally pass WebPageProxy messages along to SuspendedPageProxy objects. (WebKit::WebProcessProxy::didClose): (WebKit::WebProcessProxy::maybeShutDown): (WebKit::WebProcessProxy::canTerminateChildProcess): Don't terminate child processes if they still have suspended pages. * UIProcess/WebProcessProxy.h: * WebKit.xcodeproj/project.pbxproj: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::setIsSuspended): * WebProcess/WebPage/WebPage.h: (WebKit::WebPage::isSuspended const): For now, used only by WebProcess::updateActivePages. Will have more uses soon. * WebProcess/WebPage/WebPage.messages.in: * WebProcess/WebProcess.messages.in: * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateActivePages): Allow the UIProcess to request an update of the web processes user visible name. Source/WTF: * wtf/DebugUtilities.h: (WTF::debugString): Add a debug utility to easily construct a "const char*" that is released after a spin of the run loop. This greatly eases uses our String classes and functions inside of "%s" style environments like printf and LOG. Tools: * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm: Canonical link: https://commits.webkit.org/200140@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230640 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-04-13 18:04:22 +00:00
#pragma once
#include <wtf/Assertions.h>
Add globally-unique HistoryItem identifiers (and have WebKit2 adopt them). <rdar://problem/39533949> and https://bugs.webkit.org/show_bug.cgi?id=184750 Reviewed by Ryosuke Niwa. Source/WebCore: No new tests (Refactor, no behavior change). In WebCore, we: - Add a process-unique "BackForwardItemIdentifier" - Make all HistoryItems have such an identifier as a member * WebCore.xcodeproj/project.pbxproj: * history/BackForwardItemIdentifier.h: Added. (WebCore::BackForwardItemIdentifier::logString const): (WebCore::operator==): (WebCore::BackForwardItemIdentifier::encode const): (WebCore::BackForwardItemIdentifier::decode): (WebCore::BackForwardItemIdentifier::hash const): (WTF::BackForwardItemIdentifierHash::hash): (WTF::BackForwardItemIdentifierHash::equal): (WTF::HashTraits<WebCore::BackForwardItemIdentifier>::emptyValue): (WTF::HashTraits<WebCore::BackForwardItemIdentifier>::constructDeletedValue): (WTF::HashTraits<WebCore::BackForwardItemIdentifier>::isDeletedValue): * history/HistoryItem.cpp: (WebCore::HistoryItem::generateSequenceNumber): (WebCore::HistoryItem::HistoryItem): (WebCore::generateSequenceNumber): Deleted. * history/HistoryItem.h: (WebCore::HistoryItem::create): (WebCore::HistoryItem::identifier const): Source/WebKit: With process swapping, the assumption that "back/forward items belong to a process" is invalid. All HistoryItem/WebBackForwardListItems now need to be uniquely identified across all processes, no matter which process they originated from, so there will never be a collision in the UIProcess. This allows us to: - Have the UIProcess to keep a single process-wide map of all WebBackForwardListItems - Get rid of the per-WebProcess WebBackForwardListItem map - Simplify a lot of WebBackForwardList(Proxy) code that no longer needs to keep that per-process map in sync - Get rid of a lot of other ancillary code * Shared/SessionState.cpp: (WebKit::BackForwardListItemState::decode): * Shared/SessionState.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::WebBackForwardListItem): (WebKit::WebBackForwardListItem::~WebBackForwardListItem): (WebKit::WebBackForwardListItem::itemForID): (WebKit::WebBackForwardListItem::highestUsedItemID): Deleted. * Shared/WebBackForwardListItem.h: (WebKit::WebBackForwardListItem::itemID const): * Shared/WebPageCreationParameters.cpp: (WebKit::WebPageCreationParameters::encode const): (WebKit::WebPageCreationParameters::decode): * Shared/WebPageCreationParameters.h: * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::itemForID): (WebKit::WebBackForwardList::pageClosed): (WebKit::WebBackForwardList::addItem): (WebKit::WebBackForwardList::restoreFromState): (WebKit::generateWebBackForwardItemID): Deleted. * UIProcess/WebBackForwardList.h: * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::maybeCreateSuspendedPage): (WebKit::WebPageProxy::initializeWebPage): (WebKit::WebPageProxy::willGoToBackForwardListItem): (WebKit::WebPageProxy::restoreFromSessionState): (WebKit::WebPageProxy::backForwardAddItem): (WebKit::WebPageProxy::backForwardGoToItem): (WebKit::WebPageProxy::backForwardItemAtIndex): (WebKit::WebPageProxy::creationParameters): (WebKit::WebPageProxy::backForwardRemovedItem): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * UIProcess/WebProcessPool.cpp: Explicitly set the UIProcess Process::Identifier so it starts at "1" and then the first child process starts at "2", etc etc. * UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::removeWebPage): (WebKit::WebProcessProxy::checkURLReceivedFromWebProcess): (WebKit::WebProcessProxy::updateBackForwardItem): (WebKit::WebProcessProxy::webBackForwardItem const): Deleted. (WebKit::WebProcessProxy::registerNewWebBackForwardListItem): Deleted. (WebKit::WebProcessProxy::removeBackForwardItem): Deleted. (WebKit::WebProcessProxy::addOrUpdateBackForwardItem): Deleted. * UIProcess/WebProcessProxy.h: * UIProcess/WebProcessProxy.messages.in: * WebProcess/WebCoreSupport/SessionStateConversion.cpp: (WebKit::toBackForwardListItemState): (WebKit::applyFrameState): (WebKit::toHistoryItem): (WebKit::toPageState): Deleted. * WebProcess/WebCoreSupport/SessionStateConversion.h: * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: (WebKit::WebFrameLoaderClient::shouldGoToHistoryItem const): * WebProcess/WebPage/WebBackForwardListProxy.cpp: (WebKit::WebBackForwardListProxy::addItemFromUIProcess): (WebKit::WK2NotifyHistoryItemChanged): (WebKit::WebBackForwardListProxy::itemForID): (WebKit::WebBackForwardListProxy::removeItem): (WebKit::WebBackForwardListProxy::addItem): Previously this was a two-step process of adding an item to the process and then associating it with the page. Now it's just directly adding it to the page, so we don't need to call updateBackForwardItem first. (WebKit::WebBackForwardListProxy::goToItem): (WebKit::WebBackForwardListProxy::itemAtIndex): (WebKit::WebBackForwardListProxy::close): (WebKit::historyItemToIDMap): Deleted. (WebKit::generateHistoryItemID): Deleted. (WebKit::WebBackForwardListProxy::setHighestItemIDFromUIProcess): Deleted. (WebKit::updateBackForwardItem): Deleted. (WebKit::WebBackForwardListProxy::idForItem): Deleted. * WebProcess/WebPage/WebBackForwardListProxy.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::m_credentialsMessenger): (WebKit::WebPage::goToBackForwardItem): (WebKit::WebPage::restoreSessionInternal): (WebKit::WebPage::didRemoveBackForwardItem): * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.messages.in: Source/WTF: * wtf/DebugUtilities.h: (WTF::debugString): Canonical link: https://commits.webkit.org/200291@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230812 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-04-19 18:45:40 +00:00
#include <wtf/MainThread.h>
#include <wtf/ProcessID.h>
Introduce SuspendedPageProxy to keep old web processes around after their WebPageProxy has been swapped to a new one. https://bugs.webkit.org/show_bug.cgi?id=184559 Reviewed by Alex Christensen. Source/WebCore: Covered by new API test. WebCore changes rework the meaning of a "ForSuspension" policy to simply navigate the page to about:blank. * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::redirectReceived): (WebCore::DocumentLoader::willSendRequest): (WebCore::DocumentLoader::startLoadingMainResource): * loader/DocumentLoader.h: * loader/FrameLoader.cpp: (WebCore::FrameLoader::init): (WebCore::FrameLoader::continueLoadAfterNavigationPolicy): Source/WebKit: Before this patch, when a WebPageProxy navigates and is swapped to a new process, the old process almost always goes away. This is not desirable for a few reasons: 1 - We can't keep the PageCache working for back/forward scenarios 2 - We throw away a "foo.com" web process, meaning the next time we need to host a "foo.com" web page we have to launch and initialize a new web process. This patch adds a SuspendedPageProxy object to keep around the old web process and to manage communication with it. For now, a WebPageProxy keeps exactly one "suspended page" representing the most recently visited page and its process. Additionally, that process is never reused. So no benefit is achieved with this patch, but it enables future benefits. * Platform/Logging.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::setSuspendedPage): * Shared/WebBackForwardListItem.h: New object to represent the state of a WebPageProxy in an old web process that is not currently hosting the view. * UIProcess/SuspendedPageProxy.cpp: Added. (WebKit::SuspendedPageProxy::SuspendedPageProxy): (WebKit::SuspendedPageProxy::~SuspendedPageProxy): (WebKit::SuspendedPageProxy::webProcessDidClose): (WebKit::SuspendedPageProxy::didFinishLoad): (WebKit::SuspendedPageProxy::didReceiveMessage): (WebKit::SuspendedPageProxy::loggingString const): * UIProcess/SuspendedPageProxy.h: Copied from Source/WebKit/Platform/Logging.h. (WebKit::SuspendedPageProxy::create): (WebKit::SuspendedPageProxy::page const): (WebKit::SuspendedPageProxy::process const): (WebKit::SuspendedPageProxy::item const): (WebKit::SuspendedPageProxy::finishedSuspending const): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::reattachToWebProcess): (WebKit::WebPageProxy::attachToProcessForNavigation): (WebKit::WebPageProxy::maybeCreateSuspendedPage): (WebKit::WebPageProxy::suspendedPageProcessClosed): (WebKit::WebPageProxy::receivedPolicyDecision): (WebKit::WebPageProxy::didFinishLoadForFrame): * UIProcess/WebPageProxy.h: * UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::suspendWebPageProxy): (WebKit::WebProcessProxy::suspendedPageWasDestroyed): (WebKit::WebProcessProxy::removeWebPage): (WebKit::WebProcessProxy::didReceiveMessage): Optionally pass WebPageProxy messages along to SuspendedPageProxy objects. (WebKit::WebProcessProxy::didClose): (WebKit::WebProcessProxy::maybeShutDown): (WebKit::WebProcessProxy::canTerminateChildProcess): Don't terminate child processes if they still have suspended pages. * UIProcess/WebProcessProxy.h: * WebKit.xcodeproj/project.pbxproj: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::setIsSuspended): * WebProcess/WebPage/WebPage.h: (WebKit::WebPage::isSuspended const): For now, used only by WebProcess::updateActivePages. Will have more uses soon. * WebProcess/WebPage/WebPage.messages.in: * WebProcess/WebProcess.messages.in: * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateActivePages): Allow the UIProcess to request an update of the web processes user visible name. Source/WTF: * wtf/DebugUtilities.h: (WTF::debugString): Add a debug utility to easily construct a "const char*" that is released after a spin of the run loop. This greatly eases uses our String classes and functions inside of "%s" style environments like printf and LOG. Tools: * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm: Canonical link: https://commits.webkit.org/200140@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230640 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-04-13 18:04:22 +00:00
#include <wtf/text/StringConcatenate.h>
#define SLEEP_THREAD_FOR_DEBUGGER() \
do { \
WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, "Sleeping thread for debugger; attach to process (PID: %d) to unsleep the thread.", getCurrentProcessID()); \
do { \
sleep(1); \
if (WTFIsDebuggerAttached()) \
break; \
} while (1); \
WTFBreakpointTrap(); \
} while (0)
Introduce SuspendedPageProxy to keep old web processes around after their WebPageProxy has been swapped to a new one. https://bugs.webkit.org/show_bug.cgi?id=184559 Reviewed by Alex Christensen. Source/WebCore: Covered by new API test. WebCore changes rework the meaning of a "ForSuspension" policy to simply navigate the page to about:blank. * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::redirectReceived): (WebCore::DocumentLoader::willSendRequest): (WebCore::DocumentLoader::startLoadingMainResource): * loader/DocumentLoader.h: * loader/FrameLoader.cpp: (WebCore::FrameLoader::init): (WebCore::FrameLoader::continueLoadAfterNavigationPolicy): Source/WebKit: Before this patch, when a WebPageProxy navigates and is swapped to a new process, the old process almost always goes away. This is not desirable for a few reasons: 1 - We can't keep the PageCache working for back/forward scenarios 2 - We throw away a "foo.com" web process, meaning the next time we need to host a "foo.com" web page we have to launch and initialize a new web process. This patch adds a SuspendedPageProxy object to keep around the old web process and to manage communication with it. For now, a WebPageProxy keeps exactly one "suspended page" representing the most recently visited page and its process. Additionally, that process is never reused. So no benefit is achieved with this patch, but it enables future benefits. * Platform/Logging.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::setSuspendedPage): * Shared/WebBackForwardListItem.h: New object to represent the state of a WebPageProxy in an old web process that is not currently hosting the view. * UIProcess/SuspendedPageProxy.cpp: Added. (WebKit::SuspendedPageProxy::SuspendedPageProxy): (WebKit::SuspendedPageProxy::~SuspendedPageProxy): (WebKit::SuspendedPageProxy::webProcessDidClose): (WebKit::SuspendedPageProxy::didFinishLoad): (WebKit::SuspendedPageProxy::didReceiveMessage): (WebKit::SuspendedPageProxy::loggingString const): * UIProcess/SuspendedPageProxy.h: Copied from Source/WebKit/Platform/Logging.h. (WebKit::SuspendedPageProxy::create): (WebKit::SuspendedPageProxy::page const): (WebKit::SuspendedPageProxy::process const): (WebKit::SuspendedPageProxy::item const): (WebKit::SuspendedPageProxy::finishedSuspending const): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::reattachToWebProcess): (WebKit::WebPageProxy::attachToProcessForNavigation): (WebKit::WebPageProxy::maybeCreateSuspendedPage): (WebKit::WebPageProxy::suspendedPageProcessClosed): (WebKit::WebPageProxy::receivedPolicyDecision): (WebKit::WebPageProxy::didFinishLoadForFrame): * UIProcess/WebPageProxy.h: * UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::suspendWebPageProxy): (WebKit::WebProcessProxy::suspendedPageWasDestroyed): (WebKit::WebProcessProxy::removeWebPage): (WebKit::WebProcessProxy::didReceiveMessage): Optionally pass WebPageProxy messages along to SuspendedPageProxy objects. (WebKit::WebProcessProxy::didClose): (WebKit::WebProcessProxy::maybeShutDown): (WebKit::WebProcessProxy::canTerminateChildProcess): Don't terminate child processes if they still have suspended pages. * UIProcess/WebProcessProxy.h: * WebKit.xcodeproj/project.pbxproj: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::setIsSuspended): * WebProcess/WebPage/WebPage.h: (WebKit::WebPage::isSuspended const): For now, used only by WebProcess::updateActivePages. Will have more uses soon. * WebProcess/WebPage/WebPage.messages.in: * WebProcess/WebProcess.messages.in: * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateActivePages): Allow the UIProcess to request an update of the web processes user visible name. Source/WTF: * wtf/DebugUtilities.h: (WTF::debugString): Add a debug utility to easily construct a "const char*" that is released after a spin of the run loop. This greatly eases uses our String classes and functions inside of "%s" style environments like printf and LOG. Tools: * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm: Canonical link: https://commits.webkit.org/200140@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230640 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-04-13 18:04:22 +00:00
namespace WTF {
Add globally-unique HistoryItem identifiers (and have WebKit2 adopt them). <rdar://problem/39533949> and https://bugs.webkit.org/show_bug.cgi?id=184750 Reviewed by Ryosuke Niwa. Source/WebCore: No new tests (Refactor, no behavior change). In WebCore, we: - Add a process-unique "BackForwardItemIdentifier" - Make all HistoryItems have such an identifier as a member * WebCore.xcodeproj/project.pbxproj: * history/BackForwardItemIdentifier.h: Added. (WebCore::BackForwardItemIdentifier::logString const): (WebCore::operator==): (WebCore::BackForwardItemIdentifier::encode const): (WebCore::BackForwardItemIdentifier::decode): (WebCore::BackForwardItemIdentifier::hash const): (WTF::BackForwardItemIdentifierHash::hash): (WTF::BackForwardItemIdentifierHash::equal): (WTF::HashTraits<WebCore::BackForwardItemIdentifier>::emptyValue): (WTF::HashTraits<WebCore::BackForwardItemIdentifier>::constructDeletedValue): (WTF::HashTraits<WebCore::BackForwardItemIdentifier>::isDeletedValue): * history/HistoryItem.cpp: (WebCore::HistoryItem::generateSequenceNumber): (WebCore::HistoryItem::HistoryItem): (WebCore::generateSequenceNumber): Deleted. * history/HistoryItem.h: (WebCore::HistoryItem::create): (WebCore::HistoryItem::identifier const): Source/WebKit: With process swapping, the assumption that "back/forward items belong to a process" is invalid. All HistoryItem/WebBackForwardListItems now need to be uniquely identified across all processes, no matter which process they originated from, so there will never be a collision in the UIProcess. This allows us to: - Have the UIProcess to keep a single process-wide map of all WebBackForwardListItems - Get rid of the per-WebProcess WebBackForwardListItem map - Simplify a lot of WebBackForwardList(Proxy) code that no longer needs to keep that per-process map in sync - Get rid of a lot of other ancillary code * Shared/SessionState.cpp: (WebKit::BackForwardListItemState::decode): * Shared/SessionState.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::WebBackForwardListItem): (WebKit::WebBackForwardListItem::~WebBackForwardListItem): (WebKit::WebBackForwardListItem::itemForID): (WebKit::WebBackForwardListItem::highestUsedItemID): Deleted. * Shared/WebBackForwardListItem.h: (WebKit::WebBackForwardListItem::itemID const): * Shared/WebPageCreationParameters.cpp: (WebKit::WebPageCreationParameters::encode const): (WebKit::WebPageCreationParameters::decode): * Shared/WebPageCreationParameters.h: * UIProcess/WebBackForwardList.cpp: (WebKit::WebBackForwardList::itemForID): (WebKit::WebBackForwardList::pageClosed): (WebKit::WebBackForwardList::addItem): (WebKit::WebBackForwardList::restoreFromState): (WebKit::generateWebBackForwardItemID): Deleted. * UIProcess/WebBackForwardList.h: * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::maybeCreateSuspendedPage): (WebKit::WebPageProxy::initializeWebPage): (WebKit::WebPageProxy::willGoToBackForwardListItem): (WebKit::WebPageProxy::restoreFromSessionState): (WebKit::WebPageProxy::backForwardAddItem): (WebKit::WebPageProxy::backForwardGoToItem): (WebKit::WebPageProxy::backForwardItemAtIndex): (WebKit::WebPageProxy::creationParameters): (WebKit::WebPageProxy::backForwardRemovedItem): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * UIProcess/WebProcessPool.cpp: Explicitly set the UIProcess Process::Identifier so it starts at "1" and then the first child process starts at "2", etc etc. * UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::removeWebPage): (WebKit::WebProcessProxy::checkURLReceivedFromWebProcess): (WebKit::WebProcessProxy::updateBackForwardItem): (WebKit::WebProcessProxy::webBackForwardItem const): Deleted. (WebKit::WebProcessProxy::registerNewWebBackForwardListItem): Deleted. (WebKit::WebProcessProxy::removeBackForwardItem): Deleted. (WebKit::WebProcessProxy::addOrUpdateBackForwardItem): Deleted. * UIProcess/WebProcessProxy.h: * UIProcess/WebProcessProxy.messages.in: * WebProcess/WebCoreSupport/SessionStateConversion.cpp: (WebKit::toBackForwardListItemState): (WebKit::applyFrameState): (WebKit::toHistoryItem): (WebKit::toPageState): Deleted. * WebProcess/WebCoreSupport/SessionStateConversion.h: * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: (WebKit::WebFrameLoaderClient::shouldGoToHistoryItem const): * WebProcess/WebPage/WebBackForwardListProxy.cpp: (WebKit::WebBackForwardListProxy::addItemFromUIProcess): (WebKit::WK2NotifyHistoryItemChanged): (WebKit::WebBackForwardListProxy::itemForID): (WebKit::WebBackForwardListProxy::removeItem): (WebKit::WebBackForwardListProxy::addItem): Previously this was a two-step process of adding an item to the process and then associating it with the page. Now it's just directly adding it to the page, so we don't need to call updateBackForwardItem first. (WebKit::WebBackForwardListProxy::goToItem): (WebKit::WebBackForwardListProxy::itemAtIndex): (WebKit::WebBackForwardListProxy::close): (WebKit::historyItemToIDMap): Deleted. (WebKit::generateHistoryItemID): Deleted. (WebKit::WebBackForwardListProxy::setHighestItemIDFromUIProcess): Deleted. (WebKit::updateBackForwardItem): Deleted. (WebKit::WebBackForwardListProxy::idForItem): Deleted. * WebProcess/WebPage/WebBackForwardListProxy.h: * WebProcess/WebPage/WebPage.cpp: (WebKit::m_credentialsMessenger): (WebKit::WebPage::goToBackForwardItem): (WebKit::WebPage::restoreSessionInternal): (WebKit::WebPage::didRemoveBackForwardItem): * WebProcess/WebPage/WebPage.h: * WebProcess/WebPage/WebPage.messages.in: Source/WTF: * wtf/DebugUtilities.h: (WTF::debugString): Canonical link: https://commits.webkit.org/200291@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230812 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-04-19 18:45:40 +00:00
template<typename StringType>
const char* debugString(StringType string)
{
return debugString(string, "");
}
Introduce SuspendedPageProxy to keep old web processes around after their WebPageProxy has been swapped to a new one. https://bugs.webkit.org/show_bug.cgi?id=184559 Reviewed by Alex Christensen. Source/WebCore: Covered by new API test. WebCore changes rework the meaning of a "ForSuspension" policy to simply navigate the page to about:blank. * loader/DocumentLoader.cpp: (WebCore::DocumentLoader::redirectReceived): (WebCore::DocumentLoader::willSendRequest): (WebCore::DocumentLoader::startLoadingMainResource): * loader/DocumentLoader.h: * loader/FrameLoader.cpp: (WebCore::FrameLoader::init): (WebCore::FrameLoader::continueLoadAfterNavigationPolicy): Source/WebKit: Before this patch, when a WebPageProxy navigates and is swapped to a new process, the old process almost always goes away. This is not desirable for a few reasons: 1 - We can't keep the PageCache working for back/forward scenarios 2 - We throw away a "foo.com" web process, meaning the next time we need to host a "foo.com" web page we have to launch and initialize a new web process. This patch adds a SuspendedPageProxy object to keep around the old web process and to manage communication with it. For now, a WebPageProxy keeps exactly one "suspended page" representing the most recently visited page and its process. Additionally, that process is never reused. So no benefit is achieved with this patch, but it enables future benefits. * Platform/Logging.h: * Shared/WebBackForwardListItem.cpp: (WebKit::WebBackForwardListItem::setSuspendedPage): * Shared/WebBackForwardListItem.h: New object to represent the state of a WebPageProxy in an old web process that is not currently hosting the view. * UIProcess/SuspendedPageProxy.cpp: Added. (WebKit::SuspendedPageProxy::SuspendedPageProxy): (WebKit::SuspendedPageProxy::~SuspendedPageProxy): (WebKit::SuspendedPageProxy::webProcessDidClose): (WebKit::SuspendedPageProxy::didFinishLoad): (WebKit::SuspendedPageProxy::didReceiveMessage): (WebKit::SuspendedPageProxy::loggingString const): * UIProcess/SuspendedPageProxy.h: Copied from Source/WebKit/Platform/Logging.h. (WebKit::SuspendedPageProxy::create): (WebKit::SuspendedPageProxy::page const): (WebKit::SuspendedPageProxy::process const): (WebKit::SuspendedPageProxy::item const): (WebKit::SuspendedPageProxy::finishedSuspending const): * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::reattachToWebProcess): (WebKit::WebPageProxy::attachToProcessForNavigation): (WebKit::WebPageProxy::maybeCreateSuspendedPage): (WebKit::WebPageProxy::suspendedPageProcessClosed): (WebKit::WebPageProxy::receivedPolicyDecision): (WebKit::WebPageProxy::didFinishLoadForFrame): * UIProcess/WebPageProxy.h: * UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::suspendWebPageProxy): (WebKit::WebProcessProxy::suspendedPageWasDestroyed): (WebKit::WebProcessProxy::removeWebPage): (WebKit::WebProcessProxy::didReceiveMessage): Optionally pass WebPageProxy messages along to SuspendedPageProxy objects. (WebKit::WebProcessProxy::didClose): (WebKit::WebProcessProxy::maybeShutDown): (WebKit::WebProcessProxy::canTerminateChildProcess): Don't terminate child processes if they still have suspended pages. * UIProcess/WebProcessProxy.h: * WebKit.xcodeproj/project.pbxproj: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::setIsSuspended): * WebProcess/WebPage/WebPage.h: (WebKit::WebPage::isSuspended const): For now, used only by WebProcess::updateActivePages. Will have more uses soon. * WebProcess/WebPage/WebPage.messages.in: * WebProcess/WebProcess.messages.in: * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::updateActivePages): Allow the UIProcess to request an update of the web processes user visible name. Source/WTF: * wtf/DebugUtilities.h: (WTF::debugString): Add a debug utility to easily construct a "const char*" that is released after a spin of the run loop. This greatly eases uses our String classes and functions inside of "%s" style environments like printf and LOG. Tools: * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm: Canonical link: https://commits.webkit.org/200140@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230640 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-04-13 18:04:22 +00:00
template<typename... StringTypes>
const char* debugString(StringTypes... strings)
{
String result = tryMakeString(strings...);
if (!result)
CRASH();
auto cString = result.utf8();
const char* cStringData = cString.data();
callOnMainThread([cString = WTFMove(cString)] {
});
return cStringData;
}
} // namespace WTF
using WTF::debugString;