Bug 996061 - part 3 - try to shim param information in xptiInterfaceEntry when possible; r=bholley
authorNathan Froyd <froydnj@mozilla.com>
Fri, 16 May 2014 17:19:26 -0400
changeset 205900 2c7acfdd623bdb725c036a1b1fbb2cbe15f392b6
parent 205899 5c2eaff26d0c1b2b3ff47ecdc61d611369796468
child 205901 bee33343ee1849833b42fb7e8693e9fe6dc14013
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs996061
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 996061 - part 3 - try to shim param information in xptiInterfaceEntry when possible; r=bholley This patch does all the interesting work: we check for shims whenever we get asked about parameter information for methods. If there's a shim for what we want, we ask the shim to provide the information. If not, we fail as usual.
xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
xpcom/reflect/xptinfo/src/xptiprivate.h
--- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Implementation of xptiInterfaceEntry and xptiInterfaceInfo. */
 
 #include "xptiprivate.h"
+#include "mozilla/DebugOnly.h"
 #include "mozilla/XPTInterfaceInfoManager.h"
 #include "mozilla/PodOperations.h"
 #include "nsCxPusher.h"
 #include "jsapi.h"
 
 using namespace mozilla;
 
 /***************************************************************************/
@@ -365,51 +366,91 @@ xptiInterfaceEntry::GetEntryForParam(uin
         *entry = nullptr;
         return NS_ERROR_FAILURE;
     }
 
     *entry = theEntry;
     return NS_OK;
 }
 
+already_AddRefed<ShimInterfaceInfo>
+xptiInterfaceEntry::GetShimForParam(uint16_t methodIndex,
+                                    const nsXPTParamInfo* param)
+{
+    uint16_t interfaceIndex = 0;
+    nsresult rv = GetInterfaceIndexForParam(methodIndex, param,
+                                            &interfaceIndex);
+    if (NS_FAILED(rv)) {
+        return nullptr;
+    }
+
+    const char* shimName = mTypelib->GetEntryNameAt(interfaceIndex - 1);
+    nsRefPtr<ShimInterfaceInfo> shim =
+        ShimInterfaceInfo::MaybeConstruct(shimName, nullptr);
+    return shim.forget();
+}
+
 nsresult
 xptiInterfaceEntry::GetInfoForParam(uint16_t methodIndex,
                                     const nsXPTParamInfo *param,
                                     nsIInterfaceInfo** info)
 {
     xptiInterfaceEntry* entry;
     nsresult rv = GetEntryForParam(methodIndex, param, &entry);
-    if(NS_FAILED(rv))
-        return rv;
+    if (NS_FAILED(rv)) {
+        nsRefPtr<ShimInterfaceInfo> shim = GetShimForParam(methodIndex, param);
+        if (!shim) {
+            return rv;
+        }
+
+        shim.forget(info);
+        return NS_OK;
+    }
 
     *info = entry->InterfaceInfo().take();
 
     return NS_OK;
 }
 
 nsresult
 xptiInterfaceEntry::GetIIDForParam(uint16_t methodIndex,
                                    const nsXPTParamInfo* param, nsIID** iid)
 {
     xptiInterfaceEntry* entry;
     nsresult rv = GetEntryForParam(methodIndex, param, &entry);
-    if(NS_FAILED(rv))
-        return rv;
+    if (NS_FAILED(rv)) {
+        nsRefPtr<ShimInterfaceInfo> shim = GetShimForParam(methodIndex, param);
+        if (!shim) {
+            return rv;
+        }
+
+        return shim->GetInterfaceIID(iid);
+    }
     return entry->GetIID(iid);
 }
 
 nsresult
 xptiInterfaceEntry::GetIIDForParamNoAlloc(uint16_t methodIndex, 
                                           const nsXPTParamInfo * param, 
                                           nsIID *iid)
 {
     xptiInterfaceEntry* entry;
     nsresult rv = GetEntryForParam(methodIndex, param, &entry);
-    if(NS_FAILED(rv))
-        return rv;
+    if (NS_FAILED(rv)) {
+        nsRefPtr<ShimInterfaceInfo> shim = GetShimForParam(methodIndex, param);
+        if (!shim) {
+            return rv;
+        }
+
+        const nsIID* shimIID;
+        DebugOnly<nsresult> rv2 = shim->GetIIDShared(&shimIID);
+        MOZ_ASSERT(NS_SUCCEEDED(rv2));
+        *iid = *shimIID;
+        return NS_OK;
+    }
     *iid = entry->mIID;    
     return NS_OK;
 }
 
 // this is a private helper
 nsresult
 xptiInterfaceEntry::GetTypeInArray(const nsXPTParamInfo* param,
                                   uint16_t dimension,
--- a/xpcom/reflect/xptinfo/src/xptiprivate.h
+++ b/xpcom/reflect/xptinfo/src/xptiprivate.h
@@ -15,16 +15,17 @@
 // this after nsISupports, to pick up IID
 // so that xpt stuff doesn't try to define it itself...
 #include "xpt_struct.h"
 #include "xpt_xdr.h"
 
 #include "nsIInterfaceInfo.h"
 #include "nsIInterfaceInfoManager.h"
 #include "xptinfo.h"
+#include "ShimInterfaceInfo.h"
 
 #include "nsIServiceManager.h"
 #include "nsIFile.h"
 #include "nsIDirectoryService.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsIWeakReference.h"
 
@@ -274,16 +275,19 @@ private:
     nsresult GetTypeInArray(const nsXPTParamInfo* param,
                             uint16_t dimension,
                             const XPTTypeDescriptor** type);
 
     nsresult GetInterfaceIndexForParam(uint16_t methodIndex,
                                        const nsXPTParamInfo* param,
                                        uint16_t* interfaceIndex);
 
+    already_AddRefed<ShimInterfaceInfo>
+    GetShimForParam(uint16_t methodIndex, const nsXPTParamInfo* param);
+
 private:
     nsID                    mIID;
     XPTInterfaceDescriptor* mDescriptor;
 
     uint16_t mMethodBaseIndex;
     uint16_t mConstantBaseIndex;
     xptiTypelibGuts* mTypelib;