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

Side by Side Diff: content/renderer/render_view_impl.cc

Issue 50223002: Prevent modal dialogs when preparing to swap out. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 1 month 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
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/renderer/render_view_impl.h" 5 #include "content/renderer/render_view_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 params->swapped_out, 825 params->swapped_out,
826 params->hidden), 826 params->hidden),
827 webkit_preferences_(params->webkit_prefs), 827 webkit_preferences_(params->webkit_prefs),
828 send_content_state_immediately_(false), 828 send_content_state_immediately_(false),
829 enabled_bindings_(0), 829 enabled_bindings_(0),
830 send_preferred_size_changes_(false), 830 send_preferred_size_changes_(false),
831 is_loading_(false), 831 is_loading_(false),
832 navigation_gesture_(NavigationGestureUnknown), 832 navigation_gesture_(NavigationGestureUnknown),
833 opened_by_user_gesture_(true), 833 opened_by_user_gesture_(true),
834 opener_suppressed_(false), 834 opener_suppressed_(false),
835 suppress_dialogs_until_swap_out_(false),
835 page_id_(-1), 836 page_id_(-1),
836 last_page_id_sent_to_browser_(-1), 837 last_page_id_sent_to_browser_(-1),
837 next_page_id_(params->next_page_id), 838 next_page_id_(params->next_page_id),
838 history_list_offset_(-1), 839 history_list_offset_(-1),
839 history_list_length_(0), 840 history_list_length_(0),
840 target_url_status_(TARGET_NONE), 841 target_url_status_(TARGET_NONE),
841 selection_text_offset_(0), 842 selection_text_offset_(0),
842 selection_range_(gfx::Range::InvalidRange()), 843 selection_range_(gfx::Range::InvalidRange()),
843 #if defined(OS_ANDROID) 844 #if defined(OS_ANDROID)
844 top_controls_constraints_(cc::BOTH), 845 top_controls_constraints_(cc::BOTH),
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) 1419 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
1419 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) 1420 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
1420 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) 1421 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1421 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) 1422 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1422 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone) 1423 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone)
1423 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) 1424 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
1424 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, 1425 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
1425 OnEnumerateDirectoryResponse) 1426 OnEnumerateDirectoryResponse)
1426 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) 1427 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
1427 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) 1428 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
1429 IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut,
1430 OnSuppressDialogsUntilSwapOut)
1428 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) 1431 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
1429 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) 1432 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1430 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) 1433 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
1431 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) 1434 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
1432 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) 1435 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
1433 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) 1436 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
1434 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, 1437 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1435 OnEnablePreferredSizeChangedMode) 1438 OnEnablePreferredSizeChangedMode)
1436 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) 1439 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
1437 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) 1440 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
2270 GURL(kUnreachableWebDataURL), 2273 GURL(kUnreachableWebDataURL),
2271 error.unreachableURL, 2274 error.unreachableURL,
2272 replace); 2275 replace);
2273 } 2276 }
2274 2277
2275 bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type, 2278 bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
2276 const string16& message, 2279 const string16& message,
2277 const string16& default_value, 2280 const string16& default_value,
2278 const GURL& frame_url, 2281 const GURL& frame_url,
2279 string16* result) { 2282 string16* result) {
2283 // Don't allow further dialogs if we are waiting to swap out, since the
2284 // PageGroupLoadDeferrer in our stack prevents it.
2285 if (suppress_dialogs_until_swap_out_)
2286 return false;
2287
2280 bool success = false; 2288 bool success = false;
2281 string16 result_temp; 2289 string16 result_temp;
2282 if (!result) 2290 if (!result)
2283 result = &result_temp; 2291 result = &result_temp;
2284 2292
2285 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( 2293 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
2286 routing_id_, message, default_value, frame_url, type, &success, result)); 2294 routing_id_, message, default_value, frame_url, type, &success, result));
2287 return success; 2295 return success;
2288 } 2296 }
2289 2297
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
2717 } 2725 }
2718 2726
2719 bool RenderViewImpl::runModalBeforeUnloadDialog( 2727 bool RenderViewImpl::runModalBeforeUnloadDialog(
2720 WebFrame* frame, bool is_reload, const WebString& message) { 2728 WebFrame* frame, bool is_reload, const WebString& message) {
2721 // If we are swapping out, we have already run the beforeunload handler. 2729 // If we are swapping out, we have already run the beforeunload handler.
2722 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload 2730 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
2723 // at all, to avoid running it twice. 2731 // at all, to avoid running it twice.
2724 if (is_swapped_out_) 2732 if (is_swapped_out_)
2725 return true; 2733 return true;
2726 2734
2735 // Don't allow further dialogs if we are waiting to swap out, since the
2736 // PageGroupLoadDeferrer in our stack prevents it.
2737 if (suppress_dialogs_until_swap_out_)
2738 return false;
2739
2727 bool success = false; 2740 bool success = false;
2728 // This is an ignored return value, but is included so we can accept the same 2741 // This is an ignored return value, but is included so we can accept the same
2729 // response as RunJavaScriptMessage. 2742 // response as RunJavaScriptMessage.
2730 string16 ignored_result; 2743 string16 ignored_result;
2731 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( 2744 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
2732 routing_id_, frame->document().url(), message, is_reload, 2745 routing_id_, frame->document().url(), message, is_reload,
2733 &success, &ignored_result)); 2746 &success, &ignored_result));
2734 return success; 2747 return success;
2735 } 2748 }
2736 2749
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
3004 // browser process will impose a default position otherwise. 3017 // browser process will impose a default position otherwise.
3005 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, 3018 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
3006 NavigationPolicyToDisposition(policy), initial_pos_, 3019 NavigationPolicyToDisposition(policy), initial_pos_,
3007 opened_by_user_gesture_)); 3020 opened_by_user_gesture_));
3008 SetPendingWindowRect(initial_pos_); 3021 SetPendingWindowRect(initial_pos_);
3009 } 3022 }
3010 3023
3011 void RenderViewImpl::runModal() { 3024 void RenderViewImpl::runModal() {
3012 DCHECK(did_show_) << "should already have shown the view"; 3025 DCHECK(did_show_) << "should already have shown the view";
3013 3026
3027 // Don't allow further dialogs if we are waiting to swap out, since the
3028 // PageGroupLoadDeferrer in our stack prevents it.
3029 if (suppress_dialogs_until_swap_out_)
3030 return;
3031
3014 // We must keep WebKit's shared timer running in this case in order to allow 3032 // We must keep WebKit's shared timer running in this case in order to allow
3015 // showModalDialog to function properly. 3033 // showModalDialog to function properly.
3016 // 3034 //
3017 // TODO(darin): WebKit should really be smarter about suppressing events and 3035 // TODO(darin): WebKit should really be smarter about suppressing events and
3018 // timers so that we do not need to manage the shared timer in such a heavy 3036 // timers so that we do not need to manage the shared timer in such a heavy
3019 // handed manner. 3037 // handed manner.
3020 // 3038 //
3021 if (RenderThreadImpl::current()) // Will be NULL during unit tests. 3039 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
3022 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); 3040 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
3023 3041
(...skipping 2305 matching lines...) Expand 10 before | Expand all | Expand 10 after
5329 5347
5330 void RenderViewImpl::OnShouldClose() { 5348 void RenderViewImpl::OnShouldClose() {
5331 base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); 5349 base::TimeTicks before_unload_start_time = base::TimeTicks::Now();
5332 bool should_close = webview()->dispatchBeforeUnloadEvent(); 5350 bool should_close = webview()->dispatchBeforeUnloadEvent();
5333 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); 5351 base::TimeTicks before_unload_end_time = base::TimeTicks::Now();
5334 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, 5352 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close,
5335 before_unload_start_time, 5353 before_unload_start_time,
5336 before_unload_end_time)); 5354 before_unload_end_time));
5337 } 5355 }
5338 5356
5357 void RenderViewImpl::OnSuppressDialogsUntilSwapOut() {
5358 // Don't show any more dialogs until we finish OnSwapOut.
5359 suppress_dialogs_until_swap_out_ = true;
5360 }
5361
5339 void RenderViewImpl::OnSwapOut() { 5362 void RenderViewImpl::OnSwapOut() {
5340 // Only run unload if we're not swapped out yet, but send the ack either way. 5363 // Only run unload if we're not swapped out yet, but send the ack either way.
5341 if (!is_swapped_out_) { 5364 if (!is_swapped_out_) {
5342 // Swap this RenderView out so the tab can navigate to a page rendered by a 5365 // Swap this RenderView out so the tab can navigate to a page rendered by a
5343 // different process. This involves running the unload handler and clearing 5366 // different process. This involves running the unload handler and clearing
5344 // the page. Once WasSwappedOut is called, we also allow this process to 5367 // the page. Once WasSwappedOut is called, we also allow this process to
5345 // exit if there are no other active RenderViews in it. 5368 // exit if there are no other active RenderViews in it.
5346 5369
5347 // Send an UpdateState message before we get swapped out. 5370 // Send an UpdateState message before we get swapped out.
5348 SyncNavigationState(); 5371 SyncNavigationState();
(...skipping 13 matching lines...) Expand all
5362 // run a second time, thanks to a check in FrameLoader::stopLoading. 5385 // run a second time, thanks to a check in FrameLoader::stopLoading.
5363 // TODO(creis): Need to add a better way to do this that avoids running the 5386 // TODO(creis): Need to add a better way to do this that avoids running the
5364 // beforeunload handler. For now, we just run it a second time silently. 5387 // beforeunload handler. For now, we just run it a second time silently.
5365 NavigateToSwappedOutURL(webview()->mainFrame()); 5388 NavigateToSwappedOutURL(webview()->mainFrame());
5366 5389
5367 // Let WebKit know that this view is hidden so it can drop resources and 5390 // Let WebKit know that this view is hidden so it can drop resources and
5368 // stop compositing. 5391 // stop compositing.
5369 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); 5392 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false);
5370 } 5393 }
5371 5394
5395 // It is now safe to show modal dialogs again.
5396 suppress_dialogs_until_swap_out_ = false;
5397
5372 Send(new ViewHostMsg_SwapOut_ACK(routing_id_)); 5398 Send(new ViewHostMsg_SwapOut_ACK(routing_id_));
5373 } 5399 }
5374 5400
5375 void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) { 5401 void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) {
5376 // We use loadRequest instead of loadHTMLString because the former commits 5402 // We use loadRequest instead of loadHTMLString because the former commits
5377 // synchronously. Otherwise a new navigation can interrupt the navigation 5403 // synchronously. Otherwise a new navigation can interrupt the navigation
5378 // to kSwappedOutURL. If that happens to be to the page we had been 5404 // to kSwappedOutURL. If that happens to be to the page we had been
5379 // showing, then WebKit will never send a commit and we'll be left spinning. 5405 // showing, then WebKit will never send a commit and we'll be left spinning.
5380 CHECK(is_swapped_out_); 5406 CHECK(is_swapped_out_);
5381 GURL swappedOutURL(kSwappedOutURL); 5407 GURL swappedOutURL(kSwappedOutURL);
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
6630 for (size_t i = 0; i < icon_urls.size(); i++) { 6656 for (size_t i = 0; i < icon_urls.size(); i++) {
6631 WebURL url = icon_urls[i].iconURL(); 6657 WebURL url = icon_urls[i].iconURL();
6632 if (!url.isEmpty()) 6658 if (!url.isEmpty())
6633 urls.push_back(FaviconURL(url, 6659 urls.push_back(FaviconURL(url,
6634 ToFaviconType(icon_urls[i].iconType()))); 6660 ToFaviconType(icon_urls[i].iconType())));
6635 } 6661 }
6636 SendUpdateFaviconURL(urls); 6662 SendUpdateFaviconURL(urls);
6637 } 6663 }
6638 6664
6639 } // namespace content 6665 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698