2012-07-30 21:59:05 +00:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=40: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef DOM_CAMERA_DOMCAMERAMANAGER_H
|
|
|
|
#define DOM_CAMERA_DOMCAMERAMANAGER_H
|
|
|
|
|
2013-05-10 06:25:25 +00:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2014-10-03 08:19:00 +00:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2012-07-30 21:59:05 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2012-10-01 00:37:47 +00:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsHashKeys.h"
|
2013-05-10 06:25:25 +00:00
|
|
|
#include "nsWrapperCache.h"
|
2012-10-01 00:37:47 +00:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2012-07-31 21:30:53 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-02-14 22:41:07 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
class nsPIDOMWindowInner;
|
2012-09-21 10:32:18 +00:00
|
|
|
|
2012-10-01 00:37:47 +00:00
|
|
|
namespace mozilla {
|
2013-05-10 06:25:25 +00:00
|
|
|
class ErrorResult;
|
2014-02-14 22:41:07 +00:00
|
|
|
class nsDOMCameraControl;
|
|
|
|
namespace dom {
|
2014-06-19 00:57:51 +00:00
|
|
|
struct CameraConfiguration;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2012-10-01 00:37:47 +00:00
|
|
|
|
2014-12-13 02:18:03 +00:00
|
|
|
typedef nsTArray<nsWeakPtr> CameraControls;
|
2012-10-01 00:37:47 +00:00
|
|
|
typedef nsClassHashtable<nsUint64HashKey, CameraControls> WindowTable;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsDOMCameraManager final
|
2013-05-14 10:59:11 +00:00
|
|
|
: public nsIObserver
|
2012-10-01 00:37:47 +00:00
|
|
|
, public nsSupportsWeakReference
|
2013-05-10 06:25:25 +00:00
|
|
|
, public nsWrapperCache
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-10-01 00:37:47 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-05-10 06:25:25 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMCameraManager,
|
2013-05-14 10:59:11 +00:00
|
|
|
nsIObserver)
|
2012-10-01 00:37:47 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2014-04-09 15:53:34 +00:00
|
|
|
// 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);
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
static bool CheckPermission(nsPIDOMWindowInner* aWindow);
|
2012-09-21 10:32:18 +00:00
|
|
|
static already_AddRefed<nsDOMCameraManager>
|
2016-01-30 17:05:36 +00:00
|
|
|
CreateInstance(nsPIDOMWindowInner* aWindow);
|
2012-10-01 00:37:47 +00:00
|
|
|
static bool IsWindowStillActive(uint64_t aWindowId);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2012-10-01 00:37:47 +00:00
|
|
|
void Register(mozilla::nsDOMCameraControl* aDOMCameraControl);
|
2012-08-22 15:56:38 +00:00
|
|
|
void OnNavigation(uint64_t aWindowId);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2014-04-02 04:08:42 +00:00
|
|
|
void PermissionAllowed(uint32_t aCameraId,
|
|
|
|
const mozilla::dom::CameraConfiguration& aOptions,
|
2014-10-03 08:19:00 +00:00
|
|
|
mozilla::dom::Promise* aPromise);
|
2014-04-02 04:08:42 +00:00
|
|
|
|
|
|
|
void PermissionCancelled(uint32_t aCameraId,
|
|
|
|
const mozilla::dom::CameraConfiguration& aOptions,
|
2014-10-03 08:19:00 +00:00
|
|
|
mozilla::dom::Promise* aPromise);
|
2014-04-02 04:08:42 +00:00
|
|
|
|
2013-05-10 06:25:25 +00:00
|
|
|
// WebIDL
|
2014-10-03 08:19:00 +00:00
|
|
|
already_AddRefed<mozilla::dom::Promise>
|
|
|
|
GetCamera(const nsAString& aCamera,
|
|
|
|
const mozilla::dom::CameraConfiguration& aOptions,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2013-05-10 06:25:25 +00:00
|
|
|
void GetListOfCameras(nsTArray<nsString>& aList, mozilla::ErrorResult& aRv);
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const { return mWindow; }
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-05-10 06:25:25 +00:00
|
|
|
|
2014-10-31 17:54:02 +00:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
static void PreinitCameraHardware();
|
|
|
|
#endif
|
|
|
|
|
2012-10-01 00:37:47 +00:00
|
|
|
protected:
|
|
|
|
void XpComShutdown();
|
|
|
|
void Shutdown(uint64_t aWindowId);
|
|
|
|
~nsDOMCameraManager();
|
|
|
|
|
2012-07-30 21:59:05 +00:00
|
|
|
private:
|
2015-01-06 23:35:02 +00:00
|
|
|
nsDOMCameraManager() = delete;
|
2016-01-30 17:05:36 +00:00
|
|
|
explicit nsDOMCameraManager(nsPIDOMWindowInner* aWindow);
|
2015-01-06 23:35:02 +00:00
|
|
|
nsDOMCameraManager(const nsDOMCameraManager&) = delete;
|
|
|
|
nsDOMCameraManager& operator=(const nsDOMCameraManager&) = delete;
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
protected:
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t mWindowId;
|
2014-04-02 04:08:42 +00:00
|
|
|
uint32_t mPermission;
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
2012-10-01 00:37:47 +00:00
|
|
|
/**
|
2014-02-14 22:41:07 +00:00
|
|
|
* 'sActiveWindows' is only ever accessed while in the Main Thread,
|
2012-10-01 00:37:47 +00:00
|
|
|
* so it is not otherwise protected.
|
|
|
|
*/
|
2013-11-20 16:29:03 +00:00
|
|
|
static ::WindowTable* sActiveWindows;
|
2012-07-30 21:59:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DOM_CAMERA_DOMCAMERAMANAGER_H
|