michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=40: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef DOM_CAMERA_DOMCAMERAMANAGER_H michael@0: #define DOM_CAMERA_DOMCAMERAMANAGER_H michael@0: michael@0: #include "mozilla/dom/BindingDeclarations.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsHashKeys.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "nsWeakReference.h" michael@0: #include "nsClassHashtable.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsPIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: class ErrorResult; michael@0: class nsDOMCameraControl; michael@0: namespace dom { michael@0: class CameraConfiguration; michael@0: class GetCameraCallback; michael@0: class CameraErrorCallback; michael@0: } michael@0: } michael@0: michael@0: typedef nsTArray > CameraControls; michael@0: typedef nsClassHashtable WindowTable; michael@0: typedef mozilla::dom::Optional> michael@0: OptionalNonNullCameraErrorCallback; michael@0: michael@0: class nsDOMCameraManager MOZ_FINAL michael@0: : public nsIObserver michael@0: , public nsSupportsWeakReference michael@0: , public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMCameraManager, michael@0: nsIObserver) michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: // Because this header's filename doesn't match its C++ or DOM-facing michael@0: // classname, we can't rely on the [Func="..."] WebIDL tag to implicitly michael@0: // include the right header for us; instead we must explicitly include a michael@0: // HasSupport() method in each header. We can get rid of these with the michael@0: // Great Renaming proposed in bug 983177. michael@0: static bool HasSupport(JSContext* aCx, JSObject* aGlobal); michael@0: michael@0: static bool CheckPermission(nsPIDOMWindow* aWindow); michael@0: static already_AddRefed michael@0: CreateInstance(nsPIDOMWindow* aWindow); michael@0: static bool IsWindowStillActive(uint64_t aWindowId); michael@0: michael@0: void Register(mozilla::nsDOMCameraControl* aDOMCameraControl); michael@0: void OnNavigation(uint64_t aWindowId); michael@0: michael@0: void PermissionAllowed(uint32_t aCameraId, michael@0: const mozilla::dom::CameraConfiguration& aOptions, michael@0: mozilla::dom::GetCameraCallback* aOnSuccess, michael@0: mozilla::dom::CameraErrorCallback* aOnError); michael@0: michael@0: void PermissionCancelled(uint32_t aCameraId, michael@0: const mozilla::dom::CameraConfiguration& aOptions, michael@0: mozilla::dom::GetCameraCallback* aOnSuccess, michael@0: mozilla::dom::CameraErrorCallback* aOnError); michael@0: michael@0: // WebIDL michael@0: void GetCamera(const nsAString& aCamera, michael@0: const mozilla::dom::CameraConfiguration& aOptions, michael@0: mozilla::dom::GetCameraCallback& aOnSuccess, michael@0: const OptionalNonNullCameraErrorCallback& aOnError, michael@0: mozilla::ErrorResult& aRv); michael@0: void GetListOfCameras(nsTArray& aList, mozilla::ErrorResult& aRv); michael@0: michael@0: nsPIDOMWindow* GetParentObject() const { return mWindow; } michael@0: virtual JSObject* WrapObject(JSContext* aCx) michael@0: MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: void XpComShutdown(); michael@0: void Shutdown(uint64_t aWindowId); michael@0: ~nsDOMCameraManager(); michael@0: michael@0: private: michael@0: nsDOMCameraManager() MOZ_DELETE; michael@0: nsDOMCameraManager(nsPIDOMWindow* aWindow); michael@0: nsDOMCameraManager(const nsDOMCameraManager&) MOZ_DELETE; michael@0: nsDOMCameraManager& operator=(const nsDOMCameraManager&) MOZ_DELETE; michael@0: michael@0: protected: michael@0: uint64_t mWindowId; michael@0: uint32_t mPermission; michael@0: nsCOMPtr mWindow; michael@0: /** michael@0: * 'sActiveWindows' is only ever accessed while in the Main Thread, michael@0: * so it is not otherwise protected. michael@0: */ michael@0: static ::WindowTable* sActiveWindows; michael@0: }; michael@0: michael@0: #endif // DOM_CAMERA_DOMCAMERAMANAGER_H