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 "content/browser/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "content/browser/android/content_view_client.h" | 11 #include "content/browser/android/content_view_client.h" |
| 12 #include "content/browser/android/touch_point.h" |
12 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 15 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
13 #include "content/browser/web_contents/navigation_controller_impl.h" | 16 #include "content/browser/web_contents/navigation_controller_impl.h" |
14 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/interstitial_page.h" |
15 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
16 #include "jni/ContentViewCore_jni.h" | 20 #include "jni/ContentViewCore_jni.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent
Factory.h" |
17 #include "webkit/glue/webmenuitem.h" | 23 #include "webkit/glue/webmenuitem.h" |
18 | 24 |
19 using base::android::AttachCurrentThread; | 25 using base::android::AttachCurrentThread; |
20 using base::android::ConvertUTF16ToJavaString; | 26 using base::android::ConvertUTF16ToJavaString; |
21 using base::android::ConvertUTF8ToJavaString; | 27 using base::android::ConvertUTF8ToJavaString; |
22 using base::android::GetClass; | 28 using base::android::GetClass; |
23 using base::android::HasField; | 29 using base::android::HasField; |
24 using base::android::ScopedJavaGlobalRef; | 30 using base::android::ScopedJavaGlobalRef; |
25 using base::android::ScopedJavaLocalRef; | 31 using base::android::ScopedJavaLocalRef; |
| 32 using WebKit::WebInputEvent; |
| 33 using WebKit::WebInputEventFactory; |
26 | 34 |
27 // Describes the type and enabled state of a select popup item. | 35 // Describes the type and enabled state of a select popup item. |
28 // Keep in sync with the value defined in SelectPopupDialog.java | 36 // Keep in sync with the value defined in SelectPopupDialog.java |
29 enum PopupItemType { | 37 enum PopupItemType { |
30 POPUP_ITEM_TYPE_GROUP = 0, | 38 POPUP_ITEM_TYPE_GROUP = 0, |
31 POPUP_ITEM_TYPE_DISABLED, | 39 POPUP_ITEM_TYPE_DISABLED, |
32 POPUP_ITEM_TYPE_ENABLED | 40 POPUP_ITEM_TYPE_ENABLED |
33 }; | 41 }; |
34 | 42 |
35 namespace { | 43 namespace { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 const NotificationSource& source, | 97 const NotificationSource& source, |
90 const NotificationDetails& details) { | 98 const NotificationDetails& details) { |
91 // TODO(jrg) | 99 // TODO(jrg) |
92 } | 100 } |
93 | 101 |
94 void ContentViewCoreImpl::InitJNI(JNIEnv* env, jobject obj) { | 102 void ContentViewCoreImpl::InitJNI(JNIEnv* env, jobject obj) { |
95 java_object_ = new JavaObject; | 103 java_object_ = new JavaObject; |
96 java_object_->obj = env->NewWeakGlobalRef(obj); | 104 java_object_->obj = env->NewWeakGlobalRef(obj); |
97 } | 105 } |
98 | 106 |
| 107 RenderWidgetHostViewAndroid* |
| 108 ContentViewCoreImpl::GetRenderWidgetHostViewAndroid() { |
| 109 RenderWidgetHostView* rwhv = NULL; |
| 110 if (web_contents_) |
| 111 rwhv = web_contents_->GetRenderWidgetHostView(); |
| 112 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); |
| 113 } |
| 114 |
99 // ---------------------------------------------------------------------------- | 115 // ---------------------------------------------------------------------------- |
100 // Methods called from Java via JNI | 116 // Methods called from Java via JNI |
101 // ---------------------------------------------------------------------------- | 117 // ---------------------------------------------------------------------------- |
102 | 118 |
103 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, | 119 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, |
104 jobject, | 120 jobject, |
105 jstring jurl, | 121 jstring jurl, |
106 int page_transition) { | 122 int page_transition) { |
107 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 123 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
108 | 124 |
(...skipping 29 matching lines...) Expand all Loading... |
138 // We report 1 in that case so the UI does not assume the page is loading. | 154 // We report 1 in that case so the UI does not assume the page is loading. |
139 if (web_contents()->GetURL().is_empty() || !content_view_client_.get()) | 155 if (web_contents()->GetURL().is_empty() || !content_view_client_.get()) |
140 return static_cast<jdouble>(1.0); | 156 return static_cast<jdouble>(1.0); |
141 return static_cast<jdouble>(content_view_client_->GetLoadProgress()); | 157 return static_cast<jdouble>(content_view_client_->GetLoadProgress()); |
142 } | 158 } |
143 | 159 |
144 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { | 160 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { |
145 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 161 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
146 } | 162 } |
147 | 163 |
| 164 jboolean ContentViewCoreImpl::TouchEvent(JNIEnv* env, |
| 165 jobject obj, |
| 166 jlong time_ms, |
| 167 jint type, |
| 168 jobjectArray pts) { |
| 169 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 170 if (rwhv) { |
| 171 using WebKit::WebTouchEvent; |
| 172 WebKit::WebTouchEvent event; |
| 173 TouchPoint::BuildWebTouchEvent(env, type, time_ms, pts, event); |
| 174 rwhv->TouchEvent(event); |
| 175 return true; |
| 176 } |
| 177 return false; |
| 178 } |
| 179 |
| 180 void ContentViewCoreImpl::SendGestureEvent(WebInputEvent::Type type, |
| 181 long time_ms, int x, int y, |
| 182 float dx, float dy, |
| 183 bool link_preview_tap) { |
| 184 WebKit::WebGestureEvent event = WebInputEventFactory::gestureEvent( |
| 185 type, time_ms / 1000.0, x, y, dx, dy, 0); |
| 186 if (GetRenderWidgetHostViewAndroid()) |
| 187 GetRenderWidgetHostViewAndroid()->GestureEvent(event); |
| 188 } |
| 189 |
| 190 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms, |
| 191 jint x, jint y) { |
| 192 SendGestureEvent( |
| 193 WebInputEvent::GestureScrollBegin, time_ms, x, y, 0, 0, false); |
| 194 } |
| 195 |
| 196 void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) { |
| 197 SendGestureEvent(WebInputEvent::GestureScrollEnd, time_ms, 0, 0, 0, 0, false); |
| 198 } |
| 199 |
| 200 void ContentViewCoreImpl::ScrollBy(JNIEnv* env, jobject obj, jlong time_ms, |
| 201 jint dx, jint dy) { |
| 202 SendGestureEvent( |
| 203 WebInputEvent::GestureScrollUpdate, time_ms, 0, 0, -dx, -dy, false); |
| 204 } |
| 205 |
| 206 void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms, |
| 207 jint x, jint y, jint vx, jint vy) { |
| 208 SendGestureEvent( |
| 209 WebInputEvent::GestureFlingStart, time_ms, x, y, vx, vy, false); |
| 210 } |
| 211 |
| 212 void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) { |
| 213 SendGestureEvent( |
| 214 WebInputEvent::GestureFlingCancel, time_ms, 0, 0, 0, 0, false); |
| 215 } |
| 216 |
| 217 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, |
| 218 jint x, jint y, jboolean link_preview_tap) { |
| 219 SendGestureEvent( |
| 220 WebInputEvent::GestureTap, time_ms, x, y, 0, 0, link_preview_tap); |
| 221 } |
| 222 |
| 223 void ContentViewCoreImpl::ShowPressState(JNIEnv* env, jobject obj, |
| 224 jlong time_ms, |
| 225 jint x, jint y) { |
| 226 SendGestureEvent(WebInputEvent::GestureTapDown, time_ms, x, y, 0, 0, false); |
| 227 } |
| 228 |
| 229 void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, |
| 230 jint x, jint y) { |
| 231 SendGestureEvent(WebInputEvent::GestureDoubleTap, time_ms, x, y, 0, 0, false); |
| 232 } |
| 233 |
| 234 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, |
| 235 jint x, jint y, jboolean link_preview_tap) { |
| 236 SendGestureEvent( |
| 237 WebInputEvent::GestureLongPress, time_ms, x, y, 0, 0, link_preview_tap); |
| 238 } |
| 239 |
| 240 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, |
| 241 jint x, jint y) { |
| 242 SendGestureEvent( |
| 243 WebInputEvent::GesturePinchBegin, time_ms, x, y, 0, 0, false); |
| 244 } |
| 245 |
| 246 void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) { |
| 247 SendGestureEvent(WebInputEvent::GesturePinchEnd, time_ms, 0, 0, 0, 0, false); |
| 248 } |
| 249 |
| 250 void ContentViewCoreImpl::PinchBy(JNIEnv* env, jobject obj, jlong time_ms, |
| 251 jint anchor_x, jint anchor_y, jfloat delta) { |
| 252 SendGestureEvent(WebInputEvent::GesturePinchUpdate, |
| 253 time_ms, |
| 254 anchor_x, |
| 255 anchor_y, |
| 256 delta, |
| 257 delta, |
| 258 false); |
| 259 } |
| 260 |
148 jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { | 261 jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { |
149 return web_contents_->GetController().CanGoBack(); | 262 return web_contents_->GetController().CanGoBack(); |
150 } | 263 } |
151 | 264 |
152 jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { | 265 jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { |
153 return web_contents_->GetController().CanGoForward(); | 266 return web_contents_->GetController().CanGoForward(); |
154 } | 267 } |
155 | 268 |
156 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, | 269 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, |
157 jint offset) { | 270 jint offset) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 POPUP_ITEM_TYPE_DISABLED)); | 404 POPUP_ITEM_TYPE_DISABLED)); |
292 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 405 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
293 } | 406 } |
294 ScopedJavaLocalRef<jobjectArray> items_array( | 407 ScopedJavaLocalRef<jobjectArray> items_array( |
295 base::android::ToJavaArrayOfStrings(env, labels)); | 408 base::android::ToJavaArrayOfStrings(env, labels)); |
296 Java_ContentViewCore_showSelectPopup(env, java_object_->View(env).obj(), | 409 Java_ContentViewCore_showSelectPopup(env, java_object_->View(env).obj(), |
297 items_array.obj(), enabled_array.obj(), | 410 items_array.obj(), enabled_array.obj(), |
298 multiple, selected_array.obj()); | 411 multiple, selected_array.obj()); |
299 } | 412 } |
300 | 413 |
| 414 void ContentViewCoreImpl::ConfirmTouchEvent(bool handled) { |
| 415 // TODO(yusufo): Upstream changes for http://crbug/139386 to match upstream |
| 416 // to downstream. |
| 417 JNIEnv* env = AttachCurrentThread(); |
| 418 Java_ContentViewCore_confirmTouchEvent(env, |
| 419 java_object_->View(env).obj(), |
| 420 handled); |
| 421 } |
| 422 |
| 423 void ContentViewCoreImpl::DidSetNeedTouchEvents(bool need_touch_events) { |
| 424 JNIEnv* env = AttachCurrentThread(); |
| 425 Java_ContentViewCore_didSetNeedTouchEvents(env, |
| 426 java_object_->View(env).obj(), |
| 427 need_touch_events); |
| 428 } |
| 429 |
301 bool ContentViewCoreImpl::HasFocus() { | 430 bool ContentViewCoreImpl::HasFocus() { |
302 NOTIMPLEMENTED() << "not upstreamed yet"; | 431 NOTIMPLEMENTED() << "not upstreamed yet"; |
303 return false; | 432 return false; |
304 } | 433 } |
305 | 434 |
306 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 435 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
307 NOTIMPLEMENTED() << "not upstreamed yet"; | 436 NOTIMPLEMENTED() << "not upstreamed yet"; |
308 } | 437 } |
309 | 438 |
310 void ContentViewCoreImpl::OnSelectionBoundsChanged( | 439 void ContentViewCoreImpl::OnSelectionBoundsChanged( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 508 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
380 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 509 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
381 return false; | 510 return false; |
382 } | 511 } |
383 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 512 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
384 | 513 |
385 return RegisterNativesImpl(env) >= 0; | 514 return RegisterNativesImpl(env) >= 0; |
386 } | 515 } |
387 | 516 |
388 } // namespace content | 517 } // namespace content |
OLD | NEW |