Backed out changeset 9dc561810a74 (bug 826102)

This commit is contained in:
Josh Matthews 2013-01-07 16:34:51 +01:00
parent d9af90cebc
commit 62cda9990f
8 changed files with 61 additions and 174 deletions

View File

@ -2005,20 +2005,14 @@ ContentParent::RecvAddGeolocationListener(const IPC::Principal& aPrincipal)
}
#endif
// To ensure no geolocation updates are skipped, we always force the
// creation of a new listener.
RecvRemoveGeolocationListener();
nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
if (!geo) {
return true;
if (mGeolocationWatchID == -1) {
nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
if (!geo) {
return true;
}
jsval dummy = JSVAL_VOID;
geo->WatchPosition(this, nullptr, dummy, nullptr, &mGeolocationWatchID);
}
nsRefPtr<nsGeolocation> geosvc = static_cast<nsGeolocation*>(geo.get());
nsAutoPtr<mozilla::dom::GeoPositionOptions> options(new mozilla::dom::GeoPositionOptions());
jsval null = JS::NullValue();
options->Init(nullptr, &null);
geosvc->WatchPosition(this, nullptr, options.forget(), &mGeolocationWatchID);
return true;
}

View File

@ -9,14 +9,15 @@
#include "nsGeoPosition.h"
#include "nsIDOMGeoPosition.h"
typedef nsIDOMGeoPosition* GeoPosition;
typedef nsGeoPositionCoords *GeoPositionCoords;
typedef nsIDOMGeoPosition *GeoPosition;
namespace IPC {
template <>
struct ParamTraits<nsIDOMGeoPositionCoords*>
struct ParamTraits<GeoPositionCoords>
{
typedef nsIDOMGeoPositionCoords* paramType;
typedef GeoPositionCoords paramType;
// Function to serialize a geoposition
static void Write(Message *aMsg, const paramType& aParam)
@ -95,9 +96,9 @@ struct ParamTraits<nsIDOMGeoPositionCoords*>
};
template <>
struct ParamTraits<nsIDOMGeoPosition*>
struct ParamTraits<GeoPosition>
{
typedef nsIDOMGeoPosition* paramType;
typedef GeoPosition paramType;
// Function to serialize a geoposition
static void Write(Message *aMsg, const paramType& aParam)
@ -113,7 +114,8 @@ struct ParamTraits<nsIDOMGeoPosition*>
nsCOMPtr<nsIDOMGeoPositionCoords> coords;
aParam->GetCoords(getter_AddRefs(coords));
WriteParam(aMsg, coords.get());
GeoPositionCoords simpleCoords = static_cast<GeoPositionCoords>(coords.get());
WriteParam(aMsg, simpleCoords);
}
// Function to de-serialize a geoposition
@ -129,14 +131,16 @@ struct ParamTraits<nsIDOMGeoPosition*>
}
DOMTimeStamp timeStamp;
nsIDOMGeoPositionCoords* coords = nullptr;
GeoPositionCoords coords = nullptr;
// It's not important to us where it fails, but rather if it fails
if (!ReadParam(aMsg, aIter, &timeStamp) ||
!ReadParam(aMsg, aIter, &coords)) {
nsCOMPtr<nsIDOMGeoPositionCoords> tmpcoords = coords;
return false;
}
if (!( ReadParam(aMsg, aIter, &timeStamp)
&& ReadParam(aMsg, aIter, &coords ))) {
// note it is fine to do "delete nullptr" in case coords hasn't
// been allocated
delete coords;
return false;
}
*aResult = new nsGeoPosition(coords, timeStamp);

View File

@ -285,7 +285,6 @@ nsDOMGeoPositionError::NotifyCallback(nsIDOMGeoPositionErrorCallback* aCallback)
nsGeolocationRequest::nsGeolocationRequest(nsGeolocation* aLocator,
nsIDOMGeoPositionCallback* aCallback,
nsIDOMGeoPositionErrorCallback* aErrorCallback,
mozilla::dom::GeoPositionOptions* aOptions,
bool aWatchPositionRequest,
int32_t aWatchId)
: mAllowed(false),
@ -294,7 +293,6 @@ nsGeolocationRequest::nsGeolocationRequest(nsGeolocation* aLocator,
mIsWatchPositionRequest(aWatchPositionRequest),
mCallback(aCallback),
mErrorCallback(aErrorCallback),
mOptions(aOptions),
mLocator(aLocator),
mWatchId(aWatchId)
{
@ -304,21 +302,15 @@ nsGeolocationRequest::~nsGeolocationRequest()
{
}
static mozilla::dom::GeoPositionOptions*
OptionsFromJSOptions(JSContext* aCx, const jsval& aOptions, nsresult* aRv)
nsresult
nsGeolocationRequest::Init(JSContext* aCx, const jsval& aOptions)
{
*aRv = NS_OK;
nsAutoPtr<mozilla::dom::GeoPositionOptions> options(nullptr);
if (aCx && !JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) {
options = new mozilla::dom::GeoPositionOptions();
nsresult rv = options->Init(aCx, &aOptions);
if (NS_FAILED(rv)) {
*aRv = rv;
return nullptr;
}
mOptions = new mozilla::dom::GeoPositionOptions();
nsresult rv = mOptions->Init(aCx, &aOptions);
NS_ENSURE_SUCCESS(rv, rv);
}
return options.forget();
return NS_OK;
}
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGeolocationRequest)
@ -873,6 +865,10 @@ nsGeolocationService::IsBetterPosition(nsIDOMGeoPosition *aSomewhere)
return false;
}
if (XRE_GetProcessType() == GeckoProcessType_Content) {
return true;
}
if (mProviders.Count() == 1 || !mLastPosition) {
return true;
}
@ -1246,20 +1242,8 @@ nsGeolocation::Update(nsIDOMGeoPosition *aSomewhere, bool aIsBetter)
NS_IMETHODIMP
nsGeolocation::GetCurrentPosition(nsIDOMGeoPositionCallback *callback,
nsIDOMGeoPositionErrorCallback *errorCallback,
const jsval& jsoptions,
const jsval& options,
JSContext* cx)
{
nsresult rv;
nsAutoPtr<mozilla::dom::GeoPositionOptions> options(
OptionsFromJSOptions(cx, jsoptions, &rv));
NS_ENSURE_SUCCESS(rv, rv);
return GetCurrentPosition(callback, errorCallback, options.forget());
}
nsresult
nsGeolocation::GetCurrentPosition(nsIDOMGeoPositionCallback *callback,
nsIDOMGeoPositionErrorCallback *errorCallback,
mozilla::dom::GeoPositionOptions *options)
{
NS_ENSURE_ARG_POINTER(callback);
@ -1270,8 +1254,13 @@ nsGeolocation::GetCurrentPosition(nsIDOMGeoPositionCallback *callback,
nsRefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(this,
callback,
errorCallback,
options,
false);
if (!request) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = request->Init(cx, options);
NS_ENSURE_SUCCESS(rv, rv);
if (!sGeoEnabled) {
nsCOMPtr<nsIRunnable> ev = new RequestAllowEvent(false, request);
@ -1318,22 +1307,9 @@ nsGeolocation::GetCurrentPositionReady(nsGeolocationRequest* aRequest)
NS_IMETHODIMP
nsGeolocation::WatchPosition(nsIDOMGeoPositionCallback *callback,
nsIDOMGeoPositionErrorCallback *errorCallback,
const jsval& jsoptions,
const jsval& options,
JSContext* cx,
int32_t *_retval)
{
nsresult rv;
nsAutoPtr<mozilla::dom::GeoPositionOptions> options(
OptionsFromJSOptions(cx, jsoptions, &rv));
NS_ENSURE_SUCCESS(rv, rv);
return WatchPosition(callback, errorCallback, options.forget(), _retval);
}
nsresult
nsGeolocation::WatchPosition(nsIDOMGeoPositionCallback *callback,
nsIDOMGeoPositionErrorCallback *errorCallback,
mozilla::dom::GeoPositionOptions *options,
int32_t *_retval)
{
NS_ENSURE_ARG_POINTER(callback);
@ -1347,9 +1323,14 @@ nsGeolocation::WatchPosition(nsIDOMGeoPositionCallback *callback,
nsRefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(this,
callback,
errorCallback,
options,
true,
*_retval);
if (!request) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = request->Init(cx, options);
NS_ENSURE_SUCCESS(rv, rv);
if (!sGeoEnabled) {
nsCOMPtr<nsIRunnable> ev = new RequestAllowEvent(false, request);

View File

@ -53,9 +53,9 @@ class nsGeolocationRequest
nsGeolocationRequest(nsGeolocation* locator,
nsIDOMGeoPositionCallback* callback,
nsIDOMGeoPositionErrorCallback* errorCallback,
mozilla::dom::GeoPositionOptions* aOptions,
bool watchPositionRequest = false,
int32_t watchId = 0);
nsresult Init(JSContext* aCx, const jsval& aOptions);
void Shutdown();
// Called by the geolocation device to notify that a location has changed.
@ -75,6 +75,7 @@ class nsGeolocationRequest
void IPDLRelease() { Release(); }
int32_t WatchId() { return mWatchId; }
private:
void NotifyError(int16_t errorCode);
@ -201,14 +202,6 @@ public:
// Notification from the service:
void ServiceReady();
// Versions of the DOM APIs that don't require JS option values
nsresult WatchPosition(nsIDOMGeoPositionCallback *callback,
nsIDOMGeoPositionErrorCallback *errorCallback,
mozilla::dom::GeoPositionOptions *options,
int32_t *_retval);
nsresult GetCurrentPosition(nsIDOMGeoPositionCallback *callback,
nsIDOMGeoPositionErrorCallback *errorCallback,
mozilla::dom::GeoPositionOptions *options);
private:
~nsGeolocation();

View File

@ -15,7 +15,7 @@ const Cc = Components.classes;
let gLoggingEnabled = false;
let gTestingEnabled = false;
let gUseScanning = true;
let gDesist = false;
let gPrivateAccessToken = '';
let gPrivateAccessTime = 0;
@ -76,10 +76,6 @@ function WifiGeoPositionProvider() {
gTestingEnabled = Services.prefs.getBoolPref("geo.wifi.testing");
} catch (e) {}
try {
gUseScanning = Services.prefs.getBoolPref("geo.wifi.scan");
} catch (e) {}
this.wifiService = null;
this.timer = null;
this.hasSeenWiFi = false;
@ -115,20 +111,20 @@ WifiGeoPositionProvider.prototype = {
watch: function(c, requestPrivate) {
LOG("watch called");
if (!this.wifiService && gUseScanning) {
let useScanning = true;
try {
useScanning = Services.prefs.getBoolPref("geo.wifi.scan");
} catch (e) {}
if (!this.wifiService && useScanning) {
this.wifiService = Cc["@mozilla.org/wifi/monitor;1"].getService(Components.interfaces.nsIWifiMonitor);
this.wifiService.startWatching(this);
this.lastRequestPrivate = requestPrivate;
}
if (this.hasSeenWiFi) {
this.hasSeenWiFi = false;
if (gUseScanning) {
this.wifiService.stopWatching(this);
this.wifiService.startWatching(this);
} else {
// For testing situations, ensure that we always trigger an update.
this.timer.initWithCallback(this, 5000, this.timer.TYPE_ONE_SHOT);
}
this.wifiService.stopWatching(this);
this.wifiService.startWatching(this);
this.lastRequestPrivate = requestPrivate;
}
},
@ -318,7 +314,7 @@ WifiGeoPositionProvider.prototype = {
},
notify: function (timer) {
if (gTestingEnabled || !gUseScanning) {
if (gTestingEnabled) {
// if we are testing, timer is repeating
this.onChange(null);
}

View File

@ -1,69 +0,0 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;
Cu.import("resource://testing-common/httpd.js");
var httpserver = null;
var geolocation = null;
var success = false;
var watchId = -1;
let gAccuracy = 42;
function geoHandler(metadata, response)
{
var georesponse = {
status: "OK",
location: {
lat: 0.45,
lng: 0.45,
},
accuracy: gAccuracy,
};
var position = JSON.stringify(georesponse);
response.setStatusLine("1.0", 200, "OK");
response.setHeader("Cache-Control", "no-cache", false);
response.setHeader("Content-Type", "aplication/x-javascript", false);
response.write(position);
}
function errorCallback() {
do_check_true(false);
do_test_finished();
}
function run_test()
{
do_test_pending();
httpserver = new HttpServer();
httpserver.registerPathHandler("/geo", geoHandler);
httpserver.start(4444);
if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
prefs.setBoolPref("geo.wifi.scan", false);
prefs.setCharPref("geo.wifi.uri", "http://localhost:4444/geo");
}
let timesCalled = 0;
geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsIDOMGeoGeolocation);
geolocation.watchPosition(function(pos) {
do_check_eq(++timesCalled, 1);
do_check_eq(pos.coords.accuracy, gAccuracy);
gAccuracy = 420;
geolocation2 = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsIDOMGeoGeolocation);
geolocation2.getCurrentPosition(function(pos) {
do_check_eq(pos.coords.accuracy, gAccuracy);
gAccuracy = 400;
geolocation2.getCurrentPosition(function(pos) {
do_check_eq(pos.coords.accuracy, 42);
do_test_finished();
}, errorCallback);
}, errorCallback, {maximumAge: 0});
}, errorCallback, {maximumAge: 0});
}

View File

@ -1,9 +0,0 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
function run_test() {
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
prefs.setBoolPref("geo.wifi.scan", false);
prefs.setCharPref("geo.wifi.uri", "http://localhost:4444/geo");
run_test_in_child("test_multiple_geo_listeners.js");
}

View File

@ -5,11 +5,8 @@ tail =
[test_bug319968.js]
[test_bug465752.js]
[test_geolocation_provider.js]
# Bug 684962: test hangs consistently on Android
skip-if = os == "android"
[test_geolocation_timeout.js]
[test_geolocation_timeout_wrap.js]
skip-if = os == "mac"
[test_multiple_geo_listeners.js]
[test_multiple_geo_listeners_wrap.js]
skip-if = os == "mac"
# Bug 684962: test hangs consistently on Android
skip-if = os == "android"