From b53d1997de502b4806375f57afa70fcf89df4a2a Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Tue, 9 Jul 2002 03:43:15 +0000 Subject: [PATCH] Fixing bug 146143. Make sure the JS scope is cleared when leaving a full-page plugin. r=bzbarsky@mit.edu, sr=jaggernaut@netscape.com git-svn-id: svn://10.0.0.236/trunk@124823 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/dom/src/base/nsGlobalWindow.cpp | 22 ++++++++++++++----- .../plugin/base/src/nsPluginViewer.cpp | 6 +++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index e1db49d26a4..9b0a41a6a02 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -433,11 +433,14 @@ GlobalWindowImpl::SetNewDocument(nsIDOMDocument* aDocument, bug 49615 describes a case.) */ /* We only want to do this when we're setting a new document rather than going away. See bug 61840. */ + if (mDocShell && aDocument) { SetStatus(nsString()); SetDefaultStatus(nsString()); } + PRBool do_clear_scope = PR_FALSE; + if (mDocument) { nsCOMPtr doc(do_QueryInterface(mDocument)); nsCOMPtr docURL; @@ -449,7 +452,6 @@ GlobalWindowImpl::SetNewDocument(nsIDOMDocument* aDocument, if (doc) { doc->GetDocumentURL(getter_AddRefs(docURL)); - doc = nsnull; // Forces release now } if (aRemoveEventListeners && mListenerManager) { @@ -470,13 +472,23 @@ GlobalWindowImpl::SetNewDocument(nsIDOMDocument* aDocument, ClearAllTimeouts(); if (mContext && mJSObject) { - ::JS_ClearScope((JSContext *)mContext->GetNativeContext(), - mJSObject); - - mIsScopeClear = PR_TRUE; + do_clear_scope = PR_TRUE; } } } + } else if (!aDocument) { + // If both mDocument and aDocument are null we've just left a + // full-page plugin page and we need to ensure that the scope is + // cleared so that the cached window.document property (which + // happens to be null in a full-page plugin window) is cleared. + + do_clear_scope = PR_TRUE; + } + + if (do_clear_scope) { + ::JS_ClearScope((JSContext *)mContext->GetNativeContext(), mJSObject); + + mIsScopeClear = PR_TRUE; } if (mContext && aDocument) { diff --git a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp index c90b36925b2..f79b0f0d9bc 100644 --- a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp @@ -435,6 +435,12 @@ PluginViewerImpl::Unload(void) NS_IMETHODIMP PluginViewerImpl::Close(void) { + nsCOMPtr sgo(do_GetInterface(mContainer)); + + if (sgo) { + sgo->SetNewDocument(nsnull, PR_TRUE, PR_TRUE); + } + return NS_OK; }