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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 GuestViewBase::GuestViewBase(content::WebContents* owner_web_contents) | 146 GuestViewBase::GuestViewBase(content::WebContents* owner_web_contents) |
147 : owner_web_contents_(owner_web_contents), | 147 : owner_web_contents_(owner_web_contents), |
148 browser_context_(owner_web_contents->GetBrowserContext()), | 148 browser_context_(owner_web_contents->GetBrowserContext()), |
149 guest_instance_id_( | 149 guest_instance_id_( |
150 GuestViewManager::FromBrowserContext(browser_context_)-> | 150 GuestViewManager::FromBrowserContext(browser_context_)-> |
151 GetNextInstanceID()), | 151 GetNextInstanceID()), |
152 view_instance_id_(guestview::kInstanceIDNone), | 152 view_instance_id_(guestview::kInstanceIDNone), |
153 element_instance_id_(guestview::kInstanceIDNone), | 153 element_instance_id_(guestview::kInstanceIDNone), |
154 initialized_(false), | 154 initialized_(false), |
155 is_being_destroyed_(false), | 155 is_being_destroyed_(false), |
156 guest_sizer_(nullptr), | 156 guest_proxy_host_(nullptr), |
157 auto_size_enabled_(false), | 157 auto_size_enabled_(false), |
158 is_full_page_plugin_(false), | 158 is_full_page_plugin_(false), |
159 weak_ptr_factory_(this) { | 159 weak_ptr_factory_(this) { |
160 } | 160 } |
161 | 161 |
162 void GuestViewBase::Init(const base::DictionaryValue& create_params, | 162 void GuestViewBase::Init(const base::DictionaryValue& create_params, |
163 const WebContentsCreatedCallback& callback) { | 163 const WebContentsCreatedCallback& callback) { |
164 if (initialized_) | 164 if (initialized_) |
165 return; | 165 return; |
166 initialized_ = true; | 166 initialized_ = true; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } else { | 284 } else { |
285 new_size = gfx::Size(guestview::kDefaultWidth, guestview::kDefaultHeight); | 285 new_size = gfx::Size(guestview::kDefaultWidth, guestview::kDefaultHeight); |
286 } | 286 } |
287 | 287 |
288 if (auto_size_enabled_) { | 288 if (auto_size_enabled_) { |
289 // Autosize was previously enabled. | 289 // Autosize was previously enabled. |
290 rvh->DisableAutoResize(new_size); | 290 rvh->DisableAutoResize(new_size); |
291 GuestSizeChangedDueToAutoSize(guest_size_, new_size); | 291 GuestSizeChangedDueToAutoSize(guest_size_, new_size); |
292 } else { | 292 } else { |
293 // Autosize was already disabled. | 293 // Autosize was already disabled. |
294 guest_sizer_->SizeContents(new_size); | 294 guest_proxy_host_->SizeContents(new_size); |
295 } | 295 } |
296 | 296 |
297 DispatchOnResizeEvent(guest_size_, new_size); | 297 DispatchOnResizeEvent(guest_size_, new_size); |
298 guest_size_ = new_size; | 298 guest_size_ = new_size; |
299 } | 299 } |
300 | 300 |
301 auto_size_enabled_ = enable_auto_size; | 301 auto_size_enabled_ = enable_auto_size; |
302 } | 302 } |
303 | 303 |
304 // static | 304 // static |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 371 |
372 content::WebContents* GuestViewBase::CreateNewGuestWindow( | 372 content::WebContents* GuestViewBase::CreateNewGuestWindow( |
373 const content::WebContents::CreateParams& create_params) { | 373 const content::WebContents::CreateParams& create_params) { |
374 auto guest_manager = GuestViewManager::FromBrowserContext(browser_context()); | 374 auto guest_manager = GuestViewManager::FromBrowserContext(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() { |
382 opener_lifetime_observer_.reset(); | 382 opener_lifetime_observer_.reset(); |
383 | 383 |
384 SetUpSizing(*attach_params()); | 384 SetUpSizing(*attach_params()); |
385 | 385 |
386 // Give the derived class an opportunity to perform some actions. | 386 // Give the derived class an opportunity to perform some actions. |
387 DidAttachToEmbedder(); | 387 DidAttachToEmbedder(); |
388 | 388 |
389 // Inform the associated GuestViewContainer that the contentWindow is ready. | 389 // Inform the associated GuestViewContainer that the contentWindow is ready. |
390 embedder_web_contents()->Send(new GuestViewMsg_GuestAttached( | 390 embedder_web_contents()->Send(new GuestViewMsg_GuestAttached( |
391 element_instance_id_, | 391 element_instance_id_, |
392 guest_proxy_routing_id)); | 392 guest_proxy_host_->GetGuestProxyRoutingID())); |
393 | 393 |
394 SendQueuedEvents(); | 394 SendQueuedEvents(); |
395 } | 395 } |
396 | 396 |
397 void GuestViewBase::DidDetach() { | 397 void GuestViewBase::DidDetach() { |
398 GuestViewManager::FromBrowserContext(browser_context_)->DetachGuest(this); | 398 GuestViewManager::FromBrowserContext(browser_context_)->DetachGuest(this); |
399 StopTrackingEmbedderZoomLevel(); | 399 StopTrackingEmbedderZoomLevel(); |
400 owner_web_contents()->Send(new GuestViewMsg_GuestDetached( | 400 owner_web_contents()->Send(new GuestViewMsg_GuestDetached( |
401 element_instance_id_)); | 401 element_instance_id_)); |
402 element_instance_id_ = guestview::kInstanceIDNone; | 402 element_instance_id_ = guestview::kInstanceIDNone; |
(...skipping 14 matching lines...) Expand all Loading... |
417 const GURL& GuestViewBase::GetOwnerSiteURL() const { | 417 const GURL& GuestViewBase::GetOwnerSiteURL() const { |
418 return owner_web_contents()->GetLastCommittedURL(); | 418 return owner_web_contents()->GetLastCommittedURL(); |
419 } | 419 } |
420 | 420 |
421 void GuestViewBase::Destroy() { | 421 void GuestViewBase::Destroy() { |
422 if (is_being_destroyed_) | 422 if (is_being_destroyed_) |
423 return; | 423 return; |
424 | 424 |
425 is_being_destroyed_ = true; | 425 is_being_destroyed_ = true; |
426 | 426 |
427 guest_sizer_ = nullptr; | 427 guest_proxy_host_ = nullptr; |
428 | 428 |
429 // It is important to clear owner_web_contents_ after the call to | 429 // It is important to clear owner_web_contents_ after the call to |
430 // StopTrackingEmbedderZoomLevel(), but before the rest of | 430 // StopTrackingEmbedderZoomLevel(), but before the rest of |
431 // the statements in this function. | 431 // the statements in this function. |
432 StopTrackingEmbedderZoomLevel(); | 432 StopTrackingEmbedderZoomLevel(); |
433 owner_web_contents_ = nullptr; | 433 owner_web_contents_ = nullptr; |
434 | 434 |
435 DCHECK(web_contents()); | 435 DCHECK(web_contents()); |
436 | 436 |
437 // Give the derived class an opportunity to perform some cleanup. | 437 // Give the derived class an opportunity to perform some cleanup. |
438 WillDestroy(); | 438 WillDestroy(); |
439 | 439 |
440 // Invalidate weak pointers now so that bound callbacks cannot be called late | 440 // Invalidate weak pointers now so that bound callbacks cannot be called late |
441 // into destruction. We must call this after WillDestroy because derived types | 441 // into destruction. We must call this after WillDestroy because derived types |
442 // may wish to access their openers. | 442 // may wish to access their openers. |
443 weak_ptr_factory_.InvalidateWeakPtrs(); | 443 weak_ptr_factory_.InvalidateWeakPtrs(); |
444 | 444 |
445 // Give the content module an opportunity to perform some cleanup. | 445 // Give the content module an opportunity to perform some cleanup. |
446 if (!destruction_callback_.is_null()) | 446 guest_proxy_host_->WillDestroy(); |
447 destruction_callback_.Run(); | |
448 | 447 |
449 webcontents_guestview_map.Get().erase(web_contents()); | 448 webcontents_guestview_map.Get().erase(web_contents()); |
450 GuestViewManager::FromBrowserContext(browser_context_)-> | 449 GuestViewManager::FromBrowserContext(browser_context_)-> |
451 RemoveGuest(guest_instance_id_); | 450 RemoveGuest(guest_instance_id_); |
452 pending_events_.clear(); | 451 pending_events_.clear(); |
453 | 452 |
454 delete web_contents(); | 453 delete web_contents(); |
455 } | 454 } |
456 | 455 |
457 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { | 456 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { |
458 attach_params_.reset(params.DeepCopy()); | 457 attach_params_.reset(params.DeepCopy()); |
459 attach_params_->GetInteger(guestview::kParameterInstanceId, | 458 attach_params_->GetInteger(guestview::kParameterInstanceId, |
460 &view_instance_id_); | 459 &view_instance_id_); |
461 } | 460 } |
462 | 461 |
463 void GuestViewBase::SetOpener(GuestViewBase* guest) { | 462 void GuestViewBase::SetOpener(GuestViewBase* guest) { |
464 if (guest && guest->IsViewType(GetViewType())) { | 463 if (guest && guest->IsViewType(GetViewType())) { |
465 opener_ = guest->weak_ptr_factory_.GetWeakPtr(); | 464 opener_ = guest->weak_ptr_factory_.GetWeakPtr(); |
466 if (!attached()) | 465 if (!attached()) |
467 opener_lifetime_observer_.reset(new OpenerLifetimeObserver(this)); | 466 opener_lifetime_observer_.reset(new OpenerLifetimeObserver(this)); |
468 return; | 467 return; |
469 } | 468 } |
470 opener_ = base::WeakPtr<GuestViewBase>(); | 469 opener_ = base::WeakPtr<GuestViewBase>(); |
471 opener_lifetime_observer_.reset(); | 470 opener_lifetime_observer_.reset(); |
472 } | 471 } |
473 | 472 |
474 void GuestViewBase::RegisterDestructionCallback( | 473 void GuestViewBase::SetGuestProxyHost( |
475 const DestructionCallback& callback) { | 474 content::GuestProxyHost* guest_proxy_host) { |
476 destruction_callback_ = callback; | 475 guest_proxy_host_ = guest_proxy_host; |
477 } | |
478 | |
479 void GuestViewBase::SetGuestSizer(content::GuestSizer* guest_sizer) { | |
480 guest_sizer_ = guest_sizer; | |
481 } | 476 } |
482 | 477 |
483 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, | 478 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, |
484 int element_instance_id, | 479 int element_instance_id, |
485 bool is_full_page_plugin) { | 480 bool is_full_page_plugin) { |
486 if (owner_web_contents_ != embedder_web_contents) { | 481 if (owner_web_contents_ != embedder_web_contents) { |
487 DCHECK_EQ(owner_lifetime_observer_->web_contents(), owner_web_contents_); | 482 DCHECK_EQ(owner_lifetime_observer_->web_contents(), owner_web_contents_); |
488 // Stop tracking the old embedder's zoom level. | 483 // Stop tracking the old embedder's zoom level. |
489 StopTrackingEmbedderZoomLevel(); | 484 StopTrackingEmbedderZoomLevel(); |
490 owner_web_contents_ = embedder_web_contents; | 485 owner_web_contents_ = embedder_web_contents; |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 void GuestViewBase::RegisterGuestViewTypes() { | 808 void GuestViewBase::RegisterGuestViewTypes() { |
814 AppViewGuest::Register(); | 809 AppViewGuest::Register(); |
815 ExtensionOptionsGuest::Register(); | 810 ExtensionOptionsGuest::Register(); |
816 ExtensionViewGuest::Register(); | 811 ExtensionViewGuest::Register(); |
817 MimeHandlerViewGuest::Register(); | 812 MimeHandlerViewGuest::Register(); |
818 SurfaceWorkerGuest::Register(); | 813 SurfaceWorkerGuest::Register(); |
819 WebViewGuest::Register(); | 814 WebViewGuest::Register(); |
820 } | 815 } |
821 | 816 |
822 } // namespace extensions | 817 } // namespace extensions |
OLD | NEW |