2012-07-30 21:59:05 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
#include "DOMCameraManager.h"
|
2012-09-21 10:32:18 +00:00
|
|
|
#include "nsDebug.h"
|
2014-02-14 22:41:07 +00:00
|
|
|
#include "jsapi.h"
|
2014-04-09 15:53:34 +00:00
|
|
|
#include "Navigator.h"
|
2012-10-01 00:37:47 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "mozilla/Services.h"
|
2014-04-02 04:08:42 +00:00
|
|
|
#include "nsContentPermissionHelper.h"
|
2014-08-01 07:22:20 +00:00
|
|
|
#include "nsIContentPermissionPrompt.h"
|
2014-04-14 19:04:27 +00:00
|
|
|
#include "nsIObserverService.h"
|
2012-09-21 10:32:18 +00:00
|
|
|
#include "nsIPermissionManager.h"
|
2014-08-01 07:22:20 +00:00
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
2012-09-05 01:01:56 +00:00
|
|
|
#include "DOMCameraControl.h"
|
2012-07-30 21:59:05 +00:00
|
|
|
#include "nsDOMClassInfo.h"
|
|
|
|
#include "CameraCommon.h"
|
2014-02-14 22:41:07 +00:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-05-10 06:25:25 +00:00
|
|
|
#include "mozilla/dom/CameraManagerBinding.h"
|
2014-04-02 04:08:42 +00:00
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-05-10 06:25:25 +00:00
|
|
|
using namespace mozilla::dom;
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2014-04-29 08:57:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsDOMCameraManager, mWindow)
|
2012-10-01 00:37:47 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCameraManager)
|
2014-08-25 15:14:49 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2013-05-14 10:59:11 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
|
2012-10-01 00:37:47 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2014-02-14 22:41:07 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
2012-07-30 21:59:05 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-10-01 00:37:47 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCameraManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCameraManager)
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2012-09-05 01:01:56 +00:00
|
|
|
/**
|
|
|
|
* Global camera logging object
|
|
|
|
*
|
|
|
|
* Set the NSPR_LOG_MODULES environment variable to enable logging
|
|
|
|
* in a debug build, e.g. NSPR_LOG_MODULES=Camera:5
|
|
|
|
*/
|
2012-10-29 23:32:10 +00:00
|
|
|
PRLogModuleInfo*
|
|
|
|
GetCameraLog()
|
|
|
|
{
|
|
|
|
static PRLogModuleInfo *sLog;
|
2014-02-14 22:41:07 +00:00
|
|
|
if (!sLog) {
|
2012-10-29 23:32:10 +00:00
|
|
|
sLog = PR_NewLogModule("Camera");
|
2014-02-14 22:41:07 +00:00
|
|
|
}
|
2012-10-29 23:32:10 +00:00
|
|
|
return sLog;
|
|
|
|
}
|
2012-09-05 01:01:56 +00:00
|
|
|
|
2014-09-24 22:43:26 +00:00
|
|
|
::WindowTable* nsDOMCameraManager::sActiveWindows = nullptr;
|
2012-10-01 00:37:47 +00:00
|
|
|
|
2013-05-10 06:25:25 +00:00
|
|
|
nsDOMCameraManager::nsDOMCameraManager(nsPIDOMWindow* aWindow)
|
|
|
|
: mWindowId(aWindow->WindowID())
|
2014-04-02 04:08:42 +00:00
|
|
|
, mPermission(nsIPermissionManager::DENY_ACTION)
|
2013-05-10 06:25:25 +00:00
|
|
|
, mWindow(aWindow)
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
/* member initializers and constructor code */
|
2014-10-31 17:19:06 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p, windowId=%" PRIx64 "\n", __func__, __LINE__, this, mWindowId);
|
2014-02-14 22:41:07 +00:00
|
|
|
MOZ_COUNT_CTOR(nsDOMCameraManager);
|
2012-07-30 21:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCameraManager::~nsDOMCameraManager()
|
|
|
|
{
|
|
|
|
/* destructor code */
|
2014-02-14 22:41:07 +00:00
|
|
|
MOZ_COUNT_DTOR(nsDOMCameraManager);
|
2012-09-05 01:01:56 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
2014-02-14 22:41:07 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 15:53:34 +00:00
|
|
|
/* static */
|
2014-02-14 22:41:07 +00:00
|
|
|
void
|
|
|
|
nsDOMCameraManager::GetListOfCameras(nsTArray<nsString>& aList, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = ICameraControl::GetListOfCameras(aList);
|
2012-07-30 21:59:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 15:53:34 +00:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
nsDOMCameraManager::HasSupport(JSContext* aCx, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
return Navigator::HasCameraSupport(aCx, aGlobal);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2013-07-12 14:35:44 +00:00
|
|
|
bool
|
|
|
|
nsDOMCameraManager::CheckPermission(nsPIDOMWindow* aWindow)
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
2012-09-21 10:32:18 +00:00
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
2014-04-29 17:27:26 +00:00
|
|
|
services::GetPermissionManager();
|
2013-07-12 14:35:44 +00:00
|
|
|
NS_ENSURE_TRUE(permMgr, false);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2012-09-21 10:32:18 +00:00
|
|
|
uint32_t permission = nsIPermissionManager::DENY_ACTION;
|
|
|
|
permMgr->TestPermissionFromWindow(aWindow, "camera", &permission);
|
2014-04-02 04:08:42 +00:00
|
|
|
if (permission != nsIPermissionManager::ALLOW_ACTION &&
|
|
|
|
permission != nsIPermissionManager::PROMPT_ACTION) {
|
2013-07-12 14:35:44 +00:00
|
|
|
return false;
|
2012-09-05 01:01:56 +00:00
|
|
|
}
|
2012-09-21 10:32:18 +00:00
|
|
|
|
2013-07-12 14:35:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-09 15:53:34 +00:00
|
|
|
/* static */
|
2013-07-12 14:35:44 +00:00
|
|
|
already_AddRefed<nsDOMCameraManager>
|
|
|
|
nsDOMCameraManager::CreateInstance(nsPIDOMWindow* aWindow)
|
|
|
|
{
|
2012-10-01 00:37:47 +00:00
|
|
|
// Initialize the shared active window tracker
|
2013-09-02 08:41:57 +00:00
|
|
|
if (!sActiveWindows) {
|
2014-09-24 22:43:26 +00:00
|
|
|
sActiveWindows = new ::WindowTable();
|
2012-10-01 00:37:47 +00:00
|
|
|
}
|
|
|
|
|
2012-09-21 10:32:18 +00:00
|
|
|
nsRefPtr<nsDOMCameraManager> cameraManager =
|
2013-05-10 06:25:25 +00:00
|
|
|
new nsDOMCameraManager(aWindow);
|
2012-10-01 00:37:47 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
2014-08-25 15:14:49 +00:00
|
|
|
if (!obs) {
|
|
|
|
DOM_CAMERA_LOGE("Camera manager failed to get observer service\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = obs->AddObserver(cameraManager, "xpcom-shutdown", true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Camera manager failed to add 'xpcom-shutdown' observer (0x%x)\n", rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-10-01 00:37:47 +00:00
|
|
|
|
2012-07-30 21:59:05 +00:00
|
|
|
return cameraManager.forget();
|
|
|
|
}
|
|
|
|
|
2014-04-02 04:08:42 +00:00
|
|
|
class CameraPermissionRequest : public nsIContentPermissionRequest
|
|
|
|
, public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_NSICONTENTPERMISSIONREQUEST
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(CameraPermissionRequest,
|
|
|
|
nsIContentPermissionRequest)
|
|
|
|
|
|
|
|
CameraPermissionRequest(nsIPrincipal* aPrincipal,
|
|
|
|
nsPIDOMWindow* aWindow,
|
|
|
|
nsRefPtr<nsDOMCameraManager> aManager,
|
|
|
|
uint32_t aCameraId,
|
|
|
|
const CameraConfiguration& aInitialConfig,
|
2014-10-03 08:19:00 +00:00
|
|
|
nsRefPtr<Promise> aPromise)
|
2014-04-02 04:08:42 +00:00
|
|
|
: mPrincipal(aPrincipal)
|
|
|
|
, mWindow(aWindow)
|
|
|
|
, mCameraManager(aManager)
|
|
|
|
, mCameraId(aCameraId)
|
|
|
|
, mInitialConfig(aInitialConfig)
|
2014-10-03 08:19:00 +00:00
|
|
|
, mPromise(aPromise)
|
2014-12-11 16:02:51 +00:00
|
|
|
{ }
|
2014-04-02 04:08:42 +00:00
|
|
|
|
|
|
|
protected:
|
2014-12-11 16:02:51 +00:00
|
|
|
virtual ~CameraPermissionRequest() { }
|
2014-06-23 19:56:07 +00:00
|
|
|
|
2014-04-02 04:08:42 +00:00
|
|
|
nsresult DispatchCallback(uint32_t aPermission);
|
|
|
|
void CallAllow();
|
|
|
|
void CallCancel();
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
nsCOMPtr<nsPIDOMWindow> mWindow;
|
|
|
|
nsRefPtr<nsDOMCameraManager> mCameraManager;
|
|
|
|
uint32_t mCameraId;
|
|
|
|
CameraConfiguration mInitialConfig;
|
2014-10-03 08:19:00 +00:00
|
|
|
nsRefPtr<Promise> mPromise;
|
2014-04-02 04:08:42 +00:00
|
|
|
};
|
|
|
|
|
2014-12-11 16:02:51 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(CameraPermissionRequest, mWindow, mPromise)
|
2014-04-02 04:08:42 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CameraPermissionRequest)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentPermissionRequest)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRunnable)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentPermissionRequest)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(CameraPermissionRequest)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(CameraPermissionRequest)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CameraPermissionRequest::Run()
|
|
|
|
{
|
2014-08-01 07:22:20 +00:00
|
|
|
return nsContentPermissionUtils::AskPermission(this, mWindow);
|
2014-04-02 04:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CameraPermissionRequest::GetPrincipal(nsIPrincipal** aRequestingPrincipal)
|
|
|
|
{
|
|
|
|
NS_ADDREF(*aRequestingPrincipal = mPrincipal);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CameraPermissionRequest::GetWindow(nsIDOMWindow** aRequestingWindow)
|
|
|
|
{
|
|
|
|
NS_ADDREF(*aRequestingWindow = mWindow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CameraPermissionRequest::GetElement(nsIDOMElement** aElement)
|
|
|
|
{
|
|
|
|
*aElement = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CameraPermissionRequest::Cancel()
|
|
|
|
{
|
|
|
|
return DispatchCallback(nsIPermissionManager::DENY_ACTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CameraPermissionRequest::Allow(JS::HandleValue aChoices)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aChoices.isUndefined());
|
|
|
|
return DispatchCallback(nsIPermissionManager::ALLOW_ACTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CameraPermissionRequest::DispatchCallback(uint32_t aPermission)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> callbackRunnable;
|
|
|
|
if (aPermission == nsIPermissionManager::ALLOW_ACTION) {
|
|
|
|
callbackRunnable = NS_NewRunnableMethod(this, &CameraPermissionRequest::CallAllow);
|
|
|
|
} else {
|
|
|
|
callbackRunnable = NS_NewRunnableMethod(this, &CameraPermissionRequest::CallCancel);
|
|
|
|
}
|
|
|
|
return NS_DispatchToMainThread(callbackRunnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CameraPermissionRequest::CallAllow()
|
|
|
|
{
|
2014-12-11 16:02:51 +00:00
|
|
|
mCameraManager->PermissionAllowed(mCameraId, mInitialConfig, mPromise);
|
2014-04-02 04:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CameraPermissionRequest::CallCancel()
|
|
|
|
{
|
2014-12-11 16:02:51 +00:00
|
|
|
mCameraManager->PermissionCancelled(mCameraId, mInitialConfig, mPromise);
|
2014-04-02 04:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CameraPermissionRequest::GetTypes(nsIArray** aTypes)
|
|
|
|
{
|
|
|
|
nsTArray<nsString> emptyOptions;
|
2014-08-01 07:22:20 +00:00
|
|
|
return nsContentPermissionUtils::CreatePermissionArray(NS_LITERAL_CSTRING("camera"),
|
|
|
|
NS_LITERAL_CSTRING("unused"),
|
|
|
|
emptyOptions,
|
|
|
|
aTypes);
|
2014-04-02 04:08:42 +00:00
|
|
|
}
|
|
|
|
|
2014-10-31 17:54:02 +00:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
/* static */ void
|
|
|
|
nsDOMCameraManager::PreinitCameraHardware()
|
|
|
|
{
|
|
|
|
nsDOMCameraControl::PreinitCameraHardware();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-03 08:19:00 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-02-14 22:41:07 +00:00
|
|
|
nsDOMCameraManager::GetCamera(const nsAString& aCamera,
|
|
|
|
const CameraConfiguration& aInitialConfig,
|
2013-05-10 06:25:25 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-02-14 22:41:07 +00:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
|
2013-05-10 06:25:25 +00:00
|
|
|
uint32_t cameraId = 0; // back (or forward-facing) camera by default
|
2014-02-14 22:41:07 +00:00
|
|
|
if (aCamera.EqualsLiteral("front")) {
|
2013-05-10 06:25:25 +00:00
|
|
|
cameraId = 1;
|
|
|
|
}
|
|
|
|
|
2014-10-03 08:19:00 +00:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
|
|
|
|
if (!global) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-04-02 04:08:42 +00:00
|
|
|
if (mPermission == nsIPermissionManager::ALLOW_ACTION) {
|
2014-12-11 16:02:51 +00:00
|
|
|
PermissionAllowed(cameraId, aInitialConfig, promise);
|
2014-10-03 08:19:00 +00:00
|
|
|
return promise.forget();
|
2014-04-02 04:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mWindow);
|
|
|
|
if (!sop) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
2014-10-03 08:19:00 +00:00
|
|
|
return nullptr;
|
2014-04-02 04:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
|
2014-10-28 15:54:38 +00:00
|
|
|
// If we are a CERTIFIED app, we can short-circuit the permission check,
|
|
|
|
// which gets us a performance win.
|
|
|
|
uint16_t status = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
|
|
|
|
principal->GetAppStatus(&status);
|
|
|
|
if (status == nsIPrincipal::APP_STATUS_CERTIFIED && CheckPermission(mWindow)) {
|
2014-12-11 16:02:51 +00:00
|
|
|
PermissionAllowed(cameraId, aInitialConfig, promise);
|
2014-10-28 15:54:38 +00:00
|
|
|
return promise.forget();
|
|
|
|
}
|
2014-04-02 04:08:42 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> permissionRequest =
|
2014-12-11 16:02:51 +00:00
|
|
|
new CameraPermissionRequest(principal, mWindow, this, cameraId,
|
|
|
|
aInitialConfig, promise);
|
2014-04-02 04:08:42 +00:00
|
|
|
|
|
|
|
NS_DispatchToMainThread(permissionRequest);
|
2014-10-03 08:19:00 +00:00
|
|
|
return promise.forget();
|
2014-04-02 04:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraManager::PermissionAllowed(uint32_t aCameraId,
|
|
|
|
const CameraConfiguration& aInitialConfig,
|
2014-10-03 08:19:00 +00:00
|
|
|
Promise* aPromise)
|
2014-04-02 04:08:42 +00:00
|
|
|
{
|
|
|
|
mPermission = nsIPermissionManager::ALLOW_ACTION;
|
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
// Creating this object will trigger the aOnSuccess callback
|
|
|
|
// (or the aOnError one, if it fails).
|
2013-07-06 20:55:10 +00:00
|
|
|
nsRefPtr<nsDOMCameraControl> cameraControl =
|
2014-12-11 16:02:51 +00:00
|
|
|
new nsDOMCameraControl(aCameraId, aInitialConfig, aPromise, mWindow);
|
2013-12-10 07:38:43 +00:00
|
|
|
|
|
|
|
Register(cameraControl);
|
2013-05-10 06:25:25 +00:00
|
|
|
}
|
|
|
|
|
2014-04-02 04:08:42 +00:00
|
|
|
void
|
|
|
|
nsDOMCameraManager::PermissionCancelled(uint32_t aCameraId,
|
|
|
|
const CameraConfiguration& aInitialConfig,
|
2014-10-03 08:19:00 +00:00
|
|
|
Promise* aPromise)
|
2014-04-02 04:08:42 +00:00
|
|
|
{
|
|
|
|
mPermission = nsIPermissionManager::DENY_ACTION;
|
2014-10-03 08:19:00 +00:00
|
|
|
aPromise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
2014-04-02 04:08:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-01 00:37:47 +00:00
|
|
|
void
|
|
|
|
nsDOMCameraManager::Register(nsDOMCameraControl* aDOMCameraControl)
|
|
|
|
{
|
2014-10-31 17:19:06 +00:00
|
|
|
DOM_CAMERA_LOGI(">>> Register( aDOMCameraControl = %p ) mWindowId = 0x%" PRIx64 "\n", aDOMCameraControl, mWindowId);
|
2012-10-01 00:37:47 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
CameraControls* controls = sActiveWindows->Get(mWindowId);
|
2012-10-01 00:37:47 +00:00
|
|
|
if (!controls) {
|
2014-12-13 02:18:03 +00:00
|
|
|
controls = new CameraControls();
|
2013-09-02 08:41:57 +00:00
|
|
|
sActiveWindows->Put(mWindowId, controls);
|
2012-10-01 00:37:47 +00:00
|
|
|
}
|
2014-12-13 02:18:03 +00:00
|
|
|
|
|
|
|
// Remove any stale CameraControl objects to limit our memory usage
|
|
|
|
uint32_t i = controls->Length();
|
|
|
|
while (i > 0) {
|
|
|
|
--i;
|
|
|
|
nsRefPtr<nsDOMCameraControl> cameraControl =
|
|
|
|
do_QueryObject(controls->ElementAt(i));
|
|
|
|
if (!cameraControl) {
|
|
|
|
controls->RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put the camera control into the hash table
|
|
|
|
nsWeakPtr cameraControl =
|
|
|
|
do_GetWeakReference(static_cast<DOMMediaStream*>(aDOMCameraControl));
|
|
|
|
controls->AppendElement(cameraControl);
|
2012-10-01 00:37:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraManager::Shutdown(uint64_t aWindowId)
|
|
|
|
{
|
2014-10-31 17:19:06 +00:00
|
|
|
DOM_CAMERA_LOGI(">>> Shutdown( aWindowId = 0x%" PRIx64 " )\n", aWindowId);
|
2012-10-01 00:37:47 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
CameraControls* controls = sActiveWindows->Get(aWindowId);
|
2012-10-01 00:37:47 +00:00
|
|
|
if (!controls) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-13 02:18:03 +00:00
|
|
|
uint32_t i = controls->Length();
|
|
|
|
while (i > 0) {
|
|
|
|
--i;
|
|
|
|
nsRefPtr<nsDOMCameraControl> cameraControl =
|
|
|
|
do_QueryObject(controls->ElementAt(i));
|
|
|
|
if (cameraControl) {
|
|
|
|
cameraControl->Shutdown();
|
|
|
|
}
|
2012-10-01 00:37:47 +00:00
|
|
|
}
|
|
|
|
controls->Clear();
|
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
sActiveWindows->Remove(aWindowId);
|
2012-10-01 00:37:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraManager::XpComShutdown()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGI(">>> XPCOM Shutdown\n");
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
obs->RemoveObserver(this, "xpcom-shutdown");
|
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
delete sActiveWindows;
|
|
|
|
sActiveWindows = nullptr;
|
2012-10-01 00:37:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 15:02:17 +00:00
|
|
|
nsDOMCameraManager::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
|
2012-10-01 00:37:47 +00:00
|
|
|
{
|
|
|
|
if (strcmp(aTopic, "xpcom-shutdown") == 0) {
|
|
|
|
XpComShutdown();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMCameraManager::OnNavigation(uint64_t aWindowId)
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGI(">>> OnNavigation event\n");
|
|
|
|
Shutdown(aWindowId);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDOMCameraManager::IsWindowStillActive(uint64_t aWindowId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
if (!sActiveWindows) {
|
2012-10-01 00:37:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
return !!sActiveWindows->Get(aWindowId);
|
2012-10-01 00:37:47 +00:00
|
|
|
}
|
2013-05-10 06:25:25 +00:00
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
nsDOMCameraManager::WrapObject(JSContext* aCx)
|
2013-05-10 06:25:25 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return CameraManagerBinding::Wrap(aCx, this);
|
2013-05-10 06:25:25 +00:00
|
|
|
}
|