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 "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* ContentViewCoreImpl::GetRenderWidgetHostViewAndroid () { | |
|
Ted C
2012/07/27 01:31:53
>100 chars
| |
| 108 RenderWidgetHostView* rwhv = NULL; | |
| 109 if (!web_contents_) { | |
| 110 return NULL; | |
| 111 } else if (web_contents_->ShowingInterstitialPage()) { | |
|
aelias_OOO_until_Jul13
2012/07/27 01:35:04
Please delete this whole else block. This is the
| |
| 112 rwhv = web_contents_->GetInterstitialPage()-> | |
| 113 GetRenderViewHostForTesting()->GetView(); | |
| 114 // An interstitial page must have had Show() called immediately after | |
| 115 // construction in order for the render widget to exist. Currently Desktop | |
| 116 // Chrome does not enforce this is the case, however we do here to keep the | |
| 117 // state consistent with the WebContents. | |
| 118 CHECK(rwhv); | |
| 119 } else { | |
| 120 rwhv = web_contents_->GetRenderWidgetHostView(); | |
| 121 } | |
| 122 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | |
| 123 } | |
| 124 | |
| 99 // ---------------------------------------------------------------------------- | 125 // ---------------------------------------------------------------------------- |
| 100 // Methods called from Java via JNI | 126 // Methods called from Java via JNI |
| 101 // ---------------------------------------------------------------------------- | 127 // ---------------------------------------------------------------------------- |
| 102 | 128 |
| 103 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, | 129 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, |
| 104 jobject, | 130 jobject, |
| 105 jstring jurl, | 131 jstring jurl, |
| 106 int page_transition) { | 132 int page_transition) { |
| 107 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 133 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
| 108 | 134 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 138 // We report 1 in that case so the UI does not assume the page is loading. | 164 // 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()) | 165 if (web_contents()->GetURL().is_empty() || !content_view_client_.get()) |
| 140 return static_cast<jdouble>(1.0); | 166 return static_cast<jdouble>(1.0); |
| 141 return static_cast<jdouble>(content_view_client_->GetLoadProgress()); | 167 return static_cast<jdouble>(content_view_client_->GetLoadProgress()); |
| 142 } | 168 } |
| 143 | 169 |
| 144 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { | 170 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { |
| 145 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 171 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| 146 } | 172 } |
| 147 | 173 |
| 174 jboolean ContentViewCoreImpl::TouchEvent(JNIEnv* env, | |
| 175 jobject obj, | |
| 176 jlong time_ms, | |
| 177 jint type, | |
| 178 jobjectArray pts) { | |
| 179 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | |
| 180 if (rwhv) { | |
| 181 using WebKit::WebTouchEvent; | |
| 182 WebKit::WebTouchEvent event; | |
| 183 TouchPoint::BuildWebTouchEvent(env, type, time_ms, pts, event); | |
| 184 rwhv->TouchEvent(event); | |
| 185 return true; | |
| 186 } | |
| 187 return false; | |
| 188 } | |
| 189 | |
| 190 void ContentViewCoreImpl::SendGestureEvent(WebInputEvent::Type type, | |
| 191 long time_ms, int x, int y, | |
| 192 float dx, float dy, | |
| 193 bool link_preview_tap) { | |
| 194 WebKit::WebGestureEvent event = WebInputEventFactory::gestureEvent( | |
| 195 type, time_ms / 1000.0, x, y, dx, dy, 0); | |
| 196 if (GetRenderWidgetHostViewAndroid()) | |
| 197 GetRenderWidgetHostViewAndroid()->GestureEvent(event); | |
| 198 } | |
| 199 | |
| 200 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms, | |
| 201 jint x, jint y) { | |
| 202 SendGestureEvent( | |
| 203 WebInputEvent::GestureScrollBegin, time_ms, x, y, 0, 0, false); | |
| 204 } | |
| 205 | |
| 206 void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) { | |
| 207 SendGestureEvent(WebInputEvent::GestureScrollEnd, time_ms, 0, 0, 0, 0, false); | |
| 208 } | |
| 209 | |
| 210 void ContentViewCoreImpl::ScrollBy(JNIEnv* env, jobject obj, jlong time_ms, | |
| 211 jint dx, jint dy) { | |
| 212 SendGestureEvent( | |
| 213 WebInputEvent::GestureScrollUpdate, time_ms, 0, 0, -dx, -dy, false); | |
| 214 } | |
| 215 | |
| 216 void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms, | |
| 217 jint x, jint y, jint vx, jint vy) { | |
| 218 SendGestureEvent( | |
| 219 WebInputEvent::GestureFlingStart, time_ms, x, y, vx, vy, false); | |
| 220 } | |
| 221 | |
| 222 void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) { | |
| 223 SendGestureEvent( | |
| 224 WebInputEvent::GestureFlingCancel, time_ms, 0, 0, 0, 0, false); | |
| 225 } | |
| 226 | |
| 227 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, | |
| 228 jint x, jint y, jboolean link_preview_tap) { | |
| 229 SendGestureEvent( | |
| 230 WebInputEvent::GestureTap, time_ms, x, y, 0, 0, link_preview_tap); | |
| 231 } | |
| 232 | |
| 233 void ContentViewCoreImpl::ShowPressState(JNIEnv* env, jobject obj, | |
| 234 jlong time_ms, | |
| 235 jint x, jint y) { | |
| 236 SendGestureEvent(WebInputEvent::GestureTapDown, time_ms, x, y, 0, 0, false); | |
| 237 } | |
| 238 | |
| 239 void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, | |
| 240 jint x, jint y) { | |
| 241 SendGestureEvent(WebInputEvent::GestureDoubleTap, time_ms, x, y, 0, 0, false); | |
| 242 } | |
| 243 | |
| 244 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, | |
| 245 jint x, jint y, jboolean link_preview_tap) { | |
| 246 SendGestureEvent( | |
| 247 WebInputEvent::GestureLongPress, time_ms, x, y, 0, 0, link_preview_tap); | |
| 248 } | |
| 249 | |
| 250 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, | |
| 251 jint x, jint y) { | |
| 252 SendGestureEvent( | |
| 253 WebInputEvent::GesturePinchBegin, time_ms, x, y, 0, 0, false); | |
| 254 } | |
| 255 | |
| 256 void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) { | |
| 257 SendGestureEvent(WebInputEvent::GesturePinchEnd, time_ms, 0, 0, 0, 0, false); | |
| 258 } | |
| 259 | |
| 260 void ContentViewCoreImpl::PinchBy(JNIEnv* env, jobject obj, jlong time_ms, | |
| 261 jint anchor_x, jint anchor_y, jfloat delta) { | |
| 262 SendGestureEvent(WebInputEvent::GesturePinchUpdate, | |
| 263 time_ms, | |
| 264 anchor_x, | |
| 265 anchor_y, | |
| 266 delta, | |
| 267 delta, | |
| 268 false); | |
| 269 } | |
| 270 | |
| 148 jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { | 271 jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { |
| 149 return web_contents_->GetController().CanGoBack(); | 272 return web_contents_->GetController().CanGoBack(); |
| 150 } | 273 } |
| 151 | 274 |
| 152 jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { | 275 jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { |
| 153 return web_contents_->GetController().CanGoForward(); | 276 return web_contents_->GetController().CanGoForward(); |
| 154 } | 277 } |
| 155 | 278 |
| 156 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, | 279 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, |
| 157 jint offset) { | 280 jint offset) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 POPUP_ITEM_TYPE_DISABLED)); | 414 POPUP_ITEM_TYPE_DISABLED)); |
| 292 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 415 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
| 293 } | 416 } |
| 294 ScopedJavaLocalRef<jobjectArray> items_array( | 417 ScopedJavaLocalRef<jobjectArray> items_array( |
| 295 base::android::ToJavaArrayOfStrings(env, labels)); | 418 base::android::ToJavaArrayOfStrings(env, labels)); |
| 296 Java_ContentViewCore_showSelectPopup(env, java_object_->View(env).obj(), | 419 Java_ContentViewCore_showSelectPopup(env, java_object_->View(env).obj(), |
| 297 items_array.obj(), enabled_array.obj(), | 420 items_array.obj(), enabled_array.obj(), |
| 298 multiple, selected_array.obj()); | 421 multiple, selected_array.obj()); |
| 299 } | 422 } |
| 300 | 423 |
| 424 void ContentViewCoreImpl::ConfirmTouchEvent(bool handled) { | |
| 425 JNIEnv* env = AttachCurrentThread(); | |
| 426 Java_ContentViewCore_confirmTouchEvent(env, | |
| 427 java_object_->View(env).obj(), | |
| 428 handled); | |
| 429 } | |
| 430 | |
| 431 void ContentViewCoreImpl::DidSetNeedTouchEvents(bool need_touch_events) { | |
| 432 JNIEnv* env = AttachCurrentThread(); | |
| 433 Java_ContentViewCore_didSetNeedTouchEvents(env, | |
| 434 java_object_->View(env).obj(), | |
| 435 need_touch_events); | |
| 436 } | |
| 437 | |
| 301 bool ContentViewCoreImpl::HasFocus() { | 438 bool ContentViewCoreImpl::HasFocus() { |
| 302 NOTIMPLEMENTED() << "not upstreamed yet"; | 439 NOTIMPLEMENTED() << "not upstreamed yet"; |
| 303 return false; | 440 return false; |
| 304 } | 441 } |
| 305 | 442 |
| 306 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 443 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
| 307 NOTIMPLEMENTED() << "not upstreamed yet"; | 444 NOTIMPLEMENTED() << "not upstreamed yet"; |
| 308 } | 445 } |
| 309 | 446 |
| 310 void ContentViewCoreImpl::OnSelectionBoundsChanged( | 447 void ContentViewCoreImpl::OnSelectionBoundsChanged( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 516 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
| 380 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 517 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
| 381 return false; | 518 return false; |
| 382 } | 519 } |
| 383 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 520 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
| 384 | 521 |
| 385 return RegisterNativesImpl(env) >= 0; | 522 return RegisterNativesImpl(env) >= 0; |
| 386 } | 523 } |
| 387 | 524 |
| 388 } // namespace content | 525 } // namespace content |
| OLD | NEW |