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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 NOTIFICATION_WEB_CONTENTS_DESTROYED, | 401 NOTIFICATION_WEB_CONTENTS_DESTROYED, |
402 Source<WebContents>(this), | 402 Source<WebContents>(this), |
403 NotificationService::NoDetails()); | 403 NotificationService::NoDetails()); |
404 | 404 |
405 // Destroy all frame tree nodes except for the root; this notifies observers. | 405 // Destroy all frame tree nodes except for the root; this notifies observers. |
406 frame_tree_.ResetForMainFrameSwap(); | 406 frame_tree_.ResetForMainFrameSwap(); |
407 GetRenderManager()->ResetProxyHosts(); | 407 GetRenderManager()->ResetProxyHosts(); |
408 | 408 |
409 // Manually call the observer methods for the root frame tree node. | 409 // Manually call the observer methods for the root frame tree node. |
410 RenderFrameHostManager* root = GetRenderManager(); | 410 RenderFrameHostManager* root = GetRenderManager(); |
411 if (root->pending_frame_host()) { | 411 |
412 FOR_EACH_OBSERVER(WebContentsObserver, | 412 if (root->pending_frame_host()) |
413 observers_, | 413 root->pending_frame_host()->SetRenderFrameCreated(false); |
414 RenderFrameDeleted(root->pending_frame_host())); | 414 root->current_frame_host()->SetRenderFrameCreated(false); |
415 } | |
416 FOR_EACH_OBSERVER(WebContentsObserver, | |
417 observers_, | |
418 RenderFrameDeleted(root->current_frame_host())); | |
419 | 415 |
420 if (root->pending_render_view_host()) { | 416 if (root->pending_render_view_host()) { |
421 FOR_EACH_OBSERVER(WebContentsObserver, | 417 FOR_EACH_OBSERVER(WebContentsObserver, |
422 observers_, | 418 observers_, |
423 RenderViewDeleted(root->pending_render_view_host())); | 419 RenderViewDeleted(root->pending_render_view_host())); |
424 } | 420 } |
425 | 421 |
426 FOR_EACH_OBSERVER(WebContentsObserver, | 422 FOR_EACH_OBSERVER(WebContentsObserver, |
427 observers_, | 423 observers_, |
428 RenderViewDeleted(root->current_host())); | 424 RenderViewDeleted(root->current_host())); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 const IPC::Message& message) { | 494 const IPC::Message& message) { |
499 DCHECK(render_view_host || render_frame_host); | 495 DCHECK(render_view_host || render_frame_host); |
500 if (GetWebUI() && | 496 if (GetWebUI() && |
501 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { | 497 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { |
502 return true; | 498 return true; |
503 } | 499 } |
504 | 500 |
505 ObserverListBase<WebContentsObserver>::Iterator it(observers_); | 501 ObserverListBase<WebContentsObserver>::Iterator it(observers_); |
506 WebContentsObserver* observer; | 502 WebContentsObserver* observer; |
507 if (render_frame_host) { | 503 if (render_frame_host) { |
508 while ((observer = it.GetNext()) != NULL) | 504 if (!static_cast<RenderFrameHostImpl*>(render_frame_host) |
509 if (observer->OnMessageReceived(message, render_frame_host)) | 505 ->is_swapped_out()) { |
Charlie Reis
2015/02/12 00:29:31
I'm worried about regressions from this change. T
nasko
2015/02/12 17:52:26
Hmm, don't quite recall, but after all the followu
| |
510 return true; | 506 while ((observer = it.GetNext()) != NULL) |
507 if (observer->OnMessageReceived(message, render_frame_host)) | |
508 return true; | |
509 } | |
511 } else { | 510 } else { |
512 while ((observer = it.GetNext()) != NULL) | 511 while ((observer = it.GetNext()) != NULL) |
513 if (observer->OnMessageReceived(message)) | 512 if (observer->OnMessageReceived(message)) |
514 return true; | 513 return true; |
515 } | 514 } |
516 | 515 |
517 // Message handlers should be aware of which | 516 // Message handlers should be aware of which |
518 // RenderViewHost/RenderFrameHost sent the message, which is temporarily | 517 // RenderViewHost/RenderFrameHost sent the message, which is temporarily |
519 // stored in render_(view|frame)_message_source_. | 518 // stored in render_(view|frame)_message_source_. |
520 if (render_frame_host) | 519 if (render_frame_host) |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1259 date_time_chooser_.reset(new DateTimeChooserAndroid()); | 1258 date_time_chooser_.reset(new DateTimeChooserAndroid()); |
1260 #endif | 1259 #endif |
1261 | 1260 |
1262 // BrowserPluginGuest::Init needs to be called after this WebContents has | 1261 // BrowserPluginGuest::Init needs to be called after this WebContents has |
1263 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. | 1262 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. |
1264 if (browser_plugin_guest_) | 1263 if (browser_plugin_guest_) |
1265 browser_plugin_guest_->Init(); | 1264 browser_plugin_guest_->Init(); |
1266 | 1265 |
1267 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 1266 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
1268 g_created_callbacks.Get().at(i).Run(this); | 1267 g_created_callbacks.Get().at(i).Run(this); |
1268 | |
1269 // If the WebContents creation was renderer-initiated, it means that the | |
1270 // corresponding RenderView and main RenderFrame have already been created. | |
Charlie Reis
2015/02/12 00:29:31
Wow. There are so many ways to create RenderFrame
nasko
2015/02/12 17:52:26
Acknowledged.
| |
1271 // Ensure observers are notified about this. | |
1272 if (params.renderer_created) { | |
Charlie Reis
2015/02/12 00:29:31
Maybe params.renderer_initiated_creation?
nasko
2015/02/12 17:52:26
Done.
| |
1273 RenderViewCreated(GetRenderViewHost()); | |
1274 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true); | |
1275 } | |
1269 } | 1276 } |
1270 | 1277 |
1271 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { | 1278 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
1272 RemoveDestructionObserver(web_contents); | 1279 RemoveDestructionObserver(web_contents); |
1273 | 1280 |
1274 // Clear the opener if it has been closed. | 1281 // Clear the opener if it has been closed. |
1275 if (web_contents == opener_) { | 1282 if (web_contents == opener_) { |
1276 opener_ = NULL; | 1283 opener_ = NULL; |
1277 return; | 1284 return; |
1278 } | 1285 } |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1577 | 1584 |
1578 // Create the new web contents. This will automatically create the new | 1585 // Create the new web contents. This will automatically create the new |
1579 // WebContentsView. In the future, we may want to create the view separately. | 1586 // WebContentsView. In the future, we may want to create the view separately. |
1580 CreateParams create_params(GetBrowserContext(), site_instance.get()); | 1587 CreateParams create_params(GetBrowserContext(), site_instance.get()); |
1581 create_params.routing_id = route_id; | 1588 create_params.routing_id = route_id; |
1582 create_params.main_frame_routing_id = main_frame_route_id; | 1589 create_params.main_frame_routing_id = main_frame_route_id; |
1583 create_params.opener = this; | 1590 create_params.opener = this; |
1584 create_params.opener_suppressed = params.opener_suppressed; | 1591 create_params.opener_suppressed = params.opener_suppressed; |
1585 if (params.disposition == NEW_BACKGROUND_TAB) | 1592 if (params.disposition == NEW_BACKGROUND_TAB) |
1586 create_params.initially_hidden = true; | 1593 create_params.initially_hidden = true; |
1594 create_params.renderer_created = true; | |
1587 | 1595 |
1588 WebContentsImpl* new_contents = NULL; | 1596 WebContentsImpl* new_contents = NULL; |
1589 if (!is_guest) { | 1597 if (!is_guest) { |
1590 create_params.context = view_->GetNativeView(); | 1598 create_params.context = view_->GetNativeView(); |
1591 create_params.initial_size = GetContainerBounds().size(); | 1599 create_params.initial_size = GetContainerBounds().size(); |
1592 new_contents = static_cast<WebContentsImpl*>( | 1600 new_contents = static_cast<WebContentsImpl*>( |
1593 WebContents::Create(create_params)); | 1601 WebContents::Create(create_params)); |
1594 } else { | 1602 } else { |
1595 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); | 1603 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); |
1596 } | 1604 } |
1597 new_contents->GetController().SetSessionStorageNamespace( | 1605 new_contents->GetController().SetSessionStorageNamespace( |
1598 partition_id, | 1606 partition_id, |
1599 session_storage_namespace); | 1607 session_storage_namespace); |
1600 new_contents->RenderViewCreated(new_contents->GetRenderViewHost()); | |
1601 | 1608 |
1602 // Save the window for later if we're not suppressing the opener (since it | 1609 // Save the window for later if we're not suppressing the opener (since it |
1603 // will be shown immediately). | 1610 // will be shown immediately). |
1604 if (!params.opener_suppressed) { | 1611 if (!params.opener_suppressed) { |
1605 if (!is_guest) { | 1612 if (!is_guest) { |
1606 WebContentsView* new_view = new_contents->view_.get(); | 1613 WebContentsView* new_view = new_contents->view_.get(); |
1607 | 1614 |
1608 // TODO(brettw): It seems bogus that we have to call this function on the | 1615 // TODO(brettw): It seems bogus that we have to call this function on the |
1609 // newly created object and give it one of its own member variables. | 1616 // newly created object and give it one of its own member variables. |
1610 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false); | 1617 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false); |
(...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3642 // Put the renderer in view source mode. | 3649 // Put the renderer in view source mode. |
3643 render_view_host->Send( | 3650 render_view_host->Send( |
3644 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); | 3651 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
3645 } | 3652 } |
3646 | 3653 |
3647 view_->RenderViewCreated(render_view_host); | 3654 view_->RenderViewCreated(render_view_host); |
3648 | 3655 |
3649 FOR_EACH_OBSERVER( | 3656 FOR_EACH_OBSERVER( |
3650 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); | 3657 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
3651 | 3658 |
3652 // We tell the observers now instead of when the main RenderFrameHostImpl is | |
3653 // constructed because otherwise it would be too early (i.e. IPCs sent to the | |
3654 // frame would be dropped because it's not created yet). | |
3655 RenderFrameHost* main_frame = render_view_host->GetMainFrame(); | |
3656 FOR_EACH_OBSERVER( | |
3657 WebContentsObserver, observers_, RenderFrameCreated(main_frame)); | |
3658 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame); | |
Charlie Reis
2015/02/12 00:29:31
Where does SetAccessibilityModeOnFrame get called
nasko
2015/02/12 17:52:26
WebContentsImpl::RenderFrameCreated has pretty muc
| |
3659 | |
3660 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host); | 3659 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host); |
3661 } | 3660 } |
3662 | 3661 |
3663 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { | 3662 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
3664 if (rvh != GetRenderViewHost()) { | 3663 if (rvh != GetRenderViewHost()) { |
3665 // Don't notify the world, since this came from a renderer in the | 3664 // Don't notify the world, since this came from a renderer in the |
3666 // background. | 3665 // background. |
3667 return; | 3666 return; |
3668 } | 3667 } |
3669 | 3668 |
(...skipping 13 matching lines...) Expand all Loading... | |
3683 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { | 3682 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
3684 view_->Focus(); | 3683 view_->Focus(); |
3685 } | 3684 } |
3686 | 3685 |
3687 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); | 3686 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); |
3688 } | 3687 } |
3689 | 3688 |
3690 void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, | 3689 void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
3691 base::TerminationStatus status, | 3690 base::TerminationStatus status, |
3692 int error_code) { | 3691 int error_code) { |
3693 // TODO(nasko): This isn't ideal; the termination process should be handled by | |
3694 // RenderFrameDeleted(). See http://crbug.com/455943. | |
3695 ClearPowerSaveBlockers(rvh->GetMainFrame()); | |
Charlie Reis
2015/02/12 00:29:31
Just to confirm, we now get RenderFrameDeleted in
nasko
2015/02/12 17:52:26
Correct.
| |
3696 | |
3697 if (rvh != GetRenderViewHost()) { | 3692 if (rvh != GetRenderViewHost()) { |
3698 // The pending page's RenderViewHost is gone. | 3693 // The pending page's RenderViewHost is gone. |
3699 return; | 3694 return; |
3700 } | 3695 } |
3701 | 3696 |
3702 // Ensure fullscreen mode is exited in the |delegate_| since a crashed | 3697 // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
3703 // renderer may not have made a clean exit. | 3698 // renderer may not have made a clean exit. |
3704 if (IsFullscreenForCurrentTab()) | 3699 if (IsFullscreenForCurrentTab()) |
3705 ExitFullscreenMode(); | 3700 ExitFullscreenMode(); |
3706 | 3701 |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4509 node->render_manager()->ResumeResponseDeferredAtStart(); | 4504 node->render_manager()->ResumeResponseDeferredAtStart(); |
4510 } | 4505 } |
4511 | 4506 |
4512 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4507 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4513 force_disable_overscroll_content_ = force_disable; | 4508 force_disable_overscroll_content_ = force_disable; |
4514 if (view_) | 4509 if (view_) |
4515 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4510 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4516 } | 4511 } |
4517 | 4512 |
4518 } // namespace content | 4513 } // namespace content |
OLD | NEW |