This commit is contained in:
brendan%mozilla.org 1999-11-18 02:25:33 +00:00
Родитель dcc06e4b83
Коммит 098299e271
18 изменённых файлов: 1160 добавлений и 1243 удалений

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

@ -35,6 +35,7 @@
#include "nsDOMCID.h"
#include "nsDOMEvent.h"
#include "nsForwardReference.h"
#include "nsXPIDLString.h"
#include "nsXULAttributes.h"
#include "nsIXULPopupListener.h"
#include "nsIHTMLContentContainer.h"
@ -56,6 +57,7 @@
#include "nsIJSScriptObject.h"
#include "nsINameSpace.h"
#include "nsINameSpaceManager.h"
#include "nsIPrincipal.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIRDFNode.h"
@ -71,6 +73,7 @@
#include "nsStyleConsts.h"
#include "nsIStyleSheet.h"
#include "nsIHTMLStyleSheet.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
#include "nsIStyledContent.h"
#include "nsIStyleContext.h"
@ -86,6 +89,7 @@
#include "prlog.h"
#include "rdf.h"
#include "nsHTMLValue.h"
#include "jsapi.h" // for JS_AddNamedRoot and JS_RemoveRootRT
#include "nsIControllers.h"
@ -135,84 +139,84 @@ static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
struct XULBroadcastListener
{
nsVoidArray* mAttributeList;
nsIDOMElement* mListener;
nsVoidArray* mAttributeList;
nsIDOMElement* mListener;
XULBroadcastListener(const nsString& aAttribute, nsIDOMElement* aListener)
: mAttributeList(nsnull)
{
mListener = aListener; // WEAK REFERENCE
if (aAttribute != "*") {
mAttributeList = new nsVoidArray();
mAttributeList->AppendElement((void*)(new nsString(aAttribute)));
}
// For the "*" case we leave the attribute list nulled out, and this means
// we're observing all attribute changes.
}
~XULBroadcastListener()
{
// Release all the attribute strings.
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
delete str;
}
delete mAttributeList;
}
}
PRBool IsEmpty()
{
if (ObservingEverything())
return PR_FALSE;
PRInt32 count = mAttributeList->Count();
return (count == 0);
}
void RemoveAttribute(const nsString& aString)
{
if (ObservingEverything())
return;
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
if (*str == aString) {
mAttributeList->RemoveElementAt(i);
delete str;
break;
XULBroadcastListener(const nsString& aAttribute, nsIDOMElement* aListener)
: mAttributeList(nsnull)
{
mListener = aListener; // WEAK REFERENCE
if (aAttribute != "*") {
mAttributeList = new nsVoidArray();
mAttributeList->AppendElement((void*)(new nsString(aAttribute)));
}
}
}
}
PRBool ObservingEverything()
{
return (mAttributeList == nsnull);
}
PRBool ObservingAttribute(const nsString& aString)
{
if (ObservingEverything())
return PR_TRUE;
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
if (*str == aString)
return PR_TRUE;
}
// For the "*" case we leave the attribute list nulled out, and this means
// we're observing all attribute changes.
}
return PR_FALSE;
}
~XULBroadcastListener()
{
// Release all the attribute strings.
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
delete str;
}
delete mAttributeList;
}
}
PRBool IsEmpty()
{
if (ObservingEverything())
return PR_FALSE;
PRInt32 count = mAttributeList->Count();
return (count == 0);
}
void RemoveAttribute(const nsString& aString)
{
if (ObservingEverything())
return;
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
if (*str == aString) {
mAttributeList->RemoveElementAt(i);
delete str;
break;
}
}
}
}
PRBool ObservingEverything()
{
return (mAttributeList == nsnull);
}
PRBool ObservingAttribute(const nsString& aString)
{
if (ObservingEverything())
return PR_TRUE;
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
if (*str == aString)
return PR_TRUE;
}
}
return PR_FALSE;
}
};
//----------------------------------------------------------------------
@ -1575,15 +1579,14 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep)
// Release the named reference to the script object so it can
// be garbage collected.
if (mScriptObject) {
nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();
if (nsnull != owner) {
nsIScriptContext *context;
if (NS_OK == owner->GetScriptContext(&context)) {
nsCOMPtr<nsIScriptContextOwner> owner =
dont_AddRef( mDocument->GetScriptContextOwner() );
if (owner) {
nsCOMPtr<nsIScriptContext> context;
if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) {
context->RemoveReference((void*) &mScriptObject, mScriptObject);
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}
}
@ -1593,10 +1596,11 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep)
if (mDocument) {
// Add a named reference to the script object.
if (mScriptObject) {
nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();
if (nsnull != owner) {
nsIScriptContext *context;
if (NS_OK == owner->GetScriptContext(&context)) {
nsCOMPtr<nsIScriptContextOwner> owner =
dont_AddRef( mDocument->GetScriptContextOwner() );
if (owner) {
nsCOMPtr<nsIScriptContext> context;
if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) {
nsAutoString tag;
Tag()->ToString(tag);
@ -1609,10 +1613,7 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep)
if (p != buf)
nsCRT::free(p);
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}
}
@ -2014,8 +2015,8 @@ nsXULElement::SetAttribute(PRInt32 aNameSpaceID,
rv = EnsureSlots();
if (NS_FAILED(rv)) return rv;
// Since EnsureSlots() may have triggered mSlots->mAttributes construction,
// we need to check _again_ before creating attributes.
// Since EnsureSlots() may have triggered mSlots->mAttributes construction,
// we need to check _again_ before creating attributes.
if (! Attributes()) {
rv = nsXULAttributes::Create(NS_STATIC_CAST(nsIStyledContent*, this), &(mSlots->mAttributes));
if (NS_FAILED(rv)) return rv;
@ -2562,13 +2563,15 @@ nsXULElement::HandleDOMEvent(nsIPresContext& aPresContext,
// Node capturing stage
if (NS_EVENT_FLAG_BUBBLE != aFlags) {
if(mParent) {
// Pass off to our parent.
mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
} else if (mDocument != nsnull)
if (mParent) {
// Pass off to our parent.
mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
}
else if (mDocument != nsnull) {
ret = mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
}
}
@ -2660,7 +2663,7 @@ nsXULElement::GetRangeList(nsVoidArray*& aResult) const
NS_IMETHODIMP
nsXULElement::DoCommand()
{
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP
@ -2721,7 +2724,7 @@ nsXULElement::AddBroadcastListener(const nsString& attr, nsIDOMElement* anElemen
return NS_OK;
}
NS_IMETHODIMP
nsXULElement::RemoveBroadcastListener(const nsString& attr, nsIDOMElement* anElement)
@ -2732,7 +2735,7 @@ nsXULElement::RemoveBroadcastListener(const nsString& attr, nsIDOMElement* anEle
for (PRInt32 i = 0; i < count; i++) {
XULBroadcastListener* xulListener =
NS_REINTERPRET_CAST(XULBroadcastListener*, BroadcastListeners()->ElementAt(i));
if (xulListener->mListener == anElement) {
if (xulListener->ObservingEverything() || attr == "*") {
// Do the removal.
@ -3322,102 +3325,104 @@ nsXULElement::IsFocusableContent()
NS_IMETHODIMP
nsXULElement::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
nsresult rv = NS_OK;
aSheet = nsnull;
if (mDocument) {
nsCOMPtr<nsIHTMLContentContainer> container = do_QueryInterface(mDocument);
if (container) {
nsCOMPtr<nsIHTMLStyleSheet> htmlStyleSheet;
rv = container->GetAttributeStyleSheet(getter_AddRefs(htmlStyleSheet));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIStyleSheet> styleSheet = do_QueryInterface(htmlStyleSheet);
aSheet = styleSheet;
NS_IF_ADDREF(aSheet);
nsresult rv = NS_OK;
aSheet = nsnull;
if (mDocument) {
nsCOMPtr<nsIHTMLContentContainer> container = do_QueryInterface(mDocument);
if (container) {
nsCOMPtr<nsIHTMLStyleSheet> htmlStyleSheet;
rv = container->GetAttributeStyleSheet(getter_AddRefs(htmlStyleSheet));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIStyleSheet> styleSheet = do_QueryInterface(htmlStyleSheet);
aSheet = styleSheet;
NS_IF_ADDREF(aSheet);
}
}
}
return rv;
return rv;
}
NS_IMETHODIMP
nsXULElement::GetStrength(PRInt32& aStrength) const
{
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP
nsXULElement::MapFontStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP
nsXULElement::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
if (Tag() == kTreeColAtom) {
// Should only get called if we had a width attribute set. Retrieve it.
nsAutoString widthVal;
GetAttribute("width", widthVal);
if (widthVal != "") {
PRInt32 intVal;
float floatVal;
nsHTMLUnit unit = eHTMLUnit_Null;
if (ParseNumericValue(widthVal, intVal, floatVal, unit)) {
// Success. Update the width for the style context.
nsStylePosition* position = (nsStylePosition*)
aContext->GetMutableStyleData(eStyleStruct_Position);
switch (unit) {
case eHTMLUnit_Percent:
position->mWidth.mUnit = eStyleUnit_Percent;
position->mWidth.mValue.mFloat = floatVal;
break;
if (Tag() == kTreeColAtom) {
// Should only get called if we had a width attribute set. Retrieve it.
nsAutoString widthVal;
GetAttribute("width", widthVal);
if (widthVal != "") {
PRInt32 intVal;
float floatVal;
nsHTMLUnit unit = eHTMLUnit_Null;
if (ParseNumericValue(widthVal, intVal, floatVal, unit)) {
// Success. Update the width for the style context.
nsStylePosition* position = (nsStylePosition*)
aContext->GetMutableStyleData(eStyleStruct_Position);
switch (unit) {
case eHTMLUnit_Percent:
position->mWidth.mUnit = eStyleUnit_Percent;
position->mWidth.mValue.mFloat = floatVal;
break;
case eHTMLUnit_Pixel:
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
position->mWidth.mUnit = eStyleUnit_Coord;
position->mWidth.mValue.mInt = NSIntPixelsToTwips(intVal, p2t);
break;
case eHTMLUnit_Pixel:
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
position->mWidth.mUnit = eStyleUnit_Coord;
position->mWidth.mValue.mInt = NSIntPixelsToTwips(intVal, p2t);
break;
case eHTMLUnit_Proportional:
position->mWidth.mUnit = eStyleUnit_Proportional;
position->mWidth.mValue.mInt = intVal;
break;
default:
break;
case eHTMLUnit_Proportional:
position->mWidth.mUnit = eStyleUnit_Proportional;
position->mWidth.mValue.mInt = intVal;
break;
default:
break;
}
}
}
}
}
}
return NS_OK;
return NS_OK;
}
PRBool
nsXULElement::ParseNumericValue(const nsString& aString,
PRInt32& aIntValue,
float& aFloatValue,
nsHTMLUnit& aValueUnit)
PRInt32& aIntValue,
float& aFloatValue,
nsHTMLUnit& aValueUnit)
{
nsAutoString tmp(aString);
tmp.CompressWhitespace(PR_TRUE, PR_TRUE);
PRInt32 ec, val = tmp.ToInteger(&ec);
if (NS_OK == ec) {
if (val < 0) val = 0;
if (tmp.Last() == '%') {/* XXX not 100% compatible with ebina's code */
if (val > 100) val = 100;
aFloatValue = (float(val)/100.0f);
aValueUnit = eHTMLUnit_Percent;
} else if (tmp.Last() == '*') {
aIntValue = val;
aValueUnit = eHTMLUnit_Proportional;
} else {
aIntValue = val;
aValueUnit = eHTMLUnit_Pixel;
nsAutoString tmp(aString);
tmp.CompressWhitespace(PR_TRUE, PR_TRUE);
PRInt32 ec, val = tmp.ToInteger(&ec);
if (NS_OK == ec) {
if (val < 0) val = 0;
if (tmp.Last() == '%') {/* XXX not 100% compatible with ebina's code */
if (val > 100) val = 100;
aFloatValue = (float(val)/100.0f);
aValueUnit = eHTMLUnit_Percent;
}
else if (tmp.Last() == '*') {
aIntValue = val;
aValueUnit = eHTMLUnit_Proportional;
}
else {
aIntValue = val;
aValueUnit = eHTMLUnit_Pixel;
}
return PR_TRUE;
}
return PR_TRUE;
}
return PR_FALSE;
return PR_FALSE;
}
@ -3580,3 +3585,63 @@ nsXULPrototypeElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, nsStri
return NS_CONTENT_ATTR_NOT_THERE;
}
nsXULPrototypeScript::nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion)
: nsXULPrototypeNode(eType_Script, aLineNo),
mSrcLoading(PR_FALSE),
mSrcLoadWaiters(nsnull),
mScriptRuntime(nsnull),
mScriptObject(nsnull),
mLangVersion(aVersion)
{
MOZ_COUNT_CTOR(nsXULPrototypeScript);
}
nsXULPrototypeScript::~nsXULPrototypeScript()
{
if (mScriptRuntime)
JS_RemoveRootRT(mScriptRuntime, &mScriptObject);
MOZ_COUNT_DTOR(nsXULPrototypeScript);
}
nsresult
nsXULPrototypeScript::Compile(const PRUnichar* aText, PRInt32 aTextLength,
nsIURI* aURI, PRInt32 aLineNo,
nsIDocument* aDocument)
{
nsresult rv;
nsCOMPtr<nsIScriptContextOwner> owner =
dont_AddRef( aDocument->GetScriptContextOwner() );
NS_ASSERTION(owner != nsnull, "document has no script context owner");
if (!owner) {
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIScriptContext> context;
rv = owner->GetScriptContext(getter_AddRefs(context));
if (NS_FAILED(rv)) return rv;
if (!mScriptRuntime) {
JSContext *cx = (JSContext*) context->GetNativeContext();
if (!cx)
return NS_ERROR_UNEXPECTED;
if (!JS_AddNamedRoot(cx, &mScriptObject, "mScriptObject"))
return NS_ERROR_OUT_OF_MEMORY;
mScriptRuntime = JS_GetRuntime(cx);
}
nsCOMPtr<nsIPrincipal> principal =
dont_AddRef(aDocument->GetDocumentPrincipal());
nsXPIDLCString urlspec;
aURI->GetSpec(getter_Copies(urlspec));
rv = context->CompileScript(aText, aTextLength, nsnull,
principal, urlspec, aLineNo, mLangVersion,
(void**) &mScriptObject);
return rv;
}

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

@ -158,23 +158,26 @@ public:
nsresult GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, nsString& aValue);
};
struct JSRuntime;
struct JSObject;
class nsXULDocument;
class nsXULPrototypeScript : public nsXULPrototypeNode
{
public:
nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion)
: nsXULPrototypeNode(eType_Script, aLineNo), mVersion(aVersion)
{
MOZ_COUNT_CTOR(nsXULPrototypeScript);
}
nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion);
virtual ~nsXULPrototypeScript();
virtual ~nsXULPrototypeScript()
{
MOZ_COUNT_DTOR(nsXULPrototypeScript);
}
nsresult Compile(const PRUnichar* aText, PRInt32 aTextLength,
nsIURI* aURI, PRInt32 aLineNo,
nsIDocument* aDocument);
nsCOMPtr<nsIURI> mSrcURI;
nsString mInlineScript;
const char* mVersion;
PRBool mSrcLoading;
nsXULDocument* mSrcLoadWaiters; // [OWNER] but not COMPtr
JSRuntime* mScriptRuntime; // XXX use service, save space?
JSObject* mScriptObject;
const char* mLangVersion;
};
class nsXULPrototypeText : public nsXULPrototypeNode

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

@ -50,9 +50,6 @@ public:
NS_IMETHOD GetStyleSheet(nsIURI* aURI, nsICSSStyleSheet** _result) = 0;
NS_IMETHOD PutStyleSheet(nsICSSStyleSheet* aStyleSheet) = 0;
NS_IMETHOD GetScript(nsIURI* aURI, nsString& aScript, const char** aVersion) = 0;
NS_IMETHOD PutScript(nsIURI* aURI, const nsString& aScript, const char* aVersion) = 0;
/**
* Flush the cache; remove all XUL prototype documents, style
* sheets, and scripts.

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

@ -84,7 +84,7 @@
#include "prlog.h"
#include "prmem.h"
#include "rdfutil.h"
#include "jspubtd.h" // for JSVERSION_*
#include "jsapi.h" // for JSVERSION_*, JS_VersionToString, etc.
#include "nsHTMLTokens.h" // XXX so we can use nsIParserNode::GetTokenType()
@ -729,8 +729,13 @@ XULContentSinkImpl::CloseContainer(const nsIParserNode& aNode)
nsXULPrototypeScript* script =
NS_REINTERPRET_CAST(nsXULPrototypeScript*, node);
script->mInlineScript.SetString(mText, mTextLength);
script->mInlineScript.Trim(" \t\n\r");
// If given a src= attribute, we must ignore script tag content.
if (! script->mSrcURI) {
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
rv = script->Compile(mText, mTextLength, mDocumentURL,
script->mLineNo, doc);
}
FlushText(PR_FALSE);
}
@ -1593,7 +1598,9 @@ XULContentSinkImpl::OpenScript(const nsIParserNode& aNode)
// Don't process scripts that aren't JavaScript
if (isJavaScript) {
nsXULPrototypeScript* script = new nsXULPrototypeScript(/* line number */ -1, jsVersionString);
nsXULPrototypeScript* script =
new nsXULPrototypeScript(aNode.GetSourceLineNumber(),
jsVersionString);
if (! script)
return NS_ERROR_OUT_OF_MEMORY;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -70,7 +70,13 @@ class nsIUnicharStreamLoader;
class nsIXMLElementFactory;
class nsIXULContentUtils;
class nsIXULPrototypeCache;
#if 0 // XXXbe save me, scc (need NSCAP_FORWARD_DECL(nsXULPrototypeScript))
class nsIXULPrototypeScript;
#else
#include "nsXULElement.h"
#endif
struct JSObject;
struct PRLogModuleInfo;
/**
@ -81,7 +87,7 @@ class nsXULDocument : public nsIDocument,
public nsIStreamLoadableDocument,
public nsIDOMXULDocument,
public nsIDOMNSDocument,
public nsIDOMEventCapturer,
public nsIDOMEventCapturer,
public nsIJSScriptObject,
public nsIScriptObjectOwner,
public nsIHTMLContentContainer,
@ -254,8 +260,8 @@ public:
virtual PRBool GetDisplaySelection() const;
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus& aEventStatus);
@ -280,7 +286,6 @@ public:
NS_IMETHOD CreateFromPrototype(const char* aCommand,
nsIXULPrototypeDocument* aPrototype,
nsIPrincipal* aPrincipal,
nsISupports* aContainer);
// nsIStreamLoadableDocument interface
@ -299,9 +304,9 @@ public:
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult);
// nsIDOMEventTarget interface
NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener,
NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener,
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture);
// nsIDOMDocument interface
@ -328,7 +333,7 @@ public:
// nsIDOMXULDocument interface
NS_DECL_IDOMXULDOCUMENT
// nsIDOMNode interface
NS_IMETHOD GetNodeName(nsString& aNodeName);
NS_IMETHOD GetNodeValue(nsString& aNodeValue);
@ -411,7 +416,7 @@ protected:
ParseTagString(const nsString& aTagName, nsIAtom*& aName, PRInt32& aNameSpaceID);
NS_IMETHOD PrepareStyleSheets(nsIURI* anURL);
void SetDocumentURLAndGroup(nsIURI* anURL);
void SetIsPopup(PRBool isPopup) { mIsPopup = isPopup; };
@ -428,6 +433,7 @@ protected:
nsresult
PrepareToLoadPrototype(nsIURI* aURI,
const char* aCommand,
nsIPrincipal* aDocumentPrincipal,
nsIParser** aResult);
nsresult ApplyPersistentAttributes();
@ -481,8 +487,8 @@ protected:
nsresult
DestroyForwardReferences();
// IMPORTANT: The ownership implicit in the following member variables has been
// explicitly checked and set using nsCOMPtr for owning pointers and raw COM interface
// IMPORTANT: The ownership implicit in the following member variables has been
// explicitly checked and set using nsCOMPtr for owning pointers and raw COM interface
// pointers for weak (ie, non owning) references. If you add any members to this
// class, please make the ownership explicit (pinkerton, scc).
// NOTE, THIS IS STILL IN PROGRESS, TALK TO PINK OR SCC BEFORE CHANGING
@ -493,18 +499,19 @@ protected:
nsCOMPtr<nsIURI> mDocumentURL; // [OWNER] ??? compare with loader
nsWeakPtr mDocumentLoadGroup; // [WEAK] leads to loader
nsCOMPtr<nsIPrincipal> mDocumentPrincipal; // [OWNER]
nsCOMPtr<nsIContent> mRootContent; // [OWNER]
nsCOMPtr<nsIContent> mRootContent; // [OWNER]
nsIDocument* mParentDocument; // [WEAK]
nsIScriptContextOwner* mScriptContextOwner; // [WEAK] it owns me! (indirectly)
void* mScriptObject; // ????
nsXULDocument* mNextSrcLoadWaiter; // [OWNER] but not COMPtr
nsString mCharSetID;
nsVoidArray mStyleSheets;
nsCOMPtr<nsIDOMSelection> mSelection; // [OWNER]
nsCOMPtr<nsIDOMSelection> mSelection; // [OWNER]
PRBool mDisplaySelection;
nsVoidArray mPresShells;
nsCOMPtr<nsIEventListenerManager> mListenerManager; // [OWNER]
nsCOMPtr<nsINameSpaceManager> mNameSpaceManager; // [OWNER]
nsCOMPtr<nsIHTMLStyleSheet> mAttrStyleSheet; // [OWNER]
nsCOMPtr<nsINameSpaceManager> mNameSpaceManager; // [OWNER]
nsCOMPtr<nsIHTMLStyleSheet> mAttrStyleSheet; // [OWNER]
nsCOMPtr<nsIHTMLCSSStyleSheet> mInlineStyleSheet; // [OWNER]
nsCOMPtr<nsICSSLoader> mCSSLoader; // [OWNER]
nsElementMap mElementMap;
@ -514,7 +521,7 @@ protected:
nsCOMPtr<nsIWordBreaker> mWordBreaker; // [OWNER]
nsString mCommand;
nsVoidArray mSubDocuments; // [OWNER] of subelements
PRBool mIsPopup;
PRBool mIsPopup;
nsCOMPtr<nsIDOMHTMLFormElement> mHiddenForm; // [OWNER] of this content element
nsCOMPtr<nsIDOMXULCommandDispatcher> mCommandDispatcher; // [OWNER] of the focus tracker
@ -582,14 +589,13 @@ protected:
* prototype construction must 'block' until the load has
* completed, aBlock will be set to true.
*/
nsresult LoadScript(nsIURI* aURI, const char* aVersion, PRBool* aBlock);
nsresult LoadScript(nsXULPrototypeScript *aScriptProto, PRBool* aBlock);
/**
* Evaluate the script text in aScript. aURL and aLineNo
* specify meta-information about the script in order to
* provide useful error messages.
* Execute the precompiled script object scoped by this XUL document's
* containing window object, and using its associated script context.
*/
nsresult EvaluateScript(nsIURI* aURL, const nsString& aScript, PRInt32 aLinenNo, const char* aVersion);
nsresult ExecuteScript(JSObject* aScriptObject);
/**
* Create a delegate content model element from a prototype.
@ -608,13 +614,12 @@ protected:
nsresult AddAttributes(nsXULPrototypeElement* aPrototype, nsIContent* aElement);
/**
* The URL of the current transcluded script that is being loaded.
* For document.write('<script src="nestedwrite.js"><\/script>') to work,
* these need to be in a stack element type, and we need to hold the top
* of stack here.
* The prototype-script of the current transcluded script that is being
* loaded. For document.write('<script src="nestedwrite.js"><\/script>')
* to work, these need to be in a stack element type, and we need to hold
* the top of stack here.
*/
nsCOMPtr<nsIURI> mCurrentScriptURL;
const char* mCurrentScriptLanguageVersion;
nsXULPrototypeScript* mCurrentScriptProto;
/**
* Create a XUL template builder on the specified node if a 'datasources'
@ -704,6 +709,12 @@ protected:
*/
nsCOMPtr<nsIXULPrototypeDocument> mCurrentPrototype;
/**
* The master document (outermost, .xul) prototype, from which
* all subdocuments get their security principals.
*/
nsCOMPtr<nsIXULPrototypeDocument> mMasterPrototype;
/**
* Owning references to all of the prototype documents that were
* used to construct this document.

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

@ -27,7 +27,6 @@
*/
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsICSSStyleSheet.h"
#include "nsIXULPrototypeCache.h"
#include "nsIXULPrototypeDocument.h"
@ -49,9 +48,6 @@ public:
NS_IMETHOD GetStyleSheet(nsIURI* aURI, nsICSSStyleSheet** _result);
NS_IMETHOD PutStyleSheet(nsICSSStyleSheet* aStyleSheet);
NS_IMETHOD GetScript(nsIURI* aURI, nsString& aScript, const char** aVersion);
NS_IMETHOD PutScript(nsIURI* aURI, const nsString& aScript, const char* aVersion);
NS_IMETHOD Flush();
protected:
@ -61,12 +57,8 @@ protected:
nsXULPrototypeCache();
virtual ~nsXULPrototypeCache();
static PRBool
ReleaseScriptEntryEnumFunc(nsHashKey* aKey, void* aData, void* aClosure);
nsSupportsHashtable mPrototypeTable;
nsSupportsHashtable mStyleSheetTable;
nsHashtable mScriptTable;
class nsIURIKey : public nsHashKey {
@ -93,12 +85,6 @@ protected:
return new nsIURIKey(mKey);
}
};
class ScriptEntry {
public:
nsString mScript;
const char* mVersion;
};
};
@ -111,18 +97,9 @@ nsXULPrototypeCache::nsXULPrototypeCache()
nsXULPrototypeCache::~nsXULPrototypeCache()
{
mScriptTable.Enumerate(ReleaseScriptEntryEnumFunc, nsnull);
}
PRBool
nsXULPrototypeCache::ReleaseScriptEntryEnumFunc(nsHashKey* aKey, void* aData, void* aClosure)
{
ScriptEntry* entry = NS_REINTERPRET_CAST(ScriptEntry*, aData);
delete entry;
return PR_TRUE;
}
NS_IMPL_ISUPPORTS1(nsXULPrototypeCache, nsIXULPrototypeCache);
@ -196,48 +173,11 @@ nsXULPrototypeCache::PutStyleSheet(nsICSSStyleSheet* aStyleSheet)
}
NS_IMETHODIMP
nsXULPrototypeCache::GetScript(nsIURI* aURI, nsString& aScript, const char** aVersion)
{
nsIURIKey key(aURI);
const ScriptEntry* entry = NS_REINTERPRET_CAST(const ScriptEntry*, mScriptTable.Get(&key));
if (entry) {
aScript = entry->mScript;
*aVersion = entry->mVersion;
}
else {
aScript.Truncate();
*aVersion = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP
nsXULPrototypeCache::PutScript(nsIURI* aURI, const nsString& aScript, const char* aVersion)
{
ScriptEntry* newentry = new ScriptEntry();
if (! newentry)
return NS_ERROR_OUT_OF_MEMORY;
newentry->mScript = aScript;
newentry->mVersion = aVersion;
nsIURIKey key(aURI);
ScriptEntry* oldentry = NS_REINTERPRET_CAST(ScriptEntry*, mScriptTable.Put(&key, newentry));
delete oldentry;
return NS_OK;
}
NS_IMETHODIMP
nsXULPrototypeCache::Flush()
{
mPrototypeTable.Reset();
mStyleSheetTable.Reset();
mScriptTable.Reset(ReleaseScriptEntryEnumFunc, nsnull);
return NS_OK;
}

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

@ -27,11 +27,14 @@
*/
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
#include "nsIXULPrototypeDocument.h"
#include "nsIURI.h"
#include "nsString2.h"
#include "nsVoidArray.h"
#include "nsIPrincipal.h"
#include "nsISupportsArray.h"
#include "nsIURI.h"
#include "nsIServiceManager.h"
#include "nsIScriptSecurityManager.h"
#include "nsIXULPrototypeDocument.h"
#include "nsXULElement.h"
class nsXULPrototypeDocument : public nsIXULPrototypeDocument
@ -59,11 +62,15 @@ public:
NS_IMETHOD GetHeaderData(nsIAtom* aField, nsString& aData) const;
NS_IMETHOD SetHeaderData(nsIAtom* aField, const nsString& aData);
NS_IMETHOD GetDocumentPrincipal(nsIPrincipal** aResult);
NS_IMETHOD SetDocumentPrincipal(nsIPrincipal* aPrincipal);
protected:
nsCOMPtr<nsIURI> mURI;
nsXULPrototypeElement* mRoot;
nsCOMPtr<nsISupportsArray> mStyleSheetReferences;
nsCOMPtr<nsISupportsArray> mOverlayReferences;
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
nsXULPrototypeDocument();
virtual ~nsXULPrototypeDocument();
@ -229,4 +236,28 @@ nsXULPrototypeDocument::SetHeaderData(nsIAtom* aField, const nsString& aData)
NS_IMETHODIMP
nsXULPrototypeDocument::GetDocumentPrincipal(nsIPrincipal** aResult)
{
if (!mDocumentPrincipal) {
nsresult rv;
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
rv = securityManager->GetCodebasePrincipal(mURI, getter_AddRefs(mDocumentPrincipal));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
}
*aResult = mDocumentPrincipal;
NS_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsXULPrototypeDocument::SetDocumentPrincipal(nsIPrincipal* aPrincipal)
{
mDocumentPrincipal = aPrincipal;
return NS_OK;
}

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

@ -50,9 +50,6 @@ public:
NS_IMETHOD GetStyleSheet(nsIURI* aURI, nsICSSStyleSheet** _result) = 0;
NS_IMETHOD PutStyleSheet(nsICSSStyleSheet* aStyleSheet) = 0;
NS_IMETHOD GetScript(nsIURI* aURI, nsString& aScript, const char** aVersion) = 0;
NS_IMETHOD PutScript(nsIURI* aURI, const nsString& aScript, const char* aVersion) = 0;
/**
* Flush the cache; remove all XUL prototype documents, style
* sheets, and scripts.

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

@ -1,118 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
An XUL-specific extension to nsIXMLDocument. Includes methods for
setting the root resource of the document content model, a factory
method for constructing the children of a node, etc.
XXX This should really be called nsIXULDocument.
*/
#ifndef nsIXULDocument_h___
#define nsIXULDocument_h___
class nsIContent; // XXX nsIXMLDocument.h is bad and doesn't declare this class...
#include "nsIXMLDocument.h"
class nsForwardReference;
class nsIAtom;
class nsIDOMElement;
class nsIDOMHTMLFormElement;
class nsIPrincipal;
class nsIRDFContentModelBuilder;
class nsIRDFResource;
class nsISupportsArray;
class nsIXULPrototypeDocument;
// {954F0811-81DC-11d2-B52A-000000000000}
#define NS_IRDFDOCUMENT_IID \
{ 0x954f0811, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
/**
* RDF document extensions to nsIDocument
*/
class nsIRDFDataSource;
class nsIXULDocument : public nsIXMLDocument
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IRDFDOCUMENT_IID; return iid; }
// The resource-to-element map is a one-to-many mapping of RDF
// resources to content elements.
/**
* Add an entry to the ID-to-element map.
*/
NS_IMETHOD AddElementForID(const nsString& aID, nsIContent* aElement) = 0;
/**
* Remove an entry from the ID-to-element map.
*/
NS_IMETHOD RemoveElementForID(const nsString& aID, nsIContent* aElement) = 0;
/**
* Get the elements for a particular resource in the resource-to-element
* map. The nsISupportsArray will be truncated and filled in with
* nsIContent pointers.
*/
NS_IMETHOD GetElementsForID(const nsString& aID, nsISupportsArray* aElements) = 0;
NS_IMETHOD CreateContents(nsIContent* aElement) = 0;
/**
* Add a content model builder to the document.
*/
NS_IMETHOD AddContentModelBuilder(nsIRDFContentModelBuilder* aBuilder) = 0;
/**
* Manipulate the XUL document's form element
*/
NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm) = 0;
NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm) = 0;
/**
* Add a "forward declaration" of a XUL observer. Such declarations
* will be resolved when document loading completes.
*/
NS_IMETHOD AddForwardReference(nsForwardReference* aForwardReference) = 0;
NS_IMETHOD ResolveForwardReferences() = 0;
/**
* Create a XUL document from a prototype
*/
NS_IMETHOD CreateFromPrototype(const char* aCommand,
nsIXULPrototypeDocument* aPrototype,
nsIPrincipal* aPrincipal,
nsISupports* aContainer) = 0;
};
// factory functions
nsresult NS_NewXULDocument(nsIXULDocument** result);
#endif // nsIXULDocument_h___

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

@ -1,77 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
*/
#ifndef nsIXULPrototypeDocument_h__
#define nsIXULPrototypeDocument_h__
#include "nsISupports.h"
class nsIAtom;
class nsIURI;
class nsIStyleSheet;
class nsString;
class nsVoidArray;
class nsXULPrototypeElement;
// {187A63D0-8337-11d3-BE47-00104BDE6048}
#define NS_IXULPROTOTYPEDOCUMENT_IID \
{ 0x187a63d0, 0x8337, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
class nsIXULPrototypeDocument : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXULPROTOTYPEDOCUMENT_IID);
/**
* Retrieve the URI of the document
*/
NS_IMETHOD SetURI(nsIURI* aURI) = 0;
NS_IMETHOD GetURI(nsIURI** aResult) = 0;
/**
* Retrieve the root XULPrototype element of the document.
*/
NS_IMETHOD GetRootElement(nsXULPrototypeElement** aResult) = 0;
NS_IMETHOD SetRootElement(nsXULPrototypeElement* aElement) = 0;
NS_IMETHOD AddStyleSheetReference(nsIURI* aStyleSheet) = 0;
NS_IMETHOD GetStyleSheetReferences(nsISupportsArray** aResult) = 0;
NS_IMETHOD AddOverlayReference(nsIURI* aURI) = 0;
NS_IMETHOD GetOverlayReferences(nsISupportsArray** aResult) = 0;
NS_IMETHOD GetHeaderData(nsIAtom* aField, nsString& aData) const = 0;
NS_IMETHOD SetHeaderData(nsIAtom* aField, const nsString& aData) = 0;
};
extern NS_IMETHODIMP
NS_NewXULPrototypeDocument(nsISupports* aOuter, REFNSIID aIID, void** aResult);
#endif // nsIXULPrototypeDocument_h__

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

@ -84,7 +84,7 @@
#include "prlog.h"
#include "prmem.h"
#include "rdfutil.h"
#include "jspubtd.h" // for JSVERSION_*
#include "jsapi.h" // for JSVERSION_*, JS_VersionToString, etc.
#include "nsHTMLTokens.h" // XXX so we can use nsIParserNode::GetTokenType()
@ -729,8 +729,13 @@ XULContentSinkImpl::CloseContainer(const nsIParserNode& aNode)
nsXULPrototypeScript* script =
NS_REINTERPRET_CAST(nsXULPrototypeScript*, node);
script->mInlineScript.SetString(mText, mTextLength);
script->mInlineScript.Trim(" \t\n\r");
// If given a src= attribute, we must ignore script tag content.
if (! script->mSrcURI) {
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
rv = script->Compile(mText, mTextLength, mDocumentURL,
script->mLineNo, doc);
}
FlushText(PR_FALSE);
}
@ -1593,7 +1598,9 @@ XULContentSinkImpl::OpenScript(const nsIParserNode& aNode)
// Don't process scripts that aren't JavaScript
if (isJavaScript) {
nsXULPrototypeScript* script = new nsXULPrototypeScript(/* line number */ -1, jsVersionString);
nsXULPrototypeScript* script =
new nsXULPrototypeScript(aNode.GetSourceLineNumber(),
jsVersionString);
if (! script)
return NS_ERROR_OUT_OF_MEMORY;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -70,7 +70,13 @@ class nsIUnicharStreamLoader;
class nsIXMLElementFactory;
class nsIXULContentUtils;
class nsIXULPrototypeCache;
#if 0 // XXXbe save me, scc (need NSCAP_FORWARD_DECL(nsXULPrototypeScript))
class nsIXULPrototypeScript;
#else
#include "nsXULElement.h"
#endif
struct JSObject;
struct PRLogModuleInfo;
/**
@ -81,7 +87,7 @@ class nsXULDocument : public nsIDocument,
public nsIStreamLoadableDocument,
public nsIDOMXULDocument,
public nsIDOMNSDocument,
public nsIDOMEventCapturer,
public nsIDOMEventCapturer,
public nsIJSScriptObject,
public nsIScriptObjectOwner,
public nsIHTMLContentContainer,
@ -254,8 +260,8 @@ public:
virtual PRBool GetDisplaySelection() const;
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus& aEventStatus);
@ -280,7 +286,6 @@ public:
NS_IMETHOD CreateFromPrototype(const char* aCommand,
nsIXULPrototypeDocument* aPrototype,
nsIPrincipal* aPrincipal,
nsISupports* aContainer);
// nsIStreamLoadableDocument interface
@ -299,9 +304,9 @@ public:
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult);
// nsIDOMEventTarget interface
NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener,
NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener,
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture);
// nsIDOMDocument interface
@ -328,7 +333,7 @@ public:
// nsIDOMXULDocument interface
NS_DECL_IDOMXULDOCUMENT
// nsIDOMNode interface
NS_IMETHOD GetNodeName(nsString& aNodeName);
NS_IMETHOD GetNodeValue(nsString& aNodeValue);
@ -411,7 +416,7 @@ protected:
ParseTagString(const nsString& aTagName, nsIAtom*& aName, PRInt32& aNameSpaceID);
NS_IMETHOD PrepareStyleSheets(nsIURI* anURL);
void SetDocumentURLAndGroup(nsIURI* anURL);
void SetIsPopup(PRBool isPopup) { mIsPopup = isPopup; };
@ -428,6 +433,7 @@ protected:
nsresult
PrepareToLoadPrototype(nsIURI* aURI,
const char* aCommand,
nsIPrincipal* aDocumentPrincipal,
nsIParser** aResult);
nsresult ApplyPersistentAttributes();
@ -481,8 +487,8 @@ protected:
nsresult
DestroyForwardReferences();
// IMPORTANT: The ownership implicit in the following member variables has been
// explicitly checked and set using nsCOMPtr for owning pointers and raw COM interface
// IMPORTANT: The ownership implicit in the following member variables has been
// explicitly checked and set using nsCOMPtr for owning pointers and raw COM interface
// pointers for weak (ie, non owning) references. If you add any members to this
// class, please make the ownership explicit (pinkerton, scc).
// NOTE, THIS IS STILL IN PROGRESS, TALK TO PINK OR SCC BEFORE CHANGING
@ -493,18 +499,19 @@ protected:
nsCOMPtr<nsIURI> mDocumentURL; // [OWNER] ??? compare with loader
nsWeakPtr mDocumentLoadGroup; // [WEAK] leads to loader
nsCOMPtr<nsIPrincipal> mDocumentPrincipal; // [OWNER]
nsCOMPtr<nsIContent> mRootContent; // [OWNER]
nsCOMPtr<nsIContent> mRootContent; // [OWNER]
nsIDocument* mParentDocument; // [WEAK]
nsIScriptContextOwner* mScriptContextOwner; // [WEAK] it owns me! (indirectly)
void* mScriptObject; // ????
nsXULDocument* mNextSrcLoadWaiter; // [OWNER] but not COMPtr
nsString mCharSetID;
nsVoidArray mStyleSheets;
nsCOMPtr<nsIDOMSelection> mSelection; // [OWNER]
nsCOMPtr<nsIDOMSelection> mSelection; // [OWNER]
PRBool mDisplaySelection;
nsVoidArray mPresShells;
nsCOMPtr<nsIEventListenerManager> mListenerManager; // [OWNER]
nsCOMPtr<nsINameSpaceManager> mNameSpaceManager; // [OWNER]
nsCOMPtr<nsIHTMLStyleSheet> mAttrStyleSheet; // [OWNER]
nsCOMPtr<nsINameSpaceManager> mNameSpaceManager; // [OWNER]
nsCOMPtr<nsIHTMLStyleSheet> mAttrStyleSheet; // [OWNER]
nsCOMPtr<nsIHTMLCSSStyleSheet> mInlineStyleSheet; // [OWNER]
nsCOMPtr<nsICSSLoader> mCSSLoader; // [OWNER]
nsElementMap mElementMap;
@ -514,7 +521,7 @@ protected:
nsCOMPtr<nsIWordBreaker> mWordBreaker; // [OWNER]
nsString mCommand;
nsVoidArray mSubDocuments; // [OWNER] of subelements
PRBool mIsPopup;
PRBool mIsPopup;
nsCOMPtr<nsIDOMHTMLFormElement> mHiddenForm; // [OWNER] of this content element
nsCOMPtr<nsIDOMXULCommandDispatcher> mCommandDispatcher; // [OWNER] of the focus tracker
@ -582,14 +589,13 @@ protected:
* prototype construction must 'block' until the load has
* completed, aBlock will be set to true.
*/
nsresult LoadScript(nsIURI* aURI, const char* aVersion, PRBool* aBlock);
nsresult LoadScript(nsXULPrototypeScript *aScriptProto, PRBool* aBlock);
/**
* Evaluate the script text in aScript. aURL and aLineNo
* specify meta-information about the script in order to
* provide useful error messages.
* Execute the precompiled script object scoped by this XUL document's
* containing window object, and using its associated script context.
*/
nsresult EvaluateScript(nsIURI* aURL, const nsString& aScript, PRInt32 aLinenNo, const char* aVersion);
nsresult ExecuteScript(JSObject* aScriptObject);
/**
* Create a delegate content model element from a prototype.
@ -608,13 +614,12 @@ protected:
nsresult AddAttributes(nsXULPrototypeElement* aPrototype, nsIContent* aElement);
/**
* The URL of the current transcluded script that is being loaded.
* For document.write('<script src="nestedwrite.js"><\/script>') to work,
* these need to be in a stack element type, and we need to hold the top
* of stack here.
* The prototype-script of the current transcluded script that is being
* loaded. For document.write('<script src="nestedwrite.js"><\/script>')
* to work, these need to be in a stack element type, and we need to hold
* the top of stack here.
*/
nsCOMPtr<nsIURI> mCurrentScriptURL;
const char* mCurrentScriptLanguageVersion;
nsXULPrototypeScript* mCurrentScriptProto;
/**
* Create a XUL template builder on the specified node if a 'datasources'
@ -704,6 +709,12 @@ protected:
*/
nsCOMPtr<nsIXULPrototypeDocument> mCurrentPrototype;
/**
* The master document (outermost, .xul) prototype, from which
* all subdocuments get their security principals.
*/
nsCOMPtr<nsIXULPrototypeDocument> mMasterPrototype;
/**
* Owning references to all of the prototype documents that were
* used to construct this document.

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

@ -35,6 +35,7 @@
#include "nsDOMCID.h"
#include "nsDOMEvent.h"
#include "nsForwardReference.h"
#include "nsXPIDLString.h"
#include "nsXULAttributes.h"
#include "nsIXULPopupListener.h"
#include "nsIHTMLContentContainer.h"
@ -56,6 +57,7 @@
#include "nsIJSScriptObject.h"
#include "nsINameSpace.h"
#include "nsINameSpaceManager.h"
#include "nsIPrincipal.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIRDFNode.h"
@ -71,6 +73,7 @@
#include "nsStyleConsts.h"
#include "nsIStyleSheet.h"
#include "nsIHTMLStyleSheet.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
#include "nsIStyledContent.h"
#include "nsIStyleContext.h"
@ -86,6 +89,7 @@
#include "prlog.h"
#include "rdf.h"
#include "nsHTMLValue.h"
#include "jsapi.h" // for JS_AddNamedRoot and JS_RemoveRootRT
#include "nsIControllers.h"
@ -135,84 +139,84 @@ static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
struct XULBroadcastListener
{
nsVoidArray* mAttributeList;
nsIDOMElement* mListener;
nsVoidArray* mAttributeList;
nsIDOMElement* mListener;
XULBroadcastListener(const nsString& aAttribute, nsIDOMElement* aListener)
: mAttributeList(nsnull)
{
mListener = aListener; // WEAK REFERENCE
if (aAttribute != "*") {
mAttributeList = new nsVoidArray();
mAttributeList->AppendElement((void*)(new nsString(aAttribute)));
}
// For the "*" case we leave the attribute list nulled out, and this means
// we're observing all attribute changes.
}
~XULBroadcastListener()
{
// Release all the attribute strings.
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
delete str;
}
delete mAttributeList;
}
}
PRBool IsEmpty()
{
if (ObservingEverything())
return PR_FALSE;
PRInt32 count = mAttributeList->Count();
return (count == 0);
}
void RemoveAttribute(const nsString& aString)
{
if (ObservingEverything())
return;
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
if (*str == aString) {
mAttributeList->RemoveElementAt(i);
delete str;
break;
XULBroadcastListener(const nsString& aAttribute, nsIDOMElement* aListener)
: mAttributeList(nsnull)
{
mListener = aListener; // WEAK REFERENCE
if (aAttribute != "*") {
mAttributeList = new nsVoidArray();
mAttributeList->AppendElement((void*)(new nsString(aAttribute)));
}
}
}
}
PRBool ObservingEverything()
{
return (mAttributeList == nsnull);
}
PRBool ObservingAttribute(const nsString& aString)
{
if (ObservingEverything())
return PR_TRUE;
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
if (*str == aString)
return PR_TRUE;
}
// For the "*" case we leave the attribute list nulled out, and this means
// we're observing all attribute changes.
}
return PR_FALSE;
}
~XULBroadcastListener()
{
// Release all the attribute strings.
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
delete str;
}
delete mAttributeList;
}
}
PRBool IsEmpty()
{
if (ObservingEverything())
return PR_FALSE;
PRInt32 count = mAttributeList->Count();
return (count == 0);
}
void RemoveAttribute(const nsString& aString)
{
if (ObservingEverything())
return;
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
if (*str == aString) {
mAttributeList->RemoveElementAt(i);
delete str;
break;
}
}
}
}
PRBool ObservingEverything()
{
return (mAttributeList == nsnull);
}
PRBool ObservingAttribute(const nsString& aString)
{
if (ObservingEverything())
return PR_TRUE;
if (mAttributeList) {
PRInt32 count = mAttributeList->Count();
for (PRInt32 i = 0; i < count; i++) {
nsString* str = (nsString*)(mAttributeList->ElementAt(i));
if (*str == aString)
return PR_TRUE;
}
}
return PR_FALSE;
}
};
//----------------------------------------------------------------------
@ -1575,15 +1579,14 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep)
// Release the named reference to the script object so it can
// be garbage collected.
if (mScriptObject) {
nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();
if (nsnull != owner) {
nsIScriptContext *context;
if (NS_OK == owner->GetScriptContext(&context)) {
nsCOMPtr<nsIScriptContextOwner> owner =
dont_AddRef( mDocument->GetScriptContextOwner() );
if (owner) {
nsCOMPtr<nsIScriptContext> context;
if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) {
context->RemoveReference((void*) &mScriptObject, mScriptObject);
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}
}
@ -1593,10 +1596,11 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep)
if (mDocument) {
// Add a named reference to the script object.
if (mScriptObject) {
nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();
if (nsnull != owner) {
nsIScriptContext *context;
if (NS_OK == owner->GetScriptContext(&context)) {
nsCOMPtr<nsIScriptContextOwner> owner =
dont_AddRef( mDocument->GetScriptContextOwner() );
if (owner) {
nsCOMPtr<nsIScriptContext> context;
if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) {
nsAutoString tag;
Tag()->ToString(tag);
@ -1609,10 +1613,7 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep)
if (p != buf)
nsCRT::free(p);
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}
}
@ -2014,8 +2015,8 @@ nsXULElement::SetAttribute(PRInt32 aNameSpaceID,
rv = EnsureSlots();
if (NS_FAILED(rv)) return rv;
// Since EnsureSlots() may have triggered mSlots->mAttributes construction,
// we need to check _again_ before creating attributes.
// Since EnsureSlots() may have triggered mSlots->mAttributes construction,
// we need to check _again_ before creating attributes.
if (! Attributes()) {
rv = nsXULAttributes::Create(NS_STATIC_CAST(nsIStyledContent*, this), &(mSlots->mAttributes));
if (NS_FAILED(rv)) return rv;
@ -2562,13 +2563,15 @@ nsXULElement::HandleDOMEvent(nsIPresContext& aPresContext,
// Node capturing stage
if (NS_EVENT_FLAG_BUBBLE != aFlags) {
if(mParent) {
// Pass off to our parent.
mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
} else if (mDocument != nsnull)
if (mParent) {
// Pass off to our parent.
mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
}
else if (mDocument != nsnull) {
ret = mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
NS_EVENT_FLAG_CAPTURE, aEventStatus);
}
}
@ -2660,7 +2663,7 @@ nsXULElement::GetRangeList(nsVoidArray*& aResult) const
NS_IMETHODIMP
nsXULElement::DoCommand()
{
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP
@ -2721,7 +2724,7 @@ nsXULElement::AddBroadcastListener(const nsString& attr, nsIDOMElement* anElemen
return NS_OK;
}
NS_IMETHODIMP
nsXULElement::RemoveBroadcastListener(const nsString& attr, nsIDOMElement* anElement)
@ -2732,7 +2735,7 @@ nsXULElement::RemoveBroadcastListener(const nsString& attr, nsIDOMElement* anEle
for (PRInt32 i = 0; i < count; i++) {
XULBroadcastListener* xulListener =
NS_REINTERPRET_CAST(XULBroadcastListener*, BroadcastListeners()->ElementAt(i));
if (xulListener->mListener == anElement) {
if (xulListener->ObservingEverything() || attr == "*") {
// Do the removal.
@ -3322,102 +3325,104 @@ nsXULElement::IsFocusableContent()
NS_IMETHODIMP
nsXULElement::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
nsresult rv = NS_OK;
aSheet = nsnull;
if (mDocument) {
nsCOMPtr<nsIHTMLContentContainer> container = do_QueryInterface(mDocument);
if (container) {
nsCOMPtr<nsIHTMLStyleSheet> htmlStyleSheet;
rv = container->GetAttributeStyleSheet(getter_AddRefs(htmlStyleSheet));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIStyleSheet> styleSheet = do_QueryInterface(htmlStyleSheet);
aSheet = styleSheet;
NS_IF_ADDREF(aSheet);
nsresult rv = NS_OK;
aSheet = nsnull;
if (mDocument) {
nsCOMPtr<nsIHTMLContentContainer> container = do_QueryInterface(mDocument);
if (container) {
nsCOMPtr<nsIHTMLStyleSheet> htmlStyleSheet;
rv = container->GetAttributeStyleSheet(getter_AddRefs(htmlStyleSheet));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIStyleSheet> styleSheet = do_QueryInterface(htmlStyleSheet);
aSheet = styleSheet;
NS_IF_ADDREF(aSheet);
}
}
}
return rv;
return rv;
}
NS_IMETHODIMP
nsXULElement::GetStrength(PRInt32& aStrength) const
{
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP
nsXULElement::MapFontStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
return NS_OK;
}
NS_IMETHODIMP
nsXULElement::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
if (Tag() == kTreeColAtom) {
// Should only get called if we had a width attribute set. Retrieve it.
nsAutoString widthVal;
GetAttribute("width", widthVal);
if (widthVal != "") {
PRInt32 intVal;
float floatVal;
nsHTMLUnit unit = eHTMLUnit_Null;
if (ParseNumericValue(widthVal, intVal, floatVal, unit)) {
// Success. Update the width for the style context.
nsStylePosition* position = (nsStylePosition*)
aContext->GetMutableStyleData(eStyleStruct_Position);
switch (unit) {
case eHTMLUnit_Percent:
position->mWidth.mUnit = eStyleUnit_Percent;
position->mWidth.mValue.mFloat = floatVal;
break;
if (Tag() == kTreeColAtom) {
// Should only get called if we had a width attribute set. Retrieve it.
nsAutoString widthVal;
GetAttribute("width", widthVal);
if (widthVal != "") {
PRInt32 intVal;
float floatVal;
nsHTMLUnit unit = eHTMLUnit_Null;
if (ParseNumericValue(widthVal, intVal, floatVal, unit)) {
// Success. Update the width for the style context.
nsStylePosition* position = (nsStylePosition*)
aContext->GetMutableStyleData(eStyleStruct_Position);
switch (unit) {
case eHTMLUnit_Percent:
position->mWidth.mUnit = eStyleUnit_Percent;
position->mWidth.mValue.mFloat = floatVal;
break;
case eHTMLUnit_Pixel:
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
position->mWidth.mUnit = eStyleUnit_Coord;
position->mWidth.mValue.mInt = NSIntPixelsToTwips(intVal, p2t);
break;
case eHTMLUnit_Pixel:
float p2t;
aPresContext->GetScaledPixelsToTwips(&p2t);
position->mWidth.mUnit = eStyleUnit_Coord;
position->mWidth.mValue.mInt = NSIntPixelsToTwips(intVal, p2t);
break;
case eHTMLUnit_Proportional:
position->mWidth.mUnit = eStyleUnit_Proportional;
position->mWidth.mValue.mInt = intVal;
break;
default:
break;
case eHTMLUnit_Proportional:
position->mWidth.mUnit = eStyleUnit_Proportional;
position->mWidth.mValue.mInt = intVal;
break;
default:
break;
}
}
}
}
}
}
return NS_OK;
return NS_OK;
}
PRBool
nsXULElement::ParseNumericValue(const nsString& aString,
PRInt32& aIntValue,
float& aFloatValue,
nsHTMLUnit& aValueUnit)
PRInt32& aIntValue,
float& aFloatValue,
nsHTMLUnit& aValueUnit)
{
nsAutoString tmp(aString);
tmp.CompressWhitespace(PR_TRUE, PR_TRUE);
PRInt32 ec, val = tmp.ToInteger(&ec);
if (NS_OK == ec) {
if (val < 0) val = 0;
if (tmp.Last() == '%') {/* XXX not 100% compatible with ebina's code */
if (val > 100) val = 100;
aFloatValue = (float(val)/100.0f);
aValueUnit = eHTMLUnit_Percent;
} else if (tmp.Last() == '*') {
aIntValue = val;
aValueUnit = eHTMLUnit_Proportional;
} else {
aIntValue = val;
aValueUnit = eHTMLUnit_Pixel;
nsAutoString tmp(aString);
tmp.CompressWhitespace(PR_TRUE, PR_TRUE);
PRInt32 ec, val = tmp.ToInteger(&ec);
if (NS_OK == ec) {
if (val < 0) val = 0;
if (tmp.Last() == '%') {/* XXX not 100% compatible with ebina's code */
if (val > 100) val = 100;
aFloatValue = (float(val)/100.0f);
aValueUnit = eHTMLUnit_Percent;
}
else if (tmp.Last() == '*') {
aIntValue = val;
aValueUnit = eHTMLUnit_Proportional;
}
else {
aIntValue = val;
aValueUnit = eHTMLUnit_Pixel;
}
return PR_TRUE;
}
return PR_TRUE;
}
return PR_FALSE;
return PR_FALSE;
}
@ -3580,3 +3585,63 @@ nsXULPrototypeElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, nsStri
return NS_CONTENT_ATTR_NOT_THERE;
}
nsXULPrototypeScript::nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion)
: nsXULPrototypeNode(eType_Script, aLineNo),
mSrcLoading(PR_FALSE),
mSrcLoadWaiters(nsnull),
mScriptRuntime(nsnull),
mScriptObject(nsnull),
mLangVersion(aVersion)
{
MOZ_COUNT_CTOR(nsXULPrototypeScript);
}
nsXULPrototypeScript::~nsXULPrototypeScript()
{
if (mScriptRuntime)
JS_RemoveRootRT(mScriptRuntime, &mScriptObject);
MOZ_COUNT_DTOR(nsXULPrototypeScript);
}
nsresult
nsXULPrototypeScript::Compile(const PRUnichar* aText, PRInt32 aTextLength,
nsIURI* aURI, PRInt32 aLineNo,
nsIDocument* aDocument)
{
nsresult rv;
nsCOMPtr<nsIScriptContextOwner> owner =
dont_AddRef( aDocument->GetScriptContextOwner() );
NS_ASSERTION(owner != nsnull, "document has no script context owner");
if (!owner) {
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIScriptContext> context;
rv = owner->GetScriptContext(getter_AddRefs(context));
if (NS_FAILED(rv)) return rv;
if (!mScriptRuntime) {
JSContext *cx = (JSContext*) context->GetNativeContext();
if (!cx)
return NS_ERROR_UNEXPECTED;
if (!JS_AddNamedRoot(cx, &mScriptObject, "mScriptObject"))
return NS_ERROR_OUT_OF_MEMORY;
mScriptRuntime = JS_GetRuntime(cx);
}
nsCOMPtr<nsIPrincipal> principal =
dont_AddRef(aDocument->GetDocumentPrincipal());
nsXPIDLCString urlspec;
aURI->GetSpec(getter_Copies(urlspec));
rv = context->CompileScript(aText, aTextLength, nsnull,
principal, urlspec, aLineNo, mLangVersion,
(void**) &mScriptObject);
return rv;
}

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

@ -158,23 +158,26 @@ public:
nsresult GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, nsString& aValue);
};
struct JSRuntime;
struct JSObject;
class nsXULDocument;
class nsXULPrototypeScript : public nsXULPrototypeNode
{
public:
nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion)
: nsXULPrototypeNode(eType_Script, aLineNo), mVersion(aVersion)
{
MOZ_COUNT_CTOR(nsXULPrototypeScript);
}
nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion);
virtual ~nsXULPrototypeScript();
virtual ~nsXULPrototypeScript()
{
MOZ_COUNT_DTOR(nsXULPrototypeScript);
}
nsresult Compile(const PRUnichar* aText, PRInt32 aTextLength,
nsIURI* aURI, PRInt32 aLineNo,
nsIDocument* aDocument);
nsCOMPtr<nsIURI> mSrcURI;
nsString mInlineScript;
const char* mVersion;
PRBool mSrcLoading;
nsXULDocument* mSrcLoadWaiters; // [OWNER] but not COMPtr
JSRuntime* mScriptRuntime; // XXX use service, save space?
JSObject* mScriptObject;
const char* mLangVersion;
};
class nsXULPrototypeText : public nsXULPrototypeNode

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

@ -27,7 +27,6 @@
*/
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsICSSStyleSheet.h"
#include "nsIXULPrototypeCache.h"
#include "nsIXULPrototypeDocument.h"
@ -49,9 +48,6 @@ public:
NS_IMETHOD GetStyleSheet(nsIURI* aURI, nsICSSStyleSheet** _result);
NS_IMETHOD PutStyleSheet(nsICSSStyleSheet* aStyleSheet);
NS_IMETHOD GetScript(nsIURI* aURI, nsString& aScript, const char** aVersion);
NS_IMETHOD PutScript(nsIURI* aURI, const nsString& aScript, const char* aVersion);
NS_IMETHOD Flush();
protected:
@ -61,12 +57,8 @@ protected:
nsXULPrototypeCache();
virtual ~nsXULPrototypeCache();
static PRBool
ReleaseScriptEntryEnumFunc(nsHashKey* aKey, void* aData, void* aClosure);
nsSupportsHashtable mPrototypeTable;
nsSupportsHashtable mStyleSheetTable;
nsHashtable mScriptTable;
class nsIURIKey : public nsHashKey {
@ -93,12 +85,6 @@ protected:
return new nsIURIKey(mKey);
}
};
class ScriptEntry {
public:
nsString mScript;
const char* mVersion;
};
};
@ -111,18 +97,9 @@ nsXULPrototypeCache::nsXULPrototypeCache()
nsXULPrototypeCache::~nsXULPrototypeCache()
{
mScriptTable.Enumerate(ReleaseScriptEntryEnumFunc, nsnull);
}
PRBool
nsXULPrototypeCache::ReleaseScriptEntryEnumFunc(nsHashKey* aKey, void* aData, void* aClosure)
{
ScriptEntry* entry = NS_REINTERPRET_CAST(ScriptEntry*, aData);
delete entry;
return PR_TRUE;
}
NS_IMPL_ISUPPORTS1(nsXULPrototypeCache, nsIXULPrototypeCache);
@ -196,48 +173,11 @@ nsXULPrototypeCache::PutStyleSheet(nsICSSStyleSheet* aStyleSheet)
}
NS_IMETHODIMP
nsXULPrototypeCache::GetScript(nsIURI* aURI, nsString& aScript, const char** aVersion)
{
nsIURIKey key(aURI);
const ScriptEntry* entry = NS_REINTERPRET_CAST(const ScriptEntry*, mScriptTable.Get(&key));
if (entry) {
aScript = entry->mScript;
*aVersion = entry->mVersion;
}
else {
aScript.Truncate();
*aVersion = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP
nsXULPrototypeCache::PutScript(nsIURI* aURI, const nsString& aScript, const char* aVersion)
{
ScriptEntry* newentry = new ScriptEntry();
if (! newentry)
return NS_ERROR_OUT_OF_MEMORY;
newentry->mScript = aScript;
newentry->mVersion = aVersion;
nsIURIKey key(aURI);
ScriptEntry* oldentry = NS_REINTERPRET_CAST(ScriptEntry*, mScriptTable.Put(&key, newentry));
delete oldentry;
return NS_OK;
}
NS_IMETHODIMP
nsXULPrototypeCache::Flush()
{
mPrototypeTable.Reset();
mStyleSheetTable.Reset();
mScriptTable.Reset(ReleaseScriptEntryEnumFunc, nsnull);
return NS_OK;
}

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

@ -27,11 +27,14 @@
*/
#include "nsCOMPtr.h"
#include "nsISupportsArray.h"
#include "nsIXULPrototypeDocument.h"
#include "nsIURI.h"
#include "nsString2.h"
#include "nsVoidArray.h"
#include "nsIPrincipal.h"
#include "nsISupportsArray.h"
#include "nsIURI.h"
#include "nsIServiceManager.h"
#include "nsIScriptSecurityManager.h"
#include "nsIXULPrototypeDocument.h"
#include "nsXULElement.h"
class nsXULPrototypeDocument : public nsIXULPrototypeDocument
@ -59,11 +62,15 @@ public:
NS_IMETHOD GetHeaderData(nsIAtom* aField, nsString& aData) const;
NS_IMETHOD SetHeaderData(nsIAtom* aField, const nsString& aData);
NS_IMETHOD GetDocumentPrincipal(nsIPrincipal** aResult);
NS_IMETHOD SetDocumentPrincipal(nsIPrincipal* aPrincipal);
protected:
nsCOMPtr<nsIURI> mURI;
nsXULPrototypeElement* mRoot;
nsCOMPtr<nsISupportsArray> mStyleSheetReferences;
nsCOMPtr<nsISupportsArray> mOverlayReferences;
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
nsXULPrototypeDocument();
virtual ~nsXULPrototypeDocument();
@ -229,4 +236,28 @@ nsXULPrototypeDocument::SetHeaderData(nsIAtom* aField, const nsString& aData)
NS_IMETHODIMP
nsXULPrototypeDocument::GetDocumentPrincipal(nsIPrincipal** aResult)
{
if (!mDocumentPrincipal) {
nsresult rv;
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
rv = securityManager->GetCodebasePrincipal(mURI, getter_AddRefs(mDocumentPrincipal));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
}
*aResult = mDocumentPrincipal;
NS_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsXULPrototypeDocument::SetDocumentPrincipal(nsIPrincipal* aPrincipal)
{
mDocumentPrincipal = aPrincipal;
return NS_OK;
}