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

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

Issue 6319001: Support window.opener after a process swap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Abstract out message filtering code. Created 9 years, 7 months 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
OLDNEW
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 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView, 625 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
626 OnScrollFocusedEditableNodeIntoView) 626 OnScrollFocusedEditableNodeIntoView)
627 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) 627 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
628 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) 628 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
629 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) 629 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
630 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) 630 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
631 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, 631 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
632 OnEnumerateDirectoryResponse) 632 OnEnumerateDirectoryResponse)
633 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) 633 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
634 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) 634 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
635 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
635 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) 636 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
636 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) 637 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
637 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, 638 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
638 OnDisassociateFromPopupCount) 639 OnDisassociateFromPopupCount)
639 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) 640 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
640 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) 641 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
641 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) 642 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
642 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, 643 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
643 OnEnablePreferredSizeChangedMode) 644 OnEnablePreferredSizeChangedMode)
644 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, 645 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 // Have the super handle all other messages. 679 // Have the super handle all other messages.
679 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message)) 680 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
680 IPC_END_MESSAGE_MAP() 681 IPC_END_MESSAGE_MAP()
681 return handled; 682 return handled;
682 } 683 }
683 684
684 void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { 685 void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
685 if (!webview()) 686 if (!webview())
686 return; 687 return;
687 688
689 // Swap this renderer back in if necessary.
690 if (is_swapped_out_) {
jam 2011/05/11 20:19:31 nit: most of this file doesn't use brace brackets
Charlie Reis 2011/05/11 20:49:15 Done.
691 SetSwappedOut(false);
692 }
693
688 history_list_offset_ = params.current_history_list_offset; 694 history_list_offset_ = params.current_history_list_offset;
689 history_list_length_ = params.current_history_list_length; 695 history_list_length_ = params.current_history_list_length;
690 696
691 content::GetContentClient()->SetActiveURL(params.url); 697 content::GetContentClient()->SetActiveURL(params.url);
692 698
693 bool is_reload = 699 bool is_reload =
694 params.navigation_type == ViewMsg_Navigate_Type::RELOAD || 700 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
695 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; 701 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
696 702
697 WebFrame* main_frame = webview()->mainFrame(); 703 WebFrame* main_frame = webview()->mainFrame();
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 UTF16ToWideHack(default_value), 1563 UTF16ToWideHack(default_value),
1558 frame->url(), 1564 frame->url(),
1559 &result); 1565 &result);
1560 if (ok) 1566 if (ok)
1561 actual_value->assign(WideToUTF16Hack(result)); 1567 actual_value->assign(WideToUTF16Hack(result));
1562 return ok; 1568 return ok;
1563 } 1569 }
1564 1570
1565 bool RenderView::runModalBeforeUnloadDialog( 1571 bool RenderView::runModalBeforeUnloadDialog(
1566 WebFrame* frame, const WebString& message) { 1572 WebFrame* frame, const WebString& message) {
1573 // If we are swapping out, we have already run the beforeunload handler.
1574 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1575 // at all, to avoid running it twice.
1576 if (is_swapped_out_)
1577 return true;
1578
1567 bool success = false; 1579 bool success = false;
1568 // This is an ignored return value, but is included so we can accept the same 1580 // This is an ignored return value, but is included so we can accept the same
1569 // response as RunJavaScriptMessage. 1581 // response as RunJavaScriptMessage.
1570 std::wstring ignored_result; 1582 std::wstring ignored_result;
1571 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( 1583 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
1572 routing_id_, frame->url(), UTF16ToWideHack(message), &success, 1584 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
1573 &ignored_result)); 1585 &ignored_result));
1574 return success; 1586 return success;
1575 } 1587 }
1576 1588
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1919 if (policy == WebKit::WebNavigationPolicyDownload) { 1931 if (policy == WebKit::WebNavigationPolicyDownload) {
1920 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); 1932 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1921 } else { 1933 } else {
1922 OpenURL(request.url(), referrer, policy); 1934 OpenURL(request.url(), referrer, policy);
1923 } 1935 }
1924 } 1936 }
1925 1937
1926 WebNavigationPolicy RenderView::decidePolicyForNavigation( 1938 WebNavigationPolicy RenderView::decidePolicyForNavigation(
1927 WebFrame* frame, const WebURLRequest& request, WebNavigationType type, 1939 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
1928 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { 1940 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
1941 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
1942 if (is_swapped_out_) {
1943 DCHECK(request.url() == GURL("about:swappedout"));
1944 return default_policy;
1945 }
1946
1929 // Webkit is asking whether to navigate to a new URL. 1947 // Webkit is asking whether to navigate to a new URL.
1930 // This is fine normally, except if we're showing UI from one security 1948 // This is fine normally, except if we're showing UI from one security
1931 // context and they're trying to navigate to a different context. 1949 // context and they're trying to navigate to a different context.
1932 const GURL& url = request.url(); 1950 const GURL& url = request.url();
1933 1951
1934 // A content initiated navigation may have originated from a link-click, 1952 // A content initiated navigation may have originated from a link-click,
1935 // script, drag-n-drop operation, etc. 1953 // script, drag-n-drop operation, etc.
1936 bool is_content_initiated = 1954 bool is_content_initiated =
1937 NavigationState::FromDataSource(frame->provisionalDataSource())-> 1955 NavigationState::FromDataSource(frame->provisionalDataSource())->
1938 is_content_initiated(); 1956 is_content_initiated();
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after
3503 DCHECK(accessibility_ack_pending_); 3521 DCHECK(accessibility_ack_pending_);
3504 accessibility_ack_pending_ = false; 3522 accessibility_ack_pending_ = false;
3505 SendPendingAccessibilityNotifications(); 3523 SendPendingAccessibilityNotifications();
3506 } 3524 }
3507 3525
3508 void RenderView::OnShouldClose() { 3526 void RenderView::OnShouldClose() {
3509 bool should_close = webview()->dispatchBeforeUnloadEvent(); 3527 bool should_close = webview()->dispatchBeforeUnloadEvent();
3510 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); 3528 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
3511 } 3529 }
3512 3530
3513 void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { 3531 void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3532 if (is_swapped_out_)
3533 return;
3534
3535 // Swap this RenderView out so the tab can navigate to a page rendered by a
3536 // different process. This involves running the unload handler and clearing
3537 // the page. Once WasSwappedOut is called, we also allow this process to exit
3538 // if there are no other active RenderViews in it.
3539
3540 // Send an UpdateState message before we get swapped out.
3541 SyncNavigationState();
3542
3543 // Synchronously run the unload handler before sending the ACK.
3544 webview()->dispatchUnloadEvent();
3545
3546 // Swap out and stop sending any IPC messages that are not ACKs.
3547 SetSwappedOut(true);
3548
3549 // Replace the page with a blank dummy URL. The unload handler will not be
3550 // run a second time, thanks to a check in FrameLoader::stopLoading.
3551 // TODO(creis): Need to add a better way to do this that avoids running the
3552 // beforeunload handler. For now, we just run it a second time silently.
3553 webview()->mainFrame()->loadHTMLString(std::string(),
3554 GURL("about:swappedout"),
3555 GURL("about:swappedout"),
3556 false);
3557
3558 // Just echo back the params in the ACK.
3559 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3560 }
3561
3562 void RenderView::OnClosePage() {
3514 // TODO(creis): We'd rather use webview()->Close() here, but that currently 3563 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3515 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs 3564 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3516 // in the onunload handler from appearing. For now, we're bypassing that and 3565 // in the onunload handler from appearing. For now, we're bypassing that and
3517 // calling the FrameLoader's CloseURL method directly. This should be 3566 // calling the FrameLoader's CloseURL method directly. This should be
3518 // revisited to avoid having two ways to close a page. Having a single way 3567 // revisited to avoid having two ways to close a page. Having a single way
3519 // to close that can run onunload is also useful for fixing 3568 // to close that can run onunload is also useful for fixing
3520 // http://b/issue?id=753080. 3569 // http://b/issue?id=753080.
3521 webview()->dispatchUnloadEvent(); 3570 webview()->dispatchUnloadEvent();
3522 3571
3523 // Just echo back the params in the ACK. 3572 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
3524 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
3525 } 3573 }
3526 3574
3527 void RenderView::OnThemeChanged() { 3575 void RenderView::OnThemeChanged() {
3528 #if defined(OS_WIN) 3576 #if defined(OS_WIN)
3529 gfx::NativeThemeWin::instance()->CloseHandles(); 3577 gfx::NativeThemeWin::instance()->CloseHandles();
3530 if (webview()) 3578 if (webview())
3531 webview()->themeChanged(); 3579 webview()->themeChanged();
3532 #else // defined(OS_WIN) 3580 #else // defined(OS_WIN)
3533 // TODO(port): we don't support theming on non-Windows platforms yet 3581 // TODO(port): we don't support theming on non-Windows platforms yet
3534 NOTIMPLEMENTED(); 3582 NOTIMPLEMENTED();
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
4103 const webkit_glue::CustomContextMenuContext& custom_context) { 4151 const webkit_glue::CustomContextMenuContext& custom_context) {
4104 if (custom_context.is_pepper_menu) 4152 if (custom_context.is_pepper_menu)
4105 pepper_delegate_.OnContextMenuClosed(custom_context); 4153 pepper_delegate_.OnContextMenuClosed(custom_context);
4106 else 4154 else
4107 context_menu_node_.reset(); 4155 context_menu_node_.reset();
4108 } 4156 }
4109 4157
4110 void RenderView::OnNetworkStateChanged(bool online) { 4158 void RenderView::OnNetworkStateChanged(bool online) {
4111 WebNetworkStateNotifier::setOnLine(online); 4159 WebNetworkStateNotifier::setOnLine(online);
4112 } 4160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698