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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // whether it is a download. If so, it sends a message to the new renderer | 124 // whether it is a download. If so, it sends a message to the new renderer |
125 // causing it to cancel the request, and the download proceeds. For now, the | 125 // causing it to cancel the request, and the download proceeds. For now, the |
126 // pending RVH remains until the next DidNavigate event for this | 126 // pending RVH remains until the next DidNavigate event for this |
127 // WebContentsImpl. This isn't ideal, but it doesn't affect any functionality. | 127 // WebContentsImpl. This isn't ideal, but it doesn't affect any functionality. |
128 // - After RDH receives a response and determines that it is safe and not a | 128 // - After RDH receives a response and determines that it is safe and not a |
129 // download, the CrossSiteResourceHandler checks whether a process swap is | 129 // download, the CrossSiteResourceHandler checks whether a process swap is |
130 // needed (either because CrossSiteRequestManager has state for it or because | 130 // needed (either because CrossSiteRequestManager has state for it or because |
131 // a transfer was needed for a redirect). | 131 // a transfer was needed for a redirect). |
132 // - If so, CrossSiteResourceHandler pauses the response to first run the old | 132 // - If so, CrossSiteResourceHandler pauses the response to first run the old |
133 // page's unload handler. It does this by asynchronously calling the | 133 // page's unload handler. It does this by asynchronously calling the |
134 // OnCrossSiteResponse method of RenderViewHostManager on the UI thread, which | 134 // OnCrossSiteResponse method of RenderFrameHostManager on the UI thread, |
135 // sends a SwapOut message to the current RVH. | 135 // which sends a SwapOut message to the current RVH. |
136 // - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer | 136 // - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer |
137 // to a new process is needed, based on the stored pending_nav_params_. (This | 137 // to a new process is needed, based on the stored pending_nav_params_. (This |
138 // is independent of whether we started out with a cross-process navigation.) | 138 // is independent of whether we started out with a cross-process navigation.) |
139 // - If not, it just tells the ResourceDispatcherHost to resume the response | 139 // - If not, it just tells the ResourceDispatcherHost to resume the response |
140 // to its current RenderViewHost. | 140 // to its current RenderViewHost. |
141 // - If so, it cancels the current pending RenderViewHost and sets up a new | 141 // - If so, it cancels the current pending RenderViewHost and sets up a new |
142 // navigation using RequestTransferURL. When the transferred request | 142 // navigation using RequestTransferURL. When the transferred request |
143 // arrives in the ResourceDispatcherHost, we transfer the response and | 143 // arrives in the ResourceDispatcherHost, we transfer the response and |
144 // resume it. | 144 // resume it. |
145 // - The pending renderer sends a FrameNavigate message that invokes the | 145 // - The pending renderer sends a FrameNavigate message that invokes the |
146 // DidNavigate method. This replaces the current RVH with the | 146 // DidNavigate method. This replaces the current RVH with the |
147 // pending RVH. | 147 // pending RVH. |
148 // - The previous renderer is kept swapped out in RenderViewHostManager in case | 148 // - The previous renderer is kept swapped out in RenderFrameHostManager in case |
149 // the user goes back. The process only stays live if another tab is using | 149 // the user goes back. The process only stays live if another tab is using |
150 // it, but if so, the existing frame relationships will be maintained. | 150 // it, but if so, the existing frame relationships will be maintained. |
151 | 151 |
152 namespace content { | 152 namespace content { |
153 namespace { | 153 namespace { |
154 | 154 |
155 const char kDotGoogleDotCom[] = ".google.com"; | 155 const char kDotGoogleDotCom[] = ".google.com"; |
156 | 156 |
157 base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > | 157 base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > |
158 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; | 158 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 new_contents->Init(create_params); | 458 new_contents->Init(create_params); |
459 | 459 |
460 // We are instantiating a WebContents for browser plugin. Set its subframe bit | 460 // We are instantiating a WebContents for browser plugin. Set its subframe bit |
461 // to true. | 461 // to true. |
462 static_cast<RenderViewHostImpl*>( | 462 static_cast<RenderViewHostImpl*>( |
463 new_contents->GetRenderViewHost())->set_is_subframe(true); | 463 new_contents->GetRenderViewHost())->set_is_subframe(true); |
464 | 464 |
465 return new_contents->browser_plugin_guest_.get(); | 465 return new_contents->browser_plugin_guest_.get(); |
466 } | 466 } |
467 | 467 |
468 RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() { | 468 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
469 return GetRenderManager(); | 469 return GetRenderManager(); |
470 } | 470 } |
471 | 471 |
472 bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host, | 472 bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host, |
473 const IPC::Message& message) { | 473 const IPC::Message& message) { |
474 if (GetWebUI() && | 474 if (GetWebUI() && |
475 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { | 475 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { |
476 return true; | 476 return true; |
477 } | 477 } |
478 | 478 |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 NOTREACHED(); | 1012 NOTREACHED(); |
1013 } | 1013 } |
1014 } | 1014 } |
1015 | 1015 |
1016 WebContents* WebContentsImpl::GetWebContents() { | 1016 WebContents* WebContentsImpl::GetWebContents() { |
1017 return this; | 1017 return this; |
1018 } | 1018 } |
1019 | 1019 |
1020 void WebContentsImpl::Init(const WebContents::CreateParams& params) { | 1020 void WebContentsImpl::Init(const WebContents::CreateParams& params) { |
1021 // This is set before initializing the render manager since | 1021 // This is set before initializing the render manager since |
1022 // RenderViewHostManager::Init calls back into us via its delegate to ask if | 1022 // RenderFrameHostManager::Init calls back into us via its delegate to ask if |
1023 // it should be hidden. | 1023 // it should be hidden. |
1024 should_normally_be_visible_ = !params.initially_hidden; | 1024 should_normally_be_visible_ = !params.initially_hidden; |
1025 | 1025 |
1026 GetRenderManager()->Init( | 1026 GetRenderManager()->Init( |
1027 params.browser_context, params.site_instance, params.routing_id, | 1027 params.browser_context, params.site_instance, params.routing_id, |
1028 params.main_frame_routing_id); | 1028 params.main_frame_routing_id); |
1029 | 1029 |
1030 view_.reset(GetContentClient()->browser()-> | 1030 view_.reset(GetContentClient()->browser()-> |
1031 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_)); | 1031 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_)); |
1032 if (view_) { | 1032 if (view_) { |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 | 1617 |
1618 // The renderer will reject IPC messages with URLs longer than | 1618 // The renderer will reject IPC messages with URLs longer than |
1619 // this limit, so don't attempt to navigate with a longer URL. | 1619 // this limit, so don't attempt to navigate with a longer URL. |
1620 if (entry.GetURL().spec().size() > kMaxURLChars) { | 1620 if (entry.GetURL().spec().size() > kMaxURLChars) { |
1621 LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars | 1621 LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars |
1622 << " characters."; | 1622 << " characters."; |
1623 return false; | 1623 return false; |
1624 } | 1624 } |
1625 | 1625 |
1626 // TODO(creis): Use entry->frame_tree_node_id() to pick which | 1626 // TODO(creis): Use entry->frame_tree_node_id() to pick which |
1627 // RenderViewHostManager to use. | 1627 // RenderFrameHostManager to use. |
1628 RenderViewHostImpl* dest_render_view_host = | 1628 RenderViewHostImpl* dest_render_view_host = |
1629 static_cast<RenderViewHostImpl*>(GetRenderManager()->Navigate(entry)); | 1629 static_cast<RenderViewHostImpl*>(GetRenderManager()->Navigate(entry)); |
1630 if (!dest_render_view_host) | 1630 if (!dest_render_view_host) |
1631 return false; // Unable to create the desired render view host. | 1631 return false; // Unable to create the desired render view host. |
1632 | 1632 |
1633 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 1633 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
1634 // Double check that here. | 1634 // Double check that here. |
1635 int enabled_bindings = dest_render_view_host->GetEnabledBindings(); | 1635 int enabled_bindings = dest_render_view_host->GetEnabledBindings(); |
1636 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI(); | 1636 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI(); |
1637 bool is_allowed_in_web_ui_renderer = | 1637 bool is_allowed_in_web_ui_renderer = |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2088 if (net::ERR_ABORTED == params.error_code) { | 2088 if (net::ERR_ABORTED == params.error_code) { |
2089 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials. | 2089 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials. |
2090 // This means that the interstitial won't be torn down properly, which is | 2090 // This means that the interstitial won't be torn down properly, which is |
2091 // bad. But if we have an interstitial, go back to another tab type, and | 2091 // bad. But if we have an interstitial, go back to another tab type, and |
2092 // then load the same interstitial again, we could end up getting the first | 2092 // then load the same interstitial again, we could end up getting the first |
2093 // interstitial's "failed" message (as a result of the cancel) when we're on | 2093 // interstitial's "failed" message (as a result of the cancel) when we're on |
2094 // the second one. | 2094 // the second one. |
2095 // | 2095 // |
2096 // We can't tell this apart, so we think we're tearing down the current page | 2096 // We can't tell this apart, so we think we're tearing down the current page |
2097 // which will cause a crash later one. There is also some code in | 2097 // which will cause a crash later one. There is also some code in |
2098 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented | 2098 // RenderFrameHostManager::RendererAbortedProvisionalLoad that is commented |
2099 // out because of this problem. | 2099 // out because of this problem. |
2100 // | 2100 // |
2101 // http://code.google.com/p/chromium/issues/detail?id=2855 | 2101 // http://code.google.com/p/chromium/issues/detail?id=2855 |
2102 // Because this will not tear down the interstitial properly, if "back" is | 2102 // Because this will not tear down the interstitial properly, if "back" is |
2103 // back to another tab type, the interstitial will still be somewhat alive | 2103 // back to another tab type, the interstitial will still be somewhat alive |
2104 // in the previous tab type. If you navigate somewhere that activates the | 2104 // in the previous tab type. If you navigate somewhere that activates the |
2105 // tab with the interstitial again, you'll see a flash before the new load | 2105 // tab with the interstitial again, you'll see a flash before the new load |
2106 // commits of the interstitial page. | 2106 // commits of the interstitial page. |
2107 if (ShowingInterstitialPage()) { | 2107 if (ShowingInterstitialPage()) { |
2108 LOG(WARNING) << "Discarding message during interstitial."; | 2108 LOG(WARNING) << "Discarding message during interstitial."; |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2848 if (frame_tree_.IsFirstNavigationAfterSwap()) { | 2848 if (frame_tree_.IsFirstNavigationAfterSwap()) { |
2849 // First navigation should be a main frame navigation. | 2849 // First navigation should be a main frame navigation. |
2850 DCHECK(PageTransitionIsMainFrame(params.transition)); | 2850 DCHECK(PageTransitionIsMainFrame(params.transition)); |
2851 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id); | 2851 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id); |
2852 } | 2852 } |
2853 | 2853 |
2854 if (PageTransitionIsMainFrame(params.transition)) { | 2854 if (PageTransitionIsMainFrame(params.transition)) { |
2855 // When overscroll navigation gesture is enabled, a screenshot of the page | 2855 // When overscroll navigation gesture is enabled, a screenshot of the page |
2856 // in its current state is taken so that it can be used during the | 2856 // in its current state is taken so that it can be used during the |
2857 // nav-gesture. It is necessary to take the screenshot here, before calling | 2857 // nav-gesture. It is necessary to take the screenshot here, before calling |
2858 // RenderViewHostManager::DidNavigateMainFrame, because that can change | 2858 // RenderFrameHostManager::DidNavigateMainFrame, because that can change |
2859 // WebContents::GetRenderViewHost to return the new host, instead of the one | 2859 // WebContents::GetRenderViewHost to return the new host, instead of the one |
2860 // that may have just been swapped out. | 2860 // that may have just been swapped out. |
2861 if (delegate_ && delegate_->CanOverscrollContent()) | 2861 if (delegate_ && delegate_->CanOverscrollContent()) |
2862 controller_.TakeScreenshot(); | 2862 controller_.TakeScreenshot(); |
2863 | 2863 |
2864 GetRenderManager()->DidNavigateMainFrame(rvh); | 2864 GetRenderManager()->DidNavigateMainFrame(rvh); |
2865 } | 2865 } |
2866 | 2866 |
2867 // Update the site of the SiteInstance if it doesn't have one yet, unless | 2867 // Update the site of the SiteInstance if it doesn't have one yet, unless |
2868 // assigning a site is not necessary for this URL. In that case, the | 2868 // assigning a site is not necessary for this URL. In that case, the |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3636 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh); | 3636 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh); |
3637 // Can be NULL during tests. | 3637 // Can be NULL during tests. |
3638 if (rwh_view) | 3638 if (rwh_view) |
3639 rwh_view->SetSize(GetView()->GetContainerSize()); | 3639 rwh_view->SetSize(GetView()->GetContainerSize()); |
3640 } | 3640 } |
3641 | 3641 |
3642 bool WebContentsImpl::IsHidden() { | 3642 bool WebContentsImpl::IsHidden() { |
3643 return capturer_count_ == 0 && !should_normally_be_visible_; | 3643 return capturer_count_ == 0 && !should_normally_be_visible_; |
3644 } | 3644 } |
3645 | 3645 |
3646 RenderViewHostManager* WebContentsImpl::GetRenderManager() const { | 3646 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
3647 return frame_tree_.root()->render_manager(); | 3647 return frame_tree_.root()->render_manager(); |
3648 } | 3648 } |
3649 | 3649 |
3650 RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() { | 3650 RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() { |
3651 return static_cast<RenderViewHostImpl*>(GetRenderViewHost()); | 3651 return static_cast<RenderViewHostImpl*>(GetRenderViewHost()); |
3652 } | 3652 } |
3653 | 3653 |
3654 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { | 3654 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
3655 return browser_plugin_guest_.get(); | 3655 return browser_plugin_guest_.get(); |
3656 } | 3656 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3694 } | 3694 } |
3695 | 3695 |
3696 void WebContentsImpl::OnFrameRemoved( | 3696 void WebContentsImpl::OnFrameRemoved( |
3697 RenderViewHostImpl* render_view_host, | 3697 RenderViewHostImpl* render_view_host, |
3698 int64 frame_id) { | 3698 int64 frame_id) { |
3699 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3699 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
3700 FrameDetached(render_view_host, frame_id)); | 3700 FrameDetached(render_view_host, frame_id)); |
3701 } | 3701 } |
3702 | 3702 |
3703 } // namespace content | 3703 } // namespace content |
OLD | NEW |