mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 04:15:43 +00:00
Added asynchronous script and style loading to XML. Moved out stream loader to netlib.
This commit is contained in:
parent
df3ac56c3c
commit
ef7751a987
@ -19,6 +19,7 @@
|
|||||||
#include "nsIParser.h"
|
#include "nsIParser.h"
|
||||||
#include "nsICSSStyleSheet.h"
|
#include "nsICSSStyleSheet.h"
|
||||||
#include "nsIUnicharInputStream.h"
|
#include "nsIUnicharInputStream.h"
|
||||||
|
#include "nsIUnicharStreamLoader.h"
|
||||||
#include "nsIHTMLContent.h"
|
#include "nsIHTMLContent.h"
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
#include "nsIURLGroup.h"
|
#include "nsIURLGroup.h"
|
||||||
@ -283,38 +284,6 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class nsAccumulatingURLLoader;
|
|
||||||
|
|
||||||
typedef void (*nsAccumulationDoneFunc)(nsAccumulatingURLLoader* aLoader,
|
|
||||||
nsString& aData,
|
|
||||||
void* aRef,
|
|
||||||
nsresult aStatus);
|
|
||||||
|
|
||||||
class nsAccumulatingURLLoader : public nsIStreamListener {
|
|
||||||
public:
|
|
||||||
|
|
||||||
nsAccumulatingURLLoader(nsIURL* aURL,
|
|
||||||
nsAccumulationDoneFunc aFunc,
|
|
||||||
void* aRef);
|
|
||||||
~nsAccumulatingURLLoader();
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
|
|
||||||
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
|
|
||||||
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
|
|
||||||
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
|
|
||||||
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
|
|
||||||
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo);
|
|
||||||
NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
|
|
||||||
PRUint32 aLength);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
nsIURL* mURL;
|
|
||||||
nsAccumulationDoneFunc mFunc;
|
|
||||||
void* mRef;
|
|
||||||
nsString* mData;
|
|
||||||
};
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2106,16 +2075,16 @@ typedef struct {
|
|||||||
nsIURL* mURL;
|
nsIURL* mURL;
|
||||||
nsIHTMLContent* mElement;
|
nsIHTMLContent* mElement;
|
||||||
HTMLContentSink* mSink;
|
HTMLContentSink* mSink;
|
||||||
} nsAsyncStyleProcessingData;
|
} nsAsyncStyleProcessingDataHTML;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nsDoneLoadingStyle(nsAccumulatingURLLoader* aLoader,
|
nsDoneLoadingStyle(nsIUnicharStreamLoader* aLoader,
|
||||||
nsString& aData,
|
nsString& aData,
|
||||||
void* aRef,
|
void* aRef,
|
||||||
nsresult aStatus)
|
nsresult aStatus)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
nsAsyncStyleProcessingData* d = (nsAsyncStyleProcessingData*)aRef;
|
nsAsyncStyleProcessingDataHTML* d = (nsAsyncStyleProcessingDataHTML*)aRef;
|
||||||
nsIUnicharInputStream* uin = nsnull;
|
nsIUnicharInputStream* uin = nsnull;
|
||||||
|
|
||||||
if ((NS_OK == aStatus) && (0 < aData.Length())) {
|
if ((NS_OK == aStatus) && (0 < aData.Length())) {
|
||||||
@ -2220,7 +2189,7 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAsyncStyleProcessingData* d = new nsAsyncStyleProcessingData;
|
nsAsyncStyleProcessingDataHTML* d = new nsAsyncStyleProcessingDataHTML;
|
||||||
if (nsnull == d) {
|
if (nsnull == d) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
@ -2234,12 +2203,15 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode)
|
|||||||
d->mSink = this;
|
d->mSink = this;
|
||||||
NS_ADDREF(this);
|
NS_ADDREF(this);
|
||||||
|
|
||||||
nsAccumulatingURLLoader* loader =
|
nsIUnicharStreamLoader* loader;
|
||||||
new nsAccumulatingURLLoader(url,
|
result = NS_NewUnicharStreamLoader(&loader,
|
||||||
(nsAccumulationDoneFunc)nsDoneLoadingStyle,
|
url,
|
||||||
(void *)d);
|
(nsStreamCompleteFunc)nsDoneLoadingStyle,
|
||||||
|
(void *)d);
|
||||||
NS_RELEASE(url);
|
NS_RELEASE(url);
|
||||||
result = NS_ERROR_HTMLPARSER_BLOCK;
|
if (NS_OK == result) {
|
||||||
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2385,7 +2357,7 @@ HTMLContentSink::EvaluateScript(nsString& aScript,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nsDoneLoadingScript(nsAccumulatingURLLoader* aLoader,
|
nsDoneLoadingScript(nsIUnicharStreamLoader* aLoader,
|
||||||
nsString& aData,
|
nsString& aData,
|
||||||
void* aRef,
|
void* aRef,
|
||||||
nsresult aStatus)
|
nsresult aStatus)
|
||||||
@ -2444,7 +2416,7 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
|
|||||||
|
|
||||||
// If there is a SRC attribute...
|
// If there is a SRC attribute...
|
||||||
if (src.Length() > 0) {
|
if (src.Length() > 0) {
|
||||||
// Use the SRC attribute value to open an accumulating stream
|
// Use the SRC attribute value to load the URL
|
||||||
nsIURL* url = nsnull;
|
nsIURL* url = nsnull;
|
||||||
nsAutoString absURL;
|
nsAutoString absURL;
|
||||||
nsIURLGroup* urlGroup;
|
nsIURLGroup* urlGroup;
|
||||||
@ -2468,12 +2440,15 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
|
|||||||
// onto it as opaque data.
|
// onto it as opaque data.
|
||||||
NS_ADDREF(this);
|
NS_ADDREF(this);
|
||||||
|
|
||||||
nsAccumulatingURLLoader* loader =
|
nsIUnicharStreamLoader* loader;
|
||||||
new nsAccumulatingURLLoader(url,
|
rv = NS_NewUnicharStreamLoader(&loader,
|
||||||
(nsAccumulationDoneFunc)nsDoneLoadingScript,
|
url,
|
||||||
|
(nsStreamCompleteFunc)nsDoneLoadingScript,
|
||||||
(void *)this);
|
(void *)this);
|
||||||
NS_RELEASE(url);
|
NS_RELEASE(url);
|
||||||
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
if (NS_OK == rv) {
|
||||||
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Otherwise, get the text content of the script tag
|
// Otherwise, get the text content of the script tag
|
||||||
@ -2579,7 +2554,7 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
|
|||||||
} else {
|
} else {
|
||||||
// src with immediate style data doesn't add up
|
// src with immediate style data doesn't add up
|
||||||
// XXX what does nav do?
|
// XXX what does nav do?
|
||||||
// Use the SRC attribute value to open an accumulating stream
|
// Use the SRC attribute value to load the URL
|
||||||
nsAutoString absURL;
|
nsAutoString absURL;
|
||||||
nsIURLGroup* urlGroup;
|
nsIURLGroup* urlGroup;
|
||||||
(void)mDocumentURL->GetURLGroup(&urlGroup);
|
(void)mDocumentURL->GetURLGroup(&urlGroup);
|
||||||
@ -2598,7 +2573,7 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAsyncStyleProcessingData* d = new nsAsyncStyleProcessingData;
|
nsAsyncStyleProcessingDataHTML* d = new nsAsyncStyleProcessingDataHTML;
|
||||||
if (nsnull == d) {
|
if (nsnull == d) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
@ -2612,12 +2587,15 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
|
|||||||
d->mSink = this;
|
d->mSink = this;
|
||||||
NS_ADDREF(this);
|
NS_ADDREF(this);
|
||||||
|
|
||||||
nsAccumulatingURLLoader* loader =
|
nsIUnicharStreamLoader* loader;
|
||||||
new nsAccumulatingURLLoader(url,
|
rv = NS_NewUnicharStreamLoader(&loader,
|
||||||
(nsAccumulationDoneFunc)nsDoneLoadingStyle,
|
url,
|
||||||
(void *)d);
|
(nsStreamCompleteFunc)nsDoneLoadingStyle,
|
||||||
|
(void *)d);
|
||||||
NS_RELEASE(url);
|
NS_RELEASE(url);
|
||||||
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
if (NS_OK == rv) {
|
||||||
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_RELEASE(element);
|
NS_RELEASE(element);
|
||||||
@ -2748,103 +2726,3 @@ HTMLContentSink::NotifyError(nsresult aErrorResult)
|
|||||||
PR_ASSERT(0);
|
PR_ASSERT(0);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
|
|
||||||
nsAccumulatingURLLoader::nsAccumulatingURLLoader(nsIURL* aURL,
|
|
||||||
nsAccumulationDoneFunc aFunc,
|
|
||||||
void* aRef)
|
|
||||||
{
|
|
||||||
mFunc = aFunc;
|
|
||||||
mRef = aRef;
|
|
||||||
mData = new nsString();
|
|
||||||
|
|
||||||
nsresult rv;
|
|
||||||
if (aURL) {
|
|
||||||
rv = NS_OpenURL(aURL, this);
|
|
||||||
if ((NS_OK != rv) && (nsnull != mFunc)) {
|
|
||||||
(*mFunc)(this, *mData, mRef, rv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAccumulatingURLLoader::~nsAccumulatingURLLoader()
|
|
||||||
{
|
|
||||||
if (nsnull != mData) {
|
|
||||||
delete mData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(nsAccumulatingURLLoader, kIStreamListenerIID)
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::OnStartBinding(nsIURL* aURL,
|
|
||||||
const char *aContentType)
|
|
||||||
{
|
|
||||||
// XXX Should check content type?
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::OnProgress(nsIURL* aURL,
|
|
||||||
PRUint32 aProgress,
|
|
||||||
PRUint32 aProgressMax)
|
|
||||||
{
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
|
|
||||||
{
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::OnStopBinding(nsIURL* aURL,
|
|
||||||
nsresult aStatus,
|
|
||||||
const PRUnichar* aMsg)
|
|
||||||
{
|
|
||||||
(*mFunc)(this, *mData, mRef, aStatus);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo)
|
|
||||||
{
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BUF_SIZE 1024
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::OnDataAvailable(nsIURL* aURL,
|
|
||||||
nsIInputStream *aIStream,
|
|
||||||
PRUint32 aLength)
|
|
||||||
{
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
char buffer[BUF_SIZE];
|
|
||||||
PRUint32 len, lenRead;
|
|
||||||
|
|
||||||
aIStream->GetLength(&len);
|
|
||||||
|
|
||||||
while (len > 0) {
|
|
||||||
if (len < BUF_SIZE) {
|
|
||||||
lenRead = len;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lenRead = BUF_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = aIStream->Read(buffer, 0, lenRead, &lenRead);
|
|
||||||
if (NS_OK != rv) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
mData->Append(buffer, lenRead);
|
|
||||||
len -= lenRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
@ -20,11 +20,13 @@
|
|||||||
#include "nsXMLContentSink.h"
|
#include "nsXMLContentSink.h"
|
||||||
#include "nsIParser.h"
|
#include "nsIParser.h"
|
||||||
#include "nsIUnicharInputStream.h"
|
#include "nsIUnicharInputStream.h"
|
||||||
|
#include "nsIUnicharStreamLoader.h"
|
||||||
#include "nsIDocument.h"
|
#include "nsIDocument.h"
|
||||||
#include "nsIXMLDocument.h"
|
#include "nsIXMLDocument.h"
|
||||||
#include "nsIXMLContent.h"
|
#include "nsIXMLContent.h"
|
||||||
#include "nsIScriptObjectOwner.h"
|
#include "nsIScriptObjectOwner.h"
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
|
#include "nsIURLGroup.h"
|
||||||
#include "nsIWebShell.h"
|
#include "nsIWebShell.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
#include "nsITextContent.h"
|
#include "nsITextContent.h"
|
||||||
@ -59,6 +61,7 @@ static NS_DEFINE_IID(kIXMLContentSinkIID, NS_IXMLCONTENT_SINK_IID);
|
|||||||
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
|
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
|
||||||
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
|
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
|
||||||
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
||||||
|
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
||||||
|
|
||||||
#define XML_PSEUDO_ELEMENT 0
|
#define XML_PSEUDO_ELEMENT 0
|
||||||
|
|
||||||
@ -733,9 +736,13 @@ nsXMLContentSink::AddComment(const nsIParserNode& aNode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX Borrowed from HTMLContentSink. Should be shared.
|
// XXX Borrowed from HTMLContentSink. Should be shared.
|
||||||
nsresult
|
NS_IMETHODIMP
|
||||||
nsXMLContentSink::LoadStyleSheet(nsIURL* aURL,
|
nsXMLContentSink::LoadStyleSheet(nsIURL* aURL,
|
||||||
nsIUnicharInputStream* aUIN)
|
nsIUnicharInputStream* aUIN,
|
||||||
|
PRBool aActive,
|
||||||
|
const nsString& aTitle,
|
||||||
|
const nsString& aMedia,
|
||||||
|
nsIContent* aOwner)
|
||||||
{
|
{
|
||||||
/* XXX use repository */
|
/* XXX use repository */
|
||||||
nsICSSParser* parser;
|
nsICSSParser* parser;
|
||||||
@ -747,7 +754,16 @@ nsXMLContentSink::LoadStyleSheet(nsIURL* aURL,
|
|||||||
parser->SetCaseSensative(PR_TRUE);
|
parser->SetCaseSensative(PR_TRUE);
|
||||||
parser->Parse(aUIN, aURL, sheet);
|
parser->Parse(aUIN, aURL, sheet);
|
||||||
if (nsnull != sheet) {
|
if (nsnull != sheet) {
|
||||||
|
sheet->SetTitle(aTitle);
|
||||||
|
sheet->SetEnabled(aActive);
|
||||||
mDocument->AddStyleSheet(sheet);
|
mDocument->AddStyleSheet(sheet);
|
||||||
|
if (nsnull != aOwner) {
|
||||||
|
nsIDOMNode* domNode = nsnull;
|
||||||
|
if (NS_SUCCEEDED(aOwner->QueryInterface(kIDOMNodeIID, (void**)&domNode))) {
|
||||||
|
sheet->SetOwningNode(domNode);
|
||||||
|
NS_RELEASE(domNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
NS_RELEASE(sheet);
|
NS_RELEASE(sheet);
|
||||||
rv = NS_OK;
|
rv = NS_OK;
|
||||||
} else {
|
} else {
|
||||||
@ -794,6 +810,48 @@ GetQuotedAttributeValue(nsString& aSource,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
nsString mTitle;
|
||||||
|
nsString mMedia;
|
||||||
|
PRBool mIsActive;
|
||||||
|
nsIURL* mURL;
|
||||||
|
nsIContent* mElement;
|
||||||
|
nsXMLContentSink* mSink;
|
||||||
|
} nsAsyncStyleProcessingDataXML;
|
||||||
|
|
||||||
|
static void
|
||||||
|
nsDoneLoadingStyle(nsIUnicharStreamLoader* aLoader,
|
||||||
|
nsString& aData,
|
||||||
|
void* aRef,
|
||||||
|
nsresult aStatus)
|
||||||
|
{
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
nsAsyncStyleProcessingDataXML* d = (nsAsyncStyleProcessingDataXML*)aRef;
|
||||||
|
nsIUnicharInputStream* uin = nsnull;
|
||||||
|
|
||||||
|
if ((NS_OK == aStatus) && (0 < aData.Length())) {
|
||||||
|
// wrap the string with the CSS data up in a unicode
|
||||||
|
// input stream.
|
||||||
|
rv = NS_NewStringUnicharInputStream(&uin, new nsString(aData));
|
||||||
|
if (NS_OK == rv) {
|
||||||
|
// XXX We have no way of indicating failure. Silently fail?
|
||||||
|
rv = d->mSink->LoadStyleSheet(d->mURL, uin, d->mIsActive,
|
||||||
|
d->mTitle, d->mMedia, d->mElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
d->mSink->ResumeParsing();
|
||||||
|
|
||||||
|
NS_RELEASE(d->mURL);
|
||||||
|
NS_IF_RELEASE(d->mElement);
|
||||||
|
NS_RELEASE(d->mSink);
|
||||||
|
delete d;
|
||||||
|
|
||||||
|
// We added a reference when the loader was created. This
|
||||||
|
// release should destroy it.
|
||||||
|
NS_RELEASE(aLoader);
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
||||||
{
|
{
|
||||||
@ -801,7 +859,7 @@ nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
|||||||
|
|
||||||
// XXX For now, we don't add the PI to the content model.
|
// XXX For now, we don't add the PI to the content model.
|
||||||
// We just check for a style sheet PI
|
// We just check for a style sheet PI
|
||||||
nsAutoString text, type, href;
|
nsAutoString text, type, href, title, media;
|
||||||
PRInt32 offset;
|
PRInt32 offset;
|
||||||
nsresult result = NS_OK;
|
nsresult result = NS_OK;
|
||||||
|
|
||||||
@ -821,39 +879,61 @@ nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
|||||||
if (NS_OK != result) {
|
if (NS_OK != result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
result = GetQuotedAttributeValue(text, "title", title);
|
||||||
|
if (NS_OK != result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
title.CompressWhitespace();
|
||||||
|
result = GetQuotedAttributeValue(text, "media", media);
|
||||||
|
if (NS_OK != result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
media.ToUpperCase();
|
||||||
|
|
||||||
if (type.Equals(kCSSType)) {
|
if (type.Equals(kCSSType)) {
|
||||||
|
// Use the SRC attribute value to load the URL
|
||||||
nsIURL* url = nsnull;
|
nsIURL* url = nsnull;
|
||||||
nsIUnicharInputStream* uin = nsnull;
|
|
||||||
nsAutoString absURL;
|
nsAutoString absURL;
|
||||||
nsIURL* docURL = mDocument->GetDocumentURL();
|
nsIURL* docURL = mDocument->GetDocumentURL();
|
||||||
nsAutoString emptyURL;
|
nsIURLGroup* urlGroup;
|
||||||
emptyURL.Truncate();
|
|
||||||
result = NS_MakeAbsoluteURL(docURL, emptyURL, href, absURL);
|
result = docURL->GetURLGroup(&urlGroup);
|
||||||
if (NS_OK != result) {
|
|
||||||
return result;
|
if ((NS_OK == result) && urlGroup) {
|
||||||
|
result = urlGroup->CreateURL(&url, docURL, href, nsnull);
|
||||||
|
NS_RELEASE(urlGroup);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = NS_NewURL(&url, absURL);
|
||||||
}
|
}
|
||||||
NS_RELEASE(docURL);
|
NS_RELEASE(docURL);
|
||||||
result = NS_NewURL(&url, absURL);
|
|
||||||
if (NS_OK != result) {
|
if (NS_OK != result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
nsIInputStream* iin;
|
|
||||||
result = NS_OpenURL(url, &iin);
|
nsAsyncStyleProcessingDataXML* d = new nsAsyncStyleProcessingDataXML;
|
||||||
if (NS_OK != result) {
|
if (nsnull == d) {
|
||||||
NS_RELEASE(url);
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
result = NS_NewConverterStream(&uin, nsnull, iin);
|
d->mTitle.SetString(title);
|
||||||
NS_RELEASE(iin);
|
d->mMedia.SetString(media);
|
||||||
if (NS_OK != result) {
|
d->mIsActive = PR_TRUE;
|
||||||
NS_RELEASE(url);
|
d->mURL = url;
|
||||||
return result;
|
NS_ADDREF(url);
|
||||||
}
|
// XXX Need to create PI node
|
||||||
|
d->mElement = nsnull;
|
||||||
result = LoadStyleSheet(url, uin);
|
d->mSink = this;
|
||||||
NS_RELEASE(uin);
|
NS_ADDREF(this);
|
||||||
|
|
||||||
|
nsIUnicharStreamLoader* loader;
|
||||||
|
result = NS_NewUnicharStreamLoader(&loader,
|
||||||
|
url,
|
||||||
|
(nsStreamCompleteFunc)nsDoneLoadingStyle,
|
||||||
|
(void *)d);
|
||||||
NS_RELEASE(url);
|
NS_RELEASE(url);
|
||||||
|
if (NS_OK == result) {
|
||||||
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -901,6 +981,8 @@ nsXMLContentSink::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NS_ACCUMULATION_BUFFER_SIZE 4096
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsXMLContentSink::AddCharacterData(const nsIParserNode& aNode)
|
nsXMLContentSink::AddCharacterData(const nsIParserNode& aNode)
|
||||||
{
|
{
|
||||||
@ -913,11 +995,11 @@ nsXMLContentSink::AddCharacterData(const nsIParserNode& aNode)
|
|||||||
|
|
||||||
// Create buffer when we first need it
|
// Create buffer when we first need it
|
||||||
if (0 == mTextSize) {
|
if (0 == mTextSize) {
|
||||||
mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * 4096);
|
mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * NS_ACCUMULATION_BUFFER_SIZE);
|
||||||
if (nsnull == mText) {
|
if (nsnull == mText) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
mTextSize = 4096;
|
mTextSize = NS_ACCUMULATION_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy data from string into our buffer; flush buffer when it fills up
|
// Copy data from string into our buffer; flush buffer when it fills up
|
||||||
@ -1110,7 +1192,17 @@ nsXMLContentSink::StartLayout()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
NS_IMETHODIMP
|
||||||
|
nsXMLContentSink::ResumeParsing()
|
||||||
|
{
|
||||||
|
if (nsnull != mParser) {
|
||||||
|
mParser->EnableParser(PR_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
nsXMLContentSink::EvaluateScript(nsString& aScript, PRUint32 aLineNo)
|
nsXMLContentSink::EvaluateScript(nsString& aScript, PRUint32 aLineNo)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
@ -1194,6 +1286,29 @@ IsJavaScriptLanguage(const nsString& aName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nsDoneLoadingScript(nsIUnicharStreamLoader* aLoader,
|
||||||
|
nsString& aData,
|
||||||
|
void* aRef,
|
||||||
|
nsresult aStatus)
|
||||||
|
{
|
||||||
|
nsXMLContentSink* sink = (nsXMLContentSink*)aRef;
|
||||||
|
|
||||||
|
if (NS_OK == aStatus) {
|
||||||
|
// XXX We have no way of indicating failure. Silently fail?
|
||||||
|
sink->EvaluateScript(aData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
sink->ResumeParsing();
|
||||||
|
|
||||||
|
// The url loader held a reference to the sink
|
||||||
|
NS_RELEASE(sink);
|
||||||
|
|
||||||
|
// We added a reference when the loader was created. This
|
||||||
|
// release should destroy it.
|
||||||
|
NS_RELEASE(aLoader);
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsXMLContentSink::ProcessStartSCRIPTTag(const nsIParserNode& aNode)
|
nsXMLContentSink::ProcessStartSCRIPTTag(const nsIParserNode& aNode)
|
||||||
{
|
{
|
||||||
@ -1206,8 +1321,7 @@ nsXMLContentSink::ProcessStartSCRIPTTag(const nsIParserNode& aNode)
|
|||||||
for (i = 0; i < ac; i++) {
|
for (i = 0; i < ac; i++) {
|
||||||
const nsString& key = aNode.GetKeyAt(i);
|
const nsString& key = aNode.GetKeyAt(i);
|
||||||
if (key.EqualsIgnoreCase("src")) {
|
if (key.EqualsIgnoreCase("src")) {
|
||||||
src = aNode.GetValueAt(i);
|
GetAttributeValueAt(aNode, i, src);
|
||||||
src.Trim("\"", PR_TRUE, PR_TRUE);
|
|
||||||
}
|
}
|
||||||
else if (key.EqualsIgnoreCase("type")) {
|
else if (key.EqualsIgnoreCase("type")) {
|
||||||
nsAutoString type;
|
nsAutoString type;
|
||||||
@ -1226,53 +1340,42 @@ nsXMLContentSink::ProcessStartSCRIPTTag(const nsIParserNode& aNode)
|
|||||||
// Don't process scripts that aren't JavaScript
|
// Don't process scripts that aren't JavaScript
|
||||||
if (isJavaScript) {
|
if (isJavaScript) {
|
||||||
nsAutoString script;
|
nsAutoString script;
|
||||||
|
|
||||||
// If there is a SRC attribute, (for now) read from the
|
// If there is a SRC attribute...
|
||||||
// stream synchronously and hold the data in a string.
|
if (src.Length() > 0) {
|
||||||
if (src != "") {
|
// Use the SRC attribute value to load the URL
|
||||||
// Use the SRC attribute value to open a blocking stream
|
|
||||||
nsIURL* url = nsnull;
|
nsIURL* url = nsnull;
|
||||||
nsAutoString absURL;
|
nsAutoString absURL;
|
||||||
nsIURL* docURL = mDocument->GetDocumentURL();
|
nsIURL* docURL = mDocument->GetDocumentURL();
|
||||||
nsAutoString emptyURL;
|
nsIURLGroup* urlGroup;
|
||||||
emptyURL.Truncate();
|
|
||||||
rv = NS_MakeAbsoluteURL(docURL, emptyURL, src, absURL);
|
rv = docURL->GetURLGroup(&urlGroup);
|
||||||
if (NS_OK != rv) {
|
|
||||||
return rv;
|
if ((NS_OK == rv) && urlGroup) {
|
||||||
|
rv = urlGroup->CreateURL(&url, docURL, src, nsnull);
|
||||||
|
NS_RELEASE(urlGroup);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rv = NS_NewURL(&url, absURL);
|
||||||
}
|
}
|
||||||
NS_RELEASE(docURL);
|
NS_RELEASE(docURL);
|
||||||
rv = NS_NewURL(&url, absURL);
|
|
||||||
if (NS_OK != rv) {
|
if (NS_OK != rv) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
nsIInputStream* iin;
|
|
||||||
rv = NS_OpenURL(url, &iin);
|
// Add a reference to this since the url loader is holding
|
||||||
if (NS_OK != rv) {
|
// onto it as opaque data.
|
||||||
NS_RELEASE(url);
|
NS_ADDREF(this);
|
||||||
return rv;
|
|
||||||
}
|
nsIUnicharStreamLoader* loader;
|
||||||
|
rv = NS_NewUnicharStreamLoader(&loader,
|
||||||
// Drain the stream by reading from it a chunk at a time
|
url,
|
||||||
PRUint32 nb;
|
(nsStreamCompleteFunc)nsDoneLoadingScript,
|
||||||
nsresult err;
|
(void *)this);
|
||||||
do {
|
|
||||||
char buf[SCRIPT_BUF_SIZE];
|
|
||||||
|
|
||||||
err = iin->Read(buf, 0, SCRIPT_BUF_SIZE, &nb);
|
|
||||||
if (NS_OK == err) {
|
|
||||||
script.Append((const char *)buf, nb);
|
|
||||||
}
|
|
||||||
} while (err == NS_OK);
|
|
||||||
|
|
||||||
if (NS_BASE_STREAM_EOF != err) {
|
|
||||||
rv = NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_RELEASE(iin);
|
|
||||||
NS_RELEASE(url);
|
NS_RELEASE(url);
|
||||||
|
if (NS_OK == rv) {
|
||||||
rv = EvaluateScript(script, (PRUint32)aNode.GetSourceLineNumber());
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Wait until we get the script content
|
// Wait until we get the script content
|
||||||
|
@ -76,11 +76,18 @@ public:
|
|||||||
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
|
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
|
||||||
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
|
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
|
||||||
|
|
||||||
|
NS_IMETHOD ResumeParsing();
|
||||||
|
NS_IMETHOD LoadStyleSheet(nsIURL* aURL,
|
||||||
|
nsIUnicharInputStream* aUIN,
|
||||||
|
PRBool aActive,
|
||||||
|
const nsString& aTitle,
|
||||||
|
const nsString& aMedia,
|
||||||
|
nsIContent* aOwner);
|
||||||
|
NS_IMETHOD EvaluateScript(nsString& aScript, PRUint32 aLineNo);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void StartLayout();
|
void StartLayout();
|
||||||
|
|
||||||
nsresult LoadStyleSheet(nsIURL* aURL,
|
|
||||||
nsIUnicharInputStream* aUIN);
|
|
||||||
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
|
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
|
||||||
PRBool* aDidFlush=nsnull);
|
PRBool* aDidFlush=nsnull);
|
||||||
|
|
||||||
@ -95,7 +102,6 @@ protected:
|
|||||||
PRInt32 PushContent(nsIContent *aContent);
|
PRInt32 PushContent(nsIContent *aContent);
|
||||||
nsIContent* PopContent();
|
nsIContent* PopContent();
|
||||||
|
|
||||||
nsresult EvaluateScript(nsString& aScript, PRUint32 aLineNo);
|
|
||||||
nsresult ProcessEndSCRIPTTag(const nsIParserNode& aNode);
|
nsresult ProcessEndSCRIPTTag(const nsIParserNode& aNode);
|
||||||
nsresult ProcessStartSCRIPTTag(const nsIParserNode& aNode);
|
nsresult ProcessStartSCRIPTTag(const nsIParserNode& aNode);
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "nsIParser.h"
|
#include "nsIParser.h"
|
||||||
#include "nsICSSStyleSheet.h"
|
#include "nsICSSStyleSheet.h"
|
||||||
#include "nsIUnicharInputStream.h"
|
#include "nsIUnicharInputStream.h"
|
||||||
|
#include "nsIUnicharStreamLoader.h"
|
||||||
#include "nsIHTMLContent.h"
|
#include "nsIHTMLContent.h"
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
#include "nsIURLGroup.h"
|
#include "nsIURLGroup.h"
|
||||||
@ -283,38 +284,6 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class nsAccumulatingURLLoader;
|
|
||||||
|
|
||||||
typedef void (*nsAccumulationDoneFunc)(nsAccumulatingURLLoader* aLoader,
|
|
||||||
nsString& aData,
|
|
||||||
void* aRef,
|
|
||||||
nsresult aStatus);
|
|
||||||
|
|
||||||
class nsAccumulatingURLLoader : public nsIStreamListener {
|
|
||||||
public:
|
|
||||||
|
|
||||||
nsAccumulatingURLLoader(nsIURL* aURL,
|
|
||||||
nsAccumulationDoneFunc aFunc,
|
|
||||||
void* aRef);
|
|
||||||
~nsAccumulatingURLLoader();
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
|
|
||||||
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
|
|
||||||
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
|
|
||||||
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
|
|
||||||
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
|
|
||||||
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo);
|
|
||||||
NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
|
|
||||||
PRUint32 aLength);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
nsIURL* mURL;
|
|
||||||
nsAccumulationDoneFunc mFunc;
|
|
||||||
void* mRef;
|
|
||||||
nsString* mData;
|
|
||||||
};
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2106,16 +2075,16 @@ typedef struct {
|
|||||||
nsIURL* mURL;
|
nsIURL* mURL;
|
||||||
nsIHTMLContent* mElement;
|
nsIHTMLContent* mElement;
|
||||||
HTMLContentSink* mSink;
|
HTMLContentSink* mSink;
|
||||||
} nsAsyncStyleProcessingData;
|
} nsAsyncStyleProcessingDataHTML;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nsDoneLoadingStyle(nsAccumulatingURLLoader* aLoader,
|
nsDoneLoadingStyle(nsIUnicharStreamLoader* aLoader,
|
||||||
nsString& aData,
|
nsString& aData,
|
||||||
void* aRef,
|
void* aRef,
|
||||||
nsresult aStatus)
|
nsresult aStatus)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
nsAsyncStyleProcessingData* d = (nsAsyncStyleProcessingData*)aRef;
|
nsAsyncStyleProcessingDataHTML* d = (nsAsyncStyleProcessingDataHTML*)aRef;
|
||||||
nsIUnicharInputStream* uin = nsnull;
|
nsIUnicharInputStream* uin = nsnull;
|
||||||
|
|
||||||
if ((NS_OK == aStatus) && (0 < aData.Length())) {
|
if ((NS_OK == aStatus) && (0 < aData.Length())) {
|
||||||
@ -2220,7 +2189,7 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAsyncStyleProcessingData* d = new nsAsyncStyleProcessingData;
|
nsAsyncStyleProcessingDataHTML* d = new nsAsyncStyleProcessingDataHTML;
|
||||||
if (nsnull == d) {
|
if (nsnull == d) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
@ -2234,12 +2203,15 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode)
|
|||||||
d->mSink = this;
|
d->mSink = this;
|
||||||
NS_ADDREF(this);
|
NS_ADDREF(this);
|
||||||
|
|
||||||
nsAccumulatingURLLoader* loader =
|
nsIUnicharStreamLoader* loader;
|
||||||
new nsAccumulatingURLLoader(url,
|
result = NS_NewUnicharStreamLoader(&loader,
|
||||||
(nsAccumulationDoneFunc)nsDoneLoadingStyle,
|
url,
|
||||||
(void *)d);
|
(nsStreamCompleteFunc)nsDoneLoadingStyle,
|
||||||
|
(void *)d);
|
||||||
NS_RELEASE(url);
|
NS_RELEASE(url);
|
||||||
result = NS_ERROR_HTMLPARSER_BLOCK;
|
if (NS_OK == result) {
|
||||||
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2385,7 +2357,7 @@ HTMLContentSink::EvaluateScript(nsString& aScript,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nsDoneLoadingScript(nsAccumulatingURLLoader* aLoader,
|
nsDoneLoadingScript(nsIUnicharStreamLoader* aLoader,
|
||||||
nsString& aData,
|
nsString& aData,
|
||||||
void* aRef,
|
void* aRef,
|
||||||
nsresult aStatus)
|
nsresult aStatus)
|
||||||
@ -2444,7 +2416,7 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
|
|||||||
|
|
||||||
// If there is a SRC attribute...
|
// If there is a SRC attribute...
|
||||||
if (src.Length() > 0) {
|
if (src.Length() > 0) {
|
||||||
// Use the SRC attribute value to open an accumulating stream
|
// Use the SRC attribute value to load the URL
|
||||||
nsIURL* url = nsnull;
|
nsIURL* url = nsnull;
|
||||||
nsAutoString absURL;
|
nsAutoString absURL;
|
||||||
nsIURLGroup* urlGroup;
|
nsIURLGroup* urlGroup;
|
||||||
@ -2468,12 +2440,15 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
|
|||||||
// onto it as opaque data.
|
// onto it as opaque data.
|
||||||
NS_ADDREF(this);
|
NS_ADDREF(this);
|
||||||
|
|
||||||
nsAccumulatingURLLoader* loader =
|
nsIUnicharStreamLoader* loader;
|
||||||
new nsAccumulatingURLLoader(url,
|
rv = NS_NewUnicharStreamLoader(&loader,
|
||||||
(nsAccumulationDoneFunc)nsDoneLoadingScript,
|
url,
|
||||||
|
(nsStreamCompleteFunc)nsDoneLoadingScript,
|
||||||
(void *)this);
|
(void *)this);
|
||||||
NS_RELEASE(url);
|
NS_RELEASE(url);
|
||||||
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
if (NS_OK == rv) {
|
||||||
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Otherwise, get the text content of the script tag
|
// Otherwise, get the text content of the script tag
|
||||||
@ -2579,7 +2554,7 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
|
|||||||
} else {
|
} else {
|
||||||
// src with immediate style data doesn't add up
|
// src with immediate style data doesn't add up
|
||||||
// XXX what does nav do?
|
// XXX what does nav do?
|
||||||
// Use the SRC attribute value to open an accumulating stream
|
// Use the SRC attribute value to load the URL
|
||||||
nsAutoString absURL;
|
nsAutoString absURL;
|
||||||
nsIURLGroup* urlGroup;
|
nsIURLGroup* urlGroup;
|
||||||
(void)mDocumentURL->GetURLGroup(&urlGroup);
|
(void)mDocumentURL->GetURLGroup(&urlGroup);
|
||||||
@ -2598,7 +2573,7 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAsyncStyleProcessingData* d = new nsAsyncStyleProcessingData;
|
nsAsyncStyleProcessingDataHTML* d = new nsAsyncStyleProcessingDataHTML;
|
||||||
if (nsnull == d) {
|
if (nsnull == d) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
@ -2612,12 +2587,15 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode)
|
|||||||
d->mSink = this;
|
d->mSink = this;
|
||||||
NS_ADDREF(this);
|
NS_ADDREF(this);
|
||||||
|
|
||||||
nsAccumulatingURLLoader* loader =
|
nsIUnicharStreamLoader* loader;
|
||||||
new nsAccumulatingURLLoader(url,
|
rv = NS_NewUnicharStreamLoader(&loader,
|
||||||
(nsAccumulationDoneFunc)nsDoneLoadingStyle,
|
url,
|
||||||
(void *)d);
|
(nsStreamCompleteFunc)nsDoneLoadingStyle,
|
||||||
|
(void *)d);
|
||||||
NS_RELEASE(url);
|
NS_RELEASE(url);
|
||||||
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
if (NS_OK == rv) {
|
||||||
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_RELEASE(element);
|
NS_RELEASE(element);
|
||||||
@ -2748,103 +2726,3 @@ HTMLContentSink::NotifyError(nsresult aErrorResult)
|
|||||||
PR_ASSERT(0);
|
PR_ASSERT(0);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
|
|
||||||
nsAccumulatingURLLoader::nsAccumulatingURLLoader(nsIURL* aURL,
|
|
||||||
nsAccumulationDoneFunc aFunc,
|
|
||||||
void* aRef)
|
|
||||||
{
|
|
||||||
mFunc = aFunc;
|
|
||||||
mRef = aRef;
|
|
||||||
mData = new nsString();
|
|
||||||
|
|
||||||
nsresult rv;
|
|
||||||
if (aURL) {
|
|
||||||
rv = NS_OpenURL(aURL, this);
|
|
||||||
if ((NS_OK != rv) && (nsnull != mFunc)) {
|
|
||||||
(*mFunc)(this, *mData, mRef, rv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAccumulatingURLLoader::~nsAccumulatingURLLoader()
|
|
||||||
{
|
|
||||||
if (nsnull != mData) {
|
|
||||||
delete mData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(nsAccumulatingURLLoader, kIStreamListenerIID)
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::OnStartBinding(nsIURL* aURL,
|
|
||||||
const char *aContentType)
|
|
||||||
{
|
|
||||||
// XXX Should check content type?
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::OnProgress(nsIURL* aURL,
|
|
||||||
PRUint32 aProgress,
|
|
||||||
PRUint32 aProgressMax)
|
|
||||||
{
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
|
|
||||||
{
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::OnStopBinding(nsIURL* aURL,
|
|
||||||
nsresult aStatus,
|
|
||||||
const PRUnichar* aMsg)
|
|
||||||
{
|
|
||||||
(*mFunc)(this, *mData, mRef, aStatus);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo)
|
|
||||||
{
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BUF_SIZE 1024
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAccumulatingURLLoader::OnDataAvailable(nsIURL* aURL,
|
|
||||||
nsIInputStream *aIStream,
|
|
||||||
PRUint32 aLength)
|
|
||||||
{
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
char buffer[BUF_SIZE];
|
|
||||||
PRUint32 len, lenRead;
|
|
||||||
|
|
||||||
aIStream->GetLength(&len);
|
|
||||||
|
|
||||||
while (len > 0) {
|
|
||||||
if (len < BUF_SIZE) {
|
|
||||||
lenRead = len;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lenRead = BUF_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = aIStream->Read(buffer, 0, lenRead, &lenRead);
|
|
||||||
if (NS_OK != rv) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
mData->Append(buffer, lenRead);
|
|
||||||
len -= lenRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
@ -20,11 +20,13 @@
|
|||||||
#include "nsXMLContentSink.h"
|
#include "nsXMLContentSink.h"
|
||||||
#include "nsIParser.h"
|
#include "nsIParser.h"
|
||||||
#include "nsIUnicharInputStream.h"
|
#include "nsIUnicharInputStream.h"
|
||||||
|
#include "nsIUnicharStreamLoader.h"
|
||||||
#include "nsIDocument.h"
|
#include "nsIDocument.h"
|
||||||
#include "nsIXMLDocument.h"
|
#include "nsIXMLDocument.h"
|
||||||
#include "nsIXMLContent.h"
|
#include "nsIXMLContent.h"
|
||||||
#include "nsIScriptObjectOwner.h"
|
#include "nsIScriptObjectOwner.h"
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
|
#include "nsIURLGroup.h"
|
||||||
#include "nsIWebShell.h"
|
#include "nsIWebShell.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
#include "nsITextContent.h"
|
#include "nsITextContent.h"
|
||||||
@ -59,6 +61,7 @@ static NS_DEFINE_IID(kIXMLContentSinkIID, NS_IXMLCONTENT_SINK_IID);
|
|||||||
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
|
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
|
||||||
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
|
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
|
||||||
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
||||||
|
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
||||||
|
|
||||||
#define XML_PSEUDO_ELEMENT 0
|
#define XML_PSEUDO_ELEMENT 0
|
||||||
|
|
||||||
@ -733,9 +736,13 @@ nsXMLContentSink::AddComment(const nsIParserNode& aNode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX Borrowed from HTMLContentSink. Should be shared.
|
// XXX Borrowed from HTMLContentSink. Should be shared.
|
||||||
nsresult
|
NS_IMETHODIMP
|
||||||
nsXMLContentSink::LoadStyleSheet(nsIURL* aURL,
|
nsXMLContentSink::LoadStyleSheet(nsIURL* aURL,
|
||||||
nsIUnicharInputStream* aUIN)
|
nsIUnicharInputStream* aUIN,
|
||||||
|
PRBool aActive,
|
||||||
|
const nsString& aTitle,
|
||||||
|
const nsString& aMedia,
|
||||||
|
nsIContent* aOwner)
|
||||||
{
|
{
|
||||||
/* XXX use repository */
|
/* XXX use repository */
|
||||||
nsICSSParser* parser;
|
nsICSSParser* parser;
|
||||||
@ -747,7 +754,16 @@ nsXMLContentSink::LoadStyleSheet(nsIURL* aURL,
|
|||||||
parser->SetCaseSensative(PR_TRUE);
|
parser->SetCaseSensative(PR_TRUE);
|
||||||
parser->Parse(aUIN, aURL, sheet);
|
parser->Parse(aUIN, aURL, sheet);
|
||||||
if (nsnull != sheet) {
|
if (nsnull != sheet) {
|
||||||
|
sheet->SetTitle(aTitle);
|
||||||
|
sheet->SetEnabled(aActive);
|
||||||
mDocument->AddStyleSheet(sheet);
|
mDocument->AddStyleSheet(sheet);
|
||||||
|
if (nsnull != aOwner) {
|
||||||
|
nsIDOMNode* domNode = nsnull;
|
||||||
|
if (NS_SUCCEEDED(aOwner->QueryInterface(kIDOMNodeIID, (void**)&domNode))) {
|
||||||
|
sheet->SetOwningNode(domNode);
|
||||||
|
NS_RELEASE(domNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
NS_RELEASE(sheet);
|
NS_RELEASE(sheet);
|
||||||
rv = NS_OK;
|
rv = NS_OK;
|
||||||
} else {
|
} else {
|
||||||
@ -794,6 +810,48 @@ GetQuotedAttributeValue(nsString& aSource,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
nsString mTitle;
|
||||||
|
nsString mMedia;
|
||||||
|
PRBool mIsActive;
|
||||||
|
nsIURL* mURL;
|
||||||
|
nsIContent* mElement;
|
||||||
|
nsXMLContentSink* mSink;
|
||||||
|
} nsAsyncStyleProcessingDataXML;
|
||||||
|
|
||||||
|
static void
|
||||||
|
nsDoneLoadingStyle(nsIUnicharStreamLoader* aLoader,
|
||||||
|
nsString& aData,
|
||||||
|
void* aRef,
|
||||||
|
nsresult aStatus)
|
||||||
|
{
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
nsAsyncStyleProcessingDataXML* d = (nsAsyncStyleProcessingDataXML*)aRef;
|
||||||
|
nsIUnicharInputStream* uin = nsnull;
|
||||||
|
|
||||||
|
if ((NS_OK == aStatus) && (0 < aData.Length())) {
|
||||||
|
// wrap the string with the CSS data up in a unicode
|
||||||
|
// input stream.
|
||||||
|
rv = NS_NewStringUnicharInputStream(&uin, new nsString(aData));
|
||||||
|
if (NS_OK == rv) {
|
||||||
|
// XXX We have no way of indicating failure. Silently fail?
|
||||||
|
rv = d->mSink->LoadStyleSheet(d->mURL, uin, d->mIsActive,
|
||||||
|
d->mTitle, d->mMedia, d->mElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
d->mSink->ResumeParsing();
|
||||||
|
|
||||||
|
NS_RELEASE(d->mURL);
|
||||||
|
NS_IF_RELEASE(d->mElement);
|
||||||
|
NS_RELEASE(d->mSink);
|
||||||
|
delete d;
|
||||||
|
|
||||||
|
// We added a reference when the loader was created. This
|
||||||
|
// release should destroy it.
|
||||||
|
NS_RELEASE(aLoader);
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
||||||
{
|
{
|
||||||
@ -801,7 +859,7 @@ nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
|||||||
|
|
||||||
// XXX For now, we don't add the PI to the content model.
|
// XXX For now, we don't add the PI to the content model.
|
||||||
// We just check for a style sheet PI
|
// We just check for a style sheet PI
|
||||||
nsAutoString text, type, href;
|
nsAutoString text, type, href, title, media;
|
||||||
PRInt32 offset;
|
PRInt32 offset;
|
||||||
nsresult result = NS_OK;
|
nsresult result = NS_OK;
|
||||||
|
|
||||||
@ -821,39 +879,61 @@ nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
|||||||
if (NS_OK != result) {
|
if (NS_OK != result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
result = GetQuotedAttributeValue(text, "title", title);
|
||||||
|
if (NS_OK != result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
title.CompressWhitespace();
|
||||||
|
result = GetQuotedAttributeValue(text, "media", media);
|
||||||
|
if (NS_OK != result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
media.ToUpperCase();
|
||||||
|
|
||||||
if (type.Equals(kCSSType)) {
|
if (type.Equals(kCSSType)) {
|
||||||
|
// Use the SRC attribute value to load the URL
|
||||||
nsIURL* url = nsnull;
|
nsIURL* url = nsnull;
|
||||||
nsIUnicharInputStream* uin = nsnull;
|
|
||||||
nsAutoString absURL;
|
nsAutoString absURL;
|
||||||
nsIURL* docURL = mDocument->GetDocumentURL();
|
nsIURL* docURL = mDocument->GetDocumentURL();
|
||||||
nsAutoString emptyURL;
|
nsIURLGroup* urlGroup;
|
||||||
emptyURL.Truncate();
|
|
||||||
result = NS_MakeAbsoluteURL(docURL, emptyURL, href, absURL);
|
result = docURL->GetURLGroup(&urlGroup);
|
||||||
if (NS_OK != result) {
|
|
||||||
return result;
|
if ((NS_OK == result) && urlGroup) {
|
||||||
|
result = urlGroup->CreateURL(&url, docURL, href, nsnull);
|
||||||
|
NS_RELEASE(urlGroup);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = NS_NewURL(&url, absURL);
|
||||||
}
|
}
|
||||||
NS_RELEASE(docURL);
|
NS_RELEASE(docURL);
|
||||||
result = NS_NewURL(&url, absURL);
|
|
||||||
if (NS_OK != result) {
|
if (NS_OK != result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
nsIInputStream* iin;
|
|
||||||
result = NS_OpenURL(url, &iin);
|
nsAsyncStyleProcessingDataXML* d = new nsAsyncStyleProcessingDataXML;
|
||||||
if (NS_OK != result) {
|
if (nsnull == d) {
|
||||||
NS_RELEASE(url);
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
result = NS_NewConverterStream(&uin, nsnull, iin);
|
d->mTitle.SetString(title);
|
||||||
NS_RELEASE(iin);
|
d->mMedia.SetString(media);
|
||||||
if (NS_OK != result) {
|
d->mIsActive = PR_TRUE;
|
||||||
NS_RELEASE(url);
|
d->mURL = url;
|
||||||
return result;
|
NS_ADDREF(url);
|
||||||
}
|
// XXX Need to create PI node
|
||||||
|
d->mElement = nsnull;
|
||||||
result = LoadStyleSheet(url, uin);
|
d->mSink = this;
|
||||||
NS_RELEASE(uin);
|
NS_ADDREF(this);
|
||||||
|
|
||||||
|
nsIUnicharStreamLoader* loader;
|
||||||
|
result = NS_NewUnicharStreamLoader(&loader,
|
||||||
|
url,
|
||||||
|
(nsStreamCompleteFunc)nsDoneLoadingStyle,
|
||||||
|
(void *)d);
|
||||||
NS_RELEASE(url);
|
NS_RELEASE(url);
|
||||||
|
if (NS_OK == result) {
|
||||||
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -901,6 +981,8 @@ nsXMLContentSink::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NS_ACCUMULATION_BUFFER_SIZE 4096
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsXMLContentSink::AddCharacterData(const nsIParserNode& aNode)
|
nsXMLContentSink::AddCharacterData(const nsIParserNode& aNode)
|
||||||
{
|
{
|
||||||
@ -913,11 +995,11 @@ nsXMLContentSink::AddCharacterData(const nsIParserNode& aNode)
|
|||||||
|
|
||||||
// Create buffer when we first need it
|
// Create buffer when we first need it
|
||||||
if (0 == mTextSize) {
|
if (0 == mTextSize) {
|
||||||
mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * 4096);
|
mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * NS_ACCUMULATION_BUFFER_SIZE);
|
||||||
if (nsnull == mText) {
|
if (nsnull == mText) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
mTextSize = 4096;
|
mTextSize = NS_ACCUMULATION_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy data from string into our buffer; flush buffer when it fills up
|
// Copy data from string into our buffer; flush buffer when it fills up
|
||||||
@ -1110,7 +1192,17 @@ nsXMLContentSink::StartLayout()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
NS_IMETHODIMP
|
||||||
|
nsXMLContentSink::ResumeParsing()
|
||||||
|
{
|
||||||
|
if (nsnull != mParser) {
|
||||||
|
mParser->EnableParser(PR_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
nsXMLContentSink::EvaluateScript(nsString& aScript, PRUint32 aLineNo)
|
nsXMLContentSink::EvaluateScript(nsString& aScript, PRUint32 aLineNo)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
@ -1194,6 +1286,29 @@ IsJavaScriptLanguage(const nsString& aName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nsDoneLoadingScript(nsIUnicharStreamLoader* aLoader,
|
||||||
|
nsString& aData,
|
||||||
|
void* aRef,
|
||||||
|
nsresult aStatus)
|
||||||
|
{
|
||||||
|
nsXMLContentSink* sink = (nsXMLContentSink*)aRef;
|
||||||
|
|
||||||
|
if (NS_OK == aStatus) {
|
||||||
|
// XXX We have no way of indicating failure. Silently fail?
|
||||||
|
sink->EvaluateScript(aData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
sink->ResumeParsing();
|
||||||
|
|
||||||
|
// The url loader held a reference to the sink
|
||||||
|
NS_RELEASE(sink);
|
||||||
|
|
||||||
|
// We added a reference when the loader was created. This
|
||||||
|
// release should destroy it.
|
||||||
|
NS_RELEASE(aLoader);
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsXMLContentSink::ProcessStartSCRIPTTag(const nsIParserNode& aNode)
|
nsXMLContentSink::ProcessStartSCRIPTTag(const nsIParserNode& aNode)
|
||||||
{
|
{
|
||||||
@ -1206,8 +1321,7 @@ nsXMLContentSink::ProcessStartSCRIPTTag(const nsIParserNode& aNode)
|
|||||||
for (i = 0; i < ac; i++) {
|
for (i = 0; i < ac; i++) {
|
||||||
const nsString& key = aNode.GetKeyAt(i);
|
const nsString& key = aNode.GetKeyAt(i);
|
||||||
if (key.EqualsIgnoreCase("src")) {
|
if (key.EqualsIgnoreCase("src")) {
|
||||||
src = aNode.GetValueAt(i);
|
GetAttributeValueAt(aNode, i, src);
|
||||||
src.Trim("\"", PR_TRUE, PR_TRUE);
|
|
||||||
}
|
}
|
||||||
else if (key.EqualsIgnoreCase("type")) {
|
else if (key.EqualsIgnoreCase("type")) {
|
||||||
nsAutoString type;
|
nsAutoString type;
|
||||||
@ -1226,53 +1340,42 @@ nsXMLContentSink::ProcessStartSCRIPTTag(const nsIParserNode& aNode)
|
|||||||
// Don't process scripts that aren't JavaScript
|
// Don't process scripts that aren't JavaScript
|
||||||
if (isJavaScript) {
|
if (isJavaScript) {
|
||||||
nsAutoString script;
|
nsAutoString script;
|
||||||
|
|
||||||
// If there is a SRC attribute, (for now) read from the
|
// If there is a SRC attribute...
|
||||||
// stream synchronously and hold the data in a string.
|
if (src.Length() > 0) {
|
||||||
if (src != "") {
|
// Use the SRC attribute value to load the URL
|
||||||
// Use the SRC attribute value to open a blocking stream
|
|
||||||
nsIURL* url = nsnull;
|
nsIURL* url = nsnull;
|
||||||
nsAutoString absURL;
|
nsAutoString absURL;
|
||||||
nsIURL* docURL = mDocument->GetDocumentURL();
|
nsIURL* docURL = mDocument->GetDocumentURL();
|
||||||
nsAutoString emptyURL;
|
nsIURLGroup* urlGroup;
|
||||||
emptyURL.Truncate();
|
|
||||||
rv = NS_MakeAbsoluteURL(docURL, emptyURL, src, absURL);
|
rv = docURL->GetURLGroup(&urlGroup);
|
||||||
if (NS_OK != rv) {
|
|
||||||
return rv;
|
if ((NS_OK == rv) && urlGroup) {
|
||||||
|
rv = urlGroup->CreateURL(&url, docURL, src, nsnull);
|
||||||
|
NS_RELEASE(urlGroup);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rv = NS_NewURL(&url, absURL);
|
||||||
}
|
}
|
||||||
NS_RELEASE(docURL);
|
NS_RELEASE(docURL);
|
||||||
rv = NS_NewURL(&url, absURL);
|
|
||||||
if (NS_OK != rv) {
|
if (NS_OK != rv) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
nsIInputStream* iin;
|
|
||||||
rv = NS_OpenURL(url, &iin);
|
// Add a reference to this since the url loader is holding
|
||||||
if (NS_OK != rv) {
|
// onto it as opaque data.
|
||||||
NS_RELEASE(url);
|
NS_ADDREF(this);
|
||||||
return rv;
|
|
||||||
}
|
nsIUnicharStreamLoader* loader;
|
||||||
|
rv = NS_NewUnicharStreamLoader(&loader,
|
||||||
// Drain the stream by reading from it a chunk at a time
|
url,
|
||||||
PRUint32 nb;
|
(nsStreamCompleteFunc)nsDoneLoadingScript,
|
||||||
nsresult err;
|
(void *)this);
|
||||||
do {
|
|
||||||
char buf[SCRIPT_BUF_SIZE];
|
|
||||||
|
|
||||||
err = iin->Read(buf, 0, SCRIPT_BUF_SIZE, &nb);
|
|
||||||
if (NS_OK == err) {
|
|
||||||
script.Append((const char *)buf, nb);
|
|
||||||
}
|
|
||||||
} while (err == NS_OK);
|
|
||||||
|
|
||||||
if (NS_BASE_STREAM_EOF != err) {
|
|
||||||
rv = NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_RELEASE(iin);
|
|
||||||
NS_RELEASE(url);
|
NS_RELEASE(url);
|
||||||
|
if (NS_OK == rv) {
|
||||||
rv = EvaluateScript(script, (PRUint32)aNode.GetSourceLineNumber());
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Wait until we get the script content
|
// Wait until we get the script content
|
||||||
|
@ -76,11 +76,18 @@ public:
|
|||||||
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
|
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
|
||||||
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
|
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
|
||||||
|
|
||||||
|
NS_IMETHOD ResumeParsing();
|
||||||
|
NS_IMETHOD LoadStyleSheet(nsIURL* aURL,
|
||||||
|
nsIUnicharInputStream* aUIN,
|
||||||
|
PRBool aActive,
|
||||||
|
const nsString& aTitle,
|
||||||
|
const nsString& aMedia,
|
||||||
|
nsIContent* aOwner);
|
||||||
|
NS_IMETHOD EvaluateScript(nsString& aScript, PRUint32 aLineNo);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void StartLayout();
|
void StartLayout();
|
||||||
|
|
||||||
nsresult LoadStyleSheet(nsIURL* aURL,
|
|
||||||
nsIUnicharInputStream* aUIN);
|
|
||||||
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
|
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
|
||||||
PRBool* aDidFlush=nsnull);
|
PRBool* aDidFlush=nsnull);
|
||||||
|
|
||||||
@ -95,7 +102,6 @@ protected:
|
|||||||
PRInt32 PushContent(nsIContent *aContent);
|
PRInt32 PushContent(nsIContent *aContent);
|
||||||
nsIContent* PopContent();
|
nsIContent* PopContent();
|
||||||
|
|
||||||
nsresult EvaluateScript(nsString& aScript, PRUint32 aLineNo);
|
|
||||||
nsresult ProcessEndSCRIPTTag(const nsIParserNode& aNode);
|
nsresult ProcessEndSCRIPTTag(const nsIParserNode& aNode);
|
||||||
nsresult ProcessStartSCRIPTTag(const nsIParserNode& aNode);
|
nsresult ProcessStartSCRIPTTag(const nsIParserNode& aNode);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user