| 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 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 date_time_chooser_.reset(new DateTimeChooserAndroid()); | 1255 date_time_chooser_.reset(new DateTimeChooserAndroid()); |
| 1260 #endif | 1256 #endif |
| 1261 | 1257 |
| 1262 // BrowserPluginGuest::Init needs to be called after this WebContents has | 1258 // BrowserPluginGuest::Init needs to be called after this WebContents has |
| 1263 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. | 1259 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. |
| 1264 if (browser_plugin_guest_) | 1260 if (browser_plugin_guest_) |
| 1265 browser_plugin_guest_->Init(); | 1261 browser_plugin_guest_->Init(); |
| 1266 | 1262 |
| 1267 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 1263 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| 1268 g_created_callbacks.Get().at(i).Run(this); | 1264 g_created_callbacks.Get().at(i).Run(this); |
| 1265 |
| 1266 // If the WebContents creation was renderer-initiated, it means that the |
| 1267 // corresponding RenderView and main RenderFrame have already been created. |
| 1268 // Ensure observers are notified about this. |
| 1269 if (params.renderer_initiated_creation) { |
| 1270 RenderViewCreated(GetRenderViewHost()); |
| 1271 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true); |
| 1272 } |
| 1269 } | 1273 } |
| 1270 | 1274 |
| 1271 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { | 1275 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
| 1272 RemoveDestructionObserver(web_contents); | 1276 RemoveDestructionObserver(web_contents); |
| 1273 | 1277 |
| 1274 // Clear the opener if it has been closed. | 1278 // Clear the opener if it has been closed. |
| 1275 if (web_contents == opener_) { | 1279 if (web_contents == opener_) { |
| 1276 opener_ = NULL; | 1280 opener_ = NULL; |
| 1277 return; | 1281 return; |
| 1278 } | 1282 } |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1577 | 1581 |
| 1578 // Create the new web contents. This will automatically create the new | 1582 // Create the new web contents. This will automatically create the new |
| 1579 // WebContentsView. In the future, we may want to create the view separately. | 1583 // WebContentsView. In the future, we may want to create the view separately. |
| 1580 CreateParams create_params(GetBrowserContext(), site_instance.get()); | 1584 CreateParams create_params(GetBrowserContext(), site_instance.get()); |
| 1581 create_params.routing_id = route_id; | 1585 create_params.routing_id = route_id; |
| 1582 create_params.main_frame_routing_id = main_frame_route_id; | 1586 create_params.main_frame_routing_id = main_frame_route_id; |
| 1583 create_params.opener = this; | 1587 create_params.opener = this; |
| 1584 create_params.opener_suppressed = params.opener_suppressed; | 1588 create_params.opener_suppressed = params.opener_suppressed; |
| 1585 if (params.disposition == NEW_BACKGROUND_TAB) | 1589 if (params.disposition == NEW_BACKGROUND_TAB) |
| 1586 create_params.initially_hidden = true; | 1590 create_params.initially_hidden = true; |
| 1591 create_params.renderer_initiated_creation = true; |
| 1587 | 1592 |
| 1588 WebContentsImpl* new_contents = NULL; | 1593 WebContentsImpl* new_contents = NULL; |
| 1589 if (!is_guest) { | 1594 if (!is_guest) { |
| 1590 create_params.context = view_->GetNativeView(); | 1595 create_params.context = view_->GetNativeView(); |
| 1591 create_params.initial_size = GetContainerBounds().size(); | 1596 create_params.initial_size = GetContainerBounds().size(); |
| 1592 new_contents = static_cast<WebContentsImpl*>( | 1597 new_contents = static_cast<WebContentsImpl*>( |
| 1593 WebContents::Create(create_params)); | 1598 WebContents::Create(create_params)); |
| 1594 } else { | 1599 } else { |
| 1595 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); | 1600 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); |
| 1596 } | 1601 } |
| 1597 new_contents->GetController().SetSessionStorageNamespace( | 1602 new_contents->GetController().SetSessionStorageNamespace( |
| 1598 partition_id, | 1603 partition_id, |
| 1599 session_storage_namespace); | 1604 session_storage_namespace); |
| 1600 new_contents->RenderViewCreated(new_contents->GetRenderViewHost()); | |
| 1601 | 1605 |
| 1602 // Save the window for later if we're not suppressing the opener (since it | 1606 // Save the window for later if we're not suppressing the opener (since it |
| 1603 // will be shown immediately). | 1607 // will be shown immediately). |
| 1604 if (!params.opener_suppressed) { | 1608 if (!params.opener_suppressed) { |
| 1605 if (!is_guest) { | 1609 if (!is_guest) { |
| 1606 WebContentsView* new_view = new_contents->view_.get(); | 1610 WebContentsView* new_view = new_contents->view_.get(); |
| 1607 | 1611 |
| 1608 // TODO(brettw): It seems bogus that we have to call this function on the | 1612 // 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. | 1613 // newly created object and give it one of its own member variables. |
| 1610 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false); | 1614 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. | 3646 // Put the renderer in view source mode. |
| 3643 render_view_host->Send( | 3647 render_view_host->Send( |
| 3644 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); | 3648 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
| 3645 } | 3649 } |
| 3646 | 3650 |
| 3647 view_->RenderViewCreated(render_view_host); | 3651 view_->RenderViewCreated(render_view_host); |
| 3648 | 3652 |
| 3649 FOR_EACH_OBSERVER( | 3653 FOR_EACH_OBSERVER( |
| 3650 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); | 3654 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
| 3651 | 3655 |
| 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); | |
| 3659 | |
| 3660 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host); | 3656 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host); |
| 3661 } | 3657 } |
| 3662 | 3658 |
| 3663 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { | 3659 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
| 3664 if (rvh != GetRenderViewHost()) { | 3660 if (rvh != GetRenderViewHost()) { |
| 3665 // Don't notify the world, since this came from a renderer in the | 3661 // Don't notify the world, since this came from a renderer in the |
| 3666 // background. | 3662 // background. |
| 3667 return; | 3663 return; |
| 3668 } | 3664 } |
| 3669 | 3665 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3683 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { | 3679 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
| 3684 view_->Focus(); | 3680 view_->Focus(); |
| 3685 } | 3681 } |
| 3686 | 3682 |
| 3687 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); | 3683 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); |
| 3688 } | 3684 } |
| 3689 | 3685 |
| 3690 void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, | 3686 void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
| 3691 base::TerminationStatus status, | 3687 base::TerminationStatus status, |
| 3692 int error_code) { | 3688 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()); | |
| 3696 | |
| 3697 if (rvh != GetRenderViewHost()) { | 3689 if (rvh != GetRenderViewHost()) { |
| 3698 // The pending page's RenderViewHost is gone. | 3690 // The pending page's RenderViewHost is gone. |
| 3699 return; | 3691 return; |
| 3700 } | 3692 } |
| 3701 | 3693 |
| 3702 // Ensure fullscreen mode is exited in the |delegate_| since a crashed | 3694 // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
| 3703 // renderer may not have made a clean exit. | 3695 // renderer may not have made a clean exit. |
| 3704 if (IsFullscreenForCurrentTab()) | 3696 if (IsFullscreenForCurrentTab()) |
| 3705 ExitFullscreenMode(); | 3697 ExitFullscreenMode(); |
| 3706 | 3698 |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4509 node->render_manager()->ResumeResponseDeferredAtStart(); | 4501 node->render_manager()->ResumeResponseDeferredAtStart(); |
| 4510 } | 4502 } |
| 4511 | 4503 |
| 4512 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4504 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4513 force_disable_overscroll_content_ = force_disable; | 4505 force_disable_overscroll_content_ = force_disable; |
| 4514 if (view_) | 4506 if (view_) |
| 4515 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4507 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4516 } | 4508 } |
| 4517 | 4509 |
| 4518 } // namespace content | 4510 } // namespace content |
| OLD | NEW |