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

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: 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),
183 delegate_(delegate), 182 delegate_(delegate),
184 owner_delegate_(nullptr), 183 owner_delegate_(nullptr),
185 process_(process), 184 process_(process),
186 routing_id_(routing_id), 185 routing_id_(routing_id),
187 is_loading_(false), 186 is_loading_(false),
188 is_hidden_(hidden), 187 is_hidden_(hidden),
189 repaint_ack_pending_(false), 188 repaint_ack_pending_(false),
190 resize_ack_pending_(false), 189 resize_ack_pending_(false),
191 color_profile_out_of_date_(false), 190 color_profile_out_of_date_(false),
192 auto_resize_enabled_(false), 191 auto_resize_enabled_(false),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 base::Bind(&RenderWidgetHostImpl::RendererIsUnresponsive, 240 base::Bind(&RenderWidgetHostImpl::RendererIsUnresponsive,
242 weak_factory_.GetWeakPtr()))); 241 weak_factory_.GetWeakPtr())));
243 } 242 }
244 243
245 new_content_rendering_timeout_.reset(new TimeoutMonitor( 244 new_content_rendering_timeout_.reset(new TimeoutMonitor(
246 base::Bind(&RenderWidgetHostImpl::ClearDisplayedGraphics, 245 base::Bind(&RenderWidgetHostImpl::ClearDisplayedGraphics,
247 weak_factory_.GetWeakPtr()))); 246 weak_factory_.GetWeakPtr())));
248 } 247 }
249 248
250 RenderWidgetHostImpl::~RenderWidgetHostImpl() { 249 RenderWidgetHostImpl::~RenderWidgetHostImpl() {
251 if (view_weak_) 250 NotificationService::current()->Notify(
252 view_weak_->RenderWidgetHostGone(); 251 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, Source<RenderWidgetHost>(this),
ncarter (slow) 2015/11/17 20:59:57 We gotta worry about stuff like this: https://cod
Avi (use Gerrit) 2015/11/18 00:29:59 Sigh. Awesomeness all around. But that should call
253 SetView(NULL); 252 NotificationService::NoDetails());
253
254 // Tell the view to die.
255 // Note that in the process of the view shutting down, it can call a ton
256 // of other messages on us. So if you do any other deinitialization here,
257 // do it after this call to view_->Destroy().
258 if (view_) {
259 view_->Destroy();
260 view_.reset();
261 }
254 262
255 process_->RemoveRoute(routing_id_); 263 process_->RemoveRoute(routing_id_);
256 g_routing_id_widget_map.Get().erase( 264 g_routing_id_widget_map.Get().erase(
257 RenderWidgetHostID(process_->GetID(), routing_id_)); 265 RenderWidgetHostID(process_->GetID(), routing_id_));
258 266
259 if (delegate_) 267 if (delegate_)
260 delegate_->RenderWidgetDeleted(this); 268 delegate_->RenderWidgetDeleted(this);
261 } 269 }
262 270
263 // static 271 // static
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 return hosts.Pass(); 318 return hosts.Pass();
311 } 319 }
312 320
313 // static 321 // static
314 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { 322 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) {
315 return static_cast<RenderWidgetHostImpl*>(rwh); 323 return static_cast<RenderWidgetHostImpl*>(rwh);
316 } 324 }
317 325
318 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) { 326 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) {
319 if (view) 327 if (view)
320 view_weak_ = view->GetWeakPtr(); 328 view_ = view->GetWeakPtr();
321 else 329 else
322 view_weak_.reset(); 330 view_.reset();
323 view_ = view;
324 331
325 // If the renderer has not yet been initialized, then the surface ID 332 // If the renderer has not yet been initialized, then the surface ID
326 // namespace will be sent during initialization. 333 // namespace will be sent during initialization.
327 if (view_ && renderer_initialized_) { 334 if (view_ && renderer_initialized_) {
328 Send(new ViewMsg_SetSurfaceIdNamespace(routing_id_, 335 Send(new ViewMsg_SetSurfaceIdNamespace(routing_id_,
329 view_->GetSurfaceIdNamespace())); 336 view_->GetSurfaceIdNamespace()));
330 } 337 }
331 338
332 synthetic_gesture_controller_.reset(); 339 synthetic_gesture_controller_.reset();
333 } 340 }
334 341
335 RenderProcessHost* RenderWidgetHostImpl::GetProcess() const { 342 RenderProcessHost* RenderWidgetHostImpl::GetProcess() const {
336 return process_; 343 return process_;
337 } 344 }
338 345
339 int RenderWidgetHostImpl::GetRoutingID() const { 346 int RenderWidgetHostImpl::GetRoutingID() const {
340 return routing_id_; 347 return routing_id_;
341 } 348 }
342 349
343 RenderWidgetHostViewBase* RenderWidgetHostImpl::GetView() const { 350 RenderWidgetHostViewBase* RenderWidgetHostImpl::GetView() const {
344 return view_; 351 return view_.get();
345 } 352 }
346 353
347 gfx::NativeViewId RenderWidgetHostImpl::GetNativeViewId() const { 354 gfx::NativeViewId RenderWidgetHostImpl::GetNativeViewId() const {
348 if (view_) 355 if (view_)
349 return view_->GetNativeViewId(); 356 return view_->GetNativeViewId();
350 return 0; 357 return 0;
351 } 358 }
352 359
353 void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() { 360 void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() {
354 resize_ack_pending_ = false; 361 resize_ack_pending_ = false;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 424
418 if (owner_delegate_) 425 if (owner_delegate_)
419 owner_delegate_->RenderWidgetDidInit(); 426 owner_delegate_->RenderWidgetDidInit();
420 } 427 }
421 428
422 void RenderWidgetHostImpl::InitForFrame() { 429 void RenderWidgetHostImpl::InitForFrame() {
423 DCHECK(process_->HasConnection()); 430 DCHECK(process_->HasConnection());
424 renderer_initialized_ = true; 431 renderer_initialized_ = true;
425 } 432 }
426 433
427 void RenderWidgetHostImpl::Shutdown() { 434 void RenderWidgetHostImpl::ShutdownWidget(bool destroy) {
428 RejectMouseLockOrUnlockIfNecessary(); 435 RejectMouseLockOrUnlockIfNecessary();
429 436
430 if (process_->HasConnection()) { 437 if (process_->HasConnection()) {
431 // Tell the renderer object to close. 438 // Tell the renderer object to close.
432 bool rv = Send(new ViewMsg_Close(routing_id_)); 439 bool rv = Send(new ViewMsg_Close(routing_id_));
433 DCHECK(rv); 440 DCHECK(rv);
434 } 441 }
435 442
436 Destroy(); 443 if (destroy)
444 Destroy();
437 } 445 }
438 446
439 bool RenderWidgetHostImpl::IsLoading() const { 447 bool RenderWidgetHostImpl::IsLoading() const {
440 return is_loading_; 448 return is_loading_;
441 } 449 }
442 450
443 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { 451 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) {
444 bool handled = true; 452 bool handled = true;
445 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg) 453 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg)
446 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) 454 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone)
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 process_->WidgetHidden(); 1355 process_->WidgetHidden();
1348 is_hidden_ = true; 1356 is_hidden_ = true;
1349 } 1357 }
1350 1358
1351 // Reset this to ensure the hung renderer mechanism is working properly. 1359 // Reset this to ensure the hung renderer mechanism is working properly.
1352 in_flight_event_count_ = 0; 1360 in_flight_event_count_ = 0;
1353 StopHangMonitorTimeout(); 1361 StopHangMonitorTimeout();
1354 1362
1355 if (view_) { 1363 if (view_) {
1356 view_->RenderProcessGone(status, exit_code); 1364 view_->RenderProcessGone(status, exit_code);
1357 view_ = nullptr; // The View should be deleted by RenderProcessGone. 1365 view_.reset(); // The View should be deleted by RenderProcessGone.
1358 view_weak_.reset();
1359 } 1366 }
1360 1367
1361 // Reconstruct the input router to ensure that it has fresh state for a new 1368 // Reconstruct the input router to ensure that it has fresh state for a new
1362 // renderer. Otherwise it may be stuck waiting for the old renderer to ack an 1369 // renderer. Otherwise it may be stuck waiting for the old renderer to ack an
1363 // event. (In particular, the above call to view_->RenderProcessGone will 1370 // event. (In particular, the above call to view_->RenderProcessGone will
1364 // destroy the aura window, which may dispatch a synthetic mouse move.) 1371 // destroy the aura window, which may dispatch a synthetic mouse move.)
1365 input_router_.reset(new InputRouterImpl( 1372 input_router_.reset(new InputRouterImpl(
1366 process_, this, this, routing_id_, GetInputRouterConfigForPlatform())); 1373 process_, this, this, routing_id_, GetInputRouterConfigForPlatform()));
1367 1374
1368 synthetic_gesture_controller_.reset(); 1375 synthetic_gesture_controller_.reset();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 1432
1426 void RenderWidgetHostImpl::SetAutoResize(bool enable, 1433 void RenderWidgetHostImpl::SetAutoResize(bool enable,
1427 const gfx::Size& min_size, 1434 const gfx::Size& min_size,
1428 const gfx::Size& max_size) { 1435 const gfx::Size& max_size) {
1429 auto_resize_enabled_ = enable; 1436 auto_resize_enabled_ = enable;
1430 min_size_for_auto_resize_ = min_size; 1437 min_size_for_auto_resize_ = min_size;
1431 max_size_for_auto_resize_ = max_size; 1438 max_size_for_auto_resize_ = max_size;
1432 } 1439 }
1433 1440
1434 void RenderWidgetHostImpl::Destroy() { 1441 void RenderWidgetHostImpl::Destroy() {
1435 NotificationService::current()->Notify( 1442 DCHECK(!owner_delegate_);
1436 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1437 Source<RenderWidgetHost>(this),
1438 NotificationService::NoDetails());
1439
1440 // Tell the view to die.
1441 // Note that in the process of the view shutting down, it can call a ton
1442 // of other messages on us. So if you do any other deinitialization here,
1443 // do it after this call to view_->Destroy().
1444 if (view_) {
1445 view_->Destroy();
1446 view_ = nullptr;
1447 }
1448
1449 delete this; 1443 delete this;
1450 } 1444 }
1451 1445
1452 void RenderWidgetHostImpl::RendererIsUnresponsive() { 1446 void RenderWidgetHostImpl::RendererIsUnresponsive() {
1453 NotificationService::current()->Notify( 1447 NotificationService::current()->Notify(
1454 NOTIFICATION_RENDER_WIDGET_HOST_HANG, 1448 NOTIFICATION_RENDER_WIDGET_HOST_HANG,
1455 Source<RenderWidgetHost>(this), 1449 Source<RenderWidgetHost>(this),
1456 NotificationService::NoDetails()); 1450 NotificationService::NoDetails());
1457 is_unresponsive_ = true; 1451 is_unresponsive_ = true;
1458 if (delegate_) 1452 if (delegate_)
(...skipping 21 matching lines...) Expand all
1480 // TODO(evanm): This synchronously ends up calling "delete this". 1474 // TODO(evanm): This synchronously ends up calling "delete this".
1481 // Is that really what we want in response to this message? I'm matching 1475 // Is that really what we want in response to this message? I'm matching
1482 // previous behavior of the code here. 1476 // previous behavior of the code here.
1483 Destroy(); 1477 Destroy();
1484 } else { 1478 } else {
1485 RendererExited(static_cast<base::TerminationStatus>(status), exit_code); 1479 RendererExited(static_cast<base::TerminationStatus>(status), exit_code);
1486 } 1480 }
1487 } 1481 }
1488 1482
1489 void RenderWidgetHostImpl::OnClose() { 1483 void RenderWidgetHostImpl::OnClose() {
1490 Shutdown(); 1484 ShutdownWidget(true);
1491 } 1485 }
1492 1486
1493 void RenderWidgetHostImpl::OnSetTooltipText( 1487 void RenderWidgetHostImpl::OnSetTooltipText(
1494 const base::string16& tooltip_text, 1488 const base::string16& tooltip_text,
1495 WebTextDirection text_direction_hint) { 1489 WebTextDirection text_direction_hint) {
1496 // First, add directionality marks around tooltip text if necessary. 1490 // First, add directionality marks around tooltip text if necessary.
1497 // A naive solution would be to simply always wrap the text. However, on 1491 // A naive solution would be to simply always wrap the text. However, on
1498 // windows, Unicode directional embedding characters can't be displayed on 1492 // windows, Unicode directional embedding characters can't be displayed on
1499 // systems that lack RTL fonts and are instead displayed as empty squares. 1493 // systems that lack RTL fonts and are instead displayed as empty squares.
1500 // 1494 //
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 1704
1711 void RenderWidgetHostImpl::OnSetCursor(const WebCursor& cursor) { 1705 void RenderWidgetHostImpl::OnSetCursor(const WebCursor& cursor) {
1712 SetCursor(cursor); 1706 SetCursor(cursor);
1713 } 1707 }
1714 1708
1715 void RenderWidgetHostImpl::SetTouchEventEmulationEnabled( 1709 void RenderWidgetHostImpl::SetTouchEventEmulationEnabled(
1716 bool enabled, ui::GestureProviderConfigType config_type) { 1710 bool enabled, ui::GestureProviderConfigType config_type) {
1717 if (enabled) { 1711 if (enabled) {
1718 if (!touch_emulator_) { 1712 if (!touch_emulator_) {
1719 touch_emulator_.reset(new TouchEmulator( 1713 touch_emulator_.reset(new TouchEmulator(
1720 this, view_ ? content::GetScaleFactorForView(view_) : 1.0f)); 1714 this,
1715 view_.get() ? content::GetScaleFactorForView(view_.get()) : 1.0f));
1721 } 1716 }
1722 touch_emulator_->Enable(config_type); 1717 touch_emulator_->Enable(config_type);
1723 } else { 1718 } else {
1724 if (touch_emulator_) 1719 if (touch_emulator_)
1725 touch_emulator_->Disable(); 1720 touch_emulator_->Disable();
1726 } 1721 }
1727 } 1722 }
1728 1723
1729 void RenderWidgetHostImpl::OnTextInputStateChanged( 1724 void RenderWidgetHostImpl::OnTextInputStateChanged(
1730 const ViewHostMsg_TextInputState_Params& params) { 1725 const ViewHostMsg_TextInputState_Params& params) {
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 } 2222 }
2228 2223
2229 #if defined(OS_WIN) 2224 #if defined(OS_WIN)
2230 gfx::NativeViewAccessible 2225 gfx::NativeViewAccessible
2231 RenderWidgetHostImpl::GetParentNativeViewAccessible() { 2226 RenderWidgetHostImpl::GetParentNativeViewAccessible() {
2232 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; 2227 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL;
2233 } 2228 }
2234 #endif 2229 #endif
2235 2230
2236 } // namespace content 2231 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698