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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 ->render_manager() | 229 ->render_manager() |
230 ->GetRenderWidgetHostView(); | 230 ->GetRenderWidgetHostView(); |
231 set->insert(rwhv); | 231 set->insert(rwhv); |
232 } | 232 } |
233 | 233 |
234 void SetAccessibilityModeOnFrame(AccessibilityMode mode, | 234 void SetAccessibilityModeOnFrame(AccessibilityMode mode, |
235 RenderFrameHost* frame_host) { | 235 RenderFrameHost* frame_host) { |
236 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode); | 236 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode); |
237 } | 237 } |
238 | 238 |
239 // Enable sudden termination for the current RenderFrameHost of | |
240 // |frame_tree_node| if the ID of its SiteInstance is |site_instance_id|. Used | |
241 // with FrameTree::ForEach. | |
242 bool EnableSuddenTermination(int32 site_instance_id, | |
243 FrameTreeNode* frame_tree_node) { | |
244 if (frame_tree_node->current_frame_host()->GetSiteInstance()->GetId() | |
245 == site_instance_id) { | |
246 frame_tree_node->current_frame_host() | |
247 ->set_override_sudden_termination_status(true); | |
248 } | |
249 return true; | |
250 } | |
251 | |
252 // Returns false and sets |sudden_termination_allowed| to false if sudden | |
253 // termination is not allowed for the current RenderFrameHost of | |
254 // |frame_tree_node|. Used with FrameTree::ForEach. | |
255 bool SuddenTerminationAllowed(bool* sudden_termination_allowed, | |
256 FrameTreeNode* frame_tree_node) { | |
257 if (frame_tree_node->current_frame_host()->SuddenTerminationAllowed()) | |
258 return true; | |
259 *sudden_termination_allowed = false; | |
260 return false; | |
261 } | |
262 | |
263 // Returns true if at least one of the nodes in the |frame_tree| is loading. | 239 // Returns true if at least one of the nodes in the |frame_tree| is loading. |
264 bool IsFrameTreeLoading(FrameTree& frame_tree) { | 240 bool IsFrameTreeLoading(FrameTree& frame_tree) { |
265 bool is_loading = false; | 241 bool is_loading = false; |
266 frame_tree.ForEach(base::Bind(&IsNodeLoading, &is_loading)); | 242 frame_tree.ForEach(base::Bind(&IsNodeLoading, &is_loading)); |
267 return is_loading; | 243 return is_loading; |
268 } | 244 } |
269 | 245 |
270 } // namespace | 246 } // namespace |
271 | 247 |
272 WebContents* WebContents::Create(const WebContents::CreateParams& params) { | 248 WebContents* WebContents::Create(const WebContents::CreateParams& params) { |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 } | 824 } |
849 | 825 |
850 bool WebContentsImpl::IsFullAccessibilityModeForTesting() const { | 826 bool WebContentsImpl::IsFullAccessibilityModeForTesting() const { |
851 return accessibility_mode_ == AccessibilityModeComplete; | 827 return accessibility_mode_ == AccessibilityModeComplete; |
852 } | 828 } |
853 | 829 |
854 #if defined(OS_WIN) | 830 #if defined(OS_WIN) |
855 void WebContentsImpl::SetParentNativeViewAccessible( | 831 void WebContentsImpl::SetParentNativeViewAccessible( |
856 gfx::NativeViewAccessible accessible_parent) { | 832 gfx::NativeViewAccessible accessible_parent) { |
857 accessible_parent_ = accessible_parent; | 833 accessible_parent_ = accessible_parent; |
858 RenderFrameHostImpl* rfh = GetMainFrame(); | 834 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); |
859 if (rfh) | 835 if (rfh) |
860 rfh->SetParentNativeViewAccessible(accessible_parent); | 836 rfh->SetParentNativeViewAccessible(accessible_parent); |
861 } | 837 } |
862 #endif | 838 #endif |
863 | 839 |
864 const base::string16& WebContentsImpl::GetTitle() const { | 840 const base::string16& WebContentsImpl::GetTitle() const { |
865 // Transient entries take precedence. They are used for interstitial pages | 841 // Transient entries take precedence. They are used for interstitial pages |
866 // that are shown on top of existing pages. | 842 // that are shown on top of existing pages. |
867 NavigationEntry* entry = controller_.GetTransientEntry(); | 843 NavigationEntry* entry = controller_.GetTransientEntry(); |
868 std::string accept_languages = | 844 std::string accept_languages = |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 } | 1158 } |
1183 | 1159 |
1184 void WebContentsImpl::WasUnOccluded() { | 1160 void WebContentsImpl::WasUnOccluded() { |
1185 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { | 1161 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
1186 if (view) | 1162 if (view) |
1187 view->WasUnOccluded(); | 1163 view->WasUnOccluded(); |
1188 } | 1164 } |
1189 } | 1165 } |
1190 | 1166 |
1191 bool WebContentsImpl::NeedToFireBeforeUnload() { | 1167 bool WebContentsImpl::NeedToFireBeforeUnload() { |
1192 bool sudden_termination_allowed = true; | |
1193 frame_tree_.ForEach(base::Bind( | |
1194 &SuddenTerminationAllowed, &sudden_termination_allowed)); | |
1195 // TODO(creis): Should we fire even for interstitial pages? | 1168 // TODO(creis): Should we fire even for interstitial pages? |
1196 return WillNotifyDisconnection() && | 1169 return WillNotifyDisconnection() && |
1197 !ShowingInterstitialPage() && | 1170 !ShowingInterstitialPage() && |
1198 !sudden_termination_allowed; | 1171 !static_cast<RenderViewHostImpl*>( |
| 1172 GetRenderViewHost())->SuddenTerminationAllowed(); |
1199 } | 1173 } |
1200 | 1174 |
1201 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { | 1175 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { |
1202 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); | 1176 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload( |
| 1177 for_cross_site_transition); |
1203 } | 1178 } |
1204 | 1179 |
1205 void WebContentsImpl::Stop() { | 1180 void WebContentsImpl::Stop() { |
1206 GetRenderManager()->Stop(); | 1181 GetRenderManager()->Stop(); |
1207 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); | 1182 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); |
1208 } | 1183 } |
1209 | 1184 |
1210 WebContents* WebContentsImpl::Clone() { | 1185 WebContents* WebContentsImpl::Clone() { |
1211 // We use our current SiteInstance since the cloned entry will use it anyway. | 1186 // We use our current SiteInstance since the cloned entry will use it anyway. |
1212 // We pass our own opener so that the cloned page can access it if it was | 1187 // We pass our own opener so that the cloned page can access it if it was |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 // Notify the delegate if an embedded fullscreen widget was focused. | 1416 // Notify the delegate if an embedded fullscreen widget was focused. |
1442 if (delegate_ && render_widget_host && | 1417 if (delegate_ && render_widget_host && |
1443 delegate_->EmbedsFullscreenWidget() && | 1418 delegate_->EmbedsFullscreenWidget() && |
1444 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) | 1419 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) |
1445 delegate_->WebContentsFocused(this); | 1420 delegate_->WebContentsFocused(this); |
1446 } | 1421 } |
1447 | 1422 |
1448 void WebContentsImpl::RenderWidgetWasResized( | 1423 void WebContentsImpl::RenderWidgetWasResized( |
1449 RenderWidgetHostImpl* render_widget_host, | 1424 RenderWidgetHostImpl* render_widget_host, |
1450 bool width_changed) { | 1425 bool width_changed) { |
1451 RenderFrameHostImpl* rfh = GetMainFrame(); | 1426 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); |
1452 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) | 1427 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) |
1453 return; | 1428 return; |
1454 | 1429 |
1455 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 1430 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
1456 MainFrameWasResized(width_changed)); | 1431 MainFrameWasResized(width_changed)); |
1457 } | 1432 } |
1458 | 1433 |
1459 void WebContentsImpl::ScreenInfoChanged() { | 1434 void WebContentsImpl::ScreenInfoChanged() { |
1460 if (browser_plugin_embedder_) | 1435 if (browser_plugin_embedder_) |
1461 browser_plugin_embedder_->ScreenInfoChanged(); | 1436 browser_plugin_embedder_->ScreenInfoChanged(); |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 if (BrowserPluginGuest::IsGuest(new_contents)) | 1849 if (BrowserPluginGuest::IsGuest(new_contents)) |
1875 return new_contents; | 1850 return new_contents; |
1876 | 1851 |
1877 if (!new_contents->GetRenderProcessHost()->HasConnection() || | 1852 if (!new_contents->GetRenderProcessHost()->HasConnection() || |
1878 !new_contents->GetRenderViewHost()->GetView()) | 1853 !new_contents->GetRenderViewHost()->GetView()) |
1879 return NULL; | 1854 return NULL; |
1880 | 1855 |
1881 // Resume blocked requests for both the RenderViewHost and RenderFrameHost. | 1856 // Resume blocked requests for both the RenderViewHost and RenderFrameHost. |
1882 // TODO(brettw): It seems bogus to reach into here and initialize the host. | 1857 // TODO(brettw): It seems bogus to reach into here and initialize the host. |
1883 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init(); | 1858 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init(); |
1884 new_contents->GetMainFrame()->Init(); | 1859 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init(); |
1885 | 1860 |
1886 return new_contents; | 1861 return new_contents; |
1887 } | 1862 } |
1888 | 1863 |
1889 RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) { | 1864 RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) { |
1890 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); | 1865 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); |
1891 if (iter == pending_widget_views_.end()) { | 1866 if (iter == pending_widget_views_.end()) { |
1892 DCHECK(false); | 1867 DCHECK(false); |
1893 return NULL; | 1868 return NULL; |
1894 } | 1869 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 delegate_->MoveValidationMessage(this, anchor_in_root_view); | 1967 delegate_->MoveValidationMessage(this, anchor_in_root_view); |
1993 } | 1968 } |
1994 | 1969 |
1995 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) { | 1970 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) { |
1996 if (browser_plugin_embedder_) | 1971 if (browser_plugin_embedder_) |
1997 browser_plugin_embedder_->DidSendScreenRects(); | 1972 browser_plugin_embedder_->DidSendScreenRects(); |
1998 } | 1973 } |
1999 | 1974 |
2000 BrowserAccessibilityManager* | 1975 BrowserAccessibilityManager* |
2001 WebContentsImpl::GetRootBrowserAccessibilityManager() { | 1976 WebContentsImpl::GetRootBrowserAccessibilityManager() { |
2002 RenderFrameHostImpl* rfh = GetMainFrame(); | 1977 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); |
2003 return rfh ? rfh->browser_accessibility_manager() : NULL; | 1978 return rfh ? rfh->browser_accessibility_manager() : NULL; |
2004 } | 1979 } |
2005 | 1980 |
2006 BrowserAccessibilityManager* | 1981 BrowserAccessibilityManager* |
2007 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { | 1982 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { |
2008 RenderFrameHostImpl* rfh = GetMainFrame(); | 1983 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); |
2009 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL; | 1984 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL; |
2010 } | 1985 } |
2011 | 1986 |
2012 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { | 1987 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
2013 const gfx::Size old_size = GetPreferredSize(); | 1988 const gfx::Size old_size = GetPreferredSize(); |
2014 preferred_size_ = pref_size; | 1989 preferred_size_ = pref_size; |
2015 OnPreferredSizeChanged(old_size); | 1990 OnPreferredSizeChanged(old_size); |
2016 } | 1991 } |
2017 | 1992 |
2018 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { | 1993 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { |
(...skipping 2183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4202 // Ignore renderer unresponsive event if debugger is attached to the tab | 4177 // Ignore renderer unresponsive event if debugger is attached to the tab |
4203 // since the event may be a result of the renderer sitting on a breakpoint. | 4178 // since the event may be a result of the renderer sitting on a breakpoint. |
4204 // See http://crbug.com/65458 | 4179 // See http://crbug.com/65458 |
4205 if (DevToolsAgentHost::IsDebuggerAttached(this)) | 4180 if (DevToolsAgentHost::IsDebuggerAttached(this)) |
4206 return; | 4181 return; |
4207 | 4182 |
4208 if (rfhi->IsWaitingForBeforeUnloadACK() || | 4183 if (rfhi->IsWaitingForBeforeUnloadACK() || |
4209 rfhi->IsWaitingForUnloadACK()) { | 4184 rfhi->IsWaitingForUnloadACK()) { |
4210 // Hang occurred while firing the beforeunload/unload handler. | 4185 // Hang occurred while firing the beforeunload/unload handler. |
4211 // Pretend the handler fired so tab closing continues as if it had. | 4186 // Pretend the handler fired so tab closing continues as if it had. |
4212 frame_tree_.ForEach(base::Bind( | 4187 rvhi->set_sudden_termination_allowed(true); |
4213 &EnableSuddenTermination, rvhi->GetSiteInstance()->GetId())); | |
4214 | 4188 |
4215 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) | 4189 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) |
4216 return; | 4190 return; |
4217 | 4191 |
4218 // If the tab hangs in the beforeunload/unload handler there's really | 4192 // If the tab hangs in the beforeunload/unload handler there's really |
4219 // nothing we can do to recover. If the hang is in the beforeunload handler, | 4193 // nothing we can do to recover. If the hang is in the beforeunload handler, |
4220 // pretend the beforeunload listeners have all fired and allow the delegate | 4194 // pretend the beforeunload listeners have all fired and allow the delegate |
4221 // to continue closing; the user will not have the option of cancelling the | 4195 // to continue closing; the user will not have the option of cancelling the |
4222 // close. Otherwise, pretend the unload listeners have all fired and close | 4196 // close. Otherwise, pretend the unload listeners have all fired and close |
4223 // the tab. | 4197 // the tab. |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4648 node->render_manager()->ResumeResponseDeferredAtStart(); | 4622 node->render_manager()->ResumeResponseDeferredAtStart(); |
4649 } | 4623 } |
4650 | 4624 |
4651 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4625 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4652 force_disable_overscroll_content_ = force_disable; | 4626 force_disable_overscroll_content_ = force_disable; |
4653 if (view_) | 4627 if (view_) |
4654 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4628 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4655 } | 4629 } |
4656 | 4630 |
4657 } // namespace content | 4631 } // namespace content |
OLD | NEW |