Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2922)

Unified Diff: android_webview/native/aw_contents.cc

Issue 12211047: Implementing geolocation for the Android Webview (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated indenting Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/native/aw_contents.cc
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index a0438a31d714525a6d7f573ffb22b04e4d3edef4..14bb861a015fb3f955d2fece73a928ef9e3ad7fc 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/aw_contents.cc
@@ -727,20 +727,68 @@ bool RegisterAwContents(JNIEnv* env) {
return RegisterNativesImpl(env) >= 0;
}
-void AwContents::OnGeolocationShowPrompt(int render_process_id,
- int render_view_id,
- int bridge_id,
- const GURL& requesting_frame) {
+namespace {
+
+void GeolocationShowPrompt(JavaObjectWeakGlobalRef java_ref,
+ const GURL& origin) {
JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> j_requesting_frame(
- ConvertUTF8ToJavaString(env, requesting_frame.spec()));
+ ScopedJavaLocalRef<jstring> j_origin(
+ ConvertUTF8ToJavaString(env,origin.spec()));
joth 2013/02/08 02:15:01 nit: space after comma
Kristian Monsen 2013/02/12 18:53:03 Done.
Java_AwContents_onGeolocationPermissionsShowPrompt(env,
- java_ref_.get(env).obj(), render_process_id, render_view_id, bridge_id,
- j_requesting_frame.obj());
+ java_ref.get(env).obj(),
+ j_origin.obj());
}
-void AwContents::OnGeolocationHidePrompt() {
- // TODO(kristianm): Implement this
+} // anonymous namespace
+
+void AwContents::OnGeolocationShowPrompt(const GURL& requesting_frame,
+ base::Callback<void(bool)> callback) {
+ const GURL& origin = requesting_frame.GetOrigin();
+ bool show_prompt = geolocation_callbacks_.empty();
+ geolocation_callbacks_.push_back(OriginCallback(origin, callback));
+ if (show_prompt) {
+ GeolocationShowPrompt(java_ref_, origin);
+ }
+}
+
+void AwContents::InvokeGeolocationCallback(JNIEnv* env,
+ jobject obj,
+ jboolean value,
+ jstring origin) {
+ GURL callback_origin(base::android::ConvertJavaStringToUTF16(env, origin));
+ if (callback_origin.GetOrigin() == geolocation_callbacks_.front().first) {
+ geolocation_callbacks_.front().second.Run(value);
+ geolocation_callbacks_.pop_front();
+ if (!geolocation_callbacks_.empty()) {
+ GeolocationShowPrompt(java_ref_, geolocation_callbacks_.front().first);
joth 2013/02/08 02:15:01 this could create a callstack as deep as the numbe
Kristian Monsen 2013/02/12 18:53:03 Converted showprompt into a task, that actually fo
+ }
+ }
+}
+
+void AwContents::OnGeolocationHidePrompt(const GURL& origin) {
+ bool removed_current_outstanding_callback = false;
+ std::list<OriginCallback>::iterator it = geolocation_callbacks_.begin();
+ for ( ; it != geolocation_callbacks_.end(); ) {
joth 2013/02/08 02:15:01 This construct has it's very own special syntax:
Kristian Monsen 2013/02/12 18:53:03 Done.
+ if ((*it).first == origin.GetOrigin()) {
+ it = geolocation_callbacks_.erase(it);
+ if (it == geolocation_callbacks_.begin()) {
joth 2013/02/08 02:15:01 you still need to make this check *prior* to updat
Kristian Monsen 2013/02/12 18:53:03 I think it should fine, I did think of that. For t
+ removed_current_outstanding_callback = true;
+ }
+ } else {
+ it++;
+ }
+ }
+
+ if (removed_current_outstanding_callback) {
+ JNIEnv* env = AttachCurrentThread();
+ Java_AwContents_onGeolocationPermissionsHidePrompt(
+ env,
+ java_ref_.get(env).obj());
+ if (!geolocation_callbacks_.empty()) {
+ GeolocationShowPrompt(java_ref_,
+ geolocation_callbacks_.front().first);
+ }
+ }
}
jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) {

Powered by Google App Engine
This is Rietveld 408576698