Skip to content

Commit

Permalink
Merge branch 'jb50272' into 'master'
Browse files Browse the repository at this point in the history
[sailfishos][embedlite] Guard PuppetWidgetBase use after destruction. JB#50272

See merge request mer-core/gecko-dev!190
  • Loading branch information
rainemak committed Nov 16, 2020
2 parents 59376b4 + 1109fe3 commit d5805fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
14 changes: 7 additions & 7 deletions embedding/embedlite/embedshared/EmbedLitePuppetWidget.cpp
Expand Up @@ -371,20 +371,16 @@ void EmbedLitePuppetWidget::CreateCompositor(int aWidth, int aHeight)
LayerManager *
EmbedLitePuppetWidget::GetLayerManager(PLayerTransactionChild *aShadowManager, LayersBackend aBackendHint, LayerManagerPersistence aPersistence)
{
LOGC("EmbedLiteLayerManager", "layer manager %p is shutdown %p this: %p", mLayerManager.get(), mShutdownObserver, this);

if (!mLayerManager) {
if (!mShutdownObserver || Destroyed()) {
// We are shutting down, do not try to re-create a LayerManager
LOGC("EmbedLiteLayerManager", "Shutting down or puppet destroyed.");
return nullptr;
}
}

LayerManager *lm = PuppetWidgetBase::GetLayerManager(aShadowManager, aBackendHint, aPersistence);
if (lm) {
mLayerManager = lm;
LOGC("EmbedLiteLayerManager", "base layer manager: %p this: %p", mLayerManager.get(), this);
return mLayerManager;
}

Expand All @@ -400,9 +396,13 @@ EmbedLitePuppetWidget::GetLayerManager(PLayerTransactionChild *aShadowManager, L
}

nsIWidget* topWidget = GetTopLevelWidget();
mLayerManager = topWidget->GetLayerManager(aShadowManager, aBackendHint, aPersistence);
LOGC("EmbedLiteLayerManager", "Get layer manager from top: %p this: %p", mLayerManager.get(), this);
return mLayerManager;
if (topWidget && topWidget != this) {
mLayerManager = topWidget->GetLayerManager(aShadowManager, aBackendHint, aPersistence);
return mLayerManager;
}
else {
return nullptr;
}
}

bool
Expand Down
24 changes: 13 additions & 11 deletions embedding/embedlite/embedshared/PuppetWidgetBase.cpp
Expand Up @@ -79,9 +79,6 @@ PuppetWidgetBase::Destroy()
}

mOnDestroyCalled = true;

LOGC("EmbedLiteLayerManager", "Destroy %s this: %p", Type(), this);

mLayerManager = nullptr;

Base::OnDestroy();
Expand Down Expand Up @@ -109,7 +106,7 @@ PuppetWidgetBase::Show(bool aState)
NS_ASSERTION(mEnabled,
"does it make sense to Show()/Hide() a disabled widget?");

if (!WillShow(aState)) {
if (Destroyed() || !WillShow(aState)) {
return;
}

Expand All @@ -123,6 +120,10 @@ PuppetWidgetBase::Show(bool aState)
mLayerManager->ClearCachedResources();
}

if (Destroyed()) {
return;
}

if (!wasVisible && mVisible) {
Resize(mNaturalBounds.width, mNaturalBounds.height, false);
Invalidate(mBounds);
Expand Down Expand Up @@ -163,6 +164,10 @@ PuppetWidgetBase::Move(double aX, double aY)
void
PuppetWidgetBase::Resize(double aWidth, double aHeight, bool aRepaint)
{
if (Destroyed()) {
return;
}

LayoutDeviceIntRect oldBounds = mBounds;
LOGT("sz[%i,%i]->[%g,%g]", oldBounds.width, oldBounds.height, aWidth, aHeight);

Expand Down Expand Up @@ -257,10 +262,7 @@ PuppetWidgetBase::Invalidate(const LayoutDeviceIntRect &aRect)
{
Unused << aRect;

LOGC("EmbedLiteLayerManager", "destroyed: %d type: %s LayerManager %p this: %p",
mOnDestroyCalled, Type(), mLayerManager.get(), this);

if (mOnDestroyCalled) {
if (Destroyed()) {
return;
}

Expand Down Expand Up @@ -371,7 +373,9 @@ PuppetWidgetBase::GetLayerManager(PLayerTransactionChild *aShadowManager,
LayersBackend aBackendHint,
LayerManagerPersistence aPersistence)
{
LOGC("EmbedLiteLayerManager", "lm: %p", mLayerManager.get());
if (Destroyed()) {
return nullptr;
}

if (mLayerManager) {
// This layer manager might be used for painting outside of DoDraw(), so we need
Expand All @@ -385,8 +389,6 @@ PuppetWidgetBase::GetLayerManager(PLayerTransactionChild *aShadowManager,
return mLayerManager;
}

LOGC("EmbedLiteLayerManager", "lm: %p", mLayerManager.get());

// Layer manager can be null here. Sub-class shall handle this.
return mLayerManager;
}
Expand Down

0 comments on commit d5805fa

Please sign in to comment.