2012-07-30 14:59:05 -07: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-09 23:25:25 -07:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2014-10-03 01:19:00 -07:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2012-07-30 14:59:05 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2012-09-30 17:37:47 -07:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsHashKeys.h"
|
2013-05-09 23:25:25 -07:00
|
|
|
#include "nsWrapperCache.h"
|
2012-09-30 17:37:47 -07:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2012-07-31 14:30:53 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
class nsPIDOMWindow;
|
2012-09-21 03:32:18 -07:00
|
|
|
|
2012-09-30 17:37:47 -07:00
|
|
|
namespace mozilla {
|
2013-05-09 23:25:25 -07:00
|
|
|
class ErrorResult;
|
2014-02-14 14:41:07 -08:00
|
|
|
class nsDOMCameraControl;
|
|
|
|
namespace dom {
|
2014-06-18 17:57:51 -07:00
|
|
|
struct CameraConfiguration;
|
2014-02-14 14:41:07 -08:00
|
|
|
class GetCameraCallback;
|
|
|
|
class CameraErrorCallback;
|
|
|
|
}
|
2012-09-30 17:37:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef nsTArray<nsRefPtr<mozilla::nsDOMCameraControl> > CameraControls;
|
|
|
|
typedef nsClassHashtable<nsUint64HashKey, CameraControls> WindowTable;
|
2014-10-03 01:19:00 -07:00
|
|
|
typedef mozilla::dom::Optional<mozilla::dom::OwningNonNull<mozilla::dom::GetCameraCallback> >
|
|
|
|
OptionalNonNullGetCameraCallback;
|
|
|
|
typedef mozilla::dom::Optional<mozilla::dom::OwningNonNull<mozilla::dom::CameraErrorCallback> >
|
2014-04-01 21:08:42 -07:00
|
|
|
OptionalNonNullCameraErrorCallback;
|
2012-09-30 17:37:47 -07:00
|
|
|
|
|
|
|
class nsDOMCameraManager MOZ_FINAL
|
2013-05-14 03:59:11 -07:00
|
|
|
: public nsIObserver
|
2012-09-30 17:37:47 -07:00
|
|
|
, public nsSupportsWeakReference
|
2013-05-09 23:25:25 -07:00
|
|
|
, public nsWrapperCache
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-09-30 17:37:47 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-05-09 23:25:25 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMCameraManager,
|
2013-05-14 03:59:11 -07:00
|
|
|
nsIObserver)
|
2012-09-30 17:37:47 -07:00
|
|
|
NS_DECL_NSIOBSERVER
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-04-09 08:53:34 -07: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);
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
static bool CheckPermission(nsPIDOMWindow* aWindow);
|
2012-09-21 03:32:18 -07:00
|
|
|
static already_AddRefed<nsDOMCameraManager>
|
2013-07-12 07:35:44 -07:00
|
|
|
CreateInstance(nsPIDOMWindow* aWindow);
|
2012-09-30 17:37:47 -07:00
|
|
|
static bool IsWindowStillActive(uint64_t aWindowId);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2012-09-30 17:37:47 -07:00
|
|
|
void Register(mozilla::nsDOMCameraControl* aDOMCameraControl);
|
2012-08-22 08:56:38 -07:00
|
|
|
void OnNavigation(uint64_t aWindowId);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-04-01 21:08:42 -07:00
|
|
|
void PermissionAllowed(uint32_t aCameraId,
|
|
|
|
const mozilla::dom::CameraConfiguration& aOptions,
|
|
|
|
mozilla::dom::GetCameraCallback* aOnSuccess,
|
2014-10-03 01:19:00 -07:00
|
|
|
mozilla::dom::CameraErrorCallback* aOnError,
|
|
|
|
mozilla::dom::Promise* aPromise);
|
2014-04-01 21:08:42 -07:00
|
|
|
|
|
|
|
void PermissionCancelled(uint32_t aCameraId,
|
|
|
|
const mozilla::dom::CameraConfiguration& aOptions,
|
|
|
|
mozilla::dom::GetCameraCallback* aOnSuccess,
|
2014-10-03 01:19:00 -07:00
|
|
|
mozilla::dom::CameraErrorCallback* aOnError,
|
|
|
|
mozilla::dom::Promise* aPromise);
|
2014-04-01 21:08:42 -07:00
|
|
|
|
2013-05-09 23:25:25 -07:00
|
|
|
// WebIDL
|
2014-10-03 01:19:00 -07:00
|
|
|
already_AddRefed<mozilla::dom::Promise>
|
|
|
|
GetCamera(const nsAString& aCamera,
|
|
|
|
const mozilla::dom::CameraConfiguration& aOptions,
|
|
|
|
const OptionalNonNullGetCameraCallback& aOnSuccess,
|
|
|
|
const OptionalNonNullCameraErrorCallback& aOnError,
|
|
|
|
mozilla::ErrorResult& aRv);
|
2013-05-09 23:25:25 -07:00
|
|
|
void GetListOfCameras(nsTArray<nsString>& aList, mozilla::ErrorResult& aRv);
|
|
|
|
|
|
|
|
nsPIDOMWindow* GetParentObject() const { return mWindow; }
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx)
|
2013-05-09 23:25:25 -07:00
|
|
|
MOZ_OVERRIDE;
|
|
|
|
|
2012-09-30 17:37:47 -07:00
|
|
|
protected:
|
|
|
|
void XpComShutdown();
|
|
|
|
void Shutdown(uint64_t aWindowId);
|
|
|
|
~nsDOMCameraManager();
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
private:
|
2013-02-15 00:04:11 -08:00
|
|
|
nsDOMCameraManager() MOZ_DELETE;
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit nsDOMCameraManager(nsPIDOMWindow* aWindow);
|
2012-07-30 14:59:05 -07:00
|
|
|
nsDOMCameraManager(const nsDOMCameraManager&) MOZ_DELETE;
|
|
|
|
nsDOMCameraManager& operator=(const nsDOMCameraManager&) MOZ_DELETE;
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mWindowId;
|
2014-04-01 21:08:42 -07:00
|
|
|
uint32_t mPermission;
|
2013-05-09 23:25:25 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> mWindow;
|
2012-09-30 17:37:47 -07:00
|
|
|
/**
|
2014-02-14 14:41:07 -08:00
|
|
|
* 'sActiveWindows' is only ever accessed while in the Main Thread,
|
2012-09-30 17:37:47 -07:00
|
|
|
* so it is not otherwise protected.
|
|
|
|
*/
|
2013-11-20 08:29:03 -08:00
|
|
|
static ::WindowTable* sActiveWindows;
|
2012-07-30 14:59:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DOM_CAMERA_DOMCAMERAMANAGER_H
|