| 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 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 process_->WidgetHidden(); | 1352 process_->WidgetHidden(); |
| 1362 is_hidden_ = true; | 1353 is_hidden_ = true; |
| 1363 } | 1354 } |
| 1364 | 1355 |
| 1365 // Reset this to ensure the hung renderer mechanism is working properly. | 1356 // Reset this to ensure the hung renderer mechanism is working properly. |
| 1366 in_flight_event_count_ = 0; | 1357 in_flight_event_count_ = 0; |
| 1367 StopHangMonitorTimeout(); | 1358 StopHangMonitorTimeout(); |
| 1368 | 1359 |
| 1369 if (view_) { | 1360 if (view_) { |
| 1370 view_->RenderProcessGone(status, exit_code); | 1361 view_->RenderProcessGone(status, exit_code); |
| 1371 view_ = nullptr; // The View should be deleted by RenderProcessGone. | 1362 view_.reset(); // The View should be deleted by RenderProcessGone. |
| 1372 view_weak_.reset(); | |
| 1373 } | 1363 } |
| 1374 | 1364 |
| 1375 // Reconstruct the input router to ensure that it has fresh state for a new | 1365 // Reconstruct the input router to ensure that it has fresh state for a new |
| 1376 // renderer. Otherwise it may be stuck waiting for the old renderer to ack an | 1366 // renderer. Otherwise it may be stuck waiting for the old renderer to ack an |
| 1377 // event. (In particular, the above call to view_->RenderProcessGone will | 1367 // event. (In particular, the above call to view_->RenderProcessGone will |
| 1378 // destroy the aura window, which may dispatch a synthetic mouse move.) | 1368 // destroy the aura window, which may dispatch a synthetic mouse move.) |
| 1379 input_router_.reset(new InputRouterImpl( | 1369 input_router_.reset(new InputRouterImpl( |
| 1380 process_, this, this, routing_id_, GetInputRouterConfigForPlatform())); | 1370 process_, this, this, routing_id_, GetInputRouterConfigForPlatform())); |
| 1381 | 1371 |
| 1382 synthetic_gesture_controller_.reset(); | 1372 synthetic_gesture_controller_.reset(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 } | 1428 } |
| 1439 | 1429 |
| 1440 void RenderWidgetHostImpl::SetAutoResize(bool enable, | 1430 void RenderWidgetHostImpl::SetAutoResize(bool enable, |
| 1441 const gfx::Size& min_size, | 1431 const gfx::Size& min_size, |
| 1442 const gfx::Size& max_size) { | 1432 const gfx::Size& max_size) { |
| 1443 auto_resize_enabled_ = enable; | 1433 auto_resize_enabled_ = enable; |
| 1444 min_size_for_auto_resize_ = min_size; | 1434 min_size_for_auto_resize_ = min_size; |
| 1445 max_size_for_auto_resize_ = max_size; | 1435 max_size_for_auto_resize_ = max_size; |
| 1446 } | 1436 } |
| 1447 | 1437 |
| 1448 void RenderWidgetHostImpl::Destroy() { | 1438 void RenderWidgetHostImpl::Destroy(bool also_delete) { |
| 1439 DCHECK(!destroyed_); |
| 1440 destroyed_ = true; |
| 1441 |
| 1449 NotificationService::current()->Notify( | 1442 NotificationService::current()->Notify( |
| 1450 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 1443 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, Source<RenderWidgetHost>(this), |
| 1451 Source<RenderWidgetHost>(this), | |
| 1452 NotificationService::NoDetails()); | 1444 NotificationService::NoDetails()); |
| 1453 | 1445 |
| 1454 // Tell the view to die. | 1446 // Tell the view to die. |
| 1455 // Note that in the process of the view shutting down, it can call a ton | 1447 // Note that in the process of the view shutting down, it can call a ton |
| 1456 // of other messages on us. So if you do any other deinitialization here, | 1448 // of other messages on us. So if you do any other deinitialization here, |
| 1457 // do it after this call to view_->Destroy(). | 1449 // do it after this call to view_->Destroy(). |
| 1458 if (view_) { | 1450 if (view_) { |
| 1459 view_->Destroy(); | 1451 view_->Destroy(); |
| 1460 view_ = nullptr; | 1452 view_.reset(); |
| 1461 } | 1453 } |
| 1462 | 1454 |
| 1463 delete this; | 1455 process_->RemoveRoute(routing_id_); |
| 1456 g_routing_id_widget_map.Get().erase( |
| 1457 RenderWidgetHostID(process_->GetID(), routing_id_)); |
| 1458 |
| 1459 if (delegate_) |
| 1460 delegate_->RenderWidgetDeleted(this); |
| 1461 |
| 1462 if (also_delete) |
| 1463 delete this; |
| 1464 } | 1464 } |
| 1465 | 1465 |
| 1466 void RenderWidgetHostImpl::RendererIsUnresponsive() { | 1466 void RenderWidgetHostImpl::RendererIsUnresponsive() { |
| 1467 NotificationService::current()->Notify( | 1467 NotificationService::current()->Notify( |
| 1468 NOTIFICATION_RENDER_WIDGET_HOST_HANG, | 1468 NOTIFICATION_RENDER_WIDGET_HOST_HANG, |
| 1469 Source<RenderWidgetHost>(this), | 1469 Source<RenderWidgetHost>(this), |
| 1470 NotificationService::NoDetails()); | 1470 NotificationService::NoDetails()); |
| 1471 is_unresponsive_ = true; | 1471 is_unresponsive_ = true; |
| 1472 if (delegate_) | 1472 if (delegate_) |
| 1473 delegate_->RendererUnresponsive(this); | 1473 delegate_->RendererUnresponsive(this); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1487 view_->ClearCompositorFrame(); | 1487 view_->ClearCompositorFrame(); |
| 1488 } | 1488 } |
| 1489 | 1489 |
| 1490 void RenderWidgetHostImpl::OnRenderProcessGone(int status, int exit_code) { | 1490 void RenderWidgetHostImpl::OnRenderProcessGone(int status, int exit_code) { |
| 1491 // RenderFrameHost owns a RenderWidgetHost when it needs one, in which case | 1491 // RenderFrameHost owns a RenderWidgetHost when it needs one, in which case |
| 1492 // it handles destruction. | 1492 // it handles destruction. |
| 1493 if (!owned_by_render_frame_host_) { | 1493 if (!owned_by_render_frame_host_) { |
| 1494 // TODO(evanm): This synchronously ends up calling "delete this". | 1494 // TODO(evanm): This synchronously ends up calling "delete this". |
| 1495 // Is that really what we want in response to this message? I'm matching | 1495 // Is that really what we want in response to this message? I'm matching |
| 1496 // previous behavior of the code here. | 1496 // previous behavior of the code here. |
| 1497 Destroy(); | 1497 Destroy(true); |
| 1498 } else { | 1498 } else { |
| 1499 RendererExited(static_cast<base::TerminationStatus>(status), exit_code); | 1499 RendererExited(static_cast<base::TerminationStatus>(status), exit_code); |
| 1500 } | 1500 } |
| 1501 } | 1501 } |
| 1502 | 1502 |
| 1503 void RenderWidgetHostImpl::OnClose() { | 1503 void RenderWidgetHostImpl::OnClose() { |
| 1504 Shutdown(); | 1504 ShutdownAndDestroyWidget(true); |
| 1505 } | 1505 } |
| 1506 | 1506 |
| 1507 void RenderWidgetHostImpl::OnSetTooltipText( | 1507 void RenderWidgetHostImpl::OnSetTooltipText( |
| 1508 const base::string16& tooltip_text, | 1508 const base::string16& tooltip_text, |
| 1509 WebTextDirection text_direction_hint) { | 1509 WebTextDirection text_direction_hint) { |
| 1510 // First, add directionality marks around tooltip text if necessary. | 1510 // First, add directionality marks around tooltip text if necessary. |
| 1511 // A naive solution would be to simply always wrap the text. However, on | 1511 // A naive solution would be to simply always wrap the text. However, on |
| 1512 // windows, Unicode directional embedding characters can't be displayed on | 1512 // windows, Unicode directional embedding characters can't be displayed on |
| 1513 // systems that lack RTL fonts and are instead displayed as empty squares. | 1513 // systems that lack RTL fonts and are instead displayed as empty squares. |
| 1514 // | 1514 // |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 | 1724 |
| 1725 void RenderWidgetHostImpl::OnSetCursor(const WebCursor& cursor) { | 1725 void RenderWidgetHostImpl::OnSetCursor(const WebCursor& cursor) { |
| 1726 SetCursor(cursor); | 1726 SetCursor(cursor); |
| 1727 } | 1727 } |
| 1728 | 1728 |
| 1729 void RenderWidgetHostImpl::SetTouchEventEmulationEnabled( | 1729 void RenderWidgetHostImpl::SetTouchEventEmulationEnabled( |
| 1730 bool enabled, ui::GestureProviderConfigType config_type) { | 1730 bool enabled, ui::GestureProviderConfigType config_type) { |
| 1731 if (enabled) { | 1731 if (enabled) { |
| 1732 if (!touch_emulator_) { | 1732 if (!touch_emulator_) { |
| 1733 touch_emulator_.reset(new TouchEmulator( | 1733 touch_emulator_.reset(new TouchEmulator( |
| 1734 this, view_ ? content::GetScaleFactorForView(view_) : 1.0f)); | 1734 this, |
| 1735 view_.get() ? content::GetScaleFactorForView(view_.get()) : 1.0f)); |
| 1735 } | 1736 } |
| 1736 touch_emulator_->Enable(config_type); | 1737 touch_emulator_->Enable(config_type); |
| 1737 } else { | 1738 } else { |
| 1738 if (touch_emulator_) | 1739 if (touch_emulator_) |
| 1739 touch_emulator_->Disable(); | 1740 touch_emulator_->Disable(); |
| 1740 } | 1741 } |
| 1741 } | 1742 } |
| 1742 | 1743 |
| 1743 void RenderWidgetHostImpl::OnTextInputStateChanged( | 1744 void RenderWidgetHostImpl::OnTextInputStateChanged( |
| 1744 const ViewHostMsg_TextInputState_Params& params) { | 1745 const ViewHostMsg_TextInputState_Params& params) { |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2241 } | 2242 } |
| 2242 | 2243 |
| 2243 #if defined(OS_WIN) | 2244 #if defined(OS_WIN) |
| 2244 gfx::NativeViewAccessible | 2245 gfx::NativeViewAccessible |
| 2245 RenderWidgetHostImpl::GetParentNativeViewAccessible() { | 2246 RenderWidgetHostImpl::GetParentNativeViewAccessible() { |
| 2246 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; | 2247 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; |
| 2247 } | 2248 } |
| 2248 #endif | 2249 #endif |
| 2249 | 2250 |
| 2250 } // namespace content | 2251 } // namespace content |
| OLD | NEW |