diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 95cfe93c9687..3cae8c206d46 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -1315,14 +1315,33 @@ nsXULDocument::Persist(const nsAString& aID, } +PRBool +nsXULDocument::IsCapabilityEnabled(const char* aCapabilityLabel) +{ + nsresult rv; + + // NodePrincipal is guarantied to be non-null + PRBool enabled = PR_FALSE; + rv = NodePrincipal()->IsCapabilityEnabled(aCapabilityLabel, nsnull, &enabled); + if (NS_FAILED(rv)) + return PR_FALSE; + + return enabled; +} + + nsresult nsXULDocument::Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aAttribute) { + // For non-chrome documents, persistance is simply broken + if (!IsCapabilityEnabled("UniversalBrowserWrite")) + return NS_ERROR_NOT_AVAILABLE; + // First make sure we _have_ a local store to stuff the persisted // information into. (We might not have one if profile information // hasn't been loaded yet...) - if (! mLocalStore) + if (!mLocalStore) return NS_OK; nsresult rv; @@ -2119,13 +2138,26 @@ nsXULDocument::PrepareToLoadPrototype(nsIURI* aURI, const char* aCommand, nsresult nsXULDocument::ApplyPersistentAttributes() { + // For non-chrome documents, persistance is simply broken + if (!IsCapabilityEnabled("UniversalBrowserRead")) + return NS_ERROR_NOT_AVAILABLE; + // Add all of the 'persisted' attributes into the content // model. - if (! mLocalStore) + if (!mLocalStore) return NS_OK; mApplyingPersistedAttrs = PR_TRUE; + ApplyPersistentAttributesInternal(); + mApplyingPersistedAttrs = PR_FALSE; + return NS_OK; +} + + +nsresult +nsXULDocument::ApplyPersistentAttributesInternal() +{ nsCOMArray elements; nsCAutoString docurl; @@ -2172,8 +2204,6 @@ nsXULDocument::ApplyPersistentAttributes() ApplyPersistentAttributesToElements(resource, elements); } - mApplyingPersistedAttrs = PR_FALSE; - return NS_OK; } @@ -3081,8 +3111,7 @@ nsXULDocument::ResumeWalk() rv = ResolveForwardReferences(); if (NS_FAILED(rv)) return rv; - rv = ApplyPersistentAttributes(); - if (NS_FAILED(rv)) return rv; + ApplyPersistentAttributes(); mStillWalking = PR_FALSE; if (mPendingSheets == 0) { diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index 84e6d284279f..cf5b91d59e86 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -225,6 +225,7 @@ protected: PRBool* aFailureFromContent); nsresult ApplyPersistentAttributes(); + nsresult ApplyPersistentAttributesInternal(); nsresult ApplyPersistentAttributesToElements(nsIRDFResource* aResource, nsCOMArray& aElements); @@ -261,6 +262,9 @@ protected: static PRLogModuleInfo* gXULLog; + PRBool + IsCapabilityEnabled(const char* aCapabilityLabel); + nsresult Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aAttribute);