Chromium Code Reviews| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 routing_id_(routing_id), | 184 routing_id_(routing_id), |
| 184 render_frame_created_(false), | 185 render_frame_created_(false), |
| 185 navigations_suspended_(false), | 186 navigations_suspended_(false), |
| 186 is_waiting_for_beforeunload_ack_(false), | 187 is_waiting_for_beforeunload_ack_(false), |
| 187 unload_ack_is_for_navigation_(false), | 188 unload_ack_is_for_navigation_(false), |
| 188 is_loading_(false), | 189 is_loading_(false), |
| 189 pending_commit_(false), | 190 pending_commit_(false), |
| 190 accessibility_reset_token_(0), | 191 accessibility_reset_token_(0), |
| 191 accessibility_reset_count_(0), | 192 accessibility_reset_count_(0), |
| 192 no_create_browser_accessibility_manager_for_testing_(false), | 193 no_create_browser_accessibility_manager_for_testing_(false), |
| 194 web_ui_type_(WebUI::kNoWebUI), | |
| 195 should_reuse_web_ui_(false), | |
| 193 weak_ptr_factory_(this) { | 196 weak_ptr_factory_(this) { |
| 194 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); | 197 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); |
| 195 bool hidden = !!(flags & CREATE_RF_HIDDEN); | 198 bool hidden = !!(flags & CREATE_RF_HIDDEN); |
| 196 frame_tree_->AddRenderViewHostRef(render_view_host_); | 199 frame_tree_->AddRenderViewHostRef(render_view_host_); |
| 197 GetProcess()->AddRoute(routing_id_, this); | 200 GetProcess()->AddRoute(routing_id_, this); |
| 198 g_routing_id_frame_map.Get().insert(std::make_pair( | 201 g_routing_id_frame_map.Get().insert(std::make_pair( |
| 199 RenderFrameHostID(GetProcess()->GetID(), routing_id_), | 202 RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
| 200 this)); | 203 this)); |
| 201 | 204 |
| 202 if (is_swapped_out) { | 205 if (is_swapped_out) { |
| 203 rfh_state_ = STATE_SWAPPED_OUT; | 206 rfh_state_ = STATE_SWAPPED_OUT; |
| 204 } else { | 207 } else { |
| 205 rfh_state_ = STATE_DEFAULT; | 208 rfh_state_ = STATE_DEFAULT; |
| 206 GetSiteInstance()->increment_active_frame_count(); | 209 GetSiteInstance()->increment_active_frame_count(); |
| 207 } | 210 } |
| 208 | 211 |
| 209 SetUpMojoIfNeeded(); | 212 SetUpMojoIfNeeded(); |
| 210 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( | 213 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( |
| 211 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); | 214 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); |
| 212 | 215 |
| 213 if (widget_routing_id != MSG_ROUTING_NONE) { | 216 if (widget_routing_id != MSG_ROUTING_NONE) { |
| 214 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), | 217 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), |
| 215 widget_routing_id, hidden); | 218 widget_routing_id, hidden); |
| 216 render_widget_host_->set_owned_by_render_frame_host(true); | 219 render_widget_host_->set_owned_by_render_frame_host(true); |
| 217 } | 220 } |
| 218 } | 221 } |
| 219 | 222 |
| 220 RenderFrameHostImpl::~RenderFrameHostImpl() { | 223 RenderFrameHostImpl::~RenderFrameHostImpl() { |
| 224 // Release the WebUI before all else as the WebUI accesses the RenderFrameHost | |
| 225 // during cleanup. | |
| 226 web_ui_.reset(); | |
| 227 pending_web_ui_.reset(); | |
| 228 | |
| 221 GetProcess()->RemoveRoute(routing_id_); | 229 GetProcess()->RemoveRoute(routing_id_); |
| 222 g_routing_id_frame_map.Get().erase( | 230 g_routing_id_frame_map.Get().erase( |
| 223 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 231 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
| 224 | 232 |
| 225 if (delegate_ && render_frame_created_) | 233 if (delegate_ && render_frame_created_) |
| 226 delegate_->RenderFrameDeleted(this); | 234 delegate_->RenderFrameDeleted(this); |
| 227 | 235 |
| 228 // If this was swapped out, it already decremented the active frame count of | 236 // If this was swapped out, it already decremented the active frame count of |
| 229 // the SiteInstance it belongs to. | 237 // the SiteInstance it belongs to. |
| 230 if (IsRFHStateActive(rfh_state_)) | 238 if (IsRFHStateActive(rfh_state_)) |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1013 // gone through this, therefore just return. | 1021 // gone through this, therefore just return. |
| 1014 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { | 1022 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { |
| 1015 NOTREACHED() << "RFH should be in default state when calling SwapOut."; | 1023 NOTREACHED() << "RFH should be in default state when calling SwapOut."; |
| 1016 return; | 1024 return; |
| 1017 } | 1025 } |
| 1018 | 1026 |
| 1019 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); | 1027 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); |
| 1020 swapout_event_monitor_timeout_->Start( | 1028 swapout_event_monitor_timeout_->Start( |
| 1021 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); | 1029 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); |
| 1022 | 1030 |
| 1031 web_ui_.reset(); | |
| 1032 web_ui_type_ = WebUI::kNoWebUI; | |
| 1033 | |
| 1023 // There may be no proxy if there are no active views in the process. | 1034 // There may be no proxy if there are no active views in the process. |
| 1024 int proxy_routing_id = MSG_ROUTING_NONE; | 1035 int proxy_routing_id = MSG_ROUTING_NONE; |
| 1025 FrameReplicationState replication_state; | 1036 FrameReplicationState replication_state; |
| 1026 if (proxy) { | 1037 if (proxy) { |
| 1027 set_render_frame_proxy_host(proxy); | 1038 set_render_frame_proxy_host(proxy); |
| 1028 proxy_routing_id = proxy->GetRoutingID(); | 1039 proxy_routing_id = proxy->GetRoutingID(); |
| 1029 replication_state = proxy->frame_tree_node()->current_replication_state(); | 1040 replication_state = proxy->frame_tree_node()->current_replication_state(); |
| 1030 } | 1041 } |
| 1031 | 1042 |
| 1032 if (IsRenderFrameLive()) { | 1043 if (IsRenderFrameLive()) { |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1950 bool RenderFrameHostImpl::IsFocused() { | 1961 bool RenderFrameHostImpl::IsFocused() { |
| 1951 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops | 1962 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops |
| 1952 // returning nullptr in some cases. See https://crbug.com/455245. | 1963 // returning nullptr in some cases. See https://crbug.com/455245. |
| 1953 return RenderWidgetHostImpl::From( | 1964 return RenderWidgetHostImpl::From( |
| 1954 GetView()->GetRenderWidgetHost())->is_focused() && | 1965 GetView()->GetRenderWidgetHost())->is_focused() && |
| 1955 frame_tree_->GetFocusedFrame() && | 1966 frame_tree_->GetFocusedFrame() && |
| 1956 (frame_tree_->GetFocusedFrame() == frame_tree_node() || | 1967 (frame_tree_->GetFocusedFrame() == frame_tree_node() || |
| 1957 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); | 1968 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); |
| 1958 } | 1969 } |
| 1959 | 1970 |
| 1971 void RenderFrameHostImpl::InitializeWebUI(const GURL& dest_url, | |
| 1972 int past_bindings) { | |
| 1973 CHECK(!web_ui_ && !pending_web_ui_); | |
| 1974 web_ui_ = CreateWebUI(dest_url, past_bindings, &web_ui_type_); | |
| 1975 CHECK_IMPLIES(web_ui_, web_ui_type_ != WebUI::kNoWebUI); | |
| 1976 CHECK_IMPLIES(!web_ui_, web_ui_type_ == WebUI::kNoWebUI); | |
| 1977 | |
| 1978 if (web_ui_ && frame_tree_node_->IsMainFrame()) | |
| 1979 web_ui_->RenderViewCreated(render_view_host_); | |
|
carlosk
2015/09/30 19:37:27
With this change the order of creation of the RVH
clamy
2015/10/01 13:15:13
I think the assumptions make sense, provided:
- th
carlosk
2015/10/01 16:00:22
InitializeWebUI was removed and its logic moved to
clamy
2015/10/02 14:20:01
Acknowledged. But this needs to be really well doc
| |
| 1980 } | |
| 1981 | |
| 1982 void RenderFrameHostImpl::UpdatePendingWebUI(const GURL& dest_url, | |
| 1983 int past_bindings) { | |
| 1984 WebUI::TypeID new_web_ui_type = | |
| 1985 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | |
| 1986 GetSiteInstance()->GetBrowserContext(), dest_url); | |
| 1987 // The current WebUI should be reused when dest_url requires a WebUI and its | |
| 1988 // type matches the current. | |
| 1989 should_reuse_web_ui_ = | |
| 1990 new_web_ui_type != WebUI::kNoWebUI && web_ui_type_ == new_web_ui_type; | |
| 1991 DCHECK_IMPLIES(should_reuse_web_ui_, web_ui_); | |
| 1992 | |
| 1993 if (should_reuse_web_ui_) { | |
| 1994 // Reset the pending WebUI if the current one will be reused. | |
| 1995 pending_web_ui_.reset(); | |
| 1996 pending_web_ui_type_ = WebUI::kNoWebUI; | |
| 1997 } else if (pending_web_ui_type_ != new_web_ui_type) { | |
| 1998 // Otherwise create, update or reset the pending one if its type doesn't | |
| 1999 // match the new type (if new type is kNoWebUI then it will be reset). | |
| 2000 pending_web_ui_ = | |
| 2001 CreateWebUI(dest_url, past_bindings, &pending_web_ui_type_); | |
| 2002 | |
| 2003 if (pending_web_ui_ && IsRenderFrameLive()) { | |
| 2004 pending_web_ui_->RenderViewReused(render_view_host_, | |
| 2005 frame_tree_node_->IsMainFrame()); | |
| 2006 } | |
| 2007 } | |
| 2008 CHECK_IMPLIES(pending_web_ui_, pending_web_ui_type_ != WebUI::kNoWebUI); | |
| 2009 CHECK_IMPLIES(!pending_web_ui_, pending_web_ui_type_ == WebUI::kNoWebUI); | |
| 2010 } | |
| 2011 | |
| 2012 void RenderFrameHostImpl::CommitPendingWebUI() { | |
| 2013 if (should_reuse_web_ui_) { | |
| 2014 CHECK(!pending_web_ui_ && pending_web_ui_type_ == WebUI::kNoWebUI); | |
| 2015 should_reuse_web_ui_ = false; | |
| 2016 } else { | |
| 2017 web_ui_ = pending_web_ui_.Pass(); | |
| 2018 web_ui_type_ = pending_web_ui_type_; | |
| 2019 pending_web_ui_type_ = WebUI::kNoWebUI; | |
| 2020 } | |
| 2021 } | |
| 2022 | |
| 2023 void RenderFrameHostImpl::DiscardPendingWebUI() { | |
| 2024 pending_web_ui_.reset(); | |
| 2025 pending_web_ui_type_ = WebUI::kNoWebUI; | |
| 2026 should_reuse_web_ui_ = false; | |
| 2027 } | |
| 2028 | |
| 1960 const image_downloader::ImageDownloaderPtr& | 2029 const image_downloader::ImageDownloaderPtr& |
| 1961 RenderFrameHostImpl::GetMojoImageDownloader() { | 2030 RenderFrameHostImpl::GetMojoImageDownloader() { |
| 1962 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { | 2031 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { |
| 1963 GetServiceRegistry()->ConnectToRemoteService( | 2032 GetServiceRegistry()->ConnectToRemoteService( |
| 1964 mojo::GetProxy(&mojo_image_downloader_)); | 2033 mojo::GetProxy(&mojo_image_downloader_)); |
| 1965 } | 2034 } |
| 1966 return mojo_image_downloader_; | 2035 return mojo_image_downloader_; |
| 1967 } | 2036 } |
| 1968 | 2037 |
| 1969 bool RenderFrameHostImpl::IsSameSiteInstance( | 2038 bool RenderFrameHostImpl::IsSameSiteInstance( |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2245 ui::AX_ATTR_CHILD_TREE_ID, | 2314 ui::AX_ATTR_CHILD_TREE_ID, |
| 2246 BrowserPluginInstanceIDToAXTreeID(value))); | 2315 BrowserPluginInstanceIDToAXTreeID(value))); |
| 2247 break; | 2316 break; |
| 2248 case AX_CONTENT_INT_ATTRIBUTE_LAST: | 2317 case AX_CONTENT_INT_ATTRIBUTE_LAST: |
| 2249 NOTREACHED(); | 2318 NOTREACHED(); |
| 2250 break; | 2319 break; |
| 2251 } | 2320 } |
| 2252 } | 2321 } |
| 2253 } | 2322 } |
| 2254 | 2323 |
| 2324 scoped_ptr<WebUIImpl> RenderFrameHostImpl::CreateWebUI( | |
| 2325 const GURL& dest_url, | |
| 2326 int past_bindings, | |
| 2327 WebUI::TypeID* web_ui_type) { | |
| 2328 scoped_ptr<WebUIImpl> web_ui; | |
| 2329 *web_ui_type = WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | |
| 2330 GetSiteInstance()->GetBrowserContext(), dest_url); | |
| 2331 if (*web_ui_type != WebUI::kNoWebUI) { | |
| 2332 web_ui = delegate_->CreateMainFrameWebUI(dest_url); | |
| 2333 // If we have assigned (zero or more) bindings to the NavigationEntry in the | |
| 2334 // past, make sure we're not granting it different bindings than it had | |
| 2335 // before. If so, note it and don't give it any bindings, to avoid a | |
| 2336 // potential privilege escalation. | |
| 2337 if (web_ui && past_bindings != NavigationEntryImpl::kInvalidBindings && | |
| 2338 web_ui->GetBindings() != past_bindings) { | |
| 2339 RecordAction(base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); | |
| 2340 web_ui.reset(); | |
| 2341 *web_ui_type = WebUI::kNoWebUI; | |
| 2342 } | |
| 2343 } | |
| 2344 | |
| 2345 // Check RenderViewHost for proper bindings. | |
| 2346 if (web_ui && !render_view_host_->GetProcess()->IsForGuestsOnly()) { | |
| 2347 // If a WebUI was created for the URL and the RenderView is not in a guest | |
| 2348 // process, then enable missing bindings with the RenderViewHost. | |
| 2349 int new_bindings = web_ui->GetBindings(); | |
| 2350 if ((render_view_host_->GetEnabledBindings() & new_bindings) != | |
| 2351 new_bindings) { | |
| 2352 render_view_host_->AllowBindings(new_bindings); | |
| 2353 } | |
| 2354 } | |
| 2355 | |
| 2356 return web_ui.Pass(); | |
| 2357 } | |
| 2358 | |
| 2255 } // namespace content | 2359 } // namespace content |
| OLD | NEW |