haikuwebkit/Source/WebCore/platform/SleepDisabler.cpp

52 lines
2.0 KiB
C++
Raw Permalink Normal View History

[Cocoa] Sleep disabling should be performed in the UI process https://bugs.webkit.org/show_bug.cgi?id=209676 Reviewed by Darin Adler. Source/WebCore: Since sleep disabling is causing communication with the power management service, it should be performed in the UI process. This patch fixes this by creating a sleep disabler client, which will notify the UI process when a sleep disabler is being created and destroyed. In response to these messages, the UI process will perform the actual sleep disabling and enabling. A new sleep disabler class is created which wraps the PAL sleep disabler, and notifies the sleep disabler client when set. If the sleep disabler client is set, a PAL sleep disabler instance will not be created in the WebContent process, since this will then happen in the UI process. API test: WebKit.SleepDisabler * Headers.cmake: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::updateSleepDisabling): * html/HTMLMediaElement.h: * platform/SleepDisabler.cpp: Added. (WebCore::SleepDisabler::SleepDisabler): (WebCore::SleepDisabler::~SleepDisabler): * platform/SleepDisabler.h: Added. (WebCore::SleepDisabler::type const): * platform/SleepDisablerClient.cpp: Added. (WebCore::sleepDisablerClient): * platform/SleepDisablerClient.h: Added. (WebCore::SleepDisablerClient::~SleepDisablerClient): * platform/SleepDisablerIdentifier.h: Added. * testing/Internals.cpp: (WebCore::Internals::createSleepDisabler): (WebCore::Internals::destroySleepDisabler): * testing/Internals.h: * testing/Internals.idl: Source/WebKit: Since sleep disabling is causing communication with the power management service, it should be performed in the UI process. The UI process will be notified by the WebContent process about sleep disablers being created and destroyed, and will perform the actual sleep disabling and enabling. * Scripts/webkit/messages.py: * Sources.txt: * UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h: * UIProcess/API/Cocoa/WKWebViewTesting.mm: (-[WKWebView _hasSleepDisabler]): * UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::didCreateSleepDisabler): (WebKit::WebProcessProxy::didDestroySleepDisabler): (WebKit::WebProcessProxy::hasSleepDisabler): * UIProcess/WebProcessProxy.h: * UIProcess/WebProcessProxy.messages.in: * WebKit.xcodeproj/project.pbxproj: * WebProcess/GPU/media/RemoteLegacyCDM.cpp: * WebProcess/GPU/media/ios/RemoteMediaSessionHelper.cpp: * WebProcess/GPU/media/ios/RemoteMediaSessionHelper.h: * WebProcess/WebPage/ViewGestureGeometryCollector.cpp: * WebProcess/WebSleepDisablerClient.cpp: Added. (WebKit::WebSleepDisablerClient::didCreateSleepDisabler): (WebKit::WebSleepDisablerClient::didDestroySleepDisabler): * WebProcess/WebSleepDisablerClient.h: Added. * WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::WebProcess::platformInitializeWebProcess): Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebKit/SleepDisabler.mm: Added. (TEST): Canonical link: https://commits.webkit.org/222665@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259200 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-30 14:48:38 +00:00
/*
* Copyright (C) 2020 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 "SleepDisabler.h"
#include "SleepDisablerClient.h"
namespace WebCore {
SleepDisabler::SleepDisabler(const char* reason, PAL::SleepDisabler::Type type)
: m_type(type)
{
if (sleepDisablerClient()) {
m_identifier = SleepDisablerIdentifier::generate();
sleepDisablerClient()->didCreateSleepDisabler(m_identifier, reason, type == PAL::SleepDisabler::Type::Display);
return;
}
m_platformSleepDisabler = PAL::SleepDisabler::create(reason, type);
}
SleepDisabler::~SleepDisabler()
{
if (sleepDisablerClient())
sleepDisablerClient()->didDestroySleepDisabler(m_identifier);
}
} // namespace WebCore