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

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: Merge with trunk. 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
« no previous file with comments | « content/renderer/render_view.h ('k') | content/renderer/render_widget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_)
691 SetSwappedOut(false);
692
688 history_list_offset_ = params.current_history_list_offset; 693 history_list_offset_ = params.current_history_list_offset;
689 history_list_length_ = params.current_history_list_length; 694 history_list_length_ = params.current_history_list_length;
690 695
691 content::GetContentClient()->SetActiveURL(params.url); 696 content::GetContentClient()->SetActiveURL(params.url);
692 697
693 bool is_reload = 698 bool is_reload =
694 params.navigation_type == ViewMsg_Navigate_Type::RELOAD || 699 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
695 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; 700 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
696 701
697 WebFrame* main_frame = webview()->mainFrame(); 702 WebFrame* main_frame = webview()->mainFrame();
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 UTF16ToWideHack(default_value), 1562 UTF16ToWideHack(default_value),
1558 frame->url(), 1563 frame->url(),
1559 &result); 1564 &result);
1560 if (ok) 1565 if (ok)
1561 actual_value->assign(WideToUTF16Hack(result)); 1566 actual_value->assign(WideToUTF16Hack(result));
1562 return ok; 1567 return ok;
1563 } 1568 }
1564 1569
1565 bool RenderView::runModalBeforeUnloadDialog( 1570 bool RenderView::runModalBeforeUnloadDialog(
1566 WebFrame* frame, const WebString& message) { 1571 WebFrame* frame, const WebString& message) {
1572 // If we are swapping out, we have already run the beforeunload handler.
1573 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1574 // at all, to avoid running it twice.
1575 if (is_swapped_out_)
1576 return true;
1577
1567 bool success = false; 1578 bool success = false;
1568 // This is an ignored return value, but is included so we can accept the same 1579 // This is an ignored return value, but is included so we can accept the same
1569 // response as RunJavaScriptMessage. 1580 // response as RunJavaScriptMessage.
1570 std::wstring ignored_result; 1581 std::wstring ignored_result;
1571 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( 1582 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
1572 routing_id_, frame->url(), UTF16ToWideHack(message), &success, 1583 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
1573 &ignored_result)); 1584 &ignored_result));
1574 return success; 1585 return success;
1575 } 1586 }
1576 1587
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1919 if (policy == WebKit::WebNavigationPolicyDownload) { 1930 if (policy == WebKit::WebNavigationPolicyDownload) {
1920 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); 1931 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1921 } else { 1932 } else {
1922 OpenURL(request.url(), referrer, policy); 1933 OpenURL(request.url(), referrer, policy);
1923 } 1934 }
1924 } 1935 }
1925 1936
1926 WebNavigationPolicy RenderView::decidePolicyForNavigation( 1937 WebNavigationPolicy RenderView::decidePolicyForNavigation(
1927 WebFrame* frame, const WebURLRequest& request, WebNavigationType type, 1938 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
1928 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { 1939 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
1940 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
1941 if (is_swapped_out_) {
1942 DCHECK(request.url() == GURL("about:swappedout"));
1943 return default_policy;
1944 }
1945
1929 // Webkit is asking whether to navigate to a new URL. 1946 // Webkit is asking whether to navigate to a new URL.
1930 // This is fine normally, except if we're showing UI from one security 1947 // 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. 1948 // context and they're trying to navigate to a different context.
1932 const GURL& url = request.url(); 1949 const GURL& url = request.url();
1933 1950
1934 // A content initiated navigation may have originated from a link-click, 1951 // A content initiated navigation may have originated from a link-click,
1935 // script, drag-n-drop operation, etc. 1952 // script, drag-n-drop operation, etc.
1936 bool is_content_initiated = 1953 bool is_content_initiated =
1937 NavigationState::FromDataSource(frame->provisionalDataSource())-> 1954 NavigationState::FromDataSource(frame->provisionalDataSource())->
1938 is_content_initiated(); 1955 is_content_initiated();
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after
3503 DCHECK(accessibility_ack_pending_); 3520 DCHECK(accessibility_ack_pending_);
3504 accessibility_ack_pending_ = false; 3521 accessibility_ack_pending_ = false;
3505 SendPendingAccessibilityNotifications(); 3522 SendPendingAccessibilityNotifications();
3506 } 3523 }
3507 3524
3508 void RenderView::OnShouldClose() { 3525 void RenderView::OnShouldClose() {
3509 bool should_close = webview()->dispatchBeforeUnloadEvent(); 3526 bool should_close = webview()->dispatchBeforeUnloadEvent();
3510 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); 3527 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
3511 } 3528 }
3512 3529
3513 void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { 3530 void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3531 if (is_swapped_out_)
3532 return;
3533
3534 // Swap this RenderView out so the tab can navigate to a page rendered by a
3535 // different process. This involves running the unload handler and clearing
3536 // the page. Once WasSwappedOut is called, we also allow this process to exit
3537 // if there are no other active RenderViews in it.
3538
3539 // Send an UpdateState message before we get swapped out.
3540 SyncNavigationState();
3541
3542 // Synchronously run the unload handler before sending the ACK.
3543 webview()->dispatchUnloadEvent();
3544
3545 // Swap out and stop sending any IPC messages that are not ACKs.
3546 SetSwappedOut(true);
3547
3548 // Replace the page with a blank dummy URL. The unload handler will not be
3549 // run a second time, thanks to a check in FrameLoader::stopLoading.
3550 // TODO(creis): Need to add a better way to do this that avoids running the
3551 // beforeunload handler. For now, we just run it a second time silently.
3552 webview()->mainFrame()->loadHTMLString(std::string(),
3553 GURL("about:swappedout"),
3554 GURL("about:swappedout"),
3555 false);
3556
3557 // Just echo back the params in the ACK.
3558 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3559 }
3560
3561 void RenderView::OnClosePage() {
3514 // TODO(creis): We'd rather use webview()->Close() here, but that currently 3562 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3515 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs 3563 // 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 3564 // in the onunload handler from appearing. For now, we're bypassing that and
3517 // calling the FrameLoader's CloseURL method directly. This should be 3565 // 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 3566 // 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 3567 // to close that can run onunload is also useful for fixing
3520 // http://b/issue?id=753080. 3568 // http://b/issue?id=753080.
3521 webview()->dispatchUnloadEvent(); 3569 webview()->dispatchUnloadEvent();
3522 3570
3523 // Just echo back the params in the ACK. 3571 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
3524 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
3525 } 3572 }
3526 3573
3527 void RenderView::OnThemeChanged() { 3574 void RenderView::OnThemeChanged() {
3528 #if defined(OS_WIN) 3575 #if defined(OS_WIN)
3529 gfx::NativeThemeWin::instance()->CloseHandles(); 3576 gfx::NativeThemeWin::instance()->CloseHandles();
3530 if (webview()) 3577 if (webview())
3531 webview()->themeChanged(); 3578 webview()->themeChanged();
3532 #else // defined(OS_WIN) 3579 #else // defined(OS_WIN)
3533 // TODO(port): we don't support theming on non-Windows platforms yet 3580 // TODO(port): we don't support theming on non-Windows platforms yet
3534 NOTIMPLEMENTED(); 3581 NOTIMPLEMENTED();
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
4103 const webkit_glue::CustomContextMenuContext& custom_context) { 4150 const webkit_glue::CustomContextMenuContext& custom_context) {
4104 if (custom_context.is_pepper_menu) 4151 if (custom_context.is_pepper_menu)
4105 pepper_delegate_.OnContextMenuClosed(custom_context); 4152 pepper_delegate_.OnContextMenuClosed(custom_context);
4106 else 4153 else
4107 context_menu_node_.reset(); 4154 context_menu_node_.reset();
4108 } 4155 }
4109 4156
4110 void RenderView::OnNetworkStateChanged(bool online) { 4157 void RenderView::OnNetworkStateChanged(bool online) {
4111 WebNetworkStateNotifier::setOnLine(online); 4158 WebNetworkStateNotifier::setOnLine(online);
4112 } 4159 }
OLDNEW
« no previous file with comments | « content/renderer/render_view.h ('k') | content/renderer/render_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698