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 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1416 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) | 1417 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
1417 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) | 1418 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
1418 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) | 1419 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
1419 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) | 1420 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
1420 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone) | 1421 IPC_MESSAGE_HANDLER(ViewMsg_TimezoneChange, OnUpdateTimezone) |
1421 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) | 1422 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
1422 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, | 1423 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
1423 OnEnumerateDirectoryResponse) | 1424 OnEnumerateDirectoryResponse) |
1424 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) | 1425 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
1425 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) | 1426 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
1427 IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut, | |
1428 OnSuppressDialogsUntilSwapOut) | |
1426 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) | 1429 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
1427 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) | 1430 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
1428 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) | 1431 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
1429 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) | 1432 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
1430 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) | 1433 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
1431 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) | 1434 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
1432 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, | 1435 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
1433 OnEnablePreferredSizeChangedMode) | 1436 OnEnablePreferredSizeChangedMode) |
1434 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) | 1437 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize) |
1435 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) | 1438 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize) |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2264 GURL(kUnreachableWebDataURL), | 2267 GURL(kUnreachableWebDataURL), |
2265 error.unreachableURL, | 2268 error.unreachableURL, |
2266 replace); | 2269 replace); |
2267 } | 2270 } |
2268 | 2271 |
2269 bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type, | 2272 bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type, |
2270 const string16& message, | 2273 const string16& message, |
2271 const string16& default_value, | 2274 const string16& default_value, |
2272 const GURL& frame_url, | 2275 const GURL& frame_url, |
2273 string16* result) { | 2276 string16* result) { |
2277 // Don't allow further dialogs if we are waiting to swap out, since the | |
2278 // PageGroupLoadDeferrer in our stack prevents it. | |
2279 if (suppress_dialogs_until_swap_out_) | |
2280 return false; | |
2281 | |
2274 bool success = false; | 2282 bool success = false; |
2275 string16 result_temp; | 2283 string16 result_temp; |
2276 if (!result) | 2284 if (!result) |
2277 result = &result_temp; | 2285 result = &result_temp; |
2278 | 2286 |
2279 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( | 2287 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
2280 routing_id_, message, default_value, frame_url, type, &success, result)); | 2288 routing_id_, message, default_value, frame_url, type, &success, result)); |
2281 return success; | 2289 return success; |
2282 } | 2290 } |
2283 | 2291 |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2699 } | 2707 } |
2700 | 2708 |
2701 bool RenderViewImpl::runModalBeforeUnloadDialog( | 2709 bool RenderViewImpl::runModalBeforeUnloadDialog( |
2702 WebFrame* frame, bool is_reload, const WebString& message) { | 2710 WebFrame* frame, bool is_reload, const WebString& message) { |
2703 // If we are swapping out, we have already run the beforeunload handler. | 2711 // If we are swapping out, we have already run the beforeunload handler. |
2704 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload | 2712 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
2705 // at all, to avoid running it twice. | 2713 // at all, to avoid running it twice. |
2706 if (is_swapped_out_) | 2714 if (is_swapped_out_) |
2707 return true; | 2715 return true; |
2708 | 2716 |
2717 // Don't allow further dialogs if we are waiting to swap out, since the | |
2718 // PageGroupLoadDeferrer in our stack prevents it. | |
2719 if (suppress_dialogs_until_swap_out_) | |
2720 return false; | |
2721 | |
2709 bool success = false; | 2722 bool success = false; |
2710 // This is an ignored return value, but is included so we can accept the same | 2723 // This is an ignored return value, but is included so we can accept the same |
2711 // response as RunJavaScriptMessage. | 2724 // response as RunJavaScriptMessage. |
2712 string16 ignored_result; | 2725 string16 ignored_result; |
2713 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( | 2726 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
2714 routing_id_, frame->document().url(), message, is_reload, | 2727 routing_id_, frame->document().url(), message, is_reload, |
2715 &success, &ignored_result)); | 2728 &success, &ignored_result)); |
2716 return success; | 2729 return success; |
2717 } | 2730 } |
2718 | 2731 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2984 // NOTE: initial_pos_ may still have its default values at this point, but | 2997 // NOTE: initial_pos_ may still have its default values at this point, but |
2985 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the | 2998 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
2986 // browser process will impose a default position otherwise. | 2999 // browser process will impose a default position otherwise. |
2987 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, | 3000 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
2988 NavigationPolicyToDisposition(policy), initial_pos_, | 3001 NavigationPolicyToDisposition(policy), initial_pos_, |
2989 opened_by_user_gesture_)); | 3002 opened_by_user_gesture_)); |
2990 SetPendingWindowRect(initial_pos_); | 3003 SetPendingWindowRect(initial_pos_); |
2991 } | 3004 } |
2992 | 3005 |
2993 void RenderViewImpl::runModal() { | 3006 void RenderViewImpl::runModal() { |
3007 // TODO(creis): runModalDialog looks deprecated. Is this code dead? | |
Charlie Reis
2013/10/29 02:59:56
Darin, can we still get here? I didn't see any ca
Charlie Reis
2013/10/30 16:09:52
Ah, I had the name wrong. showModalDialog still e
| |
3008 NOTREACHED(); | |
2994 DCHECK(did_show_) << "should already have shown the view"; | 3009 DCHECK(did_show_) << "should already have shown the view"; |
2995 | 3010 |
3011 // Don't allow further dialogs if we are waiting to swap out, since the | |
3012 // PageGroupLoadDeferrer in our stack prevents it. | |
3013 if (suppress_dialogs_until_swap_out_) | |
3014 return; | |
3015 | |
2996 // We must keep WebKit's shared timer running in this case in order to allow | 3016 // We must keep WebKit's shared timer running in this case in order to allow |
2997 // showModalDialog to function properly. | 3017 // showModalDialog to function properly. |
2998 // | 3018 // |
2999 // TODO(darin): WebKit should really be smarter about suppressing events and | 3019 // TODO(darin): WebKit should really be smarter about suppressing events and |
3000 // timers so that we do not need to manage the shared timer in such a heavy | 3020 // timers so that we do not need to manage the shared timer in such a heavy |
3001 // handed manner. | 3021 // handed manner. |
3002 // | 3022 // |
3003 if (RenderThreadImpl::current()) // Will be NULL during unit tests. | 3023 if (RenderThreadImpl::current()) // Will be NULL during unit tests. |
3004 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); | 3024 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer(); |
3005 | 3025 |
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5370 | 5390 |
5371 void RenderViewImpl::OnShouldClose() { | 5391 void RenderViewImpl::OnShouldClose() { |
5372 base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); | 5392 base::TimeTicks before_unload_start_time = base::TimeTicks::Now(); |
5373 bool should_close = webview()->dispatchBeforeUnloadEvent(); | 5393 bool should_close = webview()->dispatchBeforeUnloadEvent(); |
5374 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); | 5394 base::TimeTicks before_unload_end_time = base::TimeTicks::Now(); |
5375 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, | 5395 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close, |
5376 before_unload_start_time, | 5396 before_unload_start_time, |
5377 before_unload_end_time)); | 5397 before_unload_end_time)); |
5378 } | 5398 } |
5379 | 5399 |
5400 void RenderViewImpl::OnSuppressDialogsUntilSwapOut() { | |
5401 // Don't show any more dialogs until we finish OnSwapOut. | |
5402 suppress_dialogs_until_swap_out_ = true; | |
5403 } | |
5404 | |
5380 void RenderViewImpl::OnSwapOut() { | 5405 void RenderViewImpl::OnSwapOut() { |
5381 // Only run unload if we're not swapped out yet, but send the ack either way. | 5406 // Only run unload if we're not swapped out yet, but send the ack either way. |
5382 if (!is_swapped_out_) { | 5407 if (!is_swapped_out_) { |
5383 // Swap this RenderView out so the tab can navigate to a page rendered by a | 5408 // Swap this RenderView out so the tab can navigate to a page rendered by a |
5384 // different process. This involves running the unload handler and clearing | 5409 // different process. This involves running the unload handler and clearing |
5385 // the page. Once WasSwappedOut is called, we also allow this process to | 5410 // the page. Once WasSwappedOut is called, we also allow this process to |
5386 // exit if there are no other active RenderViews in it. | 5411 // exit if there are no other active RenderViews in it. |
5387 | 5412 |
5388 // Send an UpdateState message before we get swapped out. | 5413 // Send an UpdateState message before we get swapped out. |
5389 SyncNavigationState(); | 5414 SyncNavigationState(); |
(...skipping 13 matching lines...) Expand all Loading... | |
5403 // run a second time, thanks to a check in FrameLoader::stopLoading. | 5428 // run a second time, thanks to a check in FrameLoader::stopLoading. |
5404 // TODO(creis): Need to add a better way to do this that avoids running the | 5429 // TODO(creis): Need to add a better way to do this that avoids running the |
5405 // beforeunload handler. For now, we just run it a second time silently. | 5430 // beforeunload handler. For now, we just run it a second time silently. |
5406 NavigateToSwappedOutURL(webview()->mainFrame()); | 5431 NavigateToSwappedOutURL(webview()->mainFrame()); |
5407 | 5432 |
5408 // Let WebKit know that this view is hidden so it can drop resources and | 5433 // Let WebKit know that this view is hidden so it can drop resources and |
5409 // stop compositing. | 5434 // stop compositing. |
5410 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); | 5435 webview()->setVisibilityState(WebKit::WebPageVisibilityStateHidden, false); |
5411 } | 5436 } |
5412 | 5437 |
5438 // It is now safe to show modal dialogs again. | |
5439 suppress_dialogs_until_swap_out_ = false; | |
5440 | |
5413 Send(new ViewHostMsg_SwapOut_ACK(routing_id_)); | 5441 Send(new ViewHostMsg_SwapOut_ACK(routing_id_)); |
5414 } | 5442 } |
5415 | 5443 |
5416 void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) { | 5444 void RenderViewImpl::NavigateToSwappedOutURL(WebKit::WebFrame* frame) { |
5417 // We use loadRequest instead of loadHTMLString because the former commits | 5445 // We use loadRequest instead of loadHTMLString because the former commits |
5418 // synchronously. Otherwise a new navigation can interrupt the navigation | 5446 // synchronously. Otherwise a new navigation can interrupt the navigation |
5419 // to kSwappedOutURL. If that happens to be to the page we had been | 5447 // to kSwappedOutURL. If that happens to be to the page we had been |
5420 // showing, then WebKit will never send a commit and we'll be left spinning. | 5448 // showing, then WebKit will never send a commit and we'll be left spinning. |
5421 CHECK(is_swapped_out_); | 5449 CHECK(is_swapped_out_); |
5422 GURL swappedOutURL(kSwappedOutURL); | 5450 GURL swappedOutURL(kSwappedOutURL); |
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6583 for (size_t i = 0; i < icon_urls.size(); i++) { | 6611 for (size_t i = 0; i < icon_urls.size(); i++) { |
6584 WebURL url = icon_urls[i].iconURL(); | 6612 WebURL url = icon_urls[i].iconURL(); |
6585 if (!url.isEmpty()) | 6613 if (!url.isEmpty()) |
6586 urls.push_back(FaviconURL(url, | 6614 urls.push_back(FaviconURL(url, |
6587 ToFaviconType(icon_urls[i].iconType()))); | 6615 ToFaviconType(icon_urls[i].iconType()))); |
6588 } | 6616 } |
6589 SendUpdateFaviconURL(urls); | 6617 SendUpdateFaviconURL(urls); |
6590 } | 6618 } |
6591 | 6619 |
6592 } // namespace content | 6620 } // namespace content |
OLD | NEW |