Bug 557557 - Properly handle destruction in taskbar previews when the window outlives the preview r=jimm

This commit is contained in:
Rob Arnold 2010-04-21 15:09:59 -04:00
parent 4dddc1fb4e
commit e033b38382
6 changed files with 25 additions and 34 deletions

View File

@ -112,9 +112,8 @@ TaskbarPreview::~TaskbarPreview() {
if (sActivePreview == this)
sActivePreview = nsnull;
// Here we remove the hook since this preview is dying before the nsWindow
if (mWnd)
DetachFromNSWindow(PR_TRUE);
// Our subclass should have invoked DetachFromNSWindow already.
NS_ASSERTION(!mWnd, "TaskbarPreview::DetachFromNSWindow was not called before destruction");
// Make sure to release before potentially uninitializing COM
mTaskbar = NULL;
@ -240,11 +239,9 @@ TaskbarPreview::Disable() {
}
void
TaskbarPreview::DetachFromNSWindow(PRBool windowIsAlive) {
if (windowIsAlive) {
WindowHook &hook = GetWindowHook();
hook.RemoveMonitor(WM_DESTROY, MainWindowHook, this);
}
TaskbarPreview::DetachFromNSWindow() {
WindowHook &hook = GetWindowHook();
hook.RemoveMonitor(WM_DESTROY, MainWindowHook, this);
mWnd = NULL;
}
@ -395,9 +392,8 @@ TaskbarPreview::MainWindowHook(void *aContext,
TaskbarPreview *preview = reinterpret_cast<TaskbarPreview*>(aContext);
if (nMsg == WM_DESTROY) {
// nsWindow is being destroyed
// Don't remove the hook since it is currently in dispatch
// and the window is being destroyed
preview->DetachFromNSWindow(PR_FALSE);
// We can't really do anything at this point including removing hooks
preview->mWnd = NULL;
} else {
nsWindow *window = nsWindow::GetNSWindowPtr(preview->mWnd);
NS_ASSERTION(window, "Cannot use taskbar previews in an embedded context!");

View File

@ -74,7 +74,7 @@ protected:
virtual nsresult Disable();
// Detaches this preview from the nsWindow instance it's tied to
virtual void DetachFromNSWindow(PRBool windowIsAlive);
virtual void DetachFromNSWindow();
// Marks this preview as being active
virtual nsresult ShowActive(PRBool active) = 0;

View File

@ -69,8 +69,8 @@ TaskbarTabPreview::~TaskbarTabPreview() {
::DestroyIcon(mIcon);
mIcon = NULL;
}
// Do this here because this is our last chance to execute methods in this class
(void) SetVisible(PR_FALSE);
if (mWnd)
DetachFromNSWindow();
}
nsresult
@ -265,15 +265,12 @@ TaskbarTabPreview::Disable() {
}
void
TaskbarTabPreview::DetachFromNSWindow(PRBool windowIsAlive) {
TaskbarTabPreview::DetachFromNSWindow() {
(void) SetVisible(PR_FALSE);
WindowHook &hook = GetWindowHook();
hook.RemoveMonitor(WM_WINDOWPOSCHANGED, MainWindowHook, this);
if (windowIsAlive) {
WindowHook &hook = GetWindowHook();
hook.RemoveMonitor(WM_WINDOWPOSCHANGED, MainWindowHook, this);
}
TaskbarPreview::DetachFromNSWindow(windowIsAlive);
TaskbarPreview::DetachFromNSWindow();
}
/* static */

View File

@ -69,7 +69,7 @@ private:
virtual nsresult UpdateTaskbarProperties();
virtual nsresult Enable();
virtual nsresult Disable();
virtual void DetachFromNSWindow(PRBool windowIsAlive);
virtual void DetachFromNSWindow();
// WindowHook procedure for hooking mWnd
static PRBool MainWindowHook(void *aContext,

View File

@ -102,7 +102,7 @@ TaskbarWindowPreview::TaskbarWindowPreview(ITaskbarList4 *aTaskbar, nsITaskbarPr
TaskbarWindowPreview::~TaskbarWindowPreview() {
if (mWnd)
DetachFromNSWindow(PR_TRUE);
DetachFromNSWindow();
}
nsresult
@ -272,18 +272,16 @@ TaskbarWindowPreview::Disable() {
}
void
TaskbarWindowPreview::DetachFromNSWindow(PRBool windowIsAlive) {
if (windowIsAlive) {
// Remove the hooks we have for drawing
SetEnableCustomDrawing(PR_FALSE);
TaskbarWindowPreview::DetachFromNSWindow() {
// Remove the hooks we have for drawing
SetEnableCustomDrawing(PR_FALSE);
WindowHook &hook = GetWindowHook();
(void) hook.RemoveHook(WM_COMMAND, WindowHookProc, this);
(void) hook.RemoveMonitor(nsAppShell::GetTaskbarButtonCreatedMessage(),
TaskbarProgressWindowHook, this);
}
WindowHook &hook = GetWindowHook();
(void) hook.RemoveHook(WM_COMMAND, WindowHookProc, this);
(void) hook.RemoveMonitor(nsAppShell::GetTaskbarButtonCreatedMessage(),
TaskbarProgressWindowHook, this);
TaskbarPreview::DetachFromNSWindow(windowIsAlive);
TaskbarPreview::DetachFromNSWindow();
}
nsresult

View File

@ -75,7 +75,7 @@ private:
virtual nsresult UpdateTaskbarProperties();
virtual nsresult Enable();
virtual nsresult Disable();
virtual void DetachFromNSWindow(PRBool windowIsAlive);
virtual void DetachFromNSWindow();
nsresult UpdateButton(PRUint32 index);
nsresult UpdateButtons();