Bug 838146 part 7. Implement the MOZ_MEDIA_NAVIGATOR WebIDL APIs on Navigator. r=smaug, sr=sicking
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 12 Jul 2013 10:37:21 -0400
changeset 150920 97c9600b2f9de5be8843fa50ceb038677fed4d70
parent 150919 8fcca099a7c3f9ab6ec40240449009c781fa2a9b
child 150921 325c7efdbcf5b62100428e9bfa35e1d0de9d183d
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, sicking
bugs838146
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 838146 part 7. Implement the MOZ_MEDIA_NAVIGATOR WebIDL APIs on Navigator. r=smaug, sr=sicking
dom/base/Navigator.cpp
dom/base/Navigator.h
dom/bindings/Bindings.conf
dom/webidl/Navigator.webidl
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1222,47 +1222,109 @@ Navigator::MozGetUserMedia(nsIMediaStrea
                            nsIDOMGetUserMediaErrorCallback* aOnError)
 {
   // Make enabling peerconnection enable getUserMedia() as well
   if (!(Preferences::GetBool("media.navigator.enabled", false) ||
         Preferences::GetBool("media.peerconnection.enabled", false))) {
     return NS_OK;
   }
 
+  ErrorResult rv;
+  MozGetUserMedia(aParams, aOnSuccess, aOnError, rv);
+  return rv.ErrorCode();
+}
+
+void
+Navigator::MozGetUserMedia(nsIMediaStreamOptions* aParams,
+                           MozDOMGetUserMediaSuccessCallback* aOnSuccess,
+                           MozDOMGetUserMediaErrorCallback* aOnError,
+                           ErrorResult& aRv)
+{
+  CallbackObjectHolder<MozDOMGetUserMediaSuccessCallback,
+                       nsIDOMGetUserMediaSuccessCallback> holder1(aOnSuccess);
+  nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> onsucces =
+    holder1.ToXPCOMCallback();
+
+  CallbackObjectHolder<MozDOMGetUserMediaErrorCallback,
+                       nsIDOMGetUserMediaErrorCallback> holder2(aOnError);
+  nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onerror = holder2.ToXPCOMCallback();
+
+  MozGetUserMedia(aParams, onsucces, onerror, aRv);
+}
+
+void
+Navigator::MozGetUserMedia(nsIMediaStreamOptions* aParams,
+                           nsIDOMGetUserMediaSuccessCallback* aOnSuccess,
+                           nsIDOMGetUserMediaErrorCallback* aOnError,
+                           ErrorResult& aRv)
+{
+  // Callers (either the XPCOM method or the WebIDL binding) are responsible for
+  // the pref check here.
   if (!mWindow || !mWindow->GetOuterWindow() ||
       mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
-    return NS_ERROR_NOT_AVAILABLE;
+    aRv.Throw(NS_ERROR_NOT_AVAILABLE);
+    return;
   }
 
   bool privileged = nsContentUtils::IsChromeDoc(mWindow->GetExtantDoc());
 
   MediaManager* manager = MediaManager::Get();
-  return manager->GetUserMedia(privileged, mWindow, aParams, aOnSuccess,
-                               aOnError);
+  aRv = manager->GetUserMedia(privileged, mWindow, aParams, aOnSuccess,
+                              aOnError);
 }
 
 //*****************************************************************************
 //    Navigator::nsINavigatorUserMedia (mozGetUserMediaDevices)
 //*****************************************************************************
 NS_IMETHODIMP
 Navigator::MozGetUserMediaDevices(nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
                                   nsIDOMGetUserMediaErrorCallback* aOnError)
 {
-  if (!mWindow || !mWindow->GetOuterWindow() ||
-      mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
-    return NS_ERROR_NOT_AVAILABLE;
-  }
-
   // Check if the caller is chrome privileged, bail if not
   if (!nsContentUtils::IsCallerChrome()) {
     return NS_ERROR_FAILURE;
   }
 
+  ErrorResult rv;
+  MozGetUserMediaDevices(aOnSuccess, aOnError, rv);
+  return rv.ErrorCode();
+}
+
+void
+Navigator::MozGetUserMediaDevices(MozGetUserMediaDevicesSuccessCallback* aOnSuccess,
+                                  MozDOMGetUserMediaErrorCallback* aOnError,
+                                  ErrorResult& aRv)
+{
+  CallbackObjectHolder<MozGetUserMediaDevicesSuccessCallback,
+                       nsIGetUserMediaDevicesSuccessCallback> holder1(aOnSuccess);
+  nsCOMPtr<nsIGetUserMediaDevicesSuccessCallback> onsucces =
+    holder1.ToXPCOMCallback();
+
+  CallbackObjectHolder<MozDOMGetUserMediaErrorCallback,
+                       nsIDOMGetUserMediaErrorCallback> holder2(aOnError);
+  nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onerror = holder2.ToXPCOMCallback();
+
+  MozGetUserMediaDevices(onsucces, onerror, aRv);
+}
+
+void
+Navigator::MozGetUserMediaDevices(nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
+                                  nsIDOMGetUserMediaErrorCallback* aOnError,
+                                  ErrorResult& aRv)
+{
+  // Callers (either the XPCOM method or the WebIDL binding) are responsible for
+  // the chromeonly check here.
+  if (!mWindow || !mWindow->GetOuterWindow() ||
+      mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
+    aRv.Throw(NS_ERROR_NOT_AVAILABLE);
+    return;
+  }
+
   MediaManager* manager = MediaManager::Get();
-  return manager->GetUserMediaDevices(mWindow, aOnSuccess, aOnError);
+  aRv = manager->GetUserMediaDevices(mWindow, aOnSuccess, aOnError);
 }
 #endif
 
 //*****************************************************************************
 //    Navigator::nsIDOMNavigatorDesktopNotification
 //*****************************************************************************
 
 NS_IMETHODIMP Navigator::GetMozNotification(nsISupports** aRetVal)
@@ -2148,16 +2210,27 @@ Navigator::HasBluetoothSupport(JSContext
 bool
 Navigator::HasTimeSupport(JSContext* /* unused */, JSObject* aGlobal)
 {
   nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
   return win && CheckPermission(win, "time");
 }
 #endif // MOZ_TIME_MANAGER
 
+#ifdef MOZ_MEDIA_NAVIGATOR
+/* static */
+bool Navigator::HasUserMediaSupport(JSContext* /* unused */,
+                                    JSObject* /* unused */)
+{
+  // Make enabling peerconnection enable getUserMedia() as well
+  return Preferences::GetBool("media.navigator.enabled", false) ||
+         Preferences::GetBool("media.peerconnection.enabled", false);
+}
+#endif // MOZ_MEDIA_NAVIGATOR
+
 /* static */
 already_AddRefed<nsPIDOMWindow>
 Navigator::GetWindowFromGlobal(JSObject* aGlobal)
 {
   nsCOMPtr<nsPIDOMWindow> win =
     do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(aGlobal));
   MOZ_ASSERT(!win || win->IsInnerWindow());
   return win.forget();
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -81,16 +81,21 @@ class BatteryManager;
 
 class DesktopNotificationCenter;
 class SmsManager;
 class MobileMessageManager;
 class MozIdleObserver;
 #ifdef MOZ_GAMEPAD
 class Gamepad;
 #endif // MOZ_GAMEPAD
+#ifdef MOZ_MEDIA_NAVIGATOR
+class MozDOMGetUserMediaSuccessCallback;
+class MozDOMGetUserMediaErrorCallback;
+class MozGetUserMediaDevicesSuccessCallback;
+#endif // MOZ_MEDIA_NAVIGATOR
 
 namespace icc {
 #ifdef MOZ_B2G_RIL
 class IccManager;
 #endif
 }
 
 namespace network {
@@ -323,17 +328,32 @@ public:
   nsIDOMBluetoothManager* GetMozBluetooth(ErrorResult& aRv);
 #endif // MOZ_B2G_BT
 #ifdef MOZ_TIME_MANAGER
   time::TimeManager* GetMozTime(ErrorResult& aRv);
 #endif // MOZ_TIME_MANAGER
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   system::AudioChannelManager* GetMozAudioChannelManager(ErrorResult& aRv);
 #endif // MOZ_AUDIO_CHANNEL_MANAGER
-
+#ifdef MOZ_MEDIA_NAVIGATOR
+  void MozGetUserMedia(nsIMediaStreamOptions* aParams,
+                       MozDOMGetUserMediaSuccessCallback* aOnSuccess,
+                       MozDOMGetUserMediaErrorCallback* aOnError,
+                       ErrorResult& aRv);
+  void MozGetUserMedia(nsIMediaStreamOptions* aParams,
+                       nsIDOMGetUserMediaSuccessCallback* aOnSuccess,
+                       nsIDOMGetUserMediaErrorCallback* aOnError,
+                       ErrorResult& aRv);
+  void MozGetUserMediaDevices(MozGetUserMediaDevicesSuccessCallback* aOnSuccess,
+                              MozDOMGetUserMediaErrorCallback* aOnError,
+                              ErrorResult& aRv);
+  void MozGetUserMediaDevices(nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
+                              nsIDOMGetUserMediaErrorCallback* aOnError,
+                              ErrorResult& aRv);
+#endif // MOZ_MEDIA_NAVIGATOR
 
   // WebIDL helper methods
   static bool HasBatterySupport(JSContext* /* unused*/, JSObject* /*unused */);
   static bool HasPowerSupport(JSContext* /* unused */, JSObject* aGlobal);
   static bool HasIdleSupport(JSContext* /* unused */, JSObject* aGlobal);
   static bool HasWakeLockSupport(JSContext* /* unused*/, JSObject* /*unused */);
   static bool HasDesktopNotificationSupport(JSContext* /* unused*/,
                                             JSObject* /*unused */)
@@ -358,16 +378,20 @@ public:
                                    JSObject* aGlobal);
 #endif // MOZ_B2G_RIL
 #ifdef MOZ_B2G_BT
   static bool HasBluetoothSupport(JSContext* /* unused */, JSObject* aGlobal);
 #endif // MOZ_B2G_BT
 #ifdef MOZ_TIME_MANAGER
   static bool HasTimeSupport(JSContext* /* unused */, JSObject* aGlobal);
 #endif // MOZ_TIME_MANAGER
+#ifdef MOZ_MEDIA_NAVIGATOR
+  static bool HasUserMediaSupport(JSContext* /* unused */,
+                                  JSObject* /* unused */);
+#endif // MOZ_MEDIA_NAVIGATOR
 
   nsPIDOMWindow* GetParentObject() const
   {
     return GetWindow();
   }
 
 private:
   bool CheckPermission(const char* type);
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -1708,16 +1708,18 @@ addExternalIface('MediaList')
 addExternalIface('MenuBuilder', nativeType='nsIMenuBuilder', notflattened=True)
 addExternalIface('MozBluetoothManager', nativeType='nsIDOMBluetoothManager')
 addExternalIface('MozBoxObject', nativeType='nsIBoxObject')
 addExternalIface('MozCellBroadcast')
 addExternalIface('MozConnection', headerFile='nsIDOMConnection.h')
 addExternalIface('MozControllers', nativeType='nsIControllers')
 addExternalIface('MozFrameLoader', nativeType='nsIFrameLoader', notflattened=True)
 addExternalIface('MozIccManager', headerFile='nsIDOMIccManager.h')
+addExternalIface('MozMediaStreamOptions', nativeType='nsIMediaStreamOptions',	
+                 headerFile='nsIDOMNavigatorUserMedia.h')
 addExternalIface('MozMobileConnection', headerFile='nsIDOMMobileConnection.h')
 addExternalIface('MozMobileMessageManager', headerFile='nsIDOMMobileMessageManager.h')
 addExternalIface('MozObserver', nativeType='nsIObserver', notflattened=True)
 addExternalIface('MozPowerManager', headerFile='nsIDOMPowerManager.h')
 addExternalIface('MozRDFCompositeDataSource', nativeType='nsIRDFCompositeDataSource',
                  notflattened=True)
 addExternalIface('MozRDFResource', nativeType='nsIRDFResource', notflattened=True)
 addExternalIface('MozSmsManager', headerFile='nsIDOMSmsManager.h')
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -325,8 +325,29 @@ partial interface Navigator {
 
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
 // nsIMozNavigatorAudioChannelManager
 partial interface Navigator {
   [Throws]
   readonly attribute AudioChannelManager mozAudioChannelManager;
 };
 #endif // MOZ_AUDIO_CHANNEL_MANAGER
+
+#ifdef MOZ_MEDIA_NAVIGATOR
+// nsIDOMNavigatorUserMedia
+callback MozDOMGetUserMediaSuccessCallback = void (nsISupports? value);
+callback MozDOMGetUserMediaErrorCallback = void (DOMString error);
+interface MozMediaStreamOptions;
+partial interface Navigator {
+  [Throws, Func="Navigator::HasUserMediaSupport"]
+  void mozGetUserMedia(MozMediaStreamOptions? params,
+                       MozDOMGetUserMediaSuccessCallback? onsuccess,
+                       MozDOMGetUserMediaErrorCallback? onerror);
+};
+
+// nsINavigatorUserMedia
+callback MozGetUserMediaDevicesSuccessCallback = void (nsIVariant? devices);
+partial interface Navigator {
+  [Throws, ChromeOnly]
+  void mozGetUserMediaDevices(MozGetUserMediaDevicesSuccessCallback? onsuccess,
+                              MozDOMGetUserMediaErrorCallback? onerror);
+};
+#endif // MOZ_MEDIA_NAVIGATOR