Fix 23227 Document object vulnerability

r=mstoltz
This commit is contained in:
norris%netscape.com 2000-01-26 15:33:57 +00:00
Родитель c36c14033a
Коммит e7f484f030
31 изменённых файлов: 146 добавлений и 119 удалений

Просмотреть файл

@ -21,7 +21,7 @@
*/
#include "nsScriptSecurityManager.h"
#include "nsIServiceManager.h"
#include "nsIScriptGlobalObjectData.h"
#include "nsIScriptObjectOwner.h"
#include "nsIPref.h"
#include "nsIURL.h"
#include "nspr.h"
@ -949,22 +949,25 @@ NS_IMETHODIMP
nsScriptSecurityManager::GetObjectPrincipal(JSContext *aCx, JSObject *aObj,
nsIPrincipal **result)
{
JSObject *parent;
while ((parent = JS_GetParent(aCx, aObj)) != nsnull)
aObj = parent;
nsISupports *supports = (nsISupports *) JS_GetPrivate(aCx, aObj);
nsCOMPtr<nsIScriptGlobalObjectData> globalData;
if (!supports || NS_FAILED(supports->QueryInterface(
NS_GET_IID(nsIScriptGlobalObjectData),
(void **) getter_AddRefs(globalData))))
{
return NS_ERROR_FAILURE;
}
if (NS_FAILED(globalData->GetPrincipal(result))) {
return NS_ERROR_FAILURE;
}
return NS_OK;
JSObject *parent = aObj;
do {
JSClass *jsClass = JS_GetClass(aCx, parent);
const int privateNsISupports = JSCLASS_HAS_PRIVATE |
JSCLASS_PRIVATE_IS_NSISUPPORTS;
if (jsClass && (jsClass->flags & (privateNsISupports)) ==
privateNsISupports)
{
nsISupports *supports = (nsISupports *) JS_GetPrivate(aCx, parent);
nsCOMPtr<nsIScriptObjectPrincipal> objPrin =
do_QueryInterface(supports);
if (objPrin && NS_SUCCEEDED(objPrin->GetPrincipal(result)))
return NS_OK;
}
parent = JS_GetParent(aCx, parent);
} while (parent);
// Couldn't find a principal for this object.
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
@ -1084,6 +1087,21 @@ nsScriptSecurityManager::CheckXPCPermissions(JSContext *aJSContext)
if (NS_FAILED(IsCapabilityEnabled("UniversalXPConnect", &ok)))
ok = PR_FALSE;
if (!ok) {
// T E M P O R A R Y
// Check the pref "security.checkxpconnect". If it exists and is
// set to false, don't report an error.
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
PRBool enabled;
if (NS_SUCCEEDED(prefs->GetBoolPref("security.checkxpconnect",
&enabled)) &&
!enabled)
{
return NS_OK;
}
}
// T E M P O R A R Y
static const char msg[] = "Access denied to XPConnect service.";
JS_SetPendingException(aJSContext,
STRING_TO_JSVAL(JS_NewStringCopyZ(aJSContext, msg)));

Просмотреть файл

@ -111,7 +111,7 @@ public:
/**
* Return the principal responsible for this document.
*/
virtual nsIPrincipal* GetDocumentPrincipal() = 0;
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal) = 0;
/**
* Return the LoadGroup for the document. May return null.

Просмотреть файл

@ -710,6 +710,12 @@ nsresult nsDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIScriptObjectPrincipal::GetIID())) {
nsIScriptObjectPrincipal* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEventReceiverIID)) {
nsIDOMEventReceiver* tmp = this;
*aInstancePtr = (void*) tmp;
@ -862,20 +868,22 @@ nsIURI* nsDocument::GetDocumentURL() const
return mDocumentURL;
}
nsIPrincipal* nsDocument::GetDocumentPrincipal()
NS_IMETHODIMP
nsDocument::GetPrincipal(nsIPrincipal **aPrincipal)
{
if (!mPrincipal) {
nsresult rv;
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
if (NS_FAILED(rv))
return nsnull;
if (NS_FAILED(securityManager->GetCodebasePrincipal(mDocumentURL,
&mPrincipal)))
return nsnull;
return rv;
if (NS_FAILED(rv = securityManager->GetCodebasePrincipal(mDocumentURL,
&mPrincipal)))
return rv;
}
NS_ADDREF(mPrincipal);
return mPrincipal;
*aPrincipal = mPrincipal;
NS_ADDREF(*aPrincipal);
return NS_OK;
}
NS_IMETHODIMP

Просмотреть файл

@ -113,7 +113,8 @@ class nsDocument : public nsIDocument,
public nsIScriptObjectOwner,
public nsIJSScriptObject,
public nsSupportsWeakReference,
public nsIDOMEventReceiver
public nsIDOMEventReceiver,
public nsIScriptObjectPrincipal
{
public:
NS_DECL_ISUPPORTS
@ -139,7 +140,7 @@ public:
/**
* Return the principal responsible for this document.
*/
virtual nsIPrincipal* GetDocumentPrincipal();
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal);
/**
* Return the content (mime) type of this document.

Просмотреть файл

@ -45,7 +45,6 @@
#include "nsDOMEventsIIDs.h"
#include "prmem.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectData.h"
#include "nsLayoutAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@ -60,7 +59,6 @@ static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectDataIID, NS_ISCRIPTGLOBALOBJECTDATA_IID);
nsEventListenerManager::nsEventListenerManager()
{

Просмотреть файл

@ -3891,8 +3891,9 @@ HTMLContentSink::EvaluateScript(nsString& aScript,
NS_ERROR_FAILURE);
nsCOMPtr<nsIPrincipal> principal;
principal = getter_AddRefs(mDocument->GetDocumentPrincipal());
NS_ASSERTION(principal, "principal expected for document");
rv = mDocument->GetPrincipal(getter_AddRefs(principal));
NS_ASSERTION(NS_SUCCEEDED(rv), "principal expected for document");
if (NS_FAILED(rv)) return rv;
nsAutoString ret;
nsIURI* docURL = mDocument->GetDocumentURL();

Просмотреть файл

@ -1434,8 +1434,8 @@ nsHTMLDocument::GetReferrer(nsString& aReferrer)
NS_IMETHODIMP
nsHTMLDocument::GetDomainURI(nsIURI **uri)
{
nsCOMPtr<nsIPrincipal> principal = GetDocumentPrincipal();
if (!principal)
nsCOMPtr<nsIPrincipal> principal;
if (NS_FAILED(GetPrincipal(getter_AddRefs(principal))))
return NS_ERROR_FAILURE;
nsCOMPtr<nsICodebasePrincipal> codebase = do_QueryInterface(principal);
if (!codebase)

Просмотреть файл

@ -4113,8 +4113,9 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
// Use the enclosing document's principal
// XXX is this right? or should we use the protodoc's?
nsCOMPtr<nsIPrincipal> principal =
dont_AddRef(aDocument->GetDocumentPrincipal());
nsCOMPtr<nsIPrincipal> principal;
rv = aDocument->GetPrincipal(getter_AddRefs(principal));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString urlspec;
aURI->GetSpec(getter_Copies(urlspec));

Просмотреть файл

@ -756,12 +756,10 @@ nsXULDocument::GetDocumentURL() const
return result;
}
nsIPrincipal*
nsXULDocument::GetDocumentPrincipal()
NS_IMETHODIMP
nsXULDocument::GetPrincipal(nsIPrincipal **aPrincipal)
{
nsIPrincipal* principal = nsnull;
mMasterPrototype->GetDocumentPrincipal(&principal);
return principal;
return mMasterPrototype->GetDocumentPrincipal(aPrincipal);
}

Просмотреть файл

@ -117,7 +117,7 @@ public:
virtual nsIURI* GetDocumentURL() const;
virtual nsIPrincipal* GetDocumentPrincipal();
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal);
NS_IMETHOD GetDocumentLoadGroup(nsILoadGroup **aGroup) const;

Просмотреть файл

@ -30,7 +30,6 @@
#include "nsCOMPtr.h"
#include "nsIPrincipal.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectData.h"
#include "nsIScriptSecurityManager.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
@ -45,7 +44,7 @@
class nsXULPrototypeDocument : public nsIXULPrototypeDocument,
public nsIScriptObjectOwner,
public nsIScriptGlobalObject,
public nsIScriptGlobalObjectData
public nsIScriptObjectPrincipal
{
public:
static nsresult
@ -92,7 +91,7 @@ public:
PRUint32 aFlags,
nsEventStatus* aEventStatus);
// nsIScriptGlobalObjectData methods
// nsIScriptObjectPrincipal methods
NS_IMETHOD GetPrincipal(nsIPrincipal** aPrincipal);
@ -163,7 +162,7 @@ NS_IMPL_ISUPPORTS4(nsXULPrototypeDocument,
nsIXULPrototypeDocument,
nsIScriptObjectOwner,
nsIScriptGlobalObject,
nsIScriptGlobalObjectData);
nsIScriptObjectPrincipal);
NS_IMETHODIMP
NS_NewXULPrototypeDocument(nsISupports* aOuter, REFNSIID aIID, void** aResult)
@ -462,7 +461,7 @@ nsXULPrototypeDocument::HandleDOMEvent(nsIPresContext* aPresContext,
//----------------------------------------------------------------------
//
// nsIScriptGlobalObjectData methods
// nsIScriptObjectPrincipal methods
//
NS_IMETHODIMP

Просмотреть файл

@ -31,7 +31,6 @@ nsIDOMNativeObjectRegistry.h
nsDOMCID.h
nsDOMPropEnums.h
nsDOMPropNames.h
nsIScriptGlobalObjectData.h
nsIScriptNameSetRegistry.h
nsIScriptExternalNameSet.h
nsIScriptNameSpaceManager.h

Просмотреть файл

@ -47,7 +47,6 @@ EXPORTS = \
nsDOMCID.h \
nsDOMPropEnums.h \
nsDOMPropNames.h \
nsIScriptGlobalObjectData.h \
nsIScriptNameSetRegistry.h \
nsIScriptExternalNameSet.h \
nsIScriptNameSpaceManager.h \

Просмотреть файл

@ -45,7 +45,6 @@ EXPORTS=nsIScriptContext.h \
nsIScriptNameSetRegistry.h \
nsIScriptExternalNameSet.h \
nsIScriptNameSpaceManager.h \
nsIScriptGlobalObjectData.h \
nsDOMError.h \
nsIJSEventListener.h

Просмотреть файл

Просмотреть файл

@ -116,4 +116,20 @@ public:
NS_IMETHOD GetCompiledEventHandler(nsIAtom *aName, void** aHandler) = 0;
};
#define NS_ISCRIPTOBJECTPRINCIPAL_IID \
{ 0x98485f80, 0x9615, 0x11d2, \
{ 0xbd, 0x92, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} }
/**
* JS Object Principal information.
*/
class nsIScriptObjectPrincipal : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTOBJECTPRINCIPAL_IID)
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal) = 0;
};
#endif // nsIScriptObjectOwner_h__

Просмотреть файл

@ -235,8 +235,8 @@ GlobalWindowImpl::QueryInterface(const nsIID& aIID,
AddRef();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIScriptGlobalObjectData))) {
*aInstancePtrResult = (void*) ((nsIScriptGlobalObjectData*)this);
if (aIID.Equals(NS_GET_IID(nsIScriptObjectPrincipal))) {
*aInstancePtrResult = (void*) ((nsIScriptObjectPrincipal*)this);
AddRef();
return NS_OK;
}
@ -3377,16 +3377,10 @@ GlobalWindowImpl::DisableExternalCapture()
NS_IMETHODIMP
GlobalWindowImpl::GetPrincipal(nsIPrincipal **result)
{
nsCOMPtr<nsIDocument> doc;
if (!mDocument || NS_FAILED(mDocument->QueryInterface(kIDocumentIID,
(void **) getter_AddRefs(doc))))
{
return NS_ERROR_FAILURE;
}
*result = doc->GetDocumentPrincipal();
if (!*result)
return NS_ERROR_FAILURE;
return NS_OK;
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
if (doc)
return doc->GetPrincipal(result);
return NS_ERROR_FAILURE;
}
extern "C" NS_DOM nsresult

Просмотреть файл

@ -40,7 +40,6 @@
#include "nsIJSScriptObject.h"
#include "nsGUIEvent.h"
#include "nsFrameList.h"
#include "nsIScriptGlobalObjectData.h"
#include "nsDOMWindowList.h"
#include "nsIDOMEventTarget.h"
#include "nsIControllers.h"
@ -73,7 +72,7 @@ class HistoryImpl;
// Global object for scripting
class GlobalWindowImpl : public nsIScriptObjectOwner, public nsIScriptGlobalObject, public nsIDOMWindow,
public nsIJSScriptObject, public nsIScriptGlobalObjectData, public nsIDOMEventReceiver,
public nsIJSScriptObject, public nsIScriptObjectPrincipal, public nsIDOMEventReceiver,
public nsPIDOMWindow, public nsIDOMAbstractView
{
public:
@ -235,7 +234,7 @@ public:
virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID);
virtual void Finalize(JSContext *aContext, JSObject *aObj);
// nsIScriptGlobalObjectData interface
// nsIScriptObjectPrincipal interface
NS_IMETHOD GetPrincipal(nsIPrincipal **prin);
// nsPIDOMWindowInterface

Просмотреть файл

@ -25,7 +25,6 @@
#include "nsIScriptContextOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptGlobalObjectData.h"
#include "nsIDOMWindow.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
@ -232,10 +231,10 @@ nsJSContext::EvaluateString(const nsString& aScript,
nsCOMPtr<nsIScriptGlobalObject> global = dont_AddRef(GetGlobalObject());
if (!global)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptGlobalObjectData> globalData = do_QueryInterface(global, &rv);
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(global, &rv);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
rv = globalData->GetPrincipal(getter_AddRefs(principal));
rv = objPrincipal->GetPrincipal(getter_AddRefs(principal));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
principal->GetJSPrincipals(&jsprin);
@ -487,7 +486,7 @@ nsJSContext::CompileEventHandler(void *aTarget, nsIAtom *aName, const nsString&
nsCOMPtr<nsIScriptGlobalObject> global = getter_AddRefs(GetGlobalObject());
if (global) {
// XXXbe why the two-step QI? speed up via a new GetGlobalObjectData func?
nsCOMPtr<nsIScriptGlobalObjectData> globalData = do_QueryInterface(global);
nsCOMPtr<nsIScriptObjectPrincipal> globalData = do_QueryInterface(global);
if (globalData) {
nsCOMPtr<nsIPrincipal> prin;
if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(prin))))

Просмотреть файл

@ -34,7 +34,6 @@
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptGlobalObjectData.h"
#include "nsJSProtocolHandler.h"
#include "nsIPrincipal.h"
#include "nsIScriptSecurityManager.h"

Просмотреть файл

@ -111,7 +111,7 @@ public:
/**
* Return the principal responsible for this document.
*/
virtual nsIPrincipal* GetDocumentPrincipal() = 0;
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal) = 0;
/**
* Return the LoadGroup for the document. May return null.

Просмотреть файл

@ -710,6 +710,12 @@ nsresult nsDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIScriptObjectPrincipal::GetIID())) {
nsIScriptObjectPrincipal* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMEventReceiverIID)) {
nsIDOMEventReceiver* tmp = this;
*aInstancePtr = (void*) tmp;
@ -862,20 +868,22 @@ nsIURI* nsDocument::GetDocumentURL() const
return mDocumentURL;
}
nsIPrincipal* nsDocument::GetDocumentPrincipal()
NS_IMETHODIMP
nsDocument::GetPrincipal(nsIPrincipal **aPrincipal)
{
if (!mPrincipal) {
nsresult rv;
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
if (NS_FAILED(rv))
return nsnull;
if (NS_FAILED(securityManager->GetCodebasePrincipal(mDocumentURL,
&mPrincipal)))
return nsnull;
return rv;
if (NS_FAILED(rv = securityManager->GetCodebasePrincipal(mDocumentURL,
&mPrincipal)))
return rv;
}
NS_ADDREF(mPrincipal);
return mPrincipal;
*aPrincipal = mPrincipal;
NS_ADDREF(*aPrincipal);
return NS_OK;
}
NS_IMETHODIMP

Просмотреть файл

@ -113,7 +113,8 @@ class nsDocument : public nsIDocument,
public nsIScriptObjectOwner,
public nsIJSScriptObject,
public nsSupportsWeakReference,
public nsIDOMEventReceiver
public nsIDOMEventReceiver,
public nsIScriptObjectPrincipal
{
public:
NS_DECL_ISUPPORTS
@ -139,7 +140,7 @@ public:
/**
* Return the principal responsible for this document.
*/
virtual nsIPrincipal* GetDocumentPrincipal();
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal);
/**
* Return the content (mime) type of this document.

Просмотреть файл

@ -45,7 +45,6 @@
#include "nsDOMEventsIIDs.h"
#include "prmem.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectData.h"
#include "nsLayoutAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@ -60,7 +59,6 @@ static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectDataIID, NS_ISCRIPTGLOBALOBJECTDATA_IID);
nsEventListenerManager::nsEventListenerManager()
{

Просмотреть файл

@ -3891,8 +3891,9 @@ HTMLContentSink::EvaluateScript(nsString& aScript,
NS_ERROR_FAILURE);
nsCOMPtr<nsIPrincipal> principal;
principal = getter_AddRefs(mDocument->GetDocumentPrincipal());
NS_ASSERTION(principal, "principal expected for document");
rv = mDocument->GetPrincipal(getter_AddRefs(principal));
NS_ASSERTION(NS_SUCCEEDED(rv), "principal expected for document");
if (NS_FAILED(rv)) return rv;
nsAutoString ret;
nsIURI* docURL = mDocument->GetDocumentURL();

Просмотреть файл

@ -1434,8 +1434,8 @@ nsHTMLDocument::GetReferrer(nsString& aReferrer)
NS_IMETHODIMP
nsHTMLDocument::GetDomainURI(nsIURI **uri)
{
nsCOMPtr<nsIPrincipal> principal = GetDocumentPrincipal();
if (!principal)
nsCOMPtr<nsIPrincipal> principal;
if (NS_FAILED(GetPrincipal(getter_AddRefs(principal))))
return NS_ERROR_FAILURE;
nsCOMPtr<nsICodebasePrincipal> codebase = do_QueryInterface(principal);
if (!codebase)

Просмотреть файл

@ -27,18 +27,17 @@
#include "nsITimerCallback.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectData.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDocument.h"
#include "nsINameSpaceManager.h"
#include "nsHTMLAtoms.h"
#include "nsIPrincipal.h"
#include "nsGfxAutoTextControlFrame.h"
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectDataIID, NS_ISCRIPTGLOBALOBJECTDATA_IID);
//extern nsresult NS_NewNativeTextControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
@ -270,7 +269,7 @@ nsresult nsGfxAutoTextControlFrame::SetEventHandlers(PRInt32 handlerID)
nsresult nsGfxAutoTextControlFrame::AddScriptEventHandler(PRInt32 handlerID, const char* handlerName, const nsString& aFunc, nsIDocument* aDocument)
{
nsresult ret = NS_OK;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal;
if (nsnull != aDocument)
{
@ -302,32 +301,26 @@ nsresult nsGfxAutoTextControlFrame::BuildScriptEventHandler(nsIScriptContext* aC
const char *aName, const nsString& aFunc, JSObject **mScriptObject)
{
nsIScriptGlobalObject *global;
nsIScriptGlobalObjectData *globalData;
nsIPrincipal * prin = nsnull;
nsCOMPtr<nsIPrincipal> prin;
*mScriptObject = nsnull;
global = aContext->GetGlobalObject();
if (global && NS_SUCCEEDED(global->QueryInterface(kIScriptGlobalObjectDataIID, (void**)&globalData)))
{
if (NS_FAILED(globalData->GetPrincipal(& prin)))
{
NS_RELEASE(global);
NS_RELEASE(globalData);
return NS_ERROR_FAILURE;
}
NS_RELEASE(globalData);
}
NS_IF_RELEASE(global);
if (!global)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptObjectPrincipal> objPrin = do_QueryInterface(global);
if (!objPrin || NS_FAILED(objPrin->GetPrincipal(getter_AddRefs(prin)))) {
NS_RELEASE(global);
return NS_ERROR_FAILURE;
}
NS_RELEASE(global);
JSPrincipals *jsprin;
prin->GetJSPrincipals(&jsprin);
JSContext* mJSContext = (JSContext*)aContext->GetNativeContext();
if (NS_OK == aScriptObjectOwner->GetScriptObject(aContext, (void**)mScriptObject))
{
if (nsnull != aName)
{
if (nsnull != aName) {
JS_CompileUCFunctionForPrincipals(mJSContext, *mScriptObject, jsprin, aName,
0, nsnull, (jschar*)aFunc.GetUnicode(), aFunc.Length(),
nsnull, 0);
0, nsnull, (jschar*)aFunc.GetUnicode(),
aFunc.Length(), nsnull, 0);
JSPRINCIPALS_DROP(mJSContext, jsprin);
return NS_OK;
}

Просмотреть файл

@ -756,12 +756,10 @@ nsXULDocument::GetDocumentURL() const
return result;
}
nsIPrincipal*
nsXULDocument::GetDocumentPrincipal()
NS_IMETHODIMP
nsXULDocument::GetPrincipal(nsIPrincipal **aPrincipal)
{
nsIPrincipal* principal = nsnull;
mMasterPrototype->GetDocumentPrincipal(&principal);
return principal;
return mMasterPrototype->GetDocumentPrincipal(aPrincipal);
}

Просмотреть файл

@ -117,7 +117,7 @@ public:
virtual nsIURI* GetDocumentURL() const;
virtual nsIPrincipal* GetDocumentPrincipal();
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal);
NS_IMETHOD GetDocumentLoadGroup(nsILoadGroup **aGroup) const;

Просмотреть файл

@ -4113,8 +4113,9 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
// Use the enclosing document's principal
// XXX is this right? or should we use the protodoc's?
nsCOMPtr<nsIPrincipal> principal =
dont_AddRef(aDocument->GetDocumentPrincipal());
nsCOMPtr<nsIPrincipal> principal;
rv = aDocument->GetPrincipal(getter_AddRefs(principal));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString urlspec;
aURI->GetSpec(getter_Copies(urlspec));

Просмотреть файл

@ -30,7 +30,6 @@
#include "nsCOMPtr.h"
#include "nsIPrincipal.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectData.h"
#include "nsIScriptSecurityManager.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
@ -45,7 +44,7 @@
class nsXULPrototypeDocument : public nsIXULPrototypeDocument,
public nsIScriptObjectOwner,
public nsIScriptGlobalObject,
public nsIScriptGlobalObjectData
public nsIScriptObjectPrincipal
{
public:
static nsresult
@ -92,7 +91,7 @@ public:
PRUint32 aFlags,
nsEventStatus* aEventStatus);
// nsIScriptGlobalObjectData methods
// nsIScriptObjectPrincipal methods
NS_IMETHOD GetPrincipal(nsIPrincipal** aPrincipal);
@ -163,7 +162,7 @@ NS_IMPL_ISUPPORTS4(nsXULPrototypeDocument,
nsIXULPrototypeDocument,
nsIScriptObjectOwner,
nsIScriptGlobalObject,
nsIScriptGlobalObjectData);
nsIScriptObjectPrincipal);
NS_IMETHODIMP
NS_NewXULPrototypeDocument(nsISupports* aOuter, REFNSIID aIID, void** aResult)
@ -462,7 +461,7 @@ nsXULPrototypeDocument::HandleDOMEvent(nsIPresContext* aPresContext,
//----------------------------------------------------------------------
//
// nsIScriptGlobalObjectData methods
// nsIScriptObjectPrincipal methods
//
NS_IMETHODIMP