From adf1d8320a8efdfa36617a22296620747f296a80 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Tue, 8 May 2001 16:46:42 +0000 Subject: [PATCH] Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com. --- accessible/src/base/nsRootAccessible.cpp | 6 +- accessible/src/base/nsRootAccessible.h | 6 +- accessible/src/base/nsSelectAccessible.cpp | 6 +- accessible/src/nsMutableAccessible.h | 52 - accessible/src/nsRootAccessible.cpp | 6 +- accessible/src/nsRootAccessible.h | 6 +- accessible/src/nsSelectAccessible.cpp | 6 +- allmakefiles.sh | 17 +- build/mac/build_scripts/MozillaBuildList.pm | 30 +- caps/idl/nsIScriptSecurityManager.idl | 228 +- caps/include/nsScriptSecurityManager.h | 142 +- caps/src/nsScriptSecurityManager.cpp | 2445 ++++++++--------- caps/src/nsSecurityManagerFactory.cpp | 321 ++- content/base/public/MANIFEST | 2 +- content/base/public/nsContentUtils.h | 58 +- content/base/public/nsIContent.h | 18 +- content/base/public/nsIContentPolicy.idl | 4 +- content/base/public/nsIDocument.h | 12 +- content/base/public/nsINodeInfo.h | 22 +- content/base/public/nsISelection.idl | 7 +- .../base/public/nsISelectionController.idl | 4 +- content/base/public/nsISelectionListener.idl | 5 +- content/base/public/nsISelectionPrivate.idl | 9 +- content/base/src/makefile.win | 16 +- content/base/src/nsCommentNode.cpp | 55 +- content/base/src/nsContentList.cpp | 110 +- content/base/src/nsContentList.h | 14 +- content/base/src/nsContentUtils.cpp | 243 +- content/base/src/nsDOMAttribute.cpp | 138 +- content/base/src/nsDOMAttribute.h | 21 +- content/base/src/nsDOMAttributeMap.cpp | 48 +- content/base/src/nsDOMAttributeMap.h | 22 +- content/base/src/nsDOMDocumentType.cpp | 39 +- content/base/src/nsDOMDocumentType.h | 30 +- content/base/src/nsDocument.cpp | 370 ++- content/base/src/nsDocument.h | 144 +- content/base/src/nsDocumentFragment.cpp | 62 +- content/base/src/nsDocumentViewer.cpp | 12 +- content/base/src/nsGenericDOMDataNode.cpp | 89 +- content/base/src/nsGenericDOMDataNode.h | 110 +- content/base/src/nsGenericDOMNodeList.cpp | 61 +- content/base/src/nsGenericDOMNodeList.h | 19 +- content/base/src/nsGenericElement.cpp | 458 +-- content/base/src/nsGenericElement.h | 69 +- content/base/src/nsNodeInfo.cpp | 15 +- content/base/src/nsNodeInfo.h | 1 + content/base/src/nsNodeInfoManager.cpp | 27 +- content/base/src/nsNodeInfoManager.h | 6 +- content/base/src/nsRange.cpp | 85 +- content/base/src/nsRange.h | 11 +- content/base/src/nsSelection.cpp | 85 +- content/base/src/nsTextNode.cpp | 58 +- content/build/Makefile.in | 2 +- content/build/makefile.win | 3 +- content/build/nsContentFactory.cpp | 3 - content/build/nsContentModule.cpp | 149 +- content/build/nsContentModule.h | 78 - .../events/public/nsIEventListenerManager.h | 103 +- content/events/src/makefile.win | 9 +- content/events/src/nsDOMEvent.cpp | 113 +- content/events/src/nsDOMEvent.h | 38 +- content/events/src/nsDOMMutationEvent.cpp | 23 +- content/events/src/nsEventListenerManager.cpp | 294 +- content/events/src/nsEventListenerManager.h | 92 +- content/events/src/nsEventStateManager.cpp | 12 +- content/events/src/nsPrivateTextRange.h | 2 +- content/html/content/public/nsIForm.h | 30 +- .../content/src/GenericElementCollection.h | 1 + .../html/content/src/nsAttributeContent.cpp | 4 + .../src/nsGenericDOMHTMLCollection.cpp | 46 +- .../content/src/nsGenericDOMHTMLCollection.h | 18 +- .../html/content/src/nsGenericHTMLElement.cpp | 180 +- .../html/content/src/nsGenericHTMLElement.h | 66 +- .../html/content/src/nsHTMLAnchorElement.cpp | 40 +- .../html/content/src/nsHTMLAppletElement.cpp | 30 +- .../html/content/src/nsHTMLAreaElement.cpp | 31 +- content/html/content/src/nsHTMLBRElement.cpp | 25 +- .../html/content/src/nsHTMLBaseElement.cpp | 25 +- .../content/src/nsHTMLBaseFontElement.cpp | 25 +- .../html/content/src/nsHTMLBodyElement.cpp | 25 +- .../html/content/src/nsHTMLButtonElement.cpp | 29 +- .../html/content/src/nsHTMLDListElement.cpp | 23 +- content/html/content/src/nsHTMLDelElement.cpp | 25 +- .../content/src/nsHTMLDirectoryElement.cpp | 25 +- content/html/content/src/nsHTMLDivElement.cpp | 25 +- .../html/content/src/nsHTMLEmbedElement.cpp | 34 +- .../content/src/nsHTMLFieldSetElement.cpp | 24 +- .../html/content/src/nsHTMLFontElement.cpp | 25 +- .../html/content/src/nsHTMLFormElement.cpp | 432 +-- .../html/content/src/nsHTMLFrameElement.cpp | 32 +- .../content/src/nsHTMLFrameSetElement.cpp | 25 +- content/html/content/src/nsHTMLHRElement.cpp | 25 +- .../html/content/src/nsHTMLHeadElement.cpp | 25 +- .../html/content/src/nsHTMLHeadingElement.cpp | 25 +- .../html/content/src/nsHTMLHtmlElement.cpp | 25 +- .../html/content/src/nsHTMLIFrameElement.cpp | 34 +- .../html/content/src/nsHTMLImageElement.cpp | 281 +- .../html/content/src/nsHTMLInputElement.cpp | 27 +- content/html/content/src/nsHTMLInsElement.cpp | 25 +- .../html/content/src/nsHTMLIsIndexElement.cpp | 25 +- content/html/content/src/nsHTMLLIElement.cpp | 25 +- .../html/content/src/nsHTMLLabelElement.cpp | 25 +- .../html/content/src/nsHTMLLegendElement.cpp | 26 +- .../html/content/src/nsHTMLLinkElement.cpp | 31 +- content/html/content/src/nsHTMLMapElement.cpp | 25 +- .../html/content/src/nsHTMLMenuElement.cpp | 23 +- .../html/content/src/nsHTMLMetaElement.cpp | 25 +- content/html/content/src/nsHTMLModElement.cpp | 25 +- .../html/content/src/nsHTMLOListElement.cpp | 25 +- .../html/content/src/nsHTMLObjectElement.cpp | 34 +- .../content/src/nsHTMLOptGroupElement.cpp | 25 +- .../html/content/src/nsHTMLOptionElement.cpp | 29 +- .../content/src/nsHTMLParagraphElement.cpp | 25 +- .../html/content/src/nsHTMLParamElement.cpp | 25 +- content/html/content/src/nsHTMLPreElement.cpp | 23 +- .../html/content/src/nsHTMLQuoteElement.cpp | 25 +- .../html/content/src/nsHTMLScriptElement.cpp | 25 +- .../html/content/src/nsHTMLSelectElement.cpp | 379 +-- .../content/src/nsHTMLSharedObjectElement.cpp | 34 +- .../html/content/src/nsHTMLSpacerElement.cpp | 24 +- .../html/content/src/nsHTMLSpanElement.cpp | 21 +- .../html/content/src/nsHTMLStyleElement.cpp | 31 +- .../content/src/nsHTMLTableCaptionElement.cpp | 28 +- .../content/src/nsHTMLTableCellElement.cpp | 92 +- .../content/src/nsHTMLTableColElement.cpp | 28 +- .../src/nsHTMLTableColGroupElement.cpp | 26 +- .../html/content/src/nsHTMLTableElement.cpp | 30 +- .../content/src/nsHTMLTableRowElement.cpp | 184 +- .../content/src/nsHTMLTableSectionElement.cpp | 28 +- .../content/src/nsHTMLTextAreaElement.cpp | 31 +- .../html/content/src/nsHTMLTitleElement.cpp | 26 +- .../html/content/src/nsHTMLUListElement.cpp | 26 +- .../html/content/src/nsHTMLUnknownElement.cpp | 22 +- content/html/content/src/nsHTMLWBRElement.cpp | 23 +- .../html/document/src/nsHTMLContentSink.cpp | 12 +- content/html/document/src/nsHTMLDocument.cpp | 529 ++-- content/html/document/src/nsHTMLDocument.h | 27 +- .../src/nsHTMLFragmentContentSink.cpp | 2 +- content/html/document/src/nsIHTMLDocument.h | 4 - .../html/style/public/nsIComputedDOMStyle.h | 2 +- content/html/style/src/nsCSSStyleRule.cpp | 123 +- content/html/style/src/nsCSSStyleSheet.cpp | 306 +-- content/html/style/src/nsComputedDOMStyle.cpp | 699 ++--- .../html/style/src/nsDOMCSSDeclaration.cpp | 91 +- content/html/style/src/nsDOMCSSDeclaration.h | 18 +- .../html/style/src/nsROCSSPrimitiveValue.cpp | 49 +- .../html/style/src/nsROCSSPrimitiveValue.h | 13 +- content/macbuild/contentIDL.mcp | Bin 82606 -> 92538 bytes content/xbl/public/nsIBindingManager.h | 2 +- content/xbl/src/nsBindingManager.cpp | 27 +- content/xbl/src/nsXBLBinding.cpp | 105 +- content/xbl/src/nsXBLContextMenuHandler.h | 13 +- content/xbl/src/nsXBLDragHandler.cpp | 1 - content/xbl/src/nsXBLDragHandler.h | 12 +- content/xbl/src/nsXBLEventHandler.cpp | 7 +- content/xbl/src/nsXBLEventHandler.h | 2 +- content/xbl/src/nsXBLFocusHandler.cpp | 1 - content/xbl/src/nsXBLFocusHandler.h | 6 +- content/xbl/src/nsXBLFormHandler.cpp | 1 - content/xbl/src/nsXBLFormHandler.h | 12 +- content/xbl/src/nsXBLKeyHandler.cpp | 1 - content/xbl/src/nsXBLKeyHandler.h | 20 +- content/xbl/src/nsXBLLoadHandler.cpp | 1 - content/xbl/src/nsXBLLoadHandler.h | 10 +- content/xbl/src/nsXBLMouseHandler.cpp | 1 - content/xbl/src/nsXBLMouseHandler.h | 14 +- content/xbl/src/nsXBLMouseMotionHandler.cpp | 1 - content/xbl/src/nsXBLMouseMotionHandler.h | 11 +- content/xbl/src/nsXBLMutationHandler.cpp | 1 - content/xbl/src/nsXBLMutationHandler.h | 2 +- content/xbl/src/nsXBLPrototypeHandler.cpp | 58 +- content/xbl/src/nsXBLScrollHandler.cpp | 1 - content/xbl/src/nsXBLScrollHandler.h | 2 +- content/xbl/src/nsXBLService.cpp | 10 +- content/xbl/src/nsXBLWindowDragHandler.h | 12 +- content/xbl/src/nsXBLWindowKeyHandler.h | 8 +- content/xbl/src/nsXBLXULHandler.cpp | 1 - content/xbl/src/nsXBLXULHandler.h | 2 +- content/xml/content/src/nsXMLCDATASection.cpp | 63 +- content/xml/content/src/nsXMLElement.cpp | 23 +- content/xml/content/src/nsXMLElement.h | 9 +- content/xml/content/src/nsXMLEntity.cpp | 111 +- content/xml/content/src/nsXMLNamedNodeMap.cpp | 150 +- content/xml/content/src/nsXMLNotation.cpp | 111 +- .../src/nsXMLProcessingInstruction.cpp | 124 +- content/xml/document/src/nsXMLContentSink.cpp | 1 - content/xml/document/src/nsXMLDocument.cpp | 59 +- .../xsl/document/src/nsTransformMediator.cpp | 1 + content/xul/content/src/nsRDFDOMNodeList.cpp | 107 +- content/xul/content/src/nsRDFDOMNodeList.h | 11 +- content/xul/content/src/nsXULAttributes.cpp | 172 +- content/xul/content/src/nsXULAttributes.h | 25 +- content/xul/content/src/nsXULElement.cpp | 265 +- content/xul/content/src/nsXULElement.h | 38 +- .../xul/content/src/nsXULPopupListener.cpp | 26 +- content/xul/content/src/nsXULTreeElement.h | 8 +- content/xul/document/public/MANIFEST_IDL | 1 - content/xul/document/public/Makefile.in | 1 - content/xul/document/public/makefile.win | 1 - .../xul/document/public/nsIControllers.idl | 3 +- content/xul/document/public/xulstubs.idl | 0 .../document/src/nsXULCommandDispatcher.cpp | 89 +- .../xul/document/src/nsXULCommandDispatcher.h | 10 +- content/xul/document/src/nsXULControllers.cpp | 52 +- content/xul/document/src/nsXULControllers.h | 1 - content/xul/document/src/nsXULDocument.cpp | 409 +-- content/xul/document/src/nsXULDocument.h | 56 +- .../xul/document/src/nsXULPrototypeCache.cpp | 9 +- .../document/src/nsXULPrototypeDocument.cpp | 160 +- .../templates/src/nsContentTagTestNode.cpp | 1 + .../xul/templates/src/nsContentTagTestNode.h | 2 + .../xul/templates/src/nsContentTestNode.cpp | 1 + content/xul/templates/src/nsContentTestNode.h | 2 + .../src/nsRDFConInstanceTestNode.cpp | 1 + .../templates/src/nsRDFConMemberTestNode.cpp | 1 + .../templates/src/nsRDFPropertyTestNode.cpp | 1 + content/xul/templates/src/nsRuleNetwork.h | 1 + docshell/base/nsDocShell.cpp | 24 +- docshell/base/nsDocShell.h | 2 + docshell/base/nsIContentViewer.idl | 4 +- docshell/base/nsIDocShell.idl | 1 - docshell/base/nsIDocShellLoadInfo.idl | 1 - docshell/base/nsIMarkupDocumentViewer.idl | 3 +- docshell/base/nsIWebNavigation.idl | 4 +- docshell/base/nsWebShell.cpp | 15 +- docshell/build/Makefile.in | 1 - docshell/build/makefile.win | 1 - layout/base/nsDocumentViewer.cpp | 12 +- layout/generic/nsSelection.cpp | 85 +- layout/style/nsCSSStyleRule.cpp | 123 +- layout/style/nsCSSStyleSheet.cpp | 306 +-- layout/style/nsComputedDOMStyle.cpp | 699 ++--- layout/style/nsDOMCSSDeclaration.cpp | 91 +- layout/style/nsDOMCSSDeclaration.h | 18 +- layout/style/nsIComputedDOMStyle.h | 2 +- layout/style/nsROCSSPrimitiveValue.cpp | 49 +- layout/style/nsROCSSPrimitiveValue.h | 13 +- 237 files changed, 7005 insertions(+), 8737 deletions(-) delete mode 100644 content/xul/document/public/xulstubs.idl diff --git a/accessible/src/base/nsRootAccessible.cpp b/accessible/src/base/nsRootAccessible.cpp index 5589421dc09..8ccdde8cda5 100644 --- a/accessible/src/base/nsRootAccessible.cpp +++ b/accessible/src/base/nsRootAccessible.cpp @@ -148,7 +148,7 @@ NS_IMETHODIMP nsRootAccessible::RemoveAccessibleEventListener(nsIAccessibleEvent } -nsresult nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent) +NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent) { if (mListener) { nsCOMPtr t; @@ -185,12 +185,12 @@ nsresult nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } -nsresult nsRootAccessible::Focus(nsIDOMEvent* aEvent) +NS_IMETHODIMP nsRootAccessible::Focus(nsIDOMEvent* aEvent) { return NS_OK; } -nsresult nsRootAccessible::Blur(nsIDOMEvent* aEvent) +NS_IMETHODIMP nsRootAccessible::Blur(nsIDOMEvent* aEvent) { return NS_OK; } diff --git a/accessible/src/base/nsRootAccessible.h b/accessible/src/base/nsRootAccessible.h index f881d7028e7..3a1abc19bfa 100644 --- a/accessible/src/base/nsRootAccessible.h +++ b/accessible/src/base/nsRootAccessible.h @@ -51,9 +51,9 @@ class nsRootAccessible : public nsAccessible, NS_IMETHOD RemoveAccessibleEventListener(nsIAccessibleEventListener *aListener); // ----- nsIDOMEventListener -------- - virtual nsresult HandleEvent(nsIDOMEvent* anEvent); - virtual nsresult Focus(nsIDOMEvent* aEvent); - virtual nsresult Blur(nsIDOMEvent* aEvent); + NS_IMETHOD HandleEvent(nsIDOMEvent* anEvent); + NS_IMETHOD Focus(nsIDOMEvent* aEvent); + NS_IMETHOD Blur(nsIDOMEvent* aEvent); protected: virtual nsIFrame* GetFrame(); diff --git a/accessible/src/base/nsSelectAccessible.cpp b/accessible/src/base/nsSelectAccessible.cpp index b0a2598a97d..0e25280e442 100644 --- a/accessible/src/base/nsSelectAccessible.cpp +++ b/accessible/src/base/nsSelectAccessible.cpp @@ -61,7 +61,7 @@ public: NS_IMETHOD Action(nsIDOMEvent* aEvent) { return NS_OK; } NS_IMETHOD Broadcast(nsIDOMEvent* aEvent) { return NS_OK; } NS_IMETHOD CommandUpdate(nsIDOMEvent* aEvent) { return NS_OK; } - nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } nsCOMPtr mPopupAtom; nsCOMPtr mSelectContent; @@ -90,7 +90,7 @@ public: NS_IMETHOD GetAccRole(PRUnichar **_retval); NS_IMETHOD GetAccState(PRUint32 *_retval); NS_IMETHOD GetAccExtState(PRUint32 *_retval); - + // popup listener NS_IMETHOD Create(nsIDOMEvent* aEvent); NS_IMETHOD Close(nsIDOMEvent* aEvent); @@ -98,7 +98,7 @@ public: NS_IMETHOD Action(nsIDOMEvent* aEvent) { return NS_OK; } NS_IMETHOD Broadcast(nsIDOMEvent* aEvent) { return NS_OK; } NS_IMETHOD CommandUpdate(nsIDOMEvent* aEvent) { return NS_OK; } - nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } // helpers virtual nsIFrame* GetBoundsFrame(); diff --git a/accessible/src/nsMutableAccessible.h b/accessible/src/nsMutableAccessible.h index 1500e456cef..e69de29bb2d 100644 --- a/accessible/src/nsMutableAccessible.h +++ b/accessible/src/nsMutableAccessible.h @@ -1,52 +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.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef _nsMutableAccessible_H_ -#define _nsMutableAccessible_H_ - -#include "nsAccessible.h" -#include "nsString.h" - -#include "nsIMutableAccessible.h" - -class nsMutableAccessible : public nsIMutableAccessible -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIACCESSIBLE - NS_DECL_NSIMUTABLEACCESSIBLE - - nsMutableAccessible(nsISupports* aNode); - virtual ~nsMutableAccessible(); - -private: - nsCOMPtr mNode; - nsAutoString mName; - nsAutoString mRole; - nsCOMPtr mNameAttribute; - PRPackedBool mNameNodeValue; - PRPackedBool mNameStringSet; - PRPackedBool mIsLeaf; -}; - -#endif - diff --git a/accessible/src/nsRootAccessible.cpp b/accessible/src/nsRootAccessible.cpp index 5589421dc09..8ccdde8cda5 100644 --- a/accessible/src/nsRootAccessible.cpp +++ b/accessible/src/nsRootAccessible.cpp @@ -148,7 +148,7 @@ NS_IMETHODIMP nsRootAccessible::RemoveAccessibleEventListener(nsIAccessibleEvent } -nsresult nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent) +NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent) { if (mListener) { nsCOMPtr t; @@ -185,12 +185,12 @@ nsresult nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } -nsresult nsRootAccessible::Focus(nsIDOMEvent* aEvent) +NS_IMETHODIMP nsRootAccessible::Focus(nsIDOMEvent* aEvent) { return NS_OK; } -nsresult nsRootAccessible::Blur(nsIDOMEvent* aEvent) +NS_IMETHODIMP nsRootAccessible::Blur(nsIDOMEvent* aEvent) { return NS_OK; } diff --git a/accessible/src/nsRootAccessible.h b/accessible/src/nsRootAccessible.h index f881d7028e7..3a1abc19bfa 100644 --- a/accessible/src/nsRootAccessible.h +++ b/accessible/src/nsRootAccessible.h @@ -51,9 +51,9 @@ class nsRootAccessible : public nsAccessible, NS_IMETHOD RemoveAccessibleEventListener(nsIAccessibleEventListener *aListener); // ----- nsIDOMEventListener -------- - virtual nsresult HandleEvent(nsIDOMEvent* anEvent); - virtual nsresult Focus(nsIDOMEvent* aEvent); - virtual nsresult Blur(nsIDOMEvent* aEvent); + NS_IMETHOD HandleEvent(nsIDOMEvent* anEvent); + NS_IMETHOD Focus(nsIDOMEvent* aEvent); + NS_IMETHOD Blur(nsIDOMEvent* aEvent); protected: virtual nsIFrame* GetFrame(); diff --git a/accessible/src/nsSelectAccessible.cpp b/accessible/src/nsSelectAccessible.cpp index b0a2598a97d..0e25280e442 100644 --- a/accessible/src/nsSelectAccessible.cpp +++ b/accessible/src/nsSelectAccessible.cpp @@ -61,7 +61,7 @@ public: NS_IMETHOD Action(nsIDOMEvent* aEvent) { return NS_OK; } NS_IMETHOD Broadcast(nsIDOMEvent* aEvent) { return NS_OK; } NS_IMETHOD CommandUpdate(nsIDOMEvent* aEvent) { return NS_OK; } - nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } nsCOMPtr mPopupAtom; nsCOMPtr mSelectContent; @@ -90,7 +90,7 @@ public: NS_IMETHOD GetAccRole(PRUnichar **_retval); NS_IMETHOD GetAccState(PRUint32 *_retval); NS_IMETHOD GetAccExtState(PRUint32 *_retval); - + // popup listener NS_IMETHOD Create(nsIDOMEvent* aEvent); NS_IMETHOD Close(nsIDOMEvent* aEvent); @@ -98,7 +98,7 @@ public: NS_IMETHOD Action(nsIDOMEvent* aEvent) { return NS_OK; } NS_IMETHOD Broadcast(nsIDOMEvent* aEvent) { return NS_OK; } NS_IMETHOD CommandUpdate(nsIDOMEvent* aEvent) { return NS_OK; } - nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; } // helpers virtual nsIFrame* GetBoundsFrame(); diff --git a/allmakefiles.sh b/allmakefiles.sh index c63447b96e9..d57b67989aa 100755 --- a/allmakefiles.sh +++ b/allmakefiles.sh @@ -75,32 +75,23 @@ MAKEFILES_dom=" dom/Makefile dom/public/Makefile dom/public/base/Makefile -dom/public/coreDom/Makefile dom/public/coreEvents/Makefile -dom/public/css/Makefile -dom/public/events/Makefile -dom/public/range/Makefile -dom/public/html/Makefile -dom/public/xul/Makefile dom/public/idl/Makefile dom/public/idl/base/Makefile -dom/public/idl/coreDom/Makefile +dom/public/idl/core/Makefile dom/public/idl/css/Makefile dom/public/idl/events/Makefile dom/public/idl/html/Makefile dom/public/idl/range/Makefile +dom/public/idl/stylesheets/Makefile +dom/public/idl/views/Makefile +dom/public/idl/xbl/Makefile dom/public/idl/xul/Makefile dom/src/Makefile dom/src/base/Makefile dom/src/build/Makefile -dom/src/coreDOM/Makefile -dom/src/css/Makefile dom/src/events/Makefile -dom/src/range/Makefile -dom/src/html/Makefile -dom/src/xul/Makefile dom/src/jsurl/Makefile -dom/tools/Makefile " MAKEFILES_editor=" diff --git a/build/mac/build_scripts/MozillaBuildList.pm b/build/mac/build_scripts/MozillaBuildList.pm index d7b8fff2d1a..4ab3492248f 100644 --- a/build/mac/build_scripts/MozillaBuildList.pm +++ b/build/mac/build_scripts/MozillaBuildList.pm @@ -702,16 +702,20 @@ sub BuildClientDist() InstallFromManifest(":mozilla:view:public:MANIFEST", "$distdirectory:view:"); #DOM - InstallFromManifest(":mozilla:dom:public:MANIFEST", "$distdirectory:dom:"); InstallFromManifest(":mozilla:dom:public:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:idl:base:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:idl:core:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:idl:css:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:idl:events:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:idl:html:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:idl:range:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:idl:stylesheets:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:idl:views:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:idl:xbl:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:idl:xul:MANIFEST_IDL", "$distdirectory:idl:"); + InstallFromManifest(":mozilla:dom:public:MANIFEST", "$distdirectory:dom:"); InstallFromManifest(":mozilla:dom:public:base:MANIFEST", "$distdirectory:dom:"); - InstallFromManifest(":mozilla:dom:public:coreDom:MANIFEST", "$distdirectory:dom:"); InstallFromManifest(":mozilla:dom:public:coreEvents:MANIFEST", "$distdirectory:dom:"); - InstallFromManifest(":mozilla:dom:public:events:MANIFEST", "$distdirectory:dom:"); - InstallFromManifest(":mozilla:dom:public:range:MANIFEST", "$distdirectory:dom:"); - InstallFromManifest(":mozilla:dom:public:html:MANIFEST", "$distdirectory:dom:"); - InstallFromManifest(":mozilla:dom:public:css:MANIFEST", "$distdirectory:dom:"); - InstallFromManifest(":mozilla:dom:public:xul:MANIFEST", "$distdirectory:dom:"); InstallFromManifest(":mozilla:dom:src:jsurl:MANIFEST", "$distdirectory:dom:"); InstallFromManifest(":mozilla:dom:src:base:MANIFEST", "$distdirectory:dom:"); @@ -1051,6 +1055,16 @@ sub BuildIDLProjects() BuildIDLProject(":mozilla:modules:oji:macbuild:ojiIDL.mcp", "oji"); BuildIDLProject(":mozilla:js:macbuild:XPConnectIDL.mcp", "xpconnect"); BuildIDLProject(":mozilla:dom:macbuild:domIDL.mcp", "dom"); + BuildIDLProject(":mozilla:dom:macbuild:dom_baseIDL.mcp", "dom_base"); + BuildIDLProject(":mozilla:dom:macbuild:dom_coreIDL.mcp", "dom_core"); + BuildIDLProject(":mozilla:dom:macbuild:dom_cssIDL.mcp", "dom_css"); + BuildIDLProject(":mozilla:dom:macbuild:dom_eventsIDL.mcp", "dom_events"); + BuildIDLProject(":mozilla:dom:macbuild:dom_htmlIDL.mcp", "dom_html"); + BuildIDLProject(":mozilla:dom:macbuild:dom_rangeIDL.mcp", "dom_range"); + BuildIDLProject(":mozilla:dom:macbuild:dom_stylesheetsIDL.mcp", "dom_stylesheets"); + BuildIDLProject(":mozilla:dom:macbuild:dom_viewsIDL.mcp", "dom_views"); + BuildIDLProject(":mozilla:dom:macbuild:dom_xblIDL.mcp", "dom_xbl"); + BuildIDLProject(":mozilla:dom:macbuild:dom_xulIDL.mcp", "dom_xul"); BuildIDLProject(":mozilla:dom:src:jsurl:macbuild:JSUrlDL.mcp", "jsurl"); @@ -1538,7 +1552,7 @@ sub BuildLayoutProjects() BuildOneProject(":mozilla:htmlparser:macbuild:htmlparser.mcp", "htmlparser$D.shlb", 1, $main::ALIAS_SYM_FILES, 1); # BuildOneProject(":mozilla:gfx:macbuild:gfx.mcp", "gfx$D.shlb", 1, $main::ALIAS_SYM_FILES, 0); BuildOneProjectWithOutput(":mozilla:gfx:macbuild:gfx.mcp", "gfx$C$D.shlb", "gfx$D.shlb", 1, $main::ALIAS_SYM_FILES, 0); - BuildOneProject(":mozilla:dom:macbuild:dom.mcp", "dom$D.shlb", 1, $main::ALIAS_SYM_FILES, 0); + BuildOneProject(":mozilla:dom:macbuild:dom.mcp", "dom$D.shlb", 1, $main::ALIAS_SYM_FILES, 1); BuildOneProject(":mozilla:modules:plugin:macbuild:plugin.mcp", "plugin$D.shlb", 1, $main::ALIAS_SYM_FILES, 1); # Static library shared between different content- and layout-related libraries diff --git a/caps/idl/nsIScriptSecurityManager.idl b/caps/idl/nsIScriptSecurityManager.idl index 3eda8f9994c..0d6d17efed3 100644 --- a/caps/idl/nsIScriptSecurityManager.idl +++ b/caps/idl/nsIScriptSecurityManager.idl @@ -17,106 +17,74 @@ * Copyright (C) 1999 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): + * Norris Boyd + * Mitch Stoltz */ #include "nsISupports.idl" #include "nsIPrincipal.idl" - -%{C++ -#include "jspubtd.h" -%} -[ptr] native JSContextPtr(JSContext); - +#include "nsIXPCSecurityManager.idl" interface nsIURI; [scriptable, uuid(58df5780-8006-11d2-bd91-00805f8ae3f4)] -interface nsIScriptSecurityManager : nsISupports +interface nsIScriptSecurityManager : nsIXPCSecurityManager { - ///////////////// Principals /////////////////////// - - /** - * Return the principal of the innermost frame of the currently - * executing script. Will return null if there is no script - * currently executing. - */ - nsIPrincipal getSubjectPrincipal(); - - /** - * Return the all-powerful system principal. - */ - nsIPrincipal getSystemPrincipal(); - - /** - * Return a principal that can be QI'd to nsICodebasePrincipal and - * has the same origin as aURI. - */ - nsIPrincipal getCodebasePrincipal(in nsIURI aURI); - - /** - * Return a principal that can be QI'd to nsICertificatePrincipal. - */ - nsIPrincipal getCertificatePrincipal(in string CertID); - - ///////////////// Security Checks ////////////////// + ///////////////// Security Checks ////////////////// + /** + * Checks whether the running script is allowed to access aProperty. + */ + [noscript] void checkPropertyAccess(in PRUint32 aAction, + in JSContextPtr aJSContext, + in JSObjectPtr aJSObject, + in nsISupports aObj, + in nsIClassInfo aClassInfo, + in string aClassName, + in string aProperty, + in boolean skipFrame); /** - * Checks whether the currently executing script can access the given - * property. + * Check that the script currently running in context "cx" can load "uri". * - * @param cx The current active JavaScript context - * @param obj The object that is being accessed - * @param prop The ordinal of the property being accessed (see nsDOMPropEnums.h) - * @param isWrite True if write access is being attempted + * Will return error code NS_ERROR_DOM_BAD_URI if the load request + * should be denied. + * + * @param cx the JSContext of the script causing the load + * @param uri the URI that is being loaded */ - [noscript] void checkScriptAccess(in JSContextPtr cx, in voidPtr obj, - in long prop, in boolean isWrite); - - /** - * Check that the script with context "cx" can load "uri". - * - * Will return error code NS_ERROR_DOM_BAD_URI if the load request - * should be denied. - * - * @param cx the JSContext of the script causing the load - * @param uri the URI that is being loaded - */ [noscript] void checkLoadURIFromScript(in JSContextPtr cx, in nsIURI uri); - /** + /** * Default CheckLoadURI permissions */ + // Default permissions const unsigned long STANDARD = 0; - /** - * If the source is mail, disallow the load - */ + // If the source is mail, disallow the load const unsigned long DISALLOW_FROM_MAIL = 1 << 0; - /** - * Allow the loading of chrome URLs by non-chrome URLs - */ + // Allow the loading of chrome URLs by non-chrome URLs const unsigned long ALLOW_CHROME = 1 << 1; - /** - * Check that content from "from" can load "uri". - * - * Will return error code NS_ERROR_DOM_BAD_URI if the load request - * should be denied. - * - * @param from the URI causing the load - * @param uri the URI that is being loaded - * @param disallowFromMail if true, return NS_ERROR_DOM_BAD_URI if 'from' - * is a URI associated with mail or news - */ + /** + * Check that content from "from" can load "uri". + * + * Will return error code NS_ERROR_DOM_BAD_URI if the load request + * should be denied. + * + * @param from the URI causing the load + * @param uri the URI that is being loaded + * @param flags the permission set, see above + */ void checkLoadURI(in nsIURI from, in nsIURI uri, - in unsigned long flags); + in unsigned long flags); - /** - * Same as CheckLoadURI but takes string arguments for ease of use by scripts - */ + /** + * Same as CheckLoadURI but takes string arguments for ease of use + * by scripts + */ void checkLoadURIStr(in string from, in string uri, - in unsigned long flags); + in unsigned long flags); /** * Check that the function 'funObj' is allowed to run on 'targetObj' @@ -131,68 +99,78 @@ interface nsIScriptSecurityManager : nsISupports [noscript] void checkFunctionAccess(in JSContextPtr cx, in voidPtr funObj, in voidPtr targetObj); - /** - * Return true if content from the given principal is allowed to - * execute scripts. - */ - [noscript] boolean canExecuteScripts(in JSContextPtr cx, in nsIPrincipal principal); + /** + * Return true if content from the given principal is allowed to + * execute scripts. + */ + [noscript] boolean canExecuteScripts(in JSContextPtr cx, + in nsIPrincipal principal); - - ///////////////// Capabilities ///////////////////// + ///////////////// Principals /////////////////////// + /** + * Return the principal of the innermost frame of the currently + * executing script. Will return null if there is no script + * currently executing. + */ + nsIPrincipal getSubjectPrincipal(); /** - * Request that 'capability' can be enabled by scripts or applets running - * with 'principal'. Will prompt user if necessary. Returns - * nsIPrincipal::ENABLE_GRANTED or nsIPrincipal::ENABLE_DENIED based on user's choice. + * Return the all-powerful system principal. */ - void requestCapability(in nsIPrincipal principal, in string capability, out short result); - - /** - * Return true if the currently executing script has 'capability' enabled. - */ - boolean IsCapabilityEnabled(in string capability); - - /** - * Enable 'capability' in the innermost frame of the currently executing - * script. - */ - void enableCapability(in string capability); + nsIPrincipal getSystemPrincipal(); - /** - * Remove 'capability' from the innermost frame of the currently executing - * script. Any setting of 'capability' from enclosing frames thus comes into - * effect. - */ + /** + * Return a principal that can be QI'd to nsICertificatePrincipal. + */ + nsIPrincipal getCertificatePrincipal(in string CertID); + + /** + * Return a principal that can be QI'd to nsICodebasePrincipal and + * has the same origin as aURI. + */ + nsIPrincipal getCodebasePrincipal(in nsIURI aURI); + + ///////////////// Capabilities API ///////////////////// + /** + * Request that 'capability' can be enabled by scripts or applets + * running with 'principal'. Will prompt user if + * necessary. Returns nsIPrincipal::ENABLE_GRANTED or + * nsIPrincipal::ENABLE_DENIED based on user's choice. + */ + void requestCapability(in nsIPrincipal principal, in string capability, + out short result); + + /** + * Return true if the currently executing script has 'capability' enabled. + */ + boolean IsCapabilityEnabled(in string capability); + + /** + * Enable 'capability' in the innermost frame of the currently executing + * script. + */ + void enableCapability(in string capability); + + /** + * Remove 'capability' from the innermost frame of the currently + * executing script. Any setting of 'capability' from enclosing + * frames thus comes into effect. + */ void revertCapability(in string capability); - /** - * Disable 'capability' in the innermost frame of the currently executing - * script. - */ + /** + * Disable 'capability' in the innermost frame of the currently executing + * script. + */ void disableCapability(in string capability); //////////////// Master Certificate Functions //////////////////// - - /** - * Allow 'certificateID' to enable 'capability.' Can only be performed - * by code signed by the system certificate. - */ - void setCanEnableCapability(in string certificateID, in string capability, - in short canEnable); - - - //////////////// Temporary /////////////////////////////////////// /** - * Checks whether the currently executing script can load the given URL - * (special case for XMLHttpRequest) - * - * @param cx The current active JavaScript context - * @param url The url that is being accessed - * @param prop The ordinal of the property being accessed (see nsDOMPropEnums.h) - * @param isWrite True if write access is being attempted + * Allow 'certificateID' to enable 'capability.' Can only be performed + * by code signed by the system certificate. */ - [noscript] void checkScriptAccessToURL(in JSContextPtr cx, in string url, - in long prop, in boolean isWrite); + void setCanEnableCapability(in string certificateID, in string capability, + in short canEnable); }; %{C++ diff --git a/caps/include/nsScriptSecurityManager.h b/caps/include/nsScriptSecurityManager.h index a502d3ed49a..9a7194b233e 100644 --- a/caps/include/nsScriptSecurityManager.h +++ b/caps/include/nsScriptSecurityManager.h @@ -32,14 +32,15 @@ #include "jsdbgapi.h" #include "nsIXPCSecurityManager.h" #include "nsHashtable.h" -#include "nsDOMPropEnums.h" #include "nsCOMPtr.h" -#include "nsIPref.h" +#include "nsIPrefService.h" #include "nsISecurityPref.h" #include "nsIJSContextStack.h" +#include "nsIObserver.h" class nsIDocShell; class nsString; +class nsIClassInfo; ///////////////////// // nsIPrincipalKey // @@ -62,9 +63,9 @@ public: return hash; } - PRBool Equals(const nsHashKey *aKey) const { + PRBool Equals(const nsHashKey* aKey) const { PRBool eq; - mKey->Equals(((nsIPrincipalKey *) aKey)->mKey, &eq); + mKey->Equals(((nsIPrincipalKey*) aKey)->mKey, &eq); return eq; } @@ -80,8 +81,7 @@ protected: { 0x7ee2a4c0, 0x4b93, 0x17d3, \ { 0xba, 0x18, 0x00, 0x60, 0xb0, 0xf1, 0x99, 0xa2 }} -class nsScriptSecurityManager : public nsIScriptSecurityManager, - public nsIXPCSecurityManager +class nsScriptSecurityManager : public nsIScriptSecurityManager, public nsIObserver { public: nsScriptSecurityManager(); @@ -92,100 +92,116 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSISCRIPTSECURITYMANAGER NS_DECL_NSIXPCSECURITYMANAGER + NS_DECL_NSIOBSERVER - static nsScriptSecurityManager * + static nsScriptSecurityManager* GetScriptSecurityManager(); - JSContext * GetCurrentContextQuick(); + JSContext* GetCurrentContextQuick(); private: + + static PRBool IsDOMClass(nsIClassInfo* aClassInfo); + static nsresult ReportErrorToConsole(nsIURI* aTarget); - nsresult - GetRootDocShell(JSContext *cx, nsIDocShell **result); + nsresult + GetRootDocShell(JSContext* cx, nsIDocShell **result); - NS_IMETHOD - CheckScriptAccessInternal(JSContext *cx, - void* obj, const char* aObjUrlStr, PRInt32 domPropInt, - PRBool isWrite); + nsresult + CheckPropertyAccessImpl(PRUint32 aAction, nsIXPCNativeCallContext* aCallContext, + JSContext* aJSContext, JSObject* aJSObject, + nsISupports* aObj, nsIClassInfo* aClassInfo, + jsval aName, const char* aClassName, + const char* aProperty, PRBool skipFrame, void** aPolicy); - NS_IMETHOD - CreateCodebasePrincipal(nsIURI* aURI, nsIPrincipal** result); - - NS_IMETHOD - GetSubjectPrincipal(JSContext *aCx, nsIPrincipal **result); - - NS_IMETHOD - GetObjectPrincipal(JSContext *aCx, JSObject *aObj, nsIPrincipal **result); - - NS_IMETHOD - CheckPermissions(JSContext *aCx, nsIPrincipal* aObjectPrincipal, const char *aCapability); + nsresult + CheckSameOrigin(JSContext* aCx, nsIPrincipal* aSubject, + nsIPrincipal* aObject, PRUint32 aAction, PRBool aSkipFrame); PRInt32 - GetSecurityLevel(nsIPrincipal *principal, nsDOMProp domProp, - PRBool isWrite, nsCString &capability); + GetSecurityLevel(JSContext* aCx, nsIPrincipal *principal, + nsIClassInfo* aClassInfo, + const char* aClassName, const char* aProperty, + PRUint32 aAction, nsCString &capability, void** aPolicy); - NS_IMETHOD - GetPrefName(nsIPrincipal *principal, nsDOMProp domProp, - nsCString &result); + nsresult + GetPrefName(nsIPrincipal* principal, + const char* aClassName, const char* aPropertyName, + void* aClassPolicy, nsCString &result); - nsresult - CheckXPCCapability(JSContext *aJSContext, const char *aCapability); - - NS_IMETHOD - CheckXPCPermissions(JSContext *cx, nsISupports* aObj); + nsresult + CreateCodebasePrincipal(nsIURI* aURI, nsIPrincipal** result); - NS_IMETHOD - GetFramePrincipal(JSContext *cx, JSStackFrame *fp, nsIPrincipal **result); + nsresult + GetSubjectPrincipal(JSContext* aCx, nsIPrincipal** result); + + nsresult + GetObjectPrincipal(JSContext* aCx, JSObject* aObj, nsIPrincipal** result); + + nsresult + GetFramePrincipal(JSContext* cx, JSStackFrame* fp, nsIPrincipal** result); - NS_IMETHOD - GetScriptPrincipal(JSContext *cx, JSScript *script, nsIPrincipal **result); + nsresult + GetScriptPrincipal(JSContext* cx, JSScript* script, nsIPrincipal** result); - NS_IMETHOD - GetFunctionObjectPrincipal(JSContext *cx, JSObject *obj, - nsIPrincipal **result); + nsresult + GetCallingPrincipal(JSContext* cx, nsIPrincipal** result); - NS_IMETHOD - GetPrincipalAndFrame(JSContext *cx, nsIPrincipal **result, - JSStackFrame **frameResult); + nsresult + GetFunctionObjectPrincipal(JSContext* cx, JSObject* obj, + nsIPrincipal** result); - NS_IMETHOD + nsresult + GetPrincipalAndFrame(JSContext *cx, PRBool skipInnerFrame, + nsIPrincipal** result, + JSStackFrame** frameResult); + + nsresult SavePrincipal(nsIPrincipal* aToSave); - NS_IMETHOD - InitPrefs(); + nsresult IsCapabilityEnabledImpl(const char *capability, + PRBool skipFrame, + PRBool *result); - PRBool - EnsureNameSetRegistered(); + nsresult + CheckXPCPermissions(JSContext* cx, nsISupports* aObj, + const char* aObjectSecurityLevel, PRBool skipFrame, const char* aErrorMsg); + + nsresult + InitPrefs(); static nsresult PrincipalPrefNames(const char* pref, char** grantedPref, char** deniedPref); - static void - EnumeratePolicyCallback(const char *prefName, void *data); + nsresult + InitPolicies(PRUint32 prefCount, const char** prefNames); - static void - EnumeratePrincipalsCallback(const char *prefName, void *data); + nsresult + InitPrincipals(PRUint32 prefCount, const char** prefNames); - static int PR_CALLBACK - JSEnabledPrefChanged(const char *pref, void *data); + inline void + JSEnabledPrefChanged(); - static int PR_CALLBACK - PrincipalPrefChanged(const char *pref, void *data); + static const char* sJSEnabledPrefName; + static const char* sJSMailEnabledPrefName; + static const char* sPrincipalPrefix; - nsObjectHashtable *mOriginToPolicyMap; - nsCOMPtr mPrefs; + nsObjectHashtable* mOriginToPolicyMap; + nsHashtable* mClassPolicies; + nsCOMPtr mPrefService; + nsCOMPtr mPrefs; nsCOMPtr mSecurityPrefs; - nsIPrincipal *mSystemPrincipal; + nsIPrincipal* mSystemPrincipal; nsCOMPtr mSystemCertificate; - nsSupportsHashtable *mPrincipals; + nsSupportsHashtable* mPrincipals; PRBool mIsJavaScriptEnabled; PRBool mIsMailJavaScriptEnabled; PRBool mIsWritingPrefs; - unsigned char hasDomainPolicyVector[(NS_DOM_PROP_MAX >> 3) + 1]; nsCOMPtr mThreadJSContextStack; PRBool mNameSetRegistered; }; #endif /*_NS_SCRIPT_SECURITY_MANAGER_H_*/ + diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index 50b747a0984..4da4c217f7f 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -24,7 +24,7 @@ */ #include "nsScriptSecurityManager.h" #include "nsIServiceManager.h" -#include "nsIScriptObjectOwner.h" +#include "nsIScriptObjectPrincipal.h" #include "nsIURL.h" #include "nsIJARURI.h" #include "nspr.h" @@ -41,10 +41,7 @@ #include "nsDOMError.h" #include "xpcexception.h" #include "nsDOMCID.h" -#include "nsIScriptNameSetRegistry.h" -#include "nsIScriptExternalNameSet.h" #include "jsdbgapi.h" -#include "nsDOMPropNames.h" #include "nsIXPConnect.h" #include "nsIXPCSecurityManager.h" #include "nsTextFormatter.h" @@ -66,42 +63,48 @@ #include "nsIPrompt.h" #include "nsIWindowWatcher.h" #include "nsIConsoleService.h" +#include "nsISecurityCheckedComponent.h" +#include "nsIPref.h" static NS_DEFINE_IID(kIIOServiceIID, NS_IIOSERVICE_IID); static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); -static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); +static NS_DEFINE_CID(kPrefServiceCID, NS_PREFSERVICE_CID); static NS_DEFINE_CID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID); static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID); +//-- All values of this enum except the first map to odd numbers so they can be +// stored in a void* without being confused for a pointer value (which is always even). enum { - SCRIPT_SECURITY_UNDEFINED_ACCESS, - SCRIPT_SECURITY_CAPABILITY_ONLY, - SCRIPT_SECURITY_SAME_DOMAIN_ACCESS, - SCRIPT_SECURITY_ALL_ACCESS, - SCRIPT_SECURITY_NO_ACCESS + SCRIPT_SECURITY_UNDEFINED_ACCESS = 0, + SCRIPT_SECURITY_CAPABILITY_ONLY = 1, + SCRIPT_SECURITY_SAME_ORIGIN_ACCESS = 3, + SCRIPT_SECURITY_ALL_ACCESS = 5, + SCRIPT_SECURITY_NO_ACCESS = 7 }; -static JSContext * -GetCurrentContext() { - // Get JSContext from stack. - nsresult rv; - nsCOMPtr stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv); - if (NS_FAILED(rv)) +enum { + CLASS_POLICY_DEFAULT = 1, + CLASS_POLICY_SITE +}; + +// Result of this function should not be freed. +static const PRUnichar * +JSValIDToString(JSContext *aJSContext, const jsval idval) { + JSString *str = JS_ValueToString(aJSContext, idval); + if(!str) return nsnull; - JSContext *cx; - if (NS_FAILED(stack->Peek(&cx))) - return nsnull; - return cx; + return NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(str)); } // Convinience method to get the current js context stack. // Uses cached JSContextStack service instead of calling through // to the service manager. JSContext * -nsScriptSecurityManager::GetCurrentContextQuick() { +nsScriptSecurityManager::GetCurrentContextQuick() +{ // Get JSContext from stack. nsresult rv; if (!mThreadJSContextStack) { @@ -115,262 +118,6 @@ nsScriptSecurityManager::GetCurrentContextQuick() { return cx; } - -#if 0 -// unused. -static JSContext * -GetSafeContext() { - // Get the "safe" JSContext: our JSContext of last resort - nsresult rv; - NS_WITH_SERVICE(nsIJSContextStack, stack, "@mozilla.org/js/xpc/ContextStack;1", - &rv); - if (NS_FAILED(rv)) - return nsnull; - nsCOMPtr tcs = do_QueryInterface(stack); - JSContext *cx; - if (NS_FAILED(tcs->GetSafeJSContext(&cx))) - return nsnull; - return cx; -} -#endif - -static nsDOMProp -findDomProp(const char *propName, int n); - -/////////////////////// -// nsSecurityNameSet // -/////////////////////// - -class nsSecurityNameSet : public nsIScriptExternalNameSet -{ -public: - nsSecurityNameSet(); - virtual ~nsSecurityNameSet(); - - NS_DECL_ISUPPORTS - NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext); - NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext); -}; - -nsSecurityNameSet::nsSecurityNameSet() -{ - NS_INIT_REFCNT(); -} - -nsSecurityNameSet::~nsSecurityNameSet() -{ -} - -NS_IMPL_ISUPPORTS(nsSecurityNameSet, NS_GET_IID(nsIScriptExternalNameSet)); - -static char * -getStringArgument(JSContext *cx, JSObject *obj, PRUint16 argNum, uintN argc, jsval *argv) -{ - if (argc <= argNum || !JSVAL_IS_STRING(argv[argNum])) { - JS_ReportError(cx, "String argument expected"); - return nsnull; - } - /* - * We don't want to use JS_ValueToString because we want to be able - * to have an object to represent a target in subsequent versions. - */ - JSString *str = JSVAL_TO_STRING(argv[argNum]); - if (!str) - return nsnull; - - return JS_GetStringBytes(str); -} - -JS_STATIC_DLL_CALLBACK(JSBool) -netscape_security_isPrivilegeEnabled(JSContext *cx, JSObject *obj, uintN argc, - jsval *argv, jsval *rval) -{ - JSBool result = JS_FALSE; - char *cap = getStringArgument(cx, obj, 0, argc, argv); - if (cap) { - nsresult rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, - NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) { - NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - rv = securityManager->IsCapabilityEnabled(cap, &result); - if (NS_FAILED(rv)) - result = JS_FALSE; - } - } - *rval = BOOLEAN_TO_JSVAL(result); - return JS_TRUE; -} - - -JS_STATIC_DLL_CALLBACK(JSBool) -netscape_security_enablePrivilege(JSContext *cx, JSObject *obj, uintN argc, - jsval *argv, jsval *rval) -{ - char *cap = getStringArgument(cx, obj, 0, argc, argv); - if (!cap) - return JS_FALSE; - nsresult rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, - NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return JS_FALSE; - NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - if (NS_FAILED(securityManager->EnableCapability(cap))) - return JS_FALSE; - return JS_TRUE; -} - -JS_STATIC_DLL_CALLBACK(JSBool) -netscape_security_disablePrivilege(JSContext *cx, JSObject *obj, uintN argc, - jsval *argv, jsval *rval) -{ - char *cap = getStringArgument(cx, obj, 0, argc, argv); - if (!cap) - return JS_FALSE; - nsresult rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, - NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return JS_FALSE; - NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - if (NS_FAILED(securityManager->DisableCapability(cap))) - return JS_FALSE; - return JS_TRUE; -} - -JS_STATIC_DLL_CALLBACK(JSBool) -netscape_security_revertPrivilege(JSContext *cx, JSObject *obj, uintN argc, - jsval *argv, jsval *rval) -{ - char *cap = getStringArgument(cx, obj, 0, argc, argv); - if (!cap) - return JS_FALSE; - nsresult rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, - NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return JS_FALSE; - NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - if (NS_FAILED(securityManager->RevertCapability(cap))) - return JS_FALSE; - return JS_TRUE; -} - -JS_STATIC_DLL_CALLBACK(JSBool) -netscape_security_setCanEnablePrivilege(JSContext *cx, JSObject *obj, uintN argc, - jsval *argv, jsval *rval) -{ - if (argc < 2) return JS_FALSE; - char *principalID = getStringArgument(cx, obj, 0, argc, argv); - char *cap = getStringArgument(cx, obj, 1, argc, argv); - if (!principalID || !cap) - return JS_FALSE; - nsresult rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, - NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return JS_FALSE; - NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - if (NS_FAILED(securityManager->SetCanEnableCapability(principalID, cap, - nsIPrincipal::ENABLE_GRANTED))) - return JS_FALSE; - return JS_TRUE; -} - -JS_STATIC_DLL_CALLBACK(JSBool) -netscape_security_invalidate(JSContext *cx, JSObject *obj, uintN argc, - jsval *argv, jsval *rval) -{ - char *principalID = getStringArgument(cx, obj, 0, argc, argv); - if (!principalID) - return JS_FALSE; - nsresult rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, - NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return JS_FALSE; - NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); - if (NS_FAILED(securityManager->SetCanEnableCapability(principalID, - nsBasePrincipal::Invalid, - nsIPrincipal::ENABLE_GRANTED))) - return JS_FALSE; - return JS_TRUE; -} - -static JSFunctionSpec PrivilegeManager_static_methods[] = { - { "isPrivilegeEnabled", netscape_security_isPrivilegeEnabled, 1}, - { "enablePrivilege", netscape_security_enablePrivilege, 1}, - { "disablePrivilege", netscape_security_disablePrivilege, 1}, - { "revertPrivilege", netscape_security_revertPrivilege, 1}, - //-- System Cert Functions - { "setCanEnablePrivilege", netscape_security_setCanEnablePrivilege, 2}, - { "invalidate", netscape_security_invalidate, 1}, - {0} -}; - -/* - * "Steal" calls to netscape.security.PrivilegeManager.enablePrivilege, - * et. al. so that code that worked with 4.0 can still work. - */ -NS_IMETHODIMP -nsSecurityNameSet::InitializeClasses(nsIScriptContext* aScriptContext) -{ - JSContext *cx = (JSContext *) aScriptContext->GetNativeContext(); - JSObject *global = JS_GetGlobalObject(cx); - - /* - * Find Object.prototype's class by walking up the global object's - * prototype chain. - */ - JSObject *obj = global; - JSObject *proto; - while ((proto = JS_GetPrototype(cx, obj)) != nsnull) - obj = proto; - JSClass *objectClass = JS_GetClass(cx, obj); - - jsval v; - if (!JS_GetProperty(cx, global, "netscape", &v)) - return NS_ERROR_FAILURE; - JSObject *securityObj; - if (JSVAL_IS_OBJECT(v)) { - /* - * "netscape" property of window object exists; must be LiveConnect - * package. Get the "security" property. - */ - obj = JSVAL_TO_OBJECT(v); - if (!JS_GetProperty(cx, obj, "security", &v) || !JSVAL_IS_OBJECT(v)) - return NS_ERROR_FAILURE; - securityObj = JSVAL_TO_OBJECT(v); - } else { - /* define netscape.security object */ - obj = JS_DefineObject(cx, global, "netscape", objectClass, nsnull, 0); - if (obj == nsnull) - return NS_ERROR_FAILURE; - securityObj = JS_DefineObject(cx, obj, "security", objectClass, - nsnull, 0); - if (securityObj == nsnull) - return NS_ERROR_FAILURE; - } - - /* Define PrivilegeManager object with the necessary "static" methods. */ - obj = JS_DefineObject(cx, securityObj, "PrivilegeManager", objectClass, - nsnull, 0); - if (obj == nsnull) - return NS_ERROR_FAILURE; - - return JS_DefineFunctions(cx, obj, PrivilegeManager_static_methods) - ? NS_OK - : NS_ERROR_FAILURE; -} - - -NS_IMETHODIMP -nsSecurityNameSet::AddNameSet(nsIScriptContext* aScriptContext) -{ - return NS_OK; -} - ///////////////////////////// // nsScriptSecurityManager // ///////////////////////////// @@ -379,117 +126,440 @@ nsSecurityNameSet::AddNameSet(nsIScriptContext* aScriptContext) // Methods implementing ISupports // //////////////////////////////////// -NS_IMPL_THREADSAFE_ISUPPORTS2(nsScriptSecurityManager, +NS_IMPL_THREADSAFE_ISUPPORTS3(nsScriptSecurityManager, nsIScriptSecurityManager, - nsIXPCSecurityManager) - -inline PRBool -GetBit(unsigned char *bitVector, PRInt32 index) -{ - unsigned char c = bitVector[index >> 3]; - c &= (1 << (index & 7)); - return c != 0; -} - -inline void -SetBit(unsigned char *bitVector, PRInt32 index) -{ - bitVector[index >> 3] |= (1 << (index & 7)); -} - + nsIXPCSecurityManager, + nsIObserver) /////////////////////////////////////////////////// // Methods implementing nsIScriptSecurityManager // /////////////////////////////////////////////////// -static char *domPropNames[] = { - NS_DOM_PROP_NAMES -}; - +///////////////// Security Checks ///////////////// NS_IMETHODIMP -nsScriptSecurityManager::CheckScriptAccessToURL(JSContext *cx, - const char* aObjUrlStr, PRInt32 domPropInt, - PRBool isWrite) +nsScriptSecurityManager::CheckPropertyAccess(PRUint32 aAction, + JSContext* aJSContext, + JSObject* aJSObject, + nsISupports* aObj, + nsIClassInfo* aClassInfo, + const char* aClassName, + const char* aProperty, + PRBool aSkipFrame) { - return CheckScriptAccessInternal(cx, nsnull, aObjUrlStr, domPropInt, isWrite); + return CheckPropertyAccessImpl(aAction, nsnull, aJSContext, aJSObject, aObj, + aClassInfo, nsnull, aClassName, aProperty, + aSkipFrame, nsnull); } -NS_IMETHODIMP -nsScriptSecurityManager::CheckScriptAccess(JSContext *cx, - void *aObj, PRInt32 domPropInt, - PRBool isWrite) +nsresult +nsScriptSecurityManager::CheckPropertyAccessImpl(PRUint32 aAction, + nsIXPCNativeCallContext* aCallContext, + JSContext* aJSContext, JSObject* aJSObject, + nsISupports* aObj, nsIClassInfo* aClassInfo, + jsval aName, const char* aClassName, + const char* aProperty, + PRBool aSkipFrame, void** aPolicy) { - return CheckScriptAccessInternal(cx, aObj, nsnull, domPropInt, isWrite); -} - - -NS_IMETHODIMP -nsScriptSecurityManager::CheckScriptAccessInternal(JSContext *cx, - void* aObj, const char* aObjUrlStr, - PRInt32 domPropInt, PRBool isWrite) -{ - nsCOMPtr principal; - if (NS_FAILED(GetSubjectPrincipal(cx, getter_AddRefs(principal)))) + nsCOMPtr subjectPrincipal; + JSStackFrame *notused; + if (NS_FAILED(GetPrincipalAndFrame(aJSContext, aSkipFrame, + getter_AddRefs(subjectPrincipal), ¬used))) return NS_ERROR_FAILURE; PRBool equals; - if (!principal || - NS_SUCCEEDED(principal->Equals(mSystemPrincipal, &equals)) && equals) + if (!subjectPrincipal || + NS_SUCCEEDED(subjectPrincipal->Equals(mSystemPrincipal, &equals)) && equals) // We have native code or the system principal: just allow access return NS_OK; + +#ifdef DEBUG_mstoltz + if (aProperty) + printf("### CheckPropertyAccess(%s.%s, %i) ", aClassName, aProperty, aAction); + else + { + nsXPIDLCString classDescription; + if (aClassInfo) + aClassInfo->GetClassDescription(getter_Copies(classDescription)); + if(!classDescription) + classDescription = "UnknownClass"; + nsCAutoString propertyStr(classDescription); + propertyStr += '.'; + propertyStr.AppendWithConversion((PRUnichar*)JSValIDToString(aJSContext, aName)); + + char* property; + property = propertyStr.ToNewCString(); + printf("### CanAccess(%s, %i) ", property, aAction); + PR_FREEIF(property); + } +#endif + + //-- Look up the policy for this property/method + PRInt32 secLevel; nsCAutoString capability; - nsDOMProp domProp = (nsDOMProp) domPropInt; - PRInt32 secLevel = GetSecurityLevel(principal, domProp, isWrite, - capability); + if (aPolicy && *aPolicy) + { +#ifdef DEBUG_mstoltz + printf("Cached "); +#endif + secLevel = (PRInt32)*aPolicy; + } + else + { + nsXPIDLCString className; + nsCAutoString propertyName(aProperty); + if (aClassName) + className = aClassName; + else + //-- Get className and propertyName from aClassInfo and aName, repectively + { + if(aClassInfo) + aClassInfo->GetClassDescription(getter_Copies(className)); + if (!className) + className = "UnknownClass"; + propertyName.AssignWithConversion((PRUnichar*)JSValIDToString(aJSContext, aName)); + } - static const char UBR[] = "UniversalBrowserRead"; - static const char UBW[] = "UniversalBrowserWrite"; + secLevel = GetSecurityLevel(aJSContext, subjectPrincipal, aClassInfo, className, + propertyName, aAction, capability, aPolicy); + } + nsresult rv; switch (secLevel) { - case SCRIPT_SECURITY_ALL_ACCESS: - return NS_OK; - case SCRIPT_SECURITY_UNDEFINED_ACCESS: - case SCRIPT_SECURITY_SAME_DOMAIN_ACCESS: - { - const char *cap = isWrite ? UBW : UBR; + case SCRIPT_SECURITY_ALL_ACCESS: #ifdef DEBUG_mstoltz - printf("##### Checking %s : \n", domPropNames[domProp]); + printf("Level: AllAccess "); #endif - nsCOMPtr objectPrincipal; - if (aObj) + rv = NS_OK; + break; + case SCRIPT_SECURITY_SAME_ORIGIN_ACCESS: { - if (NS_FAILED(GetObjectPrincipal(cx, NS_REINTERPRET_CAST(JSObject*, aObj), - getter_AddRefs(objectPrincipal)))) - return NS_ERROR_FAILURE; +#ifdef DEBUG_mstoltz + printf("Level: SameOrigin "); +#endif + if(aJSObject) + { + nsCOMPtr objectPrincipal; + if (NS_FAILED(GetObjectPrincipal(aJSContext, + NS_REINTERPRET_CAST(JSObject*, aJSObject), + getter_AddRefs(objectPrincipal)))) + return NS_ERROR_FAILURE; + rv = CheckSameOrigin(aJSContext, subjectPrincipal, objectPrincipal, + aAction == nsIXPCSecurityManager::ACCESS_SET_PROPERTY, + aSkipFrame); + } + else + rv = NS_ERROR_DOM_SECURITY_ERR; + break; } + case SCRIPT_SECURITY_CAPABILITY_ONLY: + { +#ifdef DEBUG_mstoltz + printf("Level: Capability "); +#endif + PRBool capabilityEnabled = PR_FALSE; + rv = IsCapabilityEnabled(capability, &capabilityEnabled); + if (NS_FAILED(rv) || !capabilityEnabled) + rv = NS_ERROR_DOM_SECURITY_ERR; + else + rv = NS_OK; + break; + } + default: + // Default is no access +#ifdef DEBUG_mstoltz + printf("Level: NoAccess (%i)",secLevel); +#endif + rv = NS_ERROR_DOM_SECURITY_ERR; + } + + if NS_SUCCEEDED(rv) + { +#ifdef DEBUG_mstoltz + printf(" GRANTED.\n"); +#endif + return rv; + } + + //--See if the object advertises a non-default level of access + // using nsISecurityCheckedComponent + nsCOMPtr checkedComponent = + do_QueryInterface(aObj); + + nsXPIDLCString objectSecurityLevel; + if (checkedComponent) + { + nsCOMPtr wrapper; + nsCOMPtr interfaceInfo; + const nsIID* objIID; + rv = aCallContext->GetCalleeWrapper(getter_AddRefs(wrapper)); + if (NS_SUCCEEDED(rv)) + rv = wrapper->FindInterfaceWithMember(aName, getter_AddRefs(interfaceInfo)); + if (NS_SUCCEEDED(rv)) + rv = interfaceInfo->GetIIDShared(&objIID); + if (NS_SUCCEEDED(rv)) + { + switch (aAction) + { + case nsIXPCSecurityManager::ACCESS_GET_PROPERTY: + checkedComponent->CanGetProperty(objIID, + JSValIDToString(aJSContext, aName), + getter_Copies(objectSecurityLevel)); + break; + case nsIXPCSecurityManager::ACCESS_SET_PROPERTY: + checkedComponent->CanSetProperty(objIID, + JSValIDToString(aJSContext, aName), + getter_Copies(objectSecurityLevel)); + break; + case nsIXPCSecurityManager::ACCESS_CALL_METHOD: + checkedComponent->CanCallMethod(objIID, + JSValIDToString(aJSContext, aName), + getter_Copies(objectSecurityLevel)); + } + } + } + rv = CheckXPCPermissions(aJSContext, aObj, objectSecurityLevel, aSkipFrame, + "Permission denied to access property"); +#ifdef DEBUG_mstoltz + if(NS_SUCCEEDED(rv)) + printf("CheckXPCPerms GRANTED.\n"); + else + printf("CheckXPCPerms DENIED.\n"); +#endif + return rv; +} + +nsresult +nsScriptSecurityManager::CheckSameOrigin(JSContext *aCx, nsIPrincipal* aSubject, + nsIPrincipal* aObject, PRUint32 aAction, + PRBool aSkipFrame) +{ + /* + ** Get origin of subject and object and compare. + */ + if (aSubject == aObject) + return NS_OK; + + PRBool isSameOrigin = PR_FALSE; + if (NS_FAILED(aSubject->Equals(aObject, &isSameOrigin))) + return NS_ERROR_FAILURE; + + if (isSameOrigin) + return NS_OK; + + // Allow access to about:blank + nsCOMPtr objectCodebase = do_QueryInterface(aObject); + if (objectCodebase) + { + nsXPIDLCString origin; + if (NS_FAILED(objectCodebase->GetOrigin(getter_Copies(origin)))) + return NS_ERROR_FAILURE; + if (nsCRT::strcasecmp(origin, "about:blank") == 0) + return NS_OK; + } + + /* + ** If we failed the origin tests it still might be the case that we + ** are a signed script and have permissions to do this operation. + ** Check for that here + */ + PRBool capabilityEnabled = PR_FALSE; + const char* cap = aAction == nsIXPCSecurityManager::ACCESS_SET_PROPERTY ? + "UniversalBrowserWrite" : "UniversalBrowserRead"; + if (NS_FAILED(IsCapabilityEnabledImpl(cap, aSkipFrame, &capabilityEnabled))) + return NS_ERROR_FAILURE; + if (capabilityEnabled) + return NS_OK; + + /* + ** Access tests failed, so now report error. + */ + return NS_ERROR_DOM_PROP_ACCESS_DENIED; +} + +PRBool +nsScriptSecurityManager::IsDOMClass(nsIClassInfo* aClassInfo) +{ + if (!aClassInfo) + return PR_FALSE; + PRUint32 classFlags; + nsresult rv = aClassInfo->GetFlags(&classFlags); + return NS_SUCCEEDED(rv) && (classFlags | nsIClassInfo::DOM_OBJECT); +} + +PRInt32 +nsScriptSecurityManager::GetSecurityLevel(JSContext* aJSContext, + nsIPrincipal *principal, + nsIClassInfo* aClassInfo, + const char* aClassName, + const char* aPropertyName, + PRUint32 aAction, + nsCString &capability, + void** aPolicy) +{ + nsresult rv; + PRInt32 secLevel = SCRIPT_SECURITY_NO_ACCESS; + //-- See if we have a security policy for this class, otherwise use the default + void* classPolicy = nsnull; + if(mClassPolicies) + { + nsCStringKey classKey(aClassName); + classPolicy = mClassPolicies->Get(&classKey); + } + if (classPolicy) + { + //-- Look up the security policy for this property + nsCAutoString prefName; + if (NS_FAILED(GetPrefName(principal, aClassName, aPropertyName, + classPolicy, prefName))) + return SCRIPT_SECURITY_NO_ACCESS; + char *secLevelString; + rv = mSecurityPrefs->SecurityGetCharPref(prefName, &secLevelString); + if (NS_FAILED(rv)) + { + prefName += (aAction == nsIXPCSecurityManager::ACCESS_SET_PROPERTY ? ".set" : ".get"); + rv = mSecurityPrefs->SecurityGetCharPref(prefName, &secLevelString); + } + if (NS_SUCCEEDED(rv) && secLevelString) + { + if (PL_strcmp(secLevelString, "sameOrigin") == 0) + secLevel = SCRIPT_SECURITY_SAME_ORIGIN_ACCESS; + else if (PL_strcmp(secLevelString, "allAccess") == 0) + secLevel = SCRIPT_SECURITY_ALL_ACCESS; + else if (PL_strcmp(secLevelString, "noAccess") == 0) + secLevel = SCRIPT_SECURITY_NO_ACCESS; + else + { + // string should be the name of a capability + capability = secLevelString; + secLevelString = nsnull; + secLevel = SCRIPT_SECURITY_CAPABILITY_ONLY; + } + if (secLevelString) + PR_Free(secLevelString); + return secLevel; + } + } + //-- No policy for this property. + // Use the default policy: sameOrigin for DOM, noAccess for everything else + if(IsDOMClass(aClassInfo)) + secLevel = SCRIPT_SECURITY_SAME_ORIGIN_ACCESS; + if (!classPolicy && aPolicy) + //-- If there's no stored policy for this property, + // we can annotate the class's aPolicy field and avoid checking + // policy prefs next time. + *aPolicy = (void*)secLevel; + return secLevel; + return SCRIPT_SECURITY_UNDEFINED_ACCESS; +} + +struct nsDomainEntry +{ + nsDomainEntry(const char *anOrigin, const char *aPolicy, + int aPolicyLength) + : mNext(nsnull), mOrigin(anOrigin), mPolicy(aPolicy, aPolicyLength) + { } + PRBool Matches(const char *anOrigin) + { + int len = nsCRT::strlen(anOrigin); + int thisLen = mOrigin.Length(); + if (len < thisLen) + return PR_FALSE; + if (mOrigin.RFindChar(':', PR_FALSE, thisLen-1, 1) != -1) + //-- Policy applies to all URLs of this scheme, compare scheme only + return mOrigin.EqualsWithConversion(anOrigin, PR_TRUE, thisLen); + + //-- Policy applies to a particular host; compare scheme://host.domain + if (!mOrigin.Equals(anOrigin + (len - thisLen))) + return PR_FALSE; + if (len == thisLen) + return PR_TRUE; + char charBefore = anOrigin[len-thisLen-1]; + return (charBefore == '.' || charBefore == ':' || charBefore == '/'); + } + nsDomainEntry *mNext; + nsCString mOrigin; + nsCString mPolicy; +}; + +nsresult +nsScriptSecurityManager::GetPrefName(nsIPrincipal* principal, + const char* aClassName, const char* aPropertyName, + void* aClassPolicy, nsCString &result) +{ + static const char *defaultStr = "default"; + result = "capability.policy."; + if (aClassPolicy != (void*)CLASS_POLICY_SITE) + //-- No per-site policy; use the policy named "default" + result += defaultStr; + else //-- Look up the name of the relevant per-site policy + { + PRBool equals = PR_TRUE; + if (principal && NS_FAILED(principal->Equals(mSystemPrincipal, &equals))) + return NS_ERROR_FAILURE; + if (equals) + result += defaultStr; else { - nsCOMPtr objectURI; - nsresult rv = NS_NewURI(getter_AddRefs(objectURI), aObjUrlStr, nsnull); - if (NS_FAILED(rv)) return rv; - rv = GetCodebasePrincipal(objectURI, getter_AddRefs(objectPrincipal)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr codebase = do_QueryInterface(principal); + if (!codebase) + return NS_ERROR_FAILURE; + nsresult rv; + nsXPIDLCString origin; + if (NS_FAILED(rv = codebase->GetOrigin(getter_Copies(origin)))) + return rv; + nsCString *policy = nsnull; + if (mOriginToPolicyMap) + { + const char *s = origin; + const char *nextToLastDot = nsnull; + const char *lastDot = nsnull; + const char *colon = nsnull; + const char *p = s; + while (*p) + { + if (*p == '.') + { + nextToLastDot = lastDot; + lastDot = p; + } + if (!colon && *p == ':') + colon = p; + p++; + } + nsCStringKey key(nextToLastDot ? nextToLastDot+1 : s); + nsDomainEntry *de = (nsDomainEntry *) mOriginToPolicyMap->Get(&key); + if (!de) + { + nsCAutoString scheme(s, colon-s+1); + nsCStringKey schemeKey(scheme); + de = (nsDomainEntry *) mOriginToPolicyMap->Get(&schemeKey); + } + while (de) + { + if (de->Matches(s)) + { + policy = &de->mPolicy; + break; + } + de = de->mNext; + } + } + if (policy) + result += *policy; + else + result += defaultStr; } - return CheckPermissions(cx, objectPrincipal, cap); - } - case SCRIPT_SECURITY_CAPABILITY_ONLY: - { - PRBool capabilityEnabled = PR_FALSE; - nsresult rv = IsCapabilityEnabled(capability, &capabilityEnabled); - if (NS_FAILED(rv) || !capabilityEnabled) - return NS_ERROR_DOM_SECURITY_ERR; - return NS_OK; - } - default: - // Default is no access - return NS_ERROR_DOM_SECURITY_ERR; } + result += '.'; + result += aClassName; + result += '.'; + result += aPropertyName; + return NS_OK; } NS_IMETHODIMP -nsScriptSecurityManager::CheckLoadURIFromScript(JSContext *cx, - nsIURI *aURI) +nsScriptSecurityManager::CheckLoadURIFromScript(JSContext *cx, nsIURI *aURI) { // Get a context if necessary if (!cx) @@ -501,9 +571,8 @@ nsScriptSecurityManager::CheckLoadURIFromScript(JSContext *cx, // Get principal of currently executing script. nsCOMPtr principal; - if (NS_FAILED(GetSubjectPrincipal(cx, getter_AddRefs(principal)))) { + if (NS_FAILED(GetCallingPrincipal(cx, getter_AddRefs(principal)))) return NS_ERROR_FAILURE; - } // Native code can load all URIs. if (!principal) @@ -555,8 +624,6 @@ NS_IMETHODIMP nsScriptSecurityManager::CheckLoadURI(nsIURI *aSourceURI, nsIURI *aTargetURI, PRUint32 aFlags) { - //-- Get the source and target schemes - //-- jar URIs can be nested. This loop finds the innermost base URI. nsCOMPtr jarURI; nsCOMPtr sourceUri(aSourceURI); while((jarURI = do_QueryInterface(sourceUri))) @@ -565,7 +632,16 @@ nsScriptSecurityManager::CheckLoadURI(nsIURI *aSourceURI, nsIURI *aTargetURI, nsXPIDLCString sourceScheme; if (NS_FAILED(sourceUri->GetScheme(getter_Copies(sourceScheme)))) - return NS_ERROR_OUT_OF_MEMORY; + return NS_ERROR_FAILURE; + + // Some loads are not allowed from mail/news messages + if ((aFlags & nsIScriptSecurityManager::DISALLOW_FROM_MAIL) && + (nsCRT::strcasecmp(sourceScheme, "mailbox") == 0 || + nsCRT::strcasecmp(sourceScheme, "imap") == 0 || + nsCRT::strcasecmp(sourceScheme, "news") == 0)) + { + return NS_ERROR_DOM_BAD_URI; + } nsCOMPtr targetUri(aTargetURI); while((jarURI = do_QueryInterface(targetUri))) @@ -574,16 +650,7 @@ nsScriptSecurityManager::CheckLoadURI(nsIURI *aSourceURI, nsIURI *aTargetURI, nsXPIDLCString targetScheme; if (NS_FAILED(targetUri->GetScheme(getter_Copies(targetScheme)))) - return NS_ERROR_OUT_OF_MEMORY; - - // Some loads are not allowed from mail/news messages - if ((aFlags & nsIScriptSecurityManager::DISALLOW_FROM_MAIL) && - (nsCRT::strcasecmp(sourceScheme, "mailbox") == 0 || - nsCRT::strcasecmp(sourceScheme, "imap") == 0 || - nsCRT::strcasecmp(sourceScheme, "news") == 0)) - { - return ReportErrorToConsole(aTargetURI); - } + return NS_ERROR_FAILURE; if (nsCRT::strcasecmp(targetScheme, sourceScheme) == 0) { @@ -726,19 +793,16 @@ nsScriptSecurityManager::CheckFunctionAccess(JSContext *aCx, void *aFunObj, // Check if the principal the function was compiled under is // allowed to execute scripts. - if (!subject) { + if (!subject) return NS_ERROR_DOM_SECURITY_ERR; - } PRBool result; rv = CanExecuteScripts(aCx, subject, &result); - if (NS_FAILED(rv)) { + if (NS_FAILED(rv)) return rv; - } - if (!result) { + if (!result) return NS_ERROR_DOM_SECURITY_ERR; - } /* ** Get origin of subject and object and compare. @@ -747,9 +811,8 @@ nsScriptSecurityManager::CheckFunctionAccess(JSContext *aCx, void *aFunObj, nsCOMPtr object; if (NS_FAILED(GetObjectPrincipal(aCx, obj, getter_AddRefs(object)))) return NS_ERROR_FAILURE; - if (subject == object) { + if (subject == object) return NS_OK; - } PRBool isSameOrigin = PR_FALSE; if (NS_FAILED(subject->Equals(object, &isSameOrigin))) @@ -760,13 +823,13 @@ nsScriptSecurityManager::CheckFunctionAccess(JSContext *aCx, void *aFunObj, // Allow access to about:blank nsCOMPtr objectCodebase = do_QueryInterface(object); - if (objectCodebase) { + if (objectCodebase) + { nsXPIDLCString origin; if (NS_FAILED(objectCodebase->GetOrigin(getter_Copies(origin)))) return NS_ERROR_FAILURE; - if (nsCRT::strcasecmp(origin, "about:blank") == 0) { + if (nsCRT::strcasecmp(origin, "about:blank") == 0) return NS_OK; - } } /* @@ -775,11 +838,79 @@ nsScriptSecurityManager::CheckFunctionAccess(JSContext *aCx, void *aFunObj, return NS_ERROR_DOM_SECURITY_ERR; } +nsresult +nsScriptSecurityManager::GetRootDocShell(JSContext *cx, nsIDocShell **result) +{ + nsresult rv; + *result = nsnull; + nsCOMPtr docshell; + nsCOMPtr scriptContext = (nsIScriptContext*)JS_GetContextPrivate(cx); + if (!scriptContext) return NS_ERROR_FAILURE; + nsCOMPtr globalObject(dont_AddRef(scriptContext->GetGlobalObject())); + if (!globalObject) return NS_ERROR_FAILURE; + rv = globalObject->GetDocShell(getter_AddRefs(docshell)); + if (NS_FAILED(rv)) return rv; + nsCOMPtr docshellTreeItem = do_QueryInterface(docshell, &rv); + if (NS_FAILED(rv)) return rv; + nsCOMPtr rootItem; + rv = docshellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem)); + if (NS_FAILED(rv)) return rv; + + return rootItem->QueryInterface(NS_GET_IID(nsIDocShell), (void**)result); +} + +NS_IMETHODIMP +nsScriptSecurityManager::CanExecuteScripts(JSContext* cx, + nsIPrincipal *principal, + PRBool *result) +{ + if (principal == mSystemPrincipal) + { + // Even if JavaScript is disabled, we must still execute system scripts + *result = PR_TRUE; + return NS_OK; + } + + //-- See if the current window allows JS execution + nsCOMPtr docshell; + nsresult rv; + rv = GetRootDocShell(cx, getter_AddRefs(docshell)); + if (NS_SUCCEEDED(rv)) + { + rv = docshell->GetAllowJavascript(result); + if (NS_FAILED(rv)) return rv; + if (!*result) + return NS_OK; + } + + /* + There used to be a per-domain policy here, but that functionality + will hopefully be taken over by nsIContentPolicy. Meantime, it's gone. + */ + + if ((mIsJavaScriptEnabled != mIsMailJavaScriptEnabled) && docshell) + { + // Is this script running from mail? + PRUint32 appType; + rv = docshell->GetAppType(&appType); + if (NS_FAILED(rv)) return rv; + if (appType == nsIDocShell::APP_TYPE_MAIL) + { + *result = mIsMailJavaScriptEnabled; + return NS_OK; + } + } + *result = mIsJavaScriptEnabled; + return NS_OK; +} + +///////////////// Principals /////////////////////// NS_IMETHODIMP nsScriptSecurityManager::GetSubjectPrincipal(nsIPrincipal **result) { JSContext *cx = GetCurrentContextQuick(); - if (!cx) { + if (!cx) + { *result = nsnull; return NS_OK; } @@ -789,7 +920,8 @@ nsScriptSecurityManager::GetSubjectPrincipal(nsIPrincipal **result) NS_IMETHODIMP nsScriptSecurityManager::GetSystemPrincipal(nsIPrincipal **result) { - if (!mSystemPrincipal) { + if (!mSystemPrincipal) + { mSystemPrincipal = new nsSystemPrincipal(); if (!mSystemPrincipal) return NS_ERROR_OUT_OF_MEMORY; @@ -819,7 +951,8 @@ nsScriptSecurityManager::GetCertificatePrincipal(const char* aCertID, NS_RELEASE(certificate); if (NS_FAILED(rv)) return rv; - if (mPrincipals) { + if (mPrincipals) + { // Check to see if we already have this principal. nsIPrincipalKey key(principal); nsCOMPtr fromTable = (nsIPrincipal *) mPrincipals->Get(&key); @@ -848,7 +981,8 @@ nsScriptSecurityManager::CreateCodebasePrincipal(nsIURI* aURI, nsIPrincipal **re if (!codebase) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(codebase); - if (NS_FAILED(codebase->Init(aURI))) { + if (NS_FAILED(codebase->Init(aURI))) + { NS_RELEASE(codebase); return NS_ERROR_FAILURE; } @@ -866,7 +1000,8 @@ nsScriptSecurityManager::GetCodebasePrincipal(nsIURI *aURI, rv = CreateCodebasePrincipal(aURI, getter_AddRefs(principal)); if (NS_FAILED(rv)) return rv; - if (mPrincipals) { + if (mPrincipals) + { //-- Check to see if we already have this principal. nsIPrincipalKey key(principal); nsCOMPtr fromTable = (nsIPrincipal *) mPrincipals->Get(&key); @@ -904,119 +1039,13 @@ nsScriptSecurityManager::GetCodebasePrincipal(nsIURI *aURI, return NS_OK; } -PRBool -nsScriptSecurityManager::EnsureNameSetRegistered() -{ - // Confirm that our nameset is registered. We used to do this only when the - // secman was first created. But it turns out that it is possible for code - // to force instatiation of the security manager *before* the namespace - // registry is available. In that case we would fail to register our - // nameset and never try again. Now we keep trying until it succeeds. - - if (!mNameSetRegistered) { - nsresult rv; - NS_WITH_SERVICE(nsIScriptNameSetRegistry, registry, - kCScriptNameSetRegistryCID, &rv); - if (NS_SUCCEEDED(rv)) { - nsSecurityNameSet* nameSet = new nsSecurityNameSet(); - if (nameSet) { - rv = registry->AddExternalNameSet(nameSet); - if (NS_SUCCEEDED(rv)) { - mNameSetRegistered = PR_TRUE; -#ifdef DEBUG_jband - printf("##### security manager nameset registered\n"); -#endif - } - } - } - } - return mNameSetRegistered; -} - nsresult -nsScriptSecurityManager::GetRootDocShell(JSContext *cx, nsIDocShell **result) -{ - nsresult rv; - *result = nsnull; - nsCOMPtr docshell; - nsCOMPtr scriptContext = (nsIScriptContext*)JS_GetContextPrivate(cx); - if (!scriptContext) return NS_ERROR_FAILURE; - nsCOMPtr globalObject(dont_AddRef(scriptContext->GetGlobalObject())); - if (!globalObject) return NS_ERROR_FAILURE; - rv = globalObject->GetDocShell(getter_AddRefs(docshell)); - if (NS_FAILED(rv)) return rv; - nsCOMPtr docshellTreeItem = do_QueryInterface(docshell, &rv); - if (NS_FAILED(rv)) return rv; - nsCOMPtr rootItem; - rv = docshellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem)); - if (NS_FAILED(rv)) return rv; - - return rootItem->QueryInterface(NS_GET_IID(nsIDocShell), (void**)result); -} - -NS_IMETHODIMP -nsScriptSecurityManager::CanExecuteScripts(JSContext* cx, nsIPrincipal *principal, - PRBool *result) -{ - // XXX Really OK to fail? - // I suppose that in some embedding there may be no ScriptNameSetRegistry. - EnsureNameSetRegistered(); - - if (principal == mSystemPrincipal) - { - // Even if JavaScript is disabled, we must still execute system scripts - *result = PR_TRUE; - return NS_OK; - } - - //-- See if the current window allows JS execution - nsCOMPtr docshell; - nsresult rv; - rv = GetRootDocShell(cx, getter_AddRefs(docshell)); - if (NS_SUCCEEDED(rv)) - { - rv = docshell->GetAllowJavascript(result); - if (NS_FAILED(rv)) return rv; - if (!*result) - return NS_OK; - } - - if (GetBit(hasDomainPolicyVector, NS_DOM_PROP_JAVASCRIPT_ENABLED)) - { - // We may have a per-domain security policy for JavaScript execution - nsCAutoString capability; - PRInt32 secLevel = GetSecurityLevel(principal, - NS_DOM_PROP_JAVASCRIPT_ENABLED, - PR_FALSE, capability); - if (secLevel != SCRIPT_SECURITY_UNDEFINED_ACCESS) - { - *result = (secLevel == SCRIPT_SECURITY_ALL_ACCESS); - return NS_OK; - } - } - - if ((mIsJavaScriptEnabled != mIsMailJavaScriptEnabled) && docshell) - { - // Is this script running from mail? - PRUint32 appType; - rv = docshell->GetAppType(&appType); - if (NS_FAILED(rv)) return rv; - if (appType == nsIDocShell::APP_TYPE_MAIL) - { - *result = mIsMailJavaScriptEnabled; - return NS_OK; - } - } - *result = mIsJavaScriptEnabled; - return NS_OK; -} - -NS_IMETHODIMP nsScriptSecurityManager::GetScriptPrincipal(JSContext *cx, JSScript *script, nsIPrincipal **result) { - if (!script) { + if (!script) + { *result = nsnull; return NS_OK; } @@ -1034,27 +1063,27 @@ nsScriptSecurityManager::GetScriptPrincipal(JSContext *cx, } -NS_IMETHODIMP +nsresult nsScriptSecurityManager::GetFunctionObjectPrincipal(JSContext *cx, JSObject *obj, nsIPrincipal **result) { JSFunction *fun = (JSFunction *) JS_GetPrivate(cx, obj); - if (JS_GetFunctionObject(fun) != obj) { + if (JS_GetFunctionObject(fun) != obj) // Function has been cloned; get principals from scope return GetObjectPrincipal(cx, obj, result); - } JSScript *script = JS_GetFunctionScript(cx, fun); return GetScriptPrincipal(cx, script, result); } -NS_IMETHODIMP +nsresult nsScriptSecurityManager::GetFramePrincipal(JSContext *cx, JSStackFrame *fp, nsIPrincipal **result) { JSObject *obj = JS_GetFrameFunctionObject(cx, fp); - if (!obj) { + if (!obj) + { // Must be in a top-level script. Get principal from the script. JSScript *script = JS_GetFrameScript(cx, fp); return GetScriptPrincipal(cx, script, result); @@ -1062,10 +1091,185 @@ nsScriptSecurityManager::GetFramePrincipal(JSContext *cx, return GetFunctionObjectPrincipal(cx, obj, result); } +nsresult +nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx, + PRBool skipInnerFrame, + nsIPrincipal **result, + JSStackFrame **frameResult) +{ + // Get principals from innermost frame of JavaScript or Java. + JSStackFrame *fp = nsnull; // tell JS_FrameIterator to start at innermost + if (skipInnerFrame) // Skip the innermost frame + { + fp = JS_FrameIterator(cx, &fp); +#ifdef DEBUG_mstoltz + if(!fp) + printf("####### JS stack weirdness in GetPrincipalAndFrame.\n"); +#endif + } + for (fp = JS_FrameIterator(cx, &fp); fp; fp = JS_FrameIterator(cx, &fp)) + { + if (NS_FAILED(GetFramePrincipal(cx, fp, result))) + return NS_ERROR_FAILURE; + if (*result) + { + *frameResult = fp; + return NS_OK; + } + } + //-- If there's no principal on the stack, look at the global object + // and return the innermost frame for annotations. + if (cx) + { + nsCOMPtr scriptContext = + NS_REINTERPRET_CAST(nsIScriptContext*,JS_GetContextPrivate(cx)); + if (scriptContext) + { + nsCOMPtr global = scriptContext->GetGlobalObject(); + NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); + nsCOMPtr globalData = do_QueryInterface(global); + NS_ENSURE_TRUE(globalData, NS_ERROR_FAILURE); + globalData->GetPrincipal(result); + if (*result) + { + JSStackFrame *inner = nsnull; + *frameResult = JS_FrameIterator(cx, &inner); + return NS_OK; + } + } + } + + *result = nsnull; + return NS_OK; +} + +nsresult +nsScriptSecurityManager::GetSubjectPrincipal(JSContext *cx, + nsIPrincipal **result) +{ + JSStackFrame *fp; + return GetPrincipalAndFrame(cx, PR_FALSE, result, &fp); +} + +nsresult +nsScriptSecurityManager::GetCallingPrincipal(JSContext *cx, + nsIPrincipal **result) +{ + JSStackFrame *fp; + return GetPrincipalAndFrame(cx, PR_TRUE, result, &fp); +} + +nsresult +nsScriptSecurityManager::GetObjectPrincipal(JSContext *aCx, JSObject *aObj, + nsIPrincipal **result) +{ + JSObject *parent = aObj; + do + { + JSClass *jsClass = JS_GetClass(aCx, parent); + const uint32 privateNsISupports = JSCLASS_HAS_PRIVATE | + JSCLASS_PRIVATE_IS_NSISUPPORTS; + if (jsClass && (jsClass->flags & (privateNsISupports)) == + privateNsISupports) + { + nsCOMPtr supports = (nsISupports *) JS_GetPrivate(aCx, parent); + nsCOMPtr objPrin = + do_QueryInterface(supports); + if (!objPrin) + { + /* + * If it's a wrapped native, check the underlying native + * instead. + */ + nsCOMPtr xpcNative = + do_QueryInterface(supports); + if (xpcNative) + xpcNative->GetNative(getter_AddRefs(supports)); + objPrin = do_QueryInterface(supports); + } + + if (objPrin && NS_SUCCEEDED(objPrin->GetPrincipal(result))) + return NS_OK; + } + parent = JS_GetParent(aCx, parent); + } while (parent); + + // Couldn't find a principal for this object. + return NS_ERROR_FAILURE; +} + +nsresult +nsScriptSecurityManager::SavePrincipal(nsIPrincipal* aToSave) +{ + NS_ASSERTION(mSecurityPrefs, "nsScriptSecurityManager::mSecurityPrefs not initialized"); + nsresult rv; + nsCOMPtr persistent = aToSave; + nsCOMPtr aggregate = do_QueryInterface(aToSave, &rv); + if (NS_SUCCEEDED(rv)) + if (NS_FAILED(aggregate->GetPrimaryChild(getter_AddRefs(persistent)))) + return NS_ERROR_FAILURE; + + //-- Save to mPrincipals + if (!mPrincipals) + { + mPrincipals = new nsSupportsHashtable(31); + if (!mPrincipals) + return NS_ERROR_OUT_OF_MEMORY; + } + nsIPrincipalKey key(persistent); + mPrincipals->Put(&key, persistent); + + //-- Save to prefs + nsXPIDLCString idPrefName; + nsXPIDLCString id; + nsXPIDLCString grantedList; + nsXPIDLCString deniedList; + rv = persistent->GetPreferences(getter_Copies(idPrefName), + getter_Copies(id), + getter_Copies(grantedList), + getter_Copies(deniedList)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + nsXPIDLCString grantedPrefName; + nsXPIDLCString deniedPrefName; + rv = PrincipalPrefNames( idPrefName, + getter_Copies(grantedPrefName), + getter_Copies(deniedPrefName) ); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + mIsWritingPrefs = PR_TRUE; + if (grantedList) + mSecurityPrefs->SecuritySetCharPref(grantedPrefName, grantedList); + else + mSecurityPrefs->SecurityClearUserPref(grantedPrefName); + + if (deniedList) + mSecurityPrefs->SecuritySetCharPref(deniedPrefName, deniedList); + else + mSecurityPrefs->SecurityClearUserPref(deniedPrefName); + + if (grantedList || deniedList) + mSecurityPrefs->SecuritySetCharPref(idPrefName, id); + else + mSecurityPrefs->SecurityClearUserPref(idPrefName); + + mIsWritingPrefs = PR_FALSE; + return mPrefService->SavePrefFile(nsnull); +} + +///////////////// Capabilities API ///////////////////// NS_IMETHODIMP nsScriptSecurityManager::IsCapabilityEnabled(const char *capability, - PRBool *result) + PRBool *result) +{ + return IsCapabilityEnabledImpl(capability, PR_FALSE, result); +} + +nsresult +nsScriptSecurityManager::IsCapabilityEnabledImpl(const char *capability, + PRBool aSkipFrame, + PRBool *result) { nsresult rv; JSStackFrame *fp = nsnull; @@ -1076,12 +1280,14 @@ nsScriptSecurityManager::IsCapabilityEnabled(const char *capability, *result = PR_TRUE; return NS_OK; } + if (aSkipFrame) + fp = JS_FrameIterator(cx, &fp); - do { + do + { nsCOMPtr principal; - if (NS_FAILED(GetFramePrincipal(cx, fp, getter_AddRefs(principal)))) { + if (NS_FAILED(GetFramePrincipal(cx, fp, getter_AddRefs(principal)))) return NS_ERROR_FAILURE; - } if (!principal) continue; @@ -1122,13 +1328,15 @@ Localize(char *genericString, nsString &result) nsIIOService *pNetService = nsnull; ret = nsServiceManager::GetService(kIOServiceCID, kIIOServiceIID, (nsISupports**) &pNetService); - if (NS_FAILED(ret)) { + if (NS_FAILED(ret)) + { NS_WARNING("cannot get net service\n"); return ret; } nsIURI *uri = nsnull; ret = pNetService->NewURI(PROPERTIES_URL, nsnull, &uri); - if (NS_FAILED(ret)) { + if (NS_FAILED(ret)) + { NS_WARNING("cannot create URI\n"); nsServiceManager::ReleaseService(kIOServiceCID, pNetService); return ret; @@ -1138,7 +1346,8 @@ Localize(char *genericString, nsString &result) ret = uri->QueryInterface(NS_GET_IID(nsIURI), (void**)&url); nsServiceManager::ReleaseService(kIOServiceCID, pNetService); - if (NS_FAILED(ret)) { + if (NS_FAILED(ret)) + { NS_WARNING("cannot create URL\n"); return ret; } @@ -1147,13 +1356,15 @@ Localize(char *genericString, nsString &result) nsIStringBundleService *pStringService = nsnull; ret = nsServiceManager::GetService(kStringBundleServiceCID, kIStringBundleServiceIID, (nsISupports**) &pStringService); - if (NS_FAILED(ret)) { + if (NS_FAILED(ret)) + { NS_WARNING("cannot get string service\n"); return ret; } char *spec = nsnull; ret = url->GetSpec(&spec); - if (NS_FAILED(ret)) { + if (NS_FAILED(ret)) + { NS_WARNING("cannot get url spec\n"); nsServiceManager::ReleaseService(kStringBundleServiceCID, pStringService); nsCRT::free(spec); @@ -1163,7 +1374,8 @@ Localize(char *genericString, nsString &result) ret = pStringService->CreateBundle(spec, &bundle); nsCRT::free(spec); nsServiceManager::ReleaseService(kStringBundleServiceCID, pStringService); - if (NS_FAILED(ret)) { + if (NS_FAILED(ret)) + { NS_WARNING("cannot create instance\n"); return ret; } @@ -1175,9 +1387,8 @@ Localize(char *genericString, nsString &result) PRUnichar *ptrv = nsnull; ret = bundle->GetStringFromName(strtmp.GetUnicode(), &ptrv); NS_RELEASE(bundle); - if (NS_FAILED(ret)) { + if (NS_FAILED(ret)) NS_WARNING("cannot get string from name\n"); - } result = ptrv; nsCRT::free(ptrv); return ret; @@ -1223,12 +1434,10 @@ CheckConfirmDialog(JSContext* cx, const PRUnichar *szMessage, const PRUnichar *s (nsIPrompt::BUTTON_TITLE_NO * nsIPrompt::BUTTON_POS_1), nsnull, nsnull, nsnull, szCheckMessage, checkValue, &buttonPressed); - if (NS_FAILED(res)) { + if (NS_FAILED(res)) *checkValue = 0; - } - if (*checkValue != 0 && *checkValue != 1) { + if (*checkValue != 0 && *checkValue != 1) *checkValue = 0; /* this should never happen but it is happening!!! */ - } return (buttonPressed == 0); } @@ -1238,7 +1447,8 @@ nsScriptSecurityManager::RequestCapability(nsIPrincipal* aPrincipal, { if (NS_FAILED(aPrincipal->CanEnableCapability(capability, canEnable))) return NS_ERROR_FAILURE; - if (*canEnable == nsIPrincipal::ENABLE_WITH_USER_PERMISSION) { + if (*canEnable == nsIPrincipal::ENABLE_WITH_USER_PERMISSION) + { // Prompt user for permission to enable capability. static PRBool remember = PR_TRUE; nsAutoString query, check; @@ -1257,7 +1467,8 @@ nsScriptSecurityManager::RequestCapability(nsIPrincipal* aPrincipal, else *canEnable = nsIPrincipal::ENABLE_DENIED; PR_FREEIF(message); - if (remember) { + if (remember) + { //-- Save principal to prefs and to mPrincipals if (NS_FAILED(aPrincipal->SetCanEnableCapability(capability, *canEnable))) return NS_ERROR_FAILURE; @@ -1268,49 +1479,6 @@ nsScriptSecurityManager::RequestCapability(nsIPrincipal* aPrincipal, return NS_OK; } -NS_IMETHODIMP -nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx, - nsIPrincipal **result, - JSStackFrame **frameResult) -{ - // Get principals from innermost frame of JavaScript or Java. - JSStackFrame *fp = nsnull; // tell JS_FrameIterator to start at innermost - for (fp = JS_FrameIterator(cx, &fp); fp; fp = JS_FrameIterator(cx, &fp)) { - if (NS_FAILED(GetFramePrincipal(cx, fp, result))) { - return NS_ERROR_FAILURE; - } - if (*result) { - *frameResult = fp; - return NS_OK; - } - } - - //-- If there's no principal on the stack, look at the global object - // and return the innermost frame for annotations. - if (cx) - { - nsCOMPtr scriptContext = - NS_REINTERPRET_CAST(nsIScriptContext*,JS_GetContextPrivate(cx)); - if (scriptContext) - { - nsCOMPtr global(dont_AddRef(scriptContext->GetGlobalObject())); - NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); - nsCOMPtr globalData = do_QueryInterface(global); - NS_ENSURE_TRUE(globalData, NS_ERROR_FAILURE); - globalData->GetPrincipal(result); - if (*result) - { - JSStackFrame *inner = nsnull; - *frameResult = JS_FrameIterator(cx, &inner); - return NS_OK; - } - } - } - - *result = nsnull; - return NS_OK; -} - NS_IMETHODIMP nsScriptSecurityManager::EnableCapability(const char *capability) { @@ -1318,25 +1486,22 @@ nsScriptSecurityManager::EnableCapability(const char *capability) JSStackFrame *fp; //Error checks for capability string length (200) - if(PL_strlen(capability)>200) { + if(PL_strlen(capability)>200) + { static const char msg[] = "Capability name too long"; JS_SetPendingException(cx, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, msg))); return NS_ERROR_FAILURE; } nsCOMPtr principal; - if (NS_FAILED(GetPrincipalAndFrame(cx, getter_AddRefs(principal), + if (NS_FAILED(GetPrincipalAndFrame(cx, PR_FALSE, getter_AddRefs(principal), &fp))) - { return NS_ERROR_FAILURE; - } void *annotation = JS_GetFrameAnnotation(cx, fp); PRBool enabled; if (NS_FAILED(principal->IsCapabilityEnabled(capability, annotation, &enabled))) - { return NS_ERROR_FAILURE; - } if (enabled) return NS_OK; @@ -1344,7 +1509,8 @@ nsScriptSecurityManager::EnableCapability(const char *capability) if (NS_FAILED(RequestCapability(principal, capability, &canEnable))) return NS_ERROR_FAILURE; - if (canEnable != nsIPrincipal::ENABLE_GRANTED) { + if (canEnable != nsIPrincipal::ENABLE_GRANTED) + { static const char msg[] = "enablePrivilege not granted"; JS_SetPendingException(cx, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, msg))); return NS_ERROR_FAILURE; // XXX better error code? @@ -1361,11 +1527,9 @@ nsScriptSecurityManager::RevertCapability(const char *capability) JSContext *cx = GetCurrentContextQuick(); JSStackFrame *fp; nsCOMPtr principal; - if (NS_FAILED(GetPrincipalAndFrame(cx, getter_AddRefs(principal), + if (NS_FAILED(GetPrincipalAndFrame(cx, PR_FALSE, getter_AddRefs(principal), &fp))) - { return NS_ERROR_FAILURE; - } void *annotation = JS_GetFrameAnnotation(cx, fp); principal->RevertCapability(capability, &annotation); JS_SetFrameAnnotation(cx, fp, annotation); @@ -1378,17 +1542,16 @@ nsScriptSecurityManager::DisableCapability(const char *capability) JSContext *cx = GetCurrentContextQuick(); JSStackFrame *fp; nsCOMPtr principal; - if (NS_FAILED(GetPrincipalAndFrame(cx, getter_AddRefs(principal), + if (NS_FAILED(GetPrincipalAndFrame(cx, PR_FALSE, getter_AddRefs(principal), &fp))) - { return NS_ERROR_FAILURE; - } void *annotation = JS_GetFrameAnnotation(cx, fp); principal->DisableCapability(capability, &annotation); JS_SetFrameAnnotation(cx, fp, annotation); return NS_OK; } +//////////////// Master Certificate Functions /////////////////////////////////////// NS_IMETHODIMP nsScriptSecurityManager::SetCanEnableCapability(const char* certificateID, const char* capability, @@ -1463,188 +1626,177 @@ nsScriptSecurityManager::SetCanEnableCapability(const char* certificateID, // Methods implementing nsIXPCSecurityManager // //////////////////////////////////////////////// -#include "nsISecurityCheckedComponent.h" - -nsresult -nsScriptSecurityManager::CheckXPCCapability(JSContext *aJSContext, const char *aCapability) -{ - // Check for the carte blanche before anything else. - if (aCapability) { - if (PL_strcasecmp(aCapability, "AllAccess") == 0) - return NS_OK; - else if (PL_strcasecmp(aCapability, "NoAccess") != 0) { - PRBool canAccess; - if (NS_FAILED(IsCapabilityEnabled(aCapability, &canAccess))) - return NS_ERROR_FAILURE; - if (canAccess) - return NS_OK; - } - } - - static const char msg[] = "Access to XPConnect service denied."; - JS_SetPendingException(aJSContext, - STRING_TO_JSVAL(JS_NewStringCopyZ(aJSContext, msg))); - return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED; -} - NS_IMETHODIMP nsScriptSecurityManager::CanCreateWrapper(JSContext *aJSContext, const nsIID &aIID, - nsISupports *aObj) + nsISupports *aObj, + nsIClassInfo *aClassInfo, + void **aPolicy) { - // XXX could un-special-case-this - if (aIID.Equals(NS_GET_IID(nsIXPCException))) - return NS_OK; - - nsresult rv; - rv = CheckXPCPermissions(aJSContext, aObj); - if (NS_SUCCEEDED(rv)) - return rv; - - // If check fails, QI to interface that lets scomponents advertise - // their own security requirements. - nsCOMPtr checkedComponent = - do_QueryInterface(aObj, &rv); - - nsXPIDLCString capability; - if (NS_SUCCEEDED(rv) && checkedComponent) { - checkedComponent->CanCreateWrapper((nsIID *)&aIID, - getter_Copies(capability)); +#if 0 + char* iidStr = aIID.ToString(); + printf("### CanCreateWrapper(%s) ", iidStr); + PR_FREEIF(iidStr); +#endif +// XXX Special case for nsIXPCException ? + if (IsDOMClass(aClassInfo)) + { +#if 0 + printf("DOM class - GRANTED.\n"); +#endif + return NS_OK; } - return CheckXPCCapability(aJSContext, capability); + //--See if the object advertises a non-default level of access + // using nsISecurityCheckedComponent + nsCOMPtr checkedComponent = + do_QueryInterface(aObj); + + nsXPIDLCString objectSecurityLevel; + if (checkedComponent) + checkedComponent->CanCreateWrapper((nsIID *)&aIID, getter_Copies(objectSecurityLevel)); + + return CheckXPCPermissions(aJSContext, aObj, objectSecurityLevel, PR_FALSE, + "Permission denied to create wrapper for object"); } NS_IMETHODIMP -nsScriptSecurityManager::CanCreateInstance(JSContext *aJSContext, +nsScriptSecurityManager::CanCreateInstance(JSContext *aJSContext, const nsCID &aCID) { - nsresult rv; - rv = CheckXPCPermissions(aJSContext, nsnull); - if (NS_SUCCEEDED(rv)) - return rv; + //XXX Special cases needed: exceptions? +#if 0 + char* cidStr = aCID.ToString(); + printf("### CanCreateInstance(%s) ", cidStr); + PR_FREEIF(cidStr); +#endif - static const char msg[] = "Access to XPConnect service denied."; - JS_SetPendingException(aJSContext, - STRING_TO_JSVAL(JS_NewStringCopyZ(aJSContext, msg))); - return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED; + return CheckXPCPermissions(aJSContext, nsnull, nsnull, PR_FALSE, + "Permission denied to create instance of class"); } NS_IMETHODIMP nsScriptSecurityManager::CanGetService(JSContext *aJSContext, const nsCID &aCID) { - nsresult rv; - rv = CheckXPCPermissions(aJSContext, nsnull); - if (NS_SUCCEEDED(rv)) - return rv; +#if 0 + char* cidStr = aCID.ToString(); + printf("### CanGetService(%s) ", cidStr); + PR_FREEIF(cidStr); +#endif - static const char msg[] = "Access to XPConnect service denied."; + return CheckXPCPermissions(aJSContext, nsnull, nsnull, PR_FALSE, + "Permission denied to get service"); +} + +/* void CanAccess (in PRUint32 aAction, in nsIXPCNativeCallContext aCallContext, in JSContextPtr aJSContext, in JSObjectPtr aJSObject, in nsISupports aObj, in nsIClassInfo aClassInfo, in JSVal aName, inout voidPtr aPolicy); */ +NS_IMETHODIMP +nsScriptSecurityManager::CanAccess(PRUint32 aAction, + nsIXPCNativeCallContext* aCallContext, + JSContext* aJSContext, + JSObject* aJSObject, + nsISupports* aObj, + nsIClassInfo* aClassInfo, + jsval aName, + void** aPolicy) +{ + return CheckPropertyAccessImpl(aAction, aCallContext, aJSContext, aJSObject, + aObj, aClassInfo, aName, nsnull, nsnull, PR_TRUE, aPolicy); +} + +nsresult +nsScriptSecurityManager::CheckXPCPermissions(JSContext *aJSContext, + nsISupports* aObj, + const char* aObjectSecurityLevel, + PRBool aSkipFrame, + const char* aErrorMsg) +{ + //-- Check for the all-powerful UniversalXPConnect privilege + PRBool ok = PR_FALSE; + if (NS_SUCCEEDED(IsCapabilityEnabledImpl("UniversalXPConnect", aSkipFrame, &ok)) && ok) + return NS_OK; + + //-- If the object implements nsISecurityCheckedComponent, it has a non-default policy. + if (aObjectSecurityLevel) + { + if (PL_strcasecmp(aObjectSecurityLevel, "AllAccess") == 0) + return NS_OK; + else if (PL_strcasecmp(aObjectSecurityLevel, "NoAccess") != 0) + { + PRBool canAccess = PR_FALSE; + if (NS_SUCCEEDED(IsCapabilityEnabled(aObjectSecurityLevel, &canAccess)) && + canAccess) + return NS_OK; + } + } + + //-- If user allows scripting of plugins by untrusted scripts, + // and the target object is a plugin, allow the access. + if(aObj) + { + nsresult rv; + nsCOMPtr plugin = do_QueryInterface(aObj, &rv); + if (NS_SUCCEEDED(rv)) + { + static PRBool prefSet = PR_FALSE; + static PRBool allowPluginAccess = PR_FALSE; + if (!prefSet) + { + rv = mPrefs->GetBoolPref("security.xpconnect.plugin.unrestricted", + &allowPluginAccess); + prefSet = PR_TRUE; + } + if (allowPluginAccess) + return NS_OK; + } + } + + //-- Access tests failed, so report error JS_SetPendingException(aJSContext, - STRING_TO_JSVAL(JS_NewStringCopyZ(aJSContext, msg))); + STRING_TO_JSVAL(JS_NewStringCopyZ(aJSContext, aErrorMsg))); return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED; } -// Result of this function should not be freed. -static const PRUnichar * -JSIDToString(JSContext *aJSContext, const jsid id) { - jsval v; - JS_IdToValue(aJSContext, id, &v); - JSString *str = JS_ValueToString(aJSContext, v); - return NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(str)); -} - +///////////////////////////////////// +// Method implementing nsIObserver // +///////////////////////////////////// NS_IMETHODIMP -nsScriptSecurityManager::CanCallMethod(JSContext *aJSContext, - const nsIID &aIID, - nsISupports *aObj, - nsIInterfaceInfo *aInterfaceInfo, - PRUint16 aMethodIndex, - const jsid aName) +nsScriptSecurityManager::Observe(nsISupports* aObject, const PRUnichar* aAction, + const PRUnichar* aPrefName) { - nsresult rv; - rv = CheckXPCPermissions(aJSContext, aObj); - if (NS_SUCCEEDED(rv)) - return rv; + nsresult rv = NS_OK; + nsCAutoString prefNameStr; + prefNameStr.AssignWithConversion(aPrefName); + char* prefName = prefNameStr.ToNewCString(); + if (!prefName) + return NS_ERROR_OUT_OF_MEMORY; - // If check fails, QI to interface that lets scomponents advertise - // their own security requirements. - nsCOMPtr checkedComponent = - do_QueryInterface(aObj, &rv); - - nsXPIDLCString capability; - if (NS_SUCCEEDED(rv) && checkedComponent) { - checkedComponent->CanCallMethod((const nsIID *)&aIID, - JSIDToString(aJSContext, aName), - getter_Copies(capability)); + static const char jsPrefix[] = "javascript."; + if(PL_strncmp(prefName, jsPrefix, sizeof(jsPrefix)-1) == 0) + JSEnabledPrefChanged(); + else if((PL_strncmp(prefName, sPrincipalPrefix, sizeof(sPrincipalPrefix)-1) == 0) && + !mIsWritingPrefs) + { + static const char id[] = "id"; + char* lastDot = PL_strrchr(prefName, '.'); + //-- This check makes sure the string copy below doesn't overwrite its bounds + if(PL_strlen(lastDot) >= sizeof(id)) + { + PL_strcpy(lastDot + 1, id); + const char** idPrefArray = (const char**)&prefName; + rv = InitPrincipals(1, idPrefArray); + } } - - return CheckXPCCapability(aJSContext, capability); + PR_Free(prefName); + return rv; } -NS_IMETHODIMP -nsScriptSecurityManager::CanGetProperty(JSContext *aJSContext, - const nsIID &aIID, - nsISupports *aObj, - nsIInterfaceInfo *aInterfaceInfo, - PRUint16 aMethodIndex, - const jsid aName) -{ - nsresult rv; - rv = CheckXPCPermissions(aJSContext, aObj); - if (NS_SUCCEEDED(rv)) - return rv; - - // If check fails, QI to interface that lets scomponents advertise - // their own security requirements. - nsCOMPtr checkedComponent = - do_QueryInterface(aObj, &rv); - - nsXPIDLCString capability; - if (NS_SUCCEEDED(rv) && checkedComponent) { - checkedComponent->CanGetProperty((const nsIID *)&aIID, - JSIDToString(aJSContext, aName), - getter_Copies(capability)); - } - - return CheckXPCCapability(aJSContext, capability); -} - -NS_IMETHODIMP -nsScriptSecurityManager::CanSetProperty(JSContext *aJSContext, - const nsIID &aIID, - nsISupports *aObj, - nsIInterfaceInfo *aInterfaceInfo, - PRUint16 aMethodIndex, - const jsid aName) -{ - nsresult rv; - rv = CheckXPCPermissions(aJSContext, aObj); - if (NS_SUCCEEDED(rv)) - return rv; - - // If check fails, QI to interface that lets scomponents advertise - // their own security requirements. - nsCOMPtr checkedComponent = - do_QueryInterface(aObj, &rv); - - nsXPIDLCString capability; - if (NS_SUCCEEDED(rv) && checkedComponent) { - checkedComponent->CanSetProperty((const nsIID *)&aIID, - JSIDToString(aJSContext, aName), - getter_Copies(capability)); - } - - return CheckXPCCapability(aJSContext, capability); -} - -/////////////////// -// Other methods // -/////////////////// - - +///////////////////////////////////////////// +// Constructor, Destructor, Initialization // +///////////////////////////////////////////// nsScriptSecurityManager::nsScriptSecurityManager(void) : mOriginToPolicyMap(nsnull), + mClassPolicies(nsnull), mSystemPrincipal(nsnull), mPrincipals(nsnull), mIsJavaScriptEnabled(PR_FALSE), mIsMailJavaScriptEnabled(PR_FALSE), @@ -1653,7 +1805,6 @@ nsScriptSecurityManager::nsScriptSecurityManager(void) { NS_INIT_REFCNT(); - memset(hasDomainPolicyVector, 0, sizeof(hasDomainPolicyVector)); InitPrefs(); mThreadJSContextStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1"); } @@ -1661,6 +1812,7 @@ nsScriptSecurityManager::nsScriptSecurityManager(void) nsScriptSecurityManager::~nsScriptSecurityManager(void) { delete mOriginToPolicyMap; + delete mClassPolicies; NS_IF_RELEASE(mSystemPrincipal); delete mPrincipals; } @@ -1669,390 +1821,42 @@ nsScriptSecurityManager * nsScriptSecurityManager::GetScriptSecurityManager() { static nsScriptSecurityManager *ssecMan = NULL; - if (!ssecMan) { + if (!ssecMan) + { ssecMan = new nsScriptSecurityManager(); if (!ssecMan) return NULL; nsresult rv; - // Try to register the nameset. This can sometimes fail on first run - // when the nameset service is not yet available at the time when - // the script security manager is created. That is OK. We will try - // again when CanExecuteSCripts is called if necessary. - ssecMan->EnsureNameSetRegistered(); - NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv); - if (NS_SUCCEEDED(rv) && xpc) { + if (NS_SUCCEEDED(rv) && xpc) + { rv = xpc->SetDefaultSecurityManager( NS_STATIC_CAST(nsIXPCSecurityManager*, ssecMan), nsIXPCSecurityManager::HOOK_ALL); - if (NS_FAILED(rv)) { + if (NS_FAILED(rv)) NS_WARNING("failed to install xpconnect security manager!"); - } #ifdef DEBUG_jband - else { + else printf("!!!!! xpc security manager registered\n"); - } #endif } - else { + else NS_WARNING("can't get xpconnect to install security manager!"); - } } return ssecMan; } -NS_IMETHODIMP -nsScriptSecurityManager::GetSubjectPrincipal(JSContext *cx, - nsIPrincipal **result) -{ - JSStackFrame *fp; - return GetPrincipalAndFrame(cx, result, &fp); -} - -NS_IMETHODIMP -nsScriptSecurityManager::GetObjectPrincipal(JSContext *aCx, JSObject *aObj, - nsIPrincipal **result) -{ - JSObject *parent = aObj; - do { - JSClass *jsClass = JS_GetClass(aCx, parent); - const uint32 privateNsISupports = JSCLASS_HAS_PRIVATE | - JSCLASS_PRIVATE_IS_NSISUPPORTS; - if (jsClass && (jsClass->flags & (privateNsISupports)) == - privateNsISupports) - { - nsCOMPtr supports = (nsISupports *) JS_GetPrivate(aCx, parent); - nsCOMPtr objPrin = - do_QueryInterface(supports); - if (!objPrin) { - /* - * If it's a wrapped native, check the underlying native - * instead. - */ - nsCOMPtr xpcNative = - do_QueryInterface(supports); - if (xpcNative) - xpcNative->GetNative(getter_AddRefs(supports)); - objPrin = do_QueryInterface(supports); - } - - if (objPrin && NS_SUCCEEDED(objPrin->GetPrincipal(result))) - return NS_OK; - } - parent = JS_GetParent(aCx, parent); - } while (parent); - - // Couldn't find a principal for this object. - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsScriptSecurityManager::CheckPermissions(JSContext *aCx, nsIPrincipal* aObjectPrincipal, - const char *aCapability) -{ - /* - ** Get origin of subject and object and compare. - */ - nsCOMPtr subject; - if (NS_FAILED(GetSubjectPrincipal(aCx, getter_AddRefs(subject)))) - return NS_ERROR_FAILURE; - - if (subject.get() == aObjectPrincipal) - return NS_OK; - - PRBool isSameOrigin = PR_FALSE; - if (NS_FAILED(subject->Equals(aObjectPrincipal, &isSameOrigin))) - return NS_ERROR_FAILURE; - - if (isSameOrigin) - { -#ifdef DEBUG_mstoltz - printf(" OK.\n"); -#endif - return NS_OK; - } - - // Allow access to about:blank - nsCOMPtr objectCodebase = do_QueryInterface(aObjectPrincipal); - if (objectCodebase) - { - nsXPIDLCString origin; - if (NS_FAILED(objectCodebase->GetOrigin(getter_Copies(origin)))) - return NS_ERROR_FAILURE; - if (nsCRT::strcasecmp(origin, "about:blank") == 0) - return NS_OK; - } - - /* - ** If we failed the origin tests it still might be the case that we - ** are a signed script and have permissions to do this operation. - ** Check for that here - */ - PRBool capabilityEnabled = PR_FALSE; - if (NS_FAILED(IsCapabilityEnabled(aCapability, &capabilityEnabled))) - return NS_ERROR_FAILURE; - if (capabilityEnabled) - return NS_OK; - - /* - ** Access tests failed, so now report error. - */ -#ifdef DEBUG_mstoltz - printf(" FAILED.\n"); -#endif - return NS_ERROR_DOM_PROP_ACCESS_DENIED; -} - -PRInt32 -nsScriptSecurityManager::GetSecurityLevel(nsIPrincipal *principal, - nsDOMProp domProp, - PRBool isWrite, - nsCString &capability) -{ - nsCAutoString prefName; - if (NS_FAILED(GetPrefName(principal, domProp, prefName))) - return SCRIPT_SECURITY_NO_ACCESS; - PRInt32 secLevel; - char *secLevelString; - nsresult rv; - rv = mSecurityPrefs->SecurityGetCharPref(prefName, &secLevelString); - if (NS_FAILED(rv)) { - prefName += (isWrite ? ".write" : ".read"); - rv = mSecurityPrefs->SecurityGetCharPref(prefName, &secLevelString); - } - if (NS_SUCCEEDED(rv) && secLevelString) { - if (PL_strcmp(secLevelString, "sameOrigin") == 0) - secLevel = SCRIPT_SECURITY_SAME_DOMAIN_ACCESS; - else if (PL_strcmp(secLevelString, "allAccess") == 0) - secLevel = SCRIPT_SECURITY_ALL_ACCESS; - else if (PL_strcmp(secLevelString, "noAccess") == 0) - secLevel = SCRIPT_SECURITY_NO_ACCESS; - else { - // string should be the name of a capability - capability = secLevelString; - secLevelString = nsnull; - secLevel = SCRIPT_SECURITY_CAPABILITY_ONLY; - } - if (secLevelString) - PR_Free(secLevelString); - return secLevel; - } - return SCRIPT_SECURITY_UNDEFINED_ACCESS; -} - -NS_IMETHODIMP -nsScriptSecurityManager::CheckXPCPermissions(JSContext *aJSContext, - nsISupports* aObj) -{ - NS_ASSERTION(mPrefs,"nsScriptSecurityManager::mPrefs not initialized"); - PRBool ok = PR_FALSE; - if (NS_FAILED(IsCapabilityEnabled("UniversalXPConnect", &ok))) - ok = PR_FALSE; - if (!ok) { - //-- If user allows scripting of plugins by untrusted scripts, - // and the target object is a plugin, allow the access anyway. - if(aObj) - { - nsresult rv; - nsCOMPtr plugin = do_QueryInterface(aObj, &rv); - if (NS_SUCCEEDED(rv)) - { - PRBool allow = PR_FALSE; - //XXX May want to store the value of the pref in a local, - // this will help performance when dealing with plugins. - rv = mPrefs->GetBoolPref("security.xpconnect.plugin.unrestricted", &allow); - if (NS_SUCCEEDED(rv) && allow) - return NS_OK; - } - } - return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED; - } - return NS_OK; -} - -struct nsDomainEntry { - nsDomainEntry(const char *anOrigin, const char *aPolicy, - int aPolicyLength) - : mNext(nsnull), mOrigin(anOrigin), mPolicy(aPolicy, aPolicyLength) - { } - PRBool Matches(const char *anOrigin) { - int len = nsCRT::strlen(anOrigin); - int thisLen = mOrigin.Length(); - if (len < thisLen) - return PR_FALSE; - if (mOrigin.RFindChar(':', PR_FALSE, thisLen-1, 1) != -1) - //-- Policy applies to all URLs of this scheme, compare scheme only - return mOrigin.EqualsWithConversion(anOrigin, PR_TRUE, thisLen); - - //-- Policy applies to a particular host; compare scheme://host.domain - if (!mOrigin.Equals(anOrigin + (len - thisLen))) - return PR_FALSE; - if (len == thisLen) - return PR_TRUE; - char charBefore = anOrigin[len-thisLen-1]; - return (charBefore == '.' || charBefore == ':' || charBefore == '/'); - } - nsDomainEntry *mNext; - nsCString mOrigin; - nsCString mPolicy; -}; - -NS_IMETHODIMP -nsScriptSecurityManager::GetPrefName(nsIPrincipal *principal, - nsDOMProp domProp, nsCString &result) -{ - static const char *defaultStr = "default"; - result = "capability.policy."; - if (!GetBit(hasDomainPolicyVector, domProp)) { - result += defaultStr; - } else { - PRBool equals = PR_TRUE; - if (principal && NS_FAILED(principal->Equals(mSystemPrincipal, &equals))) - return NS_ERROR_FAILURE; - if (equals) { - result += defaultStr; - } else { - nsCOMPtr codebase = do_QueryInterface(principal); - if (!codebase) - return NS_ERROR_FAILURE; - nsresult rv; - nsXPIDLCString origin; - if (NS_FAILED(rv = codebase->GetOrigin(getter_Copies(origin)))) - return rv; - nsCString *policy = nsnull; - if (mOriginToPolicyMap) { - const char *s = origin; - const char *nextToLastDot = nsnull; - const char *lastDot = nsnull; - const char *colon = nsnull; - const char *p = s; - while (*p) { - if (*p == '.') { - nextToLastDot = lastDot; - lastDot = p; - } - if (!colon && *p == ':') - colon = p; - p++; - } - nsCStringKey key(nextToLastDot ? nextToLastDot+1 : s); - nsDomainEntry *de = (nsDomainEntry *) mOriginToPolicyMap->Get(&key); - if (!de) - { - nsCAutoString scheme(s, colon-s+1); - nsCStringKey schemeKey(scheme); - de = (nsDomainEntry *) mOriginToPolicyMap->Get(&schemeKey); - } - while (de) { - if (de->Matches(s)) { - policy = &de->mPolicy; - break; - } - de = de->mNext; - } - } - if (policy) - result += *policy; - else - result += defaultStr; - } - } - result += '.'; - result += domPropNames[domProp]; - return NS_OK; -} - -NS_IMETHODIMP -nsScriptSecurityManager::SavePrincipal(nsIPrincipal* aToSave) -{ - NS_ASSERTION(mSecurityPrefs, "nsScriptSecurityManager::mSecurityPrefs not initialized"); - nsresult rv; - nsCOMPtr persistent = aToSave; - nsCOMPtr aggregate = do_QueryInterface(aToSave, &rv); - if (NS_SUCCEEDED(rv)) - if (NS_FAILED(aggregate->GetPrimaryChild(getter_AddRefs(persistent)))) - return NS_ERROR_FAILURE; - - //-- Save to mPrincipals - if (!mPrincipals) - { - mPrincipals = new nsSupportsHashtable(31); - if (!mPrincipals) - return NS_ERROR_OUT_OF_MEMORY; - } - nsIPrincipalKey key(persistent); - mPrincipals->Put(&key, persistent); - - //-- Save to prefs - nsXPIDLCString idPrefName; - nsXPIDLCString id; - nsXPIDLCString grantedList; - nsXPIDLCString deniedList; - rv = persistent->GetPreferences(getter_Copies(idPrefName), - getter_Copies(id), - getter_Copies(grantedList), - getter_Copies(deniedList)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - nsXPIDLCString grantedPrefName; - nsXPIDLCString deniedPrefName; - rv = PrincipalPrefNames( idPrefName, - getter_Copies(grantedPrefName), - getter_Copies(deniedPrefName) ); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - mIsWritingPrefs = PR_TRUE; - if (grantedList) - mSecurityPrefs->SecuritySetCharPref(grantedPrefName, grantedList); - else - mSecurityPrefs->SecurityClearUserPref(grantedPrefName); - - if (deniedList) - mSecurityPrefs->SecuritySetCharPref(deniedPrefName, deniedList); - else - mSecurityPrefs->SecurityClearUserPref(deniedPrefName); - - if (grantedList || deniedList) - mSecurityPrefs->SecuritySetCharPref(idPrefName, id); - else - mSecurityPrefs->SecurityClearUserPref(idPrefName); - - mIsWritingPrefs = PR_FALSE; - return mPrefs->SavePrefFile(nsnull); -} - -static nsDOMProp -findDomProp(const char *propName, int n) -{ - int hi = sizeof(domPropNames)/sizeof(domPropNames[0]) - 1; - int lo = 0; - do { - int mid = (hi + lo) / 2; - int cmp = PL_strncmp(propName, domPropNames[mid], n); - if (cmp == 0) { - if (domPropNames[mid][n] == '\0') - return (nsDOMProp) mid; - cmp = -1; - } - if (cmp < 0) - hi = mid - 1; - else - lo = mid + 1; - } while (hi > lo); - if (PL_strncmp(propName, domPropNames[lo], n) == 0 && - domPropNames[lo][n] == '\0') - { - return (nsDOMProp) lo; - } - return NS_DOM_PROP_MAX; -} +const char* nsScriptSecurityManager::sJSEnabledPrefName = "javascript.enabled"; +const char* nsScriptSecurityManager::sJSMailEnabledPrefName = "javascript.allow.mailnews"; +const char* nsScriptSecurityManager::sPrincipalPrefix = "capability.principal"; PR_STATIC_CALLBACK(PRBool) DeleteEntry(nsHashKey *aKey, void *aData, void* closure) { nsDomainEntry *entry = (nsDomainEntry *) aData; - do { + do + { nsDomainEntry *next = entry->mNext; delete entry; entry = next; @@ -2060,104 +1864,125 @@ DeleteEntry(nsHashKey *aKey, void *aData, void* closure) return PR_TRUE; } -void -nsScriptSecurityManager::EnumeratePolicyCallback(const char *prefName, - void *data) +nsresult +nsScriptSecurityManager::InitPolicies(PRUint32 aPrefCount, const char** aPrefNames) { - if (!prefName || !*prefName) - return; - - nsScriptSecurityManager *mgr = (nsScriptSecurityManager *) data; - unsigned count = 0; - const char *dots[5]; - const char *p; - for (p=prefName; *p; p++) { - if (*p == '.') { - dots[count++] = p; - if (count == sizeof(dots)/sizeof(dots[0])) - break; - } - } - if (count < sizeof(dots)/sizeof(dots[0])) - dots[count] = p; - if (count < 3) - return; - const char *policyName = dots[1] + 1; - int policyLength = dots[2] - policyName; - PRBool isDefault = PL_strncmp("default", policyName, policyLength) == 0; - if (!isDefault && count == 3) { - // capability.policy..sites - const char *sitesName = dots[2] + 1; - int sitesLength = dots[3] - sitesName; - if (PL_strncmp("sites", sitesName, sitesLength) == 0) { - if (!mgr->mOriginToPolicyMap) { - mgr->mOriginToPolicyMap = - new nsObjectHashtable(nsnull, nsnull, DeleteEntry, nsnull); - if (!mgr->mOriginToPolicyMap) - return; + for (PRUint32 c = 0; c < aPrefCount; c++) + { + unsigned count = 0; + const char *dots[5]; + const char *p; + for (p=aPrefNames[c]; *p; p++) + { + if (*p == '.') + { + dots[count++] = p; + if (count == sizeof(dots)/sizeof(dots[0])) + break; } - char *s; - if (NS_FAILED(mgr->mSecurityPrefs->SecurityGetCharPref(prefName, &s))) - return; - char *q=s; - char *r=s; - char *lastDot = nsnull; - char *nextToLastDot = nsnull; - PRBool working = PR_TRUE; - while (working) { - if (*r == ' ' || *r == '\0') { - working = (*r != '\0'); - *r = '\0'; - nsCStringKey key(nextToLastDot ? nextToLastDot+1 : q); - nsDomainEntry *value = new nsDomainEntry(q, policyName, - policyLength); - if (!value) - break; - nsDomainEntry *de = (nsDomainEntry *) - mgr->mOriginToPolicyMap->Get(&key); - if (!de) { - mgr->mOriginToPolicyMap->Put(&key, value); - } else { - if (de->Matches(q)) { - value->mNext = de; - mgr->mOriginToPolicyMap->Put(&key, value); - } else { - while (de->mNext) { - if (de->mNext->Matches(q)) { - value->mNext = de->mNext; - de->mNext = value; - break; - } - de = de->mNext; + } + if (count < sizeof(dots)/sizeof(dots[0])) + dots[count] = p; + if (count < 3) + continue; + const char *policyName = dots[1] + 1; + int policyLength = dots[2] - policyName; + PRBool isDefault = PL_strncmp("default", policyName, policyLength) == 0; + if (!isDefault && count == 3) + { + // capability.policy..sites + const char *sitesName = dots[2] + 1; + int sitesLength = dots[3] - sitesName; + if (PL_strncmp("sites", sitesName, sitesLength) == 0) + { + if (!mOriginToPolicyMap) + { + mOriginToPolicyMap = + new nsObjectHashtable(nsnull, nsnull, DeleteEntry, nsnull); + if (!mOriginToPolicyMap) + return NS_ERROR_OUT_OF_MEMORY; + } + char *s; + if (NS_FAILED(mSecurityPrefs->SecurityGetCharPref(aPrefNames[c], &s))) + return NS_ERROR_FAILURE; + char *q=s; + char *r=s; + char *lastDot = nsnull; + char *nextToLastDot = nsnull; + PRBool working = PR_TRUE; + while (working) + { + if (*r == ' ' || *r == '\0') + { + working = (*r != '\0'); + *r = '\0'; + nsCStringKey key(nextToLastDot ? nextToLastDot+1 : q); + nsDomainEntry *value = new nsDomainEntry(q, policyName, + policyLength); + if (!value) + break; + nsDomainEntry *de = (nsDomainEntry *) + mOriginToPolicyMap->Get(&key); + if (!de) + mOriginToPolicyMap->Put(&key, value); + else + { + if (de->Matches(q)) + { + value->mNext = de; + mOriginToPolicyMap->Put(&key, value); } - if (!de->mNext) { - de->mNext = value; + else + { + while (de->mNext) + { + if (de->mNext->Matches(q)) + { + value->mNext = de->mNext; + de->mNext = value; + break; + } + de = de->mNext; + } + if (!de->mNext) + de->mNext = value; } } + q = r + 1; + lastDot = nextToLastDot = nsnull; } - q = r + 1; - lastDot = nextToLastDot = nsnull; - } else if (*r == '.') { - nextToLastDot = lastDot; - lastDot = r; + else if (*r == '.') + { + nextToLastDot = lastDot; + lastDot = r; + } + r++; } - r++; + PR_Free(s); } - PR_Free(s); - return; } - } else if (count >= 4) { - // capability.policy...[.read|.write] - const char *domPropName = dots[2] + 1; - int domPropLength = dots[4] - domPropName; - nsDOMProp domProp = findDomProp(domPropName, domPropLength); - if (domProp < NS_DOM_PROP_MAX) { - if (!isDefault) - SetBit(mgr->hasDomainPolicyVector, domProp); - return; + else if (count > 3) + { // capability.policy...[.(get|set)] + // Store the class name so we know this class has a policy set on it + const char* className = dots[2] + 1; + PRInt32 classNameLen = dots[3] - className; + char* classNameNullTerm = PL_strndup(className, classNameLen); + if (!classNameNullTerm) + return NS_ERROR_OUT_OF_MEMORY; + nsCStringKey classNameKey(classNameNullTerm); + if (!(mClassPolicies)) + mClassPolicies = new nsHashtable(31); + // We don't actually have to store the class name as data in the hashtable, + // since all we check for is whether the key exists. + void* classPolicy = mClassPolicies->Get(&classNameKey); + if (isDefault && !classPolicy) + mClassPolicies->Put(&classNameKey, (void*)CLASS_POLICY_DEFAULT); + else if (!isDefault && classPolicy != (void*)CLASS_POLICY_SITE) + mClassPolicies->Put(&classNameKey, (void*)CLASS_POLICY_SITE); + PR_Free(classNameNullTerm); } - } - NS_ASSERTION(PR_FALSE, "DOM property name invalid or not found"); + } + return NS_OK; } nsresult @@ -2190,16 +2015,8 @@ nsScriptSecurityManager::PrincipalPrefNames(const char* pref, return NS_OK; } -struct EnumeratePrincipalsInfo { - // this struct doesn't own these objects; consider them parameters on - // the stack - nsSupportsHashtable *ht; - nsISecurityPref *prefs; -}; - -void -nsScriptSecurityManager::EnumeratePrincipalsCallback(const char *prefName, - void *voidParam) +nsresult +nsScriptSecurityManager::InitPrincipals(PRUint32 aPrefCount, const char** aPrefNames) { /* This is the principal preference syntax: * capability.principal.[codebase|certificate]..[id|granted|denied] @@ -2209,174 +2026,142 @@ nsScriptSecurityManager::EnumeratePrincipalsCallback(const char *prefName, * user_pref("capability.principal.certificate.p1.denied","Capability3"); */ - EnumeratePrincipalsInfo *info = (EnumeratePrincipalsInfo *) voidParam; - static const char idName[] = ".id"; - PRInt32 prefNameLen = PL_strlen(prefName) - (sizeof(idName)-1); - if (PL_strcasecmp(prefName + prefNameLen, idName) != 0) - return; - - char* id; - if (NS_FAILED(info->prefs->SecurityGetCharPref(prefName, &id))) - return; - - nsXPIDLCString grantedPrefName; - nsXPIDLCString deniedPrefName; - if (NS_FAILED(PrincipalPrefNames( prefName, - getter_Copies(grantedPrefName), - getter_Copies(deniedPrefName) ))) - return; - - char* grantedList = nsnull; - info->prefs->SecurityGetCharPref(grantedPrefName, &grantedList); - char* deniedList = nsnull; - info->prefs->SecurityGetCharPref(deniedPrefName, &deniedList); - - //-- Delete prefs if their value is the empty string - if ((!id || id[0] == '\0') || - ((!grantedList || grantedList[0] == '\0') && (!deniedList || deniedList[0] == '\0'))) + static const char idSuffix[] = ".id"; + for (PRUint32 c = 0; c < aPrefCount; c++) { - info->prefs->SecurityClearUserPref(prefName); - info->prefs->SecurityClearUserPref(grantedPrefName); - info->prefs->SecurityClearUserPref(deniedPrefName); - return; - } + PRInt32 prefNameLen = PL_strlen(aPrefNames[c]) - (sizeof(idSuffix)-1); + if (PL_strcasecmp(aPrefNames[c] + prefNameLen, idSuffix) != 0) + continue; - //-- Create a principal based on the prefs - static const char certificateName[] = "capability.principal.certificate"; - static const char codebaseName[] = "capability.principal.codebase"; - nsCOMPtr principal; - if (PL_strncmp(prefName, certificateName, - sizeof(certificateName)-1) == 0) - { - nsCertificatePrincipal *certificate = new nsCertificatePrincipal(); - if (certificate) { - NS_ADDREF(certificate); - if (NS_SUCCEEDED(certificate->InitFromPersistent(prefName, id, - grantedList, deniedList))) - principal = do_QueryInterface((nsBasePrincipal*)certificate); - NS_RELEASE(certificate); + char* id; + if (NS_FAILED(mSecurityPrefs->SecurityGetCharPref(aPrefNames[c], &id))) + return NS_ERROR_FAILURE; + + nsXPIDLCString grantedPrefName; + nsXPIDLCString deniedPrefName; + nsresult rv = PrincipalPrefNames(aPrefNames[c], + getter_Copies(grantedPrefName), + getter_Copies(deniedPrefName)); + if (rv == NS_ERROR_OUT_OF_MEMORY) + return rv; + else if (NS_FAILED(rv)) + continue; + + char* grantedList = nsnull; + mSecurityPrefs->SecurityGetCharPref(grantedPrefName, &grantedList); + char* deniedList = nsnull; + mSecurityPrefs->SecurityGetCharPref(deniedPrefName, &deniedList); + + //-- Delete prefs if their value is the empty string + if ((!id || id[0] == '\0') || + ((!grantedList || grantedList[0] == '\0') && (!deniedList || deniedList[0] == '\0'))) + { + mSecurityPrefs->SecurityClearUserPref(aPrefNames[c]); + mSecurityPrefs->SecurityClearUserPref(grantedPrefName); + mSecurityPrefs->SecurityClearUserPref(deniedPrefName); + PR_FREEIF(grantedList); + PR_FREEIF(deniedList); + continue; } - } else if(PL_strncmp(prefName, codebaseName, - sizeof(codebaseName)-1) == 0) - { - nsCodebasePrincipal *codebase = new nsCodebasePrincipal(); - if (codebase) { - NS_ADDREF(codebase); - if (NS_SUCCEEDED(codebase->InitFromPersistent(prefName, id, - grantedList, deniedList))) - principal = do_QueryInterface((nsBasePrincipal*)codebase); - NS_RELEASE(codebase); + + //-- Create a principal based on the prefs + static const char certificateName[] = "capability.principal.certificate"; + static const char codebaseName[] = "capability.principal.codebase"; + nsCOMPtr principal; + if (PL_strncmp(aPrefNames[c], certificateName, + sizeof(certificateName)-1) == 0) + { + nsCertificatePrincipal *certificate = new nsCertificatePrincipal(); + if (certificate) { + NS_ADDREF(certificate); + if (NS_SUCCEEDED(certificate->InitFromPersistent(aPrefNames[c], id, + grantedList, deniedList))) + principal = do_QueryInterface((nsBasePrincipal*)certificate); + NS_RELEASE(certificate); + } + } else if(PL_strncmp(aPrefNames[c], codebaseName, + sizeof(codebaseName)-1) == 0) + { + nsCodebasePrincipal *codebase = new nsCodebasePrincipal(); + if (codebase) { + NS_ADDREF(codebase); + if (NS_SUCCEEDED(codebase->InitFromPersistent(aPrefNames[c], id, + grantedList, deniedList))) + principal = do_QueryInterface((nsBasePrincipal*)codebase); + NS_RELEASE(codebase); + } } - } - PR_FREEIF(grantedList); - PR_FREEIF(deniedList); + PR_FREEIF(grantedList); + PR_FREEIF(deniedList); - if (principal) { - nsIPrincipalKey key(principal); - info->ht->Put(&key, principal); + if (principal) + { + if (!mPrincipals) + { + mPrincipals = new nsSupportsHashtable(31); + if (!mPrincipals) + return NS_ERROR_OUT_OF_MEMORY; + } + nsIPrincipalKey key(principal); + mPrincipals->Put(&key, principal); + } } + return NS_OK; } -static const char jsEnabledPrefName[] = "javascript.enabled"; -static const char jsMailEnabledPrefName[] = "javascript.allow.mailnews"; -int PR_CALLBACK -nsScriptSecurityManager::JSEnabledPrefChanged(const char *pref, void *data) +inline void +nsScriptSecurityManager::JSEnabledPrefChanged() { - nsScriptSecurityManager *secMgr = (nsScriptSecurityManager *) data; - - if (NS_FAILED(secMgr->mPrefs->GetBoolPref(jsEnabledPrefName, - &secMgr->mIsJavaScriptEnabled))) - { + if (NS_FAILED(mPrefs->GetBoolPref(sJSEnabledPrefName, + &mIsJavaScriptEnabled))) // Default to enabled. - secMgr->mIsJavaScriptEnabled = PR_TRUE; - } + mIsJavaScriptEnabled = PR_TRUE; - if (NS_FAILED(secMgr->mPrefs->GetBoolPref(jsMailEnabledPrefName, - &secMgr->mIsMailJavaScriptEnabled))) - { + if (NS_FAILED(mPrefs->GetBoolPref(sJSMailEnabledPrefName, + &mIsMailJavaScriptEnabled))) // Default to enabled. - secMgr->mIsMailJavaScriptEnabled = PR_TRUE; - } - - return 0; + mIsMailJavaScriptEnabled = PR_TRUE; } -int PR_CALLBACK -nsScriptSecurityManager::PrincipalPrefChanged(const char *pref, void *data) -{ - nsScriptSecurityManager *secMgr = (nsScriptSecurityManager *) data; - if (secMgr->mIsWritingPrefs) - return 0; - - char* lastDot = PL_strrchr(pref, '.'); - if (!lastDot) return NS_ERROR_FAILURE; - PRInt32 prefLen = lastDot - pref + 1; - - static const char id[] = "id"; - char* idPref = (char*)PR_MALLOC(prefLen + sizeof(id)); - if (!idPref) return NS_ERROR_OUT_OF_MEMORY; - PL_strncpy(idPref, pref, prefLen); - PL_strcpy(idPref + prefLen, id); - - EnumeratePrincipalsInfo info; - info.ht = secMgr->mPrincipals; - info.prefs = secMgr->mSecurityPrefs; - EnumeratePrincipalsCallback(idPref, &info); - PR_FREEIF(idPref); - return 0; -} - -NS_IMETHODIMP +nsresult nsScriptSecurityManager::InitPrefs() { - // The DOM property enums and names better be in sync - NS_ASSERTION(NS_DOM_PROP_MAX == sizeof(domPropNames)/sizeof(domPropNames[0]), - "mismatch in property name count"); - - // The DOM property names had better be sorted for binary search to work -#ifdef DEBUG - for (unsigned i=1; i < sizeof(domPropNames)/sizeof(domPropNames[0]); i++) { - NS_ASSERTION(strcmp(domPropNames[i-1], domPropNames[i]) < 0, - "DOM properties are not properly sorted"); - } -#endif - nsresult rv; - NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; - mPrefs = prefs; + mPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + rv = mPrefService->GetBranch(nsnull, getter_AddRefs(mPrefs)); + NS_ENSURE_SUCCESS(rv, rv); + mSecurityPrefs = do_QueryInterface(mPrefs, &rv); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr oldPrefService = do_GetService(NS_PREF_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); - mSecurityPrefs = do_QueryInterface(prefs, &rv); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; + // Set the initial value of the "javascript.enabled" prefs + JSEnabledPrefChanged(); + // set observer callbacks in case the value of the pref changes + oldPrefService->AddObserver(sJSEnabledPrefName, this); + oldPrefService->AddObserver(sJSMailEnabledPrefName, this); - // Set the initial value of the "javascript.enabled" pref - JSEnabledPrefChanged(jsEnabledPrefName, this); + PRUint32 prefCount; + char** prefNames; - // set callbacks in case the value of the pref changes - prefs->RegisterCallback(jsEnabledPrefName, JSEnabledPrefChanged, this); - prefs->RegisterCallback(jsMailEnabledPrefName, JSEnabledPrefChanged, this); + //-- Initialize the policy database from prefs + rv = mPrefs->GetChildList("capability.policy", &prefCount, &prefNames); + NS_ENSURE_SUCCESS(rv, rv); + rv = InitPolicies(prefCount, (const char**)prefNames); + NS_ENSURE_SUCCESS(rv, rv); + NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, prefNames); - mPrefs->EnumerateChildren("capability.policy", - nsScriptSecurityManager::EnumeratePolicyCallback, - (void *) this); - - if (!mPrincipals) { - mPrincipals = new nsSupportsHashtable(31); - if (!mPrincipals) - return NS_ERROR_OUT_OF_MEMORY; - } - EnumeratePrincipalsInfo info; - info.ht = mPrincipals; - info.prefs = mSecurityPrefs; - - mPrefs->EnumerateChildren("capability.principal", - nsScriptSecurityManager::EnumeratePrincipalsCallback, - (void *) &info); - - mPrefs->RegisterCallback("capability.principal", PrincipalPrefChanged, this); + //-- Initialize the principals database from prefs + rv = mPrefs->GetChildList(sPrincipalPrefix, &prefCount, &prefNames); + NS_ENSURE_SUCCESS(rv, rv); + rv = InitPrincipals(prefCount, (const char**)prefNames); + NS_ENSURE_SUCCESS(rv, rv); + NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, prefNames); + + //-- Set a callback for principal changes + oldPrefService->AddObserver(sPrincipalPrefix, this); return NS_OK; } diff --git a/caps/src/nsSecurityManagerFactory.cpp b/caps/src/nsSecurityManagerFactory.cpp index 4007f3ef972..e5cd1a35643 100644 --- a/caps/src/nsSecurityManagerFactory.cpp +++ b/caps/src/nsSecurityManagerFactory.cpp @@ -28,8 +28,295 @@ #include "nsScriptSecurityManager.h" #include "nsIPrincipal.h" #include "nsCodebasePrincipal.h" +#include "nsIScriptNameSpaceManager.h" +#include "nsIScriptExternalNameSet.h" +#include "nsIScriptContext.h" +#include "nsICategoryManager.h" +#include "nsXPIDLString.h" +#include "nsCOMPtr.h" + +/////////////////////// +// nsSecurityNameSet // +/////////////////////// + +#define NS_SECURITYNAMESET_CID \ + { 0x7c02eadc, 0x76, 0x4d03, \ + { 0x99, 0x8d, 0x80, 0xd7, 0x79, 0xc4, 0x85, 0x89 } } +#define NS_SECURITYNAMESET_CONTRACTID "@mozilla.org/security/script/nameset;1" + +class nsSecurityNameSet : public nsIScriptExternalNameSet +{ +public: + nsSecurityNameSet(); + virtual ~nsSecurityNameSet(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD InitializeNameSet(nsIScriptContext* aScriptContext); +}; + +nsSecurityNameSet::nsSecurityNameSet() +{ + NS_INIT_REFCNT(); +} + +nsSecurityNameSet::~nsSecurityNameSet() +{ +} + +NS_IMPL_ISUPPORTS(nsSecurityNameSet, NS_GET_IID(nsIScriptExternalNameSet)); + +static char * +getStringArgument(JSContext *cx, JSObject *obj, PRUint16 argNum, uintN argc, jsval *argv) +{ + if (argc <= argNum || !JSVAL_IS_STRING(argv[argNum])) { + JS_ReportError(cx, "String argument expected"); + return nsnull; + } + /* + * We don't want to use JS_ValueToString because we want to be able + * to have an object to represent a target in subsequent versions. + */ + JSString *str = JSVAL_TO_STRING(argv[argNum]); + if (!str) + return nsnull; + + return JS_GetStringBytes(str); +} + +PR_STATIC_CALLBACK(JSBool) +netscape_security_isPrivilegeEnabled(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + JSBool result = JS_FALSE; + char *cap = getStringArgument(cx, obj, 0, argc, argv); + if (cap) { + nsresult rv; + NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, + NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + + + + // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); + + + + rv = securityManager->IsCapabilityEnabled(cap, &result); + if (NS_FAILED(rv)) + result = JS_FALSE; + } + } + *rval = BOOLEAN_TO_JSVAL(result); + return JS_TRUE; +} + + +PR_STATIC_CALLBACK(JSBool) +netscape_security_enablePrivilege(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + char *cap = getStringArgument(cx, obj, 0, argc, argv); + if (!cap) + return JS_FALSE; + nsresult rv; + NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, + NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return JS_FALSE; + + + + + // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); + + + + + if (NS_FAILED(securityManager->EnableCapability(cap))) + return JS_FALSE; + return JS_TRUE; +} + +PR_STATIC_CALLBACK(JSBool) +netscape_security_disablePrivilege(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + char *cap = getStringArgument(cx, obj, 0, argc, argv); + if (!cap) + return JS_FALSE; + nsresult rv; + NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, + NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return JS_FALSE; + + + + + // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); + + + + + + if (NS_FAILED(securityManager->DisableCapability(cap))) + return JS_FALSE; + return JS_TRUE; +} + +PR_STATIC_CALLBACK(JSBool) +netscape_security_revertPrivilege(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + char *cap = getStringArgument(cx, obj, 0, argc, argv); + if (!cap) + return JS_FALSE; + nsresult rv; + NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, + NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return JS_FALSE; + + + + // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); + + + + + if (NS_FAILED(securityManager->RevertCapability(cap))) + return JS_FALSE; + return JS_TRUE; +} + +PR_STATIC_CALLBACK(JSBool) +netscape_security_setCanEnablePrivilege(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + if (argc < 2) return JS_FALSE; + char *principalID = getStringArgument(cx, obj, 0, argc, argv); + char *cap = getStringArgument(cx, obj, 1, argc, argv); + if (!principalID || !cap) + return JS_FALSE; + nsresult rv; + NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, + NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return JS_FALSE; + + + + + // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); + + + + + if (NS_FAILED(securityManager->SetCanEnableCapability(principalID, cap, + nsIPrincipal::ENABLE_GRANTED))) + return JS_FALSE; + return JS_TRUE; +} + +PR_STATIC_CALLBACK(JSBool) +netscape_security_invalidate(JSContext *cx, JSObject *obj, uintN argc, + jsval *argv, jsval *rval) +{ + char *principalID = getStringArgument(cx, obj, 0, argc, argv); + if (!principalID) + return JS_FALSE; + nsresult rv; + NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, + NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return JS_FALSE; + + + + + // NS_ASSERTION(cx == GetCurrentContext(), "unexpected context"); + + + + + if (NS_FAILED(securityManager->SetCanEnableCapability(principalID, + nsBasePrincipal::Invalid, + nsIPrincipal::ENABLE_GRANTED))) + return JS_FALSE; + return JS_TRUE; +} + +static JSFunctionSpec PrivilegeManager_static_methods[] = { + { "isPrivilegeEnabled", netscape_security_isPrivilegeEnabled, 1}, + { "enablePrivilege", netscape_security_enablePrivilege, 1}, + { "disablePrivilege", netscape_security_disablePrivilege, 1}, + { "revertPrivilege", netscape_security_revertPrivilege, 1}, + //-- System Cert Functions + { "setCanEnablePrivilege", netscape_security_setCanEnablePrivilege, 2}, + { "invalidate", netscape_security_invalidate, 1}, + {0} +}; + +/* + * "Steal" calls to netscape.security.PrivilegeManager.enablePrivilege, + * et. al. so that code that worked with 4.0 can still work. + */ +NS_IMETHODIMP +nsSecurityNameSet::InitializeNameSet(nsIScriptContext* aScriptContext) +{ + JSContext *cx = (JSContext *) aScriptContext->GetNativeContext(); + JSObject *global = JS_GetGlobalObject(cx); + + /* + * Find Object.prototype's class by walking up the global object's + * prototype chain. + */ + JSObject *obj = global; + JSObject *proto; + while ((proto = JS_GetPrototype(cx, obj)) != nsnull) + obj = proto; + JSClass *objectClass = JS_GetClass(cx, obj); + + jsval v; + if (!JS_GetProperty(cx, global, "netscape", &v)) + return NS_ERROR_FAILURE; + JSObject *securityObj; + if (JSVAL_IS_OBJECT(v)) { + /* + * "netscape" property of window object exists; must be LiveConnect + * package. Get the "security" property. + */ + obj = JSVAL_TO_OBJECT(v); + if (!JS_GetProperty(cx, obj, "security", &v) || !JSVAL_IS_OBJECT(v)) + return NS_ERROR_FAILURE; + securityObj = JSVAL_TO_OBJECT(v); + } else { + /* define netscape.security object */ + obj = JS_DefineObject(cx, global, "netscape", objectClass, nsnull, 0); + if (obj == nsnull) + return NS_ERROR_FAILURE; + securityObj = JS_DefineObject(cx, obj, "security", objectClass, + nsnull, 0); + if (securityObj == nsnull) + return NS_ERROR_FAILURE; + } + + /* Define PrivilegeManager object with the necessary "static" methods. */ + obj = JS_DefineObject(cx, securityObj, "PrivilegeManager", objectClass, + nsnull, 0); + if (obj == nsnull) + return NS_ERROR_FAILURE; + + return JS_DefineFunctions(cx, obj, PrivilegeManager_static_methods) + ? NS_OK + : NS_ERROR_FAILURE; +} + + NS_GENERIC_FACTORY_CONSTRUCTOR(nsCodebasePrincipal) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecurityNameSet) static NS_IMETHODIMP Construct_nsIScriptSecurityManager(nsISupports *aOuter, REFNSIID aIID, @@ -48,18 +335,50 @@ Construct_nsIScriptSecurityManager(nsISupports *aOuter, REFNSIID aIID, return NS_OK; } +static NS_METHOD +RegisterSecurityNameSet(nsIComponentManager *aCompMgr, + nsIFile *aPath, + const char *registryLocation, + const char *componentType, + const nsModuleComponentInfo *info) +{ + nsresult rv = NS_OK; + + nsCOMPtr catman = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + + if (NS_FAILED(rv)) + return rv; + + nsXPIDLCString previous; + rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_STATIC_NAMESET_CATEGORY, + "PrivilegeManager", + NS_SECURITYNAMESET_CONTRACTID, + PR_TRUE, PR_TRUE, getter_Copies(previous)); + NS_ENSURE_SUCCESS(rv, rv); + + return rv; +} + static nsModuleComponentInfo components[] = { { NS_SCRIPTSECURITYMANAGER_CLASSNAME, NS_SCRIPTSECURITYMANAGER_CID, NS_SCRIPTSECURITYMANAGER_CONTRACTID, - Construct_nsIScriptSecurityManager + Construct_nsIScriptSecurityManager, + RegisterSecurityNameSet }, { NS_CODEBASEPRINCIPAL_CLASSNAME, NS_CODEBASEPRINCIPAL_CID, NS_CODEBASEPRINCIPAL_CONTRACTID, nsCodebasePrincipalConstructor + }, + + { "Security Script Name Set", + NS_SECURITYNAMESET_CID, + NS_SECURITYNAMESET_CONTRACTID, + nsSecurityNameSetConstructor } }; diff --git a/content/base/public/MANIFEST b/content/base/public/MANIFEST index 2ee420ae713..56a3dd9f2e8 100644 --- a/content/base/public/MANIFEST +++ b/content/base/public/MANIFEST @@ -2,6 +2,7 @@ # This is a list of local files which get copied to the mozilla:dist:content directory # nsContentPolicyUtils.h +nsContentUtils.h nsIAnonymousContent.h nsIContent.h nsIContentIterator.h @@ -25,4 +26,3 @@ nsIStyleRuleSupplier.h nsIStyleSheet.h nsIStyleSheetLinkingElement.h nsITextContent.h - diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index a0f445d33e1..2cc61f5e04d 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -32,7 +32,7 @@ * file under either the NPL or the GPL. */ -/* A namespace class for static layout utilities. */ +/* A namespace class for static content utilities. */ #ifndef nsContentUtils_h___ #define nsContentUtils_h___ @@ -40,13 +40,24 @@ #include "nslayout.h" #include "jspubtd.h" #include "nsAReadableString.h" +#include "nsIDOMScriptObjectFactory.h" class nsIScriptContext; class nsIScriptGlobalObject; +class nsIXPConnect; +class nsIContent; +class nsIDocument; + class nsContentUtils { public: + static nsresult Init(); + + static nsresult ReparentContentWrapper(nsIContent *aContent, + nsIContent *aNewParent, + nsIDocument *aNewDocument, + nsIDocument *aOldDocument); // These are copied from nsJSUtils.h @@ -70,6 +81,51 @@ public: PRUint32 aLength); static PRUint32 CopyNewlineNormalizedUnicodeTo(nsReadingIterator& aSrcStart, const nsReadingIterator& aSrcEnd, nsAWritableString& aDest); + + static nsISupports * + GetClassInfoInstance(nsDOMClassInfoID aID, GetDOMClassIIDsFnc aGetIIDsFptr, + const char *aName); + + static void Shutdown(); + +private: + static nsresult doReparentContentWrapper(nsIContent *aChild, + nsIDocument *aNewDocument, + nsIDocument *aOldDocument, + JSContext *cx, + JSObject *parent_obj); + + + static nsIDOMScriptObjectFactory *sDOMScriptObjectFactory; + + static nsIXPConnect *sXPConnect; }; +#define NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(_class) \ + if (aIID.Equals(NS_GET_IID(nsIClassInfo))) { \ + foundInterface = \ + nsContentUtils::GetClassInfoInstance(eDOMClassInfo_##_class##_id, \ + Get##_class##IIDs, \ + #_class); \ + NS_ENSURE_TRUE(foundInterface, NS_ERROR_OUT_OF_MEMORY); \ + \ + *aInstancePtr = foundInterface; \ + \ + return NS_OK; \ + } else + +#define NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_WITH_NAME(_class, _name) \ + if (aIID.Equals(NS_GET_IID(nsIClassInfo))) { \ + foundInterface = \ + nsContentUtils::GetClassInfoInstance(eDOMClassInfo_##_class##_id, \ + Get##_class##IIDs, \ + #_name); \ + NS_ENSURE_TRUE(foundInterface, NS_ERROR_OUT_OF_MEMORY); \ + \ + *aInstancePtr = foundInterface; \ + \ + return NS_OK; \ + } else + + #endif /* nsContentUtils_h___ */ diff --git a/content/base/public/nsIContent.h b/content/base/public/nsIContent.h index 93bd841a7c9..42580fc59cd 100644 --- a/content/base/public/nsIContent.h +++ b/content/base/public/nsIContent.h @@ -49,7 +49,7 @@ class nsINodeInfo; // is supported by all content objects. class nsIContent : public nsISupports { public: - static const nsIID& GetIID() { static nsIID iid = NS_ICONTENT_IID; return iid; } + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID) NS_IMETHOD GetDocument(nsIDocument*& aResult) const = 0; @@ -295,6 +295,22 @@ public: */ NS_IMETHOD SetBindingParent(nsIContent* aContent) = 0; NS_IMETHOD GetBindingParent(nsIContent** aContent) = 0; + + /** + * Bit-flags to pass (or'ed together) to IsContentOfType() + */ + enum { + eTEXT = 0x00000001, + eELEMENT = 0x00000002, + eHTML = 0x00000004, + eHTML_FORM_CONTROL = 0x00000008 + }; + + /** + * API for doing a quick check if a content object is of a given + * type, such as HTML, XUL, Text, ... + */ + NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags) = 0; }; // nsresult codes for GetAttribute diff --git a/content/base/public/nsIContentPolicy.idl b/content/base/public/nsIContentPolicy.idl index e6fabf55589..834aff73e9c 100644 --- a/content/base/public/nsIContentPolicy.idl +++ b/content/base/public/nsIContentPolicy.idl @@ -21,7 +21,9 @@ #include "nsISupports.idl" #include "nsIURL.idl" -#include "domstubs.idl" + +interface nsIDOMElement; + /** * Interface for content policy mechanism. Implementations of this diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index dc39eb67e1c..23a57043a87 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -61,6 +61,7 @@ class nsIDOMDocumentType; class nsIBindingManager; class nsIObserver; class nsISupportsArray; +class nsString; // IID for the nsIDocument interface #define NS_IDOCUMENT_IID \ @@ -78,7 +79,7 @@ class nsISupportsArray; // Document interface class nsIDocument : public nsISupports { public: - static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_IID; return iid; } + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID) // All documents have a memory arena associated with them which is // used for memory allocation during document creation. This call @@ -312,12 +313,6 @@ public: NS_IMETHOD StyleRuleRemoved(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule) = 0; - /** - * Finds text in content - */ - NS_IMETHOD FindNext(const nsAReadableString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound) = 0; - - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, @@ -335,6 +330,9 @@ public: NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) = 0; NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) = 0; + + NS_IMETHOD AddReference(void *aKey, nsISupports *aReference) = 0; + NS_IMETHOD RemoveReference(void *aKey, nsISupports **aOldReference) = 0; }; diff --git a/content/base/public/nsINodeInfo.h b/content/base/public/nsINodeInfo.h index e56d1a47d53..9cfd4933a18 100644 --- a/content/base/public/nsINodeInfo.h +++ b/content/base/public/nsINodeInfo.h @@ -47,7 +47,7 @@ class nsIAtom; class nsINodeInfoManager; class nsINameSpaceManager; -class nsString; +class nsIDocument; // IID for the nsINodeInfo interface @@ -191,6 +191,11 @@ public: * only by prefix from the one this is called on. */ NS_IMETHOD PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult) = 0; + + /* + * Retrieve a pointer to the document that owns this node info. + */ + NS_IMETHOD GetDocument(nsIDocument*& aDocument) = 0; }; @@ -203,7 +208,14 @@ public: * Initialize the nodeinfo manager with a namespace manager, this should * allways be done. */ - NS_IMETHOD Init(nsINameSpaceManager *aNameSpaceManager) = 0; + NS_IMETHOD Init(nsIDocument *aDocument, + nsINameSpaceManager *aNameSpaceManager) = 0; + + /* + * Release the reference to the document, this will be called when + * the document is going away. + */ + NS_IMETHOD DropDocumentReference() = 0; /* * Methods for creating nodeinfo's from atoms and/or strings. @@ -227,6 +239,12 @@ public: * Getter for the namespace manager used by this nodeinfo manager. */ NS_IMETHOD GetNamespaceManager(nsINameSpaceManager*& aNameSpaceManager) = 0; + + /* + * Retrieve a pointer to the document that owns this node info + * manager. + */ + NS_IMETHOD GetDocument(nsIDocument*& aDocument) = 0; }; extern nsresult NS_NewNodeInfoManager(nsINodeInfoManager** aResult); diff --git a/content/base/public/nsISelection.idl b/content/base/public/nsISelection.idl index 365161fd7c8..1c642cbac02 100644 --- a/content/base/public/nsISelection.idl +++ b/content/base/public/nsISelection.idl @@ -21,14 +21,11 @@ */ #include "nsISupports.idl" -#include "domstubs.idl" /* THIS IS A PUBLIC INTERFACE */ -%{C++ -class nsIDOMNode; -class nsIDOMRange; -%} +interface nsIDOMNode; +interface nsIDOMRange; /** * Interface for manipulating and querying the current selected range diff --git a/content/base/public/nsISelectionController.idl b/content/base/public/nsISelectionController.idl index 158933213a8..242f1c3e4cc 100644 --- a/content/base/public/nsISelectionController.idl +++ b/content/base/public/nsISelectionController.idl @@ -23,7 +23,6 @@ #include "nsISupports.idl" -#include "domstubs.idl" #include "nsISelection.idl" %{C++ @@ -31,9 +30,10 @@ class nsISelection; typedef short SelectionType; typedef short SelectionRegion; -class nsIDOMNode; %} +interface nsIDOMNode; + [scriptable, uuid(D2D1D179-85A7-11d3-9932-00108301233C)] interface nsISelectionController : nsISupports diff --git a/content/base/public/nsISelectionListener.idl b/content/base/public/nsISelectionListener.idl index 75fb535dfac..5c542372f1c 100644 --- a/content/base/public/nsISelectionListener.idl +++ b/content/base/public/nsISelectionListener.idl @@ -21,11 +21,8 @@ */ #include "nsISupports.idl" -#include "domstubs.idl" -%{C++ -class nsIDOMDocument; -%} +interface nsIDOMDocument; interface nsISelection; [scriptable, uuid(A6CF90E2-15B3-11d2-932E-00805F8ADD32)] diff --git a/content/base/public/nsISelectionPrivate.idl b/content/base/public/nsISelectionPrivate.idl index ec3a409de2e..14e589f4a17 100644 --- a/content/base/public/nsISelectionPrivate.idl +++ b/content/base/public/nsISelectionPrivate.idl @@ -21,15 +21,12 @@ */ #include "nsISupports.idl" -#include "domstubs.idl" #include "nsISelectionListener.idl" #include "nsIEnumerator.idl" -%{C++ -class nsIDOMNode; -class nsIDOMRange; -class nsISelectionListener; -%} +interface nsIDOMRange; +interface nsISelectionListener; + [scriptable, uuid(2d5535e2-1dd2-11b2-8e38-d53ec833adf6)] interface nsISelectionPrivate : nsISupports diff --git a/content/base/src/makefile.win b/content/base/src/makefile.win index 0c9f54498d0..b01e5c7e7a8 100644 --- a/content/base/src/makefile.win +++ b/content/base/src/makefile.win @@ -28,15 +28,15 @@ DEFINES = $(DEFINES) -DXP_NEW_SELECTION !endif CPPSRCS = \ - nsStyleContext.cpp \ - nsStyleSet.cpp \ + nsStyleContext.cpp \ + nsStyleSet.cpp \ nsCommentNode.cpp \ nsGenericElement.cpp \ nsGenericDOMDataNode.cpp \ nsGenericDOMNodeList.cpp \ nsContentList.cpp \ nsContentIterator.cpp \ - nsContentPolicy.cpp \ + nsContentPolicy.cpp \ nsDocument.cpp \ nsDocumentEncoder.cpp \ nsDocumentFragment.cpp \ @@ -57,14 +57,14 @@ CPPSRCS = \ nsHTMLContentSerializer.cpp \ nsParserUtils.cpp \ nsPlainTextSerializer.cpp \ - nsContentUtils.cpp \ + nsContentUtils.cpp \ $(NULL) MODULE=raptor CPP_OBJS= \ - .\$(OBJDIR)\nsStyleContext.obj \ - .\$(OBJDIR)\nsStyleSet.obj \ + .\$(OBJDIR)\nsStyleContext.obj \ + .\$(OBJDIR)\nsStyleSet.obj \ .\$(OBJDIR)\nsCommentNode.obj \ .\$(OBJDIR)\nsGenericDOMDataNode.obj \ .\$(OBJDIR)\nsGenericDOMNodeList.obj \ @@ -89,9 +89,9 @@ CPP_OBJS= \ .\$(OBJDIR)\nsTextNode.obj \ .\$(OBJDIR)\nsXMLContentSerializer.obj \ .\$(OBJDIR)\nsHTMLContentSerializer.obj \ - .\$(OBJDIR)\nsParserUtils.obj \ + .\$(OBJDIR)\nsParserUtils.obj \ .\$(OBJDIR)\nsPlainTextSerializer.obj \ - .\$(OBJDIR)\nsContentUtils.obj \ + .\$(OBJDIR)\nsContentUtils.obj \ $(NULL) LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ diff --git a/content/base/src/nsCommentNode.cpp b/content/base/src/nsCommentNode.cpp index 9a51676c387..8ee15ed4613 100644 --- a/content/base/src/nsCommentNode.cpp +++ b/content/base/src/nsCommentNode.cpp @@ -21,7 +21,6 @@ */ #include "nsIDOMComment.h" #include "nsGenericDOMDataNode.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIContent.h" #include "nsLayoutAtoms.h" @@ -31,9 +30,12 @@ #include "nsIEnumerator.h" #include "nsCOMPtr.h" #include "nsIDOMRange.h" +#include "nsString.h" + +#include "nsContentUtils.h" + class nsCommentNode : public nsIDOMComment, - public nsIScriptObjectOwner, public nsITextContent { public: @@ -44,16 +46,13 @@ public: NS_DECL_ISUPPORTS // nsIDOMNode - NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA(mInner) // nsIDOMCharacterData - NS_IMPL_IDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(mInner) // nsIDOMComment - // nsIScriptObjectOwner - NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(mInner) - // nsIContent //NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner) @@ -180,6 +179,10 @@ public: return mInner.SetBindingParent(aParent); } + NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags) { + return PR_FALSE; + } + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { if (!aResult) { return NS_ERROR_NULL_POINTER; @@ -241,28 +244,28 @@ nsCommentNode::~nsCommentNode() { } -NS_IMPL_ADDREF(nsCommentNode) +// XPConnect interface list for nsCommentNode +NS_CLASSINFO_MAP_BEGIN(Comment) + NS_CLASSINFO_MAP_ENTRY(nsIDOMComment) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) + NS_CLASSINFO_MAP_ENTRY(nsIDOM3Node) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsCommentNode +NS_INTERFACE_MAP_BEGIN(nsCommentNode) + NS_INTERFACE_MAP_ENTRY_DOM_DATA() + NS_INTERFACE_MAP_ENTRY(nsITextContent) + NS_INTERFACE_MAP_ENTRY(nsIDOMComment) + NS_INTERFACE_MAP_ENTRY(nsIDOMCharacterData) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Comment) +NS_INTERFACE_MAP_END + + +NS_IMPL_ADDREF(nsCommentNode) NS_IMPL_RELEASE(nsCommentNode) -NS_IMETHODIMP -nsCommentNode::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - NS_IMPL_DOM_DATA_QUERY_INTERFACE(aIID, aInstancePtr, this) - if (aIID.Equals(NS_GET_IID(nsIDOMComment))) { - nsIDOMComment* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsITextContent))) { - nsITextContent* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} NS_IMETHODIMP nsCommentNode::GetTag(nsIAtom*& aResult) const diff --git a/content/base/src/nsContentList.cpp b/content/base/src/nsContentList.cpp index a028e02973d..ae9b7378565 100644 --- a/content/base/src/nsContentList.cpp +++ b/content/base/src/nsContentList.cpp @@ -23,12 +23,12 @@ #include "nsContentList.h" #include "nsIContent.h" #include "nsIDOMNode.h" -#include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsINameSpaceManager.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsGenericElement.h" +#include "nsContentUtils.h" + #include "nsLayoutAtoms.h" #include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms @@ -36,7 +36,6 @@ #include "nsIDOMHTMLFormElement.h" nsBaseContentList::nsBaseContentList() - : mScriptObject(nsnull) { NS_INIT_REFCNT(); } @@ -48,14 +47,23 @@ nsBaseContentList::~nsBaseContentList() } +// XPConnect interface list for nsBaseContentList +NS_CLASSINFO_MAP_BEGIN(NodeList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNodeList) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsBaseContentList +NS_INTERFACE_MAP_BEGIN(nsBaseContentList) + NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsBaseContentList) NS_IMPL_RELEASE(nsBaseContentList) -NS_INTERFACE_MAP_BEGIN(nsBaseContentList) - NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList) -NS_INTERFACE_MAP_END NS_IMETHODIMP nsBaseContentList::GetLength(PRUint32* aLength) @@ -80,41 +88,6 @@ nsBaseContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) return CallQueryInterface(tmp, aReturn); } -NS_IMETHODIMP -nsBaseContentList::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - - if (!mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_FAILED(res)) { - return res; - } - - res = factory->NewScriptNodeList(aContext, - NS_STATIC_CAST(nsIDOMNodeList *, this), - global, &mScriptObject); - NS_RELEASE(factory); - } - - *aScriptObject = mScriptObject; - - NS_RELEASE(global); - - return res; -} - -NS_IMETHODIMP -nsBaseContentList::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - NS_IMETHODIMP nsBaseContentList::AppendElement(nsIContent *aContent) { @@ -387,13 +360,25 @@ nsContentList::~nsContentList() delete mData; } + +// XPConnect interface list for nsContentList +NS_CLASSINFO_MAP_BEGIN(HTMLCollection) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNodeList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLCollection) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsContentList NS_INTERFACE_MAP_BEGIN(nsContentList) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLCollection) NS_INTERFACE_MAP_END_INHERITING(nsBaseContentList) + NS_IMPL_ADDREF_INHERITED(nsContentList, nsBaseContentList) NS_IMPL_RELEASE_INHERITED(nsContentList, nsBaseContentList) + NS_IMETHODIMP nsContentList::GetLength(PRUint32* aLength) { @@ -418,10 +403,10 @@ nsContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) // Flush pending content changes Bug 4891 mDocument->FlushPendingNotifications(PR_FALSE); } - + nsISupports *element = NS_STATIC_CAST(nsISupports *, mElements.ElementAt(aIndex)); - + if (element) { result = CallQueryInterface(element, aReturn); } @@ -429,15 +414,15 @@ nsContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) *aReturn = nsnull; } } - + return result; } -NS_IMETHODIMP +NS_IMETHODIMP nsContentList::NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn) { nsresult result = CheckDocumentExistence(); - + if (NS_SUCCEEDED(result)) { if (mDocument) { mDocument->FlushPendingNotifications(PR_FALSE); // Flush pending content changes Bug 4891 @@ -466,35 +451,6 @@ nsContentList::NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn) } NS_IMETHODIMP -nsContentList::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - - if (!mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_FAILED(res)) { - return res; - } - - res = factory->NewScriptHTMLCollection(aContext, - NS_STATIC_CAST(nsIDOMNodeList *, - this), - global, &mScriptObject); - NS_RELEASE(factory); - } - - *aScriptObject = mScriptObject; - - NS_RELEASE(global); - - return res; -} - -NS_IMETHODIMP nsContentList::ContentAppended(nsIDocument *aDocument, nsIContent* aContainer, PRInt32 aNewIndexInContainer) { diff --git a/content/base/src/nsContentList.h b/content/base/src/nsContentList.h index 38f09579611..f8493b94286 100644 --- a/content/base/src/nsContentList.h +++ b/content/base/src/nsContentList.h @@ -28,7 +28,6 @@ #include "nsIDOMHTMLCollection.h" #include "nsIDOMNodeList.h" #include "nsIDocumentObserver.h" -#include "nsIScriptObjectOwner.h" typedef PRBool (*nsContentListMatchFunc)(nsIContent* aContent, nsString* aData); @@ -37,8 +36,7 @@ class nsIDocument; class nsIDOMHTMLFormElement; -class nsBaseContentList : public nsIDOMNodeList, - public nsIScriptObjectOwner +class nsBaseContentList : public nsIDOMNodeList { public: nsBaseContentList(); @@ -47,12 +45,8 @@ public: NS_DECL_ISUPPORTS // nsIDOMNodeList - NS_DECL_IDOMNODELIST + NS_DECL_NSIDOMNODELIST - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - NS_IMETHOD AppendElement(nsIContent *aContent); NS_IMETHOD RemoveElement(nsIContent *aContent); NS_IMETHOD IndexOf(nsIContent *aContent, PRInt32& aIndex); @@ -60,7 +54,6 @@ public: protected: nsVoidArray mElements; - void *mScriptObject; }; @@ -104,9 +97,6 @@ public: NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn); NS_IMETHOD NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn); - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - // nsIDocumentObserver NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; } NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; } diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 592646c34c7..d4a6d9e9f42 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -36,12 +36,37 @@ #include "jsapi.h" #include "nsCOMPtr.h" +#include "nsIServiceManager.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptContext.h" +#include "nsIDOMScriptObjectFactory.h" +#include "nsDOMCID.h" #include "nsContentUtils.h" +#include "nsIXPConnect.h" +#include "nsIContent.h" +#include "nsIDocument.h" +#include "nsINodeInfo.h" + + +nsIDOMScriptObjectFactory *nsContentUtils::sDOMScriptObjectFactory = nsnull; +nsIXPConnect *nsContentUtils::sXPConnect = nsnull; + +// static +nsresult +nsContentUtils::Init() +{ + NS_ENSURE_TRUE(!sXPConnect, NS_ERROR_ALREADY_INITIALIZED); + + nsresult rv = nsServiceManager::GetService(nsIXPConnect::GetCID(), + nsIXPConnect::GetIID(), + (nsISupports **)&sXPConnect); + NS_ENSURE_SUCCESS(rv, rv); + + return rv; +} // static -nsresult +nsresult nsContentUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj, nsIScriptGlobalObject** aNativeGlobal) @@ -70,12 +95,17 @@ nsContentUtils::GetStaticScriptGlobal(JSContext* aContext, return NS_ERROR_FAILURE; } - return supports->QueryInterface(NS_GET_IID(nsIScriptGlobalObject), - (void**) aNativeGlobal); + nsCOMPtr wrapper(do_QueryInterface(supports)); + NS_ENSURE_TRUE(wrapper, NS_ERROR_UNEXPECTED); + + nsCOMPtr native; + wrapper->GetNative(getter_AddRefs(native)); + + return CallQueryInterface(native, aNativeGlobal); } //static -nsresult +nsresult nsContentUtils::GetStaticScriptContext(JSContext* aContext, JSObject* aObj, nsIScriptContext** aScriptContext) @@ -271,3 +301,208 @@ nsContentUtils::CopyNewlineNormalizedUnicodeTo(nsReadingIterator& aSr copy_string(aSrcStart, aSrcEnd, normalizer); return normalizer.GetCharsWritten(); } + +// static +void +nsContentUtils::Shutdown() +{ + NS_IF_RELEASE(sDOMScriptObjectFactory); + NS_IF_RELEASE(sXPConnect); +} + +// static +nsISupports * +nsContentUtils::GetClassInfoInstance(nsDOMClassInfoID aID, + GetDOMClassIIDsFnc aGetIIDsFptr, + const char *aName) +{ + if (!sDOMScriptObjectFactory) { + static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, + NS_DOM_SCRIPT_OBJECT_FACTORY_CID); + + nsServiceManager::GetService(kDOMScriptObjectFactoryCID, + NS_GET_IID(nsIDOMScriptObjectFactory), + (nsISupports **)&sDOMScriptObjectFactory); + + if (!sDOMScriptObjectFactory) { + return nsnull; + } + } + + return sDOMScriptObjectFactory->GetClassInfoInstance(aID, aGetIIDsFptr, + aName); +} + +// static +nsresult +nsContentUtils::doReparentContentWrapper(nsIContent *aChild, + nsIDocument *aNewDocument, + nsIDocument *aOldDocument, + JSContext *cx, + JSObject *parent_obj) +{ + nsCOMPtr old_wrapper; + + nsresult rv; + + rv = sXPConnect->ReparentWrappedNativeIfFound(cx, ::JS_GetGlobalObject(cx), + parent_obj, aChild, + getter_AddRefs(old_wrapper)); + NS_ENSURE_SUCCESS(rv, rv); + + if (!old_wrapper) { + // If aChild isn't wrapped none of it's children are wrapped so + // there's no need to walk into aChild's children. + + return NS_OK; + } + + if (aOldDocument) { + nsCOMPtr old_ref; + + aOldDocument->RemoveReference(aChild, getter_AddRefs(old_ref)); + + if (old_ref) { + // Transfer the reference from aOldDocument to aNewDocument + + aNewDocument->AddReference(aChild, old_ref); + } + } + + JSObject *old; + + rv = old_wrapper->GetJSObject(&old); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr child; + PRInt32 count = 0, i; + + aChild->ChildCount(count); + + for (i = 0; i < count; i++) { + aChild->ChildAt(i, *getter_AddRefs(child)); + NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED); + + rv = doReparentContentWrapper(child, aNewDocument, aOldDocument, cx, old); + NS_ENSURE_SUCCESS(rv, rv); + } + + return rv; +} + +static +nsresult GetContextFromDocument(nsIDocument *aDocument, JSContext **cx) +{ + *cx = nsnull; + + nsCOMPtr sgo; + aDocument->GetScriptGlobalObject(getter_AddRefs(sgo)); + + if (!sgo) { + // No script global, no context. + + return NS_OK; + } + + nsCOMPtr scx; + sgo->GetContext(getter_AddRefs(scx)); + + if (!scx) { + // No context left in the old scope... + + return NS_OK; + } + + *cx = (JSContext *)scx->GetNativeContext(); + + return NS_OK; +} + +// static +nsresult +nsContentUtils::ReparentContentWrapper(nsIContent *aContent, + nsIContent *aNewParent, + nsIDocument *aNewDocument, + nsIDocument *aOldDocument) +{ + if (!aNewDocument || aNewDocument == aOldDocument) { + return NS_OK; + } + + nsCOMPtr old_doc(aOldDocument); + + if (!old_doc) { + nsCOMPtr ni; + + aContent->GetNodeInfo(*getter_AddRefs(ni)); + + if (ni) { + ni->GetDocument(*getter_AddRefs(old_doc)); + } + + if (!aOldDocument) { + // If we can't find our old document we don't know what our old + // scope was so there's no way to find the old wrapper + + return NS_OK; + } + } + + NS_ENSURE_TRUE(sXPConnect, NS_ERROR_NOT_INITIALIZED); + + nsCOMPtr new_parent; + + if (!aNewParent) { + nsCOMPtr root(dont_AddRef(old_doc->GetRootContent())); + + if (root.get() == aContent) { + new_parent = old_doc; + } + } else { + new_parent = aNewParent; + } + + JSContext *cx = nsnull; + + GetContextFromDocument(old_doc, &cx); + + if (!cx) { + // No JSContext left in the old scope, can't find the old wrapper + // w/o the old context. + + return NS_OK; + } + + nsCOMPtr wrapper; + + nsresult rv; + + rv = sXPConnect->GetWrappedNativeOfNativeObject(cx, ::JS_GetGlobalObject(cx), + aContent, + NS_GET_IID(nsISupports), + getter_AddRefs(wrapper)); + NS_ENSURE_SUCCESS(rv, rv); + + if (!wrapper) { + // aContent is not wrapped (and thus none of it's children are + // wrapped) so there's no need to reparent anything. + + return NS_OK; + } + + // Wrap the new parent and reparent aContent + + nsCOMPtr holder; + rv = sXPConnect->WrapNative(cx, ::JS_GetGlobalObject(cx), new_parent, + NS_GET_IID(nsISupports), + getter_AddRefs(holder)); + NS_ENSURE_SUCCESS(rv, rv); + + JSObject *obj; + rv = holder->GetJSObject(&obj); + NS_ENSURE_SUCCESS(rv, rv); + + return doReparentContentWrapper(aContent, aNewDocument, aOldDocument, cx, + obj); +} + diff --git a/content/base/src/nsDOMAttribute.cpp b/content/base/src/nsDOMAttribute.cpp index 34c2e32d6d0..5c1f8960c0c 100644 --- a/content/base/src/nsDOMAttribute.cpp +++ b/content/base/src/nsDOMAttribute.cpp @@ -23,27 +23,25 @@ #include "nsDOMAttribute.h" #include "nsGenericElement.h" #include "nsIContent.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsITextContent.h" #include "nsINameSpaceManager.h" #include "nsDOMError.h" +#include "nsContentUtils.h" + //---------------------------------------------------------------------- -nsDOMAttribute::nsDOMAttribute(nsIContent* aContent, - nsINodeInfo *aNodeInfo, +nsDOMAttribute::nsDOMAttribute(nsIContent* aContent, nsINodeInfo *aNodeInfo, const nsAReadableString& aValue) - : mNodeInfo(aNodeInfo), mValue(aValue) + : mNodeInfo(aNodeInfo), mValue(aValue), mContent(aContent), mChild(nsnull), + mChildList(nsnull) { NS_ABORT_IF_FALSE(mNodeInfo, "We must get a nodeinfo here!"); NS_INIT_REFCNT(); + // We don't add a reference to our content. It will tell us // to drop our reference when it goes away. - mContent = aContent; - mScriptObject = nsnull; - mChild = nsnull; - mChildList = nsnull; } nsDOMAttribute::~nsDOMAttribute() @@ -52,49 +50,28 @@ nsDOMAttribute::~nsDOMAttribute() NS_IF_RELEASE(mChildList); } -nsresult -nsDOMAttribute::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsIDOMAttr))) { - nsIDOMAttr* tmp = this; - *aInstancePtr = (void*)tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner* tmp = this; - *aInstancePtr = (void*)tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMAttributePrivate))) { - nsIDOMAttributePrivate* tmp = this; - *aInstancePtr = (void*)tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNode))) { - nsIDOMNode* tmp = this; - *aInstancePtr = (void*)tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsISupports))) { - nsIDOMAttr* tmp1 = this; - nsISupports* tmp2 = tmp1; - *aInstancePtr = (void*)tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} + +// XPConnect interface list for nsDOMAttribute +NS_CLASSINFO_MAP_BEGIN(Attr) + NS_CLASSINFO_MAP_ENTRY(nsIDOMAttr) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsDOMAttribute +NS_INTERFACE_MAP_BEGIN(nsDOMAttribute) + NS_INTERFACE_MAP_ENTRY(nsIDOMAttr) + NS_INTERFACE_MAP_ENTRY(nsIDOMAttributePrivate) + NS_INTERFACE_MAP_ENTRY(nsIDOMNode) + NS_INTERFACE_MAP_ENTRY(nsIDOM3Node) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMAttr) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Attr) +NS_INTERFACE_MAP_END + NS_IMPL_ADDREF(nsDOMAttribute) NS_IMPL_RELEASE(nsDOMAttribute) + NS_IMETHODIMP nsDOMAttribute::DropReference() { @@ -120,36 +97,6 @@ nsDOMAttribute::GetContent(nsIContent** aContent) return NS_OK; } -nsresult -nsDOMAttribute::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptAttr(aContext, - (nsISupports *)(nsIDOMAttr *)this, - (nsISupports *)mContent, - (void **)&mScriptObject); - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -nsresult -nsDOMAttribute::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - nsresult nsDOMAttribute::GetName(nsAWritableString& aName) { @@ -164,7 +111,7 @@ nsDOMAttribute::GetValue(nsAWritableString& aValue) NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_FAILURE); nsresult result = NS_OK; - if (nsnull != mContent) { + if (mContent) { nsresult attrResult; PRInt32 nameSpaceID; nsCOMPtr name; @@ -188,7 +135,7 @@ nsDOMAttribute::SetValue(const nsAReadableString& aValue) NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_FAILURE); nsresult result = NS_OK; - if (nsnull != mContent) { + if (mContent) { result = mContent->SetAttribute(mNodeInfo, aValue, PR_TRUE); } mValue=aValue; @@ -280,27 +227,26 @@ nsDOMAttribute::GetParentNode(nsIDOMNode** aParentNode) NS_IMETHODIMP nsDOMAttribute::GetChildNodes(nsIDOMNodeList** aChildNodes) { - if (nsnull == mChildList) { + if (!mChildList) { mChildList = new nsAttributeChildList(this); - if (nsnull == mChildList) { - return NS_ERROR_OUT_OF_MEMORY; - } + NS_ENSURE_TRUE(mChildList, NS_ERROR_OUT_OF_MEMORY); + NS_ADDREF(mChildList); } - return mChildList->QueryInterface(NS_GET_IID(nsIDOMNodeList), (void**)aChildNodes); + return CallQueryInterface(mChildList, aChildNodes); } NS_IMETHODIMP nsDOMAttribute::HasChildNodes(PRBool* aHasChildNodes) { *aHasChildNodes = PR_FALSE; - if (nsnull != mChild) { + if (mChild) { *aHasChildNodes = PR_TRUE; } - else if (nsnull != mContent) { + else if (mContent) { nsAutoString value; - + GetValue(value); if (0 < value.Length()) { *aHasChildNodes = PR_TRUE; @@ -331,7 +277,7 @@ nsDOMAttribute::GetFirstChild(nsIDOMNode** aFirstChild) return result; } if (0 < value.Length()) { - if (nsnull == mChild) { + if (!mChild) { nsIContent* content; result = NS_NewTextNode(&content); @@ -412,7 +358,7 @@ nsDOMAttribute::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) { nsDOMAttribute* newAttr; - if (nsnull != mContent) { + if (mContent) { nsAutoString value; PRInt32 nameSpaceID; nsCOMPtr name; @@ -427,7 +373,7 @@ nsDOMAttribute::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) newAttr = new nsDOMAttribute(nsnull, mNodeInfo, mValue); } - if (nsnull == newAttr) { + if (!newAttr) { return NS_ERROR_OUT_OF_MEMORY; } @@ -438,7 +384,7 @@ NS_IMETHODIMP nsDOMAttribute::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) { nsresult result = NS_OK; - if (nsnull != mContent) { + if (mContent) { nsIDOMNode* node; result = mContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node); if (NS_SUCCEEDED(result)) { @@ -477,7 +423,7 @@ nsDOMAttribute::SetPrefix(const nsAReadableString& aPrefix) nsCOMPtr prefix; nsresult rv = NS_OK; - if (aPrefix.Length()) + if (aPrefix.Length() && !DOMStringIsNull(aPrefix)) prefix = dont_AddRef(NS_NewAtom(aPrefix)); rv = mNodeInfo->PrefixChanged(prefix, *getter_AddRefs(newNodeInfo)); @@ -527,18 +473,16 @@ nsDOMAttribute::IsSupported(const nsAReadableString& aFeature, return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); } -#if 0 NS_IMETHODIMP nsDOMAttribute::GetBaseURI(nsAWritableString &aURI) { aURI.Truncate(); nsresult rv = NS_OK; - nsCOMPtr node(do_QueryInterface(mContent)); + nsCOMPtr node(do_QueryInterface(mContent)); if (node) rv = node->GetBaseURI(aURI); return rv; } -#endif //---------------------------------------------------------------------- @@ -559,7 +503,7 @@ nsAttributeChildList::GetLength(PRUint32* aLength) nsAutoString value; *aLength = 0; - if (nsnull != mAttribute) { + if (mAttribute) { mAttribute->GetValue(value); if (0 < value.Length()) { *aLength = 1; @@ -573,7 +517,7 @@ NS_IMETHODIMP nsAttributeChildList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) { *aReturn = nsnull; - if ((nsnull != mAttribute) && (0 == aIndex)) { + if (mAttribute && 0 == aIndex) { mAttribute->GetFirstChild(aReturn); } diff --git a/content/base/src/nsDOMAttribute.h b/content/base/src/nsDOMAttribute.h index 188420e6441..9ac1db19025 100644 --- a/content/base/src/nsDOMAttribute.h +++ b/content/base/src/nsDOMAttribute.h @@ -25,7 +25,6 @@ #include "nsIDOMAttr.h" #include "nsIDOMText.h" #include "nsIDOMNodeList.h" -#include "nsIScriptObjectOwner.h" #include "nsGenericDOMNodeList.h" #include "nsString.h" #include "nsCOMPtr.h" @@ -65,10 +64,9 @@ protected: }; // Attribute helper class used to wrap up an attribute with a dom -// object that implements nsIDOMAttr and nsIDOMNode and -// nsIScriptObjectOwner -class nsDOMAttribute : public nsIDOMAttr, - public nsIScriptObjectOwner, +// object that implements nsIDOMAttr and nsIDOMNode +class nsDOMAttribute : public nsIDOMAttr, + public nsIDOM3Node, public nsIDOMAttributePrivate { public: @@ -78,15 +76,15 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); + // nsIDOMNode interface + NS_DECL_NSIDOMNODE + + // nsIDOM3Node interface + NS_DECL_NSIDOM3NODE // nsIDOMAttr interface - NS_DECL_IDOMATTR + NS_DECL_NSIDOMATTR - // nsIDOMNode interface - NS_DECL_IDOMNODE - // nsIDOMAttributePrivate interface NS_IMETHOD DropReference(); NS_IMETHOD SetContent(nsIContent* aContent); @@ -100,7 +98,6 @@ private: // element representing the value nsIDOMText* mChild; nsAttributeChildList* mChildList; - void* mScriptObject; }; diff --git a/content/base/src/nsDOMAttributeMap.cpp b/content/base/src/nsDOMAttributeMap.cpp index cb806167a52..8b03f7851be 100644 --- a/content/base/src/nsDOMAttributeMap.cpp +++ b/content/base/src/nsDOMAttributeMap.cpp @@ -24,10 +24,9 @@ #include "nsDOMAttribute.h" #include "nsGenericElement.h" #include "nsIContent.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsINameSpaceManager.h" #include "nsDOMError.h" - +#include "nsContentUtils.h" //---------------------------------------------------------------------- @@ -35,7 +34,6 @@ nsDOMAttributeMap::nsDOMAttributeMap(nsIContent* aContent) : mContent(aContent) { NS_INIT_REFCNT(); - mScriptObject = nsnull; // We don't add a reference to our content. If it goes away, // we'll be told to drop our reference } @@ -50,45 +48,23 @@ nsDOMAttributeMap::DropReference() mContent = nsnull; } + +// XPConnect interface list for nsDOMAttributeMap +NS_CLASSINFO_MAP_BEGIN(NamedNodeMap) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNamedNodeMap) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsDOMAttributeMap NS_INTERFACE_MAP_BEGIN(nsDOMAttributeMap) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNamedNodeMap) - NS_INTERFACE_MAP_ENTRY(nsIDOMNamedNodeMap) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY(nsIDOMNamedNodeMap) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NamedNodeMap) NS_INTERFACE_MAP_END NS_IMPL_ADDREF(nsDOMAttributeMap) NS_IMPL_RELEASE(nsDOMAttributeMap) -nsresult -nsDOMAttributeMap::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptNamedNodeMap(aContext, - (nsISupports *)(nsIDOMNamedNodeMap *)this, - (nsISupports *)mContent, - (void**)&mScriptObject); - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -nsresult -nsDOMAttributeMap::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - nsresult nsDOMAttributeMap::GetNamedItem(const nsAReadableString& aAttrName, nsIDOMNode** aAttribute) diff --git a/content/base/src/nsDOMAttributeMap.h b/content/base/src/nsDOMAttributeMap.h index 32aeb400186..510979b7bcb 100644 --- a/content/base/src/nsDOMAttributeMap.h +++ b/content/base/src/nsDOMAttributeMap.h @@ -23,7 +23,6 @@ #define nsDOMAttributeMap_h___ #include "nsIDOMNamedNodeMap.h" -#include "nsIScriptObjectOwner.h" #include "nsVoidArray.h" #include "nsString.h" #include "plhash.h" @@ -31,8 +30,7 @@ class nsIContent; // Helper class that implements the nsIDOMNamedNodeMap interface. -class nsDOMAttributeMap : public nsIDOMNamedNodeMap, - public nsIScriptObjectOwner +class nsDOMAttributeMap : public nsIDOMNamedNodeMap { public: nsDOMAttributeMap(nsIContent* aContent); @@ -40,21 +38,8 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - // nsIDOMNamedNodeMap interface - NS_IMETHOD GetLength(PRUint32* aSize); - NS_IMETHOD GetNamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn); - NS_IMETHOD SetNamedItem(nsIDOMNode* aNode, nsIDOMNode** aReturn); - NS_IMETHOD RemoveNamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn); - NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn); - NS_IMETHOD GetNamedItemNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, nsIDOMNode** aReturn); - NS_IMETHOD SetNamedItemNS(nsIDOMNode* aArg, nsIDOMNode** aReturn); - NS_IMETHOD RemoveNamedItemNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsIDOMNode** aReturn); + NS_DECL_NSIDOMNAMEDNODEMAP void DropReference(); @@ -65,8 +50,7 @@ public: #endif private: - nsIContent* mContent; - void* mScriptObject; + nsIContent* mContent; // Weak reference }; diff --git a/content/base/src/nsDOMDocumentType.cpp b/content/base/src/nsDOMDocumentType.cpp index d1ba310150c..f3643e977ae 100644 --- a/content/base/src/nsDOMDocumentType.cpp +++ b/content/base/src/nsDOMDocumentType.cpp @@ -23,9 +23,10 @@ #include "nsDOMDocumentType.h" #include "nsDOMAttributeMap.h" #include "nsIDOMNamedNodeMap.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsLayoutAtoms.h" #include "nsCOMPtr.h" +#include "nsContentUtils.h" + nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, @@ -38,8 +39,8 @@ NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, { NS_ENSURE_ARG_POINTER(aDocType); - *aDocType = new nsDOMDocumentType(aName, aEntities, aNotations, - aPublicId, aSystemId, aInternalSubset); + *aDocType = new nsDOMDocumentType(aName, aEntities, aNotations, aPublicId, + aSystemId, aInternalSubset); if (!*aDocType) { return NS_ERROR_OUT_OF_MEMORY; } @@ -75,16 +76,27 @@ nsDOMDocumentType::~nsDOMDocumentType() NS_IF_RELEASE(mNotations); } + +// XPConnect interface list for nsDOMDocumentType +NS_CLASSINFO_MAP_BEGIN(DocumentType) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentType) + NS_CLASSINFO_MAP_ENTRY(nsIDOM3Node) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsDOMDocumentType +NS_INTERFACE_MAP_BEGIN(nsDOMDocumentType) + NS_INTERFACE_MAP_ENTRY(nsIContent) + NS_INTERFACE_MAP_ENTRY(nsIDOMNode) + NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentType) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent) + NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, nsNode3Tearoff(this)) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsDOMDocumentType) NS_IMPL_RELEASE(nsDOMDocumentType) -NS_INTERFACE_MAP_BEGIN(nsDOMDocumentType) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDocumentType) - NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentType) - NS_INTERFACE_MAP_ENTRY(nsIDOMNode) - NS_INTERFACE_MAP_ENTRY(nsIContent) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) -NS_INTERFACE_MAP_END_THREADSAFE NS_IMETHODIMP nsDOMDocumentType::GetName(nsAWritableString& aName) @@ -137,6 +149,7 @@ nsDOMDocumentType::GetSystemId(nsAWritableString& aSystemId) NS_IMETHODIMP nsDOMDocumentType::GetInternalSubset(nsAWritableString& aInternalSubset) { + // XXX: null string aInternalSubset = mInternalSubset; return NS_OK; @@ -266,3 +279,9 @@ nsDOMDocumentType::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const #endif return NS_OK; } + +NS_IMETHODIMP_(PRBool) +nsDOMDocumentType::IsContentOfType(PRUint32 aFlags) +{ + return !(aFlags & ~eTEXT); +} diff --git a/content/base/src/nsDOMDocumentType.h b/content/base/src/nsDOMDocumentType.h index def8ba0f636..0cd188b2f11 100644 --- a/content/base/src/nsDOMDocumentType.h +++ b/content/base/src/nsDOMDocumentType.h @@ -24,17 +24,13 @@ #define nsDOMDocumentType_h___ #include "nsIDOMDocumentType.h" -#include "nsIScriptObjectOwner.h" #include "nsIContent.h" #include "nsGenericDOMDataNode.h" #include "nsString.h" #include "nsISizeOfHandler.h" -class nsIDOMNamedNodeMap; - -class nsDOMDocumentType : public nsIDOMDocumentType, - public nsIScriptObjectOwner, - public nsIContent +class nsDOMDocumentType : public nsIContent, + public nsIDOMDocumentType { public: nsDOMDocumentType(const nsAReadableString& aName, @@ -50,13 +46,10 @@ public: NS_DECL_ISUPPORTS // nsIDOMNode - NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA(mInner) // nsIDOMDocumentType - NS_DECL_IDOMDOCUMENTTYPE - - // nsIScriptObjectOwner interface - NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(mInner); + NS_DECL_NSIDOMDOCUMENTTYPE // nsIContent NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner) @@ -77,12 +70,13 @@ protected: nsString mInternalSubset; }; -extern nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, - const nsAReadableString& aName, - nsIDOMNamedNodeMap *aEntities, - nsIDOMNamedNodeMap *aNotations, - const nsAReadableString& aPublicId, - const nsAReadableString& aSystemId, - const nsAReadableString& aInternalSubset); +extern nsresult +NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, + const nsAReadableString& aName, + nsIDOMNamedNodeMap *aEntities, + nsIDOMNamedNodeMap *aNotations, + const nsAReadableString& aPublicId, + const nsAReadableString& aSystemId, + const nsAReadableString& aInternalSubset); #endif // nsDOMDocument_h___ diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 7ac61f1db0a..a4bc51c8278 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -46,13 +46,13 @@ #include "nsIEventStateManager.h" #include "nsContentList.h" #include "nsIObserver.h" +#include "nsIBaseWindow.h" #include "nsIDOMEventListener.h" #include "nsIDOMStyleSheet.h" #include "nsDOMAttribute.h" #include "nsDOMCID.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsIDOMDOMImplementation.h" #include "nsIDOMDocumentView.h" #include "nsIDOMAbstractView.h" @@ -127,7 +127,6 @@ nsDOMStyleSheetList::nsDOMStyleSheetList(nsIDocument *aDocument) // The document will tell us when its going away. mDocument = aDocument; mDocument->AddObserver(this); - mScriptObject = nsnull; } nsDOMStyleSheetList::~nsDOMStyleSheetList() @@ -138,15 +137,27 @@ nsDOMStyleSheetList::~nsDOMStyleSheetList() mDocument = nsnull; } + +// XXX couldn't we use the GetIIDs method from CSSStyleSheetList here? +// XPConnect interface list for nsDOMStyleSheetList +NS_CLASSINFO_MAP_BEGIN(DocumentStyleSheetList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMStyleSheetList) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsDOMStyleSheetList +NS_INTERFACE_MAP_BEGIN(nsDOMStyleSheetList) + NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheetList) + NS_INTERFACE_MAP_ENTRY(nsIDocumentObserver) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMStyleSheetList) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_WITH_NAME(DocumentStyleSheetList, + StyleSheetList) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsDOMStyleSheetList) NS_IMPL_RELEASE(nsDOMStyleSheetList) -NS_INTERFACE_MAP_BEGIN(nsDOMStyleSheetList) - NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheetList) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY(nsIDocumentObserver) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMStyleSheetList) -NS_INTERFACE_MAP_END NS_IMETHODIMP nsDOMStyleSheetList::GetLength(PRUint32* aLength) @@ -207,33 +218,6 @@ nsDOMStyleSheetList::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn) return NS_OK; } -NS_IMETHODIMP -nsDOMStyleSheetList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsIDOMStyleSheetList *)this; - nsISupports *parent = (nsISupports *)mDocument; - - // XXX Should be done through factory - res = NS_NewScriptStyleSheetList(aContext, - supports, - parent, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -nsDOMStyleSheetList::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - NS_IMETHODIMP nsDOMStyleSheetList::StyleSheetAdded(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet) @@ -277,7 +261,6 @@ nsDOMStyleSheetList::DocumentWillBeDestroyed(nsIDocument *aDocument) // ================================================================== class nsDOMImplementation : public nsIDOMDOMImplementation, - public nsIScriptObjectOwner, public nsIPrivateDOMImplementation { public: @@ -300,15 +283,10 @@ public: nsIDOMDocumentType* aDoctype, nsIDOMDocument** aReturn); - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - //nsIPrivateDOMImplementation NS_IMETHOD Init(nsIURI* aBaseURI); protected: - void *mScriptObject; nsCOMPtr mBaseURI; }; @@ -325,7 +303,6 @@ NS_NewDOMImplementation(nsIDOMDOMImplementation** aInstancePtrResult) nsDOMImplementation::nsDOMImplementation(nsIURI* aBaseURI) { NS_INIT_REFCNT(); - mScriptObject = nsnull; mBaseURI = aBaseURI; } @@ -333,7 +310,24 @@ nsDOMImplementation::~nsDOMImplementation() { } -NS_IMPL_ISUPPORTS4(nsDOMImplementation, nsIDOMDOMImplementation, nsIPrivateDOMImplementation, nsIScriptObjectOwner, nsIDOMDOMImplementation) + +// XPConnect interface list for nsDOMImplementation +NS_CLASSINFO_MAP_BEGIN(DOMImplementation) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDOMImplementation) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsDOMImplementation +NS_INTERFACE_MAP_BEGIN(nsDOMImplementation) + NS_INTERFACE_MAP_ENTRY(nsIDOMDOMImplementation) + NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMImplementation) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDOMImplementation) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(DOMImplementation) +NS_INTERFACE_MAP_END + + +NS_IMPL_ADDREF(nsDOMImplementation); +NS_IMPL_RELEASE(nsDOMImplementation); NS_IMETHODIMP @@ -362,7 +356,7 @@ nsDOMImplementation::CreateDocument(const nsAReadableString& aNamespaceURI, nsIDOMDocumentType* aDoctype, nsIDOMDocument** aReturn) { - NS_ENSURE_ARG_POINTER(aReturn); + NS_ENSURE_ARG_POINTER(aReturn); *aReturn = nsnull; @@ -370,34 +364,6 @@ nsDOMImplementation::CreateDocument(const nsAReadableString& aNamespaceURI, mBaseURI); } -NS_IMETHODIMP -nsDOMImplementation::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult result = NS_OK; - - if (!mScriptObject) { - nsCOMPtr factory(do_GetService(kDOMScriptObjectFactoryCID, &result)); - - if (NS_OK == result) { - nsCOMPtr global(dont_AddRef(aContext->GetGlobalObject())); - - result = factory->NewScriptDOMImplementation(aContext, (nsISupports*)(nsIDOMDOMImplementation*)this, - global, &mScriptObject); - } - } - - *aScriptObject = mScriptObject; - return result; -} - -NS_IMETHODIMP -nsDOMImplementation::SetScriptObject(void *aScriptObject) -{ - mScriptObject = nsnull; - return NS_OK; -} - NS_IMETHODIMP nsDOMImplementation::Init(nsIURI* aBaseURI) { @@ -409,8 +375,6 @@ nsDOMImplementation::Init(nsIURI* aBaseURI) // = // ================================================================== -MOZ_DECL_CTOR_COUNTER(nsDocumentChildNodes) - nsDocumentChildNodes::nsDocumentChildNodes(nsIDocument* aDocument) { MOZ_COUNT_CTOR(nsDocumentChildNodes); @@ -419,7 +383,7 @@ nsDocumentChildNodes::nsDocumentChildNodes(nsIDocument* aDocument) // references). We'll be told when the document goes away. mDocument = aDocument; } - + nsDocumentChildNodes::~nsDocumentChildNodes() { MOZ_COUNT_DTOR(nsDocumentChildNodes); @@ -472,12 +436,10 @@ nsDocument::nsDocument() NS_INIT_REFCNT(); mArena = nsnull; - mDocumentTitle = nsnull; mDocumentURL = nsnull; mCharacterSet.AssignWithConversion("ISO-8859-1"); mParentDocument = nsnull; mRootContent = nsnull; - mScriptObject = nsnull; mListenerManager = nsnull; mInDestructor = PR_FALSE; mNameSpaceManager = nsnull; @@ -519,10 +481,6 @@ nsDocument::~nsDocument() } } - if (nsnull != mDocumentTitle) { - delete mDocumentTitle; - mDocumentTitle = nsnull; - } NS_IF_RELEASE(mDocumentURL); NS_IF_RELEASE(mPrincipal); mDocumentLoadGroup = null_nsCOMPtr(); @@ -571,6 +529,10 @@ nsDocument::~nsDocument() NS_IF_RELEASE(mDTD); delete mBoxObjectTable; + + if (mNodeInfoManager) { + mNodeInfoManager->DropDocumentReference(); + } } NS_INTERFACE_MAP_BEGIN(nsDocument) @@ -580,13 +542,13 @@ NS_INTERFACE_MAP_BEGIN(nsDocument) NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentEvent) NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentStyle) NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentView) + NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentRange) NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentXBL) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY(nsIJSScriptObject) NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal) NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver) NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget) NS_INTERFACE_MAP_ENTRY(nsIDOMNode) + NS_INTERFACE_MAP_ENTRY(nsIDOM3Node) NS_INTERFACE_MAP_ENTRY(nsIDiskDocument) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocument) @@ -615,7 +577,7 @@ nsresult nsDocument::Init() mNodeInfoManager = new nsNodeInfoManager(); NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_OUT_OF_MEMORY); - mNodeInfoManager->Init(mNameSpaceManager); + mNodeInfoManager->Init(this, mNameSpaceManager); return rv; } @@ -633,10 +595,8 @@ nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) { nsresult rv = NS_OK; - if (nsnull != mDocumentTitle) { - delete mDocumentTitle; - mDocumentTitle = nsnull; - } + mDocumentTitle.Truncate(); + NS_IF_RELEASE(mDocumentURL); NS_IF_RELEASE(mPrincipal); mDocumentLoadGroup = null_nsCOMPtr(); @@ -757,7 +717,7 @@ nsDocument::StopDocumentLoad() const nsString* nsDocument::GetDocumentTitle() const { - return mDocumentTitle; + return &mDocumentTitle; } nsIURI* nsDocument::GetDocumentURL() const @@ -1403,6 +1363,13 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject) shell->ReleaseAnonymousContent(); } + +#ifdef DEBUG_jst + printf ("Content wrapper hash had %d entries.\n", + mContentWrapperHash.Count()); +#endif + + mContentWrapperHash.Reset(); } mScriptGlobalObject = aScriptGlobalObject; @@ -1734,55 +1701,6 @@ nsDocument::StyleRuleRemoved(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRul } -nsresult nsDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - nsCOMPtr global; - - if (nsnull == mScriptObject) { - // XXX We make the (possibly erroneous) assumption that the first - // presentation shell represents the "primary view" of the document - // and that the JS parent chain should incorporate just that view. - // This is done for lack of a better model when we have multiple - // views. - nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0); - if (shell) { - nsCOMPtr cx; - shell->GetPresContext(getter_AddRefs(cx)); - nsCOMPtr container; - - res = cx->GetContainer(getter_AddRefs(container)); - if (NS_SUCCEEDED(res) && container) { - global = do_GetInterface(container); - } - } - // XXX If we can't find a view, parent to the calling context's - // global object. This may not be right either, but we need - // something. - else { - global = getter_AddRefs(aContext->GetGlobalObject()); - } - - if (NS_SUCCEEDED(res)) { - res = NS_NewScriptDocument(aContext, - (nsISupports *)(nsIDOMDocument *)this, - (nsISupports *)global, - (void**)&mScriptObject); - } - } - - *aScriptObject = mScriptObject; - - return res; -} - -nsresult nsDocument::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - // // nsIDOMDocument interface // @@ -1863,6 +1781,15 @@ nsDocument::CreateElement(const nsAReadableString& aTagName, return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP +nsDocument::CreateElementNS(const nsAReadableString & namespaceURI, + const nsAReadableString & qualifiedName, + nsIDOMElement **_retval) +{ + // Should be implemented by subclass + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsDocument::CreateTextNode(const nsAReadableString& aData, nsIDOMText** aReturn) { @@ -1934,6 +1861,15 @@ nsDocument::CreateAttribute(const nsAReadableString& aName, return attribute->QueryInterface(NS_GET_IID(nsIDOMAttr), (void**)aReturn); } +NS_IMETHODIMP +nsDocument::CreateAttributeNS(const nsAReadableString & namespaceURI, + const nsAReadableString & qualifiedName, + nsIDOMAttr **_retval) +{ + // Should be implemented by subclass + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsDocument::CreateEntityReference(const nsAReadableString& aName, nsIDOMEntityReference** aReturn) @@ -1983,6 +1919,14 @@ nsDocument::GetElementsByTagNameNS(const nsAReadableString& aNamespaceURI, return list->QueryInterface(NS_GET_IID(nsIDOMNodeList), (void **)aReturn); } +NS_IMETHODIMP +nsDocument::GetElementById(const nsAReadableString & elementId, + nsIDOMElement **_retval) +{ + // Should be implemented by subclass + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsDocument::GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets) { @@ -2146,30 +2090,6 @@ nsDocument::GetAnonymousNodes(nsIDOMElement* aElement, return NS_OK; } -NS_IMETHODIMP -nsDocument::GetLocation(jsval* aLocation) -{ - if (mScriptGlobalObject) { - nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); - if(window) { - return window->GetLocation(aLocation); - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::SetLocation(jsval aLocation) -{ - if (mScriptGlobalObject) { - nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); - if(window) { - return window->SetLocation(aLocation); - } - } - return NS_OK; -} - NS_IMETHODIMP nsDocument::CreateRange(nsIDOMRange** aReturn) { @@ -2249,6 +2169,59 @@ nsDocument::GetPlugins(nsIDOMPluginArray** aPlugins) return navigator->GetPlugins(aPlugins); } +NS_IMETHODIMP +nsDocument::GetLocation(nsIDOMLocation **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + *_retval = nsnull; + + nsCOMPtr w(do_QueryInterface(mScriptGlobalObject)); + + if(w) { + return w->GetLocation(_retval); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsDocument::GetTitle(nsAWritableString& aTitle) +{ + aTitle.Assign(mDocumentTitle); + + return NS_OK; +} + +NS_IMETHODIMP +nsDocument::SetTitle(const nsAReadableString& aTitle) +{ + for (PRInt32 i = mPresShells.Count() - 1; i >= 0; --i) { + nsIPresShell* shell = NS_STATIC_CAST(nsIPresShell*, mPresShells[i]); + + nsCOMPtr context; + nsresult rv = shell->GetPresContext(getter_AddRefs(context)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr container; + rv = context->GetContainer(getter_AddRefs(container)); + NS_ENSURE_SUCCESS(rv, rv); + + if (!container) + continue; + + nsCOMPtr docShellWin = do_QueryInterface(container); + if(!docShellWin) + continue; + + rv = docShellWin->SetTitle(PromiseFlatString(aTitle).get()); + NS_ENSURE_SUCCESS(rv, rv); + } + + mDocumentTitle.Assign(aTitle); + + return NS_OK; +} + NS_IMETHODIMP nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult) { @@ -2377,7 +2350,7 @@ nsDocument::GetDir(nsAWritableString& aDirection) } } #else - aDirection.Assign(NS_LITERAL_STRING("ltr") ); + aDirection.Assign(NS_LITERAL_STRING("ltr")); #endif // IBMBIDI return NS_OK; } @@ -2413,6 +2386,7 @@ nsDocument::SetDir(const nsAReadableString& aDirection) return NS_OK; } + // // nsIDOMNode methods // @@ -2426,7 +2400,8 @@ nsDocument::GetNodeName(nsAWritableString& aNodeName) NS_IMETHODIMP nsDocument::GetNodeValue(nsAWritableString& aNodeValue) { - aNodeValue.Truncate(); + SetDOMStringToNull(aNodeValue); + return NS_OK; } @@ -2544,14 +2519,16 @@ nsDocument::GetAttributes(nsIDOMNamedNodeMap** aAttributes) NS_IMETHODIMP nsDocument::GetNamespaceURI(nsAWritableString& aNamespaceURI) { - aNamespaceURI.Truncate(); + SetDOMStringToNull(aNamespaceURI); + return NS_OK; } NS_IMETHODIMP nsDocument::GetPrefix(nsAWritableString& aPrefix) { - aPrefix.Truncate(); + SetDOMStringToNull(aPrefix); + return NS_OK; } @@ -2564,7 +2541,8 @@ nsDocument::SetPrefix(const nsAReadableString& aPrefix) NS_IMETHODIMP nsDocument::GetLocalName(nsAWritableString& aLocalName) { - aLocalName.Truncate(); + SetDOMStringToNull(aLocalName); + return NS_OK; } @@ -2767,7 +2745,6 @@ nsDocument::IsSupported(const nsAReadableString& aFeature, return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); } -#if 0 NS_IMETHODIMP nsDocument::GetBaseURI(nsAWritableString &aURI) { @@ -2781,7 +2758,6 @@ nsDocument::GetBaseURI(nsAWritableString &aURI) } return NS_OK; } -#endif NS_IMETHODIMP nsDocument::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) @@ -2980,6 +2956,7 @@ nsDocument::CreateEvent(const nsAReadableString& aEventType, nsIDOMEvent** aRetu return NS_ERROR_FAILURE; } +#if 0 PRBool nsDocument::AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) { return PR_TRUE; @@ -3073,16 +3050,7 @@ PRBool nsDocument::InternalRegisterCompileEventHandler(JSContext* aContext, jsv } return PR_TRUE; } - -/** - * Finds text in content - */ -NS_IMETHODIMP nsDocument::FindNext(const nsAReadableString& aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound) -{ - aIsFound = PR_FALSE; - return NS_ERROR_FAILURE; -} - +#endif NS_IMETHODIMP nsDocument::InitDiskDocument(nsIFile *aFile) @@ -3268,39 +3236,27 @@ nsDocument::GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) return NS_OK; } - -// -// FindContent does a depth-first search from aStartNode -// and returns the first of aTest1 or aTest2 which it finds. -// I think. -// -nsIContent* nsDocument::FindContent(const nsIContent* aStartNode, - const nsIContent* aTest1, - const nsIContent* aTest2) const +NS_IMETHODIMP +nsDocument::AddReference(void *aKey, nsISupports *aReference) { - PRInt32 count; - aStartNode->ChildCount(count); - PRInt32 indx; + nsVoidKey key(aKey); - for(indx = 0; indx < count;indx++) - { - nsIContent* child; - aStartNode->ChildAt(indx, child); - nsIContent* content = FindContent(child,aTest1,aTest2); - if (content != nsnull) { - NS_IF_RELEASE(child); - return content; - } - if (child == aTest1 || child == aTest2) { - NS_IF_RELEASE(content); - return child; - } - NS_IF_RELEASE(child); - NS_IF_RELEASE(content); + if (mScriptGlobalObject) { + mContentWrapperHash.Put(&key, aReference); } - return nsnull; + + return NS_OK; } +NS_IMETHODIMP +nsDocument::RemoveReference(void *aKey, nsISupports **aOldReference) +{ + nsVoidKey key(aKey); + + mContentWrapperHash.Remove(&key, aOldReference); + + return NS_OK; +} NS_IMETHODIMP nsDocument::GetDTD(nsIDTD** aDTD) const diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index ac33adb441d..90709c5394d 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -31,14 +31,13 @@ #include "nsIDOMDocumentXBL.h" #include "nsIDOMNSDocument.h" #include "nsIDOMDocumentStyle.h" +#include "nsIDOMDocumentRange.h" #include "nsIDocumentObserver.h" #include "nsIDOMEventReceiver.h" #include "nsIDiskDocument.h" #include "nsIDOMStyleSheetList.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMEventTarget.h" -#include "nsIJSScriptObject.h" #include "nsIContent.h" #include "nsGenericDOMNodeList.h" #include "nsIPrincipal.h" @@ -49,6 +48,7 @@ #include "nsHashtable.h" #include "nsIWordBreakerFactory.h" #include "nsILineBreakerFactory.h" +#include "nsIScriptObjectPrincipal.h" #include "nsIURI.h" class nsIEventListenerManager; @@ -57,6 +57,7 @@ class nsIOutputStream; class nsDocument; class nsIDTD; + #if 0 class nsPostData : public nsIPostData { public: @@ -120,7 +121,6 @@ protected: class nsDOMStyleSheetList : public nsIDOMStyleSheetList, - public nsIScriptObjectOwner, public nsIDocumentObserver { public: @@ -128,7 +128,8 @@ public: virtual ~nsDOMStyleSheetList(); NS_DECL_ISUPPORTS - NS_DECL_IDOMSTYLESHEETLIST + + NS_DECL_NSIDOMSTYLESHEETLIST NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; } NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; } @@ -185,10 +186,6 @@ public: nsIStyleRule* aStyleRule) { return NS_OK; } NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument); - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); - protected: PRInt32 mLength; nsIDocument* mDocument; @@ -202,9 +199,10 @@ class nsDocument : public nsIDocument, public nsIDOMDocumentEvent, public nsIDOMDocumentStyle, public nsIDOMDocumentView, + public nsIDOMDocumentRange, public nsIDOMDocumentXBL, + public nsIDOM3Node, public nsIDiskDocument, - public nsIJSScriptObject, public nsSupportsWeakReference, public nsIDOMEventReceiver, public nsIScriptObjectPrincipal @@ -309,8 +307,10 @@ public: * Access HTTP header data (this may also get set from other sources, like * HTML META tags). */ - NS_IMETHOD GetHeaderData(nsIAtom* aHeaderField, nsAWritableString& aData) const; - NS_IMETHOD SetHeaderData(nsIAtom* aheaderField, const nsAReadableString& aData); + NS_IMETHOD GetHeaderData(nsIAtom* aHeaderField, + nsAWritableString& aData) const; + NS_IMETHOD SetHeaderData(nsIAtom* aheaderField, + const nsAReadableString& aData); /** * Create a new presentation shell that will use aContext for @@ -362,11 +362,13 @@ public: virtual void AddStyleSheet(nsIStyleSheet* aSheet); virtual void RemoveStyleSheet(nsIStyleSheet* aSheet); - NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets); + NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, + nsISupportsArray* aNewSheets); virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet); virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet); - NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify); + NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, + PRBool aNotify); virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet, PRBool mDisabled); @@ -435,74 +437,47 @@ public: NS_IMETHOD StyleRuleRemoved(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule); - /** - * Finds text in content - */ - NS_IMETHOD FindNext(const nsAReadableString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound); - NS_IMETHOD FlushPendingNotifications(PRBool aFlushReflows = PR_TRUE); NS_IMETHOD GetAndIncrementContentID(PRInt32* aID); NS_IMETHOD GetBindingManager(nsIBindingManager** aResult); NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager); + NS_IMETHOD AddReference(void *aKey, nsISupports *aReference); + NS_IMETHOD RemoveReference(void *aKey, nsISupports **aOldReference); public: - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); + // nsIDOMNode + NS_DECL_NSIDOMNODE - // nsIDOMDocument interface - NS_IMETHOD GetDoctype(nsIDOMDocumentType** aDoctype); - NS_IMETHOD GetImplementation(nsIDOMDOMImplementation** aImplementation); - NS_IMETHOD GetDocumentElement(nsIDOMElement** aDocumentElement); + // nsIDOM3Node + NS_DECL_NSIDOM3NODE - NS_IMETHOD CreateElement(const nsAReadableString& aTagName, nsIDOMElement** aReturn); - NS_IMETHOD CreateDocumentFragment(nsIDOMDocumentFragment** aReturn); - NS_IMETHOD CreateTextNode(const nsAReadableString& aData, nsIDOMText** aReturn); - NS_IMETHOD CreateComment(const nsAReadableString& aData, nsIDOMComment** aReturn); - NS_IMETHOD CreateCDATASection(const nsAReadableString& aData, nsIDOMCDATASection** aReturn); - NS_IMETHOD CreateProcessingInstruction(const nsAReadableString& aTarget, const nsAReadableString& aData, nsIDOMProcessingInstruction** aReturn); - NS_IMETHOD CreateAttribute(const nsAReadableString& aName, nsIDOMAttr** aReturn); - NS_IMETHOD CreateEntityReference(const nsAReadableString& aName, nsIDOMEntityReference** aReturn); - NS_IMETHOD GetElementsByTagName(const nsAReadableString& aTagname, nsIDOMNodeList** aReturn); - NS_IMETHOD GetElementsByTagNameNS(const nsAReadableString& aNamespaceURI, const nsAReadableString& aLocalName, nsIDOMNodeList** aReturn); - NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets); - NS_IMETHOD GetCharacterSet(nsAWritableString& aCharacterSet); - NS_IMETHOD ImportNode(nsIDOMNode* aImportedNode, - PRBool aDeep, - nsIDOMNode** aReturn); - NS_IMETHOD GetLocation(jsval* aLocation); - NS_IMETHOD SetLocation(jsval aLocation); - NS_IMETHOD CreateRange(nsIDOMRange** aReturn); - NS_IMETHOD Load (const nsAReadableString& aUrl); - NS_IMETHOD GetPlugins(nsIDOMPluginArray** aPlugins); - NS_IMETHOD GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult); - NS_IMETHOD SetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject* aBoxObject); + // nsIDOMDocument + NS_DECL_NSIDOMDOCUMENT - /** - * Retrieve the "direction" property of the document. - */ - NS_IMETHOD GetDir(nsAWritableString& aDirection); - - /** - * Set the "direction" property of the document. - */ - NS_IMETHOD SetDir(const nsAReadableString& aDirection); - - // nsIDOMNode interface - NS_DECL_IDOMNODE - - // nsIDOMDocumentView - NS_DECL_IDOMDOCUMENTVIEW - - // nsIDOMDocumentXBL - NS_DECL_IDOMDOCUMENTXBL + // nsIDOMNSDocument + NS_DECL_NSIDOMNSDOCUMENT // nsIDOMDocumentEvent - NS_DECL_IDOMDOCUMENTEVENT + NS_DECL_NSIDOMDOCUMENTEVENT + + // nsIDOMDocumentStyle + NS_DECL_NSIDOMDOCUMENTSTYLE + + // nsIDOMDocumentView + NS_DECL_NSIDOMDOCUMENTVIEW + + // nsIDOMDocumentRange + NS_DECL_NSIDOMDOCUMENTRANGE + + // nsIDOMDocumentXBL + NS_DECL_NSIDOMDOCUMENTXBL // nsIDOMEventReceiver interface - NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); - NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); + NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, + const nsIID& aIID); + NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, + const nsIID& aIID); NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult); NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult); NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent); @@ -511,9 +486,11 @@ public: NS_DECL_NSIDISKDOCUMENT // nsIDOMEventTarget interface - NS_IMETHOD AddEventListener(const nsAReadableString& aType, nsIDOMEventListener* aListener, + NS_IMETHOD AddEventListener(const nsAReadableString& aType, + nsIDOMEventListener* aListener, PRBool aUseCapture); - NS_IMETHOD RemoveEventListener(const nsAReadableString& aType, nsIDOMEventListener* aListener, + NS_IMETHOD RemoveEventListener(const nsAReadableString& aType, + nsIDOMEventListener* aListener, PRBool aUseCapture); NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); @@ -527,43 +504,23 @@ public: NS_IMETHOD_(PRBool) EventCaptureRegistration(PRInt32 aCapturerIncrement); - // nsIJSScriptObject interface - virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool DeleteProperty(JSContext *aContext, - JSObject *aObj, jsval aID, jsval *aVp); - virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj); - virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty); - virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID); - virtual void Finalize(JSContext *aContext, JSObject *aObj); - virtual nsresult SetDocumentURL(nsIURI* aURI); protected: - nsIContent* FindContent(const nsIContent* aStartNode, - const nsIContent* aTest1, - const nsIContent* aTest2) const; NS_IMETHOD GetDTD(nsIDTD** aDTD) const; protected: virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet); // subclass hooks for sheet ordering - virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex); - - virtual PRBool InternalRegisterCompileEventHandler(JSContext* aContext, jsval aPropName, - jsval *aVp, PRBool aCompile); + virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, + PRInt32 aIndex); nsDocument(); virtual ~nsDocument(); nsresult Init(); nsIArena* mArena; - nsString* mDocumentTitle; + nsString mDocumentTitle; nsIURI* mDocumentURL; nsCOMPtr mDocumentBaseURL; nsIPrincipal* mPrincipal; @@ -578,7 +535,6 @@ protected: // mChildren, or null if no such element exists. nsVoidArray mStyleSheets; nsVoidArray mObservers; - void* mScriptObject; nsCOMPtr mScriptGlobalObject; nsIEventListenerManager* mListenerManager; PRBool mInDestructor; @@ -607,6 +563,8 @@ protected: nsSupportsHashtable* mBoxObjectTable; PRInt32 mNumCapturers; //Number of capturing event handlers in doc. Used to optimize event delivery. + nsSupportsHashtable mContentWrapperHash; + private: // These are not implemented and not supported. nsDocument(const nsDocument& aOther); diff --git a/content/base/src/nsDocumentFragment.cpp b/content/base/src/nsDocumentFragment.cpp index f2aba9b3fb2..995b323fa13 100644 --- a/content/base/src/nsDocumentFragment.cpp +++ b/content/base/src/nsDocumentFragment.cpp @@ -23,19 +23,18 @@ #include "nsISupports.h" #include "nsIContent.h" #include "nsIDOMDocumentFragment.h" -#include "nsIScriptObjectOwner.h" #include "nsGenericElement.h" #include "nsINameSpaceManager.h" #include "nsINodeInfo.h" #include "nsNodeInfoManager.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsDOMError.h" class nsDocumentFragment : public nsGenericContainerElement, - public nsIDOMDocumentFragment + public nsIDOMDocumentFragment, + public nsIDOM3Node { public: nsDocumentFragment(nsIDocument* aOwnerDocument); @@ -101,12 +100,12 @@ public: PRBool* aReturn) { return nsGenericContainerElement::IsSupported(aFeature, aVersion, aReturn); } + + // nsIDOM3Node NS_IMETHOD GetBaseURI(nsAWritableString& aURI) - { return nsGenericContainerElement::GetBaseURI(aURI); } - - // interface nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); + { aURI.Truncate(); return NS_OK; } + // nsIContent NS_IMETHOD SetParent(nsIContent* aParent) { return NS_OK; } NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, @@ -213,20 +212,30 @@ nsDocumentFragment::nsDocumentFragment(nsIDocument* aOwnerDocument) nsDocumentFragment::~nsDocumentFragment() { } - -NS_IMPL_ADDREF(nsDocumentFragment) -NS_IMPL_RELEASE(nsDocumentFragment) +// XPConnect interface list for nsDocumentFragment +NS_CLASSINFO_MAP_BEGIN(DocumentFragment) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentFragment) + NS_CLASSINFO_MAP_ENTRY(nsIDOM3Node) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsDocumentFragment NS_INTERFACE_MAP_BEGIN(nsDocumentFragment) NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentFragment) NS_INTERFACE_MAP_ENTRY(nsIDOMNode) + NS_INTERFACE_MAP_ENTRY(nsIDOM3Node) NS_INTERFACE_MAP_ENTRY(nsIContent) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(DocumentFragment) NS_INTERFACE_MAP_END +NS_IMPL_ADDREF(nsDocumentFragment) +NS_IMPL_RELEASE(nsDocumentFragment) + + NS_IMETHODIMP nsDocumentFragment::GetNodeType(PRUint16* aNodeType) { @@ -281,34 +290,3 @@ nsDocumentFragment::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) return NS_OK; } - -NS_IMETHODIMP -nsDocumentFragment::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - *aScriptObject = nsnull; - - nsDOMSlots *slots = GetDOMSlots(); - - if (slots && !mDOMSlots->mScriptObject) { - nsCOMPtr factory; - - res = GetScriptObjectFactory(getter_AddRefs(factory)); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptDocumentFragment(aContext, - NS_STATIC_CAST(nsIDOMDocumentFragment *, this), - mOwnerDocument, - (void**)&slots->mScriptObject); - } - - if (slots) { - *aScriptObject = slots->mScriptObject; - } - - return res; -} diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index 21347c831c7..4f7de216ffb 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -242,9 +242,9 @@ public: NS_DECL_ISUPPORTS /*BEGIN implementations of focus event handler interface*/ - virtual nsresult HandleEvent(nsIDOMEvent* aEvent); - virtual nsresult Focus(nsIDOMEvent* aEvent); - virtual nsresult Blur(nsIDOMEvent* aEvent); + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); + NS_IMETHOD Focus(nsIDOMEvent* aEvent); + NS_IMETHOD Blur(nsIDOMEvent* aEvent); /*END implementations of focus event handler interface*/ nsresult Init(DocumentViewerImpl *aDocViewer); @@ -5231,7 +5231,7 @@ nsDocViewerFocusListener::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } -nsresult +NS_IMETHODIMP nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) { nsCOMPtr shell; @@ -5256,8 +5256,8 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) } return result; } - -nsresult + +NS_IMETHODIMP nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) { nsCOMPtr shell; diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp index 192057f5cee..6cb17d76a13 100644 --- a/content/base/src/nsGenericDOMDataNode.cpp +++ b/content/base/src/nsGenericDOMDataNode.cpp @@ -42,7 +42,6 @@ #include "nsISizeOfHandler.h" #include "nsIDOMEvent.h" #include "nsIDOMText.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsIScriptGlobalObject.h" #include "prprf.h" #include "nsCOMPtr.h" @@ -54,7 +53,6 @@ nsGenericDOMDataNode::nsGenericDOMDataNode() { mDocument = nsnull; mParent = nsnull; - mScriptObject = nsnull; mListenerManager = nsnull; mRangeList = nsnull; } @@ -207,14 +205,16 @@ nsGenericDOMDataNode::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) nsresult nsGenericDOMDataNode::GetNamespaceURI(nsAWritableString& aNamespaceURI) { - aNamespaceURI.Truncate(); + SetDOMStringToNull(aNamespaceURI); + return NS_OK; } nsresult nsGenericDOMDataNode::GetPrefix(nsAWritableString& aPrefix) { - aPrefix.Truncate(); + SetDOMStringToNull(aPrefix); + return NS_OK; } @@ -224,6 +224,14 @@ nsGenericDOMDataNode::SetPrefix(const nsAReadableString& aPrefix) return NS_ERROR_DOM_NAMESPACE_ERR; } +nsresult +nsGenericDOMDataNode::GetLocalName(nsAWritableString& aLocalName) +{ + SetDOMStringToNull(aLocalName); + + return NS_OK; +} + nsresult nsGenericDOMDataNode::Normalize() { @@ -244,7 +252,7 @@ nsGenericDOMDataNode::GetBaseURI(nsAWritableString& aURI) aURI.Truncate(); nsresult rv = NS_OK; // DOM Data Node inherits the base from its parent element/document - nsCOMPtr node; + nsCOMPtr node; if (mParent) { node = do_QueryInterface(mParent); } else if (mDocument) { @@ -314,14 +322,14 @@ nsGenericDOMDataNode::SetData(nsIContent *aOuterContent, const nsAReadableString return result; } -nsresult +nsresult nsGenericDOMDataNode::GetLength(PRUint32* aLength) { *aLength = mText.GetLength(); return NS_OK; } -nsresult +nsresult nsGenericDOMDataNode::SubstringData(PRUint32 aStart, PRUint32 aCount, nsAWritableString& aReturn) @@ -486,55 +494,6 @@ nsGenericDOMDataNode::ReplaceData(nsIContent *aOuterContent, PRUint32 aOffset, //---------------------------------------------------------------------- -// nsIScriptObjectOwner implementation - -nsresult -nsGenericDOMDataNode::GetScriptObject(nsIContent *aOuterContent, - nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - nsIDOMNode* node; - PRUint16 nodeType; - - res = aOuterContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node); - if (NS_OK != res) { - return res; - } - - node->GetNodeType(&nodeType); - res = factory->NewScriptCharacterData(nodeType, - aContext, aOuterContent, - mParent, (void**)&mScriptObject); - if (nsnull != mDocument) { - aContext->AddNamedReference((void *)&mScriptObject, - mScriptObject, - "nsGenericDOMDataNode::mScriptObject"); - } - NS_RELEASE(node); - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -nsresult -nsGenericDOMDataNode::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - -//---------------------------------------------------------------------- - nsresult nsGenericDOMDataNode::GetListenerManager(nsIContent* aOuterContent, nsIEventListenerManager** aResult) { @@ -618,14 +577,16 @@ nsGenericDOMDataNode::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool a // If we were part of a document, make sure we get rid of the // script context reference to our script object so that our // script object can be freed (or collected). - if ((nsnull != mDocument) && (nsnull != mScriptObject)) { + if (mDocument) { nsCOMPtr globalObject; mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if (globalObject) { nsCOMPtr context; if (NS_OK == globalObject->GetContext(getter_AddRefs(context)) && context) { - context->RemoveReference((void *)&mScriptObject, - mScriptObject); + // context->RemoveReference((void *)&mScriptObject, + // mScriptObject); + + // XXX: UnRoot! } } } @@ -636,15 +597,17 @@ nsGenericDOMDataNode::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool a // to a document, make sure that the script context adds a // reference to our script object. This will ensure that it // won't be freed (or collected) out from under us. - if ((nsnull != mDocument) && (nsnull != mScriptObject)) { + if (mDocument) { nsCOMPtr globalObject; mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); if (globalObject) { nsCOMPtr context; if (NS_OK == globalObject->GetContext(getter_AddRefs(context)) && context) { - context->AddNamedReference((void *)&mScriptObject, - mScriptObject, - "Text"); + // context->AddNamedReference((void *)&mScriptObject, + // mScriptObject, + // "Text"); + + // XXX: Root! } } } diff --git a/content/base/src/nsGenericDOMDataNode.h b/content/base/src/nsGenericDOMDataNode.h index 40d6ba3546e..453b5006d2c 100644 --- a/content/base/src/nsGenericDOMDataNode.h +++ b/content/base/src/nsGenericDOMDataNode.h @@ -24,7 +24,6 @@ #include "nsCOMPtr.h" #include "nsIDOMCharacterData.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIContent.h" #include "nsTextFragment.h" @@ -33,6 +32,7 @@ #include "nsITextContent.h" #include "nsDOMError.h" #include "nsIEventListenerManager.h" +#include "nsGenericElement.h" class nsIDOMAttr; @@ -118,6 +118,7 @@ struct nsGenericDOMDataNode { } nsresult GetOwnerDocument(nsIDOMDocument** aOwnerDocument); nsresult GetNamespaceURI(nsAWritableString& aNamespaceURI); + nsresult GetLocalName(nsAWritableString& aLocalName); nsresult GetPrefix(nsAWritableString& aPrefix); nsresult SetPrefix(const nsAReadableString& aPrefix); nsresult Normalize(); @@ -140,11 +141,6 @@ struct nsGenericDOMDataNode { PRUint32 aCount, const nsAReadableString& aArg); - // nsIScriptObjectOwner interface - nsresult GetScriptObject(nsIContent *aOuterContent, - nsIScriptContext* aContext, void** aScriptObject); - nsresult SetScriptObject(void *aScriptObject); - // Implementation for nsIContent nsresult GetDocument(nsIDocument*& aResult) const; nsresult SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers); @@ -266,7 +262,6 @@ struct nsGenericDOMDataNode { nsIDocument* mDocument; nsIContent* mParent; - void* mScriptObject; nsIEventListenerManager* mListenerManager; nsTextFragment mText; @@ -284,10 +279,10 @@ struct nsGenericDOMDataNode { * NS_IMETHOD GetNodeType(PRUint16* aNodeType); * NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); */ -#define NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(_g) \ +#define NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA(_g) \ NS_IMETHOD GetNodeName(nsAWritableString& aNodeName); \ NS_IMETHOD GetLocalName(nsAWritableString& aLocalName) { \ - return GetNodeName(aLocalName); \ + return _g.GetLocalName(aLocalName); \ } \ NS_IMETHOD GetNodeValue(nsAWritableString& aNodeValue) { \ return _g.GetNodeValue(aNodeValue); \ @@ -362,7 +357,7 @@ struct nsGenericDOMDataNode { } \ NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); -#define NS_IMPL_IDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(_g) \ +#define NS_IMPL_NSIDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(_g) \ NS_IMETHOD GetData(nsAWritableString& aData) { \ return _g.GetData(aData); \ } \ @@ -395,7 +390,7 @@ struct nsGenericDOMDataNode { * generic content object (either nsGenericHTMLLeafElement or * nsGenericHTMLContainerContent) */ -#define NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(_g) \ +#define NS_IMPL_NSIDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(_g) \ NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, \ const nsIID& aIID) { \ return _g.AddEventListenerByIID(aListener, aIID); \ @@ -424,20 +419,6 @@ struct nsGenericDOMDataNode { return _g.RemoveEventListener(aType, aListener, aUseCapture); \ } -/** - * Implement the nsIScriptObjectOwner API by forwarding the methods to a - * generic content object (either nsGenericHTMLLeafElement or - * nsGenericHTMLContainerContent) - */ -#define NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(_g) \ - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, \ - void** aScriptObject) { \ - return _g.GetScriptObject(this, aContext, aScriptObject); \ - } \ - NS_IMETHOD SetScriptObject(void *aScriptObject) { \ - return _g.SetScriptObject(aScriptObject); \ - } - #define NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(_g) \ NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ return _g.GetDocument(aResult); \ @@ -543,17 +524,18 @@ struct nsGenericDOMDataNode { return _g.RemoveFocus(aPresContext); \ } \ NS_IMETHOD GetBindingParent(nsIContent** aContent) { \ - return _g.GetBindingParent(aContent); \ + return _g.GetBindingParent(aContent); \ } \ - NS_IMETHOD SetBindingParent(nsIContent* aParent) { \ - return _g.SetBindingParent(aParent); \ - } + NS_IMETHOD SetBindingParent(nsIContent* aParent) { \ + return _g.SetBindingParent(aParent); \ + } \ + NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags); /** * Implement the nsIDOMText API by forwarding the methods to a * generic character data content object. */ -#define NS_IMPL_IDOMTEXT_USING_GENERIC_DOM_DATA(_g) \ +#define NS_IMPL_NSIDOMTEXT_USING_GENERIC_DOM_DATA(_g) \ NS_IMETHOD SplitText(PRUint32 aOffset, nsIDOMText** aReturn){ \ return _g.SplitText(this, aOffset, aReturn); \ } @@ -595,51 +577,27 @@ struct nsGenericDOMDataNode { * This macro implements the portion of query interface that is * generic to all html content objects. */ -#define NS_IMPL_DOM_DATA_QUERY_INTERFACE(_id, _iptr, _this) \ - if (_id.Equals(NS_GET_IID(nsISupports))) { \ - nsIContent* tmp = _this; \ - nsISupports* tmp2 = tmp; \ - *_iptr = (void*) tmp2; \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } \ - if (_id.Equals(NS_GET_IID(nsIDOMNode))) { \ - nsIDOMNode* tmp = _this; \ - *_iptr = (void*) tmp; \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } \ - if (_id.Equals(NS_GET_IID(nsIDOMCharacterData))) { \ - nsIDOMCharacterData* tmp = _this; \ - *_iptr = (void*) tmp; \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } \ - if (_id.Equals(NS_GET_IID(nsIDOMEventReceiver))) { \ - nsCOMPtr man; \ - if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \ - return man->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), (void**)_iptr); \ - } \ - return NS_NOINTERFACE; \ - } \ - if (_id.Equals(NS_GET_IID(nsIDOMEventTarget))) { \ - nsCOMPtr man; \ - if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \ - return man->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)_iptr); \ - } \ - return NS_NOINTERFACE; \ - } \ - if (_id.Equals(NS_GET_IID(nsIScriptObjectOwner))) { \ - nsIScriptObjectOwner* tmp = _this; \ - *_iptr = (void*) tmp; \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } \ - if (_id.Equals(NS_GET_IID(nsIContent))) { \ - nsIContent* tmp = _this; \ - *_iptr = (void*) tmp; \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } + +#define NS_INTERFACE_MAP_ENTRY_DOM_DATA() \ + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent) \ + NS_INTERFACE_MAP_ENTRY(nsIDOMNode) \ + if (aIID.Equals(NS_GET_IID(nsIDOMEventReceiver))) { \ + nsCOMPtr man; \ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))) { \ + return man->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), \ + (void**)aInstancePtr); \ + } \ + return NS_NOINTERFACE; \ + } else \ + if (aIID.Equals(NS_GET_IID(nsIDOMEventTarget))) { \ + nsCOMPtr man; \ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \ + return man->QueryInterface(NS_GET_IID(nsIDOMEventTarget), \ + (void**)aInstancePtr); \ + } \ + return NS_NOINTERFACE; \ + } else \ + NS_INTERFACE_MAP_ENTRY(nsIContent) \ + NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, nsNode3Tearoff(this)) #endif /* nsGenericDOMDataNode_h___ */ diff --git a/content/base/src/nsGenericDOMNodeList.cpp b/content/base/src/nsGenericDOMNodeList.cpp index e624bf0067a..4c1a572a2fe 100644 --- a/content/base/src/nsGenericDOMNodeList.cpp +++ b/content/base/src/nsGenericDOMNodeList.cpp @@ -21,68 +21,33 @@ */ #include "nsGenericDOMNodeList.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsGenericElement.h" nsGenericDOMNodeList::nsGenericDOMNodeList() { NS_INIT_REFCNT(); - mScriptObject = nsnull; } nsGenericDOMNodeList::~nsGenericDOMNodeList() { } -nsresult -nsGenericDOMNodeList::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNodeList))) { - *aInstancePtr = (void*)(nsIDOMNodeList*)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - *aInstancePtr = (void*)(nsIScriptObjectOwner*)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsISupports))) { - *aInstancePtr = (void*)(nsISupports*)(nsIDOMNodeList*)this; - AddRef(); - return NS_OK; - } - return NS_NOINTERFACE; -} NS_IMPL_ADDREF(nsGenericDOMNodeList) NS_IMPL_RELEASE(nsGenericDOMNodeList) -NS_IMETHODIMP -nsGenericDOMNodeList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - res = factory->NewScriptNodeList(aContext, (nsISupports *)(nsIDOMNodeList *)this, nsnull, (void**)&mScriptObject); - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} +// XPConnect interface list for nsGenericDOMNodeList +NS_CLASSINFO_MAP_BEGIN(NodeList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNodeList) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsGenericDOMNodeList +NS_INTERFACE_MAP_BEGIN(nsGenericDOMNodeList) + NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList) +NS_INTERFACE_MAP_END + -NS_IMETHODIMP -nsGenericDOMNodeList::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} diff --git a/content/base/src/nsGenericDOMNodeList.h b/content/base/src/nsGenericDOMNodeList.h index bc5322798fd..ce44ca71fc6 100644 --- a/content/base/src/nsGenericDOMNodeList.h +++ b/content/base/src/nsGenericDOMNodeList.h @@ -25,19 +25,16 @@ #include "nsISupports.h" #include "nsIDOMNodeList.h" -#include "nsIScriptObjectOwner.h" /** * This is a base class for a generic DOM Node List. The base class - * provides implementations for nsISupports and nsIScriptObjectOwner, - * but it is up to the subclass to implement the core node list - * methods: + * provides implementations for nsISupports, it is up to the subclass + * to implement the core node list methods: + * * GetLength * Item - * - */ -class nsGenericDOMNodeList : public nsIDOMNodeList, - public nsIScriptObjectOwner + * */ +class nsGenericDOMNodeList : public nsIDOMNodeList { public: nsGenericDOMNodeList(); @@ -45,16 +42,10 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - // The following need to be defined in the subclass // nsIDOMNodeList interface NS_IMETHOD GetLength(PRUint32* aLength)=0; NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn)=0; - -protected: - void* mScriptObject; }; #endif // nsGenericDOMNodeList_h__ diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 6c7144e4cb2..44b50fba085 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -51,7 +51,6 @@ #include "nsIPrivateDOMEvent.h" #include "nsDOMCID.h" #include "nsIServiceManager.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsIDOMCSSStyleDeclaration.h" #include "nsDOMCSSDeclaration.h" #include "nsINameSpaceManager.h" @@ -345,38 +344,89 @@ nsCheapVoidArray::SwitchToVector() return vector; } -//---------------------------------------------------------------------- -// XXX Currently, the script object factory is global. The way we -// obtain it should, at least, be made thread-safe later. Ideally, -// we'd find a better way. -nsIDOMScriptObjectFactory* nsGenericElement::gScriptObjectFactory = nsnull; - -static NS_DEFINE_IID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); - -nsresult -nsGenericElement::GetScriptObjectFactory(nsIDOMScriptObjectFactory **aResult) +NS_IMETHODIMP +nsNode3Tearoff::QueryInterface(REFNSIID aIID, void** aInstancePtr) { - nsresult result = NS_OK; + if (aIID.Equals(NS_GET_IID(nsIDOM3Node))) { + nsISupports *inst = this; - if (nsnull == gScriptObjectFactory) { - result = nsServiceManager::GetService(kDOMScriptObjectFactoryCID, - NS_GET_IID(nsIDOMScriptObjectFactory), - (nsISupports **)&gScriptObjectFactory); - if (result != NS_OK) { - return result; + NS_ADDREF(inst); + + *aInstancePtr = inst; + + return NS_OK; + } + + return mContent->QueryInterface(aIID, aInstancePtr); +} + + +NS_IMPL_ADDREF(nsNode3Tearoff) +NS_IMPL_RELEASE(nsNode3Tearoff) + + +NS_IMETHODIMP +nsNode3Tearoff::GetBaseURI(nsAWritableString& aURI) +{ + nsCOMPtr uri; + + nsCOMPtr doc; + + mContent->GetDocument(*getter_AddRefs(doc)); + + nsCOMPtr xmlDoc(do_QueryInterface(doc)); + + aURI.Truncate(); + + if (xmlDoc) { + // XML documents can use the XML Base (W3C spec) way of setting + // the base per element. We look at this node and its ancestors + // until we find the first XML content and get it's base. + nsCOMPtr content(mContent); + + while (content) { + nsCOMPtr xmlContent(do_QueryInterface(content)); + + if (xmlContent) { + xmlContent->GetXMLBaseURI(getter_AddRefs(uri)); + + break; + } + + nsCOMPtr tmp(content); + tmp->GetParent(*getter_AddRefs(content)); } } - *aResult = gScriptObjectFactory; - NS_ADDREF(gScriptObjectFactory); - return result; + if (!uri && doc) { + // HTML document or for some reason there was no XML content in + // XML document + + doc->GetBaseURL(*getter_AddRefs(uri)); + + if (!uri) { + uri = dont_AddRef(doc->GetDocumentURL()); + } + } + + if (uri) { + nsXPIDLCString spec; + + uri->GetSpec(getter_Copies(spec)); + + CopyASCIItoUCS2(nsLiteralCString(spec), aURI); + } + + return NS_OK; } + +//---------------------------------------------------------------------- + /* static */ void nsGenericElement::Shutdown() { - NS_IF_RELEASE(gScriptObjectFactory); // assigns null } nsGenericElement::nsGenericElement() : mDocument(nsnull), mParent(nsnull), @@ -426,7 +476,6 @@ nsGenericElement::GetDOMSlots() if (!mDOMSlots) return nsnull; - mDOMSlots->mScriptObject = nsnull; mDOMSlots->mChildNodes = nsnull; mDOMSlots->mStyle = nsnull; mDOMSlots->mAttributeMap = nsnull; @@ -442,7 +491,6 @@ void nsGenericElement::MaybeClearDOMSlots() { if (mDOMSlots && - !mDOMSlots->mScriptObject && !mDOMSlots->mChildNodes && !mDOMSlots->mStyle && !mDOMSlots->mAttributeMap && @@ -481,7 +529,10 @@ nsGenericElement::GetLocalName(nsAWritableString& aLocalName) NS_IMETHODIMP nsGenericElement::GetNodeValue(nsAWritableString& aNodeValue) { + // XXX: Null string + aNodeValue.Truncate(); + return NS_OK; } @@ -630,7 +681,7 @@ nsGenericElement::SetPrefix(const nsAReadableString& aPrefix) nsINodeInfo *newNodeInfo = nsnull; nsCOMPtr prefix; - if (aPrefix.Length()) { + if (aPrefix.Length() && !DOMStringIsNull(aPrefix)) { prefix = dont_AddRef(NS_NewAtom(aPrefix)); NS_ENSURE_TRUE(prefix, NS_ERROR_OUT_OF_MEMORY); } @@ -707,48 +758,6 @@ nsGenericElement::GetXMLBaseURI(nsIURI **aURI) return NS_OK; } - -NS_IMETHODIMP -nsGenericElement::GetBaseURI(nsAWritableString& aURI) -{ - aURI.Truncate(); - nsCOMPtr uri; - nsCOMPtr xmlDoc(do_QueryInterface(mDocument)); - if (xmlDoc) { - // XML documents can use the XML Base (W3C spec) way of setting the base - // per element. We look at this node and its ancestors until we find - // the first XML content and get it's base. - nsCOMPtr content(do_QueryInterface(NS_STATIC_CAST(nsIContent*,this))); - while (content) { - nsCOMPtr xmlContent(do_QueryInterface(content)); - if (xmlContent) { - xmlContent->GetXMLBaseURI(getter_AddRefs(uri)); - break; - } - nsCOMPtr tmp(content); - tmp->GetParent(*getter_AddRefs(content)); - } - } - - if (!uri && mDocument) { - // HTML document or for some reason there was no XML content in XML document - mDocument->GetBaseURL(*getter_AddRefs(uri)); - if (!uri) { - uri = dont_AddRef(mDocument->GetDocumentURL()); - } - } - - if (uri) { - nsXPIDLCString spec; - uri->GetSpec(getter_Copies(spec)); - if (spec) { - CopyASCIItoUCS2(nsLiteralCString(spec), aURI); - } - } - - return NS_OK; -} - NS_IMETHODIMP nsGenericElement::GetAttributes(nsIDOMNamedNodeMap** aAttributes) { @@ -791,7 +800,12 @@ nsGenericElement::GetAttribute(const nsAReadableString& aName, ni->GetNamespaceID(nsid); ni->GetNameAtom(*getter_AddRefs(nameAtom)); - NS_STATIC_CAST(nsIContent *, this)->GetAttribute(nsid, nameAtom, aReturn); + nsresult rv = NS_STATIC_CAST(nsIContent *, + this)->GetAttribute(nsid, nameAtom, aReturn); + + if (rv = NS_CONTENT_ATTR_NOT_THERE) { + // XXX: Null aReturn + } return NS_OK; } @@ -1280,17 +1294,6 @@ nsGenericElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, // If we were part of a document, make sure we get rid of the // script context reference to our script object so that our // script object can be freed (or collected). - if (mDocument && mDOMSlots && mDOMSlots->mScriptObject) { - nsCOMPtr globalObject; - mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { - nsCOMPtr context; - if (NS_OK == globalObject->GetContext(getter_AddRefs(context)) && context) { - context->RemoveReference((void *)&mDOMSlots->mScriptObject, - mDOMSlots->mScriptObject); - } - } - } if (mDocument && aDeep) { // Notify XBL- & nsIAnonymousContentCreator-generated @@ -1312,23 +1315,6 @@ nsGenericElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, } mDocument = aDocument; - - // If we already have a script object and now we're being added - // to a document, make sure that the script context adds a - // reference to our script object. This will ensure that it - // won't be freed (or collected) out from under us. - if (mDocument && mDOMSlots && mDOMSlots->mScriptObject) { - nsCOMPtr globalObject; - mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { - nsCOMPtr context; - if (NS_OK == globalObject->GetContext(getter_AddRefs(context)) && context) { - context->AddNamedReference((void *)&mDOMSlots->mScriptObject, - mDOMSlots->mScriptObject, - "nsGenericElement::mScriptObject"); - } - } - } } if (PR_TRUE == aDeep) { @@ -1351,6 +1337,7 @@ nsresult nsGenericElement::SetParent(nsIContent* aParent) { mParent = aParent; + return NS_OK; } @@ -1822,6 +1809,11 @@ nsGenericElement::SetBindingParent(nsIContent* aParent) return NS_OK; } +NS_IMETHODIMP_(PRBool) +nsGenericElement::IsContentOfType(PRUint32 aFlags) +{ + return !(aFlags & ~eELEMENT); +} //---------------------------------------------------------------------- @@ -1869,125 +1861,6 @@ nsGenericElement::RenderFrame(nsIPresContext* aPresContext) //---------------------------------------------------------------------- -// nsIScriptObjectOwner implementation - -nsresult -nsGenericElement::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - nsDOMSlots *slots = GetDOMSlots(); - - if (!slots->mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - nsAutoString tag; - mNodeInfo->GetName(tag); - - void* scriptObject; - res = factory->NewScriptElement(tag, aContext, - NS_STATIC_CAST(nsIHTMLContent *, this), - mParent ? (nsISupports*)mParent : (nsISupports*)mDocument, - (void**)&scriptObject); - NS_RELEASE(factory); - - NS_WARN_IF_FALSE(scriptObject, - "Eeek! Cound't create script object!"); - - if (slots->mScriptObject) { - // We must have re-entered; discard the newly created - // script object and use the one created during the - // nesting instead. - JSContext* cx = (JSContext*) aContext->GetNativeContext(); - ::JS_SetPrivate(cx, (JSObject*) scriptObject, nsnull); - - // Since we've eagerly cleared the transient script - // object's native pointer, we now need to ``manually'' - // balance the reference that it had to us - Release(); - - *aScriptObject = slots->mScriptObject; - return NS_OK; - } - - slots->mScriptObject = scriptObject; - - if (mDocument && slots->mScriptObject) { - aContext->AddNamedReference((void *)&slots->mScriptObject, - slots->mScriptObject, - "nsGenericElement::mScriptObject"); - - // See if we have a frame. - nsCOMPtr shell = getter_AddRefs(mDocument->GetShellAt(0)); - if (shell) { - nsIFrame* frame; - shell->GetPrimaryFrameFor(this, &frame); - if (!frame) { - // We must ensure that the XBL Binding is installed before we hand - // back this object. - nsCOMPtr bindingManager; - mDocument->GetBindingManager(getter_AddRefs(bindingManager)); - nsCOMPtr binding; - bindingManager->GetBinding(this, getter_AddRefs(binding)); - if (!binding) { - nsCOMPtr global; - mDocument->GetScriptGlobalObject(getter_AddRefs(global)); - nsCOMPtr viewCSS(do_QueryInterface(global)); - if (viewCSS) { - nsCOMPtr cssDecl; - nsAutoString empty; - nsCOMPtr elt(do_QueryInterface(NS_STATIC_CAST(nsIHTMLContent *, this))); - viewCSS->GetComputedStyle(elt, empty, getter_AddRefs(cssDecl)); - if (cssDecl) { - nsAutoString behavior; behavior.Assign(NS_LITERAL_STRING("-moz-binding")); - nsAutoString value; - cssDecl->GetPropertyValue(behavior, value); - if (!value.IsEmpty()) { - // We have a binding that must be installed. - nsresult rv; - PRBool dummy; - NS_WITH_SERVICE(nsIXBLService, xblService, "@mozilla.org/xbl;1", &rv); - xblService->LoadBindings(this, value, PR_FALSE, getter_AddRefs(binding), &dummy); - if (binding) { - binding->ExecuteAttachedHandler(); - } - } - } - } - } - } - } - } - } - - *aScriptObject = slots->mScriptObject; - return res; -} - -nsresult -nsGenericElement::SetScriptObject(void *aScriptObject) -{ - nsDOMSlots *slots = GetDOMSlots(); - - slots->mScriptObject = aScriptObject; - - if (!aScriptObject) { - if (slots->mListenerManager) { - slots->mListenerManager->RemoveAllListeners(PR_TRUE); - } - MaybeClearDOMSlots(); - } - - return NS_OK; -} - -//---------------------------------------------------------------------- - nsresult nsGenericElement::GetListenerManager(nsIEventListenerManager** aResult) { @@ -2009,115 +1882,6 @@ nsGenericElement::GetListenerManager(nsIEventListenerManager** aResult) //---------------------------------------------------------------------- -// nsIJSScriptObject implementation - -PRBool -nsGenericElement::AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, - jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsGenericElement::DeleteProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsGenericElement::GetProperty(JSContext *aContext, JSObject *aObj, jsval aID, - jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsGenericElement::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, - jsval *aVp) -{ - return InternalRegisterCompileEventHandler(aContext, aID, aVp, PR_FALSE); -} - -PRBool -nsGenericElement::EnumerateProperty(JSContext *aContext, JSObject *aObj) -{ - return PR_TRUE; -} - -PRBool -nsGenericElement::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool* aDidDefineProperty) -{ - *aDidDefineProperty = PR_FALSE; - - return InternalRegisterCompileEventHandler(aContext, aID, nsnull, PR_TRUE); -} - -PRBool -nsGenericElement::Convert(JSContext *aContext, JSObject *aObj, jsval aID) -{ - return PR_TRUE; -} - -void -nsGenericElement::Finalize(JSContext *aContext, JSObject *aObj) -{ -} - -PRBool -nsGenericElement::InternalRegisterCompileEventHandler(JSContext* aContext, jsval aPropName, - jsval *aVp, PRBool aCompile) -{ - //If called from resolve there is no aVp arg to check against. Else check for function value. - //In both cases check for string type starting with 'on' before continuing with handler checking. - if ((!aVp || JS_TypeOfValue(aContext, *aVp) == JSTYPE_FUNCTION) && JSVAL_IS_STRING(aPropName)) { - const PRUnichar* str = NS_REINTERPRET_CAST(const PRUnichar *, JS_GetStringChars(JS_ValueToString(aContext, aPropName))); - - if (str && str[0] == 'o' && str[1] == 'n' && str[2]) { - nsCOMPtr atom(dont_AddRef(NS_NewAtom(str))); - - if (atom.get() == nsLayoutAtoms::onmousedown || atom.get() == nsLayoutAtoms::onmouseup || - atom.get() == nsLayoutAtoms::onclick || atom.get() == nsLayoutAtoms::onmouseover || - atom.get() == nsLayoutAtoms::onmouseout ||atom.get() == nsLayoutAtoms::onkeydown || - atom.get() == nsLayoutAtoms::onkeyup || atom.get() == nsLayoutAtoms::onkeypress || - atom.get() == nsLayoutAtoms::onmousemove || atom.get() == nsLayoutAtoms::onfocus || - atom.get() == nsLayoutAtoms::onblur || atom.get() == nsLayoutAtoms::onsubmit || - atom.get() == nsLayoutAtoms::onreset || atom.get() == nsLayoutAtoms::onchange || - atom.get() == nsLayoutAtoms::onselect || atom.get() == nsLayoutAtoms::onload || - atom.get() == nsLayoutAtoms::onunload || atom.get() == nsLayoutAtoms::onabort || - atom.get() == nsLayoutAtoms::onerror || atom.get() == nsLayoutAtoms::onpaint || - atom.get() == nsLayoutAtoms::onresize || atom.get() == nsLayoutAtoms::onscroll || - atom.get() == nsLayoutAtoms::oncontextmenu || atom.get() == nsLayoutAtoms::onDOMAttrModified || - atom.get() == nsLayoutAtoms::onDOMCharacterDataModified || atom.get() == nsLayoutAtoms::onDOMSubtreeModified || - atom.get() == nsLayoutAtoms::onDOMNodeInsertedIntoDocument || atom.get() == nsLayoutAtoms::onDOMNodeRemovedFromDocument || - atom.get() == nsLayoutAtoms::onDOMNodeInserted || atom.get() == nsLayoutAtoms::onDOMNodeRemoved - ) { - - nsCOMPtr manager; - GetListenerManager(getter_AddRefs(manager)); - - if (manager) { - nsCOMPtr scriptContext; - nsresult rv = nsContentUtils::GetStaticScriptContext(aContext, NS_REINTERPRET_CAST(JSObject*, GetDOMSlots()->mScriptObject), - getter_AddRefs(scriptContext)); - if (NS_SUCCEEDED(rv) && scriptContext) { - if (aCompile) { - rv = manager->CompileScriptEventListener(scriptContext, this, atom); - } - else { - rv = manager->RegisterScriptEventListener(scriptContext, this, atom); - } - } - if (NS_FAILED(rv)) - return PR_FALSE; - } - } - } - } - return PR_TRUE; -} - // Generic DOMNode implementations /* @@ -2285,6 +2049,10 @@ nsGenericElement::doInsertBefore(nsIDOMNode* aNewChild, return res; } + nsCOMPtr old_doc; + + newContent->GetDocument(*getter_AddRefs(old_doc)); + /* * Remove the element from the old parent if one exists, since oldParent * is a nsIDOMNode this will do the right thing even if the parent of @@ -2333,6 +2101,9 @@ nsGenericElement::doInsertBefore(nsIDOMNode* aNewChild, } } + nsContentUtils::ReparentContentWrapper(newContent, this, mDocument, + old_doc); + res = InsertChildAt(newContent, refPos, PR_TRUE, PR_TRUE); if (NS_FAILED(res)) { @@ -2478,6 +2249,10 @@ nsGenericElement::doReplaceChild(nsIDOMNode* aNewChild, return res; } + nsCOMPtr old_doc; + + newContent->GetDocument(*getter_AddRefs(old_doc)); + /* * Remove the element from the old parent if one exists, since oldParent * is a nsIDOMNode this will do the right thing even if the parent of @@ -2518,6 +2293,9 @@ nsGenericElement::doReplaceChild(nsIDOMNode* aNewChild, } } + nsContentUtils::ReparentContentWrapper(newContent, this, mDocument, + old_doc); + res = ReplaceChildAt(newContent, oldPos, PR_TRUE, PR_TRUE); if (NS_FAILED(res)) { @@ -2596,17 +2374,13 @@ nsGenericElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) } return NS_NOINTERFACE; - } else if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - inst = NS_STATIC_CAST(nsIScriptObjectOwner *, this); - } else if (aIID.Equals(NS_GET_IID(nsIJSScriptObject))) { - inst = NS_STATIC_CAST(nsIJSScriptObject *, this); - } - else if (mDOMSlots && mDOMSlots->mScriptObject && mDocument) { + } + else if (mDocument) { nsCOMPtr manager; mDocument->GetBindingManager(getter_AddRefs(manager)); if (manager) - return manager->GetBindingImplementation(NS_STATIC_CAST(nsIStyledContent*, this), mDOMSlots->mScriptObject, - aIID, aInstancePtr); + return manager->GetBindingImplementation(this, aIID, aInstancePtr); + return NS_NOINTERFACE; } else { @@ -2719,11 +2493,8 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, receiver->GetListenerManager(getter_AddRefs(manager)); if (manager) { - nsCOMPtr objOwner(do_QueryInterface(global)); - if (objOwner) { - ret = manager->AddScriptEventListener(context, objOwner, aAttribute, - aValue, PR_FALSE); - } + ret = manager->AddScriptEventListener(context, global, aAttribute, + aValue, PR_FALSE); } } else { @@ -2884,16 +2655,15 @@ nsGenericContainerElement::GetChildNodes(nsIDOMNodeList** aChildNodes) { nsDOMSlots *slots = GetDOMSlots(); - if (nsnull == slots->mChildNodes) { + if (!slots->mChildNodes) { slots->mChildNodes = new nsChildContentList(this); - if (nsnull == slots->mChildNodes) { + if (!slots->mChildNodes) { return NS_ERROR_OUT_OF_MEMORY; } NS_ADDREF(slots->mChildNodes); } - return slots->mChildNodes->QueryInterface(NS_GET_IID(nsIDOMNodeList), - (void **)aChildNodes); + return CallQueryInterface(slots->mChildNodes, aChildNodes); } nsresult @@ -3101,8 +2871,10 @@ nsGenericContainerElement::SetAttribute(nsINodeInfo* aNodeInfo, mutation.mPrevAttrValue = getter_AddRefs(NS_NewAtom(oldValue)); if (!aValue.IsEmpty()) mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(aValue)); - mutation.mAttrChange = modification ? nsIDOMMutationEvent::MODIFICATION : - nsIDOMMutationEvent::ADDITION; + if (modification) + mutation.mAttrChange = nsIDOMMutationEvent::MODIFICATION; + else + mutation.mAttrChange = nsIDOMMutationEvent::ADDITION; nsEventStatus status = nsEventStatus_eIgnore; HandleDOMEvent(nsnull, &mutation, nsnull, NS_EVENT_FLAG_INIT, &status); diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index 0f09eaa534a..1811f10bd69 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -33,26 +33,23 @@ #include "nsICSSStyleSheet.h" #include "nsICSSLoaderObserver.h" #include "nsVoidArray.h" -#include "nsIScriptObjectOwner.h" -#include "nsIJSScriptObject.h" #include "nsILinkHandler.h" #include "nsGenericDOMNodeList.h" #include "nsIEventListenerManager.h" #include "nsINodeInfo.h" #include "nsIParser.h" +#include "nsContentUtils.h" class nsIDOMAttr; class nsIDOMEventListener; class nsIFrame; class nsISupportsArray; -class nsIDOMScriptObjectFactory; class nsDOMCSSDeclaration; class nsIDOMCSSStyleDeclaration; class nsDOMAttributeMap; class nsIURI; class nsINodeInfo; - // Class that holds the child list of a content element and also // implements the nsIDOMNodeList interface. class nsChildContentList : public nsGenericDOMNodeList @@ -62,7 +59,7 @@ public: virtual ~nsChildContentList(); // nsIDOMNodeList interface - NS_DECL_IDOMNODELIST + NS_DECL_NSIDOMNODELIST void DropReference(); @@ -117,7 +114,6 @@ private: // in a side structure that's only allocated when the content is // accessed through the DOM. typedef struct { - void *mScriptObject; nsChildContentList *mChildNodes; nsDOMCSSDeclaration *mStyle; nsDOMAttributeMap* mAttributeMap; @@ -127,8 +123,25 @@ typedef struct { // that created us. [Weak] } nsDOMSlots; -class nsGenericElement : public nsIHTMLContent, - public nsIJSScriptObject + +class nsNode3Tearoff : public nsIDOM3Node +{ + NS_DECL_ISUPPORTS + + NS_DECL_NSIDOM3NODE + + nsNode3Tearoff(nsIContent *aContent) : mContent(aContent) + { + NS_INIT_ISUPPORTS(); + } + virtual ~nsNode3Tearoff() {}; + +private: + nsCOMPtr mContent; +}; + + +class nsGenericElement : public nsIHTMLContent { public: nsGenericElement(); @@ -196,6 +209,7 @@ public: NS_IMETHOD RemoveFocus(nsIPresContext* aContext); NS_IMETHOD GetBindingParent(nsIContent** aContent); NS_IMETHOD SetBindingParent(nsIContent* aParent); + NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags); // nsIStyledContent interface methods NS_IMETHOD GetID(nsIAtom*& aResult) const; @@ -230,27 +244,6 @@ public: NS_IMETHOD GetBaseURL(nsIURI*& aBaseURL) const; NS_IMETHOD GetBaseTarget(nsAWritableString& aBaseTarget) const; - - // nsIScriptObjectOwner interface methods - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - - // nsIJSScriptObject interface methods - virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool DeleteProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj); - virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty); - virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID); - virtual void Finalize(JSContext *aContext, JSObject *aObj); - - // nsIDOMNode method implementation NS_IMETHOD GetNodeName(nsAWritableString& aNodeName); NS_IMETHOD GetLocalName(nsAWritableString& aLocalName); @@ -269,7 +262,6 @@ public: NS_IMETHOD IsSupported(const nsAReadableString& aFeature, const nsAReadableString& aVersion, PRBool* aReturn); NS_IMETHOD HasAttributes(PRBool* aHasAttributes); - NS_IMETHOD GetBaseURI(nsAWritableString& aURI); // nsIDOMElement method implementation NS_IMETHOD GetTagName(nsAWritableString& aTagName); @@ -333,10 +325,6 @@ public: static void SetDocumentInChildrenOf(nsIContent* aContent, nsIDocument* aDocument, PRBool aCompileEventHandlers); - static nsresult GetScriptObjectFactory(nsIDOMScriptObjectFactory **aFactory); - - static nsIDOMScriptObjectFactory *gScriptObjectFactory; - static nsresult InternalIsSupported(const nsAReadableString& aFeature, const nsAReadableString& aVersion, PRBool* aReturn); @@ -346,8 +334,6 @@ public: protected: virtual PRUint32 BaseSizeOf(nsISizeOfHandler *aSizer) const; - virtual PRBool InternalRegisterCompileEventHandler(JSContext* aContext, jsval aPropName, - jsval *aVp, PRBool aCompile); nsDOMSlots *GetDOMSlots(); void MaybeClearDOMSlots(); @@ -450,7 +436,7 @@ protected: }; -#define NS_FORWARD_IDOMNODE_NO_CLONENODE(_to) \ +#define NS_FORWARD_NSIDOMNODE_NO_CLONENODE(_to) \ NS_IMETHOD GetNodeName(nsAWritableString& aNodeName) { return _to GetNodeName(aNodeName); } \ NS_IMETHOD GetNodeValue(nsAWritableString& aNodeValue) { return _to GetNodeValue(aNodeValue); } \ NS_IMETHOD SetNodeValue(const nsAReadableString& aNodeValue) { return _to SetNodeValue(aNodeValue); } \ @@ -475,7 +461,12 @@ protected: NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); \ NS_IMETHOD Normalize() { return _to Normalize(); } \ NS_IMETHOD IsSupported(const nsAReadableString& aFeature, const nsAReadableString& aVersion, PRBool* aReturn) { return _to IsSupported(aFeature, aVersion, aReturn); } \ - NS_IMETHOD HasAttributes(PRBool* aReturn) { return _to HasAttributes(aReturn); } \ - NS_IMETHOD GetBaseURI(nsAWritableString& aURI) { return _to GetBaseURI(aURI); } \ + NS_IMETHOD HasAttributes(PRBool* aReturn) { return _to HasAttributes(aReturn); } + +#define NS_INTERFACE_MAP_ENTRY_TEAROFF(_iid, _tearoff) \ + if (aIID.Equals(NS_GET_IID(_iid))) { \ + foundInterface = new _tearoff; \ + NS_ENSURE_TRUE(foundInterface, NS_ERROR_OUT_OF_MEMORY); \ + } else #endif /* nsGenericElement_h___ */ diff --git a/content/base/src/nsNodeInfo.cpp b/content/base/src/nsNodeInfo.cpp index dfddcbfe223..5326ccc9f62 100644 --- a/content/base/src/nsNodeInfo.cpp +++ b/content/base/src/nsNodeInfo.cpp @@ -26,6 +26,7 @@ #include "nsString.h" #include "nsIAtom.h" #include "nsINameSpaceManager.h" +#include "domstubs.h" // for SetDOMStringToNull(); nsNodeInfo::nsNodeInfo() @@ -129,7 +130,7 @@ nsNodeInfo::GetLocalName(nsAWritableString& aLocalName) return mInner.mName->ToString(aLocalName); } - aLocalName.Truncate(); + SetDOMStringToNull(aLocalName); return NS_OK; #else @@ -144,7 +145,7 @@ nsNodeInfo::GetPrefix(nsAWritableString& aPrefix) if (mInner.mPrefix) { mInner.mPrefix->ToString(aPrefix); } else { - aPrefix.Truncate(); + SetDOMStringToNull(aPrefix); } return NS_OK; @@ -175,7 +176,7 @@ nsNodeInfo::GetNamespaceURI(nsAWritableString& aNameSpaceURI) rv = nsm->GetNameSpaceURI(mInner.mNamespaceID, aNameSpaceURI); } else { - aNameSpaceURI.Truncate(); + SetDOMStringToNull(aNameSpaceURI); } return rv; @@ -394,6 +395,14 @@ nsNodeInfo::PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult) aResult); } +NS_IMETHODIMP +nsNodeInfo::GetDocument(nsIDocument*& aDocument) +{ + NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED); + + return mOwnerManager->GetDocument(aDocument); +} + PLHashNumber nsNodeInfoInner::GetHashValue(const void *key) diff --git a/content/base/src/nsNodeInfo.h b/content/base/src/nsNodeInfo.h index e6fdff12724..4652408efec 100644 --- a/content/base/src/nsNodeInfo.h +++ b/content/base/src/nsNodeInfo.h @@ -98,6 +98,7 @@ public: NS_IMETHOD NameChanged(nsIAtom *aName, nsINodeInfo*& aResult); NS_IMETHOD PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult); + NS_IMETHOD GetDocument(nsIDocument*& aDocument); // nsNodeInfo nsNodeInfo(); diff --git a/content/base/src/nsNodeInfoManager.cpp b/content/base/src/nsNodeInfoManager.cpp index 392dc58ebdc..9e7334def24 100644 --- a/content/base/src/nsNodeInfoManager.cpp +++ b/content/base/src/nsNodeInfoManager.cpp @@ -25,6 +25,7 @@ #include "nsCOMPtr.h" #include "nsString.h" #include "nsIAtom.h" +#include "nsIDocument.h" nsNodeInfoManager* nsNodeInfoManager::gAnonymousNodeInfoManager = nsnull; PRUint32 nsNodeInfoManager::gNodeManagerCount = 0; @@ -44,7 +45,7 @@ nsresult NS_NewNodeInfoManager(nsINodeInfoManager** aResult) nsNodeInfoManager::nsNodeInfoManager() - : mNameSpaceManager(nsnull) + : mDocument(nsnull) { NS_INIT_REFCNT(); @@ -101,17 +102,28 @@ NS_IMPL_THREADSAFE_ISUPPORTS(nsNodeInfoManager, // nsINodeInfoManager NS_IMETHODIMP -nsNodeInfoManager::Init(nsINameSpaceManager *aNameSpaceManager) +nsNodeInfoManager::Init(nsIDocument *aDocument, + nsINameSpaceManager *aNameSpaceManager) { NS_ENSURE_ARG_POINTER(aNameSpaceManager); NS_ENSURE_TRUE(mNodeInfoHash, NS_ERROR_OUT_OF_MEMORY); + mDocument = aDocument; mNameSpaceManager = aNameSpaceManager; return NS_OK; } +NS_IMETHODIMP +nsNodeInfoManager::DropDocumentReference() +{ + mDocument = nsnull; + + return NS_OK; +} + + NS_IMETHODIMP nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo) @@ -263,6 +275,17 @@ nsNodeInfoManager::GetNamespaceManager(nsINameSpaceManager*& aNameSpaceManager) } +NS_IMETHODIMP +nsNodeInfoManager::GetDocument(nsIDocument*& aDocument) +{ + aDocument = mDocument; + + NS_IF_ADDREF(aDocument); + + return NS_OK; +} + + void nsNodeInfoManager::RemoveNodeInfo(nsNodeInfo *aNodeInfo) { diff --git a/content/base/src/nsNodeInfoManager.h b/content/base/src/nsNodeInfoManager.h index 131200be872..aedfb90378b 100644 --- a/content/base/src/nsNodeInfoManager.h +++ b/content/base/src/nsNodeInfoManager.h @@ -37,7 +37,9 @@ public: NS_DECL_ISUPPORTS // nsINodeInfoManager - NS_IMETHOD Init(nsINameSpaceManager *aNameSpaceManager); + NS_IMETHOD Init(nsIDocument *aDocument, + nsINameSpaceManager *aNameSpaceManager); + NS_IMETHOD DropDocumentReference(); NS_IMETHOD GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo); NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, nsIAtom *aPrefix, @@ -51,6 +53,7 @@ public: const nsAReadableString& aNamespaceURI, nsINodeInfo*& aNodeInfo); NS_IMETHOD GetNamespaceManager(nsINameSpaceManager*& aNameSpaceManager); + NS_IMETHOD GetDocument(nsIDocument*& aDocument); // nsNodeInfoManager nsNodeInfoManager(); @@ -63,6 +66,7 @@ public: private: PLHashTable *mNodeInfoHash; nsCOMPtr mNameSpaceManager; + nsIDocument *mDocument; // WEAK /* * gAnonymousNodeInfoManager is a global nodeinfo manager used for nodes diff --git a/content/base/src/nsRange.cpp b/content/base/src/nsRange.cpp index 24d46fec8f4..602dd00ddc9 100644 --- a/content/base/src/nsRange.cpp +++ b/content/base/src/nsRange.cpp @@ -36,7 +36,6 @@ #include "nsDOMError.h" #include "nsIContentIterator.h" #include "nsIDOMNodeList.h" -#include "nsIScriptGlobalObject.h" #include "nsIParser.h" #include "nsIComponentManager.h" #include "nsParserCIID.h" @@ -44,6 +43,8 @@ // XXX Temporary inclusion to deal with fragment parsing #include "nsHTMLParts.h" +#include "nsContentUtils.h" + static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); @@ -78,7 +79,6 @@ class nsAutoRangeLock }; - // Returns -1 if point1 < point2, 1, if point1 > point2, // 0 if error or if point1 == point2. PRInt32 ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1, @@ -392,8 +392,7 @@ nsRange::nsRange() : mStartOffset(0), mEndOffset(0), mStartParent(), - mEndParent(), - mScriptObject(nsnull) + mEndParent() { NS_INIT_REFCNT(); } @@ -429,44 +428,27 @@ void nsRange::Shutdown() /****************************************************** * nsISupports ******************************************************/ - + + +// XPConnect interface list for nsRange +NS_CLASSINFO_MAP_BEGIN(Range) + NS_CLASSINFO_MAP_ENTRY(nsIDOMRange) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSRange) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsRange +NS_INTERFACE_MAP_BEGIN(nsRange) + NS_INTERFACE_MAP_ENTRY(nsIDOMRange) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSRange) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMRange) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Range) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsRange) NS_IMPL_RELEASE(nsRange) -nsresult nsRange::QueryInterface(const nsIID& aIID, - void** aInstancePtrResult) -{ - NS_PRECONDITION(aInstancePtrResult, "null pointer"); - if (!aInstancePtrResult) - { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kISupportsIID)) - { - *aInstancePtrResult = (void*)(nsISupports*)(nsIDOMRange *)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMRange))) - { - *aInstancePtrResult = (void*)(nsIDOMRange*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNSRange))) - { - *aInstancePtrResult = (void*)(nsIDOMNSRange*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} /******************************************************** * Utilities for comparing points: API from nsIDOMNSRange @@ -2215,31 +2197,6 @@ nsRange::SetBeforeAndAfter(PRBool aBefore, PRBool aAfter) return NS_OK; } -// BEGIN nsIScriptObjectOwner interface implementations -NS_IMETHODIMP -nsRange::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - nsIScriptGlobalObject *globalObj = aContext->GetGlobalObject(); - - if (!mScriptObject) { - res = NS_NewScriptRange(aContext, (nsISupports *)(nsIDOMRange *)this, globalObj, (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - NS_RELEASE(globalObj); - return res; -} - -NS_IMETHODIMP -nsRange::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - -// END nsIScriptObjectOwner interface implementations - nsresult nsRange::Lock() { diff --git a/content/base/src/nsRange.h b/content/base/src/nsRange.h index 00b9b8a230f..f21df3180c5 100644 --- a/content/base/src/nsRange.h +++ b/content/base/src/nsRange.h @@ -33,7 +33,6 @@ #include "nsIDOMDocumentFragment.h" #include "nsIContent.h" #include "nsIDOMNode.h" -#include "nsIScriptObjectOwner.h" #include "prmon.h" class nsVoidArray; @@ -63,8 +62,7 @@ public: // ------------------------------------------------------------------------------- class nsRange : public nsIDOMRange, - public nsIDOMNSRange, - public nsIScriptObjectOwner + public nsIDOMNSRange { public: NS_DECL_ISUPPORTS @@ -138,12 +136,6 @@ public: NS_IMETHOD SetHasGeneratedAfter(PRBool aBool); NS_IMETHOD SetBeforeAndAfter(PRBool aBefore, PRBool aAfter); -/*BEGIN nsIScriptObjectOwner interface implementations*/ - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); -/*END nsIScriptObjectOwner interface implementations*/ - - // nsRange interface extensions static NS_METHOD OwnerGone(nsIContent* aParentNode); @@ -211,7 +203,6 @@ public: nsresult ContentOwnsUs(nsIDOMNode* domNode); protected: - void* mScriptObject; PRBool mBeforeGenContent; PRBool mAfterGenContent; diff --git a/content/base/src/nsSelection.cpp b/content/base/src/nsSelection.cpp index 548d44ac34b..2f6e22b4c7b 100644 --- a/content/base/src/nsSelection.cpp +++ b/content/base/src/nsSelection.cpp @@ -63,6 +63,8 @@ static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID); #include "nsIDOMText.h" +#include "nsContentUtils.h" + //included for desired x position; #include "nsIPresContext.h" #include "nsIPresShell.h" @@ -84,9 +86,6 @@ static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID); #include "nsISelectionController.h"//for the enums -/*included so html can call into nsISelection code with no security issues*/ -#include "nsISecurityCheckedComponent.h" - #define STATUS_CHECK_RETURN_MACRO() {if (!mTracker) return NS_ERROR_FAILURE;} //#define DEBUG_TABLE 1 @@ -141,11 +140,10 @@ class nsSelectionIterator; class nsSelection; class nsAutoScrollTimer; -class nsTypedSelection : public nsISelection , - public nsISelectionPrivate, - public nsSupportsWeakReference, - public nsIIndependentSelection, - public nsISecurityCheckedComponent +class nsTypedSelection : public nsISelection, + public nsISelectionPrivate, + public nsSupportsWeakReference, + public nsIIndependentSelection { public: nsTypedSelection(); @@ -191,9 +189,6 @@ public: NS_IMETHOD SelectionLanguageChange(PRBool aLangRTL); /*END nsISelection interface implementations*/ -/* nsISecurityCheckedComponent */ - NS_DECL_NSISECURITYCHECKEDCOMPONENT -/*END nsISecurityCheckedComponent*/ // utility methods for scrolling the selection into view nsresult GetPresContext(nsIPresContext **aPresContext); @@ -4443,13 +4438,26 @@ nsTypedSelection::~nsTypedSelection() } +// XPConnect interface list for nsTypedSelection +NS_CLASSINFO_MAP_BEGIN(Selection) + NS_CLASSINFO_MAP_ENTRY(nsISelection) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsRange +NS_INTERFACE_MAP_BEGIN(nsTypedSelection) + NS_INTERFACE_MAP_ENTRY(nsISelection) + NS_INTERFACE_MAP_ENTRY(nsISelectionPrivate) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY(nsIIndependentSelection) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISelection) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Selection) +NS_INTERFACE_MAP_END + NS_IMPL_ADDREF(nsTypedSelection) - NS_IMPL_RELEASE(nsTypedSelection) -NS_IMPL_QUERY_INTERFACE5(nsTypedSelection, nsISelection, nsISelectionPrivate, nsISupportsWeakReference, nsIIndependentSelection, nsISecurityCheckedComponent) - NS_IMETHODIMP nsTypedSelection::SetPresShell(nsIPresShell *aPresShell) @@ -7552,55 +7560,6 @@ nsTypedSelection::DeleteFromDocument() return mFrameSelection->DeleteFromDocument(); } - -static const char* kAllAccess = "AllAccess"; -static const char* kNoAccess = "NoAccess"; - -/* string canCreateWrapper (in nsIIDPtr iid); */ -NS_IMETHODIMP -nsTypedSelection::CanCreateWrapper(const nsIID * iid, char **_retval) -{ - if (iid->Equals(NS_GET_IID(nsISelection))) { - *_retval = nsCRT::strdup(kAllAccess); - } - else - *_retval = nsCRT::strdup(kNoAccess); - - return NS_OK; -} - -/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */ -NS_IMETHODIMP -nsTypedSelection::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval) -{ - if (iid->Equals(NS_GET_IID(nsISelection))) { - *_retval = nsCRT::strdup(kAllAccess); - } - - return NS_OK; -} - -/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */ -NS_IMETHODIMP -nsTypedSelection::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval) -{ - if (iid->Equals(NS_GET_IID(nsISelection))) { - *_retval = nsCRT::strdup(kAllAccess); - } - - return NS_OK; -} - -/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */ -NS_IMETHODIMP -nsTypedSelection::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval) -{ - if (iid->Equals(NS_GET_IID(nsISelection))) { - *_retval = nsCRT::strdup(kAllAccess); - } - return NS_OK; -} - /** SelectionLanguageChange modifies the cursor Bidi level after a change in keyboard direction * @param aLangRTL is PR_TRUE if the new language is right-to-left or PR_FALSE if the new language is left-to-right */ diff --git a/content/base/src/nsTextNode.cpp b/content/base/src/nsTextNode.cpp index 55d11f5196f..3872341c9bd 100644 --- a/content/base/src/nsTextNode.cpp +++ b/content/base/src/nsTextNode.cpp @@ -21,7 +21,6 @@ */ #include "nsIDOMText.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIContent.h" #include "nsITextContent.h" @@ -29,11 +28,12 @@ #include "nsIDocument.h" #include "nsCRT.h" #include "nsLayoutAtoms.h" +#include "nsString.h" +#include "nsContentUtils.h" -class nsTextNode : public nsIDOMText, - public nsIScriptObjectOwner, - public nsITextContent +class nsTextNode : public nsITextContent, + public nsIDOMText { public: nsTextNode(); @@ -43,16 +43,13 @@ public: NS_DECL_ISUPPORTS // nsIDOMNode - NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA(mInner) // nsIDOMCharacterData - NS_IMPL_IDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(mInner) // nsIDOMText - NS_IMPL_IDOMTEXT_USING_GENERIC_DOM_DATA(mInner) - - // nsIScriptObjectOwner - NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMTEXT_USING_GENERIC_DOM_DATA(mInner) // nsIContent NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner) @@ -97,24 +94,24 @@ nsTextNode::~nsTextNode() NS_IMPL_ADDREF(nsTextNode) NS_IMPL_RELEASE(nsTextNode) -NS_IMETHODIMP -nsTextNode::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - NS_IMPL_DOM_DATA_QUERY_INTERFACE(aIID, aInstancePtr, this) - if (aIID.Equals(NS_GET_IID(nsIDOMText))) { - nsIDOMText* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsITextContent))) { - nsITextContent* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} + +// XPConnect interface list for nsTextNode +NS_CLASSINFO_MAP_BEGIN(Text) + NS_CLASSINFO_MAP_ENTRY(nsIDOMText) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) + NS_CLASSINFO_MAP_ENTRY(nsIDOM3Node) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsTextNode +NS_INTERFACE_MAP_BEGIN(nsTextNode) + NS_INTERFACE_MAP_ENTRY_DOM_DATA() + NS_INTERFACE_MAP_ENTRY(nsITextContent) + NS_INTERFACE_MAP_ENTRY(nsIDOMText) + NS_INTERFACE_MAP_ENTRY(nsIDOMCharacterData) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Text) +NS_INTERFACE_MAP_END + NS_IMETHODIMP nsTextNode::GetTag(nsIAtom*& aResult) const @@ -265,3 +262,8 @@ nsTextNode::SetContentID(PRUint32 aID) return NS_OK; } +NS_IMETHODIMP_(PRBool) +nsTextNode::IsContentOfType(PRUint32 aFlags) +{ + return !(aFlags & ~eTEXT); +} diff --git a/content/build/Makefile.in b/content/build/Makefile.in index 2d9c5dea85c..9d81c0a77bc 100644 --- a/content/build/Makefile.in +++ b/content/build/Makefile.in @@ -33,7 +33,7 @@ LIBRARY_NAME = gkcontent EXPORT_LIBRARY = 1 SHORT_LIBNAME = gkcontnt IS_COMPONENT = 1 -EXTRA_DSO_LIBS = jsdom gkgfx +EXTRA_DSO_LIBS = gkgfx REQUIRES = xpcom string widget necko rdf docshell dom htmlparser uriloader webshell locale unicharutil lwbrk js pref caps xul xuldoc xultmpl gfx2 timer CPPSRCS = \ diff --git a/content/build/makefile.win b/content/build/makefile.win index cc884f95c99..344409d1ccb 100644 --- a/content/build/makefile.win +++ b/content/build/makefile.win @@ -74,7 +74,6 @@ LLIBS= \ $(DIST)\lib\xpcom.lib \ $(DIST)\lib\gkgfxwin.lib \ $(DIST)\lib\timer_s.lib \ - $(DIST)\lib\jsdom.lib \ $(DIST)\lib\js32$(VERSION_NUMBER).lib \ !if defined(MOZ_PERF) $(DIST)\lib\util.lib \ @@ -88,7 +87,7 @@ install:: gbdate.h $(DLL) $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib clobber:: - rm -f $(DIST)\bin\$(DLLNAME).dll + rm -f $(DIST)\bin\components\$(DLLNAME).dll rm -f $(DIST)\lib\$(DLLNAME).lib rm -f gbdate.h diff --git a/content/build/nsContentFactory.cpp b/content/build/nsContentFactory.cpp index 07aed752963..7d614b6e81e 100644 --- a/content/build/nsContentFactory.cpp +++ b/content/build/nsContentFactory.cpp @@ -45,9 +45,6 @@ #include "nsIRangeUtils.h" #include "nsIContentIterator.h" #include "nsINameSpaceManager.h" -#include "nsIScriptNameSetRegistry.h" -#include "nsIScriptNameSpaceManager.h" -#include "nsIScriptExternalNameSet.h" #include "nsIEventListenerManager.h" #include "nsILayoutDebugger.h" #include "nsIElementFactory.h" diff --git a/content/build/nsContentModule.cpp b/content/build/nsContentModule.cpp index 8a4f6a1e5a5..3fc4401f828 100644 --- a/content/build/nsContentModule.cpp +++ b/content/build/nsContentModule.cpp @@ -25,6 +25,7 @@ #include "nsCOMPtr.h" #include "nsContentModule.h" #include "nsContentCID.h" +#include "nsContentUtils.h" #include "nsIComponentManager.h" #include "nsNetUtil.h" #include "nsICSSStyleSheet.h" @@ -36,12 +37,10 @@ #include "nsColorNames.h" // to addref/release table #include "nsLayoutAtoms.h" #include "nsDOMCID.h" -#include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsINameSpaceManager.h" -#include "nsIScriptNameSetRegistry.h" +#include "nsICategoryManager.h" #include "nsIScriptNameSpaceManager.h" -#include "nsIScriptExternalNameSet.h" +#include "nsIObserver.h" #include "nsINodeInfo.h" @@ -60,6 +59,13 @@ #include "nsContentPolicyUtils.h" #define PRODUCT_NAME "Gecko" +#define NS_HTMLIMGELEMENT_CONTRACTID \ + "@mozilla.org/content/element/html;1?name=img" + +#define NS_HTMLOPTIONELEMENT_CONTRACTID \ + "@mozilla.org/content/element/html;1?name=option" + + #ifdef MOZ_XUL #include "nsXULAtoms.h" #include "nsXULContentUtils.h" @@ -94,81 +100,20 @@ extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr, //---------------------------------------------------------------------- - -static NS_DEFINE_IID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID); - -class ContentScriptNameSet : public nsIScriptExternalNameSet { -public: - ContentScriptNameSet(); - virtual ~ContentScriptNameSet(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD InitializeClasses(nsIScriptContext* aScriptContext); - NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext); -}; - -ContentScriptNameSet::ContentScriptNameSet() -{ - NS_INIT_REFCNT(); -} - -ContentScriptNameSet::~ContentScriptNameSet() -{ -} - -NS_IMPL_ISUPPORTS(ContentScriptNameSet, NS_GET_IID(nsIScriptExternalNameSet)); - -NS_IMETHODIMP -ContentScriptNameSet::InitializeClasses(nsIScriptContext* aScriptContext) -{ - return NS_OK; -} - -NS_IMETHODIMP -ContentScriptNameSet::AddNameSet(nsIScriptContext* aScriptContext) -{ - nsresult result = NS_OK; - nsIScriptNameSpaceManager* manager; - static NS_DEFINE_IID(kHTMLImageElementCID, NS_HTMLIMAGEELEMENT_CID); - static NS_DEFINE_IID(kHTMLOptionElementCID, NS_HTMLOPTIONELEMENT_CID); - - result = aScriptContext->GetNameSpaceManager(&manager); - if (NS_OK == result) { - result = manager->RegisterGlobalName(NS_LITERAL_STRING("HTMLImageElement"), - NS_GET_IID(nsIScriptObjectOwner), - kHTMLImageElementCID, - PR_TRUE); - if (NS_FAILED(result)) { - NS_RELEASE(manager); - return result; - } - - result = manager->RegisterGlobalName(NS_LITERAL_STRING("HTMLOptionElement"), - NS_GET_IID(nsIScriptObjectOwner), - kHTMLOptionElementCID, - PR_TRUE); - if (NS_FAILED(result)) { - NS_RELEASE(manager); - return result; - } - - NS_RELEASE(manager); - } - - return result; -} - -//---------------------------------------------------------------------- - - -nsIScriptNameSetRegistry* nsContentModule::gRegistry; nsICSSStyleSheet* nsContentModule::gUAStyleSheet = nsnull; - nsContentModule::nsContentModule() : mInitialized(PR_FALSE) { NS_INIT_ISUPPORTS(); + + nsCOMPtr observerService = + do_GetService(NS_OBSERVERSERVICE_CONTRACTID); + + if (observerService) { + nsAutoString topic; + topic.AssignWithConversion(NS_XPCOM_SHUTDOWN_OBSERVER_ID); + observerService->AddObserver(this, topic.GetUnicode()); + } } nsContentModule::~nsContentModule() @@ -176,7 +121,7 @@ nsContentModule::~nsContentModule() Shutdown(); } -NS_IMPL_ISUPPORTS(nsContentModule, NS_GET_IID(nsIModule)) +NS_IMPL_ISUPPORTS2(nsContentModule, nsIModule, nsIObserver) // Perform our one-time intialization for this module nsresult @@ -203,16 +148,7 @@ nsContentModule::Initialize() nsXULContentUtils::Init(); #endif - // XXX Initialize the script name set thingy-ma-jigger - if (!gRegistry) { - rv = nsServiceManager::GetService(kCScriptNameSetRegistryCID, - NS_GET_IID(nsIScriptNameSetRegistry), - (nsISupports**) &gRegistry); - if (NS_SUCCEEDED(rv)) { - ContentScriptNameSet* nameSet = new ContentScriptNameSet(); - gRegistry->AddExternalNameSet(nameSet); - } - } + nsContentUtils::Init(); return rv; } @@ -241,8 +177,22 @@ nsContentModule::Shutdown() nsXULAtoms::ReleaseAtoms(); #endif - NS_IF_RELEASE(gRegistry); NS_IF_RELEASE(gUAStyleSheet); + + nsContentUtils::Shutdown(); +} + +NS_IMETHODIMP +nsContentModule::Observe(nsISupports *aSubject, const PRUnichar *aTopic, + const PRUnichar *someData) +{ + nsAutoString topic; + topic.AssignWithConversion(NS_XPCOM_SHUTDOWN_OBSERVER_ID); + if (topic.EqualsWithConversion(aTopic)) { + nsContentUtils::Shutdown(); + } + + return NS_OK; } NS_IMETHODIMP @@ -322,10 +272,11 @@ static Components gComponents[] = { { "Generated Subtree iterator", NS_GENERATEDSUBTREEITERATOR_CID, nsnull, }, { "Subtree iterator", NS_SUBTREEITERATOR_CID, nsnull, }, - // XXX ick - { "HTML image element", NS_HTMLIMAGEELEMENT_CID, nsnull, }, - { "HTML option element", NS_HTMLOPTIONELEMENT_CID, nsnull, }, - // XXX end ick + // Needed to support "new Option;" and "new Image;" in JavaScript + { "HTML img element", NS_HTMLIMAGEELEMENT_CID, + NS_HTMLIMGELEMENT_CONTRACTID, }, + { "HTML option element", NS_HTMLOPTIONELEMENT_CID, + NS_HTMLOPTIONELEMENT_CONTRACTID, }, { "XML document encoder", NS_TEXT_ENCODER_CID, NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", }, @@ -420,7 +371,23 @@ nsContentModule::RegisterSelf(nsIComponentManager *aCompMgr, nsContentHTTPStartup::RegisterHTTPStartup(); rv = RegisterDocumentFactories(aCompMgr, aPath); - + + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr catman = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsXPIDLCString previous; + rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY, + "Image", NS_HTMLIMGELEMENT_CONTRACTID, + PR_TRUE, PR_TRUE, getter_Copies(previous)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY, + "Option", NS_HTMLOPTIONELEMENT_CONTRACTID, + PR_TRUE, PR_TRUE, getter_Copies(previous)); + return rv; } diff --git a/content/build/nsContentModule.h b/content/build/nsContentModule.h index 87a16d5f8d2..e69de29bb2d 100644 --- a/content/build/nsContentModule.h +++ b/content/build/nsContentModule.h @@ -1,78 +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.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsContentModule_h___ -#define nsContentModule_h___ - -#include "nslayout.h" -#include "nsIModule.h" - -class nsICSSStyleSheet; -class nsIScriptNameSetRegistry; - -// Module implementation for the content library -class nsContentModule : public nsIModule -{ -public: - nsContentModule(); - virtual ~nsContentModule(); - - NS_DECL_ISUPPORTS - - NS_DECL_NSIMODULE - - nsresult Initialize(); - -protected: - void Shutdown(); - - nsresult RegisterDocumentFactories(nsIComponentManager* aCompMgr, - nsIFile* aPath); - - void UnregisterDocumentFactories(nsIComponentManager* aCompMgr, - nsIFile* aPath); - - PRBool mInitialized; -// static nsIFactory* gFactory; - static nsIScriptNameSetRegistry* gRegistry; - -public: - static nsICSSStyleSheet* gUAStyleSheet; -}; - -//---------------------------------------------------------------------- - -class nsContentFactory : public nsIFactory -{ -public: - nsContentFactory(const nsCID &aClass); - - NS_DECL_ISUPPORTS - - NS_DECL_NSIFACTORY - -protected: - virtual ~nsContentFactory(); - - nsCID mClassID; -}; - -#endif /* nsContentModule_h___ */ diff --git a/content/events/public/nsIEventListenerManager.h b/content/events/public/nsIEventListenerManager.h index ccae6f663b0..c70d0d659c6 100644 --- a/content/events/public/nsIEventListenerManager.h +++ b/content/events/public/nsIEventListenerManager.h @@ -29,7 +29,7 @@ class nsIPresContext; class nsIDOMEventListener; -class nsIScriptObjectOwner; +class nsIScriptContext; class nsIDOMEventTarget; /* @@ -43,116 +43,123 @@ class nsIDOMEventTarget; class nsIEventListenerManager : public nsISupports { public: - static const nsIID& GetIID() { static nsIID iid = NS_IEVENTLISTENERMANAGER_IID; return iid; } + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IEVENTLISTENERMANAGER_IID) /** * Sets events listeners of all types. * @param an event listener */ - virtual nsresult AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 flags) = 0; + NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, + const nsIID& aIID, PRInt32 flags) = 0; /** * Removes events listeners of all types. * @param an event listener */ - virtual nsresult RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 flags) = 0; + NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, + const nsIID& aIID, PRInt32 flags) = 0; /** * Sets events listeners of all types. * @param an event listener */ - virtual nsresult AddEventListenerByType(nsIDOMEventListener *aListener, const nsAReadableString& type, PRInt32 flags) = 0; + NS_IMETHOD AddEventListenerByType(nsIDOMEventListener *aListener, + const nsAReadableString& type, + PRInt32 flags) = 0; /** * Removes events listeners of all types. * @param an event listener */ - virtual nsresult RemoveEventListenerByType(nsIDOMEventListener *aListener, const nsAReadableString& type, PRInt32 flags) = 0; + NS_IMETHOD RemoveEventListenerByType(nsIDOMEventListener *aListener, + const nsAReadableString& type, + PRInt32 flags) = 0; /** - * Creates a script event listener for the given script object with name aName and function - * body aFunc. + * Creates a script event listener for the given script object with + * name aName and function body aFunc. * @param an event listener */ - virtual nsresult AddScriptEventListener(nsIScriptContext*aContext, - nsIScriptObjectOwner *aScriptObjectOwner, - nsIAtom *aName, - const nsAReadableString& aFunc, - PRBool aDeferCompilation) = 0; + NS_IMETHOD AddScriptEventListener(nsIScriptContext*aContext, + nsISupports *aObject, + nsIAtom *aName, + const nsAReadableString& aFunc, + PRBool aDeferCompilation) = 0; - virtual nsresult RemoveScriptEventListener(nsIAtom *aName) = 0; + NS_IMETHOD RemoveScriptEventListener(nsIAtom *aName) = 0; /** - * Registers an event listener that already exists on the given script object with the event - * listener manager. + * Registers an event listener that already exists on the given + * script object with the event listener manager. * @param an event listener */ - virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext, - nsIScriptObjectOwner *aScriptObjectOwner, - nsIAtom* aName) = 0; + NS_IMETHOD RegisterScriptEventListener(nsIScriptContext *aContext, + nsISupports *aObject, + nsIAtom* aName) = 0; /** - * Compiles any event listeners that already exists on the given script object for a given - * event type. - * @param an event listener - */ - virtual nsresult CompileScriptEventListener(nsIScriptContext *aContext, - nsIScriptObjectOwner *aScriptObjectOwner, - nsIAtom* aName) = 0; + * Compiles any event listeners that already exists on the given + * script object for a given event type. + * @param an event listener */ + NS_IMETHOD CompileScriptEventListener(nsIScriptContext *aContext, + nsISupports *aObject, + nsIAtom* aName, + PRBool *aDidCompile) = 0; /** * Causes a check for event listeners and processing by them if they exist. * Event flags live in nsGUIEvent.h * @param an event listener */ - virtual nsresult HandleEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - nsIDOMEventTarget* aCurrentTarget, - PRUint32 aFlags, - nsEventStatus* aEventStatus) = 0; + NS_IMETHOD HandleEvent(nsIPresContext* aPresContext, + nsEvent* aEvent, + nsIDOMEvent** aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, + PRUint32 aFlags, + nsEventStatus* aEventStatus) = 0; /** * Creates a DOM event that can subsequently be passed into HandleEvent. * (used rarely in the situation where methods on the event need to be * invoked prior to the processing of the event). */ - virtual nsresult CreateEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - const nsAReadableString& aEventType, - nsIDOMEvent** aDOMEvent) = 0; + NS_IMETHOD CreateEvent(nsIPresContext* aPresContext, + nsEvent* aEvent, + const nsAReadableString& aEventType, + nsIDOMEvent** aDOMEvent) = 0; /** - * Changes script listener of specified event types from bubbling listeners to capturing listeners. - * @param event types - */ - virtual nsresult CaptureEvent(PRInt32 aEventTypes) = 0; + * Changes script listener of specified event types from bubbling + * listeners to capturing listeners. + * @param event types */ + NS_IMETHOD CaptureEvent(PRInt32 aEventTypes) = 0; /** - * Changes script listener of specified event types from capturing listeners to bubbling listeners. - * @param event types - */ - virtual nsresult ReleaseEvent(PRInt32 aEventTypes) = 0; + * Changes script listener of specified event types from capturing + * listeners to bubbling listeners. + * @param event types */ + NS_IMETHOD ReleaseEvent(PRInt32 aEventTypes) = 0; /** * Removes all event listeners registered by this instance of the listener * manager. */ - virtual nsresult RemoveAllListeners(PRBool aScriptOnly) = 0; + NS_IMETHOD RemoveAllListeners(PRBool aScriptOnly) = 0; /** * Removes all event listeners registered by this instance of the listener * manager. */ - virtual nsresult SetListenerTarget(nsISupports* aTarget) = 0; + NS_IMETHOD SetListenerTarget(nsISupports* aTarget) = 0; /** * Allows us to quickly determine if we have mutation listeners registered. */ - virtual nsresult HasMutationListeners(PRBool* aListener) = 0; + NS_IMETHOD HasMutationListeners(PRBool* aListener) = 0; }; -extern NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult); +extern nsresult +NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult); #endif // nsIEventListenerManager_h__ diff --git a/content/events/src/makefile.win b/content/events/src/makefile.win index e81301961de..43f6a471baa 100644 --- a/content/events/src/makefile.win +++ b/content/events/src/makefile.win @@ -32,15 +32,15 @@ DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN CPPSRCS= nsEventListenerManager.cpp \ nsEventStateManager.cpp \ nsDOMEvent.cpp \ - nsDOMMutationEvent.cpp \ + nsDOMMutationEvent.cpp \ nsDOMEventsIIDs.cpp \ - nsPrivateTextRange.cpp \ + nsPrivateTextRange.cpp \ $(NULL) CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \ .\$(OBJDIR)\nsEventStateManager.obj \ .\$(OBJDIR)\nsDOMEvent.obj \ - .\$(OBJDIR)\nsDOMMutationEvent.obj \ + .\$(OBJDIR)\nsDOMMutationEvent.obj \ .\$(OBJDIR)\nsDOMEventsIIDs.obj \ .\$(OBJDIR)\nsPrivateTextRange.obj \ $(NULL) @@ -48,8 +48,7 @@ CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \ EXPORTS= nsDOMEventsIIDs.h -LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ - -I$(PUBLIC)\dom -I$(PUBLIC)\js -I..\..\html\base\src -I$(PUBLIC)\netlib -I..\..\xul\content\src +LINCS= -I..\..\html\base\src -I..\..\xul\content\src -I..\..\base\src LCFLAGS = \ $(LCFLAGS) \ diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 14ea5b27ece..7fba59e62bf 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -42,6 +42,7 @@ #include "prmem.h" #include "nsLayoutAtoms.h" #include "nsMutationEvent.h" +#include "nsContentUtils.h" #include "nsIDOMKeyEvent.h" #include "nsIDOMMutationEvent.h" @@ -125,11 +126,15 @@ nsDOMEvent::operator delete(void* aPtr) -nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsAReadableString& aEventType) +nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, + const nsAReadableString& aEventType) { + NS_INIT_REFCNT(); + mPresContext = aPresContext; - if (mPresContext) - NS_ADDREF(mPresContext); + + NS_IF_ADDREF(mPresContext); + if (aEvent) { mEventIsInternal = PR_FALSE; mEvent = aEvent; @@ -158,6 +163,7 @@ nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsAR mEvent->eventStructType = NS_EVENT; } } + mTarget = nsnull; mCurrentTarget = nsnull; mOriginalTarget = nsnull; @@ -170,33 +176,46 @@ nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsAR // // extract the IME composition string // - mText = new nsString(((nsTextEvent*)aEvent)->theText); - // - // build the range list -- ranges need to be DOM-ified since the IME transaction - // will hold a ref, the widget representation isn't persistent - // - nsIPrivateTextRange** tempTextRangeList = new nsIPrivateTextRange*[((nsTextEvent*)aEvent)->rangeCount]; - if (tempTextRangeList!=nsnull) { - for(PRUint16 i=0;i<((nsTextEvent*)aEvent)->rangeCount;i++) { - nsPrivateTextRange* tempPrivateTextRange = new nsPrivateTextRange((((nsTextEvent*)aEvent)->rangeArray[i]).mStartOffset, - (((nsTextEvent*)aEvent)->rangeArray[i]).mEndOffset, - (((nsTextEvent*)aEvent)->rangeArray[i]).mRangeType); - if (tempPrivateTextRange!=nsnull) { - tempPrivateTextRange->AddRef(); - tempTextRangeList[i] = (nsIPrivateTextRange*)tempPrivateTextRange; - } - } - - } - // We need to create mTextRange even rangeCount is 0. - // if rangeCount is 0, mac carbon will return 0 for new and tempTextRangeList will be null. but we should still - // create mTextRange, otherwise, we will crash it later when some code call GetInputRange and AddRef to the result - mTextRange = (nsIPrivateTextRangeList*) new nsPrivateTextRangeList(((nsTextEvent*)aEvent)->rangeCount,tempTextRangeList); - if (mTextRange!=nsnull) - mTextRange->AddRef(); - } - NS_INIT_REFCNT(); + nsTextEvent *te = (nsTextEvent*)aEvent; + + mText = new nsString(te->theText); + + // + // build the range list -- ranges need to be DOM-ified since the + // IME transaction will hold a ref, the widget representation + // isn't persistent + // + nsIPrivateTextRange** tempTextRangeList = + new nsIPrivateTextRange*[te->rangeCount]; + + if (tempTextRangeList) { + PRUint16 i; + + for(i = 0; i < te->rangeCount; i++) { + nsPrivateTextRange* tempPrivateTextRange = new + nsPrivateTextRange(te->rangeArray[i].mStartOffset, + te->rangeArray[i].mEndOffset, + te->rangeArray[i].mRangeType); + + if (tempPrivateTextRange) { + NS_ADDREF(tempPrivateTextRange); + + tempTextRangeList[i] = (nsIPrivateTextRange*)tempPrivateTextRange; + } + } + } + + // We need to create mTextRange even rangeCount is 0. + // If rangeCount is 0, mac carbon will return 0 for new and + // tempTextRangeList will be null. but we should still create + // mTextRange, otherwise, we will crash it later when some code + // call GetInputRange and AddRef to the result + + mTextRange = new nsPrivateTextRangeList(te->rangeCount ,tempTextRangeList); + + NS_IF_ADDREF(mTextRange); + } } nsDOMEvent::~nsDOMEvent() @@ -228,6 +247,13 @@ nsDOMEvent::~nsDOMEvent() NS_IMPL_ADDREF(nsDOMEvent) NS_IMPL_RELEASE(nsDOMEvent) +// XPConnect interface list for nsDOMEvent +NS_CLASSINFO_MAP_BEGIN(Event) + NS_CLASSINFO_MAP_ENTRY(nsIDOMKeyEvent) + NS_CLASSINFO_MAP_ENTRY(nsIDOMMouseEvent) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSUIEvent) +NS_CLASSINFO_MAP_END + NS_INTERFACE_MAP_BEGIN(nsDOMEvent) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEvent, nsIDOMMouseEvent) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMUIEvent, nsIDOMMouseEvent) @@ -237,8 +263,8 @@ NS_INTERFACE_MAP_BEGIN(nsDOMEvent) NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMEvent) NS_INTERFACE_MAP_ENTRY(nsIPrivateTextEvent) NS_INTERFACE_MAP_ENTRY(nsIPrivateCompositionEvent) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMouseEvent) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Event) NS_INTERFACE_MAP_END // nsIDOMEventInterface @@ -1387,33 +1413,6 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return nsnull; } -NS_IMETHODIMP -nsDOMEvent::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - if (mEvent && mEvent->eventStructType == NS_MUTATION_EVENT) { - nsISupports *supports = (nsISupports *)(nsIDOMMutationEvent *)this; - res = NS_NewScriptMutationEvent(aContext, supports, nsnull, (void**)&mScriptObject); - } - else { - nsISupports *supports = (nsISupports *)(nsIDOMMouseEvent *)this; - res = NS_NewScriptKeyEvent(aContext, supports, nsnull, (void**)&mScriptObject); - } - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -nsDOMEvent::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, const nsAReadableString& aEventType, diff --git a/content/events/src/nsDOMEvent.h b/content/events/src/nsDOMEvent.h index c73ffa9779c..59ebc1536b3 100644 --- a/content/events/src/nsDOMEvent.h +++ b/content/events/src/nsDOMEvent.h @@ -32,7 +32,6 @@ #include "nsIPrivateTextEvent.h" #include "nsIPrivateTextRange.h" #include "nsIDOMEvent.h" -#include "nsIScriptObjectOwner.h" #include "nsIPresContext.h" #include "nsPoint.h" @@ -45,8 +44,8 @@ class nsDOMEvent : public nsIDOMKeyEvent, public nsIDOMNSUIEvent, public nsIPrivateDOMEvent, public nsIPrivateTextEvent, - public nsIPrivateCompositionEvent, - public nsIScriptObjectOwner { + public nsIPrivateCompositionEvent +{ public: // Note: this enum must be kept in sync with mEventNames in nsDOMEvent.cpp @@ -100,7 +99,8 @@ public: eDOMEvents_characterdatamodified }; - nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsAReadableString& aEventType); + nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, + const nsAReadableString& aEventType); virtual ~nsDOMEvent(); NS_DECL_ISUPPORTS @@ -118,12 +118,15 @@ public: NS_IMETHOD PreventBubble(); NS_IMETHOD PreventCapture(); NS_IMETHOD PreventDefault(); - NS_IMETHOD InitEvent(const nsAReadableString& aEventTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg); + NS_IMETHOD InitEvent(const nsAReadableString& aEventTypeArg, + PRBool aCanBubbleArg, PRBool aCancelableArg); // nsIDOMUIEvent Interface NS_IMETHOD GetView(nsIDOMAbstractView** aView); NS_IMETHOD GetDetail(PRInt32* aDetail); - NS_IMETHOD InitUIEvent(const nsAReadableString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, nsIDOMAbstractView* aViewArg, PRInt32 aDetailArg); + NS_IMETHOD InitUIEvent(const nsAReadableString& aTypeArg, + PRBool aCanBubbleArg, PRBool aCancelableArg, + nsIDOMAbstractView* aViewArg, PRInt32 aDetailArg); // nsIDOMMouseEvent Interface and nsIDOMKeyEvent Interface NS_IMETHOD GetScreenX(PRInt32* aScreenX); @@ -138,9 +141,19 @@ public: NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget); NS_IMETHOD GetCharCode(PRUint32* aCharCode); NS_IMETHOD GetKeyCode(PRUint32* aKeyCode); - NS_IMETHOD InitMouseEvent(const nsAReadableString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg); - NS_IMETHOD InitKeyEvent(const nsAReadableString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRUint32 aKeyCodeArg, PRUint32 aCharCodeArg, nsIDOMAbstractView* aViewArg); - + NS_IMETHOD InitMouseEvent(const nsAReadableString& aTypeArg, + PRBool aCtrlKeyArg, PRBool aAltKeyArg, + PRBool aShiftKeyArg, PRBool aMetaKeyArg, + PRInt32 aScreenXArg, PRInt32 aScreenYArg, + PRInt32 aClientXArg, PRInt32 aClientYArg, + PRUint16 aButtonArg, PRUint16 aDetailArg); + NS_IMETHOD InitKeyEvent(const nsAReadableString& aTypeArg, + PRBool aCanBubbleArg, PRBool aCancelableArg, + PRBool aCtrlKeyArg, PRBool aAltKeyArg, + PRBool aShiftKeyArg, PRBool aMetaKeyArg, + PRUint32 aKeyCodeArg, PRUint32 aCharCodeArg, + nsIDOMAbstractView* aViewArg); + // nsIDOMNSUIEvent interface NS_IMETHOD GetLayerX(PRInt32* aLayerX); NS_IMETHOD GetLayerY(PRInt32* aLayerY); @@ -175,10 +188,6 @@ public: NS_IMETHOD GetCompositionReply(nsTextEventReply** aReply); NS_IMETHOD GetReconversionReply(nsReconversionEventReply** aReply); - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); - /** Overloaded new operator. Initializes the memory to 0. * Relies on a recycler to perform the allocation, * optionally from a pool. @@ -206,7 +215,8 @@ protected: static PRBool gEventPoolInUse; //Internal helper funcs - nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, float* aT2P); + nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, + float* aT2P); nsresult SetEventType(const nsAReadableString& aEventTypeArg); const char* GetEventName(PRUint32 aEventType); diff --git a/content/events/src/nsDOMMutationEvent.cpp b/content/events/src/nsDOMMutationEvent.cpp index 95cb16a62ca..392acd1cfc9 100644 --- a/content/events/src/nsDOMMutationEvent.cpp +++ b/content/events/src/nsDOMMutationEvent.cpp @@ -24,13 +24,14 @@ #include "nsIDOMMutationEvent.h" #include "nsDOMEvent.h" #include "nsMutationEvent.h" +#include "nsContentUtils.h" class nsIPresContext; -class nsDOMMutationEvent : public nsIDOMMutationEvent, public nsDOMEvent +class nsDOMMutationEvent : public nsDOMEvent, public nsIDOMMutationEvent { - NS_DECL_IDOMMUTATIONEVENT - NS_FORWARD_IDOMEVENT(nsDOMEvent::) + NS_DECL_NSIDOMMUTATIONEVENT + NS_FORWARD_NSIDOMEVENT(nsDOMEvent::) NS_DECL_ISUPPORTS_INHERITED @@ -38,12 +39,11 @@ class nsDOMMutationEvent : public nsIDOMMutationEvent, public nsDOMEvent nsEvent* aEvent); ~nsDOMMutationEvent(); - }; nsDOMMutationEvent::nsDOMMutationEvent(nsIPresContext* aPresContext, nsEvent* aEvent) -:nsDOMEvent(aPresContext, aEvent, NS_LITERAL_STRING("MutationEvents")) + :nsDOMEvent(aPresContext, aEvent, NS_LITERAL_STRING("MutationEvents")) { nsMutationEvent* mutation = (nsMutationEvent*)mEvent; SetTarget(mutation->mTarget); @@ -53,16 +53,23 @@ nsDOMMutationEvent::~nsDOMMutationEvent() { } -NS_IMPL_ADDREF_INHERITED(nsDOMMutationEvent, nsDOMEvent) -NS_IMPL_RELEASE_INHERITED(nsDOMMutationEvent, nsDOMEvent) +// XPConnect interface list for nsDOMMutationEvent +NS_CLASSINFO_MAP_BEGIN(MutationEvent) + NS_CLASSINFO_MAP_ENTRY(nsIDOMMutationEvent) +NS_CLASSINFO_MAP_END NS_INTERFACE_MAP_BEGIN(nsDOMMutationEvent) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMutationEvent) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEvent, nsIDOMMutationEvent) NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMEvent) NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MutationEvent) NS_INTERFACE_MAP_END +NS_IMPL_ADDREF_INHERITED(nsDOMMutationEvent, nsDOMEvent) +NS_IMPL_RELEASE_INHERITED(nsDOMMutationEvent, nsDOMEvent) + + NS_IMETHODIMP nsDOMMutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode) { diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index ef777282867..5270f515ec4 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -42,7 +42,6 @@ #include "nsIEventStateManager.h" #include "nsPIDOMWindow.h" #include "nsIPrivateDOMEvent.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptEventListener.h" #include "nsIJSEventListener.h" #include "nsDOMEventsIIDs.h" @@ -54,12 +53,18 @@ #include "nsCOMPtr.h" #include "nsIServiceManager.h" #include "nsIScriptSecurityManager.h" -#include "nsDOMPropEnums.h" #include "nsDOMError.h" #include "nsIJSContextStack.h" #include "nsIDocument.h" #include "nsIPresShell.h" #include "nsMutationEvent.h" +#include "nsIXPConnect.h" +#include "nsIDOMScriptObjectFactory.h" +#include "nsDOMCID.h" +#include "nsIScriptObjectOwner.h" // for nsIScriptEventHandlerOwner + +static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, + NS_DOM_SCRIPT_OBJECT_FACTORY_CID); nsEventListenerManager::nsEventListenerManager() @@ -352,11 +357,13 @@ void nsEventListenerManager::ReleaseListeners(nsVoidArray** aListeners, PRBool a * Sets events listeners of all types. * @param an event listener */ -nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, - EventArrayType aType, - PRInt32 aSubType, - nsHashKey* aKey, - PRInt32 aFlags) + +nsresult +nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, + EventArrayType aType, + PRInt32 aSubType, + nsHashKey* aKey, + PRInt32 aFlags) { NS_ENSURE_TRUE(aListener, NS_ERROR_FAILURE); @@ -445,11 +452,12 @@ nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener return NS_OK; } -nsresult nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener, - EventArrayType aType, - PRInt32 aSubType, - nsHashKey* aKey, - PRInt32 aFlags) +nsresult +nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener, + EventArrayType aType, + PRInt32 aSubType, + nsHashKey* aKey, + PRInt32 aFlags) { nsVoidArray* listeners = GetListenersByType(aType, aKey, PR_FALSE); @@ -515,8 +523,10 @@ nsresult nsEventListenerManager::AddEventListenerByIID(nsIDOMEventListener *aLis return NS_OK; } -nsresult nsEventListenerManager::RemoveEventListenerByIID(nsIDOMEventListener *aListener, - const nsIID& aIID, PRInt32 aFlags) +NS_IMETHODIMP +nsEventListenerManager::RemoveEventListenerByIID(nsIDOMEventListener *aListener, + const nsIID& aIID, + PRInt32 aFlags) { RemoveEventListener(aListener, GetTypeForIID(aIID), NS_EVENT_BITS_NONE, nsnull, aFlags); return NS_OK; @@ -714,8 +724,10 @@ nsresult nsEventListenerManager::GetIdentifiersForType(nsIAtom* aType, EventArra return NS_OK; } -nsresult nsEventListenerManager::AddEventListenerByType(nsIDOMEventListener *aListener, - const nsAReadableString& aType, PRInt32 aFlags) +NS_IMETHODIMP +nsEventListenerManager::AddEventListenerByType(nsIDOMEventListener *aListener, + const nsAReadableString& aType, + PRInt32 aFlags) { PRInt32 subType; EventArrayType arrayType; @@ -739,8 +751,10 @@ nsresult nsEventListenerManager::AddEventListenerByType(nsIDOMEventListener *aLi return NS_OK; } -nsresult nsEventListenerManager::RemoveEventListenerByType(nsIDOMEventListener *aListener, - const nsAReadableString& aType, PRInt32 aFlags) +NS_IMETHODIMP +nsEventListenerManager::RemoveEventListenerByType(nsIDOMEventListener *aListener, + const nsAReadableString& aType, + PRInt32 aFlags) { PRInt32 subType; EventArrayType arrayType; @@ -781,33 +795,42 @@ nsEventListenerManager::FindJSEventListener(EventArrayType aType) return nsnull; } -nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, - nsIScriptObjectOwner *aOwner, - nsIAtom* aName, - PRBool aIsString) +nsresult +nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, + nsISupports *aObject, + nsIAtom* aName, + PRBool aIsString) { - nsresult result = NS_OK; + nsresult rv = NS_OK; nsListenerStruct *ls; PRInt32 flags; EventArrayType arrayType; - NS_ENSURE_SUCCESS(GetIdentifiersForType(aName, &arrayType, &flags), NS_ERROR_FAILURE); - + NS_ENSURE_SUCCESS(GetIdentifiersForType(aName, &arrayType, &flags), + NS_ERROR_FAILURE); + ls = FindJSEventListener(arrayType); if (nsnull == ls) { - //If we didn't find a script listener or no listeners existed create and add a new one. - nsIDOMEventListener* scriptListener; - result = NS_NewJSEventListener(&scriptListener, aContext, aOwner); - if (NS_SUCCEEDED(result)) { - AddEventListener(scriptListener, arrayType, NS_EVENT_BITS_NONE, nsnull, NS_EVENT_FLAG_BUBBLE | NS_PRIV_EVENT_FLAG_SCRIPT); - NS_RELEASE(scriptListener); + //If we didn't find a script listener or no listeners existed + //create and add a new one. + nsCOMPtr factory = + do_GetService(kDOMScriptObjectFactoryCID); + NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE); + + nsCOMPtr scriptListener; + rv = factory->NewJSEventListener(aContext, aObject, + getter_AddRefs(scriptListener)); + if (NS_SUCCEEDED(rv)) { + AddEventListener(scriptListener, arrayType, NS_EVENT_BITS_NONE, nsnull, + NS_EVENT_FLAG_BUBBLE | NS_PRIV_EVENT_FLAG_SCRIPT); + ls = FindJSEventListener(arrayType); } } - if (NS_SUCCEEDED(result) && ls) { - //Set flag to indicate possible need for compilation later + if (NS_SUCCEEDED(rv) && ls) { + // Set flag to indicate possible need for compilation later if (aIsString) { ls->mHandlerIsString |= flags; } @@ -819,25 +842,37 @@ nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, ls->mSubType |= flags; } - return result; + return rv; } -nsresult +NS_IMETHODIMP nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext, - nsIScriptObjectOwner *aScriptObjectOwner, + nsISupports *aObject, nsIAtom *aName, const nsAReadableString& aBody, PRBool aDeferCompilation) { - JSObject *scriptObject; nsresult rv; - - if (!aDeferCompilation) { - rv = aScriptObjectOwner->GetScriptObject(aContext, (void**)&scriptObject); - if (NS_FAILED(rv)) - return rv; - nsCOMPtr handlerOwner = do_QueryInterface(aScriptObjectOwner); + if (!aDeferCompilation) { + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID())); + + JSContext *cx = (JSContext *)aContext->GetNativeContext(); + + nsCOMPtr holder; + + rv = xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), aObject, + NS_GET_IID(nsISupports), getter_AddRefs(holder)); + NS_ENSURE_SUCCESS(rv, rv); + + JSObject *scriptObject = nsnull; + + rv = holder->GetJSObject(&scriptObject); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr handlerOwner = + do_QueryInterface(aObject); + void *handler = nsnull; PRBool done = PR_FALSE; @@ -855,7 +890,8 @@ nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext, if (handlerOwner) { // Always let the handler owner compile the event handler, as // it may want to use a special context or scope object. - rv = handlerOwner->CompileEventHandler(aContext, scriptObject, aName, aBody, &handler); + rv = handlerOwner->CompileEventHandler(aContext, scriptObject, aName, + aBody, &handler); } else { rv = aContext->CompileEventHandler(scriptObject, aName, aBody, @@ -865,7 +901,8 @@ nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext, if (NS_FAILED(rv)) return rv; } } - return SetJSEventListener(aContext, aScriptObjectOwner, aName, aDeferCompilation); + + return SetJSEventListener(aContext, aObject, aName, aDeferCompilation); } nsresult @@ -876,7 +913,8 @@ nsEventListenerManager::RemoveScriptEventListener(nsIAtom *aName) PRInt32 flags; EventArrayType arrayType; - NS_ENSURE_SUCCESS(GetIdentifiersForType(aName, &arrayType, &flags), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(GetIdentifiersForType(aName, &arrayType, &flags), + NS_ERROR_FAILURE); ls = FindJSEventListener(arrayType); if (ls) { @@ -896,80 +934,118 @@ nsEventListenerManager::RemoveScriptEventListener(nsIAtom *aName) return result; } -nsresult -nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext, - nsIScriptObjectOwner *aScriptObjectOwner, +NS_IMETHODIMP +nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext, + nsISupports *aObject, nsIAtom *aName) { - // Check that we have access to set an event listener. Prevents snooping attacks across - // domains by setting onkeypress handlers, for instance. - // You'd think it'd work just to get the JSContext from aContext, but that's actually the - // JSContext whose private object parents the object in aScriptObjectOwner. + // Check that we have access to set an event listener. Prevents + // snooping attacks across domains by setting onkeypress handlers, + // for instance. + // You'd think it'd work just to get the JSContext from aContext, + // but that's actually the JSContext whose private object parents + // the object in aObject. nsresult rv; - NS_WITH_SERVICE(nsIJSContextStack, stack, "@mozilla.org/js/xpc/ContextStack;1", - &rv); + nsCOMPtr stack = + do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv); if (NS_FAILED(rv)) return rv; JSContext *cx; if (NS_FAILED(stack->Peek(&cx))) return nsnull; - JSObject *jsobj; - if (NS_FAILED(rv = aScriptObjectOwner->GetScriptObject(aContext, (void**)&jsobj))) - return rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, - NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + + JSContext *current_cx = (JSContext *)aContext->GetNativeContext(); + + nsCOMPtr holder; + + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID())); + rv = xpc->WrapNative(current_cx, ::JS_GetGlobalObject(current_cx), aObject, + NS_GET_IID(nsISupports), getter_AddRefs(holder)); + NS_ENSURE_SUCCESS(rv, rv); + + JSObject *jsobj = nsnull; + + rv = holder->GetJSObject(&jsobj); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr securityManager = + do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; - if (NS_FAILED(rv = securityManager->CheckScriptAccess(cx, jsobj, - NS_DOM_PROP_EVENTTARGET_ADDEVENTLISTENER, PR_TRUE))) - { + + if (NS_FAILED(rv = securityManager->CheckPropertyAccess( + nsIXPCSecurityManager::ACCESS_SET_PROPERTY, cx, jsobj, aObject, nsnull, + "EventTarget","addEventListener", PR_FALSE))) { + // XXX set pending exception on the native call context? return rv; } - return SetJSEventListener(aContext, aScriptObjectOwner, aName, PR_FALSE); + + return SetJSEventListener(aContext, aObject, aName, PR_FALSE); } nsresult nsEventListenerManager::CompileScriptEventListener(nsIScriptContext *aContext, - nsIScriptObjectOwner *aScriptObjectOwner, - nsIAtom *aName) + nsISupports *aObject, + nsIAtom *aName, + PRBool *aDidCompile) { - nsresult result = NS_OK; + nsresult rv = NS_OK; nsListenerStruct *ls; PRInt32 subType; EventArrayType arrayType; - result = GetIdentifiersForType(aName, &arrayType, &subType); - if (NS_SUCCEEDED(result)) { - ls = FindJSEventListener(arrayType); - if (!ls) { - //nothing to compile - return NS_OK; - } + *aDidCompile = PR_FALSE; - if (ls->mHandlerIsString & subType) { - result = CompileEventHandlerInternal(aContext, aScriptObjectOwner, aName, ls, subType); - } + rv = GetIdentifiersForType(aName, &arrayType, &subType); + NS_ENSURE_SUCCESS(rv, rv); + + ls = FindJSEventListener(arrayType); + + if (!ls) { + //nothing to compile + return NS_OK; } - return result; + if (ls->mHandlerIsString & subType) { + rv = CompileEventHandlerInternal(aContext, aObject, aName, ls, subType); + } + + // Set *aDidCompile to true even if we didn't really compile + // anything right now, if we get here it means that this event + // handler has been compiled at some point, that's good enough for + // us. + + *aDidCompile = PR_TRUE; + + return rv; } nsresult nsEventListenerManager::CompileEventHandlerInternal(nsIScriptContext *aContext, - nsIScriptObjectOwner *aScriptObjectOwner, + nsISupports *aObject, nsIAtom *aName, nsListenerStruct *aListenerStruct, PRUint32 aSubType) { nsresult result = NS_OK; - JSObject* jsobj; - result = aScriptObjectOwner->GetScriptObject(aContext, (void**)&jsobj); - if (NS_FAILED(result)) { - return NS_ERROR_FAILURE; - } + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID())); - nsCOMPtr handlerOwner = do_QueryInterface(aScriptObjectOwner); + JSContext *cx = (JSContext *)aContext->GetNativeContext(); + + nsCOMPtr holder; + + result = xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), aObject, + NS_GET_IID(nsISupports), getter_AddRefs(holder)); + NS_ENSURE_SUCCESS(result, result); + + JSObject *jsobj = nsnull; + + result = holder->GetJSObject(&jsobj); + NS_ENSURE_SUCCESS(result, result); + + nsCOMPtr handlerOwner = + do_QueryInterface(aObject); void* handler = nsnull; if (handlerOwner) { @@ -985,25 +1061,29 @@ nsEventListenerManager::CompileEventHandlerInternal(nsIScriptContext *aContext, // XXX I don't like that we have to reference content // from here. The alternative is to store the event handler // string on the JS object itself. - nsCOMPtr content = do_QueryInterface(aScriptObjectOwner); + nsCOMPtr content = do_QueryInterface(aObject); NS_ASSERTION(content, "only content should have event handler attributes"); if (content) { nsAutoString handlerBody; result = content->GetAttribute(kNameSpaceID_None, aName, handlerBody); + if (NS_SUCCEEDED(result)) { if (handlerOwner) { // Always let the handler owner compile the event // handler, as it may want to use a special // context or scope object. - result = handlerOwner->CompileEventHandler(aContext, jsobj, aName, handlerBody, &handler); + result = handlerOwner->CompileEventHandler(aContext, jsobj, aName, + handlerBody, &handler); } else { result = aContext->CompileEventHandler(jsobj, aName, handlerBody, (handlerOwner != nsnull), &handler); } - if (NS_SUCCEEDED(result)) + + if (NS_SUCCEEDED(result)) { aListenerStruct->mHandlerIsString &= ~aSubType; + } } } } @@ -1040,9 +1120,10 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct, nsCOMPtr jslistener = do_QueryInterface(aListenerStruct->mListener); if (jslistener) { - nsCOMPtr owner; + nsCOMPtr target; nsCOMPtr scriptCX; - result = jslistener->GetEventTarget(getter_AddRefs(scriptCX), getter_AddRefs(owner)); + result = jslistener->GetEventTarget(getter_AddRefs(scriptCX), + getter_AddRefs(target)); if (NS_SUCCEEDED(result)) { nsAutoString eventString; @@ -1050,7 +1131,8 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct, eventString.InsertWithConversion("on", 0, 2); nsCOMPtr atom = getter_AddRefs(NS_NewAtom(eventString)); - result = CompileEventHandlerInternal(scriptCX, owner, atom, aListenerStruct, aSubType); + result = CompileEventHandlerInternal(scriptCX, target, atom, + aListenerStruct, aSubType); } } } @@ -2112,10 +2194,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, /** * Creates a DOM event */ -nsresult nsEventListenerManager::CreateEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - const nsAReadableString& aEventType, - nsIDOMEvent** aDOMEvent) + +NS_IMETHODIMP +nsEventListenerManager::CreateEvent(nsIPresContext* aPresContext, + nsEvent* aEvent, + const nsAReadableString& aEventType, + nsIDOMEvent** aDOMEvent) { nsAutoString str(aEventType); if (!aEvent && !str.EqualsIgnoreCase("MouseEvents") && !str.EqualsIgnoreCase("KeyEvents") && @@ -2135,7 +2219,8 @@ nsresult nsEventListenerManager::CreateEvent(nsIPresContext* aPresContext, * @param an event listener */ -nsresult nsEventListenerManager::CaptureEvent(PRInt32 aEventTypes) +NS_IMETHODIMP +nsEventListenerManager::CaptureEvent(PRInt32 aEventTypes) { return FlipCaptureBit(aEventTypes, PR_TRUE); } @@ -2145,7 +2230,8 @@ nsresult nsEventListenerManager::CaptureEvent(PRInt32 aEventTypes) * @param an event listener */ -nsresult nsEventListenerManager::ReleaseEvent(PRInt32 aEventTypes) +NS_IMETHODIMP +nsEventListenerManager::ReleaseEvent(PRInt32 aEventTypes) { return FlipCaptureBit(aEventTypes, PR_FALSE); } @@ -2374,7 +2460,8 @@ nsresult nsEventListenerManager::FlipCaptureBit(PRInt32 aEventTypes, PRBool aIni return NS_OK; } -nsresult nsEventListenerManager::SetListenerTarget(nsISupports* aTarget) +NS_IMETHODIMP +nsEventListenerManager::SetListenerTarget(nsISupports* aTarget) { //WEAK reference, must be set back to nsnull when done mTarget = aTarget; @@ -2469,18 +2556,15 @@ nsEventListenerManager::HandleEvent(nsIDOMEvent *aEvent) return DispatchEvent(aEvent); } -NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult) +nsresult +NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult) { nsIEventListenerManager* l = new nsEventListenerManager(); - if (nsnull == l) { + if (!l) { return NS_ERROR_OUT_OF_MEMORY; } - if (NS_OK == l->QueryInterface(NS_GET_IID(nsIEventListenerManager), (void**) aInstancePtrResult)) { - return NS_OK; - } - - return NS_ERROR_FAILURE; + return CallQueryInterface(l, aInstancePtrResult); } diff --git a/content/events/src/nsEventListenerManager.h b/content/events/src/nsEventListenerManager.h index 96ab39d8bcf..59ead64a89c 100644 --- a/content/events/src/nsEventListenerManager.h +++ b/content/events/src/nsEventListenerManager.h @@ -95,48 +95,58 @@ public: * Sets events listeners of all types. * @param an event listener */ + NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, + const nsIID& aIID, PRInt32 aFlags); + NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, + const nsIID& aIID, PRInt32 aFlags); + NS_IMETHOD AddEventListenerByType(nsIDOMEventListener *aListener, + const nsAReadableString& type, + PRInt32 aFlags); + NS_IMETHOD RemoveEventListenerByType(nsIDOMEventListener *aListener, + const nsAReadableString& type, + PRInt32 aFlags) ; + NS_IMETHOD AddScriptEventListener(nsIScriptContext*aContext, + nsISupports *aObject, + nsIAtom *aName, + const nsAReadableString& aFunc, + PRBool aDeferCompilation); + NS_IMETHOD RegisterScriptEventListener(nsIScriptContext *aContext, + nsISupports *aObject, + nsIAtom* aName); + NS_IMETHOD RemoveScriptEventListener(nsIAtom *aName); + NS_IMETHOD CompileScriptEventListener(nsIScriptContext *aContext, + nsISupports *aObject, + nsIAtom* aName, PRBool *aDidCompile); - virtual nsresult AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags); - virtual nsresult RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags); - virtual nsresult AddEventListenerByType(nsIDOMEventListener *aListener, const nsAReadableString& type, PRInt32 aFlags); - virtual nsresult RemoveEventListenerByType(nsIDOMEventListener *aListener, const nsAReadableString& type, PRInt32 aFlags) ; + NS_IMETHOD CaptureEvent(PRInt32 aEventTypes); + NS_IMETHOD ReleaseEvent(PRInt32 aEventTypes); - virtual nsresult AddScriptEventListener(nsIScriptContext*aContext, - nsIScriptObjectOwner *aScriptObjectOwner, - nsIAtom *aName, - const nsAReadableString& aFunc, - PRBool aDeferCompilation); - virtual nsresult RemoveScriptEventListener(nsIAtom *aName); - virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext, - nsIScriptObjectOwner *aScriptObjectOwner, - nsIAtom* aName); - virtual nsresult CompileScriptEventListener(nsIScriptContext *aContext, - nsIScriptObjectOwner *aScriptObjectOwner, - nsIAtom* aName); + NS_IMETHOD HandleEvent(nsIPresContext* aPresContext, + nsEvent* aEvent, + nsIDOMEvent** aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, + PRUint32 aFlags, + nsEventStatus* aEventStatus); + NS_IMETHOD CreateEvent(nsIPresContext* aPresContext, + nsEvent* aEvent, + const nsAReadableString& aEventType, + nsIDOMEvent** aDOMEvent); - virtual nsresult CaptureEvent(PRInt32 aEventTypes); - virtual nsresult ReleaseEvent(PRInt32 aEventTypes); + NS_IMETHOD RemoveAllListeners(PRBool aScriptOnly); - virtual nsresult HandleEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - nsIDOMEventTarget* aCurrentTarget, - PRUint32 aFlags, - nsEventStatus* aEventStatus); + NS_IMETHOD SetListenerTarget(nsISupports* aTarget); - virtual nsresult CreateEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - const nsAReadableString& aEventType, - nsIDOMEvent** aDOMEvent); + NS_IMETHOD HasMutationListeners(PRBool* aListener) + { + *aListener = (GetListenersByType(eEventArrayType_Mutation, nsnull, + PR_FALSE) != nsnull); + return NS_OK; + } - virtual nsresult RemoveAllListeners(PRBool aScriptOnly); - - virtual nsresult SetListenerTarget(nsISupports* aTarget); - - virtual nsresult HasMutationListeners(PRBool* aListener) { *aListener = (GetListenersByType(eEventArrayType_Mutation, nsnull, PR_FALSE) != nsnull); return NS_OK; }; - - static nsresult GetIdentifiersForType(nsIAtom* aType, EventArrayType* aArrayType, PRInt32* aSubType); + static nsresult GetIdentifiersForType(nsIAtom* aType, + EventArrayType* aArrayType, + PRInt32* aSubType); // nsIDOMEventTarget interface NS_IMETHOD AddEventListener(const nsAReadableString& aType, @@ -148,8 +158,10 @@ public: NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); // nsIDOMEventReceiver interface - NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); - NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); + NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, + const nsIID& aIID); + NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, + const nsIID& aIID); NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult); NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult); NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent); @@ -161,12 +173,14 @@ protected: PRUint32 aSubType, PRUint32 aPhaseFlags); nsresult CompileEventHandlerInternal(nsIScriptContext *aContext, - nsIScriptObjectOwner *aScriptObjectOwner, + nsISupports *aObject, nsIAtom *aName, nsListenerStruct *aListenerStruct, PRUint32 aSubType); nsListenerStruct* FindJSEventListener(EventArrayType aType); - nsresult SetJSEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aOwner, nsIAtom* aName, PRBool aIsString); + nsresult SetJSEventListener(nsIScriptContext *aContext, + nsISupports *aObject, nsIAtom* aName, + PRBool aIsString); nsresult AddEventListener(nsIDOMEventListener *aListener, EventArrayType aType, PRInt32 aSubType, diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index a260b30e790..9e14c1359c7 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -73,7 +73,7 @@ #include "nsITreeFrame.h" #include "nsIOutlinerBoxObject.h" #include "nsIScrollableViewProvider.h" -#include "nsIDOMNSDocument.h" +#include "nsIDOMDocumentRange.h" #include "nsIDOMRange.h" #include "nsICaret.h" @@ -1057,8 +1057,8 @@ nsEventStateManager::ChangeTextSize(PRInt32 change) ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow)); if(!rootWindow) return NS_ERROR_FAILURE; - nsCOMPtr windowContent; - rootWindow->Get_content(getter_AddRefs(windowContent)); + nsCOMPtr windowContent; + rootWindow->GetContent(getter_AddRefs(windowContent)); if(!windowContent) return NS_ERROR_FAILURE; nsCOMPtr domDoc; @@ -1090,7 +1090,7 @@ nsEventStateManager::ChangeTextSize(PRInt32 change) float textzoom; mv->GetTextZoom(&textzoom); - textzoom += 0.1*change; + textzoom += ((float)change) / 10; if (textzoom > 0 && textzoom <= 20) mv->SetTextZoom(textzoom); @@ -3705,7 +3705,7 @@ nsresult nsEventStateManager::MoveCaretToFocus() mPresContext->GetShell(getter_AddRefs(shell)); if (shell) { // rangeDoc is a document interface we can create a range with - nsCOMPtr rangeDoc(do_QueryInterface(mDocument)); + nsCOMPtr rangeDoc(do_QueryInterface(mDocument)); nsCOMPtr currentFocusNode(do_QueryInterface(mCurrentFocus)); nsCOMPtr frameSelection; shell->GetFrameSelection(getter_AddRefs(frameSelection)); @@ -3717,7 +3717,7 @@ nsresult nsEventStateManager::MoveCaretToFocus() getter_AddRefs(domSelection)); if (domSelection) { // First clear the selection - domSelection ->RemoveAllRanges(); + domSelection->RemoveAllRanges(); nsCOMPtr newRange; nsresult rv = rangeDoc->CreateRange(getter_AddRefs(newRange)); if (NS_SUCCEEDED(rv)) { diff --git a/content/events/src/nsPrivateTextRange.h b/content/events/src/nsPrivateTextRange.h index 6e433f70ad3..3a63d05dec9 100644 --- a/content/events/src/nsPrivateTextRange.h +++ b/content/events/src/nsPrivateTextRange.h @@ -54,7 +54,7 @@ class nsPrivateTextRangeList: public nsIPrivateTextRangeList NS_DECL_ISUPPORTS public: - nsPrivateTextRangeList(PRUint16 aLength,nsIPrivateTextRange** aList); + nsPrivateTextRangeList(PRUint16 aLength, nsIPrivateTextRange** aList); virtual ~nsPrivateTextRangeList(void); NS_IMETHOD GetLength(PRUint16* aLength); diff --git a/content/html/content/public/nsIForm.h b/content/html/content/public/nsIForm.h index 336c35c7ad2..5e772fcfe4c 100644 --- a/content/html/content/public/nsIForm.h +++ b/content/html/content/public/nsIForm.h @@ -23,26 +23,32 @@ #define nsIForm_h___ #include "nsISupports.h" -#include "nsString.h" +#include "nsAReadableString.h" + class nsIFormControl; class nsISizeOfHandler; + #define NS_FORM_METHOD_GET 0 #define NS_FORM_METHOD_POST 1 #define NS_FORM_ENCTYPE_URLENCODED 0 #define NS_FORM_ENCTYPE_MULTIPART 1 + // IID for the nsIFormManager interface #define NS_IFORM_IID \ { 0xb7e94510, 0x4c19, 0x11d2, \ { 0x80, 0x3f, 0x0, 0x60, 0x8, 0x15, 0xa7, 0x91 } } + /** * This interface provides a complete set of methods dealing with * elements which belong to a form element. When nsIDOMHTMLCollection * allows write operations */ -class nsIForm : public nsISupports { + +class nsIForm : public nsISupports +{ public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFORM_IID) @@ -60,7 +66,8 @@ public: * attributes. The name or id attributes of the form control * are used as a key into the table. */ - NS_IMETHOD AddElementToTable(nsIFormControl* aElement, const nsAReadableString& aName) = 0; + NS_IMETHOD AddElementToTable(nsIFormControl* aElement, + const nsAReadableString& aName) = 0; /** * Get the element at a specified index position @@ -84,7 +91,7 @@ public: */ NS_IMETHOD RemoveElement(nsIFormControl* aElement) = 0; - /** + /** * Remove an element from the lookup table mainted by the form. * We can't fold this method into RemoveElement() because when * RemoveElement() is called it doesn't know if the element is @@ -95,7 +102,20 @@ public: * @param aName the name or id of the element to remove * @return NS_OK if the element was successfully removed. */ - NS_IMETHOD RemoveElementFromTable(nsIFormControl* aElement, const nsAReadableString& aName) = 0; + NS_IMETHOD RemoveElementFromTable(nsIFormControl* aElement, + const nsAReadableString& aName) = 0; + + /** + * Resolve a name in the scope of the form object, this means find + * form controls in this form with the correct value in the name + * attribute. + * + * @param aElement the element to remove + * @param aName the name or id of the element to remove + * @return NS_OK if the element was successfully removed. */ + NS_IMETHOD ResolveName(const nsAReadableString& aName, + nsISupports **aResult) = 0; + NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const = 0; }; diff --git a/content/html/content/src/GenericElementCollection.h b/content/html/content/src/GenericElementCollection.h index 267376892c3..2fd06e28235 100644 --- a/content/html/content/src/GenericElementCollection.h +++ b/content/html/content/src/GenericElementCollection.h @@ -27,6 +27,7 @@ class nsIContent; class nsIAtom; +class nsISizeOfHandler; /** * This class provides a late-bound collection of elements that are diff --git a/content/html/content/src/nsAttributeContent.cpp b/content/html/content/src/nsAttributeContent.cpp index a8b4a74e7fa..e1ba93aab7e 100644 --- a/content/html/content/src/nsAttributeContent.cpp +++ b/content/html/content/src/nsAttributeContent.cpp @@ -118,6 +118,10 @@ public: return NS_OK; } + NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags) { + return !(aFlags & ~eTEXT); + } + NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, const nsAReadableString& aValue, PRBool aNotify) { return NS_OK; } NS_IMETHOD SetAttribute(nsINodeInfo *aNodeInfo, const nsAReadableString& aValue, diff --git a/content/html/content/src/nsGenericDOMHTMLCollection.cpp b/content/html/content/src/nsGenericDOMHTMLCollection.cpp index a587476d5af..5095cbd8e6d 100644 --- a/content/html/content/src/nsGenericDOMHTMLCollection.cpp +++ b/content/html/content/src/nsGenericDOMHTMLCollection.cpp @@ -26,54 +26,16 @@ nsGenericDOMHTMLCollection::nsGenericDOMHTMLCollection() { NS_INIT_REFCNT(); - mScriptObject = nsnull; } nsGenericDOMHTMLCollection::~nsGenericDOMHTMLCollection() { } -nsresult -nsGenericDOMHTMLCollection::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsIDOMHTMLCollection))) { - *aInstancePtr = (void*)(nsIDOMHTMLCollection*)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - *aInstancePtr = (void*)(nsIScriptObjectOwner*)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsISupports))) { - *aInstancePtr = (void*)(nsISupports*)(nsIDOMHTMLCollection*)this; - AddRef(); - return NS_OK; - } - return NS_NOINTERFACE; -} - NS_IMPL_ADDREF(nsGenericDOMHTMLCollection) NS_IMPL_RELEASE(nsGenericDOMHTMLCollection) -NS_IMETHODIMP -nsGenericDOMHTMLCollection::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - res = NS_NewScriptHTMLCollection(aContext, (nsISupports *)(nsIDOMHTMLCollection *)this, nsnull, (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - return res; -} - -NS_IMETHODIMP -nsGenericDOMHTMLCollection::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} +NS_INTERFACE_MAP_BEGIN(nsGenericDOMHTMLCollection) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection) + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END diff --git a/content/html/content/src/nsGenericDOMHTMLCollection.h b/content/html/content/src/nsGenericDOMHTMLCollection.h index 838ef1ff79b..f91827e72b0 100644 --- a/content/html/content/src/nsGenericDOMHTMLCollection.h +++ b/content/html/content/src/nsGenericDOMHTMLCollection.h @@ -25,20 +25,18 @@ #include "nsISupports.h" #include "nsIDOMHTMLCollection.h" -#include "nsIScriptObjectOwner.h" /** * This is a base class for a generic HTML collection. The base class - * provides implementations for nsISupports and nsIScriptObjectOwner, - * but it is up to the subclass to implement the core HTML collection + * provides implementations for nsISupports, but it is up to the + * subclass to implement the core HTML collection + * * methods: * GetLength * Item * NamedItem - * - */ -class nsGenericDOMHTMLCollection : public nsIDOMHTMLCollection, - public nsIScriptObjectOwner + * */ +class nsGenericDOMHTMLCollection : public nsIDOMHTMLCollection { public: nsGenericDOMHTMLCollection(); @@ -46,17 +44,11 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - // The following need to be defined in the subclass // nsIDOMHTMLCollection interface NS_IMETHOD GetLength(PRUint32* aLength)=0; NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn)=0; NS_IMETHOD NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn)=0; - -protected: - void* mScriptObject; }; #endif // nsGenericDOMHTMLCollection_h__ diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 4a040ab15f9..81f15ed834f 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -17,7 +17,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): */ #include "nsGenericHTMLElement.h" #include "nsCOMPtr.h" @@ -35,6 +35,8 @@ #include "nsIDOMNamedNodeMap.h" #include "nsIDOMNodeList.h" #include "nsIDOMDocumentFragment.h" +#include "nsIDOMNSHTMLElement.h" +#include "nsIDOMElementCSSInlineStyle.h" #include "nsIEventListenerManager.h" #include "nsIHTMLAttributes.h" #include "nsIHTMLStyleSheet.h" @@ -43,8 +45,6 @@ #include "nsILink.h" #include "nsILinkHandler.h" #include "nsPIDOMWindow.h" -#include "nsIScriptGlobalObject.h" -#include "nsIScriptObjectOwner.h" #include "nsISizeOfHandler.h" #include "nsIStyleContext.h" #include "nsIMutableStyleContext.h" @@ -77,7 +77,6 @@ #include "nsIPrivateDOMEvent.h" #include "nsDOMCID.h" #include "nsIServiceManager.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsIDOMCSSStyleDeclaration.h" #include "nsDOMCSSDeclaration.h" #include "prprf.h" @@ -108,10 +107,12 @@ #include "nsIHTMLContentSink.h" #include "nsLayoutCID.h" #include "nsContentCID.h" + static NS_DEFINE_CID(kPresStateCID, NS_PRESSTATE_CID); // XXX todo: add in missing out-of-memory checks #include "nsIPref.h" // Used by the temp pref, should be removed! + #include "nsIPluginHost.h" #include "nsPIPluginHost.h" static NS_DEFINE_IID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); @@ -406,6 +407,65 @@ static int gGenericHTMLElementCount = 0; static nsILanguageAtomService* gLangService = nsnull; +class nsGenericHTMLElementTearoff : public nsIDOMNSHTMLElement, + public nsIDOMElementCSSInlineStyle +{ + NS_DECL_ISUPPORTS + + nsGenericHTMLElementTearoff(nsGenericHTMLElement *aElement) + : mElement(aElement) + { + NS_INIT_REFCNT(); + NS_ADDREF(mElement); + } + + ~nsGenericHTMLElementTearoff() + { + NS_RELEASE(mElement); + } + + NS_FORWARD_NSIDOMNSHTMLELEMENT(mElement->) + NS_FORWARD_NSIDOMELEMENTCSSINLINESTYLE(mElement->) + +private: + nsGenericHTMLElement *mElement; +}; + + +NS_IMPL_ADDREF(nsGenericHTMLElementTearoff) +NS_IMPL_RELEASE(nsGenericHTMLElementTearoff) + +NS_IMETHODIMP +nsGenericHTMLElementTearoff::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + NS_ENSURE_ARG_POINTER(aInstancePtr); + + nsISupports *inst = nsnull; + + if (aIID.Equals(NS_GET_IID(nsIDOMNSHTMLElement))) { + inst = NS_STATIC_CAST(nsIDOMNSHTMLElement *, this); + } else if (aIID.Equals(NS_GET_IID(nsIDOMElementCSSInlineStyle))) { + inst = NS_STATIC_CAST(nsIDOMElementCSSInlineStyle *, this); + } else { + return mElement->QueryInterface(aIID, aInstancePtr); + } + + NS_ADDREF(inst); + + *aInstancePtr = inst; + + return NS_OK; +} + + +// XPConnect interface list for nsGenericHTMLElement +NS_CLASSINFO_MAP_BEGIN_EXPORTED(GenericHTMLElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMElementCSSInlineStyle) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) +NS_CLASSINFO_MAP_END + + nsGenericHTMLElement::nsGenericHTMLElement() { mAttributes = nsnull; @@ -455,6 +515,17 @@ nsGenericHTMLElement::DOMQueryInterface(nsIDOMHTMLElement *aElement, inst = NS_STATIC_CAST(nsIDOMElement *, aElement); } else if (aIID.Equals(NS_GET_IID(nsIDOMHTMLElement))) { inst = NS_STATIC_CAST(nsIDOMHTMLElement *, aElement); + } else if (aIID.Equals(NS_GET_IID(nsIDOMNSHTMLElement))) { + inst = NS_STATIC_CAST(nsIDOMNSHTMLElement *, + new nsGenericHTMLElementTearoff(this)); + NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY); + } else if (aIID.Equals(NS_GET_IID(nsIDOMElementCSSInlineStyle))) { + inst = NS_STATIC_CAST(nsIDOMElementCSSInlineStyle *, + new nsGenericHTMLElementTearoff(this)); + NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY); + } else if (aIID.Equals(NS_GET_IID(nsIDOMElementCSSInlineStyle))) { + inst = new nsNode3Tearoff(this); + NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY); } else { return NS_NOINTERFACE; } @@ -1396,8 +1467,10 @@ nsGenericHTMLElement::SetAttribute(PRInt32 aNameSpaceID, mutation.mPrevAttrValue = getter_AddRefs(NS_NewAtom(strValue)); if (!aValue.IsEmpty()) mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(aValue)); - mutation.mAttrChange = modification ? nsIDOMMutationEvent::MODIFICATION : - nsIDOMMutationEvent::ADDITION; + if (modification) + mutation.mAttrChange = nsIDOMMutationEvent::MODIFICATION; + else + mutation.mAttrChange = nsIDOMMutationEvent::ADDITION; nsEventStatus status = nsEventStatus_eIgnore; HandleDOMEvent(nsnull, &mutation, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -2068,6 +2141,13 @@ nsGenericHTMLElement::DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) co return NS_OK; } + +NS_IMETHODIMP_(PRBool) +nsGenericHTMLElement::IsContentOfType(PRUint32 aFlags) +{ + return !(aFlags & ~(eELEMENT | eHTML)); +} + PRUint32 nsGenericHTMLElement::BaseSizeOf(nsISizeOfHandler* aSizer) const { @@ -3308,15 +3388,15 @@ nsGenericHTMLLeafElement::GetChildNodes(nsIDOMNodeList** aChildNodes) { nsDOMSlots* slots = GetDOMSlots(); - if (nsnull == slots->mChildNodes) { + if (!slots->mChildNodes) { slots->mChildNodes = new nsChildContentList(nsnull); - if (nsnull == slots->mChildNodes) { + if (!slots->mChildNodes) { return NS_ERROR_OUT_OF_MEMORY; } NS_ADDREF(slots->mChildNodes); } - return slots->mChildNodes->QueryInterface(NS_GET_IID(nsIDOMNodeList), (void **)aChildNodes); + return CallQueryInterface(slots->mChildNodes, aChildNodes); } //---------------------------------------------------------------------- @@ -3674,6 +3754,12 @@ nsGenericHTMLContainerFormElement::QueryInterface(REFNSIID aIID, return NS_OK; } +NS_IMETHODIMP_(PRBool) +nsGenericHTMLContainerFormElement::IsContentOfType(PRUint32 aFlags) +{ + return !(aFlags & ~(eELEMENT | eHTML | eHTML_FORM_CONTROL)); +} + NS_IMETHODIMP nsGenericHTMLContainerFormElement::SetForm(nsIDOMHTMLFormElement* aForm, PRBool aRemoveFromForm) @@ -3734,40 +3820,6 @@ nsGenericHTMLContainerFormElement::GetForm(nsIDOMHTMLFormElement** aForm) return NS_OK; } -NS_IMETHODIMP -nsGenericHTMLContainerFormElement::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - NS_ENSURE_ARG_POINTER(aScriptObject); - - if (mDOMSlots && mDOMSlots->mScriptObject) { - *aScriptObject = mDOMSlots->mScriptObject; - - return NS_OK; - } - - nsresult rv = nsGenericElement::GetScriptObject(aContext, aScriptObject); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(*aScriptObject, NS_ERROR_FAILURE); - - // If there's a form associated with this control we set the form as parent - // object for this controls script object. - nsCOMPtr owner(do_QueryInterface(mForm)); - - if (owner) { - JSContext *ctx = (JSContext *)aContext->GetNativeContext(); - JSObject *parent = nsnull; - - rv = owner->GetScriptObject(aContext, (void **)&parent); - - if (NS_SUCCEEDED(rv) && parent) { - ::JS_SetParent(ctx, (JSObject *)*aScriptObject, parent); - } - } - - return rv; -} - NS_IMETHODIMP nsGenericHTMLContainerFormElement::SetParent(nsIContent* aParent) { @@ -3927,6 +3979,12 @@ nsGenericHTMLLeafFormElement::QueryInterface(REFNSIID aIID, return NS_OK; } +NS_IMETHODIMP_(PRBool) +nsGenericHTMLLeafFormElement::IsContentOfType(PRUint32 aFlags) +{ + return !(aFlags & ~(eELEMENT | eHTML | eHTML_FORM_CONTROL)); +} + NS_IMETHODIMP nsGenericHTMLLeafFormElement::SetForm(nsIDOMHTMLFormElement* aForm, PRBool aRemoveFromForm) @@ -4031,40 +4089,6 @@ nsGenericHTMLLeafFormElement::SetDocument(nsIDocument* aDocument, return rv; } -NS_IMETHODIMP -nsGenericHTMLLeafFormElement::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - NS_ENSURE_ARG_POINTER(aScriptObject); - - if (mDOMSlots && mDOMSlots->mScriptObject) { - *aScriptObject = mDOMSlots->mScriptObject; - - return NS_OK; - } - - nsresult rv = nsGenericElement::GetScriptObject(aContext, aScriptObject); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(*aScriptObject, NS_ERROR_FAILURE); - - nsCOMPtr owner(do_QueryInterface(mForm)); - - // If there's a form associated with this control we set the form as parent - // object for this controls script object. - if (owner) { - JSContext *ctx = (JSContext *)aContext->GetNativeContext(); - JSObject *parent = nsnull; - - rv = owner->GetScriptObject(aContext, (void **)&parent); - - if (NS_SUCCEEDED(rv) && parent) { - ::JS_SetParent(ctx, (JSObject *)*aScriptObject, parent); - } - } - - return rv; -} - NS_IMETHODIMP nsGenericHTMLLeafFormElement::SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, @@ -4091,6 +4115,7 @@ nsGenericHTMLElement::SetElementFocus(PRBool aDoFocus) } +#if 0 // XXX nsresult nsGenericHTMLElement::GetPluginInstance(nsIPluginInstance** aPluginInstance) { @@ -4296,3 +4321,4 @@ nsGenericHTMLElement::GetPluginProperty(JSContext *aContext, JSObject *aObj, } return nsGenericElement::GetProperty(aContext, aObj, aID, aVp); } +#endif diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index a8c4dffc9c6..4643e8b315c 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -28,13 +28,11 @@ #include "nsIContent.h" #include "nsHTMLValue.h" #include "nsVoidArray.h" -#include "nsIJSScriptObject.h" #include "nsINameSpaceManager.h" // for kNameSpaceID_HTML #include "nsIFormControl.h" #include "nsIStatefulFrame.h" - class nsIDOMAttr; class nsIDOMEventListener; class nsIDOMNodeList; @@ -46,7 +44,6 @@ class nsIHTMLContent; class nsIMutableStyleContext; class nsIStyleRule; class nsISupportsArray; -class nsIDOMScriptObjectFactory; class nsChildContentList; class nsDOMCSSDeclaration; class nsIDOMCSSStyleDeclaration; @@ -56,6 +53,8 @@ class nsIForm; class nsIPresState; class nsIPluginInstance; +extern void GetGenericHTMLElementIIDs(nsVoidArray& aArray); + class nsGenericHTMLElement : public nsGenericElement { public: nsGenericHTMLElement(); @@ -63,8 +62,8 @@ public: NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); - static nsresult DOMQueryInterface(nsIDOMHTMLElement *aElement, - REFNSIID aIID, void **aInstancePtr); + nsresult DOMQueryInterface(nsIDOMHTMLElement *aElement, REFNSIID aIID, + void **aInstancePtr); NS_METHOD CopyInnerTo(nsIContent* aSrcContent, nsGenericHTMLElement* aDest, @@ -137,6 +136,7 @@ public: NS_IMETHOD GetAttributeCount(PRInt32& aResult) const; NS_IMETHOD List(FILE* out, PRInt32 aIndent) const; NS_IMETHOD DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const; + NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags); nsresult HandleDOMEventForAnchors(nsIContent* aOuter, nsIPresContext* aPresContext, @@ -349,16 +349,10 @@ public: protected: nsresult SetElementFocus(PRBool aDoFocus); - nsresult GetPluginInstance(nsIPluginInstance** aPluginInstance); - - nsresult GetPluginScriptObject(nsIScriptContext* aContext, - void** aScriptObject); - PRBool GetPluginProperty(JSContext *aContext, JSObject *aObj, jsval aID, - jsval *aVp); - PRBool IsEventName(nsIAtom* aName); }; + //---------------------------------------------------------------------- class nsGenericHTMLLeafElement : public nsGenericHTMLElement { @@ -501,6 +495,8 @@ public: NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags); + // nsIFormControl NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm); NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm, @@ -519,8 +515,6 @@ public: return nsGenericHTMLElement::SetAttribute(aName, aValue); } - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - protected: nsIForm* mForm; }; @@ -536,6 +530,8 @@ public: NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags); + // nsIFormControl NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm); NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm, @@ -553,7 +549,6 @@ public: { return nsGenericHTMLElement::SetAttribute(aName, aValue); } - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); protected: nsIForm* mForm; @@ -810,4 +805,45 @@ _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \ return NS_STATIC_CAST(nsIHTMLContent *, this)->SetHTMLAttribute(nsHTMLAtoms::_atom, value, PR_TRUE); \ } + +/** + * QueryInterface() implementation helper macros + */ + +#define NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(_class, _base) \ + NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \ + { \ + NS_ENSURE_ARG_POINTER(aInstancePtr); \ + \ + *aInstancePtr = nsnull; \ + \ + nsresult rv; \ + \ + rv = _base::QueryInterface(aIID, aInstancePtr); \ + \ + if (NS_SUCCEEDED(rv)) \ + return rv; \ + \ + rv = DOMQueryInterface(this, aIID, aInstancePtr); \ + \ + if (NS_SUCCEEDED(rv)) \ + return rv; \ + \ + nsISupports *foundInterface = nsnull; + + +#define NS_HTML_CONTENT_INTERFACE_MAP_END \ + { \ + return NS_NOINTERFACE; \ + } \ + \ + NS_ADDREF(foundInterface); \ + \ + *aInstancePtr = foundInterface; \ + \ + return NS_OK; \ + } + + + #endif /* nsGenericHTMLElement_h___ */ diff --git a/content/html/content/src/nsHTMLAnchorElement.cpp b/content/html/content/src/nsHTMLAnchorElement.cpp index d478c105860..30ad36e8f00 100644 --- a/content/html/content/src/nsHTMLAnchorElement.cpp +++ b/content/html/content/src/nsHTMLAnchorElement.cpp @@ -23,7 +23,6 @@ #include "nsHTMLUtils.h" #include "nsIDOMHTMLAnchorElement.h" #include "nsIDOMNSHTMLAnchorElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsIHTMLDocument.h" @@ -46,7 +45,6 @@ #include "nsIPresShell.h" #include "nsIDocument.h" #include "nsIHTMLAttributes.h" -#include "prprf.h" // XXX suppress @@ -66,19 +64,19 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLAnchorElement - NS_DECL_IDOMHTMLANCHORELEMENT + NS_DECL_NSIDOMHTMLANCHORELEMENT // nsIDOMNSHTMLAnchorElement - NS_DECL_IDOMNSHTMLANCHORELEMENT + NS_DECL_NSIDOMNSHTMLANCHORELEMENT // nsILink NS_IMETHOD GetLinkState(nsLinkState &aState); @@ -102,8 +100,10 @@ protected: // The cached visited state nsLinkState mLinkState; + }; + nsresult NS_NewHTMLAnchorElement(nsIHTMLContent** aInstancePtrResult, nsINodeInfo *aNodeInfo) @@ -145,9 +145,23 @@ nsHTMLAnchorElement::~nsHTMLAnchorElement() NS_IMPL_ADDREF_INHERITED(nsHTMLAnchorElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLAnchorElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI3(nsHTMLAnchorElement, nsGenericHTMLContainerElement, - nsIDOMHTMLAnchorElement, nsIDOMNSHTMLAnchorElement, - nsILink) + +// XPConnect interface list for nsHTMLAnchorElement +NS_CLASSINFO_MAP_BEGIN(HTMLAnchorElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLAnchorElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLAnchorElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLAnchorElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLAnchorElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLAnchorElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLAnchorElement) + NS_INTERFACE_MAP_ENTRY(nsILink) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLAnchorElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult @@ -647,6 +661,12 @@ nsHTMLAnchorElement::GetText(nsAWritableString& aText) return NS_OK; } +NS_IMETHODIMP +nsHTMLAnchorElement::ToString(nsAWritableString& aSource) +{ + return GetHref(aSource); +} + NS_IMETHODIMP nsHTMLAnchorElement::GetLinkState(nsLinkState &aState) { diff --git a/content/html/content/src/nsHTMLAppletElement.cpp b/content/html/content/src/nsHTMLAppletElement.cpp index 58e2632901a..4907e8915c0 100644 --- a/content/html/content/src/nsHTMLAppletElement.cpp +++ b/content/html/content/src/nsHTMLAppletElement.cpp @@ -21,7 +21,6 @@ * Pierre Phaneuf */ #include "nsIDOMHTMLAppletElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -61,19 +60,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLAppletElement - NS_DECL_IDOMHTMLAPPLETELEMENT - - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject); + NS_DECL_NSIDOMHTMLAPPLETELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -130,8 +126,20 @@ nsHTMLAppletElement::~nsHTMLAppletElement() NS_IMPL_ADDREF_INHERITED(nsHTMLAppletElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLAppletElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLAppletElement, nsGenericHTMLContainerElement, - nsIDOMHTMLAppletElement) + +// XPConnect interface list for nsHTMLAppletElement +NS_CLASSINFO_MAP_BEGIN(HTMLAppletElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLAppletElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLAppletElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLAppletElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLAppletElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLAppletElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult @@ -262,6 +270,7 @@ nsHTMLAppletElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapF * object. That way, if the Java applet has public fields that shadow * the tag attributes, the applet's fields take precedence. */ +#if 0 NS_IMETHODIMP nsHTMLAppletElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) @@ -364,6 +373,7 @@ nsHTMLAppletElement::GetScriptObject(nsIScriptContext* aContext, return rv; } +#endif NS_IMETHODIMP nsHTMLAppletElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const diff --git a/content/html/content/src/nsHTMLAreaElement.cpp b/content/html/content/src/nsHTMLAreaElement.cpp index 93178c60c2e..e0393d74098 100644 --- a/content/html/content/src/nsHTMLAreaElement.cpp +++ b/content/html/content/src/nsHTMLAreaElement.cpp @@ -21,7 +21,6 @@ */ #include "nsIDOMHTMLAreaElement.h" #include "nsIDOMNSHTMLAreaElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -51,19 +50,19 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLAreaElement - NS_DECL_IDOMHTMLAREAELEMENT + NS_DECL_NSIDOMHTMLAREAELEMENT // nsIDOMNSHTMLAreaElement - NS_DECL_IDOMNSHTMLAREAELEMENT + NS_DECL_NSIDOMNSHTMLAREAELEMENT // nsILink NS_IMETHOD GetLinkState(nsLinkState &aState); @@ -126,9 +125,23 @@ nsHTMLAreaElement::~nsHTMLAreaElement() NS_IMPL_ADDREF_INHERITED(nsHTMLAreaElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLAreaElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI3(nsHTMLAreaElement, nsGenericHTMLLeafElement, - nsIDOMHTMLAreaElement, nsIDOMNSHTMLAreaElement, - nsILink) + +// XPConnect interface list for nsHTMLAreaElement +NS_CLASSINFO_MAP_BEGIN(HTMLAreaElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLAreaElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLAreaElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLAreaElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLAreaElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLAreaElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLAreaElement) + NS_INTERFACE_MAP_ENTRY(nsILink) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLAreaElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLBRElement.cpp b/content/html/content/src/nsHTMLBRElement.cpp index 184a9adca75..10bee2809cd 100644 --- a/content/html/content/src/nsHTMLBRElement.cpp +++ b/content/html/content/src/nsHTMLBRElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLBRElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -44,16 +43,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLBRElement - NS_DECL_IDOMHTMLBRELEMENT + NS_DECL_NSIDOMHTMLBRELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -106,8 +105,20 @@ nsHTMLBRElement::~nsHTMLBRElement() NS_IMPL_ADDREF_INHERITED(nsHTMLBRElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLBRElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLBRElement, nsGenericHTMLLeafElement, - nsIDOMHTMLBRElement) + +// XPConnect interface list for nsHTMLBRElement +NS_CLASSINFO_MAP_BEGIN(HTMLBRElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLBRElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLBRElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLBRElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLBRElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLBRElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLBaseElement.cpp b/content/html/content/src/nsHTMLBaseElement.cpp index d0e340617f0..5e15974380e 100644 --- a/content/html/content/src/nsHTMLBaseElement.cpp +++ b/content/html/content/src/nsHTMLBaseElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLBaseElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLBaseElement - NS_DECL_IDOMHTMLBASEELEMENT + NS_DECL_NSIDOMHTMLBASEELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -96,8 +95,20 @@ nsHTMLBaseElement::~nsHTMLBaseElement() NS_IMPL_ADDREF_INHERITED(nsHTMLBaseElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLBaseElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLBaseElement, nsGenericHTMLLeafElement, - nsIDOMHTMLBaseElement) + +// XPConnect interface list for nsHTMLBaseElement +NS_CLASSINFO_MAP_BEGIN(HTMLBaseElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLBaseElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLBaseElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLBaseElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLBaseElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLBaseElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLBaseFontElement.cpp b/content/html/content/src/nsHTMLBaseFontElement.cpp index 10e9d633e55..458859a5bf1 100644 --- a/content/html/content/src/nsHTMLBaseFontElement.cpp +++ b/content/html/content/src/nsHTMLBaseFontElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLBaseFontElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLBaseElement - NS_DECL_IDOMHTMLBASEFONTELEMENT + NS_DECL_NSIDOMHTMLBASEFONTELEMENT NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute, PRInt32& aHint) const; @@ -98,8 +97,20 @@ nsHTMLBaseFontElement::~nsHTMLBaseFontElement() NS_IMPL_ADDREF(nsHTMLBaseFontElement) NS_IMPL_RELEASE(nsHTMLBaseFontElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLBaseFontElement, nsGenericHTMLLeafElement, - nsIDOMHTMLBaseFontElement) + +// XPConnect interface list for nsHTMLBaseFontElement +NS_CLASSINFO_MAP_BEGIN(HTMLBaseFontElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLBaseFontElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLBaseFontElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLBaseFontElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLBaseFontElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLBaseFontElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLBodyElement.cpp b/content/html/content/src/nsHTMLBodyElement.cpp index b73bdfae808..9b69013db9c 100644 --- a/content/html/content/src/nsHTMLBodyElement.cpp +++ b/content/html/content/src/nsHTMLBodyElement.cpp @@ -21,7 +21,6 @@ */ #include "nsCOMPtr.h" #include "nsIDOMHTMLBodyElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -188,16 +187,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLBodyElement - NS_DECL_IDOMHTMLBODYELEMENT + NS_DECL_NSIDOMHTMLBODYELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -744,8 +743,20 @@ nsHTMLBodyElement::~nsHTMLBodyElement() } -NS_IMPL_HTMLCONTENT_QI(nsHTMLBodyElement, nsGenericHTMLContainerElement, - nsIDOMHTMLBodyElement) + +// XPConnect interface list for nsHTMLBodyElement +NS_CLASSINFO_MAP_BEGIN(HTMLBodyElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLBodyElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLBodyElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLBodyElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLBodyElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLBodyElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLButtonElement.cpp b/content/html/content/src/nsHTMLButtonElement.cpp index 7cf3a36f758..38f769c6285 100644 --- a/content/html/content/src/nsHTMLButtonElement.cpp +++ b/content/html/content/src/nsHTMLButtonElement.cpp @@ -22,7 +22,6 @@ #include "nsIDOMHTMLButtonElement.h" #include "nsIDOMNSHTMLButtonElement.h" #include "nsIDOMHTMLFormElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -55,19 +54,19 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerFormElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerFormElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerFormElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerFormElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLButtonElement - NS_DECL_IDOMHTMLBUTTONELEMENT + NS_DECL_NSIDOMHTMLBUTTONELEMENT // nsIDOMNSHTMLButtonElement - NS_DECL_IDOMNSHTMLBUTTONELEMENT + NS_DECL_NSIDOMNSHTMLBUTTONELEMENT // overrided nsIFormControl method NS_IMETHOD GetType(PRInt32* aType); @@ -142,8 +141,22 @@ nsHTMLButtonElement::~nsHTMLButtonElement() NS_IMPL_ADDREF_INHERITED(nsHTMLButtonElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLButtonElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI2(nsHTMLButtonElement, nsGenericHTMLContainerFormElement, - nsIDOMHTMLButtonElement, nsIDOMNSHTMLButtonElement); + +// XPConnect interface list for nsHTMLButtonElement +NS_CLASSINFO_MAP_BEGIN(HTMLButtonElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLButtonElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLButtonElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLButtonElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLButtonElement, + nsGenericHTMLContainerFormElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLButtonElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLButtonElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLButtonElement) +NS_HTML_CONTENT_INTERFACE_MAP_END NS_IMETHODIMP diff --git a/content/html/content/src/nsHTMLDListElement.cpp b/content/html/content/src/nsHTMLDListElement.cpp index 3cc55961f4b..152de2867ff 100644 --- a/content/html/content/src/nsHTMLDListElement.cpp +++ b/content/html/content/src/nsHTMLDListElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLDListElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -44,13 +43,13 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLDListElement NS_IMETHOD GetCompact(PRBool* aCompact); @@ -105,8 +104,20 @@ nsHTMLDListElement::~nsHTMLDListElement() NS_IMPL_ADDREF(nsHTMLDListElement); NS_IMPL_RELEASE(nsHTMLDListElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLDListElement, nsGenericHTMLContainerElement, - nsIDOMHTMLDListElement); + +// XPConnect interface list for nsHTMLDListElement +NS_CLASSINFO_MAP_BEGIN(HTMLDListElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLDListElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLDListElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLDListElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDListElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDListElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLDelElement.cpp b/content/html/content/src/nsHTMLDelElement.cpp index 8606b85fde4..4cdc107648e 100644 --- a/content/html/content/src/nsHTMLDelElement.cpp +++ b/content/html/content/src/nsHTMLDelElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLModElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLModElement - NS_DECL_IDOMHTMLMODELEMENT + NS_DECL_NSIDOMHTMLMODELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -96,8 +95,20 @@ nsHTMLDelElement::~nsHTMLDelElement() NS_IMPL_ADDREF_INHERITED(nsHTMLDelElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLDelElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLDelElement, nsGenericHTMLContainerElement, - nsIDOMHTMLModElement); + +// XPConnect interface list for nsHTMLDelElement +NS_CLASSINFO_MAP_BEGIN(HTMLDelElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLModElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLDelElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLDelElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLModElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDelElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLDirectoryElement.cpp b/content/html/content/src/nsHTMLDirectoryElement.cpp index 49da5d13859..732f3537098 100644 --- a/content/html/content/src/nsHTMLDirectoryElement.cpp +++ b/content/html/content/src/nsHTMLDirectoryElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLDirectoryElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -48,16 +47,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLDirectoryElement - NS_DECL_IDOMHTMLDIRECTORYELEMENT + NS_DECL_NSIDOMHTMLDIRECTORYELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -110,8 +109,20 @@ nsHTMLDirectoryElement::~nsHTMLDirectoryElement() NS_IMPL_ADDREF_INHERITED(nsHTMLDirectoryElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLDirectoryElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLDirectoryElement, nsGenericHTMLContainerElement, - nsIDOMHTMLDirectoryElement); + +// XPConnect interface list for nsHTMLDirectoryElement +NS_CLASSINFO_MAP_BEGIN(HTMLDirectoryElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLDirectoryElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLDirectoryElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLDirectoryElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDirectoryElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDirectoryElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLDivElement.cpp b/content/html/content/src/nsHTMLDivElement.cpp index 1a020d4e626..1075cda0627 100644 --- a/content/html/content/src/nsHTMLDivElement.cpp +++ b/content/html/content/src/nsHTMLDivElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLDivElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -46,16 +45,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLDivElement - NS_DECL_IDOMHTMLDIVELEMENT + NS_DECL_NSIDOMHTMLDIVELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -110,8 +109,20 @@ NS_IMPL_ADDREF_INHERITED(nsHTMLDivElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLDivElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLDivElement, nsGenericHTMLContainerElement, - nsIDOMHTMLDivElement) + +// XPConnect interface list for nsHTMLDivElement +NS_CLASSINFO_MAP_BEGIN(HTMLDivElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLDivElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLDivElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLDivElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDivElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDivElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLEmbedElement.cpp b/content/html/content/src/nsHTMLEmbedElement.cpp index 86997d9e3c6..fcf77d9f017 100644 --- a/content/html/content/src/nsHTMLEmbedElement.cpp +++ b/content/html/content/src/nsHTMLEmbedElement.cpp @@ -37,16 +37,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLEmbedElement - NS_DECL_IDOMHTMLEMBEDELEMENT + NS_DECL_NSIDOMHTMLEMBEDELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -59,14 +59,6 @@ public: NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc, nsMapAttributesFunc& aMapFunc) const; NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; - - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject); - - // nsIJSScriptObject - virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); }; nsresult @@ -107,8 +99,20 @@ nsHTMLEmbedElement::~nsHTMLEmbedElement() NS_IMPL_ADDREF_INHERITED(nsHTMLEmbedElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLEmbedElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLEmbedElement, nsGenericHTMLLeafElement, - nsIDOMHTMLEmbedElement); + +// XPConnect interface list for nsHTMLEmbedElement +NS_CLASSINFO_MAP_BEGIN(HTMLEmbedElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLEmbedElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLEmbedElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLEmbedElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLEmbedElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLEmbedElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult @@ -228,6 +232,7 @@ nsHTMLEmbedElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const /***************************************************************************/ +#if 0 NS_IMETHODIMP nsHTMLEmbedElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) @@ -241,6 +246,7 @@ nsHTMLEmbedElement::GetProperty(JSContext *aContext, JSObject *aObj, { return GetPluginProperty(aContext, aObj, aID, aVp); } +#endif ///////////////////////////////////////////// // Implement nsIDOMHTMLEmbedElement interface diff --git a/content/html/content/src/nsHTMLFieldSetElement.cpp b/content/html/content/src/nsHTMLFieldSetElement.cpp index c24940cd188..e5bd620956d 100644 --- a/content/html/content/src/nsHTMLFieldSetElement.cpp +++ b/content/html/content/src/nsHTMLFieldSetElement.cpp @@ -21,7 +21,6 @@ */ #include "nsIDOMHTMLFieldSetElement.h" #include "nsIDOMHTMLFormElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -47,13 +46,13 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerFormElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerFormElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerFormElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerFormElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerFormElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerFormElement::) // nsIDOMHTMLFieldSetElement NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm); @@ -108,9 +107,20 @@ nsHTMLFieldSetElement::~nsHTMLFieldSetElement() NS_IMPL_ADDREF_INHERITED(nsHTMLFieldSetElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLFieldSetElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLFieldSetElement, - nsGenericHTMLContainerFormElement, - nsIDOMHTMLFieldSetElement); + +// XPConnect interface list for nsHTMLFieldSetElement +NS_CLASSINFO_MAP_BEGIN(HTMLFieldSetElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLFieldSetElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLFieldSetElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLFieldSetElement, + nsGenericHTMLContainerFormElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFieldSetElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLFieldSetElement) +NS_HTML_CONTENT_INTERFACE_MAP_END // nsIDOMHTMLFieldSetElement diff --git a/content/html/content/src/nsHTMLFontElement.cpp b/content/html/content/src/nsHTMLFontElement.cpp index 219d3ececa8..2bd8dd4aba7 100644 --- a/content/html/content/src/nsHTMLFontElement.cpp +++ b/content/html/content/src/nsHTMLFontElement.cpp @@ -21,7 +21,6 @@ */ #include "nsCOMPtr.h" #include "nsIDOMHTMLFontElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -51,16 +50,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLFontElement - NS_DECL_IDOMHTMLFONTELEMENT + NS_DECL_NSIDOMHTMLFONTELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -113,8 +112,20 @@ nsHTMLFontElement::~nsHTMLFontElement() NS_IMPL_ADDREF_INHERITED(nsHTMLFontElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLFontElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLFontElement, nsGenericHTMLContainerElement, - nsIDOMHTMLFontElement); + +// XPConnect interface list for nsHTMLFontElement +NS_CLASSINFO_MAP_BEGIN(HTMLFontElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLFontElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLFontElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLFontElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFontElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLFontElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLFormElement.cpp b/content/html/content/src/nsHTMLFormElement.cpp index 6e42f6ecfa9..d83598e0241 100644 --- a/content/html/content/src/nsHTMLFormElement.cpp +++ b/content/html/content/src/nsHTMLFormElement.cpp @@ -25,9 +25,8 @@ #include "nsIFormManager.h" #include "nsIDOMHTMLFormElement.h" #include "nsIDOMNSHTMLFormElement.h" -#include "nsIDOMHTMLFormControlList.h" #include "nsIHTMLDocument.h" -#include "nsIScriptObjectOwner.h" +#include "nsIDOMNSHTMLFormControlList.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -67,22 +66,19 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLFormElement - NS_DECL_IDOMHTMLFORMELEMENT + NS_DECL_NSIDOMHTMLFORMELEMENT // nsIDOMNSHTMLFormElement - NS_DECL_IDOMNSHTMLFORMELEMENT - - virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty); + NS_DECL_NSIDOMNSHTMLFORMELEMENT // nsIForm NS_IMETHOD AddElement(nsIFormControl* aElement); @@ -93,8 +89,11 @@ public: NS_IMETHOD RemoveElement(nsIFormControl* aElement); NS_IMETHOD RemoveElementFromTable(nsIFormControl* aElement, const nsAReadableString& aName); + NS_IMETHOD ResolveName(const nsAReadableString& aName, + nsISupports **aReturn); NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; + // nsIContent NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, nsHTMLValue& aResult); @@ -116,8 +115,8 @@ protected: }; // nsFormControlList -class nsFormControlList : public nsIDOMHTMLFormControlList, - public nsIScriptObjectOwner +class nsFormControlList : public nsIDOMNSHTMLFormControlList, + public nsIDOMHTMLCollection { public: nsFormControlList(nsIDOMHTMLFormElement* aForm); @@ -128,15 +127,14 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - NS_IMETHOD ResetScriptObject(); - // nsIDOMHTMLCollection interface - NS_DECL_IDOMHTMLCOLLECTION - NS_DECL_IDOMHTMLFORMCONTROLLIST + NS_DECL_NSIDOMHTMLCOLLECTION - nsresult GetNamedObject(JSContext* aContext, jsval aID, JSObject** aObj); + // nsIDOMNSHTMLFormControlList interface + NS_DECL_NSIDOMNSHTMLFORMCONTROLLIST + + nsresult GetNamedObject(const nsAReadableString& aName, + nsISupports **aResult); nsresult AddElementToTable(nsIFormControl* aChild, const nsAReadableString& aName); @@ -147,7 +145,6 @@ public: nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; #endif - void *mScriptObject; nsIDOMHTMLFormElement* mForm; // WEAK - the form owns me nsVoidArray mElements; // Holds WEAK references - bug 36639 @@ -246,6 +243,7 @@ nsHTMLFormElement::nsHTMLFormElement(): mGeneratingReset(PR_FALSE) { mControls = new nsFormControlList(this); + NS_IF_ADDREF(mControls); } @@ -267,9 +265,23 @@ nsHTMLFormElement::~nsHTMLFormElement() NS_IMPL_ADDREF_INHERITED(nsHTMLFormElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLFormElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI3(nsHTMLFormElement, nsGenericHTMLContainerElement, - nsIDOMHTMLFormElement, nsIDOMNSHTMLFormElement, - nsIForm) + +// XPConnect interface list for nsHTMLFormElement +NS_CLASSINFO_MAP_BEGIN(HTMLFormElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLFormElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLFormElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLFormElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLFormElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFormElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFormElement) + NS_INTERFACE_MAP_ENTRY(nsIForm) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLFormElement) +NS_HTML_CONTENT_INTERFACE_MAP_END // nsIDOMHTMLFormElement @@ -582,7 +594,7 @@ nsHTMLFormElement::RemoveElement(nsIFormControl* aChild) return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLFormElement::RemoveElementFromTable(nsIFormControl* aElement, const nsAReadableString& aName) { @@ -591,12 +603,24 @@ nsHTMLFormElement::RemoveElementFromTable(nsIFormControl* aElement, return mControls->RemoveElementFromTable(aElement, aName); } +NS_IMETHODIMP +nsHTMLFormElement::ResolveName(const nsAReadableString& aName, + nsISupports **aResult) +{ + return mControls->GetNamedObject(aName, aResult); +} + + NS_IMETHODIMP nsHTMLFormElement::GetEncoding(nsAWritableString& aEncoding) { - return nsGenericHTMLContainerElement::GetAttribute(kNameSpaceID_HTML, - nsHTMLAtoms::enctype, - aEncoding); + return GetEnctype(aEncoding); +} + +NS_IMETHODIMP +nsHTMLFormElement::SetEncoding(const nsAReadableString& aEncoding) +{ + return SetEnctype(aEncoding); } NS_IMETHODIMP @@ -607,156 +631,13 @@ nsHTMLFormElement::GetLength(PRInt32* aLength) return NS_OK; } - -NS_IMETHODIMP -nsHTMLFormElement::NamedItem(JSContext* cx, jsval* argv, PRUint32 argc, - jsval* aReturn) -{ - nsresult result = mControls->NamedItem(cx, argv, argc, aReturn); - if (NS_FAILED(result)) { - return result; - } - - // If we couldn't find it in our controls list, it may be - // a different type of element (IMG, OBJECT, etc.) - if (!*aReturn && mDocument && (argc > 0)) { - PRUnichar* str = NS_REINTERPRET_CAST(PRUnichar *, JS_GetStringChars(JS_ValueToString(cx, argv[0]))); - - nsCOMPtr scriptContext; - nsCOMPtr globalObject; - - mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - - if (globalObject) { - result = globalObject->GetContext(getter_AddRefs(scriptContext)); - } - - nsCOMPtr html_doc(do_QueryInterface(mDocument)); - - if (html_doc) { - nsCOMPtr item; - - result = html_doc->ResolveName(nsLiteralString(str), this, - getter_AddRefs(item)); - if (NS_FAILED(result)) { - return result; - } - - nsCOMPtr owner(do_QueryInterface(item)); - - if (owner) { - JSObject* obj; - - result = owner->GetScriptObject(scriptContext, (void**)&obj); - if (NS_FAILED(result)) { - return result; - } - - *aReturn = OBJECT_TO_JSVAL(obj); - } - } - } - - return NS_OK; -} - -PRBool -nsHTMLFormElement::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty) -{ - if (!JSVAL_IS_STRING(aID)) { - return PR_TRUE; - } - - PRBool ret; - JSObject* obj; - jschar* str = JS_GetStringChars(JS_ValueToString(aContext, aID)); - size_t str_len = JS_GetStringLength(JS_ValueToString(aContext, aID)); - nsCOMPtr scriptContext; - nsresult rv = NS_OK; - - rv = nsContentUtils::GetStaticScriptContext(aContext, aObj, - getter_AddRefs(scriptContext)); - - // If we can't get a script context, there's nothing we can do - if (!scriptContext || NS_FAILED(rv)) { - return PR_FALSE; - } - - rv = mControls->GetNamedObject(aContext, aID, &obj); - if (NS_FAILED(rv)) { - return PR_FALSE; - } - - if (!obj && mDocument) { - nsCOMPtr html_doc(do_QueryInterface(mDocument)); - - if (html_doc) { - nsCOMPtr item; - - nsLiteralString name(NS_REINTERPRET_CAST(PRUnichar *, str), str_len); - - rv = html_doc->ResolveName(name, this, getter_AddRefs(item)); - if (NS_FAILED(rv)) { - return PR_FALSE; - } - - nsCOMPtr owner(do_QueryInterface(item)); - - if (owner) { - rv = owner->GetScriptObject(scriptContext, (void**)&obj); - - if (NS_FAILED(rv)) { - return PR_FALSE; - } - } - } - } - - if (obj) { - JSObject* myObj; - rv = GetScriptObject(scriptContext, (void**)&myObj); - ret = ::JS_DefineUCProperty(aContext, myObj, - str, str_len, OBJECT_TO_JSVAL(obj), - nsnull, nsnull, 0); - - *aDidDefineProperty = PR_TRUE; - } - else { - ret = nsGenericHTMLContainerElement::Resolve(aContext, aObj, aID, - aDidDefineProperty); - } - - return ret; -} - -NS_IMETHODIMP -nsHTMLFormElement::Item(PRUint32 aIndex, nsIDOMElement** aReturn) -{ - if (mControls) { - nsCOMPtr node; - nsresult result = mControls->Item(aIndex, getter_AddRefs(node)); - - if (node) { - result = CallQueryInterface(node, aReturn); - } else { - *aReturn = nsnull; - } - - return result; - } - - return NS_ERROR_FAILURE; -} - //---------------------------------------------------------------------- // nsFormControlList implementation, this could go away if there were // a lightweight collection implementation somewhere nsFormControlList::nsFormControlList(nsIDOMHTMLFormElement* aForm) - : mScriptObject(nsnull), mForm(aForm), - mNameLookupTable(NS_FORM_CONTROL_LIST_HASHTABLE_SIZE), + : mForm(aForm), mNameLookupTable(NS_FORM_CONTROL_LIST_HASHTABLE_SIZE), mNoNameLookupTable(nsnull) { NS_INIT_REFCNT(); @@ -771,13 +652,6 @@ nsFormControlList::~nsFormControlList() Clear(); } -NS_IMETHODIMP -nsFormControlList::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - void nsFormControlList::SetForm(nsIDOMHTMLFormElement* aForm) { @@ -818,36 +692,26 @@ nsFormControlList::Clear() } } -NS_IMPL_ADDREF(nsFormControlList) -NS_IMPL_RELEASE(nsFormControlList) +// XPConnect interface list for nsFormControlList +NS_CLASSINFO_MAP_BEGIN(HTMLFormControlCollection) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLFormControlList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLCollection) +NS_CLASSINFO_MAP_END + + +// XPConnect interface list for nsFormControlList NS_INTERFACE_MAP_BEGIN(nsFormControlList) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFormControlList) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection) - NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFormControlList) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMHTMLCollection) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_WITH_NAME(HTMLFormControlCollection, + HTMLCollection) NS_INTERFACE_MAP_END -nsresult nsFormControlList::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (!mScriptObject) { - res = NS_NewScriptHTMLFormControlList(aContext, (nsISupports *)(nsIDOMHTMLCollection *)this, nsnull, (void**)&mScriptObject); - } - - *aScriptObject = mScriptObject; - - return res; -} - -nsresult nsFormControlList::ResetScriptObject() -{ - mScriptObject = nsnull; - return NS_OK; -} +NS_IMPL_ADDREF(nsFormControlList) +NS_IMPL_RELEASE(nsFormControlList) // nsIDOMHTMLCollection interface @@ -873,79 +737,11 @@ nsFormControlList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) return NS_OK; } -NS_IMETHODIMP -nsFormControlList::Item(JSContext* cx, jsval* argv, PRUint32 argc, - jsval* aReturn) -{ - nsCOMPtr element; - nsresult result; - nsCOMPtr scriptContext; - nsCOMPtr owner; - PRInt32 index; - nsCOMPtr document; - - if (argc < 1) { - return NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR; - } - - *aReturn = nsnull; - if (!JS_ValueToInt32(cx, argv[0], (int32*)&index)) { - return NS_ERROR_FAILURE; - } - - if (!mForm) { - return NS_OK; - } - - nsCOMPtr content(do_QueryInterface(mForm)); - if (content) { - result = content->GetDocument(*getter_AddRefs(document)); - if (NS_FAILED(result)) { - return result; - } - } - - if (document) { - nsCOMPtr globalObject; - document->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { - result = globalObject->GetContext(getter_AddRefs(scriptContext)); - } - } - - // If we can't get a script context, there's nothing we can do - if (!scriptContext) { - return NS_ERROR_FAILURE; - } - - result = Item((PRUint32)index, getter_AddRefs(element)); - if (NS_FAILED(result)) { - return result; - } - - if (element) { - owner = do_QueryInterface(element); - - if (owner) { - JSObject* obj; - result = owner->GetScriptObject(scriptContext, (void**)&obj); - if (NS_FAILED(result)) { - return result; - } - - *aReturn = OBJECT_TO_JSVAL(obj); - } - } - - return NS_OK; -} - nsresult -nsFormControlList::GetNamedObject(JSContext* aContext, jsval aID, - JSObject** aObj) +nsFormControlList::GetNamedObject(const nsAReadableString& aName, + nsISupports** aResult) { - NS_ENSURE_ARG_POINTER(aObj); - *aObj = nsnull; + *aResult = nsnull; if (!mForm) { // No form, no named objects @@ -953,72 +749,13 @@ nsFormControlList::GetNamedObject(JSContext* aContext, jsval aID, } nsresult rv = NS_OK; - nsCOMPtr scriptContext; - nsCOMPtr owner; - char* str = JS_GetStringBytes(JS_ValueToString(aContext, aID)); - nsAutoString ustr; ustr.AssignWithConversion(str); // Get the hash entry - nsStringKey key(ustr); + nsStringKey key(aName); - nsCOMPtr item(dont_AddRef(mNameLookupTable.Get(&key))); + *aResult = mNameLookupTable.Get(&key); - if (item) { - // Found something, we don't care here if it's a element or a node - // list, we just return the script object - owner = do_QueryInterface(item); - } - - if (!owner) { - // No owner means we didn't find anything, at least not something we can - // return as a JSObject. - return NS_OK; - } - - nsCOMPtr document; - nsCOMPtr form = do_QueryInterface(mForm); - - if (form) { - rv = form->GetDocument(*getter_AddRefs(document)); - if (NS_FAILED(rv)) { - return rv; - } - } - - if (document) { - nsCOMPtr globalObject; - document->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { - rv = globalObject->GetContext(getter_AddRefs(scriptContext)); - } - } - - // If we can't get a script context, there's nothing we can do - if (!scriptContext) { - return NS_ERROR_FAILURE; - } - - return owner->GetScriptObject(scriptContext, (void**)aObj); -} - -NS_IMETHODIMP -nsFormControlList::NamedItem(JSContext* cx, jsval* argv, PRUint32 argc, - jsval* aReturn) -{ - JSObject *obj; - nsresult result = NS_OK; - - if (argc > 0) { - result = GetNamedObject(cx, argv[0], &obj); - if (NS_SUCCEEDED(result) && (nsnull != obj)) { - *aReturn = OBJECT_TO_JSVAL(obj); - } - } - else { - result = NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR; - } - - return result; + return NS_OK; } NS_IMETHODIMP @@ -1026,20 +763,22 @@ nsFormControlList::NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn) { NS_ENSURE_ARG_POINTER(aReturn); + *aReturn = nsnull; nsresult rv = NS_OK; + nsStringKey key(aName); - *aReturn = nsnull; nsCOMPtr supports(dont_AddRef(mNameLookupTable.Get(&key))); if (supports) { // We found something, check if it's a node - rv = CallQueryInterface(supports, aReturn); + CallQueryInterface(supports, aReturn); - if (NS_FAILED(rv)) { + if (!*aReturn) { // If not, we check if it's a node list. - nsCOMPtr nodeList(do_QueryInterface(supports, &rv)); + nsCOMPtr nodeList(do_QueryInterface(supports)); + NS_WARN_IF_FALSE(nodeList, "Huh, what's going one here?"); if (nodeList) { // And since we're only asking for one node here, we return the first @@ -1052,6 +791,19 @@ nsFormControlList::NamedItem(const nsAReadableString& aName, return rv; } +NS_IMETHODIMP +nsFormControlList::NamedItem(const nsAReadableString& aName, + nsISupports** aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsStringKey key(aName); + + *aReturn = mNameLookupTable.Get(&key); + + return NS_OK; +} + nsresult nsFormControlList::AddElementToTable(nsIFormControl* aChild, const nsAReadableString& aName) @@ -1112,10 +864,6 @@ nsFormControlList::AddElementToTable(nsIFormControl* aChild, list->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(listSupports)); - // Remove the current item from the hash so that we don't create - // a leak when we add the new item to the hash. - mNameLookupTable.Remove(&key); - // Replace the element with the list. mNameLookupTable.Put(&key, listSupports); } else { diff --git a/content/html/content/src/nsHTMLFrameElement.cpp b/content/html/content/src/nsHTMLFrameElement.cpp index aa31a5d78f6..0c0e61260f2 100644 --- a/content/html/content/src/nsHTMLFrameElement.cpp +++ b/content/html/content/src/nsHTMLFrameElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLFrameElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -50,16 +49,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLFrameElement - NS_DECL_IDOMHTMLFRAMEELEMENT + NS_DECL_NSIDOMHTMLFRAMEELEMENT // nsIChromeEventHandler NS_DECL_NSICHROMEEVENTHANDLER @@ -112,8 +111,21 @@ nsHTMLFrameElement::~nsHTMLFrameElement() NS_IMPL_ADDREF_INHERITED(nsHTMLFrameElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLFrameElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI2(nsHTMLFrameElement, nsGenericHTMLLeafElement, - nsIDOMHTMLFrameElement, nsIChromeEventHandler); + +// XPConnect interface list for nsHTMLFrameElement +NS_CLASSINFO_MAP_BEGIN(HTMLFrameElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLFrameElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLFrameElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLFrameElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFrameElement) + NS_INTERFACE_MAP_ENTRY(nsIChromeEventHandler) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLFrameElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult @@ -188,12 +200,6 @@ nsHTMLFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument) return NS_OK; } -NS_IMETHODIMP -nsHTMLFrameElement::SetContentDocument(nsIDOMDocument* aContentDocument) -{ - return NS_ERROR_DOM_INVALID_MODIFICATION_ERR; -} - NS_IMETHODIMP nsHTMLFrameElement::StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, diff --git a/content/html/content/src/nsHTMLFrameSetElement.cpp b/content/html/content/src/nsHTMLFrameSetElement.cpp index f0708bbf4dd..10b801264c5 100644 --- a/content/html/content/src/nsHTMLFrameSetElement.cpp +++ b/content/html/content/src/nsHTMLFrameSetElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLFrameSetElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLFrameSetElement - NS_DECL_IDOMHTMLFRAMESETELEMENT + NS_DECL_NSIDOMHTMLFRAMESETELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -104,8 +103,20 @@ nsHTMLFrameSetElement::~nsHTMLFrameSetElement() NS_IMPL_ADDREF_INHERITED(nsHTMLFrameSetElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLFrameSetElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLFrameSetElement, nsGenericHTMLContainerElement, - nsIDOMHTMLFrameSetElement); + +// XPConnect interface list for nsHTMLFrameSetElement +NS_CLASSINFO_MAP_BEGIN(HTMLFrameSetElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLFrameSetElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLFrameSetElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLFrameSetElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFrameSetElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLFrameSetElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLHRElement.cpp b/content/html/content/src/nsHTMLHRElement.cpp index 02a4c844d32..30a585e3a6b 100644 --- a/content/html/content/src/nsHTMLHRElement.cpp +++ b/content/html/content/src/nsHTMLHRElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLHRElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -44,16 +43,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLHRElement - NS_DECL_IDOMHTMLHRELEMENT + NS_DECL_NSIDOMHTMLHRELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -107,8 +106,20 @@ nsHTMLHRElement::~nsHTMLHRElement() NS_IMPL_ADDREF_INHERITED(nsHTMLHRElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLHRElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLHRElement, nsGenericHTMLLeafElement, - nsIDOMHTMLHRElement); + +// XPConnect interface list for nsHTMLHRElement +NS_CLASSINFO_MAP_BEGIN(HTMLHRElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLHRElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLHRElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLHRElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLHRElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLHRElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLHeadElement.cpp b/content/html/content/src/nsHTMLHeadElement.cpp index f6610a4eef0..a9214ce135b 100644 --- a/content/html/content/src/nsHTMLHeadElement.cpp +++ b/content/html/content/src/nsHTMLHeadElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLHeadElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLHeadElement - NS_DECL_IDOMHTMLHEADELEMENT + NS_DECL_NSIDOMHTMLHEADELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -96,8 +95,20 @@ nsHTMLHeadElement::~nsHTMLHeadElement() NS_IMPL_ADDREF_INHERITED(nsHTMLHeadElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLHeadElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLHeadElement, nsGenericHTMLContainerElement, - nsIDOMHTMLHeadElement); + +// XPConnect interface list for nsHTMLHeadElement +NS_CLASSINFO_MAP_BEGIN(HTMLHeadElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLHeadElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLHeadElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLHeadElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLHeadElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLHeadElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLHeadingElement.cpp b/content/html/content/src/nsHTMLHeadingElement.cpp index bca2a3e8843..3740c0172c9 100644 --- a/content/html/content/src/nsHTMLHeadingElement.cpp +++ b/content/html/content/src/nsHTMLHeadingElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLHeadingElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -44,16 +43,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLHeadingElement - NS_DECL_IDOMHTMLHEADINGELEMENT + NS_DECL_NSIDOMHTMLHEADINGELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -107,8 +106,20 @@ nsHTMLHeadingElement::~nsHTMLHeadingElement() NS_IMPL_ADDREF_INHERITED(nsHTMLHeadingElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLHeadingElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLHeadingElement, nsGenericHTMLContainerElement, - nsIDOMHTMLHeadingElement); + +// XPConnect interface list for nsHTMLHeadingElement +NS_CLASSINFO_MAP_BEGIN(HTMLHeadingElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLHeadingElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLHeadingElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLHeadingElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLHeadingElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLHeadingElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLHtmlElement.cpp b/content/html/content/src/nsHTMLHtmlElement.cpp index b39168f16fc..65c9750b1dc 100644 --- a/content/html/content/src/nsHTMLHtmlElement.cpp +++ b/content/html/content/src/nsHTMLHtmlElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLHtmlElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -44,16 +43,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLHtmlElement - NS_DECL_IDOMHTMLHTMLELEMENT + NS_DECL_NSIDOMHTMLHTMLELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -99,8 +98,20 @@ NS_IMPL_ADDREF_INHERITED(nsHTMLHtmlElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLHtmlElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLHtmlElement, nsGenericHTMLContainerElement, - nsIDOMHTMLHtmlElement) + +// XPConnect interface list for nsHTMLHtmlElement +NS_CLASSINFO_MAP_BEGIN(HTMLHtmlElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLHtmlElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLHtmlElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLHtmlElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLHtmlElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLHtmlElement) +NS_HTML_CONTENT_INTERFACE_MAP_END NS_IMETHODIMP diff --git a/content/html/content/src/nsHTMLIFrameElement.cpp b/content/html/content/src/nsHTMLIFrameElement.cpp index 4dd7a40a0aa..5cf7c2fc649 100644 --- a/content/html/content/src/nsHTMLIFrameElement.cpp +++ b/content/html/content/src/nsHTMLIFrameElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLIFrameElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -51,16 +50,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLIFrameElement - NS_DECL_IDOMHTMLIFRAMEELEMENT + NS_DECL_NSIDOMHTMLIFRAMEELEMENT // nsIChromeEventHandler NS_DECL_NSICHROMEEVENTHANDLER @@ -117,8 +116,21 @@ nsHTMLIFrameElement::~nsHTMLIFrameElement() NS_IMPL_ADDREF(nsHTMLIFrameElement); NS_IMPL_RELEASE(nsHTMLIFrameElement); -NS_IMPL_HTMLCONTENT_QI2(nsHTMLIFrameElement, nsGenericHTMLContainerElement, - nsIDOMHTMLIFrameElement, nsIChromeEventHandler); + +// XPConnect interface list for nsHTMLIFrameElement +NS_CLASSINFO_MAP_BEGIN(HTMLIFrameElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLIFrameElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLIFrameElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLIFrameElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLIFrameElement) + NS_INTERFACE_MAP_ENTRY(nsIChromeEventHandler) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLIFrameElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult @@ -194,13 +206,7 @@ nsHTMLIFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument) return NS_OK; } - -NS_IMETHODIMP -nsHTMLIFrameElement::SetContentDocument(nsIDOMDocument* aContentDocument) -{ - return NS_ERROR_DOM_INVALID_MODIFICATION_ERR; -} - + NS_IMETHODIMP nsHTMLIFrameElement::StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, diff --git a/content/html/content/src/nsHTMLImageElement.cpp b/content/html/content/src/nsHTMLImageElement.cpp index c5aa9348598..c67d9b2e80f 100644 --- a/content/html/content/src/nsHTMLImageElement.cpp +++ b/content/html/content/src/nsHTMLImageElement.cpp @@ -20,8 +20,7 @@ * Contributor(s): */ #include "nsIDOMHTMLImageElement.h" -#include "nsIDOMImage.h" -#include "nsIScriptObjectOwner.h" +#include "nsIDOMNSHTMLImageElement.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -33,7 +32,6 @@ #include "nsIPresContext.h" #include "nsIPresShell.h" #include "nsIHTMLAttributes.h" -#include "nsIJSScriptObject.h" #include "nsIJSNativeInitializer.h" #include "nsSize.h" #include "nsIDocument.h" @@ -64,11 +62,13 @@ #include "nsIFrameImageLoader.h" #endif +#include "nsIJSContextStack.h" + // XXX nav attrs: suppress class nsHTMLImageElement : public nsGenericHTMLLeafElement, public nsIDOMHTMLImageElement, - public nsIDOMImage, + public nsIDOMNSHTMLImageElement, public nsIJSNativeInitializer #ifdef USE_IMG2 , public imgIDecoderObserver @@ -82,37 +82,30 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLImageElement - NS_DECL_IDOMHTMLIMAGEELEMENT + NS_DECL_NSIDOMHTMLIMAGEELEMENT + + // nsIDOMNSHTMLImageElement + NS_DECL_NSIDOMNSHTMLIMAGEELEMENT - // nsIDOMImage - NS_DECL_IDOMIMAGE - #ifdef USE_IMG2 NS_DECL_IMGIDECODEROBSERVER NS_DECL_IMGICONTAINEROBSERVER #endif - // nsIJSScriptObject - virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty); - // nsIJSNativeInitializer NS_IMETHOD Initialize(JSContext* aContext, JSObject *aObj, PRUint32 argc, jsval *argv); + // nsIContent NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers); NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, @@ -132,7 +125,7 @@ public: protected: nsresult SetSrcInner(nsIURI* aBaseURL, const nsAReadableString& aSrc); - static nsresult GetCallerSourceURL(JSContext* cx, nsIURI** sourceURL); + static nsresult GetCallerSourceURL(nsIURI** sourceURL); nsresult GetImageFrame(nsIImageFrame** aImageFrame); @@ -217,16 +210,40 @@ nsHTMLImageElement::~nsHTMLImageElement() NS_IMPL_ADDREF_INHERITED(nsHTMLImageElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLImageElement, nsGenericElement) + +// XPConnect interface list for nsHTMLImageElement +NS_CLASSINFO_MAP_BEGIN(HTMLImageElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLImageElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLImageElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLImageElement #ifdef USE_IMG2 -NS_IMPL_HTMLCONTENT_QI4(nsHTMLImageElement, nsGenericHTMLLeafElement, - nsIDOMHTMLImageElement, nsIDOMImage, - nsIJSNativeInitializer, imgIDecoderObserver); + +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLImageElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLImageElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLImageElement) + NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer) + NS_INTERFACE_MAP_ENTRY(imgIDecoderObserver) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLImageElement) +NS_HTML_CONTENT_INTERFACE_MAP_END + #else -NS_IMPL_HTMLCONTENT_QI3(nsHTMLImageElement, nsGenericHTMLLeafElement, - nsIDOMHTMLImageElement, nsIDOMImage, - nsIJSNativeInitializer); + +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLImageElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLImageElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLImageElement) + NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLImageElement) +NS_HTML_CONTENT_INTERFACE_MAP_END + #endif + nsresult nsHTMLImageElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) { @@ -260,15 +277,12 @@ NS_IMPL_STRING_ATTR(nsHTMLImageElement, LowSrc, lowsrc) NS_IMPL_STRING_ATTR(nsHTMLImageElement, Name, name) NS_IMPL_STRING_ATTR(nsHTMLImageElement, Align, align) NS_IMPL_STRING_ATTR(nsHTMLImageElement, Alt, alt) -NS_IMPL_STRING_ATTR(nsHTMLImageElement, Border, border) NS_IMPL_INT_ATTR(nsHTMLImageElement, Border, border) -NS_IMPL_STRING_ATTR(nsHTMLImageElement, Hspace, hspace) NS_IMPL_INT_ATTR(nsHTMLImageElement, Hspace, hspace) NS_IMPL_BOOL_ATTR(nsHTMLImageElement, IsMap, ismap) NS_IMPL_STRING_ATTR(nsHTMLImageElement, LongDesc, longdesc) NS_IMPL_STRING_ATTR(nsHTMLImageElement, Lowsrc, lowsrc) NS_IMPL_STRING_ATTR(nsHTMLImageElement, UseMap, usemap) -NS_IMPL_STRING_ATTR(nsHTMLImageElement, Vspace, vspace) NS_IMPL_INT_ATTR(nsHTMLImageElement, Vspace, vspace) nsresult @@ -353,38 +367,6 @@ nsHTMLImageElement::GetComplete(PRBool* aComplete) return NS_OK; } -NS_IMETHODIMP -nsHTMLImageElement::GetHeight(nsAWritableString& aValue) -{ - nsresult rv = nsGenericHTMLLeafElement::GetAttribute(kNameSpaceID_None, - nsHTMLAtoms::height, - aValue); - - if (rv == NS_CONTENT_ATTR_NOT_THERE) { - PRInt32 height = 0; - - aValue.Truncate(); - - // A zero height most likely means that the image is not loaded yet. - if (NS_SUCCEEDED(GetHeight(&height)) && height) { - nsAutoString heightStr; - heightStr.AppendInt(height); - aValue.Append(heightStr); - aValue.Append(NS_LITERAL_STRING("px")); - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLImageElement::SetHeight(const nsAReadableString& aValue) -{ - return nsGenericHTMLLeafElement::SetAttribute(kNameSpaceID_None, - nsHTMLAtoms::height, - aValue, PR_TRUE); -} - NS_IMETHODIMP nsHTMLImageElement::GetHeight(PRInt32* aHeight) { @@ -438,38 +420,6 @@ nsHTMLImageElement::SetHeight(PRInt32 aHeight) val, PR_TRUE); } -NS_IMETHODIMP -nsHTMLImageElement::GetWidth(nsAWritableString& aValue) -{ - nsresult rv = nsGenericHTMLLeafElement::GetAttribute(kNameSpaceID_None, - nsHTMLAtoms::width, - aValue); - - if (rv == NS_CONTENT_ATTR_NOT_THERE) { - PRInt32 width = 0; - - aValue.Truncate(); - - // A zero width most likely means that the image is not loaded yet. - if (NS_SUCCEEDED(GetWidth(&width)) && width) { - nsAutoString widthStr; - widthStr.AppendInt(width); - aValue.Append(widthStr); - aValue.Append(NS_LITERAL_STRING("px")); - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLImageElement::SetWidth(const nsAReadableString& aValue) -{ - return nsGenericHTMLLeafElement::SetAttribute(kNameSpaceID_None, - nsHTMLAtoms::width, aValue, - PR_TRUE); -} - NS_IMETHODIMP nsHTMLImageElement::GetWidth(PRInt32* aWidth) { @@ -652,41 +602,8 @@ nsHTMLImageElement::HandleDOMEvent(nsIPresContext* aPresContext, aEventStatus); } -PRBool -nsHTMLImageElement::GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp) -{ - // XXX Security manager needs to be called - if (JSVAL_IS_STRING(aID)) { - PRUnichar* ustr = - NS_REINTERPRET_CAST(PRUnichar *, - JS_GetStringChars(JS_ValueToString(aContext, aID))); - - if (NS_LITERAL_STRING("src").Equals(ustr)) { - nsAutoString src; - if (NS_SUCCEEDED(GetSrc(src))) { - const PRUnichar* bytes = src.GetUnicode(); - JSString* str = JS_NewUCStringCopyZ(aContext, (const jschar*)bytes); - if (str) { - *aVp = STRING_TO_JSVAL(str); - return PR_TRUE; - } - else { - return PR_FALSE; - } - } - else { - return PR_FALSE; - } - } - } - - return nsGenericHTMLLeafElement::GetProperty(aContext, aObj, aID, aVp); -} - nsresult -nsHTMLImageElement::GetCallerSourceURL(JSContext* cx, - nsIURI** sourceURL) +nsHTMLImageElement::GetCallerSourceURL(nsIURI** sourceURL) { // XXX Code duplicated from nsHTMLDocument // XXX Question, why does this return NS_OK on failure? @@ -697,6 +614,23 @@ nsHTMLImageElement::GetCallerSourceURL(JSContext* cx, // that we can get the url of the caller. // XXX This will fail on non-DOM contexts :( + // Get JSContext from stack. + + + + + // XXX: This service should be cached. + nsCOMPtr + stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result)); + + if (NS_FAILED(result)) + return NS_ERROR_FAILURE; + + JSContext *cx; + + if (NS_FAILED(stack->Peek(&cx))) + return NS_ERROR_FAILURE; + nsCOMPtr global; nsContentUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global)); if (global) { @@ -722,91 +656,6 @@ nsHTMLImageElement::GetCallerSourceURL(JSContext* cx, return result; } -PRBool -nsHTMLImageElement::SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp) -{ - nsresult result = NS_OK; - - // XXX Security manager needs to be called - if (JSVAL_IS_STRING(aID)) { - PRUnichar* ustr = - NS_REINTERPRET_CAST(PRUnichar *, - JS_GetStringChars(JS_ValueToString(aContext, aID))); - - if (NS_LITERAL_STRING("src").Equals(ustr)) { - nsCOMPtr base; - nsAutoString src, url; - - // Get the parameter passed in - JSString *jsstring; - if ((jsstring = JS_ValueToString(aContext, *aVp))) { - src.Assign(NS_REINTERPRET_CAST(const PRUnichar*, - JS_GetStringChars(jsstring))); - src.Trim(" \t\n\r"); - } - - // Get the source of the caller - result = GetCallerSourceURL(aContext, getter_AddRefs(base)); - - if (NS_SUCCEEDED(result)) { - if (base) { - result = NS_MakeAbsoluteURI(url, src, base); - } else { - url.Assign(src); - } - - if (NS_SUCCEEDED(result)) { - result = SetSrcInner(base, url); - } - } - } - else { - result = nsGenericHTMLLeafElement::SetProperty(aContext, aObj, aID, aVp); - } - } - else { - result = nsGenericHTMLLeafElement::SetProperty(aContext, aObj, aID, aVp); - } - - if (NS_FAILED(result)) { - return PR_FALSE; - } - - return PR_TRUE; -} - -PRBool -nsHTMLImageElement::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty) -{ - if (JSVAL_IS_STRING(aID) && mDOMSlots) { - JSString *str; - - str = JSVAL_TO_STRING(aID); - - const jschar *chars = ::JS_GetStringChars(str); - const PRUnichar *unichars = NS_REINTERPRET_CAST(const PRUnichar*, chars); - - if (!nsCRT::strcmp(unichars, NS_LITERAL_STRING("src").get())) { - // Someone is trying to resolve "src" so we deifine it on the - // object with a JSVAL_VOID value, the real value will be returned - // when the caller calls GetProperty(). - ::JS_DefineUCProperty(aContext, - (JSObject *)mDOMSlots->mScriptObject, - chars, ::JS_GetStringLength(str), - JSVAL_VOID, nsnull, nsnull, 0); - - *aDidDefineProperty = PR_TRUE; - - return PR_TRUE; - } - } - - return nsGenericHTMLLeafElement::Resolve(aContext, aObj, aID, - aDidDefineProperty); -} - NS_IMETHODIMP nsHTMLImageElement::Initialize(JSContext* aContext, JSObject *aObj, @@ -1173,7 +1022,13 @@ nsHTMLImageElement::SetSrc(const nsAReadableString& aSrc) nsCOMPtr baseURL; nsresult result = NS_OK; - if (mOwnerDocument) { + GetCallerSourceURL(getter_AddRefs(baseURL)); + + if (mDocument && !baseURL) { + result = mDocument->GetBaseURL(*getter_AddRefs(baseURL)); + } + + if (mOwnerDocument && !baseURL) { result = mOwnerDocument->GetBaseURL(*getter_AddRefs(baseURL)); } diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 0148df6c85e..49ae99d0bb2 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -31,7 +31,6 @@ #include "nsContentCID.h" #include "nsIComponentManager.h" #include "nsIDOMHTMLFormElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -83,7 +82,7 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafFormElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafFormElement::) // nsIDOMElement // can't use the macro here because input type=text needs to notify up to @@ -170,13 +169,13 @@ public: } // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafFormElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafFormElement::) // nsIDOMHTMLInputElement - NS_DECL_IDOMHTMLINPUTELEMENT + NS_DECL_NSIDOMHTMLINPUTELEMENT // nsIDOMNSHTMLInputElement - NS_DECL_IDOMNSHTMLINPUTELEMENT + NS_DECL_NSIDOMNSHTMLINPUTELEMENT // Overriden nsIFormControl methods NS_IMETHOD GetType(PRInt32* aType); @@ -274,8 +273,22 @@ nsHTMLInputElement::~nsHTMLInputElement() NS_IMPL_ADDREF_INHERITED(nsHTMLInputElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLInputElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI2(nsHTMLInputElement, nsGenericHTMLLeafFormElement, - nsIDOMHTMLInputElement, nsIDOMNSHTMLInputElement) + +// XPConnect interface list for nsHTMLInputElement +NS_CLASSINFO_MAP_BEGIN(HTMLInputElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLInputElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLInputElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLInputElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLInputElement, + nsGenericHTMLLeafFormElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLInputElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLInputElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLInputElement) +NS_HTML_CONTENT_INTERFACE_MAP_END // nsIDOMNode diff --git a/content/html/content/src/nsHTMLInsElement.cpp b/content/html/content/src/nsHTMLInsElement.cpp index bd97827af65..4df513982f2 100644 --- a/content/html/content/src/nsHTMLInsElement.cpp +++ b/content/html/content/src/nsHTMLInsElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLModElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLModElement - NS_DECL_IDOMHTMLMODELEMENT + NS_DECL_NSIDOMHTMLMODELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -96,8 +95,20 @@ nsHTMLInsElement::~nsHTMLInsElement() NS_IMPL_ADDREF_INHERITED(nsHTMLInsElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLInsElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLInsElement, nsGenericHTMLContainerElement, - nsIDOMHTMLModElement); + +// XPConnect interface list for nsHTMLInsElement +NS_CLASSINFO_MAP_BEGIN(HTMLInsElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLModElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLInsElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLInsElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLModElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLInsElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLIsIndexElement.cpp b/content/html/content/src/nsHTMLIsIndexElement.cpp index 96a7cac8e5f..fe0a44777c4 100644 --- a/content/html/content/src/nsHTMLIsIndexElement.cpp +++ b/content/html/content/src/nsHTMLIsIndexElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLIsIndexElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLIsIndexElement - NS_DECL_IDOMHTMLISINDEXELEMENT + NS_DECL_NSIDOMHTMLISINDEXELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -96,8 +95,20 @@ nsHTMLIsIndexElement::~nsHTMLIsIndexElement() NS_IMPL_ADDREF_INHERITED(nsHTMLIsIndexElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLIsIndexElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLIsIndexElement, nsGenericHTMLLeafElement, - nsIDOMHTMLIsIndexElement); + +// XPConnect interface list for nsHTMLIsIndexElement +NS_CLASSINFO_MAP_BEGIN(HTMLIsIndexElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLIsIndexElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLIsIndexElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLIsIndexElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLIsIndexElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLIsIndexElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLLIElement.cpp b/content/html/content/src/nsHTMLLIElement.cpp index 738ac88b7f9..f0b8d9b9a58 100644 --- a/content/html/content/src/nsHTMLLIElement.cpp +++ b/content/html/content/src/nsHTMLLIElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLLIElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -44,16 +43,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLLIElement - NS_DECL_IDOMHTMLLIELEMENT + NS_DECL_NSIDOMHTMLLIELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -107,8 +106,20 @@ nsHTMLLIElement::~nsHTMLLIElement() NS_IMPL_ADDREF_INHERITED(nsHTMLLIElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLLIElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLLIElement, nsGenericHTMLContainerElement, - nsIDOMHTMLLIElement); + +// XPConnect interface list for nsHTMLLIElement +NS_CLASSINFO_MAP_BEGIN(HTMLLIElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLLIElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLLIElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLLIElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLLIElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLLIElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLLabelElement.cpp b/content/html/content/src/nsHTMLLabelElement.cpp index 9bbb940dc64..7a9ba2085a3 100644 --- a/content/html/content/src/nsHTMLLabelElement.cpp +++ b/content/html/content/src/nsHTMLLabelElement.cpp @@ -22,7 +22,6 @@ #include "nsCOMPtr.h" #include "nsIDOMHTMLLabelElement.h" #include "nsIDOMHTMLFormElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -53,10 +52,10 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerFormElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerFormElement::) // nsIDOMElement, because of the "htmlFor" attribute handling we can't - // use the NS_FORWARD_IDOMHTMLELEMENT macro here... + // use the NS_FORWARD_NSIDOMHTMLELEMENT macro here... NS_IMETHOD GetTagName(nsAWritableString& aTagName) { return nsGenericHTMLContainerFormElement::GetTagName(aTagName); } @@ -149,10 +148,10 @@ public: } // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerFormElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerFormElement::) // nsIDOMHTMLLabelElement - NS_DECL_IDOMHTMLLABELELEMENT + NS_DECL_NSIDOMHTMLLABELELEMENT // nsIFormControl NS_IMETHOD GetType(PRInt32* aType); @@ -207,8 +206,20 @@ nsHTMLLabelElement::~nsHTMLLabelElement() NS_IMPL_ADDREF_INHERITED(nsHTMLLabelElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLLabelElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLLabelElement, nsGenericHTMLContainerFormElement, - nsIDOMHTMLLabelElement); + +// XPConnect interface list for nsHTMLLabelElement +NS_CLASSINFO_MAP_BEGIN(HTMLLabelElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLLabelElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLLabelElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLLabelElement, + nsGenericHTMLContainerFormElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLLabelElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLLabelElement) +NS_HTML_CONTENT_INTERFACE_MAP_END // nsIDOMHTMLLabelElement diff --git a/content/html/content/src/nsHTMLLegendElement.cpp b/content/html/content/src/nsHTMLLegendElement.cpp index caa000b1072..3fcd85a3a9a 100644 --- a/content/html/content/src/nsHTMLLegendElement.cpp +++ b/content/html/content/src/nsHTMLLegendElement.cpp @@ -21,7 +21,6 @@ */ #include "nsIDOMHTMLLegendElement.h" #include "nsIDOMHTMLFormElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -47,16 +46,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLLegendElement - NS_DECL_IDOMHTMLLEGENDELEMENT + NS_DECL_NSIDOMHTMLLEGENDELEMENT // nsIFormControl NS_IMETHOD GetType(PRInt32* aType); @@ -111,9 +110,20 @@ nsHTMLLegendElement::~nsHTMLLegendElement() NS_IMPL_ADDREF_INHERITED(nsHTMLLegendElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLLegendElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLLegendElement, - nsGenericHTMLContainerFormElement, - nsIDOMHTMLLegendElement); + +// XPConnect interface list for nsHTMLLegendElement +NS_CLASSINFO_MAP_BEGIN(HTMLLegendElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLLegendElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLLegendElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLLegendElement, + nsGenericHTMLContainerFormElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLLegendElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLLegendElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLLinkElement.cpp b/content/html/content/src/nsHTMLLinkElement.cpp index 1990027f88e..30cb719912c 100644 --- a/content/html/content/src/nsHTMLLinkElement.cpp +++ b/content/html/content/src/nsHTMLLinkElement.cpp @@ -21,7 +21,6 @@ */ #include "nsIDOMHTMLLinkElement.h" #include "nsIDOMLinkStyle.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -53,16 +52,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLLinkElement - NS_DECL_IDOMHTMLLINKELEMENT + NS_DECL_NSIDOMHTMLLINKELEMENT // nsILink NS_IMETHOD GetLinkState(nsLinkState &aState); @@ -74,7 +73,7 @@ public: NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet); // nsIDOMLinkStyle - NS_DECL_IDOMLINKSTYLE + NS_DECL_NSIDOMLINKSTYLE NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, PRUint32 aFlags, @@ -132,9 +131,23 @@ nsHTMLLinkElement::~nsHTMLLinkElement() NS_IMPL_ADDREF_INHERITED(nsHTMLLinkElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLLinkElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI3(nsHTMLLinkElement, nsGenericHTMLLeafElement, - nsIDOMHTMLLinkElement, nsIDOMLinkStyle, - nsIStyleSheetLinkingElement); + +// XPConnect interface list for nsHTMLLinkElement +NS_CLASSINFO_MAP_BEGIN(HTMLLinkElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLLinkElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMLinkStyle) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLLinkElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLLinkElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLLinkElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMLinkStyle) + NS_INTERFACE_MAP_ENTRY(nsIStyleSheetLinkingElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLLinkElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLMapElement.cpp b/content/html/content/src/nsHTMLMapElement.cpp index eadc793d810..b105176d261 100644 --- a/content/html/content/src/nsHTMLMapElement.cpp +++ b/content/html/content/src/nsHTMLMapElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLMapElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -47,16 +46,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLMapElement - NS_DECL_IDOMHTMLMAPELEMENT + NS_DECL_NSIDOMHTMLMAPELEMENT NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute, PRInt32& aHint) const; @@ -113,8 +112,20 @@ nsHTMLMapElement::~nsHTMLMapElement() NS_IMPL_ADDREF_INHERITED(nsHTMLMapElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLMapElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLMapElement, nsGenericHTMLContainerElement, - nsIDOMHTMLMapElement); + +// XPConnect interface list for nsHTMLMapElement +NS_CLASSINFO_MAP_BEGIN(HTMLMapElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLMapElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLMapElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLMapElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLMapElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLMapElement) +NS_HTML_CONTENT_INTERFACE_MAP_END NS_IMETHODIMP diff --git a/content/html/content/src/nsHTMLMenuElement.cpp b/content/html/content/src/nsHTMLMenuElement.cpp index 9e53db8da4a..a79dc967c3f 100644 --- a/content/html/content/src/nsHTMLMenuElement.cpp +++ b/content/html/content/src/nsHTMLMenuElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLMenuElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -48,13 +47,13 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLMenuElement NS_IMETHOD GetCompact(PRBool* aCompact); @@ -112,8 +111,20 @@ nsHTMLMenuElement::~nsHTMLMenuElement() NS_IMPL_ADDREF_INHERITED(nsHTMLMenuElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLMenuElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLMenuElement, nsGenericHTMLContainerElement, - nsIDOMHTMLMenuElement) + +// XPConnect interface list for nsHTMLMenuElement +NS_CLASSINFO_MAP_BEGIN(HTMLMenuElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLMenuElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLMenuElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLMenuElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLMenuElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLMenuElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLMetaElement.cpp b/content/html/content/src/nsHTMLMetaElement.cpp index d09013b9853..19151818d37 100644 --- a/content/html/content/src/nsHTMLMetaElement.cpp +++ b/content/html/content/src/nsHTMLMetaElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLMetaElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLMetaElement - NS_DECL_IDOMHTMLMETAELEMENT + NS_DECL_NSIDOMHTMLMETAELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -97,8 +96,20 @@ NS_IMPL_ADDREF_INHERITED(nsHTMLMetaElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLMetaElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLMetaElement, nsGenericHTMLLeafElement, - nsIDOMHTMLMetaElement) + +// XPConnect interface list for nsHTMLMetaElement +NS_CLASSINFO_MAP_BEGIN(HTMLMetaElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLMetaElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLMetaElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLMetaElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLMetaElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLMetaElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLModElement.cpp b/content/html/content/src/nsHTMLModElement.cpp index d8761897d2d..35836bff951 100644 --- a/content/html/content/src/nsHTMLModElement.cpp +++ b/content/html/content/src/nsHTMLModElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLModElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLModElement - NS_DECL_IDOMHTMLMODELEMENT + NS_DECL_NSIDOMHTMLMODELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -96,8 +95,20 @@ nsHTMLModElement::~nsHTMLModElement() NS_IMPL_ADDREF_INHERITED(nsHTMLModElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLModElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLModElement, nsGenericHTMLContainerElement, - nsIDOMHTMLModElement); + +// XPConnect interface list for nsHTMLModElement +NS_CLASSINFO_MAP_BEGIN(HTMLModElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLModElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLModElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLModElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLModElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLModElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLOListElement.cpp b/content/html/content/src/nsHTMLOListElement.cpp index f6dc2f539d9..4461e583623 100644 --- a/content/html/content/src/nsHTMLOListElement.cpp +++ b/content/html/content/src/nsHTMLOListElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLOListElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -44,16 +43,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLOListElement - NS_DECL_IDOMHTMLOLISTELEMENT + NS_DECL_NSIDOMHTMLOLISTELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -107,8 +106,20 @@ nsHTMLOListElement::~nsHTMLOListElement() NS_IMPL_ADDREF_INHERITED(nsHTMLOListElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLOListElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLOListElement, nsGenericHTMLContainerElement, - nsIDOMHTMLOListElement); + +// XPConnect interface list for nsHTMLOListElement +NS_CLASSINFO_MAP_BEGIN(HTMLOListElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLOListElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLOListElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLOListElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLOListElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLOListElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLObjectElement.cpp b/content/html/content/src/nsHTMLObjectElement.cpp index a324d4690f1..adb6ca4f438 100644 --- a/content/html/content/src/nsHTMLObjectElement.cpp +++ b/content/html/content/src/nsHTMLObjectElement.cpp @@ -37,16 +37,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLObjectElement - NS_DECL_IDOMHTMLOBJECTELEMENT + NS_DECL_NSIDOMHTMLOBJECTELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -59,14 +59,6 @@ public: NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute, PRInt32& aHint) const; NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; - - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject); - - // nsIJSScriptObject - virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); }; nsresult @@ -108,8 +100,20 @@ nsHTMLObjectElement::~nsHTMLObjectElement() NS_IMPL_ADDREF_INHERITED(nsHTMLObjectElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLObjectElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLObjectElement, nsGenericHTMLContainerElement, - nsIDOMHTMLObjectElement); + +// XPConnect interface list for nsHTMLObjectElement +NS_CLASSINFO_MAP_BEGIN(HTMLObjectElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLObjectElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLObjectElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLObjectElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLObjectElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLObjectElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult @@ -268,6 +272,7 @@ nsHTMLObjectElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const return NS_OK; } +#if 0 NS_IMETHODIMP nsHTMLObjectElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) @@ -281,3 +286,4 @@ nsHTMLObjectElement::GetProperty(JSContext *aContext, JSObject *aObj, { return GetPluginProperty(aContext, aObj, aID, aVp); } +#endif diff --git a/content/html/content/src/nsHTMLOptGroupElement.cpp b/content/html/content/src/nsHTMLOptGroupElement.cpp index 954ad3bc576..b456bc6e838 100644 --- a/content/html/content/src/nsHTMLOptGroupElement.cpp +++ b/content/html/content/src/nsHTMLOptGroupElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLOptGroupElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -46,16 +45,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLOptGroupElement - NS_DECL_IDOMHTMLOPTGROUPELEMENT + NS_DECL_NSIDOMHTMLOPTGROUPELEMENT NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, PRUint32 aFlags, @@ -102,8 +101,20 @@ nsHTMLOptGroupElement::~nsHTMLOptGroupElement() NS_IMPL_ADDREF_INHERITED(nsHTMLOptGroupElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLOptGroupElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLOptGroupElement, nsGenericHTMLContainerElement, - nsIDOMHTMLOptGroupElement); + +// XPConnect interface list for nsHTMLOptGroupElement +NS_CLASSINFO_MAP_BEGIN(HTMLOptGroupElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLOptGroupElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLOptGroupElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLOptGroupElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLOptGroupElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLOptGroupElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLOptionElement.cpp b/content/html/content/src/nsHTMLOptionElement.cpp index fc43ab8e6c9..574cbe00af4 100644 --- a/content/html/content/src/nsHTMLOptionElement.cpp +++ b/content/html/content/src/nsHTMLOptionElement.cpp @@ -22,9 +22,7 @@ */ #include "nsIDOMHTMLOptionElement.h" #include "nsIDOMHTMLOptGroupElement.h" -#include "nsIDOMNSHTMLOptionCollection.h" #include "nsIDOMHTMLFormElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -68,16 +66,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLOptionElement - NS_DECL_IDOMHTMLOPTIONELEMENT + NS_DECL_NSIDOMHTMLOPTIONELEMENT // nsIJSNativeInitializer NS_IMETHOD Initialize(JSContext* aContext, JSObject *aObj, @@ -160,8 +158,21 @@ nsHTMLOptionElement::~nsHTMLOptionElement() NS_IMPL_ADDREF_INHERITED(nsHTMLOptionElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLOptionElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI2(nsHTMLOptionElement, nsGenericHTMLContainerElement, - nsIDOMHTMLOptionElement, nsIJSNativeInitializer); + +// XPConnect interface list for nsHTMLOptionElement +NS_CLASSINFO_MAP_BEGIN(HTMLOptionElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLOptionElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLOptionElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLOptionElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLOptionElement) + NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLOptionElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult @@ -413,7 +424,7 @@ nsHTMLOptionElement::GetIndex(PRInt32* aIndex) if (selectElement) { // Get the options from the select object. - nsCOMPtr options; + nsCOMPtr options; selectElement->GetOptions(getter_AddRefs(options)); diff --git a/content/html/content/src/nsHTMLParagraphElement.cpp b/content/html/content/src/nsHTMLParagraphElement.cpp index f47f68a5a21..34b52cbe12c 100644 --- a/content/html/content/src/nsHTMLParagraphElement.cpp +++ b/content/html/content/src/nsHTMLParagraphElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLParagraphElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -46,16 +45,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLParagraphElement - NS_DECL_IDOMHTMLPARAGRAPHELEMENT + NS_DECL_NSIDOMHTMLPARAGRAPHELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -109,8 +108,20 @@ nsHTMLParagraphElement::~nsHTMLParagraphElement() NS_IMPL_ADDREF_INHERITED(nsHTMLParagraphElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLParagraphElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLParagraphElement, nsGenericHTMLContainerElement, - nsIDOMHTMLParagraphElement); + +// XPConnect interface list for nsHTMLParagraphElement +NS_CLASSINFO_MAP_BEGIN(HTMLParagraphElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLParagraphElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLParagraphElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLParagraphElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLParagraphElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLParagraphElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLParamElement.cpp b/content/html/content/src/nsHTMLParamElement.cpp index 2731c050aa2..7bb0a3dd518 100644 --- a/content/html/content/src/nsHTMLParamElement.cpp +++ b/content/html/content/src/nsHTMLParamElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLParamElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLParamElement - NS_DECL_IDOMHTMLPARAMELEMENT + NS_DECL_NSIDOMHTMLPARAMELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -96,8 +95,20 @@ nsHTMLParamElement::~nsHTMLParamElement() NS_IMPL_ADDREF_INHERITED(nsHTMLParamElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLParamElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLParamElement, nsGenericHTMLLeafElement, - nsIDOMHTMLParamElement); + +// XPConnect interface list for nsHTMLParamElement +NS_CLASSINFO_MAP_BEGIN(HTMLParamElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLParamElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLParamElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLParamElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLParamElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLParamElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLPreElement.cpp b/content/html/content/src/nsHTMLPreElement.cpp index c2bc4225fb9..08c9ed678fd 100644 --- a/content/html/content/src/nsHTMLPreElement.cpp +++ b/content/html/content/src/nsHTMLPreElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLPreElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -46,13 +45,13 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLPreElement NS_IMETHOD GetWidth(PRInt32* aWidth); @@ -107,8 +106,20 @@ nsHTMLPreElement::~nsHTMLPreElement() NS_IMPL_ADDREF_INHERITED(nsHTMLPreElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLPreElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLPreElement, nsGenericHTMLContainerElement, - nsIDOMHTMLPreElement); + +// XPConnect interface list for nsHTMLPreElement +NS_CLASSINFO_MAP_BEGIN(HTMLPreElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLPreElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLPreElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLPreElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLPreElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLPreElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLQuoteElement.cpp b/content/html/content/src/nsHTMLQuoteElement.cpp index bf84630d300..aac661bb027 100644 --- a/content/html/content/src/nsHTMLQuoteElement.cpp +++ b/content/html/content/src/nsHTMLQuoteElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLQuoteElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,16 +42,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLQuoteElement - NS_DECL_IDOMHTMLQUOTEELEMENT + NS_DECL_NSIDOMHTMLQUOTEELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -95,8 +94,20 @@ nsHTMLQuoteElement::~nsHTMLQuoteElement() NS_IMPL_ADDREF_INHERITED(nsHTMLQuoteElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLQuoteElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLQuoteElement, nsGenericHTMLContainerElement, - nsIDOMHTMLQuoteElement); + +// XPConnect interface list for nsHTMLQuoteElement +NS_CLASSINFO_MAP_BEGIN(HTMLQuoteElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLQuoteElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLQuoteElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLQuoteElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLQuoteElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLQuoteElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLScriptElement.cpp b/content/html/content/src/nsHTMLScriptElement.cpp index 94c22bc7b01..6f2ddea3740 100644 --- a/content/html/content/src/nsHTMLScriptElement.cpp +++ b/content/html/content/src/nsHTMLScriptElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLScriptElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -44,16 +43,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLScriptElement - NS_DECL_IDOMHTMLSCRIPTELEMENT + NS_DECL_NSIDOMHTMLSCRIPTELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -97,8 +96,20 @@ nsHTMLScriptElement::~nsHTMLScriptElement() NS_IMPL_ADDREF_INHERITED(nsHTMLScriptElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLScriptElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLScriptElement, nsGenericHTMLContainerElement, - nsIDOMHTMLScriptElement); + +// XPConnect interface list for nsHTMLScriptElement +NS_CLASSINFO_MAP_BEGIN(HTMLScriptElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLScriptElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLScriptElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLScriptElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLScriptElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLScriptElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLSelectElement.cpp b/content/html/content/src/nsHTMLSelectElement.cpp index 764c25756e1..0927d1dde45 100644 --- a/content/html/content/src/nsHTMLSelectElement.cpp +++ b/content/html/content/src/nsHTMLSelectElement.cpp @@ -24,7 +24,6 @@ #include "nsIDOMHTMLSelectElement.h" #include "nsIDOMNSHTMLSelectElement.h" #include "nsIDOMHTMLFormElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsITextContent.h" @@ -41,10 +40,9 @@ #include "nsIDOMHTMLOptionElement.h" #include "nsIEventStateManager.h" #include "nsGenericDOMHTMLCollection.h" -#include "nsIJSScriptObject.h" #include "nsISelectElement.h" #include "nsISelectControlFrame.h" -#include "nsIDOMNSHTMLOptionCollection.h" +#include "nsIDOMNSHTMLOptionCollectn.h" // PresState #include "nsISupportsArray.h" @@ -64,8 +62,7 @@ class nsHTMLSelectElement; // nsHTMLOptionCollection class nsHTMLOptionCollection: public nsIDOMNSHTMLOptionCollection, - public nsGenericDOMHTMLCollection, - public nsIJSScriptObject + public nsGenericDOMHTMLCollection { public: nsHTMLOptionCollection(nsHTMLSelectElement* aSelect); @@ -73,30 +70,16 @@ public: NS_DECL_ISUPPORTS_INHERITED - // nsIDOMNSHTMLOptionCollection interface - NS_IMETHOD SetLength(PRUint32 aLength); - NS_IMETHOD GetSelectedIndex(PRInt32 *aSelectedIndex); - NS_IMETHOD SetSelectedIndex(PRInt32 aSelectedIndex); + // nsIDOMNSHTMLOptionCollection interface, can't use the macro + // NS_DECL_NSIDOMNSHTMLOPTIONLIST here since GetLength() is defined + // in mode than one interface + NS_IMETHOD SetLength(PRUint32 aLength); + NS_IMETHOD GetSelectedIndex(PRInt32 *aSelectedIndex); + NS_IMETHOD SetSelectedIndex(PRInt32 aSelectedIndex); + NS_IMETHOD SetOption(PRInt32 aIndex, nsIDOMHTMLOptionElement *aOption); // nsIDOMHTMLCollection interface - NS_DECL_IDOMHTMLCOLLECTION - - // nsIJSScriptObject interface - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - PRBool AddProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - PRBool DeleteProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - PRBool SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj); - PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty); - PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID); - void Finalize(JSContext *aContext, JSObject *aObj); + NS_DECL_NSIDOMHTMLCOLLECTION void AddOption(nsIContent* aOption); void RemoveOption(nsIContent* aOption); @@ -126,19 +109,19 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLSelectElement - NS_DECL_IDOMHTMLSELECTELEMENT + NS_DECL_NSIDOMHTMLSELECTELEMENT // nsIDOMNSHTMLSelectElement - NS_DECL_IDOMNSHTMLSELECTELEMENT + NS_DECL_NSIDOMNSHTMLSELECTELEMENT NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify, PRBool aDeepSetDocument); @@ -172,11 +155,6 @@ public: NS_IMETHOD SetOptionSelected(nsIDOMHTMLOptionElement* anOption, PRBool aIsSelected); - // Overriden nsIJSScriptObject methods - // Implement this to enable setting option via frm.select[x] - virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, nsHTMLValue& aResult); @@ -252,9 +230,23 @@ nsHTMLSelectElement::~nsHTMLSelectElement() NS_IMPL_ADDREF_INHERITED(nsHTMLSelectElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLSelectElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI3(nsHTMLSelectElement, nsGenericHTMLContainerFormElement, - nsIDOMHTMLSelectElement, nsIDOMNSHTMLSelectElement, - nsISelectElement); + +// XPConnect interface list for nsHTMLSelectElement +NS_CLASSINFO_MAP_BEGIN(HTMLSelectElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLSelectElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLSelectElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLSelectElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLSelectElement, + nsGenericHTMLContainerFormElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLSelectElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLSelectElement) + NS_INTERFACE_MAP_ENTRY(nsISelectElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLSelectElement) +NS_HTML_CONTENT_INTERFACE_MAP_END // nsIDOMHTMLSelectElement @@ -413,7 +405,7 @@ nsHTMLSelectElement::Remove(PRInt32 aIndex) } NS_IMETHODIMP -nsHTMLSelectElement::GetOptions(nsIDOMNSHTMLOptionCollection** aValue) +nsHTMLSelectElement::GetOptions(nsIDOMHTMLCollection** aValue) { if (!mOptions) { Init(); @@ -607,7 +599,7 @@ nsHTMLSelectElement::GetSelectedIndex(PRInt32* aValue) } } - nsCOMPtr options; + nsCOMPtr options; rv = GetOptions(getter_AddRefs(options)); if (NS_SUCCEEDED(rv) && options) { @@ -674,7 +666,7 @@ nsHTMLSelectElement::GetOptionIndex(nsIDOMHTMLOptionElement* aOption, *anIndex = 0; // first find index of option - nsCOMPtr options; + nsCOMPtr options; nsresult rv = GetOptions(getter_AddRefs(options)); @@ -914,7 +906,7 @@ nsHTMLSelectElement::GetValue(nsAWritableString& aValue) result = GetSelectedIndex(&selectedIndex); if (NS_SUCCEEDED(result)) { - nsCOMPtr options; + nsCOMPtr options; result = GetOptions(getter_AddRefs(options)); if (NS_SUCCEEDED(result)) { @@ -976,7 +968,7 @@ NS_IMETHODIMP nsHTMLSelectElement::SetValue(const nsAReadableString& aValue) { nsresult result = NS_OK; - nsCOMPtr options; + nsCOMPtr options; result = GetOptions(getter_AddRefs(options)); @@ -1235,7 +1227,7 @@ nsHTMLSelectElement::RemoveOption(nsIContent* aContent) if (NS_SUCCEEDED(result) && selectFrame) { // We can't get our index if we've already been replaced in the - // OptionList. If we couldn't get our index, pass -1, remove + // OptionCollection. If we couldn't get our index, pass -1, remove // all options and recreate Coincidentally, IndexOf returns -1 // if the option isn't found in the list @@ -1489,26 +1481,6 @@ nsHTMLSelectElement::Init() return NS_OK; } - -// nsIJSScriptObject interface - -PRBool -nsHTMLSelectElement::SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp) -{ - nsresult res = NS_OK; - // Set options in the options list by indexing into select - - if (JSVAL_IS_INT(aID) && mOptions) { - res = mOptions->SetProperty(aContext, aObj, aID, aVp); - } else { - res = nsGenericHTMLContainerFormElement::SetProperty(aContext, aObj, aID, - aVp); - } - - return res; -} - //---------------------------------------------------------------------- // nsHTMLOptionCollection implementation @@ -1556,7 +1528,6 @@ nsHTMLOptionCollection::nsHTMLOptionCollection(nsHTMLSelectElement* aSelect) // Do not maintain a reference counted reference. When // the select goes away, it will let us know. mSelect = aSelect; - mScriptObject = nsnull; } nsHTMLOptionCollection::~nsHTMLOptionCollection() @@ -1571,31 +1542,27 @@ nsHTMLOptionCollection::DropReference() mSelect = nsnull; } -// ISupports +// nsISupports + +// XPConnect interface list for nsHTMLOptionCollection +NS_CLASSINFO_MAP_BEGIN(HTMLOptionCollection) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLOptionCollection) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLCollection) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLOptionCollection +NS_INTERFACE_MAP_BEGIN(nsHTMLOptionCollection) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLOptionCollection) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNSHTMLOptionCollection) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLOptionCollection) +NS_INTERFACE_MAP_END + NS_IMPL_ADDREF_INHERITED(nsHTMLOptionCollection, nsGenericDOMHTMLCollection) NS_IMPL_RELEASE_INHERITED(nsHTMLOptionCollection, nsGenericDOMHTMLCollection) -nsresult -nsHTMLOptionCollection::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - NS_ENSURE_ARG_POINTER(aInstancePtr); - - nsISupports *inst = nsnull; - - if (aIID.Equals(NS_GET_IID(nsIJSScriptObject))) { - inst = NS_STATIC_CAST(nsIJSScriptObject *, this); - } else if (aIID.Equals(NS_GET_IID(nsIDOMNSHTMLOptionCollection))) { - inst = NS_STATIC_CAST(nsIDOMNSHTMLOptionCollection *, this); - } else { - return nsGenericDOMHTMLCollection::QueryInterface(aIID, aInstancePtr); - } - - *aInstancePtr = inst; - NS_ADDREF(inst); - - return NS_OK; -} // nsIDOMNSHTMLOptionCollection interface @@ -1628,35 +1595,76 @@ nsHTMLOptionCollection::SetLength(PRUint32 aLength) } NS_IMETHODIMP -nsHTMLOptionCollection::GetSelectedIndex(PRInt32 *aSelectedIndex) +nsHTMLOptionCollection::SetOption(PRInt32 aIndex, + nsIDOMHTMLOptionElement *aOption) { - nsresult result = NS_ERROR_UNEXPECTED; - - if (mSelect) { - if (mDirty) { - GetOptions(); - } - - result = mSelect->GetSelectedIndex(aSelectedIndex); + if (!mSelect) { + return NS_OK; } - return result; + nsresult rv; + + // Update the options list + if (mDirty) { + GetOptions(); + } + + PRInt32 length = mElements.Count(); + + // If the indx is within range + if ((aIndex >= 0) && (aIndex <= length)) { + // if the new option is null, remove this option + if (!aOption) { + mSelect->Remove(aIndex); + + // We're done. + + return NS_OK; + } + + nsCOMPtr ret; + + if (aIndex == length) { + rv = mSelect->AppendChild(aOption, getter_AddRefs(ret)); + } else { + nsIDOMNode *refChild = (nsIDOMNode*)mElements.ElementAt(aIndex); + NS_ENSURE_TRUE(refChild, NS_ERROR_UNEXPECTED); + + nsCOMPtr parent; + + refChild->GetParentNode(getter_AddRefs(parent)); + + if (parent) { + rv = parent->ReplaceChild(aOption, refChild, getter_AddRefs(ret)); + } + } + } + + return rv; +} + +NS_IMETHODIMP +nsHTMLOptionCollection::GetSelectedIndex(PRInt32 *aSelectedIndex) +{ + NS_ENSURE_TRUE(mSelect, NS_ERROR_UNEXPECTED); + + if (mDirty) { + GetOptions(); + } + + return mSelect->GetSelectedIndex(aSelectedIndex); } NS_IMETHODIMP nsHTMLOptionCollection::SetSelectedIndex(PRInt32 aSelectedIndex) { - nsresult result = NS_ERROR_UNEXPECTED; + NS_ENSURE_TRUE(mSelect, NS_ERROR_UNEXPECTED); - if (mSelect) { - if (mDirty) { - GetOptions(); - } - - result = mSelect->SetSelectedIndex(aSelectedIndex); + if (mDirty) { + GetOptions(); } - return result; + return mSelect->SetSelectedIndex(aSelectedIndex); } NS_IMETHODIMP @@ -1730,172 +1738,27 @@ nsHTMLOptionCollection::AddOption(nsIContent* aOption) void nsHTMLOptionCollection::RemoveOption(nsIContent* aOption) { - nsCOMPtr option; + nsCOMPtr option(do_QueryInterface(aOption)); - if (aOption && - NS_SUCCEEDED(aOption->QueryInterface(NS_GET_IID(nsIDOMHTMLOptionElement), - getter_AddRefs(option)))) { - if (mElements.RemoveElement(option)) { - } + if (option) { + mElements.RemoveElement(option); } } PRInt32 nsHTMLOptionCollection::IndexOf(nsIContent* aOption) { - nsCOMPtr option; + nsCOMPtr option(do_QueryInterface(aOption)); if (mDirty && mSelect) { GetOptions(); } - if (aOption && - NS_SUCCEEDED(aOption->QueryInterface(NS_GET_IID(nsIDOMHTMLOptionElement), - getter_AddRefs(option)))) { - return mElements.IndexOf(option); + if (!option) { + return -1; } - return -1; -} - -// nsIScriptObjectOwner interface - -NS_IMETHODIMP -nsHTMLOptionCollection::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (!mScriptObject) { - res = NS_NewScriptNSHTMLOptionCollection(aContext, (nsISupports *)(nsIDOMNSHTMLOptionCollection *)this, nsnull, (void**)&mScriptObject); - } - - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -nsHTMLOptionCollection::SetScriptObject(void* aScriptObject) -{ - return nsGenericDOMHTMLCollection::SetScriptObject(aScriptObject); -} - -// nsIJSScriptObject interface - -PRBool -nsHTMLOptionCollection::AddProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsHTMLOptionCollection::DeleteProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsHTMLOptionCollection::GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsHTMLOptionCollection::SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp) -{ - // XXX How about some error reporting and error - // propogation in this method??? - - if (JSVAL_IS_INT(aID) && mSelect) { - PRInt32 indx = JSVAL_TO_INT(aID); - nsresult result; - - // Update the options list - if (mDirty) { - GetOptions(); - } - - PRInt32 length = mElements.Count(); - - // If the indx is within range - if ((indx >= 0) && (indx <= length)) { - // aVp must refer to an object - if (!JSVAL_IS_OBJECT(*aVp) && - !JS_ConvertValue(aContext, *aVp, JSTYPE_OBJECT, aVp)) { - return PR_FALSE; - } - - // if the value is null, remove this option - if (JSVAL_IS_NULL(*aVp)) { - mSelect->Remove(indx); - - // We're done. - - return PR_TRUE; - } - - JSObject* jsobj = JSVAL_TO_OBJECT(*aVp); - JSClass* jsclass = JS_GetClass(aContext, jsobj); - - if (jsclass && !((~jsclass->flags) & (JSCLASS_HAS_PRIVATE | - JSCLASS_PRIVATE_IS_NSISUPPORTS))) { - nsISupports *supports = (nsISupports *)JS_GetPrivate(aContext, jsobj); - - nsCOMPtr option(do_QueryInterface(supports)); - nsCOMPtr ret; - - if (option) { - if (indx == length) { - result = mSelect->AppendChild(option, getter_AddRefs(ret)); - } - else { - nsIDOMNode *refChild = (nsIDOMNode*)mElements.ElementAt(indx); - if (refChild) { - nsCOMPtr parent; - - refChild->GetParentNode(getter_AddRefs(parent)); - - if (parent) { - parent->ReplaceChild(option, refChild, getter_AddRefs(ret)); - } - } - } - } - } - } - } - - return PR_TRUE; -} - -PRBool -nsHTMLOptionCollection::EnumerateProperty(JSContext *aContext, JSObject *aObj) -{ - return PR_TRUE; -} - -PRBool -nsHTMLOptionCollection::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty) -{ - *aDidDefineProperty = PR_FALSE; - - return PR_TRUE; -} - -PRBool -nsHTMLOptionCollection::Convert(JSContext *aContext, JSObject *aObj, jsval aID) -{ - return PR_TRUE; -} - -void -nsHTMLOptionCollection::Finalize(JSContext *aContext, JSObject *aObj) -{ + return mElements.IndexOf(option); } void diff --git a/content/html/content/src/nsHTMLSharedObjectElement.cpp b/content/html/content/src/nsHTMLSharedObjectElement.cpp index a324d4690f1..adb6ca4f438 100644 --- a/content/html/content/src/nsHTMLSharedObjectElement.cpp +++ b/content/html/content/src/nsHTMLSharedObjectElement.cpp @@ -37,16 +37,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLObjectElement - NS_DECL_IDOMHTMLOBJECTELEMENT + NS_DECL_NSIDOMHTMLOBJECTELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -59,14 +59,6 @@ public: NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute, PRInt32& aHint) const; NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; - - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject); - - // nsIJSScriptObject - virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); }; nsresult @@ -108,8 +100,20 @@ nsHTMLObjectElement::~nsHTMLObjectElement() NS_IMPL_ADDREF_INHERITED(nsHTMLObjectElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLObjectElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLObjectElement, nsGenericHTMLContainerElement, - nsIDOMHTMLObjectElement); + +// XPConnect interface list for nsHTMLObjectElement +NS_CLASSINFO_MAP_BEGIN(HTMLObjectElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLObjectElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLObjectElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLObjectElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLObjectElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLObjectElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult @@ -268,6 +272,7 @@ nsHTMLObjectElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const return NS_OK; } +#if 0 NS_IMETHODIMP nsHTMLObjectElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) @@ -281,3 +286,4 @@ nsHTMLObjectElement::GetProperty(JSContext *aContext, JSObject *aObj, { return GetPluginProperty(aContext, aObj, aID, aVp); } +#endif diff --git a/content/html/content/src/nsHTMLSpacerElement.cpp b/content/html/content/src/nsHTMLSpacerElement.cpp index 4833f26124f..39aa0a94a46 100644 --- a/content/html/content/src/nsHTMLSpacerElement.cpp +++ b/content/html/content/src/nsHTMLSpacerElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -32,13 +31,10 @@ #include "nsIPresContext.h" #include "nsIPresShell.h" #include "nsIHTMLAttributes.h" -#include "nsIJSScriptObject.h" #include "nsSize.h" #include "nsIDocument.h" #include "nsIDOMWindowInternal.h" #include "nsIDOMDocument.h" -#include "nsIScriptContext.h" -#include "nsIScriptGlobalObject.h" #include "nsIURL.h" #include "nsIIOService.h" #include "nsIURL.h" @@ -62,13 +58,13 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -122,7 +118,19 @@ nsHTMLSpacerElement::~nsHTMLSpacerElement() NS_IMPL_ADDREF_INHERITED(nsHTMLSpacerElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLSpacerElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI0(nsHTMLSpacerElement, nsGenericHTMLLeafElement); + +// XPConnect interface list for nsHTMLSpacerElement +NS_CLASSINFO_MAP_BEGIN(HTMLSpacerElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLSpacerElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLSpacerElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLSpacerElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLSpanElement.cpp b/content/html/content/src/nsHTMLSpanElement.cpp index 8e5952aeb5b..41f2d694ef8 100644 --- a/content/html/content/src/nsHTMLSpanElement.cpp +++ b/content/html/content/src/nsHTMLSpanElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -42,13 +41,13 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -92,7 +91,19 @@ nsHTMLSpanElement::~nsHTMLSpanElement() NS_IMPL_ADDREF_INHERITED(nsHTMLSpanElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLSpanElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI0(nsHTMLSpanElement, nsGenericHTMLContainerElement); + +// XPConnect interface list for nsHTMLSpanElement +NS_CLASSINFO_MAP_BEGIN(HTMLSpanElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLSpanElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLSpanElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLSpanElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLStyleElement.cpp b/content/html/content/src/nsHTMLStyleElement.cpp index 8f878b7469c..d25bd30b9ab 100644 --- a/content/html/content/src/nsHTMLStyleElement.cpp +++ b/content/html/content/src/nsHTMLStyleElement.cpp @@ -21,7 +21,6 @@ */ #include "nsIDOMHTMLStyleElement.h" #include "nsIDOMLinkStyle.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -51,19 +50,19 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLStyleElement - NS_DECL_IDOMHTMLSTYLEELEMENT + NS_DECL_NSIDOMHTMLSTYLEELEMENT // nsIDOMLinkStyle - NS_DECL_IDOMLINKSTYLE + NS_DECL_NSIDOMLINKSTYLE // nsIStyleSheetLinkingElement NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet); @@ -116,9 +115,23 @@ nsHTMLStyleElement::~nsHTMLStyleElement() NS_IMPL_ADDREF_INHERITED(nsHTMLStyleElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLStyleElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI3(nsHTMLStyleElement, nsGenericHTMLContainerElement, - nsIDOMHTMLStyleElement, nsIDOMLinkStyle, - nsIStyleSheetLinkingElement); + +// XPConnect interface list for nsHTMLStyleElement +NS_CLASSINFO_MAP_BEGIN(HTMLStyleElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLStyleElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMLinkStyle) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLStyleElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLStyleElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLStyleElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMLinkStyle) + NS_INTERFACE_MAP_ENTRY(nsIStyleSheetLinkingElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLStyleElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLTableCaptionElement.cpp b/content/html/content/src/nsHTMLTableCaptionElement.cpp index 9cc8b66a1b0..33ef2cc2672 100644 --- a/content/html/content/src/nsHTMLTableCaptionElement.cpp +++ b/content/html/content/src/nsHTMLTableCaptionElement.cpp @@ -19,8 +19,7 @@ * * Contributor(s): */ -#include "nsIDOMHTMLTableCaptionElement.h" -#include "nsIScriptObjectOwner.h" +#include "nsIDOMHTMLTableCaptionElem.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -44,16 +43,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLTableCaptionElement - NS_DECL_IDOMHTMLTABLECAPTIONELEMENT + NS_DECL_NSIDOMHTMLTABLECAPTIONELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -107,9 +106,20 @@ nsHTMLTableCaptionElement::~nsHTMLTableCaptionElement() NS_IMPL_ADDREF_INHERITED(nsHTMLTableCaptionElement, nsGenericElement); NS_IMPL_RELEASE_INHERITED(nsHTMLTableCaptionElement, nsGenericElement); -NS_IMPL_HTMLCONTENT_QI(nsHTMLTableCaptionElement, - nsGenericHTMLContainerElement, - nsIDOMHTMLTableCaptionElement); + +// XPConnect interface list for nsHTMLTableCaptionElement +NS_CLASSINFO_MAP_BEGIN(HTMLTableCaptionElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLTableCaptionElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLTableCaptionElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTableCaptionElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTableCaptionElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTableCaptionElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLTableCellElement.cpp b/content/html/content/src/nsHTMLTableCellElement.cpp index 6d6ec0bd11c..c1991a9de90 100644 --- a/content/html/content/src/nsHTMLTableCellElement.cpp +++ b/content/html/content/src/nsHTMLTableCellElement.cpp @@ -23,7 +23,6 @@ #include "nsIDOMHTMLTableCellElement.h" #include "nsIDOMHTMLTableRowElement.h" #include "nsIDOMHTMLCollection.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsIHTMLAttributes.h" @@ -48,16 +47,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLTableCellElement - NS_DECL_IDOMHTMLTABLECELLELEMENT + NS_DECL_NSIDOMHTMLTABLECELLELEMENT // nsIHTMLTableCellElement NS_METHOD GetColIndex (PRInt32* aColIndex); @@ -124,10 +123,21 @@ nsHTMLTableCellElement::~nsHTMLTableCellElement() NS_IMPL_ADDREF_INHERITED(nsHTMLTableCellElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTableCellElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI2(nsHTMLTableCellElement, - nsGenericHTMLContainerElement, - nsIDOMHTMLTableCellElement, - nsIHTMLTableCellElement); + +// XPConnect interface list for nsHTMLTableCellElement +NS_CLASSINFO_MAP_BEGIN(HTMLTableCellElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLTableCellElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLTableCellElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTableCellElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTableCellElement) + NS_INTERFACE_MAP_ENTRY(nsIHTMLTableCellElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTableCellElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult @@ -227,70 +237,6 @@ nsHTMLTableCellElement::GetCellIndex(PRInt32* aCellIndex) return NS_OK; } -NS_IMETHODIMP -nsHTMLTableCellElement::SetCellIndex(PRInt32 aCellIndex) -{ - PRInt32 oldIndex; - nsresult result = GetCellIndex(&oldIndex); - - if ((-1 == oldIndex) || (oldIndex == aCellIndex) || NS_FAILED(result)) { - return NS_OK; - } - - nsCOMPtr row; - - GetRow(getter_AddRefs(row)); - - if (!row) { - return NS_OK; - } - - nsCOMPtr cells; - - row->GetCells(getter_AddRefs(cells)); - - if (!cells) { - return NS_OK; - } - - PRUint32 numCellsU; - cells->GetLength(&numCellsU); - - PRInt32 numCells = numCellsU; - - // check if it really moves - if (!(((0 == oldIndex) && (aCellIndex <= 0)) || - ((numCells-1 == oldIndex) && (aCellIndex >= numCells-1)))) { - nsCOMPtr kungFuDeathGrip(NS_STATIC_CAST(nsIContent *, this)); - - row->DeleteCell(oldIndex); // delete this from the row - - numCells--; - nsCOMPtr returnNode; - - if ((numCells <= 0) || (aCellIndex >= numCells)) { - // add this back into the row - row->AppendChild(this, getter_AddRefs(returnNode)); - } else { - PRInt32 newIndex = aCellIndex; - - if (aCellIndex <= 0) { - newIndex = 0; - } else if (aCellIndex > oldIndex) { - newIndex--; - } - - nsCOMPtr refNode; - cells->Item(newIndex, getter_AddRefs(refNode)); - - // add this back into the row - row->InsertBefore(this, refNode, getter_AddRefs(returnNode)); - } - } - - return NS_OK; -} - NS_IMETHODIMP nsHTMLTableCellElement::GetContentStyleRules(nsISupportsArray* aRules) { diff --git a/content/html/content/src/nsHTMLTableColElement.cpp b/content/html/content/src/nsHTMLTableColElement.cpp index 697cc2aaf62..d6f3695a3a0 100644 --- a/content/html/content/src/nsHTMLTableColElement.cpp +++ b/content/html/content/src/nsHTMLTableColElement.cpp @@ -21,7 +21,6 @@ */ #include "nsIDOMHTMLTableColElement.h" #include "nsIHTMLTableColElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsIHTMLAttributes.h" @@ -46,16 +45,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLTableColElement - NS_DECL_IDOMHTMLTABLECOLELEMENT + NS_DECL_NSIDOMHTMLTABLECOLELEMENT // nsIHTMLTableColElement NS_IMETHOD GetSpanValue(PRInt32* aSpan); @@ -112,10 +111,21 @@ nsHTMLTableColElement::~nsHTMLTableColElement() NS_IMPL_ADDREF_INHERITED(nsHTMLTableColElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTableColElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI2(nsHTMLTableColElement, - nsGenericHTMLContainerElement, - nsIDOMHTMLTableColElement, - nsIHTMLTableColElement); + +// XPConnect interface list for nsHTMLTableColElement +NS_CLASSINFO_MAP_BEGIN(HTMLTableColElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLTableColElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLTableColElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTableColElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTableColElement) + NS_INTERFACE_MAP_ENTRY(nsIHTMLTableColElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTableColElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLTableColGroupElement.cpp b/content/html/content/src/nsHTMLTableColGroupElement.cpp index 3eabe2a2b57..c6f75ead1fc 100644 --- a/content/html/content/src/nsHTMLTableColGroupElement.cpp +++ b/content/html/content/src/nsHTMLTableColGroupElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLTableColElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsIHTMLAttributes.h" @@ -44,16 +43,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLTableColElement - NS_DECL_IDOMHTMLTABLECOLELEMENT + NS_DECL_NSIDOMHTMLTABLECOLELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -108,9 +107,20 @@ nsHTMLTableColGroupElement::~nsHTMLTableColGroupElement() NS_IMPL_ADDREF_INHERITED(nsHTMLTableColGroupElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTableColGroupElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLTableColGroupElement, - nsGenericHTMLContainerElement, - nsIDOMHTMLTableColElement); + +// XPConnect interface list for nsHTMLTableColGroupElement +NS_CLASSINFO_MAP_BEGIN(HTMLTableColGroupElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLTableColElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLTableColGroupElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTableColGroupElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTableColElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTableColGroupElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLTableElement.cpp b/content/html/content/src/nsHTMLTableElement.cpp index e96afc16272..95d40fbf168 100644 --- a/content/html/content/src/nsHTMLTableElement.cpp +++ b/content/html/content/src/nsHTMLTableElement.cpp @@ -20,10 +20,9 @@ * Contributor(s): */ #include "nsIDOMHTMLTableElement.h" -#include "nsIDOMHTMLTableCaptionElement.h" -#include "nsIDOMHTMLTableSectionElement.h" +#include "nsIDOMHTMLTableCaptionElem.h" +#include "nsIDOMHTMLTableSectionElem.h" #include "nsCOMPtr.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "GenericElementCollection.h" #include "nsIHTMLContent.h" @@ -57,16 +56,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLTableElement - NS_DECL_IDOMHTMLTABLEELEMENT + NS_DECL_NSIDOMHTMLTABLEELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -353,9 +352,20 @@ nsHTMLTableElement::~nsHTMLTableElement() NS_IMPL_ADDREF_INHERITED(nsHTMLTableElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTableElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLTableElement, - nsGenericHTMLContainerElement, - nsIDOMHTMLTableElement); + +// XPConnect interface list for nsHTMLTableElement +NS_CLASSINFO_MAP_BEGIN(HTMLTableElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLTableElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLTableElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTableElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTableElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTableElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLTableRowElement.cpp b/content/html/content/src/nsHTMLTableRowElement.cpp index eb06528fbfa..6aaebbaca29 100644 --- a/content/html/content/src/nsHTMLTableRowElement.cpp +++ b/content/html/content/src/nsHTMLTableRowElement.cpp @@ -21,9 +21,8 @@ */ #include "nsIDOMHTMLTableRowElement.h" #include "nsIDOMHTMLTableElement.h" -#include "nsIDOMHTMLTableSectionElement.h" +#include "nsIDOMHTMLTableSectionElem.h" #include "nsIDOMHTMLTableCellElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsIHTMLAttributes.h" @@ -154,16 +153,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLTableRowElement - NS_DECL_IDOMHTMLTABLEROWELEMENT + NS_DECL_NSIDOMHTMLTABLEROWELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -256,9 +255,20 @@ nsHTMLTableRowElement::~nsHTMLTableRowElement() NS_IMPL_ADDREF_INHERITED(nsHTMLTableRowElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTableRowElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLTableRowElement, - nsGenericHTMLContainerElement, - nsIDOMHTMLTableRowElement); + +// XPConnect interface list for nsHTMLTableRowElement +NS_CLASSINFO_MAP_BEGIN(HTMLTableRowElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLTableRowElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLTableRowElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTableRowElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTableRowElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTableRowElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult @@ -367,71 +377,6 @@ nsHTMLTableRowElement::GetRowIndex(PRInt32* aValue) return result; } -// this tells the table to delete a row and then insert it in a -// different place. This will generate 2 reflows until things get -// fixed at a higher level (e.g. DOM batching). -NS_IMETHODIMP -nsHTMLTableRowElement::SetRowIndex(PRInt32 aValue) -{ - PRInt32 oldIndex; - nsresult result = GetRowIndex(&oldIndex); - - if ((-1 == oldIndex) || (oldIndex == aValue) || (NS_OK != result)) { - return result; - } - - nsCOMPtr table; - - result = GetTable(getter_AddRefs(table)); - - if (NS_FAILED(result) || !table) { - return result; - } - - nsCOMPtr rows; - - table->GetRows(getter_AddRefs(rows)); - - PRUint32 numRowsU; - rows->GetLength(&numRowsU); - PRInt32 numRows = numRowsU; // numRows will be > 0 since this must be a row - - // check if it really moves - if (!(((0 == oldIndex) && (aValue <= 0)) || - ((numRows-1 == oldIndex) && (aValue >= numRows-1)))) { - nsCOMPtr section; - nsCOMPtr refRow; - - PRInt32 refIndex = aValue; - - if (aValue < numRows) { - refIndex = 0; - } else { - refIndex = numRows-1; - } - - rows->Item(refIndex, getter_AddRefs(refRow)); - - refRow->GetParentNode(getter_AddRefs(section)); - - nsCOMPtr kungFuDeathGrip(NS_STATIC_CAST(nsIContent *, this)); - - table->DeleteRow(oldIndex); // delete this from the table - - nsCOMPtr returnNode; - - if (aValue >= numRows) { - // add this back into the table - section->AppendChild(this, getter_AddRefs(returnNode)); - } else { - // add this back into the table - section->InsertBefore(this, refRow, getter_AddRefs(returnNode)); - } - } - - return NS_OK; -} - NS_IMETHODIMP nsHTMLTableRowElement::GetSectionRowIndex(PRInt32* aValue) { @@ -465,65 +410,6 @@ nsHTMLTableRowElement::GetSectionRowIndex(PRInt32* aValue) return NS_OK; } -// this generates 2 reflows like SetRowIndex -NS_IMETHODIMP -nsHTMLTableRowElement::SetSectionRowIndex(PRInt32 aValue) -{ - PRInt32 oldIndex; - nsresult result = GetRowIndex(&oldIndex); - - if ((-1 == oldIndex) || (oldIndex == aValue) || (NS_OK != result)) { - return result; - } - - nsCOMPtr section; - - result = GetSection(getter_AddRefs(section)); - - if (NS_FAILED(result) || (nsnull == section)) { - return result; - } - - nsCOMPtr rows; - section->GetRows(getter_AddRefs(rows)); - - PRUint32 numRowsU; - rows->GetLength(&numRowsU); - PRInt32 numRows = numRowsU; - - // check if it really moves - if (!(((0 == oldIndex) && (aValue <= 0)) || - ((numRows-1 == oldIndex) && (aValue >= numRows-1)))) { - nsCOMPtr kungFuDeathGrip(NS_STATIC_CAST(nsIContent *, this)); - - section->DeleteRow(oldIndex); // delete this from the section - numRows--; - - nsCOMPtr returnNode; - if ((numRows <= 0) || (aValue >= numRows)) { - // add this back into the section - section->AppendChild(this, getter_AddRefs(returnNode)); - } else { - PRInt32 newIndex = aValue; - - if (aValue <= 0) { - newIndex = 0; - } else if (aValue > oldIndex) { - // since this got removed before GetLength was called - newIndex--; - } - - nsCOMPtr refNode; - rows->Item(newIndex, getter_AddRefs(refNode)); - - // add this back into the section - section->InsertBefore(this, refNode, getter_AddRefs(returnNode)); - } - } - - return NS_OK; -} - NS_IMETHODIMP nsHTMLTableRowElement::GetCells(nsIDOMHTMLCollection** aValue) { @@ -540,38 +426,6 @@ nsHTMLTableRowElement::GetCells(nsIDOMHTMLCollection** aValue) return NS_OK; } -NS_IMETHODIMP -nsHTMLTableRowElement::SetCells(nsIDOMHTMLCollection* aValue) -{ - nsCOMPtr cells; - GetCells(getter_AddRefs(cells)); - - PRUint32 numCells; - cells->GetLength(&numCells); - - PRUint32 i; - - for (i = 0; i < numCells; i++) { - DeleteCell(i); - } - - numCells = 0; - if (aValue) { - aValue->GetLength(&numCells); - } - - for (i = 0; i < numCells; i++) { - nsCOMPtr node; - cells->Item(i, getter_AddRefs(node)); - - nsCOMPtr retChild; - AppendChild(node, getter_AddRefs(retChild)); - } - - return NS_OK; -} - - NS_IMETHODIMP nsHTMLTableRowElement::InsertCell(PRInt32 aIndex, nsIDOMHTMLElement** aValue) { diff --git a/content/html/content/src/nsHTMLTableSectionElement.cpp b/content/html/content/src/nsHTMLTableSectionElement.cpp index 496d0a70b70..9b0a574f2db 100644 --- a/content/html/content/src/nsHTMLTableSectionElement.cpp +++ b/content/html/content/src/nsHTMLTableSectionElement.cpp @@ -19,8 +19,7 @@ * * Contributor(s): */ -#include "nsIDOMHTMLTableSectionElement.h" -#include "nsIScriptObjectOwner.h" +#include "nsIDOMHTMLTableSectionElem.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsIHTMLAttributes.h" @@ -47,16 +46,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLTableSectionElement - NS_DECL_IDOMHTMLTABLESECTIONELEMENT + NS_DECL_NSIDOMHTMLTABLESECTIONELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -118,9 +117,20 @@ nsHTMLTableSectionElement::~nsHTMLTableSectionElement() NS_IMPL_ADDREF_INHERITED(nsHTMLTableSectionElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTableSectionElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLTableSectionElement, - nsGenericHTMLContainerElement, - nsIDOMHTMLTableSectionElement); + +// XPConnect interface list for nsHTMLTableSectionElement +NS_CLASSINFO_MAP_BEGIN(HTMLTableSectionElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLTableSectionElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLTableSectionElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTableSectionElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTableSectionElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTableSectionElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLTextAreaElement.cpp b/content/html/content/src/nsHTMLTextAreaElement.cpp index f87d554e926..01dfb02ba12 100644 --- a/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -30,7 +30,6 @@ #include "nsIDOMHTMLFormElement.h" #include "nsIFormControl.h" #include "nsIForm.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -66,19 +65,19 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLTextAreaElement - NS_DECL_IDOMHTMLTEXTAREAELEMENT + NS_DECL_NSIDOMHTMLTEXTAREAELEMENT // nsIDOMNSHTMLTextAreaElement - NS_DECL_IDOMNSHTMLTEXTAREAELEMENT + NS_DECL_NSIDOMNSHTMLTEXTAREAELEMENT // nsIFormControl NS_IMETHOD GetType(PRInt32* aType); @@ -144,10 +143,22 @@ nsHTMLTextAreaElement::~nsHTMLTextAreaElement() NS_IMPL_ADDREF_INHERITED(nsHTMLTextAreaElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTextAreaElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI2(nsHTMLTextAreaElement, - nsGenericHTMLContainerFormElement, - nsIDOMHTMLTextAreaElement, - nsIDOMNSHTMLTextAreaElement); + +// XPConnect interface list for nsHTMLTextAreaElement +NS_CLASSINFO_MAP_BEGIN(HTMLTextAreaElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLTextAreaElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLTextAreaElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLTextAreaElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTextAreaElement, + nsGenericHTMLContainerFormElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTextAreaElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLTextAreaElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTextAreaElement) +NS_HTML_CONTENT_INTERFACE_MAP_END // nsIDOMHTMLTextAreaElement diff --git a/content/html/content/src/nsHTMLTitleElement.cpp b/content/html/content/src/nsHTMLTitleElement.cpp index 74445791718..bb8a8cb6464 100644 --- a/content/html/content/src/nsHTMLTitleElement.cpp +++ b/content/html/content/src/nsHTMLTitleElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLTitleElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -46,16 +45,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLTitleElement - NS_DECL_IDOMHTMLTITLEELEMENT + NS_DECL_NSIDOMHTMLTITLEELEMENT NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -99,9 +98,20 @@ nsHTMLTitleElement::~nsHTMLTitleElement() NS_IMPL_ADDREF_INHERITED(nsHTMLTitleElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTitleElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLTitleElement, - nsGenericHTMLContainerElement, - nsIDOMHTMLTitleElement); + +// XPConnect interface list for nsHTMLTitleElement +NS_CLASSINFO_MAP_BEGIN(HTMLTitleElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLTitleElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLTitleElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTitleElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTitleElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTitleElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLUListElement.cpp b/content/html/content/src/nsHTMLUListElement.cpp index 6396b13dbff..6db851762b6 100644 --- a/content/html/content/src/nsHTMLUListElement.cpp +++ b/content/html/content/src/nsHTMLUListElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLUListElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -46,16 +45,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLUListElement - NS_DECL_IDOMHTMLULISTELEMENT + NS_DECL_NSIDOMHTMLULISTELEMENT NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, const nsAReadableString& aValue, @@ -109,9 +108,20 @@ nsHTMLUListElement::~nsHTMLUListElement() NS_IMPL_ADDREF_INHERITED(nsHTMLUListElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLUListElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLUListElement, - nsGenericHTMLContainerElement, - nsIDOMHTMLUListElement); + +// XPConnect interface list for nsHTMLUListElement +NS_CLASSINFO_MAP_BEGIN(HTMLUListElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLUListElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLUListElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLUListElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLUListElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLUListElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLUnknownElement.cpp b/content/html/content/src/nsHTMLUnknownElement.cpp index 2694a748642..d310cfa466a 100644 --- a/content/html/content/src/nsHTMLUnknownElement.cpp +++ b/content/html/content/src/nsHTMLUnknownElement.cpp @@ -19,7 +19,6 @@ * * Contributor(s): */ -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -51,13 +50,13 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLContainerElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerElement::) NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, const nsAReadableString& aValue, PRBool aNotify); @@ -103,8 +102,19 @@ nsHTMLUnknownElement::~nsHTMLUnknownElement() NS_IMPL_ADDREF_INHERITED(nsHTMLUnknownElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLUnknownElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI0(nsHTMLUnknownElement, - nsGenericHTMLContainerElement); + +// XPConnect interface list for nsHTMLUnknownElement +NS_CLASSINFO_MAP_BEGIN(HTMLUnknownElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLUnknownElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLUnknownElement, + nsGenericHTMLContainerElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLUnknownElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/content/src/nsHTMLWBRElement.cpp b/content/html/content/src/nsHTMLWBRElement.cpp index 29bdfa68892..37e6c6fbe61 100644 --- a/content/html/content/src/nsHTMLWBRElement.cpp +++ b/content/html/content/src/nsHTMLWBRElement.cpp @@ -20,7 +20,6 @@ * Contributor(s): */ #include "nsIDOMHTMLElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" #include "nsGenericHTMLElement.h" @@ -43,13 +42,13 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLLeafElement::) // nsIDOMHTMLElement - NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::) + NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLLeafElement::) NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; }; @@ -93,8 +92,20 @@ nsHTMLWBRElement::~nsHTMLWBRElement() NS_IMPL_ADDREF_INHERITED(nsHTMLWBRElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLWBRElement, nsGenericElement) -NS_IMPL_HTMLCONTENT_QI(nsHTMLWBRElement, nsGenericHTMLLeafElement, - nsIDOMHTMLElement); + +// XPConnect interface list for nsHTMLWBRElement +NS_CLASSINFO_MAP_BEGIN(HTMLWBRElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLElement) + NS_CLASSINFO_MAP_ENTRY_FUNCTION(GetGenericHTMLElementIIDs) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLWBRElement +NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLWBRElement, + nsGenericHTMLLeafElement) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLElement) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLWBRElement) +NS_HTML_CONTENT_INTERFACE_MAP_END nsresult diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index ce4114c976e..779351fab8f 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -314,7 +314,7 @@ public: nsIDocument* mDocument; nsIHTMLDocument* mHTMLDocument; - nsINodeInfoManager* mNodeInfoManager; + nsCOMPtr mNodeInfoManager; nsIURI* mDocumentURI; nsIURI* mDocumentBaseURL; nsCOMPtr mScriptURI; @@ -2246,7 +2246,6 @@ HTMLContentSink::HTMLContentSink() { mInNotification = 0; mInMonolithicContainer = 0; mInsideNoXXXTag = 0; - mNodeInfoManager = nsnull; mFlags=0; } @@ -2271,8 +2270,6 @@ HTMLContentSink::~HTMLContentSink() NS_IF_RELEASE(mCurrentForm); NS_IF_RELEASE(mCurrentMap); - NS_IF_RELEASE(mNodeInfoManager); - if (mNotificationTimer) { mNotificationTimer->Cancel(); } @@ -2343,7 +2340,7 @@ HTMLContentSink::Init(nsIDocument* aDoc, NS_ADDREF(aDoc); aDoc->AddObserver(this); aDoc->QueryInterface(NS_GET_IID(nsIHTMLDocument), (void**)&mHTMLDocument); - rv = mDocument->GetNodeInfoManager(mNodeInfoManager); + rv = mDocument->GetNodeInfoManager(*getter_AddRefs(mNodeInfoManager)); NS_ENSURE_SUCCESS(rv, rv); mDocumentURI = aURL; NS_ADDREF(aURL); @@ -3029,11 +3026,6 @@ HTMLContentSink::OpenForm(const nsIParserNode& aNode) } } - // add the form to the document - if (mCurrentForm) { - mHTMLDocument->AddForm(mCurrentForm); - } - MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::OpenForm()\n")); MOZ_TIMER_STOP(mWatch); return result; diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 9fc3170828c..94d3eb6b72a 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -66,13 +66,12 @@ #include "nsIWebShellServices.h" #include "nsIDocumentLoader.h" #include "nsIScriptGlobalObject.h" +#include "nsIXPConnect.h" #include "nsContentList.h" #include "nsDOMError.h" #include "nsICodebasePrincipal.h" #include "nsIAggregatePrincipal.h" #include "nsIScriptSecurityManager.h" -#include "nsJSUtils.h" -#include "nsDOMPropEnums.h" #include "nsIScrollableView.h" #include "nsIIOService.h" @@ -110,7 +109,9 @@ #include "nsICacheEntryDescriptor.h" #include "nsIXMLContent.h" //for createelementNS #include "nsHTMLParts.h" //for createelementNS -#include "nsLayoutCID.h" +#include "nsIJSContextStack.h" +#include "nsContentUtils.h" + #include "nsContentCID.h" #include "nsIPrompt.h" //AHMED 12-2 @@ -283,49 +284,35 @@ nsHTMLDocument::~nsHTMLDocument() InvalidateHashTables(); } +NS_IMPL_ADDREF_INHERITED(nsHTMLDocument, nsDocument) +NS_IMPL_RELEASE_INHERITED(nsHTMLDocument, nsDocument) + + +// XPConnect interface list for nsHTMLDocument +NS_CLASSINFO_MAP_BEGIN(HTMLDocument) + NS_CLASSINFO_MAP_ENTRY(nsIDOMHTMLDocument) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLDocument) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSDocument) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentEvent) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentStyle) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentView) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentRange) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentXBL) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLAnchorElement +NS_INTERFACE_MAP_BEGIN(nsHTMLDocument) + NS_INTERFACE_MAP_ENTRY(nsIHTMLDocument) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDocument) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLDocument) + NS_INTERFACE_MAP_ENTRY(nsIHTMLContentContainer) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDocument) +NS_INTERFACE_MAP_END_INHERITING(nsDocument) + + NS_IMETHODIMP -nsHTMLDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - NS_PRECONDITION(nsnull != aInstancePtr, "null ptr"); - if (nsnull == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsIHTMLDocument))) { - NS_ADDREF_THIS(); - *aInstancePtr = (void**) (nsIHTMLDocument *)this; - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMHTMLDocument))) { - NS_ADDREF_THIS(); - *aInstancePtr = (void**) (nsIDOMHTMLDocument *)this; - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNSHTMLDocument))) { - NS_ADDREF_THIS(); - *aInstancePtr = (void**) (nsIDOMNSHTMLDocument *)this; - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIHTMLContentContainer))) { - NS_ADDREF_THIS(); - *aInstancePtr = (void**) (nsIHTMLContentContainer *)this; - return NS_OK; - } - return nsDocument::QueryInterface(aIID, aInstancePtr); -} - -nsrefcnt -nsHTMLDocument::AddRef() -{ - return nsDocument::AddRef(); -} - -nsrefcnt -nsHTMLDocument::Release() -{ - return nsDocument::Release(); -} - -NS_IMETHODIMP nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) { nsresult result = nsDocument::Reset(aChannel, aLoadGroup); @@ -554,35 +541,34 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, nsCOMPtr file; rv = fileChannel->GetFile(getter_AddRefs(file)); - if (NS_SUCCEEDED(rv)) - { - // if we failed to get a last modification date, then we don't want to necessarily - // fail to create a document for this file. Just don't set the last modified date on it... - rv = file->GetLastModificationDate(&modDate); - if (NS_SUCCEEDED(rv)) - { - PRExplodedTime prtime; - char buf[100]; - PRInt64 intermediateValue; + if (NS_SUCCEEDED(rv)) { + // if we failed to get a last modification date, then we don't + // want to necessarily fail to create a document for this + // file. Just don't set the last modified date on it... + rv = file->GetLastModificationDate(&modDate); + if (NS_SUCCEEDED(rv)) { + PRExplodedTime prtime; + char buf[100]; + PRInt64 intermediateValue; - LL_I2L(intermediateValue, PR_USEC_PER_MSEC); - LL_MUL(usecs, modDate, intermediateValue); - PR_ExplodeTime(usecs, PR_LocalTimeParameters, &prtime); + LL_I2L(intermediateValue, PR_USEC_PER_MSEC); + LL_MUL(usecs, modDate, intermediateValue); + PR_ExplodeTime(usecs, PR_LocalTimeParameters, &prtime); - // Use '%#c' for windows, because '%c' is backward-compatible and - // non-y2k with msvc; '%#c' requests that a full year be used in the - // result string. Other OSes just use "%c". - PR_FormatTime(buf, sizeof buf, - #if defined(XP_PC) && !defined(XP_OS2) + // Use '%#c' for windows, because '%c' is backward-compatible and + // non-y2k with msvc; '%#c' requests that a full year be used in the + // result string. Other OSes just use "%c". + PR_FormatTime(buf, sizeof buf, +#if defined(XP_PC) && !defined(XP_OS2) "%#c", - #else +#else "%c", - #endif +#endif &prtime); - lastModified.AssignWithConversion(buf); - SetLastModified(lastModified); - } + lastModified.AssignWithConversion(buf); + SetLastModified(lastModified); } + } } if (needsParser) { @@ -933,31 +919,7 @@ nsHTMLDocument::EndLoad() NS_IMETHODIMP nsHTMLDocument::SetTitle(const nsAReadableString& aTitle) { - if (nsnull == mDocumentTitle) { - mDocumentTitle = new nsString(aTitle); - } - else { - mDocumentTitle->Assign(aTitle); - } - - // Pass on to any interested containers - PRInt32 i, n = mPresShells.Count(); - for (i = 0; i < n; i++) { - nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(i); - nsCOMPtr cx; - shell->GetPresContext(getter_AddRefs(cx)); - nsCOMPtr container; - if (NS_OK == cx->GetContainer(getter_AddRefs(container))) { - if (container) { - nsCOMPtr docShell(do_QueryInterface(container)); - if(docShell) { - docShell->SetTitle(mDocumentTitle->GetUnicode()); - } - } - } - } - - return NS_OK; + return nsDocument::SetTitle(aTitle); } NS_IMETHODIMP @@ -1705,7 +1667,6 @@ nsHTMLDocument::IsSupported(const nsAReadableString& aFeature, return nsDocument::IsSupported(aFeature, aVersion, aReturn); } -#if 0 NS_IMETHODIMP nsHTMLDocument::GetBaseURI(nsAWritableString &aURI) { @@ -1720,7 +1681,6 @@ nsHTMLDocument::GetBaseURI(nsAWritableString &aURI) } return NS_OK; } -#endif // // nsIDOMHTMLDocument interface implementation @@ -1731,12 +1691,7 @@ nsHTMLDocument::GetBaseURI(nsAWritableString &aURI) NS_IMETHODIMP nsHTMLDocument::GetTitle(nsAWritableString& aTitle) { - if (nsnull != mDocumentTitle) { - aTitle.Assign(*mDocumentTitle); - } else { - aTitle.Truncate(); - } - return NS_OK; + return nsDocument::GetTitle(aTitle); } NS_IMETHODIMP @@ -2283,30 +2238,32 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURL) NS_IMETHODIMP nsHTMLDocument::Open() { - nsresult result = NS_OK; - nsIURI* sourceURL; - - // XXX For the non-script Open case, we have to make - // up a URL. - result = NS_NewURI(&sourceURL, "about:blank"); - - if (NS_SUCCEEDED(result)) { - result = OpenCommon(sourceURL); - NS_RELEASE(sourceURL); - } - - return result; + nsCOMPtr doc; + return Open(getter_AddRefs(doc)); } NS_IMETHODIMP -nsHTMLDocument::Open(JSContext *cx, jsval *argv, PRUint32 argc, - nsIDOMDocument** aReturn) +nsHTMLDocument::Open(nsIDOMDocument** aReturn) { nsresult result = NS_OK; nsIURI* sourceURL; // XXX The URL of the newly created document will match // that of the source document. Is this right? + + // XXX: This service should be cached. + nsCOMPtr + stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result)); + + if (NS_FAILED(result)) + return NS_ERROR_FAILURE; + + JSContext *cx; + + if (NS_FAILED(stack->Peek(&cx))) + return NS_ERROR_FAILURE; + + result = GetSourceDocumentURL(cx, &sourceURL); // Recover if we had a problem obtaining the source URL if (nsnull == sourceURL) { @@ -2326,7 +2283,7 @@ nsHTMLDocument::Open(JSContext *cx, jsval *argv, PRUint32 argc, #define NS_GENERATE_PARSER_KEY() (void*)((mIsWriting << 31) | (mWriteLevel & 0x7fffffff)) NS_IMETHODIMP -nsHTMLDocument::Clear(JSContext* cx, jsval* argv, PRUint32 argc) +nsHTMLDocument::Clear() { // This method has been deprecated return NS_OK; @@ -2355,76 +2312,46 @@ nsresult nsHTMLDocument::WriteCommon(const nsAReadableString& aText, PRBool aNewlineTerminate) { - nsresult result = NS_OK; + nsresult rv; + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); - if (nsnull == mParser) { - result = Open(); - if (NS_FAILED(result)) { - return result; - } + nsCOMPtr ncc; + + if (xpc) { + rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(ncc)); + NS_ENSURE_SUCCESS(rv, rv); } - - nsAutoString str(aText); - - if (aNewlineTerminate) { - str.AppendWithConversion('\n'); - } - - mWriteLevel++; - result = mParser->Parse(str, NS_GENERATE_PARSER_KEY(), - NS_ConvertASCIItoUCS2("text/html"), PR_FALSE, - (!mIsWriting || (mWriteLevel > 1))); - mWriteLevel--; - - return result; -} - -NS_IMETHODIMP -nsHTMLDocument::Write(const nsAReadableString& aText) -{ - return WriteCommon(aText, PR_FALSE); -} - -NS_IMETHODIMP -nsHTMLDocument::Writeln(const nsAReadableString& aText) -{ - return WriteCommon(aText, PR_TRUE); -} - -nsresult -nsHTMLDocument::ScriptWriteCommon(JSContext *cx, - jsval *argv, - PRUint32 argc, - PRBool aNewlineTerminate) -{ - nsresult result = NS_OK; nsXPIDLCString spec; - if (!mDocumentURL || - (NS_SUCCEEDED(mDocumentURL->GetSpec(getter_Copies(spec))) && - nsCRT::strcasecmp(spec, "about:blank") == 0)) - { + + if (mDocumentURL) { + rv = mDocumentURL->GetSpec(getter_Copies(spec)); + NS_ENSURE_SUCCESS(rv, rv); + } + + if (!mDocumentURL || nsCRT::strcasecmp(spec, "about:blank") == 0) { // The current document's URL and principal are empty or "about:blank". // By writing to this document, the script acquires responsibility for the // document for security purposes. Thus a document.write of a script tag // ends up producing a script with the same principals as the script // that performed the write. - nsIScriptContext *context = (nsIScriptContext*)JS_GetContextPrivate(cx); - JSObject* obj; - if (NS_FAILED(GetScriptObject(context, (void**)&obj))) - return NS_ERROR_FAILURE; - nsIScriptSecurityManager *sm = nsJSUtils::nsGetSecurityManager(cx, nsnull); - if (!sm) - return NS_ERROR_FAILURE; + nsCOMPtr secMan = + do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr subject; - if (NS_FAILED(sm->GetSubjectPrincipal(getter_AddRefs(subject)))) - return NS_ERROR_FAILURE; + rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject)); + NS_ENSURE_SUCCESS(rv, rv); + if (subject) { nsCOMPtr codebase = do_QueryInterface(subject); if (codebase) { nsCOMPtr subjectURI; - if (NS_FAILED(codebase->GetURI(getter_AddRefs(subjectURI)))) - return NS_ERROR_FAILURE; + rv = codebase->GetURI(getter_AddRefs(subjectURI)); + NS_ENSURE_SUCCESS(rv, rv); NS_IF_RELEASE(mDocumentURL); mDocumentURL = subjectURI; @@ -2437,53 +2364,77 @@ nsHTMLDocument::ScriptWriteCommon(JSContext *cx, } } - if (!mParser) { - nsCOMPtr doc; + const nsAReadableString *text_to_write = &aText; + nsAutoString string_buffer; - result = Open(cx, argv, argc, getter_AddRefs(doc)); - if (NS_FAILED(result)) { - return result; - } - } + if (ncc) { + // We're called from C++, concatenate the extra arguments into + // string_buffer + PRUint32 i, argc; - if (argc > 0) { - PRUint32 index; - nsAutoString str; + ncc->GetArgc(&argc); - for (index = 0; index < argc; index++) { - JSString *jsstring = JS_ValueToString(cx, argv[index]); - - if (jsstring) { - str.Append(NS_REINTERPRET_CAST(const PRUnichar*, - JS_GetStringChars(jsstring)), - JS_GetStringLength(jsstring)); + if (argc > 1) { + string_buffer.Assign(aText); + text_to_write = &string_buffer; + + JSContext *cx = nsnull; + rv = ncc->GetJSContext(&cx); + NS_ENSURE_SUCCESS(rv, rv); + + jsval *argv = nsnull; + ncc->GetArgvPtr(&argv); + NS_ENSURE_TRUE(argv, NS_ERROR_UNEXPECTED); + + for (i = 1; i < argc; i++) { + + JSString *str = JS_ValueToString(cx, argv[i]); + NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY); + + string_buffer.Append(NS_REINTERPRET_CAST(const PRUnichar *, + ::JS_GetStringChars(str)), + ::JS_GetStringLength(str)); } } + } - if (aNewlineTerminate) { - str.AppendWithConversion('\n'); + if (!mParser) { + rv = Open(); + if (NS_FAILED(rv)) { + return rv; + } + } + + + if (aNewlineTerminate) { + if (string_buffer.IsEmpty()) { + string_buffer.Assign(aText); } - mWriteLevel++; - result = mParser->Parse(str, NS_GENERATE_PARSER_KEY(), - NS_ConvertASCIItoUCS2("text/html"), PR_FALSE, - (!mIsWriting || (mWriteLevel > 1))); - mWriteLevel--; + text_to_write = &string_buffer; + + string_buffer.Append((PRUnichar)'\n'); } - - return result; + + mWriteLevel++; + rv = mParser->Parse(*text_to_write, NS_GENERATE_PARSER_KEY(), + NS_ConvertASCIItoUCS2("text/html"), PR_FALSE, + (!mIsWriting || (mWriteLevel > 1))); + mWriteLevel--; + + return rv; +} + +NS_IMETHODIMP +nsHTMLDocument::Write(const nsAReadableString& aText) +{ + return WriteCommon(aText, PR_FALSE); } NS_IMETHODIMP -nsHTMLDocument::Write(JSContext *cx, jsval *argv, PRUint32 argc) +nsHTMLDocument::Writeln(const nsAReadableString& aText) { - return ScriptWriteCommon(cx, argv, argc, PR_FALSE); -} - -NS_IMETHODIMP -nsHTMLDocument::Writeln(JSContext *cx, jsval *argv, PRUint32 argc) -{ - return ScriptWriteCommon(cx, argv, argc, PR_TRUE); + return WriteCommon(aText, PR_TRUE); } nsIContent * @@ -2722,7 +2673,7 @@ nsHTMLDocument::GetHeight(PRInt32* aHeight) return result; } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLDocument::GetAlinkColor(nsAWritableString& aAlinkColor) { nsresult result = NS_OK; @@ -2746,7 +2697,7 @@ nsHTMLDocument::GetAlinkColor(nsAWritableString& aAlinkColor) return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLDocument::SetAlinkColor(const nsAReadableString& aAlinkColor) { nsresult result = NS_OK; @@ -3502,137 +3453,6 @@ nsHTMLDocument::ResolveName(const nsAReadableString& aName, return NS_OK; } -NS_IMETHODIMP -nsHTMLDocument::NamedItem(JSContext* cx, jsval* argv, PRUint32 argc, - jsval* aReturn) -{ - nsresult rv = NS_OK; - - if (argc < 1) - return NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR; - - JSString *jsstr = ::JS_ValueToString(cx, argv[0]); - PRUnichar *ustr = NS_REINTERPRET_CAST(PRUnichar *, JS_GetStringChars(jsstr)); - - nsCOMPtr item; - - rv = ResolveName(nsLiteralString(ustr, ::JS_GetStringLength(jsstr)), - nsnull, getter_AddRefs(item)); - - nsCOMPtr owner(do_QueryInterface(item)); - - nsIScriptContext *context = (nsIScriptContext*)::JS_GetContextPrivate(cx); - JSObject *scriptObject; - rv = GetScriptObject(context, (void **)&scriptObject); - if (NS_FAILED(rv)) - return rv; - - if (owner) { - nsIScriptSecurityManager *sm = - nsJSUtils::nsGetSecurityManager(cx, scriptObject); - - rv = sm->CheckScriptAccess(cx, scriptObject, - NS_DOM_PROP_NSHTMLFORMELEMENT_NAMEDITEM, - PR_FALSE); - if (NS_SUCCEEDED(rv)) { - JSObject* obj; - - rv = owner->GetScriptObject(context, (void**)&obj); - if (NS_FAILED(rv)) { - return rv; - } - - *aReturn = OBJECT_TO_JSVAL(obj); - } - - return rv; - } - - nsCOMPtr supports; - rv = this->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(supports)); - - if (NS_SUCCEEDED(rv)) { - rv = nsJSUtils::nsCallJSScriptObjectGetProperty(supports, cx, scriptObject, - argv[0], aReturn); - } - - return rv; -} - -NS_IMETHODIMP -nsHTMLDocument::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - nsCOMPtr global; - - if (nsnull == mScriptObject) { - // XXX We make the (possibly erroneous) assumption that the first - // presentation shell represents the "primary view" of the document - // and that the JS parent chain should incorporate just that view. - // This is done for lack of a better model when we have multiple - // views. - nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0); - if (shell) { - nsCOMPtr cx; - shell->GetPresContext(getter_AddRefs(cx)); - nsCOMPtr container; - - res = cx->GetContainer(getter_AddRefs(container)); - if (NS_SUCCEEDED(res) && container) { - global = do_GetInterface(container); - } - } - // XXX If we can't find a view, parent to the calling context's - // global object. This may not be right either, but we need - // something. - else { - global = getter_AddRefs(aContext->GetGlobalObject()); - } - - if (NS_SUCCEEDED(res)) { - res = NS_NewScriptHTMLDocument(aContext, - (nsISupports *)(nsIDOMHTMLDocument *)this, - (nsISupports *)global, - (void**)&mScriptObject); - } - } - - *aScriptObject = mScriptObject; - - return res; -} - -PRBool -nsHTMLDocument::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty) -{ - *aDidDefineProperty = PR_FALSE; - - if (!JSVAL_IS_STRING(aID)) { - return PR_TRUE; - } - - nsresult result; - PRBool ret = PR_TRUE; - jsval val = 0; - - result = NamedItem(aContext, &aID, 1, &val); - if (NS_SUCCEEDED(result) && val) { - JSString *str = JSVAL_TO_STRING(aID); - ret = ::JS_DefineUCProperty(aContext, aObj,JS_GetStringChars(str), - JS_GetStringLength(str), val, nsnull, - nsnull, 0); - - *aDidDefineProperty = PR_TRUE; - } - if (NS_FAILED(result)) { - ret = PR_FALSE; - } - - return ret; -} - //---------------------------- PRBool @@ -3683,35 +3503,6 @@ nsHTMLDocument::GetBodyElement(nsIDOMHTMLBodyElement** aBody) // forms related stuff -NS_IMETHODIMP -nsHTMLDocument::AddForm(nsIDOMHTMLFormElement *aForm) -{ -#if 0 - // Not necessary anymore since forms are real content now - NS_PRECONDITION(nsnull != aForm, "null ptr"); - if (nsnull == aForm) { - return NS_ERROR_NULL_POINTER; - } - - nsIContent* iContent = nsnull; - nsresult result = aForm->QueryInterface(NS_GET_IID(nsIContent), (void**)&iContent); - if ((NS_OK == result) && iContent) { - nsIDOMHTMLCollection* forms = nsnull; - - // Initialize mForms if necessary... - if (nsnull == mForms) { - mForms = new nsContentList(this, nsHTMLAtoms::form, kNameSpaceID_Unknown); - NS_ADDREF(mForms); - } - - mForms->Add(iContent); - NS_RELEASE(iContent); - } - return result; -#endif - return NS_OK; -} - NS_IMETHODIMP nsHTMLDocument::GetForms(nsIDOMHTMLCollection** aForms) { diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index 22a3858f695..fa20d4d20a0 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -28,7 +28,6 @@ #include "nsIHTMLDocument.h" #include "nsIDOMHTMLDocument.h" #include "nsIDOMNSHTMLDocument.h" -#include "nsIDOMNode.h" #include "nsIDOMHTMLBodyElement.h" #include "nsIHTMLContentContainer.h" #include "nsHashtable.h" @@ -126,25 +125,19 @@ public: NS_IMETHOD FlushPendingNotifications(PRBool aFlushReflows = PR_TRUE); // nsIDOMDocument interface - NS_DECL_IDOMDOCUMENT + NS_DECL_NSIDOMDOCUMENT // nsIDOMNode interface - NS_DECL_IDOMNODE + NS_DECL_NSIDOMNODE + + // nsIDOM3Node interface + NS_DECL_NSIDOM3NODE // nsIDOMHTMLDocument interface - NS_DECL_IDOMHTMLDOCUMENT - NS_DECL_IDOMNSHTMLDOCUMENT + NS_DECL_NSIDOMHTMLDOCUMENT - // the following is not part of nsIDOMHTMLDocument but allows the - // content sink to add forms - NS_IMETHOD AddForm(nsIDOMHTMLFormElement* aForm); - - // From nsIScriptObjectOwner interface, implemented by nsDocument - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - - // From nsJSScriptObject interface, implemented by nsDocument - virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty); + // nsIDOMNSHTMLDocument interface + NS_DECL_NSIDOMNSHTMLDOCUMENT /* * Returns true if document.domain was set for this document @@ -194,10 +187,6 @@ protected: nsresult WriteCommon(const nsAReadableString& aText, PRBool aNewlineTerminate); - nsresult ScriptWriteCommon(JSContext *cx, - jsval *argv, - PRUint32 argc, - PRBool aNewlineTerminate); nsresult OpenCommon(nsIURI* aUrl); nsIHTMLStyleSheet* mAttrStyleSheet; diff --git a/content/html/document/src/nsHTMLFragmentContentSink.cpp b/content/html/document/src/nsHTMLFragmentContentSink.cpp index 4ca2a90fb70..42742626acc 100644 --- a/content/html/document/src/nsHTMLFragmentContentSink.cpp +++ b/content/html/document/src/nsHTMLFragmentContentSink.cpp @@ -244,7 +244,7 @@ nsresult nsHTMLFragmentContentSink::Init() rv = NS_NewNameSpaceManager(getter_AddRefs(nsmgr)); NS_ENSURE_SUCCESS(rv, rv); - return mNodeInfoManager->Init(nsmgr); + return mNodeInfoManager->Init(nsnull, nsmgr); } diff --git a/content/html/document/src/nsIHTMLDocument.h b/content/html/document/src/nsIHTMLDocument.h index 9149e482f77..37b5f5e2850 100644 --- a/content/html/document/src/nsIHTMLDocument.h +++ b/content/html/document/src/nsIHTMLDocument.h @@ -54,10 +54,6 @@ public: NS_IMETHOD RemoveImageMap(nsIDOMHTMLMapElement* aMap) = 0; - NS_IMETHOD AddForm(nsIDOMHTMLFormElement* aForm) = 0; - - NS_IMETHOD GetForms(nsIDOMHTMLCollection** aForms) = 0; - NS_IMETHOD SetLastModified(const nsAReadableString& aLastModified) = 0; NS_IMETHOD SetReferrer(const nsAReadableString& aReferrer) = 0; diff --git a/content/html/style/public/nsIComputedDOMStyle.h b/content/html/style/public/nsIComputedDOMStyle.h index 9ee1025e1aa..16096fada3f 100644 --- a/content/html/style/public/nsIComputedDOMStyle.h +++ b/content/html/style/public/nsIComputedDOMStyle.h @@ -23,7 +23,7 @@ #define nsIComputedDOMStyle_h___ #include "nslayout.h" -#include "nsIDOMCSS2Properties.h" +#include "nsIDOMCSSStyleDeclaration.h" class nsIDOMElement; class nsIPresShell; diff --git a/content/html/style/src/nsCSSStyleRule.cpp b/content/html/style/src/nsCSSStyleRule.cpp index bfa54c6be5e..442d5fc3ee9 100644 --- a/content/html/style/src/nsCSSStyleRule.cpp +++ b/content/html/style/src/nsCSSStyleRule.cpp @@ -47,8 +47,6 @@ #include "nsIDOMCSSRule.h" #include "nsIDOMCSSStyleRule.h" #include "nsIDOMCSSStyleDeclaration.h" -#include "nsIScriptGlobalObject.h" -#include "nsIScriptObjectOwner.h" #include "nsDOMCSSDeclaration.h" #include "nsINameSpaceManager.h" #include "nsINameSpace.h" @@ -58,6 +56,8 @@ #include "nsIStyleSet.h" #include "nsISizeOfHandler.h" +#include "nsContentUtils.h" + // MJA: bug 31816 #include "nsIPresShell.h" #include "nsIDocShellTreeItem.h" @@ -598,6 +598,11 @@ void nsCSSSelector::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize) aSize += localSize; } + + // XXX ???? + + + // a couple of simple atom lists if(mIDList && uniqueItems->AddItem(mIDList)){ aSize += sizeof(*mIDList); @@ -1217,8 +1222,8 @@ DOMCSSDeclarationImpl::GetParent(nsISupports **aParent) class CSSStyleRuleImpl : public nsCSSRule, public nsICSSStyleRule, - public nsIDOMCSSStyleRule, - public nsIScriptObjectOwner { + public nsIDOMCSSStyleRule +{ public: CSSStyleRuleImpl(const nsCSSSelector& aSelector); CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy); @@ -1261,14 +1266,10 @@ public: virtual void SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize); // nsIDOMCSSRule interface - NS_DECL_IDOMCSSRULE + NS_DECL_NSIDOMCSSRULE // nsIDOMCSSStyleRule interface - NS_DECL_IDOMCSSSTYLERULE - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMCSSSTYLERULE private: // These are not supported and are not implemented! @@ -1283,7 +1284,6 @@ protected: PRInt32 mWeight; CSSImportantRule* mImportantRule; DOMCSSDeclarationImpl* mDOMDeclaration; - void* mScriptObject; PRUint32 mLineNumber; }; @@ -1295,8 +1295,7 @@ CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector) : nsCSSRule(), mSelector(aSelector), mDeclaration(nsnull), mWeight(0), mImportantRule(nsnull), - mDOMDeclaration(nsnull), - mScriptObject(nsnull) + mDOMDeclaration(nsnull) { #ifdef DEBUG_REFS gStyleRuleCount++; @@ -1310,8 +1309,7 @@ CSSStyleRuleImpl::CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy) mDeclaration(nsnull), mWeight(aCopy.mWeight), mImportantRule(nsnull), - mDOMDeclaration(nsnull), - mScriptObject(nsnull) + mDOMDeclaration(nsnull) { #ifdef DEBUG_REFS gStyleRuleCount++; @@ -1358,58 +1356,27 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl(void) } } +// XPConnect interface list for CSSStyleRuleImpl +NS_CLASSINFO_MAP_BEGIN(CSSStyleRule) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSStyleRuleImpl +NS_INTERFACE_MAP_BEGIN(CSSStyleRuleImpl) + NS_INTERFACE_MAP_ENTRY(nsICSSStyleRule) + NS_INTERFACE_MAP_ENTRY(nsICSSRule) + NS_INTERFACE_MAP_ENTRY(nsIStyleRule) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleRule) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleRule) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF_INHERITED(CSSStyleRuleImpl, nsCSSRule); NS_IMPL_RELEASE_INHERITED(CSSStyleRuleImpl, nsCSSRule); -nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID, - void** aInstancePtrResult) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsICSSStyleRule))) { - *aInstancePtrResult = (void*) ((nsICSSStyleRule*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsICSSRule))) { - *aInstancePtrResult = (void*) ((nsICSSRule*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIStyleRule))) { - *aInstancePtrResult = (void*) ((nsIStyleRule*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMCSSRule))) { - nsIDOMCSSRule *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMCSSStyleRule))) { - nsIDOMCSSStyleRule *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - nsICSSStyleRule *tmp = this; - nsISupports *tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} #if 0 NS_IMETHODIMP CSSStyleRuleImpl::Equals(const nsIStyleRule* aRule, PRBool& aResult) const @@ -3653,34 +3620,6 @@ CSSStyleRuleImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) return NS_OK; } -NS_IMETHODIMP -CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsICSSStyleRule *)this; - // XXX Parent should be the style sheet - // XXX Should be done through factory - res = NS_NewScriptCSSStyleRule(aContext, - supports, - (nsISupports *)global, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - NS_RELEASE(global); - return res; -} - -NS_IMETHODIMP -CSSStyleRuleImpl::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - NS_HTML nsresult NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult, const nsCSSSelector& aSelector) { diff --git a/content/html/style/src/nsCSSStyleSheet.cpp b/content/html/style/src/nsCSSStyleSheet.cpp index a187f51d970..b38b8149a17 100644 --- a/content/html/style/src/nsCSSStyleSheet.cpp +++ b/content/html/style/src/nsCSSStyleSheet.cpp @@ -58,8 +58,6 @@ #include "nsIDOMNode.h" #include "nsDOMError.h" #include "nsIPresShell.h" -#include "nsIScriptObjectOwner.h" -#include "nsIScriptGlobalObject.h" #include "nsICSSParser.h" #include "nsCSSAtoms.h" #include "nsINameSpaceManager.h" @@ -76,6 +74,8 @@ #include "nsIXULContent.h" #endif +#include "nsContentUtils.h" + //#define DEBUG_RULES //#define EVENT_DEBUG @@ -504,8 +504,8 @@ class CSSRuleListImpl; class DOMMediaListImpl; class CSSStyleSheetImpl : public nsICSSStyleSheet, - public nsIDOMCSSStyleSheet, - public nsIScriptObjectOwner { + public nsIDOMCSSStyleSheet +{ public: void* operator new(size_t size); void* operator new(size_t size, nsIArena* aArena); @@ -582,14 +582,10 @@ public: virtual void SizeOf(nsISizeOfHandler *aSizeofHandler, PRUint32 &aSize); // nsIDOMStyleSheet interface - NS_DECL_IDOMSTYLESHEET + NS_DECL_NSIDOMSTYLESHEET // nsIDOMCSSStyleSheet interface - NS_DECL_IDOMCSSSTYLESHEET - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMCSSSTYLESHEET private: // These are not supported and are not implemented! @@ -621,7 +617,6 @@ protected: nsIDOMNode* mOwningNode; PRBool mDisabled; PRBool mDirty; // has been modified - void* mScriptObject; CSSStyleSheetInner* mInner; @@ -634,8 +629,7 @@ friend class CSSRuleProcessor; // ------------------------------- // Style Rule List for the DOM // -class CSSRuleListImpl : public nsIDOMCSSRuleList, - public nsIScriptObjectOwner +class CSSRuleListImpl : public nsIDOMCSSRuleList { public: CSSRuleListImpl(CSSStyleSheetImpl *aStyleSheet); @@ -646,17 +640,12 @@ public: NS_IMETHOD GetLength(PRUint32* aLength); NS_IMETHOD Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn); - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); - void DropReference() { mStyleSheet = nsnull; } protected: virtual ~CSSRuleListImpl(); CSSStyleSheetImpl* mStyleSheet; - void* mScriptObject; public: PRBool mRulesAccessed; }; @@ -667,7 +656,6 @@ CSSRuleListImpl::CSSRuleListImpl(CSSStyleSheetImpl *aStyleSheet) // Not reference counted to avoid circular references. // The style sheet will tell us when its going away. mStyleSheet = aStyleSheet; - mScriptObject = nsnull; mRulesAccessed = PR_FALSE; } @@ -675,15 +663,23 @@ CSSRuleListImpl::~CSSRuleListImpl() { } +// XPConnect interface list for CSSStyleRuleImpl +NS_CLASSINFO_MAP_BEGIN(CSSRuleList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSRuleList) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSRuleList +NS_INTERFACE_MAP_BEGIN(CSSRuleListImpl) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSRuleList) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(CSSRuleListImpl); NS_IMPL_RELEASE(CSSRuleListImpl); -NS_INTERFACE_MAP_BEGIN(CSSRuleListImpl) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSRuleList) -NS_INTERFACE_MAP_END - NS_IMETHODIMP CSSRuleListImpl::GetLength(PRUint32* aLength) @@ -724,44 +720,12 @@ CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn) return result; } -NS_IMETHODIMP -CSSRuleListImpl::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsIDOMCSSRuleList *)this; - - // XXX Should be done through factory - res = NS_NewScriptCSSRuleList(aContext, - supports, - (nsISupports *)(nsICSSStyleSheet*)mStyleSheet, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -CSSRuleListImpl::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - class DOMMediaListImpl : public nsIDOMMediaList, - public nsIScriptObjectOwner, public nsISupportsArray { NS_DECL_ISUPPORTS - NS_DECL_IDOMMEDIALIST - - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMMEDIALIST NS_FORWARD_NSISUPPORTSARRAY(mArray->) NS_FORWARD_NSICOLLECTION(mArray->); @@ -782,21 +746,30 @@ class DOMMediaListImpl : public nsIDOMMediaList, private: nsCOMPtr mArray; CSSStyleSheetImpl* mStyleSheet; - void* mScriptObject; }; + +// XPConnect interface list for CSSStyleSheetStyleRuleImpl +NS_CLASSINFO_MAP_BEGIN(MediaList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMMediaList) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSStyleRuleImpl +NS_INTERFACE_MAP_BEGIN(DOMMediaListImpl) + NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMediaList) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MediaList) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(DOMMediaListImpl); NS_IMPL_RELEASE(DOMMediaListImpl); -NS_INTERFACE_MAP_BEGIN(DOMMediaListImpl) - NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMediaList) -NS_INTERFACE_MAP_END DOMMediaListImpl::DOMMediaListImpl(nsISupportsArray *aArray, CSSStyleSheetImpl *aStyleSheet) - : mArray(aArray), mStyleSheet(aStyleSheet), mScriptObject(nsnull) + : mArray(aArray), mStyleSheet(aStyleSheet) { NS_INIT_REFCNT(); @@ -807,33 +780,6 @@ DOMMediaListImpl::~DOMMediaListImpl() { } -NS_IMETHODIMP -DOMMediaListImpl::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsIDOMMediaList *)this; - - // XXX Should be done through factory - res = NS_NewScriptMediaList(aContext, - supports, - (nsISupports *)(nsIDOMMediaList*)mStyleSheet, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -DOMMediaListImpl::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - NS_IMETHODIMP DOMMediaListImpl::GetMediaText(nsAWritableString& aMediaText) { @@ -973,8 +919,7 @@ DOMMediaListImpl::Append(const nsAReadableString& aNewMedium) // ------------------------------- // Imports Collection for the DOM // -class CSSImportsCollectionImpl : public nsIDOMStyleSheetList, - public nsIScriptObjectOwner +class CSSImportsCollectionImpl : public nsIDOMStyleSheetList { public: CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet); @@ -985,17 +930,12 @@ public: NS_IMETHOD GetLength(PRUint32* aLength); NS_IMETHOD Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn); - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); - void DropReference() { mStyleSheet = nsnull; } protected: virtual ~CSSImportsCollectionImpl(); nsICSSStyleSheet* mStyleSheet; - void* mScriptObject; }; CSSImportsCollectionImpl::CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet) @@ -1004,47 +944,32 @@ CSSImportsCollectionImpl::CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet // Not reference counted to avoid circular references. // The style sheet will tell us when its going away. mStyleSheet = aStyleSheet; - mScriptObject = nsnull; } CSSImportsCollectionImpl::~CSSImportsCollectionImpl() { } + +// XPConnect interface list for CSSImportsCollectionImpl +NS_CLASSINFO_MAP_BEGIN(StyleSheetList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMStyleSheetList) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSImportsCollectionImpl +NS_INTERFACE_MAP_BEGIN(CSSImportsCollectionImpl) + NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheetList) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(StyleSheetList) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(CSSImportsCollectionImpl); NS_IMPL_RELEASE(CSSImportsCollectionImpl); -nsresult -CSSImportsCollectionImpl::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) -{ - if (NULL == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - if (aIID.Equals(NS_GET_IID(nsIDOMStyleSheetList))) { - nsIDOMStyleSheetList *tmp = this; - *aInstancePtrResult = (void*) tmp; - AddRef(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner *tmp = this; - *aInstancePtrResult = (void*) tmp; - AddRef(); - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - nsIDOMStyleSheetList *tmp = this; - nsISupports *tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - AddRef(); - return NS_OK; - } - return NS_NOINTERFACE; -} - -NS_IMETHODIMP +NS_IMETHODIMP CSSImportsCollectionImpl::GetLength(PRUint32* aLength) { if (nsnull != mStyleSheet) { @@ -1078,34 +1003,6 @@ CSSImportsCollectionImpl::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn) return result; } -NS_IMETHODIMP -CSSImportsCollectionImpl::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsIDOMStyleSheetList *)this; - - // XXX Should be done through factory - res = NS_NewScriptStyleSheetList(aContext, - supports, - (nsISupports *)mStyleSheet, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -CSSImportsCollectionImpl::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - // ------------------------------- // CSS Style Sheet Inner Data Container // @@ -1414,7 +1311,6 @@ CSSStyleSheetImpl::CSSStyleSheetImpl() mOwningNode(nsnull), mDisabled(PR_FALSE), mDirty(PR_FALSE), - mScriptObject(nsnull), mRuleProcessors(nsnull) { NS_INIT_REFCNT(); @@ -1435,7 +1331,6 @@ CSSStyleSheetImpl::CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy) mOwningNode(aCopy.mOwningNode), mDisabled(aCopy.mDisabled), mDirty(PR_FALSE), - mScriptObject(nsnull), mInner(aCopy.mInner), mRuleProcessors(nsnull) { @@ -1507,54 +1402,27 @@ CSSStyleSheetImpl::~CSSStyleSheetImpl() } } + +// XPConnect interface list for CSSStyleSheetImpl +NS_CLASSINFO_MAP_BEGIN(CSSStyleSheet) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleSheet) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSStyleSheetImpl +NS_INTERFACE_MAP_BEGIN(CSSStyleSheetImpl) + NS_INTERFACE_MAP_ENTRY(nsICSSStyleSheet) + NS_INTERFACE_MAP_ENTRY(nsIStyleSheet) + NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleSheet) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleSheet) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(CSSStyleSheetImpl) NS_IMPL_RELEASE(CSSStyleSheetImpl) -nsresult CSSStyleSheetImpl::QueryInterface(const nsIID& aIID, - void** aInstancePtrResult) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - if (aIID.Equals(NS_GET_IID(nsICSSStyleSheet))) { - *aInstancePtrResult = (void*) ((nsICSSStyleSheet*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIStyleSheet))) { - *aInstancePtrResult = (void*) ((nsIStyleSheet*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMStyleSheet))) { - nsIDOMStyleSheet *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMCSSStyleSheet))) { - nsIDOMCSSStyleSheet *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - nsICSSStyleSheet *tmp = this; - nsISupports *tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} NS_IMETHODIMP CSSStyleSheetImpl::GetStyleRuleProcessor(nsIStyleRuleProcessor*& aProcessor, @@ -2545,34 +2413,6 @@ CSSStyleSheetImpl::DeleteRule(PRUint32 aIndex) return result; } -NS_IMETHODIMP -CSSStyleSheetImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsICSSStyleSheet *)this; - // XXX Should be done through factory - res = NS_NewScriptCSSStyleSheet(aContext, - supports, - (nsISupports *)global, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - NS_RELEASE(global); - return res; -} - -NS_IMETHODIMP -CSSStyleSheetImpl::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - // XXX for backwards compatibility and convenience NS_HTML nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURI* aURL) diff --git a/content/html/style/src/nsComputedDOMStyle.cpp b/content/html/style/src/nsComputedDOMStyle.cpp index 367cc15b551..45fb922edcc 100644 --- a/content/html/style/src/nsComputedDOMStyle.cpp +++ b/content/html/style/src/nsComputedDOMStyle.cpp @@ -17,7 +17,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): */ #include "nsIComputedDOMStyle.h" @@ -27,7 +27,6 @@ #include "nsIFrame.h" #include "nsIDOMElement.h" #include "nsIStyleContext.h" -#include "nsIScriptObjectOwner.h" #include "nsROCSSPrimitiveValue.h" #include "nsCSSProps.h" @@ -39,6 +38,8 @@ #include "prprf.h" #include "nsReadableUtils.h" +#include "nsContentUtils.h" + /* * This is the implementation of the readonly CSSStyleDeclaration that is * returned by the getComputedStyle() function. @@ -47,8 +48,7 @@ * file that is #ifdef'd out placeholders. */ -class nsComputedDOMStyle : public nsIComputedDOMStyle, - public nsIScriptObjectOwner +class nsComputedDOMStyle : public nsIComputedDOMStyle { public: NS_DECL_ISUPPORTS @@ -58,11 +58,7 @@ public: nsIPresShell *aPresShell); // nsIDOMCSSStyleDeclaration - NS_DECL_IDOMCSSSTYLEDECLARATION - - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMCSSSTYLEDECLARATION // nsComputedDOMStyle nsComputedDOMStyle(); @@ -71,12 +67,19 @@ public: private: //Helpers nsresult GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect); - nsresult GetStyleData(nsStyleStructID aID, const nsStyleStruct*& aStyleStruct,nsIFrame* aFrame=0); - nsresult GetPaddingWidthFor(PRUint8 aSide, nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderStyleFor(PRUint8 aSide, nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderWidthFor(PRUint8 aSide, nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderColorFor(PRUint8 aSide, nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetMarginWidthFor(PRUint8 aSide, nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetStyleData(nsStyleStructID aID, + const nsStyleStruct*& aStyleStruct, + nsIFrame* aFrame=0); + nsresult GetPaddingWidthFor(PRUint8 aSide, nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderStyleFor(PRUint8 aSide, nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderWidthFor(PRUint8 aSide, nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderColorFor(PRUint8 aSide, nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetMarginWidthFor(PRUint8 aSide, nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); // Properties nsresult GetWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); @@ -95,57 +98,79 @@ private: nsresult GetFontVariant(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); // Background properties - nsresult GetBackgroundColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBackgroundImage(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBackgroundColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBackgroundImage(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); nsresult GetDisplay(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); // Padding properties nsresult GetPadding(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetPaddingTop(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetPaddingBottom(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetPaddingBottom(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); nsresult GetPaddingLeft(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetPaddingRight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); // BorderProperties nsresult GetBorderStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetBorderWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderCollapse(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderSpacing(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderTopStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderBottomStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderLeftStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderRightStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderTopColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderBottomColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderLeftColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderRightColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - + nsresult GetBorderCollapse(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderSpacing(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderTopStyle(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderBottomStyle(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderLeftStyle(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderRightStyle(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderTopWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderBottomWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderLeftWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderRightWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderTopColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderBottomColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderLeftColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderRightColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + // Margin Properties nsresult GetMarginWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetMarginTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetMarginBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetMarginLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetMarginRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - + nsresult GetMarginTopWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetMarginBottomWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetMarginLeftWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetMarginRightWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + // Outline Properties nsresult GetOutline(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetOutlineWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetOutlineStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetOutlineColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - + //Marker Properties nsresult GetMarkerOffset(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - + // z-index nsresult GetZIndex(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); // List properties - nsresult GetListStyleImage(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetListStyleImage(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); // Text Properties nsresult GetTextAlign(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); @@ -156,14 +181,12 @@ private: nsWeakPtr mPresShellWeak; // XXX could this be high cost? nsCOMPtr mContent; - // When a frame is unavailable strong reference to the + // When a frame is unavailable strong reference to the // style context while we're accessing the data from in. - nsCOMPtr mStyleContextHolder; + nsCOMPtr mStyleContextHolder; nsCOMPtr mPseudo; float mT2P; // For unit conversions - - void* mScriptObject; }; @@ -182,8 +205,7 @@ NS_NewComputedDOMStyle(nsIComputedDOMStyle** aComputedStyle) nsComputedDOMStyle::nsComputedDOMStyle() : mPresShellWeak(nsnull), - mT2P(0.0f), - mScriptObject(nsnull) + mT2P(0.0f) { NS_INIT_REFCNT(); } @@ -194,70 +216,50 @@ nsComputedDOMStyle::~nsComputedDOMStyle() } +// XPConnect interface list for nsComputedDOMStyle +NS_CLASSINFO_MAP_BEGIN(ComputedCSSStyleDeclaration) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleDeclaration) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsComputedDOMStyle +NS_INTERFACE_MAP_BEGIN(nsComputedDOMStyle) + NS_INTERFACE_MAP_ENTRY(nsIComputedDOMStyle) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleDeclaration) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIComputedDOMStyle) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ComputedCSSStyleDeclaration) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsComputedDOMStyle); NS_IMPL_RELEASE(nsComputedDOMStyle); -NS_INTERFACE_MAP_BEGIN(nsComputedDOMStyle) -NS_INTERFACE_MAP_ENTRY(nsIComputedDOMStyle) -NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleDeclaration) -NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) -NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIComputedDOMStyle) -NS_INTERFACE_MAP_END - - NS_IMETHODIMP -nsComputedDOMStyle::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (!mScriptObject) { - nsISupports *supports = NS_STATIC_CAST(nsIComputedDOMStyle *, this); - - // XXX Should be done through factory - res = NS_NewScriptCSSStyleDeclaration(aContext, supports, mContent, - &mScriptObject); - } - - *aScriptObject = mScriptObject; - - return res; -} - - -NS_IMETHODIMP -nsComputedDOMStyle::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - -NS_IMETHODIMP -nsComputedDOMStyle::Init(nsIDOMElement *aElement, const nsAReadableString& aPseudoElt, +nsComputedDOMStyle::Init(nsIDOMElement *aElement, + const nsAReadableString& aPseudoElt, nsIPresShell *aPresShell) { NS_ENSURE_ARG_POINTER(aElement); NS_ENSURE_ARG_POINTER(aPresShell); - mPresShellWeak = getter_AddRefs(NS_GetWeakReference(aPresShell)); + mPresShellWeak = getter_AddRefs(NS_GetWeakReference(aPresShell)); mContent = do_QueryInterface(aElement); if (!mContent) { // This should not happen, all our elements support nsIContent! return NS_ERROR_FAILURE; } - - if(!aPseudoElt.IsEmpty()) { + + if(!DOMStringIsNull(aPseudoElt) && !aPseudoElt.IsEmpty()) { mPseudo = dont_AddRef(NS_NewAtom(aPseudoElt)); - NS_ENSURE_TRUE(mPseudo, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(mPseudo, NS_ERROR_OUT_OF_MEMORY); } - + nsCOMPtr presCtx; aPresShell->GetPresContext(getter_AddRefs(presCtx)); - + NS_ENSURE_TRUE(presCtx, NS_ERROR_FAILURE); presCtx->GetTwipsToPixels(&mT2P); @@ -326,9 +328,9 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAReadableString& aPropertyName, *aReturn = nsnull; nsCOMPtr presShell=do_QueryReferent(mPresShellWeak); - + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - + nsIFrame *frame = nsnull; presShell->GetPrimaryFrameFor(mContent, &frame); @@ -355,7 +357,7 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAReadableString& aPropertyName, rv = GetRight(frame, *getter_AddRefs(val)); break; case eCSSProperty_bottom : rv = GetBottom(frame, *getter_AddRefs(val)); break; - + // Font properties case eCSSProperty_color : rv = GetColor(frame, *getter_AddRefs(val)); break; @@ -369,13 +371,13 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAReadableString& aPropertyName, rv = GetFontWeight(frame, *getter_AddRefs(val)); break; case eCSSProperty_font_variant : rv = GetFontVariant(frame, *getter_AddRefs(val)); break; - + // Background properties case eCSSProperty_background_color : rv = GetBackgroundColor(frame, *getter_AddRefs(val)); break; case eCSSProperty_background_image : rv = GetBackgroundImage(frame, *getter_AddRefs(val)); break; - + // Padding properties case eCSSProperty_padding : rv = GetPadding(frame, *getter_AddRefs(val)); break; @@ -452,9 +454,9 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAReadableString& aPropertyName, rv = val->QueryInterface(NS_GET_IID(nsIDOMCSSValue), (void **)aReturn); } - // Release the current style context for it should be re-resolved + // Release the current style context for it should be re-resolved // whenever a frame is not available. - mStyleContextHolder=nsnull; + mStyleContextHolder=nsnull; return rv; } @@ -498,7 +500,7 @@ nsComputedDOMStyle::Item(PRUint32 aIndex, nsAWritableString& aReturn) #if 0 -NS_IMETHODIMP +NS_IMETHODIMP nsComputedDOMStyle::GetAzimuth(nsAWritableString& aAzimuth) { return NS_ERROR_DOM_NOT_SUPPORTED_ERR; @@ -550,7 +552,7 @@ nsComputedDOMStyle::GetBehavior(nsIFrame *aFrame, NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleUserInterface* ui = nsnull; - + GetStyleData(eStyleStruct_UserInterface, (const nsStyleStruct*&)ui, aFrame); if (ui) { @@ -720,9 +722,9 @@ static void ColorToHex(nscolor aColor, nsAWritableString& aHexString) { char buf[32]; - PRUint32 len = PR_snprintf(buf, 32, "#%02x%02x%02x", + PRUint32 len = PR_snprintf(buf, 32, "#%02x%02x%02x", NS_GET_R(aColor), - NS_GET_G(aColor), + NS_GET_G(aColor), NS_GET_B(aColor)); CopyASCIItoUCS2(nsLiteralCString(buf, len), aHexString); @@ -737,18 +739,19 @@ nsComputedDOMStyle::GetColor(nsIFrame *aFrame, NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleColor* color=nsnull; - GetStyleData(eStyleStruct_Color,(const nsStyleStruct*&)color,aFrame); - + GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)color, aFrame); + if(color) { nsAutoString hex; - ColorToHex(color->mColor,hex); + ColorToHex(color->mColor, hex); val->SetString(hex); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -757,9 +760,9 @@ nsComputedDOMStyle::GetFontFamily(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleFont* font=nsnull; - GetStyleData(eStyleStruct_Font,(const nsStyleStruct*&)font,aFrame); + GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); if(font) { val->SetString(font->mFont.name); @@ -768,7 +771,8 @@ nsComputedDOMStyle::GetFontFamily(nsIFrame *aFrame, val->SetString(""); } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -777,13 +781,14 @@ nsComputedDOMStyle::GetFontSize(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleFont* font=nsnull; - GetStyleData(eStyleStruct_Font,(const nsStyleStruct*&)font,aFrame); - + GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); + val->SetTwips(font? font->mFont.size:0); - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -792,20 +797,22 @@ nsComputedDOMStyle::GetFontStyle(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleFont* font=nsnull; - GetStyleData(eStyleStruct_Font,(const nsStyleStruct*&)font,aFrame); - + GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); + if(font) { const nsCString& style= - nsCSSProps::SearchKeywordTable(font->mFont.style,nsCSSProps::kFontStyleKTable); + nsCSSProps::SearchKeywordTable(font->mFont.style, + nsCSSProps::kFontStyleKTable); val->SetString(style); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -814,13 +821,14 @@ nsComputedDOMStyle::GetFontWeight(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleFont* font=nsnull; - GetStyleData(eStyleStruct_Font,(const nsStyleStruct*&)font,aFrame); + GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); if(font) { const nsCString& str_weight= - nsCSSProps::SearchKeywordTable(font->mFont.weight,nsCSSProps::kFontWeightKTable); + nsCSSProps::SearchKeywordTable(font->mFont.weight, + nsCSSProps::kFontWeightKTable); if(str_weight.Length()>0) { val->SetString(str_weight); } @@ -833,8 +841,9 @@ nsComputedDOMStyle::GetFontWeight(nsIFrame *aFrame, else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -843,20 +852,22 @@ nsComputedDOMStyle::GetFontVariant(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleFont* font=nsnull; - GetStyleData(eStyleStruct_Font,(const nsStyleStruct*&)font,aFrame); - + GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); + if(font) { const nsCString& variant= - nsCSSProps::SearchKeywordTable(font->mFont.variant,nsCSSProps::kFontVariantKTable); + nsCSSProps::SearchKeywordTable(font->mFont.variant, + nsCSSProps::kFontVariantKTable); val->SetString(variant); } else { val->SetString(""); } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -865,20 +876,21 @@ nsComputedDOMStyle::GetBackgroundColor(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleColor* color=nsnull; - GetStyleData(eStyleStruct_Color,(const nsStyleStruct*&)color,aFrame); - + GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)color, aFrame); + if(color) { - nsAutoString hex; - ColorToHex(color->mBackgroundColor,hex); + nsAutoString hex; + ColorToHex(color->mBackgroundColor, hex); val->SetString(hex); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -887,9 +899,9 @@ nsComputedDOMStyle::GetBackgroundImage(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleColor* color=nsnull; - GetStyleData(eStyleStruct_Color,(const nsStyleStruct*&)color,aFrame); + GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)color, aFrame); if(color) { val->SetString(color->mBackgroundImage); @@ -897,8 +909,9 @@ nsComputedDOMStyle::GetBackgroundImage(nsIFrame *aFrame, else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -906,289 +919,296 @@ nsComputedDOMStyle::GetPadding(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { aValue=nsnull; // return null per spec. - return NS_OK; + return NS_OK; } nsresult nsComputedDOMStyle::GetPaddingTop(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetPaddingWidthFor(NS_SIDE_TOP,aFrame,aValue); + return GetPaddingWidthFor(NS_SIDE_TOP, aFrame, aValue); } nsresult nsComputedDOMStyle::GetPaddingBottom(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetPaddingWidthFor(NS_SIDE_BOTTOM,aFrame,aValue); + return GetPaddingWidthFor(NS_SIDE_BOTTOM, aFrame, aValue); } nsresult nsComputedDOMStyle::GetPaddingLeft(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetPaddingWidthFor(NS_SIDE_LEFT,aFrame,aValue); + return GetPaddingWidthFor(NS_SIDE_LEFT, aFrame, aValue); } nsresult nsComputedDOMStyle::GetPaddingRight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetPaddingWidthFor(NS_SIDE_RIGHT,aFrame,aValue); + return GetPaddingWidthFor(NS_SIDE_RIGHT, aFrame, aValue); } nsresult -nsComputedDOMStyle::GetBorderCollapse(nsIFrame *aFrame, +nsComputedDOMStyle::GetBorderCollapse(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleTable* table = nsnull; - GetStyleData(eStyleStruct_Table,(const nsStyleStruct*&)table,aFrame); + GetStyleData(eStyleStruct_Table, (const nsStyleStruct*&)table, aFrame); if(table) { const nsCString& ident= - nsCSSProps::SearchKeywordTable(table->mBorderCollapse,nsCSSProps::kBorderCollapseKTable); + nsCSSProps::SearchKeywordTable(table->mBorderCollapse, + nsCSSProps::kBorderCollapseKTable); val->SetString(ident); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult -nsComputedDOMStyle::GetBorderSpacing(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderSpacing(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { return NS_ERROR_DOM_NOT_SUPPORTED_ERR; } -nsresult -nsComputedDOMStyle::GetBorderStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { aValue=nsnull; // return null per spec. return NS_OK; } -nsresult -nsComputedDOMStyle::GetBorderTopStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderTopStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderStyleFor(NS_SIDE_TOP,aFrame,aValue); + return GetBorderStyleFor(NS_SIDE_TOP, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderBottomStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderBottomStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderStyleFor(NS_SIDE_BOTTOM,aFrame,aValue); + return GetBorderStyleFor(NS_SIDE_BOTTOM, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderLeftStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderLeftStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderStyleFor(NS_SIDE_LEFT,aFrame,aValue); + return GetBorderStyleFor(NS_SIDE_LEFT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderRightStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderRightStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderStyleFor(NS_SIDE_RIGHT,aFrame,aValue); + return GetBorderStyleFor(NS_SIDE_RIGHT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) -{ +{ aValue=nsnull; // return null per spec. return NS_OK; } -nsresult -nsComputedDOMStyle::GetBorderTopWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderWidthFor(NS_SIDE_TOP,aFrame,aValue); -} - -nsresult -nsComputedDOMStyle::GetBorderBottomWidth(nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) -{ - return GetBorderWidthFor(NS_SIDE_BOTTOM,aFrame,aValue); -} - -nsresult -nsComputedDOMStyle::GetBorderLeftWidth(nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) -{ - return GetBorderWidthFor(NS_SIDE_LEFT,aFrame,aValue); -} - -nsresult -nsComputedDOMStyle::GetBorderRightWidth(nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) -{ - return GetBorderWidthFor(NS_SIDE_RIGHT,aFrame,aValue); + return GetBorderWidthFor(NS_SIDE_TOP, aFrame, aValue); } nsresult -nsComputedDOMStyle::GetBorderTopColor(nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) -{ - return GetBorderColorFor(NS_SIDE_TOP,aFrame,aValue); -} - -nsresult -nsComputedDOMStyle::GetBorderBottomColor(nsIFrame *aFrame, +nsComputedDOMStyle::GetBorderBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderColorFor(NS_SIDE_BOTTOM,aFrame,aValue); + return GetBorderWidthFor(NS_SIDE_BOTTOM, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderLeftColor(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderColorFor(NS_SIDE_LEFT,aFrame,aValue); + return GetBorderWidthFor(NS_SIDE_LEFT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderRightColor(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderColorFor(NS_SIDE_RIGHT,aFrame,aValue); + return GetBorderWidthFor(NS_SIDE_RIGHT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetMarginWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderTopColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue) +{ + return GetBorderColorFor(NS_SIDE_TOP, aFrame, aValue); +} + +nsresult +nsComputedDOMStyle::GetBorderBottomColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue) +{ + return GetBorderColorFor(NS_SIDE_BOTTOM, aFrame, aValue); +} + +nsresult +nsComputedDOMStyle::GetBorderLeftColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue) +{ + return GetBorderColorFor(NS_SIDE_LEFT, aFrame, aValue); +} + +nsresult +nsComputedDOMStyle::GetBorderRightColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue) +{ + return GetBorderColorFor(NS_SIDE_RIGHT, aFrame, aValue); +} + +nsresult +nsComputedDOMStyle::GetMarginWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { aValue=nsnull; // return null per spec. return NS_OK; } - -nsresult -nsComputedDOMStyle::GetMarginTopWidth(nsIFrame *aFrame, + +nsresult +nsComputedDOMStyle::GetMarginTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetMarginWidthFor(NS_SIDE_TOP,aFrame,aValue); + return GetMarginWidthFor(NS_SIDE_TOP, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetMarginBottomWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetMarginBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetMarginWidthFor(NS_SIDE_BOTTOM,aFrame,aValue); + return GetMarginWidthFor(NS_SIDE_BOTTOM, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetMarginLeftWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetMarginLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetMarginWidthFor(NS_SIDE_LEFT,aFrame,aValue); + return GetMarginWidthFor(NS_SIDE_LEFT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetMarginRightWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetMarginRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetMarginWidthFor(NS_SIDE_RIGHT,aFrame,aValue); + return GetMarginWidthFor(NS_SIDE_RIGHT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetMarkerOffset(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetMarkerOffset(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleContent* content=nsnull; - GetStyleData(eStyleStruct_Content,(const nsStyleStruct*&)content,aFrame); - + GetStyleData(eStyleStruct_Content, (const nsStyleStruct*&)content, aFrame); + val->SetTwips(content? content->mMarkerOffset.GetCoordValue():0); - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult -nsComputedDOMStyle::GetOutline(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetOutline(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { aValue=nsnull; // return null per spec. return NS_OK; } -nsresult -nsComputedDOMStyle::GetOutlineWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetOutlineWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleOutline* outline=nsnull; - GetStyleData(eStyleStruct_Outline,(const nsStyleStruct*&)outline,aFrame); + GetStyleData(eStyleStruct_Outline, (const nsStyleStruct*&)outline, aFrame); val->SetTwips(outline? outline->mOutlineWidth.GetCoordValue():0); - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult -nsComputedDOMStyle::GetOutlineStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetOutlineStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleOutline* outline=nsnull; - GetStyleData(eStyleStruct_Outline,(const nsStyleStruct*&)outline,aFrame); - + GetStyleData(eStyleStruct_Outline, (const nsStyleStruct*&)outline, aFrame); + if(outline) { const nsCString& style= - nsCSSProps::SearchKeywordTable(outline->GetOutlineStyle(),nsCSSProps::kBorderStyleKTable); + nsCSSProps::SearchKeywordTable(outline->GetOutlineStyle(), + nsCSSProps::kBorderStyleKTable); val->SetString(style); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult -nsComputedDOMStyle::GetOutlineColor(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetOutlineColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleOutline* outline=nsnull; - GetStyleData(eStyleStruct_Outline,(const nsStyleStruct*&)outline,aFrame); - + GetStyleData(eStyleStruct_Outline, (const nsStyleStruct*&)outline, aFrame); + if(outline) { nscolor color; outline->GetOutlineColor(color); - + nsAutoString hex; - ColorToHex(color,hex); + ColorToHex(color, hex); val->SetString(hex); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult -nsComputedDOMStyle::GetZIndex(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetZIndex(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); @@ -1198,7 +1218,9 @@ nsComputedDOMStyle::GetZIndex(nsIFrame *aFrame, nsAutoString zindex; do { - GetStyleData(eStyleStruct_Position,(const nsStyleStruct*&)position,aFrame); + GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&)position, + aFrame); + if(position){ if(position->mZIndex.GetUnit()==eStyleUnit_Integer) { zindex.AppendInt(position->mZIndex.GetIntValue(), 10); @@ -1207,10 +1229,11 @@ nsComputedDOMStyle::GetZIndex(nsIFrame *aFrame, aFrame->GetParent(&aFrame); } }while(aFrame && position); - + val->SetString(zindex); - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -1221,8 +1244,8 @@ nsComputedDOMStyle::GetListStyleImage(nsIFrame *aFrame, NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleList* list; - GetStyleData(eStyleStruct_List,(const nsStyleStruct*&)list,aFrame); - + GetStyleData(eStyleStruct_List, (const nsStyleStruct*&)list, aFrame); + if(list) { val->SetString(list->mListStyleImage); } @@ -1230,29 +1253,32 @@ nsComputedDOMStyle::GetListStyleImage(nsIFrame *aFrame, val->SetString(""); } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void**)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void**)&aValue); } nsresult nsComputedDOMStyle::GetTextAlign(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); + nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - const nsStyleText* text=nsnull; - GetStyleData(eStyleStruct_Text,(const nsStyleStruct*&)text,aFrame); + const nsStyleText* text = nsnull; + GetStyleData(eStyleStruct_Text, (const nsStyleStruct*&)text, aFrame); if(text) { const nsCString& align= - nsCSSProps::SearchKeywordTable(text->mTextAlign,nsCSSProps::kTextAlignKTable); + nsCSSProps::SearchKeywordTable(text->mTextAlign, + nsCSSProps::kTextAlignKTable); val->SetString(align); } else { val->SetString("start"); } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } #if 0 @@ -1345,7 +1371,7 @@ nsComputedDOMStyle::GetDisplay(nsIFrame *aFrame, const nsStyleDisplay* display = nsnull; - GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display,aFrame); + GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display, aFrame); if (display) { switch (display->mDisplay) { @@ -1902,12 +1928,12 @@ nsComputedDOMStyle::GetWidows(nsAWritableString& aWidows) #endif nsROCSSPrimitiveValue* -nsComputedDOMStyle::GetROCSSPrimitiveValue() +nsComputedDOMStyle::GetROCSSPrimitiveValue() { nsISupports *tmp = NS_STATIC_CAST(nsIComputedDOMStyle *, this); nsROCSSPrimitiveValue *primitiveValue = new nsROCSSPrimitiveValue(tmp, mT2P); - + NS_ASSERTION(primitiveValue!=0, "ran out of memory"); return primitiveValue; @@ -1920,7 +1946,7 @@ nsComputedDOMStyle::GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect) aRect.x = aRect.y = 0; aRect.Empty(); - + if (!aFrame) { return NS_OK; } @@ -1928,7 +1954,7 @@ nsComputedDOMStyle::GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect) // Flush all pending notifications so that our frames are uptodate nsCOMPtr document; mContent->GetDocument(*getter_AddRefs(document)); - + if (document) { document->FlushPendingNotifications(); } @@ -1943,17 +1969,17 @@ nsComputedDOMStyle::GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect) } while (nsnull != next); nsIFrame* frame = aFrame; - nsPoint origin(0,0),tmp(0,0); + nsPoint origin(0, 0), tmp(0, 0); nsFrameState position; do { frame->GetOrigin(tmp); origin += tmp; - + frame->GetFrameState(&position); if(position & NS_FRAME_OUT_OF_FLOW) { break; // Do not include parent if absolutely positioned - Bug 49942 } - // Add the parent's origin to our own to + // Add the parent's origin to our own to // get to the right coordinate system frame->GetParent(&frame); } while(frame); @@ -1962,8 +1988,8 @@ nsComputedDOMStyle::GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect) const nsStyleBorder* border; const nsStylePadding* padding; nsStyleCoord coord; - GetStyleData(eStyleStruct_Border, (const nsStyleStruct*&)border,aFrame); - GetStyleData(eStyleStruct_Padding, (const nsStyleStruct*&)padding,aFrame); + GetStyleData(eStyleStruct_Border, (const nsStyleStruct*&)border, aFrame); + GetStyleData(eStyleStruct_Padding, (const nsStyleStruct*&)padding, aFrame); if (border && padding) { if (eStyleUnit_Coord == border->mBorder.GetLeftUnit()) { origin.x += border->mBorder.GetLeft(coord).GetCoordValue(); @@ -1993,30 +2019,32 @@ nsComputedDOMStyle::GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect) aRect.y = origin.y; return res; -} - +} + nsresult -nsComputedDOMStyle::GetStyleData(nsStyleStructID aID, +nsComputedDOMStyle::GetStyleData(nsStyleStructID aID, const nsStyleStruct*& aStyleStruct, - nsIFrame* aFrame) -{ + nsIFrame* aFrame) +{ if(aFrame && !mPseudo) { - aFrame->GetStyleData(aID,aStyleStruct); + aFrame->GetStyleData(aID, aStyleStruct); } else { nsCOMPtr presShell=do_QueryReferent(mPresShellWeak); - + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - + nsCOMPtr pctx; presShell->GetPresContext(getter_AddRefs(pctx)); if(pctx) { nsCOMPtr sctx; if(!mPseudo) { - pctx->ResolveStyleContextFor(mContent, nsnull, PR_FALSE,getter_AddRefs(sctx)); + pctx->ResolveStyleContextFor(mContent, nsnull, PR_FALSE, + getter_AddRefs(sctx)); } else { - pctx->ResolvePseudoStyleContextFor(mContent, mPseudo, nsnull, PR_FALSE,getter_AddRefs(sctx)); + pctx->ResolvePseudoStyleContextFor(mContent, mPseudo, nsnull, PR_FALSE, + getter_AddRefs(sctx)); } if(sctx) { aStyleStruct=sctx->GetStyleData(aID); @@ -2027,23 +2055,23 @@ nsComputedDOMStyle::GetStyleData(nsStyleStructID aID, return NS_OK; } -nsresult +nsresult nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) + nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStylePadding* padding=nsnull; - GetStyleData(eStyleStruct_Padding,(const nsStyleStruct*&)padding,aFrame); + GetStyleData(eStyleStruct_Padding, (const nsStyleStruct*&)padding, aFrame); if(padding) { nsStyleCoord coord; switch(aSide) { case NS_SIDE_TOP: padding->mPadding.GetTop(coord); break; - case NS_SIDE_BOTTOM : + case NS_SIDE_BOTTOM : padding->mPadding.GetBottom(coord); break; case NS_SIDE_LEFT : padding->mPadding.GetLeft(coord); break; @@ -2052,8 +2080,8 @@ nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, default: NS_WARNING("double check the side"); break; - } - + } + switch(coord.GetUnit()) { case eStyleUnit_Coord: val->SetTwips(coord.GetCoordValue()); break; @@ -2065,7 +2093,7 @@ nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, nsRect rect; parent->GetRect(rect); val->SetTwips(nscoord(coord.GetPercentValue() * rect.width)); - break; // intentionally breaking here... + break; // intentionally breaking here... } } default: @@ -2073,27 +2101,28 @@ nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, break; } } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult +nsresult nsComputedDOMStyle::GetBorderWidthFor(PRUint8 aSide, - nsIFrame *aFrame, + nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleBorder* border = nsnull; - GetStyleData(eStyleStruct_Border,(const nsStyleStruct*&)border,aFrame); - + GetStyleData(eStyleStruct_Border, (const nsStyleStruct*&)border, aFrame); + if(border) { nsStyleCoord coord; switch(aSide) { case NS_SIDE_TOP: border->mBorder.GetTop(coord); break; - case NS_SIDE_BOTTOM : + case NS_SIDE_BOTTOM : border->mBorder.GetBottom(coord); break; case NS_SIDE_LEFT : border->mBorder.GetLeft(coord); break; @@ -2113,60 +2142,63 @@ nsComputedDOMStyle::GetBorderWidthFor(PRUint8 aSide, case eStyleUnit_Chars: { const nsCString& width= - nsCSSProps::SearchKeywordTable(coord.GetIntValue(),nsCSSProps::kBorderWidthKTable); + nsCSSProps::SearchKeywordTable(coord.GetIntValue(), + nsCSSProps::kBorderWidthKTable); val->SetString(width); break; } default: NS_WARNING("double check the unit"); - break; + break; } } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult +nsresult nsComputedDOMStyle::GetBorderColorFor(PRUint8 aSide, - nsIFrame *aFrame, + nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleBorder* border = nsnull; - GetStyleData(eStyleStruct_Border,(const nsStyleStruct*&)border,aFrame); - + GetStyleData(eStyleStruct_Border, (const nsStyleStruct*&)border, aFrame); + if(border) { - nscolor color; - border->GetBorderColor(aSide,color); + nscolor color; + border->GetBorderColor(aSide, color); nsAutoString hex; - ColorToHex(color,hex); + ColorToHex(color, hex); val->SetString(hex); } else { val->SetString(""); } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult +nsresult nsComputedDOMStyle::GetMarginWidthFor(PRUint8 aSide, nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) + nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleMargin* margin=nsnull; - GetStyleData(eStyleStruct_Margin,(const nsStyleStruct*&)margin,aFrame); - + GetStyleData(eStyleStruct_Margin, (const nsStyleStruct*&)margin, aFrame); + if(margin) { nsStyleCoord coord; switch(aSide) { case NS_SIDE_TOP : margin->mMargin.GetTop(coord); break; - case NS_SIDE_BOTTOM : + case NS_SIDE_BOTTOM : margin->mMargin.GetBottom(coord); break; case NS_SIDE_LEFT : margin->mMargin.GetLeft(coord); break; @@ -2175,8 +2207,8 @@ nsComputedDOMStyle::GetMarginWidthFor(PRUint8 aSide, default: NS_WARNING("double check the side"); break; - } - + } + switch(coord.GetUnit()) { case eStyleUnit_Coord: val->SetTwips(coord.GetCoordValue()); break; @@ -2185,10 +2217,10 @@ nsComputedDOMStyle::GetMarginWidthFor(PRUint8 aSide, nsIFrame* parent=nsnull; aFrame->GetParent(&parent); if(parent) { - nsRect rect; + nsRect rect; parent->GetRect(rect); val->SetTwips(nscoord(coord.GetPercentValue() * rect.width)); - break; // intentionally breaking here... + break; // intentionally breaking here... } } default: @@ -2196,31 +2228,34 @@ nsComputedDOMStyle::GetMarginWidthFor(PRUint8 aSide, break; } } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult +nsresult nsComputedDOMStyle::GetBorderStyleFor(PRUint8 aSide, - nsIFrame *aFrame, + nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleBorder* border = nsnull; - GetStyleData(eStyleStruct_Border,(const nsStyleStruct*&)border,aFrame);; + GetStyleData(eStyleStruct_Border, (const nsStyleStruct*&)border, aFrame); if(border) { const nsCString& style= - nsCSSProps::SearchKeywordTable(border->GetBorderStyle(aSide),nsCSSProps::kBorderStyleKTable); + nsCSSProps::SearchKeywordTable(border->GetBorderStyle(aSide), + nsCSSProps::kBorderStyleKTable); val->SetString(style); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult diff --git a/content/html/style/src/nsDOMCSSDeclaration.cpp b/content/html/style/src/nsDOMCSSDeclaration.cpp index ca1ebfe0c13..a10f72e1926 100644 --- a/content/html/style/src/nsDOMCSSDeclaration.cpp +++ b/content/html/style/src/nsDOMCSSDeclaration.cpp @@ -29,87 +29,40 @@ #include "nsCOMPtr.h" #include "nsIURL.h" +#include "nsContentUtils.h" + + nsDOMCSSDeclaration::nsDOMCSSDeclaration() { NS_INIT_REFCNT(); - mScriptObject = nsnull; } nsDOMCSSDeclaration::~nsDOMCSSDeclaration() { } + +// XPConnect interface list for nsDOMCSSDeclaration +NS_CLASSINFO_MAP_BEGIN(CSSStyleDeclaration) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleDeclaration) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSS2Properties) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSCSS2Properties) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSStyleSheetImpl +NS_INTERFACE_MAP_BEGIN(nsDOMCSSDeclaration) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleDeclaration) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSS2Properties) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSCSS2Properties) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSS2Properties) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleDeclaration) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsDOMCSSDeclaration); NS_IMPL_RELEASE(nsDOMCSSDeclaration); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - -NS_IMETHODIMP -nsDOMCSSDeclaration::QueryInterface(REFNSIID aIID, - void** aInstancePtr) -{ - NS_PRECONDITION(nsnull != aInstancePtr, "null ptr"); - if (nsnull == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsIDOMCSS2Properties))) { - nsIDOMCSS2Properties *tmp = this; - AddRef(); - *aInstancePtr = (void*) tmp; - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMCSSStyleDeclaration))) { - nsIDOMCSSStyleDeclaration *tmp = this; - AddRef(); - *aInstancePtr = (void*) tmp; - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner *tmp = this; - AddRef(); - *aInstancePtr = (void*) tmp; - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - nsIDOMCSSStyleDeclaration *tmp = this; - nsISupports *tmp2 = tmp; - AddRef(); - *aInstancePtr = (void*) tmp2; - return NS_OK; - } - return NS_NOINTERFACE; -} - -NS_IMETHODIMP -nsDOMCSSDeclaration::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - nsCOMPtr parent; - - res = GetParent(getter_AddRefs(parent)); - if (NS_OK == res) { - nsISupports *supports = (nsISupports *)(nsIDOMCSS2Properties *)this; - // XXX Should be done through factory - res = NS_NewScriptCSS2Properties(aContext, - supports, - parent, - (void**)&mScriptObject); - } - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -nsDOMCSSDeclaration::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} NS_IMETHODIMP nsDOMCSSDeclaration::GetCssText(nsAWritableString& aCssText) diff --git a/content/html/style/src/nsDOMCSSDeclaration.h b/content/html/style/src/nsDOMCSSDeclaration.h index d9fbc15d960..965f75bf3cc 100644 --- a/content/html/style/src/nsDOMCSSDeclaration.h +++ b/content/html/style/src/nsDOMCSSDeclaration.h @@ -23,15 +23,15 @@ #define nsDOMCSSSDeclaration_h___ #include "nsISupports.h" +#include "nsIDOMCSSStyleDeclaration.h" #include "nsIDOMCSS2Properties.h" -#include "nsIScriptObjectOwner.h" class nsICSSDeclaration; class nsICSSParser; class nsIURI; -class nsDOMCSSDeclaration : public nsIDOMCSS2Properties, - public nsIScriptObjectOwner +class nsDOMCSSDeclaration : public nsIDOMCSSStyleDeclaration, + public nsIDOMNSCSS2Properties { public: nsDOMCSSDeclaration(); @@ -52,15 +52,13 @@ public: NS_IMETHOD GetPropertyPriority(const nsAReadableString& aPropertyName, nsAWritableString& aReturn); NS_IMETHOD SetProperty(const nsAReadableString& aPropertyName, - const nsAReadableString& aValue, const nsAReadableString& aPriority); + const nsAReadableString& aValue, + const nsAReadableString& aPriority); NS_IMETHOD Item(PRUint32 aIndex, nsAWritableString& aReturn); - NS_DECL_IDOMCSS2PROPERTIES - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMCSS2PROPERTIES + NS_DECL_NSIDOMNSCSS2PROPERTIES virtual void DropReference() = 0; virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl, @@ -75,8 +73,6 @@ public: protected: virtual ~nsDOMCSSDeclaration(); - - void *mScriptObject; }; #endif // nsDOMCSSDeclaration_h___ diff --git a/content/html/style/src/nsROCSSPrimitiveValue.cpp b/content/html/style/src/nsROCSSPrimitiveValue.cpp index 781f995673f..b515fa34e71 100644 --- a/content/html/style/src/nsROCSSPrimitiveValue.cpp +++ b/content/html/style/src/nsROCSSPrimitiveValue.cpp @@ -25,11 +25,10 @@ #include "nsCOMPtr.h" #include "nsDOMError.h" #include "prprf.h" - +#include "nsContentUtils.h" nsROCSSPrimitiveValue::nsROCSSPrimitiveValue(nsISupports *aOwner, float aT2P) - : mType(CSS_PX), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P), - mScriptObject(nsnull) + : mType(CSS_PX), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P) { NS_INIT_REFCNT(); } @@ -44,45 +43,23 @@ NS_IMPL_ADDREF(nsROCSSPrimitiveValue); NS_IMPL_RELEASE(nsROCSSPrimitiveValue); +// XPConnect interface list for nsROCSSPrimitiveValue +NS_CLASSINFO_MAP_BEGIN(ROCSSPrimitiveValue) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSPrimitiveValue) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsROCSSPrimitiveValue NS_INTERFACE_MAP_BEGIN(nsROCSSPrimitiveValue) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPrimitiveValue) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ROCSSPrimitiveValue) NS_INTERFACE_MAP_END -// nsIScriptObjectOwner - -NS_IMETHODIMP -nsROCSSPrimitiveValue::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (!mScriptObject) { - nsISupports *supports = NS_STATIC_CAST(nsIDOMCSSPrimitiveValue *, this); - - // XXX Should be done through factory - res = NS_NewScriptCSSPrimitiveValue(aContext, supports, mOwner, - &mScriptObject); - } - - *aScriptObject = mScriptObject; - - return res; -} - - // nsIDOMCSSValue -NS_IMETHODIMP -nsROCSSPrimitiveValue::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - NS_IMETHODIMP nsROCSSPrimitiveValue::GetCssText(nsAWritableString& aCssText) diff --git a/content/html/style/src/nsROCSSPrimitiveValue.h b/content/html/style/src/nsROCSSPrimitiveValue.h index 6fff2af2b28..46a5e61927b 100644 --- a/content/html/style/src/nsROCSSPrimitiveValue.h +++ b/content/html/style/src/nsROCSSPrimitiveValue.h @@ -32,21 +32,16 @@ #include "nsDOMError.h" -class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue, - public nsIScriptObjectOwner +class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue { public: NS_DECL_ISUPPORTS // nsIDOMCSSPrimitiveValue - NS_DECL_IDOMCSSPRIMITIVEVALUE + NS_DECL_NSIDOMCSSPRIMITIVEVALUE // nsIDOMCSSValue - NS_DECL_IDOMCSSVALUE - - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMCSSVALUE // nsROCSSPrimitiveValue nsROCSSPrimitiveValue(nsISupports *aOwner, float aP2T); @@ -78,8 +73,6 @@ private: nsISupports *mOwner; float mT2P; - - void* mScriptObject; }; #endif /* nsROCSSPrimitiveValue_h___ */ diff --git a/content/macbuild/contentIDL.mcp b/content/macbuild/contentIDL.mcp index 03309764929b0c9257bd0ad585d7e4be47d3b811..065ab75ce3eba30fb59958cfa7a9dd17b7119fc7 100644 GIT binary patch delta 3070 zcmZve3vd)g8ppeLb`qFOc9$??mL$6@5zGRzkO*XnfQjM2!$3BG6%<5bSR+Chac^6{LzlE_Pw4`q~N;%2$n1L_GMl+qUj?<(L&*i(f8(dVI zQJ&jXHBtCHmZ*BHP)^l9%Mw-lW{6{fJaNBi3m%-(6&opbn;seSWplCITJ2)GsPh$z z!L3`xi=J6xzsDBS|Ll{+-U(bT{(BD>yYiNET`aT`;$MODFw97?IT+<`xup;`r|P=+ zAuvnyiLmf`bTMdU$rr5OkC1OX;3tnP5f8>hA8fxCd|1SSmb`WBJT8}3ZOiG%k6-e|{_N-X%t9tgEFqhid%O zp>vj>Y2~lM2ki~SAE$-K#2R_sfALMekx%3cjdcv^IMNqLUm}q&eMl#eK1cctiF_ho z$OqV_fPgKSkeBh}T375cn|79hFH=7EUHv@9Dtgjy7jWCWUSM$vK-v)Hdboq2m0K#+F1f zo=8S+ZcSFqj9wn9Zdnsw5KpjkxQLV&h?%9fxVqfzpmsHD6YJt_=Qaz)+FEXiHztSi z>iLV%V;GvhEEbA2B;xCb(S;4aYk&jI%?*h)WFY?Q+M0$$lW3WtuN&%Lrr)B5#@eN! zrSW8PZKA3D*F9@DBwIHOcP!KI|9MOm^I966*@&t@q5Q|TCQaU5S5ub$Cdflty0?IP z-G2!m;b~7XpRCD=-99}9m?O78Sf|VG`z%eYuY6VbUMUmh^3d6%B%l3Tdx==OD3EWFizoV!}rE z1{Lxjos2&>AA4gN)^Ng45kO zL?V~qs_RVQ3RvNPhT%qPPPS4LicCj%sw>K;a-KRA<@s5>8+cmklPI6mQHDWX7dE%H zuSNXRv2o-`7=uo4PBvkrp_UgXjMAfc zBej{LxVayWW@WfG@I4q^st`9hJy*5&CZSJ7BKtZXq%#A3wFvq&B!~|;Fz-f%> zQ;_Yr@w76>z&`=XGMGIy24js-?f>uz*hPwuo{Mpum3aCqu<43FGLErT`byPdB(66$ zLsgg-N@c)3hV+?=AH~vUFH`M%{tAYzBH6ha4mnHey9Xee!7TUr)U_A$1*MqBnH4X* z68daaZC-^^Ex6WCH}xEcuSxY>%p(f}7>4_mxm$ifU8Sn`6rtRsc*zyes}wg|QAQO1 zydTh^t96l5hbn@D1G1*^Fuj3 zMbpxeIlRxsPo?rI`GF2R7>ub+FfO7U?n8p)g^;Q9VcbO@CJ@wG(U4`V`j7){Q@gX@%kp#)R6WO)O(bAhJp8ri4 z736?3gI(3oza|QP3Ypq=W79t9-w;L9#mLk-GY-;YPlpz=y9?QC%D|hny5ACI>{Xma zCp?UU6z<<4k^S-kWGX(4UDrUz(vVmbZz?{FT{l7ho+wuQe(b7aIO|UU6l)OcZe(F) zICK~~IRzQpgiKA$UQI`%pD55XWM9q9Zo}a^^ZOLs4_z6s4m=Ls`IU;2u9no^FdjNN zj!BIyrv1qnwr_k2gnny)j4(2FA=ot^fzV0wqX=P~k@ delta 1792 zcmYk73v82B6vyxRx^ClJ*N(1hw~m%>Knjd?48|BU3?~SIAk>V9;Ze3CTa?#iOB4c| zh=fSY$heZLL=eNo%>>ZhNEZo1NHl_RF`x+{3K(Pqi31{n@~Z#aJCKu{e&?RwxsUIh zbHCm@V?DIhI%N6UwW}Co7RG2Kqtb3h6MGpmzk{#giy;p3{SK=S`Umtn^fL4+^cu8R z@=%{e7Fm0fd7jfd*b3kOLd|hL$M4~tNyGUyr=N)Lw&jjd{0?@*!xLgGTaV+9<;G(p z&a4z88(E3cTPsKHw7U4w^e8{_Ss{O5ck@&B629Jo^E|cd= z7r$9?j~7|3ys~owAMTu=s`fD$8^bsHCsC^WE$SgGSYtHDVCX$-wl-zYYhQ7)hBujMCOviNELo>Z)r2hHaXjBL4WXc@_s&xSl=OPGAE z;V2uQ>N$>@8yTxcAY-9)^(&7Dwx_kuSkDX2cvHGIJL2(UFH5?L`7?fUD+dBo z;rN&2swK0>$=jueiRVhQHSCFvGRbAirZ$&FPV!|Ff5#OZt@jx_uwQW# zsJS}xzIgmzJJXfO%vo3!o(kuHAPqW*O_6yYEw#qB6jC@vcD3YNB)?)B^6SYVqcwa? z3>!rIWPeBb$o+l0D7N7xdXl3{WdUI>qAGE45q%SzwU~+xzG{gn=ifbOPY+J3oL3nP z1j93@&I_V)85DEm(`bt*bWn;6UH94Kri<=mS^ip+kB`Z+sa)PMY{TgEvDnb9w9fSi4hSh@~5>UEMs+J{VRB? z?j4Y{E*K?ZU4%x{WU(hg9`6fSJgH=LV;vT^sJk*Cwj-hkD|&4%IK1`iR@Abj_T8|D z>3|oviARc8Phl+CrTM;TU?ViItrDSSYW@YBAVu?npTUBfe_Sdeiud4BSu-^6z6mx; zbK7&GB{6>i#-`>|i(wZG@M_VW;3_G0&6gjAU8s4+T+y$1`W1{TG}0zB;whW z>!Kw}ZojP!vWbJ)w? zl{lRFRu6zG0p#wiC#_=s_z({Df{=$1#(Zz;_)o{dp+4b|EoYy!j(I}Dq1%(ZC_|EN z8S~<+@T<=|LjC<{;Xu8}tRrU*uFpW(&36~VR(}T&`vXx?hXlG*TSfJr#jnHuQ&F7b zl31hoV3kx|2y>G-L-xhlne|9AXr}g|F)c5C>qKxhQUi2vb_IV6+fy@KTVE?5k kV}2$cfrk!6Q3jiypZp=f-wDjP%H>Gy4}1$7e?N@<2hTveasU7T diff --git a/content/xbl/public/nsIBindingManager.h b/content/xbl/public/nsIBindingManager.h index 9246b92d83a..5c706df0775 100644 --- a/content/xbl/public/nsIBindingManager.h +++ b/content/xbl/public/nsIBindingManager.h @@ -118,7 +118,7 @@ public: NS_IMETHOD InheritsStyle(nsIContent* aContent, PRBool* aResult) = 0; NS_IMETHOD FlushChromeBindings() = 0; - NS_IMETHOD GetBindingImplementation(nsIContent* aContent, void* aScriptObject, REFNSIID aIID, void** aResult)=0; + NS_IMETHOD GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, void** aResult)=0; NS_IMETHOD ShouldBuildChildFrames(nsIContent* aContent, PRBool* aResult) = 0; }; diff --git a/content/xbl/src/nsBindingManager.cpp b/content/xbl/src/nsBindingManager.cpp index 89a19b19b60..7cdec403551 100644 --- a/content/xbl/src/nsBindingManager.cpp +++ b/content/xbl/src/nsBindingManager.cpp @@ -64,6 +64,7 @@ #include "nsIXBLPrototypeBinding.h" #include "nsIWeakReference.h" +#include "jsapi.h" #include "nsIXPConnect.h" // Static IIDs/CIDs. Try to minimize these. @@ -182,7 +183,7 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNodeList interface - NS_DECL_IDOMNODELIST + NS_DECL_NSIDOMNODELIST // nsIAnonymousContentList NS_IMETHOD GetInsertionPointCount(PRUint32* aCount); @@ -338,7 +339,7 @@ public: NS_IMETHOD InheritsStyle(nsIContent* aContent, PRBool* aResult); NS_IMETHOD FlushChromeBindings(); - NS_IMETHOD GetBindingImplementation(nsIContent* aContent, void* aScriptObject, REFNSIID aIID, void** aResult); + NS_IMETHOD GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, void** aResult); NS_IMETHOD ShouldBuildChildFrames(nsIContent* aContent, PRBool* aResult); @@ -1065,7 +1066,8 @@ nsBindingManager::FlushChromeBindings() } NS_IMETHODIMP -nsBindingManager::GetBindingImplementation(nsIContent* aContent, void* aScriptObject, REFNSIID aIID, void** aResult) +nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, + void** aResult) { *aResult = nsnull; nsCOMPtr binding; @@ -1082,7 +1084,6 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, void* aScriptOb // We have never made a wrapper for this implementation. // Create an XPC wrapper for the script object and hand it back. - JSObject* jsobj = (JSObject*)aScriptObject; nsCOMPtr doc; aContent->GetDocument(*getter_AddRefs(doc)); @@ -1107,8 +1108,22 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, void* aScriptOb if (!xpConnect) return NS_NOINTERFACE; - nsISupports* nativeThis = (nsISupports*)JS_GetPrivate(jscontext, jsobj); - nsresult rv = xpConnect->WrapJSAggregatedToNative(nativeThis, jscontext, jsobj, aIID, aResult); + nsCOMPtr wrapper; + + xpConnect->GetWrappedNativeOfNativeObject(jscontext, + JS_GetGlobalObject(jscontext), + aContent, + NS_GET_IID(nsISupports), + getter_AddRefs(wrapper)); + NS_ENSURE_TRUE(wrapper, NS_NOINTERFACE); + + JSObject* jsobj = nsnull; + + wrapper->GetJSObject(&jsobj); + NS_ENSURE_TRUE(jsobj, NS_NOINTERFACE); + + nsresult rv = xpConnect->WrapJSAggregatedToNative(aContent, jscontext, + jsobj, aIID, aResult); if (NS_FAILED(rv)) return rv; diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index 5b9af0a315f..8f2f978df82 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -49,10 +49,10 @@ #include "nsIDOMText.h" #include "nsSupportsArray.h" #include "nsINameSpace.h" -#include "nsJSUtils.h" -#include "nsIJSRuntimeService.h" +#include "jsapi.h" #include "nsXBLService.h" #include "nsIXBLInsertionPoint.h" +#include "nsIXPConnect.h" // Event listeners #include "nsIEventListenerManager.h" @@ -1408,19 +1408,36 @@ nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocumen nsCOMPtr context; global->GetContext(getter_AddRefs(context)); if (context) { - JSObject* scriptObject; - nsCOMPtr owner(do_QueryInterface(mBoundElement)); - owner->GetScriptObject(context, (void**)&scriptObject); - if (scriptObject) { - // XXX Stay in sync! What if a layered binding has an ?! - - // XXX Sanity check to make sure our class name matches - // Pull ourselves out of the proto chain. - JSContext* jscontext = (JSContext*)context->GetNativeContext(); - JSObject* ourProto = ::JS_GetPrototype(jscontext, scriptObject); - JSObject* grandProto = ::JS_GetPrototype(jscontext, ourProto); - ::JS_SetPrototype(jscontext, scriptObject, grandProto); - } + JSContext *jscontext = (JSContext *)context->GetNativeContext(); + + nsresult rv; + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), + &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr wrapper; + + rv = xpc->WrapNative(jscontext, ::JS_GetGlobalObject(jscontext), + mBoundElement, NS_GET_IID(nsISupports), + getter_AddRefs(wrapper)); + NS_ENSURE_SUCCESS(rv, rv); + + JSObject* scriptObject = nsnull; + rv = wrapper->GetJSObject(&scriptObject); + NS_ENSURE_SUCCESS(rv, rv); + + // XXX Stay in sync! What if a layered binding has an + // ?! + + // XXX Sanity check to make sure our class name matches + // Pull ourselves out of the proto chain. + JSObject* ourProto = ::JS_GetPrototype(jscontext, scriptObject); + JSObject* grandProto = ::JS_GetPrototype(jscontext, ourProto); + ::JS_SetPrototype(jscontext, scriptObject, grandProto); + + // Don't remove the reference from the document to the + // wrapper here since it'll be removed by the element + // itself when that's taken out of the document. } } } @@ -1432,7 +1449,8 @@ nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocumen if (anonymous) { // Also kill the default content within all our insertion points. if (mInsertionPointTable) - mInsertionPointTable->Enumerate(ChangeDocumentForDefaultContent, nsnull); + mInsertionPointTable->Enumerate(ChangeDocumentForDefaultContent, + nsnull); // To make XUL templates work (and other XUL-specific stuff), // we'll need to notify it using its add & remove APIs. Grab the @@ -1534,24 +1552,37 @@ nsXBLBinding::InitClass(const nsCString& aClassName, nsIScriptContext* aContext, *aClassObject = nsnull; *aScriptObject = nsnull; - // Obtain the bound element's current script object. - nsCOMPtr owner(do_QueryInterface(mBoundElement)); - owner->GetScriptObject(aContext, aScriptObject); - if (!(*aScriptObject)) - return NS_ERROR_FAILURE; + nsresult rv; - JSObject* object = (JSObject*)(*aScriptObject); + // Obtain the bound element's current script object. + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + JSContext* jscontext = (JSContext*)aContext->GetNativeContext(); + + nsCOMPtr wrapper; + + JSObject* global = ::JS_GetGlobalObject(jscontext); + + rv = xpc->WrapNative(jscontext, global, mBoundElement, + NS_GET_IID(nsISupports), getter_AddRefs(wrapper)); + NS_ENSURE_SUCCESS(rv, rv); + + JSObject* object = nsnull; + + rv = wrapper->GetJSObject(&object); + NS_ENSURE_SUCCESS(rv, rv); + + *aScriptObject = object; // First ensure our JS class is initialized. - JSContext* jscontext = (JSContext*)aContext->GetNativeContext(); - JSObject* global = ::JS_GetGlobalObject(jscontext); jsval vp; JSObject* proto; if ((! ::JS_LookupProperty(jscontext, global, aClassName, &vp)) || JSVAL_IS_PRIMITIVE(vp)) { // We need to initialize the class. - + nsXBLJSClass* c; void* classObject; nsCStringKey key(aClassName); @@ -1623,6 +1654,20 @@ nsXBLBinding::InitClass(const nsCString& aClassName, nsIScriptContext* aContext, // Set the prototype of our object to be the new class. ::JS_SetPrototype(jscontext, object, proto); + // Root mBoundElement so that it doesn't loose it's binding + nsCOMPtr doc; + + mBoundElement->GetDocument(*getter_AddRefs(doc)); + + if (doc) { + nsCOMPtr native_wrapper = + do_QueryInterface(wrapper); + + if (native_wrapper) { + doc->AddReference(mBoundElement, native_wrapper); + } + } + return NS_OK; } @@ -1697,7 +1742,8 @@ nsXBLBinding::GetEventHandlerIID(nsIAtom* aName, nsIID* aIID, PRBool* aFound) } NS_IMETHODIMP -nsXBLBinding::AddScriptEventListener(nsIContent* aElement, nsIAtom* aName, const nsString& aValue) +nsXBLBinding::AddScriptEventListener(nsIContent* aElement, nsIAtom* aName, + const nsString& aValue) { nsAutoString val; aName->ToString(val); @@ -1732,11 +1778,8 @@ nsXBLBinding::AddScriptEventListener(nsIContent* aElement, nsIAtom* aName, const rv = receiver->GetListenerManager(getter_AddRefs(manager)); if (NS_FAILED(rv)) return rv; - nsCOMPtr scriptOwner(do_QueryInterface(receiver)); - if (!scriptOwner) - return NS_OK; - - rv = manager->AddScriptEventListener(context, scriptOwner, eventName, aValue, PR_FALSE); + rv = manager->AddScriptEventListener(context, receiver, eventName, + aValue, PR_FALSE); return rv; } diff --git a/content/xbl/src/nsXBLContextMenuHandler.h b/content/xbl/src/nsXBLContextMenuHandler.h index 5d33fd3dbef..faa38930cab 100644 --- a/content/xbl/src/nsXBLContextMenuHandler.h +++ b/content/xbl/src/nsXBLContextMenuHandler.h @@ -41,14 +41,15 @@ class nsXBLContextMenuHandler : public nsIDOMContextMenuListener, public nsXBLEventHandler { public: - nsXBLContextMenuHandler(nsIDOMEventReceiver* aReceiver, nsIXBLPrototypeHandler* aHandler); + nsXBLContextMenuHandler(nsIDOMEventReceiver* aReceiver, + nsIXBLPrototypeHandler* aHandler); virtual ~nsXBLContextMenuHandler(); - + // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - - virtual nsresult ContextMenu(nsIDOMEvent* aContextMenuEvent); - + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + + NS_IMETHOD ContextMenu(nsIDOMEvent* aContextMenuEvent); + NS_DECL_ISUPPORTS_INHERITED protected: diff --git a/content/xbl/src/nsXBLDragHandler.cpp b/content/xbl/src/nsXBLDragHandler.cpp index fba4265b345..cdfec67cdef 100644 --- a/content/xbl/src/nsXBLDragHandler.cpp +++ b/content/xbl/src/nsXBLDragHandler.cpp @@ -29,7 +29,6 @@ #include "nsIDOMMouseEvent.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" diff --git a/content/xbl/src/nsXBLDragHandler.h b/content/xbl/src/nsXBLDragHandler.h index 9bd11f4caa7..998be676a32 100644 --- a/content/xbl/src/nsXBLDragHandler.h +++ b/content/xbl/src/nsXBLDragHandler.h @@ -44,13 +44,13 @@ public: virtual ~nsXBLDragHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - virtual nsresult DragEnter(nsIDOMEvent* aMouseEvent); - virtual nsresult DragOver(nsIDOMEvent* aMouseEvent); - virtual nsresult DragExit(nsIDOMEvent* aMouseEvent); - virtual nsresult DragDrop(nsIDOMEvent* aMouseEvent); - virtual nsresult DragGesture(nsIDOMEvent* aMouseEvent); + NS_IMETHOD DragEnter(nsIDOMEvent* aMouseEvent); + NS_IMETHOD DragOver(nsIDOMEvent* aMouseEvent); + NS_IMETHOD DragExit(nsIDOMEvent* aMouseEvent); + NS_IMETHOD DragDrop(nsIDOMEvent* aMouseEvent); + NS_IMETHOD DragGesture(nsIDOMEvent* aMouseEvent); NS_DECL_ISUPPORTS_INHERITED diff --git a/content/xbl/src/nsXBLEventHandler.cpp b/content/xbl/src/nsXBLEventHandler.cpp index 3a8567d6b69..2439f2dc7eb 100644 --- a/content/xbl/src/nsXBLEventHandler.cpp +++ b/content/xbl/src/nsXBLEventHandler.cpp @@ -31,7 +31,6 @@ #include "nsIDOMMouseEvent.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" @@ -148,14 +147,14 @@ nsXBLEventHandler::RemoveEventHandlers() /// Helpers that are relegated to the end of the file ///////////////////////////// nsresult -nsXBLEventHandler::GetTextData(nsIContent *aParent, nsString& aResult) +nsXBLEventHandler::GetTextData(nsIContent *aParent, nsAWritableString& aResult) { aResult.Truncate(0); nsCOMPtr textChild; PRInt32 textCount; aParent->ChildCount(textCount); - nsAutoString answer; + for (PRInt32 j = 0; j < textCount; j++) { // Get the child. aParent->ChildAt(j, *getter_AddRefs(textChild)); @@ -163,7 +162,7 @@ nsXBLEventHandler::GetTextData(nsIContent *aParent, nsString& aResult) if (text) { nsAutoString data; text->GetData(data); - aResult += data; + aResult.Append(data); } } return NS_OK; diff --git a/content/xbl/src/nsXBLEventHandler.h b/content/xbl/src/nsXBLEventHandler.h index 1a223e7cee0..0c2c9c16ada 100644 --- a/content/xbl/src/nsXBLEventHandler.h +++ b/content/xbl/src/nsXBLEventHandler.h @@ -58,7 +58,7 @@ public: if (mNextHandler) mNextHandler->MarkForDeath(); mProtoHandler = nsnull; mEventReceiver = nsnull; } - static nsresult GetTextData(nsIContent *aParent, nsString& aResult); + static nsresult GetTextData(nsIContent *aParent, nsAWritableString& aResult); protected: static PRUint32 gRefCnt; diff --git a/content/xbl/src/nsXBLFocusHandler.cpp b/content/xbl/src/nsXBLFocusHandler.cpp index 1f5b367f28b..1c7e9d26fb8 100644 --- a/content/xbl/src/nsXBLFocusHandler.cpp +++ b/content/xbl/src/nsXBLFocusHandler.cpp @@ -28,7 +28,6 @@ #include "nsIAtom.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" diff --git a/content/xbl/src/nsXBLFocusHandler.h b/content/xbl/src/nsXBLFocusHandler.h index 48b0affb0cb..41552fe5792 100644 --- a/content/xbl/src/nsXBLFocusHandler.h +++ b/content/xbl/src/nsXBLFocusHandler.h @@ -44,10 +44,10 @@ public: virtual ~nsXBLFocusHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - virtual nsresult Focus(nsIDOMEvent* aMouseEvent); - virtual nsresult Blur(nsIDOMEvent* aMouseEvent); + NS_IMETHOD Focus(nsIDOMEvent* aMouseEvent); + NS_IMETHOD Blur(nsIDOMEvent* aMouseEvent); NS_DECL_ISUPPORTS_INHERITED diff --git a/content/xbl/src/nsXBLFormHandler.cpp b/content/xbl/src/nsXBLFormHandler.cpp index 2ea9bf18a76..72af7e59e25 100644 --- a/content/xbl/src/nsXBLFormHandler.cpp +++ b/content/xbl/src/nsXBLFormHandler.cpp @@ -28,7 +28,6 @@ #include "nsIAtom.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" diff --git a/content/xbl/src/nsXBLFormHandler.h b/content/xbl/src/nsXBLFormHandler.h index acd23c19afb..720df8777d2 100644 --- a/content/xbl/src/nsXBLFormHandler.h +++ b/content/xbl/src/nsXBLFormHandler.h @@ -44,13 +44,13 @@ public: virtual ~nsXBLFormHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - virtual nsresult Submit(nsIDOMEvent* aEvent); - virtual nsresult Reset(nsIDOMEvent* aEvent); - virtual nsresult Change(nsIDOMEvent* aEvent); - virtual nsresult Select(nsIDOMEvent* aEvent); - virtual nsresult Input(nsIDOMEvent* aEvent); + NS_IMETHOD Submit(nsIDOMEvent* aEvent); + NS_IMETHOD Reset(nsIDOMEvent* aEvent); + NS_IMETHOD Change(nsIDOMEvent* aEvent); + NS_IMETHOD Select(nsIDOMEvent* aEvent); + NS_IMETHOD Input(nsIDOMEvent* aEvent); NS_DECL_ISUPPORTS_INHERITED diff --git a/content/xbl/src/nsXBLKeyHandler.cpp b/content/xbl/src/nsXBLKeyHandler.cpp index b22a0d90533..5b61f1ea8d8 100644 --- a/content/xbl/src/nsXBLKeyHandler.cpp +++ b/content/xbl/src/nsXBLKeyHandler.cpp @@ -30,7 +30,6 @@ #include "nsIDOMMouseEvent.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" diff --git a/content/xbl/src/nsXBLKeyHandler.h b/content/xbl/src/nsXBLKeyHandler.h index bf270f83c72..3d681d0be56 100644 --- a/content/xbl/src/nsXBLKeyHandler.h +++ b/content/xbl/src/nsXBLKeyHandler.h @@ -42,17 +42,18 @@ class nsXBLKeyHandler : public nsIDOMKeyListener, public nsXBLEventHandler { public: - nsXBLKeyHandler(nsIDOMEventReceiver* aReceiver, nsIXBLPrototypeHandler* aHandler); + nsXBLKeyHandler(nsIDOMEventReceiver* aReceiver, + nsIXBLPrototypeHandler* aHandler); virtual ~nsXBLKeyHandler(); - + // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - - virtual nsresult KeyUp(nsIDOMEvent* aMouseEvent); - virtual nsresult KeyDown(nsIDOMEvent* aMouseEvent); - virtual nsresult KeyPress(nsIDOMEvent* aMouseEvent); - + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + + NS_IMETHOD KeyUp(nsIDOMEvent* aMouseEvent); + NS_IMETHOD KeyDown(nsIDOMEvent* aMouseEvent); + NS_IMETHOD KeyPress(nsIDOMEvent* aMouseEvent); + NS_DECL_ISUPPORTS_INHERITED protected: @@ -66,7 +67,8 @@ protected: }; extern nsresult -NS_NewXBLKeyHandler(nsIDOMEventReceiver* aEventReceiver, nsIXBLPrototypeHandler* aHandlerElement, +NS_NewXBLKeyHandler(nsIDOMEventReceiver* aEventReceiver, + nsIXBLPrototypeHandler* aHandlerElement, nsXBLKeyHandler** aResult); diff --git a/content/xbl/src/nsXBLLoadHandler.cpp b/content/xbl/src/nsXBLLoadHandler.cpp index d7f70ab193b..01c2b15febc 100644 --- a/content/xbl/src/nsXBLLoadHandler.cpp +++ b/content/xbl/src/nsXBLLoadHandler.cpp @@ -28,7 +28,6 @@ #include "nsIAtom.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" diff --git a/content/xbl/src/nsXBLLoadHandler.h b/content/xbl/src/nsXBLLoadHandler.h index 75b4b43b5fd..2d3f844e916 100644 --- a/content/xbl/src/nsXBLLoadHandler.h +++ b/content/xbl/src/nsXBLLoadHandler.h @@ -44,12 +44,12 @@ public: virtual ~nsXBLLoadHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - virtual nsresult Load(nsIDOMEvent* aEvent); - virtual nsresult Unload(nsIDOMEvent* aEvent); - virtual nsresult Abort(nsIDOMEvent* aEvent); - virtual nsresult Error(nsIDOMEvent* aEvent); + NS_IMETHOD Load(nsIDOMEvent* aEvent); + NS_IMETHOD Unload(nsIDOMEvent* aEvent); + NS_IMETHOD Abort(nsIDOMEvent* aEvent); + NS_IMETHOD Error(nsIDOMEvent* aEvent); NS_DECL_ISUPPORTS_INHERITED diff --git a/content/xbl/src/nsXBLMouseHandler.cpp b/content/xbl/src/nsXBLMouseHandler.cpp index 24ffc9d027c..9fc0fdb091c 100644 --- a/content/xbl/src/nsXBLMouseHandler.cpp +++ b/content/xbl/src/nsXBLMouseHandler.cpp @@ -29,7 +29,6 @@ #include "nsIDOMMouseEvent.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" diff --git a/content/xbl/src/nsXBLMouseHandler.h b/content/xbl/src/nsXBLMouseHandler.h index 48716fd8a6e..ad2d746d1eb 100644 --- a/content/xbl/src/nsXBLMouseHandler.h +++ b/content/xbl/src/nsXBLMouseHandler.h @@ -45,14 +45,14 @@ public: virtual ~nsXBLMouseHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent); + NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent); + NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent); + NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent); + NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent); + NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent); + NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent); NS_DECL_ISUPPORTS_INHERITED diff --git a/content/xbl/src/nsXBLMouseMotionHandler.cpp b/content/xbl/src/nsXBLMouseMotionHandler.cpp index 07954e7ae49..ec30bd82c22 100644 --- a/content/xbl/src/nsXBLMouseMotionHandler.cpp +++ b/content/xbl/src/nsXBLMouseMotionHandler.cpp @@ -29,7 +29,6 @@ #include "nsIDOMMouseEvent.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" diff --git a/content/xbl/src/nsXBLMouseMotionHandler.h b/content/xbl/src/nsXBLMouseMotionHandler.h index 7b241b1117d..50c49869642 100644 --- a/content/xbl/src/nsXBLMouseMotionHandler.h +++ b/content/xbl/src/nsXBLMouseMotionHandler.h @@ -45,11 +45,14 @@ public: virtual ~nsXBLMouseMotionHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - virtual nsresult MouseMove(nsIDOMEvent* aMouseEvent); - virtual nsresult DragMove(nsIDOMEvent* aMouseEvent) { // XXX Dead event? - return NS_OK; }; + NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent); + NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent) + { + // XXX Dead event? + return NS_OK; + }; NS_DECL_ISUPPORTS_INHERITED diff --git a/content/xbl/src/nsXBLMutationHandler.cpp b/content/xbl/src/nsXBLMutationHandler.cpp index e590b0426a4..6cd7c62036e 100644 --- a/content/xbl/src/nsXBLMutationHandler.cpp +++ b/content/xbl/src/nsXBLMutationHandler.cpp @@ -28,7 +28,6 @@ #include "nsIAtom.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" diff --git a/content/xbl/src/nsXBLMutationHandler.h b/content/xbl/src/nsXBLMutationHandler.h index 01521ac04bb..14fc050b5d4 100644 --- a/content/xbl/src/nsXBLMutationHandler.h +++ b/content/xbl/src/nsXBLMutationHandler.h @@ -44,7 +44,7 @@ public: virtual ~nsXBLMutationHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; NS_IMETHOD SubtreeModified(nsIDOMEvent* aEvent); NS_IMETHOD AttrModified(nsIDOMEvent* aEvent); diff --git a/content/xbl/src/nsXBLPrototypeHandler.cpp b/content/xbl/src/nsXBLPrototypeHandler.cpp index 2ac9a24a1fd..d3285a19f61 100644 --- a/content/xbl/src/nsXBLPrototypeHandler.cpp +++ b/content/xbl/src/nsXBLPrototypeHandler.cpp @@ -30,7 +30,6 @@ #include "nsIDOMMouseEvent.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" @@ -55,8 +54,13 @@ #include "nsIServiceManager.h" #include "nsXPIDLString.h" #include "nsXULAtoms.h" +#include "nsIXPConnect.h" +#include "nsIDOMScriptObjectFactory.h" +#include "nsDOMCID.h" static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); +static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, + NS_DOM_SCRIPT_OBJECT_FACTORY_CID); PRUint32 nsXBLPrototypeHandler::gRefCnt = 0; @@ -185,7 +189,8 @@ nsXBLPrototypeHandler::InitAccessKeys() } NS_IMETHODIMP -nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver, nsIDOMEvent* aEvent) +nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver, + nsIDOMEvent* aEvent) { if (!mHandlerElement) return NS_ERROR_FAILURE; @@ -245,7 +250,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver, nsIDOMEven // element and call doCommand on it. nsCOMPtr controller; nsCOMPtr focusController; - + nsCOMPtr windowRoot(do_QueryInterface(aReceiver)); if (windowRoot) { windowRoot->GetFocusController(getter_AddRefs(focusController)); @@ -257,10 +262,10 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver, nsIDOMEven nsCOMPtr doc; if (elt) elt->GetDocument(*getter_AddRefs(doc)); - + if (!doc) doc = do_QueryInterface(aReceiver); - + if (!doc) return NS_ERROR_FAILURE; @@ -359,7 +364,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver, nsIDOMEven boundGlobal = do_QueryInterface(rootWin); } else boundGlobal = do_QueryInterface(aReceiver); - + if (!boundGlobal) { nsCOMPtr boundDocument(do_QueryInterface(aReceiver)); if (!boundDocument) { @@ -378,23 +383,44 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver, nsIDOMEven nsCOMPtr boundContext; boundGlobal->GetContext(getter_AddRefs(boundContext)); - nsCOMPtr owner; - if (winRoot) - owner = do_QueryInterface(boundGlobal); - else owner = do_QueryInterface(aReceiver); - - void* scriptObject; - owner->GetScriptObject(boundContext, &scriptObject); - + JSObject* scriptObject = nsnull; + + if (winRoot) { + scriptObject = boundGlobal->GetGlobalJSObject(); + } else { + JSObject *global = boundGlobal->GetGlobalJSObject(); + JSContext *cx = (JSContext *)boundContext->GetNativeContext(); + + nsresult rv; + nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); + + // root + nsCOMPtr wrapper; + + // XXX: Don't use the global object! + rv = xpc->WrapNative(cx, global, aReceiver, NS_GET_IID(nsISupports), + getter_AddRefs(wrapper)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = wrapper->GetJSObject(&scriptObject); + NS_ENSURE_SUCCESS(rv, rv); + } + boundContext->CompileEventHandler(scriptObject, onEventAtom, handlerText, - PR_TRUE, &handler); + PR_TRUE, &handler); // Temporarily bind it to the bound element boundContext->BindCompiledEventHandler(scriptObject, onEventAtom, handler); // Execute it. + nsCOMPtr factory = + do_GetService(kDOMScriptObjectFactoryCID); + NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE); + nsCOMPtr eventListener; - NS_NewJSEventListener(getter_AddRefs(eventListener), boundContext, owner); + + factory->NewJSEventListener(boundContext, aReceiver, + getter_AddRefs(eventListener)); nsCOMPtr jsListener(do_QueryInterface(eventListener)); jsListener->SetEventName(onEventAtom); diff --git a/content/xbl/src/nsXBLScrollHandler.cpp b/content/xbl/src/nsXBLScrollHandler.cpp index c8796f314cd..48ea3d23d4c 100644 --- a/content/xbl/src/nsXBLScrollHandler.cpp +++ b/content/xbl/src/nsXBLScrollHandler.cpp @@ -28,7 +28,6 @@ #include "nsIAtom.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" diff --git a/content/xbl/src/nsXBLScrollHandler.h b/content/xbl/src/nsXBLScrollHandler.h index 8926c6b1832..14d2632ec2a 100644 --- a/content/xbl/src/nsXBLScrollHandler.h +++ b/content/xbl/src/nsXBLScrollHandler.h @@ -44,7 +44,7 @@ public: virtual ~nsXBLScrollHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; NS_IMETHOD Overflow(nsIDOMEvent* aEvent); NS_IMETHOD Underflow(nsIDOMEvent* aEvent); diff --git a/content/xbl/src/nsXBLService.cpp b/content/xbl/src/nsXBLService.cpp index dc23c2ba9ed..b6a6356d61f 100644 --- a/content/xbl/src/nsXBLService.cpp +++ b/content/xbl/src/nsXBLService.cpp @@ -201,11 +201,11 @@ public: NS_DECL_NSISTREAMLISTENER NS_DECL_NSIREQUESTOBSERVER - nsresult Load(nsIDOMEvent* aEvent); - nsresult Unload(nsIDOMEvent* aEvent) { return NS_OK; }; - nsresult Abort(nsIDOMEvent* aEvent) { return NS_OK; }; - nsresult Error(nsIDOMEvent* aEvent) { return NS_OK; }; - nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD Load(nsIDOMEvent* aEvent); + NS_IMETHOD Unload(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD Abort(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD Error(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; static nsIXULPrototypeCache* gXULCache; static PRInt32 gRefCnt; diff --git a/content/xbl/src/nsXBLWindowDragHandler.h b/content/xbl/src/nsXBLWindowDragHandler.h index 2ab670c43c4..019f9ca2457 100644 --- a/content/xbl/src/nsXBLWindowDragHandler.h +++ b/content/xbl/src/nsXBLWindowDragHandler.h @@ -39,12 +39,12 @@ public: virtual ~nsXBLWindowDragHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - virtual nsresult DragGesture(nsIDOMEvent* aMouseEvent) ; - virtual nsresult DragOver(nsIDOMEvent* aMouseEvent) ; - virtual nsresult DragEnter(nsIDOMEvent* aMouseEvent) ; - virtual nsresult DragExit(nsIDOMEvent* aMouseEvent) ; - virtual nsresult DragDrop(nsIDOMEvent* aMouseEvent) ; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD DragGesture(nsIDOMEvent* aMouseEvent) ; + NS_IMETHOD DragOver(nsIDOMEvent* aMouseEvent) ; + NS_IMETHOD DragEnter(nsIDOMEvent* aMouseEvent) ; + NS_IMETHOD DragExit(nsIDOMEvent* aMouseEvent) ; + NS_IMETHOD DragDrop(nsIDOMEvent* aMouseEvent) ; NS_DECL_ISUPPORTS diff --git a/content/xbl/src/nsXBLWindowKeyHandler.h b/content/xbl/src/nsXBLWindowKeyHandler.h index 7ac6d62abef..20ab3c5d368 100644 --- a/content/xbl/src/nsXBLWindowKeyHandler.h +++ b/content/xbl/src/nsXBLWindowKeyHandler.h @@ -40,10 +40,10 @@ public: virtual ~nsXBLWindowKeyHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent); - virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent); - virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent); + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent); + NS_IMETHOD KeyDown(nsIDOMEvent* aKeyEvent); + NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent); NS_DECL_ISUPPORTS diff --git a/content/xbl/src/nsXBLXULHandler.cpp b/content/xbl/src/nsXBLXULHandler.cpp index 77d8e514e3a..938b3d5b28a 100644 --- a/content/xbl/src/nsXBLXULHandler.cpp +++ b/content/xbl/src/nsXBLXULHandler.cpp @@ -28,7 +28,6 @@ #include "nsIContent.h" #include "nsINameSpaceManager.h" #include "nsIScriptContext.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" diff --git a/content/xbl/src/nsXBLXULHandler.h b/content/xbl/src/nsXBLXULHandler.h index c6a1443279b..fd7b5762bb5 100644 --- a/content/xbl/src/nsXBLXULHandler.h +++ b/content/xbl/src/nsXBLXULHandler.h @@ -44,7 +44,7 @@ public: virtual ~nsXBLXULHandler(); // nsIDOMetc. - virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; NS_IMETHOD Create(nsIDOMEvent* aEvent); NS_IMETHOD Close(nsIDOMEvent* aEvent); diff --git a/content/xml/content/src/nsXMLCDATASection.cpp b/content/xml/content/src/nsXMLCDATASection.cpp index ae1835a77cf..cb3aede5c9c 100644 --- a/content/xml/content/src/nsXMLCDATASection.cpp +++ b/content/xml/content/src/nsXMLCDATASection.cpp @@ -21,7 +21,6 @@ */ #include "nsIDOMCDATASection.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIContent.h" #include "nsITextContent.h" @@ -30,10 +29,11 @@ #include "nsCRT.h" #include "nsLayoutAtoms.h" #include "nsIXMLContent.h" +#include "nsString.h" +#include "nsContentUtils.h" class nsXMLCDATASection : public nsIDOMCDATASection, - public nsIScriptObjectOwner, public nsITextContent { public: @@ -44,16 +44,13 @@ public: NS_DECL_ISUPPORTS // nsIDOMNode - NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA(mInner) // nsIDOMCharacterData - NS_IMPL_IDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(mInner) // nsIDOMText - NS_IMPL_IDOMTEXT_USING_GENERIC_DOM_DATA(mInner) - - // nsIScriptObjectOwner - NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMTEXT_USING_GENERIC_DOM_DATA(mInner) // nsIContent NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner) @@ -94,33 +91,28 @@ nsXMLCDATASection::~nsXMLCDATASection() { } + +// XPConnect interface list for nsXMLCDATASection +NS_CLASSINFO_MAP_BEGIN(CDATASection) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCDATASection) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsXMLCDATASection +NS_INTERFACE_MAP_BEGIN(nsXMLCDATASection) + NS_INTERFACE_MAP_ENTRY_DOM_DATA() + NS_INTERFACE_MAP_ENTRY(nsIDOMCDATASection) + NS_INTERFACE_MAP_ENTRY(nsIDOMText) + NS_INTERFACE_MAP_ENTRY(nsIDOMCharacterData) + NS_INTERFACE_MAP_ENTRY(nsITextContent) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CDATASection) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsXMLCDATASection) NS_IMPL_RELEASE(nsXMLCDATASection) -NS_IMETHODIMP -nsXMLCDATASection::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - NS_IMPL_DOM_DATA_QUERY_INTERFACE(aIID, aInstancePtr, this) - if (aIID.Equals(NS_GET_IID(nsIDOMCDATASection))) { - nsIDOMCDATASection* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMText))) { - nsIDOMText* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsITextContent))) { - nsITextContent* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} NS_IMETHODIMP nsXMLCDATASection::GetTag(nsIAtom*& aResult) const @@ -255,3 +247,10 @@ nsXMLCDATASection::SetContentID(PRUint32 aID) mContentID = aID; return NS_OK; } + + +NS_IMETHODIMP_(PRBool) +nsXMLCDATASection::IsContentOfType(PRUint32 aFlags) +{ + return PR_FALSE; +} diff --git a/content/xml/content/src/nsXMLElement.cpp b/content/xml/content/src/nsXMLElement.cpp index f84856581a4..f4e490b7eff 100644 --- a/content/xml/content/src/nsXMLElement.cpp +++ b/content/xml/content/src/nsXMLElement.cpp @@ -25,7 +25,6 @@ #include "nsIDocument.h" #include "nsIAtom.h" #include "nsIEventListenerManager.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsIWebShell.h" #include "nsIEventStateManager.h" #include "nsIDOMEvent.h" @@ -48,7 +47,6 @@ #include "nsIXBLService.h" #include "nsIXBLBinding.h" #include "nsIBindingManager.h" -#include "nsIScriptGlobalObject.h" nsresult @@ -119,6 +117,15 @@ nsXMLElement::~nsXMLElement() NS_IF_RELEASE(mNameSpace); } + +// XPConnect interface list for nsXMLElement +NS_CLASSINFO_MAP_BEGIN(Element) + NS_CLASSINFO_MAP_ENTRY(nsIDOMElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsXMLElement NS_IMETHODIMP nsXMLElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) { @@ -138,6 +145,14 @@ nsXMLElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) inst = NS_STATIC_CAST(nsIDOMElement *, this); } else if (aIID.Equals(NS_GET_IID(nsIXMLContent))) { inst = NS_STATIC_CAST(nsIXMLContent *, this); + } else if (aIID.Equals(NS_GET_IID(nsIDOM3Node))) { + inst = new nsNode3Tearoff(this); + NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY); + } else if (aIID.Equals(NS_GET_IID(nsIClassInfo))) { + inst = nsContentUtils::GetClassInfoInstance(eDOMClassInfo_Element_id, + GetElementIIDs, + "Element"); + NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY); } else { return NS_NOINTERFACE; } @@ -149,9 +164,11 @@ nsXMLElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_OK; } + NS_IMPL_ADDREF_INHERITED(nsXMLElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsXMLElement, nsGenericElement) + static inline nsresult MakeURI(const char *aSpec, nsIURI *aBase, nsIURI **aURI) { nsresult rv; @@ -546,6 +563,7 @@ nsXMLElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) return it->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) aReturn); } +#if 0 NS_IMETHODIMP nsXMLElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) { @@ -629,6 +647,7 @@ nsXMLElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) *aScriptObject = slots->mScriptObject; return res; } +#endif NS_IMETHODIMP nsXMLElement::SetContainingNameSpace(nsINameSpace* aNameSpace) diff --git a/content/xml/content/src/nsXMLElement.h b/content/xml/content/src/nsXMLElement.h index abefdc83106..f7dba1c0342 100644 --- a/content/xml/content/src/nsXMLElement.h +++ b/content/xml/content/src/nsXMLElement.h @@ -26,10 +26,8 @@ #include "nsCOMPtr.h" #include "nsIDOMElement.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIXMLContent.h" -#include "nsIJSScriptObject.h" #include "nsGenericElement.h" #include "nsIStyledContent.h" @@ -49,13 +47,10 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericContainerElement::) + NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericContainerElement::) // nsIDOMElement - NS_FORWARD_IDOMELEMENT(nsGenericContainerElement::) - - // nsIScriptObjectOwner methods - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); + NS_FORWARD_NSIDOMELEMENT(nsGenericContainerElement::) // nsIXMLContent NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace); diff --git a/content/xml/content/src/nsXMLEntity.cpp b/content/xml/content/src/nsXMLEntity.cpp index 2b53fa88635..8cc7f8973b0 100644 --- a/content/xml/content/src/nsXMLEntity.cpp +++ b/content/xml/content/src/nsXMLEntity.cpp @@ -22,19 +22,16 @@ #include "nsIDOMEntity.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIContent.h" #include "nsGenericDOMDataNode.h" #include "nsGenericElement.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsLayoutAtoms.h" #include "nsString.h" #include "nsIXMLContent.h" class nsXMLEntity : public nsIDOMEntity, - public nsIScriptObjectOwner, public nsIContent { public: @@ -48,17 +45,13 @@ public: NS_DECL_ISUPPORTS // nsIDOMNode - NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA(mInner) // nsIDOMEntity NS_IMETHOD GetPublicId(nsAWritableString& aPublicId); NS_IMETHOD GetSystemId(nsAWritableString& aSystemId); NS_IMETHOD GetNotationName(nsAWritableString& aNotationName); - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - // nsIContent NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner) @@ -74,7 +67,6 @@ protected: nsString mPublicId; nsString mSystemId; nsString mNotationName; - void* mScriptObject; }; nsresult @@ -103,63 +95,30 @@ nsXMLEntity::nsXMLEntity(const nsAReadableString& aName, mName(aName), mPublicId(aPublicId), mSystemId(aSystemId), mNotationName(aNotationName) { NS_INIT_REFCNT(); - mScriptObject = nsnull; } nsXMLEntity::~nsXMLEntity() { } + +// XPConnect interface list for nsXMLEntity +NS_CLASSINFO_MAP_BEGIN(Entity) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEntity) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsXMLEntity +NS_INTERFACE_MAP_BEGIN(nsXMLEntity) + NS_INTERFACE_MAP_ENTRY_DOM_DATA() + NS_INTERFACE_MAP_ENTRY(nsIDOMEntity) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Entity) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsXMLEntity) NS_IMPL_RELEASE(nsXMLEntity) -nsresult -nsXMLEntity::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) -{ - if (NULL == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - - if (aIID.Equals(NS_GET_IID(nsISupports))) { - nsIDOMEntity* tmp = this; - nsISupports* tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNode))) { - nsIDOMNode* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMEventReceiver))) { - nsCOMPtr man; - if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ - return man->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), (void**)aInstancePtrResult); - } - return NS_NOINTERFACE; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIContent))) { - nsIContent* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMEntity))) { - nsIDOMEntity* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} NS_IMETHODIMP nsXMLEntity::GetPublicId(nsAWritableString& aPublicId) @@ -185,38 +144,6 @@ nsXMLEntity::GetNotationName(nsAWritableString& aNotationName) return NS_OK; } -NS_IMETHODIMP -nsXMLEntity::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptEntity(aContext, - (nsISupports*)(nsIDOMEntity*)this, - mInner.mParent, - (void**)&mScriptObject); - - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -NS_IMETHODIMP -nsXMLEntity::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - NS_IMETHODIMP nsXMLEntity::GetTag(nsIAtom*& aResult) const { @@ -328,6 +255,12 @@ nsXMLEntity::SetContentID(PRUint32 aID) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP_(PRBool) +nsXMLEntity::IsContentOfType(PRUint32 aFlags) +{ + return PR_FALSE; +} + NS_IMETHODIMP nsXMLEntity::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { diff --git a/content/xml/content/src/nsXMLNamedNodeMap.cpp b/content/xml/content/src/nsXMLNamedNodeMap.cpp index 283c01a3484..750324a9d10 100644 --- a/content/xml/content/src/nsXMLNamedNodeMap.cpp +++ b/content/xml/content/src/nsXMLNamedNodeMap.cpp @@ -22,22 +22,14 @@ #include "nsIDOMNamedNodeMap.h" -#include "nsIScriptObjectOwner.h" -#include "nsIDOMEventReceiver.h" -#include "nsIContent.h" #include "nsGenericDOMDataNode.h" -#include "nsGenericElement.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsLayoutAtoms.h" #include "nsString.h" -#include "nsIXMLContent.h" #include "nsCOMPtr.h" #include "nsISupportsArray.h" +#include "nsContentUtils.h" - -class nsXMLNamedNodeMap : public nsIDOMNamedNodeMap, - public nsIScriptObjectOwner +class nsXMLNamedNodeMap : public nsIDOMNamedNodeMap { public: nsXMLNamedNodeMap(nsISupportsArray *aArray); @@ -48,9 +40,11 @@ public: // nsIDOMNamedNodeMap NS_IMETHOD GetLength(PRUint32* aLength); - NS_IMETHOD GetNamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn); + NS_IMETHOD GetNamedItem(const nsAReadableString& aName, + nsIDOMNode** aReturn); NS_IMETHOD SetNamedItem(nsIDOMNode* aArg, nsIDOMNode** aReturn); - NS_IMETHOD RemoveNamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn); + NS_IMETHOD RemoveNamedItem(const nsAReadableString& aName, + nsIDOMNode** aReturn); NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn); NS_IMETHOD GetNamedItemNS(const nsAReadableString& aNamespaceURI, const nsAReadableString& aLocalName, @@ -60,35 +54,30 @@ public: const nsAReadableString&aLocalName, nsIDOMNode** aReturn); - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - protected: nsISupportsArray *mArray; - - void* mScriptObject; }; nsresult NS_NewXMLNamedNodeMap(nsIDOMNamedNodeMap** aInstancePtrResult, nsISupportsArray *aArray) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } + NS_ENSURE_ARG_POINTER(aInstancePtrResult); + nsIDOMNamedNodeMap* it = new nsXMLNamedNodeMap(aArray); - if (nsnull == it) { + if (!it) { return NS_ERROR_OUT_OF_MEMORY; } - return it->QueryInterface(NS_GET_IID(nsIDOMNamedNodeMap), (void **) aInstancePtrResult); + + *aInstancePtrResult = it; + NS_ADDREF(*aInstancePtrResult); + + return NS_OK; } nsXMLNamedNodeMap::nsXMLNamedNodeMap(nsISupportsArray *aArray) { NS_INIT_REFCNT(); - mScriptObject = nsnull; mArray = aArray; @@ -100,37 +89,22 @@ nsXMLNamedNodeMap::~nsXMLNamedNodeMap() NS_IF_RELEASE(mArray); } +// XPConnect interface list for nsXMLNamedNodeMap +NS_CLASSINFO_MAP_BEGIN(NamedNodeMap) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNamedNodeMap) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsXMLNamedNodeMap +NS_INTERFACE_MAP_BEGIN(nsXMLNamedNodeMap) + NS_INTERFACE_MAP_ENTRY(nsIDOMNamedNodeMap) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NamedNodeMap) +NS_INTERFACE_MAP_END + NS_IMPL_ADDREF(nsXMLNamedNodeMap) NS_IMPL_RELEASE(nsXMLNamedNodeMap) -nsresult -nsXMLNamedNodeMap::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) -{ - if (NULL == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - - if (aIID.Equals(NS_GET_IID(nsISupports))) { - nsIDOMNamedNodeMap* tmp = this; - nsISupports* tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNamedNodeMap))) { - nsIDOMNamedNodeMap* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} NS_IMETHODIMP nsXMLNamedNodeMap::GetLength(PRUint32* aLength) @@ -144,7 +118,8 @@ nsXMLNamedNodeMap::GetLength(PRUint32* aLength) } NS_IMETHODIMP -nsXMLNamedNodeMap::GetNamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn) +nsXMLNamedNodeMap::GetNamedItem(const nsAReadableString& aName, + nsIDOMNode** aReturn) { if (!aReturn) return NS_ERROR_NULL_POINTER; @@ -154,12 +129,13 @@ nsXMLNamedNodeMap::GetNamedItem(const nsAReadableString& aName, nsIDOMNode** aRe if (!mArray) return NS_OK; + nsCOMPtr node; PRUint32 i, count; + mArray->Count(&count); for (i = 0; i < count; i++) { - nsCOMPtr supports_node(dont_AddRef(mArray->ElementAt(i))); - nsCOMPtr node(do_QueryInterface(supports_node)); + mArray->QueryElementAt(i, NS_GET_IID(nsIDOMNode), getter_AddRefs(node)); if (!node) break; @@ -190,12 +166,13 @@ nsXMLNamedNodeMap::SetNamedItem(nsIDOMNode* aArg, nsIDOMNode** aReturn) aArg->GetNodeName(argName); if (mArray) { + nsCOMPtr node; PRUint32 i, count; + mArray->Count(&count); for (i = 0; i < count; i++) { - nsCOMPtr supports_node(dont_AddRef(mArray->ElementAt(i))); - nsCOMPtr node(do_QueryInterface(supports_node)); + mArray->QueryElementAt(i, NS_GET_IID(nsIDOMNode), getter_AddRefs(node)); if (!node) break; @@ -226,22 +203,22 @@ nsXMLNamedNodeMap::SetNamedItem(nsIDOMNode* aArg, nsIDOMNode** aReturn) } NS_IMETHODIMP -nsXMLNamedNodeMap::RemoveNamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn) +nsXMLNamedNodeMap::RemoveNamedItem(const nsAReadableString& aName, + nsIDOMNode** aReturn) { - if (!aReturn) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aReturn); *aReturn = 0; if (!mArray) return NS_OK; + nsCOMPtr node; PRUint32 i, count; mArray->Count(&count); for (i = 0; i < count; i++) { - nsCOMPtr supports_node(dont_AddRef(mArray->ElementAt(i))); - nsCOMPtr node(do_QueryInterface(supports_node)); + mArray->QueryElementAt(i, NS_GET_IID(nsIDOMNode), getter_AddRefs(node)); if (!node) break; @@ -265,17 +242,19 @@ nsXMLNamedNodeMap::RemoveNamedItem(const nsAReadableString& aName, nsIDOMNode** NS_IMETHODIMP nsXMLNamedNodeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn) { - PRUint32 count; + NS_ENSURE_ARG_POINTER(aReturn); - if (!aReturn) - return NS_ERROR_NULL_POINTER; + PRUint32 count; mArray->Count(&count); if (mArray && aIndex < count) { - nsCOMPtr supports_node(dont_AddRef(mArray->ElementAt(aIndex))); - nsCOMPtr domNode(do_QueryInterface(supports_node)); + nsCOMPtr node; - *aReturn = domNode; + mArray->QueryElementAt(aIndex, NS_GET_IID(nsIDOMNode), + getter_AddRefs(node)); + + *aReturn = node; + NS_IF_ADDREF(*aReturn); } else *aReturn = 0; @@ -303,36 +282,3 @@ nsXMLNamedNodeMap::RemoveNamedItemNS(const nsAReadableString& aNamespaceURI, { return NS_ERROR_NOT_IMPLEMENTED; } - -NS_IMETHODIMP -nsXMLNamedNodeMap::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptNamedNodeMap(aContext, - (nsISupports*)(nsIDOMNamedNodeMap*)this, - nsnull /*mInner.mParent*/, - (void**)&mScriptObject); - - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -NS_IMETHODIMP -nsXMLNamedNodeMap::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - diff --git a/content/xml/content/src/nsXMLNotation.cpp b/content/xml/content/src/nsXMLNotation.cpp index 44ab03f3a79..d16494bfc56 100644 --- a/content/xml/content/src/nsXMLNotation.cpp +++ b/content/xml/content/src/nsXMLNotation.cpp @@ -22,19 +22,16 @@ #include "nsIDOMNotation.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIContent.h" #include "nsGenericDOMDataNode.h" #include "nsGenericElement.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsLayoutAtoms.h" #include "nsString.h" #include "nsIXMLContent.h" class nsXMLNotation : public nsIDOMNotation, - public nsIScriptObjectOwner, public nsIContent { public: @@ -47,16 +44,12 @@ public: NS_DECL_ISUPPORTS // nsIDOMNode - NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA(mInner) // nsIDOMNotation NS_IMETHOD GetPublicId(nsAWritableString& aPublicId); NS_IMETHOD GetSystemId(nsAWritableString& aSystemId); - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - // nsIContent NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner) @@ -71,7 +64,6 @@ protected: nsString mName; nsString mPublicId; nsString mSystemId; - void* mScriptObject; }; nsresult @@ -98,63 +90,30 @@ nsXMLNotation::nsXMLNotation(const nsAReadableString& aName, mName(aName), mPublicId(aPublicId), mSystemId(aSystemId) { NS_INIT_REFCNT(); - mScriptObject = nsnull; } nsXMLNotation::~nsXMLNotation() { } + +// XPConnect interface list for nsXMLNotation +NS_CLASSINFO_MAP_BEGIN(Notation) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNotation) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsXMLNotation +NS_INTERFACE_MAP_BEGIN(nsXMLNotation) + NS_INTERFACE_MAP_ENTRY_DOM_DATA() + NS_INTERFACE_MAP_ENTRY(nsIDOMNotation) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Notation) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsXMLNotation) NS_IMPL_RELEASE(nsXMLNotation) -nsresult -nsXMLNotation::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) -{ - if (NULL == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - - if (aIID.Equals(NS_GET_IID(nsISupports))) { - nsIDOMNotation* tmp = this; - nsISupports* tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNode))) { - nsIDOMNode* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMEventReceiver))) { - nsCOMPtr man; - if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ - return man->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), (void**)aInstancePtrResult); - } - return NS_NOINTERFACE; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIContent))) { - nsIContent* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNotation))) { - nsIDOMNotation* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} NS_IMETHODIMP nsXMLNotation::GetPublicId(nsAWritableString& aPublicId) @@ -172,38 +131,6 @@ nsXMLNotation::GetSystemId(nsAWritableString& aSystemId) return NS_OK; } -NS_IMETHODIMP -nsXMLNotation::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptNotation(aContext, - (nsISupports*)(nsIDOMNotation*)this, - mInner.mParent, - (void**)&mScriptObject); - - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -NS_IMETHODIMP -nsXMLNotation::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - NS_IMETHODIMP nsXMLNotation::GetTag(nsIAtom*& aResult) const { @@ -309,6 +236,12 @@ nsXMLNotation::SetContentID(PRUint32 aID) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP_(PRBool) +nsXMLNotation::IsContentOfType(PRUint32 aFlags) +{ + return PR_FALSE; +} + NS_IMETHODIMP nsXMLNotation::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { diff --git a/content/xml/content/src/nsXMLProcessingInstruction.cpp b/content/xml/content/src/nsXMLProcessingInstruction.cpp index b782501fcb6..346082bfb99 100644 --- a/content/xml/content/src/nsXMLProcessingInstruction.cpp +++ b/content/xml/content/src/nsXMLProcessingInstruction.cpp @@ -24,7 +24,6 @@ #include "nsIDOMProcessingInstruction.h" #include "nsIDOMLinkStyle.h" #include "nsIDOMStyleSheet.h" -#include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIContent.h" #include "nsIDocument.h" @@ -32,7 +31,6 @@ #include "nsIURI.h" #include "nsGenericDOMDataNode.h" #include "nsGenericElement.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsLayoutAtoms.h" #include "nsString.h" #include "nsXPIDLString.h" @@ -43,7 +41,6 @@ class nsXMLProcessingInstruction : public nsIDOMProcessingInstruction, public nsIDOMLinkStyle, - public nsIScriptObjectOwner, public nsIContent { public: @@ -54,17 +51,13 @@ public: NS_DECL_ISUPPORTS // nsIDOMNode - NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA(mInner) // nsIDOMProcessingInstruction - NS_DECL_IDOMPROCESSINGINSTRUCTION + NS_DECL_NSIDOMPROCESSINGINSTRUCTION // nsIDOMLinkStyle - NS_DECL_IDOMLINKSTYLE - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); + NS_DECL_NSIDOMLINKSTYLE // nsIContent NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner) @@ -80,7 +73,6 @@ protected: // be changed if this restricts what should be done for character data. nsGenericDOMDataNode mInner; nsString mTarget; - void* mScriptObject; }; nsresult @@ -105,69 +97,33 @@ nsXMLProcessingInstruction::nsXMLProcessingInstruction(const nsAReadableString& { NS_INIT_REFCNT(); mInner.SetData(this, aData); - mScriptObject = nsnull; } nsXMLProcessingInstruction::~nsXMLProcessingInstruction() { } + +// XPConnect interface list for nsXMLProcessingInstruction +NS_CLASSINFO_MAP_BEGIN(ProcessingInstruction) + NS_CLASSINFO_MAP_ENTRY(nsIDOMProcessingInstruction) + NS_CLASSINFO_MAP_ENTRY(nsIDOMLinkStyle) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsXMLProcessingInstruction +NS_INTERFACE_MAP_BEGIN(nsXMLProcessingInstruction) + NS_INTERFACE_MAP_ENTRY_DOM_DATA() + NS_INTERFACE_MAP_ENTRY(nsIDOMProcessingInstruction) + NS_INTERFACE_MAP_ENTRY(nsIDOMLinkStyle) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ProcessingInstruction) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsXMLProcessingInstruction) NS_IMPL_RELEASE(nsXMLProcessingInstruction) -nsresult -nsXMLProcessingInstruction::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) -{ - if (NULL == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - - if (aIID.Equals(NS_GET_IID(nsISupports))) { - nsIDOMProcessingInstruction* tmp = this; - nsISupports* tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNode))) { - nsIDOMNode* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMEventReceiver))) { - nsCOMPtr man; - if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ - return man->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), (void**)aInstancePtrResult); - } - return NS_NOINTERFACE; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIContent))) { - nsIContent* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMProcessingInstruction))) { - nsIDOMProcessingInstruction* tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMLinkStyle))) { - nsIDOMLinkStyle *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} NS_IMETHODIMP nsXMLProcessingInstruction::GetTarget(nsAWritableString& aTarget) @@ -296,38 +252,6 @@ nsXMLProcessingInstruction::GetSheet(nsIDOMStyleSheet** aSheet) return NS_OK; } -NS_IMETHODIMP -nsXMLProcessingInstruction::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptProcessingInstruction(aContext, - (nsISupports*)(nsIDOMProcessingInstruction*)this, - mInner.mParent, - (void**)&mScriptObject); - - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -NS_IMETHODIMP -nsXMLProcessingInstruction::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - NS_IMETHODIMP nsXMLProcessingInstruction::GetTag(nsIAtom*& aResult) const { @@ -436,3 +360,9 @@ nsXMLProcessingInstruction::SizeOf(nsISizeOfHandler* aSizer, #endif return NS_OK; } + +NS_IMETHODIMP_(PRBool) +nsXMLProcessingInstruction::IsContentOfType(PRUint32 aFlags) +{ + return PR_FALSE; +} diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index a456f3a8da4..d16a39afa70 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -31,7 +31,6 @@ #include "nsIDOMDOMImplementation.h" #include "nsIXMLDocument.h" #include "nsIXMLContent.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIURL.h" #include "nsIRefreshURI.h" diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index 9edac8f6361..375275cd60a 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -76,13 +76,15 @@ #include "nsLayoutCID.h" #include "nsContentCID.h" #include "nsDOMAttribute.h" -static NS_DEFINE_CID(kHTMLStyleSheetCID,NS_HTMLSTYLESHEET_CID); #include "nsCExternalHandlerService.h" #include "nsIMIMEService.h" #include "nsNetUtil.h" #include "nsMimeTypes.h" +#include "nsContentUtils.h" + +static NS_DEFINE_CID(kHTMLStyleSheetCID,NS_HTMLSTYLESHEET_CID); // XXX The XML world depends on the html atoms #include "nsHTMLAtoms.h" @@ -188,11 +190,11 @@ nsXMLDocument::nsXMLDocument() nsXMLDocument::~nsXMLDocument() { NS_IF_RELEASE(mParser); - if (nsnull != mAttrStyleSheet) { + if (mAttrStyleSheet) { mAttrStyleSheet->SetOwningDocument(nsnull); NS_RELEASE(mAttrStyleSheet); } - if (nsnull != mInlineStyleSheet) { + if (mInlineStyleSheet) { mInlineStyleSheet->SetOwningDocument(nsnull); NS_RELEASE(mInlineStyleSheet); } @@ -202,42 +204,33 @@ nsXMLDocument::~nsXMLDocument() } } -NS_IMETHODIMP -nsXMLDocument::QueryInterface(REFNSIID aIID, - void** aInstancePtr) -{ - NS_ENSURE_ARG_POINTER(aInstancePtr); - nsISupports *inst = nsnull; +// XPConnect interface list for nsXMLDocument +NS_CLASSINFO_MAP_BEGIN(Document) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocument) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSDocument) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentEvent) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentStyle) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentView) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentRange) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentXBL) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) +NS_CLASSINFO_MAP_END - if (aIID.Equals(NS_GET_IID(nsIXMLDocument))) { - inst = NS_STATIC_CAST(nsIXMLDocument *, this); - } else if (aIID.Equals(NS_GET_IID(nsIHTMLContentContainer))) { - inst = NS_STATIC_CAST(nsIHTMLContentContainer *, this); - } else if (aIID.Equals(NS_GET_IID(nsIInterfaceRequestor))) { - inst = NS_STATIC_CAST(nsIInterfaceRequestor *, this); - } else if (aIID.Equals(NS_GET_IID(nsIHTTPEventSink))) { - inst = NS_STATIC_CAST(nsIHTTPEventSink *, this); - } else { - return nsDocument::QueryInterface(aIID, aInstancePtr); - } - NS_ADDREF(inst); +// QueryInterface implementation for nsHTMLAnchorElement +NS_INTERFACE_MAP_BEGIN(nsXMLDocument) + NS_INTERFACE_MAP_ENTRY(nsIXMLDocument) + NS_INTERFACE_MAP_ENTRY(nsIHTMLContentContainer) + NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) + NS_INTERFACE_MAP_ENTRY(nsIHTTPEventSink) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Document) +NS_INTERFACE_MAP_END_INHERITING(nsDocument) - *aInstancePtr = inst; - return NS_OK; -} +NS_IMPL_ADDREF_INHERITED(nsXMLDocument, nsDocument) +NS_IMPL_RELEASE_INHERITED(nsXMLDocument, nsDocument) -nsrefcnt nsXMLDocument::AddRef() -{ - return nsDocument::AddRef(); -} - -nsrefcnt nsXMLDocument::Release() -{ - return nsDocument::Release(); -} NS_IMETHODIMP nsXMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) diff --git a/content/xsl/document/src/nsTransformMediator.cpp b/content/xsl/document/src/nsTransformMediator.cpp index 148cd1b444f..c07b8724958 100644 --- a/content/xsl/document/src/nsTransformMediator.cpp +++ b/content/xsl/document/src/nsTransformMediator.cpp @@ -22,6 +22,7 @@ #include "nsCOMPtr.h" #include "nsTransformMediator.h" #include "nsIComponentManager.h" +#include "nsString.h" const char* kTransformerContractIDPrefix = "@mozilla.org/document-transformer;1?type="; diff --git a/content/xul/content/src/nsRDFDOMNodeList.cpp b/content/xul/content/src/nsRDFDOMNodeList.cpp index 92be6decb0b..b7cbf301e3c 100644 --- a/content/xul/content/src/nsRDFDOMNodeList.cpp +++ b/content/xul/content/src/nsRDFDOMNodeList.cpp @@ -34,20 +34,10 @@ #include "nsDOMCID.h" #include "nsIDOMNode.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsIScriptGlobalObject.h" #include "nsIServiceManager.h" #include "nsISupportsArray.h" #include "nsRDFDOMNodeList.h" - -//////////////////////////////////////////////////////////////////////// -// GUID definitions - -static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); -static NS_DEFINE_IID(kIDOMNodeListIID, NS_IDOMNODELIST_IID); -static NS_DEFINE_IID(kIDOMScriptObjectFactoryIID, NS_IDOM_SCRIPT_OBJECT_FACTORY_IID); - -static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); +#include "nsContentUtils.h" //////////////////////////////////////////////////////////////////////// // ctors & dtors @@ -55,8 +45,7 @@ static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_C nsRDFDOMNodeList::nsRDFDOMNodeList(void) : //mInner(nsnull), Not being used? - mElements(nsnull), - mScriptObject(nsnull) + mElements(nsnull) { NS_INIT_REFCNT(); } @@ -91,7 +80,8 @@ nsRDFDOMNodeList::Create(nsRDFDOMNodeList** aResult) } nsresult -nsRDFDOMNodeList::CreateWithArray(nsISupportsArray* aArray, nsRDFDOMNodeList** aResult) +nsRDFDOMNodeList::CreateWithArray(nsISupportsArray* aArray, + nsRDFDOMNodeList** aResult) { nsRDFDOMNodeList* list = new nsRDFDOMNodeList(); if (! list) @@ -108,37 +98,25 @@ nsRDFDOMNodeList::CreateWithArray(nsISupportsArray* aArray, nsRDFDOMNodeList** a //////////////////////////////////////////////////////////////////////// // nsISupports interface + +// XPConnect interface list for nsRDFDOMNodeList +NS_CLASSINFO_MAP_BEGIN(XULNodeList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNodeList) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsRDFDOMNodeList +NS_INTERFACE_MAP_BEGIN(nsRDFDOMNodeList) + NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList) + NS_INTERFACE_MAP_ENTRY(nsIRDFNodeList) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_WITH_NAME(XULNodeList, NodeList) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsRDFDOMNodeList); NS_IMPL_RELEASE(nsRDFDOMNodeList); -nsresult -nsRDFDOMNodeList::QueryInterface(REFNSIID aIID, void** aResult) -{ -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); - - NS_PRECONDITION(aResult != nsnull, "null ptr"); - if (! aResult) - return NS_ERROR_NULL_POINTER; - - if (aIID.Equals(NS_GET_IID(nsIDOMNodeList)) || - aIID.Equals(kISupportsIID)) { - *aResult = NS_STATIC_CAST(nsIDOMNodeList*, this); - } - else if (aIID.Equals(NS_GET_IID(nsIRDFNodeList))) { - *aResult = NS_STATIC_CAST(nsIRDFNodeList*, this); - } - else if (aIID.Equals(kIScriptObjectOwnerIID)) { - *aResult = NS_STATIC_CAST(nsIScriptObjectOwner*, this); - } - else { - *aResult = nsnull; - return NS_NOINTERFACE; - } - - NS_ADDREF(this); - return NS_OK; -} //////////////////////////////////////////////////////////////////////// // nsIDOMNodeList interface @@ -161,12 +139,8 @@ nsRDFDOMNodeList::GetLength(PRUint32* aLength) NS_IMETHODIMP nsRDFDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) { - PRUint32 cnt; - nsresult rv = mElements->Count(&cnt); - if (NS_FAILED(rv)) return rv; - - if (aIndex >= (PRUint32) cnt) - return NS_ERROR_INVALID_ARG; + // It's ok to access past the end of the array here, if we do that + // we simply return nsnull, as per the DOM spec. // Cast is okay because we're in a closed system. *aReturn = (nsIDOMNode*) mElements->ElementAt(aIndex); @@ -174,43 +148,6 @@ nsRDFDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) } -//////////////////////////////////////////////////////////////////////// -// nsIScriptObjectOwner interface - -NS_IMETHODIMP -nsRDFDOMNodeList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult rv = NS_OK; - nsIScriptGlobalObject* global = aContext->GetGlobalObject(); - - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kDOMScriptObjectFactoryCID, - kIDOMScriptObjectFactoryIID, - (nsISupports **)&factory))) { - rv = factory->NewScriptNodeList(aContext, - (nsISupports*)(nsIDOMNodeList*)this, - global, - (void**)&mScriptObject); - - nsServiceManager::ReleaseService(kDOMScriptObjectFactoryCID, factory); - } - } - *aScriptObject = mScriptObject; - - NS_RELEASE(global); - return rv; -} - -NS_IMETHODIMP -nsRDFDOMNodeList::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - //////////////////////////////////////////////////////////////////////// // Implementation methods diff --git a/content/xul/content/src/nsRDFDOMNodeList.h b/content/xul/content/src/nsRDFDOMNodeList.h index d22d0101eb5..09fdc314ac5 100644 --- a/content/xul/content/src/nsRDFDOMNodeList.h +++ b/content/xul/content/src/nsRDFDOMNodeList.h @@ -25,18 +25,15 @@ #include "nsIDOMNodeList.h" #include "nsIRDFNodeList.h" -#include "nsIScriptObjectOwner.h" class nsIDOMNode; class nsISupportsArray; class nsRDFDOMNodeList : public nsIDOMNodeList, - public nsIRDFNodeList, - public nsIScriptObjectOwner + public nsIRDFNodeList { private: //nsISupports* mInner; Not being used? nsISupportsArray* mElements; - void* mScriptObject; nsRDFDOMNodeList(void); nsresult Init(void); @@ -51,11 +48,7 @@ public: NS_DECL_ISUPPORTS // nsIDOMNodeList interface - NS_DECL_IDOMNODELIST - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMNODELIST // Implementation methods NS_IMETHOD AppendNode(nsIDOMNode* aNode); diff --git a/content/xul/content/src/nsXULAttributes.cpp b/content/xul/content/src/nsXULAttributes.cpp index 160c658064a..a47bcdd479f 100644 --- a/content/xul/content/src/nsXULAttributes.cpp +++ b/content/xul/content/src/nsXULAttributes.cpp @@ -44,18 +44,15 @@ #include "nsINodeInfo.h" #include "nsICSSParser.h" #include "nsIDOMElement.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsINameSpaceManager.h" #include "nsIServiceManager.h" #include "nsIURL.h" #include "nsXULAttributes.h" #include "nsLayoutCID.h" #include "nsReadableUtils.h" +#include "nsContentUtils.h" -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID); -static NS_DEFINE_CID(kICSSParserIID, NS_ICSS_PARSER_IID); //---------------------------------------------------------------------- @@ -206,7 +203,6 @@ nsXULAttribute::nsXULAttribute(nsIContent* aContent, nsINodeInfo* aNodeInfo, const nsAReadableString& aValue) : mContent(aContent), - mScriptObject(nsnull), mNodeInfo(aNodeInfo) { NS_INIT_REFCNT(); @@ -248,33 +244,26 @@ nsXULAttribute::Create(nsIContent* aContent, } // nsISupports interface + +// XPConnect interface list for nsXULAttribute +NS_CLASSINFO_MAP_BEGIN(XULAttr) + NS_CLASSINFO_MAP_ENTRY(nsIDOMAttr) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsXULAttribute +NS_INTERFACE_MAP_BEGIN(nsXULAttribute) + NS_INTERFACE_MAP_ENTRY(nsIDOMAttr) + NS_INTERFACE_MAP_ENTRY(nsIDOMNode) + NS_INTERFACE_MAP_ENTRY(nsIDOM3Node) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMAttr) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_WITH_NAME(XULAttr, Attr) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsXULAttribute); NS_IMPL_RELEASE(nsXULAttribute); -NS_IMETHODIMP -nsXULAttribute::QueryInterface(REFNSIID aIID, void** aResult) -{ - NS_PRECONDITION(aResult != nsnull, "null ptr"); - if (! aResult) - return NS_ERROR_NULL_POINTER; - - if (aIID.Equals(NS_GET_IID(nsIDOMAttr)) || - aIID.Equals(NS_GET_IID(nsIDOMNode)) || - aIID.Equals(kISupportsIID)) { - *aResult = NS_STATIC_CAST(nsIDOMAttr*, this); - NS_ADDREF(this); - return NS_OK; - } - else if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - *aResult = NS_STATIC_CAST(nsIScriptObjectOwner*, this); - NS_ADDREF(this); - return NS_OK; - } - else { - *aResult = nsnull; - return NS_NOINTERFACE; - } -} // nsIDOMNode interface @@ -462,14 +451,12 @@ nsXULAttribute::IsSupported(const nsAReadableString& aFeature, return NS_ERROR_NOT_IMPLEMENTED; } -#if 0 NS_IMETHODIMP nsXULAttribute::GetBaseURI(nsAWritableString &aURI) { NS_NOTYETIMPLEMENTED("write me"); return NS_ERROR_NOT_IMPLEMENTED; } -#endif // nsIDOMAttr interface @@ -512,43 +499,6 @@ nsXULAttribute::GetOwnerElement(nsIDOMElement** aOwnerElement) } -// nsIScriptObjectOwner interface - -NS_IMETHODIMP -nsXULAttribute::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) -{ - nsresult rv = NS_OK; - if (! mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - rv = nsServiceManager::GetService(kDOMScriptObjectFactoryCID, - NS_GET_IID(nsIDOMScriptObjectFactory), - (nsISupports **)&factory); - - if (NS_FAILED(rv)) - return rv; - - rv = factory->NewScriptAttr(aContext, - (nsISupports*)(nsIDOMAttr*) this, - (nsISupports*) mContent, - (void**) &mScriptObject); - - nsServiceManager::ReleaseService(kDOMScriptObjectFactoryCID, factory); - } - - *aScriptObject = mScriptObject; - return rv; -} - - -NS_IMETHODIMP -nsXULAttribute::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - // Implementation methods void @@ -580,8 +530,7 @@ nsXULAttribute::GetValueAsAtom(nsIAtom** aResult) nsXULAttributes::nsXULAttributes(nsIContent* aContent) : mContent(aContent), mClassList(nsnull), - mStyleRule(nsnull), - mScriptObject(nsnull) + mStyleRule(nsnull) { NS_INIT_REFCNT(); } @@ -615,33 +564,24 @@ nsXULAttributes::Create(nsIContent* aContent, nsXULAttributes** aResult) // nsISupports interface +// XPConnect interface list for nsXULAttributes +NS_CLASSINFO_MAP_BEGIN(XULNamedNodeMap) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNamedNodeMap) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsXULAttributes +NS_INTERFACE_MAP_BEGIN(nsXULAttributes) + NS_INTERFACE_MAP_ENTRY(nsIDOMNamedNodeMap) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNamedNodeMap) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_WITH_NAME(XULNamedNodeMap, + NamedNodeMap) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsXULAttributes); NS_IMPL_RELEASE(nsXULAttributes); -NS_IMETHODIMP -nsXULAttributes::QueryInterface(REFNSIID aIID, void** aResult) -{ - NS_PRECONDITION(aResult != nsnull, "null ptr"); - if (! aResult) - return NS_ERROR_NULL_POINTER; - - if (aIID.Equals(NS_GET_IID(nsIDOMNamedNodeMap)) || - aIID.Equals(kISupportsIID)) { - *aResult = NS_STATIC_CAST(nsIDOMNamedNodeMap*, this); - NS_ADDREF(this); - return NS_OK; - } - else if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - *aResult = NS_STATIC_CAST(nsIScriptObjectOwner*, this); - NS_ADDREF(this); - return NS_OK; - } - else { - *aResult = nsnull; - return NS_NOINTERFACE; - } -} - // nsIDOMNamedNodeMap interface @@ -752,42 +692,6 @@ nsXULAttributes::RemoveNamedItemNS(const nsAReadableString& aNamespaceURI, } - -// nsIScriptObjectOwner interface - -NS_IMETHODIMP -nsXULAttributes::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) -{ - nsresult rv = NS_OK; - if (! mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - rv = nsServiceManager::GetService(kDOMScriptObjectFactoryCID, - NS_GET_IID(nsIDOMScriptObjectFactory), - (nsISupports **)&factory); - - if (NS_FAILED(rv)) - return rv; - - rv = factory->NewScriptNamedNodeMap(aContext, - (nsISupports*)(nsIDOMNamedNodeMap*) this, - (nsISupports*) mContent, - (void**) &mScriptObject); - - nsServiceManager::ReleaseService(kDOMScriptObjectFactoryCID, factory); - } - - *aScriptObject = mScriptObject; - return rv; -} - -NS_IMETHODIMP -nsXULAttributes::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - // Implementation methods nsresult @@ -828,11 +732,9 @@ nsresult nsXULAttributes::UpdateStyleRule(nsIURI* aDocURL, const nsAReadableStri return NS_OK; } - nsCOMPtr css; - nsresult result = nsComponentManager::CreateInstance(kCSSParserCID, - nsnull, - kICSSParserIID, - getter_AddRefs(css)); + nsresult result = NS_OK; + + nsCOMPtr css(do_CreateInstance(kCSSParserCID, &result)); if (NS_OK != result) { return result; } diff --git a/content/xul/content/src/nsXULAttributes.h b/content/xul/content/src/nsXULAttributes.h index fd7e3498842..06011d28559 100644 --- a/content/xul/content/src/nsXULAttributes.h +++ b/content/xul/content/src/nsXULAttributes.h @@ -32,7 +32,6 @@ #include "nsIDOMAttr.h" #include "nsIDOMNamedNodeMap.h" -#include "nsIScriptObjectOwner.h" #include "nsIStyleRule.h" #include "nsString.h" #include "nsIAtom.h" @@ -96,7 +95,7 @@ public: //////////////////////////////////////////////////////////////////////// class nsXULAttribute : public nsIDOMAttr, - public nsIScriptObjectOwner + public nsIDOM3Node { protected: static PRInt32 gRefCnt; @@ -130,14 +129,13 @@ public: NS_DECL_ISUPPORTS // nsIDOMNode interface - NS_DECL_IDOMNODE + NS_DECL_NSIDOMNODE + + // nsIDOM3Node interface + NS_DECL_NSIDOM3NODE // nsIDOMAttr interface - NS_DECL_IDOMATTR - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); + NS_DECL_NSIDOMATTR // Implementation methods void GetQualifiedName(nsAWritableString& aAttributeName); @@ -152,7 +150,6 @@ protected: nsXULAttribute* mNext; // For objects on the freelist }; - void* mScriptObject; // The attribute's script object, if reified nsINodeInfo* mNodeInfo; // The attribute name nsXULAttributeValue mValue; // The attribute value; either an nsIAtom* or PRUnichar*, // with the low-order bit tagging its type @@ -161,8 +158,7 @@ protected: //////////////////////////////////////////////////////////////////////// -class nsXULAttributes : public nsIDOMNamedNodeMap, - public nsIScriptObjectOwner +class nsXULAttributes : public nsIDOMNamedNodeMap { public: static nsresult @@ -172,11 +168,7 @@ public: NS_DECL_ISUPPORTS // nsIDOMNamedNodeMap interface - NS_DECL_IDOMNAMEDNODEMAP - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); + NS_DECL_NSIDOMNAMEDNODEMAP // Implementation methods // VoidArray Helpers @@ -204,7 +196,6 @@ protected: nsClassList* mClassList; nsCOMPtr mStyleRule; nsAutoVoidArray mAttributes; - void* mScriptObject; }; diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 69f59e98596..10507339b94 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -74,7 +74,6 @@ #include "nsIDOMEventListener.h" #include "nsIDOMEventReceiver.h" #include "nsIDOMNodeList.h" -#include "nsIDOMScriptObjectFactory.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIDOMXULElement.h" #include "nsIDocument.h" @@ -82,7 +81,6 @@ #include "nsIEventStateManager.h" #include "nsIHTMLContentContainer.h" #include "nsIHTMLStyleSheet.h" -#include "nsIJSScriptObject.h" #include "nsIStyleContext.h" #include "nsIMutableStyleContext.h" #include "nsINameSpace.h" @@ -95,7 +93,6 @@ #include "nsIRDFService.h" #include "nsIScriptContext.h" #include "nsIScriptGlobalObject.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObjectOwner.h" #include "nsIServiceManager.h" #include "nsIStyleContext.h" @@ -126,6 +123,8 @@ #include "nsIDOMCSSStyleDeclaration.h" #include "nsXULAtoms.h" #include "nsITreeBoxObject.h" +#include "nsContentUtils.h" +#include "nsGenericElement.h" #include "nsMutationEvent.h" #include "nsIDOMMutationEvent.h" @@ -154,29 +153,10 @@ static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI; //---------------------------------------------------------------------- -static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); -static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); -static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID); -static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); -static NS_DEFINE_IID(kIDOMNodeListIID, NS_IDOMNODELIST_IID); -static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); -static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID); -static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); -static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID); -static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID); -static NS_DEFINE_IID(kIRDFCompositeDataSourceIID, NS_IRDFCOMPOSITEDATASOURCE_IID); -static NS_DEFINE_IID(kIRDFDocumentIID, NS_IRDFDOCUMENT_IID); -static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID); -static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIXMLContentIID, NS_IXMLCONTENT_IID); - static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID); -static NS_DEFINE_IID(kIDOMEventTargetIID, NS_IDOMEVENTTARGET_IID); static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); -static NS_DEFINE_IID(kIXULPopupListenerIID, NS_IXULPOPUPLISTENER_IID); static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID); static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); @@ -506,7 +486,6 @@ nsXULElement::nsXULElement() : mPrototype(nsnull), mDocument(nsnull), mParent(nsnull), - mScriptObject(nsnull), #ifdef DEBUG mIsScriptObjectRooted(PR_FALSE), #endif @@ -527,7 +506,7 @@ nsXULElement::Init() nsresult rv; rv = nsServiceManager::GetService(kRDFServiceCID, - kIRDFServiceIID, + NS_GET_IID(nsIRDFService), (nsISupports**) &gRDFService); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); @@ -536,7 +515,7 @@ nsXULElement::Init() rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID, nsnull, - kINameSpaceManagerIID, + NS_GET_IID(nsINameSpaceManager), (void**) &gNameSpaceManager); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create namespace manager"); @@ -694,6 +673,21 @@ nsXULElement::Create(nsINodeInfo *aNodeInfo, nsIContent** aResult) //---------------------------------------------------------------------- // nsISupports interface +// XPConnect interface list for nsXULElement +NS_CLASSINFO_MAP_BEGIN(XULElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMXULElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) +NS_CLASSINFO_MAP_END + + +// XPConnect interface list for nsXULElement +NS_CLASSINFO_MAP_BEGIN(XULTreeElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMXULElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMXULTreeElement) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) +NS_CLASSINFO_MAP_END + + NS_IMPL_ADDREF(nsXULElement); NS_IMPL_RELEASE(nsXULElement); @@ -707,8 +701,8 @@ nsXULElement::QueryInterface(REFNSIID iid, void** result) nsresult rv; if (iid.Equals(NS_GET_IID(nsIStyledContent)) || - iid.Equals(kIContentIID) || - iid.Equals(kISupportsIID)) { + iid.Equals(NS_GET_IID(nsIContent)) || + iid.Equals(NS_GET_IID(nsISupports))) { *result = NS_STATIC_CAST(nsIStyledContent*, this); } else if (iid.Equals(NS_GET_IID(nsIXMLContent))) { @@ -718,25 +712,19 @@ nsXULElement::QueryInterface(REFNSIID iid, void** result) *result = NS_STATIC_CAST(nsIXULContent*, this); } else if (iid.Equals(NS_GET_IID(nsIDOMXULElement)) || - iid.Equals(kIDOMElementIID) || - iid.Equals(kIDOMNodeIID)) { + iid.Equals(NS_GET_IID(nsIDOMElement)) || + iid.Equals(NS_GET_IID(nsIDOMNode))) { *result = NS_STATIC_CAST(nsIDOMXULElement*, this); } - else if (iid.Equals(kIScriptObjectOwnerIID)) { - *result = NS_STATIC_CAST(nsIScriptObjectOwner*, this); - } else if (iid.Equals(NS_GET_IID(nsIScriptEventHandlerOwner))) { *result = NS_STATIC_CAST(nsIScriptEventHandlerOwner*, this); } - else if (iid.Equals(kIDOMEventReceiverIID)) { + else if (iid.Equals(NS_GET_IID(nsIDOMEventReceiver))) { *result = NS_STATIC_CAST(nsIDOMEventReceiver*, this); } - else if (iid.Equals(kIDOMEventTargetIID)) { + else if (iid.Equals(NS_GET_IID(nsIDOMEventTarget))) { *result = NS_STATIC_CAST(nsIDOMEventTarget*, this); } - else if (iid.Equals(kIJSScriptObjectIID)) { - *result = NS_STATIC_CAST(nsIJSScriptObject*, this); - } else if (iid.Equals(NS_GET_IID(nsIChromeEventHandler))) { *result = NS_STATIC_CAST(nsIChromeEventHandler*, this); } @@ -762,13 +750,38 @@ nsXULElement::QueryInterface(REFNSIID iid, void** result) else return NS_NOINTERFACE; } - else if (mScriptObject && mDocument) { + else if (iid.Equals(NS_GET_IID(nsIDOM3Node))) { + *result = new nsNode3Tearoff(this); + NS_ENSURE_TRUE(*result, NS_ERROR_OUT_OF_MEMORY); + } + else if (iid.Equals(NS_GET_IID(nsIClassInfo))) { + nsISupports *inst = nsnull; + + nsCOMPtr tag; + PRInt32 dummy; + NS_WITH_SERVICE(nsIXBLService, xblService, "@mozilla.org/xbl;1", &rv); + xblService->ResolveTag(NS_STATIC_CAST(nsIStyledContent*, this), &dummy, getter_AddRefs(tag)); + if (tag.get() == nsXULAtoms::tree) { + inst = nsContentUtils::GetClassInfoInstance(eDOMClassInfo_XULTreeElement_id, + GetXULTreeElementIIDs, + "XULTreeElement"); + } else { + inst = nsContentUtils::GetClassInfoInstance(eDOMClassInfo_XULElement_id, + GetXULElementIIDs, + "XULElement"); + } + + NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY); + + *result = inst; + + return NS_OK; + } + else if (mDocument) { nsCOMPtr manager; mDocument->GetBindingManager(getter_AddRefs(manager)); - return manager->GetBindingImplementation(NS_STATIC_CAST(nsIStyledContent*, this), mScriptObject, - iid, result); - } - else { + return manager->GetBindingImplementation(this, iid, result); + } else { *result = nsnull; return NS_NOINTERFACE; } @@ -814,19 +827,19 @@ NS_IMETHODIMP nsXULElement::GetParentNode(nsIDOMNode** aParentNode) { if (mParent) { - return mParent->QueryInterface(kIDOMNodeIID, (void**) aParentNode); + return mParent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) aParentNode); } else if (mDocument) { // XXX This is a mess because of our fun multiple inheritance heirarchy nsCOMPtr root = dont_AddRef( mDocument->GetRootContent() ); nsCOMPtr thisIContent; - QueryInterface(kIContentIID, getter_AddRefs(thisIContent)); + QueryInterface(NS_GET_IID(nsIContent), getter_AddRefs(thisIContent)); if (root == thisIContent) { // If we don't have a parent, and we're the root content // of the document, DOM says that our parent is the // document. - return mDocument->QueryInterface(kIDOMNodeIID, (void**)aParentNode); + return mDocument->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aParentNode); } } @@ -859,7 +872,7 @@ nsXULElement::GetChildNodes(nsIDOMNodeList** aChildNodes) break; nsCOMPtr domNode; - rv = child->QueryInterface(kIDOMNodeIID, (void**) getter_AddRefs(domNode)); + rv = child->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) getter_AddRefs(domNode)); if (NS_FAILED(rv)) { NS_WARNING("child content doesn't support nsIDOMNode"); continue; @@ -885,7 +898,7 @@ nsXULElement::GetFirstChild(nsIDOMNode** aFirstChild) rv = ChildAt(0, *getter_AddRefs(child)); if (NS_SUCCEEDED(rv) && (child != nsnull)) { - rv = child->QueryInterface(kIDOMNodeIID, (void**) aFirstChild); + rv = child->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) aFirstChild); NS_ASSERTION(NS_SUCCEEDED(rv), "not a DOM node"); return rv; } @@ -910,7 +923,7 @@ nsXULElement::GetLastChild(nsIDOMNode** aLastChild) NS_ASSERTION(child != nsnull, "no child"); if (child) { - rv = child->QueryInterface(kIDOMNodeIID, (void**) aLastChild); + rv = child->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) aLastChild); NS_ASSERTION(NS_SUCCEEDED(rv), "not a DOM node"); return rv; } @@ -931,7 +944,7 @@ nsXULElement::GetPreviousSibling(nsIDOMNode** aPreviousSibling) nsCOMPtr prev; mParent->ChildAt(--pos, *getter_AddRefs(prev)); if (prev) { - nsresult rv = prev->QueryInterface(kIDOMNodeIID, (void**) aPreviousSibling); + nsresult rv = prev->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) aPreviousSibling); NS_ASSERTION(NS_SUCCEEDED(rv), "not a DOM node"); return rv; } @@ -955,7 +968,7 @@ nsXULElement::GetNextSibling(nsIDOMNode** aNextSibling) nsCOMPtr next; mParent->ChildAt(++pos, *getter_AddRefs(next)); if (next) { - nsresult res = next->QueryInterface(kIDOMNodeIID, (void**) aNextSibling); + nsresult res = next->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) aNextSibling); NS_ASSERTION(NS_OK == res, "not a DOM Node"); return res; } @@ -1024,7 +1037,7 @@ nsXULElement::SetPrefix(const nsAReadableString& aPrefix) nsINodeInfo *newNodeInfo = nsnull; nsCOMPtr prefix; - if (aPrefix.Length()) { + if (aPrefix.Length() && !DOMStringIsNull(aPrefix)) { prefix = dont_AddRef(NS_NewAtom(aPrefix)); NS_ENSURE_TRUE(prefix, NS_ERROR_OUT_OF_MEMORY); } @@ -1809,7 +1822,6 @@ nsXULElement::GetBaseURI(nsAWritableString &aURI) } #endif - //---------------------------------------------------------------------- // nsIXULContent interface @@ -1843,7 +1855,8 @@ nsXULElement::GetLazyState(PRInt32 aFlag, PRBool& aResult) NS_IMETHODIMP -nsXULElement::AddScriptEventListener(nsIAtom* aName, const nsAReadableString& aValue) +nsXULElement::AddScriptEventListener(nsIAtom* aName, + const nsAReadableString& aValue) { if (! mDocument) return NS_OK; // XXX @@ -1873,9 +1886,7 @@ nsXULElement::AddScriptEventListener(nsIAtom* aName, const nsAReadableString& aV rv = receiver->GetListenerManager(getter_AddRefs(manager)); if (NS_FAILED(rv)) return rv; - nsCOMPtr owner = do_QueryInterface(global); - - rv = manager->AddScriptEventListener(context, owner, aName, + rv = manager->AddScriptEventListener(context, global, aName, aValue, PR_FALSE); } else { @@ -1883,8 +1894,10 @@ nsXULElement::AddScriptEventListener(nsIAtom* aName, const nsAReadableString& aV rv = GetListenerManager(getter_AddRefs(manager)); if (NS_FAILED(rv)) return rv; - rv = manager->AddScriptEventListener(context, this, aName, - aValue, PR_TRUE); + rv = manager->AddScriptEventListener(context, + NS_STATIC_CAST(nsIContent *, + this), + aName, aValue, PR_TRUE); } return rv; @@ -1999,7 +2012,7 @@ nsXULElement::GetListenerManager(nsIEventListenerManager** aResult) rv = nsComponentManager::CreateInstance(kEventListenerManagerCID, nsnull, - kIEventListenerManagerIID, + NS_GET_IID(nsIEventListenerManager), getter_AddRefs(mListenerManager)); if (NS_FAILED(rv)) return rv; mListenerManager->SetListenerTarget(NS_STATIC_CAST(nsIStyledContent*, this)); @@ -2015,7 +2028,7 @@ nsXULElement::GetNewListenerManager(nsIEventListenerManager **aResult) { return nsComponentManager::CreateInstance(kEventListenerManagerCID, nsnull, - kIEventListenerManagerIID, + NS_GET_IID(nsIEventListenerManager), (void**) aResult); } @@ -2027,12 +2040,14 @@ nsXULElement::HandleEvent(nsIDOMEvent *aEvent) //---------------------------------------------------------------------- -// nsIScriptObjectOwner interface +#if 0 +// XXX move this over to the scriptable helper... static PRBool CanHaveBinding(nsIAtom* aTag) { - // The layout atoms (the boxes, stacks, and springs) are dodgy here. Technically - // they could have bindings, but this will only apply for display: none elts - // anyway, so we're getting into a real edge case. + // The layout atoms (the boxes, stacks, and springs) are dodgy here. + // Technically they could have bindings, but this will only apply + // for display: none elts anyway, so we're getting into a real edge + // case. return (aTag != nsXULAtoms::broadcaster) && (aTag != nsXULAtoms::commandset) && (aTag != nsXULAtoms::commands) && (aTag != nsXULAtoms::command) && (aTag != nsXULAtoms::popupset) && (aTag != nsXULAtoms::broadcasterset) && (aTag != nsXULAtoms::templateAtom) && @@ -2185,6 +2200,7 @@ nsXULElement::SetScriptObject(void *aScriptObject) mScriptObject = aScriptObject; return NS_OK; } +#endif //---------------------------------------------------------------------- @@ -2253,12 +2269,10 @@ nsXULElement::CompileEventHandler(nsIScriptContext* aContext, if (NS_FAILED(rv)) return rv; // Use the prototype script's special scope object - nsCOMPtr owner = do_QueryInterface(global); - if (! owner) + + scopeObject = global->GetGlobalJSObject(); + if (!scopeObject) return NS_ERROR_UNEXPECTED; - - rv = owner->GetScriptObject(context, (void**) &scopeObject); - if (NS_FAILED(rv)) return rv; } else { // We don't have a prototype; do a one-off compile. @@ -2309,64 +2323,6 @@ nsXULElement::CompileEventHandler(nsIScriptContext* aContext, } -//---------------------------------------------------------------------- -// nsIJSScriptObject interface - -PRBool -nsXULElement::AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsXULElement::DeleteProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsXULElement::GetProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsXULElement::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - // XXXwaterson do the event handlers here! - return PR_TRUE; -} - -PRBool -nsXULElement::EnumerateProperty(JSContext *aContext, JSObject *aObj) -{ - return PR_TRUE; -} - - -PRBool -nsXULElement::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty) -{ - *aDidDefineProperty = PR_FALSE; - - return PR_TRUE; -} - - -PRBool -nsXULElement::Convert(JSContext *aContext, JSObject *aObj, jsval aID) -{ - return PR_TRUE; -} - - -void -nsXULElement::Finalize(JSContext *aContext, JSObject *aObj) -{ -} - - //---------------------------------------------------------------------- // // nsIContent interface @@ -2388,8 +2344,7 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileE if (aDocument != mDocument) { nsCOMPtr rdfDoc; if (mDocument) { - // Release the named reference to the script object so it can - // be garbage collected. + /* if (mScriptObject) { nsCOMPtr global; mDocument->GetScriptGlobalObject(getter_AddRefs(global)); @@ -2404,6 +2359,9 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileE } } } + */ + + // XXX: Unroot!!! } @@ -2445,6 +2403,7 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileE if (mDocument) { // Add a named reference to the script object. + /* if (mScriptObject) { nsCOMPtr global; mDocument->GetScriptGlobalObject(getter_AddRefs(global)); @@ -2460,6 +2419,9 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileE } } } + */ + + // XXX: Root!!! // When we SetDocument(), we're either adding an element // into the document that wasn't there before, or we're @@ -3083,8 +3045,10 @@ nsXULElement::SetAttribute(nsINodeInfo* aNodeInfo, mutation.mPrevAttrValue = getter_AddRefs(NS_NewAtom(oldValue)); if (!aValue.IsEmpty()) mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(aValue)); - mutation.mAttrChange = modification ? nsIDOMMutationEvent::MODIFICATION : - nsIDOMMutationEvent::ADDITION; + if (modification) + mutation.mAttrChange = nsIDOMMutationEvent::MODIFICATION; + else + mutation.mAttrChange = nsIDOMMutationEvent::ADDITION; nsEventStatus status = nsEventStatus_eIgnore; HandleDOMEvent(nsnull, &mutation, nsnull, NS_EVENT_FLAG_INIT, &status); } @@ -3720,7 +3684,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, // hasn't been malloc'd. Force a copy of the data here so the // DOM Event is still valid. nsIPrivateDOMEvent *privateEvent; - if (NS_OK == (*aDOMEvent)->QueryInterface(kIPrivateDOMEventIID, (void**)&privateEvent)) { + if (NS_OK == (*aDOMEvent)->QueryInterface(NS_GET_IID(nsIPrivateDOMEvent), (void**)&privateEvent)) { privateEvent->DuplicatePrivateData(); NS_RELEASE(privateEvent); } @@ -4566,6 +4530,12 @@ nsXULElement::SetBindingParent(nsIContent* aParent) return NS_OK; } +NS_IMETHODIMP_(PRBool) +nsXULElement::IsContentOfType(PRUint32 aFlags) +{ + return !(aFlags & ~eELEMENT); +} + void nsXULElement::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize) { // XXX - implement this if you want the sizes of XUL style rules @@ -4583,7 +4553,7 @@ nsXULElement::AddPopupListener(nsIAtom* aName) nsCOMPtr popupListener; rv = nsComponentManager::CreateInstance(kXULPopupListenerCID, nsnull, - kIXULPopupListenerIID, + NS_GET_IID(nsIXULPopupListener), getter_AddRefs(popupListener)); NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to create an instance of the popup listener object."); if (NS_FAILED(rv)) return rv; @@ -4773,7 +4743,7 @@ nsXULPrototypeScript::nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion : nsXULPrototypeNode(eType_Script, aLineNo), mSrcLoading(PR_FALSE), mSrcLoadWaiters(nsnull), - mScriptObject(nsnull), + mJSObject(nsnull), mLangVersion(aVersion) { MOZ_COUNT_CTOR(nsXULPrototypeScript); @@ -4782,8 +4752,8 @@ nsXULPrototypeScript::nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion nsXULPrototypeScript::~nsXULPrototypeScript() { - if (mScriptObject) - RemoveJSGCRoot(&mScriptObject); + if (mJSObject) + RemoveJSGCRoot(&mJSObject); MOZ_COUNT_DTOR(nsXULPrototypeScript); } @@ -4830,19 +4800,17 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText, if (! context) return NS_ERROR_UNEXPECTED; - nsCOMPtr owner = do_QueryInterface(global); - if (! owner) + scopeObject = global->GetGlobalJSObject(); + if (!scopeObject) return NS_ERROR_UNEXPECTED; - - rv = owner->GetScriptObject(context, (void**) &scopeObject); - if (NS_FAILED(rv)) return rv; } // Use the enclosing document's principal // XXX is this right? or should we use the protodoc's? nsCOMPtr principal; rv = aDocument->GetPrincipal(getter_AddRefs(principal)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; nsXPIDLCString urlspec; aURI->GetSpec(getter_Copies(urlspec)); @@ -4855,19 +4823,22 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText, urlspec, PRUint32(aLineNo), mLangVersion, - (void**) &mScriptObject); + (void**)&mJSObject); if (NS_FAILED(rv)) return rv; - if (mScriptObject) { + if (mJSObject) { // Root the compiled prototype script object. - JSContext* cx = NS_REINTERPRET_CAST(JSContext*, context->GetNativeContext()); + JSContext* cx = NS_REINTERPRET_CAST(JSContext*, + context->GetNativeContext()); if (!cx) return NS_ERROR_UNEXPECTED; - rv = AddJSGCRoot(cx, &mScriptObject, "nsXULPrototypeScript::mScriptObject"); - if (NS_FAILED(rv)) return rv; + rv = AddJSGCRoot(cx, &mJSObject, "nsXULPrototypeScript::mJSObject"); + if (NS_FAILED(rv)) + return rv; } return NS_OK; + } diff --git a/content/xul/content/src/nsXULElement.h b/content/xul/content/src/nsXULElement.h index 392ef842318..4a4de8337f8 100644 --- a/content/xul/content/src/nsXULElement.h +++ b/content/xul/content/src/nsXULElement.h @@ -46,7 +46,6 @@ #include "nsIDOMXULElement.h" #include "nsIDOMXULTreeElement.h" #include "nsIEventListenerManager.h" -#include "nsIJSScriptObject.h" #include "nsINameSpace.h" #include "nsINameSpaceManager.h" #include "nsIRDFCompositeDataSource.h" @@ -246,7 +245,7 @@ public: nsCOMPtr mSrcURI; PRBool mSrcLoading; nsXULDocument* mSrcLoadWaiters; // [OWNER] but not COMPtr - JSObject* mScriptObject; + JSObject* mJSObject; const char* mLangVersion; }; @@ -315,7 +314,6 @@ class nsXULElement : public nsIXULContent, public nsIDOMXULElement, public nsIDOMEventReceiver, public nsIScriptEventHandlerOwner, - public nsIJSScriptObject, public nsIChromeEventHandler { public: @@ -330,7 +328,8 @@ protected: public: static nsresult - Create(nsXULPrototypeElement* aPrototype, nsIDocument* aDocument, PRBool aIsScriptable, nsIContent** aResult); + Create(nsXULPrototypeElement* aPrototype, nsIDocument* aDocument, + PRBool aIsScriptable, nsIContent** aResult); static nsresult Create(nsINodeInfo* aNodeInfo, nsIContent** aResult); @@ -386,7 +385,8 @@ public: NS_IMETHOD GetBindingParent(nsIContent** aContent); NS_IMETHOD SetBindingParent(nsIContent* aParent); - + NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags); + // nsIXMLContent NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace); NS_IMETHOD GetContainingNameSpace(nsINameSpace*& aNameSpace) const; @@ -413,13 +413,13 @@ public: NS_IMETHOD ForceElementToOwnResource(PRBool aForce); // nsIDOMNode (from nsIDOMElement) - NS_DECL_IDOMNODE + NS_DECL_NSIDOMNODE // nsIDOMElement - NS_DECL_IDOMELEMENT + NS_DECL_NSIDOMELEMENT // nsIDOMXULElement - NS_DECL_IDOMXULELEMENT + NS_DECL_NSIDOMXULELEMENT // nsIDOMEventTarget interface (from nsIDOMEventReceiver) NS_IMETHOD AddEventListener(const nsAReadableString& aType, nsIDOMEventListener* aListener, @@ -435,10 +435,6 @@ public: NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult); NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent); - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - // nsIScriptEventHandlerOwner NS_IMETHOD CompileEventHandler(nsIScriptContext* aContext, void* aTarget, @@ -447,22 +443,7 @@ public: void** aHandler); NS_IMETHOD GetCompiledEventHandler(nsIAtom *aName, void** aHandler); - // nsIJSScriptObject - virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool DeleteProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj); - virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty); - virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID); - virtual void Finalize(JSContext *aContext, JSObject *aObj); - - virtual void SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize); + virtual void SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize); // nsIChromeEventHandler NS_DECL_NSICHROMEEVENTHANDLER @@ -508,7 +489,6 @@ protected: nsIContent* mParent; // [WEAK] nsVoidArray mChildren; // [OWNER] nsCOMPtr mListenerManager; // [OWNER] - void* mScriptObject; // [OWNER] #ifdef DEBUG PRBool mIsScriptObjectRooted; #endif diff --git a/content/xul/content/src/nsXULPopupListener.cpp b/content/xul/content/src/nsXULPopupListener.cpp index 530bb1c3587..51b5f6c9188 100644 --- a/content/xul/content/src/nsXULPopupListener.cpp +++ b/content/xul/content/src/nsXULPopupListener.cpp @@ -104,27 +104,27 @@ public: NS_IMETHOD Init(nsIDOMElement* aElement, const XULPopupType& popupType); // nsIDOMMouseListener - virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent) ; + NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent); + NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent); + NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }; + NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }; + NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; }; + NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent) ; // nsIDOMMouseMotionListener - virtual nsresult MouseMove(nsIDOMEvent* aMouseEvent); - virtual nsresult DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; }; + NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent); + NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; }; // nsIDOMContextMenuListener - virtual nsresult ContextMenu(nsIDOMEvent* aContextMenuEvent); + NS_IMETHOD ContextMenu(nsIDOMEvent* aContextMenuEvent); // nsIDOMKeyListener - virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent) ; - virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent) ; - virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent) ; + NS_IMETHOD KeyDown(nsIDOMEvent* aKeyEvent) ; + NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent) ; + NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent) ; // nsIDOMEventListener - virtual nsresult HandleEvent(nsIDOMEvent* anEvent) { return NS_OK; }; + NS_IMETHOD HandleEvent(nsIDOMEvent* anEvent) { return NS_OK; }; protected: diff --git a/content/xul/content/src/nsXULTreeElement.h b/content/xul/content/src/nsXULTreeElement.h index 1f64057f126..a3f8f1ed018 100644 --- a/content/xul/content/src/nsXULTreeElement.h +++ b/content/xul/content/src/nsXULTreeElement.h @@ -48,16 +48,16 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode interface - NS_FORWARD_IDOMNODE(mOuter->); + NS_FORWARD_NSIDOMNODE(mOuter->); // nsIDOMElement interface - NS_FORWARD_IDOMELEMENT(mOuter->); + NS_FORWARD_NSIDOMELEMENT(mOuter->); // nsIDOMXULElement interface - NS_FORWARD_IDOMXULELEMENT(mOuter->); + NS_FORWARD_NSIDOMXULELEMENT(mOuter->); // nsIDOMXULTreeElement interface - NS_DECL_IDOMXULTREEELEMENT + NS_DECL_NSIDOMXULTREEELEMENT // nsIXULTreeContent interface NS_IMETHOD FireOnSelectHandler(); diff --git a/content/xul/document/public/MANIFEST_IDL b/content/xul/document/public/MANIFEST_IDL index bcdbd5dcdbf..009388fa38f 100644 --- a/content/xul/document/public/MANIFEST_IDL +++ b/content/xul/document/public/MANIFEST_IDL @@ -1,4 +1,3 @@ nsIController.idl nsIControllerCommand.idl nsIControllers.idl -xulstubs.idl diff --git a/content/xul/document/public/Makefile.in b/content/xul/document/public/Makefile.in index 344c2a3f075..cecb8af1c66 100644 --- a/content/xul/document/public/Makefile.in +++ b/content/xul/document/public/Makefile.in @@ -32,7 +32,6 @@ XPIDLSRCS = \ nsIController.idl \ nsIControllers.idl \ nsIControllerCommand.idl \ - xulstubs.idl \ $(NULL) EXPORTS = \ diff --git a/content/xul/document/public/makefile.win b/content/xul/document/public/makefile.win index 6669cc42e24..68db7ae6a9a 100644 --- a/content/xul/document/public/makefile.win +++ b/content/xul/document/public/makefile.win @@ -28,7 +28,6 @@ XPIDLSRCS = \ .\nsIController.idl \ .\nsIControllers.idl \ .\nsIControllerCommand.idl \ - .\xulstubs.idl \ $(NULL) EXPORTS = \ diff --git a/content/xul/document/public/nsIControllers.idl b/content/xul/document/public/nsIControllers.idl index 3d369190332..b7ee067ba74 100644 --- a/content/xul/document/public/nsIControllers.idl +++ b/content/xul/document/public/nsIControllers.idl @@ -20,13 +20,12 @@ * Contributor(s): */ -#include "nsISecurityCheckedComponent.idl" #include "nsIController.idl" interface nsIDOMXULCommandDispatcher; [scriptable, uuid(A5ED3A01-7CC7-11d3-BF87-00105A1B0627)] -interface nsIControllers : nsISecurityCheckedComponent +interface nsIControllers : nsISupports { attribute nsIDOMXULCommandDispatcher commandDispatcher; diff --git a/content/xul/document/public/xulstubs.idl b/content/xul/document/public/xulstubs.idl deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/content/xul/document/src/nsXULCommandDispatcher.cpp b/content/xul/document/src/nsXULCommandDispatcher.cpp index c2ab28d73a4..0505dda3d75 100644 --- a/content/xul/document/src/nsXULCommandDispatcher.cpp +++ b/content/xul/document/src/nsXULCommandDispatcher.cpp @@ -49,6 +49,7 @@ #include "nsXULCommandDispatcher.h" #include "prlog.h" #include "nsIDOMEventTarget.h" +#include "nsContentUtils.h" #ifdef PR_LOGGING static PRLogModuleInfo* gLog; @@ -57,7 +58,7 @@ static PRLogModuleInfo* gLog; //////////////////////////////////////////////////////////////////////// nsXULCommandDispatcher::nsXULCommandDispatcher(nsIDocument* aDocument) - : mScriptObject(nsnull), mDocument(aDocument), mFocusController(nsnull), mUpdaters(nsnull) + : mDocument(aDocument), mFocusController(nsnull), mUpdaters(nsnull) { NS_INIT_REFCNT(); @@ -76,34 +77,24 @@ nsXULCommandDispatcher::~nsXULCommandDispatcher() } } +// XPConnect interface list for nsXULCommandDispatcher +NS_CLASSINFO_MAP_BEGIN(XULCommandDispatcher) + NS_CLASSINFO_MAP_ENTRY(nsIDOMXULCommandDispatcher) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsXULCommandDispatcher +NS_INTERFACE_MAP_BEGIN(nsXULCommandDispatcher) + NS_INTERFACE_MAP_ENTRY(nsIDOMXULCommandDispatcher) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMXULCommandDispatcher) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULCommandDispatcher) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsXULCommandDispatcher) NS_IMPL_RELEASE(nsXULCommandDispatcher) -NS_IMETHODIMP -nsXULCommandDispatcher::QueryInterface(REFNSIID iid, void** result) -{ - if (! result) - return NS_ERROR_NULL_POINTER; - - *result = nsnull; - if (iid.Equals(NS_GET_IID(nsISupports)) || - iid.Equals(NS_GET_IID(nsIDOMXULCommandDispatcher))) { - *result = NS_STATIC_CAST(nsIDOMXULCommandDispatcher*, this); - } - else if (iid.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - *result = NS_STATIC_CAST(nsIScriptObjectOwner*, this); - } - else if (iid.Equals(NS_GET_IID(nsISupportsWeakReference))) { - *result = NS_STATIC_CAST(nsISupportsWeakReference*, this); - } - else { - return NS_NOINTERFACE; - } - - NS_ADDREF_THIS(); - return NS_OK; -} - NS_IMETHODIMP nsXULCommandDispatcher::Create(nsIDocument* aDoc, nsIDOMXULCommandDispatcher** aResult) @@ -146,10 +137,15 @@ nsXULCommandDispatcher::GetFocusedElement(nsIDOMElement** aElement) } NS_IMETHODIMP -nsXULCommandDispatcher::GetFocusedWindow(nsIDOMWindowInternal** aWindow) +nsXULCommandDispatcher::GetFocusedWindow(nsIDOMWindow** aWindow) { EnsureFocusController(); - return mFocusController->GetFocusedWindow(aWindow); + + nsCOMPtr window; + nsresult rv = mFocusController->GetFocusedWindow(getter_AddRefs(window)); + NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && window, rv); + + return window->QueryInterface(NS_GET_IID(nsIDOMWindow), (void **)aWindow); } NS_IMETHODIMP @@ -160,11 +156,15 @@ nsXULCommandDispatcher::SetFocusedElement(nsIDOMElement* aElement) } NS_IMETHODIMP -nsXULCommandDispatcher::SetFocusedWindow(nsIDOMWindowInternal* aWindow) +nsXULCommandDispatcher::SetFocusedWindow(nsIDOMWindow* aWindow) { EnsureFocusController(); - if (mFocusController) - return mFocusController->SetFocusedWindow(aWindow); + if (mFocusController) { + nsCOMPtr window(do_QueryInterface(aWindow)); + + return mFocusController->SetFocusedWindow(window); + } + return NS_ERROR_FAILURE; } @@ -371,33 +371,6 @@ nsXULCommandDispatcher::UpdateCommands(const nsAReadableString& aEventName) return NS_OK; } - -//////////////////////////////////////////////////////////////////////// -// nsIScriptObjectOwner interface -NS_IMETHODIMP -nsXULCommandDispatcher::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - - if (nsnull == mScriptObject) { - res = NS_NewScriptXULCommandDispatcher(aContext, (nsISupports *)(nsIDOMXULCommandDispatcher*)this, global, (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - NS_RELEASE(global); - return res; -} - - -NS_IMETHODIMP -nsXULCommandDispatcher::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - PRBool nsXULCommandDispatcher::Matches(const nsString& aList, const nsAReadableString& aElement) diff --git a/content/xul/document/src/nsXULCommandDispatcher.h b/content/xul/document/src/nsXULCommandDispatcher.h index a53338240da..b8f01e96396 100644 --- a/content/xul/document/src/nsXULCommandDispatcher.h +++ b/content/xul/document/src/nsXULCommandDispatcher.h @@ -35,7 +35,6 @@ #include "nsCOMPtr.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIDOMFocusListener.h" -#include "nsIScriptObjectOwner.h" #include "nsWeakReference.h" #include "nsIDOMNode.h" #include "nsString.h" @@ -45,7 +44,6 @@ class nsPIDOMWindow; class nsIFocusController; class nsXULCommandDispatcher : public nsIDOMXULCommandDispatcher, - public nsIScriptObjectOwner, public nsSupportsWeakReference { protected: @@ -63,18 +61,12 @@ public: NS_DECL_ISUPPORTS // nsIDOMXULCommandDispatcher interface - NS_DECL_IDOMXULCOMMANDDISPATCHER - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); + NS_DECL_NSIDOMXULCOMMANDDISPATCHER protected: nsIFocusController* mFocusController; // Weak. We always die before the focus controller does. nsIDocument* mDocument; // Weak. - void* mScriptObject; - class Updater { public: Updater(nsIDOMElement* aElement, diff --git a/content/xul/document/src/nsXULControllers.cpp b/content/xul/document/src/nsXULControllers.cpp index 5b8aaa7381c..b6e8b452d96 100644 --- a/content/xul/document/src/nsXULControllers.cpp +++ b/content/xul/document/src/nsXULControllers.cpp @@ -37,6 +37,8 @@ #include "nsIDOMElement.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsXULControllers.h" +#include "nsString.h" +#include "nsContentUtils.h" //---------------------------------------------------------------------- @@ -84,7 +86,22 @@ NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult) return rv; } -NS_IMPL_ISUPPORTS2(nsXULControllers, nsIControllers, nsISecurityCheckedComponent); +// XPConnect interface list for nsXULControllers +NS_CLASSINFO_MAP_BEGIN(XULControllers) + NS_CLASSINFO_MAP_ENTRY(nsIControllers) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsXULControllers +NS_INTERFACE_MAP_BEGIN(nsXULControllers) + NS_INTERFACE_MAP_ENTRY(nsIControllers) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULControllers) +NS_INTERFACE_MAP_END + + +NS_IMPL_ADDREF(nsXULControllers) +NS_IMPL_RELEASE(nsXULControllers) NS_IMETHODIMP @@ -259,36 +276,3 @@ nsXULControllers::GetControllerCount(PRUint32 *_retval) *_retval = mControllers.Count(); return NS_OK; } - - -/* string canCreateWrapper (in nsIIDPtr iid); */ -NS_IMETHODIMP nsXULControllers::CanCreateWrapper(const nsIID * iid, char **_retval) -{ - nsCAutoString str("AllAccess"); - *_retval = str.ToNewCString(); - return NS_OK; -} - -/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */ -NS_IMETHODIMP nsXULControllers::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval) -{ - nsCAutoString str("AllAccess"); - *_retval = str.ToNewCString(); - return NS_OK; -} - -/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */ -NS_IMETHODIMP nsXULControllers::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval) -{ - nsCAutoString str("AllAccess"); - *_retval = str.ToNewCString(); - return NS_OK; -} - -/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */ -NS_IMETHODIMP nsXULControllers::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval) -{ - nsCAutoString str("AllAccess"); - *_retval = str.ToNewCString(); - return NS_OK; -} diff --git a/content/xul/document/src/nsXULControllers.h b/content/xul/document/src/nsXULControllers.h index 736881637cf..8b616634732 100644 --- a/content/xul/document/src/nsXULControllers.h +++ b/content/xul/document/src/nsXULControllers.h @@ -76,7 +76,6 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSICONTROLLERS - NS_DECL_NSISECURITYCHECKEDCOMPONENT protected: nsXULControllers(); diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index cee6ba7ef81..ccec52edf20 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -136,6 +136,7 @@ #include "nsIMIMEService.h" #include "nsNetUtil.h" #include "nsMimeTypes.h" +#include "nsContentUtils.h" //---------------------------------------------------------------------- @@ -400,7 +401,6 @@ PlaceHolderRequest::~PlaceHolderRequest() nsXULDocument::nsXULDocument(void) : mParentDocument(nsnull), mScriptGlobalObject(nsnull), - mScriptObject(nsnull), mNextSrcLoadWaiter(nsnull), mDisplaySelection(PR_FALSE), mIsPopup(PR_FALSE), @@ -501,6 +501,10 @@ nsXULDocument::~nsXULDocument() gXULCache = nsnull; } } + + if (mNodeInfoManager) { + mNodeInfoManager->DropDocumentReference(); + } } @@ -533,75 +537,46 @@ NS_NewXULDocument(nsIXULDocument** result) // nsISupports interface // -NS_IMETHODIMP -nsXULDocument::QueryInterface(REFNSIID iid, void** result) -{ - if (! result) - return NS_ERROR_NULL_POINTER; +NS_IMPL_ADDREF(nsXULDocument) +NS_IMPL_RELEASE(nsXULDocument) - *result = nsnull; - if (iid.Equals(NS_GET_IID(nsIDocument)) || - iid.Equals(NS_GET_IID(nsISupports))) { - *result = NS_STATIC_CAST(nsIDocument*, this); - } - else if (iid.Equals(NS_GET_IID(nsIXULDocument)) || - iid.Equals(NS_GET_IID(nsIXMLDocument))) { - *result = NS_STATIC_CAST(nsIXULDocument*, this); - } - else if (iid.Equals(NS_GET_IID(nsIDOMXULDocument)) || - iid.Equals(NS_GET_IID(nsIDOMDocument)) || - iid.Equals(NS_GET_IID(nsIDOMNode))) { - *result = NS_STATIC_CAST(nsIDOMXULDocument*, this); - } - else if (iid.Equals(NS_GET_IID(nsIDOMNSDocument))) { - *result = NS_STATIC_CAST(nsIDOMNSDocument*, this); - } - else if (iid.Equals(NS_GET_IID(nsIDOMDocumentEvent))) { - *result = NS_STATIC_CAST(nsIDOMDocumentEvent*, this); - } - else if (iid.Equals(NS_GET_IID(nsIDOMDocumentView))) { - *result = NS_STATIC_CAST(nsIDOMDocumentView*, this); - } - else if (iid.Equals(NS_GET_IID(nsIDOMDocumentXBL))) { - *result = NS_STATIC_CAST(nsIDOMDocumentXBL*, this); - } - else if (iid.Equals(NS_GET_IID(nsIJSScriptObject))) { - *result = NS_STATIC_CAST(nsIJSScriptObject*, this); - } - else if (iid.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - *result = NS_STATIC_CAST(nsIScriptObjectOwner*, this); - } - else if (iid.Equals(NS_GET_IID(nsIHTMLContentContainer))) { - *result = NS_STATIC_CAST(nsIHTMLContentContainer*, this); - } - else if (iid.Equals(NS_GET_IID(nsIDOMEventReceiver))) { - *result = NS_STATIC_CAST(nsIDOMEventReceiver*, this); - } - else if (iid.Equals(NS_GET_IID(nsIDOMEventTarget))) { - *result = NS_STATIC_CAST(nsIDOMEventTarget*, this); - } - else if (iid.Equals(NS_GET_IID(nsIDOMEventCapturer))) { - *result = NS_STATIC_CAST(nsIDOMEventCapturer*, this); - } - else if (iid.Equals(NS_GET_IID(nsISupportsWeakReference))) { - *result = NS_STATIC_CAST(nsISupportsWeakReference*, this); - } - else if (iid.Equals(NS_GET_IID(nsIStreamLoaderObserver))) { - *result = NS_STATIC_CAST(nsIStreamLoaderObserver*, this); - } - else if (iid.Equals(NS_GET_IID(nsIDOMDocumentStyle))) { - *result = NS_STATIC_CAST(nsIDOMDocumentStyle*, this); - } - else { - *result = nsnull; - return NS_NOINTERFACE; - } - NS_ADDREF(this); - return NS_OK; -} -NS_IMPL_ADDREF(nsXULDocument); -NS_IMPL_RELEASE(nsXULDocument); +// XPConnect interface list for nsXULDocument +NS_CLASSINFO_MAP_BEGIN(XULDocument) + NS_CLASSINFO_MAP_ENTRY(nsIDOMXULDocument) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSDocument) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentEvent) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentView) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentXBL) + NS_CLASSINFO_MAP_ENTRY(nsIDOMDocumentStyle) + NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsHTMLAnchorElement +NS_INTERFACE_MAP_BEGIN(nsXULDocument) + NS_INTERFACE_MAP_ENTRY(nsIDocument) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocument) + NS_INTERFACE_MAP_ENTRY(nsIXULDocument) + NS_INTERFACE_MAP_ENTRY(nsIXMLDocument) + NS_INTERFACE_MAP_ENTRY(nsIDOMXULDocument) + NS_INTERFACE_MAP_ENTRY(nsIDOMDocument) + NS_INTERFACE_MAP_ENTRY(nsIDOMNode) + NS_INTERFACE_MAP_ENTRY(nsIDOM3Node) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSDocument) + NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentEvent) + NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentView) + NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentXBL) + NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentStyle) + NS_INTERFACE_MAP_ENTRY(nsIHTMLContentContainer) + NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver) + NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget) + NS_INTERFACE_MAP_ENTRY(nsIDOMEventCapturer) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY(nsIStreamLoaderObserver) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULDocument) +NS_INTERFACE_MAP_END + //---------------------------------------------------------------------- // @@ -1427,6 +1402,13 @@ nsXULDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) shell->ReleaseAnonymousContent(); } + +#ifdef DEBUG_jst + printf ("Content wrapper hash had %d entries.\n", + mContentWrapperHash.Count()); +#endif + + mContentWrapperHash.Reset(); } mScriptGlobalObject = aScriptGlobalObject; @@ -1928,6 +1910,28 @@ nsXULDocument::GetNodeInfoManager(class nsINodeInfoManager *&aNodeInfoManager) return NS_OK; } +NS_IMETHODIMP +nsXULDocument::AddReference(void *aKey, nsISupports *aReference) +{ + nsVoidKey key(aKey); + + if (mScriptGlobalObject) { + mContentWrapperHash.Put(&key, aReference); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsXULDocument::RemoveReference(void *aKey, nsISupports **aOldReference) +{ + nsVoidKey key(aKey); + + mContentWrapperHash.Remove(&key, aOldReference); + + return NS_OK; +} + void nsXULDocument::SetDisplaySelection(PRInt8 aToggle) { @@ -2018,9 +2022,7 @@ nsXULDocument::SetDefaultStylesheets(nsIURI* aUrl) NS_IMETHODIMP nsXULDocument::SetTitle(const PRUnichar *aTitle) { - NS_ASSERTION(0,"not implemented"); - NS_NOTREACHED("nsXULDocument::SetTitle"); - return NS_ERROR_NOT_IMPLEMENTED; + return SetTitle(nsLiteralString(aTitle)); } //---------------------------------------------------------------------- @@ -2818,7 +2820,7 @@ nsXULDocument::GetAnonymousNodes(nsIDOMElement* aElement, } NS_IMETHODIMP -nsXULDocument::GetLocation(jsval* aLocation) +nsXULDocument::GetLocation(nsIDOMLocation** aLocation) { if (mScriptGlobalObject) { nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); @@ -2829,16 +2831,42 @@ nsXULDocument::GetLocation(jsval* aLocation) return NS_OK; } -NS_IMETHODIMP -nsXULDocument::SetLocation(jsval aLocation) +NS_IMETHODIMP +nsXULDocument::GetTitle(nsAWritableString& aTitle) { - if (mScriptGlobalObject) { - nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); - if(window) { - return window->SetLocation(aLocation); + aTitle.Assign(mDocumentTitle); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULDocument::SetTitle(const nsAReadableString& aTitle) +{ + for (PRInt32 i = mPresShells.Count() - 1; i >= 0; --i) { + nsIPresShell* shell = NS_STATIC_CAST(nsIPresShell*, mPresShells[i]); + + nsCOMPtr context; + nsresult rv = shell->GetPresContext(getter_AddRefs(context)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr container; + rv = context->GetContainer(getter_AddRefs(container)); + NS_ENSURE_SUCCESS(rv, rv); + + if (!container) + continue; + + nsCOMPtr docShellWin = do_QueryInterface(container); + if(!docShellWin) + continue; + + rv = docShellWin->SetTitle(PromiseFlatString(aTitle).get()); + NS_ENSURE_SUCCESS(rv, rv); } - } - return NS_OK; + + mDocumentTitle.Assign(aTitle); + + return NS_OK; } NS_IMETHODIMP @@ -2858,7 +2886,7 @@ nsXULDocument::GetPlugins(nsIDOMPluginArray** aPlugins) NS_IMETHODIMP nsXULDocument::GetDir(nsAWritableString& aDirection) { - aDirection.Assign(NS_LITERAL_STRING("ltr") ); + aDirection.Assign(NS_LITERAL_STRING("ltr")); return NS_OK; } @@ -3322,7 +3350,8 @@ nsXULDocument::GetNodeName(nsAWritableString& aNodeName) NS_IMETHODIMP nsXULDocument::GetNodeValue(nsAWritableString& aNodeValue) { - aNodeValue.Truncate(); + SetDOMStringToNull(aNodeValue); + return NS_OK; } @@ -3503,36 +3532,40 @@ nsXULDocument::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) NS_IMETHODIMP nsXULDocument::GetNamespaceURI(nsAWritableString& aNamespaceURI) { - aNamespaceURI.Truncate(); - return NS_OK; + SetDOMStringToNull(aNamespaceURI); + + return NS_OK; } NS_IMETHODIMP nsXULDocument::GetPrefix(nsAWritableString& aPrefix) { - aPrefix.Truncate(); - return NS_OK; + SetDOMStringToNull(aPrefix); + + return NS_OK; } NS_IMETHODIMP nsXULDocument::SetPrefix(const nsAReadableString& aPrefix) { - return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; + return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; } NS_IMETHODIMP nsXULDocument::GetLocalName(nsAWritableString& aLocalName) { - aLocalName.Truncate(); - return NS_OK; + SetDOMStringToNull(aLocalName); + + return NS_OK; } NS_IMETHODIMP -nsXULDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn) +nsXULDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, + nsIDOMNode** aReturn) { NS_NOTREACHED("nsXULDocument::InsertBefore"); return NS_ERROR_NOT_IMPLEMENTED; @@ -3540,7 +3573,8 @@ nsXULDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOM NS_IMETHODIMP -nsXULDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn) +nsXULDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, + nsIDOMNode** aReturn) { NS_NOTREACHED("nsXULDocument::ReplaceChild"); return NS_ERROR_NOT_IMPLEMENTED; @@ -3589,7 +3623,6 @@ nsXULDocument::IsSupported(const nsAReadableString& aFeature, return NS_ERROR_NOT_IMPLEMENTED; } -#if 0 NS_IMETHODIMP nsXULDocument::GetBaseURI(nsAWritableString &aURI) { @@ -3603,152 +3636,6 @@ nsXULDocument::GetBaseURI(nsAWritableString &aURI) } return NS_OK; } -#endif - - -//---------------------------------------------------------------------- -// -// nsIJSScriptObject interface -// - -PRBool -nsXULDocument::AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - NS_NOTYETIMPLEMENTED("write me"); - return PR_TRUE; -} - - -PRBool -nsXULDocument::DeleteProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - NS_NOTYETIMPLEMENTED("write me"); - return PR_TRUE; -} - - -PRBool -nsXULDocument::GetProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - - -PRBool -nsXULDocument::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - nsresult rv; - - if (JSVAL_IS_STRING(aID)) { - char* s = JS_GetStringBytes(JS_ValueToString(aContext, aID)); - if (PL_strcmp("title", s) == 0) { - JSString* jsString = JS_ValueToString(aContext, *aVp); - if (!jsString) - return PR_FALSE; - nsAutoString title(NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars(jsString))); - for (PRInt32 i = mPresShells.Count() - 1; i >= 0; --i) { - nsIPresShell* shell = NS_STATIC_CAST(nsIPresShell*, mPresShells[i]); - nsCOMPtr context; - rv = shell->GetPresContext(getter_AddRefs(context)); - if (NS_FAILED(rv)) return PR_FALSE; - - nsCOMPtr container; - rv = context->GetContainer(getter_AddRefs(container)); - if (NS_FAILED(rv)) return PR_FALSE; - - if (! container) continue; - - nsCOMPtr docShellWin = do_QueryInterface(container); - if(!docShellWin) continue; - - rv = docShellWin->SetTitle(title.GetUnicode()); - if (NS_FAILED(rv)) return PR_FALSE; - } - } - } - return PR_TRUE; -} - - -PRBool -nsXULDocument::EnumerateProperty(JSContext *aContext, JSObject *aObj) -{ - NS_NOTYETIMPLEMENTED("write me"); - return PR_TRUE; -} - - -PRBool -nsXULDocument::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty) -{ - *aDidDefineProperty = PR_FALSE; - - return PR_TRUE; -} - - -PRBool -nsXULDocument::Convert(JSContext *aContext, JSObject *aObj, jsval aID) -{ - NS_NOTYETIMPLEMENTED("write me"); - return PR_TRUE; -} - - -void -nsXULDocument::Finalize(JSContext *aContext, JSObject *aObj) -{ - NS_NOTYETIMPLEMENTED("write me"); -} - - - -//---------------------------------------------------------------------- -// -// nsIScriptObjectOwner interface -// - -NS_IMETHODIMP -nsXULDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - if (! mScriptObject) { - // ...we need to instantiate our script object for the first - // time. - - // Make sure that we've got our script context owner; this - // assertion will fire if we've tried to get the script object - // before our scope has been set up. - NS_ASSERTION(mScriptGlobalObject != nsnull, "no script object"); - if (! mScriptGlobalObject) - return NS_ERROR_NOT_INITIALIZED; - - nsresult rv; - - // Use the global object from our script context owner (the - // window) as the parent of our own script object. (Using the - // global object from aContext would make our script object - // dynamically scoped in the first context that ever tried to - // use us!) - - rv = NS_NewScriptXULDocument(aContext, - NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(nsIDOMXULDocument*, this)), - mScriptGlobalObject, &mScriptObject); - if (NS_FAILED(rv)) return rv; - } - - *aScriptObject = mScriptObject; - return NS_OK; -} - - -NS_IMETHODIMP -nsXULDocument::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - //---------------------------------------------------------------------- // @@ -3794,34 +3681,6 @@ nsXULDocument::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult) // Implementation methods // -nsIContent* -nsXULDocument::FindContent(const nsIContent* aStartNode, - const nsIContent* aTest1, - const nsIContent* aTest2) const -{ - PRInt32 count; - aStartNode->ChildCount(count); - - PRInt32 i; - for(i = 0; i < count; i++) { - nsIContent* child; - aStartNode->ChildAt(i, child); - nsIContent* content = FindContent(child,aTest1,aTest2); - if (content != nsnull) { - NS_IF_RELEASE(child); - return content; - } - if (child == aTest1 || child == aTest2) { - NS_IF_RELEASE(content); - return child; - } - NS_IF_RELEASE(child); - NS_IF_RELEASE(content); - } - return nsnull; -} - - nsresult nsXULDocument::Init() { @@ -3844,7 +3703,7 @@ nsXULDocument::Init() if (NS_FAILED(rv)) return rv; - mNodeInfoManager->Init(mNameSpaceManager); + mNodeInfoManager->Init(this, mNameSpaceManager); // Create our command dispatcher and hook it up. rv = nsXULCommandDispatcher::Create(this, getter_AddRefs(mCommandDispatcher)); @@ -4968,9 +4827,9 @@ nsXULDocument::ResumeWalk() if (blocked) return NS_OK; } - else if (scriptproto->mScriptObject) { + else if (scriptproto->mJSObject) { // An inline script - rv = ExecuteScript(scriptproto->mScriptObject); + rv = ExecuteScript(scriptproto->mJSObject); if (NS_FAILED(rv)) return rv; } } @@ -5137,8 +4996,8 @@ nsXULDocument::LoadScript(nsXULPrototypeScript* aScriptProto, PRBool* aBlock) // Load a transcluded script nsresult rv; - if (aScriptProto->mScriptObject) { - rv = ExecuteScript(aScriptProto->mScriptObject); + if (aScriptProto->mJSObject) { + rv = ExecuteScript(aScriptProto->mJSObject); // Ignore return value from execution, and don't block *aBlock = PR_FALSE; @@ -5233,8 +5092,8 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader, scriptProto->mSrcURI, 1, this, mMasterPrototype); aStatus = rv; - if (NS_SUCCEEDED(rv) && scriptProto->mScriptObject) { - rv = ExecuteScript(scriptProto->mScriptObject); + if (NS_SUCCEEDED(rv) && scriptProto->mJSObject) { + rv = ExecuteScript(scriptProto->mJSObject); } // ignore any evaluation errors } @@ -5261,8 +5120,8 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader, doc->mNextSrcLoadWaiter = nsnull; // Execute only if we loaded and compiled successfully, then resume - if (NS_SUCCEEDED(aStatus) && scriptProto->mScriptObject) { - doc->ExecuteScript(scriptProto->mScriptObject); + if (NS_SUCCEEDED(aStatus) && scriptProto->mJSObject) { + doc->ExecuteScript(scriptProto->mJSObject); } doc->ResumeWalk(); NS_RELEASE(doc); diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index 9f7bf326a3a..692cd70db20 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -38,6 +38,7 @@ #include "nsIDOMDocumentStyle.h" #include "nsIDOMDocumentView.h" #include "nsIDOMDocumentXBL.h" +#include "nsIDOMDocumentRange.h" #include "nsIDOMStyleSheetList.h" #include "nsISelection.h" #include "nsIDOMXULCommandDispatcher.h" @@ -47,13 +48,11 @@ #include "nsIHTMLCSSStyleSheet.h" #include "nsIHTMLContentContainer.h" #include "nsIHTMLStyleSheet.h" -#include "nsIJSScriptObject.h" #include "nsILineBreakerFactory.h" #include "nsINameSpaceManager.h" #include "nsIParser.h" #include "nsIPrincipal.h" #include "nsIRDFDataSource.h" -#include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptSecurityManager.h" #include "nsISupportsArray.h" @@ -98,10 +97,11 @@ class nsXULDocument : public nsIDocument, public nsIDOMDocumentEvent, public nsIDOMDocumentView, public nsIDOMDocumentXBL, + public nsIDOMDocumentRange, public nsIDOMNSDocument, + public nsIDOM3Node, public nsIDOMDocumentStyle, public nsIDOMEventCapturer, - public nsIJSScriptObject, public nsIHTMLContentContainer, public nsIStreamLoaderObserver, public nsSupportsWeakReference @@ -295,6 +295,9 @@ public: NS_IMETHOD GetNodeInfoManager(class nsINodeInfoManager *&aNodeInfoManager); + NS_IMETHOD AddReference(void *aKey, nsISupports *aReference); + NS_IMETHOD RemoveReference(void *aKey, nsISupports **aOldReference); + virtual void SetDisplaySelection(PRInt8 aToggle); virtual PRInt8 GetDisplaySelection() const; @@ -347,44 +350,31 @@ public: NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); // nsIDOMDocument interface - NS_DECL_IDOMDOCUMENT + NS_DECL_NSIDOMDOCUMENT // nsIDOMDocumentEvent interface - NS_DECL_IDOMDOCUMENTEVENT + NS_DECL_NSIDOMDOCUMENTEVENT // nsIDOMDocumentView interface - NS_DECL_IDOMDOCUMENTVIEW + NS_DECL_NSIDOMDOCUMENTVIEW // nsIDOMDocumentXBL interface - NS_DECL_IDOMDOCUMENTXBL + NS_DECL_NSIDOMDOCUMENTXBL + + // nsIDOMDocumentRange interface + NS_DECL_NSIDOMDOCUMENTRANGE // nsIDOMNSDocument interface - NS_DECL_IDOMNSDOCUMENT + NS_DECL_NSIDOMNSDOCUMENT // nsIDOMXULDocument interface - NS_DECL_IDOMXULDOCUMENT + NS_DECL_NSIDOMXULDOCUMENT // nsIDOMNode interface - NS_DECL_IDOMNODE + NS_DECL_NSIDOMNODE - // nsIJSScriptObject interface - virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool DeleteProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj); - virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty); - virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID); - virtual void Finalize(JSContext *aContext, JSObject *aObj); - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); + // nsIDOM3Node interface + NS_DECL_NSIDOM3NODE // nsIHTMLContentContainer interface NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult); @@ -477,11 +467,6 @@ protected: static void GetElementFactory(PRInt32 aNameSpaceID, nsIElementFactory** aResult); - nsIContent* - FindContent(const nsIContent* aStartNode, - const nsIContent* aTest1, - const nsIContent* aTest2) const; - nsresult Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aAttribute); @@ -496,7 +481,7 @@ protected: nsCOMPtr mArena; nsVoidArray mObservers; - nsAutoString mDocumentTitle; + nsString mDocumentTitle; nsCOMPtr mDocumentURL; // [OWNER] ??? compare with loader nsCOMPtr mDocumentBaseURL; nsWeakPtr mDocumentLoadGroup; // [WEAK] leads to loader @@ -505,7 +490,6 @@ protected: nsIDocument* mParentDocument; // [WEAK] nsCOMPtr mDOMStyleSheets; // [OWNER] nsIScriptGlobalObject* mScriptGlobalObject; // [WEAK] - void* mScriptObject; // ???? nsXULDocument* mNextSrcLoadWaiter; // [OWNER] but not COMPtr nsString mCharSetID; nsVoidArray mCharSetObservers; @@ -804,6 +788,8 @@ protected: friend class ParserObserver; + nsSupportsHashtable mContentWrapperHash; + private: // helpers diff --git a/content/xul/document/src/nsXULPrototypeCache.cpp b/content/xul/document/src/nsXULPrototypeCache.cpp index 70ec7d7c431..83a8a7b081c 100644 --- a/content/xul/document/src/nsXULPrototypeCache.cpp +++ b/content/xul/document/src/nsXULPrototypeCache.cpp @@ -140,7 +140,14 @@ nsXULPrototypeCache::~nsXULPrototypeCache() } -NS_IMPL_THREADSAFE_ISUPPORTS1(nsXULPrototypeCache, nsIXULPrototypeCache); +NS_IMPL_THREADSAFE_ADDREF(nsXULPrototypeCache) +NS_IMPL_THREADSAFE_RELEASE(nsXULPrototypeCache) + + +NS_INTERFACE_MAP_BEGIN(nsXULPrototypeCache) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY(nsIXULPrototypeCache) +NS_INTERFACE_MAP_END NS_IMETHODIMP diff --git a/content/xul/document/src/nsXULPrototypeDocument.cpp b/content/xul/document/src/nsXULPrototypeDocument.cpp index 83eefc6c327..007becaa3ec 100644 --- a/content/xul/document/src/nsXULPrototypeDocument.cpp +++ b/content/xul/document/src/nsXULPrototypeDocument.cpp @@ -35,20 +35,27 @@ #include "nsIPrincipal.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptGlobalObjectOwner.h" +#include "nsIScriptObjectPrincipal.h" #include "nsIScriptSecurityManager.h" #include "nsIServiceManager.h" #include "nsISupportsArray.h" #include "nsIURI.h" #include "nsIXULPrototypeDocument.h" -#include "nsJSUtils.h" +#include "jsapi.h" #include "nsString.h" #include "nsVoidArray.h" #include "nsXULElement.h" #include "nsIConsoleService.h" #include "nsIScriptError.h" +#include "nsIDOMScriptObjectFactory.h" +#include "nsDOMCID.h" -class nsXULPDGlobalObject : public nsIScriptObjectOwner, - public nsIScriptGlobalObject, + +static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, + NS_DOM_SCRIPT_OBJECT_FACTORY_CID); + + +class nsXULPDGlobalObject : public nsIScriptGlobalObject, public nsIScriptObjectPrincipal { public: @@ -57,10 +64,6 @@ public: // nsISupports interface NS_DECL_ISUPPORTS - // nsIScriptObjectOwner methods - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void **aObject); - NS_IMETHOD SetScriptObject(void *aObject); - // nsIScriptGlobalObject methods NS_IMETHOD SetContext(nsIScriptContext *aContext); NS_IMETHOD GetContext(nsIScriptContext **aContext); @@ -75,6 +78,8 @@ public: nsIDOMEvent** aDOMEvent, PRUint32 aFlags, nsEventStatus* aEventStatus); + NS_IMETHOD_(JSObject *) GetGlobalJSObject(); + NS_IMETHOD OnFinalize(JSObject *aObject); // nsIScriptObjectPrincipal methods NS_IMETHOD GetPrincipal(nsIPrincipal** aPrincipal); @@ -83,7 +88,7 @@ protected: virtual ~nsXULPDGlobalObject(); nsCOMPtr mScriptContext; - JSObject *mScriptObject; // XXX JS language rabies bigotry badness + JSObject *mJSObject; // XXX JS language rabies bigotry badness nsIScriptGlobalObjectOwner* mGlobalObjectOwner; // weak reference @@ -140,11 +145,45 @@ protected: NS_NewXULPrototypeDocument(nsISupports* aOuter, REFNSIID aIID, void** aResult); }; + + +void PR_CALLBACK +nsXULPDGlobalObject_finalize(JSContext *cx, JSObject *obj) +{ + nsISupports *nativeThis = (nsISupports*)JS_GetPrivate(cx, obj); + + nsCOMPtr sgo(do_QueryInterface(nativeThis)); + + if (sgo) { + sgo->OnFinalize(obj); + } + + // The addref was part of JSObject construction + NS_RELEASE(nativeThis); +} + + +JSBool PR_CALLBACK +nsXULPDGlobalObject_resolve(JSContext *cx, JSObject *obj, jsval id) +{ + if (JSVAL_IS_STRING(id)) { + JSString *str = JSVAL_TO_STRING(id); + + jschar *s = ::JS_GetStringChars(str); + } + + JSBool did_resolve = JS_FALSE; + + return JS_ResolveStandardClass(cx, obj, id, &did_resolve); +} + + JSClass nsXULPDGlobalObject::gSharedGlobalClass = { "nsXULPrototypeScript compilation scope", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, nsJSUtils::nsGenericFinalize + JS_EnumerateStub, nsXULPDGlobalObject_resolve, JS_ConvertStub, + nsXULPDGlobalObject_finalize }; @@ -403,7 +442,7 @@ nsXULPrototypeDocument::ReportScriptError(nsIScriptError *errorObject) // nsXULPDGlobalObject::nsXULPDGlobalObject() - : mScriptObject(nsnull), + : mJSObject(nsnull), mGlobalObjectOwner(nsnull) { NS_INIT_REFCNT(); @@ -418,59 +457,11 @@ NS_IMPL_ADDREF(nsXULPDGlobalObject) NS_IMPL_RELEASE(nsXULPDGlobalObject) NS_INTERFACE_MAP_BEGIN(nsXULPDGlobalObject) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObject) NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObject) NS_INTERFACE_MAP_END -//---------------------------------------------------------------------- -// -// nsIScriptObjectOwner methods -// - -NS_IMETHODIMP -nsXULPDGlobalObject::GetScriptObject(nsIScriptContext *aContext, void **aObject) -{ - // The prototype document has its own special secret script object - // that can be used to compile scripts and event handlers. - nsresult rv; - - nsCOMPtr context; - - if (mScriptContext && aContext != mScriptContext.get()) { - rv = GetContext(getter_AddRefs(context)); - if (NS_FAILED(rv)) return rv; - } - else { - context = aContext; - } - - if (! mScriptObject) { - JSContext* cx = NS_REINTERPRET_CAST(JSContext*, context->GetNativeContext()); - if (! cx) - return NS_ERROR_OUT_OF_MEMORY; - - mScriptObject = JS_NewObject(cx, &gSharedGlobalClass, nsnull, nsnull); - if (! mScriptObject) - return NS_ERROR_OUT_OF_MEMORY; - - // Add an owning reference from JS back to us. This'll be - // released when the JSObject is finalized. - ::JS_SetPrivate(cx, mScriptObject, this); - NS_ADDREF(this); - } - - *aObject = mScriptObject; - return NS_OK; -} - -NS_IMETHODIMP -nsXULPDGlobalObject::SetScriptObject(void *aObject) -{ - mScriptObject = (JSObject *)aObject; - return NS_OK; -} - //---------------------------------------------------------------------- // // nsIScriptGlobalObject methods @@ -490,9 +481,27 @@ nsXULPDGlobalObject::GetContext(nsIScriptContext **aContext) // This whole fragile mess is predicated on the fact that // GetContext() will be called before GetScriptObject() is. if (! mScriptContext) { - nsresult rv; - rv = NS_CreateScriptContext(this, getter_AddRefs(mScriptContext)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr factory = + do_GetService(kDOMScriptObjectFactoryCID); + NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE); + + nsresult rv = + factory->NewScriptContext(nsnull, getter_AddRefs(mScriptContext)); + if (NS_FAILED(rv)) + return rv; + + JSContext *cx = (JSContext *)mScriptContext->GetNativeContext(); + + mJSObject = ::JS_NewObject(cx, &gSharedGlobalClass, nsnull, nsnull); + if (!mJSObject) + return NS_ERROR_OUT_OF_MEMORY; + + ::JS_SetGlobalObject(cx, mJSObject); + + // Add an owning reference from JS back to us. This'll be + // released when the JSObject is finalized. + ::JS_SetPrivate(cx, mJSObject, this); + NS_ADDREF(this); } *aContext = mScriptContext; @@ -561,6 +570,33 @@ nsXULPDGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext, return NS_ERROR_UNEXPECTED; } +NS_IMETHODIMP_(JSObject *) +nsXULPDGlobalObject::GetGlobalJSObject() +{ + // The prototype document has its own special secret script object + // that can be used to compile scripts and event handlers. + + if (!mScriptContext) + return nsnull; + + JSContext* cx = NS_REINTERPRET_CAST(JSContext*, + mScriptContext->GetNativeContext()); + if (!cx) + return nsnull; + + return ::JS_GetGlobalObject(cx); +} + +NS_IMETHODIMP +nsXULPDGlobalObject::OnFinalize(JSObject *aObject) +{ + NS_ASSERTION(aObject == mJSObject, "Wrong object finalized!"); + + mJSObject = nsnull; + + return NS_OK; +} + //---------------------------------------------------------------------- // // nsIScriptObjectPrincipal methods diff --git a/content/xul/templates/src/nsContentTagTestNode.cpp b/content/xul/templates/src/nsContentTagTestNode.cpp index 6aa951e80f0..b475128feae 100644 --- a/content/xul/templates/src/nsContentTagTestNode.cpp +++ b/content/xul/templates/src/nsContentTagTestNode.cpp @@ -23,6 +23,7 @@ #include "nsContentTagTestNode.h" #include "nsISupportsArray.h" +#include "nsString.h" #include "prlog.h" #ifdef PR_LOGGING diff --git a/content/xul/templates/src/nsContentTagTestNode.h b/content/xul/templates/src/nsContentTagTestNode.h index 429dd85b83d..0391aee6bf1 100644 --- a/content/xul/templates/src/nsContentTagTestNode.h +++ b/content/xul/templates/src/nsContentTagTestNode.h @@ -25,6 +25,8 @@ #define nsContentTagTestNode_h__ #include "nsRuleNetwork.h" +#include "nsIAtom.h" + class nsConflictSet; class nsContentTagTestNode : public TestNode diff --git a/content/xul/templates/src/nsContentTestNode.cpp b/content/xul/templates/src/nsContentTestNode.cpp index 3d1123715d1..fc79bfcb4f7 100644 --- a/content/xul/templates/src/nsContentTestNode.cpp +++ b/content/xul/templates/src/nsContentTestNode.cpp @@ -26,6 +26,7 @@ #include "nsISupportsArray.h" #include "nsIXULDocument.h" #include "nsIRDFResource.h" +#include "nsIAtom.h" #include "nsXULContentUtils.h" #include "prlog.h" diff --git a/content/xul/templates/src/nsContentTestNode.h b/content/xul/templates/src/nsContentTestNode.h index 6e8c6699f0a..5ce9128dee8 100644 --- a/content/xul/templates/src/nsContentTestNode.h +++ b/content/xul/templates/src/nsContentTestNode.h @@ -26,6 +26,8 @@ #include "nsRuleNetwork.h" #include "nsFixedSizeAllocator.h" +#include "nsIAtom.h" + class nsIXULDocument; class nsConflictSet; diff --git a/content/xul/templates/src/nsRDFConInstanceTestNode.cpp b/content/xul/templates/src/nsRDFConInstanceTestNode.cpp index e2f17d82099..13b40f797db 100644 --- a/content/xul/templates/src/nsRDFConInstanceTestNode.cpp +++ b/content/xul/templates/src/nsRDFConInstanceTestNode.cpp @@ -29,6 +29,7 @@ #include "nsRDFCID.h" #include "nsRDFConInstanceTestNode.h" #include "nsResourceSet.h" +#include "nsString.h" #include "prlog.h" #ifdef PR_LOGGING diff --git a/content/xul/templates/src/nsRDFConMemberTestNode.cpp b/content/xul/templates/src/nsRDFConMemberTestNode.cpp index c672773fee2..05e571063aa 100644 --- a/content/xul/templates/src/nsRDFConMemberTestNode.cpp +++ b/content/xul/templates/src/nsRDFConMemberTestNode.cpp @@ -28,6 +28,7 @@ #include "nsIServiceManager.h" #include "nsResourceSet.h" #include "nsConflictSet.h" +#include "nsString.h" #include "prlog.h" #ifdef PR_LOGGING diff --git a/content/xul/templates/src/nsRDFPropertyTestNode.cpp b/content/xul/templates/src/nsRDFPropertyTestNode.cpp index 6867ef22050..6f702b2438a 100644 --- a/content/xul/templates/src/nsRDFPropertyTestNode.cpp +++ b/content/xul/templates/src/nsRDFPropertyTestNode.cpp @@ -23,6 +23,7 @@ #include "nsRDFPropertyTestNode.h" #include "nsConflictSet.h" +#include "nsString.h" #include "prlog.h" #ifdef PR_LOGGING diff --git a/content/xul/templates/src/nsRuleNetwork.h b/content/xul/templates/src/nsRuleNetwork.h index 66e84201257..94e81cdc4e9 100644 --- a/content/xul/templates/src/nsRuleNetwork.h +++ b/content/xul/templates/src/nsRuleNetwork.h @@ -50,6 +50,7 @@ #include "nsIContent.h" #include "plhash.h" #include "pldhash.h" +#include "nsCRT.h" class nsIRDFResource; class nsIRDFNode; diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 101a97896b9..c8ef8fd1345 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -33,6 +33,8 @@ #include "nsIPluginHost.h" #include "nsCURILoader.h" #include "nsLayoutCID.h" +#include "nsDOMCID.h" +#include "nsIDOMScriptObjectFactory.h" #include "nsNetUtil.h" #include "nsRect.h" #include "prprf.h" @@ -114,6 +116,8 @@ static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID); static NS_DEFINE_CID(kDocumentCharsetInfoCID, NS_DOCUMENTCHARSETINFO_CID); static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID); static NS_DEFINE_CID(kSecurityManagerCID, NS_SCRIPTSECURITYMANAGER_CID); +static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, + NS_DOM_SCRIPT_OBJECT_FACTORY_CID); // // Local function prototypes @@ -158,6 +162,7 @@ nsDocShell::nsDocShell(): mURIResultedInDocument(PR_FALSE), mUseExternalProtocolHandler(PR_FALSE), mDisallowPopupWindows(PR_FALSE), + mIsBeingDestroyed(PR_FALSE), mParent(nsnull), mTreeOwner(nsnull), mChromeEventHandler(nsnull) @@ -1333,7 +1338,6 @@ NS_IMETHODIMP nsDocShell::GetChildAt(PRInt32 aIndex, nsIDocShellTreeItem ** aChild) { NS_ENSURE_ARG_POINTER(aChild); - NS_ENSURE_ARG_RANGE(aIndex, 0, mChildren.Count() - 1); *aChild = (nsIDocShellTreeItem *) mChildren.ElementAt(aIndex); NS_IF_ADDREF(*aChild); @@ -1842,6 +1846,8 @@ nsDocShell::Create() NS_IMETHODIMP nsDocShell::Destroy() { + mIsBeingDestroyed = PR_TRUE; + // Stop any URLs that are currently being loaded... Stop(); if (mDocLoader) { @@ -2646,6 +2652,10 @@ nsDocShell::ScrollByPages(PRInt32 numPages) NS_IMETHODIMP nsDocShell::GetScriptGlobalObject(nsIScriptGlobalObject ** aGlobal) { + if (mIsBeingDestroyed) { + return NS_ERROR_NOT_AVAILABLE; + } + NS_ENSURE_ARG_POINTER(aGlobal); NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE); @@ -4824,7 +4834,15 @@ nsDocShell::EnsureScriptEnvironment() if (mScriptContext) return NS_OK; - NS_NewScriptGlobalObject(getter_AddRefs(mScriptGlobal)); + if (mIsBeingDestroyed) { + return NS_ERROR_NOT_AVAILABLE; + } + + nsCOMPtr factory = + do_GetService(kDOMScriptObjectFactoryCID); + NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE); + + factory->NewScriptGlobalObject(getter_AddRefs(mScriptGlobal)); NS_ENSURE_TRUE(mScriptGlobal, NS_ERROR_FAILURE); mScriptGlobal->SetDocShell(NS_STATIC_CAST(nsIDocShell *, this)); @@ -4832,7 +4850,7 @@ nsDocShell::EnsureScriptEnvironment() SetGlobalObjectOwner(NS_STATIC_CAST (nsIScriptGlobalObjectOwner *, this)); - NS_CreateScriptContext(mScriptGlobal, getter_AddRefs(mScriptContext)); + factory->NewScriptContext(mScriptGlobal, getter_AddRefs(mScriptContext)); NS_ENSURE_TRUE(mScriptContext, NS_ERROR_FAILURE); return NS_OK; diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index a089d872218..2cff258c333 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -323,6 +323,8 @@ protected: // Disallow popping up new windows with target= PRBool mDisallowPopupWindows; + PRBool mIsBeingDestroyed; + // WEAK REFERENCES BELOW HERE. // Note these are intentionally not addrefd. Doing so will create a cycle. // For that reasons don't use nsCOMPtr. diff --git a/docshell/base/nsIContentViewer.idl b/docshell/base/nsIContentViewer.idl index 98632c7bf38..3fd383b3439 100644 --- a/docshell/base/nsIContentViewer.idl +++ b/docshell/base/nsIContentViewer.idl @@ -1,5 +1,7 @@ #include "nsISupports.idl" -#include "domstubs.idl" + +interface nsIDOMDocument; + %{ C++ #include "nsIWidget.h" diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index b11911bd143..e9d542cab89 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -23,7 +23,6 @@ */ #include "nsISupports.idl" -#include "domstubs.idl" #include "nsIURIContentListener.idl" #include "nsIURI.idl" #include "nsIContentViewer.idl" diff --git a/docshell/base/nsIDocShellLoadInfo.idl b/docshell/base/nsIDocShellLoadInfo.idl index ccb131baf5d..f7467c6a9ac 100644 --- a/docshell/base/nsIDocShellLoadInfo.idl +++ b/docshell/base/nsIDocShellLoadInfo.idl @@ -22,7 +22,6 @@ */ #include "nsISupports.idl" -#include "domstubs.idl" /** * The nsIDocShellLoadInfo interface defines an interface for specifying diff --git a/docshell/base/nsIMarkupDocumentViewer.idl b/docshell/base/nsIMarkupDocumentViewer.idl index af96b8a34e6..94db9f7c76c 100644 --- a/docshell/base/nsIMarkupDocumentViewer.idl +++ b/docshell/base/nsIMarkupDocumentViewer.idl @@ -33,7 +33,8 @@ */ #include "nsISupports.idl" -#include "domstubs.idl" + +interface nsIDOMNode; [scriptable, uuid(69E5DE03-7B8B-11d3-AF61-00A024FFC08C)] diff --git a/docshell/base/nsIWebNavigation.idl b/docshell/base/nsIWebNavigation.idl index aa58e5de309..7085f4805d9 100644 --- a/docshell/base/nsIWebNavigation.idl +++ b/docshell/base/nsIWebNavigation.idl @@ -21,7 +21,9 @@ */ #include "nsISupports.idl" -#include "domstubs.idl" + +interface nsIDOMDocument; + /** * The nsIWebNavigation interface defines an interface for navigating the web. diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index b5a7b03cb84..87c25f60f26 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -323,18 +323,13 @@ nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr) NS_ADDREF((nsISupports*)*aInstancePtr); return NS_OK; } - else if(aIID.Equals(NS_GET_IID(nsIDOMWindowInternal))) + else if(aIID.Equals(NS_GET_IID(nsIDOMWindowInternal)) || + aIID.Equals(NS_GET_IID(nsIDOMWindow))) + { NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(NS_GET_IID(nsIDOMWindowInternal), - aInstancePtr), NS_ERROR_FAILURE); - return NS_OK; - } - else if(aIID.Equals(NS_GET_IID(nsIDOMWindow))) - { - NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(NS_GET_IID(nsIDOMWindow), - aInstancePtr), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(aIID, aInstancePtr), + NS_ERROR_FAILURE); return NS_OK; } diff --git a/docshell/build/Makefile.in b/docshell/build/Makefile.in index 870e3ddf32e..7931429054b 100644 --- a/docshell/build/Makefile.in +++ b/docshell/build/Makefile.in @@ -30,7 +30,6 @@ include $(DEPTH)/config/autoconf.mk LIBRARY_NAME = docshell EXPORT_LIBRARY = 1 -EXTRA_DSO_LIBS = jsdom REQUIRES = xpcom string dom shistory necko layout uriloader timer webshell widget pref locale view intl htmlparser chardet appcomps gfx2 find CPPSRCS = \ diff --git a/docshell/build/makefile.win b/docshell/build/makefile.win index cb2c1d4cf04..b187737e31e 100644 --- a/docshell/build/makefile.win +++ b/docshell/build/makefile.win @@ -40,7 +40,6 @@ LLIBS = \ $(DIST)\lib\xpcom.lib \ $(DIST)\lib\timer_s.lib \ $(DIST)\lib\gkgfxwin.lib \ - $(DIST)\lib\jsdom.lib \ $(LIBNSPR) include <$(DEPTH)\config\config.mak> diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 21347c831c7..4f7de216ffb 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -242,9 +242,9 @@ public: NS_DECL_ISUPPORTS /*BEGIN implementations of focus event handler interface*/ - virtual nsresult HandleEvent(nsIDOMEvent* aEvent); - virtual nsresult Focus(nsIDOMEvent* aEvent); - virtual nsresult Blur(nsIDOMEvent* aEvent); + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); + NS_IMETHOD Focus(nsIDOMEvent* aEvent); + NS_IMETHOD Blur(nsIDOMEvent* aEvent); /*END implementations of focus event handler interface*/ nsresult Init(DocumentViewerImpl *aDocViewer); @@ -5231,7 +5231,7 @@ nsDocViewerFocusListener::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } -nsresult +NS_IMETHODIMP nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) { nsCOMPtr shell; @@ -5256,8 +5256,8 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) } return result; } - -nsresult + +NS_IMETHODIMP nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) { nsCOMPtr shell; diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index 548d44ac34b..2f6e22b4c7b 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -63,6 +63,8 @@ static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID); #include "nsIDOMText.h" +#include "nsContentUtils.h" + //included for desired x position; #include "nsIPresContext.h" #include "nsIPresShell.h" @@ -84,9 +86,6 @@ static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID); #include "nsISelectionController.h"//for the enums -/*included so html can call into nsISelection code with no security issues*/ -#include "nsISecurityCheckedComponent.h" - #define STATUS_CHECK_RETURN_MACRO() {if (!mTracker) return NS_ERROR_FAILURE;} //#define DEBUG_TABLE 1 @@ -141,11 +140,10 @@ class nsSelectionIterator; class nsSelection; class nsAutoScrollTimer; -class nsTypedSelection : public nsISelection , - public nsISelectionPrivate, - public nsSupportsWeakReference, - public nsIIndependentSelection, - public nsISecurityCheckedComponent +class nsTypedSelection : public nsISelection, + public nsISelectionPrivate, + public nsSupportsWeakReference, + public nsIIndependentSelection { public: nsTypedSelection(); @@ -191,9 +189,6 @@ public: NS_IMETHOD SelectionLanguageChange(PRBool aLangRTL); /*END nsISelection interface implementations*/ -/* nsISecurityCheckedComponent */ - NS_DECL_NSISECURITYCHECKEDCOMPONENT -/*END nsISecurityCheckedComponent*/ // utility methods for scrolling the selection into view nsresult GetPresContext(nsIPresContext **aPresContext); @@ -4443,13 +4438,26 @@ nsTypedSelection::~nsTypedSelection() } +// XPConnect interface list for nsTypedSelection +NS_CLASSINFO_MAP_BEGIN(Selection) + NS_CLASSINFO_MAP_ENTRY(nsISelection) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsRange +NS_INTERFACE_MAP_BEGIN(nsTypedSelection) + NS_INTERFACE_MAP_ENTRY(nsISelection) + NS_INTERFACE_MAP_ENTRY(nsISelectionPrivate) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY(nsIIndependentSelection) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISelection) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Selection) +NS_INTERFACE_MAP_END + NS_IMPL_ADDREF(nsTypedSelection) - NS_IMPL_RELEASE(nsTypedSelection) -NS_IMPL_QUERY_INTERFACE5(nsTypedSelection, nsISelection, nsISelectionPrivate, nsISupportsWeakReference, nsIIndependentSelection, nsISecurityCheckedComponent) - NS_IMETHODIMP nsTypedSelection::SetPresShell(nsIPresShell *aPresShell) @@ -7552,55 +7560,6 @@ nsTypedSelection::DeleteFromDocument() return mFrameSelection->DeleteFromDocument(); } - -static const char* kAllAccess = "AllAccess"; -static const char* kNoAccess = "NoAccess"; - -/* string canCreateWrapper (in nsIIDPtr iid); */ -NS_IMETHODIMP -nsTypedSelection::CanCreateWrapper(const nsIID * iid, char **_retval) -{ - if (iid->Equals(NS_GET_IID(nsISelection))) { - *_retval = nsCRT::strdup(kAllAccess); - } - else - *_retval = nsCRT::strdup(kNoAccess); - - return NS_OK; -} - -/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */ -NS_IMETHODIMP -nsTypedSelection::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval) -{ - if (iid->Equals(NS_GET_IID(nsISelection))) { - *_retval = nsCRT::strdup(kAllAccess); - } - - return NS_OK; -} - -/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */ -NS_IMETHODIMP -nsTypedSelection::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval) -{ - if (iid->Equals(NS_GET_IID(nsISelection))) { - *_retval = nsCRT::strdup(kAllAccess); - } - - return NS_OK; -} - -/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */ -NS_IMETHODIMP -nsTypedSelection::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval) -{ - if (iid->Equals(NS_GET_IID(nsISelection))) { - *_retval = nsCRT::strdup(kAllAccess); - } - return NS_OK; -} - /** SelectionLanguageChange modifies the cursor Bidi level after a change in keyboard direction * @param aLangRTL is PR_TRUE if the new language is right-to-left or PR_FALSE if the new language is left-to-right */ diff --git a/layout/style/nsCSSStyleRule.cpp b/layout/style/nsCSSStyleRule.cpp index bfa54c6be5e..442d5fc3ee9 100644 --- a/layout/style/nsCSSStyleRule.cpp +++ b/layout/style/nsCSSStyleRule.cpp @@ -47,8 +47,6 @@ #include "nsIDOMCSSRule.h" #include "nsIDOMCSSStyleRule.h" #include "nsIDOMCSSStyleDeclaration.h" -#include "nsIScriptGlobalObject.h" -#include "nsIScriptObjectOwner.h" #include "nsDOMCSSDeclaration.h" #include "nsINameSpaceManager.h" #include "nsINameSpace.h" @@ -58,6 +56,8 @@ #include "nsIStyleSet.h" #include "nsISizeOfHandler.h" +#include "nsContentUtils.h" + // MJA: bug 31816 #include "nsIPresShell.h" #include "nsIDocShellTreeItem.h" @@ -598,6 +598,11 @@ void nsCSSSelector::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize) aSize += localSize; } + + // XXX ???? + + + // a couple of simple atom lists if(mIDList && uniqueItems->AddItem(mIDList)){ aSize += sizeof(*mIDList); @@ -1217,8 +1222,8 @@ DOMCSSDeclarationImpl::GetParent(nsISupports **aParent) class CSSStyleRuleImpl : public nsCSSRule, public nsICSSStyleRule, - public nsIDOMCSSStyleRule, - public nsIScriptObjectOwner { + public nsIDOMCSSStyleRule +{ public: CSSStyleRuleImpl(const nsCSSSelector& aSelector); CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy); @@ -1261,14 +1266,10 @@ public: virtual void SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize); // nsIDOMCSSRule interface - NS_DECL_IDOMCSSRULE + NS_DECL_NSIDOMCSSRULE // nsIDOMCSSStyleRule interface - NS_DECL_IDOMCSSSTYLERULE - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMCSSSTYLERULE private: // These are not supported and are not implemented! @@ -1283,7 +1284,6 @@ protected: PRInt32 mWeight; CSSImportantRule* mImportantRule; DOMCSSDeclarationImpl* mDOMDeclaration; - void* mScriptObject; PRUint32 mLineNumber; }; @@ -1295,8 +1295,7 @@ CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector) : nsCSSRule(), mSelector(aSelector), mDeclaration(nsnull), mWeight(0), mImportantRule(nsnull), - mDOMDeclaration(nsnull), - mScriptObject(nsnull) + mDOMDeclaration(nsnull) { #ifdef DEBUG_REFS gStyleRuleCount++; @@ -1310,8 +1309,7 @@ CSSStyleRuleImpl::CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy) mDeclaration(nsnull), mWeight(aCopy.mWeight), mImportantRule(nsnull), - mDOMDeclaration(nsnull), - mScriptObject(nsnull) + mDOMDeclaration(nsnull) { #ifdef DEBUG_REFS gStyleRuleCount++; @@ -1358,58 +1356,27 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl(void) } } +// XPConnect interface list for CSSStyleRuleImpl +NS_CLASSINFO_MAP_BEGIN(CSSStyleRule) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSStyleRuleImpl +NS_INTERFACE_MAP_BEGIN(CSSStyleRuleImpl) + NS_INTERFACE_MAP_ENTRY(nsICSSStyleRule) + NS_INTERFACE_MAP_ENTRY(nsICSSRule) + NS_INTERFACE_MAP_ENTRY(nsIStyleRule) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleRule) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleRule) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF_INHERITED(CSSStyleRuleImpl, nsCSSRule); NS_IMPL_RELEASE_INHERITED(CSSStyleRuleImpl, nsCSSRule); -nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID, - void** aInstancePtrResult) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsICSSStyleRule))) { - *aInstancePtrResult = (void*) ((nsICSSStyleRule*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsICSSRule))) { - *aInstancePtrResult = (void*) ((nsICSSRule*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIStyleRule))) { - *aInstancePtrResult = (void*) ((nsIStyleRule*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMCSSRule))) { - nsIDOMCSSRule *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMCSSStyleRule))) { - nsIDOMCSSStyleRule *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - nsICSSStyleRule *tmp = this; - nsISupports *tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} #if 0 NS_IMETHODIMP CSSStyleRuleImpl::Equals(const nsIStyleRule* aRule, PRBool& aResult) const @@ -3653,34 +3620,6 @@ CSSStyleRuleImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) return NS_OK; } -NS_IMETHODIMP -CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsICSSStyleRule *)this; - // XXX Parent should be the style sheet - // XXX Should be done through factory - res = NS_NewScriptCSSStyleRule(aContext, - supports, - (nsISupports *)global, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - NS_RELEASE(global); - return res; -} - -NS_IMETHODIMP -CSSStyleRuleImpl::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - NS_HTML nsresult NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult, const nsCSSSelector& aSelector) { diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index a187f51d970..b38b8149a17 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -58,8 +58,6 @@ #include "nsIDOMNode.h" #include "nsDOMError.h" #include "nsIPresShell.h" -#include "nsIScriptObjectOwner.h" -#include "nsIScriptGlobalObject.h" #include "nsICSSParser.h" #include "nsCSSAtoms.h" #include "nsINameSpaceManager.h" @@ -76,6 +74,8 @@ #include "nsIXULContent.h" #endif +#include "nsContentUtils.h" + //#define DEBUG_RULES //#define EVENT_DEBUG @@ -504,8 +504,8 @@ class CSSRuleListImpl; class DOMMediaListImpl; class CSSStyleSheetImpl : public nsICSSStyleSheet, - public nsIDOMCSSStyleSheet, - public nsIScriptObjectOwner { + public nsIDOMCSSStyleSheet +{ public: void* operator new(size_t size); void* operator new(size_t size, nsIArena* aArena); @@ -582,14 +582,10 @@ public: virtual void SizeOf(nsISizeOfHandler *aSizeofHandler, PRUint32 &aSize); // nsIDOMStyleSheet interface - NS_DECL_IDOMSTYLESHEET + NS_DECL_NSIDOMSTYLESHEET // nsIDOMCSSStyleSheet interface - NS_DECL_IDOMCSSSTYLESHEET - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMCSSSTYLESHEET private: // These are not supported and are not implemented! @@ -621,7 +617,6 @@ protected: nsIDOMNode* mOwningNode; PRBool mDisabled; PRBool mDirty; // has been modified - void* mScriptObject; CSSStyleSheetInner* mInner; @@ -634,8 +629,7 @@ friend class CSSRuleProcessor; // ------------------------------- // Style Rule List for the DOM // -class CSSRuleListImpl : public nsIDOMCSSRuleList, - public nsIScriptObjectOwner +class CSSRuleListImpl : public nsIDOMCSSRuleList { public: CSSRuleListImpl(CSSStyleSheetImpl *aStyleSheet); @@ -646,17 +640,12 @@ public: NS_IMETHOD GetLength(PRUint32* aLength); NS_IMETHOD Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn); - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); - void DropReference() { mStyleSheet = nsnull; } protected: virtual ~CSSRuleListImpl(); CSSStyleSheetImpl* mStyleSheet; - void* mScriptObject; public: PRBool mRulesAccessed; }; @@ -667,7 +656,6 @@ CSSRuleListImpl::CSSRuleListImpl(CSSStyleSheetImpl *aStyleSheet) // Not reference counted to avoid circular references. // The style sheet will tell us when its going away. mStyleSheet = aStyleSheet; - mScriptObject = nsnull; mRulesAccessed = PR_FALSE; } @@ -675,15 +663,23 @@ CSSRuleListImpl::~CSSRuleListImpl() { } +// XPConnect interface list for CSSStyleRuleImpl +NS_CLASSINFO_MAP_BEGIN(CSSRuleList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSRuleList) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSRuleList +NS_INTERFACE_MAP_BEGIN(CSSRuleListImpl) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSRuleList) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(CSSRuleListImpl); NS_IMPL_RELEASE(CSSRuleListImpl); -NS_INTERFACE_MAP_BEGIN(CSSRuleListImpl) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSRuleList) -NS_INTERFACE_MAP_END - NS_IMETHODIMP CSSRuleListImpl::GetLength(PRUint32* aLength) @@ -724,44 +720,12 @@ CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn) return result; } -NS_IMETHODIMP -CSSRuleListImpl::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsIDOMCSSRuleList *)this; - - // XXX Should be done through factory - res = NS_NewScriptCSSRuleList(aContext, - supports, - (nsISupports *)(nsICSSStyleSheet*)mStyleSheet, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -CSSRuleListImpl::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - class DOMMediaListImpl : public nsIDOMMediaList, - public nsIScriptObjectOwner, public nsISupportsArray { NS_DECL_ISUPPORTS - NS_DECL_IDOMMEDIALIST - - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMMEDIALIST NS_FORWARD_NSISUPPORTSARRAY(mArray->) NS_FORWARD_NSICOLLECTION(mArray->); @@ -782,21 +746,30 @@ class DOMMediaListImpl : public nsIDOMMediaList, private: nsCOMPtr mArray; CSSStyleSheetImpl* mStyleSheet; - void* mScriptObject; }; + +// XPConnect interface list for CSSStyleSheetStyleRuleImpl +NS_CLASSINFO_MAP_BEGIN(MediaList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMMediaList) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSStyleRuleImpl +NS_INTERFACE_MAP_BEGIN(DOMMediaListImpl) + NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMediaList) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MediaList) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(DOMMediaListImpl); NS_IMPL_RELEASE(DOMMediaListImpl); -NS_INTERFACE_MAP_BEGIN(DOMMediaListImpl) - NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMediaList) -NS_INTERFACE_MAP_END DOMMediaListImpl::DOMMediaListImpl(nsISupportsArray *aArray, CSSStyleSheetImpl *aStyleSheet) - : mArray(aArray), mStyleSheet(aStyleSheet), mScriptObject(nsnull) + : mArray(aArray), mStyleSheet(aStyleSheet) { NS_INIT_REFCNT(); @@ -807,33 +780,6 @@ DOMMediaListImpl::~DOMMediaListImpl() { } -NS_IMETHODIMP -DOMMediaListImpl::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsIDOMMediaList *)this; - - // XXX Should be done through factory - res = NS_NewScriptMediaList(aContext, - supports, - (nsISupports *)(nsIDOMMediaList*)mStyleSheet, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -DOMMediaListImpl::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - NS_IMETHODIMP DOMMediaListImpl::GetMediaText(nsAWritableString& aMediaText) { @@ -973,8 +919,7 @@ DOMMediaListImpl::Append(const nsAReadableString& aNewMedium) // ------------------------------- // Imports Collection for the DOM // -class CSSImportsCollectionImpl : public nsIDOMStyleSheetList, - public nsIScriptObjectOwner +class CSSImportsCollectionImpl : public nsIDOMStyleSheetList { public: CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet); @@ -985,17 +930,12 @@ public: NS_IMETHOD GetLength(PRUint32* aLength); NS_IMETHOD Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn); - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); - void DropReference() { mStyleSheet = nsnull; } protected: virtual ~CSSImportsCollectionImpl(); nsICSSStyleSheet* mStyleSheet; - void* mScriptObject; }; CSSImportsCollectionImpl::CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet) @@ -1004,47 +944,32 @@ CSSImportsCollectionImpl::CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet // Not reference counted to avoid circular references. // The style sheet will tell us when its going away. mStyleSheet = aStyleSheet; - mScriptObject = nsnull; } CSSImportsCollectionImpl::~CSSImportsCollectionImpl() { } + +// XPConnect interface list for CSSImportsCollectionImpl +NS_CLASSINFO_MAP_BEGIN(StyleSheetList) + NS_CLASSINFO_MAP_ENTRY(nsIDOMStyleSheetList) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSImportsCollectionImpl +NS_INTERFACE_MAP_BEGIN(CSSImportsCollectionImpl) + NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheetList) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(StyleSheetList) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(CSSImportsCollectionImpl); NS_IMPL_RELEASE(CSSImportsCollectionImpl); -nsresult -CSSImportsCollectionImpl::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) -{ - if (NULL == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - if (aIID.Equals(NS_GET_IID(nsIDOMStyleSheetList))) { - nsIDOMStyleSheetList *tmp = this; - *aInstancePtrResult = (void*) tmp; - AddRef(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner *tmp = this; - *aInstancePtrResult = (void*) tmp; - AddRef(); - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - nsIDOMStyleSheetList *tmp = this; - nsISupports *tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - AddRef(); - return NS_OK; - } - return NS_NOINTERFACE; -} - -NS_IMETHODIMP +NS_IMETHODIMP CSSImportsCollectionImpl::GetLength(PRUint32* aLength) { if (nsnull != mStyleSheet) { @@ -1078,34 +1003,6 @@ CSSImportsCollectionImpl::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn) return result; } -NS_IMETHODIMP -CSSImportsCollectionImpl::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsIDOMStyleSheetList *)this; - - // XXX Should be done through factory - res = NS_NewScriptStyleSheetList(aContext, - supports, - (nsISupports *)mStyleSheet, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -CSSImportsCollectionImpl::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - // ------------------------------- // CSS Style Sheet Inner Data Container // @@ -1414,7 +1311,6 @@ CSSStyleSheetImpl::CSSStyleSheetImpl() mOwningNode(nsnull), mDisabled(PR_FALSE), mDirty(PR_FALSE), - mScriptObject(nsnull), mRuleProcessors(nsnull) { NS_INIT_REFCNT(); @@ -1435,7 +1331,6 @@ CSSStyleSheetImpl::CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy) mOwningNode(aCopy.mOwningNode), mDisabled(aCopy.mDisabled), mDirty(PR_FALSE), - mScriptObject(nsnull), mInner(aCopy.mInner), mRuleProcessors(nsnull) { @@ -1507,54 +1402,27 @@ CSSStyleSheetImpl::~CSSStyleSheetImpl() } } + +// XPConnect interface list for CSSStyleSheetImpl +NS_CLASSINFO_MAP_BEGIN(CSSStyleSheet) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleSheet) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSStyleSheetImpl +NS_INTERFACE_MAP_BEGIN(CSSStyleSheetImpl) + NS_INTERFACE_MAP_ENTRY(nsICSSStyleSheet) + NS_INTERFACE_MAP_ENTRY(nsIStyleSheet) + NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleSheet) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleSheet) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(CSSStyleSheetImpl) NS_IMPL_RELEASE(CSSStyleSheetImpl) -nsresult CSSStyleSheetImpl::QueryInterface(const nsIID& aIID, - void** aInstancePtrResult) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - if (aIID.Equals(NS_GET_IID(nsICSSStyleSheet))) { - *aInstancePtrResult = (void*) ((nsICSSStyleSheet*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIStyleSheet))) { - *aInstancePtrResult = (void*) ((nsIStyleSheet*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMStyleSheet))) { - nsIDOMStyleSheet *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMCSSStyleSheet))) { - nsIDOMCSSStyleSheet *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner *tmp = this; - *aInstancePtrResult = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - nsICSSStyleSheet *tmp = this; - nsISupports *tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} NS_IMETHODIMP CSSStyleSheetImpl::GetStyleRuleProcessor(nsIStyleRuleProcessor*& aProcessor, @@ -2545,34 +2413,6 @@ CSSStyleSheetImpl::DeleteRule(PRUint32 aIndex) return result; } -NS_IMETHODIMP -CSSStyleSheetImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsICSSStyleSheet *)this; - // XXX Should be done through factory - res = NS_NewScriptCSSStyleSheet(aContext, - supports, - (nsISupports *)global, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - NS_RELEASE(global); - return res; -} - -NS_IMETHODIMP -CSSStyleSheetImpl::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - // XXX for backwards compatibility and convenience NS_HTML nsresult NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURI* aURL) diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 367cc15b551..45fb922edcc 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -17,7 +17,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): */ #include "nsIComputedDOMStyle.h" @@ -27,7 +27,6 @@ #include "nsIFrame.h" #include "nsIDOMElement.h" #include "nsIStyleContext.h" -#include "nsIScriptObjectOwner.h" #include "nsROCSSPrimitiveValue.h" #include "nsCSSProps.h" @@ -39,6 +38,8 @@ #include "prprf.h" #include "nsReadableUtils.h" +#include "nsContentUtils.h" + /* * This is the implementation of the readonly CSSStyleDeclaration that is * returned by the getComputedStyle() function. @@ -47,8 +48,7 @@ * file that is #ifdef'd out placeholders. */ -class nsComputedDOMStyle : public nsIComputedDOMStyle, - public nsIScriptObjectOwner +class nsComputedDOMStyle : public nsIComputedDOMStyle { public: NS_DECL_ISUPPORTS @@ -58,11 +58,7 @@ public: nsIPresShell *aPresShell); // nsIDOMCSSStyleDeclaration - NS_DECL_IDOMCSSSTYLEDECLARATION - - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMCSSSTYLEDECLARATION // nsComputedDOMStyle nsComputedDOMStyle(); @@ -71,12 +67,19 @@ public: private: //Helpers nsresult GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect); - nsresult GetStyleData(nsStyleStructID aID, const nsStyleStruct*& aStyleStruct,nsIFrame* aFrame=0); - nsresult GetPaddingWidthFor(PRUint8 aSide, nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderStyleFor(PRUint8 aSide, nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderWidthFor(PRUint8 aSide, nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderColorFor(PRUint8 aSide, nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetMarginWidthFor(PRUint8 aSide, nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetStyleData(nsStyleStructID aID, + const nsStyleStruct*& aStyleStruct, + nsIFrame* aFrame=0); + nsresult GetPaddingWidthFor(PRUint8 aSide, nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderStyleFor(PRUint8 aSide, nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderWidthFor(PRUint8 aSide, nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderColorFor(PRUint8 aSide, nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetMarginWidthFor(PRUint8 aSide, nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); // Properties nsresult GetWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); @@ -95,57 +98,79 @@ private: nsresult GetFontVariant(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); // Background properties - nsresult GetBackgroundColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBackgroundImage(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBackgroundColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBackgroundImage(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); nsresult GetDisplay(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); // Padding properties nsresult GetPadding(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetPaddingTop(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetPaddingBottom(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetPaddingBottom(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); nsresult GetPaddingLeft(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetPaddingRight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); // BorderProperties nsresult GetBorderStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetBorderWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderCollapse(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderSpacing(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderTopStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderBottomStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderLeftStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderRightStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderTopColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderBottomColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderLeftColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetBorderRightColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - + nsresult GetBorderCollapse(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderSpacing(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderTopStyle(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderBottomStyle(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderLeftStyle(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderRightStyle(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderTopWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderBottomWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderLeftWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderRightWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderTopColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderBottomColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderLeftColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetBorderRightColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + // Margin Properties nsresult GetMarginWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetMarginTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetMarginBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetMarginLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - nsresult GetMarginRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - + nsresult GetMarginTopWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetMarginBottomWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetMarginLeftWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetMarginRightWidth(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); + // Outline Properties nsresult GetOutline(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetOutlineWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetOutlineStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); nsresult GetOutlineColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - + //Marker Properties nsresult GetMarkerOffset(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); - + // z-index nsresult GetZIndex(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); // List properties - nsresult GetListStyleImage(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); + nsresult GetListStyleImage(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue); // Text Properties nsresult GetTextAlign(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue); @@ -156,14 +181,12 @@ private: nsWeakPtr mPresShellWeak; // XXX could this be high cost? nsCOMPtr mContent; - // When a frame is unavailable strong reference to the + // When a frame is unavailable strong reference to the // style context while we're accessing the data from in. - nsCOMPtr mStyleContextHolder; + nsCOMPtr mStyleContextHolder; nsCOMPtr mPseudo; float mT2P; // For unit conversions - - void* mScriptObject; }; @@ -182,8 +205,7 @@ NS_NewComputedDOMStyle(nsIComputedDOMStyle** aComputedStyle) nsComputedDOMStyle::nsComputedDOMStyle() : mPresShellWeak(nsnull), - mT2P(0.0f), - mScriptObject(nsnull) + mT2P(0.0f) { NS_INIT_REFCNT(); } @@ -194,70 +216,50 @@ nsComputedDOMStyle::~nsComputedDOMStyle() } +// XPConnect interface list for nsComputedDOMStyle +NS_CLASSINFO_MAP_BEGIN(ComputedCSSStyleDeclaration) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleDeclaration) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsComputedDOMStyle +NS_INTERFACE_MAP_BEGIN(nsComputedDOMStyle) + NS_INTERFACE_MAP_ENTRY(nsIComputedDOMStyle) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleDeclaration) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIComputedDOMStyle) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ComputedCSSStyleDeclaration) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsComputedDOMStyle); NS_IMPL_RELEASE(nsComputedDOMStyle); -NS_INTERFACE_MAP_BEGIN(nsComputedDOMStyle) -NS_INTERFACE_MAP_ENTRY(nsIComputedDOMStyle) -NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleDeclaration) -NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) -NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIComputedDOMStyle) -NS_INTERFACE_MAP_END - - NS_IMETHODIMP -nsComputedDOMStyle::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (!mScriptObject) { - nsISupports *supports = NS_STATIC_CAST(nsIComputedDOMStyle *, this); - - // XXX Should be done through factory - res = NS_NewScriptCSSStyleDeclaration(aContext, supports, mContent, - &mScriptObject); - } - - *aScriptObject = mScriptObject; - - return res; -} - - -NS_IMETHODIMP -nsComputedDOMStyle::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - -NS_IMETHODIMP -nsComputedDOMStyle::Init(nsIDOMElement *aElement, const nsAReadableString& aPseudoElt, +nsComputedDOMStyle::Init(nsIDOMElement *aElement, + const nsAReadableString& aPseudoElt, nsIPresShell *aPresShell) { NS_ENSURE_ARG_POINTER(aElement); NS_ENSURE_ARG_POINTER(aPresShell); - mPresShellWeak = getter_AddRefs(NS_GetWeakReference(aPresShell)); + mPresShellWeak = getter_AddRefs(NS_GetWeakReference(aPresShell)); mContent = do_QueryInterface(aElement); if (!mContent) { // This should not happen, all our elements support nsIContent! return NS_ERROR_FAILURE; } - - if(!aPseudoElt.IsEmpty()) { + + if(!DOMStringIsNull(aPseudoElt) && !aPseudoElt.IsEmpty()) { mPseudo = dont_AddRef(NS_NewAtom(aPseudoElt)); - NS_ENSURE_TRUE(mPseudo, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(mPseudo, NS_ERROR_OUT_OF_MEMORY); } - + nsCOMPtr presCtx; aPresShell->GetPresContext(getter_AddRefs(presCtx)); - + NS_ENSURE_TRUE(presCtx, NS_ERROR_FAILURE); presCtx->GetTwipsToPixels(&mT2P); @@ -326,9 +328,9 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAReadableString& aPropertyName, *aReturn = nsnull; nsCOMPtr presShell=do_QueryReferent(mPresShellWeak); - + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - + nsIFrame *frame = nsnull; presShell->GetPrimaryFrameFor(mContent, &frame); @@ -355,7 +357,7 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAReadableString& aPropertyName, rv = GetRight(frame, *getter_AddRefs(val)); break; case eCSSProperty_bottom : rv = GetBottom(frame, *getter_AddRefs(val)); break; - + // Font properties case eCSSProperty_color : rv = GetColor(frame, *getter_AddRefs(val)); break; @@ -369,13 +371,13 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAReadableString& aPropertyName, rv = GetFontWeight(frame, *getter_AddRefs(val)); break; case eCSSProperty_font_variant : rv = GetFontVariant(frame, *getter_AddRefs(val)); break; - + // Background properties case eCSSProperty_background_color : rv = GetBackgroundColor(frame, *getter_AddRefs(val)); break; case eCSSProperty_background_image : rv = GetBackgroundImage(frame, *getter_AddRefs(val)); break; - + // Padding properties case eCSSProperty_padding : rv = GetPadding(frame, *getter_AddRefs(val)); break; @@ -452,9 +454,9 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAReadableString& aPropertyName, rv = val->QueryInterface(NS_GET_IID(nsIDOMCSSValue), (void **)aReturn); } - // Release the current style context for it should be re-resolved + // Release the current style context for it should be re-resolved // whenever a frame is not available. - mStyleContextHolder=nsnull; + mStyleContextHolder=nsnull; return rv; } @@ -498,7 +500,7 @@ nsComputedDOMStyle::Item(PRUint32 aIndex, nsAWritableString& aReturn) #if 0 -NS_IMETHODIMP +NS_IMETHODIMP nsComputedDOMStyle::GetAzimuth(nsAWritableString& aAzimuth) { return NS_ERROR_DOM_NOT_SUPPORTED_ERR; @@ -550,7 +552,7 @@ nsComputedDOMStyle::GetBehavior(nsIFrame *aFrame, NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleUserInterface* ui = nsnull; - + GetStyleData(eStyleStruct_UserInterface, (const nsStyleStruct*&)ui, aFrame); if (ui) { @@ -720,9 +722,9 @@ static void ColorToHex(nscolor aColor, nsAWritableString& aHexString) { char buf[32]; - PRUint32 len = PR_snprintf(buf, 32, "#%02x%02x%02x", + PRUint32 len = PR_snprintf(buf, 32, "#%02x%02x%02x", NS_GET_R(aColor), - NS_GET_G(aColor), + NS_GET_G(aColor), NS_GET_B(aColor)); CopyASCIItoUCS2(nsLiteralCString(buf, len), aHexString); @@ -737,18 +739,19 @@ nsComputedDOMStyle::GetColor(nsIFrame *aFrame, NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleColor* color=nsnull; - GetStyleData(eStyleStruct_Color,(const nsStyleStruct*&)color,aFrame); - + GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)color, aFrame); + if(color) { nsAutoString hex; - ColorToHex(color->mColor,hex); + ColorToHex(color->mColor, hex); val->SetString(hex); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -757,9 +760,9 @@ nsComputedDOMStyle::GetFontFamily(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleFont* font=nsnull; - GetStyleData(eStyleStruct_Font,(const nsStyleStruct*&)font,aFrame); + GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); if(font) { val->SetString(font->mFont.name); @@ -768,7 +771,8 @@ nsComputedDOMStyle::GetFontFamily(nsIFrame *aFrame, val->SetString(""); } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -777,13 +781,14 @@ nsComputedDOMStyle::GetFontSize(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleFont* font=nsnull; - GetStyleData(eStyleStruct_Font,(const nsStyleStruct*&)font,aFrame); - + GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); + val->SetTwips(font? font->mFont.size:0); - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -792,20 +797,22 @@ nsComputedDOMStyle::GetFontStyle(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleFont* font=nsnull; - GetStyleData(eStyleStruct_Font,(const nsStyleStruct*&)font,aFrame); - + GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); + if(font) { const nsCString& style= - nsCSSProps::SearchKeywordTable(font->mFont.style,nsCSSProps::kFontStyleKTable); + nsCSSProps::SearchKeywordTable(font->mFont.style, + nsCSSProps::kFontStyleKTable); val->SetString(style); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -814,13 +821,14 @@ nsComputedDOMStyle::GetFontWeight(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleFont* font=nsnull; - GetStyleData(eStyleStruct_Font,(const nsStyleStruct*&)font,aFrame); + GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); if(font) { const nsCString& str_weight= - nsCSSProps::SearchKeywordTable(font->mFont.weight,nsCSSProps::kFontWeightKTable); + nsCSSProps::SearchKeywordTable(font->mFont.weight, + nsCSSProps::kFontWeightKTable); if(str_weight.Length()>0) { val->SetString(str_weight); } @@ -833,8 +841,9 @@ nsComputedDOMStyle::GetFontWeight(nsIFrame *aFrame, else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -843,20 +852,22 @@ nsComputedDOMStyle::GetFontVariant(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleFont* font=nsnull; - GetStyleData(eStyleStruct_Font,(const nsStyleStruct*&)font,aFrame); - + GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font, aFrame); + if(font) { const nsCString& variant= - nsCSSProps::SearchKeywordTable(font->mFont.variant,nsCSSProps::kFontVariantKTable); + nsCSSProps::SearchKeywordTable(font->mFont.variant, + nsCSSProps::kFontVariantKTable); val->SetString(variant); } else { val->SetString(""); } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -865,20 +876,21 @@ nsComputedDOMStyle::GetBackgroundColor(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleColor* color=nsnull; - GetStyleData(eStyleStruct_Color,(const nsStyleStruct*&)color,aFrame); - + GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)color, aFrame); + if(color) { - nsAutoString hex; - ColorToHex(color->mBackgroundColor,hex); + nsAutoString hex; + ColorToHex(color->mBackgroundColor, hex); val->SetString(hex); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -887,9 +899,9 @@ nsComputedDOMStyle::GetBackgroundImage(nsIFrame *aFrame, { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleColor* color=nsnull; - GetStyleData(eStyleStruct_Color,(const nsStyleStruct*&)color,aFrame); + GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)color, aFrame); if(color) { val->SetString(color->mBackgroundImage); @@ -897,8 +909,9 @@ nsComputedDOMStyle::GetBackgroundImage(nsIFrame *aFrame, else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -906,289 +919,296 @@ nsComputedDOMStyle::GetPadding(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { aValue=nsnull; // return null per spec. - return NS_OK; + return NS_OK; } nsresult nsComputedDOMStyle::GetPaddingTop(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetPaddingWidthFor(NS_SIDE_TOP,aFrame,aValue); + return GetPaddingWidthFor(NS_SIDE_TOP, aFrame, aValue); } nsresult nsComputedDOMStyle::GetPaddingBottom(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetPaddingWidthFor(NS_SIDE_BOTTOM,aFrame,aValue); + return GetPaddingWidthFor(NS_SIDE_BOTTOM, aFrame, aValue); } nsresult nsComputedDOMStyle::GetPaddingLeft(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetPaddingWidthFor(NS_SIDE_LEFT,aFrame,aValue); + return GetPaddingWidthFor(NS_SIDE_LEFT, aFrame, aValue); } nsresult nsComputedDOMStyle::GetPaddingRight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetPaddingWidthFor(NS_SIDE_RIGHT,aFrame,aValue); + return GetPaddingWidthFor(NS_SIDE_RIGHT, aFrame, aValue); } nsresult -nsComputedDOMStyle::GetBorderCollapse(nsIFrame *aFrame, +nsComputedDOMStyle::GetBorderCollapse(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleTable* table = nsnull; - GetStyleData(eStyleStruct_Table,(const nsStyleStruct*&)table,aFrame); + GetStyleData(eStyleStruct_Table, (const nsStyleStruct*&)table, aFrame); if(table) { const nsCString& ident= - nsCSSProps::SearchKeywordTable(table->mBorderCollapse,nsCSSProps::kBorderCollapseKTable); + nsCSSProps::SearchKeywordTable(table->mBorderCollapse, + nsCSSProps::kBorderCollapseKTable); val->SetString(ident); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult -nsComputedDOMStyle::GetBorderSpacing(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderSpacing(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { return NS_ERROR_DOM_NOT_SUPPORTED_ERR; } -nsresult -nsComputedDOMStyle::GetBorderStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { aValue=nsnull; // return null per spec. return NS_OK; } -nsresult -nsComputedDOMStyle::GetBorderTopStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderTopStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderStyleFor(NS_SIDE_TOP,aFrame,aValue); + return GetBorderStyleFor(NS_SIDE_TOP, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderBottomStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderBottomStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderStyleFor(NS_SIDE_BOTTOM,aFrame,aValue); + return GetBorderStyleFor(NS_SIDE_BOTTOM, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderLeftStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderLeftStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderStyleFor(NS_SIDE_LEFT,aFrame,aValue); + return GetBorderStyleFor(NS_SIDE_LEFT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderRightStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderRightStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderStyleFor(NS_SIDE_RIGHT,aFrame,aValue); + return GetBorderStyleFor(NS_SIDE_RIGHT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) -{ +{ aValue=nsnull; // return null per spec. return NS_OK; } -nsresult -nsComputedDOMStyle::GetBorderTopWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderWidthFor(NS_SIDE_TOP,aFrame,aValue); -} - -nsresult -nsComputedDOMStyle::GetBorderBottomWidth(nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) -{ - return GetBorderWidthFor(NS_SIDE_BOTTOM,aFrame,aValue); -} - -nsresult -nsComputedDOMStyle::GetBorderLeftWidth(nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) -{ - return GetBorderWidthFor(NS_SIDE_LEFT,aFrame,aValue); -} - -nsresult -nsComputedDOMStyle::GetBorderRightWidth(nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) -{ - return GetBorderWidthFor(NS_SIDE_RIGHT,aFrame,aValue); + return GetBorderWidthFor(NS_SIDE_TOP, aFrame, aValue); } nsresult -nsComputedDOMStyle::GetBorderTopColor(nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) -{ - return GetBorderColorFor(NS_SIDE_TOP,aFrame,aValue); -} - -nsresult -nsComputedDOMStyle::GetBorderBottomColor(nsIFrame *aFrame, +nsComputedDOMStyle::GetBorderBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderColorFor(NS_SIDE_BOTTOM,aFrame,aValue); + return GetBorderWidthFor(NS_SIDE_BOTTOM, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderLeftColor(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderColorFor(NS_SIDE_LEFT,aFrame,aValue); + return GetBorderWidthFor(NS_SIDE_LEFT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetBorderRightColor(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetBorderColorFor(NS_SIDE_RIGHT,aFrame,aValue); + return GetBorderWidthFor(NS_SIDE_RIGHT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetMarginWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetBorderTopColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue) +{ + return GetBorderColorFor(NS_SIDE_TOP, aFrame, aValue); +} + +nsresult +nsComputedDOMStyle::GetBorderBottomColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue) +{ + return GetBorderColorFor(NS_SIDE_BOTTOM, aFrame, aValue); +} + +nsresult +nsComputedDOMStyle::GetBorderLeftColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue) +{ + return GetBorderColorFor(NS_SIDE_LEFT, aFrame, aValue); +} + +nsresult +nsComputedDOMStyle::GetBorderRightColor(nsIFrame *aFrame, + nsIDOMCSSPrimitiveValue*& aValue) +{ + return GetBorderColorFor(NS_SIDE_RIGHT, aFrame, aValue); +} + +nsresult +nsComputedDOMStyle::GetMarginWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { aValue=nsnull; // return null per spec. return NS_OK; } - -nsresult -nsComputedDOMStyle::GetMarginTopWidth(nsIFrame *aFrame, + +nsresult +nsComputedDOMStyle::GetMarginTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetMarginWidthFor(NS_SIDE_TOP,aFrame,aValue); + return GetMarginWidthFor(NS_SIDE_TOP, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetMarginBottomWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetMarginBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetMarginWidthFor(NS_SIDE_BOTTOM,aFrame,aValue); + return GetMarginWidthFor(NS_SIDE_BOTTOM, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetMarginLeftWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetMarginLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetMarginWidthFor(NS_SIDE_LEFT,aFrame,aValue); + return GetMarginWidthFor(NS_SIDE_LEFT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetMarginRightWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetMarginRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - return GetMarginWidthFor(NS_SIDE_RIGHT,aFrame,aValue); + return GetMarginWidthFor(NS_SIDE_RIGHT, aFrame, aValue); } -nsresult -nsComputedDOMStyle::GetMarkerOffset(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetMarkerOffset(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleContent* content=nsnull; - GetStyleData(eStyleStruct_Content,(const nsStyleStruct*&)content,aFrame); - + GetStyleData(eStyleStruct_Content, (const nsStyleStruct*&)content, aFrame); + val->SetTwips(content? content->mMarkerOffset.GetCoordValue():0); - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult -nsComputedDOMStyle::GetOutline(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetOutline(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { aValue=nsnull; // return null per spec. return NS_OK; } -nsresult -nsComputedDOMStyle::GetOutlineWidth(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetOutlineWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleOutline* outline=nsnull; - GetStyleData(eStyleStruct_Outline,(const nsStyleStruct*&)outline,aFrame); + GetStyleData(eStyleStruct_Outline, (const nsStyleStruct*&)outline, aFrame); val->SetTwips(outline? outline->mOutlineWidth.GetCoordValue():0); - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult -nsComputedDOMStyle::GetOutlineStyle(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetOutlineStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleOutline* outline=nsnull; - GetStyleData(eStyleStruct_Outline,(const nsStyleStruct*&)outline,aFrame); - + GetStyleData(eStyleStruct_Outline, (const nsStyleStruct*&)outline, aFrame); + if(outline) { const nsCString& style= - nsCSSProps::SearchKeywordTable(outline->GetOutlineStyle(),nsCSSProps::kBorderStyleKTable); + nsCSSProps::SearchKeywordTable(outline->GetOutlineStyle(), + nsCSSProps::kBorderStyleKTable); val->SetString(style); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult -nsComputedDOMStyle::GetOutlineColor(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetOutlineColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleOutline* outline=nsnull; - GetStyleData(eStyleStruct_Outline,(const nsStyleStruct*&)outline,aFrame); - + GetStyleData(eStyleStruct_Outline, (const nsStyleStruct*&)outline, aFrame); + if(outline) { nscolor color; outline->GetOutlineColor(color); - + nsAutoString hex; - ColorToHex(color,hex); + ColorToHex(color, hex); val->SetString(hex); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult -nsComputedDOMStyle::GetZIndex(nsIFrame *aFrame, +nsresult +nsComputedDOMStyle::GetZIndex(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); @@ -1198,7 +1218,9 @@ nsComputedDOMStyle::GetZIndex(nsIFrame *aFrame, nsAutoString zindex; do { - GetStyleData(eStyleStruct_Position,(const nsStyleStruct*&)position,aFrame); + GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&)position, + aFrame); + if(position){ if(position->mZIndex.GetUnit()==eStyleUnit_Integer) { zindex.AppendInt(position->mZIndex.GetIntValue(), 10); @@ -1207,10 +1229,11 @@ nsComputedDOMStyle::GetZIndex(nsIFrame *aFrame, aFrame->GetParent(&aFrame); } }while(aFrame && position); - + val->SetString(zindex); - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult @@ -1221,8 +1244,8 @@ nsComputedDOMStyle::GetListStyleImage(nsIFrame *aFrame, NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleList* list; - GetStyleData(eStyleStruct_List,(const nsStyleStruct*&)list,aFrame); - + GetStyleData(eStyleStruct_List, (const nsStyleStruct*&)list, aFrame); + if(list) { val->SetString(list->mListStyleImage); } @@ -1230,29 +1253,32 @@ nsComputedDOMStyle::GetListStyleImage(nsIFrame *aFrame, val->SetString(""); } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void**)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void**)&aValue); } nsresult nsComputedDOMStyle::GetTextAlign(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { - nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); + nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - const nsStyleText* text=nsnull; - GetStyleData(eStyleStruct_Text,(const nsStyleStruct*&)text,aFrame); + const nsStyleText* text = nsnull; + GetStyleData(eStyleStruct_Text, (const nsStyleStruct*&)text, aFrame); if(text) { const nsCString& align= - nsCSSProps::SearchKeywordTable(text->mTextAlign,nsCSSProps::kTextAlignKTable); + nsCSSProps::SearchKeywordTable(text->mTextAlign, + nsCSSProps::kTextAlignKTable); val->SetString(align); } else { val->SetString("start"); } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } #if 0 @@ -1345,7 +1371,7 @@ nsComputedDOMStyle::GetDisplay(nsIFrame *aFrame, const nsStyleDisplay* display = nsnull; - GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display,aFrame); + GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display, aFrame); if (display) { switch (display->mDisplay) { @@ -1902,12 +1928,12 @@ nsComputedDOMStyle::GetWidows(nsAWritableString& aWidows) #endif nsROCSSPrimitiveValue* -nsComputedDOMStyle::GetROCSSPrimitiveValue() +nsComputedDOMStyle::GetROCSSPrimitiveValue() { nsISupports *tmp = NS_STATIC_CAST(nsIComputedDOMStyle *, this); nsROCSSPrimitiveValue *primitiveValue = new nsROCSSPrimitiveValue(tmp, mT2P); - + NS_ASSERTION(primitiveValue!=0, "ran out of memory"); return primitiveValue; @@ -1920,7 +1946,7 @@ nsComputedDOMStyle::GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect) aRect.x = aRect.y = 0; aRect.Empty(); - + if (!aFrame) { return NS_OK; } @@ -1928,7 +1954,7 @@ nsComputedDOMStyle::GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect) // Flush all pending notifications so that our frames are uptodate nsCOMPtr document; mContent->GetDocument(*getter_AddRefs(document)); - + if (document) { document->FlushPendingNotifications(); } @@ -1943,17 +1969,17 @@ nsComputedDOMStyle::GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect) } while (nsnull != next); nsIFrame* frame = aFrame; - nsPoint origin(0,0),tmp(0,0); + nsPoint origin(0, 0), tmp(0, 0); nsFrameState position; do { frame->GetOrigin(tmp); origin += tmp; - + frame->GetFrameState(&position); if(position & NS_FRAME_OUT_OF_FLOW) { break; // Do not include parent if absolutely positioned - Bug 49942 } - // Add the parent's origin to our own to + // Add the parent's origin to our own to // get to the right coordinate system frame->GetParent(&frame); } while(frame); @@ -1962,8 +1988,8 @@ nsComputedDOMStyle::GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect) const nsStyleBorder* border; const nsStylePadding* padding; nsStyleCoord coord; - GetStyleData(eStyleStruct_Border, (const nsStyleStruct*&)border,aFrame); - GetStyleData(eStyleStruct_Padding, (const nsStyleStruct*&)padding,aFrame); + GetStyleData(eStyleStruct_Border, (const nsStyleStruct*&)border, aFrame); + GetStyleData(eStyleStruct_Padding, (const nsStyleStruct*&)padding, aFrame); if (border && padding) { if (eStyleUnit_Coord == border->mBorder.GetLeftUnit()) { origin.x += border->mBorder.GetLeft(coord).GetCoordValue(); @@ -1993,30 +2019,32 @@ nsComputedDOMStyle::GetAbsoluteFrameRect(nsIFrame *aFrame, nsRect& aRect) aRect.y = origin.y; return res; -} - +} + nsresult -nsComputedDOMStyle::GetStyleData(nsStyleStructID aID, +nsComputedDOMStyle::GetStyleData(nsStyleStructID aID, const nsStyleStruct*& aStyleStruct, - nsIFrame* aFrame) -{ + nsIFrame* aFrame) +{ if(aFrame && !mPseudo) { - aFrame->GetStyleData(aID,aStyleStruct); + aFrame->GetStyleData(aID, aStyleStruct); } else { nsCOMPtr presShell=do_QueryReferent(mPresShellWeak); - + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - + nsCOMPtr pctx; presShell->GetPresContext(getter_AddRefs(pctx)); if(pctx) { nsCOMPtr sctx; if(!mPseudo) { - pctx->ResolveStyleContextFor(mContent, nsnull, PR_FALSE,getter_AddRefs(sctx)); + pctx->ResolveStyleContextFor(mContent, nsnull, PR_FALSE, + getter_AddRefs(sctx)); } else { - pctx->ResolvePseudoStyleContextFor(mContent, mPseudo, nsnull, PR_FALSE,getter_AddRefs(sctx)); + pctx->ResolvePseudoStyleContextFor(mContent, mPseudo, nsnull, PR_FALSE, + getter_AddRefs(sctx)); } if(sctx) { aStyleStruct=sctx->GetStyleData(aID); @@ -2027,23 +2055,23 @@ nsComputedDOMStyle::GetStyleData(nsStyleStructID aID, return NS_OK; } -nsresult +nsresult nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) + nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStylePadding* padding=nsnull; - GetStyleData(eStyleStruct_Padding,(const nsStyleStruct*&)padding,aFrame); + GetStyleData(eStyleStruct_Padding, (const nsStyleStruct*&)padding, aFrame); if(padding) { nsStyleCoord coord; switch(aSide) { case NS_SIDE_TOP: padding->mPadding.GetTop(coord); break; - case NS_SIDE_BOTTOM : + case NS_SIDE_BOTTOM : padding->mPadding.GetBottom(coord); break; case NS_SIDE_LEFT : padding->mPadding.GetLeft(coord); break; @@ -2052,8 +2080,8 @@ nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, default: NS_WARNING("double check the side"); break; - } - + } + switch(coord.GetUnit()) { case eStyleUnit_Coord: val->SetTwips(coord.GetCoordValue()); break; @@ -2065,7 +2093,7 @@ nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, nsRect rect; parent->GetRect(rect); val->SetTwips(nscoord(coord.GetPercentValue() * rect.width)); - break; // intentionally breaking here... + break; // intentionally breaking here... } } default: @@ -2073,27 +2101,28 @@ nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, break; } } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult +nsresult nsComputedDOMStyle::GetBorderWidthFor(PRUint8 aSide, - nsIFrame *aFrame, + nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleBorder* border = nsnull; - GetStyleData(eStyleStruct_Border,(const nsStyleStruct*&)border,aFrame); - + GetStyleData(eStyleStruct_Border, (const nsStyleStruct*&)border, aFrame); + if(border) { nsStyleCoord coord; switch(aSide) { case NS_SIDE_TOP: border->mBorder.GetTop(coord); break; - case NS_SIDE_BOTTOM : + case NS_SIDE_BOTTOM : border->mBorder.GetBottom(coord); break; case NS_SIDE_LEFT : border->mBorder.GetLeft(coord); break; @@ -2113,60 +2142,63 @@ nsComputedDOMStyle::GetBorderWidthFor(PRUint8 aSide, case eStyleUnit_Chars: { const nsCString& width= - nsCSSProps::SearchKeywordTable(coord.GetIntValue(),nsCSSProps::kBorderWidthKTable); + nsCSSProps::SearchKeywordTable(coord.GetIntValue(), + nsCSSProps::kBorderWidthKTable); val->SetString(width); break; } default: NS_WARNING("double check the unit"); - break; + break; } } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult +nsresult nsComputedDOMStyle::GetBorderColorFor(PRUint8 aSide, - nsIFrame *aFrame, + nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleBorder* border = nsnull; - GetStyleData(eStyleStruct_Border,(const nsStyleStruct*&)border,aFrame); - + GetStyleData(eStyleStruct_Border, (const nsStyleStruct*&)border, aFrame); + if(border) { - nscolor color; - border->GetBorderColor(aSide,color); + nscolor color; + border->GetBorderColor(aSide, color); nsAutoString hex; - ColorToHex(color,hex); + ColorToHex(color, hex); val->SetString(hex); } else { val->SetString(""); } - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult +nsresult nsComputedDOMStyle::GetMarginWidthFor(PRUint8 aSide, nsIFrame *aFrame, - nsIDOMCSSPrimitiveValue*& aValue) + nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); const nsStyleMargin* margin=nsnull; - GetStyleData(eStyleStruct_Margin,(const nsStyleStruct*&)margin,aFrame); - + GetStyleData(eStyleStruct_Margin, (const nsStyleStruct*&)margin, aFrame); + if(margin) { nsStyleCoord coord; switch(aSide) { case NS_SIDE_TOP : margin->mMargin.GetTop(coord); break; - case NS_SIDE_BOTTOM : + case NS_SIDE_BOTTOM : margin->mMargin.GetBottom(coord); break; case NS_SIDE_LEFT : margin->mMargin.GetLeft(coord); break; @@ -2175,8 +2207,8 @@ nsComputedDOMStyle::GetMarginWidthFor(PRUint8 aSide, default: NS_WARNING("double check the side"); break; - } - + } + switch(coord.GetUnit()) { case eStyleUnit_Coord: val->SetTwips(coord.GetCoordValue()); break; @@ -2185,10 +2217,10 @@ nsComputedDOMStyle::GetMarginWidthFor(PRUint8 aSide, nsIFrame* parent=nsnull; aFrame->GetParent(&parent); if(parent) { - nsRect rect; + nsRect rect; parent->GetRect(rect); val->SetTwips(nscoord(coord.GetPercentValue() * rect.width)); - break; // intentionally breaking here... + break; // intentionally breaking here... } } default: @@ -2196,31 +2228,34 @@ nsComputedDOMStyle::GetMarginWidthFor(PRUint8 aSide, break; } } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } -nsresult +nsresult nsComputedDOMStyle::GetBorderStyleFor(PRUint8 aSide, - nsIFrame *aFrame, + nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue) { nsROCSSPrimitiveValue* val=GetROCSSPrimitiveValue(); NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY); - + const nsStyleBorder* border = nsnull; - GetStyleData(eStyleStruct_Border,(const nsStyleStruct*&)border,aFrame);; + GetStyleData(eStyleStruct_Border, (const nsStyleStruct*&)border, aFrame); if(border) { const nsCString& style= - nsCSSProps::SearchKeywordTable(border->GetBorderStyle(aSide),nsCSSProps::kBorderStyleKTable); + nsCSSProps::SearchKeywordTable(border->GetBorderStyle(aSide), + nsCSSProps::kBorderStyleKTable); val->SetString(style); } else { val->SetString(""); } - - return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),(void **)&aValue); + + return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue), + (void **)&aValue); } nsresult diff --git a/layout/style/nsDOMCSSDeclaration.cpp b/layout/style/nsDOMCSSDeclaration.cpp index ca1ebfe0c13..a10f72e1926 100644 --- a/layout/style/nsDOMCSSDeclaration.cpp +++ b/layout/style/nsDOMCSSDeclaration.cpp @@ -29,87 +29,40 @@ #include "nsCOMPtr.h" #include "nsIURL.h" +#include "nsContentUtils.h" + + nsDOMCSSDeclaration::nsDOMCSSDeclaration() { NS_INIT_REFCNT(); - mScriptObject = nsnull; } nsDOMCSSDeclaration::~nsDOMCSSDeclaration() { } + +// XPConnect interface list for nsDOMCSSDeclaration +NS_CLASSINFO_MAP_BEGIN(CSSStyleDeclaration) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleDeclaration) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSS2Properties) + NS_CLASSINFO_MAP_ENTRY(nsIDOMNSCSS2Properties) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for CSSStyleSheetImpl +NS_INTERFACE_MAP_BEGIN(nsDOMCSSDeclaration) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleDeclaration) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSS2Properties) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSCSS2Properties) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSS2Properties) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleDeclaration) +NS_INTERFACE_MAP_END + + NS_IMPL_ADDREF(nsDOMCSSDeclaration); NS_IMPL_RELEASE(nsDOMCSSDeclaration); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - -NS_IMETHODIMP -nsDOMCSSDeclaration::QueryInterface(REFNSIID aIID, - void** aInstancePtr) -{ - NS_PRECONDITION(nsnull != aInstancePtr, "null ptr"); - if (nsnull == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsIDOMCSS2Properties))) { - nsIDOMCSS2Properties *tmp = this; - AddRef(); - *aInstancePtr = (void*) tmp; - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMCSSStyleDeclaration))) { - nsIDOMCSSStyleDeclaration *tmp = this; - AddRef(); - *aInstancePtr = (void*) tmp; - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner *tmp = this; - AddRef(); - *aInstancePtr = (void*) tmp; - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - nsIDOMCSSStyleDeclaration *tmp = this; - nsISupports *tmp2 = tmp; - AddRef(); - *aInstancePtr = (void*) tmp2; - return NS_OK; - } - return NS_NOINTERFACE; -} - -NS_IMETHODIMP -nsDOMCSSDeclaration::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - nsCOMPtr parent; - - res = GetParent(getter_AddRefs(parent)); - if (NS_OK == res) { - nsISupports *supports = (nsISupports *)(nsIDOMCSS2Properties *)this; - // XXX Should be done through factory - res = NS_NewScriptCSS2Properties(aContext, - supports, - parent, - (void**)&mScriptObject); - } - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -nsDOMCSSDeclaration::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} NS_IMETHODIMP nsDOMCSSDeclaration::GetCssText(nsAWritableString& aCssText) diff --git a/layout/style/nsDOMCSSDeclaration.h b/layout/style/nsDOMCSSDeclaration.h index d9fbc15d960..965f75bf3cc 100644 --- a/layout/style/nsDOMCSSDeclaration.h +++ b/layout/style/nsDOMCSSDeclaration.h @@ -23,15 +23,15 @@ #define nsDOMCSSSDeclaration_h___ #include "nsISupports.h" +#include "nsIDOMCSSStyleDeclaration.h" #include "nsIDOMCSS2Properties.h" -#include "nsIScriptObjectOwner.h" class nsICSSDeclaration; class nsICSSParser; class nsIURI; -class nsDOMCSSDeclaration : public nsIDOMCSS2Properties, - public nsIScriptObjectOwner +class nsDOMCSSDeclaration : public nsIDOMCSSStyleDeclaration, + public nsIDOMNSCSS2Properties { public: nsDOMCSSDeclaration(); @@ -52,15 +52,13 @@ public: NS_IMETHOD GetPropertyPriority(const nsAReadableString& aPropertyName, nsAWritableString& aReturn); NS_IMETHOD SetProperty(const nsAReadableString& aPropertyName, - const nsAReadableString& aValue, const nsAReadableString& aPriority); + const nsAReadableString& aValue, + const nsAReadableString& aPriority); NS_IMETHOD Item(PRUint32 aIndex, nsAWritableString& aReturn); - NS_DECL_IDOMCSS2PROPERTIES - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMCSS2PROPERTIES + NS_DECL_NSIDOMNSCSS2PROPERTIES virtual void DropReference() = 0; virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl, @@ -75,8 +73,6 @@ public: protected: virtual ~nsDOMCSSDeclaration(); - - void *mScriptObject; }; #endif // nsDOMCSSDeclaration_h___ diff --git a/layout/style/nsIComputedDOMStyle.h b/layout/style/nsIComputedDOMStyle.h index 9ee1025e1aa..16096fada3f 100644 --- a/layout/style/nsIComputedDOMStyle.h +++ b/layout/style/nsIComputedDOMStyle.h @@ -23,7 +23,7 @@ #define nsIComputedDOMStyle_h___ #include "nslayout.h" -#include "nsIDOMCSS2Properties.h" +#include "nsIDOMCSSStyleDeclaration.h" class nsIDOMElement; class nsIPresShell; diff --git a/layout/style/nsROCSSPrimitiveValue.cpp b/layout/style/nsROCSSPrimitiveValue.cpp index 781f995673f..b515fa34e71 100644 --- a/layout/style/nsROCSSPrimitiveValue.cpp +++ b/layout/style/nsROCSSPrimitiveValue.cpp @@ -25,11 +25,10 @@ #include "nsCOMPtr.h" #include "nsDOMError.h" #include "prprf.h" - +#include "nsContentUtils.h" nsROCSSPrimitiveValue::nsROCSSPrimitiveValue(nsISupports *aOwner, float aT2P) - : mType(CSS_PX), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P), - mScriptObject(nsnull) + : mType(CSS_PX), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P) { NS_INIT_REFCNT(); } @@ -44,45 +43,23 @@ NS_IMPL_ADDREF(nsROCSSPrimitiveValue); NS_IMPL_RELEASE(nsROCSSPrimitiveValue); +// XPConnect interface list for nsROCSSPrimitiveValue +NS_CLASSINFO_MAP_BEGIN(ROCSSPrimitiveValue) + NS_CLASSINFO_MAP_ENTRY(nsIDOMCSSPrimitiveValue) +NS_CLASSINFO_MAP_END + + +// QueryInterface implementation for nsROCSSPrimitiveValue NS_INTERFACE_MAP_BEGIN(nsROCSSPrimitiveValue) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPrimitiveValue) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCSSPrimitiveValue) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ROCSSPrimitiveValue) NS_INTERFACE_MAP_END -// nsIScriptObjectOwner - -NS_IMETHODIMP -nsROCSSPrimitiveValue::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - if (!mScriptObject) { - nsISupports *supports = NS_STATIC_CAST(nsIDOMCSSPrimitiveValue *, this); - - // XXX Should be done through factory - res = NS_NewScriptCSSPrimitiveValue(aContext, supports, mOwner, - &mScriptObject); - } - - *aScriptObject = mScriptObject; - - return res; -} - - // nsIDOMCSSValue -NS_IMETHODIMP -nsROCSSPrimitiveValue::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - NS_IMETHODIMP nsROCSSPrimitiveValue::GetCssText(nsAWritableString& aCssText) diff --git a/layout/style/nsROCSSPrimitiveValue.h b/layout/style/nsROCSSPrimitiveValue.h index 6fff2af2b28..46a5e61927b 100644 --- a/layout/style/nsROCSSPrimitiveValue.h +++ b/layout/style/nsROCSSPrimitiveValue.h @@ -32,21 +32,16 @@ #include "nsDOMError.h" -class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue, - public nsIScriptObjectOwner +class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue { public: NS_DECL_ISUPPORTS // nsIDOMCSSPrimitiveValue - NS_DECL_IDOMCSSPRIMITIVEVALUE + NS_DECL_NSIDOMCSSPRIMITIVEVALUE // nsIDOMCSSValue - NS_DECL_IDOMCSSVALUE - - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); + NS_DECL_NSIDOMCSSVALUE // nsROCSSPrimitiveValue nsROCSSPrimitiveValue(nsISupports *aOwner, float aP2T); @@ -78,8 +73,6 @@ private: nsISupports *mOwner; float mT2P; - - void* mScriptObject; }; #endif /* nsROCSSPrimitiveValue_h___ */