mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 13:07:52 +00:00
Work in progres to get out-of-line document.write working. Created Reset() method in nsDocument. Fix for bug 1668.
This commit is contained in:
parent
6d3a1438bd
commit
2934b39e2c
@ -528,11 +528,7 @@ NS_IMPL_RELEASE(nsDocument)
|
||||
nsresult nsDocument::Init()
|
||||
{
|
||||
nsresult rv = NS_NewHeapArena(&mArena, nsnull);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = NS_NewNameSpaceManager(&mNameSpaceManager);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -545,12 +541,26 @@ nsIArena* nsDocument::GetArena()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDocument::StartDocLoad(nsIURL *aURL,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener)
|
||||
nsDocument::Reset(nsIURL *aURL)
|
||||
{
|
||||
// Delete references to style sheets - this should be done in superclass...
|
||||
PRInt32 index = mStyleSheets.Count();
|
||||
if (nsnull != mDocumentTitle) {
|
||||
delete mDocumentTitle;
|
||||
mDocumentTitle = nsnull;
|
||||
}
|
||||
NS_IF_RELEASE(mDocumentURL);
|
||||
NS_IF_RELEASE(mDocumentURLGroup);
|
||||
|
||||
// Delete references to sub-documents
|
||||
PRInt32 index = mSubDocuments.Count();
|
||||
while (--index >= 0) {
|
||||
nsIDocument* subdoc = (nsIDocument*) mSubDocuments.ElementAt(index);
|
||||
NS_RELEASE(subdoc);
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mRootContent);
|
||||
|
||||
// Delete references to style sheets
|
||||
index = mStyleSheets.Count();
|
||||
while (--index >= 0) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(index);
|
||||
sheet->SetOwningDocument(nsnull);
|
||||
@ -558,11 +568,22 @@ nsDocument::StartDocLoad(nsIURL *aURL,
|
||||
}
|
||||
mStyleSheets.Clear();
|
||||
|
||||
NS_IF_RELEASE(mDocumentURL);
|
||||
NS_IF_RELEASE(mDocumentURLGroup);
|
||||
if (nsnull != mDocumentTitle) {
|
||||
delete mDocumentTitle;
|
||||
mDocumentTitle = nsnull;
|
||||
NS_IF_RELEASE(mListenerManager);
|
||||
NS_IF_RELEASE(mDOMStyleSheets);
|
||||
|
||||
NS_IF_RELEASE(mNameSpaceManager);
|
||||
return NS_NewNameSpaceManager(&mNameSpaceManager);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDocument::StartDocumentLoad(nsIURL *aURL,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand)
|
||||
{
|
||||
nsresult result = Reset(aURL);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
mDocumentURL = aURL;
|
||||
|
@ -65,6 +65,11 @@ public:
|
||||
|
||||
virtual nsIArena* GetArena();
|
||||
|
||||
NS_IMETHOD StartDocumentLoad(nsIURL *aUrl,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand);
|
||||
|
||||
/**
|
||||
* Return the title of the document. May return null.
|
||||
*/
|
||||
@ -291,12 +296,10 @@ protected:
|
||||
nsIContent* FindContent(const nsIContent* aStartNode,
|
||||
const nsIContent* aTest1,
|
||||
const nsIContent* aTest2) const;
|
||||
virtual nsresult Reset(nsIURL* aURL);
|
||||
|
||||
protected:
|
||||
|
||||
virtual nsresult StartDocLoad(nsIURL *aUrl,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener);
|
||||
|
||||
virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); // subclass hook
|
||||
|
||||
|
@ -202,18 +202,32 @@ nsrefcnt nsHTMLDocument::Release()
|
||||
return nsDocument::Release();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand)
|
||||
nsresult
|
||||
nsHTMLDocument::Reset(nsIURL *aURL)
|
||||
{
|
||||
nsresult rv = nsDocument::StartDocLoad(aURL, aContainer, aDocListener);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
nsresult result = nsDocument::Reset(aURL);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
nsIWebShell* webShell;
|
||||
PRInt32 i;
|
||||
|
||||
DeleteNamedItems();
|
||||
NS_IF_RELEASE(mImages);
|
||||
NS_IF_RELEASE(mApplets);
|
||||
NS_IF_RELEASE(mEmbeds);
|
||||
NS_IF_RELEASE(mLinks);
|
||||
NS_IF_RELEASE(mAnchors);
|
||||
|
||||
for (i = 0; i < mImageMaps.Count(); i++) {
|
||||
nsIImageMap* map = (nsIImageMap*)mImageMaps.ElementAt(i);
|
||||
|
||||
NS_RELEASE(map);
|
||||
}
|
||||
if (mForms) {
|
||||
mForms->Reset();
|
||||
NS_RELEASE(mForms);
|
||||
}
|
||||
|
||||
if (nsnull != mAttrStyleSheet) {
|
||||
mAttrStyleSheet->SetOwningDocument(nsnull);
|
||||
@ -224,6 +238,35 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
|
||||
NS_RELEASE(mStyleAttrStyleSheet);
|
||||
}
|
||||
|
||||
result = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this);
|
||||
if (NS_OK == result) {
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
|
||||
result = NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL, this);
|
||||
if (NS_OK == result) {
|
||||
AddStyleSheet(mStyleAttrStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand)
|
||||
{
|
||||
nsresult rv = nsDocument::StartDocumentLoad(aURL,
|
||||
aContainer,
|
||||
aDocListener,
|
||||
aCommand);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIWebShell* webShell;
|
||||
|
||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
||||
|
||||
@ -245,13 +288,6 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
|
||||
#endif
|
||||
|
||||
if (NS_OK == rv) {
|
||||
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this)) {
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
if (NS_OK == NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL, this)) {
|
||||
AddStyleSheet(mStyleAttrStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
|
||||
// Set the parser as the stream listener for the document loader...
|
||||
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
||||
rv = mParser->QueryInterface(kIStreamListenerIID, (void**)aDocListener);
|
||||
@ -766,7 +802,7 @@ nsHTMLDocument::GetCookie(nsString& aCookie)
|
||||
nsresult res = nsServiceManager::GetService(kNetServiceCID,
|
||||
kINetServiceIID,
|
||||
(nsISupports **)&service);
|
||||
if ((NS_OK == res) && (nsnull != service)) {
|
||||
if ((NS_OK == res) && (nsnull != service) && (nsnull != mDocumentURL)) {
|
||||
|
||||
res = service->GetCookieString(mDocumentURL, aCookie);
|
||||
|
||||
@ -783,7 +819,7 @@ nsHTMLDocument::SetCookie(const nsString& aCookie)
|
||||
nsresult res = nsServiceManager::GetService(kNetServiceCID,
|
||||
kINetServiceIID,
|
||||
(nsISupports **)&service);
|
||||
if ((NS_OK == res) && (nsnull != service)) {
|
||||
if ((NS_OK == res) && (nsnull != service) && (nsnull != mDocumentURL)) {
|
||||
|
||||
res = service->SetCookieString(mDocumentURL, aCookie);
|
||||
|
||||
@ -796,40 +832,97 @@ nsHTMLDocument::SetCookie(const nsString& aCookie)
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Open(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsresult result = NS_OK;
|
||||
#if 0
|
||||
// The open occurred after the document finished loading.
|
||||
// So we reset the document and create a new one.
|
||||
if (nsnull == mParser) {
|
||||
nsIURL* blankURL;
|
||||
|
||||
// XXX Bogus URL since we don't have a real one
|
||||
result = NS_NewURL(&blankURL, "about:blank");
|
||||
|
||||
if (NS_OK == result) {
|
||||
result = Reset(blankURL);
|
||||
if (NS_OK == result) {
|
||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
||||
|
||||
result = nsRepository::CreateInstance(kCParserCID,
|
||||
nsnull,
|
||||
kCParserIID,
|
||||
(void **)&mParser);
|
||||
|
||||
if (NS_OK == result) {
|
||||
nsIHTMLContentSink* sink;
|
||||
nsIWebShell* webShell = nsnull;
|
||||
|
||||
nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0);
|
||||
if (nsnull != shell) {
|
||||
nsIPresContext* cx = shell->GetPresContext();
|
||||
nsISupports* container;
|
||||
if (NS_OK == cx->GetContainer(&container)) {
|
||||
if (nsnull != container) {
|
||||
container->QueryInterface(kIWebShellIID, (void**) &webShell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = NS_NewHTMLContentSink(&sink, this, blankURL, webShell);
|
||||
NS_IF_RELEASE(webShell);
|
||||
|
||||
if (NS_OK == result) {
|
||||
nsIDTD* theDTD=0;
|
||||
NS_NewNavHTMLDTD(&theDTD);
|
||||
mParser->RegisterDTD(theDTD);
|
||||
mParser->SetContentSink(sink);
|
||||
NS_RELEASE(sink);
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_RELEASE(blankURL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Close()
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Write(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
nsresult
|
||||
nsHTMLDocument::WriteCommon(JSContext *cx,
|
||||
jsval *argv,
|
||||
PRUint32 argc,
|
||||
PRBool aNewlineTerminate)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
// XXX Right now, we only deal with inline document.writes
|
||||
if (nsnull == mParser) {
|
||||
result = Open(cx, argv, argc);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
if (argc > 0) {
|
||||
PRUint32 index;
|
||||
nsAutoString str;
|
||||
str.Truncate();
|
||||
for (index = 0; index < argc; index++) {
|
||||
JSString *jsstring = JS_ValueToString(cx, argv[index]);
|
||||
|
||||
if (nsnull != jsstring) {
|
||||
str.Append(JS_GetStringChars(jsstring));
|
||||
}
|
||||
else {
|
||||
str.Append(""); // Should this really be null??
|
||||
}
|
||||
}
|
||||
|
||||
if (aNewlineTerminate) {
|
||||
str.Append('\n');
|
||||
}
|
||||
|
||||
result = mParser->Parse(str, PR_TRUE);
|
||||
if (NS_OK != result) {
|
||||
return result;
|
||||
@ -839,23 +932,16 @@ nsHTMLDocument::Write(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Write(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
{
|
||||
return WriteCommon(cx, argv, argc, PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Writeln(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
{
|
||||
nsAutoString newLine("\n");
|
||||
nsresult result;
|
||||
|
||||
// XXX Right now, we only deal with inline document.writes
|
||||
if (nsnull == mParser) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
result = Write(cx, argv, argc);
|
||||
if (NS_OK == result) {
|
||||
result = mParser->Parse(newLine, PR_TRUE);
|
||||
}
|
||||
|
||||
return result;
|
||||
return WriteCommon(cx, argv, argc, PR_TRUE);
|
||||
}
|
||||
|
||||
nsIContent *
|
||||
|
@ -166,6 +166,13 @@ protected:
|
||||
|
||||
PRBool GetBodyContent();
|
||||
|
||||
virtual nsresult Reset(nsIURL *aURL);
|
||||
nsresult WriteCommon(JSContext *cx,
|
||||
jsval *argv,
|
||||
PRUint32 argc,
|
||||
PRBool aNewlineTerminate);
|
||||
|
||||
|
||||
nsIHTMLStyleSheet* mAttrStyleSheet;
|
||||
nsIHTMLCSSStyleSheet* mStyleAttrStyleSheet;
|
||||
nsDTDMode mDTDMode;
|
||||
|
@ -188,34 +188,13 @@ nsImageDocument::StartDocumentLoad(nsIURL* aURL,
|
||||
nsIStreamListener** aDocListener,
|
||||
const char* aCommand)
|
||||
{
|
||||
NS_IF_RELEASE(mDocumentURL);
|
||||
mDocumentURL = aURL;
|
||||
NS_IF_ADDREF(aURL);
|
||||
|
||||
if (nsnull != mAttrStyleSheet) {
|
||||
mAttrStyleSheet->SetOwningDocument(nsnull);
|
||||
NS_RELEASE(mAttrStyleSheet);
|
||||
}
|
||||
if (nsnull != mStyleAttrStyleSheet) {
|
||||
mStyleAttrStyleSheet->SetOwningDocument(nsnull);
|
||||
NS_RELEASE(mStyleAttrStyleSheet);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
|
||||
// Create html attribute style sheet
|
||||
rv = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this);
|
||||
nsresult rv = nsDocument::StartDocumentLoad(aURL,
|
||||
aContainer,
|
||||
aDocListener,
|
||||
aCommand);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
|
||||
// Create style attribute style sheet
|
||||
rv = NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL, this);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
AddStyleSheet(mStyleAttrStyleSheet); // tell the world about our new style sheet
|
||||
|
||||
// Create synthetic document
|
||||
rv = CreateSyntheticDocument();
|
||||
|
@ -120,15 +120,12 @@ nsrefcnt nsXMLDocument::Release()
|
||||
return nsDocument::Release();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand)
|
||||
nsresult
|
||||
nsXMLDocument::Reset(nsIURL* aURL)
|
||||
{
|
||||
nsresult rv = nsDocument::StartDocLoad(aUrl, aContainer, aDocListener);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
nsresult result = nsDocument::Reset(aURL);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (nsnull != mAttrStyleSheet) {
|
||||
@ -140,6 +137,33 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
|
||||
NS_RELEASE(mInlineStyleSheet);
|
||||
}
|
||||
|
||||
result = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this);
|
||||
if (NS_OK == result) {
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
|
||||
result = NS_NewHTMLCSSStyleSheet(&mInlineStyleSheet, aURL, this);
|
||||
if (NS_OK == result) {
|
||||
AddStyleSheet(mInlineStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand)
|
||||
{
|
||||
nsresult rv = nsDocument::StartDocumentLoad(aUrl,
|
||||
aContainer,
|
||||
aDocListener,
|
||||
aCommand);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIWebShell* webShell;
|
||||
|
||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||
@ -156,15 +180,7 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
|
||||
rv = NS_NewXMLContentSink(&sink, this, aUrl, webShell);
|
||||
NS_IF_RELEASE(webShell);
|
||||
|
||||
if (NS_OK == rv) {
|
||||
// For the HTML content within a document
|
||||
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl, this)) {
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
if (NS_OK == NS_NewHTMLCSSStyleSheet(&mInlineStyleSheet, aUrl, this)) {
|
||||
AddStyleSheet(mInlineStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
|
||||
if (NS_OK == rv) {
|
||||
// Set the parser as the stream listener for the document loader...
|
||||
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
||||
rv = mParser->QueryInterface(kIStreamListenerIID, (void**)aDocListener);
|
||||
|
@ -72,6 +72,7 @@ public:
|
||||
|
||||
protected:
|
||||
void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet);
|
||||
virtual nsresult Reset(nsIURL* aUrl);
|
||||
|
||||
|
||||
// For HTML elements in our content model
|
||||
|
@ -528,11 +528,7 @@ NS_IMPL_RELEASE(nsDocument)
|
||||
nsresult nsDocument::Init()
|
||||
{
|
||||
nsresult rv = NS_NewHeapArena(&mArena, nsnull);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = NS_NewNameSpaceManager(&mNameSpaceManager);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -545,12 +541,26 @@ nsIArena* nsDocument::GetArena()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDocument::StartDocLoad(nsIURL *aURL,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener)
|
||||
nsDocument::Reset(nsIURL *aURL)
|
||||
{
|
||||
// Delete references to style sheets - this should be done in superclass...
|
||||
PRInt32 index = mStyleSheets.Count();
|
||||
if (nsnull != mDocumentTitle) {
|
||||
delete mDocumentTitle;
|
||||
mDocumentTitle = nsnull;
|
||||
}
|
||||
NS_IF_RELEASE(mDocumentURL);
|
||||
NS_IF_RELEASE(mDocumentURLGroup);
|
||||
|
||||
// Delete references to sub-documents
|
||||
PRInt32 index = mSubDocuments.Count();
|
||||
while (--index >= 0) {
|
||||
nsIDocument* subdoc = (nsIDocument*) mSubDocuments.ElementAt(index);
|
||||
NS_RELEASE(subdoc);
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mRootContent);
|
||||
|
||||
// Delete references to style sheets
|
||||
index = mStyleSheets.Count();
|
||||
while (--index >= 0) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(index);
|
||||
sheet->SetOwningDocument(nsnull);
|
||||
@ -558,11 +568,22 @@ nsDocument::StartDocLoad(nsIURL *aURL,
|
||||
}
|
||||
mStyleSheets.Clear();
|
||||
|
||||
NS_IF_RELEASE(mDocumentURL);
|
||||
NS_IF_RELEASE(mDocumentURLGroup);
|
||||
if (nsnull != mDocumentTitle) {
|
||||
delete mDocumentTitle;
|
||||
mDocumentTitle = nsnull;
|
||||
NS_IF_RELEASE(mListenerManager);
|
||||
NS_IF_RELEASE(mDOMStyleSheets);
|
||||
|
||||
NS_IF_RELEASE(mNameSpaceManager);
|
||||
return NS_NewNameSpaceManager(&mNameSpaceManager);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDocument::StartDocumentLoad(nsIURL *aURL,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand)
|
||||
{
|
||||
nsresult result = Reset(aURL);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
mDocumentURL = aURL;
|
||||
|
@ -65,6 +65,11 @@ public:
|
||||
|
||||
virtual nsIArena* GetArena();
|
||||
|
||||
NS_IMETHOD StartDocumentLoad(nsIURL *aUrl,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand);
|
||||
|
||||
/**
|
||||
* Return the title of the document. May return null.
|
||||
*/
|
||||
@ -291,12 +296,10 @@ protected:
|
||||
nsIContent* FindContent(const nsIContent* aStartNode,
|
||||
const nsIContent* aTest1,
|
||||
const nsIContent* aTest2) const;
|
||||
virtual nsresult Reset(nsIURL* aURL);
|
||||
|
||||
protected:
|
||||
|
||||
virtual nsresult StartDocLoad(nsIURL *aUrl,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener);
|
||||
|
||||
virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); // subclass hook
|
||||
|
||||
|
@ -202,18 +202,32 @@ nsrefcnt nsHTMLDocument::Release()
|
||||
return nsDocument::Release();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand)
|
||||
nsresult
|
||||
nsHTMLDocument::Reset(nsIURL *aURL)
|
||||
{
|
||||
nsresult rv = nsDocument::StartDocLoad(aURL, aContainer, aDocListener);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
nsresult result = nsDocument::Reset(aURL);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
nsIWebShell* webShell;
|
||||
PRInt32 i;
|
||||
|
||||
DeleteNamedItems();
|
||||
NS_IF_RELEASE(mImages);
|
||||
NS_IF_RELEASE(mApplets);
|
||||
NS_IF_RELEASE(mEmbeds);
|
||||
NS_IF_RELEASE(mLinks);
|
||||
NS_IF_RELEASE(mAnchors);
|
||||
|
||||
for (i = 0; i < mImageMaps.Count(); i++) {
|
||||
nsIImageMap* map = (nsIImageMap*)mImageMaps.ElementAt(i);
|
||||
|
||||
NS_RELEASE(map);
|
||||
}
|
||||
if (mForms) {
|
||||
mForms->Reset();
|
||||
NS_RELEASE(mForms);
|
||||
}
|
||||
|
||||
if (nsnull != mAttrStyleSheet) {
|
||||
mAttrStyleSheet->SetOwningDocument(nsnull);
|
||||
@ -224,6 +238,35 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
|
||||
NS_RELEASE(mStyleAttrStyleSheet);
|
||||
}
|
||||
|
||||
result = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this);
|
||||
if (NS_OK == result) {
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
|
||||
result = NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL, this);
|
||||
if (NS_OK == result) {
|
||||
AddStyleSheet(mStyleAttrStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand)
|
||||
{
|
||||
nsresult rv = nsDocument::StartDocumentLoad(aURL,
|
||||
aContainer,
|
||||
aDocListener,
|
||||
aCommand);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIWebShell* webShell;
|
||||
|
||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
||||
|
||||
@ -245,13 +288,6 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
|
||||
#endif
|
||||
|
||||
if (NS_OK == rv) {
|
||||
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this)) {
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
if (NS_OK == NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL, this)) {
|
||||
AddStyleSheet(mStyleAttrStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
|
||||
// Set the parser as the stream listener for the document loader...
|
||||
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
||||
rv = mParser->QueryInterface(kIStreamListenerIID, (void**)aDocListener);
|
||||
@ -766,7 +802,7 @@ nsHTMLDocument::GetCookie(nsString& aCookie)
|
||||
nsresult res = nsServiceManager::GetService(kNetServiceCID,
|
||||
kINetServiceIID,
|
||||
(nsISupports **)&service);
|
||||
if ((NS_OK == res) && (nsnull != service)) {
|
||||
if ((NS_OK == res) && (nsnull != service) && (nsnull != mDocumentURL)) {
|
||||
|
||||
res = service->GetCookieString(mDocumentURL, aCookie);
|
||||
|
||||
@ -783,7 +819,7 @@ nsHTMLDocument::SetCookie(const nsString& aCookie)
|
||||
nsresult res = nsServiceManager::GetService(kNetServiceCID,
|
||||
kINetServiceIID,
|
||||
(nsISupports **)&service);
|
||||
if ((NS_OK == res) && (nsnull != service)) {
|
||||
if ((NS_OK == res) && (nsnull != service) && (nsnull != mDocumentURL)) {
|
||||
|
||||
res = service->SetCookieString(mDocumentURL, aCookie);
|
||||
|
||||
@ -796,40 +832,97 @@ nsHTMLDocument::SetCookie(const nsString& aCookie)
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Open(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsresult result = NS_OK;
|
||||
#if 0
|
||||
// The open occurred after the document finished loading.
|
||||
// So we reset the document and create a new one.
|
||||
if (nsnull == mParser) {
|
||||
nsIURL* blankURL;
|
||||
|
||||
// XXX Bogus URL since we don't have a real one
|
||||
result = NS_NewURL(&blankURL, "about:blank");
|
||||
|
||||
if (NS_OK == result) {
|
||||
result = Reset(blankURL);
|
||||
if (NS_OK == result) {
|
||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
||||
|
||||
result = nsRepository::CreateInstance(kCParserCID,
|
||||
nsnull,
|
||||
kCParserIID,
|
||||
(void **)&mParser);
|
||||
|
||||
if (NS_OK == result) {
|
||||
nsIHTMLContentSink* sink;
|
||||
nsIWebShell* webShell = nsnull;
|
||||
|
||||
nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0);
|
||||
if (nsnull != shell) {
|
||||
nsIPresContext* cx = shell->GetPresContext();
|
||||
nsISupports* container;
|
||||
if (NS_OK == cx->GetContainer(&container)) {
|
||||
if (nsnull != container) {
|
||||
container->QueryInterface(kIWebShellIID, (void**) &webShell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = NS_NewHTMLContentSink(&sink, this, blankURL, webShell);
|
||||
NS_IF_RELEASE(webShell);
|
||||
|
||||
if (NS_OK == result) {
|
||||
nsIDTD* theDTD=0;
|
||||
NS_NewNavHTMLDTD(&theDTD);
|
||||
mParser->RegisterDTD(theDTD);
|
||||
mParser->SetContentSink(sink);
|
||||
NS_RELEASE(sink);
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_RELEASE(blankURL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Close()
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Write(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
nsresult
|
||||
nsHTMLDocument::WriteCommon(JSContext *cx,
|
||||
jsval *argv,
|
||||
PRUint32 argc,
|
||||
PRBool aNewlineTerminate)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
// XXX Right now, we only deal with inline document.writes
|
||||
if (nsnull == mParser) {
|
||||
result = Open(cx, argv, argc);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
if (argc > 0) {
|
||||
PRUint32 index;
|
||||
nsAutoString str;
|
||||
str.Truncate();
|
||||
for (index = 0; index < argc; index++) {
|
||||
JSString *jsstring = JS_ValueToString(cx, argv[index]);
|
||||
|
||||
if (nsnull != jsstring) {
|
||||
str.Append(JS_GetStringChars(jsstring));
|
||||
}
|
||||
else {
|
||||
str.Append(""); // Should this really be null??
|
||||
}
|
||||
}
|
||||
|
||||
if (aNewlineTerminate) {
|
||||
str.Append('\n');
|
||||
}
|
||||
|
||||
result = mParser->Parse(str, PR_TRUE);
|
||||
if (NS_OK != result) {
|
||||
return result;
|
||||
@ -839,23 +932,16 @@ nsHTMLDocument::Write(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Write(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
{
|
||||
return WriteCommon(cx, argv, argc, PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::Writeln(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
{
|
||||
nsAutoString newLine("\n");
|
||||
nsresult result;
|
||||
|
||||
// XXX Right now, we only deal with inline document.writes
|
||||
if (nsnull == mParser) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
result = Write(cx, argv, argc);
|
||||
if (NS_OK == result) {
|
||||
result = mParser->Parse(newLine, PR_TRUE);
|
||||
}
|
||||
|
||||
return result;
|
||||
return WriteCommon(cx, argv, argc, PR_TRUE);
|
||||
}
|
||||
|
||||
nsIContent *
|
||||
|
@ -166,6 +166,13 @@ protected:
|
||||
|
||||
PRBool GetBodyContent();
|
||||
|
||||
virtual nsresult Reset(nsIURL *aURL);
|
||||
nsresult WriteCommon(JSContext *cx,
|
||||
jsval *argv,
|
||||
PRUint32 argc,
|
||||
PRBool aNewlineTerminate);
|
||||
|
||||
|
||||
nsIHTMLStyleSheet* mAttrStyleSheet;
|
||||
nsIHTMLCSSStyleSheet* mStyleAttrStyleSheet;
|
||||
nsDTDMode mDTDMode;
|
||||
|
@ -188,34 +188,13 @@ nsImageDocument::StartDocumentLoad(nsIURL* aURL,
|
||||
nsIStreamListener** aDocListener,
|
||||
const char* aCommand)
|
||||
{
|
||||
NS_IF_RELEASE(mDocumentURL);
|
||||
mDocumentURL = aURL;
|
||||
NS_IF_ADDREF(aURL);
|
||||
|
||||
if (nsnull != mAttrStyleSheet) {
|
||||
mAttrStyleSheet->SetOwningDocument(nsnull);
|
||||
NS_RELEASE(mAttrStyleSheet);
|
||||
}
|
||||
if (nsnull != mStyleAttrStyleSheet) {
|
||||
mStyleAttrStyleSheet->SetOwningDocument(nsnull);
|
||||
NS_RELEASE(mStyleAttrStyleSheet);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
|
||||
// Create html attribute style sheet
|
||||
rv = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this);
|
||||
nsresult rv = nsDocument::StartDocumentLoad(aURL,
|
||||
aContainer,
|
||||
aDocListener,
|
||||
aCommand);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
|
||||
// Create style attribute style sheet
|
||||
rv = NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL, this);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
AddStyleSheet(mStyleAttrStyleSheet); // tell the world about our new style sheet
|
||||
|
||||
// Create synthetic document
|
||||
rv = CreateSyntheticDocument();
|
||||
|
@ -120,15 +120,12 @@ nsrefcnt nsXMLDocument::Release()
|
||||
return nsDocument::Release();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand)
|
||||
nsresult
|
||||
nsXMLDocument::Reset(nsIURL* aURL)
|
||||
{
|
||||
nsresult rv = nsDocument::StartDocLoad(aUrl, aContainer, aDocListener);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
nsresult result = nsDocument::Reset(aURL);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (nsnull != mAttrStyleSheet) {
|
||||
@ -140,6 +137,33 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
|
||||
NS_RELEASE(mInlineStyleSheet);
|
||||
}
|
||||
|
||||
result = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this);
|
||||
if (NS_OK == result) {
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
|
||||
result = NS_NewHTMLCSSStyleSheet(&mInlineStyleSheet, aURL, this);
|
||||
if (NS_OK == result) {
|
||||
AddStyleSheet(mInlineStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand)
|
||||
{
|
||||
nsresult rv = nsDocument::StartDocumentLoad(aUrl,
|
||||
aContainer,
|
||||
aDocListener,
|
||||
aCommand);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIWebShell* webShell;
|
||||
|
||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||
@ -156,15 +180,7 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
|
||||
rv = NS_NewXMLContentSink(&sink, this, aUrl, webShell);
|
||||
NS_IF_RELEASE(webShell);
|
||||
|
||||
if (NS_OK == rv) {
|
||||
// For the HTML content within a document
|
||||
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl, this)) {
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
if (NS_OK == NS_NewHTMLCSSStyleSheet(&mInlineStyleSheet, aUrl, this)) {
|
||||
AddStyleSheet(mInlineStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
|
||||
if (NS_OK == rv) {
|
||||
// Set the parser as the stream listener for the document loader...
|
||||
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
||||
rv = mParser->QueryInterface(kIStreamListenerIID, (void**)aDocListener);
|
||||
|
@ -72,6 +72,7 @@ public:
|
||||
|
||||
protected:
|
||||
void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet);
|
||||
virtual nsresult Reset(nsIURL* aUrl);
|
||||
|
||||
|
||||
// For HTML elements in our content model
|
||||
|
Loading…
x
Reference in New Issue
Block a user