| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/renderer_host/render_view_host_impl.h" | 5 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 is_active_(!swapped_out), | 217 is_active_(!swapped_out), |
| 218 is_pending_deletion_(false), | 218 is_pending_deletion_(false), |
| 219 is_swapped_out_(swapped_out), | 219 is_swapped_out_(swapped_out), |
| 220 main_frame_routing_id_(main_frame_routing_id), | 220 main_frame_routing_id_(main_frame_routing_id), |
| 221 is_waiting_for_close_ack_(false), | 221 is_waiting_for_close_ack_(false), |
| 222 sudden_termination_allowed_(false), | 222 sudden_termination_allowed_(false), |
| 223 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), | 223 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 224 virtual_keyboard_requested_(false), | 224 virtual_keyboard_requested_(false), |
| 225 is_focused_element_editable_(false), | 225 is_focused_element_editable_(false), |
| 226 updating_web_preferences_(false), | 226 updating_web_preferences_(false), |
| 227 render_view_ready_on_process_launch_(false), |
| 227 weak_factory_(this) { | 228 weak_factory_(this) { |
| 228 DCHECK(instance_.get()); | 229 DCHECK(instance_.get()); |
| 229 CHECK(delegate_); // http://crbug.com/82827 | 230 CHECK(delegate_); // http://crbug.com/82827 |
| 230 | 231 |
| 231 GetProcess()->AddObserver(this); | 232 GetProcess()->AddObserver(this); |
| 232 GetProcess()->EnableSendQueue(); | 233 GetProcess()->EnableSendQueue(); |
| 233 | 234 |
| 234 if (ResourceDispatcherHostImpl::Get()) { | 235 if (ResourceDispatcherHostImpl::Get()) { |
| 235 bool has_active_audio = false; | 236 bool has_active_audio = false; |
| 236 if (has_initialized_audio_host) { | 237 if (has_initialized_audio_host) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 Send(new ViewMsg_AllowBindings(GetRoutingID(), enabled_bindings_)); | 345 Send(new ViewMsg_AllowBindings(GetRoutingID(), enabled_bindings_)); |
| 345 // Let our delegate know that we created a RenderView. | 346 // Let our delegate know that we created a RenderView. |
| 346 delegate_->RenderViewCreated(this); | 347 delegate_->RenderViewCreated(this); |
| 347 | 348 |
| 348 // Since this method can create the main RenderFrame in the renderer process, | 349 // Since this method can create the main RenderFrame in the renderer process, |
| 349 // set the proper state on its corresponding RenderFrameHost. | 350 // set the proper state on its corresponding RenderFrameHost. |
| 350 if (main_frame_routing_id_ != MSG_ROUTING_NONE) { | 351 if (main_frame_routing_id_ != MSG_ROUTING_NONE) { |
| 351 RenderFrameHostImpl::FromID(GetProcess()->GetID(), main_frame_routing_id_) | 352 RenderFrameHostImpl::FromID(GetProcess()->GetID(), main_frame_routing_id_) |
| 352 ->SetRenderFrameCreated(true); | 353 ->SetRenderFrameCreated(true); |
| 353 } | 354 } |
| 355 SendScreenRects(); |
| 356 PostRenderViewReady(); |
| 354 | 357 |
| 355 return true; | 358 return true; |
| 356 } | 359 } |
| 357 | 360 |
| 358 bool RenderViewHostImpl::IsRenderViewLive() const { | 361 bool RenderViewHostImpl::IsRenderViewLive() const { |
| 359 return GetProcess()->HasConnection() && renderer_initialized(); | 362 return GetProcess()->HasConnection() && renderer_initialized(); |
| 360 } | 363 } |
| 361 | 364 |
| 362 void RenderViewHostImpl::SyncRendererPrefs() { | 365 void RenderViewHostImpl::SyncRendererPrefs() { |
| 363 RendererPreferences renderer_preferences = | 366 RendererPreferences renderer_preferences = |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 float y) { | 578 float y) { |
| 576 Send(new InputMsg_ActivateNearestFindResult(GetRoutingID(), | 579 Send(new InputMsg_ActivateNearestFindResult(GetRoutingID(), |
| 577 request_id, x, y)); | 580 request_id, x, y)); |
| 578 } | 581 } |
| 579 | 582 |
| 580 void RenderViewHostImpl::RequestFindMatchRects(int current_version) { | 583 void RenderViewHostImpl::RequestFindMatchRects(int current_version) { |
| 581 Send(new ViewMsg_FindMatchRects(GetRoutingID(), current_version)); | 584 Send(new ViewMsg_FindMatchRects(GetRoutingID(), current_version)); |
| 582 } | 585 } |
| 583 #endif | 586 #endif |
| 584 | 587 |
| 588 void RenderViewHostImpl::RenderProcessReady(RenderProcessHost* host) { |
| 589 if (render_view_ready_on_process_launch_) { |
| 590 render_view_ready_on_process_launch_ = false; |
| 591 RenderViewReady(); |
| 592 } |
| 593 } |
| 594 |
| 585 void RenderViewHostImpl::RenderProcessExited(RenderProcessHost* host, | 595 void RenderViewHostImpl::RenderProcessExited(RenderProcessHost* host, |
| 586 base::TerminationStatus status, | 596 base::TerminationStatus status, |
| 587 int exit_code) { | 597 int exit_code) { |
| 588 if (!renderer_initialized()) | 598 if (!renderer_initialized()) |
| 589 return; | 599 return; |
| 590 | 600 |
| 591 RenderWidgetHostImpl::RendererExited(status, exit_code); | 601 RenderWidgetHostImpl::RendererExited(status, exit_code); |
| 592 delegate_->RenderViewTerminated(this, status, exit_code); | 602 delegate_->RenderViewTerminated(this, status, exit_code); |
| 593 } | 603 } |
| 594 | 604 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 if (delegate_->OnMessageReceived(this, msg)) | 906 if (delegate_->OnMessageReceived(this, msg)) |
| 897 return true; | 907 return true; |
| 898 | 908 |
| 899 bool handled = true; | 909 bool handled = true; |
| 900 IPC_BEGIN_MESSAGE_MAP(RenderViewHostImpl, msg) | 910 IPC_BEGIN_MESSAGE_MAP(RenderViewHostImpl, msg) |
| 901 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) | 911 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) |
| 902 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnShowView) | 912 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowView, OnShowView) |
| 903 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 913 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
| 904 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowFullscreenWidget, | 914 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowFullscreenWidget, |
| 905 OnShowFullscreenWidget) | 915 OnShowFullscreenWidget) |
| 906 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnRenderViewReady) | |
| 907 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateState, OnUpdateState) | 916 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateState, OnUpdateState) |
| 908 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnUpdateTargetURL) | 917 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnUpdateTargetURL) |
| 909 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose) | 918 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose) |
| 910 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove) | 919 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove) |
| 911 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentAvailableInMainFrame, | 920 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentAvailableInMainFrame, |
| 912 OnDocumentAvailableInMainFrame) | 921 OnDocumentAvailableInMainFrame) |
| 913 IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange, | 922 IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange, |
| 914 OnDidContentsPreferredSizeChange) | 923 OnDidContentsPreferredSizeChange) |
| 915 IPC_MESSAGE_HANDLER(ViewHostMsg_RouteCloseEvent, | 924 IPC_MESSAGE_HANDLER(ViewHostMsg_RouteCloseEvent, |
| 916 OnRouteCloseEvent) | 925 OnRouteCloseEvent) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 927 // Have the super handle all other messages. | 936 // Have the super handle all other messages. |
| 928 IPC_MESSAGE_UNHANDLED( | 937 IPC_MESSAGE_UNHANDLED( |
| 929 handled = RenderWidgetHostImpl::OnMessageReceived(msg)) | 938 handled = RenderWidgetHostImpl::OnMessageReceived(msg)) |
| 930 IPC_END_MESSAGE_MAP() | 939 IPC_END_MESSAGE_MAP() |
| 931 | 940 |
| 932 return handled; | 941 return handled; |
| 933 } | 942 } |
| 934 | 943 |
| 935 void RenderViewHostImpl::Init() { | 944 void RenderViewHostImpl::Init() { |
| 936 RenderWidgetHostImpl::Init(); | 945 RenderWidgetHostImpl::Init(); |
| 946 PostRenderViewReady(); |
| 937 } | 947 } |
| 938 | 948 |
| 939 void RenderViewHostImpl::Shutdown() { | 949 void RenderViewHostImpl::Shutdown() { |
| 940 // We can't release the SessionStorageNamespace until our peer | 950 // We can't release the SessionStorageNamespace until our peer |
| 941 // in the renderer has wound down. | 951 // in the renderer has wound down. |
| 942 if (GetProcess()->HasConnection()) { | 952 if (GetProcess()->HasConnection()) { |
| 943 RenderProcessHostImpl::ReleaseOnCloseACK( | 953 RenderProcessHostImpl::ReleaseOnCloseACK( |
| 944 GetProcess(), | 954 GetProcess(), |
| 945 delegate_->GetSessionStorageNamespaceMap(), | 955 delegate_->GetSessionStorageNamespaceMap(), |
| 946 GetRoutingID()); | 956 GetRoutingID()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 delegate_->ShowCreatedWidget(route_id, initial_rect); | 1025 delegate_->ShowCreatedWidget(route_id, initial_rect); |
| 1016 Send(new ViewMsg_Move_ACK(route_id)); | 1026 Send(new ViewMsg_Move_ACK(route_id)); |
| 1017 } | 1027 } |
| 1018 | 1028 |
| 1019 void RenderViewHostImpl::OnShowFullscreenWidget(int route_id) { | 1029 void RenderViewHostImpl::OnShowFullscreenWidget(int route_id) { |
| 1020 if (is_active_) | 1030 if (is_active_) |
| 1021 delegate_->ShowCreatedFullscreenWidget(route_id); | 1031 delegate_->ShowCreatedFullscreenWidget(route_id); |
| 1022 Send(new ViewMsg_Move_ACK(route_id)); | 1032 Send(new ViewMsg_Move_ACK(route_id)); |
| 1023 } | 1033 } |
| 1024 | 1034 |
| 1025 void RenderViewHostImpl::OnRenderViewReady() { | |
| 1026 render_view_termination_status_ = base::TERMINATION_STATUS_STILL_RUNNING; | |
| 1027 SendScreenRects(); | |
| 1028 WasResized(); | |
| 1029 delegate_->RenderViewReady(this); | |
| 1030 } | |
| 1031 | |
| 1032 void RenderViewHostImpl::OnRenderProcessGone(int status, int exit_code) { | 1035 void RenderViewHostImpl::OnRenderProcessGone(int status, int exit_code) { |
| 1033 // Do nothing, otherwise RenderWidgetHostImpl will assume it is not a | 1036 // Do nothing, otherwise RenderWidgetHostImpl will assume it is not a |
| 1034 // RenderViewHostImpl and destroy itself. | 1037 // RenderViewHostImpl and destroy itself. |
| 1035 // TODO(nasko): Remove this hack once RenderViewHost and RenderWidgetHost are | 1038 // TODO(nasko): Remove this hack once RenderViewHost and RenderWidgetHost are |
| 1036 // decoupled. | 1039 // decoupled. |
| 1037 } | 1040 } |
| 1038 | 1041 |
| 1039 void RenderViewHostImpl::OnUpdateState(int32 page_id, const PageState& state) { | 1042 void RenderViewHostImpl::OnUpdateState(int32 page_id, const PageState& state) { |
| 1040 // If the following DCHECK fails, you have encountered a tricky edge-case that | 1043 // If the following DCHECK fails, you have encountered a tricky edge-case that |
| 1041 // has evaded reproduction for a very long time. Please report what you were | 1044 // has evaded reproduction for a very long time. Please report what you were |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 for (const auto& file : file_paths) { | 1422 for (const auto& file : file_paths) { |
| 1420 if (!policy->CanReadFile(GetProcess()->GetID(), file)) | 1423 if (!policy->CanReadFile(GetProcess()->GetID(), file)) |
| 1421 policy->GrantReadFile(GetProcess()->GetID(), file); | 1424 policy->GrantReadFile(GetProcess()->GetID(), file); |
| 1422 } | 1425 } |
| 1423 } | 1426 } |
| 1424 | 1427 |
| 1425 void RenderViewHostImpl::SelectWordAroundCaret() { | 1428 void RenderViewHostImpl::SelectWordAroundCaret() { |
| 1426 Send(new ViewMsg_SelectWordAroundCaret(GetRoutingID())); | 1429 Send(new ViewMsg_SelectWordAroundCaret(GetRoutingID())); |
| 1427 } | 1430 } |
| 1428 | 1431 |
| 1432 void RenderViewHostImpl::PostRenderViewReady() { |
| 1433 if (GetProcess()->IsReady()) { |
| 1434 BrowserThread::PostDelayedTask( |
| 1435 BrowserThread::UI, |
| 1436 FROM_HERE, |
| 1437 base::Bind(&RenderViewHostImpl::RenderViewReady, |
| 1438 weak_factory_.GetWeakPtr()), |
| 1439 base::TimeDelta::FromMilliseconds(1000)); |
| 1440 } else { |
| 1441 render_view_ready_on_process_launch_ = true; |
| 1442 } |
| 1443 } |
| 1444 |
| 1445 void RenderViewHostImpl::RenderViewReady() { |
| 1446 delegate_->RenderViewReady(this); |
| 1447 } |
| 1448 |
| 1429 } // namespace content | 1449 } // namespace content |
| OLD | NEW |