Chromium Code Reviews| 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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 webkit_preferences_(webkit_prefs), | 474 webkit_preferences_(webkit_prefs), |
| 475 send_content_state_immediately_(false), | 475 send_content_state_immediately_(false), |
| 476 enabled_bindings_(0), | 476 enabled_bindings_(0), |
| 477 send_preferred_size_changes_(false), | 477 send_preferred_size_changes_(false), |
| 478 script_can_close_(true), | 478 script_can_close_(true), |
| 479 is_loading_(false), | 479 is_loading_(false), |
| 480 navigation_gesture_(NavigationGestureUnknown), | 480 navigation_gesture_(NavigationGestureUnknown), |
| 481 opened_by_user_gesture_(true), | 481 opened_by_user_gesture_(true), |
| 482 opener_suppressed_(false), | 482 opener_suppressed_(false), |
| 483 is_prerendering_(false), | 483 is_prerendering_(false), |
| 484 is_swapped_out_(false), | |
| 484 page_id_(-1), | 485 page_id_(-1), |
| 485 last_page_id_sent_to_browser_(-1), | 486 last_page_id_sent_to_browser_(-1), |
| 486 last_indexed_page_id_(-1), | 487 last_indexed_page_id_(-1), |
| 487 history_list_offset_(-1), | 488 history_list_offset_(-1), |
| 488 history_list_length_(0), | 489 history_list_length_(0), |
| 489 has_unload_listener_(false), | 490 has_unload_listener_(false), |
| 490 target_url_status_(TARGET_NONE), | 491 target_url_status_(TARGET_NONE), |
| 491 view_type_(ViewType::INVALID), | 492 view_type_(ViewType::INVALID), |
| 492 browser_window_id_(-1), | 493 browser_window_id_(-1), |
| 493 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), | 494 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 | 657 |
| 657 void RenderView::AddObserver(RenderViewObserver* observer) { | 658 void RenderView::AddObserver(RenderViewObserver* observer) { |
| 658 observers_.AddObserver(observer); | 659 observers_.AddObserver(observer); |
| 659 } | 660 } |
| 660 | 661 |
| 661 void RenderView::RemoveObserver(RenderViewObserver* observer) { | 662 void RenderView::RemoveObserver(RenderViewObserver* observer) { |
| 662 observer->set_render_view(NULL); | 663 observer->set_render_view(NULL); |
| 663 observers_.RemoveObserver(observer); | 664 observers_.RemoveObserver(observer); |
| 664 } | 665 } |
| 665 | 666 |
| 667 void RenderView::SwapIn() { | |
| 668 DCHECK(is_swapped_out_); | |
| 669 is_swapped_out_ = false; | |
| 670 | |
| 671 // Increment the ChildProcess's ref count now that this RenderView is active | |
| 672 // again. This prevents the process from exiting. | |
| 673 RenderProcess::current()->AddRefProcess(); | |
| 674 } | |
| 675 | |
| 666 bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() { | 676 bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() { |
| 667 typedef ViewHostMsg_AccessibilityNotification_Params params; | 677 typedef ViewHostMsg_AccessibilityNotification_Params params; |
| 668 if (type == WebKit::WebAccessibilityNotificationChildrenChanged || | 678 if (type == WebKit::WebAccessibilityNotificationChildrenChanged || |
| 669 type == WebKit::WebAccessibilityNotificationLoadComplete) { | 679 type == WebKit::WebAccessibilityNotificationLoadComplete) { |
| 670 return true; | 680 return true; |
| 671 } | 681 } |
| 672 return false; | 682 return false; |
| 673 } | 683 } |
| 674 | 684 |
| 675 WebKit::WebView* RenderView::webview() const { | 685 WebKit::WebView* RenderView::webview() const { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 OnDisplayPrerenderedPage) | 948 OnDisplayPrerenderedPage) |
| 939 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) | 949 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
| 940 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) | 950 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
| 941 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, | 951 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 942 OnGetAllSavableResourceLinksForCurrentPage) | 952 OnGetAllSavableResourceLinksForCurrentPage) |
| 943 IPC_MESSAGE_HANDLER( | 953 IPC_MESSAGE_HANDLER( |
| 944 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, | 954 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 945 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) | 955 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
| 946 IPC_MESSAGE_HANDLER(ExtensionMsg_GetApplicationInfo, OnGetApplicationInfo) | 956 IPC_MESSAGE_HANDLER(ExtensionMsg_GetApplicationInfo, OnGetApplicationInfo) |
| 947 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) | 957 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
| 958 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut) | |
| 948 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) | 959 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 949 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) | 960 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
| 950 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, | 961 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, |
| 951 OnHandleMessageFromExternalHost) | 962 OnHandleMessageFromExternalHost) |
| 952 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, | 963 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 953 OnDisassociateFromPopupCount) | 964 OnDisassociateFromPopupCount) |
| 954 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose, | 965 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose, |
| 955 OnAllowScriptToClose) | 966 OnAllowScriptToClose) |
| 956 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) | 967 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
| 957 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) | 968 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1226 | 1237 |
| 1227 HISTOGRAM_TIMES("Renderer4.Snapshot", | 1238 HISTOGRAM_TIMES("Renderer4.Snapshot", |
| 1228 base::TimeTicks::Now() - beginning_time); | 1239 base::TimeTicks::Now() - beginning_time); |
| 1229 return true; | 1240 return true; |
| 1230 } | 1241 } |
| 1231 | 1242 |
| 1232 void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { | 1243 void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { |
| 1233 if (!webview()) | 1244 if (!webview()) |
| 1234 return; | 1245 return; |
| 1235 | 1246 |
| 1247 // Swap this renderer back in if necessary. | |
| 1248 if (is_swapped_out_) { | |
| 1249 SwapIn(); | |
| 1250 } | |
| 1251 | |
| 1236 history_list_offset_ = params.current_history_list_offset; | 1252 history_list_offset_ = params.current_history_list_offset; |
| 1237 history_list_length_ = params.current_history_list_length; | 1253 history_list_length_ = params.current_history_list_length; |
| 1238 | 1254 |
| 1239 child_process_logging::SetActiveURL(params.url); | 1255 child_process_logging::SetActiveURL(params.url); |
| 1240 | 1256 |
| 1241 AboutHandler::MaybeHandle(params.url); | 1257 AboutHandler::MaybeHandle(params.url); |
| 1242 | 1258 |
| 1243 bool is_reload = | 1259 bool is_reload = |
| 1244 params.navigation_type == ViewMsg_Navigate_Type::RELOAD || | 1260 params.navigation_type == ViewMsg_Navigate_Type::RELOAD || |
| 1245 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; | 1261 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1480 | 1496 |
| 1481 // Tell the embedding application that the URL of the active page has changed | 1497 // Tell the embedding application that the URL of the active page has changed |
| 1482 void RenderView::UpdateURL(WebFrame* frame) { | 1498 void RenderView::UpdateURL(WebFrame* frame) { |
| 1483 WebDataSource* ds = frame->dataSource(); | 1499 WebDataSource* ds = frame->dataSource(); |
| 1484 DCHECK(ds); | 1500 DCHECK(ds); |
| 1485 | 1501 |
| 1486 const WebURLRequest& request = ds->request(); | 1502 const WebURLRequest& request = ds->request(); |
| 1487 const WebURLRequest& original_request = ds->originalRequest(); | 1503 const WebURLRequest& original_request = ds->originalRequest(); |
| 1488 const WebURLResponse& response = ds->response(); | 1504 const WebURLResponse& response = ds->response(); |
| 1489 | 1505 |
| 1506 // Don't send an update if this renderer is swapped out. | |
| 1507 // TODO(creis): This won't be necessary once OnSwapOut is fixed to clear | |
| 1508 // the frame without a full navigation. | |
| 1509 if (is_swapped_out_) { | |
| 1510 DCHECK(request.url() == GURL(chrome::kAboutBlankURL)); | |
| 1511 return; | |
| 1512 } | |
| 1513 | |
| 1490 NavigationState* navigation_state = NavigationState::FromDataSource(ds); | 1514 NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 1491 DCHECK(navigation_state); | 1515 DCHECK(navigation_state); |
| 1492 | 1516 |
| 1493 ViewHostMsg_FrameNavigate_Params params; | 1517 ViewHostMsg_FrameNavigate_Params params; |
| 1494 params.http_status_code = response.httpStatusCode(); | 1518 params.http_status_code = response.httpStatusCode(); |
| 1495 params.is_post = false; | 1519 params.is_post = false; |
| 1496 params.page_id = page_id_; | 1520 params.page_id = page_id_; |
| 1497 params.frame_id = frame->identifier(); | 1521 params.frame_id = frame->identifier(); |
| 1498 params.socket_address.set_host(response.remoteIPAddress().utf8()); | 1522 params.socket_address.set_host(response.remoteIPAddress().utf8()); |
| 1499 params.socket_address.set_port(response.remotePort()); | 1523 params.socket_address.set_port(response.remotePort()); |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2169 UTF16ToWideHack(default_value), | 2193 UTF16ToWideHack(default_value), |
| 2170 frame->url(), | 2194 frame->url(), |
| 2171 &result); | 2195 &result); |
| 2172 if (ok) | 2196 if (ok) |
| 2173 actual_value->assign(WideToUTF16Hack(result)); | 2197 actual_value->assign(WideToUTF16Hack(result)); |
| 2174 return ok; | 2198 return ok; |
| 2175 } | 2199 } |
| 2176 | 2200 |
| 2177 bool RenderView::runModalBeforeUnloadDialog( | 2201 bool RenderView::runModalBeforeUnloadDialog( |
| 2178 WebFrame* frame, const WebString& message) { | 2202 WebFrame* frame, const WebString& message) { |
| 2203 // If we are swapping out, we have already run the beforeunload handler. | |
| 2204 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload | |
| 2205 // at all, to avoid running it twice. | |
| 2206 if (is_swapped_out_) | |
| 2207 return true; | |
| 2208 | |
| 2179 bool success = false; | 2209 bool success = false; |
| 2180 // This is an ignored return value, but is included so we can accept the same | 2210 // This is an ignored return value, but is included so we can accept the same |
| 2181 // response as RunJavaScriptMessage. | 2211 // response as RunJavaScriptMessage. |
| 2182 std::wstring ignored_result; | 2212 std::wstring ignored_result; |
| 2183 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( | 2213 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
| 2184 routing_id_, frame->url(), UTF16ToWideHack(message), &success, | 2214 routing_id_, frame->url(), UTF16ToWideHack(message), &success, |
| 2185 &ignored_result)); | 2215 &ignored_result)); |
| 2186 return success; | 2216 return success; |
| 2187 } | 2217 } |
| 2188 | 2218 |
| (...skipping 2231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4420 frame_url, | 4450 frame_url, |
| 4421 data.data(), | 4451 data.data(), |
| 4422 static_cast<int32>(status))); | 4452 static_cast<int32>(status))); |
| 4423 } | 4453 } |
| 4424 | 4454 |
| 4425 void RenderView::OnShouldClose() { | 4455 void RenderView::OnShouldClose() { |
| 4426 bool should_close = webview()->dispatchBeforeUnloadEvent(); | 4456 bool should_close = webview()->dispatchBeforeUnloadEvent(); |
| 4427 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); | 4457 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
| 4428 } | 4458 } |
| 4429 | 4459 |
| 4430 void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { | 4460 void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) { |
| 4461 // Swap this RenderView out so the tab can navigate to a page rendered by a | |
| 4462 // different process. This involves running the unload handler, clearing | |
| 4463 // the page, and allowing the process to exit if there are no other active | |
| 4464 // RenderViews in it. | |
| 4465 DCHECK(!is_swapped_out_); | |
| 4466 is_swapped_out_ = true; | |
| 4467 | |
| 4468 // TODO(davemoore) This code should be removed once willClose() gets | |
| 4469 // called when a page is destroyed. page_load_histograms_.Dump() is safe | |
| 4470 // to call multiple times for the same frame, but it will simplify things. | |
| 4471 page_load_histograms_.Dump(webview()->mainFrame()); | |
| 4472 page_load_histograms_.ResetCrossFramePropertyAccess(); | |
| 4473 | |
| 4474 // Send an UpdateState message before we get swapped out. | |
| 4475 SyncNavigationState(); | |
| 4476 | |
| 4477 // Replace the page with a blank dummy URL, triggering the unload handler. | |
| 4478 // TODO(creis): Need to add a better way to do this that avoids running the | |
| 4479 // beforeunload handler and that can't match an existing URL. | |
| 4480 WebURLRequest request(GURL(chrome::kAboutBlankURL)); | |
| 4481 webview()->mainFrame()->loadRequest(request); | |
|
Charlie Reis
2011/04/13 22:57:21
This is the main sticking point right now. We nee
| |
| 4482 | |
| 4483 // Just echo back the params in the ACK. | |
| 4484 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params)); | |
| 4485 | |
| 4486 // Remove this RenderView from the ChildProcess's ref count, allowing the | |
| 4487 // process to exit if all of the RenderViews are swapped out. We will | |
| 4488 // increment the count if this RenderView is swapped back in. | |
| 4489 RenderProcess::current()->ReleaseProcess(); | |
| 4490 } | |
| 4491 | |
| 4492 void RenderView::OnClosePage() { | |
| 4431 // TODO(creis): We'd rather use webview()->Close() here, but that currently | 4493 // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 4432 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs | 4494 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 4433 // in the onunload handler from appearing. For now, we're bypassing that and | 4495 // in the onunload handler from appearing. For now, we're bypassing that and |
| 4434 // calling the FrameLoader's CloseURL method directly. This should be | 4496 // calling the FrameLoader's CloseURL method directly. This should be |
| 4435 // revisited to avoid having two ways to close a page. Having a single way | 4497 // revisited to avoid having two ways to close a page. Having a single way |
| 4436 // to close that can run onunload is also useful for fixing | 4498 // to close that can run onunload is also useful for fixing |
| 4437 // http://b/issue?id=753080. | 4499 // http://b/issue?id=753080. |
| 4438 // TODO(davemoore) This code should be removed once willClose() gets | 4500 // TODO(davemoore) This code should be removed once willClose() gets |
| 4439 // called when a page is destroyed. page_load_histograms_.Dump() is safe | 4501 // called when a page is destroyed. page_load_histograms_.Dump() is safe |
| 4440 // to call multiple times for the same frame, but it will simplify things. | 4502 // to call multiple times for the same frame, but it will simplify things. |
| 4441 page_load_histograms_.Dump(webview()->mainFrame()); | 4503 page_load_histograms_.Dump(webview()->mainFrame()); |
| 4442 page_load_histograms_.ResetCrossFramePropertyAccess(); | 4504 page_load_histograms_.ResetCrossFramePropertyAccess(); |
| 4443 webview()->dispatchUnloadEvent(); | 4505 webview()->dispatchUnloadEvent(); |
| 4444 | 4506 |
| 4445 // Just echo back the params in the ACK. | 4507 Send(new ViewHostMsg_ClosePage_ACK(routing_id_)); |
| 4446 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params)); | |
| 4447 } | 4508 } |
| 4448 | 4509 |
| 4449 void RenderView::OnThemeChanged() { | 4510 void RenderView::OnThemeChanged() { |
| 4450 #if defined(OS_WIN) | 4511 #if defined(OS_WIN) |
| 4451 gfx::NativeThemeWin::instance()->CloseHandles(); | 4512 gfx::NativeThemeWin::instance()->CloseHandles(); |
| 4452 if (webview()) | 4513 if (webview()) |
| 4453 webview()->themeChanged(); | 4514 webview()->themeChanged(); |
| 4454 #else // defined(OS_WIN) | 4515 #else // defined(OS_WIN) |
| 4455 // TODO(port): we don't support theming on non-Windows platforms yet | 4516 // TODO(port): we don't support theming on non-Windows platforms yet |
| 4456 NOTIMPLEMENTED(); | 4517 NOTIMPLEMENTED(); |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5060 const webkit_glue::CustomContextMenuContext& custom_context) { | 5121 const webkit_glue::CustomContextMenuContext& custom_context) { |
| 5061 if (custom_context.is_pepper_menu) | 5122 if (custom_context.is_pepper_menu) |
| 5062 pepper_delegate_.OnContextMenuClosed(custom_context); | 5123 pepper_delegate_.OnContextMenuClosed(custom_context); |
| 5063 else | 5124 else |
| 5064 context_menu_node_.reset(); | 5125 context_menu_node_.reset(); |
| 5065 } | 5126 } |
| 5066 | 5127 |
| 5067 void RenderView::OnNetworkStateChanged(bool online) { | 5128 void RenderView::OnNetworkStateChanged(bool online) { |
| 5068 WebNetworkStateNotifier::setOnLine(online); | 5129 WebNetworkStateNotifier::setOnLine(online); |
| 5069 } | 5130 } |
| OLD | NEW |