[WK2] Only send gamepad input events to the currently focused page.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Aug 2016 00:49:34 +0000 (00:49 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Aug 2016 00:49:34 +0000 (00:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=160699

Reviewed by Tim Horton.

* UIProcess/Gamepad/UIGamepadProvider.cpp:
(WebKit::UIGamepadProvider::updateTimerFired):
(WebKit::UIGamepadProvider::platformWebProcessProxyForGamepadInput):
* UIProcess/Gamepad/UIGamepadProvider.h:
* UIProcess/Gamepad/mac/UIGamepadProviderMac.mm: Copied from Source/WebKit2/UIProcess/API/mac/WKViewInternal.h.
(WebKit::UIGamepadProvider::platformWebPageProxyForGamepadInput):

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::gamepadActivity):
* UIProcess/WebPageProxy.h:

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::gamepadActivity): Deleted.
* UIProcess/WebProcessPool.h:

* WebKit2.xcodeproj/project.pbxproj:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::gamepadActivity):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::gamepadActivity): Deleted.
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

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

15 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.cpp
Source/WebKit2/UIProcess/Gamepad/UIGamepadProvider.h
Source/WebKit2/UIProcess/Gamepad/mac/UIGamepadProviderMac.mm [new file with mode: 0644]
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebProcessPool.cpp
Source/WebKit2/UIProcess/WebProcessPool.h
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebProcess.cpp
Source/WebKit2/WebProcess/WebProcess.h
Source/WebKit2/WebProcess/WebProcess.messages.in

index 1374a09..ebd9d9c 100644 (file)
@@ -1,3 +1,37 @@
+2016-08-09  Brady Eidson  <beidson@apple.com>
+
+        [WK2] Only send gamepad input events to the currently focused page.
+        https://bugs.webkit.org/show_bug.cgi?id=160699
+
+        Reviewed by Tim Horton.
+        
+        * UIProcess/Gamepad/UIGamepadProvider.cpp:
+        (WebKit::UIGamepadProvider::updateTimerFired):
+        (WebKit::UIGamepadProvider::platformWebProcessProxyForGamepadInput):
+        * UIProcess/Gamepad/UIGamepadProvider.h:
+        * UIProcess/Gamepad/mac/UIGamepadProviderMac.mm: Copied from Source/WebKit2/UIProcess/API/mac/WKViewInternal.h.
+        (WebKit::UIGamepadProvider::platformWebPageProxyForGamepadInput):
+        
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::gamepadActivity):
+        * UIProcess/WebPageProxy.h:
+        
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::gamepadActivity): Deleted.
+        * UIProcess/WebProcessPool.h:
+        
+        * WebKit2.xcodeproj/project.pbxproj:
+        
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::gamepadActivity):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::gamepadActivity): Deleted.
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
 2016-08-09  Anders Carlsson  <andersca@apple.com>
 
         Remove code that would tell clients whenever the list of installed plug-ins changes
index d4181c7..645d350 100644 (file)
@@ -72,10 +72,9 @@ void UIGamepadProvider::updateTimerFired()
             gamepadDatas.uncheckedAppend({ });
     }
 
-    // FIXME (https://bugs.webkit.org/show_bug.cgi?id=160699)
-    // Only send updates to the process pool that contains the currently focused web page.
-    for (auto& pool : m_processPoolsUsingGamepads)
-        pool->gamepadActivity(gamepadDatas);
+    auto webPageProxy = platformWebPageProxyForGamepadInput();
+    if (webPageProxy && m_processPoolsUsingGamepads.contains(&webPageProxy->process().processPool()))
+        webPageProxy->gamepadActivity(gamepadDatas);
 
     m_hadActivitySinceLastSynch = false;
 }
@@ -185,6 +184,11 @@ const Vector<PlatformGamepad*>& UIGamepadProvider::platformGamepads()
     // FIXME: Implement for other platforms
 }
 
+WebProcessProxy* UIGamepadProvider::platformWebProcessProxyForGamepadInput()
+{
+    // FIXME: Implement for other platforms
+}
+
 #endif // !PLATFORM(MAC)
 
 }
index 0e8bffa..5b04068 100644 (file)
@@ -36,6 +36,7 @@
 namespace WebKit {
 
 class UIGamepad;
+class WebPageProxy;
 class WebProcessPool;
 struct GamepadData;
 
@@ -56,6 +57,7 @@ private:
     void platformStartMonitoringGamepads();
     void platformStopMonitoringGamepads();
     const Vector<WebCore::PlatformGamepad*>& platformGamepads();
+    WebPageProxy* platformWebPageProxyForGamepadInput();
 
     void platformGamepadConnected(WebCore::PlatformGamepad&) final;
     void platformGamepadDisconnected(WebCore::PlatformGamepad&) final;
diff --git a/Source/WebKit2/UIProcess/Gamepad/mac/UIGamepadProviderMac.mm b/Source/WebKit2/UIProcess/Gamepad/mac/UIGamepadProviderMac.mm
new file mode 100644 (file)
index 0000000..4b81f08
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#import "config.h"
+#import "UIGamepadProvider.h"
+
+#if ENABLE(GAMEPAD)
+
+#import "WebPageProxy.h"
+#import "WKAPICast.h"
+#import "WKViewInternal.h"
+#import "WKWebViewInternal.h"
+
+namespace WebKit {
+
+WebPageProxy* UIGamepadProvider::platformWebPageProxyForGamepadInput()
+{
+    auto responder = [[NSApp keyWindow] firstResponder];
+
+#if WK_API_ENABLED
+    if ([responder isKindOfClass:[WKWebView class]])
+        return ((WKWebView *)responder)->_page.get();
+#endif
+
+    if ([responder isKindOfClass:[WKView class]])
+        return toImpl(((WKView *)responder).pageRef);
+
+    return nullptr;
+}
+
+}
+
+#endif // ENABLE(GAMEPAD)
index 9940418..8deff12 100644 (file)
@@ -5470,6 +5470,15 @@ void WebPageProxy::backForwardClear()
     m_backForwardList->clear();
 }
 
+#if ENABLE(GAMEPAD)
+
+void WebPageProxy::gamepadActivity(const Vector<GamepadData>& gamepadDatas)
+{
+    m_process->send(Messages::WebPage::GamepadActivity(gamepadDatas), m_pageID);
+}
+
+#endif
+
 void WebPageProxy::canAuthenticateAgainstProtectionSpace(uint64_t loaderID, uint64_t frameID, const ProtectionSpace& coreProtectionSpace)
 {
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
index 93c51e8..baf1abf 100644 (file)
@@ -205,6 +205,7 @@ struct AttributedString;
 struct ColorSpaceData;
 struct EditingRange;
 struct EditorState;
+struct GamepadData;
 struct LoadParameters;
 struct PlatformPopupMenuData;
 struct PrintInfo;
@@ -1119,6 +1120,10 @@ public:
 
     void canAuthenticateAgainstProtectionSpace(uint64_t loaderID, uint64_t frameID, const WebCore::ProtectionSpace&);
 
+#if ENABLE(GAMEPAD)
+    void gamepadActivity(const Vector<GamepadData>&);
+#endif
+
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&);
     void platformInitialize();
index 1b60ca2..4ac71a8 100644 (file)
@@ -1286,14 +1286,6 @@ void WebProcessPool::gamepadDisconnected(const UIGamepad& gamepad)
         process->send(Messages::WebProcess::GamepadDisconnected(gamepad.index()), 0);
 }
 
-void WebProcessPool::gamepadActivity(const Vector<GamepadData>& gamepadDatas)
-{
-    // FIXME (https://bugs.webkit.org/show_bug.cgi?id=160699)
-    // Only send updates to the process that contains the currently focused web page.
-    for (auto& process : m_processesUsingGamepads)
-        process->send(Messages::WebProcess::GamepadActivity(gamepadDatas), 0);
-}
-
 #endif // ENABLE(GAMEPAD)
 
 void WebProcessPool::garbageCollectJavaScriptObjects()
index 3a39b2b..91025ab 100644 (file)
@@ -371,7 +371,6 @@ public:
 #if ENABLE(GAMEPAD)
     void gamepadConnected(const UIGamepad&);
     void gamepadDisconnected(const UIGamepad&);
-    void gamepadActivity(const Vector<GamepadData>&);
 #endif
 
 private:
index 0405e30..c632fbc 100644 (file)
                515BE1B31D5902DD00DD7C68 /* GamepadData.h in Headers */ = {isa = PBXBuildFile; fileRef = 515BE1B01D59006900DD7C68 /* GamepadData.h */; };
                515BE1B41D5917FF00DD7C68 /* UIGamepad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515BE1AC1D555C5100DD7C68 /* UIGamepad.cpp */; };
                515BE1B51D5917FF00DD7C68 /* UIGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 515BE1AD1D555C5100DD7C68 /* UIGamepad.h */; };
+               515BE1B71D5A94FD00DD7C68 /* UIGamepadProviderMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 515BE1B61D5A94F900DD7C68 /* UIGamepadProviderMac.mm */; };
                515E7727183DD6F60007203F /* AsyncRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515E7725183DD6F60007203F /* AsyncRequest.cpp */; };
                515E7728183DD6F60007203F /* AsyncRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 515E7726183DD6F60007203F /* AsyncRequest.h */; };
                515E772B184008B90007203F /* DatabaseProcessCreationParameters.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515E7729184008B90007203F /* DatabaseProcessCreationParameters.cpp */; };
                515BE1AD1D555C5100DD7C68 /* UIGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIGamepad.h; sourceTree = "<group>"; };
                515BE1B01D59006900DD7C68 /* GamepadData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GamepadData.h; sourceTree = "<group>"; };
                515BE1B11D5902B600DD7C68 /* GamepadData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GamepadData.cpp; sourceTree = "<group>"; };
+               515BE1B61D5A94F900DD7C68 /* UIGamepadProviderMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = UIGamepadProviderMac.mm; path = UIProcess/Gamepad/mac/UIGamepadProviderMac.mm; sourceTree = SOURCE_ROOT; };
                515E7725183DD6F60007203F /* AsyncRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AsyncRequest.cpp; sourceTree = "<group>"; };
                515E7726183DD6F60007203F /* AsyncRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncRequest.h; sourceTree = "<group>"; };
                515E7729184008B90007203F /* DatabaseProcessCreationParameters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DatabaseProcessCreationParameters.cpp; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                515BE1A61D55293000DD7C68 /* UIGamepadProviderHID.cpp */,
+                               515BE1B61D5A94F900DD7C68 /* UIGamepadProviderMac.mm */,
                        );
                        name = mac;
                        path = UIProcess/Gamepad/mac;
                                BCD59800112B57BE00EC8C23 /* WebPreferences.cpp in Sources */,
                                7C85FD7F19341665000177C4 /* WebPreferencesKeys.cpp in Sources */,
                                BC84EB1812A7100C0083F2DA /* WebPreferencesMac.mm in Sources */,
+                               515BE1B71D5A94FD00DD7C68 /* UIGamepadProviderMac.mm in Sources */,
                                BCD598AD112B7FDF00EC8C23 /* WebPreferencesStore.cpp in Sources */,
                                BC111AE4112F5C2600337BAB /* WebProcess.cpp in Sources */,
                                7C6E70FB18B2DC7A00F24E2E /* WebProcessCocoa.mm in Sources */,
index 9969066..5270586 100644 (file)
@@ -79,6 +79,7 @@
 #include "WebFrameLoaderClient.h"
 #include "WebFullScreenManager.h"
 #include "WebFullScreenManagerMessages.h"
+#include "WebGamepadProvider.h"
 #include "WebGeolocationClient.h"
 #include "WebImage.h"
 #include "WebInspector.h"
@@ -5463,4 +5464,13 @@ void WebPage::setUserInterfaceLayoutDirection(uint32_t direction)
     m_page->setUserInterfaceLayoutDirection(m_userInterfaceLayoutDirection);
 }
 
+#if ENABLE(GAMEPAD)
+
+void WebPage::gamepadActivity(const Vector<GamepadData>& gamepadDatas)
+{
+    WebGamepadProvider::singleton().gamepadActivity(gamepadDatas);
+}
+
+#endif
+
 } // namespace WebKit
index da16d78..2f96d01 100644 (file)
@@ -192,6 +192,7 @@ struct AttributedString;
 struct BackForwardListItemState;
 struct EditingRange;
 struct EditorState;
+struct GamepadData;
 struct InteractionInformationAtPosition;
 struct LoadParameters;
 struct PrintInfo;
@@ -949,6 +950,10 @@ public:
     std::chrono::system_clock::time_point loadCommitTime() const { return m_loadCommitTime; }
 #endif
 
+#if ENABLE(GAMEPAD)
+    void gamepadActivity(const Vector<GamepadData>&);
+#endif
+
 private:
     WebPage(uint64_t pageID, const WebPageCreationParameters&);
 
index d30532d..39f8df0 100644 (file)
@@ -433,4 +433,8 @@ messages -> WebPage LegacyReceiver {
     SetResourceCachingDisabled(bool disabled)
 
     SetUserInterfaceLayoutDirection(uint32_t direction)
+
+#if ENABLE(GAMEPAD)
+    GamepadActivity(Vector<WebKit::GamepadData> gamepadDatas)
+#endif
 }
index cbf84de..fa05907 100644 (file)
@@ -1042,11 +1042,6 @@ void WebProcess::gamepadDisconnected(unsigned index)
     WebGamepadProvider::singleton().gamepadDisconnected(index);
 }
 
-void WebProcess::gamepadActivity(const Vector<GamepadData>& gamepadDatas)
-{
-    WebGamepadProvider::singleton().gamepadActivity(gamepadDatas);
-}
-
 #endif
 
 void WebProcess::setJavaScriptGarbageCollectorTimerEnabled(bool flag)
index 8243e9c..137ec57 100644 (file)
@@ -279,7 +279,6 @@ private:
 #if ENABLE(GAMEPAD)
     void gamepadConnected(const GamepadData&);
     void gamepadDisconnected(unsigned index);
-    void gamepadActivity(const Vector<GamepadData>&);
 #endif
 
     void releasePageCache();
index cd5ea81..56810a9 100644 (file)
@@ -105,6 +105,5 @@ messages -> WebProcess LegacyReceiver {
 #if ENABLE(GAMEPAD)
     GamepadConnected(struct WebKit::GamepadData gamepadData)
     GamepadDisconnected(unsigned index)
-    GamepadActivity(Vector<WebKit::GamepadData> gamepadDatas)
 #endif
 }