Title: [259200] trunk
Revision
259200
Author
[email protected]
Date
2020-03-30 07:48:38 -0700 (Mon, 30 Mar 2020)

Log Message

[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):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (259199 => 259200)


--- trunk/Source/WebCore/ChangeLog	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebCore/ChangeLog	2020-03-30 14:48:38 UTC (rev 259200)
@@ -1,3 +1,41 @@
+2020-03-30  Per Arne Vollan  <[email protected]>
+
+        [Cocoa] Sleep disabling should be performed in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=209676
+
+        Reviewed by Darin Adler.
+
+        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:
+
 2020-03-30  Antoine Quint  <[email protected]>
 
         Mark Pointer Events and Web Animations features as completed in https://webkit.org/status/

Modified: trunk/Source/WebCore/Headers.cmake (259199 => 259200)


--- trunk/Source/WebCore/Headers.cmake	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebCore/Headers.cmake	2020-03-30 14:48:38 UTC (rev 259200)
@@ -1009,6 +1009,9 @@
     platform/SerializedPlatformDataCueValue.h
     platform/SharedBuffer.h
     platform/SharedStringHash.h
+    platform/SleepDisabler.h
+    platform/SleepDisablerClient.h
+    platform/SleepDisablerIdentifier.h
     platform/SuddenTermination.h
     platform/Supplementable.h
     platform/ThemeTypes.h

Modified: trunk/Source/WebCore/Sources.txt (259199 => 259200)


--- trunk/Source/WebCore/Sources.txt	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebCore/Sources.txt	2020-03-30 14:48:38 UTC (rev 259200)
@@ -1799,6 +1799,8 @@
 platform/SharedBuffer.cpp
 platform/SharedBufferChunkReader.cpp
 platform/SharedStringHash.cpp
+platform/SleepDisabler.cpp
+platform/SleepDisablerClient.cpp
 platform/StaticPasteboard.cpp
 platform/Theme.cpp
 platform/ThreadGlobalData.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (259199 => 259200)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-03-30 14:48:38 UTC (rev 259200)
@@ -3988,6 +3988,9 @@
 		C105DA640F3AA6B8001DD44F /* TextEncodingDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */; };
 		C11A9ECE21403A5C00CFB20A /* SwitchingGPUClient.h in Headers */ = {isa = PBXBuildFile; fileRef = C11A9ECD21403A5C00CFB20A /* SwitchingGPUClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C14938072234551A000CD707 /* SpeechSynthesisClient.h in Headers */ = {isa = PBXBuildFile; fileRef = C149380522342719000CD707 /* SpeechSynthesisClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		C149D55D242EA6B9003EBB12 /* SleepDisabler.h in Headers */ = {isa = PBXBuildFile; fileRef = C149D55A242EA4F9003EBB12 /* SleepDisabler.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		C149D55F242EA7B8003EBB12 /* SleepDisablerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = C149D55B242EA4FA003EBB12 /* SleepDisablerClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		C149D567242EB84A003EBB12 /* SleepDisablerIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = C149D565242EB765003EBB12 /* SleepDisablerIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C1692DD223D23ABD006E88F7 /* SystemBattery.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1692DD123D23ABD006E88F7 /* SystemBattery.mm */; };
 		C1692DD523D23E08006E88F7 /* SystemBattery.h in Headers */ = {isa = PBXBuildFile; fileRef = C1692DD423D23AE0006E88F7 /* SystemBattery.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C1E1D236203DF15400584665 /* ScreenProperties.h in Headers */ = {isa = PBXBuildFile; fileRef = C1E1D235203DF15400584665 /* ScreenProperties.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -13587,8 +13590,13 @@
 		C11A9ED22140578B00CFB20A /* SwitchingGPUClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SwitchingGPUClient.cpp; sourceTree = "<group>"; };
 		C137846B242BEEBA00E86FA8 /* PlatformScreen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformScreen.cpp; sourceTree = "<group>"; };
 		C149380522342719000CD707 /* SpeechSynthesisClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpeechSynthesisClient.h; sourceTree = "<group>"; };
+		C149D559242EA4F8003EBB12 /* SleepDisabler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SleepDisabler.cpp; sourceTree = "<group>"; };
+		C149D55A242EA4F9003EBB12 /* SleepDisabler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SleepDisabler.h; sourceTree = "<group>"; };
+		C149D55B242EA4FA003EBB12 /* SleepDisablerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SleepDisablerClient.h; sourceTree = "<group>"; };
+		C149D565242EB765003EBB12 /* SleepDisablerIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SleepDisablerIdentifier.h; sourceTree = "<group>"; };
 		C1692DD123D23ABD006E88F7 /* SystemBattery.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemBattery.mm; sourceTree = "<group>"; };
 		C1692DD423D23AE0006E88F7 /* SystemBattery.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SystemBattery.h; sourceTree = "<group>"; };
+		C18FB518242F9382007E9875 /* SleepDisablerClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SleepDisablerClient.cpp; sourceTree = "<group>"; };
 		C1E1D235203DF15400584665 /* ScreenProperties.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScreenProperties.h; sourceTree = "<group>"; };
 		C2015C091BE6FE2C00822389 /* FontVariantBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontVariantBuilder.h; sourceTree = "<group>"; };
 		C20F4F6421DFBE5C0070C45A /* WHLSLTypeReference.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLTypeReference.cpp; sourceTree = "<group>"; };
@@ -26253,6 +26261,11 @@
 				834DFACE1F7DAE5700C2725B /* SharedStringHash.cpp */,
 				834DFACC1F7DAE5600C2725B /* SharedStringHash.h */,
 				93309EA0099EB78C0056E581 /* SharedTimer.h */,
+				C149D559242EA4F8003EBB12 /* SleepDisabler.cpp */,
+				C149D55A242EA4F9003EBB12 /* SleepDisabler.h */,
+				C18FB518242F9382007E9875 /* SleepDisablerClient.cpp */,
+				C149D55B242EA4FA003EBB12 /* SleepDisablerClient.h */,
+				C149D565242EB765003EBB12 /* SleepDisablerIdentifier.h */,
 				A334BD822194E4610000D77F /* SSLKeyGenerator.cpp */,
 				F587866202DE3B1101EA4122 /* SSLKeyGenerator.h */,
 				F433E9041DBBDBC200EF0D14 /* StaticPasteboard.cpp */,
@@ -32726,6 +32739,9 @@
 				9444CBD61D860C8B0073A074 /* SizesAttributeParser.h in Headers */,
 				9444CBD41D860C8B0073A074 /* SizesCalcParser.h in Headers */,
 				49E911CD0EF86D47009D0CAF /* SkewTransformOperation.h in Headers */,
+				C149D55D242EA6B9003EBB12 /* SleepDisabler.h in Headers */,
+				C149D55F242EA7B8003EBB12 /* SleepDisablerClient.h in Headers */,
+				C149D567242EB84A003EBB12 /* SleepDisablerIdentifier.h in Headers */,
 				4150F9F112B6E0E70008C860 /* SliderThumbElement.h in Headers */,
 				9B532EA41BA928570038A827 /* SlotAssignment.h in Headers */,
 				4B6FA6F40C39E48C00087011 /* SmartReplace.h in Headers */,

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (259199 => 259200)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2020-03-30 14:48:38 UTC (rev 259200)
@@ -92,6 +92,7 @@
 #include "SecurityPolicy.h"
 #include "Settings.h"
 #include "ShadowRoot.h"
+#include "SleepDisabler.h"
 #include "TimeRanges.h"
 #include "UserContentController.h"
 #include "UserGestureIndicator.h"
@@ -99,7 +100,6 @@
 #include <_javascript_Core/Uint8Array.h>
 #include <limits>
 #include <pal/SessionID.h>
-#include <pal/system/SleepDisabler.h>
 #include <wtf/Algorithms.h>
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/Language.h>
@@ -6953,7 +6953,7 @@
     else if (shouldDisableSleep != SleepType::None) {
         auto type = shouldDisableSleep == SleepType::Display ? PAL::SleepDisabler::Type::Display : PAL::SleepDisabler::Type::System;
         if (!m_sleepDisabler || m_sleepDisabler->type() != type)
-            m_sleepDisabler = PAL::SleepDisabler::create("com.apple.WebCore: HTMLMediaElement playback", type);
+            m_sleepDisabler = makeUnique<SleepDisabler>("com.apple.WebCore: HTMLMediaElement playback", type);
     }
 
     if (m_player)

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (259199 => 259200)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2020-03-30 14:48:38 UTC (rev 259200)
@@ -63,10 +63,6 @@
 #include <wtf/StringPrintStream.h>
 #endif
 
-namespace PAL {
-class SleepDisabler;
-}
-
 namespace WebCore {
 
 class AudioSourceProvider;
@@ -94,6 +90,7 @@
 class RenderMedia;
 class ScriptController;
 class ScriptExecutionContext;
+class SleepDisabler;
 class SourceBuffer;
 class TextTrackList;
 class TimeRanges;
@@ -1162,7 +1159,7 @@
     friend class MediaController;
     RefPtr<MediaController> m_mediaController;
 
-    std::unique_ptr<PAL::SleepDisabler> m_sleepDisabler;
+    std::unique_ptr<SleepDisabler> m_sleepDisabler;
 
     WeakPtr<const MediaResourceLoader> m_lastMediaResourceLoaderForTesting;
 

Added: trunk/Source/WebCore/platform/SleepDisabler.cpp (0 => 259200)


--- trunk/Source/WebCore/platform/SleepDisabler.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/SleepDisabler.cpp	2020-03-30 14:48:38 UTC (rev 259200)
@@ -0,0 +1,51 @@
+/*
+ * 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

Added: trunk/Source/WebCore/platform/SleepDisabler.h (0 => 259200)


--- trunk/Source/WebCore/platform/SleepDisabler.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/SleepDisabler.h	2020-03-30 14:48:38 UTC (rev 259200)
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "SleepDisablerIdentifier.h"
+
+#include <pal/system/SleepDisabler.h>
+#include <wtf/ObjectIdentifier.h>
+
+namespace WebCore {
+
+class SleepDisabler {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    WEBCORE_EXPORT SleepDisabler(const char*, PAL::SleepDisabler::Type);
+    WEBCORE_EXPORT ~SleepDisabler();
+
+    PAL::SleepDisabler::Type type() const { return m_type; }
+
+private:
+    std::unique_ptr<PAL::SleepDisabler> m_platformSleepDisabler;
+    SleepDisablerIdentifier m_identifier;
+    PAL::SleepDisabler::Type m_type;
+};
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/SleepDisablerClient.cpp (0 => 259200)


--- trunk/Source/WebCore/platform/SleepDisablerClient.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/SleepDisablerClient.cpp	2020-03-30 14:48:38 UTC (rev 259200)
@@ -0,0 +1,39 @@
+/*
+ * 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 "SleepDisablerClient.h"
+
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+std::unique_ptr<SleepDisablerClient>& sleepDisablerClient()
+{
+    static NeverDestroyed<std::unique_ptr<SleepDisablerClient>> client;
+    return client.get();
+}
+
+}

Added: trunk/Source/WebCore/platform/SleepDisablerClient.h (0 => 259200)


--- trunk/Source/WebCore/platform/SleepDisablerClient.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/SleepDisablerClient.h	2020-03-30 14:48:38 UTC (rev 259200)
@@ -0,0 +1,42 @@
+/*
+* 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 COMPUTER, 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 COMPUTER, 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.
+*/
+
+#pragma once
+
+#include "SleepDisablerIdentifier.h"
+#include <wtf/Forward.h>
+
+namespace WebCore {
+
+class SleepDisablerClient {
+public:
+    virtual ~SleepDisablerClient() { }
+    virtual void didCreateSleepDisabler(SleepDisablerIdentifier, const String& reason, bool display) = 0;
+    virtual void didDestroySleepDisabler(SleepDisablerIdentifier) = 0;
+};
+
+WEBCORE_EXPORT std::unique_ptr<SleepDisablerClient>& sleepDisablerClient();
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/SleepDisablerIdentifier.h (0 => 259200)


--- trunk/Source/WebCore/platform/SleepDisablerIdentifier.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/SleepDisablerIdentifier.h	2020-03-30 14:48:38 UTC (rev 259200)
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <wtf/ObjectIdentifier.h>
+
+namespace WebCore {
+
+enum SleepDisablerIdentifierType { };
+using SleepDisablerIdentifier = ObjectIdentifier<SleepDisablerIdentifierType>;
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/testing/Internals.cpp (259199 => 259200)


--- trunk/Source/WebCore/testing/Internals.cpp	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebCore/testing/Internals.cpp	2020-03-30 14:48:38 UTC (rev 259200)
@@ -5564,4 +5564,17 @@
     return RenderTheme::singleton().focusRingColor(options).cssText();
 }
 
+unsigned Internals::createSleepDisabler(const String& reason, bool display)
+{
+    static unsigned lastUsedIdentifier = 0;
+    auto sleepDisabler = makeUnique<WebCore::SleepDisabler>(reason.utf8().data(), display ? PAL::SleepDisabler::Type::Display : PAL::SleepDisabler::Type::System);
+    m_sleepDisablers.add(++lastUsedIdentifier, WTFMove(sleepDisabler));
+    return lastUsedIdentifier;
+}
+
+bool Internals::destroySleepDisabler(unsigned identifier)
+{
+    return m_sleepDisablers.remove(identifier);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/testing/Internals.h (259199 => 259200)


--- trunk/Source/WebCore/testing/Internals.h	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebCore/testing/Internals.h	2020-03-30 14:48:38 UTC (rev 259200)
@@ -35,6 +35,7 @@
 #include "OrientationNotifier.h"
 #include "PageConsoleClient.h"
 #include "RealtimeMediaSource.h"
+#include "SleepDisabler.h"
 #include "TextIndicator.h"
 #include <_javascript_Core/Float32Array.h>
 #include <wtf/Optional.h>
@@ -960,6 +961,9 @@
 
     bool isRemoteUIAppForAccessibility();
 
+    unsigned createSleepDisabler(const String& reason, bool display);
+    bool destroySleepDisabler(unsigned identifier);
+
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;
@@ -981,6 +985,8 @@
 
     std::unique_ptr<InspectorStubFrontend> m_inspectorFrontend;
     RefPtr<CacheStorageConnection> m_cacheStorageConnection;
+
+    HashMap<unsigned, std::unique_ptr<WebCore::SleepDisabler>> m_sleepDisablers;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/testing/Internals.idl (259199 => 259200)


--- trunk/Source/WebCore/testing/Internals.idl	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebCore/testing/Internals.idl	2020-03-30 14:48:38 UTC (rev 259200)
@@ -862,4 +862,7 @@
     boolean supportsPictureInPicture();
 
     boolean isRemoteUIAppForAccessibility();
+
+    unsigned long createSleepDisabler(DOMString reason, boolean display);
+    boolean destroySleepDisabler(unsigned long identifier);
 };

Modified: trunk/Source/WebKit/ChangeLog (259199 => 259200)


--- trunk/Source/WebKit/ChangeLog	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/ChangeLog	2020-03-30 14:48:38 UTC (rev 259200)
@@ -1,3 +1,37 @@
+2020-03-30  Per Arne Vollan  <[email protected]>
+
+        [Cocoa] Sleep disabling should be performed in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=209676
+
+        Reviewed by Darin Adler.
+
+        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):
+
 2020-03-30  Wenson Hsieh  <[email protected]>
 
         [macOS] Datalist dropdown suggestions table can be scrolled too far

Modified: trunk/Source/WebKit/Scripts/webkit/messages.py (259199 => 259200)


--- trunk/Source/WebKit/Scripts/webkit/messages.py	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/Scripts/webkit/messages.py	2020-03-30 14:48:38 UTC (rev 259200)
@@ -222,6 +222,7 @@
         'WebCore::ServiceWorkerOrClientData',
         'WebCore::ServiceWorkerOrClientIdentifier',
         'WebCore::ServiceWorkerRegistrationIdentifier',
+        'WebCore::SleepDisablerIdentifier',
         'WebCore::SWServerConnectionIdentifier',
         'WebKit::ActivityStateChangeID',
         'WebKit::AudioMediaStreamTrackRendererIdentifier',

Modified: trunk/Source/WebKit/Sources.txt (259199 => 259200)


--- trunk/Source/WebKit/Sources.txt	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/Sources.txt	2020-03-30 14:48:38 UTC (rev 259200)
@@ -478,6 +478,7 @@
 
 WebProcess/WebConnectionToUIProcess.cpp
 WebProcess/WebProcess.cpp
+WebProcess/WebSleepDisablerClient.cpp
 
 // FIXME(206266): AutomationProtocolObjects.h's "namespace Protocol" conflicts with objc/runtime.h's "typedef struct objc_object Protocol"
 WebProcess/Automation/WebAutomationSessionProxy.cpp @no-unify

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h (259199 => 259200)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h	2020-03-30 14:48:38 UTC (rev 259200)
@@ -64,4 +64,5 @@
 + (void)_setApplicationBundleIdentifier:(NSString *)bundleIdentifier;
 + (void)_clearApplicationBundleIdentifierTestingOverride;
 
+- (BOOL)_hasSleepDisabler;
 @end

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm (259199 => 259200)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm	2020-03-30 14:48:38 UTC (rev 259200)
@@ -220,4 +220,9 @@
     WebCore::clearApplicationBundleIdentifierTestingOverride();
 }
 
+- (BOOL)_hasSleepDisabler
+{
+    return _page && _page->process().hasSleepDisabler();
+}
+
 @end

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (259199 => 259200)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2020-03-30 14:48:38 UTC (rev 259200)
@@ -1780,6 +1780,24 @@
 }
 #endif
 
+void WebProcessProxy::didCreateSleepDisabler(SleepDisablerIdentifier identifier, const String& reason, bool display)
+{
+    MESSAGE_CHECK(identifier);
+    auto sleepDisabler = makeUnique<WebCore::SleepDisabler>(reason.utf8().data(), display ? PAL::SleepDisabler::Type::Display : PAL::SleepDisabler::Type::System);
+    m_sleepDisablers.add(identifier, WTFMove(sleepDisabler));
+}
+
+void WebProcessProxy::didDestroySleepDisabler(SleepDisablerIdentifier identifier)
+{
+    MESSAGE_CHECK(identifier);
+    m_sleepDisablers.remove(identifier);
+}
+
+bool WebProcessProxy::hasSleepDisabler() const
+{
+    return !m_sleepDisablers.isEmpty();
+}
+
 } // namespace WebKit
 
 #undef MESSAGE_CHECK

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.h (259199 => 259200)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2020-03-30 14:48:38 UTC (rev 259200)
@@ -46,6 +46,7 @@
 #include <WebCore/ProcessIdentifier.h>
 #include <WebCore/RegistrableDomain.h>
 #include <WebCore/SharedStringHash.h>
+#include <WebCore/SleepDisabler.h>
 #include <memory>
 #include <pal/SessionID.h>
 #include <wtf/Forward.h>
@@ -378,6 +379,8 @@
     void gpuProcessCrashed();
 #endif
 
+    bool hasSleepDisabler() const;
+
 protected:
     WebProcessProxy(WebProcessPool&, WebsiteDataStore*, IsPrewarmed);
 
@@ -475,6 +478,9 @@
     void sendMessageToWebContextWithReply(UserMessage&&, CompletionHandler<void(UserMessage&&)>&&);
 #endif
 
+    void didCreateSleepDisabler(WebCore::SleepDisablerIdentifier, const String& reason, bool display);
+    void didDestroySleepDisabler(WebCore::SleepDisablerIdentifier);
+
     enum class IsWeak { No, Yes };
     template<typename T> class WeakOrStrongPtr {
     public:
@@ -580,6 +586,8 @@
         WeakHashSet<WebProcessProxy> clientProcesses;
     };
     Optional<ServiceWorkerInformation> m_serviceWorkerInformation;
+
+    HashMap<WebCore::SleepDisablerIdentifier, std::unique_ptr<WebCore::SleepDisabler>> m_sleepDisablers;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.messages.in (259199 => 259200)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.messages.in	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.messages.in	2020-03-30 14:48:38 UTC (rev 259200)
@@ -80,4 +80,7 @@
     SendMessageToWebContext(struct WebKit::UserMessage userMessage)
     SendMessageToWebContextWithReply(struct WebKit::UserMessage userMessage) -> (struct WebKit::UserMessage replyMessage) Async
 #endif
+
+    DidCreateSleepDisabler(WebCore::SleepDisablerIdentifier identifier, String reason, bool display)
+    DidDestroySleepDisabler(WebCore::SleepDisablerIdentifier identifier)
 }

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (259199 => 259200)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-03-30 14:48:38 UTC (rev 259200)
@@ -4983,6 +4983,8 @@
 		C181735E205839F600DFDA65 /* DrawingAreaMac.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DrawingAreaMac.cpp; sourceTree = "<group>"; };
 		C18173602058424700DFDA65 /* DisplayLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayLink.h; sourceTree = "<group>"; };
 		C1817362205844A900DFDA65 /* DisplayLink.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayLink.cpp; sourceTree = "<group>"; };
+		C18FB51D242F9F76007E9875 /* WebSleepDisablerClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSleepDisablerClient.cpp; sourceTree = "<group>"; };
+		C18FB51E242F9F77007E9875 /* WebSleepDisablerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSleepDisablerClient.h; sourceTree = "<group>"; };
 		C1E123B920A11572002646F4 /* PDFContextMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDFContextMenu.h; sourceTree = "<group>"; };
 		C517388012DF8F4F00EE3F47 /* DragControllerAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragControllerAction.h; sourceTree = "<group>"; };
 		C5237F5F12441CA300780472 /* WebEditorClientMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebEditorClientMac.mm; sourceTree = "<group>"; };
@@ -8701,6 +8703,8 @@
 				BC032D9110F437AF0058C15A /* WebProcess.h */,
 				BC3066B9125A436300E71278 /* WebProcess.messages.in */,
 				BCE0E424168B7A280057E66A /* WebProcessSupplement.h */,
+				C18FB51D242F9F76007E9875 /* WebSleepDisablerClient.cpp */,
+				C18FB51E242F9F77007E9875 /* WebSleepDisablerClient.h */,
 			);
 			path = WebProcess;
 			sourceTree = "<group>";

Modified: trunk/Source/WebKit/WebProcess/GPU/media/RemoteLegacyCDM.cpp (259199 => 259200)


--- trunk/Source/WebKit/WebProcess/GPU/media/RemoteLegacyCDM.cpp	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/WebProcess/GPU/media/RemoteLegacyCDM.cpp	2020-03-30 14:48:38 UTC (rev 259200)
@@ -28,6 +28,7 @@
 
 #if ENABLE(GPU_PROCESS) && ENABLE(LEGACY_ENCRYPTED_MEDIA)
 
+#include "GPUProcessConnection.h"
 #include "RemoteLegacyCDMFactory.h"
 #include "RemoteLegacyCDMProxyMessages.h"
 #include "RemoteLegacyCDMSession.h"

Modified: trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.cpp (259199 => 259200)


--- trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.cpp	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.cpp	2020-03-30 14:48:38 UTC (rev 259200)
@@ -29,6 +29,8 @@
 #if ENABLE(GPU_PROCESS) && PLATFORM(IOS_FAMILY)
 
 #include "Connection.h"
+#include "GPUConnectionToWebProcessMessages.h"
+#include "GPUProcessConnection.h"
 #include "RemoteMediaSessionHelperProxyMessages.h"
 #include "WebProcess.h"
 #include <WebCore/MediaPlaybackTargetCocoa.h>

Modified: trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.h (259199 => 259200)


--- trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.h	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/WebProcess/GPU/media/ios/RemoteMediaSessionHelper.h	2020-03-30 14:48:38 UTC (rev 259200)
@@ -28,6 +28,7 @@
 #if ENABLE(GPU_PROCESS) && PLATFORM(IOS_FAMILY)
 
 #include "MessageReceiver.h"
+#include <WebCore/MediaPlaybackTargetContext.h>
 #include <WebCore/MediaSessionHelperIOS.h>
 
 namespace WebKit {

Modified: trunk/Source/WebKit/WebProcess/WebPage/ViewGestureGeometryCollector.cpp (259199 => 259200)


--- trunk/Source/WebKit/WebProcess/WebPage/ViewGestureGeometryCollector.cpp	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/WebProcess/WebPage/ViewGestureGeometryCollector.cpp	2020-03-30 14:48:38 UTC (rev 259200)
@@ -39,6 +39,7 @@
 #include <WebCore/HTMLTextFormControlElement.h>
 #include <WebCore/HitTestResult.h>
 #include <WebCore/ImageDocument.h>
+#include <WebCore/Range.h>
 #include <WebCore/RenderView.h>
 #include <WebCore/TextIterator.h>
 

Added: trunk/Source/WebKit/WebProcess/WebSleepDisablerClient.cpp (0 => 259200)


--- trunk/Source/WebKit/WebProcess/WebSleepDisablerClient.cpp	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/WebSleepDisablerClient.cpp	2020-03-30 14:48:38 UTC (rev 259200)
@@ -0,0 +1,44 @@
+/*
+* 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 COMPUTER, 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 COMPUTER, 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.
+*/
+
+#include "config.h"
+#include "WebSleepDisablerClient.h"
+
+#include "WebProcess.h"
+#include "WebProcessProxyMessages.h"
+
+namespace WebKit {
+
+void WebSleepDisablerClient::didCreateSleepDisabler(SleepDisablerIdentifier identifier, const String& reason, bool display)
+{
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidCreateSleepDisabler(identifier, reason, display), 0);
+}
+
+void WebSleepDisablerClient::didDestroySleepDisabler(SleepDisablerIdentifier identifier)
+{
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::DidDestroySleepDisabler(identifier), 0);
+}
+
+} // namespace WebKit

Added: trunk/Source/WebKit/WebProcess/WebSleepDisablerClient.h (0 => 259200)


--- trunk/Source/WebKit/WebProcess/WebSleepDisablerClient.h	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/WebSleepDisablerClient.h	2020-03-30 14:48:38 UTC (rev 259200)
@@ -0,0 +1,39 @@
+/*
+* 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 COMPUTER, 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 COMPUTER, 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.
+*/
+
+#pragma once
+
+#include <WebCore/SleepDisablerClient.h>
+
+namespace WebKit {
+
+class WebSleepDisablerClient : public WebCore::SleepDisablerClient {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    void didCreateSleepDisabler(SleepDisablerIdentifier, const String&, bool) override;
+    void didDestroySleepDisabler(SleepDisablerIdentifier) override;
+};
+
+} // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (259199 => 259200)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-03-30 14:48:38 UTC (rev 259200)
@@ -46,6 +46,7 @@
 #import "WebProcessCreationParameters.h"
 #import "WebProcessDataStoreParameters.h"
 #import "WebProcessProxyMessages.h"
+#import "WebSleepDisablerClient.h"
 #import "WebsiteDataStoreParameters.h"
 #import <_javascript_Core/ConfigFile.h>
 #import <_javascript_Core/Options.h>
@@ -63,10 +64,12 @@
 #import <WebCore/MIMETypeRegistry.h>
 #import <WebCore/MemoryRelease.h>
 #import <WebCore/NSScrollerImpDetails.h>
+#import <WebCore/NetworkExtensionContentFilter.h>
 #import <WebCore/PerformanceLogging.h>
 #import <WebCore/PictureInPictureSupport.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SWContextManager.h>
+#import <WebCore/SystemBattery.h>
 #import <WebCore/UTIUtilities.h>
 #import <algorithm>
 #import <dispatch/dispatch.h>
@@ -131,11 +134,6 @@
 #import <os/state_private.h>
 #endif
 
-#if PLATFORM(COCOA)
-#import <WebCore/NetworkExtensionContentFilter.h>
-#import <WebCore/SystemBattery.h>
-#endif
-
 #if HAVE(CSCHECKFIXDISABLE)
 extern "C" void _CSCheckFixDisable();
 #endif
@@ -317,6 +315,8 @@
         setVectorOfUTTypeItem(WTFMove(parameters.vectorOfUTTypeItem));
     }
 #endif
+
+    WebCore::sleepDisablerClient() = makeUnique<WebSleepDisablerClient>();
 }
 
 void WebProcess::platformSetWebsiteDataStoreParameters(WebProcessDataStoreParameters&& parameters)

Modified: trunk/Tools/ChangeLog (259199 => 259200)


--- trunk/Tools/ChangeLog	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Tools/ChangeLog	2020-03-30 14:48:38 UTC (rev 259200)
@@ -1,5 +1,16 @@
 2020-03-30  Per Arne Vollan  <[email protected]>
 
+        [Cocoa] Sleep disabling should be performed in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=209676
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/SleepDisabler.mm: Added.
+        (TEST):
+
+2020-03-30  Per Arne Vollan  <[email protected]>
+
         [macOS] REGRESSION(r258949) API test failures
         https://bugs.webkit.org/show_bug.cgi?id=209702
 

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (259199 => 259200)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-03-30 14:15:49 UTC (rev 259199)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-03-30 14:48:38 UTC (rev 259200)
@@ -883,6 +883,7 @@
 		C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */; };
 		C13D82D92416F13200A62793 /* EnableAccessibility.mm in Sources */ = {isa = PBXBuildFile; fileRef = C13D82D82416F13200A62793 /* EnableAccessibility.mm */; };
 		C145CC0C23DA5A1F003A5EEB /* MimeTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = C145CC0B23DA5A0F003A5EEB /* MimeTypes.mm */; };
+		C149D550242E98DF003EBB12 /* SleepDisabler.mm in Sources */ = {isa = PBXBuildFile; fileRef = C149D54F242E9844003EBB12 /* SleepDisabler.mm */; };
 		C15CBB3023F1FF1A00300CC7 /* BacklightLevelNotification.mm in Sources */ = {isa = PBXBuildFile; fileRef = C15CBB2F23F1FF1A00300CC7 /* BacklightLevelNotification.mm */; };
 		C15CBB3F23FB177A00300CC7 /* PreferenceChanges.mm in Sources */ = {isa = PBXBuildFile; fileRef = C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */; };
 		C1692DCA23D10DAE006E88F7 /* Battery.mm in Sources */ = {isa = PBXBuildFile; fileRef = C1692DC923D10DAE006E88F7 /* Battery.mm */; };
@@ -2458,6 +2459,7 @@
 		C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetBackingScaleFactor_Bundle.mm; sourceTree = "<group>"; };
 		C13D82D82416F13200A62793 /* EnableAccessibility.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = EnableAccessibility.mm; sourceTree = "<group>"; };
 		C145CC0B23DA5A0F003A5EEB /* MimeTypes.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MimeTypes.mm; sourceTree = "<group>"; };
+		C149D54F242E9844003EBB12 /* SleepDisabler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SleepDisabler.mm; sourceTree = "<group>"; };
 		C15CBB2F23F1FF1A00300CC7 /* BacklightLevelNotification.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BacklightLevelNotification.mm; sourceTree = "<group>"; };
 		C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PreferenceChanges.mm; sourceTree = "<group>"; };
 		C1692DC923D10DAE006E88F7 /* Battery.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = Battery.mm; sourceTree = "<group>"; };
@@ -2921,6 +2923,7 @@
 				C145CC0B23DA5A0F003A5EEB /* MimeTypes.mm */,
 				E325C90623E3870200BC7D3B /* PictureInPictureSupport.mm */,
 				C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */,
+				C149D54F242E9844003EBB12 /* SleepDisabler.mm */,
 				C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */,
 				E3CAAA4B2415505100CED2E2 /* UTIFromTag.mm */,
 				0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */,
@@ -5058,6 +5061,7 @@
 				37BCA61C1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm in Sources */,
 				7C83E0C51D0A654600FEBCF3 /* ShrinkToFit.mm in Sources */,
 				7CCE7ECD1A411A7E00447C4C /* SimplifyMarkup.mm in Sources */,
+				C149D550242E98DF003EBB12 /* SleepDisabler.mm in Sources */,
 				2DFF7B6D1DA487AF00814614 /* SnapshotStore.mm in Sources */,
 				0F4FFA9E1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm in Sources */,
 				7CCE7F151A411AE600447C4C /* SpacebarScrolling.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/SleepDisabler.mm (0 => 259200)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/SleepDisabler.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/SleepDisabler.mm	2020-03-30 14:48:38 UTC (rev 259200)
@@ -0,0 +1,64 @@
+/*
+ * 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"
+
+#if WK_HAVE_C_SPI
+
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKWebViewPrivateForTesting.h>
+#import <wtf/Threading.h>
+
+TEST(WebKit, SleepDisabler)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
+    configuration.get().processPool = (WKProcessPool *)context.get();
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
+
+    ASSERT_FALSE([webView _hasSleepDisabler]);
+
+    auto createSleepDisabler = [&] {
+        return [webView stringByEvaluatingJavaScript:@"window.internals.createSleepDisabler(\"TestDisabler\", true)"].longLongValue;
+    };
+
+    auto identifier = createSleepDisabler();
+
+    ASSERT_NE(identifier, 0);
+
+    ASSERT_TRUE([webView _hasSleepDisabler]);
+
+    auto destroySleepDisabler = [&] {
+        NSString *js = [NSString stringWithFormat:@"window.internals.destroySleepDisabler(%lld)", identifier];
+        return [webView stringByEvaluatingJavaScript:js];
+    };
+
+    ASSERT_TRUE(destroySleepDisabler());
+
+    ASSERT_FALSE([webView _hasSleepDisabler]);
+}
+
+#endif // WK_HAVE_C_SPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to