Index: android_webview/native/aw_contents.cc |
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc |
index 28f6f18f60a53e9b2830449f39eee84aeee3c10a..b69d433e71afa946bcd0ffd4262c333796055e0b 100644 |
--- a/android_webview/native/aw_contents.cc |
+++ b/android_webview/native/aw_contents.cc |
@@ -215,6 +215,7 @@ AwContents::~AwContents() { |
find_helper_->SetListener(NULL); |
if (icon_helper_.get()) |
icon_helper_->SetListener(NULL); |
+ geolocation_callbacks_.clear(); |
} |
void AwContents::DrawGL(AwDrawGLInfo* draw_info) { |
@@ -711,20 +712,63 @@ 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) { |
benm (inactive)
2013/02/07 17:22:39
nit: one param per line for function definitions/d
Kristian Monsen
2013/02/08 00:07:44
Done.
|
JNIEnv* env = AttachCurrentThread(); |
- ScopedJavaLocalRef<jstring> j_requesting_frame( |
- ConvertUTF8ToJavaString(env, requesting_frame.spec())); |
- Java_AwContents_onGeolocationPermissionsShowPrompt(env, |
- java_ref_.get(env).obj(), render_process_id, render_view_id, bridge_id, |
- j_requesting_frame.obj()); |
+ ScopedJavaLocalRef<jstring> j_origin( |
+ ConvertUTF8ToJavaString(env,origin.spec())); |
+ Java_AwContents_onGeolocationPermissionsShowPrompt( |
+ env, java_ref.get(env).obj(), j_origin.obj()); |
+} |
+ |
+} // 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); |
+ } |
+ } |
} |
-void AwContents::OnGeolocationHidePrompt() { |
- // TODO(kristianm): Implement this |
+void AwContents::OnGeolocationHidePrompt(const GURL& origin) { |
+ std::list<OriginCallback>::iterator it = geolocation_callbacks_.begin(); |
+ bool removed_current_outstanding_callback = false; |
+ for ( ; it != geolocation_callbacks_.end(); ) { |
+ if ((*it).first == origin.GetOrigin()) { |
+ it = geolocation_callbacks_.erase(it); |
+ if (it == geolocation_callbacks_.begin()) { |
+ 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) { |