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/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 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 params->swapped_out, | 826 params->swapped_out, |
827 params->hidden), | 827 params->hidden), |
828 webkit_preferences_(params->webkit_prefs), | 828 webkit_preferences_(params->webkit_prefs), |
829 send_content_state_immediately_(false), | 829 send_content_state_immediately_(false), |
830 enabled_bindings_(0), | 830 enabled_bindings_(0), |
831 send_preferred_size_changes_(false), | 831 send_preferred_size_changes_(false), |
832 is_loading_(false), | 832 is_loading_(false), |
833 navigation_gesture_(NavigationGestureUnknown), | 833 navigation_gesture_(NavigationGestureUnknown), |
834 opened_by_user_gesture_(true), | 834 opened_by_user_gesture_(true), |
835 opener_suppressed_(false), | 835 opener_suppressed_(false), |
| 836 suppress_dialogs_until_swap_out_(false), |
836 page_id_(-1), | 837 page_id_(-1), |
837 last_page_id_sent_to_browser_(-1), | 838 last_page_id_sent_to_browser_(-1), |
838 next_page_id_(params->next_page_id), | 839 next_page_id_(params->next_page_id), |
839 history_list_offset_(-1), | 840 history_list_offset_(-1), |
840 history_list_length_(0), | 841 history_list_length_(0), |
841 target_url_status_(TARGET_NONE), | 842 target_url_status_(TARGET_NONE), |
842 selection_text_offset_(0), | 843 selection_text_offset_(0), |
843 selection_range_(gfx::Range::InvalidRange()), | 844 selection_range_(gfx::Range::InvalidRange()), |
844 #if defined(OS_ANDROID) | 845 #if defined(OS_ANDROID) |
845 top_controls_constraints_(cc::BOTH), | 846 top_controls_constraints_(cc::BOTH), |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) | 1420 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
1420 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) | 1421 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
1421 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) | 1422 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
1422 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) | 1423 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
1423 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone) | 1424 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone) |
1424 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) | 1425 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
1425 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, | 1426 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
1426 OnEnumerateDirectoryResponse) | 1427 OnEnumerateDirectoryResponse) |
1427 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) | 1428 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
1428 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) | 1429 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
| 1430 IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut, |
| 1431 OnSuppressDialogsUntilSwapOut) |
1429 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) | 1432 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
1430 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) | 1433 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
1431 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) | 1434 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
1432 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) | 1435 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
1433 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) | 1436 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
1434 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) | 1437 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
1435 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, | 1438 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
1436 OnEnablePreferredSizeChangedMode) | 1439 OnEnablePreferredSizeChangedMode) |
1437 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) | 1440 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
1438 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) | 1441 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2271 GURL(kUnreachableWebDataURL), | 2274 GURL(kUnreachableWebDataURL), |
2272 error.unreachableURL, | 2275 error.unreachableURL, |
2273 replace); | 2276 replace); |
2274 } | 2277 } |
2275 | 2278 |
2276 bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type, | 2279 bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type, |
2277 const string16& message, | 2280 const string16& message, |
2278 const string16& default_value, | 2281 const string16& default_value, |
2279 const GURL& frame_url, | 2282 const GURL& frame_url, |
2280 string16* result) { | 2283 string16* result) { |
| 2284 // Don't allow further dialogs if we are waiting to swap out, since the |
| 2285 // PageGroupLoadDeferrer in our stack prevents it. |
| 2286 if (suppress_dialogs_until_swap_out_) |
| 2287 return false; |
| 2288 |
2281 bool success = false; | 2289 bool success = false; |
2282 string16 result_temp; | 2290 string16 result_temp; |
2283 if (!result) | 2291 if (!result) |
2284 result = &result_temp; | 2292 result = &result_temp; |
2285 | 2293 |
2286 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( | 2294 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
2287 routing_id_, message, default_value, frame_url, type, &success, result)); | 2295 routing_id_, message, default_value, frame_url, type, &success, result)); |
2288 return success; | 2296 return success; |
2289 } | 2297 } |
2290 | 2298 |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2707 } | 2715 } |
2708 | 2716 |
2709 bool RenderViewImpl::runModalBeforeUnloadDialog( | 2717 bool RenderViewImpl::runModalBeforeUnloadDialog( |
2710 WebFrame* frame, bool is_reload, const WebString& message) { | 2718 WebFrame* frame, bool is_reload, const WebString& message) { |
2711 // If we are swapping out, we have already run the beforeunload handler. | 2719 // If we are swapping out, we have already run the beforeunload handler. |
2712 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload | 2720 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
2713 // at all, to avoid running it twice. | 2721 // at all, to avoid running it twice. |
2714 if (is_swapped_out_) | 2722 if (is_swapped_out_) |
2715 return true; | 2723 return true; |
2716 | 2724 |
| 2725 // Don't allow further dialogs if we are waiting to swap out, since the |
| 2726 // PageGroupLoadDeferrer in our stack prevents it. |
| 2727 if (suppress_dialogs_until_swap_out_) |
| 2728 return false; |
| 2729 |
2717 bool success = false; | 2730 bool success = false; |
2718 // This is an ignored return value, but is included so we can accept the same | 2731 // This is an ignored return value, but is included so we can accept the same |
2719 // response as RunJavaScriptMessage. | 2732 // response as RunJavaScriptMessage. |
2720 string16 ignored_result; | 2733 string16 ignored_result; |
2721 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( | 2734 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
2722 routing_id_, frame->document().url(), message, is_reload, | 2735 routing_id_, frame->document().url(), message, is_reload, |
2723 &success, &ignored_result)); | 2736 &success, &ignored_result)); |
2724 return success; | 2737 return success; |
2725 } | 2738 } |
2726 | 2739 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2994 // browser process will impose a default position otherwise. | 3007 // browser process will impose a default position otherwise. |
2995 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, | 3008 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
2996 NavigationPolicyToDisposition(policy), initial_pos_, | 3009 NavigationPolicyToDisposition(policy), initial_pos_, |
2997 opened_by_user_gesture_)); | 3010 opened_by_user_gesture_)); |
2998 SetPendingWindowRect(initial_pos_); | 3011 SetPendingWindowRect(initial_pos_); |
2999 } | 3012 } |
3000 | 3013 |
3001 void RenderViewImpl::runModal() { | 3014 void RenderViewImpl::runModal() { |
3002 DCHECK(did_show_) << "should already have shown the view"; | 3015 DCHECK(did_show_) << "should already have shown the view"; |
3003 | 3016 |
| 3017 // Don't allow further dialogs if we are waiting to swap out, since the |
| 3018 // PageGroupLoadDeferrer in our stack prevents it. |
| 3019 if (suppress_dialogs_until_swap_out_) |
| 3020 return; |
| 3021 |
3004 // We must keep WebKit's shared timer running in this case in order to allow | 3022 // We must keep WebKit's shared timer running in this case in order to allow |
3005 // showModalDialog to function properly. | 3023 // showModalDialog to function properly. |
3006 // | 3024 // |
3007 // TODO(darin): WebKit should really be smarter about suppressing events and | 3025 // TODO(darin): WebKit should really be smarter about suppressing events and |
3008 // timers so that we do not need to manage the shared timer in such a heavy | 3026 // timers so that we do not need to manage the shared timer in such a heavy |
3009 // handed manner. | 3027 // handed manner. |
3010 // | 3028 // |
3011 if (RenderThreadImpl::current()) // Will be NULL during unit tests. | 3029 if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
3012 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); | 3030 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
3013 | 3031 |
(...skipping 2374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5388 | 5406 |
5389 void RenderViewImpl::OnShouldClose() { | 5407 void RenderViewImpl::OnShouldClose() { |
5390 base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); | 5408 base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); |
5391 bool should_close = webview()->dispatchBeforeUnloadEvent(); | 5409 bool should_close = webview()->dispatchBeforeUnloadEvent(); |
5392 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); | 5410 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); |
5393 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, | 5411 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, |
5394 before_unload_start_time, | 5412 before_unload_start_time, |
5395 before_unload_end_time)); | 5413 before_unload_end_time)); |
5396 } | 5414 } |
5397 | 5415 |
| 5416 void RenderViewImpl::OnSuppressDialogsUntilSwapOut() { |
| 5417 // Don't show any more dialogs until we finish OnSwapOut. |
| 5418 suppress_dialogs_until_swap_out_ = true; |
| 5419 } |
| 5420 |
5398 void RenderViewImpl::OnSwapOut() { | 5421 void RenderViewImpl::OnSwapOut() { |
5399 // Only run unload if we're not swapped out yet, but send the ack either way. | 5422 // Only run unload if we're not swapped out yet, but send the ack either way. |
5400 if (!is_swapped_out_) { | 5423 if (!is_swapped_out_) { |
5401 // Swap this RenderView out so the tab can navigate to a page rendered by a | 5424 // Swap this RenderView out so the tab can navigate to a page rendered by a |
5402 // different process. This involves running the unload handler and clearing | 5425 // different process. This involves running the unload handler and clearing |
5403 // the page. Once WasSwappedOut is called, we also allow this process to | 5426 // the page. Once WasSwappedOut is called, we also allow this process to |
5404 // exit if there are no other active RenderViews in it. | 5427 // exit if there are no other active RenderViews in it. |
5405 | 5428 |
5406 // Send an UpdateState message before we get swapped out. | 5429 // Send an UpdateState message before we get swapped out. |
5407 SyncNavigationState(); | 5430 SyncNavigationState(); |
(...skipping 13 matching lines...) Expand all Loading... |
5421 // run a second time, thanks to a check in FrameLoader::stopLoading. | 5444 // run a second time, thanks to a check in FrameLoader::stopLoading. |
5422 // TODO(creis): Need to add a better way to do this that avoids running the | 5445 // TODO(creis): Need to add a better way to do this that avoids running the |
5423 // beforeunload handler. For now, we just run it a second time silently. | 5446 // beforeunload handler. For now, we just run it a second time silently. |
5424 NavigateToSwappedOutURL(webview()->mainFrame()); | 5447 NavigateToSwappedOutURL(webview()->mainFrame()); |
5425 | 5448 |
5426 // Let WebKit know that this view is hidden so it can drop resources and | 5449 // Let WebKit know that this view is hidden so it can drop resources and |
5427 // stop compositing. | 5450 // stop compositing. |
5428 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); | 5451 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); |
5429 } | 5452 } |
5430 | 5453 |
| 5454 // It is now safe to show modal dialogs again. |
| 5455 suppress_dialogs_until_swap_out_ = false; |
| 5456 |
5431 Send(new ViewHostMsg_SwapOut_ACK(routing_id_)); | 5457 Send(new ViewHostMsg_SwapOut_ACK(routing_id_)); |
5432 } | 5458 } |
5433 | 5459 |
5434 void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) { | 5460 void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) { |
5435 // We use loadRequest instead of loadHTMLString because the former commits | 5461 // We use loadRequest instead of loadHTMLString because the former commits |
5436 // synchronously. Otherwise a new navigation can interrupt the navigation | 5462 // synchronously. Otherwise a new navigation can interrupt the navigation |
5437 // to kSwappedOutURL. If that happens to be to the page we had been | 5463 // to kSwappedOutURL. If that happens to be to the page we had been |
5438 // showing, then WebKit will never send a commit and we'll be left spinning. | 5464 // showing, then WebKit will never send a commit and we'll be left spinning. |
5439 CHECK(is_swapped_out_); | 5465 CHECK(is_swapped_out_); |
5440 GURL swappedOutURL(kSwappedOutURL); | 5466 GURL swappedOutURL(kSwappedOutURL); |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6606 for (size_t i = 0; i < icon_urls.size(); i++) { | 6632 for (size_t i = 0; i < icon_urls.size(); i++) { |
6607 WebURL url = icon_urls[i].iconURL(); | 6633 WebURL url = icon_urls[i].iconURL(); |
6608 if (!url.isEmpty()) | 6634 if (!url.isEmpty()) |
6609 urls.push_back(FaviconURL(url, | 6635 urls.push_back(FaviconURL(url, |
6610 ToFaviconType(icon_urls[i].iconType()))); | 6636 ToFaviconType(icon_urls[i].iconType()))); |
6611 } | 6637 } |
6612 SendUpdateFaviconURL(urls); | 6638 SendUpdateFaviconURL(urls); |
6613 } | 6639 } |
6614 | 6640 |
6615 } // namespace content | 6641 } // namespace content |
OLD | NEW |