From 889ac174c8bbb099096bd12c044ecb05ca3794ff Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Sat, 22 Dec 2012 03:09:36 -0500 Subject: [PATCH] Bug 799417: Backend support for list of documents that have active gUM MediaStreams r=derf --- dom/media/Makefile.in | 1 + dom/media/MediaManager.cpp | 47 +++++++++++++++++++++++++++++++-- dom/media/MediaManager.h | 10 +++++-- dom/media/nsIMediaManager.idl | 18 +++++++++++++ layout/build/Makefile.in | 1 + layout/build/nsLayoutModule.cpp | 7 +++++ 6 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 dom/media/nsIMediaManager.idl diff --git a/dom/media/Makefile.in b/dom/media/Makefile.in index 9accd09faf04..3f8f0a8d4093 100644 --- a/dom/media/Makefile.in +++ b/dom/media/Makefile.in @@ -28,6 +28,7 @@ XPIDLSRCS = \ nsIDOMMediaStream.idl \ nsIDOMRTCPeerConnection.idl \ nsIDOMNavigatorUserMedia.idl \ + nsIMediaManager.idl \ $(NULL) EXPORTS_NAMESPACE = mozilla diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 79a2c3782079..6053b23a5897 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -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 mError; }; -nsRefPtr MediaManager::sSingleton; +NS_IMPL_THREADSAFE_ISUPPORTS2(MediaManager, nsIMediaManagerService, nsIObserver) -NS_IMPL_THREADSAFE_ISUPPORTS1(MediaManager, nsIObserver) +/* static */ StaticRefPtr MediaManager::sSingleton; + +/* static */ already_AddRefed +MediaManager::GetInstance() +{ + // so we can have non-refcounted getters + nsRefPtr 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(userArg); + nsPIDOMWindow *window = static_cast + (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 diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index 7e1a54a912e0..3139564e423a 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -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 mSource; }; -class MediaManager MOZ_FINAL : public nsIObserver +class MediaManager MOZ_FINAL : public nsIMediaManagerService, + public nsIObserver { public: + static already_AddRefed 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 sSingleton; + static StaticRefPtr sSingleton; }; } // namespace mozilla diff --git a/dom/media/nsIMediaManager.idl b/dom/media/nsIMediaManager.idl new file mode 100644 index 000000000000..75c4bb0b83ad --- /dev/null +++ b/dom/media/nsIMediaManager.idl @@ -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; +}; diff --git a/layout/build/Makefile.in b/layout/build/Makefile.in index 173bb128e8ec..6d9506d0b43c 100644 --- a/layout/build/Makefile.in +++ b/layout/build/Makefile.in @@ -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 \ diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 0f57fbda31ac..2159e9020816 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -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 } };