Bug 878366: don't send send out messages of PContendPermissionRequest if the managing TabParent is being destroyed. r=bent

This commit is contained in:
Cervantes Yu 2013-10-17 06:25:50 +08:00
parent 5b846337b8
commit ea96436c1b
3 changed files with 31 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include "nsIDOMElement.h"
#include "nsIPrincipal.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/unused.h"
#include "nsComponentManagerUtils.h"
@ -105,6 +106,12 @@ nsContentPermissionRequestProxy::Cancel()
return NS_ERROR_FAILURE;
}
// Don't send out the delete message when the managing protocol (PBrowser) is
// being destroyed and PContentPermissionRequest will soon be.
if (mParent->IsBeingDestroyed()) {
return NS_ERROR_FAILURE;
}
unused << ContentPermissionRequestParent::Send__delete__(mParent, false);
mParent = nullptr;
return NS_OK;
@ -116,6 +123,13 @@ nsContentPermissionRequestProxy::Allow()
if (mParent == nullptr) {
return NS_ERROR_FAILURE;
}
// Don't send out the delete message when the managing protocol (PBrowser) is
// being destroyed and PContentPermissionRequest will soon be.
if (mParent->IsBeingDestroyed()) {
return NS_ERROR_FAILURE;
}
unused << ContentPermissionRequestParent::Send__delete__(mParent, true);
mParent = nullptr;
return NS_OK;
@ -161,5 +175,14 @@ ContentPermissionRequestParent::ActorDestroy(ActorDestroyReason why)
}
}
bool
ContentPermissionRequestParent::IsBeingDestroyed()
{
// When TabParent::Destroy() is called, we are being destroyed. It's unsafe
// to send out any message now.
TabParent* tabParent = static_cast<TabParent*>(Manager());
return tabParent->IsDestroyed();
}
} // namespace dom
} // namespace mozilla

View File

@ -27,6 +27,8 @@ class ContentPermissionRequestParent : public PContentPermissionRequestParent
const IPC::Principal& principal);
virtual ~ContentPermissionRequestParent();
bool IsBeingDestroyed();
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<Element> mElement;
nsCOMPtr<nsContentPermissionRequestProxy> mProxy;

View File

@ -238,6 +238,12 @@ public:
ContentParent* Manager() { return mManager; }
/**
* Let managees query if Destroy() is already called so they don't send out
* messages when the PBrowser actor is being destroyed.
*/
bool IsDestroyed() const { return mIsDestroyed; }
protected:
bool ReceiveMessage(const nsString& aMessage,
bool aSync,