Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: extensions/browser/guest_view/guest_view_base.cc

Issue 910073003: <webview>: Make contentWindow available prior to attachment (on display:none). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nit Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_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 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 const Feature* feature = FeatureProvider::GetAPIFeature(GetAPINamespace()); 169 const Feature* feature = FeatureProvider::GetAPIFeature(GetAPINamespace());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 create_params.GetInteger(guestview::kParameterInstanceId, 226 create_params.GetInteger(guestview::kParameterInstanceId,
226 &view_instance_id_); 227 &view_instance_id_);
227 228
228 if (CanRunInDetachedState()) 229 if (CanRunInDetachedState())
229 SetUpSizing(create_params); 230 SetUpSizing(create_params);
230 231
231 // Give the derived class an opportunity to perform additional initialization. 232 // Give the derived class an opportunity to perform additional initialization.
232 DidInitialize(create_params); 233 DidInitialize(create_params);
233 } 234 }
234 235
236 void GuestViewBase::LoadURLWithParams(
237 const content::NavigationController::LoadURLParams& load_params) {
238 int guest_proxy_routing_id = host()->LoadURLWithParams(load_params);
239 DCHECK(guest_proxy_routing_id_ == MSG_ROUTING_NONE ||
240 guest_proxy_routing_id == guest_proxy_routing_id_);
241 guest_proxy_routing_id_ = guest_proxy_routing_id;
242 }
243
235 void GuestViewBase::DispatchOnResizeEvent(const gfx::Size& old_size, 244 void GuestViewBase::DispatchOnResizeEvent(const gfx::Size& old_size,
236 const gfx::Size& new_size) { 245 const gfx::Size& new_size) {
237 if (new_size == old_size) 246 if (new_size == old_size)
238 return; 247 return;
239 248
240 // Dispatch the onResize event. 249 // Dispatch the onResize event.
241 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 250 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
242 args->SetInteger(guestview::kOldWidth, old_size.width()); 251 args->SetInteger(guestview::kOldWidth, old_size.width());
243 args->SetInteger(guestview::kOldHeight, old_size.height()); 252 args->SetInteger(guestview::kOldHeight, old_size.height());
244 args->SetInteger(guestview::kNewWidth, new_size.width()); 253 args->SetInteger(guestview::kNewWidth, new_size.width());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } else { 293 } else {
285 new_size = gfx::Size(guestview::kDefaultWidth, guestview::kDefaultHeight); 294 new_size = gfx::Size(guestview::kDefaultWidth, guestview::kDefaultHeight);
286 } 295 }
287 296
288 if (auto_size_enabled_) { 297 if (auto_size_enabled_) {
289 // Autosize was previously enabled. 298 // Autosize was previously enabled.
290 rvh->DisableAutoResize(new_size); 299 rvh->DisableAutoResize(new_size);
291 GuestSizeChangedDueToAutoSize(guest_size_, new_size); 300 GuestSizeChangedDueToAutoSize(guest_size_, new_size);
292 } else { 301 } else {
293 // Autosize was already disabled. 302 // Autosize was already disabled.
294 guest_sizer_->SizeContents(new_size); 303 guest_host_->SizeContents(new_size);
295 } 304 }
296 305
297 DispatchOnResizeEvent(guest_size_, new_size); 306 DispatchOnResizeEvent(guest_size_, new_size);
298 guest_size_ = new_size; 307 guest_size_ = new_size;
299 } 308 }
300 309
301 auto_size_enabled_ = enable_auto_size; 310 auto_size_enabled_ = enable_auto_size;
302 } 311 }
303 312
304 // static 313 // static
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 content::WebContents* GuestViewBase::CreateNewGuestWindow( 381 content::WebContents* GuestViewBase::CreateNewGuestWindow(
373 const content::WebContents::CreateParams& create_params) { 382 const content::WebContents::CreateParams& create_params) {
374 auto guest_manager = GuestViewManager::FromBrowserContext(browser_context()); 383 auto guest_manager = GuestViewManager::FromBrowserContext(browser_context());
375 return guest_manager->CreateGuestWithWebContentsParams( 384 return guest_manager->CreateGuestWithWebContentsParams(
376 GetViewType(), 385 GetViewType(),
377 owner_web_contents(), 386 owner_web_contents(),
378 create_params); 387 create_params);
379 } 388 }
380 389
381 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { 390 void GuestViewBase::DidAttach(int guest_proxy_routing_id) {
391 DCHECK(guest_proxy_routing_id_ == MSG_ROUTING_NONE ||
392 guest_proxy_routing_id == guest_proxy_routing_id_);
393 guest_proxy_routing_id_ = guest_proxy_routing_id;
394
382 opener_lifetime_observer_.reset(); 395 opener_lifetime_observer_.reset();
383 396
384 SetUpSizing(*attach_params()); 397 SetUpSizing(*attach_params());
385 398
386 // Give the derived class an opportunity to perform some actions. 399 // Give the derived class an opportunity to perform some actions.
387 DidAttachToEmbedder(); 400 DidAttachToEmbedder();
388 401
389 // Inform the associated GuestViewContainer that the contentWindow is ready. 402 // Inform the associated GuestViewContainer that the contentWindow is ready.
390 embedder_web_contents()->Send(new GuestViewMsg_GuestAttached( 403 embedder_web_contents()->Send(new GuestViewMsg_GuestAttached(
391 element_instance_id_, 404 element_instance_id_,
(...skipping 25 matching lines...) Expand all
417 const GURL& GuestViewBase::GetOwnerSiteURL() const { 430 const GURL& GuestViewBase::GetOwnerSiteURL() const {
418 return owner_web_contents()->GetLastCommittedURL(); 431 return owner_web_contents()->GetLastCommittedURL();
419 } 432 }
420 433
421 void GuestViewBase::Destroy() { 434 void GuestViewBase::Destroy() {
422 if (is_being_destroyed_) 435 if (is_being_destroyed_)
423 return; 436 return;
424 437
425 is_being_destroyed_ = true; 438 is_being_destroyed_ = true;
426 439
427 guest_sizer_ = nullptr;
428
429 // It is important to clear owner_web_contents_ after the call to 440 // It is important to clear owner_web_contents_ after the call to
430 // StopTrackingEmbedderZoomLevel(), but before the rest of 441 // StopTrackingEmbedderZoomLevel(), but before the rest of
431 // the statements in this function. 442 // the statements in this function.
432 StopTrackingEmbedderZoomLevel(); 443 StopTrackingEmbedderZoomLevel();
433 owner_web_contents_ = nullptr; 444 owner_web_contents_ = nullptr;
434 445
435 DCHECK(web_contents()); 446 DCHECK(web_contents());
436 447
437 // Give the derived class an opportunity to perform some cleanup. 448 // Give the derived class an opportunity to perform some cleanup.
438 WillDestroy(); 449 WillDestroy();
439 450
440 // Invalidate weak pointers now so that bound callbacks cannot be called late 451 // Invalidate weak pointers now so that bound callbacks cannot be called late
441 // into destruction. We must call this after WillDestroy because derived types 452 // into destruction. We must call this after WillDestroy because derived types
442 // may wish to access their openers. 453 // may wish to access their openers.
443 weak_ptr_factory_.InvalidateWeakPtrs(); 454 weak_ptr_factory_.InvalidateWeakPtrs();
444 455
445 // Give the content module an opportunity to perform some cleanup. 456 // Give the content module an opportunity to perform some cleanup.
446 if (!destruction_callback_.is_null()) 457 guest_host_->WillDestroy();
447 destruction_callback_.Run(); 458 guest_host_ = nullptr;
448 459
449 webcontents_guestview_map.Get().erase(web_contents()); 460 webcontents_guestview_map.Get().erase(web_contents());
450 GuestViewManager::FromBrowserContext(browser_context_)-> 461 GuestViewManager::FromBrowserContext(browser_context_)->
451 RemoveGuest(guest_instance_id_); 462 RemoveGuest(guest_instance_id_);
452 pending_events_.clear(); 463 pending_events_.clear();
453 464
454 delete web_contents(); 465 delete web_contents();
455 } 466 }
456 467
457 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) { 468 void GuestViewBase::SetAttachParams(const base::DictionaryValue& params) {
458 attach_params_.reset(params.DeepCopy()); 469 attach_params_.reset(params.DeepCopy());
459 attach_params_->GetInteger(guestview::kParameterInstanceId, 470 attach_params_->GetInteger(guestview::kParameterInstanceId,
460 &view_instance_id_); 471 &view_instance_id_);
461 } 472 }
462 473
463 void GuestViewBase::SetOpener(GuestViewBase* guest) { 474 void GuestViewBase::SetOpener(GuestViewBase* guest) {
464 if (guest && guest->IsViewType(GetViewType())) { 475 if (guest && guest->IsViewType(GetViewType())) {
465 opener_ = guest->weak_ptr_factory_.GetWeakPtr(); 476 opener_ = guest->weak_ptr_factory_.GetWeakPtr();
466 if (!attached()) 477 if (!attached())
467 opener_lifetime_observer_.reset(new OpenerLifetimeObserver(this)); 478 opener_lifetime_observer_.reset(new OpenerLifetimeObserver(this));
468 return; 479 return;
469 } 480 }
470 opener_ = base::WeakPtr<GuestViewBase>(); 481 opener_ = base::WeakPtr<GuestViewBase>();
471 opener_lifetime_observer_.reset(); 482 opener_lifetime_observer_.reset();
472 } 483 }
473 484
474 void GuestViewBase::RegisterDestructionCallback( 485 void GuestViewBase::SetGuestHost(content::GuestHost* guest_host) {
475 const DestructionCallback& callback) { 486 guest_host_ = guest_host;
476 destruction_callback_ = callback;
477 }
478
479 void GuestViewBase::SetGuestSizer(content::GuestSizer* guest_sizer) {
480 guest_sizer_ = guest_sizer;
481 } 487 }
482 488
483 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, 489 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents,
484 int element_instance_id, 490 int element_instance_id,
485 bool is_full_page_plugin) { 491 bool is_full_page_plugin) {
486 if (owner_web_contents_ != embedder_web_contents) { 492 if (owner_web_contents_ != embedder_web_contents) {
487 DCHECK_EQ(owner_lifetime_observer_->web_contents(), owner_web_contents_); 493 DCHECK_EQ(owner_lifetime_observer_->web_contents(), owner_web_contents_);
488 // Stop tracking the old embedder's zoom level. 494 // Stop tracking the old embedder's zoom level.
489 StopTrackingEmbedderZoomLevel(); 495 StopTrackingEmbedderZoomLevel();
490 owner_web_contents_ = embedder_web_contents; 496 owner_web_contents_ = embedder_web_contents;
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 void GuestViewBase::RegisterGuestViewTypes() { 819 void GuestViewBase::RegisterGuestViewTypes() {
814 AppViewGuest::Register(); 820 AppViewGuest::Register();
815 ExtensionOptionsGuest::Register(); 821 ExtensionOptionsGuest::Register();
816 ExtensionViewGuest::Register(); 822 ExtensionViewGuest::Register();
817 MimeHandlerViewGuest::Register(); 823 MimeHandlerViewGuest::Register();
818 SurfaceWorkerGuest::Register(); 824 SurfaceWorkerGuest::Register();
819 WebViewGuest::Register(); 825 WebViewGuest::Register();
820 } 826 }
821 827
822 } // namespace extensions 828 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/guest_view_base.h ('k') | extensions/browser/guest_view/guest_view_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698