diff --git a/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.cpp b/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.cpp index cbb29b7ca0a..99d62f0bb0d 100644 --- a/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.cpp +++ b/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.cpp @@ -55,6 +55,7 @@ NS_INTERFACE_MAP_BEGIN(nsBaseCommandController) NS_INTERFACE_MAP_END nsBaseCommandController::nsBaseCommandController() + : mCommandContextRawPtr(nsnull) { } @@ -78,7 +79,21 @@ nsBaseCommandController::Init(nsIControllerCommandTable *aCommandTable) NS_IMETHODIMP nsBaseCommandController::SetCommandContext(nsISupports *aCommandContext) { - mCommandContext = do_GetWeakReference(aCommandContext); + mCommandContextWeakPtr = nsnull; + mCommandContextRawPtr = nsnull; + + if (aCommandContext) { + nsCOMPtr weak = do_QueryInterface(aCommandContext); + if (weak) { + nsresult rv = + weak->GetWeakReference(getter_AddRefs(mCommandContextWeakPtr)); + NS_ENSURE_SUCCESS(rv, rv); + } + else { + mCommandContextRawPtr = aCommandContext; + } + } + return NS_OK; } @@ -112,7 +127,13 @@ nsBaseCommandController::IsCommandEnabled(const char *aCommand, { NS_ENSURE_ARG_POINTER(aCommand); NS_ENSURE_ARG_POINTER(aResult); - nsCOMPtr context = do_QueryReferent(mCommandContext); + + nsISupports* context = mCommandContextRawPtr; + nsCOMPtr weak; + if (!context) { + weak = do_QueryReferent(mCommandContextWeakPtr); + context = weak; + } return mCommandTable->IsCommandEnabled(aCommand, context, aResult); } @@ -121,7 +142,13 @@ nsBaseCommandController::SupportsCommand(const char *aCommand, PRBool *aResult) { NS_ENSURE_ARG_POINTER(aCommand); NS_ENSURE_ARG_POINTER(aResult); - nsCOMPtr context = do_QueryReferent(mCommandContext); + + nsISupports* context = mCommandContextRawPtr; + nsCOMPtr weak; + if (!context) { + weak = do_QueryReferent(mCommandContextWeakPtr); + context = weak; + } return mCommandTable->SupportsCommand(aCommand, context, aResult); } @@ -129,7 +156,13 @@ NS_IMETHODIMP nsBaseCommandController::DoCommand(const char *aCommand) { NS_ENSURE_ARG_POINTER(aCommand); - nsCOMPtr context = do_QueryReferent(mCommandContext); + + nsISupports* context = mCommandContextRawPtr; + nsCOMPtr weak; + if (!context) { + weak = do_QueryReferent(mCommandContextWeakPtr); + context = weak; + } return mCommandTable->DoCommand(aCommand, context); } @@ -138,7 +171,13 @@ nsBaseCommandController::DoCommandWithParams(const char *aCommand, nsICommandParams *aParams) { NS_ENSURE_ARG_POINTER(aCommand); - nsCOMPtr context = do_QueryReferent(mCommandContext); + + nsISupports* context = mCommandContextRawPtr; + nsCOMPtr weak; + if (!context) { + weak = do_QueryReferent(mCommandContextWeakPtr); + context = weak; + } return mCommandTable->DoCommandParams(aCommand, aParams, context); } @@ -147,7 +186,13 @@ nsBaseCommandController::GetCommandStateWithParams(const char *aCommand, nsICommandParams *aParams) { NS_ENSURE_ARG_POINTER(aCommand); - nsCOMPtr context = do_QueryReferent(mCommandContext); + + nsISupports* context = mCommandContextRawPtr; + nsCOMPtr weak; + if (!context) { + weak = do_QueryReferent(mCommandContextWeakPtr); + context = weak; + } return mCommandTable->GetCommandState(aCommand, aParams, context); } diff --git a/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.h b/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.h index 0241ab54f0f..c2433642eac 100644 --- a/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.h +++ b/mozilla/embedding/components/commandhandler/src/nsBaseCommandController.h @@ -81,7 +81,8 @@ public: private: - nsWeakPtr mCommandContext; + nsWeakPtr mCommandContextWeakPtr; + nsISupports* mCommandContextRawPtr; // Our reference to the command manager nsCOMPtr mCommandTable;