|
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=40: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef DOM_CAMERA_DOMCAMERAMANAGER_H |
|
8 #define DOM_CAMERA_DOMCAMERAMANAGER_H |
|
9 |
|
10 #include "mozilla/dom/BindingDeclarations.h" |
|
11 #include "nsCOMPtr.h" |
|
12 #include "nsAutoPtr.h" |
|
13 #include "nsIObserver.h" |
|
14 #include "nsHashKeys.h" |
|
15 #include "nsWrapperCache.h" |
|
16 #include "nsWeakReference.h" |
|
17 #include "nsClassHashtable.h" |
|
18 #include "nsCycleCollectionParticipant.h" |
|
19 #include "mozilla/Attributes.h" |
|
20 |
|
21 class nsPIDOMWindow; |
|
22 |
|
23 namespace mozilla { |
|
24 class ErrorResult; |
|
25 class nsDOMCameraControl; |
|
26 namespace dom { |
|
27 class CameraConfiguration; |
|
28 class GetCameraCallback; |
|
29 class CameraErrorCallback; |
|
30 } |
|
31 } |
|
32 |
|
33 typedef nsTArray<nsRefPtr<mozilla::nsDOMCameraControl> > CameraControls; |
|
34 typedef nsClassHashtable<nsUint64HashKey, CameraControls> WindowTable; |
|
35 typedef mozilla::dom::Optional<mozilla::dom::OwningNonNull<mozilla::dom::CameraErrorCallback>> |
|
36 OptionalNonNullCameraErrorCallback; |
|
37 |
|
38 class nsDOMCameraManager MOZ_FINAL |
|
39 : public nsIObserver |
|
40 , public nsSupportsWeakReference |
|
41 , public nsWrapperCache |
|
42 { |
|
43 public: |
|
44 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
45 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMCameraManager, |
|
46 nsIObserver) |
|
47 NS_DECL_NSIOBSERVER |
|
48 |
|
49 // Because this header's filename doesn't match its C++ or DOM-facing |
|
50 // classname, we can't rely on the [Func="..."] WebIDL tag to implicitly |
|
51 // include the right header for us; instead we must explicitly include a |
|
52 // HasSupport() method in each header. We can get rid of these with the |
|
53 // Great Renaming proposed in bug 983177. |
|
54 static bool HasSupport(JSContext* aCx, JSObject* aGlobal); |
|
55 |
|
56 static bool CheckPermission(nsPIDOMWindow* aWindow); |
|
57 static already_AddRefed<nsDOMCameraManager> |
|
58 CreateInstance(nsPIDOMWindow* aWindow); |
|
59 static bool IsWindowStillActive(uint64_t aWindowId); |
|
60 |
|
61 void Register(mozilla::nsDOMCameraControl* aDOMCameraControl); |
|
62 void OnNavigation(uint64_t aWindowId); |
|
63 |
|
64 void PermissionAllowed(uint32_t aCameraId, |
|
65 const mozilla::dom::CameraConfiguration& aOptions, |
|
66 mozilla::dom::GetCameraCallback* aOnSuccess, |
|
67 mozilla::dom::CameraErrorCallback* aOnError); |
|
68 |
|
69 void PermissionCancelled(uint32_t aCameraId, |
|
70 const mozilla::dom::CameraConfiguration& aOptions, |
|
71 mozilla::dom::GetCameraCallback* aOnSuccess, |
|
72 mozilla::dom::CameraErrorCallback* aOnError); |
|
73 |
|
74 // WebIDL |
|
75 void GetCamera(const nsAString& aCamera, |
|
76 const mozilla::dom::CameraConfiguration& aOptions, |
|
77 mozilla::dom::GetCameraCallback& aOnSuccess, |
|
78 const OptionalNonNullCameraErrorCallback& aOnError, |
|
79 mozilla::ErrorResult& aRv); |
|
80 void GetListOfCameras(nsTArray<nsString>& aList, mozilla::ErrorResult& aRv); |
|
81 |
|
82 nsPIDOMWindow* GetParentObject() const { return mWindow; } |
|
83 virtual JSObject* WrapObject(JSContext* aCx) |
|
84 MOZ_OVERRIDE; |
|
85 |
|
86 protected: |
|
87 void XpComShutdown(); |
|
88 void Shutdown(uint64_t aWindowId); |
|
89 ~nsDOMCameraManager(); |
|
90 |
|
91 private: |
|
92 nsDOMCameraManager() MOZ_DELETE; |
|
93 nsDOMCameraManager(nsPIDOMWindow* aWindow); |
|
94 nsDOMCameraManager(const nsDOMCameraManager&) MOZ_DELETE; |
|
95 nsDOMCameraManager& operator=(const nsDOMCameraManager&) MOZ_DELETE; |
|
96 |
|
97 protected: |
|
98 uint64_t mWindowId; |
|
99 uint32_t mPermission; |
|
100 nsCOMPtr<nsPIDOMWindow> mWindow; |
|
101 /** |
|
102 * 'sActiveWindows' is only ever accessed while in the Main Thread, |
|
103 * so it is not otherwise protected. |
|
104 */ |
|
105 static ::WindowTable* sActiveWindows; |
|
106 }; |
|
107 |
|
108 #endif // DOM_CAMERA_DOMCAMERAMANAGER_H |