Added noscript qualifier to HTMLDocument::Open, Write and Writeln and moved the JS-specific versions over to NSHTMLDocument.

This commit is contained in:
vidur%netscape.com 1999-05-28 00:18:48 +00:00
Родитель c4b12aea87
Коммит b8ecc55881
9 изменённых файлов: 469 добавлений и 408 удалений

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

@ -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<nsIPresContext> 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<nsIPresContext> 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 *

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

@ -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;

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

@ -1,122 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMNSEvent_h__
#define nsIDOMNSEvent_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMRenderingContext;
#define NS_IDOMNSEVENT_IID \
{ 0xa6cf90c4, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
class nsIDOMNSEvent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOMNSEVENT_IID; return iid; }
enum {
EVENT_MOUSEDOWN = 1,
EVENT_MOUSEUP = 2,
EVENT_MOUSEOVER = 4,
EVENT_MOUSEOUT = 8,
EVENT_MOUSEMOVE = 16,
EVENT_MOUSEDRAG = 32,
EVENT_CLICK = 64,
EVENT_DBLCLICK = 128,
EVENT_KEYDOWN = 256,
EVENT_KEYUP = 512,
EVENT_KEYPRESS = 1024,
EVENT_DRAGDROP = 2048,
EVENT_FOCUS = 4096,
EVENT_BLUR = 8192,
EVENT_SELECT = 16384,
EVENT_CHANGE = 32768,
EVENT_RESET = 65536,
EVENT_SUBMIT = 131072,
EVENT_SCROLL = 262144,
EVENT_LOAD = 524288,
EVENT_UNLOAD = 1048576,
EVENT_XFER_DONE = 2097152,
EVENT_ABORT = 4194304,
EVENT_ERROR = 8388608,
EVENT_LOCATE = 16777216,
EVENT_MOVE = 33554432,
EVENT_RESIZE = 67108864,
EVENT_FORWARD = 134217728,
EVENT_HELP = 268435456,
EVENT_BACK = 536870912,
EVENT_TEXT = 1073741824,
EVENT_ALT_MASK = 1,
EVENT_CONTROL_MASK = 2,
EVENT_SHIFT_MASK = 4,
EVENT_META_MASK = 8
};
NS_IMETHOD GetLayerX(PRInt32* aLayerX)=0;
NS_IMETHOD SetLayerX(PRInt32 aLayerX)=0;
NS_IMETHOD GetLayerY(PRInt32* aLayerY)=0;
NS_IMETHOD SetLayerY(PRInt32 aLayerY)=0;
NS_IMETHOD GetPageX(PRInt32* aPageX)=0;
NS_IMETHOD SetPageX(PRInt32 aPageX)=0;
NS_IMETHOD GetPageY(PRInt32* aPageY)=0;
NS_IMETHOD SetPageY(PRInt32 aPageY)=0;
NS_IMETHOD GetWhich(PRUint32* aWhich)=0;
NS_IMETHOD SetWhich(PRUint32 aWhich)=0;
NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc)=0;
};
#define NS_DECL_IDOMNSEVENT \
NS_IMETHOD GetLayerX(PRInt32* aLayerX); \
NS_IMETHOD SetLayerX(PRInt32 aLayerX); \
NS_IMETHOD GetLayerY(PRInt32* aLayerY); \
NS_IMETHOD SetLayerY(PRInt32 aLayerY); \
NS_IMETHOD GetPageX(PRInt32* aPageX); \
NS_IMETHOD SetPageX(PRInt32 aPageX); \
NS_IMETHOD GetPageY(PRInt32* aPageY); \
NS_IMETHOD SetPageY(PRInt32 aPageY); \
NS_IMETHOD GetWhich(PRUint32* aWhich); \
NS_IMETHOD SetWhich(PRUint32 aWhich); \
NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc); \
#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); } \
#endif // nsIDOMNSEvent_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); } \

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

@ -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__

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

@ -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);
};
void open(/* ... */);
void write(/* ... */);
void writeln(/* ... */);
};

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

@ -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}
};

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

@ -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<nsIPresContext> 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<nsIPresContext> 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 *

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

@ -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;