mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 20:33:07 +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);
|
Geo.stop(watchId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Taken from Jesse's geo fix (similar problem) in PhoneGap iPhone. Go figure, same browser!
|
PhoneGap.addConstructor(function() {
|
||||||
function __proxyObj(origObj, proxyObj, funkList) {
|
// 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) {
|
for (var v in funkList) {
|
||||||
origObj[funkList[v]] = proxyObj[funkList[v]];
|
origObj[funkList[v]] = proxyObj[funkList[v]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PhoneGap.addConstructor(function() {
|
// 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();
|
navigator._geo = new Geolocation();
|
||||||
__proxyObj(navigator.geolocation, navigator._geo,
|
__proxyObj(navigator.geolocation, navigator._geo, ["setLocation", "getCurrentPosition", "watchPosition", "clearWatch", "setError", "start", "stop", "gotCurrentPosition"]);
|
||||||
["setLocation", "getCurrentPosition", "watchPosition",
|
} else {
|
||||||
"clearWatch", "setError", "start", "stop", "gotCurrentPosition"]
|
navigator.geolocation = new Geolocation();
|
||||||
);
|
}
|
||||||
});
|
});
|
@ -102,7 +102,6 @@ public class DroidGap extends Activity {
|
|||||||
settings.setJavaScriptCanOpenWindowsAutomatically(true);
|
settings.setJavaScriptCanOpenWindowsAutomatically(true);
|
||||||
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
|
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
|
||||||
|
|
||||||
|
|
||||||
Package pack = this.getClass().getPackage();
|
Package pack = this.getClass().getPackage();
|
||||||
String appPackage = pack.getName();
|
String appPackage = pack.getName();
|
||||||
|
|
||||||
@ -111,6 +110,9 @@ public class DroidGap extends Activity {
|
|||||||
// Turn on DOM storage!
|
// Turn on DOM storage!
|
||||||
WebViewReflect.setDomStorage(settings);
|
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 */
|
/* Bind the appView object to the gap class methods */
|
||||||
bindBrowser(appView);
|
bindBrowser(appView);
|
||||||
if(cupcakeStorage != null)
|
if(cupcakeStorage != null)
|
||||||
|
@ -10,6 +10,7 @@ public class WebViewReflect {
|
|||||||
private static Method mWebSettings_setDatabaseEnabled;
|
private static Method mWebSettings_setDatabaseEnabled;
|
||||||
private static Method mWebSettings_setDatabasePath;
|
private static Method mWebSettings_setDatabasePath;
|
||||||
private static Method mWebSettings_setDomStorageEnabled;
|
private static Method mWebSettings_setDomStorageEnabled;
|
||||||
|
private static Method mWebSettings_setGeolocationEnabled;
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
@ -48,6 +49,8 @@ public class WebViewReflect {
|
|||||||
"setDatabasePath", new Class[] { String.class });
|
"setDatabasePath", new Class[] { String.class });
|
||||||
mWebSettings_setDomStorageEnabled = WebSettings.class.getMethod(
|
mWebSettings_setDomStorageEnabled = WebSettings.class.getMethod(
|
||||||
"setDomStorageEnabled", new Class[] { boolean.class });
|
"setDomStorageEnabled", new Class[] { boolean.class });
|
||||||
|
mWebSettings_setGeolocationEnabled = WebSettings.class.getMethod(
|
||||||
|
"setGeolocationEnabled", new Class[] { boolean.class });
|
||||||
/* success, this is a newer device */
|
/* success, this is a newer device */
|
||||||
} catch (NoSuchMethodException nsme) {
|
} catch (NoSuchMethodException nsme) {
|
||||||
/* failure, must be older device */
|
/* failure, must be older device */
|
||||||
@ -58,7 +61,7 @@ public class WebViewReflect {
|
|||||||
if (mWebSettings_setDatabaseEnabled != null) {
|
if (mWebSettings_setDatabaseEnabled != null) {
|
||||||
/* feature is supported */
|
/* feature is supported */
|
||||||
try {
|
try {
|
||||||
mWebSettings_setDatabaseEnabled.invoke(setting, true);
|
mWebSettings_setDatabaseEnabled.invoke(setting, enable);
|
||||||
mWebSettings_setDatabasePath.invoke(setting, path);
|
mWebSettings_setDatabasePath.invoke(setting, path);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
@ -75,7 +78,26 @@ public class WebViewReflect {
|
|||||||
System.out.println("Database not supported");
|
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)
|
public static void setDomStorage(WebSettings setting)
|
||||||
{
|
{
|
||||||
if(mWebSettings_setDomStorageEnabled != null)
|
if(mWebSettings_setDomStorageEnabled != null)
|
||||||
|
Loading…
Reference in New Issue
Block a user