| 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 NOTIFICATION_WEB_CONTENTS_DESTROYED, | 400 NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 401 Source<WebContents>(this), | 401 Source<WebContents>(this), |
| 402 NotificationService::NoDetails()); | 402 NotificationService::NoDetails()); |
| 403 | 403 |
| 404 // Destroy all frame tree nodes except for the root; this notifies observers. | 404 // Destroy all frame tree nodes except for the root; this notifies observers. |
| 405 frame_tree_.ResetForMainFrameSwap(); | 405 frame_tree_.ResetForMainFrameSwap(); |
| 406 GetRenderManager()->ResetProxyHosts(); | 406 GetRenderManager()->ResetProxyHosts(); |
| 407 | 407 |
| 408 // Manually call the observer methods for the root frame tree node. | 408 // Manually call the observer methods for the root frame tree node. |
| 409 RenderFrameHostManager* root = GetRenderManager(); | 409 RenderFrameHostManager* root = GetRenderManager(); |
| 410 if (root->pending_frame_host()) { | 410 |
| 411 FOR_EACH_OBSERVER(WebContentsObserver, | 411 if (root->pending_frame_host()) |
| 412 observers_, | 412 root->pending_frame_host()->SetRenderFrameCreated(false); |
| 413 RenderFrameDeleted(root->pending_frame_host())); | 413 root->current_frame_host()->SetRenderFrameCreated(false); |
| 414 } | |
| 415 FOR_EACH_OBSERVER(WebContentsObserver, | |
| 416 observers_, | |
| 417 RenderFrameDeleted(root->current_frame_host())); | |
| 418 | 414 |
| 419 if (root->pending_render_view_host()) { | 415 if (root->pending_render_view_host()) { |
| 420 FOR_EACH_OBSERVER(WebContentsObserver, | 416 FOR_EACH_OBSERVER(WebContentsObserver, |
| 421 observers_, | 417 observers_, |
| 422 RenderViewDeleted(root->pending_render_view_host())); | 418 RenderViewDeleted(root->pending_render_view_host())); |
| 423 } | 419 } |
| 424 | 420 |
| 425 FOR_EACH_OBSERVER(WebContentsObserver, | 421 FOR_EACH_OBSERVER(WebContentsObserver, |
| 426 observers_, | 422 observers_, |
| 427 RenderViewDeleted(root->current_host())); | 423 RenderViewDeleted(root->current_host())); |
| (...skipping 830 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1576 | 1580 |
| 1577 // Create the new web contents. This will automatically create the new | 1581 // Create the new web contents. This will automatically create the new |
| 1578 // WebContentsView. In the future, we may want to create the view separately. | 1582 // WebContentsView. In the future, we may want to create the view separately. |
| 1579 CreateParams create_params(GetBrowserContext(), site_instance.get()); | 1583 CreateParams create_params(GetBrowserContext(), site_instance.get()); |
| 1580 create_params.routing_id = route_id; | 1584 create_params.routing_id = route_id; |
| 1581 create_params.main_frame_routing_id = main_frame_route_id; | 1585 create_params.main_frame_routing_id = main_frame_route_id; |
| 1582 create_params.opener = this; | 1586 create_params.opener = this; |
| 1583 create_params.opener_suppressed = params.opener_suppressed; | 1587 create_params.opener_suppressed = params.opener_suppressed; |
| 1584 if (params.disposition == NEW_BACKGROUND_TAB) | 1588 if (params.disposition == NEW_BACKGROUND_TAB) |
| 1585 create_params.initially_hidden = true; | 1589 create_params.initially_hidden = true; |
| 1590 create_params.renderer_initiated_creation = true; |
| 1586 | 1591 |
| 1587 WebContentsImpl* new_contents = NULL; | 1592 WebContentsImpl* new_contents = NULL; |
| 1588 if (!is_guest) { | 1593 if (!is_guest) { |
| 1589 create_params.context = view_->GetNativeView(); | 1594 create_params.context = view_->GetNativeView(); |
| 1590 create_params.initial_size = GetContainerBounds().size(); | 1595 create_params.initial_size = GetContainerBounds().size(); |
| 1591 new_contents = static_cast<WebContentsImpl*>( | 1596 new_contents = static_cast<WebContentsImpl*>( |
| 1592 WebContents::Create(create_params)); | 1597 WebContents::Create(create_params)); |
| 1593 } else { | 1598 } else { |
| 1594 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); | 1599 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); |
| 1595 } | 1600 } |
| 1596 new_contents->GetController().SetSessionStorageNamespace( | 1601 new_contents->GetController().SetSessionStorageNamespace( |
| 1597 partition_id, | 1602 partition_id, |
| 1598 session_storage_namespace); | 1603 session_storage_namespace); |
| 1599 new_contents->RenderViewCreated(new_contents->GetRenderViewHost()); | |
| 1600 | 1604 |
| 1601 // Save the window for later if we're not suppressing the opener (since it | 1605 // Save the window for later if we're not suppressing the opener (since it |
| 1602 // will be shown immediately). | 1606 // will be shown immediately). |
| 1603 if (!params.opener_suppressed) { | 1607 if (!params.opener_suppressed) { |
| 1604 if (!is_guest) { | 1608 if (!is_guest) { |
| 1605 WebContentsView* new_view = new_contents->view_.get(); | 1609 WebContentsView* new_view = new_contents->view_.get(); |
| 1606 | 1610 |
| 1607 // TODO(brettw): It seems bogus that we have to call this function on the | 1611 // TODO(brettw): It seems bogus that we have to call this function on the |
| 1608 // newly created object and give it one of its own member variables. | 1612 // newly created object and give it one of its own member variables. |
| 1609 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false); | 1613 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false); |
| (...skipping 2034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3644 // Put the renderer in view source mode. | 3648 // Put the renderer in view source mode. |
| 3645 render_view_host->Send( | 3649 render_view_host->Send( |
| 3646 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); | 3650 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
| 3647 } | 3651 } |
| 3648 | 3652 |
| 3649 view_->RenderViewCreated(render_view_host); | 3653 view_->RenderViewCreated(render_view_host); |
| 3650 | 3654 |
| 3651 FOR_EACH_OBSERVER( | 3655 FOR_EACH_OBSERVER( |
| 3652 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); | 3656 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
| 3653 | 3657 |
| 3654 // We tell the observers now instead of when the main RenderFrameHostImpl is | |
| 3655 // constructed because otherwise it would be too early (i.e. IPCs sent to the | |
| 3656 // frame would be dropped because it's not created yet). | |
| 3657 RenderFrameHost* main_frame = render_view_host->GetMainFrame(); | |
| 3658 FOR_EACH_OBSERVER( | |
| 3659 WebContentsObserver, observers_, RenderFrameCreated(main_frame)); | |
| 3660 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame); | |
| 3661 | |
| 3662 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host); | 3658 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host); |
| 3663 } | 3659 } |
| 3664 | 3660 |
| 3665 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { | 3661 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
| 3666 if (rvh != GetRenderViewHost()) { | 3662 if (rvh != GetRenderViewHost()) { |
| 3667 // Don't notify the world, since this came from a renderer in the | 3663 // Don't notify the world, since this came from a renderer in the |
| 3668 // background. | 3664 // background. |
| 3669 return; | 3665 return; |
| 3670 } | 3666 } |
| 3671 | 3667 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3685 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { | 3681 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
| 3686 view_->Focus(); | 3682 view_->Focus(); |
| 3687 } | 3683 } |
| 3688 | 3684 |
| 3689 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); | 3685 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); |
| 3690 } | 3686 } |
| 3691 | 3687 |
| 3692 void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, | 3688 void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
| 3693 base::TerminationStatus status, | 3689 base::TerminationStatus status, |
| 3694 int error_code) { | 3690 int error_code) { |
| 3695 // TODO(nasko): This isn't ideal; the termination process should be handled by | |
| 3696 // RenderFrameDeleted(). See http://crbug.com/455943. | |
| 3697 ClearPowerSaveBlockers(rvh->GetMainFrame()); | |
| 3698 | |
| 3699 if (rvh != GetRenderViewHost()) { | 3691 if (rvh != GetRenderViewHost()) { |
| 3700 // The pending page's RenderViewHost is gone. | 3692 // The pending page's RenderViewHost is gone. |
| 3701 return; | 3693 return; |
| 3702 } | 3694 } |
| 3703 | 3695 |
| 3704 // Ensure fullscreen mode is exited in the |delegate_| since a crashed | 3696 // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
| 3705 // renderer may not have made a clean exit. | 3697 // renderer may not have made a clean exit. |
| 3706 if (IsFullscreenForCurrentTab()) | 3698 if (IsFullscreenForCurrentTab()) |
| 3707 ExitFullscreenMode(); | 3699 ExitFullscreenMode(); |
| 3708 | 3700 |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4500 node->render_manager()->ResumeResponseDeferredAtStart(); | 4492 node->render_manager()->ResumeResponseDeferredAtStart(); |
| 4501 } | 4493 } |
| 4502 | 4494 |
| 4503 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4495 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4504 force_disable_overscroll_content_ = force_disable; | 4496 force_disable_overscroll_content_ = force_disable; |
| 4505 if (view_) | 4497 if (view_) |
| 4506 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4498 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4507 } | 4499 } |
| 4508 | 4500 |
| 4509 } // namespace content | 4501 } // namespace content |
| OLD | NEW |