Move ENABLE(GAMEPAD) logic out of Navigator.h/cpp
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Feb 2012 07:03:16 +0000 (07:03 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Feb 2012 07:03:16 +0000 (07:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78457

Reviewed by Hajime Morita.

This patch moves GAMEPAD-specific logic out of Navigator by introducing
the concept of a NavigatorSupplement, analogous to the recently
introduced PageSupplement.

* Modules/gamepad/NavigatorGamepad.cpp:
(WebCore::NavigatorGamepad::from):
(WebCore):
(WebCore::NavigatorGamepad::webkitGamepads):
(WebCore::NavigatorGamepad::gamepads):
* Modules/gamepad/NavigatorGamepad.h:
(NavigatorGamepad):
* WebCore.gypi:
* dom/DeviceMotionController.cpp:
(WebCore::DeviceMotionController::supplementName):
* page/Navigator.cpp:
(WebCore::Navigator::provideSupplement):
(WebCore):
(WebCore::Navigator::requireSupplement):
* page/Navigator.h:
(Navigator):
* page/Page.h:
(Page):
* page/PageSupplement.h:
    - This patch cleans up some nits in PageSupplement.
(WebCore):
(PageSupplement):

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

16 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Modules/gamepad/NavigatorGamepad.cpp
Source/WebCore/Modules/gamepad/NavigatorGamepad.h
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/DeviceMotionController.cpp
Source/WebCore/page/Navigator.cpp
Source/WebCore/page/Navigator.h
Source/WebCore/page/NavigatorSupplement.cpp [new file with mode: 0644]
Source/WebCore/page/NavigatorSupplement.h [new file with mode: 0644]
Source/WebCore/page/Page.h
Source/WebCore/page/PageSupplement.h

index a7f90f1..d77667b 100644 (file)
@@ -1020,6 +1020,7 @@ SET(WebCore_SOURCES
     page/MouseEventWithHitTestResults.cpp
     page/Navigator.cpp
     page/NavigatorBase.cpp
+    page/NavigatorSupplement.cpp
     page/OriginAccessEntry.cpp
     page/Page.cpp
     page/PageGroup.cpp
index 37d95b6..a38e52d 100644 (file)
@@ -1,3 +1,37 @@
+2012-02-12  Adam Barth  <abarth@webkit.org>
+
+        Move ENABLE(GAMEPAD) logic out of Navigator.h/cpp
+        https://bugs.webkit.org/show_bug.cgi?id=78457
+
+        Reviewed by Hajime Morita.
+
+        This patch moves GAMEPAD-specific logic out of Navigator by introducing
+        the concept of a NavigatorSupplement, analogous to the recently
+        introduced PageSupplement.
+
+        * Modules/gamepad/NavigatorGamepad.cpp:
+        (WebCore::NavigatorGamepad::from):
+        (WebCore):
+        (WebCore::NavigatorGamepad::webkitGamepads):
+        (WebCore::NavigatorGamepad::gamepads):
+        * Modules/gamepad/NavigatorGamepad.h:
+        (NavigatorGamepad):
+        * WebCore.gypi:
+        * dom/DeviceMotionController.cpp:
+        (WebCore::DeviceMotionController::supplementName):
+        * page/Navigator.cpp:
+        (WebCore::Navigator::provideSupplement):
+        (WebCore):
+        (WebCore::Navigator::requireSupplement):
+        * page/Navigator.h:
+        (Navigator):
+        * page/Page.h:
+        (Page):
+        * page/PageSupplement.h:
+            - This patch cleans up some nits in PageSupplement.
+        (WebCore):
+        (PageSupplement):
+
 2012-02-12  Kentaro Hara  <haraken@chromium.org>
 
         Add a [V8CustomToJSObject] IDL attribute
index 7a27e6a..809df88 100644 (file)
@@ -2722,6 +2722,8 @@ webcore_sources += \
        Source/WebCore/page/Navigator.h \
        Source/WebCore/page/NavigatorBase.cpp \
        Source/WebCore/page/NavigatorBase.h \
+       Source/WebCore/page/NavigatorSupplement.cpp \
+       Source/WebCore/page/NavigatorSupplement.h \
        Source/WebCore/page/OriginAccessEntry.cpp \
        Source/WebCore/page/OriginAccessEntry.h \
        Source/WebCore/page/Page.cpp \
index 4d1d933..95cd602 100644 (file)
 
 #if ENABLE(GAMEPAD)
 
+#include "GamepadList.h"
+#include "Gamepads.h"
 #include "Navigator.h"
+#include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
@@ -40,10 +43,28 @@ NavigatorGamepad::~NavigatorGamepad()
 {
 }
 
+NavigatorGamepad* NavigatorGamepad::from(Navigator* navigator)
+{
+    DEFINE_STATIC_LOCAL(AtomicString, name, ("NavigatorGamepad"));
+    NavigatorGamepad* supplement = static_cast<NavigatorGamepad*>(NavigatorSupplement::from(navigator, name));
+    if (!supplement) {
+        supplement = new NavigatorGamepad();
+        provideTo(navigator, name, adoptPtr(supplement));
+    }
+    return supplement;
+}
+
 GamepadList* NavigatorGamepad::webkitGamepads(Navigator* navigator)
 {
-    // FIXME: We shouldn't need to direct this call to Navigator.
-    return navigator->gamepads();
+    return NavigatorGamepad::from(navigator)->gamepads();
+}
+
+GamepadList* NavigatorGamepad::gamepads()
+{
+    if (!m_gamepads)
+        m_gamepads = GamepadList::create();
+    sampleGamepads(m_gamepads.get());
+    return m_gamepads.get();
 }
 
 } // namespace WebCore
index 2dc125a..0ab51b5 100644 (file)
 
 #if ENABLE(GAMEPAD)
 
+#include "NavigatorSupplement.h"
+
 namespace WebCore {
 
 class GamepadList;
 class Navigator;
 
-class NavigatorGamepad {
+class NavigatorGamepad : public NavigatorSupplement {
 public:
+    virtual ~NavigatorGamepad();
+    static NavigatorGamepad* from(Navigator*);
+
     static GamepadList* webkitGamepads(Navigator*);
 
+    GamepadList* gamepads();
+
 private:
     NavigatorGamepad();
-    ~NavigatorGamepad();
+
+    RefPtr<GamepadList> m_gamepads;
 };
 
 } // namespace WebCore
index ff60ac3..7257c56 100644 (file)
@@ -997,6 +997,7 @@ SOURCES += \
     page/MouseEventWithHitTestResults.cpp \
     page/Navigator.cpp \
     page/NavigatorBase.cpp \
+    page/NavigatorSupplement.cpp \
     page/OriginAccessEntry.cpp \
     page/Page.cpp \
     page/PageGroup.cpp \
index 009cc45..8660619 100644 (file)
             'page/Navigator.h',
             'page/NavigatorBase.cpp',
             'page/NavigatorBase.h',
+            'page/NavigatorSupplement.cpp',
+            'page/NavigatorSupplement.h',
             'page/OriginAccessEntry.cpp',
             'page/OriginAccessEntry.h',
             'page/Page.cpp',
index 50e00ff..232b233 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\page\NavigatorSupplement.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\page\NavigatorSupplement.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\page\OriginAccessEntry.cpp"
                                >
                        </File>
index ef6fb01..8fe11e1 100644 (file)
                97C078501165D5BE003A32EF /* SuffixTree.h in Headers */ = {isa = PBXBuildFile; fileRef = 97C0784F1165D5BE003A32EF /* SuffixTree.h */; };
                97C471DB12F925BD0086354B /* ContentSecurityPolicy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97C471D912F925BC0086354B /* ContentSecurityPolicy.cpp */; };
                97C471DC12F925BD0086354B /* ContentSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 97C471DA12F925BD0086354B /* ContentSecurityPolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               97CC3AE214E8E4A200894988 /* NavigatorSupplement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97CC3AE014E8E4A200894988 /* NavigatorSupplement.cpp */; };
+               97CC3AE314E8E4A200894988 /* NavigatorSupplement.h in Headers */ = {isa = PBXBuildFile; fileRef = 97CC3AE114E8E4A200894988 /* NavigatorSupplement.h */; settings = {ATTRIBUTES = (Private, ); }; };
                97D2AD0314B823A60093DF32 /* DOMWindowProperty.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97D2AD0114B823A60093DF32 /* DOMWindowProperty.cpp */; };
                97D2AD0414B823A60093DF32 /* DOMWindowProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 97D2AD0214B823A60093DF32 /* DOMWindowProperty.h */; settings = {ATTRIBUTES = (Private, ); }; };
                97DCE20110807C750057D394 /* HistoryController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97DCE1FF10807C750057D394 /* HistoryController.cpp */; };
                97C1F552122855CB00EDE616 /* HTMLToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HTMLToken.h; path = parser/HTMLToken.h; sourceTree = "<group>"; };
                97C471D912F925BC0086354B /* ContentSecurityPolicy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentSecurityPolicy.cpp; sourceTree = "<group>"; };
                97C471DA12F925BD0086354B /* ContentSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentSecurityPolicy.h; sourceTree = "<group>"; };
+               97CC3AE014E8E4A200894988 /* NavigatorSupplement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NavigatorSupplement.cpp; sourceTree = "<group>"; };
+               97CC3AE114E8E4A200894988 /* NavigatorSupplement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigatorSupplement.h; sourceTree = "<group>"; };
                97D2AD0114B823A60093DF32 /* DOMWindowProperty.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMWindowProperty.cpp; sourceTree = "<group>"; };
                97D2AD0214B823A60093DF32 /* DOMWindowProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMWindowProperty.h; sourceTree = "<group>"; };
                97DCE1FF10807C750057D394 /* HistoryController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HistoryController.cpp; sourceTree = "<group>"; };
                                A9C6E65D0D746694006442E9 /* Navigator.idl */,
                                E12719C90EEEC21300F61213 /* NavigatorBase.cpp */,
                                E12719C60EEEC16800F61213 /* NavigatorBase.h */,
+                               97CC3AE014E8E4A200894988 /* NavigatorSupplement.cpp */,
+                               97CC3AE114E8E4A200894988 /* NavigatorSupplement.h */,
                                00146288103CD1DE000B20DB /* OriginAccessEntry.cpp */,
                                00146289103CD1DE000B20DB /* OriginAccessEntry.h */,
                                65FEA86809833ADE00BED4AB /* Page.cpp */,
                                4A957F0714E241300049DBFB /* WebSocketExtensionDispatcher.h in Headers */,
                                4ADE25FA14E3BB4C004C2213 /* WebSocketExtensionProcessor.h in Headers */,
                                572E92FC14E540580087FFBA /* ShadowRootList.h in Headers */,
+                               97CC3AE314E8E4A200894988 /* NavigatorSupplement.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                7A54881814E432A1006AE05A /* DOMPatchSupport.cpp in Sources */,
                                4A957F0614E2412A0049DBFB /* WebSocketExtensionDispatcher.cpp in Sources */,
                                572E92FB14E540580087FFBA /* ShadowRootList.cpp in Sources */,
+                               97CC3AE214E8E4A200894988 /* NavigatorSupplement.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index aceec02..79eacc5 100644 (file)
@@ -137,7 +137,7 @@ void DeviceMotionController::didChangeDeviceMotion(DeviceMotionData* deviceMotio
 
 const AtomicString& DeviceMotionController::supplementName()
 {
-    DEFINE_STATIC_LOCAL(AtomicString, name, ("deviceMotion"));
+    DEFINE_STATIC_LOCAL(AtomicString, name, ("DeviceMotionController"));
     return name;
 }
 
index b394cd8..a4a7a3d 100644 (file)
 #include <wtf/HashSet.h>
 #include <wtf/StdLibExtras.h>
 
-#if ENABLE(GAMEPAD)
-#include "GamepadList.h"
-#include "Gamepads.h"
-#endif
-
 #if ENABLE(MEDIA_STREAM)
 #include "NavigatorUserMediaErrorCallback.h"
 #include "NavigatorUserMediaSuccessCallback.h"
@@ -67,6 +62,17 @@ Navigator::~Navigator()
 {
 }
 
+void Navigator::provideSupplement(const AtomicString& name, PassOwnPtr<NavigatorSupplement> supplement)
+{
+    ASSERT(!m_suppliments.get(name.impl()));
+    m_suppliments.set(name.impl(), supplement);
+}
+
+NavigatorSupplement* Navigator::requireSupplement(const AtomicString& name)
+{
+    return m_suppliments.get(name.impl());
+}
+
 void Navigator::resetGeolocation()
 {
     if (m_geolocation)
@@ -291,14 +297,4 @@ void Navigator::webkitGetUserMedia(const String& options, PassRefPtr<NavigatorUs
 }
 #endif
 
-#if ENABLE(GAMEPAD)
-GamepadList* Navigator::gamepads()
-{
-    if (!m_gamepads)
-        m_gamepads = GamepadList::create();
-    sampleGamepads(m_gamepads.get());
-    return m_gamepads.get();
-}
-#endif
-
 } // namespace WebCore
index 07c9d2b..476d96b 100644 (file)
@@ -22,7 +22,9 @@
 
 #include "DOMWindowProperty.h"
 #include "NavigatorBase.h"
+#include "NavigatorSupplement.h"
 #include <wtf/Forward.h>
+#include <wtf/HashMap.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -74,21 +76,18 @@ public:
     virtual void webkitGetUserMedia(const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback>, PassRefPtr<NavigatorUserMediaErrorCallback>, ExceptionCode&);
 #endif
 
-#if ENABLE(GAMEPAD)
-    // FIXME: This method should be in WebCore/Modules/gamepad.
-    GamepadList* gamepads();
-#endif
+    void provideSupplement(const AtomicString&, PassOwnPtr<NavigatorSupplement>);
+    NavigatorSupplement* requireSupplement(const AtomicString&);
 
 private:
     explicit Navigator(Frame*);
 
+    typedef HashMap<AtomicStringImpl*, OwnPtr<NavigatorSupplement> > NavigatorSupplementMap;
+    NavigatorSupplementMap m_suppliments;
+
     mutable RefPtr<DOMPluginArray> m_plugins;
     mutable RefPtr<DOMMimeTypeArray> m_mimeTypes;
     mutable RefPtr<Geolocation> m_geolocation;
-#if ENABLE(GAMEPAD)
-    // FIXME: This state should be in WebCore/Modules/gamepad.
-    mutable RefPtr<GamepadList> m_gamepads;
-#endif
 #if ENABLE(POINTER_LOCK)
     mutable RefPtr<PointerLock> m_pointer;
 #endif
diff --git a/Source/WebCore/page/NavigatorSupplement.cpp b/Source/WebCore/page/NavigatorSupplement.cpp
new file mode 100644 (file)
index 0000000..bb424d4
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2012 Google 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:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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 THE COPYRIGHT HOLDERS ``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 THE COPYRIGHT OWNER 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 "NavigatorSupplement.h"
+
+#include "Navigator.h"
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+NavigatorSupplement::~NavigatorSupplement()
+{
+}
+
+void NavigatorSupplement::provideTo(Navigator* navigator, const AtomicString& key, PassOwnPtr<NavigatorSupplement> supplement)
+{
+    navigator->provideSupplement(key, supplement);
+}
+
+NavigatorSupplement* NavigatorSupplement::from(Navigator* navigator, const AtomicString& name)
+{
+    if (!navigator)
+        return 0;
+    return navigator->requireSupplement(name);
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/page/NavigatorSupplement.h b/Source/WebCore/page/NavigatorSupplement.h
new file mode 100644 (file)
index 0000000..fc958fd
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 Google 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:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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 THE COPYRIGHT HOLDERS ``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 THE COPYRIGHT OWNER 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.
+ */
+
+#ifndef NavigatorSupplement_h
+#define NavigatorSupplement_h
+
+#include <wtf/Forward.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/text/AtomicString.h>
+
+namespace WebCore {
+
+class Navigator;
+
+class NavigatorSupplement {
+public:
+    virtual ~NavigatorSupplement();
+
+    static void provideTo(Navigator*, const AtomicString&, PassOwnPtr<NavigatorSupplement>);
+    static NavigatorSupplement* from(Navigator*, const AtomicString&);
+};
+
+} // namespace WebCore
+
+#endif // NavigatorSupplement_h
index 066fc4d..781ff05 100644 (file)
@@ -350,7 +350,6 @@ namespace WebCore {
 
     private:
         void initGroup();
-        void notifyDestroyedToSupplements();
 
         typedef HashMap<AtomicStringImpl*, OwnPtr<PageSupplement> > PageSupplementMap;
         PageSupplementMap m_suppliments;
index 967f8e7..e1b48aa 100644 (file)
@@ -36,7 +36,6 @@ namespace WebCore {
 class Page;
 class Frame;
 
-
 class PageSupplement {
 public:
     virtual ~PageSupplement();
@@ -44,8 +43,6 @@ public:
     static void provideTo(Page*, const AtomicString&, PassOwnPtr<PageSupplement>);
     static PageSupplement* from(Page*, const AtomicString&);
     static PageSupplement* from(Frame*, const AtomicString&);
-private:
-    OwnPtr<PageSupplement> m_self;
 };
 
 } // namespace WebCore