Adds the Java side of the system to show the Geolocation permissions prompt.

This commit is contained in:
Steve Block
2009-07-28 18:20:50 +01:00
parent 0ac031b3d2
commit 4faee09c42
4 changed files with 164 additions and 33 deletions

View File

@@ -72,39 +72,41 @@ class CallbackProxy extends Handler {
private final Context mContext;
// Message Ids
private static final int PAGE_STARTED = 100;
private static final int RECEIVED_ICON = 101;
private static final int RECEIVED_TITLE = 102;
private static final int OVERRIDE_URL = 103;
private static final int AUTH_REQUEST = 104;
private static final int SSL_ERROR = 105;
private static final int PROGRESS = 106;
private static final int UPDATE_VISITED = 107;
private static final int LOAD_RESOURCE = 108;
private static final int CREATE_WINDOW = 109;
private static final int CLOSE_WINDOW = 110;
private static final int SAVE_PASSWORD = 111;
private static final int JS_ALERT = 112;
private static final int JS_CONFIRM = 113;
private static final int JS_PROMPT = 114;
private static final int JS_UNLOAD = 115;
private static final int ASYNC_KEYEVENTS = 116;
private static final int TOO_MANY_REDIRECTS = 117;
private static final int DOWNLOAD_FILE = 118;
private static final int REPORT_ERROR = 119;
private static final int RESEND_POST_DATA = 120;
private static final int PAGE_FINISHED = 121;
private static final int REQUEST_FOCUS = 122;
private static final int SCALE_CHANGED = 123;
private static final int RECEIVED_CERTIFICATE = 124;
private static final int SWITCH_OUT_HISTORY = 125;
private static final int EXCEEDED_DATABASE_QUOTA = 126;
private static final int REACHED_APPCACHE_MAXSIZE = 127;
private static final int JS_TIMEOUT = 128;
private static final int ADD_MESSAGE_TO_CONSOLE = 129;
private static final int PAGE_STARTED = 100;
private static final int RECEIVED_ICON = 101;
private static final int RECEIVED_TITLE = 102;
private static final int OVERRIDE_URL = 103;
private static final int AUTH_REQUEST = 104;
private static final int SSL_ERROR = 105;
private static final int PROGRESS = 106;
private static final int UPDATE_VISITED = 107;
private static final int LOAD_RESOURCE = 108;
private static final int CREATE_WINDOW = 109;
private static final int CLOSE_WINDOW = 110;
private static final int SAVE_PASSWORD = 111;
private static final int JS_ALERT = 112;
private static final int JS_CONFIRM = 113;
private static final int JS_PROMPT = 114;
private static final int JS_UNLOAD = 115;
private static final int ASYNC_KEYEVENTS = 116;
private static final int TOO_MANY_REDIRECTS = 117;
private static final int DOWNLOAD_FILE = 118;
private static final int REPORT_ERROR = 119;
private static final int RESEND_POST_DATA = 120;
private static final int PAGE_FINISHED = 121;
private static final int REQUEST_FOCUS = 122;
private static final int SCALE_CHANGED = 123;
private static final int RECEIVED_CERTIFICATE = 124;
private static final int SWITCH_OUT_HISTORY = 125;
private static final int EXCEEDED_DATABASE_QUOTA = 126;
private static final int REACHED_APPCACHE_MAXSIZE = 127;
private static final int JS_TIMEOUT = 128;
private static final int ADD_MESSAGE_TO_CONSOLE = 129;
private static final int GEOLOCATION_PERMISSIONS_SHOW_PROMPT = 130;
private static final int GEOLOCATION_PERMISSIONS_HIDE_PROMPT = 131;
// Message triggered by the client to resume execution
private static final int NOTIFY = 200;
private static final int NOTIFY = 200;
// Result transportation object for returning results across thread
// boundaries.
@@ -438,6 +440,25 @@ class CallbackProxy extends Handler {
}
break;
case GEOLOCATION_PERMISSIONS_SHOW_PROMPT:
if (mWebChromeClient != null) {
HashMap<String, Object> map =
(HashMap<String, Object>) msg.obj;
String origin = (String) map.get("origin");
GeolocationPermissions.Callback callback =
(GeolocationPermissions.Callback)
map.get("callback");
mWebChromeClient.onGeolocationPermissionsShowPrompt(origin,
callback);
}
break;
case GEOLOCATION_PERMISSIONS_HIDE_PROMPT:
if (mWebChromeClient != null) {
mWebChromeClient.onGeolocationPermissionsHidePrompt();
}
break;
case JS_ALERT:
if (mWebChromeClient != null) {
final JsResult res = (JsResult) msg.obj;
@@ -1191,6 +1212,44 @@ class CallbackProxy extends Handler {
sendMessage(msg);
}
/**
* Called by WebViewCore to instruct the browser to display a prompt to ask
* the user to set the Geolocation permission state for the given origin.
* @param origin The origin requesting Geolocation permsissions.
* @param callback The callback to call once a permission state has been
* obtained.
* @hide pending API council review.
*/
public void onGeolocationPermissionsShowPrompt(String origin,
GeolocationPermissions.Callback callback) {
if (mWebChromeClient == null) {
return;
}
Message showMessage =
obtainMessage(GEOLOCATION_PERMISSIONS_SHOW_PROMPT);
HashMap<String, Object> map = new HashMap();
map.put("origin", origin);
map.put("callback", callback);
showMessage.obj = map;
sendMessage(showMessage);
}
/**
* Called by WebViewCore to instruct the browser to hide the Geolocation
* permissions prompt.
* origin.
* @hide pending API council review.
*/
public void onGeolocationPermissionsHidePrompt() {
if (mWebChromeClient == null) {
return;
}
Message hideMessage = obtainMessage(GEOLOCATION_PERMISSIONS_HIDE_PROMPT);
sendMessage(hideMessage);
}
/**
* Called by WebViewCore when we have a message to be added to the JavaScript
* error console. Sends a message to the Java side with the details.

View File

@@ -31,6 +31,14 @@ import java.util.Set;
* @hide
*/
public final class GeolocationPermissions {
/**
* Callback interface used by the browser to report a Geolocation permission
* state set by the user in response to a permissions prompt.
*/
public interface Callback {
public void invoke(String origin, boolean allow, boolean remember);
};
// Log tag
private static final String TAG = "geolocationPermissions";

View File

@@ -226,6 +226,20 @@ public class WebChromeClient {
quotaUpdater.updateQuota(0);
}
/**
* Instructs the client to show a prompt to ask the user to set the
* Geolocation permission state for the specified origin.
* @hide pending API council approval.
*/
public void onGeolocationPermissionsShowPrompt(String origin,
GeolocationPermissions.Callback callback) {}
/**
* Instructs the client to hide the Geolocation permissions prompt.
* @hide pending API council approval.
*/
public void onGeolocationPermissionsHidePrompt() {}
/**
* Tell the client that a JavaScript execution timeout has occured. And the
* client may decide whether or not to interrupt the execution. If the
@@ -249,6 +263,5 @@ public class WebChromeClient {
* @param sourceID The name of the source file that caused the error.
* @hide pending API council.
*/
public void addMessageToConsole(String message, int lineNumber, String sourceID) {
}
public void addMessageToConsole(String message, int lineNumber, String sourceID) {}
}

View File

@@ -284,6 +284,33 @@ final class WebViewCore {
});
}
/**
* Shows a prompt to ask the user to set the Geolocation permission state
* for the given origin.
* @param origin The origin for which Geolocation permissions are
* requested.
*/
protected void geolocationPermissionsShowPrompt(String origin) {
mCallbackProxy.onGeolocationPermissionsShowPrompt(origin,
new GeolocationPermissions.Callback() {
public void invoke(String origin, boolean allow, boolean remember) {
GeolocationPermissionsData data = new GeolocationPermissionsData();
data.mOrigin = origin;
data.mAllow = allow;
data.mRemember = remember;
// Marshall to WebCore thread.
sendMessage(EventHub.GEOLOCATION_PERMISSIONS_PROVIDE, data);
}
});
}
/**
* Hides the Geolocation permissions prompt.
*/
protected void geolocationPermissionsHidePrompt() {
mCallbackProxy.onGeolocationPermissionsHidePrompt();
}
/**
* Invoke a javascript confirm dialog.
* @param message The message displayed in the dialog.
@@ -465,6 +492,16 @@ final class WebViewCore {
private native void nativeUpdatePluginState(int framePtr, int nodePtr, int state);
/**
* Provide WebCore with a Geolocation permission state for the specified
* origin.
* @param origin The origin for which Geolocation permissions are provided.
* @param allow Whether Geolocation permissions are allowed.
* @param remember Whether this decision should be remembered beyond the
* life of the current page.
*/
private native void nativeGeolocationPermissionsProvide(String origin, boolean allow, boolean remember);
// EventHub for processing messages
private final EventHub mEventHub;
// WebCore thread handler
@@ -608,6 +645,12 @@ final class WebViewCore {
int mState;
}
static class GeolocationPermissionsData {
String mOrigin;
boolean mAllow;
boolean mRemember;
}
static final String[] HandlerDebugString = {
"SCROLL_TEXT_INPUT", // = 99
"LOAD_URL", // = 100;
@@ -733,6 +776,8 @@ final class WebViewCore {
static final int DUMP_NAVTREE = 172;
static final int SET_JS_FLAGS = 173;
// Geolocation
static final int GEOLOCATION_PERMISSIONS_PROVIDE = 180;
// private message ids
private static final int DESTROY = 200;
@@ -1119,6 +1164,12 @@ final class WebViewCore {
case SET_JS_FLAGS:
nativeSetJsFlags((String)msg.obj);
case GEOLOCATION_PERMISSIONS_PROVIDE:
GeolocationPermissionsData data =
(GeolocationPermissionsData) msg.obj;
nativeGeolocationPermissionsProvide(data.mOrigin,
data.mAllow, data.mRemember);
break;
case SYNC_SCROLL: