Chromium Code Reviews| 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/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 g_create_render_widget = create_render_widget; | 281 g_create_render_widget = create_render_widget; |
| 282 g_render_widget_initialized = render_widget_initialized; | 282 g_render_widget_initialized = render_widget_initialized; |
| 283 } | 283 } |
| 284 | 284 |
| 285 // static | 285 // static |
| 286 RenderWidget* RenderWidget::Create(int32_t opener_id, | 286 RenderWidget* RenderWidget::Create(int32_t opener_id, |
| 287 CompositorDependencies* compositor_deps, | 287 CompositorDependencies* compositor_deps, |
| 288 blink::WebPopupType popup_type, | 288 blink::WebPopupType popup_type, |
| 289 const ScreenInfo& screen_info) { | 289 const ScreenInfo& screen_info) { |
| 290 DCHECK(opener_id != MSG_ROUTING_NONE); | 290 DCHECK(opener_id != MSG_ROUTING_NONE); |
| 291 int32_t routing_id = MSG_ROUTING_NONE; | |
|
ncarter (slow)
2016/11/07 18:54:55
The code in this function is a result of inlining
| |
| 292 | |
| 293 // Do a synchronous IPC to obtain a routing ID. | |
| 294 RenderThreadImpl::current_render_message_filter()->CreateNewWidget( | |
| 295 opener_id, popup_type, &routing_id); | |
|
ncarter (slow)
2016/11/07 18:54:55
This line used to be in RenderWidget::CreateWidget
| |
| 296 | |
| 297 if (routing_id == MSG_ROUTING_NONE) | |
| 298 return nullptr; | |
| 299 | |
| 291 scoped_refptr<RenderWidget> widget(new RenderWidget( | 300 scoped_refptr<RenderWidget> widget(new RenderWidget( |
| 292 compositor_deps, popup_type, screen_info, false, false, false)); | 301 compositor_deps, popup_type, screen_info, false, false, false)); |
| 293 if (widget->Init(opener_id)) { // adds reference on success. | 302 |
| 294 return widget.get(); | 303 widget->Init(routing_id, opener_id, |
| 295 } | 304 RenderWidget::CreateWebWidget(widget.get())); |
| 296 return NULL; | 305 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference. |
| 306 return widget.get(); | |
| 297 } | 307 } |
| 298 | 308 |
| 299 // static | 309 // static |
| 300 RenderWidget* RenderWidget::CreateForFrame( | 310 RenderWidget* RenderWidget::CreateForFrame( |
| 301 int routing_id, | 311 int widget_routing_id, |
| 302 bool hidden, | 312 bool hidden, |
| 303 const ScreenInfo& screen_info, | 313 const ScreenInfo& screen_info, |
| 304 CompositorDependencies* compositor_deps, | 314 CompositorDependencies* compositor_deps, |
| 305 blink::WebLocalFrame* frame) { | 315 blink::WebLocalFrame* frame) { |
| 306 CHECK_NE(routing_id, MSG_ROUTING_NONE); | 316 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE); |
| 307 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the | 317 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the |
| 308 // same routing ID for both the view routing ID and the main frame widget | 318 // same routing ID for both the view routing ID and the main frame widget |
| 309 // routing ID. https://crbug.com/545684 | 319 // routing ID. https://crbug.com/545684 |
| 310 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id); | 320 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id); |
| 311 if (view) { | 321 if (view) { |
| 312 view->AttachWebFrameWidget( | 322 view->AttachWebFrameWidget( |
| 313 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame)); | 323 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame)); |
| 314 return view->GetWidget(); | 324 return view->GetWidget(); |
| 315 } | 325 } |
| 316 scoped_refptr<RenderWidget> widget( | 326 scoped_refptr<RenderWidget> widget( |
| 317 g_create_render_widget | 327 g_create_render_widget |
| 318 ? g_create_render_widget(compositor_deps, blink::WebPopupTypeNone, | 328 ? g_create_render_widget(compositor_deps, blink::WebPopupTypeNone, |
| 319 screen_info, false, hidden, false) | 329 screen_info, false, hidden, false) |
| 320 : new RenderWidget(compositor_deps, blink::WebPopupTypeNone, | 330 : new RenderWidget(compositor_deps, blink::WebPopupTypeNone, |
| 321 screen_info, false, hidden, false)); | 331 screen_info, false, hidden, false)); |
| 322 widget->SetRoutingID(routing_id); | |
| 323 widget->for_oopif_ = true; | 332 widget->for_oopif_ = true; |
| 324 // DoInit increments the reference count on |widget|, keeping it alive after | 333 // Init increments the reference count on |widget|, keeping it alive after |
| 325 // this function returns. | 334 // this function returns. |
| 326 if (widget->DoInit(MSG_ROUTING_NONE, | 335 widget->Init( |
| 327 RenderWidget::CreateWebFrameWidget(widget.get(), frame), | 336 widget_routing_id, MSG_ROUTING_NONE, |
| 328 CreateWidgetCallback())) { | 337 RenderWidget::CreateWebFrameWidget(widget.get(), frame)); |
| 329 if (g_render_widget_initialized) | 338 |
| 330 g_render_widget_initialized(widget.get()); | 339 if (g_render_widget_initialized) |
| 331 return widget.get(); | 340 g_render_widget_initialized(widget.get()); |
| 332 } | 341 return widget.get(); |
| 333 return nullptr; | |
| 334 } | 342 } |
| 335 | 343 |
| 336 // static | 344 // static |
| 337 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( | 345 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( |
| 338 RenderWidget* render_widget, | 346 RenderWidget* render_widget, |
| 339 blink::WebLocalFrame* frame) { | 347 blink::WebLocalFrame* frame) { |
| 340 if (!frame->parent()) { | 348 if (!frame->parent()) { |
| 341 // TODO(dcheng): The main frame widget currently has a special case. | 349 // TODO(dcheng): The main frame widget currently has a special case. |
| 342 // Eliminate this once WebView is no longer a WebWidget. | 350 // Eliminate this once WebView is no longer a WebWidget. |
| 343 return blink::WebFrameWidget::create(render_widget, frame->view(), frame); | 351 return blink::WebFrameWidget::create(render_widget, frame->view(), frame); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 | 383 |
| 376 // If we are swapping out, we will call ReleaseProcess, allowing the process | 384 // If we are swapping out, we will call ReleaseProcess, allowing the process |
| 377 // to exit if all of its RenderViews are swapped out. We wait until the | 385 // to exit if all of its RenderViews are swapped out. We wait until the |
| 378 // WasSwappedOut call to do this, to allow the unload handler to finish. | 386 // WasSwappedOut call to do this, to allow the unload handler to finish. |
| 379 // If we are swapping in, we call AddRefProcess to prevent the process from | 387 // If we are swapping in, we call AddRefProcess to prevent the process from |
| 380 // exiting. | 388 // exiting. |
| 381 if (!is_swapped_out_) | 389 if (!is_swapped_out_) |
| 382 RenderProcess::current()->AddRefProcess(); | 390 RenderProcess::current()->AddRefProcess(); |
| 383 } | 391 } |
| 384 | 392 |
| 385 bool RenderWidget::CreateWidget(int32_t opener_id, | 393 void RenderWidget::Init(int32_t widget_routing_id, |
|
ncarter (slow)
2016/11/07 18:54:55
I eliminated the single-arg ::Init function, and t
| |
| 386 blink::WebPopupType popup_type, | 394 int32_t opener_id, |
| 387 int32_t* routing_id) { | 395 WebWidget* web_widget) { |
| 388 RenderThreadImpl::current_render_message_filter()->CreateNewWidget( | 396 DCHECK(!webwidget_internal_); |
| 389 opener_id, popup_type, routing_id); | |
| 390 return true; | |
| 391 } | |
| 392 | 397 |
| 393 bool RenderWidget::Init(int32_t opener_id) { | 398 SetRoutingID(widget_routing_id); |
| 394 bool success = DoInit(opener_id, RenderWidget::CreateWebWidget(this), | |
| 395 base::Bind(&RenderWidget::CreateWidget, base::Unretained(this), | |
| 396 opener_id, popup_type_, &routing_id_)); | |
| 397 if (success) { | |
| 398 SetRoutingID(routing_id_); | |
| 399 return true; | |
| 400 } | |
| 401 return false; | |
| 402 } | |
| 403 | |
| 404 bool RenderWidget::DoInit(int32_t opener_id, | |
| 405 WebWidget* web_widget, | |
| 406 CreateWidgetCallback create_widget_callback) { | |
|
ncarter (slow)
2016/11/07 18:54:55
Instead of passing a callback, we just have the ca
| |
| 407 DCHECK(!webwidget_internal_); | |
| 408 | 399 |
| 409 if (opener_id != MSG_ROUTING_NONE) | 400 if (opener_id != MSG_ROUTING_NONE) |
| 410 opener_id_ = opener_id; | 401 opener_id_ = opener_id; |
| 411 | 402 |
| 412 webwidget_internal_ = web_widget; | 403 webwidget_internal_ = web_widget; |
| 413 webwidget_mouse_lock_target_.reset( | 404 webwidget_mouse_lock_target_.reset( |
| 414 new WebWidgetLockTarget(webwidget_internal_)); | 405 new WebWidgetLockTarget(webwidget_internal_)); |
| 415 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); | 406 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); |
| 416 | 407 |
| 417 bool result = true; | 408 RenderThread::Get()->AddRoute(routing_id_, this); |
| 418 if (!create_widget_callback.is_null()) | 409 // Take a reference on behalf of the RenderThread. This will be balanced |
| 419 result = std::move(create_widget_callback).Run(); | 410 // when we receive ViewMsg_Close. |
| 420 | 411 AddRef(); |
| 421 if (result) { | 412 if (RenderThreadImpl::current()) { |
| 422 RenderThread::Get()->AddRoute(routing_id_, this); | 413 RenderThreadImpl::current()->WidgetCreated(); |
| 423 // Take a reference on behalf of the RenderThread. This will be balanced | 414 if (is_hidden_) |
| 424 // when we receive ViewMsg_Close. | 415 RenderThreadImpl::current()->WidgetHidden(); |
| 425 AddRef(); | |
| 426 if (RenderThreadImpl::current()) { | |
| 427 RenderThreadImpl::current()->WidgetCreated(); | |
| 428 if (is_hidden_) | |
| 429 RenderThreadImpl::current()->WidgetHidden(); | |
| 430 } | |
| 431 | |
| 432 return true; | |
| 433 } else { | |
| 434 // The above Send can fail when the tab is closing. | |
| 435 return false; | |
| 436 } | 416 } |
| 437 } | 417 } |
| 438 | 418 |
| 439 void RenderWidget::WasSwappedOut() { | 419 void RenderWidget::WasSwappedOut() { |
| 440 // If we have been swapped out and no one else is using this process, | 420 // If we have been swapped out and no one else is using this process, |
| 441 // it's safe to exit now. | 421 // it's safe to exit now. |
| 442 CHECK(is_swapped_out_); | 422 CHECK(is_swapped_out_); |
| 443 RenderProcess::current()->ReleaseProcess(); | 423 RenderProcess::current()->ReleaseProcess(); |
| 444 } | 424 } |
| 445 | 425 |
| (...skipping 1651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2097 bool RenderWidget::isPointerLocked() { | 2077 bool RenderWidget::isPointerLocked() { |
| 2098 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2078 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2099 webwidget_mouse_lock_target_.get()); | 2079 webwidget_mouse_lock_target_.get()); |
| 2100 } | 2080 } |
| 2101 | 2081 |
| 2102 blink::WebWidget* RenderWidget::GetWebWidget() const { | 2082 blink::WebWidget* RenderWidget::GetWebWidget() const { |
| 2103 return webwidget_internal_; | 2083 return webwidget_internal_; |
| 2104 } | 2084 } |
| 2105 | 2085 |
| 2106 } // namespace content | 2086 } // namespace content |
| OLD | NEW |