| 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/renderer/render_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 13 #include "content/child/appcache/appcache_dispatcher.h" | 12 #include "content/child/appcache/appcache_dispatcher.h" |
| 14 #include "content/child/plugin_messages.h" | 13 #include "content/child/plugin_messages.h" |
| 15 #include "content/child/quota_dispatcher.h" | 14 #include "content/child/quota_dispatcher.h" |
| 16 #include "content/child/request_extra_data.h" | 15 #include "content/child/request_extra_data.h" |
| 17 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 16 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
| 18 #include "content/common/frame_messages.h" | 17 #include "content/common/frame_messages.h" |
| 19 #include "content/common/socket_stream_handle_data.h" | 18 #include "content/common/socket_stream_handle_data.h" |
| 20 #include "content/common/swapped_out_messages.h" | 19 #include "content/common/swapped_out_messages.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 make_scoped_ptr(client)); | 214 make_scoped_ptr(client)); |
| 216 } | 215 } |
| 217 | 216 |
| 218 void RenderFrameImpl::didAccessInitialDocument(blink::WebFrame* frame) { | 217 void RenderFrameImpl::didAccessInitialDocument(blink::WebFrame* frame) { |
| 219 render_view_->didAccessInitialDocument(frame); | 218 render_view_->didAccessInitialDocument(frame); |
| 220 } | 219 } |
| 221 | 220 |
| 222 blink::WebFrame* RenderFrameImpl::createChildFrame( | 221 blink::WebFrame* RenderFrameImpl::createChildFrame( |
| 223 blink::WebFrame* parent, | 222 blink::WebFrame* parent, |
| 224 const blink::WebString& name) { | 223 const blink::WebString& name) { |
| 225 RenderFrameImpl* child_render_frame = this; | |
| 226 long long child_frame_identifier = WebFrame::generateEmbedderIdentifier(); | 224 long long child_frame_identifier = WebFrame::generateEmbedderIdentifier(); |
| 227 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) { | 225 // Synchronously notify the browser of a child frame creation to get the |
| 228 // Synchronously notify the browser of a child frame creation to get the | 226 // routing_id for the RenderFrame. |
| 229 // routing_id for the RenderFrame. | 227 int routing_id = MSG_ROUTING_NONE; |
| 230 int routing_id; | 228 Send(new FrameHostMsg_CreateChildFrame(GetRoutingID(), |
| 231 Send(new FrameHostMsg_CreateChildFrame(GetRoutingID(), | 229 parent->identifier(), |
| 232 parent->identifier(), | 230 child_frame_identifier, |
| 233 child_frame_identifier, | 231 UTF16ToUTF8(name), |
| 234 UTF16ToUTF8(name), | 232 &routing_id)); |
| 235 &routing_id)); | 233 if (routing_id == MSG_ROUTING_NONE) |
| 236 child_render_frame = RenderFrameImpl::Create(render_view_, routing_id); | 234 return NULL; |
| 237 } | 235 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create(render_view_, |
| 236 routing_id); |
| 238 | 237 |
| 239 blink::WebFrame* web_frame = WebFrame::create(child_render_frame, | 238 blink::WebFrame* web_frame = WebFrame::create(child_render_frame, |
| 240 child_frame_identifier); | 239 child_frame_identifier); |
| 241 | 240 |
| 242 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) { | 241 g_child_frame_map.Get().insert( |
| 243 g_child_frame_map.Get().insert( | 242 std::make_pair(web_frame, child_render_frame)); |
| 244 std::make_pair(web_frame, child_render_frame)); | |
| 245 } | |
| 246 | 243 |
| 247 return web_frame; | 244 return web_frame; |
| 248 } | 245 } |
| 249 | 246 |
| 250 void RenderFrameImpl::didDisownOpener(blink::WebFrame* frame) { | 247 void RenderFrameImpl::didDisownOpener(blink::WebFrame* frame) { |
| 251 render_view_->didDisownOpener(frame); | 248 render_view_->didDisownOpener(frame); |
| 252 } | 249 } |
| 253 | 250 |
| 254 void RenderFrameImpl::frameDetached(blink::WebFrame* frame) { | 251 void RenderFrameImpl::frameDetached(blink::WebFrame* frame) { |
| 255 // NOTE: This function is called on the frame that is being detached and not | 252 // NOTE: This function is called on the frame that is being detached and not |
| 256 // the parent frame. This is different from createChildFrame() which is | 253 // the parent frame. This is different from createChildFrame() which is |
| 257 // called on the parent frame. | 254 // called on the parent frame. |
| 258 CHECK(!is_detaching_); | 255 CHECK(!is_detaching_); |
| 259 | 256 |
| 257 bool is_subframe = !!frame->parent(); |
| 260 int64 parent_frame_id = -1; | 258 int64 parent_frame_id = -1; |
| 261 if (frame->parent()) | 259 if (is_subframe) |
| 262 parent_frame_id = frame->parent()->identifier(); | 260 parent_frame_id = frame->parent()->identifier(); |
| 263 | 261 |
| 264 Send(new FrameHostMsg_Detach(GetRoutingID(), parent_frame_id, | 262 Send(new FrameHostMsg_Detach(GetRoutingID(), parent_frame_id, |
| 265 frame->identifier())); | 263 frame->identifier())); |
| 266 | 264 |
| 267 // Currently multiple WebCore::Frames can send frameDetached to a single | 265 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be |
| 268 // RenderFrameImpl. This is legacy behavior from when RenderViewImpl served | 266 // sent before setting |is_detaching_| to true. In contrast, Observers |
| 269 // as a shared WebFrameClient for multiple Webcore::Frame objects. It also | 267 // should only be notified afterwards so they cannot call back into and |
| 270 // prevents this class from entering the |is_detaching_| state because | 268 // have IPCs fired off. |
| 271 // even though one WebCore::Frame may have detached itself, others will | 269 is_detaching_ = true; |
| 272 // still need to use this object. | |
| 273 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) { | |
| 274 // The |is_detaching_| flag disables Send(). FrameHostMsg_Detach must be | |
| 275 // sent before setting |is_detaching_| to true. In contrast, Observers | |
| 276 // should only be notified afterwards so they cannot call back into and | |
| 277 // have IPCs fired off. | |
| 278 is_detaching_ = true; | |
| 279 } | |
| 280 | 270 |
| 281 // Call back to RenderViewImpl for observers to be notified. | 271 // Call back to RenderViewImpl for observers to be notified. |
| 282 // TODO(nasko): Remove once we have RenderFrameObserver. | 272 // TODO(nasko): Remove once we have RenderFrameObserver. |
| 283 render_view_->frameDetached(frame); | 273 render_view_->frameDetached(frame); |
| 284 | 274 |
| 275 // We need to clean up subframes by removing them from the map and deleting |
| 276 // the RenderFrameImpl. In contrast, the main frame is owned by its |
| 277 // containing RenderViewHost (so that they have the same lifetime), so it does |
| 278 // not require any cleanup here. |
| 279 if (is_subframe) { |
| 280 FrameMap::iterator it = g_child_frame_map.Get().find(frame); |
| 281 DCHECK(it != g_child_frame_map.Get().end()); |
| 282 DCHECK_EQ(it->second, this); |
| 283 g_child_frame_map.Get().erase(it); |
| 284 } |
| 285 |
| 286 // |frame| is invalid after here. |
| 285 frame->close(); | 287 frame->close(); |
| 286 | 288 |
| 287 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) { | 289 if (is_subframe) { |
| 288 // If the frame does not have a parent, it is the main frame. The main | 290 delete this; |
| 289 // frame is owned by the containing RenderViewHost so it does not require | 291 // Object is invalid after this point. |
| 290 // any cleanup here. | |
| 291 if (frame->parent()) { | |
| 292 FrameMap::iterator it = g_child_frame_map.Get().find(frame); | |
| 293 DCHECK(it != g_child_frame_map.Get().end()); | |
| 294 DCHECK_EQ(it->second, this); | |
| 295 g_child_frame_map.Get().erase(it); | |
| 296 delete this; | |
| 297 // Object is invalid after this point. | |
| 298 } | |
| 299 } | 292 } |
| 300 } | 293 } |
| 301 | 294 |
| 302 void RenderFrameImpl::willClose(blink::WebFrame* frame) { | 295 void RenderFrameImpl::willClose(blink::WebFrame* frame) { |
| 303 // Call back to RenderViewImpl for observers to be notified. | 296 // Call back to RenderViewImpl for observers to be notified. |
| 304 // TODO(nasko): Remove once we have RenderFrameObserver. | 297 // TODO(nasko): Remove once we have RenderFrameObserver. |
| 305 render_view_->willClose(frame); | 298 render_view_->willClose(frame); |
| 306 } | 299 } |
| 307 | 300 |
| 308 void RenderFrameImpl::didChangeName(blink::WebFrame* frame, | 301 void RenderFrameImpl::didChangeName(blink::WebFrame* frame, |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 | 971 |
| 979 void RenderFrameImpl::didLoseWebGLContext(blink::WebFrame* frame, | 972 void RenderFrameImpl::didLoseWebGLContext(blink::WebFrame* frame, |
| 980 int arb_robustness_status_code) { | 973 int arb_robustness_status_code) { |
| 981 render_view_->Send(new ViewHostMsg_DidLose3DContext( | 974 render_view_->Send(new ViewHostMsg_DidLose3DContext( |
| 982 GURL(frame->top()->document().securityOrigin().toString()), | 975 GURL(frame->top()->document().securityOrigin().toString()), |
| 983 THREE_D_API_TYPE_WEBGL, | 976 THREE_D_API_TYPE_WEBGL, |
| 984 arb_robustness_status_code)); | 977 arb_robustness_status_code)); |
| 985 } | 978 } |
| 986 | 979 |
| 987 } // namespace content | 980 } // namespace content |
| OLD | NEW |