| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/tab_contents.h" | 5 #include "content/browser/tab_contents/tab_contents.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // pending cross-site request, and then installs a CrossSiteEventHandler. | 107 // pending cross-site request, and then installs a CrossSiteEventHandler. |
| 108 // - When RDH receives a response, the BufferedEventHandler determines whether | 108 // - When RDH receives a response, the BufferedEventHandler determines whether |
| 109 // it is a download. If so, it sends a message to the new renderer causing | 109 // it is a download. If so, it sends a message to the new renderer causing |
| 110 // it to cancel the request, and the download proceeds in the download | 110 // it to cancel the request, and the download proceeds in the download |
| 111 // thread. For now, we stay in a PENDING state (with a pending RVH) until | 111 // thread. For now, we stay in a PENDING state (with a pending RVH) until |
| 112 // the next DidNavigate event for this TabContents. This isn't ideal, but it | 112 // the next DidNavigate event for this TabContents. This isn't ideal, but it |
| 113 // doesn't affect any functionality. | 113 // doesn't affect any functionality. |
| 114 // - After RDH receives a response and determines that it is safe and not a | 114 // - After RDH receives a response and determines that it is safe and not a |
| 115 // download, it pauses the response to first run the old page's onunload | 115 // download, it pauses the response to first run the old page's onunload |
| 116 // handler. It does this by asynchronously calling the OnCrossSiteResponse | 116 // handler. It does this by asynchronously calling the OnCrossSiteResponse |
| 117 // method of TabContents on the UI thread, which sends a ClosePage message | 117 // method of TabContents on the UI thread, which sends a SwapOut message |
| 118 // to the current RVH. | 118 // to the current RVH. |
| 119 // - Once the onunload handler is finished, a ClosePage_ACK message is sent to | 119 // - Once the onunload handler is finished, a SwapOut_ACK message is sent to |
| 120 // the ResourceDispatcherHost, who unpauses the response. Data is then sent | 120 // the ResourceDispatcherHost, who unpauses the response. Data is then sent |
| 121 // to the pending RVH. | 121 // to the pending RVH. |
| 122 // - The pending renderer sends a FrameNavigate message that invokes the | 122 // - The pending renderer sends a FrameNavigate message that invokes the |
| 123 // DidNavigate method. This replaces the current RVH with the | 123 // DidNavigate method. This replaces the current RVH with the |
| 124 // pending RVH and goes back to the NORMAL RendererState. | 124 // pending RVH and goes back to the NORMAL RendererState. |
| 125 // - The previous renderer is kept swapped out in RenderViewHostManager in case |
| 126 // the user goes back. The process only stays live if another tab is using |
| 127 // it, but if so, the existing frame relationships will be maintained. |
| 125 | 128 |
| 126 namespace { | 129 namespace { |
| 127 | 130 |
| 128 // Amount of time we wait between when a key event is received and the renderer | 131 // Amount of time we wait between when a key event is received and the renderer |
| 129 // is queried for its state and pushed to the NavigationEntry. | 132 // is queried for its state and pushed to the NavigationEntry. |
| 130 const int kQueryStateDelay = 5000; | 133 const int kQueryStateDelay = 5000; |
| 131 | 134 |
| 132 const int kSyncWaitDelay = 40; | 135 const int kSyncWaitDelay = 40; |
| 133 | 136 |
| 134 // The list of prefs we want to observe. | 137 // The list of prefs we want to observe. |
| (...skipping 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1799 | 1802 |
| 1800 // Run post-commit tasks. | 1803 // Run post-commit tasks. |
| 1801 if (details.is_main_frame) | 1804 if (details.is_main_frame) |
| 1802 DidNavigateMainFramePostCommit(details, params); | 1805 DidNavigateMainFramePostCommit(details, params); |
| 1803 DidNavigateAnyFramePostCommit(rvh, details, params); | 1806 DidNavigateAnyFramePostCommit(rvh, details, params); |
| 1804 } | 1807 } |
| 1805 | 1808 |
| 1806 void TabContents::UpdateState(RenderViewHost* rvh, | 1809 void TabContents::UpdateState(RenderViewHost* rvh, |
| 1807 int32 page_id, | 1810 int32 page_id, |
| 1808 const std::string& state) { | 1811 const std::string& state) { |
| 1809 DCHECK(rvh == render_view_host()); | 1812 // Ensure that this state update comes from either the active RVH or one of |
| 1813 // the swapped out RVHs. We don't expect to hear from any other RVHs. |
| 1814 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh)); |
| 1810 | 1815 |
| 1811 // We must be prepared to handle state updates for any page, these occur | 1816 // We must be prepared to handle state updates for any page, these occur |
| 1812 // when the user is scrolling and entering form data, as well as when we're | 1817 // when the user is scrolling and entering form data, as well as when we're |
| 1813 // leaving a page, in which case our state may have already been moved to | 1818 // leaving a page, in which case our state may have already been moved to |
| 1814 // the next page. The navigation controller will look up the appropriate | 1819 // the next page. The navigation controller will look up the appropriate |
| 1815 // NavigationEntry and update it when it is notified via the delegate. | 1820 // NavigationEntry and update it when it is notified via the delegate. |
| 1816 | 1821 |
| 1817 int entry_index = controller_.GetEntryIndexWithPageID( | 1822 int entry_index = controller_.GetEntryIndexWithPageID( |
| 1818 GetSiteInstance(), page_id); | 1823 rvh->site_instance(), page_id); |
| 1819 if (entry_index < 0) | 1824 if (entry_index < 0) |
| 1820 return; | 1825 return; |
| 1821 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); | 1826 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); |
| 1822 | 1827 |
| 1823 if (state == entry->content_state()) | 1828 if (state == entry->content_state()) |
| 1824 return; // Nothing to update. | 1829 return; // Nothing to update. |
| 1825 entry->set_content_state(state); | 1830 entry->set_content_state(state); |
| 1826 controller_.NotifyEntryChanged(entry, entry_index); | 1831 controller_.NotifyEntryChanged(entry, entry_index); |
| 1827 } | 1832 } |
| 1828 | 1833 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1970 } | 1975 } |
| 1971 | 1976 |
| 1972 void TabContents::ProcessExternalHostMessage(const std::string& message, | 1977 void TabContents::ProcessExternalHostMessage(const std::string& message, |
| 1973 const std::string& origin, | 1978 const std::string& origin, |
| 1974 const std::string& target) { | 1979 const std::string& target) { |
| 1975 if (delegate()) | 1980 if (delegate()) |
| 1976 delegate()->ForwardMessageToExternalHost(message, origin, target); | 1981 delegate()->ForwardMessageToExternalHost(message, origin, target); |
| 1977 } | 1982 } |
| 1978 | 1983 |
| 1979 void TabContents::RunJavaScriptMessage( | 1984 void TabContents::RunJavaScriptMessage( |
| 1985 const RenderViewHost* rvh, |
| 1980 const std::wstring& message, | 1986 const std::wstring& message, |
| 1981 const std::wstring& default_prompt, | 1987 const std::wstring& default_prompt, |
| 1982 const GURL& frame_url, | 1988 const GURL& frame_url, |
| 1983 const int flags, | 1989 const int flags, |
| 1984 IPC::Message* reply_msg, | 1990 IPC::Message* reply_msg, |
| 1985 bool* did_suppress_message) { | 1991 bool* did_suppress_message) { |
| 1986 // Suppress javascript messages when requested and when inside a constrained | 1992 // Suppress javascript messages when requested and when inside a constrained |
| 1987 // popup window (because that activates them and breaks them out of the | 1993 // popup window (because that activates them and breaks them out of the |
| 1988 // constrained window jail). | 1994 // constrained window jail). |
| 1989 // Also suppress messages when showing an interstitial. The interstitial is | 1995 // Also suppress messages when showing an interstitial. The interstitial is |
| 1990 // shown over the previous page, we don't want the hidden page dialogs to | 1996 // shown over the previous page, we don't want the hidden page dialogs to |
| 1991 // interfere with the interstitial. | 1997 // interfere with the interstitial. |
| 1992 bool suppress_this_message = | 1998 bool suppress_this_message = |
| 1999 rvh->is_swapped_out() || |
| 1993 suppress_javascript_messages_ || | 2000 suppress_javascript_messages_ || |
| 1994 showing_interstitial_page() || | 2001 showing_interstitial_page() || |
| 1995 (delegate() && delegate()->ShouldSuppressDialogs()); | 2002 (delegate() && delegate()->ShouldSuppressDialogs()); |
| 1996 if (delegate()) | 2003 if (delegate()) |
| 1997 suppress_this_message |= | 2004 suppress_this_message |= |
| 1998 (delegate()->GetConstrainingContents(this) != this); | 2005 (delegate()->GetConstrainingContents(this) != this); |
| 1999 | 2006 |
| 2000 *did_suppress_message = suppress_this_message; | 2007 *did_suppress_message = suppress_this_message; |
| 2001 | 2008 |
| 2002 if (!suppress_this_message) { | 2009 if (!suppress_this_message) { |
| 2003 base::TimeDelta time_since_last_message( | 2010 base::TimeDelta time_since_last_message( |
| 2004 base::TimeTicks::Now() - last_javascript_message_dismissal_); | 2011 base::TimeTicks::Now() - last_javascript_message_dismissal_); |
| 2005 bool show_suppress_checkbox = false; | 2012 bool show_suppress_checkbox = false; |
| 2006 // Show a checkbox offering to suppress further messages if this message is | 2013 // Show a checkbox offering to suppress further messages if this message is |
| 2007 // being displayed within kJavascriptMessageExpectedDelay of the last one. | 2014 // being displayed within kJavascriptMessageExpectedDelay of the last one. |
| 2008 if (time_since_last_message < | 2015 if (time_since_last_message < |
| 2009 base::TimeDelta::FromMilliseconds( | 2016 base::TimeDelta::FromMilliseconds( |
| 2010 chrome::kJavascriptMessageExpectedDelay)) | 2017 chrome::kJavascriptMessageExpectedDelay)) |
| 2011 show_suppress_checkbox = true; | 2018 show_suppress_checkbox = true; |
| 2012 | 2019 |
| 2013 RunJavascriptMessageBox(profile(), this, frame_url, flags, message, | 2020 RunJavascriptMessageBox(profile(), this, frame_url, flags, message, |
| 2014 default_prompt, show_suppress_checkbox, reply_msg); | 2021 default_prompt, show_suppress_checkbox, reply_msg); |
| 2015 } else { | 2022 } else { |
| 2016 // If we are suppressing messages, just reply as is if the user immediately | 2023 // If we are suppressing messages, just reply as is if the user immediately |
| 2017 // pressed "Cancel". | 2024 // pressed "Cancel". |
| 2018 OnMessageBoxClosed(reply_msg, false, std::wstring()); | 2025 OnMessageBoxClosed(reply_msg, false, std::wstring()); |
| 2019 } | 2026 } |
| 2020 } | 2027 } |
| 2021 | 2028 |
| 2022 void TabContents::RunBeforeUnloadConfirm(const std::wstring& message, | 2029 void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh, |
| 2030 const std::wstring& message, |
| 2023 IPC::Message* reply_msg) { | 2031 IPC::Message* reply_msg) { |
| 2024 if (delegate()) | 2032 if (delegate()) |
| 2025 delegate()->WillRunBeforeUnloadConfirm(); | 2033 delegate()->WillRunBeforeUnloadConfirm(); |
| 2026 if (delegate() && delegate()->ShouldSuppressDialogs()) { | 2034 bool suppress_this_message = rvh->is_swapped_out() || |
| 2035 (delegate() && delegate()->ShouldSuppressDialogs()); |
| 2036 if (suppress_this_message) { |
| 2027 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, | 2037 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, |
| 2028 std::wstring()); | 2038 std::wstring()); |
| 2029 return; | 2039 return; |
| 2030 } | 2040 } |
| 2031 is_showing_before_unload_dialog_ = true; | 2041 is_showing_before_unload_dialog_ = true; |
| 2032 RunBeforeUnloadDialog(this, message, reply_msg); | 2042 RunBeforeUnloadDialog(this, message, reply_msg); |
| 2033 } | 2043 } |
| 2034 | 2044 |
| 2035 GURL TabContents::GetAlternateErrorPageURL() const { | 2045 GURL TabContents::GetAlternateErrorPageURL() const { |
| 2036 return content::GetContentClient()->browser()->GetAlternateErrorPageURL(this); | 2046 return content::GetContentClient()->browser()->GetAlternateErrorPageURL(this); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 int new_request_id) { | 2090 int new_request_id) { |
| 2081 // Allows the TabContents to react when a cross-site response is ready to be | 2091 // Allows the TabContents to react when a cross-site response is ready to be |
| 2082 // delivered to a pending RenderViewHost. We must first run the onunload | 2092 // delivered to a pending RenderViewHost. We must first run the onunload |
| 2083 // handler of the old RenderViewHost before we can allow it to proceed. | 2093 // handler of the old RenderViewHost before we can allow it to proceed. |
| 2084 render_manager_.OnCrossSiteResponse(new_render_process_host_id, | 2094 render_manager_.OnCrossSiteResponse(new_render_process_host_id, |
| 2085 new_request_id); | 2095 new_request_id); |
| 2086 } | 2096 } |
| 2087 | 2097 |
| 2088 void TabContents::RendererUnresponsive(RenderViewHost* rvh, | 2098 void TabContents::RendererUnresponsive(RenderViewHost* rvh, |
| 2089 bool is_during_unload) { | 2099 bool is_during_unload) { |
| 2100 // Don't show hung renderer dialog for a swapped out RVH. |
| 2101 if (rvh != render_view_host()) |
| 2102 return; |
| 2103 |
| 2090 if (is_during_unload) { | 2104 if (is_during_unload) { |
| 2091 // Hang occurred while firing the beforeunload/unload handler. | 2105 // Hang occurred while firing the beforeunload/unload handler. |
| 2092 // Pretend the handler fired so tab closing continues as if it had. | 2106 // Pretend the handler fired so tab closing continues as if it had. |
| 2093 rvh->set_sudden_termination_allowed(true); | 2107 rvh->set_sudden_termination_allowed(true); |
| 2094 | 2108 |
| 2095 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) | 2109 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) |
| 2096 return; | 2110 return; |
| 2097 | 2111 |
| 2098 // If the tab hangs in the beforeunload/unload handler there's really | 2112 // If the tab hangs in the beforeunload/unload handler there's really |
| 2099 // nothing we can do to recover. Pretend the unload listeners have | 2113 // nothing we can do to recover. Pretend the unload listeners have |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2347 | 2361 |
| 2348 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2362 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2349 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 2363 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 2350 rwh_view->SetSize(view()->GetContainerSize()); | 2364 rwh_view->SetSize(view()->GetContainerSize()); |
| 2351 } | 2365 } |
| 2352 | 2366 |
| 2353 void TabContents::OnOnlineStateChanged(bool online) { | 2367 void TabContents::OnOnlineStateChanged(bool online) { |
| 2354 render_view_host()->Send(new ViewMsg_NetworkStateChanged( | 2368 render_view_host()->Send(new ViewMsg_NetworkStateChanged( |
| 2355 render_view_host()->routing_id(), online)); | 2369 render_view_host()->routing_id(), online)); |
| 2356 } | 2370 } |
| OLD | NEW |