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" |
54 #include "content/public/browser/browser_context.h" | 55 #include "content/public/browser/browser_context.h" |
55 #include "content/public/browser/browser_plugin_guest_manager.h" | 56 #include "content/public/browser/browser_plugin_guest_manager.h" |
56 #include "content/public/browser/browser_thread.h" | 57 #include "content/public/browser/browser_thread.h" |
57 #include "content/public/browser/content_browser_client.h" | 58 #include "content/public/browser/content_browser_client.h" |
58 #include "content/public/browser/permission_manager.h" | 59 #include "content/public/browser/permission_manager.h" |
59 #include "content/public/browser/permission_type.h" | 60 #include "content/public/browser/permission_type.h" |
60 #include "content/public/browser/render_process_host.h" | 61 #include "content/public/browser/render_process_host.h" |
61 #include "content/public/browser/render_widget_host_view.h" | 62 #include "content/public/browser/render_widget_host_view.h" |
62 #include "content/public/browser/stream_handle.h" | 63 #include "content/public/browser/stream_handle.h" |
63 #include "content/public/browser/user_metrics.h" | 64 #include "content/public/browser/user_metrics.h" |
65 #include "content/public/browser/web_ui_controller.h" | |
64 #include "content/public/common/content_constants.h" | 66 #include "content/public/common/content_constants.h" |
65 #include "content/public/common/content_switches.h" | 67 #include "content/public/common/content_switches.h" |
66 #include "content/public/common/isolated_world_ids.h" | 68 #include "content/public/common/isolated_world_ids.h" |
67 #include "content/public/common/url_constants.h" | 69 #include "content/public/common/url_constants.h" |
68 #include "content/public/common/url_utils.h" | 70 #include "content/public/common/url_utils.h" |
69 #include "ui/accessibility/ax_tree.h" | 71 #include "ui/accessibility/ax_tree.h" |
70 #include "ui/accessibility/ax_tree_update.h" | 72 #include "ui/accessibility/ax_tree_update.h" |
71 #include "url/gurl.h" | 73 #include "url/gurl.h" |
72 | 74 |
73 #if defined(OS_ANDROID) | 75 #if defined(OS_ANDROID) |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 routing_id_(routing_id), | 186 routing_id_(routing_id), |
185 render_frame_created_(false), | 187 render_frame_created_(false), |
186 navigations_suspended_(false), | 188 navigations_suspended_(false), |
187 is_waiting_for_beforeunload_ack_(false), | 189 is_waiting_for_beforeunload_ack_(false), |
188 unload_ack_is_for_navigation_(false), | 190 unload_ack_is_for_navigation_(false), |
189 is_loading_(false), | 191 is_loading_(false), |
190 pending_commit_(false), | 192 pending_commit_(false), |
191 accessibility_reset_token_(0), | 193 accessibility_reset_token_(0), |
192 accessibility_reset_count_(0), | 194 accessibility_reset_count_(0), |
193 no_create_browser_accessibility_manager_for_testing_(false), | 195 no_create_browser_accessibility_manager_for_testing_(false), |
196 web_ui_type_(WebUI::kNoWebUI), | |
197 should_reuse_web_ui_(false), | |
194 weak_ptr_factory_(this) { | 198 weak_ptr_factory_(this) { |
195 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); | 199 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); |
196 bool hidden = !!(flags & CREATE_RF_HIDDEN); | 200 bool hidden = !!(flags & CREATE_RF_HIDDEN); |
197 frame_tree_->AddRenderViewHostRef(render_view_host_); | 201 frame_tree_->AddRenderViewHostRef(render_view_host_); |
198 GetProcess()->AddRoute(routing_id_, this); | 202 GetProcess()->AddRoute(routing_id_, this); |
199 g_routing_id_frame_map.Get().insert(std::make_pair( | 203 g_routing_id_frame_map.Get().insert(std::make_pair( |
200 RenderFrameHostID(GetProcess()->GetID(), routing_id_), | 204 RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
201 this)); | 205 this)); |
202 | 206 |
203 if (is_swapped_out) { | 207 if (is_swapped_out) { |
(...skipping 10 matching lines...) Expand all Loading... | |
214 if (widget_routing_id != MSG_ROUTING_NONE) { | 218 if (widget_routing_id != MSG_ROUTING_NONE) { |
215 render_widget_host_ = new RenderWidgetHostImpl( | 219 render_widget_host_ = new RenderWidgetHostImpl( |
216 rwh_delegate, GetProcess(), widget_routing_id, surface_id, hidden); | 220 rwh_delegate, GetProcess(), widget_routing_id, surface_id, hidden); |
217 render_widget_host_->set_owned_by_render_frame_host(true); | 221 render_widget_host_->set_owned_by_render_frame_host(true); |
218 } else { | 222 } else { |
219 DCHECK_EQ(0, surface_id); | 223 DCHECK_EQ(0, surface_id); |
220 } | 224 } |
221 } | 225 } |
222 | 226 |
223 RenderFrameHostImpl::~RenderFrameHostImpl() { | 227 RenderFrameHostImpl::~RenderFrameHostImpl() { |
228 // Release the WebUI before all else as the WebUI accesses the RenderFrameHost | |
229 // during cleanup. | |
230 web_ui_.reset(); | |
231 pending_web_ui_.reset(); | |
232 | |
224 GetProcess()->RemoveRoute(routing_id_); | 233 GetProcess()->RemoveRoute(routing_id_); |
225 g_routing_id_frame_map.Get().erase( | 234 g_routing_id_frame_map.Get().erase( |
226 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 235 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
227 | 236 |
228 if (delegate_ && render_frame_created_) | 237 if (delegate_ && render_frame_created_) |
229 delegate_->RenderFrameDeleted(this); | 238 delegate_->RenderFrameDeleted(this); |
230 | 239 |
231 // If this was swapped out, it already decremented the active frame count of | 240 // If this was swapped out, it already decremented the active frame count of |
232 // the SiteInstance it belongs to. | 241 // the SiteInstance it belongs to. |
233 if (IsRFHStateActive(rfh_state_)) | 242 if (IsRFHStateActive(rfh_state_)) |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1011 // gone through this, therefore just return. | 1020 // gone through this, therefore just return. |
1012 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { | 1021 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { |
1013 NOTREACHED() << "RFH should be in default state when calling SwapOut."; | 1022 NOTREACHED() << "RFH should be in default state when calling SwapOut."; |
1014 return; | 1023 return; |
1015 } | 1024 } |
1016 | 1025 |
1017 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); | 1026 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); |
1018 swapout_event_monitor_timeout_->Start( | 1027 swapout_event_monitor_timeout_->Start( |
1019 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); | 1028 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); |
1020 | 1029 |
1030 web_ui_.reset(); | |
1031 web_ui_type_ = WebUI::kNoWebUI; | |
nasko
2015/09/18 18:40:19
Are we sure this is safe to do? What if the render
carlosk
2015/09/30 19:37:27
In the cases where SwapOut is called -- when commi
| |
1032 | |
1021 // There may be no proxy if there are no active views in the process. | 1033 // There may be no proxy if there are no active views in the process. |
1022 int proxy_routing_id = MSG_ROUTING_NONE; | 1034 int proxy_routing_id = MSG_ROUTING_NONE; |
1023 FrameReplicationState replication_state; | 1035 FrameReplicationState replication_state; |
1024 if (proxy) { | 1036 if (proxy) { |
1025 set_render_frame_proxy_host(proxy); | 1037 set_render_frame_proxy_host(proxy); |
1026 proxy_routing_id = proxy->GetRoutingID(); | 1038 proxy_routing_id = proxy->GetRoutingID(); |
1027 replication_state = proxy->frame_tree_node()->current_replication_state(); | 1039 replication_state = proxy->frame_tree_node()->current_replication_state(); |
1028 } | 1040 } |
1029 | 1041 |
1030 if (IsRenderFrameLive()) { | 1042 if (IsRenderFrameLive()) { |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1943 bool RenderFrameHostImpl::IsFocused() { | 1955 bool RenderFrameHostImpl::IsFocused() { |
1944 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops | 1956 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops |
1945 // returning nullptr in some cases. See https://crbug.com/455245. | 1957 // returning nullptr in some cases. See https://crbug.com/455245. |
1946 return RenderWidgetHostImpl::From( | 1958 return RenderWidgetHostImpl::From( |
1947 GetView()->GetRenderWidgetHost())->is_focused() && | 1959 GetView()->GetRenderWidgetHost())->is_focused() && |
1948 frame_tree_->GetFocusedFrame() && | 1960 frame_tree_->GetFocusedFrame() && |
1949 (frame_tree_->GetFocusedFrame() == frame_tree_node() || | 1961 (frame_tree_->GetFocusedFrame() == frame_tree_node() || |
1950 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); | 1962 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); |
1951 } | 1963 } |
1952 | 1964 |
1965 void RenderFrameHostImpl::InitializeWebUI(const GURL& dest_url, | |
1966 int past_bindings) { | |
1967 CHECK(!web_ui_ && !pending_web_ui_); | |
1968 web_ui_ = CreateWebUI(dest_url, past_bindings, &web_ui_type_); | |
1969 if (web_ui_) | |
1970 web_ui_->GetController()->RenderViewCreated(render_view_host_); | |
1971 } | |
1972 | |
1973 void RenderFrameHostImpl::UpdatePendingWebUI(const GURL& dest_url, | |
1974 int past_bindings) { | |
1975 // TODO(carlosk): CHECK-enforce that the characteristic of this RFH having or | |
1976 // not-having a WebUI remains unchanged with these calls. | |
1977 WebUI::TypeID new_web_ui_type = | |
1978 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | |
1979 GetSiteInstance()->GetBrowserContext(), dest_url); | |
1980 should_reuse_web_ui_ = | |
nasko
2015/09/18 18:40:19
Some textual comment explaining when exactly we sh
carlosk
2015/09/30 19:37:27
Done.
| |
1981 new_web_ui_type != WebUI::kNoWebUI && web_ui_type_ == new_web_ui_type; | |
1982 DCHECK_IMPLIES(should_reuse_web_ui_, web_ui_); | |
1983 | |
1984 if (should_reuse_web_ui_) { | |
1985 // Resets the pending WebUI in case the current one will be reused. | |
1986 pending_web_ui_.reset(); | |
1987 pending_web_ui_type_ = WebUI::kNoWebUI; | |
1988 } else if (pending_web_ui_type_ != new_web_ui_type) { | |
1989 // Otherwise create or simply reset the pending one if its type doesn't | |
1990 // match the new type (if new type is kNoWebUI then it will be reset). | |
1991 pending_web_ui_ = | |
1992 CreateWebUI(dest_url, past_bindings, &pending_web_ui_type_); | |
1993 } | |
1994 | |
1995 CHECK_IMPLIES(pending_web_ui_, pending_web_ui_type_ != WebUI::kNoWebUI); | |
1996 CHECK_IMPLIES(!pending_web_ui_, pending_web_ui_type_ == WebUI::kNoWebUI); | |
1997 } | |
1998 | |
1999 void RenderFrameHostImpl::CommitPendingWebUI() { | |
2000 if (should_reuse_web_ui_) { | |
2001 CHECK(!pending_web_ui_ && pending_web_ui_type_ == WebUI::kNoWebUI); | |
2002 should_reuse_web_ui_ = false; | |
2003 } else { | |
2004 web_ui_ = pending_web_ui_.Pass(); | |
2005 web_ui_type_ = pending_web_ui_type_; | |
2006 pending_web_ui_type_ = WebUI::kNoWebUI; | |
2007 } | |
2008 } | |
2009 | |
2010 void RenderFrameHostImpl::DiscardPendingWebUI() { | |
2011 pending_web_ui_.reset(); | |
2012 pending_web_ui_type_ = WebUI::kNoWebUI; | |
2013 should_reuse_web_ui_ = false; | |
2014 } | |
2015 | |
1953 const image_downloader::ImageDownloaderPtr& | 2016 const image_downloader::ImageDownloaderPtr& |
1954 RenderFrameHostImpl::GetMojoImageDownloader() { | 2017 RenderFrameHostImpl::GetMojoImageDownloader() { |
1955 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { | 2018 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { |
1956 GetServiceRegistry()->ConnectToRemoteService( | 2019 GetServiceRegistry()->ConnectToRemoteService( |
1957 mojo::GetProxy(&mojo_image_downloader_)); | 2020 mojo::GetProxy(&mojo_image_downloader_)); |
1958 } | 2021 } |
1959 return mojo_image_downloader_; | 2022 return mojo_image_downloader_; |
1960 } | 2023 } |
1961 | 2024 |
1962 bool RenderFrameHostImpl::IsSameSiteInstance( | 2025 bool RenderFrameHostImpl::IsSameSiteInstance( |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2241 ui::AX_ATTR_CHILD_TREE_ID, | 2304 ui::AX_ATTR_CHILD_TREE_ID, |
2242 BrowserPluginInstanceIDToAXTreeID(value))); | 2305 BrowserPluginInstanceIDToAXTreeID(value))); |
2243 break; | 2306 break; |
2244 case AX_CONTENT_INT_ATTRIBUTE_LAST: | 2307 case AX_CONTENT_INT_ATTRIBUTE_LAST: |
2245 NOTREACHED(); | 2308 NOTREACHED(); |
2246 break; | 2309 break; |
2247 } | 2310 } |
2248 } | 2311 } |
2249 } | 2312 } |
2250 | 2313 |
2314 scoped_ptr<WebUIImpl> RenderFrameHostImpl::CreateWebUI( | |
2315 const GURL& dest_url, | |
2316 int past_bindings, | |
2317 WebUI::TypeID* web_ui_type) { | |
2318 scoped_ptr<WebUIImpl> web_ui; | |
2319 *web_ui_type = WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | |
2320 GetSiteInstance()->GetBrowserContext(), dest_url); | |
2321 if (*web_ui_type != WebUI::kNoWebUI) { | |
2322 web_ui = delegate_->CreateWebUIForRenderManager(dest_url); | |
2323 // If we have assigned (zero or more) bindings to the NavigationEntry in the | |
2324 // past, make sure we're not granting it different bindings than it had | |
2325 // before. If so, note it and don't give it any bindings, to avoid a | |
2326 // potential privilege escalation. | |
2327 if (web_ui && past_bindings != NavigationEntryImpl::kInvalidBindings && | |
2328 web_ui->GetBindings() != past_bindings) { | |
2329 RecordAction(base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); | |
2330 web_ui.reset(); | |
2331 *web_ui_type = WebUI::kNoWebUI; | |
2332 } | |
2333 } | |
2334 | |
2335 // Check RenderViewHost for proper bindings. | |
2336 if (web_ui && !render_view_host_->GetProcess()->IsForGuestsOnly()) { | |
2337 // If a WebUI was created for the URL and the RenderView is not in a guest | |
2338 // process, then enable missing bindings with the RenderViewHost. | |
2339 int new_bindings = web_ui->GetBindings(); | |
2340 if ((render_view_host_->GetEnabledBindings() & new_bindings) != | |
2341 new_bindings) { | |
2342 render_view_host_->AllowBindings(new_bindings); | |
2343 } | |
2344 } else { | |
2345 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled | |
2346 // process unless it's swapped out. | |
2347 if (render_view_host_->is_active()) { | |
2348 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | |
2349 render_view_host_->GetProcess()->GetID())); | |
2350 } | |
2351 } | |
2352 | |
2353 return web_ui.Pass(); | |
2354 } | |
2355 | |
2251 } // namespace content | 2356 } // namespace content |
OLD | NEW |