OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/guest_view/guest_view_base.h" | 5 #include "extensions/browser/guest_view/guest_view_base.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/public/browser/render_frame_host.h" | 9 #include "content/public/browser/render_frame_host.h" |
10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 virtual void WebContentsDestroyed() OVERRIDE { | 72 virtual void WebContentsDestroyed() OVERRIDE { |
73 Destroy(); | 73 Destroy(); |
74 } | 74 } |
75 | 75 |
76 virtual void RenderViewHostChanged( | 76 virtual void RenderViewHostChanged( |
77 content::RenderViewHost* old_host, | 77 content::RenderViewHost* old_host, |
78 content::RenderViewHost* new_host) OVERRIDE { | 78 content::RenderViewHost* new_host) OVERRIDE { |
79 Destroy(); | 79 Destroy(); |
80 } | 80 } |
81 | 81 |
82 virtual void AboutToNavigateRenderView( | |
83 content::RenderViewHost* render_view_host) OVERRIDE { | |
84 Destroy(); | |
lfg
2014/09/30 18:59:27
Why do we need this?
Is it safe? This call will d
Fady Samuel
2014/09/30 22:50:03
Add comments throughout to explain lifetime manage
lfg
2014/09/30 23:29:42
I see. Makes sense now :)
| |
85 } | |
86 | |
82 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE { | 87 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE { |
83 Destroy(); | 88 Destroy(); |
84 } | 89 } |
85 | 90 |
86 private: | 91 private: |
87 bool destroyed_; | 92 bool destroyed_; |
88 GuestViewBase* guest_; | 93 GuestViewBase* guest_; |
89 | 94 |
90 void Destroy() { | 95 void Destroy() { |
91 if (destroyed_) | 96 if (destroyed_) |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 // WebContents. | 295 // WebContents. |
291 CHECK(!attached()); | 296 CHECK(!attached()); |
292 CHECK_EQ(host->GetID(), embedder_render_process_id()); | 297 CHECK_EQ(host->GetID(), embedder_render_process_id()); |
293 | 298 |
294 // This code path may be reached if the embedder WebContents is killed for | 299 // This code path may be reached if the embedder WebContents is killed for |
295 // whatever reason immediately after a called to GuestViewInternal.createGuest | 300 // whatever reason immediately after a called to GuestViewInternal.createGuest |
296 // and before attaching the new guest to a frame. | 301 // and before attaching the new guest to a frame. |
297 Destroy(); | 302 Destroy(); |
298 } | 303 } |
299 | 304 |
300 void GuestViewBase::Destroy() { | |
301 DCHECK(web_contents()); | |
302 content::RenderProcessHost* host = | |
303 content::RenderProcessHost::FromID(embedder_render_process_id()); | |
304 if (host) | |
305 host->RemoveObserver(this); | |
306 WillDestroy(); | |
307 if (!destruction_callback_.is_null()) | |
308 destruction_callback_.Run(); | |
309 | |
310 webcontents_guestview_map.Get().erase(web_contents()); | |
311 GuestViewManager::FromBrowserContext(browser_context_)-> | |
312 RemoveGuest(guest_instance_id_); | |
313 pending_events_.clear(); | |
314 | |
315 delete web_contents(); | |
316 } | |
317 | |
318 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { | 305 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { |
319 // Give the derived class an opportunity to perform some actions. | 306 // Give the derived class an opportunity to perform some actions. |
320 DidAttachToEmbedder(); | 307 DidAttachToEmbedder(); |
321 | 308 |
322 // Inform the associated GuestViewContainer that the contentWindow is ready. | 309 // Inform the associated GuestViewContainer that the contentWindow is ready. |
323 embedder_web_contents()->Send(new ExtensionMsg_GuestAttached( | 310 embedder_web_contents()->Send(new ExtensionMsg_GuestAttached( |
324 embedder_web_contents()->GetMainFrame()->GetRoutingID(), | 311 embedder_web_contents()->GetMainFrame()->GetRoutingID(), |
325 element_instance_id_, | 312 element_instance_id_, |
326 guest_proxy_routing_id)); | 313 guest_proxy_routing_id)); |
327 | 314 |
328 SendQueuedEvents(); | 315 SendQueuedEvents(); |
329 } | 316 } |
330 | 317 |
331 void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size, | 318 void GuestViewBase::ElementSizeChanged(const gfx::Size& old_size, |
332 const gfx::Size& new_size) { | 319 const gfx::Size& new_size) { |
333 element_size_ = new_size; | 320 element_size_ = new_size; |
334 } | 321 } |
335 | 322 |
336 void GuestViewBase::GuestSizeChanged(const gfx::Size& old_size, | 323 void GuestViewBase::GuestSizeChanged(const gfx::Size& old_size, |
337 const gfx::Size& new_size) { | 324 const gfx::Size& new_size) { |
338 if (!auto_size_enabled_) | 325 if (!auto_size_enabled_) |
339 return; | 326 return; |
340 guest_size_ = new_size; | 327 guest_size_ = new_size; |
341 GuestSizeChangedDueToAutoSize(old_size, new_size); | 328 GuestSizeChangedDueToAutoSize(old_size, new_size); |
342 } | 329 } |
343 | 330 |
331 void GuestViewBase::Destroy() { | |
332 DCHECK(web_contents()); | |
333 content::RenderProcessHost* host = | |
334 content::RenderProcessHost::FromID(embedder_render_process_id()); | |
335 if (host) | |
336 host->RemoveObserver(this); | |
337 WillDestroy(); | |
338 if (!destruction_callback_.is_null()) | |
339 destruction_callback_.Run(); | |
340 | |
341 webcontents_guestview_map.Get().erase(web_contents()); | |
342 GuestViewManager::FromBrowserContext(browser_context_)-> | |
343 RemoveGuest(guest_instance_id_); | |
344 pending_events_.clear(); | |
345 | |
346 delete web_contents(); | |
347 } | |
348 | |
344 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { | 349 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { |
345 attach_params_.reset(params.DeepCopy()); | 350 attach_params_.reset(params.DeepCopy()); |
346 attach_params_->GetInteger(guestview::kParameterInstanceId, | 351 attach_params_->GetInteger(guestview::kParameterInstanceId, |
347 &view_instance_id_); | 352 &view_instance_id_); |
348 } | 353 } |
349 | 354 |
350 void GuestViewBase::SetOpener(GuestViewBase* guest) { | 355 void GuestViewBase::SetOpener(GuestViewBase* guest) { |
351 if (guest && guest->IsViewType(GetViewType())) { | 356 if (guest && guest->IsViewType(GetViewType())) { |
352 opener_ = guest->AsWeakPtr(); | 357 opener_ = guest->AsWeakPtr(); |
353 return; | 358 return; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 | 496 |
492 // static | 497 // static |
493 void GuestViewBase::RegisterGuestViewTypes() { | 498 void GuestViewBase::RegisterGuestViewTypes() { |
494 AppViewGuest::Register(); | 499 AppViewGuest::Register(); |
495 ExtensionOptionsGuest::Register(); | 500 ExtensionOptionsGuest::Register(); |
496 MimeHandlerViewGuest::Register(); | 501 MimeHandlerViewGuest::Register(); |
497 WebViewGuest::Register(); | 502 WebViewGuest::Register(); |
498 } | 503 } |
499 | 504 |
500 } // namespace extensions | 505 } // namespace extensions |
OLD | NEW |