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 ShowGeolocationPromptHelperTask(const JavaObjectWeakGlobalRef& java_ref, |
733 const GURL& requesting_frame) { | 733 const GURL& origin) { |
734 JNIEnv* env = AttachCurrentThread(); | 734 JNIEnv* env = AttachCurrentThread(); |
735 ScopedJavaLocalRef<jstring> j_requesting_frame( | 735 ScopedJavaLocalRef<jobject> j_ref = java_ref.get(env); |
736 ConvertUTF8ToJavaString(env, requesting_frame.spec())); | 736 if (j_ref.obj()) { |
737 Java_AwContents_onGeolocationPermissionsShowPrompt(env, | 737 ScopedJavaLocalRef<jstring> j_origin( |
738 java_ref_.get(env).obj(), render_process_id, render_view_id, bridge_id, | 738 ConvertUTF8ToJavaString(env, origin.spec())); |
739 j_requesting_frame.obj()); | 739 Java_AwContents_onGeolocationPermissionsShowPrompt(env, |
| 740 j_ref.obj(), |
| 741 j_origin.obj()); |
| 742 } |
740 } | 743 } |
741 | 744 |
742 void AwContents::OnGeolocationHidePrompt() { | 745 void ShowGeolocationPromptHelper(const JavaObjectWeakGlobalRef& java_ref, |
743 // TODO(kristianm): Implement this | 746 const GURL& origin) { |
| 747 JNIEnv* env = AttachCurrentThread(); |
| 748 if (java_ref.get(env).obj()) { |
| 749 content::BrowserThread::PostTask( |
| 750 content::BrowserThread::UI, |
| 751 FROM_HERE, |
| 752 base::Bind(&ShowGeolocationPromptHelperTask, |
| 753 java_ref, |
| 754 origin)); |
| 755 } |
| 756 } |
| 757 |
| 758 } // anonymous namespace |
| 759 |
| 760 void AwContents::ShowGeolocationPrompt(const GURL& requesting_frame, |
| 761 base::Callback<void(bool)> callback) { |
| 762 GURL origin = requesting_frame.GetOrigin(); |
| 763 bool show_prompt = pending_geolocation_prompts_.empty(); |
| 764 pending_geolocation_prompts_.push_back(OriginCallback(origin, callback)); |
| 765 if (show_prompt) { |
| 766 ShowGeolocationPromptHelper(java_ref_, origin); |
| 767 } |
| 768 } |
| 769 |
| 770 // Invoked from Java |
| 771 void AwContents::InvokeGeolocationCallback(JNIEnv* env, |
| 772 jobject obj, |
| 773 jboolean value, |
| 774 jstring origin) { |
| 775 GURL callback_origin(base::android::ConvertJavaStringToUTF16(env, origin)); |
| 776 if (callback_origin.GetOrigin() == |
| 777 pending_geolocation_prompts_.front().first) { |
| 778 pending_geolocation_prompts_.front().second.Run(value); |
| 779 pending_geolocation_prompts_.pop_front(); |
| 780 if (!pending_geolocation_prompts_.empty()) { |
| 781 ShowGeolocationPromptHelper(java_ref_, |
| 782 pending_geolocation_prompts_.front().first); |
| 783 } |
| 784 } |
| 785 } |
| 786 |
| 787 void AwContents::HideGeolocationPrompt(const GURL& origin) { |
| 788 bool removed_current_outstanding_callback = false; |
| 789 std::list<OriginCallback>::iterator it = pending_geolocation_prompts_.begin(); |
| 790 while (it != pending_geolocation_prompts_.end()) { |
| 791 if ((*it).first == origin.GetOrigin()) { |
| 792 if (it == pending_geolocation_prompts_.begin()) { |
| 793 removed_current_outstanding_callback = true; |
| 794 } |
| 795 it = pending_geolocation_prompts_.erase(it); |
| 796 } else { |
| 797 ++it; |
| 798 } |
| 799 } |
| 800 |
| 801 if (removed_current_outstanding_callback) { |
| 802 JNIEnv* env = AttachCurrentThread(); |
| 803 ScopedJavaLocalRef<jobject> j_ref = java_ref_.get(env); |
| 804 if (j_ref.obj()) { |
| 805 Java_AwContents_onGeolocationPermissionsHidePrompt(env, j_ref.obj()); |
| 806 } |
| 807 if (!pending_geolocation_prompts_.empty()) { |
| 808 ShowGeolocationPromptHelper(java_ref_, |
| 809 pending_geolocation_prompts_.front().first); |
| 810 } |
| 811 } |
744 } | 812 } |
745 | 813 |
746 jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) { | 814 jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) { |
747 return GetFindHelper()->FindAllSync( | 815 return GetFindHelper()->FindAllSync( |
748 ConvertJavaStringToUTF16(env, search_string)); | 816 ConvertJavaStringToUTF16(env, search_string)); |
749 } | 817 } |
750 | 818 |
751 void AwContents::FindAllAsync(JNIEnv* env, jobject obj, jstring search_string) { | 819 void AwContents::FindAllAsync(JNIEnv* env, jobject obj, jstring search_string) { |
752 GetFindHelper()->FindAllAsync(ConvertJavaStringToUTF16(env, search_string)); | 820 GetFindHelper()->FindAllAsync(ConvertJavaStringToUTF16(env, search_string)); |
753 } | 821 } |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 if (!picture) { | 1163 if (!picture) { |
1096 render_view_host_ext_->CapturePictureSync(); | 1164 render_view_host_ext_->CapturePictureSync(); |
1097 picture = RendererPictureMap::GetInstance()->GetRendererPicture( | 1165 picture = RendererPictureMap::GetInstance()->GetRendererPicture( |
1098 web_contents_->GetRoutingID()); | 1166 web_contents_->GetRoutingID()); |
1099 } | 1167 } |
1100 | 1168 |
1101 return picture; | 1169 return picture; |
1102 } | 1170 } |
1103 | 1171 |
1104 } // namespace android_webview | 1172 } // namespace android_webview |
OLD | NEW |