From f5bc62edead23a10dfd21061856a385ec4f9d7d9 Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Tue, 31 Jul 2001 19:05:34 +0000 Subject: [PATCH] FASTLOAD_20010703_BRANCH landing, r=dbaron, sr=shaver. git-svn-id: svn://10.0.0.236/trunk@100030 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/caps/idl/nsIPrincipal.idl | 34 +- mozilla/caps/include/nsAggregatePrincipal.h | 4 +- mozilla/caps/include/nsBasePrincipal.h | 8 + mozilla/caps/include/nsCertificatePrincipal.h | 5 +- mozilla/caps/include/nsCodebasePrincipal.h | 1 + mozilla/caps/include/nsJSPrincipals.h | 3 +- mozilla/caps/include/nsSystemPrincipal.h | 3 + mozilla/caps/src/nsAggregatePrincipal.cpp | 43 +- mozilla/caps/src/nsBasePrincipal.cpp | 103 + mozilla/caps/src/nsCertificatePrincipal.cpp | 49 +- mozilla/caps/src/nsCodebasePrincipal.cpp | 30 +- mozilla/caps/src/nsJSPrincipals.cpp | 122 +- mozilla/caps/src/nsScriptSecurityManager.cpp | 212 +- mozilla/caps/src/nsSecurityManagerFactory.cpp | 154 +- mozilla/caps/src/nsSystemPrincipal.cpp | 20 +- .../chrome/src/nsChromeProtocolHandler.cpp | 2 +- mozilla/content/build/nsContentFactory.cpp | 27 +- mozilla/content/build/nsContentModule.cpp | 3 + .../html/style/src/nsCSSStyleSheet.cpp | 2 + .../content/xul/content/src/nsXULElement.cpp | 416 +++- .../content/xul/content/src/nsXULElement.h | 18 +- .../xul/document/public/nsIXULDocument.h | 12 + .../document/public/nsIXULPrototypeCache.h | 4 + .../document/public/nsIXULPrototypeDocument.h | 14 +- .../xul/document/src/nsXULContentSink.cpp | 139 +- .../xul/document/src/nsXULDocument.cpp | 991 ++++++-- .../content/xul/document/src/nsXULDocument.h | 60 +- .../xul/document/src/nsXULPrototypeCache.cpp | 112 +- .../document/src/nsXULPrototypeDocument.cpp | 139 +- .../dom/public/nsIScriptGlobalObjectOwner.idl | 4 +- mozilla/dom/src/base/nsDOMClassInfo.cpp | 6 +- mozilla/js/src/js.msg | 1 + mozilla/js/src/jsapi.c | 29 + mozilla/js/src/jsapi.h | 16 +- mozilla/js/src/jscntxt.h | 3 + mozilla/js/src/jsfun.c | 1 + mozilla/js/src/jsnum.h | 12 +- mozilla/js/src/jspubtd.h | 10 + mozilla/js/src/jsscan.c | 33 +- mozilla/js/src/jsscript.c | 40 +- mozilla/js/src/jsxdrapi.c | 50 +- mozilla/js/src/jsxdrapi.h | 11 +- mozilla/js/src/xpconnect/src/xpcjsid.cpp | 9 +- mozilla/layout/style/nsCSSStyleSheet.cpp | 2 + mozilla/mailnews/base/util/nsMsgFolder.cpp | 24 +- mozilla/mailnews/base/util/nsMsgFolder.h | 2 + mozilla/modules/libjar/nsIJARURI.idl | 2 +- mozilla/modules/libjar/nsJARURI.cpp | 21 +- mozilla/modules/libjar/nsJARURI.h | 4 +- .../libpr0n/decoders/icon/nsIconURI.cpp | 5 +- .../modules/libpr0n/decoders/icon/nsIconURI.h | 2 +- .../src/nsMPFileLocProvider.cpp | 6 +- .../netwerk/base/public/nsIFileStreams.idl | 16 +- mozilla/netwerk/base/public/nsIURI.idl | 2 +- .../netwerk/base/src/nsBufferedStreams.cpp | 186 +- mozilla/netwerk/base/src/nsBufferedStreams.h | 28 +- mozilla/netwerk/base/src/nsFileStreams.cpp | 79 +- mozilla/netwerk/base/src/nsFileStreams.h | 4 +- mozilla/netwerk/base/src/nsSimpleURI.cpp | 51 +- mozilla/netwerk/base/src/nsSimpleURI.h | 4 +- mozilla/netwerk/base/src/nsStdURL.cpp | 155 +- mozilla/netwerk/base/src/nsStdURL.h | 4 +- .../netwerk/protocol/jar/public/nsIJARURI.idl | 2 +- mozilla/netwerk/protocol/jar/src/nsJARURI.cpp | 21 +- mozilla/netwerk/protocol/jar/src/nsJARURI.h | 4 +- .../chrome/src/nsChromeProtocolHandler.cpp | 2 +- .../tools/trace-malloc/lib/nsTraceMalloc.c | 5 +- mozilla/xpcom/base/nsAgg.h | 16 +- mozilla/xpcom/base/nsCOMPtr.h | 4 +- mozilla/xpcom/base/nsISupportsUtils.h | 1491 +++++++----- mozilla/xpcom/base/nsTraceMalloc.c | 5 +- mozilla/xpcom/base/nsrootidl.idl | 2 + mozilla/xpcom/build/nsXPComInit.cpp | 6 +- mozilla/xpcom/components/nsGenericFactory.cpp | 6 +- mozilla/xpcom/components/nsGenericFactory.h | 22 +- mozilla/xpcom/components/nsIClassInfo.idl | 5 +- .../xpcom/components/nsIComponentManager.idl | 3 - mozilla/xpcom/components/nsIGenericFactory.h | 265 ++- mozilla/xpcom/ds/MANIFEST_IDL | 8 +- mozilla/xpcom/ds/Makefile.in | 4 +- mozilla/xpcom/ds/makefile.win | 152 +- mozilla/xpcom/ds/nsHashtable.cpp | 550 +++-- mozilla/xpcom/ds/nsHashtable.h | 470 ++-- mozilla/xpcom/ds/nsICollection.idl | 4 +- mozilla/xpcom/ds/nsISerializable.idl | 49 + mozilla/xpcom/ds/nsSupportsArray.cpp | 107 +- mozilla/xpcom/ds/nsSupportsArray.h | 2 + mozilla/xpcom/glue/nsCOMPtr.h | 4 +- mozilla/xpcom/glue/nsGenericFactory.cpp | 6 +- mozilla/xpcom/glue/nsGenericFactory.h | 22 +- mozilla/xpcom/glue/nsIGenericFactory.h | 265 ++- mozilla/xpcom/glue/nsISupportsUtils.h | 1491 +++++++----- mozilla/xpcom/io/MANIFEST_IDL | 22 +- mozilla/xpcom/io/Makefile.in | 52 +- mozilla/xpcom/io/makefile.win | 116 +- .../xpcom/io/nsAppFileLocationProvider.cpp | 82 +- mozilla/xpcom/io/nsBinaryStream.cpp | 297 ++- mozilla/xpcom/io/nsBinaryStream.h | 48 +- mozilla/xpcom/io/nsDirectoryService.cpp | 56 +- mozilla/xpcom/io/nsFastLoadFile.cpp | 2088 +++++++++++++++++ mozilla/xpcom/io/nsFastLoadFile.h | 548 +++++ mozilla/xpcom/io/nsFastLoadPtr.h | 92 + mozilla/xpcom/io/nsFastLoadService.cpp | 472 ++++ mozilla/xpcom/io/nsFastLoadService.h | 51 + mozilla/xpcom/io/nsIBaseStream.idl | 2 +- mozilla/xpcom/io/nsIBinaryInputStream.idl | 40 +- mozilla/xpcom/io/nsIBinaryOutputStream.idl | 32 +- mozilla/xpcom/io/nsIFastLoadFileControl.idl | 77 + mozilla/xpcom/io/nsIFastLoadService.idl | 114 + mozilla/xpcom/io/nsIInputStream.idl | 4 +- mozilla/xpcom/io/nsILocalFile.idl | 27 +- mozilla/xpcom/io/nsIObjectInputStream.idl | 73 + mozilla/xpcom/io/nsIObjectOutputStream.idl | 115 + mozilla/xpcom/io/nsIOutputStream.idl | 4 +- mozilla/xpcom/io/nsISeekableStream.idl | 44 + mozilla/xpcom/io/nsIStreamBufferAccess.idl | 142 ++ mozilla/xpcom/macbuild/XPCOMIDL.mcp | Bin 91970 -> 91970 bytes mozilla/xpcom/macbuild/xpcomPPC.mcp | Bin 142636 -> 142636 bytes 118 files changed, 10050 insertions(+), 3093 deletions(-) create mode 100644 mozilla/xpcom/ds/nsISerializable.idl create mode 100644 mozilla/xpcom/io/nsFastLoadFile.cpp create mode 100644 mozilla/xpcom/io/nsFastLoadFile.h create mode 100644 mozilla/xpcom/io/nsFastLoadPtr.h create mode 100644 mozilla/xpcom/io/nsFastLoadService.cpp create mode 100644 mozilla/xpcom/io/nsFastLoadService.h create mode 100644 mozilla/xpcom/io/nsIFastLoadFileControl.idl create mode 100644 mozilla/xpcom/io/nsIFastLoadService.idl create mode 100644 mozilla/xpcom/io/nsIObjectInputStream.idl create mode 100644 mozilla/xpcom/io/nsIObjectOutputStream.idl create mode 100644 mozilla/xpcom/io/nsISeekableStream.idl create mode 100644 mozilla/xpcom/io/nsIStreamBufferAccess.idl diff --git a/mozilla/caps/idl/nsIPrincipal.idl b/mozilla/caps/idl/nsIPrincipal.idl index 50647149c63..27962896948 100644 --- a/mozilla/caps/idl/nsIPrincipal.idl +++ b/mozilla/caps/idl/nsIPrincipal.idl @@ -24,7 +24,7 @@ /* Defines the abstract interface for a principal. */ -#include "nsISupports.idl" +#include "nsISerializable.idl" %{C++ struct JSPrincipals; @@ -35,40 +35,38 @@ interface nsIPref; [ptr] native JSPrincipals(JSPrincipals); [uuid(ff9313d0-25e1-11d2-8160-006008119d7a)] -interface nsIPrincipal : nsISupports { +interface nsIPrincipal : nsISerializable { - // Values of capabilities for each principal. Order is - // significant: if an operation is performed on a set - // of capabilities, the minimum is computed. - const short ENABLE_DENIED = 1; - const short ENABLE_UNKNOWN = 2; - const short ENABLE_WITH_USER_PERMISSION = 3; - const short ENABLE_GRANTED = 4; + // Values of capabilities for each principal. Order is + // significant: if an operation is performed on a set + // of capabilities, the minimum is computed. + const short ENABLE_DENIED = 1; + const short ENABLE_UNKNOWN = 2; + const short ENABLE_WITH_USER_PERMISSION = 3; + const short ENABLE_GRANTED = 4; - string ToString(); + string ToString(); - string ToUserVisibleString(); + string ToUserVisibleString(); void GetPreferences(out string prefName, out string id, out string grantedList, out string deniedList); - boolean Equals(in nsIPrincipal other); + boolean Equals(in nsIPrincipal other); - unsigned long HashValue(); + unsigned long HashValue(); - JSPrincipals GetJSPrincipals(); + JSPrincipals GetJSPrincipals(); short CanEnableCapability(in string capability); void SetCanEnableCapability(in string capability, in short canEnable); boolean IsCapabilityEnabled(in string capability, in voidPtr annotation); - - void EnableCapability(in string capability, inout voidPtr annotation); + + void EnableCapability(in string capability, inout voidPtr annotation); void RevertCapability(in string capability, inout voidPtr annotation); void DisableCapability(in string capability, inout voidPtr annotation); }; - - diff --git a/mozilla/caps/include/nsAggregatePrincipal.h b/mozilla/caps/include/nsAggregatePrincipal.h index 8dea5bba391..ace4ddcc57e 100644 --- a/mozilla/caps/include/nsAggregatePrincipal.h +++ b/mozilla/caps/include/nsAggregatePrincipal.h @@ -36,6 +36,7 @@ #define NS_AGGREGATEPRINCIPAL_CID \ { 0x867cf414, 0x1dd2, 0x11b2, \ { 0x82, 0x66, 0xca, 0x64, 0x3b, 0xbc, 0x35, 0x64 }} + /* 867cf414-1dd2-11b2-8266-ca643bbc3564 */ class nsAggregatePrincipal : public nsIAggregatePrincipal, public nsICertificatePrincipal, @@ -46,6 +47,7 @@ public: NS_DEFINE_STATIC_CID_ACCESSOR(NS_AGGREGATEPRINCIPAL_CID) NS_DECL_ISUPPORTS + NS_DECL_NSISERIALIZABLE NS_DECL_NSIAGGREGATEPRINCIPAL NS_DECL_NSICERTIFICATEPRINCIPAL NS_DECL_NSICODEBASEPRINCIPAL @@ -87,7 +89,7 @@ public: nsAggregatePrincipal(); - virtual ~nsAggregatePrincipal(void); + virtual ~nsAggregatePrincipal(void); protected: nsCOMPtr mCertificate; diff --git a/mozilla/caps/include/nsBasePrincipal.h b/mozilla/caps/include/nsBasePrincipal.h index 3a6f5fab3f4..e83be39fa0f 100644 --- a/mozilla/caps/include/nsBasePrincipal.h +++ b/mozilla/caps/include/nsBasePrincipal.h @@ -28,6 +28,8 @@ #include "nsJSPrincipals.h" #include "nsVoidArray.h" #include "nsHashtable.h" +#include "nsIObjectInputStream.h" +#include "nsIObjectOutputStream.h" class nsBasePrincipal: public nsIPrincipal { public: @@ -66,6 +68,12 @@ public: InitFromPersistent(const char* aPrefName,const char* aID, const char* aGrantedList, const char* aDeniedList); + NS_IMETHOD + Read(nsIObjectInputStream* aStream); + + NS_IMETHOD + Write(nsIObjectOutputStream* aStream); + static const char Invalid[]; protected: diff --git a/mozilla/caps/include/nsCertificatePrincipal.h b/mozilla/caps/include/nsCertificatePrincipal.h index c1a83e08e7c..e3b7ac1a5ee 100644 --- a/mozilla/caps/include/nsCertificatePrincipal.h +++ b/mozilla/caps/include/nsCertificatePrincipal.h @@ -32,7 +32,7 @@ class nsIURI; -#define NS_CERTIFICATEPRINCIPALMANAGER_CID \ +#define NS_CERTIFICATEPRINCIPAL_CID \ { 0x7ee2a4c0, 0x4b91, 0x11d3, \ { 0xba, 0x18, 0x00, 0x60, 0xb0, 0xf1, 0x99, 0xa2 }} @@ -40,8 +40,9 @@ class nsCertificatePrincipal : public nsICertificatePrincipal, public nsBasePrin { public: - NS_DEFINE_STATIC_CID_ACCESSOR(NS_CERTIFICATEPRINCIPALMANAGER_CID) + NS_DEFINE_STATIC_CID_ACCESSOR(NS_CERTIFICATEPRINCIPAL_CID) NS_DECL_ISUPPORTS + NS_DECL_NSISERIALIZABLE NS_DECL_NSICERTIFICATEPRINCIPAL NS_IMETHOD ToString(char **result); diff --git a/mozilla/caps/include/nsCodebasePrincipal.h b/mozilla/caps/include/nsCodebasePrincipal.h index 436a020dfc3..1f9e7fd5cd7 100644 --- a/mozilla/caps/include/nsCodebasePrincipal.h +++ b/mozilla/caps/include/nsCodebasePrincipal.h @@ -42,6 +42,7 @@ public: NS_DEFINE_STATIC_CID_ACCESSOR(NS_CODEBASEPRINCIPAL_CID) NS_DECL_ISUPPORTS + NS_DECL_NSISERIALIZABLE NS_DECL_NSICODEBASEPRINCIPAL NS_IMETHOD ToString(char **result); diff --git a/mozilla/caps/include/nsJSPrincipals.h b/mozilla/caps/include/nsJSPrincipals.h index 2aac9e725eb..9c4c3493aff 100644 --- a/mozilla/caps/include/nsJSPrincipals.h +++ b/mozilla/caps/include/nsJSPrincipals.h @@ -26,8 +26,7 @@ #include "nsIPrincipal.h" struct nsJSPrincipals : JSPrincipals { - -public: + static nsresult Startup(); nsJSPrincipals(); nsresult Init(char *prin); ~nsJSPrincipals(void); diff --git a/mozilla/caps/include/nsSystemPrincipal.h b/mozilla/caps/include/nsSystemPrincipal.h index e672b3218a2..e149dea5760 100644 --- a/mozilla/caps/include/nsSystemPrincipal.h +++ b/mozilla/caps/include/nsSystemPrincipal.h @@ -28,15 +28,18 @@ #include "nsBasePrincipal.h" +#define NS_SYSTEMPRINCIPAL_CLASSNAME "systemprincipal" #define NS_SYSTEMPRINCIPAL_CID \ { 0x4a6212db, 0xaccb, 0x11d3, \ { 0xb7, 0x65, 0x0, 0x60, 0xb0, 0xb6, 0xce, 0xcb }} +#define NS_SYSTEMPRINCIPAL_CONTRACTID "@mozilla.org/systemprincipal;1" class nsSystemPrincipal : public nsBasePrincipal { public: NS_DECL_ISUPPORTS + NS_DECL_NSISERIALIZABLE NS_IMETHOD ToString(char **result); diff --git a/mozilla/caps/src/nsAggregatePrincipal.cpp b/mozilla/caps/src/nsAggregatePrincipal.cpp index 1953f6e575b..dcec990228c 100644 --- a/mozilla/caps/src/nsAggregatePrincipal.cpp +++ b/mozilla/caps/src/nsAggregatePrincipal.cpp @@ -28,8 +28,9 @@ static NS_DEFINE_IID(kIAggregatePrincipalIID, NS_IAGGREGATEPRINCIPAL_IID); -NS_IMPL_QUERY_INTERFACE4(nsAggregatePrincipal, nsIAggregatePrincipal, - nsICertificatePrincipal, nsICodebasePrincipal, nsIPrincipal) +NS_IMPL_QUERY_INTERFACE5_CI(nsAggregatePrincipal, nsIAggregatePrincipal, + nsICertificatePrincipal, nsICodebasePrincipal, + nsIPrincipal, nsISerializable) NSBASEPRINCIPALS_ADDREF(nsAggregatePrincipal); NSBASEPRINCIPALS_RELEASE(nsAggregatePrincipal); @@ -357,6 +358,44 @@ nsAggregatePrincipal::GetPreferences(char** aPrefName, char** aID, aGrantedList, aDeniedList); } +////////////////////////////////////////// +// Methods implementing nsISerializable // +////////////////////////////////////////// + +NS_IMETHODIMP +nsAggregatePrincipal::Read(nsIObjectInputStream* aStream) +{ + nsresult rv; + + rv = nsBasePrincipal::Read(aStream); + if (NS_FAILED(rv)) return rv; + + rv = NS_ReadOptionalObject(aStream, PR_TRUE, getter_AddRefs(mCertificate)); + if (NS_FAILED(rv)) return rv; + + rv = NS_ReadOptionalObject(aStream, PR_TRUE, getter_AddRefs(mCodebase)); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +NS_IMETHODIMP +nsAggregatePrincipal::Write(nsIObjectOutputStream* aStream) +{ + nsresult rv; + + rv = nsBasePrincipal::Write(aStream); + if (NS_FAILED(rv)) return rv; + + rv = NS_WriteOptionalObject(aStream, mCertificate, PR_TRUE); + if (NS_FAILED(rv)) return rv; + + rv = NS_WriteOptionalObject(aStream, mCodebase, PR_TRUE); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + ///////////////////////////////////////////// // Constructor, Destructor, initialization // ///////////////////////////////////////////// diff --git a/mozilla/caps/src/nsBasePrincipal.cpp b/mozilla/caps/src/nsBasePrincipal.cpp index 0e8b70ecc5f..6576b0afff8 100644 --- a/mozilla/caps/src/nsBasePrincipal.cpp +++ b/mozilla/caps/src/nsBasePrincipal.cpp @@ -318,3 +318,106 @@ nsBasePrincipal::GetPreferences(char** aPrefName, char** aID, } return NS_OK; } + +PR_STATIC_CALLBACK(nsresult) +ReadAnnotationEntry(nsIObjectInputStream* aStream, nsHashKey** aKey, + void** aData) +{ + nsresult rv; + nsCStringKey* key = new nsCStringKey(aStream, &rv); + if (NS_FAILED(rv)) return rv; + + PRUint32 value; + rv = aStream->Read32(&value); + if (NS_FAILED(rv)) { + delete key; + return rv; + } + + *aKey = key; + *aData = (void*) value; + return NS_OK; +} + +PR_STATIC_CALLBACK(void) +FreeAnnotationEntry(nsIObjectInputStream* aStream, nsHashKey* aKey, + void* aData) +{ + if (aKey) + delete NS_STATIC_CAST(nsCStringKey*, aKey); +} + +nsresult +nsBasePrincipal::Read(nsIObjectInputStream* aStream) +{ + nsresult rv; + + PRUint32 annotationCount; + rv = aStream->Read32(&annotationCount); + if (NS_FAILED(rv)) return rv; + + for (PRInt32 i = 0, n = PRInt32(annotationCount); i < n; i++) { + nsHashtable *ht = new nsHashtable(aStream, + ReadAnnotationEntry, + FreeAnnotationEntry, + &rv); + NS_ASSERTION(NS_SUCCEEDED(rv) || ht == nsnull, + "failure but non-null return from nsHashtable ctor!"); + if (NS_FAILED(rv)) return rv; + + if (!mAnnotations.InsertElementAt(NS_REINTERPRET_CAST(void*, ht), i)) { + delete ht; + return NS_ERROR_OUT_OF_MEMORY; + } + } + + PRBool hasCapabilities; + rv = aStream->ReadBoolean(&hasCapabilities); + if (NS_SUCCEEDED(rv) && hasCapabilities) { + mCapabilities = new nsHashtable(aStream, + ReadAnnotationEntry, + FreeAnnotationEntry, + &rv); + } + if (NS_FAILED(rv)) return rv; + + rv = NS_ReadOptionalStringZ(aStream, &mPrefName); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +PR_STATIC_CALLBACK(nsresult) +WriteScalarValue(nsIObjectOutputStream* aStream, void* aData) +{ + PRUint32 value = (PRUint32) aData; + + return aStream->Write32(value); +} + +nsresult +nsBasePrincipal::Write(nsIObjectOutputStream* aStream) +{ + nsresult rv; + + PRUint32 annotationCount = PRUint32(mAnnotations.Count()); + rv = aStream->Write32(annotationCount); + if (NS_FAILED(rv)) return rv; + + for (PRInt32 i = 0, n = PRInt32(annotationCount); i < n; i++) { + nsHashtable *ht = NS_REINTERPRET_CAST(nsHashtable *, mAnnotations[i]); + rv = ht->Write(aStream, WriteScalarValue); + if (NS_FAILED(rv)) return rv; + } + + PRBool hasCapabilities = (mCapabilities != nsnull); + rv = aStream->WriteBoolean(hasCapabilities); + if (NS_SUCCEEDED(rv) && hasCapabilities) + rv = mCapabilities->Write(aStream, WriteScalarValue); + if (NS_FAILED(rv)) return rv; + + rv = NS_WriteOptionalStringZ(aStream, mPrefName); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} diff --git a/mozilla/caps/src/nsCertificatePrincipal.cpp b/mozilla/caps/src/nsCertificatePrincipal.cpp index 309e7a50c0e..98f2d5cedc6 100644 --- a/mozilla/caps/src/nsCertificatePrincipal.cpp +++ b/mozilla/caps/src/nsCertificatePrincipal.cpp @@ -29,7 +29,10 @@ static NS_DEFINE_IID(kICertificatePrincipalIID, NS_ICERTIFICATEPRINCIPAL_IID); -NS_IMPL_QUERY_INTERFACE2(nsCertificatePrincipal, nsICertificatePrincipal, nsIPrincipal) +NS_IMPL_QUERY_INTERFACE3_CI(nsCertificatePrincipal, + nsICertificatePrincipal, + nsIPrincipal, + nsISerializable) NSBASEPRINCIPALS_ADDREF(nsCertificatePrincipal); NSBASEPRINCIPALS_RELEASE(nsCertificatePrincipal); @@ -41,14 +44,14 @@ NS_IMETHODIMP nsCertificatePrincipal::GetCertificateID(char** aCertificateID) { *aCertificateID = nsCRT::strdup(mCertificateID); - return *mCertificateID ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + return *mCertificateID ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsCertificatePrincipal::GetCommonName(char** aCommonName) { *aCommonName = nsCRT::strdup(mCommonName); - return *aCommonName ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + return *aCommonName ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP @@ -56,7 +59,7 @@ nsCertificatePrincipal::SetCommonName(const char* aCommonName) { PR_FREEIF(mCommonName); mCommonName = nsCRT::strdup(aCommonName); - return * mCommonName ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + return * mCommonName ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } /////////////////////////////////////// @@ -138,6 +141,44 @@ nsCertificatePrincipal::HashValue(PRUint32 *result) return NS_OK; } +////////////////////////////////////////// +// Methods implementing nsISerializable // +////////////////////////////////////////// + +NS_IMETHODIMP +nsCertificatePrincipal::Read(nsIObjectInputStream* aStream) +{ + nsresult rv; + + rv = nsBasePrincipal::Read(aStream); + if (NS_FAILED(rv)) return rv; + + rv = aStream->ReadStringZ(&mCertificateID); + if (NS_FAILED(rv)) return rv; + + rv = NS_ReadOptionalStringZ(aStream, &mCommonName); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +NS_IMETHODIMP +nsCertificatePrincipal::Write(nsIObjectOutputStream* aStream) +{ + nsresult rv; + + rv = nsBasePrincipal::Write(aStream); + if (NS_FAILED(rv)) return rv; + + rv = aStream->WriteStringZ(mCertificateID); + if (NS_FAILED(rv)) return rv; + + rv = NS_WriteOptionalStringZ(aStream, mCommonName); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + ///////////////////////////////////////////// // Constructor, Destructor, initialization // ///////////////////////////////////////////// diff --git a/mozilla/caps/src/nsCodebasePrincipal.cpp b/mozilla/caps/src/nsCodebasePrincipal.cpp index 4d774fcce21..86af507895d 100644 --- a/mozilla/caps/src/nsCodebasePrincipal.cpp +++ b/mozilla/caps/src/nsCodebasePrincipal.cpp @@ -33,7 +33,10 @@ #include "nsIPref.h" #include "nsXPIDLString.h" -NS_IMPL_QUERY_INTERFACE2(nsCodebasePrincipal, nsICodebasePrincipal, nsIPrincipal) +NS_IMPL_QUERY_INTERFACE3_CI(nsCodebasePrincipal, + nsICodebasePrincipal, + nsIPrincipal, + nsISerializable) NSBASEPRINCIPALS_ADDREF(nsCodebasePrincipal); NSBASEPRINCIPALS_RELEASE(nsCodebasePrincipal); @@ -213,6 +216,31 @@ nsCodebasePrincipal::Equals(nsIPrincipal *other, PRBool *result) return NS_OK; } +////////////////////////////////////////// +// Methods implementing nsISerializable // +////////////////////////////////////////// + +NS_IMETHODIMP +nsCodebasePrincipal::Read(nsIObjectInputStream* aStream) +{ + nsresult rv; + + rv = nsBasePrincipal::Read(aStream); + if (NS_FAILED(rv)) return rv; + + return aStream->ReadObject(PR_TRUE, getter_AddRefs(mURI)); +} + +NS_IMETHODIMP +nsCodebasePrincipal::Write(nsIObjectOutputStream* aStream) +{ + nsresult rv; + + rv = nsBasePrincipal::Write(aStream); + if (NS_FAILED(rv)) return rv; + + return aStream->WriteObject(mURI, PR_TRUE); +} ///////////////////////////////////////////// // Constructor, Destructor, initialization // diff --git a/mozilla/caps/src/nsJSPrincipals.cpp b/mozilla/caps/src/nsJSPrincipals.cpp index bf70918795b..f30a4575de8 100644 --- a/mozilla/caps/src/nsJSPrincipals.cpp +++ b/mozilla/caps/src/nsJSPrincipals.cpp @@ -17,28 +17,36 @@ * Copyright (C) 1999 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): */ #include "nsCodebasePrincipal.h" #include "nsJSPrincipals.h" #include "plstr.h" #include "nsXPIDLString.h" +#include "nsCOMPtr.h" +#include "jsapi.h" +#include "jsxdrapi.h" +#include "nsIJSRuntimeService.h" +#include "nsIServiceManager.h" +#include "nsMemory.h" -JS_STATIC_DLL_CALLBACK(void *) -nsGetPrincipalArray(JSContext *cx, struct JSPrincipals *prin) +JS_STATIC_DLL_CALLBACK(void *) +nsGetPrincipalArray(JSContext *cx, struct JSPrincipals *prin) { return nsnull; } -JS_STATIC_DLL_CALLBACK(JSBool) -nsGlobalPrivilegesEnabled(JSContext *cx , struct JSPrincipals *jsprin) +JS_STATIC_DLL_CALLBACK(JSBool) +nsGlobalPrivilegesEnabled(JSContext *cx , struct JSPrincipals *jsprin) { return JS_TRUE; } JS_STATIC_DLL_CALLBACK(void) -nsDestroyJSPrincipals(JSContext *cx, struct JSPrincipals *jsprin) { - nsJSPrincipals *nsjsprin = (nsJSPrincipals *)jsprin; +nsDestroyJSPrincipals(JSContext *cx, struct JSPrincipals *jsprin) +{ + nsJSPrincipals *nsjsprin = NS_STATIC_CAST(nsJSPrincipals *, jsprin); + // We need to destroy the nsIPrincipal. We'll do this by adding // to the refcount and calling release @@ -61,6 +69,97 @@ nsDestroyJSPrincipals(JSContext *cx, struct JSPrincipals *jsprin) { // so we don't need to worry about "codebase" } +JS_STATIC_DLL_CALLBACK(JSBool) +nsDecodeJSPrincipals(JSXDRState *xdr, JSPrincipals **jsprinp) +{ + nsresult rv; + nsCOMPtr prin; + + NS_ASSERTION(JS_XDRMemDataLeft(xdr) == 0, "XDR out of sync?!"); + + nsIObjectInputStream *stream = NS_REINTERPRET_CAST(nsIObjectInputStream*, + xdr->userdata); + + rv = stream->ReadObject(PR_TRUE, getter_AddRefs(prin)); + if (NS_SUCCEEDED(rv)) { + PRUint32 size; + rv = stream->Read32(&size); + if (NS_SUCCEEDED(rv)) { + char *data = nsnull; + if (size != 0) + rv = stream->ReadBytes(&data, size); + if (NS_SUCCEEDED(rv)) { + char *olddata; + uint32 oldsize; + + // Any decode-mode JSXDRState whose userdata points to an + // nsIObjectInputStream instance must use nsMemory to allocate + // and free its data buffer. So swap the new buffer we just + // read for the old, exhausted data. + + olddata = (char*) ::JS_XDRMemGetData(xdr, &oldsize); + nsMemory::Free(olddata); + ::JS_XDRMemSetData(xdr, data, size); + } + } + } + + if (NS_FAILED(rv)) { + ::JS_ReportError(xdr->cx, "can't decode principals (failure code %x)", + (unsigned int) rv); + return JS_FALSE; + } + + prin->GetJSPrincipals(jsprinp); + return JS_TRUE; +} + +JS_STATIC_DLL_CALLBACK(JSBool) +nsEncodeJSPrincipals(JSXDRState *xdr, struct JSPrincipals *jsprin) +{ + nsresult rv; + + // Flush xdr'ed data to the underlying object output stream. + nsIObjectOutputStream *stream = NS_REINTERPRET_CAST(nsIObjectOutputStream*, + xdr->userdata); + uint32 size; + char *data = (char*) ::JS_XDRMemGetData(xdr, &size); + + rv = stream->Write32(size); + if (NS_SUCCEEDED(rv)) + rv = stream->WriteBytes(data, size); + if (NS_FAILED(rv)) return rv; + + ::JS_XDRMemResetData(xdr); + + // Require that GetJSPrincipals has been called already by the code that + // compiled the script that owns this principals instance. + nsJSPrincipals *nsjsprin = NS_STATIC_CAST(nsJSPrincipals *, jsprin); + nsCOMPtr prin = nsjsprin->nsIPrincipalPtr; + + rv = stream->WriteObject(prin, PR_TRUE); + return NS_SUCCEEDED(rv); // NB: guaranteed to be 0 or 1 +} + +nsresult +nsJSPrincipals::Startup() +{ + static const char rtsvc_id[] = "@mozilla.org/js/xpc/RuntimeService;1"; + nsCOMPtr rtsvc(do_GetService(rtsvc_id)); + if (!rtsvc) + return NS_ERROR_FAILURE; + + JSRuntime *rt; + rtsvc->GetRuntime(&rt); + NS_ASSERTION(rt != nsnull, "no JSRuntime?!"); + + JSPrincipalsDecoder oldpd; + oldpd = ::JS_SetPrincipalsDecoder(rt, nsDecodeJSPrincipals); + NS_ASSERTION(oldpd == nsnull, "oops, JS_SetPrincipalsDecoder wars!"); + + return NS_OK; +} + nsJSPrincipals::nsJSPrincipals() { codebase = nsnull; @@ -68,20 +167,19 @@ nsJSPrincipals::nsJSPrincipals() globalPrivilegesEnabled = nsGlobalPrivilegesEnabled; refcount = 0; destroy = nsDestroyJSPrincipals; + encode = nsEncodeJSPrincipals; nsIPrincipalPtr = nsnull; } nsresult -nsJSPrincipals::Init(char *aCodebase) +nsJSPrincipals::Init(char *aCodebase) { codebase = aCodebase; return NS_OK; } -nsJSPrincipals::~nsJSPrincipals() +nsJSPrincipals::~nsJSPrincipals() { if (codebase) - PL_strfree(codebase); + PL_strfree(codebase); } - - diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index de43fc3169e..b1dae6284af 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -17,7 +17,7 @@ * Copyright (C) 1998-2000 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): * Norris Boyd * Mitch Stoltz * Steve Morse @@ -69,7 +69,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_CID(kPrefServiceCID, NS_PREFSERVICE_CID); -static NS_DEFINE_CID(kCScriptNameSetRegistryCID, +static NS_DEFINE_CID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID); static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID); @@ -174,7 +174,7 @@ nsScriptSecurityManager::CheckPropertyAccessImpl(PRUint32 aAction, JSContext* aJSContext, JSObject* aJSObject, nsISupports* aObj, nsIURI* aTargetURI, nsIClassInfo* aClassInfo, - jsval aName, const char* aClassName, + jsval aName, const char* aClassName, const char* aProperty, void** aPolicy) { nsCOMPtr subjectPrincipal; @@ -183,7 +183,7 @@ nsScriptSecurityManager::CheckPropertyAccessImpl(PRUint32 aAction, PRBool equals; if (!subjectPrincipal || - NS_SUCCEEDED(subjectPrincipal->Equals(mSystemPrincipal, &equals)) && equals) + NS_SUCCEEDED(subjectPrincipal->Equals(mSystemPrincipal, &equals)) && equals) // We have native code or the system principal: just allow access return NS_OK; @@ -264,7 +264,7 @@ nsScriptSecurityManager::CheckPropertyAccessImpl(PRUint32 aAction, nsCOMPtr objectPrincipal; if(aJSObject) { - if (NS_FAILED(GetObjectPrincipal(aJSContext, + if (NS_FAILED(GetObjectPrincipal(aJSContext, NS_REINTERPRET_CAST(JSObject*, aJSObject), getter_AddRefs(objectPrincipal)))) return NS_ERROR_FAILURE; @@ -362,7 +362,7 @@ nsScriptSecurityManager::CheckPropertyAccessImpl(PRUint32 aAction, } nsresult -nsScriptSecurityManager::CheckSameOrigin(JSContext *aCx, nsIPrincipal* aSubject, +nsScriptSecurityManager::CheckSameOrigin(JSContext *aCx, nsIPrincipal* aSubject, nsIPrincipal* aObject, PRUint32 aAction) { /* @@ -374,7 +374,7 @@ nsScriptSecurityManager::CheckSameOrigin(JSContext *aCx, nsIPrincipal* aSubject, PRBool isSameOrigin = PR_FALSE; if (NS_FAILED(aSubject->Equals(aObject, &isSameOrigin))) return NS_ERROR_FAILURE; - + if (isSameOrigin) return NS_OK; @@ -408,7 +408,7 @@ nsScriptSecurityManager::CheckSameOrigin(JSContext *aCx, nsIPrincipal* aSubject, return NS_ERROR_DOM_PROP_ACCESS_DENIED; } -PRBool +PRBool nsScriptSecurityManager::IsDOMClass(nsIClassInfo* aClassInfo) { if (!aClassInfo) @@ -418,7 +418,7 @@ nsScriptSecurityManager::IsDOMClass(nsIClassInfo* aClassInfo) return NS_SUCCEEDED(rv) && (classFlags & nsIClassInfo::DOM_OBJECT); } -PRInt32 +PRInt32 nsScriptSecurityManager::GetSecurityLevel(JSContext* aJSContext, nsIPrincipal *principal, PRBool aIsDOM, @@ -463,7 +463,7 @@ nsScriptSecurityManager::GetSecurityLevel(JSContext* aJSContext, rv = mSecurityPrefs->SecurityGetCharPref(prefName, &secLevelString); } } - if (NS_SUCCEEDED(rv) && secLevelString) + if (NS_SUCCEEDED(rv) && secLevelString) { if (PL_strcmp(secLevelString, "sameOrigin") == 0) secLevel = SCRIPT_SECURITY_SAME_ORIGIN_ACCESS; @@ -471,7 +471,7 @@ nsScriptSecurityManager::GetSecurityLevel(JSContext* aJSContext, secLevel = SCRIPT_SECURITY_ALL_ACCESS; else if (PL_strcmp(secLevelString, "noAccess") == 0) secLevel = SCRIPT_SECURITY_NO_ACCESS; - else + else { // string should be the name of a capability capability = secLevelString; @@ -488,7 +488,7 @@ nsScriptSecurityManager::GetSecurityLevel(JSContext* aJSContext, if(aIsDOM) secLevel = SCRIPT_SECURITY_SAME_ORIGIN_ACCESS; if (!classPolicy && aPolicy) - //-- If there's no stored policy for this property, + //-- If there's no stored policy for this property, // we can annotate the class's aPolicy field and avoid checking // policy prefs next time. *aPolicy = (void*)secLevel; @@ -499,7 +499,7 @@ nsScriptSecurityManager::GetSecurityLevel(JSContext* aJSContext, struct nsDomainEntry { nsDomainEntry(const char *anOrigin, const char *aPolicy, - int aPolicyLength) + int aPolicyLength) : mNext(nsnull), mOrigin(anOrigin), mPolicy(aPolicy, aPolicyLength) { } PRBool Matches(const char *anOrigin) @@ -610,7 +610,7 @@ nsScriptSecurityManager::CheckLoadURIFromScript(JSContext *cx, nsIURI *aURI) return NS_ERROR_FAILURE; // Native code can load all URIs. - if (!principal) + if (!principal) return NS_OK; // The system principal can load all URIs. @@ -623,19 +623,19 @@ nsScriptSecurityManager::CheckLoadURIFromScript(JSContext *cx, nsIURI *aURI) // Otherwise, principal should have a codebase that we can use to // do the remaining tests. nsCOMPtr codebase = do_QueryInterface(principal); - if (!codebase) + if (!codebase) return NS_ERROR_FAILURE; nsCOMPtr uri; - if (NS_FAILED(codebase->GetURI(getter_AddRefs(uri)))) + if (NS_FAILED(codebase->GetURI(getter_AddRefs(uri)))) return NS_ERROR_FAILURE; if (NS_SUCCEEDED(CheckLoadURI(uri, aURI, nsIScriptSecurityManager::STANDARD ))) return NS_OK; - // See if we're attempting to load a file: URI. If so, let a + // See if we're attempting to load a file: URI. If so, let a // UniversalFileRead capability trump the above check. PRBool isFile = PR_FALSE; PRBool isRes = PR_FALSE; - if (NS_FAILED(aURI->SchemeIs("file", &isFile)) || + if (NS_FAILED(aURI->SchemeIs("file", &isFile)) || NS_FAILED(aURI->SchemeIs("resource", &isRes))) return NS_ERROR_FAILURE; if (isFile || isRes) @@ -670,7 +670,7 @@ nsScriptSecurityManager::CheckLoadURI(nsIURI *aSourceURI, nsIURI *aTargetURI, return NS_ERROR_FAILURE; // Some loads are not allowed from mail/news messages - if ((aFlags & nsIScriptSecurityManager::DISALLOW_FROM_MAIL) && + if ((aFlags & nsIScriptSecurityManager::DISALLOW_FROM_MAIL) && (nsCRT::strcasecmp(sourceScheme, "mailbox") == 0 || nsCRT::strcasecmp(sourceScheme, "imap") == 0 || nsCRT::strcasecmp(sourceScheme, "news") == 0)) @@ -686,7 +686,7 @@ nsScriptSecurityManager::CheckLoadURI(nsIURI *aSourceURI, nsIURI *aTargetURI, nsXPIDLCString targetScheme; if (NS_FAILED(targetUri->GetScheme(getter_Copies(targetScheme)))) return NS_ERROR_FAILURE; - + if (nsCRT::strcasecmp(targetScheme, sourceScheme) == 0) { // every scheme can access another URI from the same scheme @@ -694,7 +694,7 @@ nsScriptSecurityManager::CheckLoadURI(nsIURI *aSourceURI, nsIURI *aTargetURI, } enum Action { AllowProtocol, DenyProtocol, PrefControlled, ChromeProtocol, AboutProtocol }; - static const struct { + static const struct { const char *name; Action action; } protocolList[] = { @@ -749,7 +749,7 @@ nsScriptSecurityManager::CheckLoadURI(nsIURI *aSourceURI, nsIURI *aTargetURI, if(NS_FAILED(targetUri->GetSpec(getter_Copies(targetSpec)))) return NS_ERROR_FAILURE; targetPage = targetSpec.get() + sizeof("about:") - 1; - return (PL_strcmp(targetPage, "blank") == 0) || + return (PL_strcmp(targetPage, "blank") == 0) || (PL_strcmp(targetPage, "") == 0) || (PL_strcmp(targetPage, "mozilla") == 0) || (PL_strcmp(targetPage, "credits") == 0) ? @@ -769,7 +769,7 @@ nsScriptSecurityManager::CheckLoadURI(nsIURI *aSourceURI, nsIURI *aTargetURI, return NS_OK; } -nsresult +nsresult nsScriptSecurityManager::ReportErrorToConsole(nsIURI* aTarget) { nsXPIDLCString spec; @@ -816,12 +816,12 @@ nsScriptSecurityManager::CheckLoadURIStr(const char* aSourceURIStr, const char* } NS_IMETHODIMP -nsScriptSecurityManager::CheckFunctionAccess(JSContext *aCx, void *aFunObj, +nsScriptSecurityManager::CheckFunctionAccess(JSContext *aCx, void *aFunObj, void *aTargetObj) { //-- This check is called for event handlers nsCOMPtr subject; - nsresult rv = GetFunctionObjectPrincipal(aCx, (JSObject *)aFunObj, + nsresult rv = GetFunctionObjectPrincipal(aCx, (JSObject *)aFunObj, getter_AddRefs(subject)); //-- If subject is null, get a principal from the function object's scope. if (NS_SUCCEEDED(rv) && !subject) @@ -832,7 +832,7 @@ nsScriptSecurityManager::CheckFunctionAccess(JSContext *aCx, void *aFunObj, PRBool isSystem; - if (NS_SUCCEEDED(subject->Equals(mSystemPrincipal, &isSystem)) && isSystem) + if (NS_SUCCEEDED(subject->Equals(mSystemPrincipal, &isSystem)) && isSystem) // This is the system principal: just allow access return NS_OK; @@ -843,7 +843,7 @@ nsScriptSecurityManager::CheckFunctionAccess(JSContext *aCx, void *aFunObj, rv = CanExecuteScripts(aCx, subject, &result); if (NS_FAILED(rv)) return rv; - + if (!result) return NS_ERROR_DOM_SECURITY_ERR; @@ -948,7 +948,7 @@ nsScriptSecurityManager::CanExecuteScripts(JSContext* cx, return NS_OK; } -///////////////// Principals /////////////////////// +///////////////// Principals /////////////////////// NS_IMETHODIMP nsScriptSecurityManager::GetSubjectPrincipal(nsIPrincipal **result) { @@ -1000,7 +1000,7 @@ nsScriptSecurityManager::GetCertificatePrincipal(const char* aCertID, // Check to see if we already have this principal. nsIPrincipalKey key(principal); nsCOMPtr fromTable = (nsIPrincipal *) mPrincipals->Get(&key); - if (fromTable) + if (fromTable) principal = fromTable; } @@ -1049,7 +1049,7 @@ nsScriptSecurityManager::GetCodebasePrincipal(nsIURI *aURI, //-- Check to see if we already have this principal. nsIPrincipalKey key(principal); nsCOMPtr fromTable = (nsIPrincipal *) mPrincipals->Get(&key); - if (fromTable) + if (fromTable) principal = fromTable; else //-- Check to see if we have a more general principal { @@ -1065,7 +1065,7 @@ nsScriptSecurityManager::GetCodebasePrincipal(nsIURI *aURI, if (NS_FAILED(rv)) return rv; nsIPrincipalKey key2(principal2); fromTable = (nsIPrincipal *) mPrincipals->Get(&key2); - if (fromTable) + if (fromTable) principal = fromTable; } } @@ -1084,9 +1084,9 @@ nsScriptSecurityManager::GetCodebasePrincipal(nsIURI *aURI, } nsresult -nsScriptSecurityManager::GetScriptPrincipal(JSContext *cx, +nsScriptSecurityManager::GetScriptPrincipal(JSContext *cx, JSScript *script, - nsIPrincipal **result) + nsIPrincipal **result) { if (!script) { @@ -1108,9 +1108,9 @@ nsScriptSecurityManager::GetScriptPrincipal(JSContext *cx, } nsresult -nsScriptSecurityManager::GetFunctionObjectPrincipal(JSContext *cx, +nsScriptSecurityManager::GetFunctionObjectPrincipal(JSContext *cx, JSObject *obj, - nsIPrincipal **result) + nsIPrincipal **result) { JSFunction *fun = (JSFunction *) JS_GetPrivate(cx, obj); JSScript *script = JS_GetFunctionScript(cx, fun); @@ -1135,9 +1135,9 @@ nsScriptSecurityManager::GetFunctionObjectPrincipal(JSContext *cx, } nsresult -nsScriptSecurityManager::GetFramePrincipal(JSContext *cx, +nsScriptSecurityManager::GetFramePrincipal(JSContext *cx, JSStackFrame *fp, - nsIPrincipal **result) + nsIPrincipal **result) { JSObject *obj = JS_GetFrameFunctionObject(cx, fp); if (!obj) @@ -1145,14 +1145,14 @@ nsScriptSecurityManager::GetFramePrincipal(JSContext *cx, // Must be in a top-level script. Get principal from the script. JSScript *script = JS_GetFrameScript(cx, fp); return GetScriptPrincipal(cx, script, result); - } + } return GetFunctionObjectPrincipal(cx, obj, result); } nsresult nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx, - nsIPrincipal **result, - JSStackFrame **frameResult) + nsIPrincipal **result, + JSStackFrame **frameResult) { // Get principals from innermost frame of JavaScript or Java. JSStackFrame *fp = nsnull; // tell JS_FrameIterator to start at innermost @@ -1169,9 +1169,9 @@ nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx, //-- If there's no principal on the stack, look at the global object // and return the innermost frame for annotations. - if (cx) + if (cx) { - nsCOMPtr scriptContext = + nsCOMPtr scriptContext = NS_REINTERPRET_CAST(nsIScriptContext*,JS_GetContextPrivate(cx)); if (scriptContext) { @@ -1188,14 +1188,14 @@ nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx, return NS_OK; } } - } + } *result = nsnull; return NS_OK; } nsresult -nsScriptSecurityManager::GetSubjectPrincipal(JSContext *cx, +nsScriptSecurityManager::GetSubjectPrincipal(JSContext *cx, nsIPrincipal **result) { JSStackFrame *fp; @@ -1210,13 +1210,13 @@ nsScriptSecurityManager::GetObjectPrincipal(JSContext *aCx, JSObject *aObj, do { JSClass *jsClass = JS_GetClass(aCx, parent); - const uint32 privateNsISupports = JSCLASS_HAS_PRIVATE | + const uint32 privateNsISupports = JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS; - if (jsClass && (jsClass->flags & (privateNsISupports)) == + if (jsClass && (jsClass->flags & (privateNsISupports)) == privateNsISupports) { nsCOMPtr supports = (nsISupports *) JS_GetPrivate(aCx, parent); - nsCOMPtr objPrin = + nsCOMPtr objPrin = do_QueryInterface(supports); if (!objPrin) { @@ -1224,7 +1224,7 @@ nsScriptSecurityManager::GetObjectPrincipal(JSContext *aCx, JSObject *aObj, * If it's a wrapped native, check the underlying native * instead. */ - nsCOMPtr xpcNative = + nsCOMPtr xpcNative = do_QueryInterface(supports); if (xpcNative) xpcNative->GetNative(getter_AddRefs(supports)); @@ -1253,7 +1253,7 @@ nsScriptSecurityManager::SavePrincipal(nsIPrincipal* aToSave) return NS_ERROR_FAILURE; //-- Save to mPrincipals - if (!mPrincipals) + if (!mPrincipals) { mPrincipals = new nsSupportsHashtable(31); if (!mPrincipals) @@ -1275,8 +1275,8 @@ nsScriptSecurityManager::SavePrincipal(nsIPrincipal* aToSave) nsXPIDLCString grantedPrefName; nsXPIDLCString deniedPrefName; - rv = PrincipalPrefNames( idPrefName, - getter_Copies(grantedPrefName), + rv = PrincipalPrefNames( idPrefName, + getter_Copies(grantedPrefName), getter_Copies(deniedPrefName) ); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; @@ -1334,7 +1334,7 @@ nsScriptSecurityManager::IsCapabilityEnabled(const char *capability, else previousPrincipal = principal; - // First check if the principal is even able to enable the + // First check if the principal is even able to enable the // given capability. If not, don't look any further. PRInt16 canEnable; rv = principal->CanEnableCapability(capability, &canEnable); @@ -1356,10 +1356,10 @@ nsScriptSecurityManager::IsCapabilityEnabled(const char *capability, #define PROPERTIES_URL "chrome://communicator/locale/security/security.properties" nsresult -Localize(char *genericString, nsString &result) +Localize(char *genericString, nsString &result) { nsresult ret; - + /* create a URL for the string resource file */ nsIIOService *pNetService = nsnull; ret = nsServiceManager::GetService(kIOServiceCID, kIIOServiceIID, @@ -1377,17 +1377,17 @@ Localize(char *genericString, nsString &result) nsServiceManager::ReleaseService(kIOServiceCID, pNetService); return ret; } - + nsIURI *url = nsnull; ret = uri->QueryInterface(NS_GET_IID(nsIURI), (void**)&url); nsServiceManager::ReleaseService(kIOServiceCID, pNetService); - + if (NS_FAILED(ret)) { NS_WARNING("cannot create URL\n"); return ret; } - + /* create a bundle for the localization */ nsIStringBundleService *pStringService = nsnull; ret = nsServiceManager::GetService(kStringBundleServiceCID, @@ -1415,7 +1415,7 @@ Localize(char *genericString, nsString &result) NS_WARNING("cannot create instance\n"); return ret; } - + /* localize the given string */ nsAutoString strtmp; strtmp.AssignWithConversion(genericString); @@ -1432,7 +1432,7 @@ Localize(char *genericString, nsString &result) static PRBool CheckConfirmDialog(JSContext* cx, const PRUnichar *szMessage, const PRUnichar *szCheckMessage, - PRBool *checkValue) + PRBool *checkValue) { nsresult res; //-- Get a prompter for the current window. @@ -1460,7 +1460,7 @@ CheckConfirmDialog(JSContext* cx, const PRUnichar *szMessage, const PRUnichar *s *checkValue = 0; return PR_FALSE; } - + PRInt32 buttonPressed = 1; /* in case user exits dialog by clicking X */ nsAutoString dialogTitle; if (NS_FAILED(res = Localize("Titleline", dialogTitle))) @@ -1470,7 +1470,7 @@ CheckConfirmDialog(JSContext* cx, const PRUnichar *szMessage, const PRUnichar *s (nsIPrompt::BUTTON_TITLE_YES * nsIPrompt::BUTTON_POS_0) + (nsIPrompt::BUTTON_TITLE_NO * nsIPrompt::BUTTON_POS_1), nsnull, nsnull, nsnull, szCheckMessage, checkValue, &buttonPressed); - + if (NS_FAILED(res)) *checkValue = 0; if (*checkValue != 0 && *checkValue != 1) @@ -1479,7 +1479,7 @@ CheckConfirmDialog(JSContext* cx, const PRUnichar *szMessage, const PRUnichar *s } NS_IMETHODIMP -nsScriptSecurityManager::RequestCapability(nsIPrincipal* aPrincipal, +nsScriptSecurityManager::RequestCapability(nsIPrincipal* aPrincipal, const char *capability, PRInt16* canEnable) { if (NS_FAILED(aPrincipal->CanEnableCapability(capability, canEnable))) @@ -1529,13 +1529,13 @@ nsScriptSecurityManager::EnableCapability(const char *capability) JS_SetPendingException(cx, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, msg))); return NS_ERROR_FAILURE; } - + nsCOMPtr principal; if (NS_FAILED(GetPrincipalAndFrame(cx, getter_AddRefs(principal), &fp))) return NS_ERROR_FAILURE; void *annotation = JS_GetFrameAnnotation(cx, fp); PRBool enabled; - if (NS_FAILED(principal->IsCapabilityEnabled(capability, annotation, + if (NS_FAILED(principal->IsCapabilityEnabled(capability, annotation, &enabled))) return NS_ERROR_FAILURE; if (enabled) @@ -1544,14 +1544,14 @@ nsScriptSecurityManager::EnableCapability(const char *capability) PRInt16 canEnable; if (NS_FAILED(RequestCapability(principal, capability, &canEnable))) return NS_ERROR_FAILURE; - + if (canEnable != nsIPrincipal::ENABLE_GRANTED) { static const char msg[] = "enablePrivilege not granted"; JS_SetPendingException(cx, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, msg))); return NS_ERROR_FAILURE; // XXX better error code? } - if (NS_FAILED(principal->EnableCapability(capability, &annotation))) + if (NS_FAILED(principal->EnableCapability(capability, &annotation))) return NS_ERROR_FAILURE; JS_SetFrameAnnotation(cx, fp, annotation); return NS_OK; @@ -1587,7 +1587,7 @@ nsScriptSecurityManager::DisableCapability(const char *capability) //////////////// Master Certificate Functions /////////////////////////////////////// NS_IMETHODIMP -nsScriptSecurityManager::SetCanEnableCapability(const char* certificateID, +nsScriptSecurityManager::SetCanEnableCapability(const char* certificateID, const char* capability, PRInt16 canEnable) { @@ -1603,7 +1603,7 @@ nsScriptSecurityManager::SetCanEnableCapability(const char* certificateID, nsCOMPtr directoryService = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); if (!directoryService) return NS_ERROR_FAILURE; - rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), + rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(systemCertFile)); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; #ifdef XP_MAC @@ -1614,7 +1614,7 @@ nsScriptSecurityManager::SetCanEnableCapability(const char* certificateID, systemCertFile->Append("systemSignature.jar"); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; nsCOMPtr systemCertZip; - rv = nsComponentManager::CreateInstance(kZipReaderCID, nsnull, + rv = nsComponentManager::CreateInstance(kZipReaderCID, nsnull, NS_GET_IID(nsIZipReader), getter_AddRefs(systemCertZip)); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; @@ -1624,7 +1624,7 @@ nsScriptSecurityManager::SetCanEnableCapability(const char* certificateID, { nsCOMPtr systemCertJar = do_QueryInterface(systemCertZip, &rv); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - rv = systemCertJar->GetCertificatePrincipal(nsnull, + rv = systemCertJar->GetCertificatePrincipal(nsnull, getter_AddRefs(mSystemCertificate)); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; } @@ -1643,7 +1643,7 @@ nsScriptSecurityManager::SetCanEnableCapability(const char* certificateID, if (!cx) return NS_ERROR_FAILURE; static const char msg1[] = "Only code signed by the system certificate may call SetCanEnableCapability or Invalidate"; static const char msg2[] = "Attempt to call SetCanEnableCapability or Invalidate when no system certificate has been established"; - JS_SetPendingException(cx, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, + JS_SetPendingException(cx, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, mSystemCertificate ? msg1 : msg2))); return NS_ERROR_FAILURE; } @@ -1662,8 +1662,8 @@ nsScriptSecurityManager::SetCanEnableCapability(const char* certificateID, //////////////////////////////////////////////// NS_IMETHODIMP -nsScriptSecurityManager::CanCreateWrapper(JSContext *aJSContext, - const nsIID &aIID, +nsScriptSecurityManager::CanCreateWrapper(JSContext *aJSContext, + const nsIID &aIID, nsISupports *aObj, nsIClassInfo *aClassInfo, void **aPolicy) @@ -1711,7 +1711,7 @@ nsScriptSecurityManager::CanCreateInstance(JSContext *aJSContext, } NS_IMETHODIMP -nsScriptSecurityManager::CanGetService(JSContext *aJSContext, +nsScriptSecurityManager::CanGetService(JSContext *aJSContext, const nsCID &aCID) { #if 0 @@ -1725,7 +1725,7 @@ nsScriptSecurityManager::CanGetService(JSContext *aJSContext, } /* void CanAccess (in PRUint32 aAction, in nsIXPCNativeCallContext aCallContext, in JSContextPtr aJSContext, in JSObjectPtr aJSObject, in nsISupports aObj, in nsIClassInfo aClassInfo, in JSVal aName, inout voidPtr aPolicy); */ -NS_IMETHODIMP +NS_IMETHODIMP nsScriptSecurityManager::CanAccess(PRUint32 aAction, nsIXPCNativeCallContext* aCallContext, JSContext* aJSContext, @@ -1765,7 +1765,7 @@ nsScriptSecurityManager::CheckXPCPermissions(JSContext *aJSContext, } } - //-- If user allows scripting of plugins by untrusted scripts, + //-- If user allows scripting of plugins by untrusted scripts, // and the target object is a plugin, allow the access. if(aObj) { @@ -1787,7 +1787,7 @@ nsScriptSecurityManager::CheckXPCPermissions(JSContext *aJSContext, } //-- Access tests failed, so report error - JS_SetPendingException(aJSContext, + JS_SetPendingException(aJSContext, STRING_TO_JSVAL(JS_NewStringCopyZ(aJSContext, aErrorMsg))); return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED; } @@ -1832,7 +1832,7 @@ nsScriptSecurityManager::Observe(nsISupports* aObject, const PRUnichar* aAction, nsScriptSecurityManager::nsScriptSecurityManager(void) : mOriginToPolicyMap(nsnull), mClassPolicies(nsnull), - mSystemPrincipal(nsnull), mPrincipals(nsnull), + mSystemPrincipal(nsnull), mPrincipals(nsnull), mIsJavaScriptEnabled(PR_FALSE), mIsMailJavaScriptEnabled(PR_FALSE), mIsWritingPrefs(PR_FALSE), @@ -1850,7 +1850,7 @@ nsScriptSecurityManager::~nsScriptSecurityManager(void) delete mClassPolicies; NS_IF_RELEASE(mSystemPrincipal); delete mPrincipals; -} +} nsScriptSecurityManager * nsScriptSecurityManager::GetScriptSecurityManager() @@ -1863,22 +1863,26 @@ nsScriptSecurityManager::GetScriptSecurityManager() return NULL; nsresult rv; + rv = nsJSPrincipals::Startup(); + if (NS_FAILED(rv)) + NS_WARNING("can't initialize JS engine security protocol glue!"); + nsCOMPtr xpc = do_GetService(nsIXPConnect::GetCID(), &rv); if (NS_SUCCEEDED(rv) && xpc) { rv = xpc->SetDefaultSecurityManager( - NS_STATIC_CAST(nsIXPCSecurityManager*, ssecMan), + NS_STATIC_CAST(nsIXPCSecurityManager*, ssecMan), nsIXPCSecurityManager::HOOK_ALL); if (NS_FAILED(rv)) - NS_WARNING("failed to install xpconnect security manager!"); + NS_WARNING("failed to install xpconnect security manager!"); #ifdef DEBUG_jband else printf("!!!!! xpc security manager registered\n"); #endif } else - NS_WARNING("can't get xpconnect to install security manager!"); + NS_WARNING("can't get xpconnect to install security manager!"); } return ssecMan; } @@ -1933,7 +1937,7 @@ nsScriptSecurityManager::InitPolicies(PRUint32 aPrefCount, const char** aPrefNam { if (!mOriginToPolicyMap) { - mOriginToPolicyMap = + mOriginToPolicyMap = new nsObjectHashtable(nsnull, nsnull, DeleteEntry, nsnull); if (!mOriginToPolicyMap) return NS_ERROR_OUT_OF_MEMORY; @@ -1953,11 +1957,11 @@ nsScriptSecurityManager::InitPolicies(PRUint32 aPrefCount, const char** aPrefNam working = (*r != '\0'); *r = '\0'; nsCStringKey key(nextToLastDot ? nextToLastDot+1 : q); - nsDomainEntry *value = new nsDomainEntry(q, policyName, + nsDomainEntry *value = new nsDomainEntry(q, policyName, policyLength); if (!value) break; - nsDomainEntry *de = (nsDomainEntry *) + nsDomainEntry *de = (nsDomainEntry *) mOriginToPolicyMap->Get(&key); if (!de) mOriginToPolicyMap->Put(&key, value); @@ -2006,7 +2010,7 @@ nsScriptSecurityManager::InitPolicies(PRUint32 aPrefCount, const char** aPrefNam nsCStringKey classNameKey(dots[2] + 1); if (!(mClassPolicies)) mClassPolicies = new nsHashtable(31); - // We don't actually have to store the class name as data in the hashtable, + // We don't actually have to store the class name as data in the hashtable, // since all we check for is whether the key exists. void* classPolicy = mClassPolicies->Get(&classNameKey); if (isDefault && !classPolicy) @@ -2019,7 +2023,7 @@ nsScriptSecurityManager::InitPolicies(PRUint32 aPrefCount, const char** aPrefNam } nsresult -nsScriptSecurityManager::PrincipalPrefNames(const char* pref, +nsScriptSecurityManager::PrincipalPrefNames(const char* pref, char** grantedPref, char** deniedPref) { char* lastDot = PL_strrchr(pref, '.'); @@ -2055,7 +2059,7 @@ nsScriptSecurityManager::InitPrincipals(PRUint32 aPrefCount, const char** aPrefN * capability.principal.[codebase|certificate]..[id|granted|denied] * For example: * user_pref("capability.principal.certificate.p1.id","12:34:AB:CD"); - * user_pref("capability.principal.certificate.p1.granted","Capability1 Capability2"); + * user_pref("capability.principal.certificate.p1.granted","Capability1 Capability2"); * user_pref("capability.principal.certificate.p1.denied","Capability3"); */ @@ -2067,13 +2071,13 @@ nsScriptSecurityManager::InitPrincipals(PRUint32 aPrefCount, const char** aPrefN continue; char* id; - if (NS_FAILED(mSecurityPrefs->SecurityGetCharPref(aPrefNames[c], &id))) + if (NS_FAILED(mSecurityPrefs->SecurityGetCharPref(aPrefNames[c], &id))) return NS_ERROR_FAILURE; nsXPIDLCString grantedPrefName; nsXPIDLCString deniedPrefName; - nsresult rv = PrincipalPrefNames(aPrefNames[c], - getter_Copies(grantedPrefName), + nsresult rv = PrincipalPrefNames(aPrefNames[c], + getter_Copies(grantedPrefName), getter_Copies(deniedPrefName)); if (rv == NS_ERROR_OUT_OF_MEMORY) return rv; @@ -2086,7 +2090,7 @@ nsScriptSecurityManager::InitPrincipals(PRUint32 aPrefCount, const char** aPrefN mSecurityPrefs->SecurityGetCharPref(deniedPrefName, &deniedList); //-- Delete prefs if their value is the empty string - if ((!id || id[0] == '\0') || + if ((!id || id[0] == '\0') || ((!grantedList || grantedList[0] == '\0') && (!deniedList || deniedList[0] == '\0'))) { mSecurityPrefs->SecurityClearUserPref(aPrefNames[c]); @@ -2101,32 +2105,32 @@ nsScriptSecurityManager::InitPrincipals(PRUint32 aPrefCount, const char** aPrefN static const char certificateName[] = "capability.principal.certificate"; static const char codebaseName[] = "capability.principal.codebase"; nsCOMPtr principal; - if (PL_strncmp(aPrefNames[c], certificateName, - sizeof(certificateName)-1) == 0) + if (PL_strncmp(aPrefNames[c], certificateName, + sizeof(certificateName)-1) == 0) { nsCertificatePrincipal *certificate = new nsCertificatePrincipal(); if (certificate) { NS_ADDREF(certificate); - if (NS_SUCCEEDED(certificate->InitFromPersistent(aPrefNames[c], id, - grantedList, deniedList))) + if (NS_SUCCEEDED(certificate->InitFromPersistent(aPrefNames[c], id, + grantedList, deniedList))) principal = do_QueryInterface((nsBasePrincipal*)certificate); NS_RELEASE(certificate); } - } else if(PL_strncmp(aPrefNames[c], codebaseName, - sizeof(codebaseName)-1) == 0) + } else if(PL_strncmp(aPrefNames[c], codebaseName, + sizeof(codebaseName)-1) == 0) { nsCodebasePrincipal *codebase = new nsCodebasePrincipal(); if (codebase) { NS_ADDREF(codebase); - if (NS_SUCCEEDED(codebase->InitFromPersistent(aPrefNames[c], id, - grantedList, deniedList))) + if (NS_SUCCEEDED(codebase->InitFromPersistent(aPrefNames[c], id, + grantedList, deniedList))) principal = do_QueryInterface((nsBasePrincipal*)codebase); NS_RELEASE(codebase); } } PR_FREEIF(grantedList); PR_FREEIF(deniedList); - + if (principal) { if (!mPrincipals) @@ -2146,13 +2150,13 @@ nsScriptSecurityManager::InitPrincipals(PRUint32 aPrefCount, const char** aPrefN inline void nsScriptSecurityManager::JSEnabledPrefChanged() { - if (NS_FAILED(mPrefs->GetBoolPref(sJSEnabledPrefName, + if (NS_FAILED(mPrefs->GetBoolPref(sJSEnabledPrefName, &mIsJavaScriptEnabled))) // Default to enabled. mIsJavaScriptEnabled = PR_TRUE; - if (NS_FAILED(mPrefs->GetBoolPref(sJSMailEnabledPrefName, - &mIsMailJavaScriptEnabled))) + if (NS_FAILED(mPrefs->GetBoolPref(sJSMailEnabledPrefName, + &mIsMailJavaScriptEnabled))) // Default to enabled. mIsMailJavaScriptEnabled = PR_TRUE; } diff --git a/mozilla/caps/src/nsSecurityManagerFactory.cpp b/mozilla/caps/src/nsSecurityManagerFactory.cpp index f667d253357..7183b26e588 100644 --- a/mozilla/caps/src/nsSecurityManagerFactory.cpp +++ b/mozilla/caps/src/nsSecurityManagerFactory.cpp @@ -27,7 +27,10 @@ #include "nsIScriptSecurityManager.h" #include "nsScriptSecurityManager.h" #include "nsIPrincipal.h" +#include "nsAggregatePrincipal.h" +#include "nsCertificatePrincipal.h" #include "nsCodebasePrincipal.h" +#include "nsSystemPrincipal.h" #include "nsIScriptNameSpaceManager.h" #include "nsIScriptExternalNameSet.h" #include "nsIScriptContext.h" @@ -74,6 +77,7 @@ getStringArgument(JSContext *cx, JSObject *obj, PRUint16 argNum, uintN argc, jsv JS_ReportError(cx, "String argument expected"); return nsnull; } + /* * We don't want to use JS_ValueToString because we want to be able * to have an object to represent a target in subsequent versions. @@ -96,13 +100,8 @@ netscape_security_isPrivilegeEnabled(JSContext *cx, JSObject *obj, uintN argc, nsCOMPtr securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { - - - // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - - rv = securityManager->IsCapabilityEnabled(cap, &result); if (NS_FAILED(rv)) result = JS_FALSE; @@ -120,21 +119,17 @@ netscape_security_enablePrivilege(JSContext *cx, JSObject *obj, uintN argc, char *cap = getStringArgument(cx, obj, 0, argc, argv); if (!cap) return JS_FALSE; + nsresult rv; nsCOMPtr securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return JS_FALSE; - - - // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - - - - if (NS_FAILED(securityManager->EnableCapability(cap))) + rv = securityManager->EnableCapability(cap); + if (NS_FAILED(rv)) return JS_FALSE; return JS_TRUE; } @@ -146,22 +141,17 @@ netscape_security_disablePrivilege(JSContext *cx, JSObject *obj, uintN argc, char *cap = getStringArgument(cx, obj, 0, argc, argv); if (!cap) return JS_FALSE; + nsresult rv; nsCOMPtr securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return JS_FALSE; - - - // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - - - - - if (NS_FAILED(securityManager->DisableCapability(cap))) + rv = securityManager->DisableCapability(cap); + if (NS_FAILED(rv)) return JS_FALSE; return JS_TRUE; } @@ -173,20 +163,17 @@ netscape_security_revertPrivilege(JSContext *cx, JSObject *obj, uintN argc, char *cap = getStringArgument(cx, obj, 0, argc, argv); if (!cap) return JS_FALSE; + nsresult rv; nsCOMPtr securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return JS_FALSE; - - // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - - - - if (NS_FAILED(securityManager->RevertCapability(cap))) + rv = securityManager->RevertCapability(cap); + if (NS_FAILED(rv)) return JS_FALSE; return JS_TRUE; } @@ -200,22 +187,18 @@ netscape_security_setCanEnablePrivilege(JSContext *cx, JSObject *obj, uintN argc char *cap = getStringArgument(cx, obj, 1, argc, argv); if (!principalID || !cap) return JS_FALSE; + nsresult rv; nsCOMPtr securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return JS_FALSE; - - - // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - - - - if (NS_FAILED(securityManager->SetCanEnableCapability(principalID, cap, - nsIPrincipal::ENABLE_GRANTED))) + rv = securityManager->SetCanEnableCapability(principalID, cap, + nsIPrincipal::ENABLE_GRANTED); + if (NS_FAILED(rv)) return JS_FALSE; return JS_TRUE; } @@ -227,23 +210,19 @@ netscape_security_invalidate(JSContext *cx, JSObject *obj, uintN argc, char *principalID = getStringArgument(cx, obj, 0, argc, argv); if (!principalID) return JS_FALSE; + nsresult rv; nsCOMPtr securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return JS_FALSE; - - - // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - - - - if (NS_FAILED(securityManager->SetCanEnableCapability(principalID, - nsBasePrincipal::Invalid, - nsIPrincipal::ENABLE_GRANTED))) + rv = securityManager->SetCanEnableCapability(principalID, + nsBasePrincipal::Invalid, + nsIPrincipal::ENABLE_GRANTED); + if (NS_FAILED(rv)) return JS_FALSE; return JS_TRUE; } @@ -316,24 +295,45 @@ nsSecurityNameSet::InitializeNameSet(nsIScriptContext* aScriptContext) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsAggregatePrincipal) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCertificatePrincipal) NS_GENERIC_FACTORY_CONSTRUCTOR(nsCodebasePrincipal) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecurityNameSet) +static nsSystemPrincipal *GetSystemPrincipal() +{ + nsIPrincipal *sysprin = nsnull; + nsCOMPtr + secmgr(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID)); + if (secmgr) + secmgr->GetSystemPrincipal(&sysprin); + return NS_STATIC_CAST(nsSystemPrincipal*, sysprin); +} + +NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemPrincipal, GetSystemPrincipal) + + +NS_DECL_CLASSINFO(nsAggregatePrincipal) +NS_DECL_CLASSINFO(nsCertificatePrincipal) +NS_DECL_CLASSINFO(nsCodebasePrincipal) +NS_DECL_CLASSINFO(nsSystemPrincipal) + + static NS_IMETHODIMP Construct_nsIScriptSecurityManager(nsISupports *aOuter, REFNSIID aIID, - void **aResult) + void **aResult) { - if (!aResult) - return NS_ERROR_NULL_POINTER; - *aResult = nsnull; - if (aOuter) - return NS_ERROR_NO_AGGREGATION; - nsScriptSecurityManager *obj = nsScriptSecurityManager::GetScriptSecurityManager(); - if (!obj) - return NS_ERROR_OUT_OF_MEMORY; - if (NS_FAILED(obj->QueryInterface(aIID, aResult))) - return NS_ERROR_FAILURE; - return NS_OK; + if (!aResult) + return NS_ERROR_NULL_POINTER; + *aResult = nsnull; + if (aOuter) + return NS_ERROR_NO_AGGREGATION; + nsScriptSecurityManager *obj = nsScriptSecurityManager::GetScriptSecurityManager(); + if (!obj) + return NS_ERROR_OUT_OF_MEMORY; + if (NS_FAILED(obj->QueryInterface(aIID, aResult))) + return NS_ERROR_FAILURE; + return NS_OK; } static NS_METHOD @@ -343,22 +343,22 @@ RegisterSecurityNameSet(nsIComponentManager *aCompMgr, const char *componentType, const nsModuleComponentInfo *info) { - nsresult rv = NS_OK; + nsresult rv = NS_OK; - nsCOMPtr catman = - do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + nsCOMPtr catman = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + + if (NS_FAILED(rv)) + return rv; + + nsXPIDLCString previous; + rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_STATIC_NAMESET_CATEGORY, + "PrivilegeManager", + NS_SECURITYNAMESET_CONTRACTID, + PR_TRUE, PR_TRUE, getter_Copies(previous)); + NS_ENSURE_SUCCESS(rv, rv); - if (NS_FAILED(rv)) return rv; - - nsXPIDLCString previous; - rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_STATIC_NAMESET_CATEGORY, - "PrivilegeManager", - NS_SECURITYNAMESET_CONTRACTID, - PR_TRUE, PR_TRUE, getter_Copies(previous)); - NS_ENSURE_SUCCESS(rv, rv); - - return rv; } static nsModuleComponentInfo components[] = @@ -370,12 +370,30 @@ static nsModuleComponentInfo components[] = RegisterSecurityNameSet }, + { NS_AGGREGATEPRINCIPAL_CLASSNAME, + NS_AGGREGATEPRINCIPAL_CID, + NS_AGGREGATEPRINCIPAL_CONTRACTID, + nsAggregatePrincipalConstructor + }, + + { NS_CERTIFICATEPRINCIPAL_CLASSNAME, + NS_CERTIFICATEPRINCIPAL_CID, + NS_CERTIFICATEPRINCIPAL_CONTRACTID, + nsCertificatePrincipalConstructor + }, + { NS_CODEBASEPRINCIPAL_CLASSNAME, NS_CODEBASEPRINCIPAL_CID, NS_CODEBASEPRINCIPAL_CONTRACTID, nsCodebasePrincipalConstructor }, + { NS_SYSTEMPRINCIPAL_CLASSNAME, + NS_SYSTEMPRINCIPAL_CID, + NS_SYSTEMPRINCIPAL_CONTRACTID, + nsSystemPrincipalConstructor + }, + { "Security Script Name Set", NS_SECURITYNAMESET_CID, NS_SECURITYNAMESET_CONTRACTID, diff --git a/mozilla/caps/src/nsSystemPrincipal.cpp b/mozilla/caps/src/nsSystemPrincipal.cpp index 6ccd0ae95fe..80371f13af8 100644 --- a/mozilla/caps/src/nsSystemPrincipal.cpp +++ b/mozilla/caps/src/nsSystemPrincipal.cpp @@ -31,7 +31,7 @@ #include "nsXPIDLString.h" -NS_IMPL_QUERY_INTERFACE1(nsSystemPrincipal, nsIPrincipal) +NS_IMPL_QUERY_INTERFACE2_CI(nsSystemPrincipal, nsIPrincipal, nsISerializable) NSBASEPRINCIPALS_ADDREF(nsSystemPrincipal); NSBASEPRINCIPALS_RELEASE(nsSystemPrincipal); @@ -125,6 +125,24 @@ nsSystemPrincipal::DisableCapability(const char *capability, void **annotation) return NS_ERROR_FAILURE; } +////////////////////////////////////////// +// Methods implementing nsISerializable // +////////////////////////////////////////// + +NS_IMETHODIMP +nsSystemPrincipal::Read(nsIObjectInputStream* aStream) +{ + // no-op: CID is sufficient to identify the mSystemPrincipal singleton + return NS_OK; +} + +NS_IMETHODIMP +nsSystemPrincipal::Write(nsIObjectOutputStream* aStream) +{ + // no-op: CID is sufficient to identify the mSystemPrincipal singleton + return NS_OK; +} + ///////////////////////////////////////////// // Constructor, Destructor, initialization // ///////////////////////////////////////////// diff --git a/mozilla/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/chrome/src/nsChromeProtocolHandler.cpp index 5ee8f08f1de..c1def664768 100644 --- a/mozilla/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/chrome/src/nsChromeProtocolHandler.cpp @@ -73,7 +73,7 @@ static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); // which will fire the listener's OnStopRequest() and remove the // channel from the load group. // -// Each is done asynchronously to allbow the stack to unwind back to +// Each is done asynchronously to allow the stack to unwind back to // the main event loop. This avoids any weird re-entrancy that occurs // if we try to immediately fire the On[Start|Stop]Request(). // diff --git a/mozilla/content/build/nsContentFactory.cpp b/mozilla/content/build/nsContentFactory.cpp index 7d614b6e81e..1c3d36e56fb 100644 --- a/mozilla/content/build/nsContentFactory.cpp +++ b/mozilla/content/build/nsContentFactory.cpp @@ -169,19 +169,21 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsContentHTTPStartup) #include "nsIXULDocument.h" #include "nsIXULPopupListener.h" #include "nsIXULPrototypeCache.h" +#include "nsIXULPrototypeDocument.h" #include "nsIController.h" #include "nsIControllers.h" #include "nsIControllerCommand.h" -static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID); -static NS_DEFINE_CID(kXULTemplateBuilderCID, NS_XULTEMPLATEBUILDER_CID); -static NS_DEFINE_CID(kXULOutlinerBuilderCID, NS_XULOUTLINERBUILDER_CID); -static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID); -static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID); -static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID); -static NS_DEFINE_CID(kXULElementFactoryCID, NS_XULELEMENTFACTORY_CID); -static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); -static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); +static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID); +static NS_DEFINE_CID(kXULTemplateBuilderCID, NS_XULTEMPLATEBUILDER_CID); +static NS_DEFINE_CID(kXULOutlinerBuilderCID, NS_XULOUTLINERBUILDER_CID); +static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID); +static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID); +static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID); +static NS_DEFINE_CID(kXULElementFactoryCID, NS_XULELEMENTFACTORY_CID); +static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); +static NS_DEFINE_CID(kXULPrototypeDocumentCID, NS_XULPROTOTYPEDOCUMENT_CID); +static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); extern nsresult NS_NewXULElementFactory(nsIElementFactory** aResult); extern NS_IMETHODIMP NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult); @@ -591,6 +593,13 @@ nsContentFactory::CreateInstance(nsISupports *aOuter, return res; } } + else if (mClassID.Equals(kXULPrototypeDocumentCID)) { + res = NS_NewXULPrototypeDocument(nsnull, NS_GET_IID(nsIXULPrototypeDocument), (void**) &inst); + if (NS_FAILED(res)) { + LOG_NEW_FAILURE("NS_NewXULPrototypeDocument", res); + return res; + } + } else if (mClassID.Equals(kXULControllersCID)) { res = NS_NewXULControllers(nsnull, NS_GET_IID(nsIControllers), (void**) &inst); if (NS_FAILED(res)) { diff --git a/mozilla/content/build/nsContentModule.cpp b/mozilla/content/build/nsContentModule.cpp index a999fd5f475..afd56a258fa 100644 --- a/mozilla/content/build/nsContentModule.cpp +++ b/mozilla/content/build/nsContentModule.cpp @@ -71,6 +71,7 @@ #ifdef MOZ_XUL #include "nsXULAtoms.h" #include "nsXULContentUtils.h" +#include "nsIXULPrototypeDocument.h" #endif static nsContentModule *gModule = NULL; @@ -333,6 +334,8 @@ static Components gComponents[] = { "@mozilla.org/xul/xul-controllers;1", }, { "XUL Prototype Cache", NS_XULPROTOTYPECACHE_CID, "@mozilla.org/xul/xul-prototype-cache;1", }, + { NS_XULPROTOTYPEDOCUMENT_CLASSNAME, NS_XULPROTOTYPEDOCUMENT_CID, + nsnull, }, { "XUL Element Factory", NS_XULELEMENTFACTORY_CID, NS_ELEMENT_FACTORY_CONTRACTID_PREFIX "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", }, #endif diff --git a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp index 04a2181844c..06184a18af4 100644 --- a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp @@ -911,6 +911,7 @@ class DOMMediaListImpl : public nsIDOMMediaList, NS_FORWARD_NSISUPPORTSARRAY(mArray->) NS_FORWARD_NSICOLLECTION(mArray->); + NS_FORWARD_NSISERIALIZABLE(mArray->); // XXXbe temporary NS_IMETHOD_(PRBool) operator==(const nsISupportsArray& other) { return PR_FALSE; @@ -936,6 +937,7 @@ NS_INTERFACE_MAP_BEGIN(DOMMediaListImpl) NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMediaList) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MediaList) + NS_INTERFACE_MAP_ENTRY(nsISerializable) NS_INTERFACE_MAP_END diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index 033c4afcffc..c2154dcd54d 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -20,9 +20,10 @@ * Original Author(s): * Chris Waterson * - * Contributor(s): + * Contributor(s): * Pierre Phaneuf * Peter Annema + * Brendan Eich * * * This Original Code has been modified by IBM Corporation. @@ -49,6 +50,7 @@ */ #include "jsapi.h" // for JS_AddNamedRoot and JS_RemoveRootRT +#include "jsxdrapi.h" #include "nsCOMPtr.h" #include "nsDOMCID.h" #include "nsDOMError.h" @@ -84,6 +86,8 @@ #include "nsIStyleContext.h" #include "nsINameSpace.h" #include "nsINameSpaceManager.h" +#include "nsIObjectInputStream.h" +#include "nsIObjectOutputStream.h" #include "nsIPresShell.h" #include "nsIPrincipal.h" #include "nsIRDFCompositeDataSource.h" @@ -172,7 +176,7 @@ static nsresult AddJSGCRoot(JSContext* cx, void* aScriptObjectRef, const char* aName) { PRBool ok; - ok = JS_AddNamedRoot(cx, aScriptObjectRef, aName); + ok = ::JS_AddNamedRoot(cx, aScriptObjectRef, aName); if (! ok) return NS_ERROR_OUT_OF_MEMORY; if (gScriptRuntimeRefcnt++ == 0) { @@ -195,7 +199,7 @@ RemoveJSGCRoot(void* aScriptObjectRef) if (! gScriptRuntime) return NS_ERROR_FAILURE; - JS_RemoveRootRT(gScriptRuntime, aScriptObjectRef); + ::JS_RemoveRootRT(gScriptRuntime, aScriptObjectRef); if (--gScriptRuntimeRefcnt == 0) { NS_RELEASE(gJSRuntimeService); @@ -253,7 +257,7 @@ static EventHandlerMapEntry kEventHandlerMap[] = { { "oninput", nsnull, &NS_GET_IID(nsIDOMFormListener) }, { "onpaint", nsnull, &NS_GET_IID(nsIDOMPaintListener) }, - + { "ondragenter", nsnull, &NS_GET_IID(nsIDOMDragListener) }, { "ondragover", nsnull, &NS_GET_IID(nsIDOMDragListener) }, { "ondragexit", nsnull, &NS_GET_IID(nsIDOMDragListener) }, @@ -313,7 +317,7 @@ struct XULBroadcastListener nsVoidArray* mAttributeList; nsIDOMElement* mListener; - XULBroadcastListener(const nsAReadableString& aAttribute, + XULBroadcastListener(const nsAReadableString& aAttribute, nsIDOMElement* aListener) : mAttributeList(nsnull) { @@ -445,7 +449,7 @@ static PRBool HasMutationListeners(nsIContent* aContent, PRUint32 aType) return PR_TRUE; } } - + rec = do_QueryInterface(window); if (rec) { rec->GetListenerManager(getter_AddRefs(manager)); @@ -478,6 +482,25 @@ PRUint32 nsXULPrototypeAttribute::gNumCacheSets; PRUint32 nsXULPrototypeAttribute::gNumCacheFills; #endif +//---------------------------------------------------------------------- +// nsXULNode +// XXXbe temporary, make 'em pure when all subclasses implement + +nsresult +nsXULPrototypeNode::Serialize(nsIObjectOutputStream* aStream, + nsIScriptContext* aContext) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +nsresult +nsXULPrototypeNode::Deserialize(nsIObjectInputStream* aStream, + nsIScriptContext* aContext) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + //---------------------------------------------------------------------- // nsXULElement @@ -511,7 +534,7 @@ nsXULElement::Init() NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); if (NS_FAILED(rv)) return rv; - + rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID, nsnull, @@ -560,7 +583,7 @@ nsXULElement::~nsXULElement() nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); gRDFService = nsnull; } - + NS_IF_RELEASE(gNameSpaceManager); } } @@ -676,7 +699,7 @@ nsXULElement::Create(nsINodeInfo *aNodeInfo, nsIContent** aResult) NS_IMPL_ADDREF(nsXULElement); NS_IMPL_RELEASE(nsXULElement); -NS_IMETHODIMP +NS_IMETHODIMP nsXULElement::QueryInterface(REFNSIID iid, void** result) { if (! result) @@ -1301,7 +1324,7 @@ nsXULElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) NS_ASSERTION(domchild != nsnull, "child is not a DOM node"); if (! domchild) return NS_ERROR_UNEXPECTED; - + nsCOMPtr newdomchild; rv = domchild->CloneNode(PR_TRUE, getter_AddRefs(newdomchild)); if (NS_FAILED(rv)) return rv; @@ -1942,7 +1965,7 @@ nsXULElement::RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsI NS_IMETHODIMP nsXULElement::AddEventListener(const nsAReadableString& aType, - nsIDOMEventListener* aListener, + nsIDOMEventListener* aListener, PRBool aUseCapture) { nsIEventListenerManager *manager; @@ -1959,7 +1982,7 @@ nsXULElement::AddEventListener(const nsAReadableString& aType, NS_IMETHODIMP nsXULElement::RemoveEventListener(const nsAReadableString& aType, - nsIDOMEventListener* aListener, + nsIDOMEventListener* aListener, PRBool aUseCapture) { if (mListenerManager) { @@ -2035,8 +2058,8 @@ static PRBool CanHaveBinding(nsIAtom* aTag) { (aTag != nsXULAtoms::box) && (aTag != nsXULAtoms::hbox) && (aTag != nsXULAtoms::vbox) && (aTag != nsXULAtoms::stack) && (aTag != nsXULAtoms::spring); } - -NS_IMETHODIMP + +NS_IMETHODIMP nsXULElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) { nsresult rv = NS_OK; @@ -2144,7 +2167,7 @@ nsXULElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) if (viewCSS) { nsCOMPtr cssDecl; nsAutoString empty; - viewCSS->GetComputedStyle(this, empty, getter_AddRefs(cssDecl)); + viewCSS->GetComputedStyle(this, empty, getter_AddRefs(cssDecl)); /*nsString str; ourTag->ToString(str); nsCString cstr; cstr.AssignWithConversion(str); @@ -2172,11 +2195,11 @@ nsXULElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) } *aScriptObject = mScriptObject; - + return rv; } -NS_IMETHODIMP +NS_IMETHODIMP nsXULElement::SetScriptObject(void *aScriptObject) { mScriptObject = aScriptObject; @@ -2317,7 +2340,7 @@ nsXULElement::GetDocument(nsIDocument*& aResult) const NS_IF_ADDREF(aResult); return NS_OK; } - + NS_IMETHODIMP nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers) { @@ -2361,7 +2384,7 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileE nsCOMPtr nsDoc(do_QueryInterface(mDocument)); nsDoc->SetBoxObjectFor(domElement, nsnull); } - + // mControllers can own objects that are implemented // in JavaScript (such as some implementations of // nsIControllers. These objects prevent their global @@ -2545,7 +2568,7 @@ nsXULElement::InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify, aKid->SetDocument(mDocument, aDeepSetDocument, PR_TRUE); - if (mDocument && HasMutationListeners(NS_STATIC_CAST(nsIStyledContent*,this), + if (mDocument && HasMutationListeners(NS_STATIC_CAST(nsIStyledContent*,this), NS_EVENT_BITS_MUTATION_NODEINSERTED)) { nsCOMPtr node(do_QueryInterface(aKid)); nsMutationEvent mutation; @@ -2627,7 +2650,7 @@ nsXULElement::AppendChildTo(nsIContent* aKid, PRBool aNotify, PRBool aDeepSetDoc aKid->SetDocument(mDocument, aDeepSetDocument, PR_TRUE); - if (mDocument && HasMutationListeners(NS_STATIC_CAST(nsIStyledContent*,this), + if (mDocument && HasMutationListeners(NS_STATIC_CAST(nsIStyledContent*,this), NS_EVENT_BITS_MUTATION_NODEINSERTED)) { nsCOMPtr node(do_QueryInterface(aKid)); nsMutationEvent mutation; @@ -2793,7 +2816,7 @@ nsXULElement::RemoveChildAt(PRInt32 aIndex, PRBool aNotify) return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsXULElement::GetNameSpaceID(PRInt32& aNameSpaceID) const { return NodeInfo()->GetNamespaceID(aNameSpaceID); @@ -2805,8 +2828,8 @@ nsXULElement::GetTag(nsIAtom*& aResult) const return NodeInfo()->GetNameAtom(aResult); } -NS_IMETHODIMP -nsXULElement::NormalizeAttributeString(const nsAReadableString& aStr, +NS_IMETHODIMP +nsXULElement::NormalizeAttributeString(const nsAReadableString& aStr, nsINodeInfo*& aNodeInfo) { PRInt32 i, count = Attributes() ? Attributes()->Count() : 0; @@ -2846,8 +2869,8 @@ nsXULElement::NormalizeAttributeString(const nsAReadableString& aStr, // XXX attribute code swiped from nsGenericContainerElement // this class could probably just use nsGenericContainerElement // needed to maintain attribute namespace ID as well as ordering -NS_IMETHODIMP -nsXULElement::SetAttribute(nsINodeInfo* aNodeInfo, +NS_IMETHODIMP +nsXULElement::SetAttribute(nsINodeInfo* aNodeInfo, const nsAReadableString& aValue, PRBool aNotify) { @@ -2916,14 +2939,14 @@ nsXULElement::SetAttribute(nsINodeInfo* aNodeInfo, nodeList = do_QueryInterface(nodes); } } - + if (nodeList) { // Append this node to the list. nodeList->AppendNode(this); } } - + // Check to see if the POPUP attribute is being set. If so, we need to attach // a new instance of our popup handler to the node. if (mDocument && (aNodeInfo->Equals(nsXULAtoms::popup, kNameSpaceID_None) || aNodeInfo->Equals(nsXULAtoms::tooltip, kNameSpaceID_None) || aNodeInfo->Equals(nsXULAtoms::context, kNameSpaceID_None))) @@ -2933,7 +2956,7 @@ nsXULElement::SetAttribute(nsINodeInfo* aNodeInfo, // XXX need to check if they're changing an event handler: if so, then we need // to unhook the old one. - + nsXULAttribute* attr; PRInt32 i = 0; PRInt32 count = Attributes()->Count(); @@ -2958,7 +2981,7 @@ nsXULElement::SetAttribute(nsINodeInfo* aNodeInfo, aNodeInfo, aValue, &attr); if (NS_FAILED(rv)) return rv; - // transfer ownership here... + // transfer ownership here... Attributes()->AppendElement(attr); } @@ -2987,7 +3010,7 @@ nsXULElement::SetAttribute(nsINodeInfo* aNodeInfo, XULBroadcastListener* xulListener = NS_REINTERPRET_CAST(XULBroadcastListener*, BroadcastListeners()->ElementAt(i)); - if (xulListener->ObservingAttribute(attribute) && + if (xulListener->ObservingAttribute(attribute) && (!aNodeInfo->Equals(nsXULAtoms::id)) && (!aNodeInfo->Equals(nsXULAtoms::persist)) && (!aNodeInfo->Equals(nsXULAtoms::ref))) @@ -3023,7 +3046,7 @@ nsXULElement::SetAttribute(nsINodeInfo* aNodeInfo, mutation.mRelatedNode = attrNode; mutation.mAttrName = attrName; - if (!oldValue.IsEmpty()) + if (!oldValue.IsEmpty()) mutation.mPrevAttrValue = getter_AddRefs(NS_NewAtom(oldValue)); if (!aValue.IsEmpty()) mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(aValue)); @@ -3052,7 +3075,7 @@ nsXULElement::SetAttribute(nsINodeInfo* aNodeInfo, NS_IMETHODIMP nsXULElement::SetAttribute(PRInt32 aNameSpaceID, - nsIAtom* aName, + nsIAtom* aName, const nsAReadableString& aValue, PRBool aNotify) { @@ -3154,7 +3177,7 @@ nsXULElement::UnsetAttribute(PRInt32 aNameSpaceID, (aName == nsXULAtoms::clazz)) { Attributes()->UpdateClassList(nsAutoString()); } - + if (mDocument && (aNameSpaceID == kNameSpaceID_None) && aName == nsXULAtoms::style) { @@ -3187,7 +3210,7 @@ nsXULElement::UnsetAttribute(PRInt32 aNameSpaceID, nodeList = do_QueryInterface(nodes); } } - + if (nodeList) { // Remove this node from the list. nodeList->RemoveNode(this); @@ -3222,7 +3245,7 @@ nsXULElement::UnsetAttribute(PRInt32 aNameSpaceID, mutation.mRelatedNode = attrNode; mutation.mAttrName = aName; - if (!oldValue.IsEmpty()) + if (!oldValue.IsEmpty()) mutation.mPrevAttrValue = getter_AddRefs(NS_NewAtom(oldValue)); mutation.mAttrChange = nsIDOMMutationEvent::REMOVAL; nsEventStatus status = nsEventStatus_eIgnore; @@ -3242,7 +3265,7 @@ nsXULElement::UnsetAttribute(PRInt32 aNameSpaceID, // Check to see if the OBSERVES attribute is being unset. If so, we // need to remove ourselves completely. if (mDocument && - (aNameSpaceID == kNameSpaceID_None) && + (aNameSpaceID == kNameSpaceID_None) && (aName == nsXULAtoms::observes || aName == nsXULAtoms::command)) { // Do a getElementById to retrieve the broadcaster. @@ -3265,7 +3288,7 @@ nsXULElement::UnsetAttribute(PRInt32 aNameSpaceID, nsAutoString str; aName->ToString(str); - if (xulListener->ObservingAttribute(str) && + if (xulListener->ObservingAttribute(str) && (aName != nsXULAtoms::id) && (aName != nsXULAtoms::persist) && (aName != nsXULAtoms::ref)) @@ -3279,7 +3302,7 @@ nsXULElement::UnsetAttribute(PRInt32 aNameSpaceID, } } } - + // Notify document if (NS_SUCCEEDED(rv) && mDocument) { nsCOMPtr bindingManager; @@ -3381,7 +3404,7 @@ nsXULElement::List(FILE* out, PRInt32 aIndent) const if (namespaceID == kNameSpaceID_Unknown) { fputs("unknown:", out); } - + nsAutoString as; NodeInfo()->GetQualifiedName(as); fputs(as, out); @@ -3462,7 +3485,7 @@ nsXULElement::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, @@ -3470,7 +3493,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, nsEventStatus* aEventStatus) { nsresult ret = NS_OK; - + PRBool retarget = PR_FALSE; nsCOMPtr oldTarget; @@ -3482,8 +3505,8 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, // In order for the event to have a proper target for events that don't go through // the presshell (onselect, oncommand, oncreate, ondestroy) we need to set our target // ourselves. Also, key sets and menus don't have frames and therefore need their - // targets explicitly specified. - // + // targets explicitly specified. + // // We need this for drag&drop as well since the mouse may have moved into a different // frame between the initial mouseDown and the generation of the drag gesture. // Obviously, the target should be the content/frame where the mouse was depressed, @@ -3506,7 +3529,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, NS_ERROR("This event will fail without the ability to create the event early."); return ret; } - + // We need to explicitly set the target here, because the // DOM implementation will try to compute the target from // the frame. If we don't have a frame (e.g., we're a @@ -3518,7 +3541,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, else return NS_ERROR_FAILURE; } } - + // Find out if we're anonymous. nsCOMPtr bindingParent; if (*aDOMEvent) { @@ -3571,7 +3594,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent))) return ret; } - + if (!*aDOMEvent) { return NS_ERROR_FAILURE; } @@ -3581,7 +3604,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, } (*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget)); - + PRBool hasOriginal; privateEvent->HasOriginalTarget(&hasOriginal); @@ -3593,7 +3616,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, privateEvent->SetTarget(target); } } - + //Capturing stage evaluation if (NS_EVENT_FLAG_BUBBLE != aFlags) { //Initiate capturing phase. Special case first call to document @@ -3605,7 +3628,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, NS_EVENT_FLAG_CAPTURE, aEventStatus); } } - + if (retarget) { // The event originated beneath us, and we performed a retargeting. @@ -3692,23 +3715,23 @@ nsXULElement::SetContentID(PRUint32 aID) return NS_OK; } -NS_IMETHODIMP -nsXULElement::RangeAdd(nsIDOMRange& aRange) -{ +NS_IMETHODIMP +nsXULElement::RangeAdd(nsIDOMRange& aRange) +{ // rdf content does not yet support DOM ranges return NS_OK; } - -NS_IMETHODIMP -nsXULElement::RangeRemove(nsIDOMRange& aRange) + +NS_IMETHODIMP +nsXULElement::RangeRemove(nsIDOMRange& aRange) { // rdf content does not yet support DOM ranges return NS_OK; -} +} -NS_IMETHODIMP +NS_IMETHODIMP nsXULElement::GetRangeList(nsVoidArray*& aResult) const { // rdf content does not yet support DOM ranges @@ -3720,8 +3743,8 @@ nsXULElement::GetRangeList(nsVoidArray*& aResult) const //---------------------------------------------------------------------- NS_IMETHODIMP nsXULElement::AddBroadcastListener(const nsAReadableString& attr, - nsIDOMElement* anElement) -{ + nsIDOMElement* anElement) +{ // Add ourselves to the array. nsresult rv; @@ -3766,7 +3789,7 @@ nsXULElement::AddBroadcastListener(const nsAReadableString& attr, result == NS_CONTENT_ATTR_HAS_VALUE); if (attrPresent) { - // Set the attribute + // Set the attribute anElement->SetAttribute(attr, attrValue); } else { @@ -3775,14 +3798,14 @@ nsXULElement::AddBroadcastListener(const nsAReadableString& attr, } } - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsXULElement::RemoveBroadcastListener(const nsAReadableString& attr, - nsIDOMElement* anElement) -{ + nsIDOMElement* anElement) +{ if (BroadcastListeners()) { // Find the element. PRInt32 count = BroadcastListeners()->Count(); @@ -3791,7 +3814,7 @@ nsXULElement::RemoveBroadcastListener(const nsAReadableString& attr, NS_REINTERPRET_CAST(XULBroadcastListener*, BroadcastListeners()->ElementAt(i)); if (xulListener->mListener == anElement) { - if (xulListener->ObservingEverything() || attr.Equals(NS_LITERAL_STRING("*"))) { + if (xulListener->ObservingEverything() || attr.Equals(NS_LITERAL_STRING("*"))) { // Do the removal. BroadcastListeners()->RemoveElementAt(i); delete xulListener; @@ -3924,7 +3947,7 @@ nsXULElement::EnsureContentsGenerated(void) const return NS_OK; } - + nsresult nsXULElement::ExecuteOnBroadcastHandler(nsIDOMElement* anElement, const nsAReadableString& attrName) { @@ -3957,7 +3980,7 @@ nsXULElement::ExecuteOnBroadcastHandler(nsIDOMElement* anElement, const nsAReada // Execute the onchange event handler nsEvent event; event.eventStructType = NS_EVENT; - event.message = NS_XUL_BROADCAST; + event.message = NS_XUL_BROADCAST; ExecuteJSCode(domElement, &event); } } @@ -3971,7 +3994,7 @@ nsXULElement::ExecuteOnBroadcastHandler(nsIDOMElement* anElement, const nsAReada nsresult nsXULElement::ExecuteJSCode(nsIDOMElement* anElement, nsEvent* aEvent) -{ +{ // This code executes in every presentation context in which this // document is appearing. nsCOMPtr content; @@ -4120,7 +4143,7 @@ nsXULElement::GetElementsByAttribute(nsIDOMNode* aNode, return rv; } } - + // Now recursively look for children if (NS_FAILED(rv = GetElementsByAttribute(child, aAttribute, aValue, aElements))) { NS_ERROR("unable to recursively get elements by attribute"); @@ -4166,7 +4189,7 @@ nsXULElement::GetID(nsIAtom*& aResult) const return NS_OK; } - + NS_IMETHODIMP nsXULElement::GetClasses(nsVoidArray& aArray) const { @@ -4183,7 +4206,7 @@ nsXULElement::GetClasses(nsVoidArray& aArray) const return rv; } -NS_IMETHODIMP +NS_IMETHODIMP nsXULElement::HasClass(nsIAtom* aClass) const { nsresult rv = NS_ERROR_NULL_POINTER; @@ -4201,7 +4224,7 @@ nsXULElement::WalkContentStyleRules(nsIRuleWalker* aRuleWalker) { return NS_OK; } - + NS_IMETHODIMP nsXULElement::WalkInlineStyleRules(nsIRuleWalker* aRuleWalker) { @@ -4224,7 +4247,7 @@ nsXULElement::WalkInlineStyleRules(nsIRuleWalker* aRuleWalker) } NS_IMETHODIMP -nsXULElement::GetMappedAttributeImpact(const nsIAtom* aAttribute, +nsXULElement::GetMappedAttributeImpact(const nsIAtom* aAttribute, PRInt32& aHint) const { aHint = NS_STYLE_HINT_CONTENT; // by default, never map attributes to style @@ -4246,9 +4269,9 @@ nsXULElement::GetMappedAttributeImpact(const nsIAtom* aAttribute, if (nsXULAtoms::width == aAttribute || nsXULAtoms::height == aAttribute) aHint = NS_STYLE_HINT_NONE; } else { - // if left or top changes we reflow. This will happen in xul containers that + // if left or top changes we reflow. This will happen in xul containers that // manage positioned children such as a bulletinboard. - if (nsXULAtoms::left == aAttribute || nsXULAtoms::top == aAttribute) + if (nsXULAtoms::left == aAttribute || nsXULAtoms::top == aAttribute) aHint = NS_STYLE_HINT_REFLOW; } @@ -4296,7 +4319,7 @@ nsXULElement::GetBoxObject(nsIBoxObject** aResult) { *aResult = nsnull; - if (!mDocument) + if (!mDocument) return NS_ERROR_FAILURE; nsCOMPtr nsDoc(do_QueryInterface(mDocument)); @@ -4332,7 +4355,7 @@ nsXULElement::SetClassName(const nsAReadableString& aClassName) return NS_OK; } -nsresult +nsresult nsXULElement::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) { NS_NOTYETIMPLEMENTED("write me!"); @@ -4361,7 +4384,7 @@ nsXULElement::GetParentTree(nsIDOMXULTreeElement** aTreeElement) return NS_OK; } -PRBool +PRBool nsXULElement::IsAncestor(nsIDOMNode* aParentNode, nsIDOMNode* aChildNode) { nsCOMPtr parent = dont_QueryInterface(aChildNode); @@ -4427,7 +4450,7 @@ nsXULElement::Click() for (PRInt32 i=0; iGetShellAt(i, getter_AddRefs(shell)); shell->GetPresContext(getter_AddRefs(context)); - + nsEventStatus status = nsEventStatus_eIgnore; nsMouseEvent event; event.eventStructType = NS_GUI_EVENT; @@ -4454,7 +4477,6 @@ nsXULElement::Command() PRInt32 numShells = doc->GetNumberOfShells(); nsCOMPtr shell; nsCOMPtr context; - PRBool isButton = NodeInfo()->Equals(NS_LITERAL_STRING("button")); for (PRInt32 i=0; iGetShellAt(i, getter_AddRefs(shell)); @@ -4467,7 +4489,7 @@ nsXULElement::Command() HandleDOMEvent(context, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } } - + return NS_OK; } @@ -4480,14 +4502,14 @@ nsXULElement::SetFocus(nsIPresContext* aPresContext) GetAttribute(NS_LITERAL_STRING("disabled"), disabled); if (disabled == NS_LITERAL_STRING("true")) return NS_OK; - + nsIEventStateManager* esm; if (NS_OK == aPresContext->GetEventStateManager(&esm)) { - + esm->SetContentState((nsIStyledContent*)this, NS_EVENT_STATE_FOCUS); NS_RELEASE(esm); } - + return NS_OK; } @@ -4506,7 +4528,7 @@ nsXULElement::GetBindingParent(nsIContent** aContent) } NS_IMETHODIMP -nsXULElement::SetBindingParent(nsIContent* aParent) +nsXULElement::SetBindingParent(nsIContent* aParent) { mBindingParent = aParent; // [Weak] no addref if (mBindingParent) { @@ -4529,7 +4551,7 @@ nsXULElement::IsContentOfType(PRUint32 aFlags) void nsXULElement::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize) { - // XXX - implement this if you want the sizes of XUL style rules + // XXX - implement this if you want the sizes of XUL style rules // dumped during StyleSize dump return; } @@ -4572,8 +4594,8 @@ nsXULElement::AddPopupListener(nsIAtom* aName) AddEventListener(NS_LITERAL_STRING("keydown"), eventListener, PR_FALSE); } else { - AddEventListener(NS_LITERAL_STRING("mousedown"), eventListener, PR_FALSE); - AddEventListener(NS_LITERAL_STRING("contextmenu"), eventListener, PR_FALSE); + AddEventListener(NS_LITERAL_STRING("mousedown"), eventListener, PR_FALSE); + AddEventListener(NS_LITERAL_STRING("contextmenu"), eventListener, PR_FALSE); } return NS_OK; @@ -4581,10 +4603,10 @@ nsXULElement::AddPopupListener(nsIAtom* aName) //***************************************************************************** // nsXULElement::nsIChromeEventHandler -//***************************************************************************** +//***************************************************************************** NS_IMETHODIMP nsXULElement::HandleChromeEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, nsIDOMEvent** aDOMEvent, PRUint32 aFlags, + nsEvent* aEvent, nsIDOMEvent** aDOMEvent, PRUint32 aFlags, nsEventStatus* aEventStatus) { // XXX This is a disgusting hack to prevent the doc from going @@ -4711,6 +4733,47 @@ nsXULPrototypeAttribute::~nsXULPrototypeAttribute() // nsXULPrototypeElement // +nsresult +nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream, + nsIScriptContext* aContext) +{ + nsresult rv; + +#if 0 + // XXXbe partial deserializer is not ready for this yet + rv = aStream->Write32(PRUint32(mNumChildren)); + if (NS_FAILED(rv)) return rv; +#endif + + // XXXbe check for failure once all elements have been taught to serialize + for (PRInt32 i = 0; i < mNumChildren; i++) { + rv = mChildren[i]->Serialize(aStream, aContext); + NS_ASSERTION(NS_SUCCEEDED(rv) || rv == NS_ERROR_NOT_IMPLEMENTED, + "can't serialize!"); + } + return NS_OK; +} + +nsresult +nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream, + nsIScriptContext* aContext) +{ + nsresult rv; + + PRUint32 numChildren; + rv = aStream->Read32(&numChildren); + if (NS_FAILED(rv)) return rv; + + // XXXbe temporary until we stop parsing tags when deserializing + NS_ASSERTION(PRInt32(numChildren) == mNumChildren, "XUL/FastLoad mismatch"); + + // XXXbe check for failure once all elements have been taught to serialize + for (PRInt32 i = 0; i < mNumChildren; i++) + (void) mChildren[i]->Deserialize(aStream, aContext); + return NS_OK; +} + + nsresult nsXULPrototypeElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, nsAWritableString& aValue) { @@ -4719,7 +4782,7 @@ nsXULPrototypeElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, nsAWri mAttributes[i].mValue.GetValue( aValue ); return aValue.Length() ? NS_CONTENT_ATTR_HAS_VALUE : NS_CONTENT_ATTR_NO_VALUE; } - + } return NS_CONTENT_ATTR_NOT_THERE; } @@ -4748,6 +4811,164 @@ nsXULPrototypeScript::~nsXULPrototypeScript() MOZ_COUNT_DTOR(nsXULPrototypeScript); } + +nsresult +nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream, + nsIScriptContext* aContext) +{ + nsresult rv; + + NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nsnull || !mJSObject, + "script source still loading when serializing?!"); + +#if 0 + // XXXbe redundant while we're still parsing XUL instead of deserializing it + // XXXbe also, we should serialize mType and mLineNo first. + rv = NS_WriteOptionalCompoundObject(aStream, mSrcURI, NS_GET_IID(nsIURI), + PR_TRUE); + if (NS_FAILED(rv)) return rv; +#endif + + JSContext* cx = NS_REINTERPRET_CAST(JSContext*, + aContext->GetNativeContext()); + JSXDRState *xdr = ::JS_XDRNewMem(cx, JSXDR_ENCODE); + if (! xdr) + return NS_ERROR_OUT_OF_MEMORY; + xdr->userdata = (void*) aStream; + + JSScript *script = NS_REINTERPRET_CAST(JSScript*, + ::JS_GetPrivate(cx, mJSObject)); + if (! ::JS_XDRScript(xdr, &script)) { + rv = NS_ERROR_OUT_OF_MEMORY; // extremely likely, barring bugs! + } else { + // Get the encoded JSXDRState data and write it. The JSXDRState owns + // this buffer memory and will free it beneath ::JS_XDRDestroy. + // + // If an XPCOM object needs to be written in the midst of the JS XDR + // encoding process, the C++ code called back from the JS engine (e.g., + // nsEncodeJSPrincipals in caps/src/nsJSPrincipals.cpp) will flush data + // from the JSXDRState to aStream, then write the object, then return + // to JS XDR code with xdr reset so new JS data is encoded at the front + // of the xdr's data buffer. + // + // However many XPCOM objects are interleaved with JS XDR data in the + // stream, when control returns here from ::JS_XDRScript, we'll have + // one last buffer of data to write to aStream. + + uint32 size; + const char* data = NS_REINTERPRET_CAST(const char*, + ::JS_XDRMemGetData(xdr, &size)); + NS_ASSERTION(data, "no decoded JSXDRState data!"); + + rv = aStream->Write32(size); + if (NS_SUCCEEDED(rv)) + rv = aStream->WriteBytes(data, size); + } + + ::JS_XDRDestroy(xdr); + if (NS_FAILED(rv)) return rv; + + PRUint32 version = PRUint32(mLangVersion + ? ::JS_StringToVersion(mLangVersion) + : JSVERSION_DEFAULT); + rv = aStream->Write32(version); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +nsresult +nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream, + nsIScriptContext* aContext) +{ + nsresult rv; + + NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nsnull || !mJSObject, + "prototype script not well-initialized when deserializing?!"); + +#if 0 + // XXXbe redundant while we're still parsing XUL instead of deserializing it + // XXXbe also, we should deserialize mType and mLineNo first. + rv = NS_ReadOptionalObject(aStream, PR_TRUE, getter_AddRefs(mSrcURI)); + if (NS_FAILED(rv)) return rv; +#endif + + PRUint32 size; + rv = aStream->Read32(&size); + if (NS_FAILED(rv)) return rv; + + char* data; + rv = aStream->ReadBytes(&data, size); + if (NS_SUCCEEDED(rv)) { + JSContext* cx = NS_REINTERPRET_CAST(JSContext*, + aContext->GetNativeContext()); + + JSXDRState *xdr = ::JS_XDRNewMem(cx, JSXDR_DECODE); + if (! xdr) { + rv = NS_ERROR_OUT_OF_MEMORY; + } else { + xdr->userdata = (void*) aStream; + ::JS_XDRMemSetData(xdr, data, size); + + JSScript *script = nsnull; + if (! ::JS_XDRScript(xdr, &script)) { + rv = NS_ERROR_OUT_OF_MEMORY; // likely error + } else { + mJSObject = ::JS_NewScriptObject(cx, script); + if (! mJSObject) { + rv = NS_ERROR_OUT_OF_MEMORY; // certain error + ::JS_DestroyScript(cx, script); + } else { + rv = AddJSGCRoot(cx, &mJSObject, + "nsXULPrototypeScript::mJSObject"); + } + } + + // Update data in case ::JS_XDRScript called back into C++ code to + // read an XPCOM object. + // + // In that case, the serialization process must have flushed a run + // of counted bytes containing JS data at the point where the XPCOM + // object starts, after which an encoding C++ callback from the JS + // XDR code must have written the XPCOM object directly into the + // nsIObjectOutputStream. + // + // The deserialization process will XDR-decode counted bytes up to + // but not including the XPCOM object, then call back into C++ to + // read the object, then read more counted bytes and hand them off + // to the JSXDRState, so more JS data can be decoded. + // + // This interleaving of JS XDR data and XPCOM object data may occur + // several times beneath the call to ::JS_XDRScript, above. At the + // end of the day, we need to free (via nsMemory) the data owned by + // the JSXDRState. So we steal it back, nulling xdr's buffer so it + // doesn't get passed to ::JS_free by ::JS_XDRDestroy. + + uint32 junk; + data = (char*) ::JS_XDRMemGetData(xdr, &junk); + if (data) + ::JS_XDRMemSetData(xdr, NULL, 0); + ::JS_XDRDestroy(xdr); + } + + // If data is null now, it must have been freed while deserializing an + // XPCOM object (e.g., a principal) beneath ::JS_XDRScript. + if (data) + nsMemory::Free(data); + } + if (NS_FAILED(rv)) return rv; + + PRUint32 version; + rv = aStream->Read32(&version); + if (NS_FAILED(rv)) return rv; + + mLangVersion = ::JS_VersionToString(JSVersion(version)); + return NS_OK; +} + +// XXXbe temporary, goes away when we serialize entire XUL prototype document +#include "nsIFastLoadService.h" + nsresult nsXULPrototypeScript::Compile(const PRUnichar* aText, PRInt32 aTextLength, @@ -4828,6 +5049,19 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText, rv = AddJSGCRoot(cx, &mJSObject, "nsXULPrototypeScript::mJSObject"); if (NS_FAILED(rv)) return rv; + + // XXXbe temporary, until we serialize/deserialize everything from the + // nsXULPrototypeDocument on down... + nsCOMPtr fastLoadService(do_GetService(NS_FAST_LOAD_SERVICE_CONTRACTID)); + nsCOMPtr objectOutput; + fastLoadService->GetCurrentOutputStream(getter_AddRefs(objectOutput)); + if (objectOutput) { + rv = Serialize(objectOutput, context); + if (NS_FAILED(rv)) { + // XXXbe remove FastLoad file + fastLoadService->SetCurrentOutputStream(nsnull); + } + } } return NS_OK; diff --git a/mozilla/content/xul/content/src/nsXULElement.h b/mozilla/content/xul/content/src/nsXULElement.h index 393e8774575..af5de624be0 100644 --- a/mozilla/content/xul/content/src/nsXULElement.h +++ b/mozilla/content/xul/content/src/nsXULElement.h @@ -76,6 +76,9 @@ class nsXULAttributes; class nsVoidArray; class nsIWebShell; +class nsIObjectInputStream; +class nsIObjectOutputStream; + //////////////////////////////////////////////////////////////////////// #ifdef XUL_PROTOTYPE_ATTRIBUTE_METERING @@ -165,8 +168,6 @@ public: */ -class nsXULPrototypeElement; - class nsXULPrototypeNode { public: @@ -176,6 +177,10 @@ public: PRInt32 mLineNo; virtual ~nsXULPrototypeNode() {} + virtual nsresult Serialize(nsIObjectOutputStream* aStream, + nsIScriptContext* aContext); + virtual nsresult Deserialize(nsIObjectInputStream* aStream, + nsIScriptContext* aContext); protected: nsXULPrototypeNode(Type aType, PRInt32 aLineNo) @@ -210,6 +215,10 @@ public: delete[] mChildren; } + virtual nsresult Serialize(nsIObjectOutputStream* aStream, + nsIScriptContext* aContext); + virtual nsresult Deserialize(nsIObjectInputStream* aStream, + nsIScriptContext* aContext); nsIXULPrototypeDocument* mDocument; // [WEAK] because doc is refcounted PRInt32 mNumChildren; @@ -237,6 +246,11 @@ public: nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion); virtual ~nsXULPrototypeScript(); + virtual nsresult Serialize(nsIObjectOutputStream* aStream, + nsIScriptContext* aContext); + virtual nsresult Deserialize(nsIObjectInputStream* aStream, + nsIScriptContext* aContext); + nsresult Compile(const PRUnichar* aText, PRInt32 aTextLength, nsIURI* aURI, PRInt32 aLineNo, nsIDocument* aDocument, diff --git a/mozilla/content/xul/document/public/nsIXULDocument.h b/mozilla/content/xul/document/public/nsIXULDocument.h index bd479b1af2c..6d82d8dffde 100644 --- a/mozilla/content/xul/document/public/nsIXULDocument.h +++ b/mozilla/content/xul/document/public/nsIXULDocument.h @@ -142,6 +142,18 @@ public: * node. */ NS_IMETHOD GetTemplateBuilderFor(nsIContent* aContent, nsIXULTemplateBuilder** aResult) = 0; + + /** + * Callback notifying this document when its XUL prototype document load + * completes. The prototype load was initiated by another document load + * request than the one whose document is being notified here. + */ + NS_IMETHOD OnPrototypeLoadDone() = 0; + + /** + * Callback from the content sink upon resumption from the parser. + */ + NS_IMETHOD OnResumeContentSink() = 0; }; // factory functions diff --git a/mozilla/content/xul/document/public/nsIXULPrototypeCache.h b/mozilla/content/xul/document/public/nsIXULPrototypeCache.h index 777ab30a210..3be44731d3d 100644 --- a/mozilla/content/xul/document/public/nsIXULPrototypeCache.h +++ b/mozilla/content/xul/document/public/nsIXULPrototypeCache.h @@ -59,6 +59,10 @@ public: NS_IMETHOD PutStyleSheet(nsICSSStyleSheet* aStyleSheet) = 0; NS_IMETHOD FlushStyleSheets() = 0; + NS_IMETHOD GetScript(nsIURI* aURI, void** aScriptObject) = 0; + NS_IMETHOD PutScript(nsIURI* aURI, void* aScriptObject) = 0; + NS_IMETHOD FlushScripts() = 0; + NS_IMETHOD GetXBLDocumentInfo(const nsCString& aString, nsIXBLDocumentInfo** aResult) = 0; NS_IMETHOD PutXBLDocumentInfo(nsIXBLDocumentInfo* aDocument) = 0; diff --git a/mozilla/content/xul/document/public/nsIXULPrototypeDocument.h b/mozilla/content/xul/document/public/nsIXULPrototypeDocument.h index c0c25419e13..e610772922a 100644 --- a/mozilla/content/xul/document/public/nsIXULPrototypeDocument.h +++ b/mozilla/content/xul/document/public/nsIXULPrototypeDocument.h @@ -29,7 +29,7 @@ #ifndef nsIXULPrototypeDocument_h__ #define nsIXULPrototypeDocument_h__ -#include "nsISupports.h" +#include "nsISerializable.h" #include "nsAWritableString.h" class nsIAtom; @@ -39,13 +39,14 @@ class nsIURI; class nsString; class nsVoidArray; class nsXULPrototypeElement; +class nsIXULDocument; // {187A63D0-8337-11d3-BE47-00104BDE6048} #define NS_IXULPROTOTYPEDOCUMENT_IID \ { 0x187a63d0, 0x8337, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } -class nsIXULPrototypeDocument : public nsISupports +class nsIXULPrototypeDocument : public nsISerializable { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXULPROTOTYPEDOCUMENT_IID); @@ -73,9 +74,18 @@ public: NS_IMETHOD GetDocumentPrincipal(nsIPrincipal** aResult) = 0; NS_IMETHOD SetDocumentPrincipal(nsIPrincipal* aPrincipal) = 0; + + NS_IMETHOD AwaitLoadDone(nsIXULDocument* aDocument, PRBool* aResult) = 0; + NS_IMETHOD NotifyLoadDone() = 0; }; +// CID for factory-based creation, used only for deserialization. +#define NS_XULPROTOTYPEDOCUMENT_CLASSNAME "XUL Prototype Document" +#define NS_XULPROTOTYPEDOCUMENT_CID \ + {0xa08101ae,0xc0e8,0x4464,{0x99,0x9e,0xe5,0xa4,0xd7,0x09,0xa9,0x28}} + + extern NS_IMETHODIMP NS_NewXULPrototypeDocument(nsISupports* aOuter, REFNSIID aIID, void** aResult); diff --git a/mozilla/content/xul/document/src/nsXULContentSink.cpp b/mozilla/content/xul/document/src/nsXULContentSink.cpp index aea53c87e84..f18752722dd 100644 --- a/mozilla/content/xul/document/src/nsXULContentSink.cpp +++ b/mozilla/content/xul/document/src/nsXULContentSink.cpp @@ -64,6 +64,8 @@ #include "nsIRDFCompositeDataSource.h" #include "nsIRDFService.h" #include "nsIScriptContext.h" +#include "nsIScriptGlobalObject.h" +#include "nsIScriptGlobalObjectOwner.h" #include "nsIServiceManager.h" #include "nsITextContent.h" #include "nsIURL.h" @@ -85,6 +87,10 @@ #include "prmem.h" #include "jsapi.h" // for JSVERSION_*, JS_VersionToString, etc. +#include "nsIFastLoadService.h" // XXXbe temporary +#include "nsIObjectInputStream.h" // XXXbe temporary +#include "nsXULDocument.h" // XXXbe temporary + #include "nsHTMLTokens.h" // XXX so we can use nsIParserNode::GetTokenType() static const char kNameSpaceSeparator = ':'; @@ -529,6 +535,10 @@ XULContentSinkImpl::WillInterrupt(void) NS_IMETHODIMP XULContentSinkImpl::WillResume(void) { + nsCOMPtr xuldoc(do_QueryReferent(mDocument)); + if (xuldoc) + xuldoc->OnResumeContentSink(); + // XXX Notify the webshell, if necessary return NS_OK; } @@ -696,10 +706,10 @@ XULContentSinkImpl::CloseContainer(const nsIParserNode& aNode) case nsXULPrototypeNode::eType_Script: { nsXULPrototypeScript* script = - NS_REINTERPRET_CAST(nsXULPrototypeScript*, node); + NS_STATIC_CAST(nsXULPrototypeScript*, node); // If given a src= attribute, we must ignore script tag content. - if (! script->mSrcURI) { + if (! script->mSrcURI && ! script->mJSObject) { nsCOMPtr doc = do_QueryReferent(mDocument); rv = script->Compile(mText, mTextLength, mDocumentURL, @@ -732,7 +742,7 @@ XULContentSinkImpl::CloseContainer(const nsIParserNode& aNode) // root element. This transfers ownership of the prototype // element tree to the prototype document. nsXULPrototypeElement* element = - NS_REINTERPRET_CAST(nsXULPrototypeElement*, node); + NS_STATIC_CAST(nsXULPrototypeElement*, node); rv = mPrototype->SetRootElement(element); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set document root"); @@ -1546,6 +1556,119 @@ XULContentSinkImpl::OpenScript(const nsIParserNode& aNode) if (! script) return NS_ERROR_OUT_OF_MEMORY; + // If there is a SRC attribute... + if (! src.IsEmpty()) { + // Use the SRC attribute value to load the URL + rv = NS_NewURI(getter_AddRefs(script->mSrcURI), src, mDocumentURL); + if (NS_FAILED(rv)) { + delete script; + return rv; + } + } + + // XXXbe temporary, until we serialize/deserialize everything from + // the nsXULPrototypeDocument on down... + nsCOMPtr fastLoadService; + nsCOMPtr objectInput; + nsXULDocument::GetFastLoadService(getter_AddRefs(fastLoadService)); + if (fastLoadService) + fastLoadService->GetCurrentInputStream(getter_AddRefs(objectInput)); + + if (objectInput) { + PRBool useXULCache = PR_TRUE; + if (script->mSrcURI) { + // NB: we must check the XUL script cache early, to avoid + // multiple deserialization attempts for a given script, which + // would exhaust the multiplexed stream containing the singly + // serialized script. Note that nsXULDocument::LoadScript + // checks the XUL script cache too, in order to handle the + // serialization case. + // + // We need do this only for