1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/camera/DOMCameraManager.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=40: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef DOM_CAMERA_DOMCAMERAMANAGER_H 1.11 +#define DOM_CAMERA_DOMCAMERAMANAGER_H 1.12 + 1.13 +#include "mozilla/dom/BindingDeclarations.h" 1.14 +#include "nsCOMPtr.h" 1.15 +#include "nsAutoPtr.h" 1.16 +#include "nsIObserver.h" 1.17 +#include "nsHashKeys.h" 1.18 +#include "nsWrapperCache.h" 1.19 +#include "nsWeakReference.h" 1.20 +#include "nsClassHashtable.h" 1.21 +#include "nsCycleCollectionParticipant.h" 1.22 +#include "mozilla/Attributes.h" 1.23 + 1.24 +class nsPIDOMWindow; 1.25 + 1.26 +namespace mozilla { 1.27 + class ErrorResult; 1.28 + class nsDOMCameraControl; 1.29 + namespace dom { 1.30 + class CameraConfiguration; 1.31 + class GetCameraCallback; 1.32 + class CameraErrorCallback; 1.33 + } 1.34 +} 1.35 + 1.36 +typedef nsTArray<nsRefPtr<mozilla::nsDOMCameraControl> > CameraControls; 1.37 +typedef nsClassHashtable<nsUint64HashKey, CameraControls> WindowTable; 1.38 +typedef mozilla::dom::Optional<mozilla::dom::OwningNonNull<mozilla::dom::CameraErrorCallback>> 1.39 + OptionalNonNullCameraErrorCallback; 1.40 + 1.41 +class nsDOMCameraManager MOZ_FINAL 1.42 + : public nsIObserver 1.43 + , public nsSupportsWeakReference 1.44 + , public nsWrapperCache 1.45 +{ 1.46 +public: 1.47 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.48 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMCameraManager, 1.49 + nsIObserver) 1.50 + NS_DECL_NSIOBSERVER 1.51 + 1.52 + // Because this header's filename doesn't match its C++ or DOM-facing 1.53 + // classname, we can't rely on the [Func="..."] WebIDL tag to implicitly 1.54 + // include the right header for us; instead we must explicitly include a 1.55 + // HasSupport() method in each header. We can get rid of these with the 1.56 + // Great Renaming proposed in bug 983177. 1.57 + static bool HasSupport(JSContext* aCx, JSObject* aGlobal); 1.58 + 1.59 + static bool CheckPermission(nsPIDOMWindow* aWindow); 1.60 + static already_AddRefed<nsDOMCameraManager> 1.61 + CreateInstance(nsPIDOMWindow* aWindow); 1.62 + static bool IsWindowStillActive(uint64_t aWindowId); 1.63 + 1.64 + void Register(mozilla::nsDOMCameraControl* aDOMCameraControl); 1.65 + void OnNavigation(uint64_t aWindowId); 1.66 + 1.67 + void PermissionAllowed(uint32_t aCameraId, 1.68 + const mozilla::dom::CameraConfiguration& aOptions, 1.69 + mozilla::dom::GetCameraCallback* aOnSuccess, 1.70 + mozilla::dom::CameraErrorCallback* aOnError); 1.71 + 1.72 + void PermissionCancelled(uint32_t aCameraId, 1.73 + const mozilla::dom::CameraConfiguration& aOptions, 1.74 + mozilla::dom::GetCameraCallback* aOnSuccess, 1.75 + mozilla::dom::CameraErrorCallback* aOnError); 1.76 + 1.77 + // WebIDL 1.78 + void GetCamera(const nsAString& aCamera, 1.79 + const mozilla::dom::CameraConfiguration& aOptions, 1.80 + mozilla::dom::GetCameraCallback& aOnSuccess, 1.81 + const OptionalNonNullCameraErrorCallback& aOnError, 1.82 + mozilla::ErrorResult& aRv); 1.83 + void GetListOfCameras(nsTArray<nsString>& aList, mozilla::ErrorResult& aRv); 1.84 + 1.85 + nsPIDOMWindow* GetParentObject() const { return mWindow; } 1.86 + virtual JSObject* WrapObject(JSContext* aCx) 1.87 + MOZ_OVERRIDE; 1.88 + 1.89 +protected: 1.90 + void XpComShutdown(); 1.91 + void Shutdown(uint64_t aWindowId); 1.92 + ~nsDOMCameraManager(); 1.93 + 1.94 +private: 1.95 + nsDOMCameraManager() MOZ_DELETE; 1.96 + nsDOMCameraManager(nsPIDOMWindow* aWindow); 1.97 + nsDOMCameraManager(const nsDOMCameraManager&) MOZ_DELETE; 1.98 + nsDOMCameraManager& operator=(const nsDOMCameraManager&) MOZ_DELETE; 1.99 + 1.100 +protected: 1.101 + uint64_t mWindowId; 1.102 + uint32_t mPermission; 1.103 + nsCOMPtr<nsPIDOMWindow> mWindow; 1.104 + /** 1.105 + * 'sActiveWindows' is only ever accessed while in the Main Thread, 1.106 + * so it is not otherwise protected. 1.107 + */ 1.108 + static ::WindowTable* sActiveWindows; 1.109 +}; 1.110 + 1.111 +#endif // DOM_CAMERA_DOMCAMERAMANAGER_H