diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index 971308ae9bf..6a89b588975 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -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 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 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))); diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 6262bb6176d..9149f15f55e 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.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. diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 61af15aee4d..4528f648d25 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -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 diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 0a037e18b23..7393497828b 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -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. diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index d2ceeab96ab..63efac093d4 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -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() { diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 72cac7924a5..c882f4b3550 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -3891,8 +3891,9 @@ HTMLContentSink::EvaluateScript(nsString& aScript, NS_ERROR_FAILURE); nsCOMPtr 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(); diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index c9e1021ab8c..c3206b37548 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -1434,8 +1434,8 @@ nsHTMLDocument::GetReferrer(nsString& aReferrer) NS_IMETHODIMP nsHTMLDocument::GetDomainURI(nsIURI **uri) { - nsCOMPtr principal = GetDocumentPrincipal(); - if (!principal) + nsCOMPtr principal; + if (NS_FAILED(GetPrincipal(getter_AddRefs(principal)))) return NS_ERROR_FAILURE; nsCOMPtr codebase = do_QueryInterface(principal); if (!codebase) diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index 30550e8ac03..f96fad624db 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -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 principal = - dont_AddRef(aDocument->GetDocumentPrincipal()); + nsCOMPtr principal; + rv = aDocument->GetPrincipal(getter_AddRefs(principal)); + if (NS_FAILED(rv)) return rv; nsXPIDLCString urlspec; aURI->GetSpec(getter_Copies(urlspec)); diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index ba85b812b6a..3ee815d5d04 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -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); } diff --git a/mozilla/content/xul/document/src/nsXULDocument.h b/mozilla/content/xul/document/src/nsXULDocument.h index df8c284404b..d8850019247 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.h +++ b/mozilla/content/xul/document/src/nsXULDocument.h @@ -117,7 +117,7 @@ public: virtual nsIURI* GetDocumentURL() const; - virtual nsIPrincipal* GetDocumentPrincipal(); + NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal); NS_IMETHOD GetDocumentLoadGroup(nsILoadGroup **aGroup) const; diff --git a/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp b/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp index 10a7bc23254..c1cd187e0e6 100644 --- a/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp @@ -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 diff --git a/mozilla/dom/public/MANIFEST b/mozilla/dom/public/MANIFEST index edacd59bade..a23a6d03987 100644 --- a/mozilla/dom/public/MANIFEST +++ b/mozilla/dom/public/MANIFEST @@ -31,7 +31,6 @@ nsIDOMNativeObjectRegistry.h nsDOMCID.h nsDOMPropEnums.h nsDOMPropNames.h -nsIScriptGlobalObjectData.h nsIScriptNameSetRegistry.h nsIScriptExternalNameSet.h nsIScriptNameSpaceManager.h diff --git a/mozilla/dom/public/Makefile.in b/mozilla/dom/public/Makefile.in index 6d6c95e8622..af9f9c210a8 100644 --- a/mozilla/dom/public/Makefile.in +++ b/mozilla/dom/public/Makefile.in @@ -47,7 +47,6 @@ EXPORTS = \ nsDOMCID.h \ nsDOMPropEnums.h \ nsDOMPropNames.h \ - nsIScriptGlobalObjectData.h \ nsIScriptNameSetRegistry.h \ nsIScriptExternalNameSet.h \ nsIScriptNameSpaceManager.h \ diff --git a/mozilla/dom/public/makefile.win b/mozilla/dom/public/makefile.win index 8cacdf1e333..a601c430519 100644 --- a/mozilla/dom/public/makefile.win +++ b/mozilla/dom/public/makefile.win @@ -45,7 +45,6 @@ EXPORTS=nsIScriptContext.h \ nsIScriptNameSetRegistry.h \ nsIScriptExternalNameSet.h \ nsIScriptNameSpaceManager.h \ - nsIScriptGlobalObjectData.h \ nsDOMError.h \ nsIJSEventListener.h diff --git a/mozilla/dom/public/nsIScriptGlobalObjectData.h b/mozilla/dom/public/nsIScriptGlobalObjectData.h deleted file mode 100644 index fb2726a8f7a..00000000000 --- a/mozilla/dom/public/nsIScriptGlobalObjectData.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsIScriptGlobalObjectData_h__ -#define nsIScriptGlobalObjectData_h__ - -#include "nsISupports.h" -#include "nsIURI.h" -#include "nsIPrincipal.h" - -#define NS_ISCRIPTGLOBALOBJECTDATA_IID \ -{ 0x98485f80, 0x9615, 0x11d2, \ -{ 0xbd, 0x92, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } -/** - * JS Global Object information. - */ - -class nsIScriptGlobalObjectData : public nsISupports { -public: - -NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECTDATA_IID) - - NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal) = 0; -}; - -#endif //nsIScriptGlobalObjectData_h__ diff --git a/mozilla/dom/public/nsIScriptObjectOwner.h b/mozilla/dom/public/nsIScriptObjectOwner.h index 5367783088c..5f686c4d7f4 100644 --- a/mozilla/dom/public/nsIScriptObjectOwner.h +++ b/mozilla/dom/public/nsIScriptObjectOwner.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__ diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index a19500f4947..2bb0a2c661e 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -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 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 doc = do_QueryInterface(mDocument); + if (doc) + return doc->GetPrincipal(result); + return NS_ERROR_FAILURE; } extern "C" NS_DOM nsresult diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index 87f93f44e61..fc58865e609 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -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 diff --git a/mozilla/dom/src/base/nsJSEnvironment.cpp b/mozilla/dom/src/base/nsJSEnvironment.cpp index 8d2258f427e..8892de3c67b 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.cpp +++ b/mozilla/dom/src/base/nsJSEnvironment.cpp @@ -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 global = dont_AddRef(GetGlobalObject()); if (!global) return NS_ERROR_FAILURE; - nsCOMPtr globalData = do_QueryInterface(global, &rv); + nsCOMPtr 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 global = getter_AddRefs(GetGlobalObject()); if (global) { // XXXbe why the two-step QI? speed up via a new GetGlobalObjectData func? - nsCOMPtr globalData = do_QueryInterface(global); + nsCOMPtr globalData = do_QueryInterface(global); if (globalData) { nsCOMPtr prin; if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(prin)))) diff --git a/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp b/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp index d5d72fedfa9..2fe4aeb15fa 100644 --- a/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -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" diff --git a/mozilla/layout/base/public/nsIDocument.h b/mozilla/layout/base/public/nsIDocument.h index 6262bb6176d..9149f15f55e 100644 --- a/mozilla/layout/base/public/nsIDocument.h +++ b/mozilla/layout/base/public/nsIDocument.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. diff --git a/mozilla/layout/base/src/nsDocument.cpp b/mozilla/layout/base/src/nsDocument.cpp index 61af15aee4d..4528f648d25 100644 --- a/mozilla/layout/base/src/nsDocument.cpp +++ b/mozilla/layout/base/src/nsDocument.cpp @@ -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 diff --git a/mozilla/layout/base/src/nsDocument.h b/mozilla/layout/base/src/nsDocument.h index 0a037e18b23..7393497828b 100644 --- a/mozilla/layout/base/src/nsDocument.h +++ b/mozilla/layout/base/src/nsDocument.h @@ -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. diff --git a/mozilla/layout/events/src/nsEventListenerManager.cpp b/mozilla/layout/events/src/nsEventListenerManager.cpp index d2ceeab96ab..63efac093d4 100644 --- a/mozilla/layout/events/src/nsEventListenerManager.cpp +++ b/mozilla/layout/events/src/nsEventListenerManager.cpp @@ -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() { diff --git a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp index 72cac7924a5..c882f4b3550 100644 --- a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp @@ -3891,8 +3891,9 @@ HTMLContentSink::EvaluateScript(nsString& aScript, NS_ERROR_FAILURE); nsCOMPtr 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(); diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index c9e1021ab8c..c3206b37548 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -1434,8 +1434,8 @@ nsHTMLDocument::GetReferrer(nsString& aReferrer) NS_IMETHODIMP nsHTMLDocument::GetDomainURI(nsIURI **uri) { - nsCOMPtr principal = GetDocumentPrincipal(); - if (!principal) + nsCOMPtr principal; + if (NS_FAILED(GetPrincipal(getter_AddRefs(principal)))) return NS_ERROR_FAILURE; nsCOMPtr codebase = do_QueryInterface(principal); if (!codebase) diff --git a/mozilla/layout/html/forms/src/nsGfxAutoTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxAutoTextControlFrame.cpp index 127ee403553..bf5e947aee5 100644 --- a/mozilla/layout/html/forms/src/nsGfxAutoTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxAutoTextControlFrame.cpp @@ -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 scriptGlobal; + nsCOMPtr 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 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 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; } diff --git a/mozilla/rdf/content/src/nsXULDocument.cpp b/mozilla/rdf/content/src/nsXULDocument.cpp index ba85b812b6a..3ee815d5d04 100644 --- a/mozilla/rdf/content/src/nsXULDocument.cpp +++ b/mozilla/rdf/content/src/nsXULDocument.cpp @@ -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); } diff --git a/mozilla/rdf/content/src/nsXULDocument.h b/mozilla/rdf/content/src/nsXULDocument.h index df8c284404b..d8850019247 100644 --- a/mozilla/rdf/content/src/nsXULDocument.h +++ b/mozilla/rdf/content/src/nsXULDocument.h @@ -117,7 +117,7 @@ public: virtual nsIURI* GetDocumentURL() const; - virtual nsIPrincipal* GetDocumentPrincipal(); + NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal); NS_IMETHOD GetDocumentLoadGroup(nsILoadGroup **aGroup) const; diff --git a/mozilla/rdf/content/src/nsXULElement.cpp b/mozilla/rdf/content/src/nsXULElement.cpp index 30550e8ac03..f96fad624db 100644 --- a/mozilla/rdf/content/src/nsXULElement.cpp +++ b/mozilla/rdf/content/src/nsXULElement.cpp @@ -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 principal = - dont_AddRef(aDocument->GetDocumentPrincipal()); + nsCOMPtr principal; + rv = aDocument->GetPrincipal(getter_AddRefs(principal)); + if (NS_FAILED(rv)) return rv; nsXPIDLCString urlspec; aURI->GetSpec(getter_Copies(urlspec)); diff --git a/mozilla/rdf/content/src/nsXULPrototypeDocument.cpp b/mozilla/rdf/content/src/nsXULPrototypeDocument.cpp index 10a7bc23254..c1cd187e0e6 100644 --- a/mozilla/rdf/content/src/nsXULPrototypeDocument.cpp +++ b/mozilla/rdf/content/src/nsXULPrototypeDocument.cpp @@ -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