OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 156 |
157 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, | 157 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, |
158 bool hardware_accelerated, | 158 bool hardware_accelerated, |
159 WebContents* web_contents, | 159 WebContents* web_contents, |
160 ui::ViewAndroid* view_android, | 160 ui::ViewAndroid* view_android, |
161 ui::WindowAndroid* window_android) | 161 ui::WindowAndroid* window_android) |
162 : WebContentsObserver(web_contents), | 162 : WebContentsObserver(web_contents), |
163 java_ref_(env, obj), | 163 java_ref_(env, obj), |
164 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 164 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
165 root_layer_(cc::Layer::Create()), | 165 root_layer_(cc::Layer::Create()), |
166 tab_crashed_(false), | |
167 vsync_interval_(base::TimeDelta::FromMicroseconds( | 166 vsync_interval_(base::TimeDelta::FromMicroseconds( |
168 kDefaultVSyncIntervalMicros)), | 167 kDefaultVSyncIntervalMicros)), |
169 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( | 168 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( |
170 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), | 169 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), |
171 view_android_(view_android), | 170 view_android_(view_android), |
172 window_android_(window_android), | 171 window_android_(window_android), |
173 device_orientation_(0) { | 172 device_orientation_(0) { |
174 CHECK(web_contents) << | 173 CHECK(web_contents) << |
175 "A ContentViewCoreImpl should be created with a valid WebContents."; | 174 "A ContentViewCoreImpl should be created with a valid WebContents."; |
176 | 175 |
177 // When a tab is restored (from a saved state), it does not have a renderer | |
178 // process. We treat it like the tab is crashed. If the content is loaded | |
179 // when the tab is shown, tab_crashed_ will be reset. | |
180 UpdateTabCrashedFlag(); | |
181 | |
182 // TODO(leandrogracia): make use of the hardware_accelerated argument. | 176 // TODO(leandrogracia): make use of the hardware_accelerated argument. |
183 | 177 |
184 const gfx::Display& display = | 178 const gfx::Display& display = |
185 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 179 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
186 dpi_scale_ = display.device_scale_factor(); | 180 dpi_scale_ = display.device_scale_factor(); |
187 | 181 |
188 // Currently, the only use case we have for overriding a user agent involves | 182 // Currently, the only use case we have for overriding a user agent involves |
189 // spoofing a desktop Linux user agent for "Request desktop site". | 183 // spoofing a desktop Linux user agent for "Request desktop site". |
190 // Automatically set it for all WebContents so that it is available when a | 184 // Automatically set it for all WebContents so that it is available when a |
191 // NavigationEntry requires the user agent to be overridden. | 185 // NavigationEntry requires the user agent to be overridden. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 void ContentViewCoreImpl::OnHide(JNIEnv* env, jobject obj) { | 319 void ContentViewCoreImpl::OnHide(JNIEnv* env, jobject obj) { |
326 Hide(); | 320 Hide(); |
327 } | 321 } |
328 | 322 |
329 void ContentViewCoreImpl::OnShow(JNIEnv* env, jobject obj) { | 323 void ContentViewCoreImpl::OnShow(JNIEnv* env, jobject obj) { |
330 Show(); | 324 Show(); |
331 } | 325 } |
332 | 326 |
333 void ContentViewCoreImpl::Show() { | 327 void ContentViewCoreImpl::Show() { |
334 GetWebContents()->WasShown(); | 328 GetWebContents()->WasShown(); |
335 // Displaying WebContents may trigger a lazy reload, spawning a new renderer | |
336 // for the tab. | |
337 UpdateTabCrashedFlag(); | |
338 } | 329 } |
339 | 330 |
340 void ContentViewCoreImpl::Hide() { | 331 void ContentViewCoreImpl::Hide() { |
341 GetWebContents()->WasHidden(); | 332 GetWebContents()->WasHidden(); |
342 PauseVideo(); | 333 PauseVideo(); |
343 } | 334 } |
344 | 335 |
345 void ContentViewCoreImpl::PauseVideo() { | 336 void ContentViewCoreImpl::PauseVideo() { |
346 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 337 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
347 if (host) | 338 if (host) |
348 host->Send(new ViewMsg_PauseVideo(host->GetRoutingID())); | 339 host->Send(new ViewMsg_PauseVideo(host->GetRoutingID())); |
349 } | 340 } |
350 | 341 |
351 void ContentViewCoreImpl::OnTabCrashed() { | 342 void ContentViewCoreImpl::OnTabCrashed() { |
352 JNIEnv* env = AttachCurrentThread(); | 343 JNIEnv* env = AttachCurrentThread(); |
353 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 344 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
354 if (obj.is_null()) | 345 if (obj.is_null()) |
355 return; | 346 return; |
356 Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); | 347 Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); |
357 | |
358 // Note that we might reach this place multiple times while the | |
359 // ContentViewCore remains crashed. E.g. if two tabs share the render process | |
360 // and the process crashes, this will be called for each tab. If the user | |
361 // reload one tab, a new render process is created and it can be shared by the | |
362 // other tab. But if user closes the reloaded tab before reloading the other | |
363 // tab, the new render process will be shut down. This will trigger the other | |
364 // tab's OnTabCrashed() called again as two tabs share the same | |
365 // BrowserRenderProcessHost. The Java side will distinguish this case using | |
366 // tab_crashed_ passed below. | |
367 Java_ContentViewCore_onTabCrash(env, obj.obj(), tab_crashed_); | |
368 tab_crashed_ = true; | |
369 } | 348 } |
370 | 349 |
371 // All positions and sizes are in CSS pixels. | 350 // All positions and sizes are in CSS pixels. |
372 // Note that viewport_width/height is a best effort based. | 351 // Note that viewport_width/height is a best effort based. |
373 // ContentViewCore has the actual information about the physical viewport size. | 352 // ContentViewCore has the actual information about the physical viewport size. |
374 void ContentViewCoreImpl::UpdateFrameInfo( | 353 void ContentViewCoreImpl::UpdateFrameInfo( |
375 const gfx::Vector2dF& scroll_offset, | 354 const gfx::Vector2dF& scroll_offset, |
376 float page_scale_factor, | 355 float page_scale_factor, |
377 const gfx::Vector2dF& page_scale_factor_limits, | 356 const gfx::Vector2dF& page_scale_factor_limits, |
378 const gfx::SizeF& content_size, | 357 const gfx::SizeF& content_size, |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 root_layer_->AddChild(layer); | 693 root_layer_->AddChild(layer); |
715 } | 694 } |
716 | 695 |
717 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { | 696 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { |
718 layer->RemoveFromParent(); | 697 layer->RemoveFromParent(); |
719 } | 698 } |
720 | 699 |
721 void ContentViewCoreImpl::LoadUrl( | 700 void ContentViewCoreImpl::LoadUrl( |
722 NavigationController::LoadURLParams& params) { | 701 NavigationController::LoadURLParams& params) { |
723 GetWebContents()->GetController().LoadURLWithParams(params); | 702 GetWebContents()->GetController().LoadURLWithParams(params); |
724 UpdateTabCrashedFlag(); | |
725 } | 703 } |
726 | 704 |
727 void ContentViewCoreImpl::AddBeginFrameSubscriber() { | 705 void ContentViewCoreImpl::AddBeginFrameSubscriber() { |
728 JNIEnv* env = AttachCurrentThread(); | 706 JNIEnv* env = AttachCurrentThread(); |
729 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 707 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
730 if (obj.is_null()) | 708 if (obj.is_null()) |
731 return; | 709 return; |
732 Java_ContentViewCore_addVSyncSubscriber(env, obj.obj()); | 710 Java_ContentViewCore_addVSyncSubscriber(env, obj.obj()); |
733 } | 711 } |
734 | 712 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); | 940 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); |
963 } | 941 } |
964 | 942 |
965 void ContentViewCoreImpl::SendGestureEvent( | 943 void ContentViewCoreImpl::SendGestureEvent( |
966 const WebKit::WebGestureEvent& event) { | 944 const WebKit::WebGestureEvent& event) { |
967 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 945 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
968 if (rwhv) | 946 if (rwhv) |
969 rwhv->SendGestureEvent(event); | 947 rwhv->SendGestureEvent(event); |
970 } | 948 } |
971 | 949 |
972 void ContentViewCoreImpl::UpdateTabCrashedFlag() { | |
973 // Since RenderWidgetHostView is associated with the lifetime of the renderer | |
974 // process, we use it to test whether there is a renderer process. | |
975 tab_crashed_ = !(web_contents_->GetRenderWidgetHostView()); | |
976 } | |
977 | |
978 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms, | 950 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms, |
979 jfloat x, jfloat y) { | 951 jfloat x, jfloat y) { |
980 WebGestureEvent event = MakeGestureEvent( | 952 WebGestureEvent event = MakeGestureEvent( |
981 WebInputEvent::GestureScrollBegin, time_ms, x, y); | 953 WebInputEvent::GestureScrollBegin, time_ms, x, y); |
982 SendGestureEvent(event); | 954 SendGestureEvent(event); |
983 } | 955 } |
984 | 956 |
985 void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) { | 957 void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) { |
986 WebGestureEvent event = MakeGestureEvent( | 958 WebGestureEvent event = MakeGestureEvent( |
987 WebInputEvent::GestureScrollEnd, time_ms, 0, 0); | 959 WebInputEvent::GestureScrollEnd, time_ms, 0, 0); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 return web_contents_->GetController().CanGoForward(); | 1132 return web_contents_->GetController().CanGoForward(); |
1161 } | 1133 } |
1162 | 1134 |
1163 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, | 1135 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, |
1164 jint offset) { | 1136 jint offset) { |
1165 return web_contents_->GetController().CanGoToOffset(offset); | 1137 return web_contents_->GetController().CanGoToOffset(offset); |
1166 } | 1138 } |
1167 | 1139 |
1168 void ContentViewCoreImpl::GoBack(JNIEnv* env, jobject obj) { | 1140 void ContentViewCoreImpl::GoBack(JNIEnv* env, jobject obj) { |
1169 web_contents_->GetController().GoBack(); | 1141 web_contents_->GetController().GoBack(); |
1170 UpdateTabCrashedFlag(); | |
1171 } | 1142 } |
1172 | 1143 |
1173 void ContentViewCoreImpl::GoForward(JNIEnv* env, jobject obj) { | 1144 void ContentViewCoreImpl::GoForward(JNIEnv* env, jobject obj) { |
1174 web_contents_->GetController().GoForward(); | 1145 web_contents_->GetController().GoForward(); |
1175 UpdateTabCrashedFlag(); | |
1176 } | 1146 } |
1177 | 1147 |
1178 void ContentViewCoreImpl::GoToOffset(JNIEnv* env, jobject obj, jint offset) { | 1148 void ContentViewCoreImpl::GoToOffset(JNIEnv* env, jobject obj, jint offset) { |
1179 web_contents_->GetController().GoToOffset(offset); | 1149 web_contents_->GetController().GoToOffset(offset); |
1180 UpdateTabCrashedFlag(); | |
1181 } | 1150 } |
1182 | 1151 |
1183 void ContentViewCoreImpl::GoToNavigationIndex(JNIEnv* env, | 1152 void ContentViewCoreImpl::GoToNavigationIndex(JNIEnv* env, |
1184 jobject obj, | 1153 jobject obj, |
1185 jint index) { | 1154 jint index) { |
1186 web_contents_->GetController().GoToIndex(index); | 1155 web_contents_->GetController().GoToIndex(index); |
1187 UpdateTabCrashedFlag(); | |
1188 } | 1156 } |
1189 | 1157 |
1190 void ContentViewCoreImpl::LoadIfNecessary(JNIEnv* env, jobject obj) { | 1158 void ContentViewCoreImpl::LoadIfNecessary(JNIEnv* env, jobject obj) { |
1191 web_contents_->GetController().LoadIfNecessary(); | 1159 web_contents_->GetController().LoadIfNecessary(); |
1192 UpdateTabCrashedFlag(); | |
1193 } | 1160 } |
1194 | 1161 |
1195 void ContentViewCoreImpl::RequestRestoreLoad(JNIEnv* env, jobject obj) { | 1162 void ContentViewCoreImpl::RequestRestoreLoad(JNIEnv* env, jobject obj) { |
1196 web_contents_->GetController().SetNeedsReload(); | 1163 web_contents_->GetController().SetNeedsReload(); |
1197 } | 1164 } |
1198 | 1165 |
1199 void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) { | 1166 void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) { |
1200 web_contents_->Stop(); | 1167 web_contents_->Stop(); |
1201 } | 1168 } |
1202 | 1169 |
1203 void ContentViewCoreImpl::Reload(JNIEnv* env, jobject obj) { | 1170 void ContentViewCoreImpl::Reload(JNIEnv* env, jobject obj) { |
1204 // Set check_for_repost parameter to false as we have no repost confirmation | 1171 // Set check_for_repost parameter to false as we have no repost confirmation |
1205 // dialog ("confirm form resubmission" screen will still appear, however). | 1172 // dialog ("confirm form resubmission" screen will still appear, however). |
1206 if (web_contents_->GetController().NeedsReload()) | 1173 if (web_contents_->GetController().NeedsReload()) |
1207 web_contents_->GetController().LoadIfNecessary(); | 1174 web_contents_->GetController().LoadIfNecessary(); |
1208 else | 1175 else |
1209 web_contents_->GetController().Reload(true); | 1176 web_contents_->GetController().Reload(true); |
1210 UpdateTabCrashedFlag(); | |
1211 } | 1177 } |
1212 | 1178 |
1213 void ContentViewCoreImpl::CancelPendingReload(JNIEnv* env, jobject obj) { | 1179 void ContentViewCoreImpl::CancelPendingReload(JNIEnv* env, jobject obj) { |
1214 web_contents_->GetController().CancelPendingReload(); | 1180 web_contents_->GetController().CancelPendingReload(); |
1215 } | 1181 } |
1216 | 1182 |
1217 void ContentViewCoreImpl::ContinuePendingReload(JNIEnv* env, jobject obj) { | 1183 void ContentViewCoreImpl::ContinuePendingReload(JNIEnv* env, jobject obj) { |
1218 web_contents_->GetController().ContinuePendingReload(); | 1184 web_contents_->GetController().ContinuePendingReload(); |
1219 } | 1185 } |
1220 | 1186 |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1642 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1608 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1643 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1609 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1644 return reinterpret_cast<jint>(view); | 1610 return reinterpret_cast<jint>(view); |
1645 } | 1611 } |
1646 | 1612 |
1647 bool RegisterContentViewCore(JNIEnv* env) { | 1613 bool RegisterContentViewCore(JNIEnv* env) { |
1648 return RegisterNativesImpl(env); | 1614 return RegisterNativesImpl(env); |
1649 } | 1615 } |
1650 | 1616 |
1651 } // namespace content | 1617 } // namespace content |
OLD | NEW |