Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: content/browser/tab_contents/tab_contents.cc

Issue 6319001: Support window.opener after a process swap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add WasSwappedOut message for clean exit. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // pending cross-site request, and then installs a CrossSiteEventHandler. 115 // pending cross-site request, and then installs a CrossSiteEventHandler.
116 // - When RDH receives a response, the BufferedEventHandler determines whether 116 // - When RDH receives a response, the BufferedEventHandler determines whether
117 // it is a download. If so, it sends a message to the new renderer causing 117 // it is a download. If so, it sends a message to the new renderer causing
118 // it to cancel the request, and the download proceeds in the download 118 // it to cancel the request, and the download proceeds in the download
119 // thread. For now, we stay in a PENDING state (with a pending RVH) until 119 // thread. For now, we stay in a PENDING state (with a pending RVH) until
120 // the next DidNavigate event for this TabContents. This isn't ideal, but it 120 // the next DidNavigate event for this TabContents. This isn't ideal, but it
121 // doesn't affect any functionality. 121 // doesn't affect any functionality.
122 // - After RDH receives a response and determines that it is safe and not a 122 // - After RDH receives a response and determines that it is safe and not a
123 // download, it pauses the response to first run the old page's onunload 123 // download, it pauses the response to first run the old page's onunload
124 // handler. It does this by asynchronously calling the OnCrossSiteResponse 124 // handler. It does this by asynchronously calling the OnCrossSiteResponse
125 // method of TabContents on the UI thread, which sends a ClosePage message 125 // method of TabContents on the UI thread, which sends a SwapOut message
126 // to the current RVH. 126 // to the current RVH.
127 // - Once the onunload handler is finished, a ClosePage_ACK message is sent to 127 // - Once the onunload handler is finished, a SwapOut_ACK message is sent to
128 // the ResourceDispatcherHost, who unpauses the response. Data is then sent 128 // the ResourceDispatcherHost, who unpauses the response. Data is then sent
129 // to the pending RVH. 129 // to the pending RVH.
130 // - The pending renderer sends a FrameNavigate message that invokes the 130 // - The pending renderer sends a FrameNavigate message that invokes the
131 // DidNavigate method. This replaces the current RVH with the 131 // DidNavigate method. This replaces the current RVH with the
132 // pending RVH and goes back to the NORMAL RendererState. 132 // pending RVH and goes back to the NORMAL RendererState.
133 // - The previous renderer is kept swapped out in RenderViewHostManager in case
134 // the user goes back. The process only stays live if another tab is using
135 // it, but if so, the existing frame relationships will be maintained.
133 136
134 namespace { 137 namespace {
135 138
136 // Amount of time we wait between when a key event is received and the renderer 139 // Amount of time we wait between when a key event is received and the renderer
137 // is queried for its state and pushed to the NavigationEntry. 140 // is queried for its state and pushed to the NavigationEntry.
138 const int kQueryStateDelay = 5000; 141 const int kQueryStateDelay = 5000;
139 142
140 const int kSyncWaitDelay = 40; 143 const int kSyncWaitDelay = 40;
141 144
142 // The list of prefs we want to observe. 145 // The list of prefs we want to observe.
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 bool TabContents::OnMessageReceived(const IPC::Message& message) { 380 bool TabContents::OnMessageReceived(const IPC::Message& message) {
378 ObserverListBase<TabContentsObserver>::Iterator it(observers_); 381 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
379 TabContentsObserver* observer; 382 TabContentsObserver* observer;
380 while ((observer = it.GetNext()) != NULL) 383 while ((observer = it.GetNext()) != NULL)
381 if (observer->OnMessageReceived(message)) 384 if (observer->OnMessageReceived(message))
382 return true; 385 return true;
383 386
384 bool handled = true; 387 bool handled = true;
385 bool message_is_ok = true; 388 bool message_is_ok = true;
386 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok) 389 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
387 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
388 OnDidStartProvisionalLoadForFrame)
389 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
390 OnDidRedirectProvisionalLoad)
391 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
392 OnDidFailProvisionalLoadWithError)
393 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
394 OnDidLoadResourceFromMemoryCache)
395 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
396 OnDidDisplayInsecureContent)
397 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
398 OnDidRunInsecureContent)
399 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
400 OnDocumentLoadedInFrame)
401 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
402 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
403 OnUpdateContentRestrictions)
404 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature, 390 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
405 OnPDFHasUnsupportedFeature) 391 OnPDFHasUnsupportedFeature)
406 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) 392 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
407 IPC_MESSAGE_UNHANDLED(handled = false) 393 IPC_MESSAGE_UNHANDLED(handled = false)
408 IPC_END_MESSAGE_MAP_EX() 394 IPC_END_MESSAGE_MAP_EX()
409 395
410 if (!message_is_ok) { 396 if (!message_is_ok) {
411 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); 397 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
412 GetRenderProcessHost()->ReceivedBadMessage(); 398 GetRenderProcessHost()->ReceivedBadMessage();
413 } 399 }
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 return; 1120 return;
1135 1121
1136 delegate_->ViewSourceForFrame(this, url, content_state); 1122 delegate_->ViewSourceForFrame(this, url, content_state);
1137 } 1123 }
1138 1124
1139 void TabContents::SetContentRestrictions(int restrictions) { 1125 void TabContents::SetContentRestrictions(int restrictions) {
1140 content_restrictions_ = restrictions; 1126 content_restrictions_ = restrictions;
1141 delegate()->ContentRestrictionsChanged(this); 1127 delegate()->ContentRestrictionsChanged(this);
1142 } 1128 }
1143 1129
1144 void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, 1130 void TabContents::DidStartProvisionalLoadForFrame(int64 frame_id,
1145 bool is_main_frame, 1131 bool is_main_frame,
1146 const GURL& url) { 1132 const GURL& url) {
1147 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL); 1133 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1148 GURL validated_url(url); 1134 GURL validated_url(url);
1149 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(), 1135 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1150 GetRenderProcessHost()->id(), &validated_url); 1136 GetRenderProcessHost()->id(), &validated_url);
1151 1137
1152 // Notify observers about the start of the provisional load. 1138 // Notify observers about the start of the provisional load.
1153 FOR_EACH_OBSERVER(TabContentsObserver, observers_, 1139 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1154 DidStartProvisionalLoadForFrame(frame_id, is_main_frame, 1140 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
1155 validated_url, is_error_page)); 1141 validated_url, is_error_page));
1156 1142
1157 if (is_main_frame) { 1143 if (is_main_frame) {
1158 // If we're displaying a network error page do not reset the content 1144 // If we're displaying a network error page do not reset the content
1159 // settings delegate's cookies so the user has a chance to modify cookie 1145 // settings delegate's cookies so the user has a chance to modify cookie
1160 // settings. 1146 // settings.
1161 if (!is_error_page) 1147 if (!is_error_page)
1162 content_settings_delegate_->ClearCookieSpecificContentSettings(); 1148 content_settings_delegate_->ClearCookieSpecificContentSettings();
1163 content_settings_delegate_->ClearGeolocationContentSettings(); 1149 content_settings_delegate_->ClearGeolocationContentSettings();
1164 1150
1165 // Notify observers about the provisional change in the main frame URL. 1151 // Notify observers about the provisional change in the main frame URL.
1166 FOR_EACH_OBSERVER(TabContentsObserver, observers_, 1152 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1167 ProvisionalChangeToMainFrameUrl(url)); 1153 ProvisionalChangeToMainFrameUrl(url));
1168 } 1154 }
1169 } 1155 }
1170 1156
1171 void TabContents::OnDidRedirectProvisionalLoad(int32 page_id, 1157 void TabContents::DidRedirectProvisionalLoad(int32 page_id,
1172 const GURL& source_url, 1158 const GURL& source_url,
1173 const GURL& target_url) { 1159 const GURL& target_url) {
1174 // TODO(creis): Remove this method and have the pre-rendering code listen to 1160 // TODO(creis): Remove this method and have the pre-rendering code listen to
1175 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification 1161 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1176 // instead. See http://crbug.com/78512. 1162 // instead. See http://crbug.com/78512.
1177 NavigationEntry* entry; 1163 NavigationEntry* entry;
1178 if (page_id == -1) 1164 if (page_id == -1)
1179 entry = controller_.pending_entry(); 1165 entry = controller_.pending_entry();
1180 else 1166 else
1181 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id); 1167 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1182 if (!entry || entry->url() != source_url) 1168 if (!entry || entry->url() != source_url)
1183 return; 1169 return;
1184 1170
1185 // Notify observers about the provisional change in the main frame URL. 1171 // Notify observers about the provisional change in the main frame URL.
1186 FOR_EACH_OBSERVER(TabContentsObserver, observers_, 1172 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1187 ProvisionalChangeToMainFrameUrl(target_url)); 1173 ProvisionalChangeToMainFrameUrl(target_url));
1188 } 1174 }
1189 1175
1190 void TabContents::OnDidFailProvisionalLoadWithError( 1176 void TabContents::DidFailProvisionalLoadWithError(
1191 int64 frame_id, 1177 int64 frame_id,
1192 bool is_main_frame, 1178 bool is_main_frame,
1193 int error_code, 1179 int error_code,
1194 const GURL& url, 1180 const GURL& url,
1195 bool showing_repost_interstitial) { 1181 bool showing_repost_interstitial) {
1196 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec() 1182 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1197 << ", error_code: " << error_code 1183 << ", error_code: " << error_code
1198 << " is_main_frame: " << is_main_frame 1184 << " is_main_frame: " << is_main_frame
1199 << " showing_repost_interstitial: " << showing_repost_interstitial 1185 << " showing_repost_interstitial: " << showing_repost_interstitial
1200 << " frame_id: " << frame_id; 1186 << " frame_id: " << frame_id;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 NotificationService::current()->Notify( 1235 NotificationService::current()->Notify(
1250 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, 1236 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1251 Source<NavigationController>(&controller_), 1237 Source<NavigationController>(&controller_),
1252 Details<ProvisionalLoadDetails>(&details)); 1238 Details<ProvisionalLoadDetails>(&details));
1253 1239
1254 FOR_EACH_OBSERVER(TabContentsObserver, observers_, 1240 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1255 DidFailProvisionalLoad(frame_id, is_main_frame, 1241 DidFailProvisionalLoad(frame_id, is_main_frame,
1256 validated_url, error_code)); 1242 validated_url, error_code));
1257 } 1243 }
1258 1244
1259 void TabContents::OnDidLoadResourceFromMemoryCache( 1245 void TabContents::DidLoadResourceFromMemoryCache(
1260 const GURL& url, 1246 const GURL& url,
1261 const std::string& security_info) { 1247 const std::string& security_info) {
1262 base::StatsCounter cache("WebKit.CacheHit"); 1248 base::StatsCounter cache("WebKit.CacheHit");
1263 cache.Increment(); 1249 cache.Increment();
1264 1250
1265 // Send out a notification that we loaded a resource from our memory cache. 1251 // Send out a notification that we loaded a resource from our memory cache.
1266 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0; 1252 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1267 SSLManager::DeserializeSecurityInfo(security_info, 1253 SSLManager::DeserializeSecurityInfo(security_info,
1268 &cert_id, &cert_status, 1254 &cert_id, &cert_status,
1269 &security_bits, 1255 &security_bits,
1270 &connection_status); 1256 &connection_status);
1271 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(), 1257 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1272 cert_id, cert_status); 1258 cert_id, cert_status);
1273 1259
1274 NotificationService::current()->Notify( 1260 NotificationService::current()->Notify(
1275 NotificationType::LOAD_FROM_MEMORY_CACHE, 1261 NotificationType::LOAD_FROM_MEMORY_CACHE,
1276 Source<NavigationController>(&controller_), 1262 Source<NavigationController>(&controller_),
1277 Details<LoadFromMemoryCacheDetails>(&details)); 1263 Details<LoadFromMemoryCacheDetails>(&details));
1278 } 1264 }
1279 1265
1280 void TabContents::OnDidDisplayInsecureContent() { 1266 void TabContents::DidDisplayInsecureContent() {
1281 displayed_insecure_content_ = true; 1267 displayed_insecure_content_ = true;
1282 SSLManager::NotifySSLInternalStateChanged(); 1268 SSLManager::NotifySSLInternalStateChanged();
1283 } 1269 }
1284 1270
1285 void TabContents::OnDidRunInsecureContent( 1271 void TabContents::DidRunInsecureContent(
1286 const std::string& security_origin, const GURL& target_url) { 1272 const std::string& security_origin, const GURL& target_url) {
1287 LOG(INFO) << security_origin << " ran insecure content from " 1273 LOG(INFO) << security_origin << " ran insecure content from "
1288 << target_url.possibly_invalid_spec(); 1274 << target_url.possibly_invalid_spec();
1289 controller_.ssl_manager()->DidRunInsecureContent(security_origin); 1275 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1290 } 1276 }
1291 1277
1292 void TabContents::OnDocumentLoadedInFrame(int64 frame_id) { 1278 void TabContents::DocumentLoadedInFrame(int64 frame_id) {
1293 controller_.DocumentLoadedInFrame(); 1279 controller_.DocumentLoadedInFrame();
1294 FOR_EACH_OBSERVER(TabContentsObserver, observers_, 1280 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1295 DocumentLoadedInFrame(frame_id)); 1281 DocumentLoadedInFrame(frame_id));
1296 } 1282 }
1297 1283
1298 void TabContents::OnDidFinishLoad(int64 frame_id) { 1284 void TabContents::DidFinishLoad(int64 frame_id) {
1299 FOR_EACH_OBSERVER(TabContentsObserver, observers_, 1285 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1300 DidFinishLoad(frame_id)); 1286 DidFinishLoad(frame_id));
1301 } 1287 }
1302 1288
1303 void TabContents::OnUpdateContentRestrictions(int restrictions) { 1289 void TabContents::UpdateContentRestrictions(int restrictions) {
1304 SetContentRestrictions(restrictions); 1290 SetContentRestrictions(restrictions);
1305 } 1291 }
1306 1292
1307 void TabContents::OnPDFHasUnsupportedFeature() { 1293 void TabContents::OnPDFHasUnsupportedFeature() {
1308 PDFHasUnsupportedFeature(this); 1294 PDFHasUnsupportedFeature(this);
1309 } 1295 }
1310 1296
1311 // Notifies the RenderWidgetHost instance about the fact that the page is 1297 // Notifies the RenderWidgetHost instance about the fact that the page is
1312 // loading, or done loading and calls the base implementation. 1298 // loading, or done loading and calls the base implementation.
1313 void TabContents::SetIsLoading(bool is_loading, 1299 void TabContents::SetIsLoading(bool is_loading,
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 1835
1850 // Run post-commit tasks. 1836 // Run post-commit tasks.
1851 if (details.is_main_frame) 1837 if (details.is_main_frame)
1852 DidNavigateMainFramePostCommit(details, params); 1838 DidNavigateMainFramePostCommit(details, params);
1853 DidNavigateAnyFramePostCommit(rvh, details, params); 1839 DidNavigateAnyFramePostCommit(rvh, details, params);
1854 } 1840 }
1855 1841
1856 void TabContents::UpdateState(RenderViewHost* rvh, 1842 void TabContents::UpdateState(RenderViewHost* rvh,
1857 int32 page_id, 1843 int32 page_id,
1858 const std::string& state) { 1844 const std::string& state) {
1859 DCHECK(rvh == render_view_host()); 1845 // Ensure that this state update comes from either the active RVH or one of
1846 // the swapped out RVHs. We don't expect to hear from any other RVHs.
1847 DCHECK(rvh == render_view_host() || render_manager_.IsSwappedOut(rvh));
1860 1848
1861 // We must be prepared to handle state updates for any page, these occur 1849 // We must be prepared to handle state updates for any page, these occur
1862 // when the user is scrolling and entering form data, as well as when we're 1850 // when the user is scrolling and entering form data, as well as when we're
1863 // leaving a page, in which case our state may have already been moved to 1851 // leaving a page, in which case our state may have already been moved to
1864 // the next page. The navigation controller will look up the appropriate 1852 // the next page. The navigation controller will look up the appropriate
1865 // NavigationEntry and update it when it is notified via the delegate. 1853 // NavigationEntry and update it when it is notified via the delegate.
1866 1854
1867 int entry_index = controller_.GetEntryIndexWithPageID( 1855 int entry_index = controller_.GetEntryIndexWithPageID(
1868 GetSiteInstance(), page_id); 1856 rvh->site_instance(), page_id);
1869 if (entry_index < 0) 1857 if (entry_index < 0)
1870 return; 1858 return;
1871 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); 1859 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1872 1860
1873 if (state == entry->content_state()) 1861 if (state == entry->content_state())
1874 return; // Nothing to update. 1862 return; // Nothing to update.
1875 entry->set_content_state(state); 1863 entry->set_content_state(state);
1876 controller_.NotifyEntryChanged(entry, entry_index); 1864 controller_.NotifyEntryChanged(entry, entry_index);
1877 } 1865 }
1878 1866
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 } 2018 }
2031 2019
2032 void TabContents::ProcessExternalHostMessage(const std::string& message, 2020 void TabContents::ProcessExternalHostMessage(const std::string& message,
2033 const std::string& origin, 2021 const std::string& origin,
2034 const std::string& target) { 2022 const std::string& target) {
2035 if (delegate()) 2023 if (delegate())
2036 delegate()->ForwardMessageToExternalHost(message, origin, target); 2024 delegate()->ForwardMessageToExternalHost(message, origin, target);
2037 } 2025 }
2038 2026
2039 void TabContents::RunJavaScriptMessage( 2027 void TabContents::RunJavaScriptMessage(
2028 const RenderViewHost* rvh,
2040 const std::wstring& message, 2029 const std::wstring& message,
2041 const std::wstring& default_prompt, 2030 const std::wstring& default_prompt,
2042 const GURL& frame_url, 2031 const GURL& frame_url,
2043 const int flags, 2032 const int flags,
2044 IPC::Message* reply_msg, 2033 IPC::Message* reply_msg,
2045 bool* did_suppress_message) { 2034 bool* did_suppress_message) {
2046 // Suppress javascript messages when requested and when inside a constrained 2035 // Suppress javascript messages when requested and when inside a constrained
2047 // popup window (because that activates them and breaks them out of the 2036 // popup window (because that activates them and breaks them out of the
2048 // constrained window jail). 2037 // constrained window jail).
2049 // Also suppress messages when showing an interstitial. The interstitial is 2038 // Also suppress messages when showing an interstitial. The interstitial is
2050 // shown over the previous page, we don't want the hidden page dialogs to 2039 // shown over the previous page, we don't want the hidden page dialogs to
2051 // interfere with the interstitial. 2040 // interfere with the interstitial.
2052 bool suppress_this_message = 2041 bool suppress_this_message =
2042 rvh->is_swapped_out() ||
2053 suppress_javascript_messages_ || 2043 suppress_javascript_messages_ ||
2054 showing_interstitial_page() || 2044 showing_interstitial_page() ||
2055 (delegate() && delegate()->ShouldSuppressDialogs()); 2045 (delegate() && delegate()->ShouldSuppressDialogs());
2056 if (delegate()) 2046 if (delegate())
2057 suppress_this_message |= 2047 suppress_this_message |=
2058 (delegate()->GetConstrainingContents(this) != this); 2048 (delegate()->GetConstrainingContents(this) != this);
2059 2049
2060 *did_suppress_message = suppress_this_message; 2050 *did_suppress_message = suppress_this_message;
2061 2051
2062 if (!suppress_this_message) { 2052 if (!suppress_this_message) {
2063 base::TimeDelta time_since_last_message( 2053 base::TimeDelta time_since_last_message(
2064 base::TimeTicks::Now() - last_javascript_message_dismissal_); 2054 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2065 bool show_suppress_checkbox = false; 2055 bool show_suppress_checkbox = false;
2066 // Show a checkbox offering to suppress further messages if this message is 2056 // Show a checkbox offering to suppress further messages if this message is
2067 // being displayed within kJavascriptMessageExpectedDelay of the last one. 2057 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2068 if (time_since_last_message < 2058 if (time_since_last_message <
2069 base::TimeDelta::FromMilliseconds( 2059 base::TimeDelta::FromMilliseconds(
2070 chrome::kJavascriptMessageExpectedDelay)) 2060 chrome::kJavascriptMessageExpectedDelay))
2071 show_suppress_checkbox = true; 2061 show_suppress_checkbox = true;
2072 2062
2073 RunJavascriptMessageBox(profile(), this, frame_url, flags, message, 2063 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2074 default_prompt, show_suppress_checkbox, reply_msg); 2064 default_prompt, show_suppress_checkbox, reply_msg);
2075 } else { 2065 } else {
2076 // If we are suppressing messages, just reply as is if the user immediately 2066 // If we are suppressing messages, just reply as is if the user immediately
2077 // pressed "Cancel". 2067 // pressed "Cancel".
2078 OnMessageBoxClosed(reply_msg, false, std::wstring()); 2068 OnMessageBoxClosed(reply_msg, false, std::wstring());
2079 } 2069 }
2080 } 2070 }
2081 2071
2082 void TabContents::RunBeforeUnloadConfirm(const std::wstring& message, 2072 void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh,
2073 const std::wstring& message,
2083 IPC::Message* reply_msg) { 2074 IPC::Message* reply_msg) {
2084 if (delegate()) 2075 if (delegate())
2085 delegate()->WillRunBeforeUnloadConfirm(); 2076 delegate()->WillRunBeforeUnloadConfirm();
2086 if (delegate() && delegate()->ShouldSuppressDialogs()) { 2077 bool suppress_this_message = rvh->is_swapped_out() ||
2078 (delegate() && delegate()->ShouldSuppressDialogs());
2079 if (suppress_this_message) {
2087 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, 2080 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2088 std::wstring()); 2081 std::wstring());
2089 return; 2082 return;
2090 } 2083 }
2091 is_showing_before_unload_dialog_ = true; 2084 is_showing_before_unload_dialog_ = true;
2092 RunBeforeUnloadDialog(this, message, reply_msg); 2085 RunBeforeUnloadDialog(this, message, reply_msg);
2093 } 2086 }
2094 2087
2095 GURL TabContents::GetAlternateErrorPageURL() const { 2088 GURL TabContents::GetAlternateErrorPageURL() const {
2096 GURL url; 2089 GURL url;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2152 int new_request_id) { 2145 int new_request_id) {
2153 // Allows the TabContents to react when a cross-site response is ready to be 2146 // Allows the TabContents to react when a cross-site response is ready to be
2154 // delivered to a pending RenderViewHost. We must first run the onunload 2147 // delivered to a pending RenderViewHost. We must first run the onunload
2155 // handler of the old RenderViewHost before we can allow it to proceed. 2148 // handler of the old RenderViewHost before we can allow it to proceed.
2156 render_manager_.OnCrossSiteResponse(new_render_process_host_id, 2149 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2157 new_request_id); 2150 new_request_id);
2158 } 2151 }
2159 2152
2160 void TabContents::RendererUnresponsive(RenderViewHost* rvh, 2153 void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2161 bool is_during_unload) { 2154 bool is_during_unload) {
2155 // Don't show hung renderer dialog for a swapped out RVH.
2156 if (rvh != render_view_host())
2157 return;
2158
2162 if (is_during_unload) { 2159 if (is_during_unload) {
2163 // Hang occurred while firing the beforeunload/unload handler. 2160 // Hang occurred while firing the beforeunload/unload handler.
2164 // Pretend the handler fired so tab closing continues as if it had. 2161 // Pretend the handler fired so tab closing continues as if it had.
2165 rvh->set_sudden_termination_allowed(true); 2162 rvh->set_sudden_termination_allowed(true);
2166 2163
2167 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) 2164 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2168 return; 2165 return;
2169 2166
2170 // If the tab hangs in the beforeunload/unload handler there's really 2167 // If the tab hangs in the beforeunload/unload handler there's really
2171 // nothing we can do to recover. Pretend the unload listeners have 2168 // nothing we can do to recover. Pretend the unload listeners have
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2418 2415
2419 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { 2416 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2420 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); 2417 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2421 rwh_view->SetSize(view()->GetContainerSize()); 2418 rwh_view->SetSize(view()->GetContainerSize());
2422 } 2419 }
2423 2420
2424 void TabContents::OnOnlineStateChanged(bool online) { 2421 void TabContents::OnOnlineStateChanged(bool online) {
2425 render_view_host()->Send(new ViewMsg_NetworkStateChanged( 2422 render_view_host()->Send(new ViewMsg_NetworkStateChanged(
2426 render_view_host()->routing_id(), online)); 2423 render_view_host()->routing_id(), online));
2427 } 2424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698