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), |
Charlie Reis
2015/03/09 21:25:22
You need to initialize guest_proxy_routing_id_ to
Fady Samuel
2015/03/09 23:02:42
Done.
| |
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 create_params.GetInteger(guestview::kParameterInstanceId, | 225 create_params.GetInteger(guestview::kParameterInstanceId, |
226 &view_instance_id_); | 226 &view_instance_id_); |
227 | 227 |
228 if (CanRunInDetachedState()) | 228 if (CanRunInDetachedState()) |
229 SetUpSizing(create_params); | 229 SetUpSizing(create_params); |
230 | 230 |
231 // Give the derived class an opportunity to perform additional initialization. | 231 // Give the derived class an opportunity to perform additional initialization. |
232 DidInitialize(create_params); | 232 DidInitialize(create_params); |
233 } | 233 } |
234 | 234 |
235 void GuestViewBase::LoadURLWithParams( | |
Charlie Reis
2015/03/09 21:25:22
Can this get called multiple times? We don't want
Fady Samuel
2015/03/09 23:02:41
Done.
| |
236 const content::NavigationController::LoadURLParams& load_params) { | |
237 guest_proxy_routing_id_ = proxy_host()->LoadURLWithParams(load_params); | |
Charlie Reis
2015/03/09 18:52:59
If we can get the routing ID from the GuestProxyHo
Charlie Reis
2015/03/09 21:25:22
Disregard. Only makes sense in Option 2.
Fady Samuel
2015/03/09 23:02:41
Done.
Fady Samuel
2015/03/09 23:02:41
Done.
| |
238 } | |
239 | |
235 void GuestViewBase::DispatchOnResizeEvent(const gfx::Size& old_size, | 240 void GuestViewBase::DispatchOnResizeEvent(const gfx::Size& old_size, |
236 const gfx::Size& new_size) { | 241 const gfx::Size& new_size) { |
237 if (new_size == old_size) | 242 if (new_size == old_size) |
238 return; | 243 return; |
239 | 244 |
240 // Dispatch the onResize event. | 245 // Dispatch the onResize event. |
241 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 246 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
242 args->SetInteger(guestview::kOldWidth, old_size.width()); | 247 args->SetInteger(guestview::kOldWidth, old_size.width()); |
243 args->SetInteger(guestview::kOldHeight, old_size.height()); | 248 args->SetInteger(guestview::kOldHeight, old_size.height()); |
244 args->SetInteger(guestview::kNewWidth, new_size.width()); | 249 args->SetInteger(guestview::kNewWidth, new_size.width()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 } else { | 289 } else { |
285 new_size = gfx::Size(guestview::kDefaultWidth, guestview::kDefaultHeight); | 290 new_size = gfx::Size(guestview::kDefaultWidth, guestview::kDefaultHeight); |
286 } | 291 } |
287 | 292 |
288 if (auto_size_enabled_) { | 293 if (auto_size_enabled_) { |
289 // Autosize was previously enabled. | 294 // Autosize was previously enabled. |
290 rvh->DisableAutoResize(new_size); | 295 rvh->DisableAutoResize(new_size); |
291 GuestSizeChangedDueToAutoSize(guest_size_, new_size); | 296 GuestSizeChangedDueToAutoSize(guest_size_, new_size); |
292 } else { | 297 } else { |
293 // Autosize was already disabled. | 298 // Autosize was already disabled. |
294 guest_sizer_->SizeContents(new_size); | 299 guest_proxy_host_->SizeContents(new_size); |
295 } | 300 } |
296 | 301 |
297 DispatchOnResizeEvent(guest_size_, new_size); | 302 DispatchOnResizeEvent(guest_size_, new_size); |
298 guest_size_ = new_size; | 303 guest_size_ = new_size; |
299 } | 304 } |
300 | 305 |
301 auto_size_enabled_ = enable_auto_size; | 306 auto_size_enabled_ = enable_auto_size; |
302 } | 307 } |
303 | 308 |
304 // static | 309 // static |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 content::WebContents* GuestViewBase::CreateNewGuestWindow( | 377 content::WebContents* GuestViewBase::CreateNewGuestWindow( |
373 const content::WebContents::CreateParams& create_params) { | 378 const content::WebContents::CreateParams& create_params) { |
374 auto guest_manager = GuestViewManager::FromBrowserContext(browser_context()); | 379 auto guest_manager = GuestViewManager::FromBrowserContext(browser_context()); |
375 return guest_manager->CreateGuestWithWebContentsParams( | 380 return guest_manager->CreateGuestWithWebContentsParams( |
376 GetViewType(), | 381 GetViewType(), |
377 owner_web_contents(), | 382 owner_web_contents(), |
378 create_params); | 383 create_params); |
379 } | 384 } |
380 | 385 |
381 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { | 386 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { |
387 guest_proxy_routing_id_ = guest_proxy_routing_id; | |
Charlie Reis
2015/03/09 21:25:22
Similar DCHECK to make sure it doesn't change afte
Fady Samuel
2015/03/09 23:02:42
Done.
| |
388 | |
382 opener_lifetime_observer_.reset(); | 389 opener_lifetime_observer_.reset(); |
383 | 390 |
384 SetUpSizing(*attach_params()); | 391 SetUpSizing(*attach_params()); |
385 | 392 |
386 // Give the derived class an opportunity to perform some actions. | 393 // Give the derived class an opportunity to perform some actions. |
387 DidAttachToEmbedder(); | 394 DidAttachToEmbedder(); |
388 | 395 |
389 // Inform the associated GuestViewContainer that the contentWindow is ready. | 396 // Inform the associated GuestViewContainer that the contentWindow is ready. |
390 embedder_web_contents()->Send(new GuestViewMsg_GuestAttached( | 397 embedder_web_contents()->Send(new GuestViewMsg_GuestAttached( |
391 element_instance_id_, | 398 element_instance_id_, |
(...skipping 25 matching lines...) Expand all Loading... | |
417 const GURL& GuestViewBase::GetOwnerSiteURL() const { | 424 const GURL& GuestViewBase::GetOwnerSiteURL() const { |
418 return owner_web_contents()->GetLastCommittedURL(); | 425 return owner_web_contents()->GetLastCommittedURL(); |
419 } | 426 } |
420 | 427 |
421 void GuestViewBase::Destroy() { | 428 void GuestViewBase::Destroy() { |
422 if (is_being_destroyed_) | 429 if (is_being_destroyed_) |
423 return; | 430 return; |
424 | 431 |
425 is_being_destroyed_ = true; | 432 is_being_destroyed_ = true; |
426 | 433 |
427 guest_sizer_ = nullptr; | |
428 | |
429 // It is important to clear owner_web_contents_ after the call to | 434 // It is important to clear owner_web_contents_ after the call to |
430 // StopTrackingEmbedderZoomLevel(), but before the rest of | 435 // StopTrackingEmbedderZoomLevel(), but before the rest of |
431 // the statements in this function. | 436 // the statements in this function. |
432 StopTrackingEmbedderZoomLevel(); | 437 StopTrackingEmbedderZoomLevel(); |
433 owner_web_contents_ = nullptr; | 438 owner_web_contents_ = nullptr; |
434 | 439 |
435 DCHECK(web_contents()); | 440 DCHECK(web_contents()); |
436 | 441 |
437 // Give the derived class an opportunity to perform some cleanup. | 442 // Give the derived class an opportunity to perform some cleanup. |
438 WillDestroy(); | 443 WillDestroy(); |
439 | 444 |
440 // Invalidate weak pointers now so that bound callbacks cannot be called late | 445 // Invalidate weak pointers now so that bound callbacks cannot be called late |
441 // into destruction. We must call this after WillDestroy because derived types | 446 // into destruction. We must call this after WillDestroy because derived types |
442 // may wish to access their openers. | 447 // may wish to access their openers. |
443 weak_ptr_factory_.InvalidateWeakPtrs(); | 448 weak_ptr_factory_.InvalidateWeakPtrs(); |
444 | 449 |
445 // Give the content module an opportunity to perform some cleanup. | 450 // Give the content module an opportunity to perform some cleanup. |
446 if (!destruction_callback_.is_null()) | 451 guest_proxy_host_->WillDestroy(); |
447 destruction_callback_.Run(); | 452 guest_proxy_host_ = nullptr; |
448 | 453 |
449 webcontents_guestview_map.Get().erase(web_contents()); | 454 webcontents_guestview_map.Get().erase(web_contents()); |
450 GuestViewManager::FromBrowserContext(browser_context_)-> | 455 GuestViewManager::FromBrowserContext(browser_context_)-> |
451 RemoveGuest(guest_instance_id_); | 456 RemoveGuest(guest_instance_id_); |
452 pending_events_.clear(); | 457 pending_events_.clear(); |
453 | 458 |
454 delete web_contents(); | 459 delete web_contents(); |
455 } | 460 } |
456 | 461 |
457 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { | 462 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { |
458 attach_params_.reset(params.DeepCopy()); | 463 attach_params_.reset(params.DeepCopy()); |
459 attach_params_->GetInteger(guestview::kParameterInstanceId, | 464 attach_params_->GetInteger(guestview::kParameterInstanceId, |
460 &view_instance_id_); | 465 &view_instance_id_); |
461 } | 466 } |
462 | 467 |
463 void GuestViewBase::SetOpener(GuestViewBase* guest) { | 468 void GuestViewBase::SetOpener(GuestViewBase* guest) { |
464 if (guest && guest->IsViewType(GetViewType())) { | 469 if (guest && guest->IsViewType(GetViewType())) { |
465 opener_ = guest->weak_ptr_factory_.GetWeakPtr(); | 470 opener_ = guest->weak_ptr_factory_.GetWeakPtr(); |
466 if (!attached()) | 471 if (!attached()) |
467 opener_lifetime_observer_.reset(new OpenerLifetimeObserver(this)); | 472 opener_lifetime_observer_.reset(new OpenerLifetimeObserver(this)); |
468 return; | 473 return; |
469 } | 474 } |
470 opener_ = base::WeakPtr<GuestViewBase>(); | 475 opener_ = base::WeakPtr<GuestViewBase>(); |
471 opener_lifetime_observer_.reset(); | 476 opener_lifetime_observer_.reset(); |
472 } | 477 } |
473 | 478 |
474 void GuestViewBase::RegisterDestructionCallback( | 479 void GuestViewBase::SetGuestProxyHost( |
475 const DestructionCallback& callback) { | 480 content::GuestProxyHost* guest_proxy_host) { |
476 destruction_callback_ = callback; | 481 guest_proxy_host_ = guest_proxy_host; |
477 } | |
478 | |
479 void GuestViewBase::SetGuestSizer(content::GuestSizer* guest_sizer) { | |
480 guest_sizer_ = guest_sizer; | |
481 } | 482 } |
482 | 483 |
483 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, | 484 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, |
484 int element_instance_id, | 485 int element_instance_id, |
485 bool is_full_page_plugin) { | 486 bool is_full_page_plugin) { |
486 if (owner_web_contents_ != embedder_web_contents) { | 487 if (owner_web_contents_ != embedder_web_contents) { |
487 DCHECK_EQ(owner_lifetime_observer_->web_contents(), owner_web_contents_); | 488 DCHECK_EQ(owner_lifetime_observer_->web_contents(), owner_web_contents_); |
488 // Stop tracking the old embedder's zoom level. | 489 // Stop tracking the old embedder's zoom level. |
489 StopTrackingEmbedderZoomLevel(); | 490 StopTrackingEmbedderZoomLevel(); |
490 owner_web_contents_ = embedder_web_contents; | 491 owner_web_contents_ = embedder_web_contents; |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
813 void GuestViewBase::RegisterGuestViewTypes() { | 814 void GuestViewBase::RegisterGuestViewTypes() { |
814 AppViewGuest::Register(); | 815 AppViewGuest::Register(); |
815 ExtensionOptionsGuest::Register(); | 816 ExtensionOptionsGuest::Register(); |
816 ExtensionViewGuest::Register(); | 817 ExtensionViewGuest::Register(); |
817 MimeHandlerViewGuest::Register(); | 818 MimeHandlerViewGuest::Register(); |
818 SurfaceWorkerGuest::Register(); | 819 SurfaceWorkerGuest::Register(); |
819 WebViewGuest::Register(); | 820 WebViewGuest::Register(); |
820 } | 821 } |
821 | 822 |
822 } // namespace extensions | 823 } // namespace extensions |
OLD | NEW |