Bumping manifests a=b2g-bump
[gecko.git] / dom / camera / DOMCameraManager.h
blob4562513bc477fa939b58e66c1de2fab662c891fc
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/. */
7 #ifndef DOM_CAMERA_DOMCAMERAMANAGER_H
8 #define DOM_CAMERA_DOMCAMERAMANAGER_H
10 #include "mozilla/dom/BindingDeclarations.h"
11 #include "nsCOMPtr.h"
12 #include "nsAutoPtr.h"
13 #include "nsWeakPtr.h"
14 #include "nsIObserver.h"
15 #include "nsHashKeys.h"
16 #include "nsWrapperCache.h"
17 #include "nsWeakReference.h"
18 #include "nsClassHashtable.h"
19 #include "nsCycleCollectionParticipant.h"
20 #include "mozilla/Attributes.h"
22 class nsPIDOMWindow;
24 namespace mozilla {
25 class ErrorResult;
26 class nsDOMCameraControl;
27 namespace dom {
28 struct CameraConfiguration;
29 class GetCameraCallback;
30 class CameraErrorCallback;
34 typedef nsTArray<nsWeakPtr> CameraControls;
35 typedef nsClassHashtable<nsUint64HashKey, CameraControls> WindowTable;
36 typedef mozilla::dom::Optional<mozilla::dom::OwningNonNull<mozilla::dom::CameraErrorCallback>>
37 OptionalNonNullCameraErrorCallback;
39 class nsDOMCameraManager MOZ_FINAL
40 : public nsIObserver
41 , public nsSupportsWeakReference
42 , public nsWrapperCache
44 public:
45 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
46 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMCameraManager,
47 nsIObserver)
48 NS_DECL_NSIOBSERVER
50 // Because this header's filename doesn't match its C++ or DOM-facing
51 // classname, we can't rely on the [Func="..."] WebIDL tag to implicitly
52 // include the right header for us; instead we must explicitly include a
53 // HasSupport() method in each header. We can get rid of these with the
54 // Great Renaming proposed in bug 983177.
55 static bool HasSupport(JSContext* aCx, JSObject* aGlobal);
57 static bool CheckPermission(nsPIDOMWindow* aWindow);
58 static already_AddRefed<nsDOMCameraManager>
59 CreateInstance(nsPIDOMWindow* aWindow);
60 static bool IsWindowStillActive(uint64_t aWindowId);
62 void Register(mozilla::nsDOMCameraControl* aDOMCameraControl);
63 void OnNavigation(uint64_t aWindowId);
65 void PermissionAllowed(uint32_t aCameraId,
66 const mozilla::dom::CameraConfiguration& aOptions,
67 mozilla::dom::GetCameraCallback* aOnSuccess,
68 mozilla::dom::CameraErrorCallback* aOnError);
70 void PermissionCancelled(uint32_t aCameraId,
71 const mozilla::dom::CameraConfiguration& aOptions,
72 mozilla::dom::GetCameraCallback* aOnSuccess,
73 mozilla::dom::CameraErrorCallback* aOnError);
75 // WebIDL
76 void GetCamera(const nsAString& aCamera,
77 const mozilla::dom::CameraConfiguration& aOptions,
78 mozilla::dom::GetCameraCallback& aOnSuccess,
79 const OptionalNonNullCameraErrorCallback& aOnError,
80 mozilla::ErrorResult& aRv);
81 void GetListOfCameras(nsTArray<nsString>& aList, mozilla::ErrorResult& aRv);
83 nsPIDOMWindow* GetParentObject() const { return mWindow; }
84 virtual JSObject* WrapObject(JSContext* aCx)
85 MOZ_OVERRIDE;
87 protected:
88 void XpComShutdown();
89 void Shutdown(uint64_t aWindowId);
90 ~nsDOMCameraManager();
92 private:
93 nsDOMCameraManager() MOZ_DELETE;
94 explicit nsDOMCameraManager(nsPIDOMWindow* aWindow);
95 nsDOMCameraManager(const nsDOMCameraManager&) MOZ_DELETE;
96 nsDOMCameraManager& operator=(const nsDOMCameraManager&) MOZ_DELETE;
98 protected:
99 uint64_t mWindowId;
100 uint32_t mPermission;
101 nsCOMPtr<nsPIDOMWindow> mWindow;
103 * 'sActiveWindows' is only ever accessed while in the Main Thread,
104 * so it is not otherwise protected.
106 static ::WindowTable* sActiveWindows;
109 #endif // DOM_CAMERA_DOMCAMERAMANAGER_H