From 9dc580c231f48a3b13935508baa79419cdbe3a6c Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Tue, 4 Nov 2008 07:20:44 -0800 Subject: [PATCH 01/10] Bug 461827. GetClassName fixup in DOM. r=blassey sr=jst --- dom/src/base/nsDOMClassInfo.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index b41aa24c844..4a9fa65ccb7 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -152,16 +152,16 @@ #ifdef OJI // HTMLAppletElement helper includes #include "nsIJVMManager.h" - -// Oh, did I mention that I hate Microsoft for doing this to me? -#ifndef WINCE -#undef GetClassName -#endif - #include "nsILiveConnectManager.h" #include "nsIJVMPluginInstance.h" #endif +// Oh, did I mention that I hate Microsoft for doing this to me? +#ifdef WINCE +#undef GetClassName +#endif + + // HTMLOptionsCollection includes #include "nsIDOMHTMLOptionElement.h" #include "nsIDOMNSHTMLOptionElement.h" From 064e0b307fc9109bab3138061e0121f4e0ff6b11 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Tue, 4 Nov 2008 07:22:07 -0800 Subject: [PATCH 02/10] Bug 461827. Winnls.h include is no needed after removal of the wince shunt library. r/sr=stuart --- intl/locale/src/windows/nsCollationWin.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/intl/locale/src/windows/nsCollationWin.cpp b/intl/locale/src/windows/nsCollationWin.cpp index bd2d453661d..81d726c4ab5 100644 --- a/intl/locale/src/windows/nsCollationWin.cpp +++ b/intl/locale/src/windows/nsCollationWin.cpp @@ -49,11 +49,7 @@ #include "plstr.h" #include -#ifdef WINCE -#include -#else #undef CompareString -#endif NS_IMPL_ISUPPORTS1(nsCollationWin, nsICollation) From f8bc2af1eacb257fb214473f63de0ad2785d9751 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Tue, 4 Nov 2008 07:23:54 -0800 Subject: [PATCH 03/10] Bug 461832 - windows mobile bustage on file protocol handler. r=blassey sr=bz --- netwerk/protocol/file/src/nsFileProtocolHandler.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/netwerk/protocol/file/src/nsFileProtocolHandler.cpp b/netwerk/protocol/file/src/nsFileProtocolHandler.cpp index b7189a1b9aa..f0a43a00b76 100644 --- a/netwerk/protocol/file/src/nsFileProtocolHandler.cpp +++ b/netwerk/protocol/file/src/nsFileProtocolHandler.cpp @@ -51,8 +51,13 @@ // URL file handling, copied and modified from xpfe/components/bookmarks/src/nsBookmarksService.cpp #ifdef XP_WIN +#ifndef WINCE +// Windows mobile does not support internet shortcuts including +// CLSID_InternetShortcut and IUniformResourceLocator used in +// this file #include #include +#endif #include "nsIFileURL.h" #ifdef CompareString #undef CompareString From 4e7a24bda98b35028e186fe494f0a352bf61d496 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Tue, 4 Nov 2008 07:43:45 -0800 Subject: [PATCH 04/10] Bug 462911 - support NS_PRINTING in gfx / cairo. r=vlad --- gfx/cairo/README | 3 +++ gfx/cairo/cairo/src/Makefile.in | 9 ++++++-- gfx/cairo/cairo/src/cairo-win32-surface.c | 3 ++- gfx/cairo/disable-printing.patch | 27 +++++++++++++++++++++++ gfx/thebes/src/gfxWindowsSurface.cpp | 5 +++-- 5 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 gfx/cairo/disable-printing.patch diff --git a/gfx/cairo/README b/gfx/cairo/README index fbffdd0abd6..8b03ef67a85 100644 --- a/gfx/cairo/README +++ b/gfx/cairo/README @@ -32,3 +32,6 @@ tmpfile_wince.patch: Make Windows CE use tmpfile() on windows mobile due to the endian.patch: include cairo-platform.h for endian macros +==== disable printing patch ==== + +disable-printing.patch: allows us to use NS_PRINTING to disable printing. diff --git a/gfx/cairo/cairo/src/Makefile.in b/gfx/cairo/cairo/src/Makefile.in index d5ff48ba523..21d2c0bb099 100644 --- a/gfx/cairo/cairo/src/Makefile.in +++ b/gfx/cairo/cairo/src/Makefile.in @@ -147,8 +147,13 @@ PS_EXPORTS = cairo-ps.h ifeq ($(MOZ_WIDGET_TOOLKIT),windows) CSRCS += cairo-win32-font.c \ - cairo-win32-surface.c \ - cairo-win32-printing-surface.c + cairo-win32-surface.c + +ifdef NS_PRINTING +DEFINES += CAIRO_OMIT_WIN32_PRINTING +CSRCS += cairo-win32-printing-surface.c +endif + EXPORTS += cairo-win32.h CSRCS += $(PSPDF_BASE_CSRCS) $(PDF_CSRCS) EXPORTS += $(PDF_EXPORTS) diff --git a/gfx/cairo/cairo/src/cairo-win32-surface.c b/gfx/cairo/cairo/src/cairo-win32-surface.c index b66bd359c27..2a8c0723488 100644 --- a/gfx/cairo/cairo/src/cairo-win32-surface.c +++ b/gfx/cairo/cairo/src/cairo-win32-surface.c @@ -1897,11 +1897,12 @@ cairo_win32_surface_get_dc (cairo_surface_t *surface) target = _cairo_paginated_surface_get_target (surface); +#ifndef CAIRO_OMIT_WIN32_PRINTING if (_cairo_surface_is_win32_printing (target)) { winsurf = (cairo_win32_surface_t *) target; - return winsurf->dc; } +#endif } return NULL; diff --git a/gfx/cairo/disable-printing.patch b/gfx/cairo/disable-printing.patch new file mode 100644 index 00000000000..c1006d81913 --- /dev/null +++ b/gfx/cairo/disable-printing.patch @@ -0,0 +1,27 @@ +diff --git a/gfx/cairo/cairo/src/cairo-win32-surface.c b/gfx/cairo/cairo/src/cairo-win32-surface.c +--- a/gfx/cairo/cairo/src/cairo-win32-surface.c ++++ b/gfx/cairo/cairo/src/cairo-win32-surface.c +@@ -1892,21 +1892,22 @@ cairo_win32_surface_get_dc (cairo_surfac + return winsurf->dc; + } + + if (_cairo_surface_is_paginated (surface)) { + cairo_surface_t *target; + + target = _cairo_paginated_surface_get_target (surface); + ++#ifndef CAIRO_OMIT_WIN32_PRINTING + if (_cairo_surface_is_win32_printing (target)) { + winsurf = (cairo_win32_surface_t *) target; +- + return winsurf->dc; + } ++#endif + } + + return NULL; + } + + /** + * cairo_win32_surface_get_image + * @surface: a #cairo_surface_t diff --git a/gfx/thebes/src/gfxWindowsSurface.cpp b/gfx/thebes/src/gfxWindowsSurface.cpp index 5c4df331ef5..8aef1848251 100644 --- a/gfx/thebes/src/gfxWindowsSurface.cpp +++ b/gfx/thebes/src/gfxWindowsSurface.cpp @@ -57,12 +57,13 @@ gfxWindowsSurface::gfxWindowsSurface(HDC dc, PRUint32 flags) : if (flags & FLAG_TAKE_DC) mOwnsDC = PR_TRUE; +#ifdef NS_PRINTING if (flags & FLAG_FOR_PRINTING) { Init(cairo_win32_printing_surface_create(mDC)); mForPrinting = PR_TRUE; - } else { + } else +#endif Init(cairo_win32_surface_create(mDC)); - } } gfxWindowsSurface::gfxWindowsSurface(const gfxIntSize& size, gfxImageFormat imageFormat) : From 34cb8ef32fe9fc3132b4bd0df58414558f27fe38 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Tue, 4 Nov 2008 08:58:42 -0800 Subject: [PATCH 05/10] Fix build bustage in 462911. We need to either build printing or define CAIRO_OMIT_WIN32_PRINTING --- gfx/cairo/cairo/src/Makefile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gfx/cairo/cairo/src/Makefile.in b/gfx/cairo/cairo/src/Makefile.in index 21d2c0bb099..a3fdcc550c9 100644 --- a/gfx/cairo/cairo/src/Makefile.in +++ b/gfx/cairo/cairo/src/Makefile.in @@ -150,8 +150,9 @@ CSRCS += cairo-win32-font.c \ cairo-win32-surface.c ifdef NS_PRINTING -DEFINES += CAIRO_OMIT_WIN32_PRINTING CSRCS += cairo-win32-printing-surface.c +else +DEFINES += CAIRO_OMIT_WIN32_PRINTING endif EXPORTS += cairo-win32.h From ce0671e4ede7245006f57c5ac6f825ee086b80a0 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Tue, 4 Nov 2008 10:08:21 -0800 Subject: [PATCH 06/10] GetClassName is a problem also on XP_WIN. Bug 461827. GetClassName fixup in DOM. r=blassey sr=jst --- dom/src/base/nsDOMClassInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index 4a9fa65ccb7..47466c9dd30 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -157,7 +157,7 @@ #endif // Oh, did I mention that I hate Microsoft for doing this to me? -#ifdef WINCE +#ifdef XP_WIN #undef GetClassName #endif From af9c4cf810029bfbe3ff75951c7af4f7a62720a2 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Tue, 4 Nov 2008 10:15:02 -0800 Subject: [PATCH 07/10] Quick follow up to 461827. Removing unneeded ifdef WINCE in the last file that has wince specific stuff wrt GetClassName. r=me --- content/html/content/src/nsHTMLSharedObjectElement.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/html/content/src/nsHTMLSharedObjectElement.cpp b/content/html/content/src/nsHTMLSharedObjectElement.cpp index f17e8a3ced1..348e99c4e8e 100644 --- a/content/html/content/src/nsHTMLSharedObjectElement.cpp +++ b/content/html/content/src/nsHTMLSharedObjectElement.cpp @@ -51,7 +51,7 @@ // XXX this is to get around conflicts with windows.h defines // introduced through jni.h -#if defined (XP_WIN) && ! defined (WINCE) +#ifdef XP_WIN #undef GetClassName #undef GetObject #endif From 032a5805cfe5c5411565e8ec9df7a368d820867c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A3o=20Gottwald?= Date: Tue, 4 Nov 2008 20:47:46 +0100 Subject: [PATCH 08/10] make Ctrl+Tab test more robust --- browser/base/content/test/browser_ctrlTab.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/browser/base/content/test/browser_ctrlTab.js b/browser/base/content/test/browser_ctrlTab.js index 650387ce5ff..c08353e0f29 100644 --- a/browser/base/content/test/browser_ctrlTab.js +++ b/browser/base/content/test/browser_ctrlTab.js @@ -77,6 +77,9 @@ function test() { function releaseCtrl() EventUtils.synthesizeKey("VK_CONTROL", { type: "keyup" }); + function isOpen() + ctrlTab.panel.state == "showing" || ctrlTab.panel.state == "open"; + function assertTabs(aTabs) { var tabs = gBrowser.mTabs.length; if (tabs != aTabs) { @@ -110,7 +113,7 @@ function test() { } if (tabCount > 2) { - ok(ctrlTab.panel.state == "showing" || ctrlTab.panel.state == "open", + ok(isOpen(), "With " + tabCount + " tabs open, Ctrl+Tab opens the preview panel"); is(ctrlTab.label.value, gBrowser.mTabs[expectedIndex].label, @@ -118,10 +121,10 @@ function test() { releaseCtrl(); - ok(ctrlTab.panel.state == "hiding" || ctrlTab.panel.state == "closed", + ok(!isOpen(), "Releasing Ctrl closes the preview panel"); } else { - ok(ctrlTab.panel.state == "hiding" || ctrlTab.panel.state == "closed", + ok(!isOpen(), "With " + tabCount + " tabs open, Ctrl+Tab doesn't open the preview panel"); } From 9d268931907c3b83602f0ae3285c4e759bcc6c8f Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Tue, 4 Nov 2008 20:54:08 +0100 Subject: [PATCH 09/10] Backed out changeset 81c0a2ec449f to fix orange --- content/base/public/nsIContent.h | 13 ++ content/base/public/nsIDocument.h | 8 +- content/base/public/nsINode.h | 18 +- content/base/src/nsContentList.cpp | 1 - content/base/src/nsContentList.h | 4 +- content/base/src/nsContentUtils.cpp | 9 + content/base/src/nsDOMAttribute.cpp | 1 - content/base/src/nsDocument.cpp | 55 +++++- content/base/src/nsDocument.h | 4 + content/base/src/nsGenericDOMDataNode.cpp | 4 +- content/base/src/nsGenericElement.cpp | 5 +- content/base/src/nsGenericElement.h | 24 +-- content/base/src/nsNodeUtils.cpp | 15 +- content/base/src/nsXMLHttpRequest.cpp | 20 +- content/base/src/nsXMLHttpRequest.h | 34 +--- content/xbl/src/nsXBLProtoImpl.cpp | 8 +- dom/public/Makefile.in | 1 - dom/public/nsWrapperCache.h | 137 ------------- dom/src/base/nsDOMClassInfo.cpp | 224 ++++++---------------- dom/src/base/nsDOMClassInfo.h | 23 +-- dom/src/base/nsGlobalWindow.cpp | 13 ++ dom/src/base/nsJSEnvironment.cpp | 3 +- js/src/xpconnect/src/xpcconvert.cpp | 22 +-- js/src/xpconnect/src/xpcwrappednative.cpp | 55 ++---- 24 files changed, 224 insertions(+), 477 deletions(-) delete mode 100644 dom/public/nsWrapperCache.h diff --git a/content/base/public/nsIContent.h b/content/base/public/nsIContent.h index d9d2e3c10c4..bc6772c89b1 100644 --- a/content/base/public/nsIContent.h +++ b/content/base/public/nsIContent.h @@ -902,6 +902,15 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID) nsContentUtils::TraverseListenerManager(tmp, cb); \ } +#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_PRESERVED_WRAPPER \ + { \ + nsISupports *preservedWrapper = nsnull; \ + if (tmp->GetOwnerDoc()) \ + preservedWrapper = tmp->GetOwnerDoc()->GetReference(tmp); \ + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[preserved wrapper]");\ + cb.NoteXPCOMChild(preservedWrapper); \ + } + #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA \ if (tmp->HasProperties()) { \ nsNodeUtils::TraverseUserData(tmp, cb); \ @@ -913,6 +922,10 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID) tmp->UnsetFlags(NODE_HAS_LISTENERMANAGER); \ } +#define NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER \ + if (tmp->GetOwnerDoc()) \ + tmp->GetOwnerDoc()->RemoveReference(tmp); + #define NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA \ if (tmp->HasProperties()) { \ nsNodeUtils::UnlinkUserData(tmp); \ diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index ac55a30e722..c78ac3fd62f 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -96,8 +96,8 @@ class nsFrameLoader; // IID for the nsIDocument interface #define NS_IDOCUMENT_IID \ -{ 0x92b19d1c, 0x8f37, 0x4d4b, \ - { 0xa3, 0x42, 0xb5, 0xc6, 0x8b, 0x54, 0xde, 0x6c } } +{ 0x6304ae8e, 0x2634, 0x45ed, \ + { 0x9e, 0x09, 0x83, 0x09, 0x5b, 0x46, 0x72, 0x8b } } // Flag for AddStyleSheet(). #define NS_STYLESHEET_FROM_CATALOG (1 << 0) @@ -677,6 +677,10 @@ public: virtual void ResetToURI(nsIURI *aURI, nsILoadGroup* aLoadGroup, nsIPrincipal* aPrincipal) = 0; + virtual void AddReference(void *aKey, nsISupports *aReference) = 0; + virtual nsISupports *GetReference(void *aKey) = 0; + virtual void RemoveReference(void *aKey) = 0; + /** * Set the container (docshell) for this document. */ diff --git a/content/base/public/nsINode.h b/content/base/public/nsINode.h index 9d6f8cf8704..9b91448ee0d 100644 --- a/content/base/public/nsINode.h +++ b/content/base/public/nsINode.h @@ -44,7 +44,6 @@ #include "nsTObserverArray.h" #include "nsINodeInfo.h" #include "nsCOMPtr.h" -#include "nsWrapperCache.h" class nsIContent; class nsIDocument; @@ -151,17 +150,16 @@ inline nsINode* NODE_FROM(C& aContent, D& aDocument) // IID for the nsINode interface #define NS_INODE_IID \ -{ 0x0f7b2557, 0xa09d, 0x468f, \ - { 0x93, 0x92, 0xf1, 0xf1, 0xd1, 0xfa, 0x31, 0x78 } } +{ 0x2593b0d5, 0x9a06, 0x4d6b, \ + { 0x9a, 0x10, 0xb1, 0x39, 0x9f, 0x1b, 0xa0, 0x8e } } + /** * An internal interface that abstracts some DOMNode-related parts that both * nsIContent and nsIDocument share. An instance of this interface has a list * of nsIContent children and provides access to them. */ -class nsINode : public nsPIDOMEventTarget, - public nsWrapperCache -{ +class nsINode : public nsPIDOMEventTarget { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_INODE_IID) @@ -852,12 +850,4 @@ extern const nsIID kThisPtrOffsetsSID; NS_DEFINE_STATIC_IID_ACCESSOR(nsINode, NS_INODE_IID) - -#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_PRESERVED_WRAPPER \ - tmp->TraverseWrapper(cb); - -#define NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER \ - tmp->ClearWrapper(); - - #endif /* nsINode_h___ */ diff --git a/content/base/src/nsContentList.cpp b/content/base/src/nsContentList.cpp index 6ad28c08468..0567dc19e53 100644 --- a/content/base/src/nsContentList.cpp +++ b/content/base/src/nsContentList.cpp @@ -358,7 +358,6 @@ nsContentList::~nsContentList() // QueryInterface implementation for nsContentList NS_INTERFACE_TABLE_HEAD(nsContentList) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_NODELIST_OFFSET_AND_INTERFACE_TABLE_BEGIN(nsContentList) NS_CONTENT_LIST_INTERFACES(nsContentList) NS_INTERFACE_TABLE_ENTRY(nsContentList, nsIHTMLCollection) diff --git a/content/base/src/nsContentList.h b/content/base/src/nsContentList.h index 4a60b3fdf9b..1f65c6de29b 100644 --- a/content/base/src/nsContentList.h +++ b/content/base/src/nsContentList.h @@ -54,7 +54,6 @@ #include "nsIAtom.h" #include "nsINameSpaceManager.h" #include "nsCycleCollectionParticipant.h" -#include "nsWrapperCache.h" // Magic namespace id that means "match all namespaces". This is // negative so it won't collide with actual namespace constants. @@ -183,8 +182,7 @@ protected: class nsContentList : public nsBaseContentList, protected nsContentListKey, public nsIHTMLCollection, - public nsStubMutationObserver, - public nsWrapperCache + public nsStubMutationObserver { public: NS_DECL_ISUPPORTS_INHERITED diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 514849a2302..1a127741e61 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -1119,6 +1119,15 @@ nsContentUtils::doReparentContentWrapper(nsIContent *aNode, getter_AddRefs(old_wrapper)); NS_ENSURE_SUCCESS(rv, rv); + if (aOldDocument) { + nsCOMPtr old_ref = aOldDocument->GetReference(aNode); + if (old_ref) { + // Transfer the reference from aOldDocument to aNewDocument + aOldDocument->RemoveReference(aNode); + aNewDocument->AddReference(aNode, old_ref); + } + } + // Whether or not aChild is already wrapped we must iterate through // its descendants since there's no guarantee that a descendant isn't // wrapped even if this child is not wrapped. That used to be true diff --git a/content/base/src/nsDOMAttribute.cpp b/content/base/src/nsDOMAttribute.cpp index c809d3fb53d..e292811f731 100644 --- a/content/base/src/nsDOMAttribute.cpp +++ b/content/base/src/nsDOMAttribute.cpp @@ -101,7 +101,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMAttribute) NS_IMPL_CYCLE_COLLECTION_UNLINK_END // QueryInterface implementation for nsDOMAttribute NS_INTERFACE_TABLE_HEAD(nsDOMAttribute) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_NODE_INTERFACE_TABLE7(nsDOMAttribute, nsIDOMAttr, nsIAttribute, nsINode, nsIDOMNode, nsIDOM3Node, nsIDOM3Attr, nsPIDOMEventTarget) diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 11b8504744f..f0245899e65 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -1567,12 +1567,13 @@ nsDocument::~nsDocument() mBoxObjectTable->EnumerateRead(ClearAllBoxObjects, nsnull); delete mBoxObjectTable; } + + delete mContentWrapperHash; } NS_IMPL_CYCLE_COLLECTION_CLASS(nsDocument) NS_INTERFACE_TABLE_HEAD(nsDocument) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_DOCUMENT_INTERFACE_TABLE_BEGIN(nsDocument) NS_INTERFACE_TABLE_ENTRY(nsDocument, nsINode) NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDocument) @@ -1752,7 +1753,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocument) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mCatalogSheets) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mVisitednessChangedURIs) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_PRESERVED_WRAPPER + // Traverse any associated preserved wrapper. + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[preserved wrapper]"); + cb.NoteXPCOMChild(tmp->GetReference(tmp)); if (tmp->mSubDocuments && tmp->mSubDocuments->ops) { PL_DHashTableEnumerate(tmp->mSubDocuments, SubDocTraverser, &cb); @@ -1783,9 +1786,11 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA - tmp->mParentDocument = nsnull; + // Drop the content hash. + delete tmp->mContentWrapperHash; + tmp->mContentWrapperHash = nsnull; - NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER + tmp->mParentDocument = nsnull; // nsDocument has a pretty complex destructor, so we're going to // assume that *most* cycles you actually want to break somewhere @@ -6223,6 +6228,41 @@ nsDocument::FlushPendingNotifications(mozFlushType aType) } } +void +nsDocument::AddReference(void *aKey, nsISupports *aReference) +{ + if (mScriptGlobalObject) { + if (!mContentWrapperHash) { + mContentWrapperHash = new nsInterfaceHashtable; + if (mContentWrapperHash) { + mContentWrapperHash->Init(10); + } + } + + if (mContentWrapperHash) + mContentWrapperHash->Put(aKey, aReference); + } +} + +nsISupports* +nsDocument::GetReference(void *aKey) +{ + // NB: This method is part of content cycle collection, + // and must *not* Addref its return value. + + if (mContentWrapperHash) + return mContentWrapperHash->GetWeak(aKey); + return nsnull; +} + +void +nsDocument::RemoveReference(void *aKey) +{ + if (mContentWrapperHash) { + mContentWrapperHash->Remove(aKey); + } +} + nsIScriptEventManager* nsDocument::GetScriptEventManager() { @@ -6833,6 +6873,13 @@ nsDocument::Destroy() // leak-fixing if we fix DocumentViewerImpl to do cycle-collection, but // tearing down all those frame trees right now is the right thing to do. mExternalResourceMap.Shutdown(); + + // XXX We really should let cycle collection do this, but that currently still + // leaks (see https://bugzilla.mozilla.org/show_bug.cgi?id=406684). + // When we start relying on cycle collection again we should remove the + // check for mScriptGlobalObject in AddReference. + delete mContentWrapperHash; + mContentWrapperHash = nsnull; } void diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 1cdf14b563f..e83914bbb20 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -750,6 +750,9 @@ public: nsIStyleRule* aStyleRule); virtual void FlushPendingNotifications(mozFlushType aType); + virtual void AddReference(void *aKey, nsISupports *aReference); + virtual nsISupports *GetReference(void *aKey); + virtual void RemoveReference(void *aKey); virtual nsIScriptEventManager* GetScriptEventManager(); virtual void SetXMLDeclaration(const PRUnichar *aVersion, const PRUnichar *aEncoding, @@ -1155,6 +1158,7 @@ protected: PRUint8 mIdMissCount; nsInterfaceHashtable *mBoxObjectTable; + nsInterfaceHashtable *mContentWrapperHash; // The channel that got passed to StartDocumentLoad(), if any nsCOMPtr mChannel; diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp index e6856fddc59..70e8eb00e8f 100644 --- a/content/base/src/nsGenericDOMDataNode.cpp +++ b/content/base/src/nsGenericDOMDataNode.cpp @@ -105,9 +105,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericDOMDataNode) NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_INTERFACE_MAP_BEGIN(nsGenericDOMDataNode) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsGenericDOMDataNode) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGenericDOMDataNode) NS_INTERFACE_MAP_ENTRY(nsIContent) NS_INTERFACE_MAP_ENTRY(nsINode) NS_INTERFACE_MAP_ENTRY(nsPIDOMEventTarget) diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 4010ccfdf84..061ca3ce60b 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -462,7 +462,6 @@ NS_IMPL_ADDREF(nsChildContentList) NS_IMPL_RELEASE(nsChildContentList) NS_INTERFACE_TABLE_HEAD(nsChildContentList) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_NODELIST_OFFSET_AND_INTERFACE_TABLE_BEGIN(nsChildContentList) NS_INTERFACE_TABLE_ENTRY(nsChildContentList, nsINodeList) NS_INTERFACE_TABLE_ENTRY(nsChildContentList, nsIDOMNodeList) @@ -4067,9 +4066,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericElement) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END -NS_INTERFACE_MAP_BEGIN(nsGenericElement) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsGenericElement) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGenericElement) NS_INTERFACE_MAP_ENTRY(nsIContent) NS_INTERFACE_MAP_ENTRY(nsINode) NS_INTERFACE_MAP_ENTRY(nsPIDOMEventTarget) diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index fc02e6e3a52..c3b69c6f597 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -89,8 +89,7 @@ typedef unsigned long PtrBits; * and Item to its existing child list. * @see nsIDOMNodeList */ -class nsChildContentList : public nsINodeList, - public nsWrapperCache +class nsChildContentList : public nsINodeList { public: nsChildContentList(nsINode* aNode) @@ -111,27 +110,6 @@ public: mNode = nsnull; } - nsISupports* GetParentObject() - { - return mNode; - } - - static nsChildContentList* FromSupports(nsISupports* aSupports) - { - nsINodeList* list = static_cast(aSupports); -#ifdef DEBUG - { - nsCOMPtr list_qi = do_QueryInterface(aSupports); - - // If this assertion fires the QI implementation for the object in - // question doesn't use the nsINodeList pointer as the nsISupports - // pointer. That must be fixed, or we'll crash... - NS_ASSERTION(list_qi == list, "Uh, fix QI!"); - } -#endif - return static_cast(list); - } - private: // The node whose children make up the list (weak reference) nsINode* mNode; diff --git a/content/base/src/nsNodeUtils.cpp b/content/base/src/nsNodeUtils.cpp index 6325a3ac5cb..0542147aa76 100755 --- a/content/base/src/nsNodeUtils.cpp +++ b/content/base/src/nsNodeUtils.cpp @@ -564,15 +564,26 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep, } } else if (nodeInfoManager) { + nsCOMPtr oldRef; nsIDocument* oldDoc = aNode->GetOwnerDoc(); - if (oldDoc && aNode->IsNodeOfType(nsINode::eELEMENT)) { - oldDoc->ClearBoxObjectFor(static_cast(aNode)); + if (oldDoc) { + if (aNode->IsNodeOfType(nsINode::eELEMENT)) { + oldDoc->ClearBoxObjectFor(static_cast(aNode)); + } + oldRef = oldDoc->GetReference(aNode); + if (oldRef) { + oldDoc->RemoveReference(aNode); + } } aNode->mNodeInfo.swap(newNodeInfo); nsIDocument* newDoc = aNode->GetOwnerDoc(); if (newDoc) { + if (oldRef) { + newDoc->AddReference(aNode, oldRef); + } + nsPIDOMWindow* window = newDoc->GetInnerWindow(); if (window) { nsCOMPtr elm; diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index 513ea902571..b60f611c36d 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -530,7 +530,13 @@ GetDocumentFromScriptContext(nsIScriptContext *aScriptContext) NS_IMPL_CYCLE_COLLECTION_CLASS(nsXHREventTarget) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXHREventTarget) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_PRESERVED_WRAPPER + if (tmp->mOwner) { + nsCOMPtr doc = + do_QueryInterface(tmp->mOwner->GetExtantDocument()); + if (doc) { + cb.NoteXPCOMChild(doc->GetReference(tmp)); + } + } NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnLoadListener) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnAbortListener) @@ -542,7 +548,13 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXHREventTarget) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXHREventTarget) - NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER + if (tmp->mOwner) { + nsCOMPtr doc = + do_QueryInterface(tmp->mOwner->GetExtantDocument()); + if (doc) { + doc->RemoveReference(tmp); + } + } NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnLoadListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnAbortListener) @@ -553,9 +565,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXHREventTarget) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOwner) NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_INTERFACE_MAP_BEGIN(nsXHREventTarget) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsXHREventTarget) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXHREventTarget) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXMLHttpRequestEventTarget) NS_INTERFACE_MAP_ENTRY(nsIXMLHttpRequestEventTarget) NS_INTERFACE_MAP_ENTRY(nsPIDOMEventTarget) diff --git a/content/base/src/nsXMLHttpRequest.h b/content/base/src/nsXMLHttpRequest.h index 417e35003c4..9291ba57538 100644 --- a/content/base/src/nsXMLHttpRequest.h +++ b/content/base/src/nsXMLHttpRequest.h @@ -73,7 +73,6 @@ #include "nsITimer.h" #include "nsIPrivateDOMEvent.h" #include "nsDOMProgressEvent.h" -#include "nsIScriptGlobalObject.h" class nsILoadGroup; @@ -160,8 +159,7 @@ protected: class nsXHREventTarget : public nsIXMLHttpRequestEventTarget, public nsPIDOMEventTarget, - public nsIDOMNSEventTarget, - public nsWrapperCache + public nsIDOMNSEventTarget { public: nsXHREventTarget() : mLang(nsIProgrammingLanguage::JAVASCRIPT) {} @@ -209,36 +207,6 @@ public: } return NS_OK; } - - void GetParentObject(nsIScriptGlobalObject **aParentObject) - { - if (mOwner) { - CallQueryInterface(mOwner, aParentObject); - } - else { - *aParentObject = nsnull; - } - } - - static nsXHREventTarget* FromSupports(nsISupports* aSupports) - { - nsIXMLHttpRequestEventTarget* target = - static_cast(aSupports); -#ifdef DEBUG - { - nsCOMPtr target_qi = - do_QueryInterface(aSupports); - - // If this assertion fires the QI implementation for the object in - // question doesn't use the nsIXMLHttpRequestEventTarget pointer as the - // nsISupports pointer. That must be fixed, or we'll crash... - NS_ASSERTION(target_qi == target, "Uh, fix QI!"); - } -#endif - - return static_cast(target); - } - protected: nsRefPtr mOnLoadListener; nsRefPtr mOnErrorListener; diff --git a/content/xbl/src/nsXBLProtoImpl.cpp b/content/xbl/src/nsXBLProtoImpl.cpp index 27edd77b567..5c3e6fb70c0 100644 --- a/content/xbl/src/nsXBLProtoImpl.cpp +++ b/content/xbl/src/nsXBLProtoImpl.cpp @@ -151,7 +151,13 @@ nsXBLProtoImpl::InitTargetObjects(nsXBLPrototypeBinding* aBinding, if (NS_FAILED(rv)) return rv; - aBoundElement->PreserveWrapper(); + // Root ourselves in the document. + nsIDocument* doc = aBoundElement->GetOwnerDoc(); + if (doc) { + nsCOMPtr nativeWrapper(do_QueryInterface(wrapper)); + if (nativeWrapper) + doc->AddReference(aBoundElement, nativeWrapper); + } wrapper.swap(*aScriptObjectHolder); diff --git a/dom/public/Makefile.in b/dom/public/Makefile.in index dc1cb6eb273..e2e9f499ef7 100644 --- a/dom/public/Makefile.in +++ b/dom/public/Makefile.in @@ -71,7 +71,6 @@ EXPORTS=nsIScriptContext.h \ nsDOMString.h \ nsDOMJSUtils.h \ nsDOMScriptObjectHolder.h \ - nsWrapperCache.h \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/dom/public/nsWrapperCache.h b/dom/public/nsWrapperCache.h deleted file mode 100644 index c077ee61975..00000000000 --- a/dom/public/nsWrapperCache.h +++ /dev/null @@ -1,137 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla 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/MPL/ - * - * 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 Gecko DOM code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Van der Beken - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsWrapperCache_h___ -#define nsWrapperCache_h___ - -#include "nsCycleCollectionParticipant.h" - -typedef unsigned long PtrBits; - -#define NS_WRAPPERCACHE_IID \ -{ 0x3a51ca81, 0xddab, 0x422c, \ - { 0x95, 0x3a, 0x13, 0x06, 0x28, 0x0e, 0xee, 0x14 } } - -/** - * Class to store the XPCWrappedNative for an object. This can only be used - * with objects that only have one XPCWrappedNative at a time (usually ensured - * by setting an explicit parent in the PreCreate hook for the class). This - * object can be gotten by calling QueryInterface, note that this breaks XPCOM - * rules a bit (this object doesn't derive from nsISupports). - */ -class nsWrapperCache -{ -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_WRAPPERCACHE_IID) - - nsWrapperCache() : mWrapperPtrBits(0) - { - } - ~nsWrapperCache() - { - if (PreservingWrapper()) { - GetWrapper()->Release(); - } - } - - /** - * This method returns an nsIXPConnectWrappedNative, but we want to avoid - * including nsIXPConnect, because we don't want to make everyone require - * JS and XPConnect. - */ - nsISupports* GetWrapper() - { - return reinterpret_cast(mWrapperPtrBits & ~kWrapperBitMask); - } - - /** - * This method takes an nsIXPConnectWrappedNative, but we want to avoid - * including nsIXPConnect, because we don't want to make everyone require - * JS and XPConnect. - */ - void SetWrapper(nsISupports* aWrapper) - { - NS_ASSERTION(!mWrapperPtrBits, "Already have a wrapper!"); - mWrapperPtrBits = reinterpret_cast(aWrapper); - } - - void ClearWrapper() - { - if (PreservingWrapper()) { - GetWrapper()->Release(); - } - mWrapperPtrBits = 0; - } - - void PreserveWrapper() - { - NS_ASSERTION(mWrapperPtrBits, "No wrapper to preserve?"); - if (!PreservingWrapper()) { - NS_ADDREF(reinterpret_cast(mWrapperPtrBits)); - mWrapperPtrBits |= WRAPPER_BIT_PRESERVED; - } - } - - void TraverseWrapper(nsCycleCollectionTraversalCallback &cb) - { - if (PreservingWrapper()) { - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mWrapper"); - cb.NoteXPCOMChild(GetWrapper()); - } - } - -private: - PRBool PreservingWrapper() - { - return mWrapperPtrBits & WRAPPER_BIT_PRESERVED; - } - - enum { WRAPPER_BIT_PRESERVED = 1 << 0 }; - enum { kWrapperBitMask = 0x1 }; - - PtrBits mWrapperPtrBits; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsWrapperCache, NS_WRAPPERCACHE_IID) - -#define NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY \ - if ( aIID.Equals(NS_GET_IID(nsWrapperCache)) ) { \ - *aInstancePtr = static_cast(this); \ - return NS_OK; \ - } - -#endif /* nsWrapperCache_h___ */ diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index 85f435a6ab2..b41aa24c844 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -171,7 +171,6 @@ // ContentList includes #include "nsContentList.h" -#include "nsGenericElement.h" // Event related includes #include "nsIEventListenerManager.h" @@ -213,7 +212,7 @@ #include "nsIDOMLSProgressEvent.h" #include "nsIDOMParser.h" #include "nsIDOMSerializer.h" -#include "nsXMLHttpRequest.h" +#include "nsIXMLHttpRequest.h" // includes needed for the prototype chain interfaces #include "nsIDOMNavigator.h" @@ -490,8 +489,7 @@ static const char kDOMStringBundleURL[] = ((DOM_DEFAULT_SCRIPTABLE_FLAGS | \ nsIXPCScriptable::WANT_GETPROPERTY | \ nsIXPCScriptable::WANT_ADDPROPERTY | \ - nsIXPCScriptable::WANT_SETPROPERTY | \ - nsIXPCScriptable::WANT_FINALIZE) & \ + nsIXPCScriptable::WANT_SETPROPERTY) & \ ~nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY) // We need to let JavaScript QI elements to interfaces that are not in @@ -515,22 +513,15 @@ static const char kDOMStringBundleURL[] = nsIXPCScriptable::WANT_ADDPROPERTY | \ nsIXPCScriptable::WANT_DELPROPERTY | \ nsIXPCScriptable::WANT_GETPROPERTY | \ - nsIXPCScriptable::WANT_ENUMERATE) + nsIXPCScriptable::WANT_ENUMERATE | \ + nsIXPCScriptable::WANT_POSTCREATE | \ + nsIXPCScriptable::WANT_FINALIZE) #define ARRAY_SCRIPTABLE_FLAGS \ (DOM_DEFAULT_SCRIPTABLE_FLAGS | \ nsIXPCScriptable::WANT_GETPROPERTY | \ nsIXPCScriptable::WANT_ENUMERATE) -#define NODELIST_SCRIPTABLE_FLAGS \ - (ARRAY_SCRIPTABLE_FLAGS | \ - nsIXPCScriptable::WANT_FINALIZE) - -#define EVENTTARGET_SCRIPTABLE_FLAGS \ - (DOM_DEFAULT_SCRIPTABLE_FLAGS | \ - nsIXPCScriptable::WANT_ADDPROPERTY | \ - nsIXPCScriptable::WANT_FINALIZE) - #define DOMCLASSINFO_STANDARD_FLAGS \ (nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::DOM_OBJECT) @@ -641,7 +632,7 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(ProcessingInstruction, nsNodeSH, NODE_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(Notation, nsNodeSH, NODE_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(NodeList, nsNodeListSH, NODELIST_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(NodeList, nsNodeListSH, ARRAY_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(NamedNodeMap, nsNamedNodeMapSH, ARRAY_SCRIPTABLE_FLAGS) @@ -892,7 +883,9 @@ static nsDOMClassInfoData sClassInfoData[] = { ARRAY_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA_WITH_NAME(ContentList, HTMLCollection, - nsContentListSH, NODELIST_SCRIPTABLE_FLAGS) + nsContentListSH, + ARRAY_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(XMLStylesheetProcessingInstruction, nsNodeSH, NODE_SCRIPTABLE_FLAGS) @@ -1213,7 +1206,8 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(XMLHttpProgressEvent, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(XMLHttpRequest, nsEventTargetSH, - EVENTTARGET_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_ADDPROPERTY) NS_DEFINE_CLASSINFO_DATA(ClientRect, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) @@ -1284,7 +1278,8 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(XMLHttpRequestUpload, nsEventTargetSH, - EVENTTARGET_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_ADDPROPERTY) // DOM Traversal NodeIterator class NS_DEFINE_CLASSINFO_DATA(NodeIterator, nsDOMGenericSH, @@ -4172,14 +4167,28 @@ nsDOMClassInfo::GetClassInfoInstance(nsDOMClassInfoData* aData) } // static -void +nsresult nsDOMClassInfo::PreserveNodeWrapper(nsIXPConnectWrappedNative *aWrapper) { - nsWrapperCache* cache; - CallQueryInterface(aWrapper->Native(), &cache); - if (cache) { - cache->PreserveWrapper(); + nsISupports *native = aWrapper->Native(); + nsCOMPtr node(do_QueryInterface(native)); + + nsCOMPtr doc; + if (node) { + nsCOMPtr domdoc; + node->GetOwnerDocument(getter_AddRefs(domdoc)); + doc = do_QueryInterface(domdoc); } + + if (!doc) { + doc = do_QueryInterface(native); + } + + if (doc) { + nsCOMPtr n(do_QueryInterface(node)); + doc->AddReference(n, aWrapper); + } + return NS_OK; } @@ -6901,16 +6910,6 @@ nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj, return rv; } -NS_IMETHODIMP -nsNodeSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj) -{ - nsINode* node = static_cast(wrapper->Native()); - node->SetWrapper(wrapper); - - return nsEventReceiverSH::PostCreate(wrapper, cx, obj); -} - NS_IMETHODIMP nsNodeSH::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval id, jsval *vp, PRBool *_retval) @@ -6929,13 +6928,6 @@ nsNodeSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, return DefineVoidProp(cx, obj, id, objp); } - if (id == sOnload_id || id == sOnerror_id) { - // Make sure that this node can't go away while waiting for a - // network load that could fire an event handler. - nsINode* node = static_cast(wrapper->Native()); - node->PreserveWrapper(); - } - return nsEventReceiverSH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval); } @@ -7004,16 +6996,6 @@ nsNodeSH::GetFlags(PRUint32 *aFlags) return NS_OK; } -NS_IMETHODIMP -nsNodeSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj) -{ - nsINode* node = static_cast(wrapper->Native()); - node->ClearWrapper(); - - return NS_OK; -} - // EventReceiver helper // static @@ -7264,6 +7246,12 @@ nsEventReceiverSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval id, PRUint32 flags, JSObject **objp, PRBool *_retval) { + if (id == sOnload_id || id == sOnerror_id) { + // Make sure that this node can't go away while waiting for a + // network load that could fire an event handler. + nsDOMClassInfo::PreserveNodeWrapper(wrapper); + } + if (!JSVAL_IS_STRING(id)) { return NS_OK; } @@ -7348,30 +7336,6 @@ nsEventReceiverSH::AddProperty(nsIXPConnectWrappedNative *wrapper, // EventTarget helper -NS_IMETHODIMP -nsEventTargetSH::PreCreate(nsISupports *nativeObj, JSContext *cx, - JSObject *globalObj, JSObject **parentObj) -{ - nsXHREventTarget *target = nsXHREventTarget::FromSupports(nativeObj); - - nsCOMPtr native_parent; - target->GetParentObject(getter_AddRefs(native_parent)); - - *parentObj = native_parent ? native_parent->GetGlobalJSObject() : globalObj; - - return NS_OK; -} - -NS_IMETHODIMP -nsEventTargetSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj) -{ - nsXHREventTarget *target = nsXHREventTarget::FromSupports(wrapper->Native()); - target->SetWrapper(wrapper); - - return nsDOMGenericSH::PostCreate(wrapper, cx, obj); -} - NS_IMETHODIMP nsEventTargetSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval id, @@ -7394,24 +7358,26 @@ nsEventTargetSH::AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, if (id == sAddEventListener_id) { return NS_OK; } - - nsXHREventTarget *target = nsXHREventTarget::FromSupports(wrapper->Native()); - target->PreserveWrapper(); - + nsISupports* native = wrapper->Native(); + nsCOMPtr target = do_QueryInterface(native); + if (target) { + nsCOMPtr scriptContext; + target->GetContextForEventHandlers(getter_AddRefs(scriptContext)); + if (scriptContext) { + nsCOMPtr window = + do_QueryInterface(scriptContext->GetGlobalObject()); + if (window) { + nsCOMPtr doc = + do_QueryInterface(window->GetExtantDocument()); + if (doc) { + doc->AddReference(native, wrapper); + } + } + } + } return NS_OK; } -NS_IMETHODIMP -nsEventTargetSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj) -{ - nsXHREventTarget *target = nsXHREventTarget::FromSupports(wrapper->Native()); - target->ClearWrapper(); - - return NS_OK; -} - - // Element helper NS_IMETHODIMP @@ -7684,49 +7650,6 @@ nsArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, // NodeList scriptable helper -nsresult -nsNodeListSH::PreCreate(nsISupports *nativeObj, JSContext *cx, - JSObject *globalObj, JSObject **parentObj) -{ - nsWrapperCache* cache; - CallQueryInterface(nativeObj, &cache); - if (!cache) { - *parentObj = globalObj; - return NS_OK; - } - - // nsChildContentList is the only class that uses nsNodeListSH and has a - // cached wrapper. - nsChildContentList *list = nsChildContentList::FromSupports(nativeObj); - nsISupports *native_parent = list->GetParentObject(); - if (!native_parent) { - return NS_ERROR_FAILURE; - } - - jsval v; - nsCOMPtr holder; - nsresult rv = WrapNative(cx, globalObj, native_parent, - NS_GET_IID(nsISupports), &v, - getter_AddRefs(holder)); - - *parentObj = JSVAL_TO_OBJECT(v); - - return rv; -} - -NS_IMETHODIMP -nsNodeListSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj) -{ - nsWrapperCache* cache; - CallQueryInterface(wrapper->Native(), &cache); - if (cache) { - cache->SetWrapper(wrapper); - } - - return nsArraySH::PostCreate(wrapper, cx, obj); -} - nsresult nsNodeListSH::GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, PRUint32 *length) @@ -7765,19 +7688,6 @@ nsNodeListSH::GetItemAt(nsISupports *aNative, PRUint32 aIndex, return list->GetNodeAt(aIndex); } -NS_IMETHODIMP -nsNodeListSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj) -{ - nsWrapperCache* cache; - CallQueryInterface(wrapper->Native(), &cache); - if (cache) { - cache->ClearWrapper(); - } - - return NS_OK; -} - // StringList scriptable helper @@ -7915,7 +7825,8 @@ nsContentListSH::PreCreate(nsISupports *nativeObj, JSContext *cx, nsISupports *native_parent = contentList->GetParentObject(); if (!native_parent) { - return NS_ERROR_FAILURE; + *parentObj = globalObj; + return NS_OK; } jsval v; @@ -7929,16 +7840,6 @@ nsContentListSH::PreCreate(nsISupports *nativeObj, JSContext *cx, return rv; } -NS_IMETHODIMP -nsContentListSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj) -{ - nsContentList *list = nsContentList::FromSupports(wrapper->Native()); - list->SetWrapper(wrapper); - - return nsNamedArraySH::PostCreate(wrapper, cx, obj); -} - nsresult nsContentListSH::GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, PRUint32 *length) @@ -7966,15 +7867,6 @@ nsContentListSH::GetNamedItem(nsISupports *aNative, const nsAString& aName, return list->GetNamedItem(aName, aResult); } -NS_IMETHODIMP -nsContentListSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj) -{ - nsContentList *list = nsContentList::FromSupports(wrapper->Native()); - list->ClearWrapper(); - - return NS_OK; -} // Document helper for document.location and document.on* @@ -8199,7 +8091,7 @@ nsDocumentSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx, doc->SetJSObject(nsnull); - return nsNodeSH::Finalize(wrapper, cx, obj); + return NS_OK; } // HTMLDocument helper diff --git a/dom/src/base/nsDOMClassInfo.h b/dom/src/base/nsDOMClassInfo.h index 70740623b15..f0329721290 100644 --- a/dom/src/base/nsDOMClassInfo.h +++ b/dom/src/base/nsDOMClassInfo.h @@ -172,7 +172,7 @@ public: ::JS_GET_CLASS(cx, obj) == sXPCNativeWrapperClass; } - static void PreserveNodeWrapper(nsIXPConnectWrappedNative *aWrapper); + static nsresult PreserveNodeWrapper(nsIXPConnectWrappedNative *aWrapper); protected: friend nsIClassInfo* NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID); @@ -400,17 +400,11 @@ protected: { } public: - NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx, - JSObject *globalObj, JSObject **parentObj); - NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj); NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval id, PRUint32 flags, JSObject **objp, PRBool *_retval); NS_IMETHOD AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval id, jsval *vp, PRBool *_retval); - NS_IMETHOD Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj); static nsIClassInfo *doCreate(nsDOMClassInfoData* aData) { @@ -562,8 +556,6 @@ protected: public: NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj, JSObject **parentObj); - NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj); NS_IMETHOD AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval id, jsval *vp, PRBool *_retval); NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, @@ -574,8 +566,6 @@ public: NS_IMETHOD SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval id, jsval *vp, PRBool *_retval); NS_IMETHOD GetFlags(PRUint32 *aFlags); - NS_IMETHOD Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj); static nsIClassInfo *doCreate(nsDOMClassInfoData* aData) { @@ -678,13 +668,6 @@ protected: } public: - NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx, - JSObject *globalObj, JSObject **parentObj); - NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj); - NS_IMETHOD Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj); - virtual nsresult GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, PRUint32 *length); virtual nsISupports* GetItemAt(nsISupports *aNative, PRUint32 aIndex, @@ -796,10 +779,6 @@ protected: public: NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj, JSObject **parentObj); - NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj); - NS_IMETHOD Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx, - JSObject *obj); virtual nsresult GetLength(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, PRUint32 *length); diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index d5ad0785e5c..8d16510e59a 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -1001,6 +1001,13 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGlobalWindow) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocumentPrincipal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDoc) + // Traverse any associated preserved wrappers. + { + if (tmp->mDoc) { + cb.NoteXPCOMChild(tmp->mDoc->GetReference(tmp)); + } + } + // Traverse stuff from nsPIDOMWindow NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChromeEventHandler) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument) @@ -1033,6 +1040,12 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mApplicationCache) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocumentPrincipal) + // Unlink any associated preserved wrapper. + if (tmp->mDoc) { + tmp->mDoc->RemoveReference(tmp); + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDoc) + } + // Unlink stuff from nsPIDOMWindow NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChromeEventHandler) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument) diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp index 61c9c000f58..6408eccc837 100644 --- a/dom/src/base/nsJSEnvironment.cpp +++ b/dom/src/base/nsJSEnvironment.cpp @@ -3372,8 +3372,7 @@ nsJSContext::ScriptExecuted() NS_IMETHODIMP nsJSContext::PreserveWrapper(nsIXPConnectWrappedNative *aWrapper) { - nsDOMClassInfo::PreserveNodeWrapper(aWrapper); - return NS_OK; + return nsDOMClassInfo::PreserveNodeWrapper(aWrapper); } //static diff --git a/js/src/xpconnect/src/xpcconvert.cpp b/js/src/xpconnect/src/xpcconvert.cpp index 1fd1f820ff2..c6c87a9e85c 100644 --- a/js/src/xpconnect/src/xpcconvert.cpp +++ b/js/src/xpconnect/src/xpcconvert.cpp @@ -48,7 +48,6 @@ #include "nsIAtom.h" #include "XPCWrapper.h" #include "nsJSPrincipals.h" -#include "nsWrapperCache.h" //#define STRICT_CHECK_OF_UNICODE #ifdef STRICT_CHECK_OF_UNICODE @@ -1092,28 +1091,15 @@ XPCConvert::NativeInterface2JSObject(XPCCallContext& ccx, if(!iface) return JS_FALSE; - nsresult rv; XPCWrappedNative* wrapper; - nsWrapperCache* cache; - src->QueryInterface(NS_GET_IID(nsWrapperCache), (void**)&cache); - if(cache && - (wrapper = static_cast(cache->GetWrapper()))) - { - NS_ADDREF(wrapper); - wrapper->FindTearOff(ccx, iface, JS_FALSE, &rv); - } - else - { - rv = XPCWrappedNative::GetNewOrUsed(ccx, src, xpcscope, iface, - isGlobal, &wrapper); - } - + nsresult rv = XPCWrappedNative::GetNewOrUsed(ccx, src, xpcscope, + iface, isGlobal, + &wrapper); if(pErr) *pErr = rv; if(NS_SUCCEEDED(rv) && wrapper) { uint32 flags = 0; - JSObject *flat = wrapper->GetFlatJSObject(); if (allowNativeWrapper && wrapper->GetScope() != xpcscope) { // Cross scope access detected. Check if chrome code @@ -1171,6 +1157,7 @@ XPCConvert::NativeInterface2JSObject(XPCCallContext& ccx, flags = script ? JS_GetScriptFilenameFlags(script) : 0; NS_ASSERTION(flags != JSFILENAME_NULL, "null script filename"); + JSObject *flat = wrapper->GetFlatJSObject(); if(!JS_IsSystemObject(ccx, flat)) { @@ -1278,6 +1265,7 @@ XPCConvert::NativeInterface2JSObject(XPCCallContext& ccx, } } + JSObject *flat = wrapper->GetFlatJSObject(); const char *name = STOBJ_GET_CLASS(flat)->name; if(allowNativeWrapper && !(flags & JSFILENAME_SYSTEM) && diff --git a/js/src/xpconnect/src/xpcwrappednative.cpp b/js/src/xpconnect/src/xpcwrappednative.cpp index a14f64ffd6b..1804a2a3ba9 100644 --- a/js/src/xpconnect/src/xpcwrappednative.cpp +++ b/js/src/xpconnect/src/xpcwrappednative.cpp @@ -45,7 +45,6 @@ #include "nsCRT.h" #include "XPCNativeWrapper.h" #include "XPCWrapper.h" -#include "nsWrapperCache.h" /***************************************************************************/ @@ -590,13 +589,27 @@ XPCWrappedNative::GetUsedOnly(XPCCallContext& ccx, XPCWrappedNative** resultWrapper) { NS_ASSERTION(Object, "XPCWrappedNative::GetUsedOnly was called with a null Object"); + nsCOMPtr identity; +#ifdef XPC_IDISPATCH_SUPPORT + // XXX See GetNewOrUsed for more info on this + if(Interface->GetIID()->Equals(NSID_IDISPATCH)) + identity = Object; + else +#endif + identity = do_QueryInterface(Object); + + if(!identity) + { + NS_ERROR("This XPCOM object fails in QueryInterface to nsISupports!"); + return NS_ERROR_FAILURE; + } XPCWrappedNative* wrapper; - nsWrapperCache* cache; - Object->QueryInterface(NS_GET_IID(nsWrapperCache), (void**)&cache); - if(cache) - { - wrapper = static_cast(cache->GetWrapper()); + Native2WrappedNativeMap* map = Scope->GetWrappedNativeMap(); + + { // scoped lock + XPCAutoLock lock(Scope->GetRuntime()->GetMapLock()); + wrapper = map->Find(identity); if(!wrapper) { *resultWrapper = nsnull; @@ -604,36 +617,6 @@ XPCWrappedNative::GetUsedOnly(XPCCallContext& ccx, } NS_ADDREF(wrapper); } - else - { - nsCOMPtr identity; -#ifdef XPC_IDISPATCH_SUPPORT - // XXX See GetNewOrUsed for more info on this - if(Interface->GetIID()->Equals(NSID_IDISPATCH)) - identity = Object; - else -#endif - identity = do_QueryInterface(Object); - - if(!identity) - { - NS_ERROR("This XPCOM object fails in QueryInterface to nsISupports!"); - return NS_ERROR_FAILURE; - } - - Native2WrappedNativeMap* map = Scope->GetWrappedNativeMap(); - - { // scoped lock - XPCAutoLock lock(Scope->GetRuntime()->GetMapLock()); - wrapper = map->Find(identity); - if(!wrapper) - { - *resultWrapper = nsnull; - return NS_OK; - } - NS_ADDREF(wrapper); - } - } nsresult rv; if(!wrapper->FindTearOff(ccx, Interface, JS_FALSE, &rv)) From 9bbc67f4de6dd27eee64803cb531ed4d4a2a4b13 Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Tue, 4 Nov 2008 20:55:48 +0100 Subject: [PATCH 10/10] Backed out changeset 47c0377779bb to fix orange --- js/src/xpconnect/crashtests/crashtests.list | 1 - js/src/xpconnect/src/xpcquickstubs.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/js/src/xpconnect/crashtests/crashtests.list b/js/src/xpconnect/crashtests/crashtests.list index ce10de174a2..54947a55de1 100644 --- a/js/src/xpconnect/crashtests/crashtests.list +++ b/js/src/xpconnect/crashtests/crashtests.list @@ -8,4 +8,3 @@ load 394810-1.html load 403356-1.html load 418139-1.svg load 420513-1.html -load 462926.html diff --git a/js/src/xpconnect/src/xpcquickstubs.h b/js/src/xpconnect/src/xpcquickstubs.h index 99379b36dd7..0bafed8f5f0 100644 --- a/js/src/xpconnect/src/xpcquickstubs.h +++ b/js/src/xpconnect/src/xpcquickstubs.h @@ -266,7 +266,7 @@ public: struct xpc_qsSelfRef { - xpc_qsSelfRef() : ptr(nsnull) {} + xpc_qsSelfRef() {} explicit xpc_qsSelfRef(nsISupports *p) : ptr(p) {} ~xpc_qsSelfRef() { NS_IF_RELEASE(ptr); }