mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
90 lines
2.6 KiB
C++
90 lines
2.6 KiB
C++
/* 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/. */
|
|
|
|
#include "CameraControl.h"
|
|
#include "DOMCameraManager.h"
|
|
#include "nsDOMClassInfo.h"
|
|
#include "DictionaryHelpers.h"
|
|
|
|
#define DOM_CAMERA_LOG_LEVEL 3
|
|
#include "CameraCommon.h"
|
|
|
|
using namespace mozilla;
|
|
|
|
DOMCI_DATA(CameraManager, nsIDOMCameraManager)
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMCameraManager)
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCameraManager)
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CameraManager)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
NS_IMPL_ADDREF(nsDOMCameraManager)
|
|
NS_IMPL_RELEASE(nsDOMCameraManager)
|
|
|
|
/**
|
|
* nsDOMCameraManager::GetListOfCameras
|
|
* is implementation-specific, and can be found in (e.g.)
|
|
* GonkCameraManager.cpp and FallbackCameraManager.cpp.
|
|
*/
|
|
|
|
nsDOMCameraManager::nsDOMCameraManager(PRUint64 aWindowId)
|
|
: mWindowId(aWindowId)
|
|
{
|
|
/* member initializers and constructor code */
|
|
DOM_CAMERA_LOGI("%s:%d\n", __func__, __LINE__);
|
|
}
|
|
|
|
nsDOMCameraManager::~nsDOMCameraManager()
|
|
{
|
|
/* destructor code */
|
|
DOM_CAMERA_LOGI("%s:%d\n", __func__, __LINE__);
|
|
}
|
|
|
|
void
|
|
nsDOMCameraManager::OnNavigation(PRUint64 aWindowId)
|
|
{
|
|
// TODO: implement -- see getUserMedia() implementation
|
|
}
|
|
|
|
// static creator
|
|
already_AddRefed<nsDOMCameraManager>
|
|
nsDOMCameraManager::Create(PRUint64 aWindowId)
|
|
{
|
|
// TODO: check for permissions here to access cameras
|
|
|
|
nsRefPtr<nsDOMCameraManager> cameraManager = new nsDOMCameraManager(aWindowId);
|
|
return cameraManager.forget();
|
|
}
|
|
|
|
/* [implicit_jscontext] void getCamera ([optional] in jsval aOptions, in nsICameraGetCameraCallback onSuccess, [optional] in nsICameraErrorCallback onError); */
|
|
NS_IMETHODIMP
|
|
nsDOMCameraManager::GetCamera(const JS::Value& aOptions, nsICameraGetCameraCallback* onSuccess, nsICameraErrorCallback* onError, JSContext* cx)
|
|
{
|
|
NS_ENSURE_TRUE(onSuccess, NS_ERROR_INVALID_ARG);
|
|
|
|
PRUint32 cameraId = 0; // back (or forward-facing) camera by default
|
|
CameraSelector selector;
|
|
|
|
nsresult rv = selector.Init(cx, &aOptions);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (selector.camera.EqualsASCII("front")) {
|
|
cameraId = 1;
|
|
}
|
|
|
|
// reuse the same camera thread to conserve resources
|
|
if (!mCameraThread) {
|
|
rv = NS_NewThread(getter_AddRefs(mCameraThread));
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
|
|
DOM_CAMERA_LOGI("%s:%d\n", __func__, __LINE__);
|
|
|
|
nsCOMPtr<nsIRunnable> getCameraTask = new GetCameraTask(cameraId, onSuccess, onError, mCameraThread);
|
|
mCameraThread->Dispatch(getCameraTask, NS_DISPATCH_NORMAL);
|
|
|
|
return NS_OK;
|
|
}
|