Bug 983180 - hide camera objects behind Navigator::HasCameraSupport(), r=bz
authorMike Habicher <mikeh@mozilla.com>
Wed, 09 Apr 2014 11:53:34 -0400
changeset 177875 72a05425a854e7b482b61101a52ed3cb8551eb8f
parent 177874 e6ac52f874d097648fcf91fd2db247af3a297d6b
child 177876 958d209e788e0f45fa3dc73b52699c3f4b811043
push id26567
push userryanvm@gmail.com
push dateFri, 11 Apr 2014 01:09:26 +0000
treeherdermozilla-central@68c042c2b2e5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs983180
milestone31.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 983180 - hide camera objects behind Navigator::HasCameraSupport(), r=bz
dom/camera/DOMCameraCapabilities.cpp
dom/camera/DOMCameraCapabilities.h
dom/camera/DOMCameraControl.cpp
dom/camera/DOMCameraControl.h
dom/camera/DOMCameraDetectedFace.cpp
dom/camera/DOMCameraDetectedFace.h
dom/camera/DOMCameraManager.cpp
dom/camera/DOMCameraManager.h
dom/camera/GonkCameraManager.cpp
dom/tests/mochitest/general/test_interfaces.html
dom/webidl/CameraCapabilities.webidl
dom/webidl/CameraControl.webidl
dom/webidl/CameraManager.webidl
--- a/dom/camera/DOMCameraCapabilities.cpp
+++ b/dom/camera/DOMCameraCapabilities.cpp
@@ -4,16 +4,17 @@
  * 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 "DOMCameraCapabilities.h"
 #include "nsPIDOMWindow.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/CameraManagerBinding.h"
 #include "mozilla/dom/CameraCapabilitiesBinding.h"
+#include "Navigator.h"
 #include "CameraCommon.h"
 #include "ICameraControl.h"
 #include "CameraRecorderProfiles.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(CameraCapabilities)
@@ -37,16 +38,23 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
 NS_IMPL_CYCLE_COLLECTING_ADDREF(CameraCapabilities)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(CameraCapabilities)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CameraCapabilities)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
+/* static */
+bool
+CameraCapabilities::HasSupport(JSContext* aCx, JSObject* aGlobal)
+{
+  return Navigator::HasCameraSupport(aCx, aGlobal);
+}
+
 CameraCapabilities::CameraCapabilities(nsPIDOMWindow* aWindow)
   : mRecorderProfiles(JS::UndefinedValue())
   , mWindow(aWindow)
 {
   DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
   MOZ_COUNT_CTOR(CameraCapabilities);
   mozilla::HoldJSObjects(this);
   SetIsDOMBinding();
--- a/dom/camera/DOMCameraCapabilities.h
+++ b/dom/camera/DOMCameraCapabilities.h
@@ -28,16 +28,23 @@ namespace dom {
 
 class CameraCapabilities MOZ_FINAL : public nsISupports
                                    , public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CameraCapabilities)
 
+  // Because this header's filename doesn't match its C++ or DOM-facing
+  // classname, we can't rely on the [Func="..."] WebIDL tag to implicitly
+  // include the right header for us; instead we must explicitly include a
+  // HasSupport() method in each header. We can get rid of these with the
+  // Great Renaming proposed in bug 983177.
+  static bool HasSupport(JSContext* aCx, JSObject* aGlobal);
+
   CameraCapabilities(nsPIDOMWindow* aWindow);
   ~CameraCapabilities();
 
   nsresult Populate(ICameraControl* aCameraControl);
 
   nsPIDOMWindow* GetParentObject() const { return mWindow; }
 
   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
--- a/dom/camera/DOMCameraControl.cpp
+++ b/dom/camera/DOMCameraControl.cpp
@@ -15,16 +15,17 @@
 #include "mozilla/MediaManager.h"
 #include "mozilla/Services.h"
 #include "mozilla/unused.h"
 #include "nsIAppsService.h"
 #include "nsIObserverService.h"
 #include "nsIDOMDeviceStorage.h"
 #include "nsIDOMEventListener.h"
 #include "nsIScriptSecurityManager.h"
+#include "Navigator.h"
 #include "nsXULAppAPI.h"
 #include "DOMCameraManager.h"
 #include "DOMCameraCapabilities.h"
 #include "CameraCommon.h"
 #include "nsGlobalWindow.h"
 #include "CameraPreviewMediaStream.h"
 #include "mozilla/dom/CameraControlBinding.h"
 #include "mozilla/dom/CameraManagerBinding.h"
@@ -61,16 +62,23 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED_20(ns
                                       mSetConfigurationOnErrorCb,
                                       mOnShutterCb,
                                       mOnClosedCb,
                                       mOnRecorderStateChangeCb,
                                       mOnPreviewStateChangeCb,
                                       mOnAutoFocusMovingCb,
                                       mOnFacesDetectedCb)
 
+/* static */
+bool
+nsDOMCameraControl::HasSupport(JSContext* aCx, JSObject* aGlobal)
+{
+  return Navigator::HasCameraSupport(aCx, aGlobal);
+}
+
 class mozilla::StartRecordingHelper : public nsIDOMEventListener
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMEVENTLISTENER
 
   StartRecordingHelper(nsDOMCameraControl* aDOMCameraControl)
     : mDOMCameraControl(aDOMCameraControl)
--- a/dom/camera/DOMCameraControl.h
+++ b/dom/camera/DOMCameraControl.h
@@ -35,16 +35,23 @@ class StartRecordingHelper;
 
 // Main camera control.
 class nsDOMCameraControl MOZ_FINAL : public DOMMediaStream
 {
 public:
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMCameraControl, DOMMediaStream)
   NS_DECL_ISUPPORTS_INHERITED
 
+  // Because this header's filename doesn't match its C++ or DOM-facing
+  // classname, we can't rely on the [Func="..."] WebIDL tag to implicitly
+  // include the right header for us; instead we must explicitly include a
+  // HasSupport() method in each header. We can get rid of these with the
+  // Great Renaming proposed in bug 983177.
+  static bool HasSupport(JSContext* aCx, JSObject* aGlobal);
+
   nsDOMCameraControl(uint32_t aCameraId,
                      const dom::CameraConfiguration& aInitialConfig,
                      dom::GetCameraCallback* aOnSuccess,
                      dom::CameraErrorCallback* aOnError,
                      nsPIDOMWindow* aWindow);
 
   void Shutdown();
 
--- a/dom/camera/DOMCameraDetectedFace.cpp
+++ b/dom/camera/DOMCameraDetectedFace.cpp
@@ -1,13 +1,14 @@
 /* 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 "DOMCameraDetectedFace.h"
+#include "Navigator.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DOMCameraPoint, mParent)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMCameraPoint)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMCameraPoint)
@@ -21,16 +22,30 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_5(
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMCameraDetectedFace)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMCameraDetectedFace)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMCameraDetectedFace)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
+/* static */
+bool
+DOMCameraPoint::HasSupport(JSContext* aCx, JSObject* aGlobal)
+{
+  return Navigator::HasCameraSupport(aCx, aGlobal);
+}
+
+/* static */
+bool
+DOMCameraDetectedFace::HasSupport(JSContext* aCx, JSObject* aGlobal)
+{
+  return Navigator::HasCameraSupport(aCx, aGlobal);
+}
+
 JSObject*
 DOMCameraPoint::WrapObject(JSContext* aCx)
 {
   return CameraPointBinding::Wrap(aCx, this);
 }
 
 JSObject*
 DOMCameraDetectedFace::WrapObject(JSContext* aCx)
--- a/dom/camera/DOMCameraDetectedFace.h
+++ b/dom/camera/DOMCameraDetectedFace.h
@@ -17,16 +17,23 @@ namespace dom {
 
 class DOMCameraPoint MOZ_FINAL : public nsISupports
                                , public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMCameraPoint)
 
+  // Because this header's filename doesn't match its C++ or DOM-facing
+  // classname, we can't rely on the [Func="..."] WebIDL tag to implicitly
+  // include the right header for us; instead we must explicitly include a
+  // HasSupport() method in each header. We can get rid of these with the
+  // Great Renaming proposed in bug 983177.
+  static bool HasSupport(JSContext* aCx, JSObject* aGlobal);
+
   DOMCameraPoint(nsISupports* aParent, const ICameraControl::Point& aPoint)
     : mParent(aParent)
     , mX(aPoint.x)
     , mY(aPoint.y)
   {
     SetIsDOMBinding();
   }
 
@@ -62,16 +69,23 @@ protected:
 
 class DOMCameraDetectedFace MOZ_FINAL : public nsISupports
                                       , public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMCameraDetectedFace)
 
+  // Because this header's filename doesn't match its C++ or DOM-facing
+  // classname, we can't rely on the [Func="..."] WebIDL tag to implicitly
+  // include the right header for us; instead we must explicitly include a
+  // HasSupport() method in each header. We can get rid of these with the
+  // Great Renaming proposed in bug 983177.
+  static bool HasSupport(JSContext* aCx, JSObject* aGlobal);
+
   DOMCameraDetectedFace(nsISupports* aParent, const ICameraControl::Face& aFace);
 
   uint32_t Id()       { return mId; }
   uint32_t Score()    { return mScore; }
   bool HasLeftEye()   { return mLeftEye; }
   bool HasRightEye()  { return mRightEye; }
   bool HasMouth()     { return mMouth; }
 
--- a/dom/camera/DOMCameraManager.cpp
+++ b/dom/camera/DOMCameraManager.cpp
@@ -1,15 +1,16 @@
 /* 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 "DOMCameraManager.h"
 #include "nsDebug.h"
 #include "jsapi.h"
+#include "Navigator.h"
 #include "nsPIDOMWindow.h"
 #include "mozilla/Services.h"
 #include "nsContentPermissionHelper.h"
 #include "nsObserverService.h"
 #include "nsIPermissionManager.h"
 #include "DOMCameraControl.h"
 #include "nsDOMClassInfo.h"
 #include "CameraCommon.h"
@@ -65,22 +66,31 @@ nsDOMCameraManager::nsDOMCameraManager(n
 
 nsDOMCameraManager::~nsDOMCameraManager()
 {
   /* destructor code */
   MOZ_COUNT_DTOR(nsDOMCameraManager);
   DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
 }
 
+/* static */
 void
 nsDOMCameraManager::GetListOfCameras(nsTArray<nsString>& aList, ErrorResult& aRv)
 {
   aRv = ICameraControl::GetListOfCameras(aList);
 }
 
+/* static */
+bool
+nsDOMCameraManager::HasSupport(JSContext* aCx, JSObject* aGlobal)
+{
+  return Navigator::HasCameraSupport(aCx, aGlobal);
+}
+
+/* static */
 bool
 nsDOMCameraManager::CheckPermission(nsPIDOMWindow* aWindow)
 {
   nsCOMPtr<nsIPermissionManager> permMgr =
     do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
   NS_ENSURE_TRUE(permMgr, false);
 
   uint32_t permission = nsIPermissionManager::DENY_ACTION;
@@ -88,17 +98,17 @@ nsDOMCameraManager::CheckPermission(nsPI
   if (permission != nsIPermissionManager::ALLOW_ACTION &&
       permission != nsIPermissionManager::PROMPT_ACTION) {
     return false;
   }
 
   return true;
 }
 
-// static creator
+/* static */
 already_AddRefed<nsDOMCameraManager>
 nsDOMCameraManager::CreateInstance(nsPIDOMWindow* aWindow)
 {
   // Initialize the shared active window tracker
   if (!sActiveWindows) {
     sActiveWindows = new WindowTable();
   }
 
--- a/dom/camera/DOMCameraManager.h
+++ b/dom/camera/DOMCameraManager.h
@@ -41,16 +41,23 @@ class nsDOMCameraManager MOZ_FINAL
   , public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMCameraManager,
                                                          nsIObserver)
   NS_DECL_NSIOBSERVER
 
+  // Because this header's filename doesn't match its C++ or DOM-facing
+  // classname, we can't rely on the [Func="..."] WebIDL tag to implicitly
+  // include the right header for us; instead we must explicitly include a
+  // HasSupport() method in each header. We can get rid of these with the
+  // Great Renaming proposed in bug 983177.
+  static bool HasSupport(JSContext* aCx, JSObject* aGlobal);
+
   static bool CheckPermission(nsPIDOMWindow* aWindow);
   static already_AddRefed<nsDOMCameraManager>
     CreateInstance(nsPIDOMWindow* aWindow);
   static bool IsWindowStillActive(uint64_t aWindowId);
 
   void Register(mozilla::nsDOMCameraControl* aDOMCameraControl);
   void OnNavigation(uint64_t aWindowId);
 
--- a/dom/camera/GonkCameraManager.cpp
+++ b/dom/camera/GonkCameraManager.cpp
@@ -9,21 +9,22 @@
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
+#include "ICameraControl.h"
+
 #include <camera/Camera.h>
 
 #include "CameraCommon.h"
 #include "GonkCameraControl.h"
-#include "ICameraControl.h"
 
 using namespace mozilla;
 
 // From ICameraControl, gonk-specific management functions
 nsresult
 ICameraControl::GetNumberOfCameras(int32_t& aDeviceCount)
 {
   aDeviceCount = android::Camera::getNumberOfCameras();
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -23,17 +23,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 // This is a list of all interfaces that are exposed to every webpage.
 // Please only add things to this list with great care and proper review
 // from the associated module peers.
 
 // This file lists global interfaces we want exposed and verifies they
 // are what we intend. Each entry in the arrays below can either be a
 // simple string with the interface name, or an object with a 'name'
 // property giving the interface name as a string, and additional
-// properties which quality the exposure of that interface. For example:
+// properties which qualify the exposure of that interface. For example:
 //
 // [
 //   "AGlobalInterface",
 //   {name: "ExperimentalThing", release: false},
 //   {name: "OptionalThing", pref: "some.thing.enabled"},
 //   {name: "FancyControl", xbl: true},
 // ];
 //
@@ -163,25 +163,25 @@ var interfaceNamesInGlobalScope =
     {name: "BluetoothStatusChangedEvent", b2g: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "BoxObject", xbl: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "CallEvent", b2g: true, pref: "dom.telephony.enabled"},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "CallGroupErrorEvent", b2g: true, pref: "dom.telephony.enabled"},
 // IMPORTANT: Do not change this list without review from a DOM peer!
-    "CameraCapabilities",
+    {name: "CameraCapabilities", b2g: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
-    "CameraControl",
+    {name: "CameraControl", b2g: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
-    {name: "CameraDetectedFace", pref: "camera.control.face_detection.enabled"},
+    {name: "CameraDetectedFace", b2g: true, pref: "camera.control.face_detection.enabled"},
 // IMPORTANT: Do not change this list without review from a DOM peer!
-    "CameraManager",
+    {name: "CameraManager", b2g: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
-    {name: "CameraPoint", pref: "camera.control.face_detection.enabled"},
+    {name: "CameraPoint", b2g: true, pref: "camera.control.face_detection.enabled"},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CanvasGradient",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CanvasPattern",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CanvasRenderingContext2D",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "CaretPosition",
--- a/dom/webidl/CameraCapabilities.webidl
+++ b/dom/webidl/CameraCapabilities.webidl
@@ -1,15 +1,19 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* 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/.
  */
 
+/* The capabilities of a CameraControl instance. These are guaranteed
+   not to change over the lifetime of that particular instance.
+*/
+[Func="CameraCapabilities::HasSupport"]
 interface CameraCapabilities
 {
   [Constant, Cached] readonly attribute sequence<CameraSize> previewSizes;
   [Constant, Cached] readonly attribute sequence<CameraSize> pictureSizes;
   [Constant, Cached] readonly attribute sequence<CameraSize> thumbnailSizes;
   [Constant, Cached] readonly attribute sequence<CameraSize> videoSizes;
 
   [Constant, Cached] readonly attribute sequence<DOMString> fileFormats;
--- a/dom/webidl/CameraControl.webidl
+++ b/dom/webidl/CameraControl.webidl
@@ -129,16 +129,17 @@ callback CameraReleaseCallback = void ()
 callback CameraRecorderStateChange = void (DOMString newState);
 callback CameraPreviewStateChange = void (DOMString newState);
 callback CameraAutoFocusMovingCallback = void (boolean isMoving);
 
 /*
     attributes here affect the preview, any pictures taken, and/or
     any video recorded by the camera.
 */
+[Func="nsDOMCameraControl::HasSupport"]
 interface CameraControl : MediaStream
 {
   [Constant, Cached]
   readonly attribute CameraCapabilities capabilities;
 
   /* one of the values chosen from capabilities.effects;
      default is "none" */
   [Throws]
@@ -347,17 +348,17 @@ interface CameraControl : MediaStream
 };
 
 /* The coordinates of a point, relative to the camera sensor, of the center of
    detected facial features. As with CameraRegions:
      { x: -1000, y: -1000 } is the top-left corner
      { x:  1000, y:  1000 } is the bottom-right corner
    x and y can range from -1000 to 1000.
 */
-[Pref="camera.control.face_detection.enabled"]
+[Pref="camera.control.face_detection.enabled", Func="DOMCameraPoint::HasSupport"]
 interface CameraPoint
 {
   attribute long x;
   attribute long y;
 };
 
 /* The information of the each face detected by a camera device, e.g.
      {
@@ -391,17 +392,17 @@ interface CameraPoint
    the value will be set to null.
 
    'rightEye' is the coordinates of the detected right eye; null if not
    supported or detected.
 
    'mouth' is the coordinates of the detected mouth; null if not supported or
    detected.
 */
-[Pref="camera.control.face_detection.enabled"]
+[Pref="camera.control.face_detection.enabled", Func="DOMCameraDetectedFace::HasSupport"]
 interface CameraDetectedFace
 {
   readonly attribute unsigned long id;
 
   readonly attribute unsigned long score;
 
   readonly attribute DOMRect bounds;
 
--- a/dom/webidl/CameraManager.webidl
+++ b/dom/webidl/CameraManager.webidl
@@ -24,16 +24,17 @@ dictionary CameraConfiguration
                                       // supported by the CameraControl
 };
 
 callback CameraErrorCallback = void (DOMString error);
 
 callback GetCameraCallback = void (CameraControl camera,
                                    CameraConfiguration configuration);
 
+[Func="nsDOMCameraManager::HasSupport"]
 interface CameraManager
 {
   /* get a camera instance; 'camera' is one of the camera
      identifiers returned by getListOfCameras() below.
   */
   [Throws]
   void getCamera(DOMString camera,
                  CameraConfiguration initialConfiguration,