зеркало из https://github.com/mozilla/gecko-dev.git
Bug 334515: Use nsWeakPtr rather than raw pointers to avoid crashes. r/sr=dbaron
This commit is contained in:
Родитель
055dda3e6a
Коммит
eb966d89e7
|
@ -55,7 +55,6 @@ NS_INTERFACE_MAP_BEGIN(nsBaseCommandController)
|
|||
NS_INTERFACE_MAP_END
|
||||
|
||||
nsBaseCommandController::nsBaseCommandController()
|
||||
: mCommandContext(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -79,7 +78,7 @@ nsBaseCommandController::Init(nsIControllerCommandTable *aCommandTable)
|
|||
NS_IMETHODIMP
|
||||
nsBaseCommandController::SetCommandContext(nsISupports *aCommandContext)
|
||||
{
|
||||
mCommandContext = aCommandContext; // no addref
|
||||
mCommandContext = do_GetWeakReference(aCommandContext);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -114,7 +113,8 @@ nsBaseCommandController::IsCommandEnabled(const char *aCommand,
|
|||
NS_ENSURE_ARG_POINTER(aCommand);
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
NS_ENSURE_STATE(mCommandTable);
|
||||
return mCommandTable->IsCommandEnabled(aCommand, mCommandContext, aResult);
|
||||
nsCOMPtr<nsISupports> context = do_QueryReferent(mCommandContext);
|
||||
return mCommandTable->IsCommandEnabled(aCommand, context, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -123,7 +123,8 @@ nsBaseCommandController::SupportsCommand(const char *aCommand, PRBool *aResult)
|
|||
NS_ENSURE_ARG_POINTER(aCommand);
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
NS_ENSURE_STATE(mCommandTable);
|
||||
return mCommandTable->SupportsCommand(aCommand, mCommandContext, aResult);
|
||||
nsCOMPtr<nsISupports> context = do_QueryReferent(mCommandContext);
|
||||
return mCommandTable->SupportsCommand(aCommand, context, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -131,7 +132,8 @@ nsBaseCommandController::DoCommand(const char *aCommand)
|
|||
{
|
||||
NS_ENSURE_ARG_POINTER(aCommand);
|
||||
NS_ENSURE_STATE(mCommandTable);
|
||||
return mCommandTable->DoCommand(aCommand, mCommandContext);
|
||||
nsCOMPtr<nsISupports> context = do_QueryReferent(mCommandContext);
|
||||
return mCommandTable->DoCommand(aCommand, context);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -140,7 +142,8 @@ nsBaseCommandController::DoCommandWithParams(const char *aCommand,
|
|||
{
|
||||
NS_ENSURE_ARG_POINTER(aCommand);
|
||||
NS_ENSURE_STATE(mCommandTable);
|
||||
return mCommandTable->DoCommandParams(aCommand, aParams, mCommandContext);
|
||||
nsCOMPtr<nsISupports> context = do_QueryReferent(mCommandContext);
|
||||
return mCommandTable->DoCommandParams(aCommand, aParams, context);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -149,7 +152,8 @@ nsBaseCommandController::GetCommandStateWithParams(const char *aCommand,
|
|||
{
|
||||
NS_ENSURE_ARG_POINTER(aCommand);
|
||||
NS_ENSURE_STATE(mCommandTable);
|
||||
return mCommandTable->GetCommandState(aCommand, aParams, mCommandContext);
|
||||
nsCOMPtr<nsISupports> context = do_QueryReferent(mCommandContext);
|
||||
return mCommandTable->GetCommandState(aCommand, aParams, context);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -49,6 +49,8 @@
|
|||
#include "nsIControllerContext.h"
|
||||
#include "nsIControllerCommandTable.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIWeakReference.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
|
||||
// The base editor controller is used for both text widgets,
|
||||
// and all other text and html editing
|
||||
|
@ -79,7 +81,7 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
nsISupports *mCommandContext;
|
||||
nsWeakPtr mCommandContext;
|
||||
|
||||
// Our reference to the command manager
|
||||
nsCOMPtr<nsIControllerCommandTable> mCommandTable;
|
||||
|
|
Загрузка…
Ссылка в новой задаче