MEDIA_STREAM should be implemented as a PageSupplement.
authormorrita@google.com <morrita@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Feb 2012 03:56:43 +0000 (03:56 +0000)
committermorrita@google.com <morrita@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Feb 2012 03:56:43 +0000 (03:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79050

Reviewed by Adam Barth.

Source/WebCore:

Added UserMediaController which implements PageSupplement. This
controller mediates WebCore-to-client communication and lifecycle
management. Then pushed UserMediaController out as a
PageSupplement module.

No new tests. No behavior change.

* WebCore.gypi:
* GNUmakefile.list.am:
* mediastream/NavigatorMediaStream.cpp:
(WebCore::NavigatorMediaStream::webkitGetUserMedia):
* mediastream/UserMediaClient.h:
(WebCore):
* mediastream/UserMediaController.cpp: Added.
(WebCore):
(WebCore::UserMediaController::supplementName):
(WebCore::UserMediaController::UserMediaController):
(WebCore::UserMediaController::~UserMediaController):
(WebCore::UserMediaController::create):
(WebCore::provideUserMediaTo):
* mediastream/UserMediaController.h: Added.
(WebCore):
(UserMediaController):
(WebCore::UserMediaController::client):
(WebCore::UserMediaController::from):
(WebCore::UserMediaController::requestUserMedia):
(WebCore::UserMediaController::cancelUserMediaRequest):
* mediastream/UserMediaRequest.cpp:
(WebCore::UserMediaRequest::create):
(WebCore::UserMediaRequest::UserMediaRequest):
(WebCore::UserMediaRequest::didCompleteQuery):
(WebCore::UserMediaRequest::contextDestroyed):
* mediastream/UserMediaRequest.h:
(WebCore):
(UserMediaRequest):
* page/Page.cpp:
(WebCore::Page::Page):
(WebCore::Page::~Page):
(WebCore::Page::PageClients::PageClients):
* page/Page.h:
(WebCore):
(PageClients):
(Page):

Source/WebKit/chromium:

* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::WebViewImpl):

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

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.gypi
Source/WebCore/mediastream/NavigatorMediaStream.cpp
Source/WebCore/mediastream/UserMediaClient.h
Source/WebCore/mediastream/UserMediaController.cpp [new file with mode: 0644]
Source/WebCore/mediastream/UserMediaController.h [new file with mode: 0644]
Source/WebCore/mediastream/UserMediaRequest.cpp
Source/WebCore/mediastream/UserMediaRequest.h
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebViewImpl.cpp

index c4229d4..5e11ea5 100644 (file)
@@ -1,3 +1,54 @@
+2012-02-20  MORITA Hajime  <morrita@google.com>
+
+        MEDIA_STREAM should be implemented as a PageSupplement.
+        https://bugs.webkit.org/show_bug.cgi?id=79050
+
+        Reviewed by Adam Barth.
+
+        Added UserMediaController which implements PageSupplement. This
+        controller mediates WebCore-to-client communication and lifecycle
+        management. Then pushed UserMediaController out as a
+        PageSupplement module.
+
+        No new tests. No behavior change.
+
+        * WebCore.gypi:
+        * GNUmakefile.list.am:
+        * mediastream/NavigatorMediaStream.cpp:
+        (WebCore::NavigatorMediaStream::webkitGetUserMedia):
+        * mediastream/UserMediaClient.h:
+        (WebCore):
+        * mediastream/UserMediaController.cpp: Added.
+        (WebCore):
+        (WebCore::UserMediaController::supplementName):
+        (WebCore::UserMediaController::UserMediaController):
+        (WebCore::UserMediaController::~UserMediaController):
+        (WebCore::UserMediaController::create):
+        (WebCore::provideUserMediaTo):
+        * mediastream/UserMediaController.h: Added.
+        (WebCore):
+        (UserMediaController):
+        (WebCore::UserMediaController::client):
+        (WebCore::UserMediaController::from):
+        (WebCore::UserMediaController::requestUserMedia):
+        (WebCore::UserMediaController::cancelUserMediaRequest):
+        * mediastream/UserMediaRequest.cpp:
+        (WebCore::UserMediaRequest::create):
+        (WebCore::UserMediaRequest::UserMediaRequest):
+        (WebCore::UserMediaRequest::didCompleteQuery):
+        (WebCore::UserMediaRequest::contextDestroyed):
+        * mediastream/UserMediaRequest.h:
+        (WebCore):
+        (UserMediaRequest):
+        * page/Page.cpp:
+        (WebCore::Page::Page):
+        (WebCore::Page::~Page):
+        (WebCore::Page::PageClients::PageClients):
+        * page/Page.h:
+        (WebCore):
+        (PageClients):
+        (Page):
+
 2012-02-21  James Robinson  <jamesr@chromium.org>
 
         Node::isContentEditable should only update styles, not layout
index 7cb6107..38dc0ee 100644 (file)
@@ -2642,6 +2642,8 @@ webcore_sources += \
        Source/WebCore/mediastream/PeerConnection.h \
        Source/WebCore/mediastream/SignalingCallback.h \
        Source/WebCore/mediastream/UserMediaClient.h \
+       Source/WebCore/mediastream/UserMediaController.h \
+       Source/WebCore/mediastream/UserMediaController.cpp \
        Source/WebCore/mediastream/UserMediaRequest.cpp \
        Source/WebCore/mediastream/UserMediaRequest.h \
        Source/WebCore/notifications/NotificationCenter.cpp \
index 5f57c4c..1f316a9 100644 (file)
             'mediastream/PeerConnection.h',
             'mediastream/SignalingCallback.h',
             'mediastream/UserMediaClient.h',
+            'mediastream/UserMediaController.h',
+            'mediastream/UserMediaController.cpp',
             'mediastream/UserMediaRequest.cpp',
             'mediastream/UserMediaRequest.h',
             'notifications/Notification.cpp',
index 2727bf7..204d6e3 100644 (file)
@@ -35,6 +35,7 @@
 #include "NavigatorUserMediaErrorCallback.h"
 #include "NavigatorUserMediaSuccessCallback.h"
 #include "Page.h"
+#include "UserMediaController.h"
 #include "UserMediaRequest.h"
 
 namespace WebCore {
@@ -52,15 +53,13 @@ void NavigatorMediaStream::webkitGetUserMedia(Navigator* navigator, const String
     if (!successCallback)
         return;
 
-    Frame* frame = navigator->frame();
-    if (!frame)
-        return;
-
-    Page* page = frame->page();
-    if (!page)
+    UserMediaController* userMedia = UserMediaController::from(navigator->frame());
+    if (!userMedia) {
+        ec = NOT_SUPPORTED_ERR;
         return;
+    }
 
-    RefPtr<UserMediaRequest> request = UserMediaRequest::create(frame->document(), page->userMediaClient(), options, successCallback, errorCallback);
+    RefPtr<UserMediaRequest> request = UserMediaRequest::create(navigator->frame()->document(), userMedia, options, successCallback, errorCallback);
     if (!request) {
         ec = NOT_SUPPORTED_ERR;
         return;
index c8e2952..744711e 100644 (file)
@@ -38,6 +38,8 @@
 
 namespace WebCore {
 
+class Page;
+
 class UserMediaClient {
 public:
     virtual void pageDestroyed() = 0;
@@ -49,6 +51,8 @@ protected:
     virtual ~UserMediaClient() { }
 };
 
+void provideUserMediaTo(Page*, UserMediaClient*);
+
 } // namespace WebCore
 
 #endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/mediastream/UserMediaController.cpp b/Source/WebCore/mediastream/UserMediaController.cpp
new file mode 100644 (file)
index 0000000..2adbae5
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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:
+ * 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 "UserMediaController.h"
+
+#if ENABLE(MEDIA_STREAM)
+
+namespace WebCore {
+
+const AtomicString& UserMediaController::supplementName()
+{
+    DEFINE_STATIC_LOCAL(AtomicString, name, ("userMediaController"));
+    return name;
+}
+
+UserMediaController::UserMediaController(UserMediaClient* client)
+    : m_client(client)
+{
+}
+
+UserMediaController::~UserMediaController()
+{
+    m_client->pageDestroyed();
+}
+
+PassOwnPtr<UserMediaController> UserMediaController::create(UserMediaClient* client)
+{
+    return adoptPtr(new UserMediaController(client));
+}
+
+void provideUserMediaTo(Page* page, UserMediaClient* client)
+{
+    PageSupplement::provideTo(page, UserMediaController::supplementName(), UserMediaController::create(client));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/mediastream/UserMediaController.h b/Source/WebCore/mediastream/UserMediaController.h
new file mode 100644 (file)
index 0000000..6b0590e
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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:
+ * 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.
+ */
+
+#ifndef UserMediaController_h
+#define UserMediaController_h
+
+#if ENABLE(MEDIA_STREAM)
+
+#include "PageSupplement.h"
+#include "UserMediaClient.h"
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class Frame;
+class Page;
+
+class UserMediaController : public PageSupplement {
+public:
+    ~UserMediaController();
+
+    UserMediaClient* client() const { return m_client; }
+    void requestUserMedia(PassRefPtr<UserMediaRequest>, const MediaStreamSourceVector& audioSources,  const MediaStreamSourceVector& videoSources);
+    void cancelUserMediaRequest(UserMediaRequest*);
+
+    static PassOwnPtr<UserMediaController> create(UserMediaClient*);
+    static const AtomicString& supplementName();
+    static UserMediaController* from(Frame* frame) { return static_cast<UserMediaController*>(PageSupplement::from(frame, supplementName())); }
+    static UserMediaController* from(Page* page) { return static_cast<UserMediaController*>(PageSupplement::from(page, supplementName())); }
+
+protected:
+    UserMediaController(UserMediaClient*);
+
+private:
+    UserMediaClient* m_client;
+};
+
+inline void UserMediaController::requestUserMedia(PassRefPtr<UserMediaRequest> request, const MediaStreamSourceVector& audioSources,  const MediaStreamSourceVector& videoSources)
+{
+    m_client->requestUserMedia(request, audioSources, videoSources);
+}
+
+inline void UserMediaController::cancelUserMediaRequest(UserMediaRequest* request)
+{
+    m_client->cancelUserMediaRequest(request);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
+
+#endif // UserMediaController_h
index faf3d4d..3f3c9ef 100644 (file)
 
 #include "LocalMediaStream.h"
 #include "SpaceSplitString.h"
-#include "UserMediaClient.h"
+#include "UserMediaController.h"
 
 namespace WebCore {
 
-PassRefPtr<UserMediaRequest> UserMediaRequest::create(ScriptExecutionContext* context, UserMediaClient* client, const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback> successCallback, PassRefPtr<NavigatorUserMediaErrorCallback> errorCallback)
+PassRefPtr<UserMediaRequest> UserMediaRequest::create(ScriptExecutionContext* context, UserMediaController* controller, const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback> successCallback, PassRefPtr<NavigatorUserMediaErrorCallback> errorCallback)
 {
-    RefPtr<UserMediaRequest> request = adoptRef(new UserMediaRequest(context, client, options, successCallback, errorCallback));
+    RefPtr<UserMediaRequest> request = adoptRef(new UserMediaRequest(context, controller, options, successCallback, errorCallback));
     if (!request->audio() && !request->video())
         return 0;
 
     return request.release();
 }
 
-UserMediaRequest::UserMediaRequest(ScriptExecutionContext* context, UserMediaClient* client, const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback> successCallback, PassRefPtr<NavigatorUserMediaErrorCallback> errorCallback)
+UserMediaRequest::UserMediaRequest(ScriptExecutionContext* context, UserMediaController* controller, const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback> successCallback, PassRefPtr<NavigatorUserMediaErrorCallback> errorCallback)
     : ContextDestructionObserver(context)
     , m_audio(false)
     , m_video(false)
     , m_cameraPreferenceUser(false)
     , m_cameraPreferenceEnvironment(false)
-    , m_client(client)
+    , m_controller(controller)
     , m_successCallback(successCallback)
     , m_errorCallback(errorCallback)
 {
@@ -73,8 +73,8 @@ void UserMediaRequest::start()
 
 void UserMediaRequest::didCompleteQuery(const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources)
 {
-    if (m_client)
-        m_client->requestUserMedia(this, audioSources, videoSources);
+    if (m_controller)
+        m_controller->requestUserMedia(this, audioSources, videoSources);
 }
 
 void UserMediaRequest::succeed(const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources)
@@ -99,9 +99,9 @@ void UserMediaRequest::fail()
 
 void UserMediaRequest::contextDestroyed()
 {
-    if (m_client) {
-        m_client->cancelUserMediaRequest(this);
-        m_client = 0;
+    if (m_controller) {
+        m_controller->cancelUserMediaRequest(this);
+        m_controller = 0;
     }
 
     ContextDestructionObserver::contextDestroyed();
index a71b5e9..6af31f3 100644 (file)
 
 namespace WebCore {
 
-class UserMediaClient;
+class UserMediaController;
 
 class UserMediaRequest : public MediaStreamSourcesQueryClient, public ContextDestructionObserver {
 public:
-    static PassRefPtr<UserMediaRequest> create(ScriptExecutionContext*, UserMediaClient*, const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback>, PassRefPtr<NavigatorUserMediaErrorCallback>);
+    static PassRefPtr<UserMediaRequest> create(ScriptExecutionContext*, UserMediaController*, const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback>, PassRefPtr<NavigatorUserMediaErrorCallback>);
     ~UserMediaRequest();
 
     NavigatorUserMediaSuccessCallback* successCallback() const { return m_successCallback.get(); }
@@ -70,7 +70,7 @@ public:
     virtual void contextDestroyed();
 
 private:
-    UserMediaRequest(ScriptExecutionContext*, UserMediaClient*, const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback>, PassRefPtr<NavigatorUserMediaErrorCallback>);
+    UserMediaRequest(ScriptExecutionContext*, UserMediaController*, const String& options, PassRefPtr<NavigatorUserMediaSuccessCallback>, PassRefPtr<NavigatorUserMediaErrorCallback>);
 
     void parseOptions(const String& options);
 
@@ -80,7 +80,7 @@ private:
     bool m_cameraPreferenceUser;
     bool m_cameraPreferenceEnvironment;
 
-    UserMediaClient* m_client;
+    UserMediaController* m_controller;
 
     RefPtr<NavigatorUserMediaSuccessCallback> m_successCallback;
     RefPtr<NavigatorUserMediaErrorCallback> m_errorCallback;
index ab9ef66..ffd1b0e 100644 (file)
 #include "GeolocationController.h"
 #endif
 
-#if ENABLE(MEDIA_STREAM)
-#include "UserMediaClient.h"
-#endif
-
 namespace WebCore {
 
 static HashSet<Page*>* allPages;
@@ -144,9 +140,6 @@ Page::Page(PageClients& pageClients)
 #if ENABLE(INPUT_SPEECH)
     , m_speechInputClient(pageClients.speechInputClient)
 #endif
-#if ENABLE(MEDIA_STREAM)
-    , m_userMediaClient(pageClients.userMediaClient)
-#endif
     , m_settings(Settings::create(this))
     , m_progress(ProgressTracker::create())
     , m_backForwardController(BackForwardController::create(this, pageClients.backForwardClient))
@@ -208,11 +201,6 @@ Page::~Page()
     m_inspectorController->inspectedPageDestroyed();
 #endif
 
-#if ENABLE(MEDIA_STREAM)
-    if (m_userMediaClient)
-        m_userMediaClient->pageDestroyed();
-#endif
-
     if (m_scrollingCoordinator)
         m_scrollingCoordinator->pageDestroyed();
 
@@ -1098,7 +1086,6 @@ Page::PageClients::PageClients()
     , geolocationClient(0)
     , speechInputClient(0)
     , notificationClient(0)
-    , userMediaClient(0)
 {
 }
 
index 090b42c..4b75806 100644 (file)
@@ -85,7 +85,6 @@ namespace WebCore {
     class Settings;
     class SpeechInput;
     class SpeechInputClient;
-    class UserMediaClient;
     class StorageNamespace;
 #if ENABLE(NOTIFICATIONS)
     class NotificationPresenter;
@@ -119,7 +118,6 @@ namespace WebCore {
             RefPtr<BackForwardList> backForwardClient;
             SpeechInputClient* speechInputClient;
             NotificationPresenter* notificationClient;
-            UserMediaClient* userMediaClient;
         };
 
         Page(PageClients&);
@@ -189,9 +187,6 @@ namespace WebCore {
 #if ENABLE(INPUT_SPEECH)
         SpeechInput* speechInput();
 #endif
-#if ENABLE(MEDIA_STREAM)
-        UserMediaClient* userMediaClient() const { return m_userMediaClient; }
-#endif
         ScrollingCoordinator* scrollingCoordinator();
 
         Settings* settings() const { return m_settings.get(); }
@@ -389,9 +384,6 @@ namespace WebCore {
         SpeechInputClient* m_speechInputClient;
         OwnPtr<SpeechInput> m_speechInput;
 #endif
-#if ENABLE(MEDIA_STREAM)
-        UserMediaClient* m_userMediaClient;
-#endif
         RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
 
         OwnPtr<Settings> m_settings;
index 78af4f6..295cdba 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-20  MORITA Hajime  <morrita@google.com>
+
+        MEDIA_STREAM should be implemented as a PageSupplement.
+        https://bugs.webkit.org/show_bug.cgi?id=79050
+
+        Reviewed by Adam Barth.
+
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::WebViewImpl):
+
 2012-02-21  Dana Jansens  <danakj@chromium.org>
 
         [chromium] Painting a layer clears opaque rect in untouched tiles
index 80a1d96..cfdc195 100644 (file)
@@ -405,11 +405,11 @@ WebViewImpl::WebViewImpl(WebViewClient* client)
     pageClients.notificationClient = notificationPresenterImpl();
 #endif
     pageClients.backForwardClient = BackForwardListChromium::create(this);
-#if ENABLE(MEDIA_STREAM)
-    pageClients.userMediaClient = &m_userMediaClientImpl;
-#endif
 
     m_page = adoptPtr(new Page(pageClients));
+#if ENABLE(MEDIA_STREAM)
+    provideUserMediaTo(m_page.get(), &m_userMediaClientImpl);
+#endif
     provideDeviceOrientationTo(m_page.get(), m_deviceOrientationClientProxy.get());
     m_geolocationClientProxy->setController(m_page->geolocationController());