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