Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(650)

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 1453803002: Separate RenderViewHost from RenderWidgetHost, part 10: shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: all in destroy, plus mac Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 } // namespace 172 } // namespace
173 173
174 /////////////////////////////////////////////////////////////////////////////// 174 ///////////////////////////////////////////////////////////////////////////////
175 // RenderWidgetHostImpl 175 // RenderWidgetHostImpl
176 176
177 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, 177 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
178 RenderProcessHost* process, 178 RenderProcessHost* process,
179 int32_t routing_id, 179 int32_t routing_id,
180 bool hidden) 180 bool hidden)
181 : view_(NULL), 181 : renderer_initialized_(false),
182 renderer_initialized_(false), 182 destroyed_(false),
183 delegate_(delegate), 183 delegate_(delegate),
184 owner_delegate_(nullptr), 184 owner_delegate_(nullptr),
185 process_(process), 185 process_(process),
186 routing_id_(routing_id), 186 routing_id_(routing_id),
187 is_loading_(false), 187 is_loading_(false),
188 is_hidden_(hidden), 188 is_hidden_(hidden),
189 repaint_ack_pending_(false), 189 repaint_ack_pending_(false),
190 resize_ack_pending_(false), 190 resize_ack_pending_(false),
191 color_profile_out_of_date_(false), 191 color_profile_out_of_date_(false),
192 auto_resize_enabled_(false), 192 auto_resize_enabled_(false),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 base::Bind(&RenderWidgetHostImpl::RendererIsUnresponsive, 241 base::Bind(&RenderWidgetHostImpl::RendererIsUnresponsive,
242 weak_factory_.GetWeakPtr()))); 242 weak_factory_.GetWeakPtr())));
243 } 243 }
244 244
245 new_content_rendering_timeout_.reset(new TimeoutMonitor( 245 new_content_rendering_timeout_.reset(new TimeoutMonitor(
246 base::Bind(&RenderWidgetHostImpl::ClearDisplayedGraphics, 246 base::Bind(&RenderWidgetHostImpl::ClearDisplayedGraphics,
247 weak_factory_.GetWeakPtr()))); 247 weak_factory_.GetWeakPtr())));
248 } 248 }
249 249
250 RenderWidgetHostImpl::~RenderWidgetHostImpl() { 250 RenderWidgetHostImpl::~RenderWidgetHostImpl() {
251 if (view_weak_) 251 if (!destroyed_)
252 view_weak_->RenderWidgetHostGone(); 252 Destroy(false);
Avi (use Gerrit) 2015/11/20 20:10:40 Perhaps instead DCHECK that Destroy() was called?
ncarter (slow) 2015/11/30 21:32:33 You can do the DCHECK, but you'll have to fix up a
253 SetView(NULL);
254
255 process_->RemoveRoute(routing_id_);
256 g_routing_id_widget_map.Get().erase(
257 RenderWidgetHostID(process_->GetID(), routing_id_));
258
259 if (delegate_)
260 delegate_->RenderWidgetDeleted(this);
261 } 253 }
262 254
263 // static 255 // static
264 RenderWidgetHost* RenderWidgetHost::FromID( 256 RenderWidgetHost* RenderWidgetHost::FromID(
265 int32_t process_id, 257 int32_t process_id,
266 int32_t routing_id) { 258 int32_t routing_id) {
267 return RenderWidgetHostImpl::FromID(process_id, routing_id); 259 return RenderWidgetHostImpl::FromID(process_id, routing_id);
268 } 260 }
269 261
270 // static 262 // static
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 return hosts.Pass(); 302 return hosts.Pass();
311 } 303 }
312 304
313 // static 305 // static
314 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { 306 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) {
315 return static_cast<RenderWidgetHostImpl*>(rwh); 307 return static_cast<RenderWidgetHostImpl*>(rwh);
316 } 308 }
317 309
318 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) { 310 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) {
319 if (view) 311 if (view)
320 view_weak_ = view->GetWeakPtr(); 312 view_ = view->GetWeakPtr();
321 else 313 else
322 view_weak_.reset(); 314 view_.reset();
323 view_ = view;
324 315
325 // If the renderer has not yet been initialized, then the surface ID 316 // If the renderer has not yet been initialized, then the surface ID
326 // namespace will be sent during initialization. 317 // namespace will be sent during initialization.
327 if (view_ && renderer_initialized_) { 318 if (view_ && renderer_initialized_) {
328 Send(new ViewMsg_SetSurfaceIdNamespace(routing_id_, 319 Send(new ViewMsg_SetSurfaceIdNamespace(routing_id_,
329 view_->GetSurfaceIdNamespace())); 320 view_->GetSurfaceIdNamespace()));
330 } 321 }
331 322
332 synthetic_gesture_controller_.reset(); 323 synthetic_gesture_controller_.reset();
333 } 324 }
334 325
335 RenderProcessHost* RenderWidgetHostImpl::GetProcess() const { 326 RenderProcessHost* RenderWidgetHostImpl::GetProcess() const {
336 return process_; 327 return process_;
337 } 328 }
338 329
339 int RenderWidgetHostImpl::GetRoutingID() const { 330 int RenderWidgetHostImpl::GetRoutingID() const {
340 return routing_id_; 331 return routing_id_;
341 } 332 }
342 333
343 RenderWidgetHostViewBase* RenderWidgetHostImpl::GetView() const { 334 RenderWidgetHostViewBase* RenderWidgetHostImpl::GetView() const {
344 return view_; 335 return view_.get();
345 } 336 }
346 337
347 gfx::NativeViewId RenderWidgetHostImpl::GetNativeViewId() const { 338 gfx::NativeViewId RenderWidgetHostImpl::GetNativeViewId() const {
348 if (view_) 339 if (view_)
349 return view_->GetNativeViewId(); 340 return view_->GetNativeViewId();
350 return 0; 341 return 0;
351 } 342 }
352 343
353 void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() { 344 void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() {
354 resize_ack_pending_ = false; 345 resize_ack_pending_ = false;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 408
418 if (owner_delegate_) 409 if (owner_delegate_)
419 owner_delegate_->RenderWidgetDidInit(); 410 owner_delegate_->RenderWidgetDidInit();
420 } 411 }
421 412
422 void RenderWidgetHostImpl::InitForFrame() { 413 void RenderWidgetHostImpl::InitForFrame() {
423 DCHECK(process_->HasConnection()); 414 DCHECK(process_->HasConnection());
424 renderer_initialized_ = true; 415 renderer_initialized_ = true;
425 } 416 }
426 417
427 void RenderWidgetHostImpl::Shutdown() { 418 void RenderWidgetHostImpl::ShutdownAndDestroyWidget(bool also_delete) {
428 RejectMouseLockOrUnlockIfNecessary(); 419 RejectMouseLockOrUnlockIfNecessary();
429 420
430 if (process_->HasConnection()) { 421 if (process_->HasConnection()) {
431 // Tell the renderer object to close. 422 // Tell the renderer object to close.
432 bool rv = Send(new ViewMsg_Close(routing_id_)); 423 bool rv = Send(new ViewMsg_Close(routing_id_));
433 DCHECK(rv); 424 DCHECK(rv);
434 } 425 }
435 426
436 Destroy(); 427 Destroy(also_delete);
437 } 428 }
438 429
439 bool RenderWidgetHostImpl::IsLoading() const { 430 bool RenderWidgetHostImpl::IsLoading() const {
440 return is_loading_; 431 return is_loading_;
441 } 432 }
442 433
443 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { 434 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) {
444 bool handled = true; 435 bool handled = true;
445 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg) 436 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg)
446 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) 437 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone)
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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
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
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/renderer_host/render_widget_host_view_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698