|
|
|
|
| 1066 |
"Can't set DONT_SHARE_PROTOTYPE on an instance scriptable " |
1066 |
"Can't set DONT_SHARE_PROTOTYPE on an instance scriptable " |
| 1067 |
"without also setting it on the class scriptable (if present and shared)"); |
1067 |
"without also setting it on the class scriptable (if present and shared)"); |
| 1068 |
|
1068 |
|
|
|
1069 |
NS_ASSERTION(!(sciWrapper.GetFlags().ClassInfoInterfacesOnlyNoPrivs() && |
| 1070 |
!sciProto.GetFlags().ClassInfoInterfacesOnlyNoPrivs() && |
| 1071 |
sciProto.GetCallback()), |
| 1072 |
"Can't set CLASSINFO_INTERFACES_ONLY_NOPRIVS on an instance scriptable " |
| 1073 |
"without also setting it on the class scriptable (if present and shared)"); |
| 1074 |
|
| 1069 |
return sciWrapper; |
1075 |
return sciWrapper; |
| 1070 |
} |
1076 |
} |
| 1071 |
|
1077 |
|
|
|
| 1826 |
{ |
1832 |
{ |
| 1827 |
if(to->GetInterface() == aInterface) |
1833 |
if(to->GetInterface() == aInterface) |
| 1828 |
{ |
1834 |
{ |
|
|
1835 |
if(to->IsUnsafe()) |
| 1836 |
continue; // Don't reuse an unsafe tearoff |
| 1837 |
|
| 1829 |
if(needJSObject && !to->GetJSObject()) |
1838 |
if(needJSObject && !to->GetJSObject()) |
| 1830 |
{ |
1839 |
{ |
| 1831 |
AutoMarkingWrappedNativeTearOffPtr tearoff(ccx, to); |
1840 |
AutoMarkingWrappedNativeTearOffPtr tearoff(ccx, to); |
|
|
| 1870 |
to->Unmark(); |
1879 |
to->Unmark(); |
| 1871 |
if(NS_FAILED(rv)) |
1880 |
if(NS_FAILED(rv)) |
| 1872 |
to = nsnull; |
1881 |
to = nsnull; |
|
|
1882 |
if (rv == NS_SUCCESS_XPC_DONT_CACHE_TEAROFF) |
| 1883 |
to->MarkUnsafe(); |
| 1873 |
} |
1884 |
} |
| 1874 |
|
1885 |
|
| 1875 |
return_result: |
1886 |
return_result: |
|
|
| 1880 |
} |
1891 |
} |
| 1881 |
|
1892 |
|
| 1882 |
nsresult |
1893 |
nsresult |
|
|
1894 |
XPCWrappedNative::ShouldAllowQI(nsISupports* aIdentity, |
| 1895 |
XPCNativeInterface* aInterface) |
| 1896 |
{ |
| 1897 |
if(!mScriptableInfo) |
| 1898 |
return NS_OK; |
| 1899 |
|
| 1900 |
// Does the scriptable helper say ClassInfo only for everyone? |
| 1901 |
if (mScriptableInfo->GetFlags().ClassInfoInterfacesOnly() && |
| 1902 |
// NB: If the interface is Unsafe then we can't rely on it being in |
| 1903 |
// the set as a test of whether this is safe or not. |
| 1904 |
(aInterface->IsUnsafe() || |
| 1905 |
(!mSet->HasInterface(aInterface) && |
| 1906 |
!mSet->HasInterfaceWithAncestor(aInterface))) && |
| 1907 |
!mScriptableInfo->ShouldReflectNonClassInfoIface(aIdentity, |
| 1908 |
*aInterface->GetIID())) |
| 1909 |
{ |
| 1910 |
// Don't even try the QI |
| 1911 |
return NS_ERROR_NO_INTERFACE; |
| 1912 |
} |
| 1913 |
|
| 1914 |
PRBool shouldRestrictTearoff = PR_FALSE; |
| 1915 |
// Or for non-privileged callers when the caller is non-privileged? |
| 1916 |
if (mScriptableInfo->GetFlags().ClassInfoInterfacesOnlyNoPrivs() && |
| 1917 |
// NB: If the interface is Unsafe then we can't rely on it being in |
| 1918 |
// the set as a test of whether this is safe or not. |
| 1919 |
(aInterface->IsUnsafe() || |
| 1920 |
(!mSet->HasInterface(aInterface) && |
| 1921 |
!mSet->HasInterfaceWithAncestor(aInterface))) && |
| 1922 |
!mScriptableInfo->ShouldReflectNonClassInfoIface(aIdentity, |
| 1923 |
*aInterface->GetIID()) && |
| 1924 |
(!NS_SUCCEEDED(XPCWrapper::GetSecurityManager()-> |
| 1925 |
IsCapabilityEnabled("UniversalXPConnect", |
| 1926 |
&shouldRestrictTearoff)) || |
| 1927 |
!shouldRestrictTearoff)) |
| 1928 |
{ |
| 1929 |
// Don't even try the QI |
| 1930 |
return NS_ERROR_NO_INTERFACE; |
| 1931 |
} |
| 1932 |
|
| 1933 |
// Otherwise, try the QI, but be careful with the result tearoff if necessary |
| 1934 |
return shouldRestrictTearoff ? NS_SUCCESS_XPC_DONT_CACHE_TEAROFF : NS_OK; |
| 1935 |
} |
| 1936 |
|
| 1937 |
nsresult |
| 1883 |
XPCWrappedNative::InitTearOff(XPCCallContext& ccx, |
1938 |
XPCWrappedNative::InitTearOff(XPCCallContext& ccx, |
| 1884 |
XPCWrappedNativeTearOff* aTearOff, |
1939 |
XPCWrappedNativeTearOff* aTearOff, |
| 1885 |
XPCNativeInterface* aInterface, |
1940 |
XPCNativeInterface* aInterface, |
|
|
| 1888 |
// This is only called while locked (during XPCWrappedNative::FindTearOff). |
1943 |
// This is only called while locked (during XPCWrappedNative::FindTearOff). |
| 1889 |
|
1944 |
|
| 1890 |
// Determine if the object really does this interface... |
1945 |
// Determine if the object really does this interface... |
| 1891 |
|
1946 |
nsresult rv; |
| 1892 |
const nsIID* iid = aInterface->GetIID(); |
1947 |
const nsIID* iid = aInterface->GetIID(); |
| 1893 |
nsISupports* identity = GetIdentityObject(); |
1948 |
nsISupports* identity = GetIdentityObject(); |
| 1894 |
nsISupports* obj; |
1949 |
nsISupports* obj; |
| 1895 |
|
1950 |
|
| 1896 |
// If the scriptable helper forbids us from reflecting additional |
1951 |
// Check to see if we should allow this QI |
| 1897 |
// interfaces, then don't even try the QI, just fail. |
1952 |
rv = ShouldAllowQI(identity, aInterface); |
| 1898 |
if(mScriptableInfo && |
1953 |
if (NS_FAILED(rv)) { return rv; }; |
| 1899 |
mScriptableInfo->GetFlags().ClassInfoInterfacesOnly() && |
|
|
| 1900 |
!mSet->HasInterface(aInterface) && |
| 1901 |
!mSet->HasInterfaceWithAncestor(aInterface)) |
| 1902 |
{ |
| 1903 |
return NS_ERROR_NO_INTERFACE; |
| 1904 |
} |
| 1905 |
|
1954 |
|
| 1906 |
// We are about to call out to unlock and other code. |
1955 |
// We are about to call out to unlock and other code. |
| 1907 |
// So protect our intended tearoff. |
1956 |
// So protect our intended tearoff. |
|
|
| 2051 |
// Note: we do not cache the result of the previous call to HasInterface() |
2100 |
// Note: we do not cache the result of the previous call to HasInterface() |
| 2052 |
// because we unlocked and called out in the interim and the result of the |
2101 |
// because we unlocked and called out in the interim and the result of the |
| 2053 |
// previous call might not be correct anymore. |
2102 |
// previous call might not be correct anymore. |
| 2054 |
|
2103 |
if(!mSet->HasInterface(aInterface) && |
| 2055 |
if(!mSet->HasInterface(aInterface) && !ExtendSet(ccx, aInterface)) |
2104 |
!ExtendSet(ccx, aInterface)) |
| 2056 |
{ |
2105 |
{ |
| 2057 |
NS_RELEASE(obj); |
2106 |
NS_RELEASE(obj); |
| 2058 |
aTearOff->SetInterface(nsnull); |
2107 |
aTearOff->SetInterface(nsnull); |
|
|
| 2061 |
|
2110 |
|
| 2062 |
aTearOff->SetInterface(aInterface); |
2111 |
aTearOff->SetInterface(aInterface); |
| 2063 |
aTearOff->SetNative(obj); |
2112 |
aTearOff->SetNative(obj); |
|
|
2113 |
if (rv == NS_SUCCESS_XPC_DONT_CACHE_TEAROFF) |
| 2114 |
aInterface->MarkUnsafe(); |
| 2115 |
|
| 2064 |
#ifdef XPC_IDISPATCH_SUPPORT |
2116 |
#ifdef XPC_IDISPATCH_SUPPORT |
| 2065 |
// Are we building a tearoff for IDispatch? |
2117 |
// Are we building a tearoff for IDispatch? |
| 2066 |
if(iid->Equals(NSID_IDISPATCH)) |
2118 |
if(iid->Equals(NSID_IDISPATCH)) |
|
|
| 2071 |
if(needJSObject && !InitTearOffJSObject(ccx, aTearOff)) |
2123 |
if(needJSObject && !InitTearOffJSObject(ccx, aTearOff)) |
| 2072 |
return NS_ERROR_OUT_OF_MEMORY; |
2124 |
return NS_ERROR_OUT_OF_MEMORY; |
| 2073 |
|
2125 |
|
| 2074 |
return NS_OK; |
2126 |
return rv; |
| 2075 |
} |
2127 |
} |
| 2076 |
|
2128 |
|
| 2077 |
JSBool |
2129 |
JSBool |