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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 g_create_render_widget = create_render_widget; | 280 g_create_render_widget = create_render_widget; |
| 281 g_render_widget_initialized = render_widget_initialized; | 281 g_render_widget_initialized = render_widget_initialized; |
| 282 } | 282 } |
| 283 | 283 |
| 284 // static | 284 // static |
| 285 RenderWidget* RenderWidget::Create(int32_t opener_id, | 285 RenderWidget* RenderWidget::Create(int32_t opener_id, |
| 286 CompositorDependencies* compositor_deps, | 286 CompositorDependencies* compositor_deps, |
| 287 blink::WebPopupType popup_type, | 287 blink::WebPopupType popup_type, |
| 288 const ScreenInfo& screen_info) { | 288 const ScreenInfo& screen_info) { |
| 289 DCHECK(opener_id != MSG_ROUTING_NONE); | 289 DCHECK(opener_id != MSG_ROUTING_NONE); |
| 290 int32_t routing_id = MSG_ROUTING_NONE; | |
| 291 | |
| 292 // Do a synchronous IPC to obtain a routing ID. | |
| 293 RenderThreadImpl::current_render_message_filter()->CreateNewWidget( | |
| 294 opener_id, popup_type, &routing_id); | |
|
ncarter (slow)
2016/11/09 22:52:38
This comes from the old RenderWidget::CreateWidget
| |
| 295 | |
| 296 if (routing_id == MSG_ROUTING_NONE) | |
|
lfg
2016/11/09 23:27:30
Is this for error handling when the IPC fails? The
ncarter (slow)
2016/11/10 18:44:45
I read up on this, and asked on chromium-mojo. Moj
| |
| 297 return nullptr; | |
| 298 | |
| 290 scoped_refptr<RenderWidget> widget(new RenderWidget( | 299 scoped_refptr<RenderWidget> widget(new RenderWidget( |
| 291 compositor_deps, popup_type, screen_info, false, false, false)); | 300 compositor_deps, popup_type, screen_info, false, false, false)); |
| 292 if (widget->Init(opener_id)) { // adds reference on success. | 301 widget->InitRoutingID(routing_id); |
|
ncarter (slow)
2016/11/09 22:52:38
The one-arg Init() function has been inlined into
| |
| 293 return widget.get(); | 302 widget->Init(opener_id, RenderWidget::CreateWebWidget(widget.get())); |
| 294 } | 303 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference. |
| 295 return NULL; | 304 return widget.get(); |
| 296 } | 305 } |
| 297 | 306 |
| 298 // static | 307 // static |
| 299 RenderWidget* RenderWidget::CreateForFrame( | 308 RenderWidget* RenderWidget::CreateForFrame( |
| 300 int routing_id, | 309 int widget_routing_id, |
| 301 bool hidden, | 310 bool hidden, |
| 302 const ScreenInfo& screen_info, | 311 const ScreenInfo& screen_info, |
| 303 CompositorDependencies* compositor_deps, | 312 CompositorDependencies* compositor_deps, |
| 304 blink::WebLocalFrame* frame) { | 313 blink::WebLocalFrame* frame) { |
| 305 CHECK_NE(routing_id, MSG_ROUTING_NONE); | 314 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE); |
| 306 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the | 315 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the |
| 307 // same routing ID for both the view routing ID and the main frame widget | 316 // same routing ID for both the view routing ID and the main frame widget |
| 308 // routing ID. https://crbug.com/545684 | 317 // routing ID. https://crbug.com/545684 |
| 309 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id); | 318 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id); |
| 310 if (view) { | 319 if (view) { |
| 311 view->AttachWebFrameWidget( | 320 view->AttachWebFrameWidget( |
| 312 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame)); | 321 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame)); |
| 313 return view->GetWidget(); | 322 return view->GetWidget(); |
| 314 } | 323 } |
| 315 scoped_refptr<RenderWidget> widget( | 324 scoped_refptr<RenderWidget> widget( |
| 316 g_create_render_widget | 325 g_create_render_widget |
| 317 ? g_create_render_widget(compositor_deps, blink::WebPopupTypeNone, | 326 ? g_create_render_widget(compositor_deps, blink::WebPopupTypeNone, |
| 318 screen_info, false, hidden, false) | 327 screen_info, false, hidden, false) |
| 319 : new RenderWidget(compositor_deps, blink::WebPopupTypeNone, | 328 : new RenderWidget(compositor_deps, blink::WebPopupTypeNone, |
| 320 screen_info, false, hidden, false)); | 329 screen_info, false, hidden, false)); |
| 321 widget->SetRoutingID(routing_id); | |
| 322 widget->for_oopif_ = true; | 330 widget->for_oopif_ = true; |
| 323 // DoInit increments the reference count on |widget|, keeping it alive after | 331 // Init increments the reference count on |widget|, keeping it alive after |
| 324 // this function returns. | 332 // this function returns. |
| 325 if (widget->DoInit(MSG_ROUTING_NONE, | 333 widget->InitRoutingID(widget_routing_id); |
| 326 RenderWidget::CreateWebFrameWidget(widget.get(), frame), | 334 widget->Init(MSG_ROUTING_NONE, |
| 327 CreateWidgetCallback())) { | 335 RenderWidget::CreateWebFrameWidget(widget.get(), frame)); |
| 328 if (g_render_widget_initialized) | 336 |
| 329 g_render_widget_initialized(widget.get()); | 337 if (g_render_widget_initialized) |
| 330 return widget.get(); | 338 g_render_widget_initialized(widget.get()); |
| 331 } | 339 return widget.get(); |
| 332 return nullptr; | |
| 333 } | 340 } |
| 334 | 341 |
| 335 // static | 342 // static |
| 336 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( | 343 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( |
| 337 RenderWidget* render_widget, | 344 RenderWidget* render_widget, |
| 338 blink::WebLocalFrame* frame) { | 345 blink::WebLocalFrame* frame) { |
| 339 if (!frame->parent()) { | 346 if (!frame->parent()) { |
| 340 // TODO(dcheng): The main frame widget currently has a special case. | 347 // TODO(dcheng): The main frame widget currently has a special case. |
| 341 // Eliminate this once WebView is no longer a WebWidget. | 348 // Eliminate this once WebView is no longer a WebWidget. |
| 342 return blink::WebFrameWidget::create(render_widget, frame->view(), frame); | 349 return blink::WebFrameWidget::create(render_widget, frame->view(), frame); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 354 default: | 361 default: |
| 355 NOTREACHED(); | 362 NOTREACHED(); |
| 356 } | 363 } |
| 357 return NULL; | 364 return NULL; |
| 358 } | 365 } |
| 359 | 366 |
| 360 void RenderWidget::CloseForFrame() { | 367 void RenderWidget::CloseForFrame() { |
| 361 OnClose(); | 368 OnClose(); |
| 362 } | 369 } |
| 363 | 370 |
| 364 void RenderWidget::SetRoutingID(int32_t routing_id) { | |
| 365 routing_id_ = routing_id; | |
| 366 input_handler_.reset(new RenderWidgetInputHandler( | |
| 367 GetRenderWidgetInputHandlerDelegate(this), this)); | |
| 368 } | |
| 369 | |
| 370 void RenderWidget::SetSwappedOut(bool is_swapped_out) { | 371 void RenderWidget::SetSwappedOut(bool is_swapped_out) { |
| 371 // We should only toggle between states. | 372 // We should only toggle between states. |
| 372 DCHECK(is_swapped_out_ != is_swapped_out); | 373 DCHECK(is_swapped_out_ != is_swapped_out); |
| 373 is_swapped_out_ = is_swapped_out; | 374 is_swapped_out_ = is_swapped_out; |
| 374 | 375 |
| 375 // If we are swapping out, we will call ReleaseProcess, allowing the process | 376 // If we are swapping out, we will call ReleaseProcess, allowing the process |
| 376 // to exit if all of its RenderViews are swapped out. We wait until the | 377 // to exit if all of its RenderViews are swapped out. We wait until the |
| 377 // WasSwappedOut call to do this, to allow the unload handler to finish. | 378 // WasSwappedOut call to do this, to allow the unload handler to finish. |
| 378 // If we are swapping in, we call AddRefProcess to prevent the process from | 379 // If we are swapping in, we call AddRefProcess to prevent the process from |
| 379 // exiting. | 380 // exiting. |
| 380 if (!is_swapped_out_) | 381 if (!is_swapped_out_) |
| 381 RenderProcess::current()->AddRefProcess(); | 382 RenderProcess::current()->AddRefProcess(); |
| 382 } | 383 } |
| 383 | 384 |
| 384 bool RenderWidget::CreateWidget(int32_t opener_id, | 385 void RenderWidget::InitRoutingID(int32_t routing_id) { |
| 385 blink::WebPopupType popup_type, | 386 DCHECK_EQ(routing_id_, MSG_ROUTING_NONE); |
| 386 int32_t* routing_id) { | 387 routing_id_ = routing_id; |
| 387 RenderThreadImpl::current_render_message_filter()->CreateNewWidget( | 388 input_handler_.reset(new RenderWidgetInputHandler( |
| 388 opener_id, popup_type, routing_id); | 389 GetRenderWidgetInputHandlerDelegate(this), this)); |
| 389 return true; | |
| 390 } | 390 } |
| 391 | 391 |
| 392 bool RenderWidget::Init(int32_t opener_id) { | 392 void RenderWidget::Init(int32_t opener_id, WebWidget* web_widget) { |
| 393 bool success = DoInit(opener_id, RenderWidget::CreateWebWidget(this), | |
| 394 base::Bind(&RenderWidget::CreateWidget, base::Unretained(this), | |
| 395 opener_id, popup_type_, &routing_id_)); | |
| 396 if (success) { | |
| 397 SetRoutingID(routing_id_); | |
| 398 return true; | |
| 399 } | |
| 400 return false; | |
| 401 } | |
| 402 | |
| 403 bool RenderWidget::DoInit(int32_t opener_id, | |
| 404 WebWidget* web_widget, | |
| 405 CreateWidgetCallback create_widget_callback) { | |
| 406 DCHECK(!webwidget_internal_); | 393 DCHECK(!webwidget_internal_); |
| 394 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); | |
| 407 | 395 |
| 408 if (opener_id != MSG_ROUTING_NONE) | 396 if (opener_id != MSG_ROUTING_NONE) |
| 409 opener_id_ = opener_id; | 397 opener_id_ = opener_id; |
| 410 | 398 |
| 411 webwidget_internal_ = web_widget; | 399 webwidget_internal_ = web_widget; |
| 412 webwidget_mouse_lock_target_.reset( | 400 webwidget_mouse_lock_target_.reset( |
| 413 new WebWidgetLockTarget(webwidget_internal_)); | 401 new WebWidgetLockTarget(webwidget_internal_)); |
| 414 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); | 402 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); |
| 415 | 403 |
| 416 bool result = true; | 404 RenderThread::Get()->AddRoute(routing_id_, this); |
| 417 if (!create_widget_callback.is_null()) | 405 // Take a reference on behalf of the RenderThread. This will be balanced |
| 418 result = std::move(create_widget_callback).Run(); | 406 // when we receive ViewMsg_Close. |
| 419 | 407 AddRef(); |
| 420 if (result) { | 408 if (RenderThreadImpl::current()) { |
| 421 RenderThread::Get()->AddRoute(routing_id_, this); | 409 RenderThreadImpl::current()->WidgetCreated(); |
| 422 // Take a reference on behalf of the RenderThread. This will be balanced | 410 if (is_hidden_) |
| 423 // when we receive ViewMsg_Close. | 411 RenderThreadImpl::current()->WidgetHidden(); |
| 424 AddRef(); | |
| 425 if (RenderThreadImpl::current()) { | |
| 426 RenderThreadImpl::current()->WidgetCreated(); | |
| 427 if (is_hidden_) | |
| 428 RenderThreadImpl::current()->WidgetHidden(); | |
| 429 } | |
| 430 | |
| 431 return true; | |
| 432 } else { | |
| 433 // The above Send can fail when the tab is closing. | |
| 434 return false; | |
| 435 } | 412 } |
| 436 } | 413 } |
| 437 | 414 |
| 438 void RenderWidget::WasSwappedOut() { | 415 void RenderWidget::WasSwappedOut() { |
| 439 // If we have been swapped out and no one else is using this process, | 416 // If we have been swapped out and no one else is using this process, |
| 440 // it's safe to exit now. | 417 // it's safe to exit now. |
| 441 CHECK(is_swapped_out_); | 418 CHECK(is_swapped_out_); |
| 442 RenderProcess::current()->ReleaseProcess(); | 419 RenderProcess::current()->ReleaseProcess(); |
| 443 } | 420 } |
| 444 | 421 |
| (...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2067 bool RenderWidget::isPointerLocked() { | 2044 bool RenderWidget::isPointerLocked() { |
| 2068 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2045 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2069 webwidget_mouse_lock_target_.get()); | 2046 webwidget_mouse_lock_target_.get()); |
| 2070 } | 2047 } |
| 2071 | 2048 |
| 2072 blink::WebWidget* RenderWidget::GetWebWidget() const { | 2049 blink::WebWidget* RenderWidget::GetWebWidget() const { |
| 2073 return webwidget_internal_; | 2050 return webwidget_internal_; |
| 2074 } | 2051 } |
| 2075 | 2052 |
| 2076 } // namespace content | 2053 } // namespace content |
| OLD | NEW |