Skip to content

Commit

Permalink
Bug 740997 - ICS camera support, r=jst,gal,roc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Habicher committed Jul 30, 2012
1 parent 4237747 commit 9e245cc
Show file tree
Hide file tree
Showing 38 changed files with 4,807 additions and 6 deletions.
1 change: 1 addition & 0 deletions b2g/installer/package-manifest.in
Expand Up @@ -165,6 +165,7 @@
#ifdef MOZ_B2G_BT
@BINPATH@/components/dom_bluetooth.xpt
#endif
@BINPATH@/components/dom_camera.xpt
@BINPATH@/components/dom_canvas.xpt
@BINPATH@/components/dom_contacts.xpt
@BINPATH@/components/dom_alarm.xpt
Expand Down
1 change: 1 addition & 0 deletions browser/installer/package-manifest.in
Expand Up @@ -174,6 +174,7 @@
#ifdef MOZ_B2G_BT
@BINPATH@/components/dom_bluetooth.xpt
#endif
@BINPATH@/components/dom_camera.xpt
@BINPATH@/components/dom_canvas.xpt
@BINPATH@/components/dom_contacts.xpt
@BINPATH@/components/dom_alarm.xpt
Expand Down
1 change: 1 addition & 0 deletions config/autoconf.mk.in
Expand Up @@ -273,6 +273,7 @@ MOZ_NATIVE_NSS = @MOZ_NATIVE_NSS@

MOZ_B2G_RIL = @MOZ_B2G_RIL@
MOZ_B2G_BT = @MOZ_B2G_BT@
MOZ_B2G_CAMERA = @MOZ_B2G_CAMERA@

MOZ_SYS_MSG = @MOZ_SYS_MSG@

Expand Down
14 changes: 13 additions & 1 deletion configure.in
Expand Up @@ -192,7 +192,7 @@ if test -n "$gonkdir" ; then
;;
esac

CPPFLAGS="-DANDROID -isystem $gonkdir/bionic/libc/$ARCH_DIR/include -isystem $gonkdir/bionic/libc/include/ -isystem $gonkdir/bionic/libc/kernel/common -isystem $gonkdir/bionic/libc/kernel/$ARCH_DIR -isystem $gonkdir/bionic/libm/include -I$gonkdir/frameworks/base/opengl/include -I$gonkdir/frameworks/base/native/include -I$gonkdir/hardware/libhardware/include -I$gonkdir/hardware/libhardware_legacy/include -I$gonkdir/system -I$gonkdir/system/core/include -isystem $gonkdir/bionic -I$gonkdir/frameworks/base/include -I$gonkdir/external/dbus $CPPFLAGS -I$gonkdir/frameworks/base/services/sensorservice"
CPPFLAGS="-DANDROID -isystem $gonkdir/bionic/libc/$ARCH_DIR/include -isystem $gonkdir/bionic/libc/include/ -isystem $gonkdir/bionic/libc/kernel/common -isystem $gonkdir/bionic/libc/kernel/$ARCH_DIR -isystem $gonkdir/bionic/libm/include -I$gonkdir/frameworks/base/opengl/include -I$gonkdir/frameworks/base/native/include -I$gonkdir/hardware/libhardware/include -I$gonkdir/hardware/libhardware_legacy/include -I$gonkdir/system -I$gonkdir/system/core/include -isystem $gonkdir/bionic -I$gonkdir/frameworks/base/include -I$gonkdir/external/dbus $CPPFLAGS -I$gonkdir/frameworks/base/services/sensorservice -I$gonkdir/frameworks/base/services/camera"
CFLAGS="-mandroid -fno-short-enums -fno-exceptions $CFLAGS"
CXXFLAGS="-mandroid -fno-short-enums -fno-exceptions $CXXFLAGS $STLPORT_CPPFLAGS"
LIBS="$LIBS $STLPORT_LIBS"
Expand Down Expand Up @@ -7351,6 +7351,18 @@ if test -n "$MOZ_SYS_MSG"; then
fi
AC_SUBST(MOZ_SYS_MSG)

dnl ========================================================
dnl = Enable Camera Interface for B2G (Gonk usually)
dnl ========================================================
MOZ_ARG_ENABLE_BOOL(b2g-camera,
[ --enable-b2g-camera Set compile flags necessary for compiling camera API for B2G ],
MOZ_B2G_CAMERA=1,
MOZ_B2G_CAMERA= )
if test -n "$MOZ_B2G_CAMERA"; then
AC_DEFINE(MOZ_B2G_CAMERA)
fi
AC_SUBST(MOZ_B2G_CAMERA)

dnl ========================================================
dnl = Support for demangling undefined symbols
dnl ========================================================
Expand Down
1 change: 1 addition & 0 deletions dom/Makefile.in
Expand Up @@ -70,6 +70,7 @@ DIRS += \
ipc \
identity \
workers \
camera \
$(NULL)

ifdef MOZ_B2G_RIL
Expand Down
42 changes: 39 additions & 3 deletions dom/base/Navigator.cpp
Expand Up @@ -50,6 +50,8 @@
#include "nsIDOMBluetoothManager.h"
#include "BluetoothManager.h"
#endif
#include "nsIDOMCameraManager.h"
#include "DOMCameraManager.h"

#include "nsIDOMGlobalPropertyInitializer.h"

Expand Down Expand Up @@ -112,6 +114,7 @@ NS_INTERFACE_MAP_BEGIN(Navigator)
#ifdef MOZ_B2G_BT
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorBluetooth)
#endif
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorCamera)
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorSystemMessages)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Navigator)
NS_INTERFACE_MAP_END
Expand Down Expand Up @@ -181,6 +184,8 @@ Navigator::Invalidate()
}
#endif

mCameraManager = nullptr;

#ifdef MOZ_SYS_MSG
if (mMessagesManager) {
mMessagesManager = nullptr;
Expand Down Expand Up @@ -1320,6 +1325,30 @@ Navigator::MozSetMessageHandler(const nsAString& aType,
#endif
}

//*****************************************************************************
// nsNavigator::nsIDOMNavigatorCamera
//*****************************************************************************

NS_IMETHODIMP
Navigator::GetMozCameras(nsIDOMCameraManager** aCameraManager)
{
if (!mCameraManager) {
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
NS_ENSURE_TRUE(win, NS_ERROR_FAILURE);

if (!win->GetOuterWindow() || win->GetOuterWindow()->GetCurrentInnerWindow() != win) {
return NS_ERROR_NOT_AVAILABLE;
}

mCameraManager = nsDOMCameraManager::Create(win->WindowID());
}

nsRefPtr<nsDOMCameraManager> cameraManager = mCameraManager;
cameraManager.forget(aCameraManager);

return NS_OK;
}

size_t
Navigator::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
{
Expand All @@ -1344,12 +1373,19 @@ Navigator::SetWindow(nsPIDOMWindow *aInnerWindow)
void
Navigator::OnNavigation()
{
// Inform MediaManager in case there are live streams or pending callbacks.
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
if (!win) {
return;
}

#ifdef MOZ_MEDIA_NAVIGATOR
// Inform MediaManager in case there are live streams or pending callbacks.
MediaManager *manager = MediaManager::Get();
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
return manager->OnNavigation(win->WindowID());
manager->OnNavigation(win->WindowID());
#endif
if (mCameraManager) {
mCameraManager->OnNavigation(win->WindowID());
}
}

} // namespace dom
Expand Down
6 changes: 6 additions & 0 deletions dom/base/Navigator.h
Expand Up @@ -41,6 +41,9 @@ class nsIDOMMozVoicemail;

#include "nsIDOMNavigatorSystemMessages.h"

#include "nsIDOMNavigatorCamera.h"
#include "DOMCameraManager.h"

//*****************************************************************************
// Navigator: Script "navigator" object
//*****************************************************************************
Expand Down Expand Up @@ -82,6 +85,7 @@ class Navigator : public nsIDOMNavigator
#ifdef MOZ_B2G_BT
, public nsIDOMNavigatorBluetooth
#endif
, public nsIDOMNavigatorCamera
, public nsIDOMNavigatorSystemMessages
{
public:
Expand Down Expand Up @@ -134,6 +138,7 @@ class Navigator : public nsIDOMNavigator
// Helper to initialize mMessagesManager.
nsresult EnsureMessagesManager();
#endif
NS_DECL_NSIDOMNAVIGATORCAMERA

private:
bool IsSmsAllowed() const;
Expand All @@ -155,6 +160,7 @@ class Navigator : public nsIDOMNavigator
#ifdef MOZ_B2G_BT
nsCOMPtr<nsIDOMBluetoothManager> mBluetooth;
#endif
nsRefPtr<nsDOMCameraManager> mCameraManager;
nsCOMPtr<nsIDOMNavigatorSystemMessages> mMessagesManager;
nsWeakPtr mWindow;
};
Expand Down
24 changes: 24 additions & 0 deletions dom/base/nsDOMClassInfo.cpp
Expand Up @@ -522,6 +522,10 @@ using mozilla::dom::indexedDB::IDBWrapperCache;

#include "mozilla/dom/Activity.h"

#include "DOMCameraManager.h"
#include "CameraControl.h"
#include "CameraCapabilities.h"

#include "DOMError.h"
#include "DOMRequest.h"
#include "nsIOpenWindowEventDetail.h"
Expand Down Expand Up @@ -1668,6 +1672,13 @@ static nsDOMClassInfoData sClassInfoData[] = {
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif

NS_DEFINE_CLASSINFO_DATA(CameraManager, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CameraControl, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CameraCapabilities, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)

NS_DEFINE_CLASSINFO_DATA(DOMError, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)

Expand Down Expand Up @@ -2466,6 +2477,7 @@ nsDOMClassInfo::Init()
#ifdef MOZ_B2G_BT
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorBluetooth)
#endif
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorCamera)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorSystemMessages)

DOM_CLASSINFO_MAP_END
Expand Down Expand Up @@ -4457,6 +4469,18 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END
#endif

DOM_CLASSINFO_MAP_BEGIN(CameraManager, nsIDOMCameraManager)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCameraManager)
DOM_CLASSINFO_MAP_END

DOM_CLASSINFO_MAP_BEGIN(CameraControl, nsICameraControl)
DOM_CLASSINFO_MAP_ENTRY(nsICameraControl)
DOM_CLASSINFO_MAP_END

DOM_CLASSINFO_MAP_BEGIN(CameraCapabilities, nsICameraCapabilities)
DOM_CLASSINFO_MAP_ENTRY(nsICameraCapabilities)
DOM_CLASSINFO_MAP_END

DOM_CLASSINFO_MAP_BEGIN(DOMError, nsIDOMDOMError)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMError)
DOM_CLASSINFO_MAP_END
Expand Down
4 changes: 4 additions & 0 deletions dom/base/nsDOMClassInfoClasses.h
Expand Up @@ -526,6 +526,10 @@ DOMCI_CLASS(BluetoothDevice)
DOMCI_CLASS(BluetoothDeviceEvent)
#endif

DOMCI_CLASS(CameraManager)
DOMCI_CLASS(CameraControl)
DOMCI_CLASS(CameraCapabilities)

DOMCI_CLASS(DOMError)
DOMCI_CLASS(DOMRequest)
DOMCI_CLASS(OpenWindowEventDetail)
Expand Down
44 changes: 44 additions & 0 deletions dom/camera/CameraCapabilities.h
@@ -0,0 +1,44 @@
/* 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_NSCAMERACAPABILITIES_H
#define DOM_CAMERA_NSCAMERACAPABILITIES_H

#include "CameraControl.h"
#include "nsAutoPtr.h"

namespace mozilla {

typedef nsresult (*ParseItemAndAddFunc)(JSContext* aCx, JSObject* aArray, PRUint32 aIndex, const char* aStart, char** aEnd);

class nsCameraCapabilities : public nsICameraCapabilities
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICAMERACAPABILITIES

nsCameraCapabilities(nsCameraControl* aCamera);

nsresult ParameterListToNewArray(
JSContext* cx,
JSObject** aArray,
PRUint32 aKey,
ParseItemAndAddFunc aParseItemAndAdd
);
nsresult StringListToNewObject(JSContext* aCx, JS::Value* aArray, PRUint32 aKey);
nsresult DimensionListToNewObject(JSContext* aCx, JS::Value* aArray, PRUint32 aKey);

private:
nsCameraCapabilities(const nsCameraCapabilities&) MOZ_DELETE;
nsCameraCapabilities& operator=(const nsCameraCapabilities&) MOZ_DELETE;

protected:
/* additional members */
~nsCameraCapabilities();
nsCOMPtr<nsCameraControl> mCamera;
};

} // namespace mozilla

#endif // DOM_CAMERA_NSCAMERACAPABILITIES_H
68 changes: 68 additions & 0 deletions dom/camera/CameraCommon.h
@@ -0,0 +1,68 @@
/* -*- 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_CAMERACOMMON_H
#define DOM_CAMERA_CAMERACOMMON_H

#ifndef __func__
#ifdef __FUNCTION__
#define __func__ __FUNCTION__
#else
#define __func__ __FILE__
#endif
#endif

#ifndef NAN
#define NAN std::numeric_limits<double>::quiet_NaN()
#endif

#include "nsThreadUtils.h"
#include "nsIDOMCameraManager.h"

#define DOM_CAMERA_LOG( l, ... ) \
do { \
if ( DOM_CAMERA_LOG_LEVEL >= (l) ) { \
printf_stderr (__VA_ARGS__); \
} \
} while (0)

#define DOM_CAMERA_LOGA( ... ) DOM_CAMERA_LOG( 0, __VA_ARGS__ )

enum {
DOM_CAMERA_LOG_NOTHING,
DOM_CAMERA_LOG_ERROR,
DOM_CAMERA_LOG_WARNING,
DOM_CAMERA_LOG_INFO
};

#define DOM_CAMERA_LOGI( ... ) DOM_CAMERA_LOG( DOM_CAMERA_LOG_INFO, __VA_ARGS__ )
#define DOM_CAMERA_LOGW( ... ) DOM_CAMERA_LOG( DOM_CAMERA_LOG_WARNING, __VA_ARGS__ )
#define DOM_CAMERA_LOGE( ... ) DOM_CAMERA_LOG( DOM_CAMERA_LOG_ERROR, __VA_ARGS__ )

class CameraErrorResult : public nsRunnable
{
public:
CameraErrorResult(nsICameraErrorCallback* onError, const nsString& aErrorMsg)
: mOnErrorCb(onError)
, mErrorMsg(aErrorMsg)
{ }

NS_IMETHOD Run()
{
MOZ_ASSERT(NS_IsMainThread());

if (mOnErrorCb) {
mOnErrorCb->HandleEvent(mErrorMsg);
}
return NS_OK;
}

protected:
nsCOMPtr<nsICameraErrorCallback> mOnErrorCb;
const nsString mErrorMsg;
};

#endif // DOM_CAMERA_CAMERACOMMON_H

0 comments on commit 9e245cc

Please sign in to comment.