Bug 823789 - Pass enableHighAccuracy geolocation changes to the chrome process. r=dougt a=bbajaj
☠☠ backed out by 23a6717c6d3f ☠ ☠
authorJosh Matthews <josh@joshmatthews.net>
Mon, 24 Dec 2012 15:14:34 -0500
changeset 117918 d1349e9be2afcab203d75e2a94cecfa5c9a5dd10
parent 117917 5f3d228b6506fb996465467bed2c7e7bb765d5bc
child 117919 f73abd268bad0a88c021e8cfa4edcebc627e6f4f
push id112
push userjosh@joshmatthews.net
push dateWed, 02 Jan 2013 20:10:34 +0000
reviewersdougt, bbajaj
bugs823789
milestone18.0
Bug 823789 - Pass enableHighAccuracy geolocation changes to the chrome process. r=dougt a=bbajaj
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/Makefile.in
dom/ipc/PContent.ipdl
dom/src/geolocation/nsGeolocation.cpp
dom/tests/unit/test_geolocation_timeout.js
dom/tests/unit/test_geolocation_timeout_wrap.js
dom/tests/unit/xpcshell.ini
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -75,16 +75,17 @@
 #include "nsSystemInfo.h"
 #include "nsThreadUtils.h"
 #include "nsToolkitCompsCID.h"
 #include "nsWidgetsCID.h"
 #include "SandboxHal.h"
 #include "StructuredCloneUtils.h"
 #include "TabParent.h"
 #include "URIUtils.h"
+#include "nsGeolocation.h"
 
 #ifdef ANDROID
 # include "gfxAndroidPlatform.h"
 #endif
 
 #ifdef MOZ_CRASHREPORTER
 # include "nsExceptionHandler.h"
 # include "nsICrashReporter.h"
@@ -1992,16 +1993,25 @@ ContentParent::RecvRemoveGeolocationList
       return true;
     }
     geo->ClearWatch(mGeolocationWatchID);
     mGeolocationWatchID = -1;
   }
   return true;
 }
 
+bool
+ContentParent::RecvSetGeolocationHigherAccuracy(const bool& aEnable)
+{
+    nsRefPtr<nsGeolocationService> geoSvc =
+        nsGeolocationService::GetGeolocationService();
+    geoSvc->SetHigherAccuracy(aEnable);
+    return true;
+}
+
 NS_IMETHODIMP
 ContentParent::HandleEvent(nsIDOMGeoPosition* postion)
 {
   unused << SendGeolocationUpdate(GeoPosition(postion));
   return NS_OK;
 }
 
 nsConsoleService *
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -302,16 +302,17 @@ private:
     virtual bool RecvSyncMessage(const nsString& aMsg,
                                  const ClonedMessageData& aData,
                                  InfallibleTArray<nsString>* aRetvals);
     virtual bool RecvAsyncMessage(const nsString& aMsg,
                                   const ClonedMessageData& aData);
 
     virtual bool RecvAddGeolocationListener();
     virtual bool RecvRemoveGeolocationListener();
+    virtual bool RecvSetGeolocationHigherAccuracy(const bool& aEnable);
 
     virtual bool RecvConsoleMessage(const nsString& aMessage);
     virtual bool RecvScriptError(const nsString& aMessage,
                                  const nsString& aSourceName,
                                  const nsString& aSourceLine,
                                  const uint32_t& aLineNumber,
                                  const uint32_t& aColNumber,
                                  const uint32_t& aFlags,
--- a/dom/ipc/Makefile.in
+++ b/dom/ipc/Makefile.in
@@ -87,16 +87,17 @@ include $(topsrcdir)/config/rules.mk
 LOCAL_INCLUDES += \
 	-I$(srcdir)/../../content/base/src \
 	-I$(srcdir)/../../content/events/src \
 	-I$(srcdir)/../../docshell/base \
 	-I$(topsrcdir)/chrome/src \
 	-I$(topsrcdir)/uriloader/exthandler \
 	-I$(srcdir)/../../netwerk/base/src \
 	-I$(srcdir)/../src/base \
+	-I$(srcdir)/../src/geolocation \
 	-I$(srcdir)/../src/storage \
 	-I$(srcdir)/../../xpcom/base \
 	-I$(topsrcdir)/dom/indexedDB \
 	-I$(topsrcdir)/dom/indexedDB/ipc \
 	-I$(topsrcdir)/extensions/cookie \
 	-I$(topsrcdir)/dom/base \
 	-I$(topsrcdir)/toolkit/xre \
 	-I$(topsrcdir)/hal/sandbox \
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -396,16 +396,17 @@ parent:
                           nsString name);
 
     PExternalHelperApp(OptionalURIParams uri, nsCString aMimeContentType,
                        nsCString aContentDisposition, bool aForceSave,
                        int64_t aContentLength, OptionalURIParams aReferrer);
 
     AddGeolocationListener();
     RemoveGeolocationListener();
+    SetGeolocationHigherAccuracy(bool enable);
 
     ConsoleMessage(nsString message);
     ScriptError(nsString message, nsString sourceName, nsString sourceLine,
                 uint32_t lineNumber, uint32_t colNumber, uint32_t flags,
                 nsCString category); 
 
     // nsIPermissionManager messages
     sync ReadPermissions() returns (Permission[] permissions);
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -986,16 +986,22 @@ nsGeolocationService::SetDisconnectTimer
   mDisconnectTimer->Init(this,
                          sProviderTimeout,
                          nsITimer::TYPE_ONE_SHOT);
 }
 
 void
 nsGeolocationService::SetHigherAccuracy(bool aEnable)
 {
+  if (XRE_GetProcessType() == GeckoProcessType_Content) {
+    ContentChild* cpc = ContentChild::GetSingleton();
+    cpc->SendSetGeolocationHigherAccuracy(aEnable);
+    return;
+  }
+
   if (!mHigherAccuracy && aEnable) {
     for (int32_t i = 0; i < mProviders.Count(); i++) {
       mProviders[i]->SetHighAccuracy(true);
     }
   }
 
   if (mHigherAccuracy && !aEnable) {
     for (int32_t i = 0; i < mProviders.Count(); i++) {
new file mode 100644
--- /dev/null
+++ b/dom/tests/unit/test_geolocation_timeout.js
@@ -0,0 +1,60 @@
+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;
+
+function geoHandler(metadata, response)
+{
+    var georesponse = {
+        status: "OK",
+        location: {
+            lat: 42,
+            lng: 42,
+        },
+        accuracy: 42,
+    };
+  var position = JSON.stringify(georesponse);
+  response.processAsync();
+  response.setStatusLine("1.0", 200, "OK");
+  response.setHeader("Cache-Control", "no-cache", false);
+  response.setHeader("Content-Type", "aplication/x-javascript", false);
+  do_timeout(5000, function() {
+    response.write(position);
+    response.finish();
+  });
+}
+
+function successCallback() {
+  do_check_true(false);
+  do_test_finished();
+}
+
+function errorCallback() {
+  do_check_true(true);
+  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.setCharPref("geo.wifi.uri", "http://localhost:4444/geo");  
+  }
+
+  geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsIDOMGeoGeolocation);
+  geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 2000});
+}
new file mode 100644
--- /dev/null
+++ b/dom/tests/unit/test_geolocation_timeout_wrap.js
@@ -0,0 +1,8 @@
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+function run_test() {
+  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
+  prefs.setCharPref("geo.wifi.uri", "http://localhost:4444/geo");  
+  run_test_in_child("./test_geolocation_timeout.js");
+}
\ No newline at end of file
--- a/dom/tests/unit/xpcshell.ini
+++ b/dom/tests/unit/xpcshell.ini
@@ -1,9 +1,12 @@
 [DEFAULT]
 head = 
 tail = 
 
 [test_bug319968.js]
 [test_bug465752.js]
 [test_geolocation_provider.js]
+[test_geolocation_timeout.js]
+[test_geolocation_timeout_wrap.js]
+skip-if = os == "mac"
 # Bug 684962: test hangs consistently on Android
 skip-if = os == "android"