| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 137 } |
| 138 | 138 |
| 139 private: | 139 private: |
| 140 GuestViewBase* guest_; | 140 GuestViewBase* guest_; |
| 141 | 141 |
| 142 DISALLOW_COPY_AND_ASSIGN(OpenerLifetimeObserver); | 142 DISALLOW_COPY_AND_ASSIGN(OpenerLifetimeObserver); |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 GuestViewBase::GuestViewBase(content::WebContents* owner_web_contents) | 145 GuestViewBase::GuestViewBase(content::WebContents* owner_web_contents) |
| 146 : owner_web_contents_(owner_web_contents), | 146 : owner_web_contents_(owner_web_contents), |
| 147 owner_host_(owner_web_contents->GetLastCommittedURL().host()), |
| 147 browser_context_(owner_web_contents->GetBrowserContext()), | 148 browser_context_(owner_web_contents->GetBrowserContext()), |
| 148 guest_instance_id_( | 149 guest_instance_id_( |
| 149 GuestViewManager::FromBrowserContextIfAvailable(browser_context_)-> | 150 GuestViewManager::FromBrowserContext(browser_context_)-> |
| 150 GetNextInstanceID()), | 151 GetNextInstanceID()), |
| 151 view_instance_id_(guestview::kInstanceIDNone), | 152 view_instance_id_(guestview::kInstanceIDNone), |
| 152 element_instance_id_(guestview::kInstanceIDNone), | 153 element_instance_id_(guestview::kInstanceIDNone), |
| 153 initialized_(false), | 154 initialized_(false), |
| 154 is_being_destroyed_(false), | 155 is_being_destroyed_(false), |
| 155 guest_host_(nullptr), | 156 guest_host_(nullptr), |
| 156 auto_size_enabled_(false), | 157 auto_size_enabled_(false), |
| 157 is_full_page_plugin_(false), | 158 is_full_page_plugin_(false), |
| 158 guest_proxy_routing_id_(MSG_ROUTING_NONE), | 159 guest_proxy_routing_id_(MSG_ROUTING_NONE), |
| 159 weak_ptr_factory_(this) { | 160 weak_ptr_factory_(this) { |
| 160 } | 161 } |
| 161 | 162 |
| 162 void GuestViewBase::Init(const base::DictionaryValue& create_params, | 163 void GuestViewBase::Init(const base::DictionaryValue& create_params, |
| 163 const WebContentsCreatedCallback& callback) { | 164 const WebContentsCreatedCallback& callback) { |
| 164 if (initialized_) | 165 if (initialized_) |
| 165 return; | 166 return; |
| 166 initialized_ = true; | 167 initialized_ = true; |
| 167 | 168 |
| 168 if (!GuestViewManager::FromBrowserContextIfAvailable(browser_context_)-> | 169 if (!GuestViewManager::FromBrowserContext(browser_context_)-> |
| 169 IsGuestAvailableToContext(this, &owner_extension_id_)) { | 170 IsGuestAvailableToContext(this)) { |
| 170 // The derived class did not create a WebContents so this class serves no | 171 // The derived class did not create a WebContents so this class serves no |
| 171 // purpose. Let's self-destruct. | 172 // purpose. Let's self-destruct. |
| 172 delete this; | 173 delete this; |
| 173 callback.Run(nullptr); | 174 callback.Run(nullptr); |
| 174 return; | 175 return; |
| 175 } | 176 } |
| 176 | 177 |
| 177 scoped_ptr<base::DictionaryValue> params(create_params.DeepCopy()); | 178 scoped_ptr<base::DictionaryValue> params(create_params.DeepCopy()); |
| 178 CreateWebContents(create_params, | 179 CreateWebContents(create_params, |
| 179 base::Bind(&GuestViewBase::CompleteInit, | 180 base::Bind(&GuestViewBase::CompleteInit, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 201 // At this point, we have just created the guest WebContents, we need to add | 202 // At this point, we have just created the guest WebContents, we need to add |
| 202 // an observer to the owner WebContents. This observer will be responsible | 203 // an observer to the owner WebContents. This observer will be responsible |
| 203 // for destroying the guest WebContents if the owner goes away. | 204 // for destroying the guest WebContents if the owner goes away. |
| 204 owner_contents_observer_.reset( | 205 owner_contents_observer_.reset( |
| 205 new OwnerContentsObserver(this, owner_web_contents_)); | 206 new OwnerContentsObserver(this, owner_web_contents_)); |
| 206 | 207 |
| 207 WebContentsObserver::Observe(guest_web_contents); | 208 WebContentsObserver::Observe(guest_web_contents); |
| 208 guest_web_contents->SetDelegate(this); | 209 guest_web_contents->SetDelegate(this); |
| 209 webcontents_guestview_map.Get().insert( | 210 webcontents_guestview_map.Get().insert( |
| 210 std::make_pair(guest_web_contents, this)); | 211 std::make_pair(guest_web_contents, this)); |
| 211 GuestViewManager::FromBrowserContextIfAvailable(browser_context_)-> | 212 GuestViewManager::FromBrowserContext(browser_context_)-> |
| 212 AddGuest(guest_instance_id_, guest_web_contents); | 213 AddGuest(guest_instance_id_, guest_web_contents); |
| 213 | 214 |
| 214 // Populate the view instance ID if we have it on creation. | 215 // Populate the view instance ID if we have it on creation. |
| 215 create_params.GetInteger(guestview::kParameterInstanceId, | 216 create_params.GetInteger(guestview::kParameterInstanceId, |
| 216 &view_instance_id_); | 217 &view_instance_id_); |
| 217 | 218 |
| 218 if (CanRunInDetachedState()) | 219 if (CanRunInDetachedState()) |
| 219 SetUpSizing(create_params); | 220 SetUpSizing(create_params); |
| 220 | 221 |
| 221 // Observe guest zoom changes. | 222 // Observe guest zoom changes. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 325 } |
| 325 | 326 |
| 326 // static | 327 // static |
| 327 GuestViewBase* GuestViewBase::From(int owner_process_id, | 328 GuestViewBase* GuestViewBase::From(int owner_process_id, |
| 328 int guest_instance_id) { | 329 int guest_instance_id) { |
| 329 auto host = content::RenderProcessHost::FromID(owner_process_id); | 330 auto host = content::RenderProcessHost::FromID(owner_process_id); |
| 330 if (!host) | 331 if (!host) |
| 331 return nullptr; | 332 return nullptr; |
| 332 | 333 |
| 333 content::WebContents* guest_web_contents = | 334 content::WebContents* guest_web_contents = |
| 334 GuestViewManager::FromBrowserContextIfAvailable( | 335 GuestViewManager::FromBrowserContext( |
| 335 host->GetBrowserContext())-> | 336 host->GetBrowserContext())-> |
| 336 GetGuestByInstanceIDSafely(guest_instance_id, owner_process_id); | 337 GetGuestByInstanceIDSafely(guest_instance_id, owner_process_id); |
| 337 if (!guest_web_contents) | 338 if (!guest_web_contents) |
| 338 return nullptr; | 339 return nullptr; |
| 339 | 340 |
| 340 return GuestViewBase::FromWebContents(guest_web_contents); | 341 return GuestViewBase::FromWebContents(guest_web_contents); |
| 341 } | 342 } |
| 342 | 343 |
| 343 // static | 344 // static |
| 344 WebContents* GuestViewBase::GetTopLevelWebContents(WebContents* web_contents) { | 345 WebContents* GuestViewBase::GetTopLevelWebContents(WebContents* web_contents) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 363 bool GuestViewBase::IsDragAndDropEnabled() const { | 364 bool GuestViewBase::IsDragAndDropEnabled() const { |
| 364 return false; | 365 return false; |
| 365 } | 366 } |
| 366 | 367 |
| 367 bool GuestViewBase::ZoomPropagatesFromEmbedderToGuest() const { | 368 bool GuestViewBase::ZoomPropagatesFromEmbedderToGuest() const { |
| 368 return true; | 369 return true; |
| 369 } | 370 } |
| 370 | 371 |
| 371 content::WebContents* GuestViewBase::CreateNewGuestWindow( | 372 content::WebContents* GuestViewBase::CreateNewGuestWindow( |
| 372 const content::WebContents::CreateParams& create_params) { | 373 const content::WebContents::CreateParams& create_params) { |
| 373 auto guest_manager = | 374 auto guest_manager = GuestViewManager::FromBrowserContext(browser_context()); |
| 374 GuestViewManager::FromBrowserContextIfAvailable(browser_context()); | |
| 375 return guest_manager->CreateGuestWithWebContentsParams( | 375 return guest_manager->CreateGuestWithWebContentsParams( |
| 376 GetViewType(), | 376 GetViewType(), |
| 377 owner_web_contents(), | 377 owner_web_contents(), |
| 378 create_params); | 378 create_params); |
| 379 } | 379 } |
| 380 | 380 |
| 381 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { | 381 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { |
| 382 DCHECK(guest_proxy_routing_id_ == MSG_ROUTING_NONE || | 382 DCHECK(guest_proxy_routing_id_ == MSG_ROUTING_NONE || |
| 383 guest_proxy_routing_id == guest_proxy_routing_id_); | 383 guest_proxy_routing_id == guest_proxy_routing_id_); |
| 384 guest_proxy_routing_id_ = guest_proxy_routing_id; | 384 guest_proxy_routing_id_ = guest_proxy_routing_id; |
| 385 | 385 |
| 386 opener_lifetime_observer_.reset(); | 386 opener_lifetime_observer_.reset(); |
| 387 | 387 |
| 388 SetUpSizing(*attach_params()); | 388 SetUpSizing(*attach_params()); |
| 389 | 389 |
| 390 // Give the derived class an opportunity to perform some actions. | 390 // Give the derived class an opportunity to perform some actions. |
| 391 DidAttachToEmbedder(); | 391 DidAttachToEmbedder(); |
| 392 | 392 |
| 393 // Inform the associated GuestViewContainer that the contentWindow is ready. | 393 // Inform the associated GuestViewContainer that the contentWindow is ready. |
| 394 embedder_web_contents()->Send(new GuestViewMsg_GuestAttached( | 394 embedder_web_contents()->Send(new GuestViewMsg_GuestAttached( |
| 395 element_instance_id_, | 395 element_instance_id_, |
| 396 guest_proxy_routing_id)); | 396 guest_proxy_routing_id)); |
| 397 | 397 |
| 398 SendQueuedEvents(); | 398 SendQueuedEvents(); |
| 399 } | 399 } |
| 400 | 400 |
| 401 void GuestViewBase::DidDetach() { | 401 void GuestViewBase::DidDetach() { |
| 402 GuestViewManager::FromBrowserContextIfAvailable(browser_context_)-> | 402 GuestViewManager::FromBrowserContext(browser_context_)->DetachGuest(this); |
| 403 DetachGuest(this); | |
| 404 StopTrackingEmbedderZoomLevel(); | 403 StopTrackingEmbedderZoomLevel(); |
| 405 owner_web_contents()->Send(new GuestViewMsg_GuestDetached( | 404 owner_web_contents()->Send(new GuestViewMsg_GuestDetached( |
| 406 element_instance_id_)); | 405 element_instance_id_)); |
| 407 element_instance_id_ = guestview::kInstanceIDNone; | 406 element_instance_id_ = guestview::kInstanceIDNone; |
| 408 } | 407 } |
| 409 | 408 |
| 410 WebContents* GuestViewBase::GetOwnerWebContents() const { | 409 WebContents* GuestViewBase::GetOwnerWebContents() const { |
| 411 return owner_web_contents_; | 410 return owner_web_contents_; |
| 412 } | 411 } |
| 413 | 412 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 443 // Invalidate weak pointers now so that bound callbacks cannot be called late | 442 // Invalidate weak pointers now so that bound callbacks cannot be called late |
| 444 // into destruction. We must call this after WillDestroy because derived types | 443 // into destruction. We must call this after WillDestroy because derived types |
| 445 // may wish to access their openers. | 444 // may wish to access their openers. |
| 446 weak_ptr_factory_.InvalidateWeakPtrs(); | 445 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 447 | 446 |
| 448 // Give the content module an opportunity to perform some cleanup. | 447 // Give the content module an opportunity to perform some cleanup. |
| 449 guest_host_->WillDestroy(); | 448 guest_host_->WillDestroy(); |
| 450 guest_host_ = nullptr; | 449 guest_host_ = nullptr; |
| 451 | 450 |
| 452 webcontents_guestview_map.Get().erase(web_contents()); | 451 webcontents_guestview_map.Get().erase(web_contents()); |
| 453 GuestViewManager::FromBrowserContextIfAvailable(browser_context_)-> | 452 GuestViewManager::FromBrowserContext(browser_context_)-> |
| 454 RemoveGuest(guest_instance_id_); | 453 RemoveGuest(guest_instance_id_); |
| 455 pending_events_.clear(); | 454 pending_events_.clear(); |
| 456 | 455 |
| 457 delete web_contents(); | 456 delete web_contents(); |
| 458 } | 457 } |
| 459 | 458 |
| 460 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { | 459 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { |
| 461 attach_params_.reset(params.DeepCopy()); | 460 attach_params_.reset(params.DeepCopy()); |
| 462 attach_params_->GetInteger(guestview::kParameterInstanceId, | 461 attach_params_->GetInteger(guestview::kParameterInstanceId, |
| 463 &view_instance_id_); | 462 &view_instance_id_); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 481 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, | 480 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, |
| 482 int element_instance_id, | 481 int element_instance_id, |
| 483 bool is_full_page_plugin) { | 482 bool is_full_page_plugin) { |
| 484 if (owner_web_contents_ != embedder_web_contents) { | 483 if (owner_web_contents_ != embedder_web_contents) { |
| 485 DCHECK_EQ(owner_contents_observer_->web_contents(), owner_web_contents_); | 484 DCHECK_EQ(owner_contents_observer_->web_contents(), owner_web_contents_); |
| 486 // Stop tracking the old embedder's zoom level. | 485 // Stop tracking the old embedder's zoom level. |
| 487 StopTrackingEmbedderZoomLevel(); | 486 StopTrackingEmbedderZoomLevel(); |
| 488 owner_web_contents_ = embedder_web_contents; | 487 owner_web_contents_ = embedder_web_contents; |
| 489 owner_contents_observer_.reset( | 488 owner_contents_observer_.reset( |
| 490 new OwnerContentsObserver(this, embedder_web_contents)); | 489 new OwnerContentsObserver(this, embedder_web_contents)); |
| 490 owner_host_ = owner_web_contents_->GetLastCommittedURL().host(); |
| 491 } | 491 } |
| 492 | 492 |
| 493 // Start tracking the new embedder's zoom level. | 493 // Start tracking the new embedder's zoom level. |
| 494 StartTrackingEmbedderZoomLevel(); | 494 StartTrackingEmbedderZoomLevel(); |
| 495 element_instance_id_ = element_instance_id; | 495 element_instance_id_ = element_instance_id; |
| 496 is_full_page_plugin_ = is_full_page_plugin; | 496 is_full_page_plugin_ = is_full_page_plugin; |
| 497 | 497 |
| 498 WillAttachToEmbedder(); | 498 WillAttachToEmbedder(); |
| 499 } | 499 } |
| 500 | 500 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 | 807 |
| 808 auto embedder_zoom_controller = | 808 auto embedder_zoom_controller = |
| 809 ui_zoom::ZoomController::FromWebContents(owner_web_contents()); | 809 ui_zoom::ZoomController::FromWebContents(owner_web_contents()); |
| 810 // Chrome Apps do not have a ZoomController. | 810 // Chrome Apps do not have a ZoomController. |
| 811 if (!embedder_zoom_controller) | 811 if (!embedder_zoom_controller) |
| 812 return; | 812 return; |
| 813 embedder_zoom_controller->RemoveObserver(this); | 813 embedder_zoom_controller->RemoveObserver(this); |
| 814 } | 814 } |
| 815 | 815 |
| 816 } // namespace extensions | 816 } // namespace extensions |
| OLD | NEW |