| 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/renderer_host/render_widget_host_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 } // namespace | 173 } // namespace |
| 174 | 174 |
| 175 /////////////////////////////////////////////////////////////////////////////// | 175 /////////////////////////////////////////////////////////////////////////////// |
| 176 // RenderWidgetHostImpl | 176 // RenderWidgetHostImpl |
| 177 | 177 |
| 178 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, | 178 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, |
| 179 RenderProcessHost* process, | 179 RenderProcessHost* process, |
| 180 int32_t routing_id, | 180 int32_t routing_id, |
| 181 bool hidden) | 181 bool hidden) |
| 182 : view_(NULL), | 182 : renderer_initialized_(false), |
| 183 renderer_initialized_(false), | 183 destroyed_(false), |
| 184 delegate_(delegate), | 184 delegate_(delegate), |
| 185 owner_delegate_(nullptr), | 185 owner_delegate_(nullptr), |
| 186 process_(process), | 186 process_(process), |
| 187 routing_id_(routing_id), | 187 routing_id_(routing_id), |
| 188 is_loading_(false), | 188 is_loading_(false), |
| 189 is_hidden_(hidden), | 189 is_hidden_(hidden), |
| 190 repaint_ack_pending_(false), | 190 repaint_ack_pending_(false), |
| 191 resize_ack_pending_(false), | 191 resize_ack_pending_(false), |
| 192 color_profile_out_of_date_(false), | 192 color_profile_out_of_date_(false), |
| 193 auto_resize_enabled_(false), | 193 auto_resize_enabled_(false), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 244 } |
| 245 | 245 |
| 246 new_content_rendering_timeout_.reset(new TimeoutMonitor( | 246 new_content_rendering_timeout_.reset(new TimeoutMonitor( |
| 247 base::Bind(&RenderWidgetHostImpl::ClearDisplayedGraphics, | 247 base::Bind(&RenderWidgetHostImpl::ClearDisplayedGraphics, |
| 248 weak_factory_.GetWeakPtr()))); | 248 weak_factory_.GetWeakPtr()))); |
| 249 | 249 |
| 250 delegate_->RenderWidgetCreated(this); | 250 delegate_->RenderWidgetCreated(this); |
| 251 } | 251 } |
| 252 | 252 |
| 253 RenderWidgetHostImpl::~RenderWidgetHostImpl() { | 253 RenderWidgetHostImpl::~RenderWidgetHostImpl() { |
| 254 if (view_weak_) | 254 if (!destroyed_) |
| 255 view_weak_->RenderWidgetHostGone(); | 255 Destroy(false); |
| 256 SetView(NULL); | |
| 257 | |
| 258 process_->RemoveRoute(routing_id_); | |
| 259 g_routing_id_widget_map.Get().erase( | |
| 260 RenderWidgetHostID(process_->GetID(), routing_id_)); | |
| 261 | |
| 262 if (delegate_) | |
| 263 delegate_->RenderWidgetDeleted(this); | |
| 264 } | 256 } |
| 265 | 257 |
| 266 // static | 258 // static |
| 267 RenderWidgetHost* RenderWidgetHost::FromID( | 259 RenderWidgetHost* RenderWidgetHost::FromID( |
| 268 int32_t process_id, | 260 int32_t process_id, |
| 269 int32_t routing_id) { | 261 int32_t routing_id) { |
| 270 return RenderWidgetHostImpl::FromID(process_id, routing_id); | 262 return RenderWidgetHostImpl::FromID(process_id, routing_id); |
| 271 } | 263 } |
| 272 | 264 |
| 273 // static | 265 // static |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 return hosts.Pass(); | 305 return hosts.Pass(); |
| 314 } | 306 } |
| 315 | 307 |
| 316 // static | 308 // static |
| 317 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { | 309 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { |
| 318 return static_cast<RenderWidgetHostImpl*>(rwh); | 310 return static_cast<RenderWidgetHostImpl*>(rwh); |
| 319 } | 311 } |
| 320 | 312 |
| 321 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) { | 313 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) { |
| 322 if (view) | 314 if (view) |
| 323 view_weak_ = view->GetWeakPtr(); | 315 view_ = view->GetWeakPtr(); |
| 324 else | 316 else |
| 325 view_weak_.reset(); | 317 view_.reset(); |
| 326 view_ = view; | |
| 327 | 318 |
| 328 // If the renderer has not yet been initialized, then the surface ID | 319 // If the renderer has not yet been initialized, then the surface ID |
| 329 // namespace will be sent during initialization. | 320 // namespace will be sent during initialization. |
| 330 if (view_ && renderer_initialized_) { | 321 if (view_ && renderer_initialized_) { |
| 331 Send(new ViewMsg_SetSurfaceIdNamespace(routing_id_, | 322 Send(new ViewMsg_SetSurfaceIdNamespace(routing_id_, |
| 332 view_->GetSurfaceIdNamespace())); | 323 view_->GetSurfaceIdNamespace())); |
| 333 } | 324 } |
| 334 | 325 |
| 335 synthetic_gesture_controller_.reset(); | 326 synthetic_gesture_controller_.reset(); |
| 336 } | 327 } |
| 337 | 328 |
| 338 RenderProcessHost* RenderWidgetHostImpl::GetProcess() const { | 329 RenderProcessHost* RenderWidgetHostImpl::GetProcess() const { |
| 339 return process_; | 330 return process_; |
| 340 } | 331 } |
| 341 | 332 |
| 342 int RenderWidgetHostImpl::GetRoutingID() const { | 333 int RenderWidgetHostImpl::GetRoutingID() const { |
| 343 return routing_id_; | 334 return routing_id_; |
| 344 } | 335 } |
| 345 | 336 |
| 346 RenderWidgetHostViewBase* RenderWidgetHostImpl::GetView() const { | 337 RenderWidgetHostViewBase* RenderWidgetHostImpl::GetView() const { |
| 347 return view_; | 338 return view_.get(); |
| 348 } | 339 } |
| 349 | 340 |
| 350 gfx::NativeViewId RenderWidgetHostImpl::GetNativeViewId() const { | 341 gfx::NativeViewId RenderWidgetHostImpl::GetNativeViewId() const { |
| 351 if (view_) | 342 if (view_) |
| 352 return view_->GetNativeViewId(); | 343 return view_->GetNativeViewId(); |
| 353 return 0; | 344 return 0; |
| 354 } | 345 } |
| 355 | 346 |
| 356 void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() { | 347 void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() { |
| 357 resize_ack_pending_ = false; | 348 resize_ack_pending_ = false; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 | 411 |
| 421 if (owner_delegate_) | 412 if (owner_delegate_) |
| 422 owner_delegate_->RenderWidgetDidInit(); | 413 owner_delegate_->RenderWidgetDidInit(); |
| 423 } | 414 } |
| 424 | 415 |
| 425 void RenderWidgetHostImpl::InitForFrame() { | 416 void RenderWidgetHostImpl::InitForFrame() { |
| 426 DCHECK(process_->HasConnection()); | 417 DCHECK(process_->HasConnection()); |
| 427 renderer_initialized_ = true; | 418 renderer_initialized_ = true; |
| 428 } | 419 } |
| 429 | 420 |
| 430 void RenderWidgetHostImpl::Shutdown() { | 421 void RenderWidgetHostImpl::ShutdownAndDestroyWidget(bool also_delete) { |
| 431 RejectMouseLockOrUnlockIfNecessary(); | 422 RejectMouseLockOrUnlockIfNecessary(); |
| 432 | 423 |
| 433 if (process_->HasConnection()) { | 424 if (process_->HasConnection()) { |
| 434 // Tell the renderer object to close. | 425 // Tell the renderer object to close. |
| 435 bool rv = Send(new ViewMsg_Close(routing_id_)); | 426 bool rv = Send(new ViewMsg_Close(routing_id_)); |
| 436 DCHECK(rv); | 427 DCHECK(rv); |
| 437 } | 428 } |
| 438 | 429 |
| 439 Destroy(); | 430 Destroy(also_delete); |
| 440 } | 431 } |
| 441 | 432 |
| 442 bool RenderWidgetHostImpl::IsLoading() const { | 433 bool RenderWidgetHostImpl::IsLoading() const { |
| 443 return is_loading_; | 434 return is_loading_; |
| 444 } | 435 } |
| 445 | 436 |
| 446 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { | 437 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { |
| 447 bool handled = true; | 438 bool handled = true; |
| 448 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg) | 439 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg) |
| 449 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) | 440 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 process_->WidgetHidden(); | 1353 process_->WidgetHidden(); |
| 1363 is_hidden_ = true; | 1354 is_hidden_ = true; |
| 1364 } | 1355 } |
| 1365 | 1356 |
| 1366 // Reset this to ensure the hung renderer mechanism is working properly. | 1357 // Reset this to ensure the hung renderer mechanism is working properly. |
| 1367 in_flight_event_count_ = 0; | 1358 in_flight_event_count_ = 0; |
| 1368 StopHangMonitorTimeout(); | 1359 StopHangMonitorTimeout(); |
| 1369 | 1360 |
| 1370 if (view_) { | 1361 if (view_) { |
| 1371 view_->RenderProcessGone(status, exit_code); | 1362 view_->RenderProcessGone(status, exit_code); |
| 1372 view_ = nullptr; // The View should be deleted by RenderProcessGone. | 1363 view_.reset(); // The View should be deleted by RenderProcessGone. |
| 1373 view_weak_.reset(); | |
| 1374 } | 1364 } |
| 1375 | 1365 |
| 1376 // Reconstruct the input router to ensure that it has fresh state for a new | 1366 // Reconstruct the input router to ensure that it has fresh state for a new |
| 1377 // renderer. Otherwise it may be stuck waiting for the old renderer to ack an | 1367 // renderer. Otherwise it may be stuck waiting for the old renderer to ack an |
| 1378 // event. (In particular, the above call to view_->RenderProcessGone will | 1368 // event. (In particular, the above call to view_->RenderProcessGone will |
| 1379 // destroy the aura window, which may dispatch a synthetic mouse move.) | 1369 // destroy the aura window, which may dispatch a synthetic mouse move.) |
| 1380 input_router_.reset(new InputRouterImpl( | 1370 input_router_.reset(new InputRouterImpl( |
| 1381 process_, this, this, routing_id_, GetInputRouterConfigForPlatform())); | 1371 process_, this, this, routing_id_, GetInputRouterConfigForPlatform())); |
| 1382 | 1372 |
| 1383 synthetic_gesture_controller_.reset(); | 1373 synthetic_gesture_controller_.reset(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1439 } | 1429 } |
| 1440 | 1430 |
| 1441 void RenderWidgetHostImpl::SetAutoResize(bool enable, | 1431 void RenderWidgetHostImpl::SetAutoResize(bool enable, |
| 1442 const gfx::Size& min_size, | 1432 const gfx::Size& min_size, |
| 1443 const gfx::Size& max_size) { | 1433 const gfx::Size& max_size) { |
| 1444 auto_resize_enabled_ = enable; | 1434 auto_resize_enabled_ = enable; |
| 1445 min_size_for_auto_resize_ = min_size; | 1435 min_size_for_auto_resize_ = min_size; |
| 1446 max_size_for_auto_resize_ = max_size; | 1436 max_size_for_auto_resize_ = max_size; |
| 1447 } | 1437 } |
| 1448 | 1438 |
| 1449 void RenderWidgetHostImpl::Destroy() { | 1439 void RenderWidgetHostImpl::Destroy(bool also_delete) { |
| 1440 DCHECK(!destroyed_); |
| 1441 destroyed_ = true; |
| 1442 |
| 1450 NotificationService::current()->Notify( | 1443 NotificationService::current()->Notify( |
| 1451 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 1444 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, Source<RenderWidgetHost>(this), |
| 1452 Source<RenderWidgetHost>(this), | |
| 1453 NotificationService::NoDetails()); | 1445 NotificationService::NoDetails()); |
| 1454 | 1446 |
| 1455 // Tell the view to die. | 1447 // Tell the view to die. |
| 1456 // Note that in the process of the view shutting down, it can call a ton | 1448 // Note that in the process of the view shutting down, it can call a ton |
| 1457 // of other messages on us. So if you do any other deinitialization here, | 1449 // of other messages on us. So if you do any other deinitialization here, |
| 1458 // do it after this call to view_->Destroy(). | 1450 // do it after this call to view_->Destroy(). |
| 1459 if (view_) { | 1451 if (view_) { |
| 1460 view_->Destroy(); | 1452 view_->Destroy(); |
| 1461 view_ = nullptr; | 1453 view_.reset(); |
| 1462 } | 1454 } |
| 1463 | 1455 |
| 1464 delete this; | 1456 process_->RemoveRoute(routing_id_); |
| 1457 g_routing_id_widget_map.Get().erase( |
| 1458 RenderWidgetHostID(process_->GetID(), routing_id_)); |
| 1459 |
| 1460 if (delegate_) |
| 1461 delegate_->RenderWidgetDeleted(this); |
| 1462 |
| 1463 if (also_delete) |
| 1464 delete this; |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 void RenderWidgetHostImpl::RendererIsUnresponsive() { | 1467 void RenderWidgetHostImpl::RendererIsUnresponsive() { |
| 1468 NotificationService::current()->Notify( | 1468 NotificationService::current()->Notify( |
| 1469 NOTIFICATION_RENDER_WIDGET_HOST_HANG, | 1469 NOTIFICATION_RENDER_WIDGET_HOST_HANG, |
| 1470 Source<RenderWidgetHost>(this), | 1470 Source<RenderWidgetHost>(this), |
| 1471 NotificationService::NoDetails()); | 1471 NotificationService::NoDetails()); |
| 1472 is_unresponsive_ = true; | 1472 is_unresponsive_ = true; |
| 1473 if (delegate_) | 1473 if (delegate_) |
| 1474 delegate_->RendererUnresponsive(this); | 1474 delegate_->RendererUnresponsive(this); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1488 view_->ClearCompositorFrame(); | 1488 view_->ClearCompositorFrame(); |
| 1489 } | 1489 } |
| 1490 | 1490 |
| 1491 void RenderWidgetHostImpl::OnRenderProcessGone(int status, int exit_code) { | 1491 void RenderWidgetHostImpl::OnRenderProcessGone(int status, int exit_code) { |
| 1492 // RenderFrameHost owns a RenderWidgetHost when it needs one, in which case | 1492 // RenderFrameHost owns a RenderWidgetHost when it needs one, in which case |
| 1493 // it handles destruction. | 1493 // it handles destruction. |
| 1494 if (!owned_by_render_frame_host_) { | 1494 if (!owned_by_render_frame_host_) { |
| 1495 // TODO(evanm): This synchronously ends up calling "delete this". | 1495 // TODO(evanm): This synchronously ends up calling "delete this". |
| 1496 // Is that really what we want in response to this message? I'm matching | 1496 // Is that really what we want in response to this message? I'm matching |
| 1497 // previous behavior of the code here. | 1497 // previous behavior of the code here. |
| 1498 Destroy(); | 1498 Destroy(true); |
| 1499 } else { | 1499 } else { |
| 1500 RendererExited(static_cast<base::TerminationStatus>(status), exit_code); | 1500 RendererExited(static_cast<base::TerminationStatus>(status), exit_code); |
| 1501 } | 1501 } |
| 1502 } | 1502 } |
| 1503 | 1503 |
| 1504 void RenderWidgetHostImpl::OnClose() { | 1504 void RenderWidgetHostImpl::OnClose() { |
| 1505 Shutdown(); | 1505 ShutdownAndDestroyWidget(true); |
| 1506 } | 1506 } |
| 1507 | 1507 |
| 1508 void RenderWidgetHostImpl::OnSetTooltipText( | 1508 void RenderWidgetHostImpl::OnSetTooltipText( |
| 1509 const base::string16& tooltip_text, | 1509 const base::string16& tooltip_text, |
| 1510 WebTextDirection text_direction_hint) { | 1510 WebTextDirection text_direction_hint) { |
| 1511 // First, add directionality marks around tooltip text if necessary. | 1511 // First, add directionality marks around tooltip text if necessary. |
| 1512 // A naive solution would be to simply always wrap the text. However, on | 1512 // A naive solution would be to simply always wrap the text. However, on |
| 1513 // windows, Unicode directional embedding characters can't be displayed on | 1513 // windows, Unicode directional embedding characters can't be displayed on |
| 1514 // systems that lack RTL fonts and are instead displayed as empty squares. | 1514 // systems that lack RTL fonts and are instead displayed as empty squares. |
| 1515 // | 1515 // |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1725 | 1725 |
| 1726 void RenderWidgetHostImpl::OnSetCursor(const WebCursor& cursor) { | 1726 void RenderWidgetHostImpl::OnSetCursor(const WebCursor& cursor) { |
| 1727 SetCursor(cursor); | 1727 SetCursor(cursor); |
| 1728 } | 1728 } |
| 1729 | 1729 |
| 1730 void RenderWidgetHostImpl::SetTouchEventEmulationEnabled( | 1730 void RenderWidgetHostImpl::SetTouchEventEmulationEnabled( |
| 1731 bool enabled, ui::GestureProviderConfigType config_type) { | 1731 bool enabled, ui::GestureProviderConfigType config_type) { |
| 1732 if (enabled) { | 1732 if (enabled) { |
| 1733 if (!touch_emulator_) { | 1733 if (!touch_emulator_) { |
| 1734 touch_emulator_.reset(new TouchEmulator( | 1734 touch_emulator_.reset(new TouchEmulator( |
| 1735 this, view_ ? content::GetScaleFactorForView(view_) : 1.0f)); | 1735 this, |
| 1736 view_.get() ? content::GetScaleFactorForView(view_.get()) : 1.0f)); |
| 1736 } | 1737 } |
| 1737 touch_emulator_->Enable(config_type); | 1738 touch_emulator_->Enable(config_type); |
| 1738 } else { | 1739 } else { |
| 1739 if (touch_emulator_) | 1740 if (touch_emulator_) |
| 1740 touch_emulator_->Disable(); | 1741 touch_emulator_->Disable(); |
| 1741 } | 1742 } |
| 1742 } | 1743 } |
| 1743 | 1744 |
| 1744 void RenderWidgetHostImpl::OnTextInputStateChanged( | 1745 void RenderWidgetHostImpl::OnTextInputStateChanged( |
| 1745 const ViewHostMsg_TextInputState_Params& params) { | 1746 const ViewHostMsg_TextInputState_Params& params) { |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2242 } | 2243 } |
| 2243 | 2244 |
| 2244 #if defined(OS_WIN) | 2245 #if defined(OS_WIN) |
| 2245 gfx::NativeViewAccessible | 2246 gfx::NativeViewAccessible |
| 2246 RenderWidgetHostImpl::GetParentNativeViewAccessible() { | 2247 RenderWidgetHostImpl::GetParentNativeViewAccessible() { |
| 2247 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; | 2248 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; |
| 2248 } | 2249 } |
| 2249 #endif | 2250 #endif |
| 2250 | 2251 |
| 2251 } // namespace content | 2252 } // namespace content |
| OLD | NEW |