mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-16 22:04:36 +00:00
bug 605341 - remote orientation api for android r=dougt a=blocking-fennec
This commit is contained in:
parent
c90d923fa5
commit
b33f6e7f97
@ -90,6 +90,8 @@
|
||||
static const int kRelativeNiceness = 10;
|
||||
#endif
|
||||
|
||||
#include "nsAccelerometer.h"
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
using namespace mozilla::net;
|
||||
using namespace mozilla::places;
|
||||
@ -487,6 +489,16 @@ ContentChild::RecvAddPermission(const IPC::Permission& permission)
|
||||
|
||||
return true;
|
||||
}
|
||||
bool
|
||||
ContentChild::RecvAccelerationChanged(const double& x, const double& y,
|
||||
const double& z)
|
||||
{
|
||||
nsCOMPtr<nsIAccelerometerUpdate> acu =
|
||||
do_GetService(NS_ACCELEROMETER_CONTRACTID);
|
||||
if (acu)
|
||||
acu->AccelerationChanged(x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -114,6 +114,9 @@ public:
|
||||
|
||||
virtual bool RecvAddPermission(const IPC::Permission& permission);
|
||||
|
||||
virtual bool RecvAccelerationChanged(const double& x, const double& y,
|
||||
const double& z);
|
||||
|
||||
private:
|
||||
NS_OVERRIDE
|
||||
virtual void ActorDestroy(ActorDestroyReason why);
|
||||
|
@ -72,6 +72,7 @@
|
||||
#endif
|
||||
|
||||
#include "mozilla/dom/ExternalHelperAppParent.h"
|
||||
#include "nsAccelerometer.h"
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
using namespace mozilla::net;
|
||||
@ -288,7 +289,7 @@ ContentParent::Observe(nsISupports* aSubject,
|
||||
}
|
||||
}
|
||||
|
||||
RecvGeolocationStop();
|
||||
RecvRemoveGeolocationListener();
|
||||
|
||||
Close();
|
||||
XRE_GetIOMessageLoop()->PostTask(
|
||||
@ -622,7 +623,7 @@ ContentParent::RecvAsyncMessage(const nsString& aMsg, const nsString& aJSON)
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::RecvGeolocationStart()
|
||||
ContentParent::RecvAddGeolocationListener()
|
||||
{
|
||||
if (mGeolocationWatchID == -1) {
|
||||
nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
|
||||
@ -635,7 +636,7 @@ ContentParent::RecvGeolocationStart()
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::RecvGeolocationStop()
|
||||
ContentParent::RecvRemoveGeolocationListener()
|
||||
{
|
||||
if (mGeolocationWatchID != -1) {
|
||||
nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
|
||||
@ -648,6 +649,26 @@ ContentParent::RecvGeolocationStop()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::RecvAddAccelerometerListener()
|
||||
{
|
||||
nsCOMPtr<nsIAccelerometer> ac =
|
||||
do_GetService(NS_ACCELEROMETER_CONTRACTID);
|
||||
if (ac)
|
||||
ac->AddListener(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::RecvRemoveAccelerometerListener()
|
||||
{
|
||||
nsCOMPtr<nsIAccelerometer> ac =
|
||||
do_GetService(NS_ACCELEROMETER_CONTRACTID);
|
||||
if (ac)
|
||||
ac->RemoveListener(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContentParent::HandleEvent(nsIDOMGeoPosition* postion)
|
||||
{
|
||||
@ -690,5 +711,19 @@ ContentParent::RecvScriptError(const nsString& aMessage,
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContentParent::OnAccelerationChange(nsIAcceleration *aAcceleration)
|
||||
{
|
||||
double x, y, z;
|
||||
aAcceleration->GetX(&x);
|
||||
aAcceleration->GetY(&y);
|
||||
aAcceleration->GetZ(&z);
|
||||
|
||||
mozilla::dom::ContentParent::GetSingleton()->
|
||||
SendAccelerationChanged(x, y, z);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIDOMGeoPositionCallback.h"
|
||||
#include "nsIAccelerometer.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -66,6 +67,7 @@ class ContentParent : public PContentParent
|
||||
, public nsIObserver
|
||||
, public nsIThreadObserver
|
||||
, public nsIDOMGeoPositionCallback
|
||||
, public nsIAccelerationListener
|
||||
{
|
||||
private:
|
||||
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
|
||||
@ -83,6 +85,7 @@ public:
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSITHREADOBSERVER
|
||||
NS_DECL_NSIDOMGEOPOSITIONCALLBACK
|
||||
NS_DECL_NSIACCELERATIONLISTENER
|
||||
|
||||
TabParent* CreateTab(PRUint32 aChromeFlags);
|
||||
|
||||
@ -161,8 +164,10 @@ private:
|
||||
nsTArray<nsString>* aRetvals);
|
||||
virtual bool RecvAsyncMessage(const nsString& aMsg, const nsString& aJSON);
|
||||
|
||||
virtual bool RecvGeolocationStart();
|
||||
virtual bool RecvGeolocationStop();
|
||||
virtual bool RecvAddGeolocationListener();
|
||||
virtual bool RecvRemoveGeolocationListener();
|
||||
virtual bool RecvAddAccelerometerListener();
|
||||
virtual bool RecvRemoveAccelerometerListener();
|
||||
|
||||
virtual bool RecvConsoleMessage(const nsString& aMessage);
|
||||
virtual bool RecvScriptError(const nsString& aMessage,
|
||||
|
@ -88,6 +88,8 @@ child:
|
||||
// nsIPermissionManager messages
|
||||
AddPermission(Permission permission);
|
||||
|
||||
AccelerationChanged(double x, double y, double z);
|
||||
|
||||
parent:
|
||||
PNecko();
|
||||
|
||||
@ -122,8 +124,10 @@ parent:
|
||||
nsCString aContentDisposition, bool aForceSave,
|
||||
PRInt64 aContentLength);
|
||||
|
||||
GeolocationStart();
|
||||
GeolocationStop();
|
||||
AddGeolocationListener();
|
||||
RemoveGeolocationListener();
|
||||
AddAccelerometerListener();
|
||||
RemoveAccelerometerListener();
|
||||
|
||||
ConsoleMessage(nsString message);
|
||||
ScriptError(nsString message, nsString sourceName, nsString sourceLine,
|
||||
|
@ -749,7 +749,7 @@ nsGeolocationService::StartDevice()
|
||||
#ifdef MOZ_IPC
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
ContentChild* cpc = ContentChild::GetSingleton();
|
||||
cpc->SendGeolocationStart();
|
||||
cpc->SendAddGeolocationListener();
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
@ -794,7 +794,7 @@ nsGeolocationService::StopDevice()
|
||||
#ifdef MOZ_IPC
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
ContentChild* cpc = ContentChild::GetSingleton();
|
||||
cpc->SendGeolocationStop();
|
||||
cpc->SendRemoveGeolocationListener();
|
||||
return; // bail early
|
||||
}
|
||||
#endif
|
||||
|
@ -35,9 +35,11 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "nsAccelerometerSystem.h"
|
||||
|
||||
#include "AndroidBridge.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
@ -54,12 +56,18 @@ nsAccelerometerSystem::~nsAccelerometerSystem()
|
||||
|
||||
void nsAccelerometerSystem::Startup()
|
||||
{
|
||||
if (AndroidBridge::Bridge())
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default)
|
||||
AndroidBridge::Bridge()->EnableAccelerometer(true);
|
||||
else
|
||||
mozilla::dom::ContentChild::GetSingleton()->
|
||||
SendAddAccelerometerListener();
|
||||
}
|
||||
|
||||
void nsAccelerometerSystem::Shutdown()
|
||||
{
|
||||
if (AndroidBridge::Bridge())
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default)
|
||||
AndroidBridge::Bridge()->EnableAccelerometer(false);
|
||||
else
|
||||
mozilla::dom::ContentChild::GetSingleton()->
|
||||
SendRemoveAccelerometerListener();
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ NS_IMETHODIMP nsAcceleration::GetZ(double *aZ)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsAccelerometer, nsIAccelerometer)
|
||||
NS_IMPL_ISUPPORTS2(nsAccelerometer, nsIAccelerometer, nsIAccelerometerUpdate)
|
||||
|
||||
nsAccelerometer::nsAccelerometer()
|
||||
: mLastX(10), /* initialize to values that can't be possible */
|
||||
@ -200,11 +200,11 @@ NS_IMETHODIMP nsAccelerometer::RemoveWindowListener(nsIDOMWindow *aWindow)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
NS_IMETHODIMP
|
||||
nsAccelerometer::AccelerationChanged(double x, double y, double z)
|
||||
{
|
||||
if (!mEnabled)
|
||||
return;
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (x > 1)
|
||||
x = 1;
|
||||
@ -223,7 +223,7 @@ nsAccelerometer::AccelerationChanged(double x, double y, double z)
|
||||
if (PR_ABS(mLastX - x) < .01 &&
|
||||
PR_ABS(mLastY - y) < .01 &&
|
||||
PR_ABS(mLastZ - z) < .01)
|
||||
return;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mLastX = x;
|
||||
@ -270,4 +270,5 @@ nsAccelerometer::AccelerationChanged(double x, double y, double z)
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -50,19 +50,17 @@
|
||||
|
||||
class nsIDOMWindow;
|
||||
|
||||
class nsAccelerometer : public nsIAccelerometer
|
||||
class nsAccelerometer : public nsIAccelerometerUpdate
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIACCELEROMETER
|
||||
NS_DECL_NSIACCELEROMETERUPDATE
|
||||
|
||||
nsAccelerometer();
|
||||
|
||||
virtual ~nsAccelerometer();
|
||||
|
||||
/* must be called on the main thread or else */
|
||||
void AccelerationChanged(double x, double y, double z);
|
||||
|
||||
double mLastX;
|
||||
double mLastY;
|
||||
double mLastZ;
|
||||
|
@ -62,3 +62,13 @@ interface nsIAccelerometer : nsISupports
|
||||
void removeWindowListener(in nsIDOMWindow aWindow);
|
||||
|
||||
};
|
||||
|
||||
/* for use by IPC system to notify non-chrome processes of
|
||||
* accelerometer events
|
||||
*/
|
||||
[uuid(22dd1d8a-51bf-406f-8b6d-d1919f8f1c7d)]
|
||||
interface nsIAccelerometerUpdate : nsIAccelerometer
|
||||
{
|
||||
/* must be called on the main thread or else */
|
||||
void accelerationChanged(in double x, in double y, in double z);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user