Bug 799417: Backend support for list of documents that have active gUM MediaStreams r=derf

This commit is contained in:
Randell Jesup 2012-12-22 03:09:36 -05:00
parent e0f74b0102
commit 889ac174c8
6 changed files with 80 additions and 4 deletions

View File

@ -28,6 +28,7 @@ XPIDLSRCS = \
nsIDOMMediaStream.idl \
nsIDOMRTCPeerConnection.idl \
nsIDOMNavigatorUserMedia.idl \
nsIMediaManager.idl \
$(NULL)
EXPORTS_NAMESPACE = mozilla

View File

@ -10,6 +10,7 @@
#include "nsIUUIDGenerator.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPopupWindowManager.h"
#include "nsISupportsArray.h"
// For PR_snprintf
#include "prprf.h"
@ -690,9 +691,17 @@ private:
already_AddRefed<nsIDOMGetUserMediaErrorCallback> mError;
};
nsRefPtr<MediaManager> MediaManager::sSingleton;
NS_IMPL_THREADSAFE_ISUPPORTS2(MediaManager, nsIMediaManagerService, nsIObserver)
NS_IMPL_THREADSAFE_ISUPPORTS1(MediaManager, nsIObserver)
/* static */ StaticRefPtr<MediaManager> MediaManager::sSingleton;
/* static */ already_AddRefed<MediaManager>
MediaManager::GetInstance()
{
// so we can have non-refcounted getters
nsRefPtr<MediaManager> service = MediaManager::Get();
return service.forget();
}
/**
* The entry point for this file. A call from Navigator::mozGetUserMedia
@ -1050,4 +1059,38 @@ MediaManager::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
static PLDHashOperator
WindowsHashToArrayFunc (const uint64_t& aId,
StreamListeners* aData,
void *userArg)
{
nsISupportsArray *array =
static_cast<nsISupportsArray *>(userArg);
nsPIDOMWindow *window = static_cast<nsPIDOMWindow*>
(nsGlobalWindow::GetInnerWindowWithId(aId));
(void) aData;
MOZ_ASSERT(window);
if (window) {
array->AppendElement(window);
}
return PL_DHASH_NEXT;
}
nsresult
MediaManager::GetActiveMediaCaptureWindows(nsISupportsArray **aArray)
{
MOZ_ASSERT(aArray);
nsISupportsArray *array;
nsresult rv = NS_NewISupportsArray(&array); // AddRefs
if (NS_FAILED(rv))
return rv;
mActiveWindows.EnumerateRead(WindowsHashToArrayFunc, array);
*aArray = array;
return NS_OK;
}
} // namespace mozilla

View File

@ -4,6 +4,7 @@
#include "MediaEngine.h"
#include "mozilla/Services.h"
#include "nsIMediaManager.h"
#include "nsHashKeys.h"
#include "nsGlobalWindow.h"
@ -14,6 +15,7 @@
#include "nsPIDOMWindow.h"
#include "nsIDOMNavigatorUserMedia.h"
#include "mozilla/Attributes.h"
#include "mozilla/StaticPtr.h"
#include "prlog.h"
namespace mozilla {
@ -272,9 +274,12 @@ private:
nsRefPtr<MediaEngineSource> mSource;
};
class MediaManager MOZ_FINAL : public nsIObserver
class MediaManager MOZ_FINAL : public nsIMediaManagerService,
public nsIObserver
{
public:
static already_AddRefed<MediaManager> GetInstance();
static MediaManager* Get() {
if (!sSingleton) {
sSingleton = new MediaManager();
@ -296,6 +301,7 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSIMEDIAMANAGERSERVICE
MediaEngine* GetBackend();
StreamListeners *GetWindowListeners(uint64_t aWindowId) {
@ -345,7 +351,7 @@ private:
// protected with mMutex:
MediaEngine* mBackend;
static nsRefPtr<MediaManager> sSingleton;
static StaticRefPtr<MediaManager> sSingleton;
};
} // namespace mozilla

View File

@ -0,0 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface nsISupportsArray;
%{C++
#define NS_MEDIAMANAGERSERVICE_CID {0xabc622ea, 0x9655, 0x4123, {0x80, 0xd9, 0x22, 0x62, 0x1b, 0xdd, 0x54, 0x65}}
#define MEDIAMANAGERSERVICE_CONTRACTID "@mozilla.org/mediaManagerService;1"
%}
[scriptable, builtinclass, uuid(afe82ff1-2caa-4304-85da-0158a5dee56b)]
interface nsIMediaManagerService : nsISupports
{
readonly attribute nsISupportsArray activeMediaCaptureWindows;
};

View File

@ -302,6 +302,7 @@ LOCAL_INCLUDES += -I$(srcdir)/../base \
-I$(topsrcdir)/dom/settings \
-I$(topsrcdir)/dom/permission \
-I$(topsrcdir)/dom/telephony \
-I$(topsrcdir)/dom/media \
-I. \
-I$(topsrcdir)/editor/libeditor/base \
-I$(topsrcdir)/editor/libeditor/text \

View File

@ -233,6 +233,7 @@ static void Shutdown();
#include "mozilla/dom/sms/SmsServicesFactory.h"
#include "nsIPowerManagerService.h"
#include "nsIAlarmHalService.h"
#include "nsIMediaManager.h"
#include "nsMixedContentBlocker.h"
#include "AudioChannelService.h"
@ -244,6 +245,7 @@ static void Shutdown();
#ifdef MOZ_WIDGET_GONK
#include "GonkGPSGeolocationProvider.h"
#endif
#include "MediaManager.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -326,6 +328,8 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsITimeService,
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIGeolocationProvider,
GonkGPSGeolocationProvider::GetSingleton)
#endif
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMediaManagerService,
MediaManager::GetInstance)
//-----------------------------------------------------------------------------
@ -840,6 +844,7 @@ NS_DEFINE_NAMED_CID(NS_TIMESERVICE_CID);
#ifdef MOZ_WIDGET_GONK
NS_DEFINE_NAMED_CID(GONK_GPS_GEOLOCATION_PROVIDER_CID);
#endif
NS_DEFINE_NAMED_CID(NS_MEDIAMANAGERSERVICE_CID);
static nsresult
CreateWindowCommandTableConstructor(nsISupports *aOuter,
@ -1119,6 +1124,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
#ifdef MOZ_WIDGET_GONK
{ &kGONK_GPS_GEOLOCATION_PROVIDER_CID, false, NULL, nsIGeolocationProviderConstructor },
#endif
{ &kNS_MEDIAMANAGERSERVICE_CID, false, NULL, nsIMediaManagerServiceConstructor },
{ NULL }
};
@ -1262,6 +1268,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
#ifdef MOZ_WIDGET_GONK
{ GONK_GPS_GEOLOCATION_PROVIDER_CONTRACTID, &kGONK_GPS_GEOLOCATION_PROVIDER_CID },
#endif
{ MEDIAMANAGERSERVICE_CONTRACTID, &kNS_MEDIAMANAGERSERVICE_CID },
{ NULL }
};