Make nsIWidget::GetToolkit not AddRef, and thus fix leaks at callers who assumed it didn't. b=386297 r+sr=roc

This commit is contained in:
dbaron@dbaron.org 2007-06-29 20:04:32 -07:00
parent ab765e1d21
commit 3dbcfc7638
5 changed files with 11 additions and 20 deletions

View File

@ -795,6 +795,8 @@ class nsIWidget : public nsISupports {
/**
* Return the widget's toolkit
*
* An AddRef has NOT been done for the caller.
*
* @return the toolkit this widget was created in. See nsToolkit.
*/

View File

@ -2799,7 +2799,6 @@ bool nsWindowBeOS::QuitRequested( void )
MethodInfo *info = nsnull;
if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::CLOSEWINDOW)))
t->CallMethodAsync(info);
NS_RELEASE(t);
}
}
return true;
@ -2844,7 +2843,6 @@ void nsWindowBeOS::DispatchMessage(BMessage *msg, BHandler *handler)
MethodInfo *info = nsnull;
if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::CLOSEWINDOW)))
t->CallMethodAsync(info);
NS_RELEASE(t);
}
}
else
@ -2870,7 +2868,6 @@ void nsWindowBeOS::FrameMoved(BPoint origin)
MethodInfo *info = nsnull;
if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::ONMOVE)))
t->CallMethodAsync(info);
NS_RELEASE(t);
}
}
@ -2887,7 +2884,6 @@ void nsWindowBeOS::WindowActivated(bool active)
MethodInfo *info = nsnull;
if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::ONACTIVATE, 2, args)))
t->CallMethodAsync(info);
NS_RELEASE(t);
}
}
@ -2905,7 +2901,6 @@ void nsWindowBeOS::WorkspacesChanged(uint32 oldworkspace, uint32 newworkspace)
MethodInfo *info = nsnull;
if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::ONWORKSPACE, 2, args)))
t->CallMethodAsync(info);
NS_RELEASE(t);
}
}
@ -2926,7 +2921,6 @@ void nsWindowBeOS::FrameResized(float width, float height)
if (t->CallMethodAsync(info))
fJustGotBounds = false;
}
NS_RELEASE(t);
}
}
@ -2987,7 +2981,6 @@ void nsViewBeOS::Draw(BRect updateRect)
if (t->CallMethodAsync(info))
fJustValidated = false;
}
NS_RELEASE(t);
}
}
@ -3059,7 +3052,6 @@ void nsViewBeOS::MouseDown(BPoint point)
MethodInfo *info = nsnull;
if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::BTNCLICK, 6, args)))
t->CallMethodAsync(info);
NS_RELEASE(t);
}
void nsViewBeOS::MouseMoved(BPoint point, uint32 transit, const BMessage *msg)
@ -3078,7 +3070,7 @@ void nsViewBeOS::MouseMoved(BPoint point, uint32 transit, const BMessage *msg)
nsWindow *w = (nsWindow *)GetMozillaWidget();
if (w == NULL)
return;
nsToolkit *t = t = w->GetToolkit();
nsToolkit *t = w->GetToolkit();
if (t == NULL)
return;
uint32 args[4];
@ -3121,7 +3113,6 @@ void nsViewBeOS::MouseMoved(BPoint point, uint32 transit, const BMessage *msg)
MethodInfo *moveInfo = nsnull;
if (nsnull != (moveInfo = new MethodInfo(w, w, nsSwitchToUIThread::ONMOUSE, 4, args)))
t->CallMethodAsync(moveInfo);
NS_RELEASE(t);
}
void nsViewBeOS::MouseUp(BPoint point)
@ -3143,7 +3134,7 @@ void nsViewBeOS::MouseUp(BPoint point)
nsWindow *w = (nsWindow *)GetMozillaWidget();
if (w == NULL)
return;
nsToolkit *t = t = w->GetToolkit();
nsToolkit *t = w->GetToolkit();
if (t == NULL)
return;
@ -3158,7 +3149,6 @@ void nsViewBeOS::MouseUp(BPoint point)
MethodInfo *info = nsnull;
if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::BTNCLICK, 6, args)))
t->CallMethodAsync(info);
NS_RELEASE(t);
}
void nsViewBeOS::MessageReceived(BMessage *msg)
@ -3168,7 +3158,7 @@ void nsViewBeOS::MessageReceived(BMessage *msg)
nsWindow *w = (nsWindow *)GetMozillaWidget();
if (w == NULL)
return;
nsToolkit *t = t = w->GetToolkit();
nsToolkit *t = w->GetToolkit();
if (t == NULL)
return;
@ -3238,7 +3228,6 @@ void nsViewBeOS::MessageReceived(BMessage *msg)
fWheelDispatched = false;
}
NS_RELEASE(t);
}
}
break;
@ -3285,7 +3274,6 @@ void nsViewBeOS::KeyDown(const char *bytes, int32 numBytes)
MethodInfo *info = nsnull;
if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::ONKEY, 6, args)))
t->CallMethodAsync(info);
NS_RELEASE(t);
}
}
@ -3319,7 +3307,6 @@ void nsViewBeOS::KeyUp(const char *bytes, int32 numBytes)
MethodInfo *info = nsnull;
if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::ONKEY, 6, args)))
t->CallMethodAsync(info);
NS_RELEASE(t);
}
}
@ -3346,7 +3333,6 @@ void nsViewBeOS::MakeFocus(bool focused)
t->CallMethodAsync(info);
}
#endif
NS_RELEASE(t);
}
}

View File

@ -367,7 +367,7 @@ nsresult nsMacWindow::StandardCreate(nsIWidget *aParent,
// when we show it.
mOffsetParent = aParent;
if( aParent )
theToolkit = getter_AddRefs(aParent->GetToolkit());
theToolkit = aParent->GetToolkit();
mAcceptsActivation = PR_FALSE;

View File

@ -868,7 +868,10 @@ void nsWindow::DoCreate( HWND hwndP, nsWindow *aParent,
NS_ADDREF(mToolkit);
}
else if( aParent)
{
mToolkit = aParent->GetToolkit();
NS_IF_ADDREF(mToolkit);
}
else
{
// it's some top level window with no toolkit passed in.

View File

@ -144,7 +144,8 @@ void nsBaseWidget::BaseCreate(nsIWidget *aParent,
}
else {
if (nsnull != aParent) {
mToolkit = (nsIToolkit*)(aParent->GetToolkit()); // the call AddRef's, we don't have to
mToolkit = aParent->GetToolkit();
NS_IF_ADDREF(mToolkit);
}
// it's some top level window with no toolkit passed in.
// Create a default toolkit with the current thread
@ -641,7 +642,6 @@ nsIRenderingContext* nsBaseWidget::GetRenderingContext()
//-------------------------------------------------------------------------
nsIToolkit* nsBaseWidget::GetToolkit()
{
NS_IF_ADDREF(mToolkit);
return mToolkit;
}