OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/frame_host/render_frame_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "content/browser/permissions/permission_service_impl.h" | 34 #include "content/browser/permissions/permission_service_impl.h" |
35 #include "content/browser/presentation/presentation_service_impl.h" | 35 #include "content/browser/presentation/presentation_service_impl.h" |
36 #include "content/browser/renderer_host/input/input_router.h" | 36 #include "content/browser/renderer_host/input/input_router.h" |
37 #include "content/browser/renderer_host/input/timeout_monitor.h" | 37 #include "content/browser/renderer_host/input/timeout_monitor.h" |
38 #include "content/browser/renderer_host/render_process_host_impl.h" | 38 #include "content/browser/renderer_host/render_process_host_impl.h" |
39 #include "content/browser/renderer_host/render_view_host_delegate.h" | 39 #include "content/browser/renderer_host/render_view_host_delegate.h" |
40 #include "content/browser/renderer_host/render_view_host_delegate_view.h" | 40 #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
41 #include "content/browser/renderer_host/render_view_host_impl.h" | 41 #include "content/browser/renderer_host/render_view_host_impl.h" |
42 #include "content/browser/renderer_host/render_widget_host_impl.h" | 42 #include "content/browser/renderer_host/render_widget_host_impl.h" |
43 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 43 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 44 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
44 #include "content/common/accessibility_messages.h" | 45 #include "content/common/accessibility_messages.h" |
45 #include "content/common/frame_messages.h" | 46 #include "content/common/frame_messages.h" |
46 #include "content/common/input_messages.h" | 47 #include "content/common/input_messages.h" |
47 #include "content/common/inter_process_time_ticks_converter.h" | 48 #include "content/common/inter_process_time_ticks_converter.h" |
48 #include "content/common/navigation_params.h" | 49 #include "content/common/navigation_params.h" |
49 #include "content/common/render_frame_setup.mojom.h" | 50 #include "content/common/render_frame_setup.mojom.h" |
50 #include "content/common/site_isolation_policy.h" | 51 #include "content/common/site_isolation_policy.h" |
51 #include "content/common/swapped_out_messages.h" | 52 #include "content/common/swapped_out_messages.h" |
52 #include "content/public/browser/ax_event_notification_details.h" | 53 #include "content/public/browser/ax_event_notification_details.h" |
53 #include "content/public/browser/browser_accessibility_state.h" | 54 #include "content/public/browser/browser_accessibility_state.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 routing_id_(routing_id), | 185 routing_id_(routing_id), |
185 render_frame_created_(false), | 186 render_frame_created_(false), |
186 navigations_suspended_(false), | 187 navigations_suspended_(false), |
187 is_waiting_for_beforeunload_ack_(false), | 188 is_waiting_for_beforeunload_ack_(false), |
188 unload_ack_is_for_navigation_(false), | 189 unload_ack_is_for_navigation_(false), |
189 is_loading_(false), | 190 is_loading_(false), |
190 pending_commit_(false), | 191 pending_commit_(false), |
191 accessibility_reset_token_(0), | 192 accessibility_reset_token_(0), |
192 accessibility_reset_count_(0), | 193 accessibility_reset_count_(0), |
193 no_create_browser_accessibility_manager_for_testing_(false), | 194 no_create_browser_accessibility_manager_for_testing_(false), |
| 195 web_ui_type_(WebUI::kNoWebUI), |
| 196 should_reuse_web_ui_(false), |
194 weak_ptr_factory_(this) { | 197 weak_ptr_factory_(this) { |
195 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); | 198 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); |
196 bool hidden = !!(flags & CREATE_RF_HIDDEN); | 199 bool hidden = !!(flags & CREATE_RF_HIDDEN); |
197 frame_tree_->AddRenderViewHostRef(render_view_host_); | 200 frame_tree_->AddRenderViewHostRef(render_view_host_); |
198 GetProcess()->AddRoute(routing_id_, this); | 201 GetProcess()->AddRoute(routing_id_, this); |
199 g_routing_id_frame_map.Get().insert(std::make_pair( | 202 g_routing_id_frame_map.Get().insert(std::make_pair( |
200 RenderFrameHostID(GetProcess()->GetID(), routing_id_), | 203 RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
201 this)); | 204 this)); |
202 | 205 |
203 if (is_swapped_out) { | 206 if (is_swapped_out) { |
(...skipping 10 matching lines...) Expand all Loading... |
214 if (widget_routing_id != MSG_ROUTING_NONE) { | 217 if (widget_routing_id != MSG_ROUTING_NONE) { |
215 render_widget_host_ = new RenderWidgetHostImpl( | 218 render_widget_host_ = new RenderWidgetHostImpl( |
216 rwh_delegate, GetProcess(), widget_routing_id, surface_id, hidden); | 219 rwh_delegate, GetProcess(), widget_routing_id, surface_id, hidden); |
217 render_widget_host_->set_owned_by_render_frame_host(true); | 220 render_widget_host_->set_owned_by_render_frame_host(true); |
218 } else { | 221 } else { |
219 DCHECK_EQ(0, surface_id); | 222 DCHECK_EQ(0, surface_id); |
220 } | 223 } |
221 } | 224 } |
222 | 225 |
223 RenderFrameHostImpl::~RenderFrameHostImpl() { | 226 RenderFrameHostImpl::~RenderFrameHostImpl() { |
| 227 // Release the WebUI before all else as the WebUI accesses the RenderFrameHost |
| 228 // during cleanup. |
| 229 web_ui_.reset(); |
| 230 pending_web_ui_.reset(); |
| 231 |
224 GetProcess()->RemoveRoute(routing_id_); | 232 GetProcess()->RemoveRoute(routing_id_); |
225 g_routing_id_frame_map.Get().erase( | 233 g_routing_id_frame_map.Get().erase( |
226 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 234 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
227 | 235 |
228 if (delegate_ && render_frame_created_) | 236 if (delegate_ && render_frame_created_) |
229 delegate_->RenderFrameDeleted(this); | 237 delegate_->RenderFrameDeleted(this); |
230 | 238 |
231 // If this was swapped out, it already decremented the active frame count of | 239 // If this was swapped out, it already decremented the active frame count of |
232 // the SiteInstance it belongs to. | 240 // the SiteInstance it belongs to. |
233 if (IsRFHStateActive(rfh_state_)) | 241 if (IsRFHStateActive(rfh_state_)) |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 // gone through this, therefore just return. | 1019 // gone through this, therefore just return. |
1012 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { | 1020 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { |
1013 NOTREACHED() << "RFH should be in default state when calling SwapOut."; | 1021 NOTREACHED() << "RFH should be in default state when calling SwapOut."; |
1014 return; | 1022 return; |
1015 } | 1023 } |
1016 | 1024 |
1017 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); | 1025 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); |
1018 swapout_event_monitor_timeout_->Start( | 1026 swapout_event_monitor_timeout_->Start( |
1019 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); | 1027 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); |
1020 | 1028 |
| 1029 web_ui_.reset(); |
| 1030 web_ui_type_ = WebUI::kNoWebUI; |
| 1031 |
1021 // There may be no proxy if there are no active views in the process. | 1032 // There may be no proxy if there are no active views in the process. |
1022 int proxy_routing_id = MSG_ROUTING_NONE; | 1033 int proxy_routing_id = MSG_ROUTING_NONE; |
1023 FrameReplicationState replication_state; | 1034 FrameReplicationState replication_state; |
1024 if (proxy) { | 1035 if (proxy) { |
1025 set_render_frame_proxy_host(proxy); | 1036 set_render_frame_proxy_host(proxy); |
1026 proxy_routing_id = proxy->GetRoutingID(); | 1037 proxy_routing_id = proxy->GetRoutingID(); |
1027 replication_state = proxy->frame_tree_node()->current_replication_state(); | 1038 replication_state = proxy->frame_tree_node()->current_replication_state(); |
1028 } | 1039 } |
1029 | 1040 |
1030 if (IsRenderFrameLive()) { | 1041 if (IsRenderFrameLive()) { |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 bool RenderFrameHostImpl::IsFocused() { | 1954 bool RenderFrameHostImpl::IsFocused() { |
1944 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops | 1955 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops |
1945 // returning nullptr in some cases. See https://crbug.com/455245. | 1956 // returning nullptr in some cases. See https://crbug.com/455245. |
1946 return RenderWidgetHostImpl::From( | 1957 return RenderWidgetHostImpl::From( |
1947 GetView()->GetRenderWidgetHost())->is_focused() && | 1958 GetView()->GetRenderWidgetHost())->is_focused() && |
1948 frame_tree_->GetFocusedFrame() && | 1959 frame_tree_->GetFocusedFrame() && |
1949 (frame_tree_->GetFocusedFrame() == frame_tree_node() || | 1960 (frame_tree_->GetFocusedFrame() == frame_tree_node() || |
1950 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); | 1961 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); |
1951 } | 1962 } |
1952 | 1963 |
| 1964 void RenderFrameHostImpl::InitializeWebUI(const GURL& dest_url, |
| 1965 int past_bindings) { |
| 1966 CHECK(!web_ui_ && !pending_web_ui_); |
| 1967 web_ui_ = CreateWebUI(dest_url, past_bindings, &web_ui_type_); |
| 1968 if (web_ui_) |
| 1969 web_ui_->RenderViewCreated(render_view_host_); |
| 1970 } |
| 1971 |
| 1972 void RenderFrameHostImpl::UpdatePendingWebUI(const GURL& dest_url, |
| 1973 int past_bindings) { |
| 1974 // TODO(carlosk): CHECK-enforce that the characteristic of this RFH having or |
| 1975 // not-having a WebUI remains unchanged with these calls. |
| 1976 WebUI::TypeID new_web_ui_type = |
| 1977 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
| 1978 GetSiteInstance()->GetBrowserContext(), dest_url); |
| 1979 should_reuse_web_ui_ = |
| 1980 new_web_ui_type != WebUI::kNoWebUI && web_ui_type_ == new_web_ui_type; |
| 1981 DCHECK_IMPLIES(should_reuse_web_ui_, web_ui_); |
| 1982 |
| 1983 if (should_reuse_web_ui_) { |
| 1984 // Resets the pending WebUI in case the current one will be reused. |
| 1985 pending_web_ui_.reset(); |
| 1986 pending_web_ui_type_ = WebUI::kNoWebUI; |
| 1987 } else if (pending_web_ui_type_ != new_web_ui_type) { |
| 1988 // Otherwise create or simply reset the pending one if its type doesn't |
| 1989 // match the new type (if new type is kNoWebUI then it will be reset). |
| 1990 pending_web_ui_ = |
| 1991 CreateWebUI(dest_url, past_bindings, &pending_web_ui_type_); |
| 1992 } |
| 1993 |
| 1994 CHECK_IMPLIES(pending_web_ui_, pending_web_ui_type_ != WebUI::kNoWebUI); |
| 1995 CHECK_IMPLIES(!pending_web_ui_, pending_web_ui_type_ == WebUI::kNoWebUI); |
| 1996 } |
| 1997 |
| 1998 void RenderFrameHostImpl::CommitPendingWebUI() { |
| 1999 if (should_reuse_web_ui_) { |
| 2000 CHECK(!pending_web_ui_ && pending_web_ui_type_ == WebUI::kNoWebUI); |
| 2001 should_reuse_web_ui_ = false; |
| 2002 } else { |
| 2003 web_ui_ = pending_web_ui_.Pass(); |
| 2004 web_ui_type_ = pending_web_ui_type_; |
| 2005 pending_web_ui_type_ = WebUI::kNoWebUI; |
| 2006 } |
| 2007 } |
| 2008 |
| 2009 void RenderFrameHostImpl::DiscardPendingWebUI() { |
| 2010 pending_web_ui_.reset(); |
| 2011 pending_web_ui_type_ = WebUI::kNoWebUI; |
| 2012 should_reuse_web_ui_ = false; |
| 2013 } |
| 2014 |
1953 const image_downloader::ImageDownloaderPtr& | 2015 const image_downloader::ImageDownloaderPtr& |
1954 RenderFrameHostImpl::GetMojoImageDownloader() { | 2016 RenderFrameHostImpl::GetMojoImageDownloader() { |
1955 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { | 2017 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { |
1956 GetServiceRegistry()->ConnectToRemoteService( | 2018 GetServiceRegistry()->ConnectToRemoteService( |
1957 mojo::GetProxy(&mojo_image_downloader_)); | 2019 mojo::GetProxy(&mojo_image_downloader_)); |
1958 } | 2020 } |
1959 return mojo_image_downloader_; | 2021 return mojo_image_downloader_; |
1960 } | 2022 } |
1961 | 2023 |
1962 bool RenderFrameHostImpl::IsSameSiteInstance( | 2024 bool RenderFrameHostImpl::IsSameSiteInstance( |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2241 ui::AX_ATTR_CHILD_TREE_ID, | 2303 ui::AX_ATTR_CHILD_TREE_ID, |
2242 BrowserPluginInstanceIDToAXTreeID(value))); | 2304 BrowserPluginInstanceIDToAXTreeID(value))); |
2243 break; | 2305 break; |
2244 case AX_CONTENT_INT_ATTRIBUTE_LAST: | 2306 case AX_CONTENT_INT_ATTRIBUTE_LAST: |
2245 NOTREACHED(); | 2307 NOTREACHED(); |
2246 break; | 2308 break; |
2247 } | 2309 } |
2248 } | 2310 } |
2249 } | 2311 } |
2250 | 2312 |
| 2313 scoped_ptr<WebUIImpl> RenderFrameHostImpl::CreateWebUI( |
| 2314 const GURL& dest_url, |
| 2315 int past_bindings, |
| 2316 WebUI::TypeID* web_ui_type) { |
| 2317 *web_ui_type = WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
| 2318 GetSiteInstance()->GetBrowserContext(), dest_url); |
| 2319 if (*web_ui_type == WebUI::kNoWebUI) |
| 2320 return nullptr; |
| 2321 |
| 2322 scoped_ptr<WebUIImpl> web_ui( |
| 2323 delegate_->CreateWebUIForRenderManager(dest_url)); |
| 2324 // If we have assigned (zero or more) bindings to the NavigationEntry in the |
| 2325 // past, make sure we're not granting it different bindings than it had |
| 2326 // before. If so, note it and don't give it any bindings, to avoid a |
| 2327 // potential privilege escalation. |
| 2328 if (web_ui_ && past_bindings != NavigationEntryImpl::kInvalidBindings && |
| 2329 web_ui_->GetBindings() != past_bindings) { |
| 2330 RecordAction(base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); |
| 2331 *web_ui_type = WebUI::kNoWebUI; |
| 2332 return nullptr; |
| 2333 } |
| 2334 return web_ui.Pass(); |
| 2335 } |
| 2336 |
2251 } // namespace content | 2337 } // namespace content |
OLD | NEW |