From f5f85d2946bbf11fff441bdeb4c9556be60bce2e Mon Sep 17 00:00:00 2001 From: "peterv%propagandism.org" Date: Fri, 2 Sep 2005 18:02:51 +0000 Subject: [PATCH] Fix for bug 298064 (nsContentUtils::GetDocumentFromCaller() is broken.). r=jst, sr=brendan. git-svn-id: svn://10.0.0.236/trunk@179553 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsContentUtils.h | 4 ++-- mozilla/content/base/src/nsContentUtils.cpp | 18 +++++++++++------- .../html/document/src/nsHTMLDocument.cpp | 9 ++++----- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/mozilla/content/base/public/nsContentUtils.h b/mozilla/content/base/public/nsContentUtils.h index 2296d99a71a..05c65c41b94 100644 --- a/mozilla/content/base/public/nsContentUtils.h +++ b/mozilla/content/base/public/nsContentUtils.h @@ -241,9 +241,9 @@ public: /** * Get the document through the JS context that's currently on the stack. - * If there's no JS context currently on the stack aDocument will be null. + * If there's no JS context currently on the stack it will return null. * - * @param aDocument The document or null if no JS context + * @return The document or null if no JS context */ static nsIDOMDocument *GetDocumentFromCaller(); diff --git a/mozilla/content/base/src/nsContentUtils.cpp b/mozilla/content/base/src/nsContentUtils.cpp index 3c0309ffcf9..f44a5f97a99 100644 --- a/mozilla/content/base/src/nsContentUtils.cpp +++ b/mozilla/content/base/src/nsContentUtils.cpp @@ -70,7 +70,7 @@ #include "nsNetUtil.h" #include "nsIScriptSecurityManager.h" #include "nsDOMError.h" -#include "nsIDOMWindowInternal.h" +#include "nsPIDOMWindow.h" #include "nsIJSContextStack.h" #include "nsIDocShell.h" #include "nsIDocShellTreeItem.h" @@ -113,6 +113,7 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID); #include "nsILineBreaker.h" #include "nsIWordBreaker.h" #include "nsIEventQueueService.h" +#include "jsdbgapi.h" // for ReportToConsole #include "nsIStringBundle.h" @@ -931,19 +932,22 @@ nsContentUtils::GetDocumentFromCaller() JSContext *cx = nsnull; sThreadJSContextStack->Peek(&cx); - nsCOMPtr doc; + nsIDOMDocument *doc = nsnull; if (cx) { - nsIScriptGlobalObject *sgo = nsJSUtils::GetDynamicScriptGlobal(cx); + JSObject *callee = nsnull; + JSStackFrame *fp = nsnull; + while (!callee && (fp = ::JS_FrameIterator(cx, &fp))) { + callee = ::JS_GetFrameCalleeObject(cx, fp); + } - nsCOMPtr win(do_QueryInterface(sgo)); + nsCOMPtr win = + do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(cx, callee)); if (win) { - win->GetDocument(getter_AddRefs(doc)); + doc = win->GetExtantDocument(); } } - // This will return a pointer to something we're about to release, - // but that's ok here. return doc; } diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 9775d5dfc9d..86c6ae1770d 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -1850,15 +1850,14 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) // Grab a reference to the calling documents security info (if any) // and principal as it may be lost in the call to Reset(). nsCOMPtr securityInfo; - nsCOMPtr callerPrincipal; - if (callerDoc) { securityInfo = callerDoc->GetSecurityInfo(); - - nsContentUtils::GetSecurityManager()-> - GetSubjectPrincipal(getter_AddRefs(callerPrincipal)); } + nsCOMPtr callerPrincipal; + nsContentUtils::GetSecurityManager()-> + GetSubjectPrincipal(getter_AddRefs(callerPrincipal)); + // The URI for the document after this call. Get it from the calling // principal (if available), or set it to "about:blank" if no // principal is reachable.