From 11e4581e686b3a193342368664869c5413aed82a Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Tue, 13 Apr 2004 03:21:50 +0000 Subject: [PATCH] Fixing bug 239953. Remove duplicated code in nsContentUtils. r=jonas@sicking.cc, sr=peterv@propagandism.org. git-svn-id: svn://10.0.0.236/trunk@154766 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsContentUtils.h | 13 ---- mozilla/content/base/src/Makefile.in | 1 + mozilla/content/base/src/nsContentUtils.cpp | 69 +------------------ mozilla/content/events/src/Makefile.in | 1 + .../events/src/nsEventListenerManager.cpp | 3 +- mozilla/content/html/document/src/Makefile.in | 1 + .../html/document/src/nsHTMLDocument.cpp | 3 +- mozilla/content/xml/document/src/Makefile.in | 1 + .../xml/document/src/nsXMLDocument.cpp | 3 +- 9 files changed, 13 insertions(+), 82 deletions(-) diff --git a/mozilla/content/base/public/nsContentUtils.h b/mozilla/content/base/public/nsContentUtils.h index a5f9f6f3dde..af6047c9460 100644 --- a/mozilla/content/base/public/nsContentUtils.h +++ b/mozilla/content/base/public/nsContentUtils.h @@ -46,7 +46,6 @@ #include "nsCOMArray.h" #include "nsIStatefulFrame.h" -class nsIScriptGlobalObject; class nsIXPConnect; class nsIContent; class nsIDocument; @@ -175,18 +174,6 @@ public: */ static PRUint16 ReverseDocumentPosition(PRUint16 aDocumentPosition); - // These are copied from nsJSUtils.h - - static nsIScriptGlobalObject *GetStaticScriptGlobal(JSContext* aContext, - JSObject* aObj); - - static nsIScriptContext *GetStaticScriptContext(JSContext* aContext, - JSObject* aObj); - - static nsIScriptGlobalObject *GetDynamicScriptGlobal(JSContext *aContext); - - static nsIScriptContext *GetDynamicScriptContext(JSContext *aContext); - static PRUint32 CopyNewlineNormalizedUnicodeTo(const nsAString& aSource, PRUint32 aSrcOffset, PRUnichar* aDest, diff --git a/mozilla/content/base/src/Makefile.in b/mozilla/content/base/src/Makefile.in index 18d1ca7cebf..fabe082dd77 100644 --- a/mozilla/content/base/src/Makefile.in +++ b/mozilla/content/base/src/Makefile.in @@ -134,6 +134,7 @@ INCLUDES += \ -I$(srcdir)/../../html/content/src \ -I$(srcdir)/../../base/src \ -I$(srcdir)/../../../layout/html/base/src \ + -I$(srcdir)/../../../dom/src/base \ $(NULL) DEFINES += -D_IMPL_NS_LAYOUT diff --git a/mozilla/content/base/src/nsContentUtils.cpp b/mozilla/content/base/src/nsContentUtils.cpp index 509a59d5d83..66252a58ff4 100644 --- a/mozilla/content/base/src/nsContentUtils.cpp +++ b/mozilla/content/base/src/nsContentUtils.cpp @@ -36,7 +36,7 @@ /* A namespace class for static layout utilities. */ -#include "jsapi.h" +#include "nsJSUtils.h" #include "nsCOMPtr.h" #include "nsAString.h" #include "nsPrintfCString.h" @@ -172,69 +172,6 @@ nsContentUtils::GetParserServiceWeakRef() return sParserService; } -// static -nsIScriptGlobalObject * -nsContentUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj) -{ - if (!sXPConnect) { - return nsnull; - } - - JSObject* parent; - JSObject* glob = aObj; // starting point for search - - if (!glob) - return nsnull; - - while (nsnull != (parent = JS_GetParent(aContext, glob))) { - glob = parent; - } - - nsCOMPtr wrapped_native; - - sXPConnect->GetWrappedNativeOfJSObject(aContext, glob, - getter_AddRefs(wrapped_native)); - NS_ENSURE_TRUE(wrapped_native, nsnull); - - nsCOMPtr native; - wrapped_native->GetNative(getter_AddRefs(native)); - - nsCOMPtr sgo(do_QueryInterface(native)); - - // This will return a pointer to something that's about to be - // released, but that's ok here. - return sgo; -} - -//static -nsIScriptContext * -nsContentUtils::GetStaticScriptContext(JSContext* aContext, - JSObject* aObj) -{ - nsIScriptGlobalObject *nativeGlobal = GetStaticScriptGlobal(aContext, aObj); - if (!nativeGlobal) - return nsnull; - return nativeGlobal->GetContext(); -} - -//static -nsIScriptGlobalObject * -nsContentUtils::GetDynamicScriptGlobal(JSContext* aContext) -{ - nsIScriptContext *scriptCX = GetDynamicScriptContext(aContext); - if (!scriptCX) { - return nsnull; - } - return scriptCX->GetGlobalObject(); -} - -//static -nsIScriptContext * -nsContentUtils::GetDynamicScriptContext(JSContext *aContext) -{ - return GetScriptContextFromJSContext(aContext); -} - template struct NormalizeNewlinesCharTraits { public: @@ -867,7 +804,7 @@ nsContentUtils::GetDocShellFromCaller() sThreadJSContextStack->Peek(&cx); if (cx) { - nsIScriptGlobalObject *sgo = GetDynamicScriptGlobal(cx); + nsIScriptGlobalObject *sgo = nsJSUtils::GetDynamicScriptGlobal(cx); if (sgo) { return sgo->GetDocShell(); @@ -890,7 +827,7 @@ nsContentUtils::GetDocumentFromCaller() nsCOMPtr doc; if (cx) { - nsIScriptGlobalObject *sgo = GetDynamicScriptGlobal(cx); + nsIScriptGlobalObject *sgo = nsJSUtils::GetDynamicScriptGlobal(cx); nsCOMPtr win(do_QueryInterface(sgo)); if (win) { diff --git a/mozilla/content/events/src/Makefile.in b/mozilla/content/events/src/Makefile.in index dc1f97eb455..1f01c271853 100644 --- a/mozilla/content/events/src/Makefile.in +++ b/mozilla/content/events/src/Makefile.in @@ -61,6 +61,7 @@ include $(topsrcdir)/config/rules.mk LOCAL_INCLUDES = -I$(srcdir)/../../html/base/src \ -I$(srcdir)/../../xul/content/src \ + -I$(srcdir)/../../../dom/src/base \ $(NULL) DEFINES += -D_IMPL_NS_LAYOUT diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index 747e7166eb2..79b0b981081 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -89,6 +89,7 @@ #include "nsIDOMNSDocument.h" #include "nsIWidget.h" #include "nsContentUtils.h" +#include "nsJSUtils.h" #include "nsIDOMEventGroup.h" #include "nsContentCID.h" @@ -1128,7 +1129,7 @@ nsEventListenerManager::AddScriptEventListener(nsISupports *aObject, NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE); } - context = nsContentUtils::GetDynamicScriptContext(cx); + context = nsJSUtils::GetDynamicScriptContext(cx); NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); } diff --git a/mozilla/content/html/document/src/Makefile.in b/mozilla/content/html/document/src/Makefile.in index 7f369fdc547..05855880523 100644 --- a/mozilla/content/html/document/src/Makefile.in +++ b/mozilla/content/html/document/src/Makefile.in @@ -83,6 +83,7 @@ INCLUDES += \ -I$(srcdir)/../../../base/src \ -I$(srcdir)/../../content/src \ -I$(srcdir)/../../style/src \ + -I$(srcdir)/../../../../dom/src/base \ $(NULL) DEFINES += -D_IMPL_NS_LAYOUT diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index ad7b3bd9268..eec73ddca4b 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -117,6 +117,7 @@ #include "nsICharsetAlias.h" #include "nsIPref.h" #include "nsContentUtils.h" +#include "nsJSUtils.h" #include "nsIDocumentCharsetInfo.h" #include "nsIDocumentEncoder.h" //for outputting selection #include "nsICharsetResolver.h" @@ -998,7 +999,7 @@ nsHTMLDocument::EndLoad() stack->Peek(&cx); if (cx) { - nsIScriptContext *scx = nsContentUtils::GetDynamicScriptContext(cx); + nsIScriptContext *scx = nsJSUtils::GetDynamicScriptContext(cx); if (scx) { // The load of the document was terminated while we're diff --git a/mozilla/content/xml/document/src/Makefile.in b/mozilla/content/xml/document/src/Makefile.in index 895ff2ee77e..a85740958d9 100644 --- a/mozilla/content/xml/document/src/Makefile.in +++ b/mozilla/content/xml/document/src/Makefile.in @@ -71,6 +71,7 @@ LOCAL_INCLUDES = \ -I$(srcdir)/../../../html/style/src \ -I$(srcdir)/../../../base/src \ -I$(srcdir)/../../../xul/content/src \ + -I$(srcdir)/../../../../dom/src/base \ $(NULL) DEFINES += -D_IMPL_NS_LAYOUT diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index b3edfa9a6bb..fd23338306d 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -85,6 +85,7 @@ #include "nsMimeTypes.h" #include "nsIEventListenerManager.h" #include "nsContentUtils.h" +#include "nsJSUtils.h" #include "nsIElementFactory.h" #include "nsCRT.h" #include "nsIWindowWatcher.h" @@ -368,7 +369,7 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn) if (stack) { JSContext *cx; if (NS_SUCCEEDED(stack->Peek(&cx)) && cx) { - callingContext = nsContentUtils::GetDynamicScriptContext(cx); + callingContext = nsJSUtils::GetDynamicScriptContext(cx); } }