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 ShowGeolocationPromptHelperTask(JavaObjectWeakGlobalRef java_ref, |
|
benm (inactive)
2013/02/12 19:40:33
nit: const& ? (throughout)
Kristian Monsen
2013/02/12 23:48:35
Added const here. Didn't do it for the callback as
| |
| 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(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 void AwContents::InvokeGeolocationCallback(JNIEnv* env, | |
| 771 jobject obj, | |
| 772 jboolean value, | |
| 773 jstring origin) { | |
| 774 GURL callback_origin(base::android::ConvertJavaStringToUTF16(env, origin)); | |
| 775 if (callback_origin.GetOrigin() == | |
| 776 pending_geolocation_prompts_.front().first) { | |
| 777 pending_geolocation_prompts_.front().second.Run(value); | |
| 778 pending_geolocation_prompts_.pop_front(); | |
| 779 if (!pending_geolocation_prompts_.empty()) { | |
| 780 ShowGeolocationPromptHelper(java_ref_, | |
| 781 pending_geolocation_prompts_.front().first); | |
| 782 } | |
| 783 } | |
| 784 } | |
| 785 | |
| 786 void AwContents::HideGeolocationPrompt(const GURL& origin) { | |
| 787 bool removed_current_outstanding_callback = false; | |
| 788 std::list<OriginCallback>::iterator it = pending_geolocation_prompts_.begin(); | |
| 789 while (it != pending_geolocation_prompts_.end()) { | |
| 790 if ((*it).first == origin.GetOrigin()) { | |
| 791 if (it == pending_geolocation_prompts_.begin()) { | |
| 792 removed_current_outstanding_callback = true; | |
| 793 } | |
| 794 it = pending_geolocation_prompts_.erase(it); | |
| 795 } else { | |
| 796 ++it; | |
| 797 } | |
| 798 } | |
| 799 | |
| 800 if (removed_current_outstanding_callback) { | |
| 801 JNIEnv* env = AttachCurrentThread(); | |
| 802 ScopedJavaLocalRef<jobject> j_ref = java_ref_.get(env); | |
| 803 if (j_ref.obj()) { | |
| 804 Java_AwContents_onGeolocationPermissionsHidePrompt(env, j_ref.obj()); | |
| 805 } | |
| 806 if (!pending_geolocation_prompts_.empty()) { | |
| 807 ShowGeolocationPromptHelper(java_ref_, | |
| 808 pending_geolocation_prompts_.front().first); | |
| 809 } | |
| 810 } | |
| 744 } | 811 } |
| 745 | 812 |
| 746 jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) { | 813 jint AwContents::FindAllSync(JNIEnv* env, jobject obj, jstring search_string) { |
| 747 return GetFindHelper()->FindAllSync( | 814 return GetFindHelper()->FindAllSync( |
| 748 ConvertJavaStringToUTF16(env, search_string)); | 815 ConvertJavaStringToUTF16(env, search_string)); |
| 749 } | 816 } |
| 750 | 817 |
| 751 void AwContents::FindAllAsync(JNIEnv* env, jobject obj, jstring search_string) { | 818 void AwContents::FindAllAsync(JNIEnv* env, jobject obj, jstring search_string) { |
| 752 GetFindHelper()->FindAllAsync(ConvertJavaStringToUTF16(env, search_string)); | 819 GetFindHelper()->FindAllAsync(ConvertJavaStringToUTF16(env, search_string)); |
| 753 } | 820 } |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1095 if (!picture) { | 1162 if (!picture) { |
| 1096 render_view_host_ext_->CapturePictureSync(); | 1163 render_view_host_ext_->CapturePictureSync(); |
| 1097 picture = RendererPictureMap::GetInstance()->GetRendererPicture( | 1164 picture = RendererPictureMap::GetInstance()->GetRendererPicture( |
| 1098 web_contents_->GetRoutingID()); | 1165 web_contents_->GetRoutingID()); |
| 1099 } | 1166 } |
| 1100 | 1167 |
| 1101 return picture; | 1168 return picture; |
| 1102 } | 1169 } |
| 1103 | 1170 |
| 1104 } // namespace android_webview | 1171 } // namespace android_webview |
| OLD | NEW |