Bug 811470 - Send geolocation error codes to the content process. r=jdm

This commit is contained in:
Vinay G Shetty 2014-10-23 11:31:00 -07:00
Родитель cd0d5fbdc0
Коммит 0f56cc3110
8 изменённых файлов: 88 добавлений и 5 удалений

Просмотреть файл

@ -1907,6 +1907,17 @@ ContentChild::RecvGeolocationUpdate(const GeoPosition& somewhere)
return true;
}
bool
ContentChild::RecvGeolocationError(const uint16_t& errorCode)
{
nsCOMPtr<nsIGeolocationUpdate> gs = do_GetService("@mozilla.org/geolocation/service;1");
if (!gs) {
return true;
}
gs->NotifyError(errorCode);
return true;
}
bool
ContentChild::RecvUpdateDictionaryList(const InfallibleTArray<nsString>& aDictionaries)
{

Просмотреть файл

@ -305,6 +305,8 @@ public:
virtual bool RecvGeolocationUpdate(const GeoPosition& somewhere) MOZ_OVERRIDE;
virtual bool RecvGeolocationError(const uint16_t& errorCode) MOZ_OVERRIDE;
virtual bool RecvUpdateDictionaryList(const InfallibleTArray<nsString>& aDictionaries) MOZ_OVERRIDE;
virtual bool RecvAddPermission(const IPC::Permission& permission) MOZ_OVERRIDE;

Просмотреть файл

@ -93,6 +93,7 @@
#include "nsICycleCollectorListener.h"
#include "nsIDocument.h"
#include "nsIDOMGeoGeolocation.h"
#include "nsIDOMGeoPositionError.h"
#include "mozilla/dom/WakeLock.h"
#include "nsIDOMWindow.h"
#include "nsIExternalProtocolService.h"
@ -2590,6 +2591,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ContentParent)
NS_INTERFACE_MAP_ENTRY(nsIContentParent)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionCallback)
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionErrorCallback)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
NS_INTERFACE_MAP_END
@ -3689,7 +3691,7 @@ ContentParent::RecvFilePathUpdateNotify(const nsString& aType,
}
static int32_t
AddGeolocationListener(nsIDOMGeoPositionCallback* watcher, bool highAccuracy)
AddGeolocationListener(nsIDOMGeoPositionCallback* watcher, nsIDOMGeoPositionErrorCallback* errorCallBack, bool highAccuracy)
{
nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
if (!geo) {
@ -3701,7 +3703,7 @@ AddGeolocationListener(nsIDOMGeoPositionCallback* watcher, bool highAccuracy)
options->mMaximumAge = 0;
options->mEnableHighAccuracy = highAccuracy;
int32_t retval = 1;
geo->WatchPosition(watcher, nullptr, options, &retval);
geo->WatchPosition(watcher, errorCallBack, options, &retval);
return retval;
}
@ -3722,7 +3724,7 @@ ContentParent::RecvAddGeolocationListener(const IPC::Principal& aPrincipal,
// To ensure no geolocation updates are skipped, we always force the
// creation of a new listener.
RecvRemoveGeolocationListener();
mGeolocationWatchID = AddGeolocationListener(this, aHighAccuracy);
mGeolocationWatchID = AddGeolocationListener(this, this, aHighAccuracy);
return true;
}
@ -3747,7 +3749,7 @@ ContentParent::RecvSetGeolocationHigherAccuracy(const bool& aEnable)
// so this check allows us to forgo securing privileges.
if (mGeolocationWatchID != -1) {
RecvRemoveGeolocationListener();
mGeolocationWatchID = AddGeolocationListener(this, aEnable);
mGeolocationWatchID = AddGeolocationListener(this, this, aEnable);
}
return true;
}
@ -3759,6 +3761,17 @@ ContentParent::HandleEvent(nsIDOMGeoPosition* postion)
return NS_OK;
}
NS_IMETHODIMP
ContentParent::HandleEvent(nsIDOMGeoPositionError* postionError)
{
int16_t errorCode;
nsresult rv;
rv = postionError->GetCode(&errorCode);
NS_ENSURE_SUCCESS(rv,rv);
unused << SendGeolocationError(errorCode);
return NS_OK;
}
nsConsoleService *
ContentParent::GetConsoleService()
{

Просмотреть файл

@ -22,6 +22,7 @@
#include "nsIObserver.h"
#include "nsIThreadInternal.h"
#include "nsIDOMGeoPositionCallback.h"
#include "nsIDOMGeoPositionErrorCallback.h"
#include "PermissionMessageUtils.h"
#define CHILD_PROCESS_SHUTDOWN_MESSAGE NS_LITERAL_STRING("child-process-shutdown")
@ -68,6 +69,7 @@ class ContentParent MOZ_FINAL : public PContentParent
, public nsIContentParent
, public nsIObserver
, public nsIDOMGeoPositionCallback
, public nsIDOMGeoPositionErrorCallback
, public mozilla::LinkedListElement<ContentParent>
{
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
@ -160,6 +162,7 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMGEOPOSITIONCALLBACK
NS_DECL_NSIDOMGEOPOSITIONERRORCALLBACK
/**
* MessageManagerCallback methods that we override.

Просмотреть файл

@ -449,6 +449,8 @@ child:
GeolocationUpdate(GeoPosition somewhere);
GeolocationError(uint16_t errorCode);
UpdateDictionaryList(nsString[] dictionaries);
// nsIPermissionManager messages

Просмотреть файл

@ -0,0 +1,36 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;
function successCallback() {
do_check_true(false);
do_test_finished();
}
function errorCallback(err) {
do_check_eq(Ci.nsIDOMGeoPositionError.POSITION_UNAVAILABLE, err.code);
do_test_finished();
}
function run_test()
{
do_test_pending();
if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
// XPCShell does not get a profile by default. The geolocation service
// depends on the settings service which uses IndexedDB and IndexedDB
// needs a place where it can store databases.
do_get_profile();
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
prefs.setBoolPref("geo.wifi.scan", false);
prefs.setCharPref("geo.wifi.uri", "UrlNotUsedHere:");
prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
}
geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
geolocation.getCurrentPosition(successCallback, errorCallback);
}

Просмотреть файл

@ -0,0 +1,13 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
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", "UrlNotUsedHere");
prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
run_test_in_child("./test_geolocation_position_unavailable.js");
}

Просмотреть файл

@ -18,4 +18,7 @@ skip-if = os == "mac" || os == "android"
skip-if = os == "android"
[test_geolocation_reset_accuracy_wrap.js]
skip-if = os == "mac" || os == "android"
[test_PromiseDebugging.js]
[test_geolocation_position_unavailable.js]
skip-if = os == "android"
[test_geolocation_position_unavailable_wrap.js]
skip-if = os == "mac" || os == "android"[test_PromiseDebugging.js]