mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 870678 - convert CameraManager to webidl r=bz
This commit is contained in:
parent
eb31476a13
commit
22b7362f5a
@ -158,6 +158,11 @@ DOMInterfaces = {
|
||||
'headerFile': 'BatteryManager.h'
|
||||
},
|
||||
|
||||
'CameraManager': {
|
||||
'nativeType': 'nsDOMCameraManager',
|
||||
'headerFile': 'DOMCameraManager.h'
|
||||
},
|
||||
|
||||
'CanvasRenderingContext2D': {
|
||||
'implicitJSContext': [
|
||||
'createImageData', 'getImageData', 'strokeStyle',
|
||||
@ -1647,3 +1652,5 @@ addExternalIface('XPathExpression')
|
||||
addExternalIface('XPathNSResolver')
|
||||
addExternalIface('XULCommandDispatcher')
|
||||
addExternalIface('DataTransfer', notflattened=True)
|
||||
addExternalIface('GetCameraCallback', nativeType='nsICameraGetCameraCallback', headerFile='nsIDOMCameraManager.h')
|
||||
addExternalIface('CameraErrorCallback', nativeType='nsICameraErrorCallback', headerFile='nsIDOMCameraManager.h')
|
||||
|
@ -2,6 +2,7 @@
|
||||
* 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 "nsContentUtils.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "mozilla/Services.h"
|
||||
@ -12,20 +13,21 @@
|
||||
#include "nsDOMClassInfo.h"
|
||||
#include "DictionaryHelpers.h"
|
||||
#include "CameraCommon.h"
|
||||
#include "mozilla/dom/CameraManagerBinding.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace dom;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
DOMCI_DATA(CameraManager, nsIDOMCameraManager)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_1(nsDOMCameraManager,
|
||||
mCameraThread)
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMCameraManager, mWindow)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCameraManager)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCameraManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMCameraManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CameraManager)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCameraManager)
|
||||
@ -55,12 +57,14 @@ GetCameraLog()
|
||||
WindowTable nsDOMCameraManager::sActiveWindows;
|
||||
bool nsDOMCameraManager::sActiveWindowsInitialized = false;
|
||||
|
||||
nsDOMCameraManager::nsDOMCameraManager(uint64_t aWindowId)
|
||||
: mWindowId(aWindowId)
|
||||
nsDOMCameraManager::nsDOMCameraManager(nsPIDOMWindow* aWindow)
|
||||
: mWindowId(aWindow->WindowID())
|
||||
, mCameraThread(nullptr)
|
||||
, mWindow(aWindow)
|
||||
{
|
||||
/* member initializers and constructor code */
|
||||
DOM_CAMERA_LOGT("%s:%d : this=%p, windowId=%llx\n", __func__, __LINE__, this, mWindowId);
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
nsDOMCameraManager::~nsDOMCameraManager()
|
||||
@ -93,7 +97,7 @@ nsDOMCameraManager::CheckPermissionAndCreateInstance(nsPIDOMWindow* aWindow)
|
||||
}
|
||||
|
||||
nsRefPtr<nsDOMCameraManager> cameraManager =
|
||||
new nsDOMCameraManager(aWindow->WindowID());
|
||||
new nsDOMCameraManager(aWindow);
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
obs->AddObserver(cameraManager, "xpcom-shutdown", true);
|
||||
@ -132,6 +136,42 @@ nsDOMCameraManager::GetCamera(const JS::Value& aOptions, nsICameraGetCameraCallb
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMCameraManager::GetCamera(JSContext* aCx, const JS::Value aOptions,
|
||||
nsICameraGetCameraCallback* onSuccess,
|
||||
const Optional<nsICameraErrorCallback*>& onError,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
uint32_t cameraId = 0; // back (or forward-facing) camera by default
|
||||
mozilla::idl::CameraSelector selector;
|
||||
|
||||
aRv = selector.Init(aCx, &aOptions);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selector.camera.EqualsLiteral("front")) {
|
||||
cameraId = 1;
|
||||
}
|
||||
|
||||
// reuse the same camera thread to conserve resources
|
||||
if (!mCameraThread) {
|
||||
aRv = NS_NewThread(getter_AddRefs(mCameraThread));
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
||||
|
||||
// Creating this object will trigger the onSuccess handler
|
||||
nsCOMPtr<nsDOMCameraControl> cameraControl =
|
||||
new nsDOMCameraControl(cameraId, mCameraThread,
|
||||
onSuccess, onError.WasPassed() ? onError.Value() : nullptr, mWindowId);
|
||||
|
||||
Register(cameraControl);
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMCameraManager::Register(nsDOMCameraControl* aDOMCameraControl)
|
||||
{
|
||||
@ -207,3 +247,9 @@ nsDOMCameraManager::IsWindowStillActive(uint64_t aWindowId)
|
||||
|
||||
return !!sActiveWindows.Get(aWindowId);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
nsDOMCameraManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||
{
|
||||
return CameraManagerBinding::Wrap(aCx, aScope, this);
|
||||
}
|
||||
|
@ -7,12 +7,14 @@
|
||||
#ifndef DOM_CAMERA_DOMCAMERAMANAGER_H
|
||||
#define DOM_CAMERA_DOMCAMERAMANAGER_H
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "nsIDOMCameraManager.h"
|
||||
@ -22,6 +24,7 @@
|
||||
class nsPIDOMWindow;
|
||||
|
||||
namespace mozilla {
|
||||
class ErrorResult;
|
||||
class nsDOMCameraControl;
|
||||
}
|
||||
|
||||
@ -32,10 +35,12 @@ class nsDOMCameraManager MOZ_FINAL
|
||||
: public nsIDOMCameraManager
|
||||
, public nsIObserver
|
||||
, public nsSupportsWeakReference
|
||||
, public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsDOMCameraManager, nsIObserver)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMCameraManager,
|
||||
nsIDOMCameraManager)
|
||||
NS_DECL_NSIDOMCAMERAMANAGER
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
@ -49,6 +54,17 @@ public:
|
||||
nsresult GetNumberOfCameras(int32_t& aDeviceCount);
|
||||
nsresult GetCameraName(uint32_t aDeviceNum, nsCString& aDeviceName);
|
||||
|
||||
// WebIDL
|
||||
void GetCamera(JSContext* aCx, const JS::Value aOptions,
|
||||
nsICameraGetCameraCallback* aCallback,
|
||||
const mozilla::dom::Optional<nsICameraErrorCallback*>& ErrorCallback,
|
||||
mozilla::ErrorResult& aRv);
|
||||
void GetListOfCameras(nsTArray<nsString>& aList, mozilla::ErrorResult& aRv);
|
||||
|
||||
nsPIDOMWindow* GetParentObject() const { return mWindow; }
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||
MOZ_OVERRIDE;
|
||||
|
||||
protected:
|
||||
void XpComShutdown();
|
||||
void Shutdown(uint64_t aWindowId);
|
||||
@ -56,13 +72,14 @@ protected:
|
||||
|
||||
private:
|
||||
nsDOMCameraManager() MOZ_DELETE;
|
||||
nsDOMCameraManager(uint64_t aWindowId);
|
||||
nsDOMCameraManager(nsPIDOMWindow* aWindow);
|
||||
nsDOMCameraManager(const nsDOMCameraManager&) MOZ_DELETE;
|
||||
nsDOMCameraManager& operator=(const nsDOMCameraManager&) MOZ_DELETE;
|
||||
|
||||
protected:
|
||||
uint64_t mWindowId;
|
||||
nsCOMPtr<nsIThread> mCameraThread;
|
||||
nsCOMPtr<nsPIDOMWindow> mWindow;
|
||||
/**
|
||||
* 'mActiveWindows' is only ever accessed while in the main thread,
|
||||
* so it is not otherwise protected.
|
||||
|
@ -4,6 +4,10 @@
|
||||
|
||||
#include "DOMCameraManager.h"
|
||||
|
||||
#include "mozilla/ErrorResult.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
// From nsDOMCameraManager.
|
||||
nsresult
|
||||
nsDOMCameraManager::GetNumberOfCameras(int32_t& aDeviceCount)
|
||||
@ -23,3 +27,9 @@ nsDOMCameraManager::GetListOfCameras(uint32_t *aCount, char * **aCameras)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMCameraManager::GetListOfCameras(nsTArray<nsString>& aList, ErrorResult& aRv)
|
||||
{
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
@ -20,6 +20,9 @@
|
||||
#include "GonkCameraControl.h"
|
||||
#include "DOMCameraManager.h"
|
||||
#include "CameraCommon.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
// From nsDOMCameraManager, but gonk-specific!
|
||||
nsresult
|
||||
@ -130,3 +133,48 @@ nsDOMCameraManager::GetListOfCameras(uint32_t *aCount, char * **aCameras)
|
||||
*aCount = arraySize - offset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMCameraManager::GetListOfCameras(nsTArray<nsString>& aList, ErrorResult& aRv)
|
||||
{
|
||||
int32_t count = android::Camera::getNumberOfCameras();
|
||||
if (count <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
DOM_CAMERA_LOGI("getListOfCameras : getNumberOfCameras() returned %d\n", count);
|
||||
|
||||
// Allocate 2 extra slots to reserve space for 'front' and 'back' cameras
|
||||
// at the front of the array--we will collapse any empty slots below.
|
||||
aList.SetLength(2);
|
||||
uint32_t extraIdx = 2;
|
||||
bool gotFront = false, gotBack = false;
|
||||
while (count--) {
|
||||
nsCString cameraName;
|
||||
nsresult result = GetCameraName(count, cameraName);
|
||||
if (result != NS_OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// The first camera we find named 'back' gets slot 0; and the first
|
||||
// we find named 'front' gets slot 1. All others appear after these.
|
||||
if (cameraName.EqualsLiteral("back")) {
|
||||
CopyUTF8toUTF16(cameraName, aList[0]);
|
||||
gotBack = true;
|
||||
} else if (cameraName.EqualsLiteral("front")) {
|
||||
CopyUTF8toUTF16(cameraName, aList[1]);
|
||||
gotFront = true;
|
||||
} else {
|
||||
CopyUTF8toUTF16(cameraName, *aList.InsertElementAt(extraIdx));
|
||||
extraIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!gotFront) {
|
||||
aList.RemoveElementAt(1);
|
||||
}
|
||||
|
||||
if (!gotBack) {
|
||||
aList.RemoveElementAt(0);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* 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/.
|
||||
@ -46,3 +47,14 @@ dictionary CameraPictureOptions {
|
||||
};
|
||||
|
||||
// If we start using CameraPictureOptions here, remove it from DummyBinding.
|
||||
|
||||
interface GetCameraCallback;
|
||||
interface CameraErrorCallback;
|
||||
|
||||
interface CameraManager {
|
||||
[Throws]
|
||||
void getCamera(any options, GetCameraCallback callback,
|
||||
optional CameraErrorCallback errorCallback);
|
||||
[Throws]
|
||||
sequence<DOMString> getListOfCameras();
|
||||
};
|
||||
|
@ -28,6 +28,7 @@ webidl_files = \
|
||||
BeforeUnloadEvent.webidl \
|
||||
BiquadFilterNode.webidl \
|
||||
Blob.webidl \
|
||||
CameraManager.webidl \
|
||||
CanvasRenderingContext2D.webidl \
|
||||
CaretPosition.webidl \
|
||||
CDATASection.webidl \
|
||||
@ -39,7 +40,6 @@ webidl_files = \
|
||||
ClientRect.webidl \
|
||||
ClientRectList.webidl \
|
||||
ClipboardEvent.webidl \
|
||||
CameraManager.webidl \
|
||||
CommandEvent.webidl \
|
||||
Comment.webidl \
|
||||
CompositionEvent.webidl \
|
||||
|
Loading…
Reference in New Issue
Block a user