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