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< |
144 GetMethodID(env, rect_clazz, "<init>", "(IIII)V"); | 145 MethodID::METHODTYPE_NORMAL, MethodID::EXCEPTIONCHECK_YES>( |
| 146 env, rect_clazz.obj(), "<init>", "(IIII)V"); |
145 | 147 |
146 ScopedJavaLocalRef<jobject> selection_rect = CreateAndroidRect( | 148 ScopedJavaLocalRef<jobject> selection_rect = CreateAndroidRect( |
147 env, rect_clazz, rect_constructor, find_result->selection_rect()); | 149 env, rect_clazz, rect_constructor, find_result->selection_rect()); |
148 | 150 |
149 // Create the details object. | 151 // Create the details object. |
150 ScopedJavaLocalRef<jclass> details_clazz = | 152 ScopedJavaLocalRef<jclass> details_clazz = |
151 GetClass(env, "org/chromium/chrome/browser/FindNotificationDetails"); | 153 GetClass(env, "org/chromium/chrome/browser/FindNotificationDetails"); |
152 | 154 |
153 jmethodID details_constructor = GetMethodID(env, details_clazz, "<init>", | 155 jmethodID details_constructor = MethodID::Get< |
154 "(ILandroid/graphics/Rect;IZ)V"); | 156 MethodID::METHODTYPE_NORMAL, MethodID::EXCEPTIONCHECK_YES>( |
| 157 env, details_clazz.obj(), "<init>", "(ILandroid/graphics/Rect;IZ)V"); |
155 | 158 |
156 ScopedJavaLocalRef<jobject> details_object( | 159 ScopedJavaLocalRef<jobject> details_object( |
157 env, | 160 env, |
158 env->NewObject(details_clazz.obj(), | 161 env->NewObject(details_clazz.obj(), |
159 details_constructor, | 162 details_constructor, |
160 find_result->number_of_matches(), | 163 find_result->number_of_matches(), |
161 selection_rect.obj(), | 164 selection_rect.obj(), |
162 find_result->active_match_ordinal(), | 165 find_result->active_match_ordinal(), |
163 find_result->final_update())); | 166 find_result->final_update())); |
164 DCHECK(!details_object.is_null()); | 167 DCHECK(!details_object.is_null()); |
(...skipping 17 matching lines...) Expand all Loading... |
182 | 185 |
183 JNIEnv* env = AttachCurrentThread(); | 186 JNIEnv* env = AttachCurrentThread(); |
184 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 187 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
185 if (obj.is_null()) | 188 if (obj.is_null()) |
186 return; | 189 return; |
187 | 190 |
188 // Create the rects. | 191 // Create the rects. |
189 ScopedJavaLocalRef<jclass> rect_clazz = | 192 ScopedJavaLocalRef<jclass> rect_clazz = |
190 GetClass(env, "android/graphics/RectF"); | 193 GetClass(env, "android/graphics/RectF"); |
191 | 194 |
192 jmethodID rect_constructor = | 195 jmethodID rect_constructor = MethodID::Get< |
193 GetMethodID(env, rect_clazz, "<init>", "(FFFF)V"); | 196 MethodID::METHODTYPE_NORMAL, MethodID::EXCEPTIONCHECK_YES>( |
| 197 env, rect_clazz.obj(), "<init>", "(FFFF)V"); |
194 | 198 |
195 ScopedJavaLocalRef<jobjectArray> jrects(env, env->NewObjectArray( | 199 ScopedJavaLocalRef<jobjectArray> jrects(env, env->NewObjectArray( |
196 match_rects.rects().size(), rect_clazz.obj(), NULL)); | 200 match_rects.rects().size(), rect_clazz.obj(), NULL)); |
197 | 201 |
198 for (size_t i = 0; i < match_rects.rects().size(); ++i) { | 202 for (size_t i = 0; i < match_rects.rects().size(); ++i) { |
199 env->SetObjectArrayElement( | 203 env->SetObjectArrayElement( |
200 jrects.obj(), i, | 204 jrects.obj(), i, |
201 CreateAndroidRect(env, | 205 CreateAndroidRect(env, |
202 rect_clazz, | 206 rect_clazz, |
203 rect_constructor, | 207 rect_constructor, |
204 match_rects.rects()[i]).obj()); | 208 match_rects.rects()[i]).obj()); |
205 } | 209 } |
206 | 210 |
207 ScopedJavaLocalRef<jobject> jactive_rect = CreateAndroidRect( | 211 ScopedJavaLocalRef<jobject> jactive_rect = CreateAndroidRect( |
208 env, rect_clazz, rect_constructor, match_rects.active_rect()); | 212 env, rect_clazz, rect_constructor, match_rects.active_rect()); |
209 | 213 |
210 // Create the details object. | 214 // Create the details object. |
211 ScopedJavaLocalRef<jclass> details_clazz = | 215 ScopedJavaLocalRef<jclass> details_clazz = |
212 GetClass(env, "org/chromium/chrome/browser/FindMatchRectsDetails"); | 216 GetClass(env, "org/chromium/chrome/browser/FindMatchRectsDetails"); |
213 | 217 |
214 jmethodID details_constructor = GetMethodID(env, details_clazz, "<init>", | 218 jmethodID details_constructor = MethodID::Get< |
215 "(I[Landroid/graphics/RectF;Landroid/graphics/RectF;)V"); | 219 MethodID::METHODTYPE_NORMAL, MethodID::EXCEPTIONCHECK_YES>( |
| 220 env, details_clazz.obj(), "<init>", |
| 221 "(I[Landroid/graphics/RectF;Landroid/graphics/RectF;)V"); |
216 | 222 |
217 ScopedJavaLocalRef<jobject> details_object( | 223 ScopedJavaLocalRef<jobject> details_object( |
218 env, | 224 env, |
219 env->NewObject(details_clazz.obj(), | 225 env->NewObject(details_clazz.obj(), |
220 details_constructor, | 226 details_constructor, |
221 match_rects.version(), | 227 match_rects.version(), |
222 jrects.obj(), | 228 jrects.obj(), |
223 jactive_rect.obj())); | 229 jactive_rect.obj())); |
224 DCHECK(!details_object.is_null()); | 230 DCHECK(!details_object.is_null()); |
225 | 231 |
226 Java_ChromeWebContentsDelegateAndroid_onFindMatchRectsAvailable( | 232 Java_ChromeWebContentsDelegateAndroid_onFindMatchRectsAvailable( |
227 env, | 233 env, |
228 obj.obj(), | 234 obj.obj(), |
229 details_object.obj()); | 235 details_object.obj()); |
230 } | 236 } |
231 | 237 |
232 content::JavaScriptDialogCreator* | 238 content::JavaScriptDialogCreator* |
233 ChromeWebContentsDelegateAndroid::GetJavaScriptDialogCreator() { | 239 ChromeWebContentsDelegateAndroid::GetJavaScriptDialogCreator() { |
234 return GetJavaScriptDialogCreatorInstance(); | 240 return GetJavaScriptDialogCreatorInstance(); |
235 } | 241 } |
236 | 242 |
237 } // namespace android | 243 } // namespace android |
238 } // namespace chrome | 244 } // namespace chrome |
OLD | NEW |