diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp
index 60cb626d1d7..49ec060cb2b 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.cpp
+++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp
@@ -73,7 +73,7 @@ const PRInt32 kBackward = 1;
#endif
// XXX Used to control whether we implement document.layers
-//#define NS_IMPLEMENT_DOCUMENT_LAYERS
+#define NS_IMPLEMENT_DOCUMENT_LAYERS
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
@@ -1229,67 +1229,97 @@ nsHTMLDocument::GetSourceDocumentURL(JSContext* cx,
return result;
}
-NS_IMETHODIMP
-nsHTMLDocument::Open(JSContext *cx, jsval *argv, PRUint32 argc)
+
+// XXX TBI: accepting arguments to the open method.
+nsresult
+nsHTMLDocument::OpenCommon(nsIURL* aSourceURL)
{
nsresult result = NS_OK;
// The open occurred after the document finished loading.
// So we reset the document and create a new one.
if (nsnull == mParser) {
- nsIURL* sourceURL;
-
- // XXX The URL of the newly created document will match
- // that of the source document. Is this right?
- result = GetSourceDocumentURL(cx, &sourceURL);
- // Recover if we had a problem obtaining the source URL
- if (nsnull == sourceURL) {
- result = NS_NewURL(&sourceURL, "about:blank");
- }
-
- if (NS_SUCCEEDED(result)) {
- result = Reset(sourceURL);
- if (NS_OK == result) {
- static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
- static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
-
- result = nsComponentManager::CreateInstance(kCParserCID,
- nsnull,
- kCParserIID,
- (void **)&mParser);
- mIsWriting = 1;
-
- if (NS_OK == result) {
- nsIHTMLContentSink* sink;
- nsIWebShell* webShell = nsnull;
-
- // Get the webshell of our primary presentation shell
- nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0);
- if (nsnull != shell) {
- nsCOMPtr cx;
- shell->GetPresContext(getter_AddRefs(cx));
- nsISupports* container;
- if (NS_OK == cx->GetContainer(&container)) {
- if (nsnull != container) {
- container->QueryInterface(kIWebShellIID, (void**) &webShell);
- }
+ result = Reset(aSourceURL);
+ if (NS_OK == result) {
+ static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
+ static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
+
+ result = nsComponentManager::CreateInstance(kCParserCID,
+ nsnull,
+ kCParserIID,
+ (void **)&mParser);
+ mIsWriting = 1;
+
+ if (NS_OK == result) {
+ nsIHTMLContentSink* sink;
+ nsIWebShell* webShell = nsnull;
+
+ // Get the webshell of our primary presentation shell
+ nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0);
+ if (nsnull != shell) {
+ nsCOMPtr cx;
+ shell->GetPresContext(getter_AddRefs(cx));
+ nsISupports* container;
+ if (NS_OK == cx->GetContainer(&container)) {
+ if (nsnull != container) {
+ container->QueryInterface(kIWebShellIID, (void**) &webShell);
}
}
+ }
- result = NS_NewHTMLContentSink(&sink, this, sourceURL, webShell);
- NS_IF_RELEASE(webShell);
-
- if (NS_OK == result) {
- nsIDTD* theDTD=0;
- NS_NewNavHTMLDTD(&theDTD);
- mParser->RegisterDTD(theDTD);
- mParser->SetContentSink(sink);
- NS_RELEASE(sink);
- }
+ result = NS_NewHTMLContentSink(&sink, this, aSourceURL, 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(sourceURL);
}
}
+
+ return result;
+}
+
+NS_IMETHODIMP
+nsHTMLDocument::Open()
+{
+ nsresult result = NS_OK;
+ nsIURL* sourceURL;
+
+ // XXX For the non-script Open case, we have to make
+ // up a URL.
+ result = NS_NewURL(&sourceURL, "about:blank");
+
+ if (NS_SUCCEEDED(result)) {
+ result = OpenCommon(sourceURL);
+ NS_RELEASE(sourceURL);
+ }
+
+ return result;
+}
+
+NS_IMETHODIMP
+nsHTMLDocument::Open(JSContext *cx, jsval *argv, PRUint32 argc)
+{
+ nsresult result = NS_OK;
+ nsIURL* sourceURL;
+
+ // XXX The URL of the newly created document will match
+ // that of the source document. Is this right?
+ result = GetSourceDocumentURL(cx, &sourceURL);
+ // Recover if we had a problem obtaining the source URL
+ if (nsnull == sourceURL) {
+ result = NS_NewURL(&sourceURL, "about:blank");
+ }
+
+ if (NS_SUCCEEDED(result)) {
+ result = OpenCommon(sourceURL);
+ NS_RELEASE(sourceURL);
+ }
+
return result;
}
@@ -1313,14 +1343,56 @@ nsHTMLDocument::Close()
}
nsresult
-nsHTMLDocument::WriteCommon(JSContext *cx,
- jsval *argv,
- PRUint32 argc,
+nsHTMLDocument::WriteCommon(const nsString& aText,
PRBool aNewlineTerminate)
{
nsresult result = NS_OK;
- // XXX Right now, we only deal with inline document.writes
+ if (nsnull == mParser) {
+ result = Open();
+ if (NS_OK != result) {
+ return result;
+ }
+ }
+
+ nsAutoString str(aText);
+
+ if (aNewlineTerminate) {
+ str.Append('\n');
+ }
+
+ mWriteLevel++;
+ result = mParser->Parse(str, NS_GENERATE_PARSER_KEY(),
+ "text/html", PR_FALSE,
+ (!mIsWriting || (mWriteLevel > 1)));
+ mWriteLevel--;
+ if (NS_OK != result) {
+ return result;
+ }
+
+ return result;
+}
+
+NS_IMETHODIMP
+nsHTMLDocument::Write(const nsString& aText)
+{
+ return WriteCommon(aText, PR_FALSE);
+}
+
+NS_IMETHODIMP
+nsHTMLDocument::Writeln(const nsString& aText)
+{
+ return WriteCommon(aText, PR_TRUE);
+}
+
+nsresult
+nsHTMLDocument::ScriptWriteCommon(JSContext *cx,
+ jsval *argv,
+ PRUint32 argc,
+ PRBool aNewlineTerminate)
+{
+ nsresult result = NS_OK;
+
if (nsnull == mParser) {
result = Open(cx, argv, argc);
if (NS_OK != result) {
@@ -1360,13 +1432,13 @@ nsHTMLDocument::WriteCommon(JSContext *cx,
NS_IMETHODIMP
nsHTMLDocument::Write(JSContext *cx, jsval *argv, PRUint32 argc)
{
- return WriteCommon(cx, argv, argc, PR_FALSE);
+ return ScriptWriteCommon(cx, argv, argc, PR_FALSE);
}
NS_IMETHODIMP
nsHTMLDocument::Writeln(JSContext *cx, jsval *argv, PRUint32 argc)
{
- return WriteCommon(cx, argv, argc, PR_TRUE);
+ return ScriptWriteCommon(cx, argv, argc, PR_TRUE);
}
nsIContent *
diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h
index d87ddd9aa73..b597a614b3c 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.h
+++ b/mozilla/content/html/document/src/nsHTMLDocument.h
@@ -178,11 +178,13 @@ protected:
nsresult GetBodyElement(nsIDOMHTMLBodyElement** aBody);
virtual nsresult Reset(nsIURL *aURL);
- nsresult WriteCommon(JSContext *cx,
- jsval *argv,
- PRUint32 argc,
+ nsresult WriteCommon(const nsString& aText,
PRBool aNewlineTerminate);
-
+ nsresult ScriptWriteCommon(JSContext *cx,
+ jsval *argv,
+ PRUint32 argc,
+ PRBool aNewlineTerminate);
+ nsresult OpenCommon(nsIURL* aUrl);
nsIHTMLStyleSheet* mAttrStyleSheet;
nsIHTMLCSSStyleSheet* mStyleAttrStyleSheet;
diff --git a/mozilla/dom/public/coreEvents/nsIDOMNSEvent.h b/mozilla/dom/public/coreEvents/nsIDOMNSEvent.h
index 1d2be34987d..77706a528d4 100644
--- a/mozilla/dom/public/coreEvents/nsIDOMNSEvent.h
+++ b/mozilla/dom/public/coreEvents/nsIDOMNSEvent.h
@@ -106,17 +106,17 @@ public:
#define NS_FORWARD_IDOMNSEVENT(_to) \
- NS_IMETHOD GetLayerX(PRInt32* aLayerX) { return _to##GetLayerX(aLayerX); } \
- NS_IMETHOD SetLayerX(PRInt32 aLayerX) { return _to##SetLayerX(aLayerX); } \
- NS_IMETHOD GetLayerY(PRInt32* aLayerY) { return _to##GetLayerY(aLayerY); } \
- NS_IMETHOD SetLayerY(PRInt32 aLayerY) { return _to##SetLayerY(aLayerY); } \
- NS_IMETHOD GetPageX(PRInt32* aPageX) { return _to##GetPageX(aPageX); } \
- NS_IMETHOD SetPageX(PRInt32 aPageX) { return _to##SetPageX(aPageX); } \
- NS_IMETHOD GetPageY(PRInt32* aPageY) { return _to##GetPageY(aPageY); } \
- NS_IMETHOD SetPageY(PRInt32 aPageY) { return _to##SetPageY(aPageY); } \
- NS_IMETHOD GetWhich(PRUint32* aWhich) { return _to##GetWhich(aWhich); } \
- NS_IMETHOD SetWhich(PRUint32 aWhich) { return _to##SetWhich(aWhich); } \
- NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc) { return _to##GetRc(aRc); } \
+ NS_IMETHOD GetLayerX(PRInt32* aLayerX) { return _to GetLayerX(aLayerX); } \
+ NS_IMETHOD SetLayerX(PRInt32 aLayerX) { return _to SetLayerX(aLayerX); } \
+ NS_IMETHOD GetLayerY(PRInt32* aLayerY) { return _to GetLayerY(aLayerY); } \
+ NS_IMETHOD SetLayerY(PRInt32 aLayerY) { return _to SetLayerY(aLayerY); } \
+ NS_IMETHOD GetPageX(PRInt32* aPageX) { return _to GetPageX(aPageX); } \
+ NS_IMETHOD SetPageX(PRInt32 aPageX) { return _to SetPageX(aPageX); } \
+ NS_IMETHOD GetPageY(PRInt32* aPageY) { return _to GetPageY(aPageY); } \
+ NS_IMETHOD SetPageY(PRInt32 aPageY) { return _to SetPageY(aPageY); } \
+ NS_IMETHOD GetWhich(PRUint32* aWhich) { return _to GetWhich(aWhich); } \
+ NS_IMETHOD SetWhich(PRUint32 aWhich) { return _to SetWhich(aWhich); } \
+ NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc) { return _to GetRc(aRc); } \
#endif // nsIDOMNSEvent_h__
diff --git a/mozilla/dom/public/html/nsIDOMHTMLDocument.h b/mozilla/dom/public/html/nsIDOMHTMLDocument.h
index 2b20ab5b100..e1c54b170e7 100644
--- a/mozilla/dom/public/html/nsIDOMHTMLDocument.h
+++ b/mozilla/dom/public/html/nsIDOMHTMLDocument.h
@@ -24,7 +24,6 @@
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMDocument.h"
-#include "jsapi.h"
class nsIDOMElement;
class nsIDOMHTMLElement;
@@ -64,13 +63,13 @@ public:
NS_IMETHOD GetCookie(nsString& aCookie)=0;
NS_IMETHOD SetCookie(const nsString& aCookie)=0;
- NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc)=0;
+ NS_IMETHOD Open()=0;
NS_IMETHOD Close()=0;
- NS_IMETHOD Write(JSContext *cx, jsval *argv, PRUint32 argc)=0;
+ NS_IMETHOD Write(const nsString& aText)=0;
- NS_IMETHOD Writeln(JSContext *cx, jsval *argv, PRUint32 argc)=0;
+ NS_IMETHOD Writeln(const nsString& aText)=0;
NS_IMETHOD GetElementById(const nsString& aElementId, nsIDOMElement** aReturn)=0;
@@ -93,10 +92,10 @@ public:
NS_IMETHOD GetAnchors(nsIDOMHTMLCollection** aAnchors); \
NS_IMETHOD GetCookie(nsString& aCookie); \
NS_IMETHOD SetCookie(const nsString& aCookie); \
- NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc); \
+ NS_IMETHOD Open(); \
NS_IMETHOD Close(); \
- NS_IMETHOD Write(JSContext *cx, jsval *argv, PRUint32 argc); \
- NS_IMETHOD Writeln(JSContext *cx, jsval *argv, PRUint32 argc); \
+ NS_IMETHOD Write(const nsString& aText); \
+ NS_IMETHOD Writeln(const nsString& aText); \
NS_IMETHOD GetElementById(const nsString& aElementId, nsIDOMElement** aReturn); \
NS_IMETHOD GetElementsByName(const nsString& aElementName, nsIDOMNodeList** aReturn); \
@@ -117,10 +116,10 @@ public:
NS_IMETHOD GetAnchors(nsIDOMHTMLCollection** aAnchors) { return _to GetAnchors(aAnchors); } \
NS_IMETHOD GetCookie(nsString& aCookie) { return _to GetCookie(aCookie); } \
NS_IMETHOD SetCookie(const nsString& aCookie) { return _to SetCookie(aCookie); } \
- NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc) { return _to Open(cx, argv, argc); } \
+ NS_IMETHOD Open() { return _to Open(); } \
NS_IMETHOD Close() { return _to Close(); } \
- NS_IMETHOD Write(JSContext *cx, jsval *argv, PRUint32 argc) { return _to Write(cx, argv, argc); } \
- NS_IMETHOD Writeln(JSContext *cx, jsval *argv, PRUint32 argc) { return _to Writeln(cx, argv, argc); } \
+ NS_IMETHOD Write(const nsString& aText) { return _to Write(aText); } \
+ NS_IMETHOD Writeln(const nsString& aText) { return _to Writeln(aText); } \
NS_IMETHOD GetElementById(const nsString& aElementId, nsIDOMElement** aReturn) { return _to GetElementById(aElementId, aReturn); } \
NS_IMETHOD GetElementsByName(const nsString& aElementName, nsIDOMNodeList** aReturn) { return _to GetElementsByName(aElementName, aReturn); } \
diff --git a/mozilla/dom/public/html/nsIDOMNSHTMLDocument.h b/mozilla/dom/public/html/nsIDOMNSHTMLDocument.h
index 27021010d2b..862f36846f2 100644
--- a/mozilla/dom/public/html/nsIDOMNSHTMLDocument.h
+++ b/mozilla/dom/public/html/nsIDOMNSHTMLDocument.h
@@ -23,6 +23,7 @@
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
+#include "jsapi.h"
class nsIDOMElement;
class nsIDOMHTMLCollection;
@@ -61,6 +62,12 @@ public:
NS_IMETHOD GetSelection(nsString& aReturn)=0;
NS_IMETHOD NamedItem(const nsString& aName, nsIDOMElement** aReturn)=0;
+
+ NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc)=0;
+
+ NS_IMETHOD Write(JSContext *cx, jsval *argv, PRUint32 argc)=0;
+
+ NS_IMETHOD Writeln(JSContext *cx, jsval *argv, PRUint32 argc)=0;
};
@@ -81,6 +88,9 @@ public:
NS_IMETHOD GetPlugins(nsIDOMHTMLCollection** aPlugins); \
NS_IMETHOD GetSelection(nsString& aReturn); \
NS_IMETHOD NamedItem(const nsString& aName, nsIDOMElement** aReturn); \
+ NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc); \
+ NS_IMETHOD Write(JSContext *cx, jsval *argv, PRUint32 argc); \
+ NS_IMETHOD Writeln(JSContext *cx, jsval *argv, PRUint32 argc); \
@@ -101,6 +111,9 @@ public:
NS_IMETHOD GetPlugins(nsIDOMHTMLCollection** aPlugins) { return _to GetPlugins(aPlugins); } \
NS_IMETHOD GetSelection(nsString& aReturn) { return _to GetSelection(aReturn); } \
NS_IMETHOD NamedItem(const nsString& aName, nsIDOMElement** aReturn) { return _to NamedItem(aName, aReturn); } \
+ NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc) { return _to Open(cx, argv, argc); } \
+ NS_IMETHOD Write(JSContext *cx, jsval *argv, PRUint32 argc) { return _to Write(cx, argv, argc); } \
+ NS_IMETHOD Writeln(JSContext *cx, jsval *argv, PRUint32 argc) { return _to Writeln(cx, argv, argc); } \
#endif // nsIDOMNSHTMLDocument_h__
diff --git a/mozilla/dom/public/idl/html/HTMLDocument.idl b/mozilla/dom/public/idl/html/HTMLDocument.idl
index 0cd7d42da22..5f033702ac6 100644
--- a/mozilla/dom/public/idl/html/HTMLDocument.idl
+++ b/mozilla/dom/public/idl/html/HTMLDocument.idl
@@ -13,10 +13,11 @@
readonly attribute HTMLCollection forms;
readonly attribute HTMLCollection anchors;
attribute DOMString cookie;
- void open(/* ... */);
+
+ noscript void open();
void close();
- void write(/* ... */);
- void writeln(/* ... */);
+ noscript void write(in DOMString text);
+ noscript void writeln(in DOMString text);
Element getElementById(in DOMString elementId);
NodeList getElementsByName(in DOMString elementName);
};
@@ -38,4 +39,8 @@
wstring getSelection();
Element namedItem(in wstring name);
- };
\ No newline at end of file
+
+ void open(/* ... */);
+ void write(/* ... */);
+ void writeln(/* ... */);
+ };
diff --git a/mozilla/dom/src/html/nsJSHTMLDocument.cpp b/mozilla/dom/src/html/nsJSHTMLDocument.cpp
index 8dd0e910523..8857fae7fbe 100644
--- a/mozilla/dom/src/html/nsJSHTMLDocument.cpp
+++ b/mozilla/dom/src/html/nsJSHTMLDocument.cpp
@@ -782,54 +782,6 @@ ResolveHTMLDocument(JSContext *cx, JSObject *obj, jsval id)
}
-//
-// Native method Open
-//
-PR_STATIC_CALLBACK(JSBool)
-HTMLDocumentOpen(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
- nsIDOMHTMLDocument *nativeThis = (nsIDOMHTMLDocument*)JS_GetPrivate(cx, obj);
- JSBool rBool = JS_FALSE;
-
- *rval = JSVAL_NULL;
-
- nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
- nsIScriptSecurityManager *secMan;
- if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
- PRBool ok;
- secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.open", &ok);
- if (!ok) {
- //Need to throw error here
- return JS_FALSE;
- }
- NS_RELEASE(secMan);
- }
- else {
- return JS_FALSE;
- }
-
- // If there's no private data, this must be the prototype, so ignore
- if (nsnull == nativeThis) {
- return JS_TRUE;
- }
-
- if (argc >= 0) {
-
- if (NS_OK != nativeThis->Open(cx, argv+0, argc-0)) {
- return JS_FALSE;
- }
-
- *rval = JSVAL_VOID;
- }
- else {
- JS_ReportError(cx, "Function open requires 0 parameters");
- return JS_FALSE;
- }
-
- return JS_TRUE;
-}
-
-
//
// Native method Close
//
@@ -845,7 +797,7 @@ HTMLDocumentClose(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *
nsIScriptSecurityManager *secMan;
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
PRBool ok;
- secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.close", &ok);
+ secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.open", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
@@ -878,102 +830,6 @@ HTMLDocumentClose(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *
}
-//
-// Native method Write
-//
-PR_STATIC_CALLBACK(JSBool)
-HTMLDocumentWrite(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
- nsIDOMHTMLDocument *nativeThis = (nsIDOMHTMLDocument*)JS_GetPrivate(cx, obj);
- JSBool rBool = JS_FALSE;
-
- *rval = JSVAL_NULL;
-
- nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
- nsIScriptSecurityManager *secMan;
- if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
- PRBool ok;
- secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.write", &ok);
- if (!ok) {
- //Need to throw error here
- return JS_FALSE;
- }
- NS_RELEASE(secMan);
- }
- else {
- return JS_FALSE;
- }
-
- // If there's no private data, this must be the prototype, so ignore
- if (nsnull == nativeThis) {
- return JS_TRUE;
- }
-
- if (argc >= 0) {
-
- if (NS_OK != nativeThis->Write(cx, argv+0, argc-0)) {
- return JS_FALSE;
- }
-
- *rval = JSVAL_VOID;
- }
- else {
- JS_ReportError(cx, "Function write requires 0 parameters");
- return JS_FALSE;
- }
-
- return JS_TRUE;
-}
-
-
-//
-// Native method Writeln
-//
-PR_STATIC_CALLBACK(JSBool)
-HTMLDocumentWriteln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
- nsIDOMHTMLDocument *nativeThis = (nsIDOMHTMLDocument*)JS_GetPrivate(cx, obj);
- JSBool rBool = JS_FALSE;
-
- *rval = JSVAL_NULL;
-
- nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
- nsIScriptSecurityManager *secMan;
- if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
- PRBool ok;
- secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.writeln", &ok);
- if (!ok) {
- //Need to throw error here
- return JS_FALSE;
- }
- NS_RELEASE(secMan);
- }
- else {
- return JS_FALSE;
- }
-
- // If there's no private data, this must be the prototype, so ignore
- if (nsnull == nativeThis) {
- return JS_TRUE;
- }
-
- if (argc >= 0) {
-
- if (NS_OK != nativeThis->Writeln(cx, argv+0, argc-0)) {
- return JS_FALSE;
- }
-
- *rval = JSVAL_VOID;
- }
- else {
- JS_ReportError(cx, "Function writeln requires 0 parameters");
- return JS_FALSE;
- }
-
- return JS_TRUE;
-}
-
-
//
// Native method GetElementById
//
@@ -991,7 +847,7 @@ HTMLDocumentGetElementById(JSContext *cx, JSObject *obj, uintN argc, jsval *argv
nsIScriptSecurityManager *secMan;
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
PRBool ok;
- secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.getelementbyid", &ok);
+ secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.close", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
@@ -1043,7 +899,7 @@ HTMLDocumentGetElementsByName(JSContext *cx, JSObject *obj, uintN argc, jsval *a
nsIScriptSecurityManager *secMan;
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
PRBool ok;
- secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.getelementsbyname", &ok);
+ secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.write", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
@@ -1100,7 +956,7 @@ NSHTMLDocumentGetSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv
nsIScriptSecurityManager *secMan;
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
PRBool ok;
- secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.getselection", &ok);
+ secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.writeln", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
@@ -1156,7 +1012,7 @@ NSHTMLDocumentNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j
nsIScriptSecurityManager *secMan;
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
PRBool ok;
- secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.nameditem", &ok);
+ secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.getelementbyid", &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
@@ -1191,6 +1047,168 @@ NSHTMLDocumentNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j
}
+//
+// Native method Open
+//
+PR_STATIC_CALLBACK(JSBool)
+NSHTMLDocumentOpen(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+ nsIDOMHTMLDocument *privateThis = (nsIDOMHTMLDocument*)JS_GetPrivate(cx, obj);
+ nsIDOMNSHTMLDocument *nativeThis = nsnull;
+ if (NS_OK != privateThis->QueryInterface(kINSHTMLDocumentIID, (void **)&nativeThis)) {
+ JS_ReportError(cx, "Object must be of type NSHTMLDocument");
+ return JS_FALSE;
+ }
+
+ JSBool rBool = JS_FALSE;
+
+ *rval = JSVAL_NULL;
+
+ nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
+ nsIScriptSecurityManager *secMan;
+ if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
+ PRBool ok;
+ secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.getelementsbyname", &ok);
+ if (!ok) {
+ //Need to throw error here
+ return JS_FALSE;
+ }
+ NS_RELEASE(secMan);
+ }
+ else {
+ return JS_FALSE;
+ }
+
+ // If there's no private data, this must be the prototype, so ignore
+ if (nsnull == nativeThis) {
+ return JS_TRUE;
+ }
+
+ if (argc >= 0) {
+
+ if (NS_OK != nativeThis->Open(cx, argv+0, argc-0)) {
+ return JS_FALSE;
+ }
+
+ *rval = JSVAL_VOID;
+ }
+ else {
+ JS_ReportError(cx, "Function open requires 0 parameters");
+ return JS_FALSE;
+ }
+
+ return JS_TRUE;
+}
+
+
+//
+// Native method Write
+//
+PR_STATIC_CALLBACK(JSBool)
+NSHTMLDocumentWrite(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+ nsIDOMHTMLDocument *privateThis = (nsIDOMHTMLDocument*)JS_GetPrivate(cx, obj);
+ nsIDOMNSHTMLDocument *nativeThis = nsnull;
+ if (NS_OK != privateThis->QueryInterface(kINSHTMLDocumentIID, (void **)&nativeThis)) {
+ JS_ReportError(cx, "Object must be of type NSHTMLDocument");
+ return JS_FALSE;
+ }
+
+ JSBool rBool = JS_FALSE;
+
+ *rval = JSVAL_NULL;
+
+ nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
+ nsIScriptSecurityManager *secMan;
+ if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
+ PRBool ok;
+ secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.getselection", &ok);
+ if (!ok) {
+ //Need to throw error here
+ return JS_FALSE;
+ }
+ NS_RELEASE(secMan);
+ }
+ else {
+ return JS_FALSE;
+ }
+
+ // If there's no private data, this must be the prototype, so ignore
+ if (nsnull == nativeThis) {
+ return JS_TRUE;
+ }
+
+ if (argc >= 0) {
+
+ if (NS_OK != nativeThis->Write(cx, argv+0, argc-0)) {
+ return JS_FALSE;
+ }
+
+ *rval = JSVAL_VOID;
+ }
+ else {
+ JS_ReportError(cx, "Function write requires 0 parameters");
+ return JS_FALSE;
+ }
+
+ return JS_TRUE;
+}
+
+
+//
+// Native method Writeln
+//
+PR_STATIC_CALLBACK(JSBool)
+NSHTMLDocumentWriteln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+ nsIDOMHTMLDocument *privateThis = (nsIDOMHTMLDocument*)JS_GetPrivate(cx, obj);
+ nsIDOMNSHTMLDocument *nativeThis = nsnull;
+ if (NS_OK != privateThis->QueryInterface(kINSHTMLDocumentIID, (void **)&nativeThis)) {
+ JS_ReportError(cx, "Object must be of type NSHTMLDocument");
+ return JS_FALSE;
+ }
+
+ JSBool rBool = JS_FALSE;
+
+ *rval = JSVAL_NULL;
+
+ nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
+ nsIScriptSecurityManager *secMan;
+ if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
+ PRBool ok;
+ secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.nameditem", &ok);
+ if (!ok) {
+ //Need to throw error here
+ return JS_FALSE;
+ }
+ NS_RELEASE(secMan);
+ }
+ else {
+ return JS_FALSE;
+ }
+
+ // If there's no private data, this must be the prototype, so ignore
+ if (nsnull == nativeThis) {
+ return JS_TRUE;
+ }
+
+ if (argc >= 0) {
+
+ if (NS_OK != nativeThis->Writeln(cx, argv+0, argc-0)) {
+ return JS_FALSE;
+ }
+
+ *rval = JSVAL_VOID;
+ }
+ else {
+ JS_ReportError(cx, "Function writeln requires 0 parameters");
+ return JS_FALSE;
+ }
+
+ return JS_TRUE;
+}
+
+
/***********************************************************************/
//
// class for HTMLDocument
@@ -1243,14 +1261,14 @@ static JSPropertySpec HTMLDocumentProperties[] =
//
static JSFunctionSpec HTMLDocumentMethods[] =
{
- {"open", HTMLDocumentOpen, 0},
{"close", HTMLDocumentClose, 0},
- {"write", HTMLDocumentWrite, 0},
- {"writeln", HTMLDocumentWriteln, 0},
{"getElementById", HTMLDocumentGetElementById, 1},
{"getElementsByName", HTMLDocumentGetElementsByName, 1},
{"getSelection", NSHTMLDocumentGetSelection, 0},
{"namedItem", NSHTMLDocumentNamedItem, 1},
+ {"open", NSHTMLDocumentOpen, 0},
+ {"write", NSHTMLDocumentWrite, 0},
+ {"writeln", NSHTMLDocumentWriteln, 0},
{0}
};
diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp
index 60cb626d1d7..49ec060cb2b 100644
--- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp
+++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp
@@ -73,7 +73,7 @@ const PRInt32 kBackward = 1;
#endif
// XXX Used to control whether we implement document.layers
-//#define NS_IMPLEMENT_DOCUMENT_LAYERS
+#define NS_IMPLEMENT_DOCUMENT_LAYERS
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
@@ -1229,67 +1229,97 @@ nsHTMLDocument::GetSourceDocumentURL(JSContext* cx,
return result;
}
-NS_IMETHODIMP
-nsHTMLDocument::Open(JSContext *cx, jsval *argv, PRUint32 argc)
+
+// XXX TBI: accepting arguments to the open method.
+nsresult
+nsHTMLDocument::OpenCommon(nsIURL* aSourceURL)
{
nsresult result = NS_OK;
// The open occurred after the document finished loading.
// So we reset the document and create a new one.
if (nsnull == mParser) {
- nsIURL* sourceURL;
-
- // XXX The URL of the newly created document will match
- // that of the source document. Is this right?
- result = GetSourceDocumentURL(cx, &sourceURL);
- // Recover if we had a problem obtaining the source URL
- if (nsnull == sourceURL) {
- result = NS_NewURL(&sourceURL, "about:blank");
- }
-
- if (NS_SUCCEEDED(result)) {
- result = Reset(sourceURL);
- if (NS_OK == result) {
- static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
- static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
-
- result = nsComponentManager::CreateInstance(kCParserCID,
- nsnull,
- kCParserIID,
- (void **)&mParser);
- mIsWriting = 1;
-
- if (NS_OK == result) {
- nsIHTMLContentSink* sink;
- nsIWebShell* webShell = nsnull;
-
- // Get the webshell of our primary presentation shell
- nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0);
- if (nsnull != shell) {
- nsCOMPtr cx;
- shell->GetPresContext(getter_AddRefs(cx));
- nsISupports* container;
- if (NS_OK == cx->GetContainer(&container)) {
- if (nsnull != container) {
- container->QueryInterface(kIWebShellIID, (void**) &webShell);
- }
+ result = Reset(aSourceURL);
+ if (NS_OK == result) {
+ static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
+ static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
+
+ result = nsComponentManager::CreateInstance(kCParserCID,
+ nsnull,
+ kCParserIID,
+ (void **)&mParser);
+ mIsWriting = 1;
+
+ if (NS_OK == result) {
+ nsIHTMLContentSink* sink;
+ nsIWebShell* webShell = nsnull;
+
+ // Get the webshell of our primary presentation shell
+ nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0);
+ if (nsnull != shell) {
+ nsCOMPtr cx;
+ shell->GetPresContext(getter_AddRefs(cx));
+ nsISupports* container;
+ if (NS_OK == cx->GetContainer(&container)) {
+ if (nsnull != container) {
+ container->QueryInterface(kIWebShellIID, (void**) &webShell);
}
}
+ }
- result = NS_NewHTMLContentSink(&sink, this, sourceURL, webShell);
- NS_IF_RELEASE(webShell);
-
- if (NS_OK == result) {
- nsIDTD* theDTD=0;
- NS_NewNavHTMLDTD(&theDTD);
- mParser->RegisterDTD(theDTD);
- mParser->SetContentSink(sink);
- NS_RELEASE(sink);
- }
+ result = NS_NewHTMLContentSink(&sink, this, aSourceURL, 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(sourceURL);
}
}
+
+ return result;
+}
+
+NS_IMETHODIMP
+nsHTMLDocument::Open()
+{
+ nsresult result = NS_OK;
+ nsIURL* sourceURL;
+
+ // XXX For the non-script Open case, we have to make
+ // up a URL.
+ result = NS_NewURL(&sourceURL, "about:blank");
+
+ if (NS_SUCCEEDED(result)) {
+ result = OpenCommon(sourceURL);
+ NS_RELEASE(sourceURL);
+ }
+
+ return result;
+}
+
+NS_IMETHODIMP
+nsHTMLDocument::Open(JSContext *cx, jsval *argv, PRUint32 argc)
+{
+ nsresult result = NS_OK;
+ nsIURL* sourceURL;
+
+ // XXX The URL of the newly created document will match
+ // that of the source document. Is this right?
+ result = GetSourceDocumentURL(cx, &sourceURL);
+ // Recover if we had a problem obtaining the source URL
+ if (nsnull == sourceURL) {
+ result = NS_NewURL(&sourceURL, "about:blank");
+ }
+
+ if (NS_SUCCEEDED(result)) {
+ result = OpenCommon(sourceURL);
+ NS_RELEASE(sourceURL);
+ }
+
return result;
}
@@ -1313,14 +1343,56 @@ nsHTMLDocument::Close()
}
nsresult
-nsHTMLDocument::WriteCommon(JSContext *cx,
- jsval *argv,
- PRUint32 argc,
+nsHTMLDocument::WriteCommon(const nsString& aText,
PRBool aNewlineTerminate)
{
nsresult result = NS_OK;
- // XXX Right now, we only deal with inline document.writes
+ if (nsnull == mParser) {
+ result = Open();
+ if (NS_OK != result) {
+ return result;
+ }
+ }
+
+ nsAutoString str(aText);
+
+ if (aNewlineTerminate) {
+ str.Append('\n');
+ }
+
+ mWriteLevel++;
+ result = mParser->Parse(str, NS_GENERATE_PARSER_KEY(),
+ "text/html", PR_FALSE,
+ (!mIsWriting || (mWriteLevel > 1)));
+ mWriteLevel--;
+ if (NS_OK != result) {
+ return result;
+ }
+
+ return result;
+}
+
+NS_IMETHODIMP
+nsHTMLDocument::Write(const nsString& aText)
+{
+ return WriteCommon(aText, PR_FALSE);
+}
+
+NS_IMETHODIMP
+nsHTMLDocument::Writeln(const nsString& aText)
+{
+ return WriteCommon(aText, PR_TRUE);
+}
+
+nsresult
+nsHTMLDocument::ScriptWriteCommon(JSContext *cx,
+ jsval *argv,
+ PRUint32 argc,
+ PRBool aNewlineTerminate)
+{
+ nsresult result = NS_OK;
+
if (nsnull == mParser) {
result = Open(cx, argv, argc);
if (NS_OK != result) {
@@ -1360,13 +1432,13 @@ nsHTMLDocument::WriteCommon(JSContext *cx,
NS_IMETHODIMP
nsHTMLDocument::Write(JSContext *cx, jsval *argv, PRUint32 argc)
{
- return WriteCommon(cx, argv, argc, PR_FALSE);
+ return ScriptWriteCommon(cx, argv, argc, PR_FALSE);
}
NS_IMETHODIMP
nsHTMLDocument::Writeln(JSContext *cx, jsval *argv, PRUint32 argc)
{
- return WriteCommon(cx, argv, argc, PR_TRUE);
+ return ScriptWriteCommon(cx, argv, argc, PR_TRUE);
}
nsIContent *
diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.h b/mozilla/layout/html/document/src/nsHTMLDocument.h
index d87ddd9aa73..b597a614b3c 100644
--- a/mozilla/layout/html/document/src/nsHTMLDocument.h
+++ b/mozilla/layout/html/document/src/nsHTMLDocument.h
@@ -178,11 +178,13 @@ protected:
nsresult GetBodyElement(nsIDOMHTMLBodyElement** aBody);
virtual nsresult Reset(nsIURL *aURL);
- nsresult WriteCommon(JSContext *cx,
- jsval *argv,
- PRUint32 argc,
+ nsresult WriteCommon(const nsString& aText,
PRBool aNewlineTerminate);
-
+ nsresult ScriptWriteCommon(JSContext *cx,
+ jsval *argv,
+ PRUint32 argc,
+ PRBool aNewlineTerminate);
+ nsresult OpenCommon(nsIURL* aUrl);
nsIHTMLStyleSheet* mAttrStyleSheet;
nsIHTMLCSSStyleSheet* mStyleAttrStyleSheet;