mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 12:03:28 +08:00
Added explicit disabling of native Geolocation object in the web client, added a fallback measure to JavaScript geolocation PhoneGap constructor so that it builds/proxies the the instantiated Geo objects properly if it still does exist.
This commit is contained in:
parent
655c6ac130
commit
887ab4a28b
@ -73,16 +73,18 @@ Geolocation.prototype.clearWatch = function(watchId)
|
||||
Geo.stop(watchId);
|
||||
}
|
||||
|
||||
// Taken from Jesse's geo fix (similar problem) in PhoneGap iPhone. Go figure, same browser!
|
||||
function __proxyObj(origObj, proxyObj, funkList) {
|
||||
for (var v in funkList) {
|
||||
origObj[funkList[v]] = proxyObj[funkList[v]];
|
||||
}
|
||||
}
|
||||
PhoneGap.addConstructor(function() {
|
||||
navigator._geo = new Geolocation();
|
||||
__proxyObj(navigator.geolocation, navigator._geo,
|
||||
["setLocation", "getCurrentPosition", "watchPosition",
|
||||
"clearWatch", "setError", "start", "stop", "gotCurrentPosition"]
|
||||
);
|
||||
// Taken from Jesse's geo fix (similar problem) in PhoneGap iPhone. Go figure, same browser!
|
||||
function __proxyObj(origObj, proxyObj, funkList) {
|
||||
for (var v in funkList) {
|
||||
origObj[funkList[v]] = proxyObj[funkList[v]];
|
||||
}
|
||||
}
|
||||
// In case a native geolocation object exists, proxy the native one over to a diff object so that we can overwrite the native implementation.
|
||||
if (typeof navigator.geolocation != 'undefined') {
|
||||
navigator._geo = new Geolocation();
|
||||
__proxyObj(navigator.geolocation, navigator._geo, ["setLocation", "getCurrentPosition", "watchPosition", "clearWatch", "setError", "start", "stop", "gotCurrentPosition"]);
|
||||
} else {
|
||||
navigator.geolocation = new Geolocation();
|
||||
}
|
||||
});
|
@ -102,7 +102,6 @@ public class DroidGap extends Activity {
|
||||
settings.setJavaScriptCanOpenWindowsAutomatically(true);
|
||||
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
|
||||
|
||||
|
||||
Package pack = this.getClass().getPackage();
|
||||
String appPackage = pack.getName();
|
||||
|
||||
@ -111,6 +110,9 @@ public class DroidGap extends Activity {
|
||||
// Turn on DOM storage!
|
||||
WebViewReflect.setDomStorage(settings);
|
||||
|
||||
// Turn off native geolocation object in browser - we use our own :)
|
||||
WebViewReflect.setGeolocationEnabled(settings, false);
|
||||
|
||||
/* Bind the appView object to the gap class methods */
|
||||
bindBrowser(appView);
|
||||
if(cupcakeStorage != null)
|
||||
|
@ -10,6 +10,7 @@ public class WebViewReflect {
|
||||
private static Method mWebSettings_setDatabaseEnabled;
|
||||
private static Method mWebSettings_setDatabasePath;
|
||||
private static Method mWebSettings_setDomStorageEnabled;
|
||||
private static Method mWebSettings_setGeolocationEnabled;
|
||||
|
||||
static
|
||||
{
|
||||
@ -48,6 +49,8 @@ public class WebViewReflect {
|
||||
"setDatabasePath", new Class[] { String.class });
|
||||
mWebSettings_setDomStorageEnabled = WebSettings.class.getMethod(
|
||||
"setDomStorageEnabled", new Class[] { boolean.class });
|
||||
mWebSettings_setGeolocationEnabled = WebSettings.class.getMethod(
|
||||
"setGeolocationEnabled", new Class[] { boolean.class });
|
||||
/* success, this is a newer device */
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
/* failure, must be older device */
|
||||
@ -58,9 +61,9 @@ public class WebViewReflect {
|
||||
if (mWebSettings_setDatabaseEnabled != null) {
|
||||
/* feature is supported */
|
||||
try {
|
||||
mWebSettings_setDatabaseEnabled.invoke(setting, true);
|
||||
mWebSettings_setDatabaseEnabled.invoke(setting, enable);
|
||||
mWebSettings_setDatabasePath.invoke(setting, path);
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
@ -75,7 +78,26 @@ public class WebViewReflect {
|
||||
System.out.println("Database not supported");
|
||||
}
|
||||
}
|
||||
|
||||
public static void setGeolocationEnabled(WebSettings setting, boolean enable) {
|
||||
if (mWebSettings_setGeolocationEnabled != null) {
|
||||
/* feature is supported */
|
||||
try {
|
||||
mWebSettings_setGeolocationEnabled.invoke(setting, enable);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
/* feature not supported, do something else */
|
||||
System.out.println("Native Geolocation not supported - we're ok");
|
||||
}
|
||||
}
|
||||
public static void setDomStorage(WebSettings setting)
|
||||
{
|
||||
if(mWebSettings_setDomStorageEnabled != null)
|
||||
|
Loading…
Reference in New Issue
Block a user