Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 jobject obj, | 720 jobject obj, |
| 721 jobject web_contents_delegate) { | 721 jobject web_contents_delegate) { |
| 722 AwContents* tab = new AwContents(env, obj, web_contents_delegate); | 722 AwContents* tab = new AwContents(env, obj, web_contents_delegate); |
| 723 return reinterpret_cast<jint>(tab); | 723 return reinterpret_cast<jint>(tab); |
| 724 } | 724 } |
| 725 | 725 |
| 726 bool RegisterAwContents(JNIEnv* env) { | 726 bool RegisterAwContents(JNIEnv* env) { |
| 727 return RegisterNativesImpl(env) >= 0; | 727 return RegisterNativesImpl(env) >= 0; |
| 728 } | 728 } |
| 729 | 729 |
| 730 void AwContents::OnGeolocationShowPrompt(int render_process_id, | 730 namespace { |
| 731 int render_view_id, | 731 |
| 732 int bridge_id, | 732 void GeolocationShowPromptTask(JavaObjectWeakGlobalRef java_ref, |
| 733 const GURL& requesting_frame) { | 733 const GURL& origin) { |
| 734 LOG(INFO) << "Running task geo"; | |
|
benm (inactive)
2013/02/12 10:46:30
nit: remove logging?
Kristian Monsen
2013/02/12 18:53:03
Done.
| |
| 734 JNIEnv* env = AttachCurrentThread(); | 735 JNIEnv* env = AttachCurrentThread(); |
| 735 ScopedJavaLocalRef<jstring> j_requesting_frame( | 736 ScopedJavaLocalRef<jstring> j_origin( |
| 736 ConvertUTF8ToJavaString(env, requesting_frame.spec())); | 737 ConvertUTF8ToJavaString(env, origin.spec())); |
| 737 Java_AwContents_onGeolocationPermissionsShowPrompt(env, | 738 Java_AwContents_onGeolocationPermissionsShowPrompt(env, |
| 738 java_ref_.get(env).obj(), render_process_id, render_view_id, bridge_id, | 739 java_ref.get(env).obj(), |
|
benm (inactive)
2013/02/12 10:46:30
This will NPE if java_ref has been collected.
Kristian Monsen
2013/02/12 18:53:03
Done.
| |
| 739 j_requesting_frame.obj()); | 740 j_origin.obj()); |
| 740 } | 741 } |
| 741 | 742 |
| 742 void AwContents::OnGeolocationHidePrompt() { | 743 void GeolocationShowPrompt(JavaObjectWeakGlobalRef java_ref, |
| 743 // TODO(kristianm): Implement this | 744 const GURL& origin) { |
| 745 content::BrowserThread::PostTask(content::BrowserThread::UI, | |
| 746 FROM_HERE, | |
| 747 base::Bind(&GeolocationShowPromptTask, | |
| 748 java_ref, | |
| 749 origin)); | |
| 750 } | |
| 751 | |
| 752 } // anonymous namespace | |
| 753 | |
| 754 void AwContents::OnGeolocationShowPrompt(const GURL& requesting_frame, | |
| 755 base::Callback<void(bool)> callback) { | |
| 756 GURL origin = requesting_frame.GetOrigin(); | |
| 757 bool show_prompt = pending_geolocation_prompts_.empty(); | |
| 758 pending_geolocation_prompts_.push_back(OriginCallback(origin, callback)); | |
| 759 if (show_prompt) { | |
| 760 GeolocationShowPrompt(java_ref_, origin); | |
|
benm (inactive)
2013/02/12 10:46:30
I think we should take a strong ref to the java_re
Kristian Monsen
2013/02/12 18:53:03
I have checked if the weak pointer is not null bef
benm (inactive)
2013/02/12 19:03:21
I don't think checking for null is enough, it may
Kristian Monsen
2013/02/12 19:17:20
Right, but this is happening when you call get() (
boliu
2013/02/12 19:18:47
Sorry, I got confused this morning, I confused Wea
Ben Murdoch
2013/02/12 19:21:05
Yes, get() will return a ScopedJavaLocalRef. I jus
Kristian Monsen
2013/02/12 19:23:38
I updated after your comment as I realized it coul
| |
| 761 } | |
| 762 } | |
| 763 | |
| 764 void AwContents::InvokeGeolocationCallback(JNIEnv* env, | |
| 765 jobject obj, | |
| 766 jboolean value, | |
| 767 jstring origin) { | |
| 768 GURL callback_origin(base::android::ConvertJavaStringToUTF16(env, origin)); | |
| 769 if (callback_origin.GetOrigin() == | |
| 770 pending_geolocation_prompts_.front().first) { | |
| 771 pending_geolocation_prompts_.front().second.Run(value); | |
| 772 pending_geolocation_prompts_.pop_front(); | |
| 773 if (!pending_geolocation_prompts_.empty()) { | |
| 774 GeolocationShowPrompt(java_ref_, | |
| 775 pending_geolocation_prompts_.front().first); | |
| 776 } | |
| 777 } | |
| 778 } | |
| 779 | |
| 780 void AwContents::OnGeolocationHidePrompt(const GURL& origin) { | |
| 781 bool removed_current_outstanding_callback = false; | |
| 782 std::list<OriginCallback>::iterator it = pending_geolocation_prompts_.begin(); | |
| 783 while (it != pending_geolocation_prompts_.end()) { | |
| 784 if ((*it).first == origin.GetOrigin()) { | |
| 785 if (it == pending_geolocation_prompts_.begin()) { | |
| 786 removed_current_outstanding_callback = true; | |
| 787 } | |
| 788 it = pending_geolocation_prompts_.erase(it); | |
| 789 } else { | |
| 790 it++; | |
|
benm (inactive)
2013/02/12 10:46:30
nit: style guide says to pre-increment.
Kristian Monsen
2013/02/12 18:53:03
Done.
| |
| 791 } | |
| 792 } | |
| 793 | |
| 794 if (removed_current_outstanding_callback) { | |
| 795 JNIEnv* env = AttachCurrentThread(); | |
| 796 Java_AwContents_onGeolocationPermissionsHidePrompt( | |
| 797 env, | |
| 798 java_ref_.get(env).obj()); | |
| 799 if (!pending_geolocation_prompts_.empty()) { | |
| 800 GeolocationShowPrompt(java_ref_, | |
| 801 pending_geolocation_prompts_.front().first); | |
| 802 } | |
| 803 } | |
| 744 } | 804 } |
| 745 | 805 |
| 746 jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) { | 806 jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) { |
| 747 return GetFindHelper()->FindAllSync( | 807 return GetFindHelper()->FindAllSync( |
| 748 ConvertJavaStringToUTF16(env, search_string)); | 808 ConvertJavaStringToUTF16(env, search_string)); |
| 749 } | 809 } |
| 750 | 810 |
| 751 void AwContents::FindAllAsync(JNIEnv* env, jobject obj, jstring search_string) { | 811 void AwContents::FindAllAsync(JNIEnv* env, jobject obj, jstring search_string) { |
| 752 GetFindHelper()->FindAllAsync(ConvertJavaStringToUTF16(env, search_string)); | 812 GetFindHelper()->FindAllAsync(ConvertJavaStringToUTF16(env, search_string)); |
| 753 } | 813 } |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1095 if (!picture) { | 1155 if (!picture) { |
| 1096 render_view_host_ext_->CapturePictureSync(); | 1156 render_view_host_ext_->CapturePictureSync(); |
| 1097 picture = RendererPictureMap::GetInstance()->GetRendererPicture( | 1157 picture = RendererPictureMap::GetInstance()->GetRendererPicture( |
| 1098 web_contents_->GetRoutingID()); | 1158 web_contents_->GetRoutingID()); |
| 1099 } | 1159 } |
| 1100 | 1160 |
| 1101 return picture; | 1161 return picture; |
| 1102 } | 1162 } |
| 1103 | 1163 |
| 1104 } // namespace android_webview | 1164 } // namespace android_webview |
| OLD | NEW |