Fix for bug 9392. document.plugins now aliases to window.navigator.plugins. r=nisheeth

This commit is contained in:
vidur%netscape.com 2000-06-21 00:53:26 +00:00
parent c99e74c3a1
commit 3be227878d
17 changed files with 183 additions and 25 deletions

View File

@ -55,7 +55,6 @@
#include "nsIDOMFocusListener.h"
#include "nsIDOMLoadListener.h"
#include "nsIDOMStyleSheet.h"
#include "nsIDOMStyleSheetList.h"
#include "nsDOMAttribute.h"
@ -65,6 +64,7 @@
#include "nsIDOMDocumentView.h"
#include "nsIDOMAbstractView.h"
#include "nsIDOMDocumentXBL.h"
#include "nsIDOMNavigator.h"
#include "nsGenericElement.h"
#include "nsICSSStyleSheet.h"
@ -932,6 +932,16 @@ nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
return rv;
}
nsresult
nsDocument::SetDocumentURL(nsIURI* aURI)
{
NS_IF_RELEASE(mDocumentURL);
mDocumentURL = aURI;
NS_IF_ADDREF(mDocumentURL);
return NS_OK;
}
NS_IMETHODIMP
nsDocument::StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
@ -2459,6 +2469,39 @@ nsDocument::Load (const nsString& aUrl)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetPlugins(nsIDOMPluginArray** aPlugins)
{
NS_ENSURE_ARG_POINTER(aPlugins);
*aPlugins = nsnull;
// XXX Could also get this through mScriptGlobalObject
nsIPresShell *shell = NS_STATIC_CAST(nsIPresShell *,
mPresShells.ElementAt(0));
NS_ENSURE_TRUE(shell, NS_OK);
nsCOMPtr<nsIPresContext> ctx;
nsresult rv = shell->GetPresContext(getter_AddRefs(ctx));
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && ctx, rv);
nsCOMPtr<nsISupports> container;
rv = ctx->GetContainer(getter_AddRefs(container));
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && container, rv);
nsCOMPtr<nsIInterfaceRequestor> ifrq(do_QueryInterface(container));
NS_ENSURE_TRUE(ifrq, NS_OK);
nsCOMPtr<nsIDOMWindow> window;
ifrq->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(window));
NS_ENSURE_TRUE(window, NS_OK);
nsCOMPtr<nsIDOMNavigator> navigator;
window->GetNavigator(getter_AddRefs(navigator));
NS_ENSURE_TRUE(navigator, NS_OK);
return navigator->GetPlugins(aPlugins);
}
//
// nsIDOMNode methods
//
@ -2513,7 +2556,11 @@ nsDocument::GetChildNodes(nsIDOMNodeList** aChildNodes)
NS_IMETHODIMP
nsDocument::HasChildNodes(PRBool* aHasChildNodes)
{
*aHasChildNodes = PR_TRUE;
NS_ENSURE_ARG(aHasChildNodes);
*aHasChildNodes = (((nsnull != mProlog) && (0 != mProlog->Count())) ||
(nsnull != mRootContent) ||
((nsnull != mEpilog) && (0 != mEpilog->Count())));
return NS_OK;
}
@ -2522,6 +2569,7 @@ nsDocument::GetFirstChild(nsIDOMNode** aFirstChild)
{
nsresult result = NS_OK;
*aFirstChild = nsnull;
if ((nsnull != mProlog) && (0 != mProlog->Count())) {
nsIContent* content;
content = (nsIContent *)mProlog->ElementAt(0);
@ -2533,7 +2581,7 @@ nsDocument::GetFirstChild(nsIDOMNode** aFirstChild)
else {
nsIDOMElement* element;
result = GetDocumentElement(&element);
if (NS_OK == result) {
if ((NS_OK == result) && element) {
result = element->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aFirstChild);
NS_RELEASE(element);
}
@ -2557,7 +2605,7 @@ nsDocument::GetLastChild(nsIDOMNode** aLastChild)
else {
nsIDOMElement* element;
result = GetDocumentElement(&element);
if (NS_OK == result) {
if ((NS_OK == result) && element) {
result = element->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aLastChild);
NS_RELEASE(element);
}
@ -3393,7 +3441,7 @@ nsDocument::CreateXIF(nsString & aBuffer, nsIDOMSelection* aSelection)
}
if (!rootElement)
result=GetDocumentElement(getter_AddRefs(rootElement));
if (NS_SUCCEEDED(result))
if (NS_SUCCEEDED(result) && rootElement)
{
#if 1
result=ToXIF(converter,rootElement);

View File

@ -397,7 +397,8 @@ public:
NS_IMETHOD GetWidth(PRInt32* aWidth);
NS_IMETHOD GetHeight(PRInt32* aHeight);
NS_IMETHOD Load (const nsString& aUrl);
NS_IMETHOD GetPlugins(nsIDOMPluginArray** aPlugins);
// nsIDOMNode interface
NS_DECL_IDOMNODE
@ -465,6 +466,7 @@ public:
virtual void Finalize(JSContext *aContext, JSObject *aObj);
virtual nsresult Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
virtual nsresult SetDocumentURL(nsIURI* aURI);
protected:
nsIContent* FindContent(const nsIContent* aStartNode,

View File

@ -135,12 +135,19 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
{
nsresult rv;
nsXMLDocument* doc = new nsXMLDocument(aBaseURI);
*aInstancePtrResult = nsnull;
nsXMLDocument* doc = new nsXMLDocument();
if (doc == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = doc->Reset(nsnull, nsnull);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) {
delete doc;
return rv;
}
doc->SetDocumentURL(aBaseURI);
if (aDoctype) {
nsCOMPtr<nsIDOMNode> tmpNode;
@ -169,14 +176,12 @@ NS_NewXMLDocument(nsIDocument** aInstancePtrResult)
return doc->QueryInterface(kIDocumentIID, (void**) aInstancePtrResult);
}
nsXMLDocument::nsXMLDocument(nsIURI* aBaseURI)
nsXMLDocument::nsXMLDocument()
{
mParser = nsnull;
mAttrStyleSheet = nsnull;
mInlineStyleSheet = nsnull;
mCSSLoader = nsnull;
mDocumentURL = aBaseURI;
NS_IF_ADDREF(mDocumentURL);
#ifdef MOZ_XSL
mTransformMediator = nsnull;

View File

@ -40,7 +40,7 @@ class nsXMLDocument : public nsMarkupDocument,
public nsIHTMLContentContainer
{
public:
nsXMLDocument(nsIURI* aBaseURI = nsnull);
nsXMLDocument();
virtual ~nsXMLDocument();
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);

View File

@ -3069,6 +3069,13 @@ nsXULDocument::Load(const nsString& aUrl)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULDocument::GetPlugins(nsIDOMPluginArray** aPlugins)
{
NS_NOTREACHED("nsXULDocument::GetPlugins");
return NS_ERROR_NOT_IMPLEMENTED;
}
//----------------------------------------------------------------------
//
// nsIDOMXULDocument interface

View File

@ -368,6 +368,7 @@ public:
NS_IMETHOD GetWidth(PRInt32* aWidth);
NS_IMETHOD GetHeight(PRInt32* aHeight);
NS_IMETHOD Load (const nsString& aUrl);
NS_IMETHOD GetPlugins(nsIDOMPluginArray** aPlugins);
// nsIDOMXULDocument interface
NS_DECL_IDOMXULDOCUMENT

View File

@ -29,6 +29,7 @@
#include "nsIScriptContext.h"
class nsIDOMElement;
class nsIDOMPluginArray;
class nsIDOMRange;
#define NS_IDOMNSDOCUMENT_IID \
@ -45,6 +46,8 @@ public:
NS_IMETHOD GetCharacterSet(nsString& aCharacterSet)=0;
NS_IMETHOD GetPlugins(nsIDOMPluginArray** aPlugins)=0;
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aReturn)=0;
NS_IMETHOD CreateRange(nsIDOMRange** aReturn)=0;
@ -57,6 +60,7 @@ public:
NS_IMETHOD GetWidth(PRInt32* aWidth); \
NS_IMETHOD GetHeight(PRInt32* aHeight); \
NS_IMETHOD GetCharacterSet(nsString& aCharacterSet); \
NS_IMETHOD GetPlugins(nsIDOMPluginArray** aPlugins); \
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aReturn); \
NS_IMETHOD CreateRange(nsIDOMRange** aReturn); \
NS_IMETHOD Load(const nsString& aUrl); \
@ -67,6 +71,7 @@ public:
NS_IMETHOD GetWidth(PRInt32* aWidth) { return _to GetWidth(aWidth); } \
NS_IMETHOD GetHeight(PRInt32* aHeight) { return _to GetHeight(aHeight); } \
NS_IMETHOD GetCharacterSet(nsString& aCharacterSet) { return _to GetCharacterSet(aCharacterSet); } \
NS_IMETHOD GetPlugins(nsIDOMPluginArray** aPlugins) { return _to GetPlugins(aPlugins); } \
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aReturn) { return _to CreateElementWithNameSpace(aTagName, aNameSpace, aReturn); } \
NS_IMETHOD CreateRange(nsIDOMRange** aReturn) { return _to CreateRange(aReturn); } \
NS_IMETHOD Load(const nsString& aUrl) { return _to Load(aUrl); } \

View File

@ -88,6 +88,7 @@ interface NSDocument {
readonly attribute long width;
readonly attribute long height;
readonly attribute DOMString characterSet;
readonly attribute PluginArray plugins;
// XXX This should be removed, the new createElementNS should be used in stead
Element createElementWithNameSpace(in DOMString tagName,
in DOMString nameSpace)

View File

@ -756,6 +756,7 @@ enum nsDOMProp {
NS_DOM_PROP_NSDOCUMENT_CREATERANGE,
NS_DOM_PROP_NSDOCUMENT_HEIGHT,
NS_DOM_PROP_NSDOCUMENT_LOAD,
NS_DOM_PROP_NSDOCUMENT_PLUGINS,
NS_DOM_PROP_NSDOCUMENT_WIDTH,
NS_DOM_PROP_NSHTMLANCHORELEMENT_HASH,
NS_DOM_PROP_NSHTMLANCHORELEMENT_HOST,

View File

@ -754,6 +754,7 @@
"nsdocument.createrange", \
"nsdocument.height", \
"nsdocument.load", \
"nsdocument.plugins", \
"nsdocument.width", \
"nshtmlanchorelement.hash", \
"nshtmlanchorelement.host", \

View File

@ -46,6 +46,7 @@
#include "nsIDOMNode.h"
#include "nsIDOMCDATASection.h"
#include "nsIDOMDocumentEvent.h"
#include "nsIDOMPluginArray.h"
#include "nsIDOMEvent.h"
#include "nsIDOMText.h"
#include "nsIDOMDOMImplementation.h"
@ -75,6 +76,7 @@ static NS_DEFINE_IID(kIDocumentXBLIID, NS_IDOMDOCUMENTXBL_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kICDATASectionIID, NS_IDOMCDATASECTION_IID);
static NS_DEFINE_IID(kIDocumentEventIID, NS_IDOMDOCUMENTEVENT_IID);
static NS_DEFINE_IID(kIPluginArrayIID, NS_IDOMPLUGINARRAY_IID);
static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kITextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMImplementationIID, NS_IDOMDOMIMPLEMENTATION_IID);
@ -99,7 +101,8 @@ enum Document_slots {
DOCUMENTVIEW_DEFAULTVIEW = -5,
NSDOCUMENT_WIDTH = -6,
NSDOCUMENT_HEIGHT = -7,
NSDOCUMENT_CHARACTERSET = -8
NSDOCUMENT_CHARACTERSET = -8,
NSDOCUMENT_PLUGINS = -9
};
/***********************************************************************/
@ -258,6 +261,26 @@ GetDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case NSDOCUMENT_PLUGINS:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSDOCUMENT_PLUGINS, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
nsIDOMPluginArray* prop;
nsIDOMNSDocument* b;
if (NS_OK == a->QueryInterface(kINSDocumentIID, (void **)&b)) {
rv = b->GetPlugins(&prop);
if(NS_SUCCEEDED(rv)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);
}
NS_RELEASE(b);
}
else {
rv = NS_ERROR_DOM_WRONG_TYPE_ERR;
}
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);
}
@ -1368,6 +1391,7 @@ static JSPropertySpec DocumentProperties[] =
{"width", NSDOCUMENT_WIDTH, JSPROP_ENUMERATE | JSPROP_READONLY},
{"height", NSDOCUMENT_HEIGHT, JSPROP_ENUMERATE | JSPROP_READONLY},
{"characterSet", NSDOCUMENT_CHARACTERSET, JSPROP_ENUMERATE | JSPROP_READONLY},
{"plugins", NSDOCUMENT_PLUGINS, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};

View File

@ -55,7 +55,6 @@
#include "nsIDOMFocusListener.h"
#include "nsIDOMLoadListener.h"
#include "nsIDOMStyleSheet.h"
#include "nsIDOMStyleSheetList.h"
#include "nsDOMAttribute.h"
@ -65,6 +64,7 @@
#include "nsIDOMDocumentView.h"
#include "nsIDOMAbstractView.h"
#include "nsIDOMDocumentXBL.h"
#include "nsIDOMNavigator.h"
#include "nsGenericElement.h"
#include "nsICSSStyleSheet.h"
@ -932,6 +932,16 @@ nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
return rv;
}
nsresult
nsDocument::SetDocumentURL(nsIURI* aURI)
{
NS_IF_RELEASE(mDocumentURL);
mDocumentURL = aURI;
NS_IF_ADDREF(mDocumentURL);
return NS_OK;
}
NS_IMETHODIMP
nsDocument::StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
@ -2459,6 +2469,39 @@ nsDocument::Load (const nsString& aUrl)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDocument::GetPlugins(nsIDOMPluginArray** aPlugins)
{
NS_ENSURE_ARG_POINTER(aPlugins);
*aPlugins = nsnull;
// XXX Could also get this through mScriptGlobalObject
nsIPresShell *shell = NS_STATIC_CAST(nsIPresShell *,
mPresShells.ElementAt(0));
NS_ENSURE_TRUE(shell, NS_OK);
nsCOMPtr<nsIPresContext> ctx;
nsresult rv = shell->GetPresContext(getter_AddRefs(ctx));
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && ctx, rv);
nsCOMPtr<nsISupports> container;
rv = ctx->GetContainer(getter_AddRefs(container));
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && container, rv);
nsCOMPtr<nsIInterfaceRequestor> ifrq(do_QueryInterface(container));
NS_ENSURE_TRUE(ifrq, NS_OK);
nsCOMPtr<nsIDOMWindow> window;
ifrq->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(window));
NS_ENSURE_TRUE(window, NS_OK);
nsCOMPtr<nsIDOMNavigator> navigator;
window->GetNavigator(getter_AddRefs(navigator));
NS_ENSURE_TRUE(navigator, NS_OK);
return navigator->GetPlugins(aPlugins);
}
//
// nsIDOMNode methods
//
@ -2513,7 +2556,11 @@ nsDocument::GetChildNodes(nsIDOMNodeList** aChildNodes)
NS_IMETHODIMP
nsDocument::HasChildNodes(PRBool* aHasChildNodes)
{
*aHasChildNodes = PR_TRUE;
NS_ENSURE_ARG(aHasChildNodes);
*aHasChildNodes = (((nsnull != mProlog) && (0 != mProlog->Count())) ||
(nsnull != mRootContent) ||
((nsnull != mEpilog) && (0 != mEpilog->Count())));
return NS_OK;
}
@ -2522,6 +2569,7 @@ nsDocument::GetFirstChild(nsIDOMNode** aFirstChild)
{
nsresult result = NS_OK;
*aFirstChild = nsnull;
if ((nsnull != mProlog) && (0 != mProlog->Count())) {
nsIContent* content;
content = (nsIContent *)mProlog->ElementAt(0);
@ -2533,7 +2581,7 @@ nsDocument::GetFirstChild(nsIDOMNode** aFirstChild)
else {
nsIDOMElement* element;
result = GetDocumentElement(&element);
if (NS_OK == result) {
if ((NS_OK == result) && element) {
result = element->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aFirstChild);
NS_RELEASE(element);
}
@ -2557,7 +2605,7 @@ nsDocument::GetLastChild(nsIDOMNode** aLastChild)
else {
nsIDOMElement* element;
result = GetDocumentElement(&element);
if (NS_OK == result) {
if ((NS_OK == result) && element) {
result = element->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aLastChild);
NS_RELEASE(element);
}
@ -3393,7 +3441,7 @@ nsDocument::CreateXIF(nsString & aBuffer, nsIDOMSelection* aSelection)
}
if (!rootElement)
result=GetDocumentElement(getter_AddRefs(rootElement));
if (NS_SUCCEEDED(result))
if (NS_SUCCEEDED(result) && rootElement)
{
#if 1
result=ToXIF(converter,rootElement);

View File

@ -397,7 +397,8 @@ public:
NS_IMETHOD GetWidth(PRInt32* aWidth);
NS_IMETHOD GetHeight(PRInt32* aHeight);
NS_IMETHOD Load (const nsString& aUrl);
NS_IMETHOD GetPlugins(nsIDOMPluginArray** aPlugins);
// nsIDOMNode interface
NS_DECL_IDOMNODE
@ -465,6 +466,7 @@ public:
virtual void Finalize(JSContext *aContext, JSObject *aObj);
virtual nsresult Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
virtual nsresult SetDocumentURL(nsIURI* aURI);
protected:
nsIContent* FindContent(const nsIContent* aStartNode,

View File

@ -135,12 +135,19 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
{
nsresult rv;
nsXMLDocument* doc = new nsXMLDocument(aBaseURI);
*aInstancePtrResult = nsnull;
nsXMLDocument* doc = new nsXMLDocument();
if (doc == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = doc->Reset(nsnull, nsnull);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) {
delete doc;
return rv;
}
doc->SetDocumentURL(aBaseURI);
if (aDoctype) {
nsCOMPtr<nsIDOMNode> tmpNode;
@ -169,14 +176,12 @@ NS_NewXMLDocument(nsIDocument** aInstancePtrResult)
return doc->QueryInterface(kIDocumentIID, (void**) aInstancePtrResult);
}
nsXMLDocument::nsXMLDocument(nsIURI* aBaseURI)
nsXMLDocument::nsXMLDocument()
{
mParser = nsnull;
mAttrStyleSheet = nsnull;
mInlineStyleSheet = nsnull;
mCSSLoader = nsnull;
mDocumentURL = aBaseURI;
NS_IF_ADDREF(mDocumentURL);
#ifdef MOZ_XSL
mTransformMediator = nsnull;

View File

@ -40,7 +40,7 @@ class nsXMLDocument : public nsMarkupDocument,
public nsIHTMLContentContainer
{
public:
nsXMLDocument(nsIURI* aBaseURI = nsnull);
nsXMLDocument();
virtual ~nsXMLDocument();
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);

View File

@ -3069,6 +3069,13 @@ nsXULDocument::Load(const nsString& aUrl)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULDocument::GetPlugins(nsIDOMPluginArray** aPlugins)
{
NS_NOTREACHED("nsXULDocument::GetPlugins");
return NS_ERROR_NOT_IMPLEMENTED;
}
//----------------------------------------------------------------------
//
// nsIDOMXULDocument interface

View File

@ -368,6 +368,7 @@ public:
NS_IMETHOD GetWidth(PRInt32* aWidth);
NS_IMETHOD GetHeight(PRInt32* aHeight);
NS_IMETHOD Load (const nsString& aUrl);
NS_IMETHOD GetPlugins(nsIDOMPluginArray** aPlugins);
// nsIDOMXULDocument interface
NS_DECL_IDOMXULDOCUMENT