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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 NOTIFICATION_WEB_CONTENTS_DESTROYED, | 399 NOTIFICATION_WEB_CONTENTS_DESTROYED, |
400 Source<WebContents>(this), | 400 Source<WebContents>(this), |
401 NotificationService::NoDetails()); | 401 NotificationService::NoDetails()); |
402 | 402 |
403 // Destroy all frame tree nodes except for the root; this notifies observers. | 403 // Destroy all frame tree nodes except for the root; this notifies observers. |
404 frame_tree_.ResetForMainFrameSwap(); | 404 frame_tree_.ResetForMainFrameSwap(); |
405 GetRenderManager()->ResetProxyHosts(); | 405 GetRenderManager()->ResetProxyHosts(); |
406 | 406 |
407 // Manually call the observer methods for the root frame tree node. | 407 // Manually call the observer methods for the root frame tree node. |
408 RenderFrameHostManager* root = GetRenderManager(); | 408 RenderFrameHostManager* root = GetRenderManager(); |
409 if (root->pending_frame_host()) { | 409 |
410 FOR_EACH_OBSERVER(WebContentsObserver, | 410 if (root->pending_frame_host()) |
411 observers_, | 411 root->pending_frame_host()->SetRenderFrameCreated(false); |
412 RenderFrameDeleted(root->pending_frame_host())); | 412 root->current_frame_host()->SetRenderFrameCreated(false); |
413 } | |
414 FOR_EACH_OBSERVER(WebContentsObserver, | |
415 observers_, | |
416 RenderFrameDeleted(root->current_frame_host())); | |
417 | 413 |
418 if (root->pending_render_view_host()) { | 414 if (root->pending_render_view_host()) { |
419 FOR_EACH_OBSERVER(WebContentsObserver, | 415 FOR_EACH_OBSERVER(WebContentsObserver, |
420 observers_, | 416 observers_, |
421 RenderViewDeleted(root->pending_render_view_host())); | 417 RenderViewDeleted(root->pending_render_view_host())); |
422 } | 418 } |
423 | 419 |
424 FOR_EACH_OBSERVER(WebContentsObserver, | 420 FOR_EACH_OBSERVER(WebContentsObserver, |
425 observers_, | 421 observers_, |
426 RenderViewDeleted(root->current_host())); | 422 RenderViewDeleted(root->current_host())); |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 date_time_chooser_.reset(new DateTimeChooserAndroid()); | 1254 date_time_chooser_.reset(new DateTimeChooserAndroid()); |
1259 #endif | 1255 #endif |
1260 | 1256 |
1261 // BrowserPluginGuest::Init needs to be called after this WebContents has | 1257 // BrowserPluginGuest::Init needs to be called after this WebContents has |
1262 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. | 1258 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. |
1263 if (browser_plugin_guest_) | 1259 if (browser_plugin_guest_) |
1264 browser_plugin_guest_->Init(); | 1260 browser_plugin_guest_->Init(); |
1265 | 1261 |
1266 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 1262 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
1267 g_created_callbacks.Get().at(i).Run(this); | 1263 g_created_callbacks.Get().at(i).Run(this); |
| 1264 |
| 1265 // If the WebContents creation was renderer-initiated, it means that the |
| 1266 // corresponding RenderView and main RenderFrame have already been created. |
| 1267 // Ensure observers are notified about this. |
| 1268 if (params.renderer_initiated_creation) { |
| 1269 RenderViewCreated(GetRenderViewHost()); |
| 1270 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true); |
| 1271 } |
1268 } | 1272 } |
1269 | 1273 |
1270 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { | 1274 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
1271 RemoveDestructionObserver(web_contents); | 1275 RemoveDestructionObserver(web_contents); |
1272 | 1276 |
1273 // Clear the opener if it has been closed. | 1277 // Clear the opener if it has been closed. |
1274 if (web_contents == opener_) { | 1278 if (web_contents == opener_) { |
1275 opener_ = NULL; | 1279 opener_ = NULL; |
1276 return; | 1280 return; |
1277 } | 1281 } |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 | 1591 |
1588 // Create the new web contents. This will automatically create the new | 1592 // Create the new web contents. This will automatically create the new |
1589 // WebContentsView. In the future, we may want to create the view separately. | 1593 // WebContentsView. In the future, we may want to create the view separately. |
1590 CreateParams create_params(GetBrowserContext(), site_instance.get()); | 1594 CreateParams create_params(GetBrowserContext(), site_instance.get()); |
1591 create_params.routing_id = route_id; | 1595 create_params.routing_id = route_id; |
1592 create_params.main_frame_routing_id = main_frame_route_id; | 1596 create_params.main_frame_routing_id = main_frame_route_id; |
1593 create_params.opener = this; | 1597 create_params.opener = this; |
1594 create_params.opener_suppressed = params.opener_suppressed; | 1598 create_params.opener_suppressed = params.opener_suppressed; |
1595 if (params.disposition == NEW_BACKGROUND_TAB) | 1599 if (params.disposition == NEW_BACKGROUND_TAB) |
1596 create_params.initially_hidden = true; | 1600 create_params.initially_hidden = true; |
| 1601 create_params.renderer_initiated_creation = true; |
1597 | 1602 |
1598 WebContentsImpl* new_contents = NULL; | 1603 WebContentsImpl* new_contents = NULL; |
1599 if (!is_guest) { | 1604 if (!is_guest) { |
1600 create_params.context = view_->GetNativeView(); | 1605 create_params.context = view_->GetNativeView(); |
1601 create_params.initial_size = GetContainerBounds().size(); | 1606 create_params.initial_size = GetContainerBounds().size(); |
1602 new_contents = static_cast<WebContentsImpl*>( | 1607 new_contents = static_cast<WebContentsImpl*>( |
1603 WebContents::Create(create_params)); | 1608 WebContents::Create(create_params)); |
1604 } else { | 1609 } else { |
1605 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); | 1610 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); |
1606 } | 1611 } |
1607 new_contents->GetController().SetSessionStorageNamespace( | 1612 new_contents->GetController().SetSessionStorageNamespace( |
1608 partition_id, | 1613 partition_id, |
1609 session_storage_namespace); | 1614 session_storage_namespace); |
1610 new_contents->RenderViewCreated(new_contents->GetRenderViewHost()); | |
1611 | 1615 |
1612 // Save the window for later if we're not suppressing the opener (since it | 1616 // Save the window for later if we're not suppressing the opener (since it |
1613 // will be shown immediately). | 1617 // will be shown immediately). |
1614 if (!params.opener_suppressed) { | 1618 if (!params.opener_suppressed) { |
1615 if (!is_guest) { | 1619 if (!is_guest) { |
1616 WebContentsView* new_view = new_contents->view_.get(); | 1620 WebContentsView* new_view = new_contents->view_.get(); |
1617 | 1621 |
1618 // TODO(brettw): It seems bogus that we have to call this function on the | 1622 // TODO(brettw): It seems bogus that we have to call this function on the |
1619 // newly created object and give it one of its own member variables. | 1623 // newly created object and give it one of its own member variables. |
1620 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false); | 1624 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false); |
(...skipping 2035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3656 // Put the renderer in view source mode. | 3660 // Put the renderer in view source mode. |
3657 render_view_host->Send( | 3661 render_view_host->Send( |
3658 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); | 3662 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
3659 } | 3663 } |
3660 | 3664 |
3661 view_->RenderViewCreated(render_view_host); | 3665 view_->RenderViewCreated(render_view_host); |
3662 | 3666 |
3663 FOR_EACH_OBSERVER( | 3667 FOR_EACH_OBSERVER( |
3664 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); | 3668 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
3665 | 3669 |
3666 // We tell the observers now instead of when the main RenderFrameHostImpl is | |
3667 // constructed because otherwise it would be too early (i.e. IPCs sent to the | |
3668 // frame would be dropped because it's not created yet). | |
3669 RenderFrameHost* main_frame = render_view_host->GetMainFrame(); | |
3670 FOR_EACH_OBSERVER( | |
3671 WebContentsObserver, observers_, RenderFrameCreated(main_frame)); | |
3672 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame); | |
3673 | |
3674 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host); | 3670 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host); |
3675 } | 3671 } |
3676 | 3672 |
3677 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { | 3673 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
3678 if (rvh != GetRenderViewHost()) { | 3674 if (rvh != GetRenderViewHost()) { |
3679 // Don't notify the world, since this came from a renderer in the | 3675 // Don't notify the world, since this came from a renderer in the |
3680 // background. | 3676 // background. |
3681 return; | 3677 return; |
3682 } | 3678 } |
3683 | 3679 |
(...skipping 13 matching lines...) Expand all Loading... |
3697 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { | 3693 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
3698 view_->Focus(); | 3694 view_->Focus(); |
3699 } | 3695 } |
3700 | 3696 |
3701 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); | 3697 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); |
3702 } | 3698 } |
3703 | 3699 |
3704 void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, | 3700 void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
3705 base::TerminationStatus status, | 3701 base::TerminationStatus status, |
3706 int error_code) { | 3702 int error_code) { |
3707 // TODO(nasko): This isn't ideal; the termination process should be handled by | |
3708 // RenderFrameDeleted(). See http://crbug.com/455943. | |
3709 ClearPowerSaveBlockers(rvh->GetMainFrame()); | |
3710 | |
3711 if (rvh != GetRenderViewHost()) { | 3703 if (rvh != GetRenderViewHost()) { |
3712 // The pending page's RenderViewHost is gone. | 3704 // The pending page's RenderViewHost is gone. |
3713 return; | 3705 return; |
3714 } | 3706 } |
3715 | 3707 |
3716 // Ensure fullscreen mode is exited in the |delegate_| since a crashed | 3708 // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
3717 // renderer may not have made a clean exit. | 3709 // renderer may not have made a clean exit. |
3718 if (IsFullscreenForCurrentTab()) | 3710 if (IsFullscreenForCurrentTab()) |
3719 ExitFullscreenMode(); | 3711 ExitFullscreenMode(); |
3720 | 3712 |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4520 node->render_manager()->ResumeResponseDeferredAtStart(); | 4512 node->render_manager()->ResumeResponseDeferredAtStart(); |
4521 } | 4513 } |
4522 | 4514 |
4523 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4515 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4524 force_disable_overscroll_content_ = force_disable; | 4516 force_disable_overscroll_content_ = force_disable; |
4525 if (view_) | 4517 if (view_) |
4526 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4518 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4527 } | 4519 } |
4528 | 4520 |
4529 } // namespace content | 4521 } // namespace content |
OLD | NEW |