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

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: Added const 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
« no previous file with comments | « android_webview/native/aw_contents.h ('k') | android_webview/native/aw_geolocation_permission_context.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/native/aw_contents.cc
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index 1fd2ec1d5857d77975ffa0ed45c5f4334d35f44b..60f1f693035ae003278df6e48cc030fb8377aa66 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/aw_contents.cc
@@ -727,20 +727,88 @@ 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 ShowGeolocationPromptHelperTask(const JavaObjectWeakGlobalRef& java_ref,
+ const GURL& origin) {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> j_ref = java_ref.get(env);
+ if (j_ref.obj()) {
+ ScopedJavaLocalRef<jstring> j_origin(
+ ConvertUTF8ToJavaString(env, origin.spec()));
+ Java_AwContents_onGeolocationPermissionsShowPrompt(env,
+ j_ref.obj(),
+ j_origin.obj());
+ }
+}
+
+void ShowGeolocationPromptHelper(const JavaObjectWeakGlobalRef& java_ref,
+ const GURL& origin) {
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());
+ if (java_ref.get(env).obj()) {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&ShowGeolocationPromptHelperTask,
+ java_ref,
+ origin));
+ }
+}
+
+} // anonymous namespace
+
+void AwContents::ShowGeolocationPrompt(const GURL& requesting_frame,
+ base::Callback<void(bool)> callback) {
+ GURL origin = requesting_frame.GetOrigin();
+ bool show_prompt = pending_geolocation_prompts_.empty();
+ pending_geolocation_prompts_.push_back(OriginCallback(origin, callback));
+ if (show_prompt) {
+ ShowGeolocationPromptHelper(java_ref_, origin);
+ }
}
-void AwContents::OnGeolocationHidePrompt() {
- // TODO(kristianm): Implement this
+// Invoked from Java
+void AwContents::InvokeGeolocationCallback(JNIEnv* env,
+ jobject obj,
+ jboolean value,
+ jstring origin) {
+ GURL callback_origin(base::android::ConvertJavaStringToUTF16(env, origin));
+ if (callback_origin.GetOrigin() ==
+ pending_geolocation_prompts_.front().first) {
+ pending_geolocation_prompts_.front().second.Run(value);
+ pending_geolocation_prompts_.pop_front();
+ if (!pending_geolocation_prompts_.empty()) {
+ ShowGeolocationPromptHelper(java_ref_,
+ pending_geolocation_prompts_.front().first);
+ }
+ }
+}
+
+void AwContents::HideGeolocationPrompt(const GURL& origin) {
+ bool removed_current_outstanding_callback = false;
+ std::list<OriginCallback>::iterator it = pending_geolocation_prompts_.begin();
+ while (it != pending_geolocation_prompts_.end()) {
+ if ((*it).first == origin.GetOrigin()) {
+ if (it == pending_geolocation_prompts_.begin()) {
+ removed_current_outstanding_callback = true;
+ }
+ it = pending_geolocation_prompts_.erase(it);
+ } else {
+ ++it;
+ }
+ }
+
+ if (removed_current_outstanding_callback) {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> j_ref = java_ref_.get(env);
+ if (j_ref.obj()) {
+ Java_AwContents_onGeolocationPermissionsHidePrompt(env, j_ref.obj());
+ }
+ if (!pending_geolocation_prompts_.empty()) {
+ ShowGeolocationPromptHelper(java_ref_,
+ pending_geolocation_prompts_.front().first);
+ }
+ }
}
jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) {
« no previous file with comments | « android_webview/native/aw_contents.h ('k') | android_webview/native/aw_geolocation_permission_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698