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 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3623 DCHECK(accessibility_ack_pending_); | 3641 DCHECK(accessibility_ack_pending_); |
3624 accessibility_ack_pending_ = false; | 3642 accessibility_ack_pending_ = false; |
3625 SendPendingAccessibilityNotifications(); | 3643 SendPendingAccessibilityNotifications(); |
3626 } | 3644 } |
3627 | 3645 |
3628 void RenderView::OnShouldClose() { | 3646 void RenderView::OnShouldClose() { |
3629 bool should_close = webview()->dispatchBeforeUnloadEvent(); | 3647 bool should_close = webview()->dispatchBeforeUnloadEvent(); |
3630 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); | 3648 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
3631 } | 3649 } |
3632 | 3650 |
3633 void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { | 3651 void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) { |
| 3652 if (is_swapped_out_) |
| 3653 return; |
| 3654 |
| 3655 // Swap this RenderView out so the tab can navigate to a page rendered by a |
| 3656 // different process. This involves running the unload handler and clearing |
| 3657 // the page. Once WasHidden is called, we also allow this process to exit |
| 3658 // if there are no other active RenderViews in it. |
| 3659 |
| 3660 // Send an UpdateState message before we get swapped out. |
| 3661 SyncNavigationState(); |
| 3662 |
| 3663 // Swap out and stop sending any IPC messages that are not ACKs. |
| 3664 SetSwappedOut(true); |
| 3665 |
| 3666 // Replace the page with a blank dummy URL, triggering the unload handler. |
| 3667 // TODO(creis): Need to add a better way to do this that avoids running the |
| 3668 // beforeunload handler. For now, we just run it a second time silently. |
| 3669 webview()->mainFrame()->loadHTMLString(std::string(), |
| 3670 GURL("about:swappedout"), |
| 3671 GURL("about:swappedout"), |
| 3672 false); |
| 3673 |
| 3674 // Just echo back the params in the ACK. |
| 3675 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); |
| 3676 } |
| 3677 |
| 3678 void RenderView::OnClosePage() { |
3634 // TODO(creis): We'd rather use webview()->Close() here, but that currently | 3679 // TODO(creis): We'd rather use webview()->Close() here, but that currently |
3635 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs | 3680 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
3636 // in the onunload handler from appearing. For now, we're bypassing that and | 3681 // in the onunload handler from appearing. For now, we're bypassing that and |
3637 // calling the FrameLoader's CloseURL method directly. This should be | 3682 // calling the FrameLoader's CloseURL method directly. This should be |
3638 // revisited to avoid having two ways to close a page. Having a single way | 3683 // revisited to avoid having two ways to close a page. Having a single way |
3639 // to close that can run onunload is also useful for fixing | 3684 // to close that can run onunload is also useful for fixing |
3640 // http://b/issue?id=753080. | 3685 // http://b/issue?id=753080. |
3641 webview()->dispatchUnloadEvent(); | 3686 webview()->dispatchUnloadEvent(); |
3642 | 3687 |
3643 // Just echo back the params in the ACK. | 3688 Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
3644 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params)); | |
3645 } | 3689 } |
3646 | 3690 |
3647 void RenderView::OnThemeChanged() { | 3691 void RenderView::OnThemeChanged() { |
3648 #if defined(OS_WIN) | 3692 #if defined(OS_WIN) |
3649 gfx::NativeThemeWin::instance()->CloseHandles(); | 3693 gfx::NativeThemeWin::instance()->CloseHandles(); |
3650 if (webview()) | 3694 if (webview()) |
3651 webview()->themeChanged(); | 3695 webview()->themeChanged(); |
3652 #else // defined(OS_WIN) | 3696 #else // defined(OS_WIN) |
3653 // TODO(port): we don't support theming on non-Windows platforms yet | 3697 // TODO(port): we don't support theming on non-Windows platforms yet |
3654 NOTIMPLEMENTED(); | 3698 NOTIMPLEMENTED(); |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4223 const webkit_glue::CustomContextMenuContext& custom_context) { | 4267 const webkit_glue::CustomContextMenuContext& custom_context) { |
4224 if (custom_context.is_pepper_menu) | 4268 if (custom_context.is_pepper_menu) |
4225 pepper_delegate_.OnContextMenuClosed(custom_context); | 4269 pepper_delegate_.OnContextMenuClosed(custom_context); |
4226 else | 4270 else |
4227 context_menu_node_.reset(); | 4271 context_menu_node_.reset(); |
4228 } | 4272 } |
4229 | 4273 |
4230 void RenderView::OnNetworkStateChanged(bool online) { | 4274 void RenderView::OnNetworkStateChanged(bool online) { |
4231 WebNetworkStateNotifier::setOnLine(online); | 4275 WebNetworkStateNotifier::setOnLine(online); |
4232 } | 4276 } |
OLD | NEW |