From e253dbb57e2775b326256e6e23c62866baffefc9 Mon Sep 17 00:00:00 2001 From: "dmose%netscape.com" Date: Fri, 13 Apr 2001 22:13:04 +0000 Subject: [PATCH] helper function to make code that gets nsISupports proxies more readable: NS_GetProxyForObject (bug 74792). r=brendan@mozilla.org, sr=waterson@netscape.com git-svn-id: svn://10.0.0.236/trunk@92235 18797224-902f-48f8-a5cc-f745e15eee43 --- .../proxy/public/nsIProxyObjectManager.idl | 16 ++++++- .../xpcom/proxy/src/nsProxyObjectManager.cpp | 42 ++++++++++++++++++- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/mozilla/xpcom/proxy/public/nsIProxyObjectManager.idl b/mozilla/xpcom/proxy/public/nsIProxyObjectManager.idl index e7bf27f510d..3f1eee9dc8b 100644 --- a/mozilla/xpcom/proxy/public/nsIProxyObjectManager.idl +++ b/mozilla/xpcom/proxy/public/nsIProxyObjectManager.idl @@ -17,7 +17,8 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): Doug Turner (Original Author) + * Dan Mosedale */ #include "nsISupports.idl" interface nsIEventQueue; @@ -54,4 +55,17 @@ interface nsIProxyObjectManager : nsISupports {0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33}\ } +/** + * Helper function for code that already has a link-time dependency on + * libxpcom and needs to get proxies in a bunch of different places. + * This way, the caller isn't forced to get the proxy object manager + * themselves every single time, thus making the calling code more + * readable. + */ +extern NS_COM nsresult +NS_GetProxyForObject(nsIEventQueue *destQueue, + REFNSIID aIID, + nsISupports* aObj, + PRInt32 proxyType, + void** aProxyObject); %} diff --git a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp index 3151518d2b9..184a61f0dfe 100644 --- a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp @@ -17,8 +17,17 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): - * Pierre Phaneuf + * Contributor(s): Doug Turner (Original Author) + * Judson Valeski + * Dan Matejka + * Scott Collins + * Heikki Toivonen + * Patrick Beard + * Pierre Phaneuf + * Warren Harris + * Chris Seawood + * Chris Waterson + * Dan Mosedale */ @@ -265,5 +274,34 @@ nsProxyObjectManager::GetProxy( nsIEventQueue *destQueue, return rv; } +/** + * Helper function for code that already has a link-time dependency on + * libxpcom and needs to get proxies in a bunch of different places. + * This way, the caller isn't forced to get the proxy object manager + * themselves every single time, thus making the calling code more + * readable. + */ +NS_COM nsresult +NS_GetProxyForObject(nsIEventQueue *destQueue, + REFNSIID aIID, + nsISupports* aObj, + PRInt32 proxyType, + void** aProxyObject) +{ + static NS_DEFINE_CID(proxyObjMgrCID, NS_PROXYEVENT_MANAGER_CID); + nsresult rv; // temp for return value + // get the proxy object manager + // + nsCOMPtr proxyObjMgr = + do_GetService(proxyObjMgrCID, &rv); + + if (NS_FAILED(rv)) + return NS_ERROR_FAILURE; + + // and try to get the proxy object + // + return proxyObjMgr->GetProxyForObject(destQueue, aIID, aObj, + proxyType, aProxyObject); +}