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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 ->render_manager() | 195 ->render_manager() |
196 ->GetRenderWidgetHostView(); | 196 ->GetRenderWidgetHostView(); |
197 set->insert(rwhv); | 197 set->insert(rwhv); |
198 } | 198 } |
199 | 199 |
200 void SetAccessibilityModeOnFrame(AccessibilityMode mode, | 200 void SetAccessibilityModeOnFrame(AccessibilityMode mode, |
201 RenderFrameHost* frame_host) { | 201 RenderFrameHost* frame_host) { |
202 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode); | 202 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode); |
203 } | 203 } |
204 | 204 |
205 // Enable sudden termination for the current RenderFrameHost of | |
206 // |frame_tree_node| if its SiteInstance is |site_instance|. Used with | |
207 // FrameTree::ForEach. | |
208 bool EnableSuddenTermination(scoped_refptr<SiteInstance> site_instance, | |
Charlie Reis
2015/02/03 19:33:15
Again, just a raw pointer is fine here.
clamy
2015/02/04 13:16:19
As explained in the other file, I went with using
| |
209 FrameTreeNode* frame_tree_node) { | |
210 if (frame_tree_node->current_frame_host()->GetSiteInstance() | |
211 == site_instance.get()) { | |
212 frame_tree_node->current_frame_host() | |
213 ->set_override_sudden_termination_status(true); | |
214 } | |
215 return true; | |
216 } | |
217 | |
218 // Returns false and sets |sudden_termination_allowed| to false if sudden | |
219 // termination is not allowed for the current RenderFrameHost of | |
220 // |frame_tree_node| (if its SiteInstance is |site_instance|). Used with | |
221 // FrameTree::ForEach. | |
222 bool SuddenTerminationAllowed(bool* sudden_termination_allowed, | |
223 scoped_refptr<SiteInstance> site_instance, | |
224 FrameTreeNode* frame_tree_node) { | |
225 if (frame_tree_node->current_frame_host()->SuddenTerminationAllowed() || | |
226 frame_tree_node->current_frame_host()->GetSiteInstance() | |
227 != site_instance.get()) { | |
228 return true; | |
229 } | |
230 *sudden_termination_allowed = false; | |
231 return false; | |
232 } | |
233 | |
205 } // namespace | 234 } // namespace |
206 | 235 |
207 WebContents* WebContents::Create(const WebContents::CreateParams& params) { | 236 WebContents* WebContents::Create(const WebContents::CreateParams& params) { |
208 return WebContentsImpl::CreateWithOpener( | 237 return WebContentsImpl::CreateWithOpener( |
209 params, static_cast<WebContentsImpl*>(params.opener)); | 238 params, static_cast<WebContentsImpl*>(params.opener)); |
210 } | 239 } |
211 | 240 |
212 WebContents* WebContents::CreateWithSessionStorage( | 241 WebContents* WebContents::CreateWithSessionStorage( |
213 const WebContents::CreateParams& params, | 242 const WebContents::CreateParams& params, |
214 const SessionStorageNamespaceMap& session_storage_namespace_map) { | 243 const SessionStorageNamespaceMap& session_storage_namespace_map) { |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 if (view_) | 663 if (view_) |
635 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 664 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
636 } | 665 } |
637 } | 666 } |
638 | 667 |
639 RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { | 668 RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { |
640 RenderViewHostImpl* host = GetRenderManager()->current_host(); | 669 RenderViewHostImpl* host = GetRenderManager()->current_host(); |
641 return host ? host->GetProcess() : NULL; | 670 return host ? host->GetProcess() : NULL; |
642 } | 671 } |
643 | 672 |
644 RenderFrameHost* WebContentsImpl::GetMainFrame() { | 673 RenderFrameHostImpl* WebContentsImpl::GetMainFrame() { |
645 return frame_tree_.root()->current_frame_host(); | 674 return frame_tree_.root()->current_frame_host(); |
646 } | 675 } |
647 | 676 |
648 RenderFrameHost* WebContentsImpl::GetFocusedFrame() { | 677 RenderFrameHost* WebContentsImpl::GetFocusedFrame() { |
649 if (!frame_tree_.GetFocusedFrame()) | 678 if (!frame_tree_.GetFocusedFrame()) |
650 return NULL; | 679 return NULL; |
651 return frame_tree_.GetFocusedFrame()->current_frame_host(); | 680 return frame_tree_.GetFocusedFrame()->current_frame_host(); |
652 } | 681 } |
653 | 682 |
654 void WebContentsImpl::ForEachFrame( | 683 void WebContentsImpl::ForEachFrame( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 } | 804 } |
776 | 805 |
777 bool WebContentsImpl::IsFullAccessibilityModeForTesting() const { | 806 bool WebContentsImpl::IsFullAccessibilityModeForTesting() const { |
778 return accessibility_mode_ == AccessibilityModeComplete; | 807 return accessibility_mode_ == AccessibilityModeComplete; |
779 } | 808 } |
780 | 809 |
781 #if defined(OS_WIN) | 810 #if defined(OS_WIN) |
782 void WebContentsImpl::SetParentNativeViewAccessible( | 811 void WebContentsImpl::SetParentNativeViewAccessible( |
783 gfx::NativeViewAccessible accessible_parent) { | 812 gfx::NativeViewAccessible accessible_parent) { |
784 accessible_parent_ = accessible_parent; | 813 accessible_parent_ = accessible_parent; |
785 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); | 814 RenderFrameHostImpl* rfh = GetMainFrame(); |
786 if (rfh) | 815 if (rfh) |
787 rfh->SetParentNativeViewAccessible(accessible_parent); | 816 rfh->SetParentNativeViewAccessible(accessible_parent); |
788 } | 817 } |
789 #endif | 818 #endif |
790 | 819 |
791 const base::string16& WebContentsImpl::GetTitle() const { | 820 const base::string16& WebContentsImpl::GetTitle() const { |
792 // Transient entries take precedence. They are used for interstitial pages | 821 // Transient entries take precedence. They are used for interstitial pages |
793 // that are shown on top of existing pages. | 822 // that are shown on top of existing pages. |
794 NavigationEntry* entry = controller_.GetTransientEntry(); | 823 NavigationEntry* entry = controller_.GetTransientEntry(); |
795 std::string accept_languages = | 824 std::string accept_languages = |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1104 } | 1133 } |
1105 | 1134 |
1106 void WebContentsImpl::WasUnOccluded() { | 1135 void WebContentsImpl::WasUnOccluded() { |
1107 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { | 1136 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
1108 if (view) | 1137 if (view) |
1109 view->WasUnOccluded(); | 1138 view->WasUnOccluded(); |
1110 } | 1139 } |
1111 } | 1140 } |
1112 | 1141 |
1113 bool WebContentsImpl::NeedToFireBeforeUnload() { | 1142 bool WebContentsImpl::NeedToFireBeforeUnload() { |
1143 bool sudden_termination_allowed = true; | |
1144 frame_tree_.ForEach(base::Bind( | |
1145 &SuddenTerminationAllowed, | |
1146 &sudden_termination_allowed, | |
1147 scoped_refptr<SiteInstance>(GetRenderViewHost()->GetSiteInstance()))); | |
1114 // TODO(creis): Should we fire even for interstitial pages? | 1148 // TODO(creis): Should we fire even for interstitial pages? |
1115 return WillNotifyDisconnection() && | 1149 return WillNotifyDisconnection() && |
1116 !ShowingInterstitialPage() && | 1150 !ShowingInterstitialPage() && |
1117 !static_cast<RenderViewHostImpl*>( | 1151 !sudden_termination_allowed; |
1118 GetRenderViewHost())->SuddenTerminationAllowed(); | |
1119 } | 1152 } |
1120 | 1153 |
1121 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { | 1154 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { |
1122 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload( | 1155 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); |
1123 for_cross_site_transition); | |
1124 } | 1156 } |
1125 | 1157 |
1126 void WebContentsImpl::Stop() { | 1158 void WebContentsImpl::Stop() { |
1127 GetRenderManager()->Stop(); | 1159 GetRenderManager()->Stop(); |
1128 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); | 1160 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); |
1129 } | 1161 } |
1130 | 1162 |
1131 WebContents* WebContentsImpl::Clone() { | 1163 WebContents* WebContentsImpl::Clone() { |
1132 // We use our current SiteInstance since the cloned entry will use it anyway. | 1164 // We use our current SiteInstance since the cloned entry will use it anyway. |
1133 // We pass our own opener so that the cloned page can access it if it was | 1165 // We pass our own opener so that the cloned page can access it if it was |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1347 // Notify the delegate if an embedded fullscreen widget was focused. | 1379 // Notify the delegate if an embedded fullscreen widget was focused. |
1348 if (delegate_ && render_widget_host && | 1380 if (delegate_ && render_widget_host && |
1349 delegate_->EmbedsFullscreenWidget() && | 1381 delegate_->EmbedsFullscreenWidget() && |
1350 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) | 1382 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) |
1351 delegate_->WebContentsFocused(this); | 1383 delegate_->WebContentsFocused(this); |
1352 } | 1384 } |
1353 | 1385 |
1354 void WebContentsImpl::RenderWidgetWasResized( | 1386 void WebContentsImpl::RenderWidgetWasResized( |
1355 RenderWidgetHostImpl* render_widget_host, | 1387 RenderWidgetHostImpl* render_widget_host, |
1356 bool width_changed) { | 1388 bool width_changed) { |
1357 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); | 1389 RenderFrameHostImpl* rfh = GetMainFrame(); |
1358 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) | 1390 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) |
1359 return; | 1391 return; |
1360 | 1392 |
1361 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 1393 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
1362 MainFrameWasResized(width_changed)); | 1394 MainFrameWasResized(width_changed)); |
1363 } | 1395 } |
1364 | 1396 |
1365 bool WebContentsImpl::PreHandleKeyboardEvent( | 1397 bool WebContentsImpl::PreHandleKeyboardEvent( |
1366 const NativeWebKeyboardEvent& event, | 1398 const NativeWebKeyboardEvent& event, |
1367 bool* is_keyboard_shortcut) { | 1399 bool* is_keyboard_shortcut) { |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1804 if (BrowserPluginGuest::IsGuest(new_contents)) | 1836 if (BrowserPluginGuest::IsGuest(new_contents)) |
1805 return new_contents; | 1837 return new_contents; |
1806 | 1838 |
1807 if (!new_contents->GetRenderProcessHost()->HasConnection() || | 1839 if (!new_contents->GetRenderProcessHost()->HasConnection() || |
1808 !new_contents->GetRenderViewHost()->GetView()) | 1840 !new_contents->GetRenderViewHost()->GetView()) |
1809 return NULL; | 1841 return NULL; |
1810 | 1842 |
1811 // Resume blocked requests for both the RenderViewHost and RenderFrameHost. | 1843 // Resume blocked requests for both the RenderViewHost and RenderFrameHost. |
1812 // TODO(brettw): It seems bogus to reach into here and initialize the host. | 1844 // TODO(brettw): It seems bogus to reach into here and initialize the host. |
1813 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init(); | 1845 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init(); |
1814 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init(); | 1846 new_contents->GetMainFrame()->Init(); |
1815 | 1847 |
1816 return new_contents; | 1848 return new_contents; |
1817 } | 1849 } |
1818 | 1850 |
1819 RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) { | 1851 RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) { |
1820 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); | 1852 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); |
1821 if (iter == pending_widget_views_.end()) { | 1853 if (iter == pending_widget_views_.end()) { |
1822 DCHECK(false); | 1854 DCHECK(false); |
1823 return NULL; | 1855 return NULL; |
1824 } | 1856 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1921 delegate_->MoveValidationMessage(this, anchor_in_root_view); | 1953 delegate_->MoveValidationMessage(this, anchor_in_root_view); |
1922 } | 1954 } |
1923 | 1955 |
1924 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) { | 1956 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) { |
1925 if (browser_plugin_embedder_) | 1957 if (browser_plugin_embedder_) |
1926 browser_plugin_embedder_->DidSendScreenRects(); | 1958 browser_plugin_embedder_->DidSendScreenRects(); |
1927 } | 1959 } |
1928 | 1960 |
1929 BrowserAccessibilityManager* | 1961 BrowserAccessibilityManager* |
1930 WebContentsImpl::GetRootBrowserAccessibilityManager() { | 1962 WebContentsImpl::GetRootBrowserAccessibilityManager() { |
1931 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); | 1963 RenderFrameHostImpl* rfh = GetMainFrame(); |
1932 return rfh ? rfh->browser_accessibility_manager() : NULL; | 1964 return rfh ? rfh->browser_accessibility_manager() : NULL; |
1933 } | 1965 } |
1934 | 1966 |
1935 BrowserAccessibilityManager* | 1967 BrowserAccessibilityManager* |
1936 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { | 1968 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { |
1937 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); | 1969 RenderFrameHostImpl* rfh = GetMainFrame(); |
1938 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL; | 1970 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL; |
1939 } | 1971 } |
1940 | 1972 |
1941 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { | 1973 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
1942 const gfx::Size old_size = GetPreferredSize(); | 1974 const gfx::Size old_size = GetPreferredSize(); |
1943 preferred_size_ = pref_size; | 1975 preferred_size_ = pref_size; |
1944 OnPreferredSizeChanged(old_size); | 1976 OnPreferredSizeChanged(old_size); |
1945 } | 1977 } |
1946 | 1978 |
1947 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { | 1979 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { |
(...skipping 2107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4055 // Ignore renderer unresponsive event if debugger is attached to the tab | 4087 // Ignore renderer unresponsive event if debugger is attached to the tab |
4056 // since the event may be a result of the renderer sitting on a breakpoint. | 4088 // since the event may be a result of the renderer sitting on a breakpoint. |
4057 // See http://crbug.com/65458 | 4089 // See http://crbug.com/65458 |
4058 if (DevToolsAgentHost::IsDebuggerAttached(this)) | 4090 if (DevToolsAgentHost::IsDebuggerAttached(this)) |
4059 return; | 4091 return; |
4060 | 4092 |
4061 if (rfhi->IsWaitingForBeforeUnloadACK() || | 4093 if (rfhi->IsWaitingForBeforeUnloadACK() || |
4062 rfhi->IsWaitingForUnloadACK()) { | 4094 rfhi->IsWaitingForUnloadACK()) { |
4063 // Hang occurred while firing the beforeunload/unload handler. | 4095 // Hang occurred while firing the beforeunload/unload handler. |
4064 // Pretend the handler fired so tab closing continues as if it had. | 4096 // Pretend the handler fired so tab closing continues as if it had. |
4065 rvhi->set_sudden_termination_allowed(true); | 4097 frame_tree_.ForEach(base::Bind( |
4098 &EnableSuddenTermination, | |
4099 scoped_refptr<SiteInstance>(rvhi->GetSiteInstance()))); | |
Charlie Reis
2015/02/03 19:33:15
No scoped_refptr.
| |
4066 | 4100 |
4067 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) | 4101 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) |
4068 return; | 4102 return; |
4069 | 4103 |
4070 // If the tab hangs in the beforeunload/unload handler there's really | 4104 // If the tab hangs in the beforeunload/unload handler there's really |
4071 // nothing we can do to recover. If the hang is in the beforeunload handler, | 4105 // nothing we can do to recover. If the hang is in the beforeunload handler, |
4072 // pretend the beforeunload listeners have all fired and allow the delegate | 4106 // pretend the beforeunload listeners have all fired and allow the delegate |
4073 // to continue closing; the user will not have the option of cancelling the | 4107 // to continue closing; the user will not have the option of cancelling the |
4074 // close. Otherwise, pretend the unload listeners have all fired and close | 4108 // close. Otherwise, pretend the unload listeners have all fired and close |
4075 // the tab. | 4109 // the tab. |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4483 node->render_manager()->ResumeResponseDeferredAtStart(); | 4517 node->render_manager()->ResumeResponseDeferredAtStart(); |
4484 } | 4518 } |
4485 | 4519 |
4486 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4520 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4487 force_disable_overscroll_content_ = force_disable; | 4521 force_disable_overscroll_content_ = force_disable; |
4488 if (view_) | 4522 if (view_) |
4489 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4523 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4490 } | 4524 } |
4491 | 4525 |
4492 } // namespace content | 4526 } // namespace content |
OLD | NEW |