| 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 "chrome/browser/android/chrome_web_contents_delegate_android.h" | 5 #include "chrome/browser/android/chrome_web_contents_delegate_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "chrome/browser/file_select_helper.h" | 8 #include "chrome/browser/file_select_helper.h" |
| 9 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" | 9 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" |
| 10 #include "chrome/browser/ui/find_bar/find_match_rects_details.h" | 10 #include "chrome/browser/ui/find_bar/find_match_rects_details.h" |
| 11 #include "chrome/browser/ui/find_bar/find_notification_details.h" | 11 #include "chrome/browser/ui/find_bar/find_notification_details.h" |
| 12 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 12 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
| 15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/common/file_chooser_params.h" | 18 #include "content/public/common/file_chooser_params.h" |
| 19 #include "jni/ChromeWebContentsDelegateAndroid_jni.h" | 19 #include "jni/ChromeWebContentsDelegateAndroid_jni.h" |
| 20 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
| 21 #include "ui/gfx/rect_f.h" | 21 #include "ui/gfx/rect_f.h" |
| 22 | 22 |
| 23 using base::android::AttachCurrentThread; | 23 using base::android::AttachCurrentThread; |
| 24 using base::android::GetClass; | 24 using base::android::GetClass; |
| 25 using base::android::MethodID; |
| 25 using base::android::ScopedJavaLocalRef; | 26 using base::android::ScopedJavaLocalRef; |
| 26 using content::FileChooserParams; | 27 using content::FileChooserParams; |
| 27 using content::WebContents; | 28 using content::WebContents; |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // Convenience method to create Android rects. | 32 // Convenience method to create Android rects. |
| 32 // RectType should be either gfx::Rect or gfx::RectF. | 33 // RectType should be either gfx::Rect or gfx::RectF. |
| 33 template <typename RectType> | 34 template <typename RectType> |
| 34 ScopedJavaLocalRef<jobject> CreateAndroidRect( | 35 ScopedJavaLocalRef<jobject> CreateAndroidRect( |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 const FindNotificationDetails* find_result) { | 134 const FindNotificationDetails* find_result) { |
| 134 JNIEnv* env = AttachCurrentThread(); | 135 JNIEnv* env = AttachCurrentThread(); |
| 135 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 136 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
| 136 if (obj.is_null()) | 137 if (obj.is_null()) |
| 137 return; | 138 return; |
| 138 | 139 |
| 139 // Create the selection rect. | 140 // Create the selection rect. |
| 140 ScopedJavaLocalRef<jclass> rect_clazz = | 141 ScopedJavaLocalRef<jclass> rect_clazz = |
| 141 GetClass(env, "android/graphics/Rect"); | 142 GetClass(env, "android/graphics/Rect"); |
| 142 | 143 |
| 143 jmethodID rect_constructor = | 144 jmethodID rect_constructor = MethodID::Get<MethodID::METHODTYPE_NORMAL>( |
| 144 GetMethodID(env, rect_clazz, "<init>", "(IIII)V"); | 145 env, rect_clazz.obj(), "<init>", "(IIII)V"); |
| 145 | 146 |
| 146 ScopedJavaLocalRef<jobject> selection_rect = CreateAndroidRect( | 147 ScopedJavaLocalRef<jobject> selection_rect = CreateAndroidRect( |
| 147 env, rect_clazz, rect_constructor, find_result->selection_rect()); | 148 env, rect_clazz, rect_constructor, find_result->selection_rect()); |
| 148 | 149 |
| 149 // Create the details object. | 150 // Create the details object. |
| 150 ScopedJavaLocalRef<jclass> details_clazz = | 151 ScopedJavaLocalRef<jclass> details_clazz = |
| 151 GetClass(env, "org/chromium/chrome/browser/FindNotificationDetails"); | 152 GetClass(env, "org/chromium/chrome/browser/FindNotificationDetails"); |
| 152 | 153 |
| 153 jmethodID details_constructor = GetMethodID(env, details_clazz, "<init>", | 154 jmethodID details_constructor = MethodID::Get<MethodID::METHODTYPE_NORMAL>( |
| 154 "(ILandroid/graphics/Rect;IZ)V"); | 155 env, details_clazz.obj(), "<init>", "(ILandroid/graphics/Rect;IZ)V"); |
| 155 | 156 |
| 156 ScopedJavaLocalRef<jobject> details_object( | 157 ScopedJavaLocalRef<jobject> details_object( |
| 157 env, | 158 env, |
| 158 env->NewObject(details_clazz.obj(), | 159 env->NewObject(details_clazz.obj(), |
| 159 details_constructor, | 160 details_constructor, |
| 160 find_result->number_of_matches(), | 161 find_result->number_of_matches(), |
| 161 selection_rect.obj(), | 162 selection_rect.obj(), |
| 162 find_result->active_match_ordinal(), | 163 find_result->active_match_ordinal(), |
| 163 find_result->final_update())); | 164 find_result->final_update())); |
| 164 DCHECK(!details_object.is_null()); | 165 DCHECK(!details_object.is_null()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 182 | 183 |
| 183 JNIEnv* env = AttachCurrentThread(); | 184 JNIEnv* env = AttachCurrentThread(); |
| 184 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 185 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
| 185 if (obj.is_null()) | 186 if (obj.is_null()) |
| 186 return; | 187 return; |
| 187 | 188 |
| 188 // Create the rects. | 189 // Create the rects. |
| 189 ScopedJavaLocalRef<jclass> rect_clazz = | 190 ScopedJavaLocalRef<jclass> rect_clazz = |
| 190 GetClass(env, "android/graphics/RectF"); | 191 GetClass(env, "android/graphics/RectF"); |
| 191 | 192 |
| 192 jmethodID rect_constructor = | 193 jmethodID rect_constructor = MethodID::Get<MethodID::METHODTYPE_NORMAL>( |
| 193 GetMethodID(env, rect_clazz, "<init>", "(FFFF)V"); | 194 env, rect_clazz.obj(), "<init>", "(FFFF)V"); |
| 194 | 195 |
| 195 ScopedJavaLocalRef<jobjectArray> jrects(env, env->NewObjectArray( | 196 ScopedJavaLocalRef<jobjectArray> jrects(env, env->NewObjectArray( |
| 196 match_rects.rects().size(), rect_clazz.obj(), NULL)); | 197 match_rects.rects().size(), rect_clazz.obj(), NULL)); |
| 197 | 198 |
| 198 for (size_t i = 0; i < match_rects.rects().size(); ++i) { | 199 for (size_t i = 0; i < match_rects.rects().size(); ++i) { |
| 199 env->SetObjectArrayElement( | 200 env->SetObjectArrayElement( |
| 200 jrects.obj(), i, | 201 jrects.obj(), i, |
| 201 CreateAndroidRect(env, | 202 CreateAndroidRect(env, |
| 202 rect_clazz, | 203 rect_clazz, |
| 203 rect_constructor, | 204 rect_constructor, |
| 204 match_rects.rects()[i]).obj()); | 205 match_rects.rects()[i]).obj()); |
| 205 } | 206 } |
| 206 | 207 |
| 207 ScopedJavaLocalRef<jobject> jactive_rect = CreateAndroidRect( | 208 ScopedJavaLocalRef<jobject> jactive_rect = CreateAndroidRect( |
| 208 env, rect_clazz, rect_constructor, match_rects.active_rect()); | 209 env, rect_clazz, rect_constructor, match_rects.active_rect()); |
| 209 | 210 |
| 210 // Create the details object. | 211 // Create the details object. |
| 211 ScopedJavaLocalRef<jclass> details_clazz = | 212 ScopedJavaLocalRef<jclass> details_clazz = |
| 212 GetClass(env, "org/chromium/chrome/browser/FindMatchRectsDetails"); | 213 GetClass(env, "org/chromium/chrome/browser/FindMatchRectsDetails"); |
| 213 | 214 |
| 214 jmethodID details_constructor = GetMethodID(env, details_clazz, "<init>", | 215 jmethodID details_constructor = MethodID::Get<MethodID::METHODTYPE_NORMAL>( |
| 216 env, details_clazz.obj(), "<init>", |
| 215 "(I[Landroid/graphics/RectF;Landroid/graphics/RectF;)V"); | 217 "(I[Landroid/graphics/RectF;Landroid/graphics/RectF;)V"); |
| 216 | 218 |
| 217 ScopedJavaLocalRef<jobject> details_object( | 219 ScopedJavaLocalRef<jobject> details_object( |
| 218 env, | 220 env, |
| 219 env->NewObject(details_clazz.obj(), | 221 env->NewObject(details_clazz.obj(), |
| 220 details_constructor, | 222 details_constructor, |
| 221 match_rects.version(), | 223 match_rects.version(), |
| 222 jrects.obj(), | 224 jrects.obj(), |
| 223 jactive_rect.obj())); | 225 jactive_rect.obj())); |
| 224 DCHECK(!details_object.is_null()); | 226 DCHECK(!details_object.is_null()); |
| 225 | 227 |
| 226 Java_ChromeWebContentsDelegateAndroid_onFindMatchRectsAvailable( | 228 Java_ChromeWebContentsDelegateAndroid_onFindMatchRectsAvailable( |
| 227 env, | 229 env, |
| 228 obj.obj(), | 230 obj.obj(), |
| 229 details_object.obj()); | 231 details_object.obj()); |
| 230 } | 232 } |
| 231 | 233 |
| 232 content::JavaScriptDialogCreator* | 234 content::JavaScriptDialogCreator* |
| 233 ChromeWebContentsDelegateAndroid::GetJavaScriptDialogCreator() { | 235 ChromeWebContentsDelegateAndroid::GetJavaScriptDialogCreator() { |
| 234 return GetJavaScriptDialogCreatorInstance(); | 236 return GetJavaScriptDialogCreatorInstance(); |
| 235 } | 237 } |
| 236 | 238 |
| 237 } // namespace android | 239 } // namespace android |
| 238 } // namespace chrome | 240 } // namespace chrome |
| OLD | NEW |