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

Side by Side 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: Minor style updates 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/native/aw_contents.h" 5 #include "android_webview/native/aw_contents.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 #include <sys/system_properties.h> 8 #include <sys/system_properties.h>
9 9
10 #include "android_webview/browser/aw_browser_context.h" 10 #include "android_webview/browser/aw_browser_context.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 SetWebContents(reinterpret_cast<content::WebContents*>(new_wc)); 208 SetWebContents(reinterpret_cast<content::WebContents*>(new_wc));
209 } 209 }
210 210
211 AwContents::~AwContents() { 211 AwContents::~AwContents() {
212 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this); 212 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this);
213 web_contents_->RemoveUserData(kAwContentsUserDataKey); 213 web_contents_->RemoveUserData(kAwContentsUserDataKey);
214 if (find_helper_.get()) 214 if (find_helper_.get())
215 find_helper_->SetListener(NULL); 215 find_helper_->SetListener(NULL);
216 if (icon_helper_.get()) 216 if (icon_helper_.get())
217 icon_helper_->SetListener(NULL); 217 icon_helper_->SetListener(NULL);
218 geolocation_callbacks_.clear();
boliu 2013/02/06 20:29:54 is this necessary?
Kristian Monsen 2013/02/08 00:07:44 When thinking about it, no. It happens automatical
218 } 219 }
219 220
220 void AwContents::DrawGL(AwDrawGLInfo* draw_info) { 221 void AwContents::DrawGL(AwDrawGLInfo* draw_info) {
221 222
222 TRACE_EVENT0("AwContents", "AwContents::DrawGL"); 223 TRACE_EVENT0("AwContents", "AwContents::DrawGL");
223 224
224 if (view_size_.IsEmpty() || !scissor_clip_layer_ || 225 if (view_size_.IsEmpty() || !scissor_clip_layer_ ||
225 draw_info->mode == AwDrawGLInfo::kModeProcess) 226 draw_info->mode == AwDrawGLInfo::kModeProcess)
226 return; 227 return;
227 228
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 jobject obj, 705 jobject obj,
705 jobject web_contents_delegate) { 706 jobject web_contents_delegate) {
706 AwContents* tab = new AwContents(env, obj, web_contents_delegate); 707 AwContents* tab = new AwContents(env, obj, web_contents_delegate);
707 return reinterpret_cast<jint>(tab); 708 return reinterpret_cast<jint>(tab);
708 } 709 }
709 710
710 bool RegisterAwContents(JNIEnv* env) { 711 bool RegisterAwContents(JNIEnv* env) {
711 return RegisterNativesImpl(env) >= 0; 712 return RegisterNativesImpl(env) >= 0;
712 } 713 }
713 714
714 void AwContents::OnGeolocationShowPrompt(int render_process_id, 715 namespace {
715 int render_view_id, 716
716 int bridge_id, 717 void GeolocationShowPrompt(
717 const GURL& requesting_frame) { 718 JavaObjectWeakGlobalRef java_ref, const GURL& origin) {
718 JNIEnv* env = AttachCurrentThread(); 719 JNIEnv* env = AttachCurrentThread();
719 ScopedJavaLocalRef<jstring> j_requesting_frame( 720 ScopedJavaLocalRef<jstring> j_origin(
720 ConvertUTF8ToJavaString(env, requesting_frame.spec())); 721 ConvertUTF8ToJavaString(env,origin.spec()));
721 Java_AwContents_onGeolocationPermissionsShowPrompt(env, 722 Java_AwContents_onGeolocationPermissionsShowPrompt(
722 java_ref_.get(env).obj(), render_process_id, render_view_id, bridge_id, 723 env, java_ref.get(env).obj(), j_origin.obj());
723 j_requesting_frame.obj());
724 } 724 }
725 725
726 void AwContents::OnGeolocationHidePrompt() { 726 }
boliu 2013/02/06 20:29:54 // namespace
Kristian Monsen 2013/02/08 00:07:44 Done.
727 // TODO(kristianm): Implement this 727
728 void AwContents::OnGeolocationShowPrompt(
729 const GURL& requesting_frame, base::Callback<void(bool)> callback) {
730 const GURL& origin = requesting_frame.GetOrigin();
731 bool show_prompt = geolocation_callbacks_.empty();
732 geolocation_callbacks_.push_back(OriginCallback(origin, callback));
boliu 2013/02/06 20:29:54 So using a list means if there are multiple reques
joth 2013/02/06 22:09:51 onGeolocationPermissionsShowPrompt on java side al
733 if (show_prompt) {
734 GeolocationShowPrompt(java_ref_, origin);
735 }
736 }
737
738 void AwContents::InvokeGeolocationCallback(
739 JNIEnv* env, jobject obj, jboolean value, jstring origin) {
740 GURL callback_origin(base::android::ConvertJavaStringToUTF16(env, origin));
741 if (callback_origin.GetOrigin() == geolocation_callbacks_.front().first) {
742 geolocation_callbacks_.front().second.Run(value);
743 geolocation_callbacks_.pop_front();
744 if (!geolocation_callbacks_.empty()) {
745 GeolocationShowPrompt(java_ref_, geolocation_callbacks_.front().first);
746 }
747 }
748 }
749
750 void AwContents::OnGeolocationHidePrompt(const GURL& origin) {
751 std::list<OriginCallback>::iterator it = geolocation_callbacks_.begin();
752 bool removed_current_outstanding_callback = false;
753 for ( ; it != geolocation_callbacks_.end(); ++it) {
754 if ((*it).first == origin.GetOrigin()) {
755 it = geolocation_callbacks_.erase(it);
756 if (it == geolocation_callbacks_.begin()) {
joth 2013/02/06 22:09:51 'it' will be invalidated by the erase() call, so y
Kristian Monsen 2013/02/08 00:07:44 seting it to the next element after the erase, but
joth 2013/02/08 02:15:01 Right - We have upstream instrumentation tests and
757 removed_current_outstanding_callback = true;
758 }
759 }
760 }
761 if (removed_current_outstanding_callback) {
boliu 2013/02/06 20:29:54 Can removed_current_outstanding_callback ever be f
Kristian Monsen 2013/02/08 00:07:44 Yes, if it was cancelled before the callback came
762 JNIEnv* env = AttachCurrentThread();
763 Java_AwContents_onGeolocationPermissionsHidePrompt(
764 env, java_ref_.get(env).obj());
765 GeolocationShowPrompt(
766 java_ref_, geolocation_callbacks_.front().first);
boliu 2013/02/06 20:29:54 check front() is not null?
Kristian Monsen 2013/02/08 00:07:44 Good catch! Adding an empty list check.
767 }
728 } 768 }
729 769
730 jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) { 770 jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) {
731 return GetFindHelper()->FindAllSync( 771 return GetFindHelper()->FindAllSync(
732 ConvertJavaStringToUTF16(env, search_string)); 772 ConvertJavaStringToUTF16(env, search_string));
733 } 773 }
734 774
735 void AwContents::FindAllAsync(JNIEnv* env, jobject obj, jstring search_string) { 775 void AwContents::FindAllAsync(JNIEnv* env, jobject obj, jstring search_string) {
736 GetFindHelper()->FindAllAsync(ConvertJavaStringToUTF16(env, search_string)); 776 GetFindHelper()->FindAllAsync(ConvertJavaStringToUTF16(env, search_string));
737 } 777 }
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 if (!picture) { 1116 if (!picture) {
1077 render_view_host_ext_->CapturePictureSync(); 1117 render_view_host_ext_->CapturePictureSync();
1078 picture = RendererPictureMap::GetInstance()->GetRendererPicture( 1118 picture = RendererPictureMap::GetInstance()->GetRendererPicture(
1079 web_contents_->GetRoutingID()); 1119 web_contents_->GetRoutingID());
1080 } 1120 }
1081 1121
1082 return picture; 1122 return picture;
1083 } 1123 }
1084 1124
1085 } // namespace android_webview 1125 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698