[iOS] Check if PIP is supported in the UI process
authorpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Feb 2020 20:22:05 +0000 (20:22 +0000)
committerpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Feb 2020 20:22:05 +0000 (20:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=207406

Reviewed by Brent Fulgham.

Source/WebCore:

This is currently being checked in the WebProcess, but since this check is initiating communication with the frontboard
service which will be blocked, this check should be moved to the UI process. In the UI process, this is checked when
starting a new WebContent process, and sent to the WebContent process as part of the process creation parameters. The
WebContent is storing the received value.

API test: WebKit.PictureInPictureSupport

* platform/PictureInPictureSupport.h:
* platform/ios/VideoFullscreenInterfaceAVKit.mm:
(WebCore::setSupportsPictureInPicture):
(WebCore::supportsPictureInPicture):
* testing/Internals.cpp:
(WebCore::Internals::supportsPictureInPicture):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

When starting a new WebContent process, check if PIP is supported, and pass the results to the newly created
WebContent process.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/PictureInPictureSupport.mm: Added.
(TEST):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@256531 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/PictureInPictureSupport.h
Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebProcessCreationParameters.cpp
Source/WebKit/Shared/WebProcessCreationParameters.h
Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit/PictureInPictureSupport.mm [new file with mode: 0644]

index 59b66bf..64d648a 100644 (file)
@@ -1,3 +1,26 @@
+2020-02-13  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Check if PIP is supported in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=207406
+
+        Reviewed by Brent Fulgham.
+
+        This is currently being checked in the WebProcess, but since this check is initiating communication with the frontboard
+        service which will be blocked, this check should be moved to the UI process. In the UI process, this is checked when
+        starting a new WebContent process, and sent to the WebContent process as part of the process creation parameters. The
+        WebContent is storing the received value.
+
+        API test: WebKit.PictureInPictureSupport
+
+        * platform/PictureInPictureSupport.h:
+        * platform/ios/VideoFullscreenInterfaceAVKit.mm:
+        (WebCore::setSupportsPictureInPicture):
+        (WebCore::supportsPictureInPicture):
+        * testing/Internals.cpp:
+        (WebCore::Internals::supportsPictureInPicture):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2020-02-13  Benjamin Nham  <nham@apple.com>
 
         Allow use of proxies in MiniBrowser
index e8366b6..bc4f64b 100644 (file)
@@ -28,6 +28,7 @@
 namespace WebCore {
 
 #if PLATFORM(IOS_FAMILY) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
+WEBCORE_EXPORT void setSupportsPictureInPicture(bool);
 WEBCORE_EXPORT bool supportsPictureInPicture();
 #else
 constexpr bool supportsPictureInPicture() { return false; }
index 2639ee8..075f337 100644 (file)
@@ -1503,9 +1503,18 @@ bool VideoFullscreenInterfaceAVKit::isPlayingVideoInEnhancedFullscreen() const
 
 #endif // HAVE(AVKIT)
 
+static Optional<bool> isPictureInPictureSupported;
+
+void WebCore::setSupportsPictureInPicture(bool isSupported)
+{
+    isPictureInPictureSupported = isSupported;
+}
+
 bool WebCore::supportsPictureInPicture()
 {
 #if PLATFORM(IOS_FAMILY) && HAVE(AVKIT) && !PLATFORM(WATCHOS)
+    if (isPictureInPictureSupported.hasValue())
+        return *isPictureInPictureSupported;
     return [getAVPictureInPictureControllerClass() isPictureInPictureSupported];
 #else
     return false;
index fe96d7a..96539c1 100644 (file)
 #include "Page.h"
 #include "PageOverlay.h"
 #include "PathUtilities.h"
+#include "PictureInPictureSupport.h"
 #include "PlatformKeyboardEvent.h"
 #include "PlatformMediaSessionManager.h"
 #include "PlatformScreen.h"
@@ -5466,6 +5467,11 @@ String Internals::mediaMIMETypeForExtension(const String& extension)
     return MIMETypeRegistry::getMediaMIMETypeForExtension(extension);
 }
 
+bool Internals::supportsPictureInPicture()
+{
+    return WebCore::supportsPictureInPicture();
+}
+
 String Internals::focusRingColor()
 {
     OptionSet<StyleColor::Options> options;
index 53175c5..4398624 100644 (file)
@@ -935,6 +935,8 @@ public:
 
     String mediaMIMETypeForExtension(const String& extension);
 
+    bool supportsPictureInPicture();
+
     String focusRingColor();
 
 private:
index e9e8be3..8f0004f 100644 (file)
@@ -843,4 +843,6 @@ enum CompositingPolicy {
     boolean systemHasBattery();
 
     DOMString mediaMIMETypeForExtension(DOMString extension);
+    
+    boolean supportsPictureInPicture();
 };
index 6aefc42..d0014b6 100644 (file)
@@ -1,3 +1,22 @@
+2020-02-13  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Check if PIP is supported in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=207406
+
+        Reviewed by Brent Fulgham.
+
+        When starting a new WebContent process, check if PIP is supported, and pass the results to the newly created
+        WebContent process.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeWebProcess):
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2020-02-13  Benjamin Nham  <nham@apple.com>
 
         Allow use of proxies in MiniBrowser
index 61b10d7..be07eed 100644 (file)
@@ -172,6 +172,7 @@ void WebProcessCreationParameters::encode(IPC::Encoder& encoder) const
 
 #if PLATFORM(IOS_FAMILY)
     encoder << currentUserInterfaceIdiomIsPad;
+    encoder << supportsPictureInPicture;
     encoder << cssValueToSystemColorMap;
     encoder << focusRingColor;
 #endif
@@ -454,6 +455,9 @@ bool WebProcessCreationParameters::decode(IPC::Decoder& decoder, WebProcessCreat
     if (!decoder.decode(parameters.currentUserInterfaceIdiomIsPad))
         return false;
 
+    if (!decoder.decode(parameters.supportsPictureInPicture))
+        return false;
+
     Optional<WebCore::RenderThemeIOS::CSSValueToSystemColorMap> cssValueToSystemColorMap;
     decoder >> cssValueToSystemColorMap;
     if (!cssValueToSystemColorMap)
index 1fa0304..c23a0a7 100644 (file)
@@ -214,6 +214,7 @@ struct WebProcessCreationParameters {
 
 #if PLATFORM(IOS_FAMILY)
     bool currentUserInterfaceIdiomIsPad { false };
+    bool supportsPictureInPicture { false };
     WebCore::RenderThemeIOS::CSSValueToSystemColorMap cssValueToSystemColorMap;
     WebCore::Color focusRingColor;
 #endif
index a64db46..2e0df76 100644 (file)
@@ -360,6 +360,7 @@ void WebProcessPool::platformInitializeWebProcess(const WebProcessProxy& process
     
 #if PLATFORM(IOS_FAMILY)
     parameters.currentUserInterfaceIdiomIsPad = currentUserInterfaceIdiomIsPad();
+    parameters.supportsPictureInPicture = supportsPictureInPicture();
     parameters.cssValueToSystemColorMap = RenderThemeIOS::cssValueToSystemColorMap();
     parameters.focusRingColor = RenderTheme::singleton().focusRingColor(OptionSet<StyleColor::Options>());
 #endif
index 7ecdb45..01028ee 100644 (file)
@@ -63,6 +63,7 @@
 #import <WebCore/MemoryRelease.h>
 #import <WebCore/NSScrollerImpDetails.h>
 #import <WebCore/PerformanceLogging.h>
+#import <WebCore/PictureInPictureSupport.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SWContextManager.h>
 #import <algorithm>
@@ -197,6 +198,7 @@ void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& para
 
 #if PLATFORM(IOS_FAMILY)
     setCurrentUserInterfaceIdiomIsPad(parameters.currentUserInterfaceIdiomIsPad);
+    setSupportsPictureInPicture(parameters.supportsPictureInPicture);
 #endif
 
 #if USE(APPKIT)
index 502c48c..5ca159f 100644 (file)
@@ -1,3 +1,14 @@
+2020-02-13  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Check if PIP is supported in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=207406
+
+        Reviewed by Brent Fulgham.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/PictureInPictureSupport.mm: Added.
+        (TEST):
+
 2020-02-13  Jonathan Bedard  <jbedard@apple.com>
 
         TestWebKitAPI: Conditionalize fullscreen tests on fullscreen API
index 1459d91..6aa0e93 100644 (file)
                E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
                E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
                E324A6F02041C82000A76593 /* UniqueArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E398BC0F2041C76300387136 /* UniqueArray.cpp */; };
+               E325C90723E3870200BC7D3B /* PictureInPictureSupport.mm in Sources */ = {isa = PBXBuildFile; fileRef = E325C90623E3870200BC7D3B /* PictureInPictureSupport.mm */; };
                E32B549222810AC4008AD702 /* Packed.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E32B549122810AC0008AD702 /* Packed.cpp */; };
                E35FC7B222B82A7300F32F98 /* JSLockTakesWebThreadLock.mm in Sources */ = {isa = PBXBuildFile; fileRef = E35FC7B122B82A6D00F32F98 /* JSLockTakesWebThreadLock.mm */; };
                E373D7911F2CF35200C6FAAF /* Signals.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3953F951F2CF32100A76A2E /* Signals.cpp */; };
                E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = MemoryCacheDisableWithinResourceLoadDelegate.html; sourceTree = "<group>"; };
                E194E1BA177E5145009C4D4E /* StopLoadingFromDidReceiveResponse.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StopLoadingFromDidReceiveResponse.mm; sourceTree = "<group>"; };
                E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = StopLoadingFromDidReceiveResponse.html; sourceTree = "<group>"; };
+               E325C90623E3870200BC7D3B /* PictureInPictureSupport.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PictureInPictureSupport.mm; sourceTree = "<group>"; };
                E32B549122810AC0008AD702 /* Packed.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Packed.cpp; sourceTree = "<group>"; };
                E35FC7B122B82A6D00F32F98 /* JSLockTakesWebThreadLock.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JSLockTakesWebThreadLock.mm; sourceTree = "<group>"; };
                E388887020C9098100E632BC /* WorkerPool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerPool.cpp; sourceTree = "<group>"; };
                                C1692DC923D10DAE006E88F7 /* Battery.mm */,
                                E394AE6E23F2303E005B4936 /* GrantAccessToMobileAssets.mm */,
                                C145CC0B23DA5A0F003A5EEB /* MimeTypes.mm */,
+                               E325C90623E3870200BC7D3B /* PictureInPictureSupport.mm */,
                                0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */,
                        );
                        name = cocoa;
                                516281272325C19800BB7E42 /* PDFSnapshot.mm in Sources */,
                                7C83E0531D0A643A00FEBCF3 /* PendingAPIRequestURL.cpp in Sources */,
                                3FCC4FE51EC4E8520076E37C /* PictureInPictureDelegate.mm in Sources */,
+                               E325C90723E3870200BC7D3B /* PictureInPictureSupport.mm in Sources */,
                                7CCE7EA61A411A0F00447C4C /* PlatformUtilitiesMac.mm in Sources */,
                                7CCE7EA71A411A1300447C4C /* PlatformWebViewMac.mm in Sources */,
                                83BAEE8D1EF4625500DDE894 /* PluginLoadClientPolicies.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit/PictureInPictureSupport.mm b/Tools/TestWebKitAPI/Tests/WebKit/PictureInPictureSupport.mm
new file mode 100644 (file)
index 0000000..5d58ca6
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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 <WebCore/PictureInPictureSupport.h>
+
+TEST(WebKit, PictureInPictureSupport)
+{
+    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]);
+
+    auto supportsPictureInPicture = [&] {
+        return [webView stringByEvaluatingJavaScript:@"window.internals.supportsPictureInPicture()"].boolValue;
+    };
+
+    ASSERT_TRUE(supportsPictureInPicture() == WebCore::supportsPictureInPicture());
+}
+
+#endif // WK_HAVE_C_SPI