| 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/android/download_controller_android.h" | 14 #include "content/public/browser/android/download_controller_android.h" |
| 15 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/common/file_chooser_params.h" | 19 #include "content/public/common/file_chooser_params.h" |
| 20 #include "jni/ChromeWebContentsDelegateAndroid_jni.h" | 20 #include "jni/ChromeWebContentsDelegateAndroid_jni.h" |
| 21 #include "net/http/http_request_headers.h" | 21 #include "net/http/http_request_headers.h" |
| 22 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
| 23 #include "ui/gfx/rect_f.h" | 23 #include "ui/gfx/rect_f.h" |
| 24 | 24 |
| 25 using base::android::AttachCurrentThread; | 25 using base::android::AttachCurrentThread; |
| 26 using base::android::GetClass; | 26 using base::android::GetClass; |
| 27 using base::android::MethodID; |
| 27 using base::android::ScopedJavaLocalRef; | 28 using base::android::ScopedJavaLocalRef; |
| 28 using content::FileChooserParams; | 29 using content::FileChooserParams; |
| 29 using content::WebContents; | 30 using content::WebContents; |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 // Convenience method to create Android rects. | 34 // Convenience method to create Android rects. |
| 34 // RectType should be either gfx::Rect or gfx::RectF. | 35 // RectType should be either gfx::Rect or gfx::RectF. |
| 35 template <typename RectType> | 36 template <typename RectType> |
| 36 ScopedJavaLocalRef<jobject> CreateAndroidRect( | 37 ScopedJavaLocalRef<jobject> CreateAndroidRect( |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 const FindNotificationDetails* find_result) { | 136 const FindNotificationDetails* find_result) { |
| 136 JNIEnv* env = AttachCurrentThread(); | 137 JNIEnv* env = AttachCurrentThread(); |
| 137 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 138 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
| 138 if (obj.is_null()) | 139 if (obj.is_null()) |
| 139 return; | 140 return; |
| 140 | 141 |
| 141 // Create the selection rect. | 142 // Create the selection rect. |
| 142 ScopedJavaLocalRef<jclass> rect_clazz = | 143 ScopedJavaLocalRef<jclass> rect_clazz = |
| 143 GetClass(env, "android/graphics/Rect"); | 144 GetClass(env, "android/graphics/Rect"); |
| 144 | 145 |
| 145 jmethodID rect_constructor = | 146 jmethodID rect_constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 146 GetMethodID(env, rect_clazz, "<init>", "(IIII)V"); | 147 env, rect_clazz.obj(), "<init>", "(IIII)V"); |
| 147 | 148 |
| 148 ScopedJavaLocalRef<jobject> selection_rect = CreateAndroidRect( | 149 ScopedJavaLocalRef<jobject> selection_rect = CreateAndroidRect( |
| 149 env, rect_clazz, rect_constructor, find_result->selection_rect()); | 150 env, rect_clazz, rect_constructor, find_result->selection_rect()); |
| 150 | 151 |
| 151 // Create the details object. | 152 // Create the details object. |
| 152 ScopedJavaLocalRef<jclass> details_clazz = | 153 ScopedJavaLocalRef<jclass> details_clazz = |
| 153 GetClass(env, "org/chromium/chrome/browser/FindNotificationDetails"); | 154 GetClass(env, "org/chromium/chrome/browser/FindNotificationDetails"); |
| 154 | 155 |
| 155 jmethodID details_constructor = GetMethodID(env, details_clazz, "<init>", | 156 jmethodID details_constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 156 "(ILandroid/graphics/Rect;IZ)V"); | 157 env, details_clazz.obj(), "<init>", "(ILandroid/graphics/Rect;IZ)V"); |
| 157 | 158 |
| 158 ScopedJavaLocalRef<jobject> details_object( | 159 ScopedJavaLocalRef<jobject> details_object( |
| 159 env, | 160 env, |
| 160 env->NewObject(details_clazz.obj(), | 161 env->NewObject(details_clazz.obj(), |
| 161 details_constructor, | 162 details_constructor, |
| 162 find_result->number_of_matches(), | 163 find_result->number_of_matches(), |
| 163 selection_rect.obj(), | 164 selection_rect.obj(), |
| 164 find_result->active_match_ordinal(), | 165 find_result->active_match_ordinal(), |
| 165 find_result->final_update())); | 166 find_result->final_update())); |
| 166 DCHECK(!details_object.is_null()); | 167 DCHECK(!details_object.is_null()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 184 | 185 |
| 185 JNIEnv* env = AttachCurrentThread(); | 186 JNIEnv* env = AttachCurrentThread(); |
| 186 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 187 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
| 187 if (obj.is_null()) | 188 if (obj.is_null()) |
| 188 return; | 189 return; |
| 189 | 190 |
| 190 // Create the rects. | 191 // Create the rects. |
| 191 ScopedJavaLocalRef<jclass> rect_clazz = | 192 ScopedJavaLocalRef<jclass> rect_clazz = |
| 192 GetClass(env, "android/graphics/RectF"); | 193 GetClass(env, "android/graphics/RectF"); |
| 193 | 194 |
| 194 jmethodID rect_constructor = | 195 jmethodID rect_constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 195 GetMethodID(env, rect_clazz, "<init>", "(FFFF)V"); | 196 env, rect_clazz.obj(), "<init>", "(FFFF)V"); |
| 196 | 197 |
| 197 ScopedJavaLocalRef<jobjectArray> jrects(env, env->NewObjectArray( | 198 ScopedJavaLocalRef<jobjectArray> jrects(env, env->NewObjectArray( |
| 198 match_rects.rects().size(), rect_clazz.obj(), NULL)); | 199 match_rects.rects().size(), rect_clazz.obj(), NULL)); |
| 199 | 200 |
| 200 for (size_t i = 0; i < match_rects.rects().size(); ++i) { | 201 for (size_t i = 0; i < match_rects.rects().size(); ++i) { |
| 201 env->SetObjectArrayElement( | 202 env->SetObjectArrayElement( |
| 202 jrects.obj(), i, | 203 jrects.obj(), i, |
| 203 CreateAndroidRect(env, | 204 CreateAndroidRect(env, |
| 204 rect_clazz, | 205 rect_clazz, |
| 205 rect_constructor, | 206 rect_constructor, |
| 206 match_rects.rects()[i]).obj()); | 207 match_rects.rects()[i]).obj()); |
| 207 } | 208 } |
| 208 | 209 |
| 209 ScopedJavaLocalRef<jobject> jactive_rect = CreateAndroidRect( | 210 ScopedJavaLocalRef<jobject> jactive_rect = CreateAndroidRect( |
| 210 env, rect_clazz, rect_constructor, match_rects.active_rect()); | 211 env, rect_clazz, rect_constructor, match_rects.active_rect()); |
| 211 | 212 |
| 212 // Create the details object. | 213 // Create the details object. |
| 213 ScopedJavaLocalRef<jclass> details_clazz = | 214 ScopedJavaLocalRef<jclass> details_clazz = |
| 214 GetClass(env, "org/chromium/chrome/browser/FindMatchRectsDetails"); | 215 GetClass(env, "org/chromium/chrome/browser/FindMatchRectsDetails"); |
| 215 | 216 |
| 216 jmethodID details_constructor = GetMethodID(env, details_clazz, "<init>", | 217 jmethodID details_constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 218 env, details_clazz.obj(), "<init>", |
| 217 "(I[Landroid/graphics/RectF;Landroid/graphics/RectF;)V"); | 219 "(I[Landroid/graphics/RectF;Landroid/graphics/RectF;)V"); |
| 218 | 220 |
| 219 ScopedJavaLocalRef<jobject> details_object( | 221 ScopedJavaLocalRef<jobject> details_object( |
| 220 env, | 222 env, |
| 221 env->NewObject(details_clazz.obj(), | 223 env->NewObject(details_clazz.obj(), |
| 222 details_constructor, | 224 details_constructor, |
| 223 match_rects.version(), | 225 match_rects.version(), |
| 224 jrects.obj(), | 226 jrects.obj(), |
| 225 jactive_rect.obj())); | 227 jactive_rect.obj())); |
| 226 DCHECK(!details_object.is_null()); | 228 DCHECK(!details_object.is_null()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 250 | 252 |
| 251 void ChromeWebContentsDelegateAndroid::OnStartDownload( | 253 void ChromeWebContentsDelegateAndroid::OnStartDownload( |
| 252 WebContents* source, | 254 WebContents* source, |
| 253 content::DownloadItem* download) { | 255 content::DownloadItem* download) { |
| 254 content::DownloadControllerAndroid::Get()->OnPostDownloadStarted( | 256 content::DownloadControllerAndroid::Get()->OnPostDownloadStarted( |
| 255 source, download); | 257 source, download); |
| 256 } | 258 } |
| 257 | 259 |
| 258 } // namespace android | 260 } // namespace android |
| 259 } // namespace chrome | 261 } // namespace chrome |
| OLD | NEW |