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/renderer/render_view.h" | 5 #include "content/renderer/render_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) | 628 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
629 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) | 629 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
630 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) | 630 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
631 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) | 631 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) |
632 IPC_MESSAGE_HANDLER(ViewMsg_DisplayPrerenderedPage, | 632 IPC_MESSAGE_HANDLER(ViewMsg_DisplayPrerenderedPage, |
633 OnDisplayPrerenderedPage) | 633 OnDisplayPrerenderedPage) |
634 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, | 634 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
635 OnEnumerateDirectoryResponse) | 635 OnEnumerateDirectoryResponse) |
636 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) | 636 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
637 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) | 637 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
| 638 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) |
638 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) | 639 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
639 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) | 640 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
640 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, | 641 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
641 OnDisassociateFromPopupCount) | 642 OnDisassociateFromPopupCount) |
642 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) | 643 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
643 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) | 644 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
644 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) | 645 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
645 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, | 646 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
646 OnEnablePreferredSizeChangedMode) | 647 OnEnablePreferredSizeChangedMode) |
647 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, | 648 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 // Have the super handle all other messages. | 682 // Have the super handle all other messages. |
682 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) | 683 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) |
683 IPC_END_MESSAGE_MAP() | 684 IPC_END_MESSAGE_MAP() |
684 return handled; | 685 return handled; |
685 } | 686 } |
686 | 687 |
687 void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { | 688 void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { |
688 if (!webview()) | 689 if (!webview()) |
689 return; | 690 return; |
690 | 691 |
| 692 // Swap this renderer back in if necessary. |
| 693 if (is_swapped_out_) { |
| 694 SetSwappedOut(false); |
| 695 } |
| 696 |
691 history_list_offset_ = params.current_history_list_offset; | 697 history_list_offset_ = params.current_history_list_offset; |
692 history_list_length_ = params.current_history_list_length; | 698 history_list_length_ = params.current_history_list_length; |
693 | 699 |
694 content::GetContentClient()->SetActiveURL(params.url); | 700 content::GetContentClient()->SetActiveURL(params.url); |
695 | 701 |
696 bool is_reload = | 702 bool is_reload = |
697 params.navigation_type == ViewMsg_Navigate_Type::RELOAD || | 703 params.navigation_type == ViewMsg_Navigate_Type::RELOAD || |
698 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; | 704 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; |
699 | 705 |
700 WebFrame* main_frame = webview()->mainFrame(); | 706 WebFrame* main_frame = webview()->mainFrame(); |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 UTF16ToWideHack(default_value), | 1570 UTF16ToWideHack(default_value), |
1565 frame->url(), | 1571 frame->url(), |
1566 &result); | 1572 &result); |
1567 if (ok) | 1573 if (ok) |
1568 actual_value->assign(WideToUTF16Hack(result)); | 1574 actual_value->assign(WideToUTF16Hack(result)); |
1569 return ok; | 1575 return ok; |
1570 } | 1576 } |
1571 | 1577 |
1572 bool RenderView::runModalBeforeUnloadDialog( | 1578 bool RenderView::runModalBeforeUnloadDialog( |
1573 WebFrame* frame, const WebString& message) { | 1579 WebFrame* frame, const WebString& message) { |
| 1580 // If we are swapping out, we have already run the beforeunload handler. |
| 1581 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload |
| 1582 // at all, to avoid running it twice. |
| 1583 if (is_swapped_out_) |
| 1584 return true; |
| 1585 |
1574 bool success = false; | 1586 bool success = false; |
1575 // This is an ignored return value, but is included so we can accept the same | 1587 // This is an ignored return value, but is included so we can accept the same |
1576 // response as RunJavaScriptMessage. | 1588 // response as RunJavaScriptMessage. |
1577 std::wstring ignored_result; | 1589 std::wstring ignored_result; |
1578 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( | 1590 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
1579 routing_id_, frame->url(), UTF16ToWideHack(message), &success, | 1591 routing_id_, frame->url(), UTF16ToWideHack(message), &success, |
1580 &ignored_result)); | 1592 &ignored_result)); |
1581 return success; | 1593 return success; |
1582 } | 1594 } |
1583 | 1595 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1928 if (policy == WebKit::WebNavigationPolicyDownload) { | 1940 if (policy == WebKit::WebNavigationPolicyDownload) { |
1929 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); | 1941 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); |
1930 } else { | 1942 } else { |
1931 OpenURL(request.url(), referrer, policy); | 1943 OpenURL(request.url(), referrer, policy); |
1932 } | 1944 } |
1933 } | 1945 } |
1934 | 1946 |
1935 WebNavigationPolicy RenderView::decidePolicyForNavigation( | 1947 WebNavigationPolicy RenderView::decidePolicyForNavigation( |
1936 WebFrame* frame, const WebURLRequest& request, WebNavigationType type, | 1948 WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
1937 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { | 1949 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
| 1950 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation. |
| 1951 if (is_swapped_out_) { |
| 1952 DCHECK(request.url() == GURL("about:swappedout")); |
| 1953 return default_policy; |
| 1954 } |
| 1955 |
1938 // Webkit is asking whether to navigate to a new URL. | 1956 // Webkit is asking whether to navigate to a new URL. |
1939 // This is fine normally, except if we're showing UI from one security | 1957 // This is fine normally, except if we're showing UI from one security |
1940 // context and they're trying to navigate to a different context. | 1958 // context and they're trying to navigate to a different context. |
1941 const GURL& url = request.url(); | 1959 const GURL& url = request.url(); |
1942 | 1960 |
1943 // A content initiated navigation may have originated from a link-click, | 1961 // A content initiated navigation may have originated from a link-click, |
1944 // script, drag-n-drop operation, etc. | 1962 // script, drag-n-drop operation, etc. |
1945 bool is_content_initiated = | 1963 bool is_content_initiated = |
1946 NavigationState::FromDataSource(frame->provisionalDataSource())-> | 1964 NavigationState::FromDataSource(frame->provisionalDataSource())-> |
1947 is_content_initiated(); | 1965 is_content_initiated(); |
(...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3622 DCHECK(accessibility_ack_pending_); | 3640 DCHECK(accessibility_ack_pending_); |
3623 accessibility_ack_pending_ = false; | 3641 accessibility_ack_pending_ = false; |
3624 SendPendingAccessibilityNotifications(); | 3642 SendPendingAccessibilityNotifications(); |
3625 } | 3643 } |
3626 | 3644 |
3627 void RenderView::OnShouldClose() { | 3645 void RenderView::OnShouldClose() { |
3628 bool should_close = webview()->dispatchBeforeUnloadEvent(); | 3646 bool should_close = webview()->dispatchBeforeUnloadEvent(); |
3629 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); | 3647 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
3630 } | 3648 } |
3631 | 3649 |
3632 void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { | 3650 void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) { |
| 3651 if (is_swapped_out_) |
| 3652 return; |
| 3653 |
| 3654 // Swap this RenderView out so the tab can navigate to a page rendered by a |
| 3655 // different process. This involves running the unload handler and clearing |
| 3656 // the page. Once WasHidden is called, we also allow this process to exit |
| 3657 // if there are no other active RenderViews in it. |
| 3658 |
| 3659 // Send an UpdateState message before we get swapped out. |
| 3660 SyncNavigationState(); |
| 3661 |
| 3662 // Swap out and stop sending any IPC messages that are not ACKs. |
| 3663 SetSwappedOut(true); |
| 3664 |
| 3665 // Replace the page with a blank dummy URL, triggering the unload handler. |
| 3666 // TODO(creis): Need to add a better way to do this that avoids running the |
| 3667 // beforeunload handler. For now, we just run it a second time silently. |
| 3668 webview()->mainFrame()->loadHTMLString(std::string(), |
| 3669 GURL("about:swappedout"), |
| 3670 GURL("about:swappedout"), |
| 3671 false); |
| 3672 |
| 3673 // Just echo back the params in the ACK. |
| 3674 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); |
| 3675 } |
| 3676 |
| 3677 void RenderView::OnClosePage() { |
3633 // TODO(creis): We'd rather use webview()->Close() here, but that currently | 3678 // TODO(creis): We'd rather use webview()->Close() here, but that currently |
3634 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs | 3679 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
3635 // in the onunload handler from appearing. For now, we're bypassing that and | 3680 // in the onunload handler from appearing. For now, we're bypassing that and |
3636 // calling the FrameLoader's CloseURL method directly. This should be | 3681 // calling the FrameLoader's CloseURL method directly. This should be |
3637 // revisited to avoid having two ways to close a page. Having a single way | 3682 // revisited to avoid having two ways to close a page. Having a single way |
3638 // to close that can run onunload is also useful for fixing | 3683 // to close that can run onunload is also useful for fixing |
3639 // http://b/issue?id=753080. | 3684 // http://b/issue?id=753080. |
3640 webview()->dispatchUnloadEvent(); | 3685 webview()->dispatchUnloadEvent(); |
3641 | 3686 |
3642 // Just echo back the params in the ACK. | 3687 Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
3643 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params)); | |
3644 } | 3688 } |
3645 | 3689 |
3646 void RenderView::OnThemeChanged() { | 3690 void RenderView::OnThemeChanged() { |
3647 #if defined(OS_WIN) | 3691 #if defined(OS_WIN) |
3648 gfx::NativeThemeWin::instance()->CloseHandles(); | 3692 gfx::NativeThemeWin::instance()->CloseHandles(); |
3649 if (webview()) | 3693 if (webview()) |
3650 webview()->themeChanged(); | 3694 webview()->themeChanged(); |
3651 #else // defined(OS_WIN) | 3695 #else // defined(OS_WIN) |
3652 // TODO(port): we don't support theming on non-Windows platforms yet | 3696 // TODO(port): we don't support theming on non-Windows platforms yet |
3653 NOTIMPLEMENTED(); | 3697 NOTIMPLEMENTED(); |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4222 const webkit_glue::CustomContextMenuContext& custom_context) { | 4266 const webkit_glue::CustomContextMenuContext& custom_context) { |
4223 if (custom_context.is_pepper_menu) | 4267 if (custom_context.is_pepper_menu) |
4224 pepper_delegate_.OnContextMenuClosed(custom_context); | 4268 pepper_delegate_.OnContextMenuClosed(custom_context); |
4225 else | 4269 else |
4226 context_menu_node_.reset(); | 4270 context_menu_node_.reset(); |
4227 } | 4271 } |
4228 | 4272 |
4229 void RenderView::OnNetworkStateChanged(bool online) { | 4273 void RenderView::OnNetworkStateChanged(bool online) { |
4230 WebNetworkStateNotifier::setOnLine(online); | 4274 WebNetworkStateNotifier::setOnLine(online); |
4231 } | 4275 } |
OLD | NEW |