Chromium Code Reviews| 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 "components/ui/zoom/page_zoom.h" | 9 #include "components/ui/zoom/page_zoom.h" |
| 10 #include "components/ui/zoom/zoom_controller.h" | 10 #include "components/ui/zoom/zoom_controller.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 } | 65 } |
| 66 | 66 |
| 67 GuestViewBase::Event::~Event() { | 67 GuestViewBase::Event::~Event() { |
| 68 } | 68 } |
| 69 | 69 |
| 70 scoped_ptr<base::DictionaryValue> GuestViewBase::Event::GetArguments() { | 70 scoped_ptr<base::DictionaryValue> GuestViewBase::Event::GetArguments() { |
| 71 return args_.Pass(); | 71 return args_.Pass(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // This observer ensures that the GuestViewBase destroys itself when its | 74 // This observer ensures that the GuestViewBase destroys itself when its |
| 75 // embedder goes away. | 75 // embedder goes away. It also tracks when the embedder's fullscreen is |
| 76 class GuestViewBase::OwnerLifetimeObserver : public WebContentsObserver { | 76 // toggled so guests can change itself accordingly. |
|
Fady Samuel
2015/03/13 01:43:06
so the guest can change itself
lazyboy
2015/03/13 16:27:02
Done.
| |
| 77 class GuestViewBase::OwnerContentsObserver : public WebContentsObserver { | |
| 77 public: | 78 public: |
| 78 OwnerLifetimeObserver(GuestViewBase* guest, | 79 OwnerContentsObserver(GuestViewBase* guest, |
| 79 content::WebContents* embedder_web_contents) | 80 content::WebContents* embedder_web_contents) |
| 80 : WebContentsObserver(embedder_web_contents), | 81 : WebContentsObserver(embedder_web_contents), |
| 82 is_fullscreen_(false), | |
| 81 destroyed_(false), | 83 destroyed_(false), |
| 82 guest_(guest) {} | 84 guest_(guest) {} |
| 83 | 85 |
| 84 ~OwnerLifetimeObserver() override {} | 86 ~OwnerContentsObserver() override {} |
| 85 | 87 |
| 86 // WebContentsObserver implementation. | 88 // WebContentsObserver implementation. |
| 87 void WebContentsDestroyed() override { | 89 void WebContentsDestroyed() override { |
| 88 // If the embedder is destroyed then destroy the guest. | 90 // If the embedder is destroyed then destroy the guest. |
| 89 Destroy(); | 91 Destroy(); |
| 90 } | 92 } |
| 91 | 93 |
| 92 void DidNavigateMainFrame( | 94 void DidNavigateMainFrame( |
| 93 const content::LoadCommittedDetails& details, | 95 const content::LoadCommittedDetails& details, |
| 94 const content::FrameNavigateParams& params) override { | 96 const content::FrameNavigateParams& params) override { |
| 95 // If the embedder navigates to a different page then destroy the guest. | 97 // If the embedder navigates to a different page then destroy the guest. |
| 96 if (details.is_navigation_to_different_page()) | 98 if (details.is_navigation_to_different_page()) |
| 97 Destroy(); | 99 Destroy(); |
| 98 } | 100 } |
| 99 | 101 |
| 100 void RenderProcessGone(base::TerminationStatus status) override { | 102 void RenderProcessGone(base::TerminationStatus status) override { |
| 101 // If the embedder crashes, then destroy the guest. | 103 // If the embedder crashes, then destroy the guest. |
| 102 Destroy(); | 104 Destroy(); |
| 103 } | 105 } |
| 104 | 106 |
| 107 void DidToggleFullscreenModeForTab(bool entered_fullscreen) override { | |
| 108 if (destroyed_) | |
| 109 return; | |
| 110 | |
| 111 is_fullscreen_ = entered_fullscreen; | |
| 112 guest_->EmbedderFullscreenToggled(is_fullscreen_); | |
| 113 } | |
| 114 | |
| 115 void MainFrameWasResized(bool width_changed) override { | |
| 116 if (destroyed_) | |
|
Fady Samuel
2015/03/13 01:43:06
Exit early if the embedder doesn't have a delegate
lazyboy
2015/03/13 16:27:02
In theory GetDelegate() can return NULL, so adding
| |
| 117 return; | |
| 118 | |
| 119 bool current_fullscreen = | |
| 120 web_contents()->GetDelegate()->IsFullscreenForTabOrPending( | |
| 121 web_contents()); | |
| 122 if (is_fullscreen_ && !current_fullscreen) { | |
| 123 is_fullscreen_ = false; | |
| 124 guest_->EmbedderFullscreenToggled(is_fullscreen_); | |
| 125 } | |
| 126 } | |
| 127 | |
| 105 private: | 128 private: |
| 129 bool is_fullscreen_; | |
| 106 bool destroyed_; | 130 bool destroyed_; |
| 107 GuestViewBase* guest_; | 131 GuestViewBase* guest_; |
| 108 | 132 |
| 109 void Destroy() { | 133 void Destroy() { |
| 110 if (destroyed_) | 134 if (destroyed_) |
| 111 return; | 135 return; |
| 112 | 136 |
| 113 destroyed_ = true; | 137 destroyed_ = true; |
| 114 guest_->EmbedderWillBeDestroyed(); | 138 guest_->EmbedderWillBeDestroyed(); |
| 115 guest_->Destroy(); | 139 guest_->Destroy(); |
| 116 } | 140 } |
| 117 | 141 |
| 118 DISALLOW_COPY_AND_ASSIGN(OwnerLifetimeObserver); | 142 DISALLOW_COPY_AND_ASSIGN(OwnerContentsObserver); |
| 119 }; | 143 }; |
| 120 | 144 |
| 121 // This observer ensures that the GuestViewBase destroys itself when its | 145 // This observer ensures that the GuestViewBase destroys itself when its |
| 122 // embedder goes away. | 146 // embedder goes away. |
| 123 class GuestViewBase::OpenerLifetimeObserver : public WebContentsObserver { | 147 class GuestViewBase::OpenerLifetimeObserver : public WebContentsObserver { |
| 124 public: | 148 public: |
| 125 OpenerLifetimeObserver(GuestViewBase* guest) | 149 OpenerLifetimeObserver(GuestViewBase* guest) |
| 126 : WebContentsObserver(guest->GetOpener()->web_contents()), | 150 : WebContentsObserver(guest->GetOpener()->web_contents()), |
| 127 guest_(guest) {} | 151 guest_(guest) {} |
| 128 | 152 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 } | 226 } |
| 203 | 227 |
| 204 void GuestViewBase::InitWithWebContents( | 228 void GuestViewBase::InitWithWebContents( |
| 205 const base::DictionaryValue& create_params, | 229 const base::DictionaryValue& create_params, |
| 206 content::WebContents* guest_web_contents) { | 230 content::WebContents* guest_web_contents) { |
| 207 DCHECK(guest_web_contents); | 231 DCHECK(guest_web_contents); |
| 208 | 232 |
| 209 // At this point, we have just created the guest WebContents, we need to add | 233 // At this point, we have just created the guest WebContents, we need to add |
| 210 // an observer to the owner WebContents. This observer will be responsible | 234 // an observer to the owner WebContents. This observer will be responsible |
| 211 // for destroying the guest WebContents if the owner goes away. | 235 // for destroying the guest WebContents if the owner goes away. |
| 212 owner_lifetime_observer_.reset( | 236 owner_contents_observer_.reset( |
| 213 new OwnerLifetimeObserver(this, owner_web_contents_)); | 237 new OwnerContentsObserver(this, owner_web_contents_)); |
| 214 | 238 |
| 215 WebContentsObserver::Observe(guest_web_contents); | 239 WebContentsObserver::Observe(guest_web_contents); |
| 216 guest_web_contents->SetDelegate(this); | 240 guest_web_contents->SetDelegate(this); |
| 217 webcontents_guestview_map.Get().insert( | 241 webcontents_guestview_map.Get().insert( |
| 218 std::make_pair(guest_web_contents, this)); | 242 std::make_pair(guest_web_contents, this)); |
| 219 GuestViewManager::FromBrowserContext(browser_context_)-> | 243 GuestViewManager::FromBrowserContext(browser_context_)-> |
| 220 AddGuest(guest_instance_id_, guest_web_contents); | 244 AddGuest(guest_instance_id_, guest_web_contents); |
| 221 | 245 |
| 222 // Create a ZoomController to allow the guest's contents to be zoomed. | 246 // Create a ZoomController to allow the guest's contents to be zoomed. |
| 223 ui_zoom::ZoomController::CreateForWebContents(guest_web_contents); | 247 ui_zoom::ZoomController::CreateForWebContents(guest_web_contents); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 } | 507 } |
| 484 | 508 |
| 485 void GuestViewBase::SetGuestHost(content::GuestHost* guest_host) { | 509 void GuestViewBase::SetGuestHost(content::GuestHost* guest_host) { |
| 486 guest_host_ = guest_host; | 510 guest_host_ = guest_host; |
| 487 } | 511 } |
| 488 | 512 |
| 489 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, | 513 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, |
| 490 int element_instance_id, | 514 int element_instance_id, |
| 491 bool is_full_page_plugin) { | 515 bool is_full_page_plugin) { |
| 492 if (owner_web_contents_ != embedder_web_contents) { | 516 if (owner_web_contents_ != embedder_web_contents) { |
| 493 DCHECK_EQ(owner_lifetime_observer_->web_contents(), owner_web_contents_); | 517 DCHECK_EQ(owner_contents_observer_->web_contents(), owner_web_contents_); |
| 494 // Stop tracking the old embedder's zoom level. | 518 // Stop tracking the old embedder's zoom level. |
| 495 StopTrackingEmbedderZoomLevel(); | 519 StopTrackingEmbedderZoomLevel(); |
| 496 owner_web_contents_ = embedder_web_contents; | 520 owner_web_contents_ = embedder_web_contents; |
| 497 owner_lifetime_observer_.reset( | 521 owner_contents_observer_.reset( |
| 498 new OwnerLifetimeObserver(this, embedder_web_contents)); | 522 new OwnerContentsObserver(this, embedder_web_contents)); |
| 499 } | 523 } |
| 500 | 524 |
| 501 // Start tracking the new embedder's zoom level. | 525 // Start tracking the new embedder's zoom level. |
| 502 StartTrackingEmbedderZoomLevel(); | 526 StartTrackingEmbedderZoomLevel(); |
| 503 element_instance_id_ = element_instance_id; | 527 element_instance_id_ = element_instance_id; |
| 504 is_full_page_plugin_ = is_full_page_plugin; | 528 is_full_page_plugin_ = is_full_page_plugin; |
| 505 | 529 |
| 506 WillAttachToEmbedder(); | 530 WillAttachToEmbedder(); |
| 507 } | 531 } |
| 508 | 532 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 void GuestViewBase::RegisterGuestViewTypes() { | 843 void GuestViewBase::RegisterGuestViewTypes() { |
| 820 AppViewGuest::Register(); | 844 AppViewGuest::Register(); |
| 821 ExtensionOptionsGuest::Register(); | 845 ExtensionOptionsGuest::Register(); |
| 822 ExtensionViewGuest::Register(); | 846 ExtensionViewGuest::Register(); |
| 823 MimeHandlerViewGuest::Register(); | 847 MimeHandlerViewGuest::Register(); |
| 824 SurfaceWorkerGuest::Register(); | 848 SurfaceWorkerGuest::Register(); |
| 825 WebViewGuest::Register(); | 849 WebViewGuest::Register(); |
| 826 } | 850 } |
| 827 | 851 |
| 828 } // namespace extensions | 852 } // namespace extensions |
| OLD | NEW |